fix: 重写新增预算接口
This commit is contained in:
@@ -55,104 +55,95 @@ public class BudgetController {
|
||||
) throws Exception {
|
||||
params.check();
|
||||
var user = StpLoginUserUtil.getLoginUser();
|
||||
|
||||
// 查询各月份材料价格
|
||||
LambdaQueryWrapper<PricePublish> query = pricePublishService.getQuery(params);
|
||||
// 转换查询结果为键值对 材料id,月份 => 价格
|
||||
var priceMap = pricePublishService.getPriceMapEntryByMaterialIdAndMonth(query);
|
||||
// 各月份求和
|
||||
var totalMap = params.getTotalMap(priceMap);
|
||||
var budgetItemList = params.getBudgetItemList(priceMap);
|
||||
// 入库
|
||||
var budget = new Budget(params, user, totalMap);
|
||||
var budget = new Budget(params, user);
|
||||
budgetService.save(budget);
|
||||
for (var budgetItem: budgetItemList) {
|
||||
budgetItem.setBudgetId(budget.getId());
|
||||
budgetItemService.save(budgetItem);
|
||||
for (var item: params.getItems()) {
|
||||
budgetItemService.save(new BudgetItem(budget.getId(), item));
|
||||
}
|
||||
|
||||
return FuHttpResponse.Builder().dataResponse(budgetItemList).build();
|
||||
return FuHttpResponse.Builder().dataResponse(budget).build();
|
||||
}
|
||||
|
||||
@ApiOperation("查询预算")
|
||||
@GetMapping("/")
|
||||
public HttpResponse list (
|
||||
@ApiParam(value = "每页数量") @RequestParam(name = "size", required = false, defaultValue = "10") Integer size,
|
||||
@ApiParam(value = "页码") @RequestParam(name = "current", required = false, defaultValue = "1") Integer current,
|
||||
@ApiParam(value = "名称") @RequestParam(value="name", required = false) String name
|
||||
) throws Exception {
|
||||
var query = new LambdaQueryWrapper<Budget>();
|
||||
if (!ObjectUtils.isEmpty(name)) {
|
||||
query.like(Budget::getName, name);
|
||||
}
|
||||
var result = budgetService.page(new Page<>(current, size), query);
|
||||
return FuHttpResponse.Builder().dataResponse(result).build();
|
||||
}
|
||||
|
||||
@ApiOperation("删除预算")
|
||||
@CommonLog("删除预算")
|
||||
@DeleteMapping("/")
|
||||
public HttpResponse delete (
|
||||
@ApiParam(value = "id列表:1,2,3") @RequestParam(value="ids") String ids
|
||||
) throws Exception {
|
||||
var idList = Arrays.asList(ids.split(","));
|
||||
var query = new LambdaQueryWrapper<Budget>();
|
||||
query.in(Budget::getId, idList);
|
||||
budgetService.remove(query);
|
||||
return FuHttpResponse.Builder().dataResponse().build();
|
||||
}
|
||||
|
||||
@ApiOperation("预算详情")
|
||||
@GetMapping("/{id}")
|
||||
public HttpResponse detail (
|
||||
@ApiParam(value = "id") @PathVariable("id") Integer id
|
||||
) throws Exception {
|
||||
var budget = budgetService.getById(id);
|
||||
if (budget == null) {
|
||||
throw new NcHttpException(HttpErrorResponseEnum.BUDGET_NOT_FOUND);
|
||||
}
|
||||
|
||||
var query = new LambdaQueryWrapper<BudgetItem>();
|
||||
query.eq(BudgetItem::getBudgetId, id);
|
||||
var list = budgetItemService.list(query);
|
||||
|
||||
var result = new BudgetDetail(budget, list);
|
||||
return FuHttpResponse.Builder().dataResponse(result).build();
|
||||
}
|
||||
|
||||
@ApiOperation("预算编辑")
|
||||
@CommonLog("预算编辑")
|
||||
@PutMapping("/{id}")
|
||||
public HttpResponse edit (
|
||||
@ApiParam("id") @PathVariable String id,
|
||||
@ApiParam("参数") @RequestBody BudgetCreateRequest params
|
||||
) throws Exception {
|
||||
params.check();
|
||||
var user = StpLoginUserUtil.getLoginUser();
|
||||
|
||||
var budget = budgetService.getById(id);
|
||||
if (budget == null) {
|
||||
throw new NcHttpException(HttpErrorResponseEnum.BUDGET_NOT_FOUND);
|
||||
}
|
||||
|
||||
// 查询各月份材料价格
|
||||
LambdaQueryWrapper<PricePublish> query = pricePublishService.getQuery(params);
|
||||
// 转换查询结果为键值对 材料id,月份 => 价格
|
||||
var priceMap = pricePublishService.getPriceMapEntryByMaterialIdAndMonth(query);
|
||||
// 各月份求和
|
||||
var totalMap = params.getTotalMap(priceMap);
|
||||
var budgetItemList = params.getBudgetItemList(priceMap);
|
||||
// 入库
|
||||
budget.update(params, user, totalMap);
|
||||
budgetService.updateById(budget);
|
||||
budgetItemService.remove(new LambdaQueryWrapper<BudgetItem>().eq(BudgetItem::getBudgetId, id));
|
||||
for (var budgetItem: budgetItemList) {
|
||||
budgetItem.setBudgetId(budget.getId());
|
||||
budgetItemService.save(budgetItem);
|
||||
}
|
||||
|
||||
return FuHttpResponse.Builder().dataResponse(budgetItemList).build();
|
||||
}
|
||||
// @ApiOperation("查询预算")
|
||||
// @GetMapping("/")
|
||||
// public HttpResponse list (
|
||||
// @ApiParam(value = "每页数量") @RequestParam(name = "size", required = false, defaultValue = "10") Integer size,
|
||||
// @ApiParam(value = "页码") @RequestParam(name = "current", required = false, defaultValue = "1") Integer current,
|
||||
// @ApiParam(value = "名称") @RequestParam(value="name", required = false) String name
|
||||
// ) throws Exception {
|
||||
// var query = new LambdaQueryWrapper<Budget>();
|
||||
// if (!ObjectUtils.isEmpty(name)) {
|
||||
// query.like(Budget::getName, name);
|
||||
// }
|
||||
// var result = budgetService.page(new Page<>(current, size), query);
|
||||
// return FuHttpResponse.Builder().dataResponse(result).build();
|
||||
// }
|
||||
//
|
||||
// @ApiOperation("删除预算")
|
||||
// @CommonLog("删除预算")
|
||||
// @DeleteMapping("/")
|
||||
// public HttpResponse delete (
|
||||
// @ApiParam(value = "id列表:1,2,3") @RequestParam(value="ids") String ids
|
||||
// ) throws Exception {
|
||||
// var idList = Arrays.asList(ids.split(","));
|
||||
// var query = new LambdaQueryWrapper<Budget>();
|
||||
// query.in(Budget::getId, idList);
|
||||
// budgetService.remove(query);
|
||||
// return FuHttpResponse.Builder().dataResponse().build();
|
||||
// }
|
||||
//
|
||||
// @ApiOperation("预算详情")
|
||||
// @GetMapping("/{id}")
|
||||
// public HttpResponse detail (
|
||||
// @ApiParam(value = "id") @PathVariable("id") Integer id
|
||||
// ) throws Exception {
|
||||
// var budget = budgetService.getById(id);
|
||||
// if (budget == null) {
|
||||
// throw new NcHttpException(HttpErrorResponseEnum.BUDGET_NOT_FOUND);
|
||||
// }
|
||||
//
|
||||
// var query = new LambdaQueryWrapper<BudgetItem>();
|
||||
// query.eq(BudgetItem::getBudgetId, id);
|
||||
// var list = budgetItemService.list(query);
|
||||
//
|
||||
// var result = new BudgetDetail(budget, list);
|
||||
// return FuHttpResponse.Builder().dataResponse(result).build();
|
||||
// }
|
||||
//
|
||||
// @ApiOperation("预算编辑")
|
||||
// @CommonLog("预算编辑")
|
||||
// @PutMapping("/{id}")
|
||||
// public HttpResponse edit (
|
||||
// @ApiParam("id") @PathVariable String id,
|
||||
// @ApiParam("参数") @RequestBody BudgetCreateRequest params
|
||||
// ) throws Exception {
|
||||
// params.check();
|
||||
// var user = StpLoginUserUtil.getLoginUser();
|
||||
//
|
||||
// var budget = budgetService.getById(id);
|
||||
// if (budget == null) {
|
||||
// throw new NcHttpException(HttpErrorResponseEnum.BUDGET_NOT_FOUND);
|
||||
// }
|
||||
//
|
||||
// // 查询各月份材料价格
|
||||
// LambdaQueryWrapper<PricePublish> query = pricePublishService.getQuery(params);
|
||||
// // 转换查询结果为键值对 材料id,月份 => 价格
|
||||
// var priceMap = pricePublishService.getPriceMapEntryByMaterialIdAndMonth(query);
|
||||
// // 各月份求和
|
||||
// var totalMap = params.getTotalMap(priceMap);
|
||||
// var budgetItemList = params.getBudgetItemList(priceMap);
|
||||
// // 入库
|
||||
// budget.update(params, user, totalMap);
|
||||
// budgetService.updateById(budget);
|
||||
// budgetItemService.remove(new LambdaQueryWrapper<BudgetItem>().eq(BudgetItem::getBudgetId, id));
|
||||
// for (var budgetItem: budgetItemList) {
|
||||
// budgetItem.setBudgetId(budget.getId());
|
||||
// budgetItemService.save(budgetItem);
|
||||
// }
|
||||
//
|
||||
// return FuHttpResponse.Builder().dataResponse(budgetItemList).build();
|
||||
// }
|
||||
|
||||
// todo-1 地图里程数据
|
||||
// todo-2 外省数据上传
|
||||
|
@@ -47,6 +47,13 @@ public class PricePublishController {
|
||||
if (year == null || month == null) {
|
||||
throw new NcHttpException(HttpErrorResponseEnum.PRICE_PUBLISH_YEAR_MONTH_NEEDED);
|
||||
}
|
||||
// 获取最新数据
|
||||
if (month < 0 || year < 0) {
|
||||
var date = pricePublishService.getLatestDate();
|
||||
year = date.getYear();
|
||||
month = date.getMonth();
|
||||
}
|
||||
|
||||
var query = pricePublishService.getQuery(year, month, materialId, name, spec, type);
|
||||
query.orderByAsc(PricePublish::getMaterialId);
|
||||
var result = pricePublishService.list(query);
|
||||
|
@@ -41,41 +41,49 @@ public class Budget extends Model<Budget> {
|
||||
@TableField("`NAME`")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("总数")
|
||||
@ApiModelProperty("当期总价")
|
||||
@TableField("AMOUNT")
|
||||
private Double amount;
|
||||
|
||||
@ApiModelProperty("最小值")
|
||||
@TableField("MIN_AMOUNT")
|
||||
@JsonProperty(value = "min_amount")
|
||||
private Double minAmount;
|
||||
@ApiModelProperty("基期总价")
|
||||
@TableField("BASE_AMOUNT")
|
||||
private Double baseAmount;
|
||||
|
||||
@ApiModelProperty("最大值")
|
||||
@TableField("MAX_AMOUNT")
|
||||
@JsonProperty(value = "max_amount")
|
||||
private Double maxAmount;
|
||||
@ApiModelProperty("调差金额")
|
||||
@TableField("DIFF")
|
||||
private Double diff;
|
||||
|
||||
@ApiModelProperty("最小值月份")
|
||||
@TableField("MIN_MONTH")
|
||||
@JsonProperty(value = "min_month")
|
||||
private String minMonth;
|
||||
|
||||
@ApiModelProperty("最大值月份")
|
||||
@TableField("MAX_MONTH")
|
||||
@JsonProperty(value = "max_month")
|
||||
private String maxMonth;
|
||||
// @ApiModelProperty("最小值")
|
||||
// @TableField("MIN_AMOUNT")
|
||||
// @JsonProperty(value = "min_amount")
|
||||
// private Double minAmount;
|
||||
//
|
||||
// @ApiModelProperty("最大值")
|
||||
// @TableField("MAX_AMOUNT")
|
||||
// @JsonProperty(value = "max_amount")
|
||||
// private Double maxAmount;
|
||||
//
|
||||
// @ApiModelProperty("最小值月份")
|
||||
// @TableField("MIN_MONTH")
|
||||
// @JsonProperty(value = "min_month")
|
||||
// private String minMonth;
|
||||
//
|
||||
// @ApiModelProperty("最大值月份")
|
||||
// @TableField("MAX_MONTH")
|
||||
// @JsonProperty(value = "max_month")
|
||||
// private String maxMonth;
|
||||
|
||||
@ApiModelProperty("日期")
|
||||
@TableField("`DATE`")
|
||||
private LocalDate date;
|
||||
|
||||
@ApiModelProperty("年份")
|
||||
@TableField("`YEAR`")
|
||||
private Integer year;
|
||||
|
||||
@ApiModelProperty("月份")
|
||||
@TableField(value="`MONTHS`", typeHandler = FastjsonArrayHandler.class)
|
||||
private List months;
|
||||
//
|
||||
// @ApiModelProperty("年份")
|
||||
// @TableField("`YEAR`")
|
||||
// private Integer year;
|
||||
//
|
||||
// @ApiModelProperty("月份")
|
||||
// @TableField(value="`MONTHS`", typeHandler = FastjsonArrayHandler.class)
|
||||
// private List months;
|
||||
|
||||
@Override
|
||||
public Serializable pkVal() {
|
||||
@@ -84,26 +92,36 @@ public class Budget extends Model<Budget> {
|
||||
|
||||
public Budget() {}
|
||||
|
||||
public Budget(BudgetCreateRequest params, SaBaseLoginUser user, Map<String, Double> totalMap) {
|
||||
this.update(params, user, totalMap);
|
||||
public Budget(BudgetCreateRequest params, SaBaseLoginUser user) {
|
||||
this.update(params, user);
|
||||
}
|
||||
// public Budget(BudgetCreateRequest params, SaBaseLoginUser user, Map<String, Double> totalMap) {
|
||||
// this.update(params, user, totalMap);
|
||||
// }
|
||||
|
||||
public void update(BudgetCreateRequest params, SaBaseLoginUser user, Map<String, Double> totalMap) {
|
||||
this.name = params.getName();
|
||||
this.amount = params.getItems().stream().mapToDouble(item -> item.getTotalPrice()).sum();
|
||||
|
||||
List<Map.Entry<String, Double>> list = new ArrayList(totalMap.entrySet());
|
||||
Collections.sort(list, (o1, o2) -> (o1.getValue().compareTo(o2.getValue())));
|
||||
|
||||
this.minAmount = list.get(0).getValue();
|
||||
this.maxAmount = list.get(list.size() -1).getValue();
|
||||
this.minMonth = list.get(0).getKey();
|
||||
this.maxMonth = list.get(list.size() -1).getKey();
|
||||
// list.get(0).getKey();
|
||||
// list.get(list.size() -1 ).getKey();
|
||||
// public void update(BudgetCreateRequest params, SaBaseLoginUser user, Map<String, Double> totalMap) {
|
||||
// this.name = params.getName();
|
||||
// this.amount = params.getItems().stream().mapToDouble(item -> item.getTotalPrice()).sum();
|
||||
//
|
||||
// List<Map.Entry<String, Double>> list = new ArrayList(totalMap.entrySet());
|
||||
// Collections.sort(list, (o1, o2) -> (o1.getValue().compareTo(o2.getValue())));
|
||||
//
|
||||
// this.minAmount = list.get(0).getValue();
|
||||
// this.maxAmount = list.get(list.size() -1).getValue();
|
||||
// this.minMonth = list.get(0).getKey();
|
||||
// this.maxMonth = list.get(list.size() -1).getKey();
|
||||
//// list.get(0).getKey();
|
||||
//// list.get(list.size() -1 ).getKey();
|
||||
// this.date = LocalDate.now();
|
||||
// this.year = params.getYear();
|
||||
// this.months = params.getMonths();
|
||||
// }
|
||||
public void update(BudgetCreateRequest param, SaBaseLoginUser user) {
|
||||
this.name = param.getName();
|
||||
this.baseAmount = param.getTotalBaseAmount(); // 基期总价
|
||||
this.diff = param.getTotalDiff(); // 调差金额
|
||||
this.amount = baseAmount + diff; // 当期总价
|
||||
this.date = LocalDate.now();
|
||||
this.year = params.getYear();
|
||||
this.months = params.getMonths();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -49,25 +49,58 @@ public class BudgetItem extends Model<BudgetItem> {
|
||||
@TableField("`NAME`")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("总数")
|
||||
@TableField("QUANTITY")
|
||||
private Integer quantity;
|
||||
// @ApiModelProperty("总数")
|
||||
// @TableField("QUANTITY")
|
||||
// private Integer quantity;
|
||||
|
||||
@ApiModelProperty("数据")
|
||||
@TableField(value="`META`", typeHandler = FastjsonArrayHandler.class)
|
||||
private List<Map<String, Object>> meta;
|
||||
// @ApiModelProperty("数据")
|
||||
// @TableField(value="`META`", typeHandler = FastjsonArrayHandler.class)
|
||||
// private List<Map<String, Object>> meta;
|
||||
|
||||
@ApiModelProperty("单位")
|
||||
@TableField("UNIT")
|
||||
private String unit;
|
||||
|
||||
@ApiModelProperty("单价")
|
||||
@TableField("UNIT_PRICE")
|
||||
private Double unitPrice;
|
||||
// @ApiModelProperty("单价")
|
||||
// @TableField("UNIT_PRICE")
|
||||
// private Double unitPrice;
|
||||
//
|
||||
// @ApiModelProperty("总价")
|
||||
// @TableField("TOTAL_PRICE")
|
||||
// private Double totalPrice;
|
||||
|
||||
@ApiModelProperty("总价")
|
||||
@TableField("TOTAL_PRICE")
|
||||
private Double totalPrice;
|
||||
@ApiModelProperty("单价")
|
||||
@JsonProperty(value = "price")
|
||||
@TableField("PRICE")
|
||||
private Double price;
|
||||
|
||||
@ApiModelProperty("基期单价")
|
||||
@JsonProperty(value = "base_price")
|
||||
@TableField("BASE_PRICE")
|
||||
private Double basePrice;
|
||||
|
||||
@ApiModelProperty("涨跌幅")
|
||||
@JsonProperty(value = "chg")
|
||||
@TableField("CHG")
|
||||
private Double chg;
|
||||
|
||||
@ApiModelProperty("幅度差")
|
||||
@JsonProperty(value = "chg_diff")
|
||||
@TableField("CHG_DIFF")
|
||||
private Double chgDiff;
|
||||
|
||||
@ApiModelProperty("项目金额")
|
||||
@TableField("AMOUNT")
|
||||
private Double amount;
|
||||
|
||||
@ApiModelProperty("材料占比")
|
||||
@TableField("RATIO")
|
||||
private Double ratio;
|
||||
|
||||
@ApiModelProperty("调差金额")
|
||||
@TableField("AMOUNT_DIFF")
|
||||
@JsonProperty(value = "amount_diff")
|
||||
private Double amountDiff;
|
||||
|
||||
@Override
|
||||
public Serializable pkVal() {
|
||||
@@ -76,12 +109,16 @@ public class BudgetItem extends Model<BudgetItem> {
|
||||
|
||||
public BudgetItem() {}
|
||||
|
||||
public BudgetItem(BudgetCreateRequest.BudgetMaterial item, ArrayList<Map<String, Object>> meta) {
|
||||
this.meta = meta;
|
||||
public BudgetItem(Integer budgetId, BudgetCreateRequest.BudgetMaterial item) {
|
||||
this.budgetId = budgetId;
|
||||
this.name = item.getName();
|
||||
this.quantity = item.getQuantity();
|
||||
this.unit = item.getUnit();
|
||||
this.unitPrice = item.getUnitPrice();
|
||||
this.totalPrice = item.getTotalPrice();
|
||||
this.price = item.getPrice();
|
||||
this.basePrice = item.getBasePrice();
|
||||
this.chg = item.getChg();
|
||||
this.chgDiff = item.getChgDiff();
|
||||
this.amount = item.getAmount();
|
||||
this.ratio = item.getRatio();
|
||||
this.amountDiff = item.getAmountDiff();
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package mjkf.xinke.main.model.vo;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
@@ -21,7 +22,15 @@ public class BudgetCreateRequest {
|
||||
private Integer year;
|
||||
|
||||
@ApiModelProperty("月份")
|
||||
private List<Integer> months;
|
||||
private Integer month;
|
||||
|
||||
@ApiModelProperty("基期年份")
|
||||
@JsonProperty(value = "base_year")
|
||||
private Integer baseYear;
|
||||
|
||||
@ApiModelProperty("基期月份")
|
||||
@JsonProperty(value = "base_month")
|
||||
private Integer baseMonth;
|
||||
|
||||
@ApiModelProperty("材料")
|
||||
private List<BudgetMaterial> items;
|
||||
@@ -41,49 +50,81 @@ public class BudgetCreateRequest {
|
||||
private String unit;
|
||||
|
||||
@ApiModelProperty("单价")
|
||||
@JsonProperty(value = "unit_price")
|
||||
private Double unitPrice;
|
||||
@JsonProperty(value = "price")
|
||||
private Double price;
|
||||
|
||||
@ApiModelProperty("数量")
|
||||
private Integer quantity;
|
||||
@ApiModelProperty("基期单价")
|
||||
@JsonProperty(value = "base_price")
|
||||
private Double basePrice;
|
||||
|
||||
@ApiModelProperty("总价")
|
||||
@JsonProperty(value = "total_price")
|
||||
private Double totalPrice;
|
||||
@ApiModelProperty("涨跌幅")
|
||||
@JsonProperty(value = "chg")
|
||||
private Double chg;
|
||||
|
||||
@ApiModelProperty("幅度差")
|
||||
@JsonProperty(value = "chg_diff")
|
||||
private Double chgDiff;
|
||||
|
||||
@ApiModelProperty("项目金额")
|
||||
private Double amount;
|
||||
|
||||
@ApiModelProperty("材料占比")
|
||||
private Double ratio;
|
||||
|
||||
@ApiModelProperty("调差金额")
|
||||
@JsonProperty(value = "amount_diff")
|
||||
private Double amountDiff;
|
||||
|
||||
// @ApiModelProperty("总价")
|
||||
// @JsonProperty(value = "total_price")
|
||||
// private Double totalPrice;
|
||||
}
|
||||
|
||||
public Map<String, Double> getTotalMap(Map<String, Double> priceMap) {
|
||||
var params = this;
|
||||
var totalMap = new HashMap<String, Double>();
|
||||
for (var item: params.getItems()) {
|
||||
for (var month: params.getMonths()) {
|
||||
var key = item.getName() + month.toString();
|
||||
var price = priceMap.getOrDefault(key, 0.0);
|
||||
var total = totalMap.getOrDefault(month.toString(), 0.0);
|
||||
totalMap.put(month.toString(), total + price * item.getQuantity());
|
||||
}
|
||||
}
|
||||
return totalMap;
|
||||
// public Map<String, Double> getTotalMap(Map<String, Double> priceMap) {
|
||||
// var params = this;
|
||||
// var totalMap = new HashMap<String, Double>();
|
||||
// for (var item: params.getItems()) {
|
||||
// for (var month: params.getMonths()) {
|
||||
// var key = item.getName() + month.toString();
|
||||
// var price = priceMap.getOrDefault(key, 0.0);
|
||||
// var total = totalMap.getOrDefault(month.toString(), 0.0);
|
||||
// totalMap.put(month.toString(), total + price * item.getQuantity());
|
||||
// }
|
||||
// }
|
||||
// return totalMap;
|
||||
// }
|
||||
|
||||
// public List<BudgetItem> getBudgetItemList(Map<String, Double> priceMap) {
|
||||
// var params = this;
|
||||
// var budgetItemList = new ArrayList<BudgetItem>();
|
||||
// for (var item: params.getItems()) {
|
||||
// var meta = new ArrayList<Map<String, Object>>();
|
||||
// for (var month: params.getMonths()) {
|
||||
// var key = item.getName() + month.toString();
|
||||
// var price = priceMap.getOrDefault(key, 0.0);
|
||||
// meta.add(Map.of(
|
||||
// "month", month,
|
||||
// "total", price * item.getQuantity(),
|
||||
// "price", price
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
// var budgetItem = new BudgetItem(item, meta);
|
||||
// budgetItemList.add(budgetItem);
|
||||
// }
|
||||
// return budgetItemList;
|
||||
// }
|
||||
|
||||
public Double getTotalBaseAmount() {
|
||||
var result = this.items.stream()
|
||||
.filter(i-> ObjectUtil.isNotEmpty(i.getAmount()) && ObjectUtil.isNotEmpty(i.getRatio()))
|
||||
.mapToDouble(i->i.getAmount() * i.getRatio() / 100)
|
||||
.sum();
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<BudgetItem> getBudgetItemList(Map<String, Double> priceMap) {
|
||||
var params = this;
|
||||
var budgetItemList = new ArrayList<BudgetItem>();
|
||||
for (var item: params.getItems()) {
|
||||
var meta = new ArrayList<Map<String, Object>>();
|
||||
for (var month: params.getMonths()) {
|
||||
var key = item.getName() + month.toString();
|
||||
var price = priceMap.getOrDefault(key, 0.0);
|
||||
meta.add(Map.of(
|
||||
"month", month,
|
||||
"total", price * item.getQuantity(),
|
||||
"price", price
|
||||
)
|
||||
);
|
||||
}
|
||||
var budgetItem = new BudgetItem(item, meta);
|
||||
budgetItemList.add(budgetItem);
|
||||
}
|
||||
return budgetItemList;
|
||||
public Double getTotalDiff() {
|
||||
var result = this.items.stream().filter(i-> ObjectUtil.isNotEmpty(i.getAmountDiff())).mapToDouble(i->i.getAmountDiff()).sum();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -35,14 +35,14 @@ public class BudgetDetail{
|
||||
public BudgetDetail() {}
|
||||
|
||||
public BudgetDetail(Budget data, List<BudgetItem> list) {
|
||||
this.id = data.getId();
|
||||
this.name = data.getName();
|
||||
this.amount = data.getAmount();
|
||||
this.minAmount = data.getMinAmount();
|
||||
this.maxAmount = data.getMaxAmount();
|
||||
this.date = data.getDate();
|
||||
this.year = data.getYear();
|
||||
this.months = data.getMonths();
|
||||
this.list = list;
|
||||
// this.id = data.getId();
|
||||
// this.name = data.getName();
|
||||
// this.amount = data.getAmount();
|
||||
// this.minAmount = data.getMinAmount();
|
||||
// this.maxAmount = data.getMaxAmount();
|
||||
// this.date = data.getDate();
|
||||
// this.year = data.getYear();
|
||||
// this.months = data.getMonths();
|
||||
// this.list = list;
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import mjkf.xinke.main.model.vo.BudgetCreateRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -40,7 +42,7 @@ public class PricePublishService extends ServiceImpl<BaseMapper<PricePublish>, P
|
||||
public LambdaQueryWrapper getQuery(BudgetCreateRequest params) {
|
||||
var query = new LambdaQueryWrapper<PricePublish>();
|
||||
query.eq(PricePublish::getYear, params.getYear());
|
||||
query.in(PricePublish::getMonth, params.getMonths());
|
||||
query.in(PricePublish::getMonth, List.of(params.getMonth(), params.getBaseMonth()));
|
||||
query.in(PricePublish::getName, params.getItems().stream().map(item -> item.getName()).collect(Collectors.toList()));
|
||||
// query.in(PricePublish::getMaterialId, params.getItems().stream().map(item -> item.getId()).collect(Collectors.toList()));
|
||||
return query;
|
||||
@@ -55,5 +57,14 @@ public class PricePublishService extends ServiceImpl<BaseMapper<PricePublish>, P
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Date getLatestDate() {
|
||||
var query = new LambdaQueryWrapper<PricePublish>();
|
||||
query.orderByDesc(PricePublish::getYear);
|
||||
query.orderByDesc(PricePublish::getMonth);
|
||||
var data = this.getOne(query, false);
|
||||
var result = new Date(data.getYear(), data.getMonth(), 1);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
23
src/main/resources/_sql/init/mysql/tools.sql
Normal file
23
src/main/resources/_sql/init/mysql/tools.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
-- 删除6月份至今数据
|
||||
select * from PRICE_PUBLISH where year = 2024 and month >= 6;
|
||||
select * from PRICE_RESULT where year = 2024 and month >= 6;
|
||||
select * from DATA_FUJIAN where year = 2024 and month >= 6;
|
||||
select * from DATA_ADJACENT where year = 2024 and month >= 6;
|
||||
select * from DATA_NETWORK where date >= '2024-6-1';
|
||||
select * from SANMING_STEEL where date >= '2024-6-1';
|
||||
select * from FUZHOU_HIGHWAY_BUREAU where date >= '2024-6-1';
|
||||
select * from FUZHOU_TRANSPORTATION_BUREAU where date >= '2024-6-1';
|
||||
select * from FUJIAN_SURVEY where date >= '2024-6-1';
|
||||
# Guangzhou
|
||||
# Meizhou
|
||||
# Chaozhou
|
||||
# Nanchang
|
||||
# Fuzhou
|
||||
# Ganzhou
|
||||
# Shangrao
|
||||
# Yingtan
|
||||
# Hangzhou
|
||||
# Lishui
|
||||
# Quzhou
|
||||
# Wenzhou
|
||||
# Kunming
|
@@ -49,20 +49,6 @@ create table DATA_ADJACENT (
|
||||
|
||||
|
||||
|
||||
Guangzhou
|
||||
Meizhou
|
||||
Chaozhou
|
||||
Nanchang
|
||||
Fuzhou
|
||||
Ganzhou
|
||||
Shangrao
|
||||
Yingtan
|
||||
Hangzhou
|
||||
Lishui
|
||||
Quzhou
|
||||
Wenzhou
|
||||
Kunming
|
||||
|
||||
|
||||
|
||||
|
||||
|
19
src/main/resources/_sql/init/mysql/v0.4.sql
Normal file
19
src/main/resources/_sql/init/mysql/v0.4.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
# ALTER TABLE BUDGET ADD AMOUNT decimal(16,4) default 0 comment '当期总价';
|
||||
ALTER TABLE BUDGET ADD BASE_AMOUNT decimal(16,4) default 0 comment '基期总价';
|
||||
ALTER TABLE BUDGET ADD DIFF decimal(16,4) default 0 comment '调差金额';
|
||||
|
||||
|
||||
ALTER TABLE BUDGET_ITEM ADD PRICE decimal(16,4) default 0 comment '单价';
|
||||
ALTER TABLE BUDGET_ITEM ADD BASE_PRICE decimal(16,4) default 0 comment '基期单价';
|
||||
ALTER TABLE BUDGET_ITEM ADD CHG decimal(16,4) default 0 comment '涨跌幅';
|
||||
ALTER TABLE BUDGET_ITEM ADD CHG_DIFF decimal(16,4) default 0 comment '幅度差';
|
||||
ALTER TABLE BUDGET_ITEM ADD AMOUNT decimal(16,4) default 0 comment '项目金额';
|
||||
ALTER TABLE BUDGET_ITEM ADD RATIO decimal(16,4) default 0 comment '材料占比';
|
||||
ALTER TABLE BUDGET_ITEM ADD AMOUNT_DIFF decimal(16,4) default 0 comment '调差金额';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user