package mjkf.xinke.main.controller; import cn.hutool.core.collection.ListUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.jgy.xxs.core.http.resp.HttpResponse; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import mjkf.xinke.main.common.http.FuHttpResponse; import mjkf.xinke.main.dao.LocalMaterialCityAggrMapper; import mjkf.xinke.main.model.db.LocalMaterial; import mjkf.xinke.main.model.vo.LocalMaterialCityAggr; import mjkf.xinke.main.model.vo.LocalMaterialSummary; import mjkf.xinke.main.service.LocalMaterialService; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** *

* 地材 前端控制器 *

* * @author han0 * @since 2023-12-14 */ @RestController @RequestMapping("/local-material") public class LocalMaterialController { @Resource LocalMaterialService localMaterialService; @Resource LocalMaterialCityAggrMapper localMaterialCityAggrMapper; @ApiOperation("获取地材列表") @GetMapping("/") public HttpResponse list ( @ApiParam(value = "年") @RequestParam(value="year") Integer year, @ApiParam(value = "月") @RequestParam(value="month") Integer month, @ApiParam(value = "地市") @RequestParam(value="city", required=false) String city, @ApiParam(value = "区县") @RequestParam(value="county", required=false) String county, @ApiParam(value = "规格") @RequestParam(value="spec", required=false) String spec, @ApiParam(value = "名称") @RequestParam(value="name", required=false) String name ) { var query = localMaterialService.getQuery(year, month, city, county, spec, name); query.orderByDesc(LocalMaterial::getName); List data = localMaterialService.list(query); var groupMap = data.stream().collect(Collectors.groupingBy(item->item.getName(), Collectors.toList())); var result = new ArrayList(); for (String key: groupMap.keySet()) { result.add(new LocalMaterialSummary(groupMap.get(key))); } // 排序 result = (ArrayList) ListUtil.sortByProperty(result, "name"); return FuHttpResponse.Builder().dataResponse(result).build(); } @ApiOperation("获取地材概览") @GetMapping("/summary") public HttpResponse summary ( @ApiParam(value = "年") @RequestParam(value="year") Integer year, @ApiParam(value = "月") @RequestParam(value="month") Integer month ) { LambdaQueryWrapper query = new LambdaQueryWrapper<>(); if (year != null) { var date = LocalDate.of(year, month, 1); query.between(LocalMaterialCityAggr::getDate, date, date.plusYears(1)); } if (month != null) { var date = LocalDate.of(year, month, 1); query.between(LocalMaterialCityAggr::getDate, date, date.plusMonths(1)); } query.select(LocalMaterialCityAggr::getCity, LocalMaterialCityAggr::getCount); query.groupBy(LocalMaterialCityAggr::getCity); var result = localMaterialCityAggrMapper.selectList(query); return FuHttpResponse.Builder().dataResponse(result).build(); } }