feat(local-material): 新增地材相关接口

This commit is contained in:
han0
2023-12-14 17:10:49 +08:00
parent 3bd3724e2f
commit 8553f01361
6 changed files with 156 additions and 0 deletions

View File

@@ -1,8 +1,27 @@
package mjkf.xinke.main.controller; package mjkf.xinke.main.controller;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; 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;
/** /**
* <p> * <p>
* 地材 前端控制器 * 地材 前端控制器
@@ -14,5 +33,52 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("/local-material") @RequestMapping("/local-material")
public class LocalMaterialController { 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") 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<LocalMaterial> data = localMaterialService.list(query);
var groupMap = data.stream().collect(Collectors.groupingBy(item->item.getName(), Collectors.toList()));
var result = new ArrayList<LocalMaterialSummary>();
for (String key: groupMap.keySet()) {
result.add(new LocalMaterialSummary(groupMap.get(key)));
}
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<LocalMaterialCityAggr> 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();
}
} }

View File

@@ -0,0 +1,16 @@
package mjkf.xinke.main.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import mjkf.xinke.main.model.vo.LocalMaterialCityAggr;
/**
* <p>
* 地材 Mapper 接口
* </p>
*
* @author han0
* @since 2023-12-14
*/
public interface LocalMaterialCityAggrMapper extends BaseMapper<LocalMaterialCityAggr> {
}

View File

@@ -45,6 +45,10 @@ public class LocalMaterial extends Model<LocalMaterial> {
@TableField("SPEC") @TableField("SPEC")
private String spec; private String spec;
@ApiModelProperty("单位")
@TableField("UNIT")
private String unit;
@ApiModelProperty("地市") @ApiModelProperty("地市")
@TableField("CITY") @TableField("CITY")
private String city; private String city;
@@ -74,6 +78,8 @@ public class LocalMaterial extends Model<LocalMaterial> {
this.setCounty(row.getCell(2).getStringCellValue()); this.setCounty(row.getCell(2).getStringCellValue());
this.setPrice(BigDecimal.valueOf(row.getCell(3).getNumericCellValue())); this.setPrice(BigDecimal.valueOf(row.getCell(3).getNumericCellValue()));
this.setDate(row.getCell(4).getLocalDateTimeCellValue().toLocalDate()); this.setDate(row.getCell(4).getLocalDateTimeCellValue().toLocalDate());
this.setSpec(row.getCell(5).getStringCellValue());
this.setUnit(row.getCell(6).getStringCellValue());
} }
public LocalMaterial update(LocalMaterial item) { public LocalMaterial update(LocalMaterial item) {
@@ -82,6 +88,8 @@ public class LocalMaterial extends Model<LocalMaterial> {
this.setCounty(item.getCounty()); this.setCounty(item.getCounty());
this.setPrice(item.getPrice()); this.setPrice(item.getPrice());
this.setDate(item.getDate()); this.setDate(item.getDate());
this.setSpec(item.getSpec());
this.setUnit(item.getUnit());
return this; return this;
} }
} }

View File

@@ -0,0 +1,21 @@
package mjkf.xinke.main.model.vo;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.time.LocalDate;
@Data
@TableName("LOCAL_MATERIAL")
public class LocalMaterialCityAggr{
private String city;
@JsonIgnore
private LocalDate date;
@TableField(value = "count(*)", insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
private Long count;
}

View File

@@ -0,0 +1,29 @@
package mjkf.xinke.main.model.vo;
import mjkf.xinke.main.model.db.LocalMaterial;
import java.math.BigDecimal;
import java.util.List;
public class LocalMaterialSummary {
private String name;
private String spec;
private String unit;
private List<LocalMaterial> data;
public LocalMaterialSummary() {}
public LocalMaterialSummary(List<LocalMaterial> list) {
this.name = list.get(0).getName();
this.spec = list.get(0).getSpec();
this.unit = list.get(0).getUnit();
this.data = list;
LocalMaterial avg_item = new LocalMaterial();
avg_item.setName(list.get(0).getName());
avg_item.setSpec(list.get(0).getSpec());
avg_item.setUnit(list.get(0).getUnit());
avg_item.setCounty("城区");
avg_item.setPrice(BigDecimal.valueOf(list.stream().mapToDouble(item->item.getPrice().doubleValue()).average().orElse(0D)));
this.data.add(avg_item);
}
}

View File

@@ -53,6 +53,22 @@ public class LocalMaterialService extends DataService<BaseMapper<LocalMaterial>,
return query; return query;
} }
public LambdaQueryWrapper<LocalMaterial> getQuery(Integer year, Integer month, String city, String county, String spec, String name) {
var query = this.getQuery(null, year, month, null, name);
if (city != null) {
query.like(LocalMaterial::getCity, city);
}
if(county != null) {
query.like(LocalMaterial::getCounty, county);
}
if(spec!= null) {
query.like(LocalMaterial::getSpec, spec);
}
return query;
}
public LambdaQueryWrapper<LocalMaterial> filterQuery(LambdaQueryWrapper<LocalMaterial> query) { public LambdaQueryWrapper<LocalMaterial> filterQuery(LambdaQueryWrapper<LocalMaterial> query) {
return query; return query;
} }