From 1a2dee14e48e07501c82e034c75a0381962dabf2 Mon Sep 17 00:00:00 2001 From: wangqiong <1322446236@qq.com> Date: Fri, 2 Aug 2024 08:59:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=88=90=E6=9C=AC=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppSceneCostCountController.java | 21 +- .../cost/manage/entity/AppSceneCostCount.java | 95 +++-- .../entity/AppSceneCostResultValue.java | 2 +- .../entity/AppSceneCostStandardDetail.java | 34 +- .../manage/enums/CostCountStatusEnum.java | 73 ++++ .../manage/plugin/StandardCostService.java | 355 +++++++++--------- .../cost/manage/vo/AppSceneCostCountVO.java | 14 + 7 files changed, 364 insertions(+), 230 deletions(-) create mode 100644 qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/enums/CostCountStatusEnum.java create mode 100644 qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/vo/AppSceneCostCountVO.java diff --git a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/controller/AppSceneCostCountController.java b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/controller/AppSceneCostCountController.java index c30a3e5..a0fe483 100644 --- a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/controller/AppSceneCostCountController.java +++ b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/controller/AppSceneCostCountController.java @@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostCount; +import com.zzsmart.qomo.kn.cost.manage.enums.CostCountStatusEnum; import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostCountService; +import com.zzsmart.qomo.kn.cost.manage.vo.AppSceneCostCountVO; import com.zzsmart.qomo.kn.cost.manage.vo.MissingComponentVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -14,12 +16,14 @@ import org.jeecg.common.api.vo.Result; import org.jeecg.common.aspect.annotation.AutoLog; import org.jeecg.common.system.base.controller.JeecgController; import org.jeecg.common.system.query.QueryGenerator; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -49,11 +53,22 @@ public class AppSceneCostCountController extends JeecgController> queryPageList(AppSceneCostCount appSceneCostCount, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) { + public Result> queryPageList(AppSceneCostCount appSceneCostCount, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) { QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(appSceneCostCount, req.getParameterMap()); Page page = new Page(pageNo, pageSize); IPage pageList = appSceneCostCountService.page(page, queryWrapper); - return Result.OK(pageList); + IPage pageList1 = new Page<>(); + BeanUtils.copyProperties(pageList, pageList1); + Listlist=new ArrayList<>(); + for(int i=0;i addCostCountTask(@RequestBody AppSceneCostCount appSceneCostCount) { appSceneCostCountService.addCostCountTask(appSceneCostCount); diff --git a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/AppSceneCostCount.java b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/AppSceneCostCount.java index 2a00bc3..4437de9 100644 --- a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/AppSceneCostCount.java +++ b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/AppSceneCostCount.java @@ -1,85 +1,106 @@ package com.zzsmart.qomo.kn.cost.manage.entity; -import java.io.Serializable; -import java.io.UnsupportedEncodingException; -import java.util.Date; -import java.math.BigDecimal; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.annotation.TableLogic; -import lombok.Builder; -import lombok.Data; import com.fasterxml.jackson.annotation.JsonFormat; -import org.springframework.format.annotation.DateTimeFormat; -import org.jeecgframework.poi.excel.annotation.Excel; -import org.jeecg.common.aspect.annotation.Dict; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import lombok.EqualsAndHashCode; +import lombok.*; import lombok.experimental.Accessors; +import org.jeecgframework.poi.excel.annotation.Excel; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.Date; /** * @Description: app_scene_cost_count * @Author: jeecg-boot - * @Date: 2024-07-29 + * @Date: 2024-07-29 * @Version: V1.0 */ @Data @TableName("app_scene_cost_count") @Builder +@NoArgsConstructor +@AllArgsConstructor @Accessors(chain = true) @EqualsAndHashCode(callSuper = false) -@ApiModel(value="app_scene_cost_count对象", description="app_scene_cost_count") +@ApiModel(value = "app_scene_cost_count对象", description = "app_scene_cost_count") public class AppSceneCostCount implements Serializable { private static final long serialVersionUID = 1L; - /**主键*/ - @TableId(type = IdType.ASSIGN_ID) + /** + * 主键 + */ + @TableId(type = IdType.ASSIGN_ID) @ApiModelProperty(value = "主键") private Integer id; - /**物料编号*/ - @Excel(name = "物料编号", width = 15) + /** + * 物料编号 + */ + @Excel(name = "物料编号", width = 15) @ApiModelProperty(value = "物料编号") private String materialNo; - /**图号*/ - @Excel(name = "图号", width = 15) + /** + * 图号 + */ + @Excel(name = "图号", width = 15) @ApiModelProperty(value = "图号") private String drawingNo; - /**stage*/ - @Excel(name = "stage", width = 15) + /** + * stage + */ + @Excel(name = "阶段", width = 15) @ApiModelProperty(value = "stage") private String stage; - /**标准成本计算流程id*/ - @Excel(name = "标准成本计算流程id", width = 15) + /** + * 标准成本计算流程id + */ + @Excel(name = "标准成本计算流程id", width = 15) @ApiModelProperty(value = "标准成本计算流程id") private Integer flowDefinitionId; - /**year*/ - @Excel(name = "year", width = 15) + /** + * year + */ + @Excel(name = "年份", width = 15) @ApiModelProperty(value = "year") private String year; - /**状态*/ - @Excel(name = "状态", width = 15) + /** + * 状态 + */ + @Excel(name = "状态", width = 15) @ApiModelProperty(value = "状态") private Integer status; - /**模型版本*/ - @Excel(name = "标准成本版本", width = 15) + /** + * 模型版本 + */ + @Excel(name = "标准成本版本", width = 15) @ApiModelProperty(value = "标准成本版本") private String costVersion; - /**创建人*/ + /** + * 创建人 + */ @ApiModelProperty(value = "创建人") private Integer createBy; - /**创建时间*/ - @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") - @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + /** + * 创建时间 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "创建时间") private Date createTime; - /**更新人*/ + /** + * 更新人 + */ @ApiModelProperty(value = "更新人") private Integer updateBy; - /**更新时间*/ - @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") - @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + /** + * 更新时间 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "更新时间") private Date updateTime; } diff --git a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/AppSceneCostResultValue.java b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/AppSceneCostResultValue.java index 8d14ca3..3cd6588 100644 --- a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/AppSceneCostResultValue.java +++ b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/AppSceneCostResultValue.java @@ -35,7 +35,7 @@ public class AppSceneCostResultValue implements Serializable { /** * 主键 */ - @TableId(type = IdType.ASSIGN_ID) + @TableId(type = IdType.AUTO) @ApiModelProperty(value = "主键") private Integer id; /** diff --git a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/AppSceneCostStandardDetail.java b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/AppSceneCostStandardDetail.java index c6ed1d0..b4a1432 100644 --- a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/AppSceneCostStandardDetail.java +++ b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/AppSceneCostStandardDetail.java @@ -77,8 +77,8 @@ public class AppSceneCostStandardDetail implements Serializable { @ApiModelProperty(value = "本阶材料费") private BigDecimal materialCost; /**本阶人工费*/ - @Excel(name = "本阶人工费", width = 15) - @ApiModelProperty(value = "本阶人工费") + @Excel(name = "本阶人工陈本", width = 15) + @ApiModelProperty(value = "本阶人工成本") private BigDecimal laborCost; /**本阶辅料费*/ @Excel(name = "本阶辅料费", width = 15) @@ -93,32 +93,32 @@ public class AppSceneCostStandardDetail implements Serializable { @ApiModelProperty(value = "本阶水电费(燃动费)") private BigDecimal driveCost; /**本阶其他制造费*/ - @Excel(name = "本阶其他制造费", width = 15) - @ApiModelProperty(value = "本阶其他制造费") + @Excel(name = "本阶其他费用", width = 15) + @ApiModelProperty(value = "本阶其他费用") private BigDecimal otherCost; /**本阶物流费*/ @Excel(name = "本阶物流费", width = 15) @ApiModelProperty(value = "本阶物流费") private BigDecimal logisticsCost; - /**累计人工费*/ - @Excel(name = "累计人工费", width = 15) - @ApiModelProperty(value = "累计人工费") + /**累计物料成本*/ + @Excel(name = "累计物料成本", width = 15) + @ApiModelProperty(value = "累计物料成本") private BigDecimal totalMaterialCost; - /**累计机器消耗费*/ - @Excel(name = "累计机器消耗费", width = 15) - @ApiModelProperty(value = "累计机器消耗费") + /**累计人工成本*/ + @Excel(name = "累计人工成本", width = 15) + @ApiModelProperty(value = "累计人工成本") private BigDecimal totalLaborCost; + /**累计辅料费*/ + @Excel(name = "累计辅料费", width = 15) + @ApiModelProperty(value = "累计辅料费") + private BigDecimal totalSupplyMaterialCost; /**累计机器折旧费*/ @Excel(name = "累计机器折旧费", width = 15) @ApiModelProperty(value = "累计机器折旧费") - private BigDecimal totalSupplyMaterialCost; - /**累计水电费*/ - @Excel(name = "累计水电费", width = 15) - @ApiModelProperty(value = "累计水电费") private BigDecimal totalEquipmentCost; - /**累计其它费用*/ - @Excel(name = "累计其它费用", width = 15) - @ApiModelProperty(value = "累计其它费用") + /**累计水电费(燃动费)*/ + @Excel(name = "累计水电费(燃动费)", width = 15) + @ApiModelProperty(value = "累计水电费(燃动费)") private BigDecimal totalDriveCost; /**累计其他费用*/ @Excel(name = "累计其他费用", width = 15) diff --git a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/enums/CostCountStatusEnum.java b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/enums/CostCountStatusEnum.java new file mode 100644 index 0000000..64ceedd --- /dev/null +++ b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/enums/CostCountStatusEnum.java @@ -0,0 +1,73 @@ +package com.zzsmart.qomo.kn.cost.manage.enums; + +/** + * @Classname StandardStageEnum + * @Description 阶段枚举 + * @Version 1.0.0 + * @Date 2024/6/18 9:51 + * @Created wangqiong + */ +public enum CostCountStatusEnum { + + NotExecute("NotExecute", "未执行", 0), Executing("Executing", "计算中", 1), ExecutedFinished("ExecutedFinished", "计算完成", 2), ExecutedError("ExecutedError", "出错中止", 3); + private final String code; + private final String name; + private final Integer value; + + CostCountStatusEnum(String code, String name, Integer value) { + this.code = code; + this.name = name; + this.value = value; + } + + public String getCode() { + return code; + } + + public String getName() { + return name; + } + + public Integer getValue() { + return value; + } + + /** + * 根据code获取text + * + * @param codeNo + * @return + */ + public static String getTextByCode(String codeNo) { + for (CostCountStatusEnum value : CostCountStatusEnum.values()) { + if (value.getCode().equals(codeNo)) { + return value.name(); + } + } + return codeNo.toString(); + } + + public static String getTextByValue(Integer indexNo) { + for (CostCountStatusEnum value : CostCountStatusEnum.values()) { + if (value.getValue().equals(indexNo)) { + return value.name(); + } + } + return indexNo.toString(); + } + + /** + * 根据text获取code + * + * @param name + * @return + */ + public static String getCodeByName(String name) { + for (CostCountStatusEnum value : CostCountStatusEnum.values()) { + if (value.name().equals(name)) { + return value.name(); + } + } + return name; + } +} diff --git a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/plugin/StandardCostService.java b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/plugin/StandardCostService.java index 47e352a..cbbfc8a 100644 --- a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/plugin/StandardCostService.java +++ b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/plugin/StandardCostService.java @@ -14,16 +14,19 @@ import com.zzsmart.qomo.plugin.task.api.TaskExecutionContext; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.PostConstruct; import java.math.BigDecimal; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @Service @Slf4j +@Transactional public class StandardCostService { /** * 物料BOM信息 @@ -469,145 +472,150 @@ public class StandardCostService { * 5.标准成本计算任务 */ public static void standardCostTask(TaskExecutionContext parameters) { - //获取任务流程相关信息 - FlowTaskInfoVO flowTaskInfoVO = analysisFlowTaskInfo(parameters); - //获取最上层的物料号 - String topMaterialCode = flowTaskInfoVO.getTopMaterialCode(); - //获取任务类型 - String taskType = parameters.getTaskType(); - //获取任务代码 - String taskCode = flowTaskInfoVO.getTaskCode(); - //获取流程id - String flowInstanceId = flowTaskInfoVO.getFlowInstanceId(); - String costType = FeeTypeEnum.StandardCost.getCode(); - //1.查询出根物料编号对应的下所有的BOM信息结果值 - List list = standardCostService.iAppSceneCostResultValueService.getAllResultValueByTopMaterialNo(topMaterialCode, flowInstanceId); - //2.计算出所有的单个物料的本阶的标准成本(标准成本=物料成本+人工成本+制造费用) - //按照物料编号进行分组 - Map> materialNoMap = list.stream().collect(Collectors.groupingBy(AppSceneCostResultValue::getMarterialNo)); - //遍历根物料下所有的物料进行该物料本阶成本和费用类别的统计 - for (String key : materialNoMap.keySet()) { - List appSceneCostResultValues = materialNoMap.get(key); - //按照费用类别进行分组 - Map> costTypeMap = appSceneCostResultValues.stream().filter(s -> s.getCostType() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getCostType)); - //【本阶标准成本】 - BigDecimal currentCost = new BigDecimal("0.0"); - //1.本阶物料成本 - BigDecimal materialCost = new BigDecimal("0.0"); - //2.本阶人工成本 - BigDecimal laborCost = new BigDecimal("0.0"); - //3.本阶制造费(设备费) - BigDecimal equipmentCost = new BigDecimal("0.0"); - //4.本阶制造费(辅料费用) - BigDecimal supplyMaterialCost = new BigDecimal("0.0"); - //5.本阶制造费(水电费、燃动费) - BigDecimal driveCost = new BigDecimal("0.0"); - //6.本阶制造费(其他制造费用) - BigDecimal otherCost = new BigDecimal("0.0"); - //7.本阶制造费(物流费) - BigDecimal logisticsCost = new BigDecimal("0.0"); - //物料单价 - BigDecimal materialUnitPrice = new BigDecimal("0.0"); - //人员工时、小时费率 - BigDecimal laborHour = new BigDecimal("0.0"); - BigDecimal laborHourRate = new BigDecimal("0.0"); - //设备工时、小时费率 - BigDecimal equipmentHour = new BigDecimal("0.0"); - BigDecimal equipmentHourRate = new BigDecimal("0.0"); - //辅料工时、小时费率 - BigDecimal supplyMaterialHour = new BigDecimal("0.0"); - BigDecimal supplyMaterialHourRate = new BigDecimal("0.0"); - //燃动工时、小时费率 - BigDecimal driveHour = new BigDecimal("0.0"); - BigDecimal driveHourRate = new BigDecimal("0.0"); - //其他工时、小时费率 - BigDecimal otherHour = new BigDecimal("0.0"); - BigDecimal otherHourRate = new BigDecimal("0.0"); - AppSceneCostResultValue currentMaterialCost = null; - //遍历所有费用类别计算本阶标准成本 - for (int j = 0; j < appSceneCostResultValues.size(); j++) { - if (j == 0) { - currentMaterialCost = appSceneCostResultValues.get(0); - } - AppSceneCostResultValue appSceneCostResultValue = appSceneCostResultValues.get(j); - String countValue = appSceneCostResultValue.getCountValue(); - if (countValue != null) { - currentCost = currentCost.add(new BigDecimal(countValue)); - } - } - //计算本阶各个费用类别费用以及记录本阶物料的工时和小时费率 - for (String feeType : costTypeMap.keySet()) { - List appSceneCostResultValues1 = costTypeMap.get(feeType); - for (int m = 0; m < appSceneCostResultValues1.size(); m++) { - if (FeeTypeEnum.MaterialCost.getCode().equals(feeType)) { - //物料成本 - materialCost = materialCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue())); - //物料单价 - materialUnitPrice = appSceneCostResultValues1.get(m).getPriceOrRate(); - } else if (FeeTypeEnum.LaborCost.getCode().equals(feeType)) { - //人工成本 - laborCost = laborCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue())); - //人工工时、小时费率 - laborHour = laborHour.add(appSceneCostResultValues1.get(m).getHour()); - laborHourRate = laborHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate()); - } else if (FeeTypeEnum.EquipmentFee.getCode().equals(feeType)) { - //设备费用 - equipmentCost = equipmentCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue())); - //设备工时、小时费率 - equipmentHour = equipmentHour.add(appSceneCostResultValues1.get(m).getHour()); - equipmentHourRate = equipmentHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate()); - } else if (FeeTypeEnum.SupplyMaterialFee.getCode().equals(feeType)) { - //辅料费用 - supplyMaterialCost = supplyMaterialCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue())); - //辅料工时、小时费率 - supplyMaterialHour = supplyMaterialHour.add(appSceneCostResultValues1.get(m).getHour()); - supplyMaterialHourRate = supplyMaterialHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate()); - } else if (FeeTypeEnum.DriverFee.getCode().equals(feeType)) { - //燃动费用 - driveCost = driveCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue())); - //燃动工时、小时费率 - driveHour = driveHour.add(appSceneCostResultValues1.get(m).getHour()); - driveHourRate = driveHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate()); - } else if (FeeTypeEnum.LogisticsFee.getCode().equals(feeType)) { - //物流费用 - logisticsCost = logisticsCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue())); - } else if (FeeTypeEnum.OtherFee.getCode().equals(feeType)) { - //其他费用 - otherCost = otherCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue())); - //其他工时、小时费率 - otherHour = otherHour.add(appSceneCostResultValues1.get(m).getHour()); - otherHourRate = otherHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate()); + try { + //获取任务流程相关信息 + FlowTaskInfoVO flowTaskInfoVO = analysisFlowTaskInfo(parameters); + //获取最上层的物料号 + String topMaterialCode = flowTaskInfoVO.getTopMaterialCode(); + //获取任务类型 + String taskType = parameters.getTaskType(); + //获取任务代码 + String taskCode = flowTaskInfoVO.getTaskCode(); + //获取流程id + String flowInstanceId = flowTaskInfoVO.getFlowInstanceId(); + String costType = FeeTypeEnum.StandardCost.getCode(); + //1.查询出根物料编号对应的下所有的BOM信息结果值 + List list = standardCostService.iAppSceneCostResultValueService.getAllResultValueByTopMaterialNo(topMaterialCode, flowInstanceId); + //2.计算出所有的单个物料的本阶的标准成本(标准成本=物料成本+人工成本+制造费用) + //按照物料编号进行分组 + Map> materialNoMap = list.stream().collect(Collectors.groupingBy(AppSceneCostResultValue::getMarterialNo)); + //遍历根物料下所有的物料进行该物料本阶成本和费用类别的统计 + for (String key : materialNoMap.keySet()) { + List appSceneCostResultValues = materialNoMap.get(key); + //按照费用类别进行分组 + Map> costTypeMap = appSceneCostResultValues.stream().filter(s -> s.getCostType() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getCostType)); + //【本阶标准成本】 + BigDecimal currentCost = new BigDecimal("0.0"); + //1.本阶物料成本 + BigDecimal materialCost = new BigDecimal("0.0"); + //2.本阶人工成本 + BigDecimal laborCost = new BigDecimal("0.0"); + //3.本阶制造费(设备费) + BigDecimal equipmentCost = new BigDecimal("0.0"); + //4.本阶制造费(辅料费用) + BigDecimal supplyMaterialCost = new BigDecimal("0.0"); + //5.本阶制造费(水电费、燃动费) + BigDecimal driveCost = new BigDecimal("0.0"); + //6.本阶制造费(其他制造费用) + BigDecimal otherCost = new BigDecimal("0.0"); + //7.本阶制造费(物流费) + BigDecimal logisticsCost = new BigDecimal("0.0"); + //物料单价 + BigDecimal materialUnitPrice = new BigDecimal("0.0"); + //人员工时、小时费率 + BigDecimal laborHour = new BigDecimal("0.0"); + BigDecimal laborHourRate = new BigDecimal("0.0"); + //设备工时、小时费率 + BigDecimal equipmentHour = new BigDecimal("0.0"); + BigDecimal equipmentHourRate = new BigDecimal("0.0"); + //辅料工时、小时费率 + BigDecimal supplyMaterialHour = new BigDecimal("0.0"); + BigDecimal supplyMaterialHourRate = new BigDecimal("0.0"); + //燃动工时、小时费率 + BigDecimal driveHour = new BigDecimal("0.0"); + BigDecimal driveHourRate = new BigDecimal("0.0"); + //其他工时、小时费率 + BigDecimal otherHour = new BigDecimal("0.0"); + BigDecimal otherHourRate = new BigDecimal("0.0"); + AppSceneCostResultValue currentMaterialCost = null; + //遍历所有费用类别计算本阶标准成本 + for (int j = 0; j < appSceneCostResultValues.size(); j++) { + if (j == 0) { + currentMaterialCost = appSceneCostResultValues.get(0); + } + AppSceneCostResultValue appSceneCostResultValue = appSceneCostResultValues.get(j); + String countValue = appSceneCostResultValue.getCountValue(); + if (countValue != null) { + currentCost = currentCost.add(new BigDecimal(countValue)); } } + //计算本阶各个费用类别费用以及记录本阶物料的工时和小时费率 + for (String feeType : costTypeMap.keySet()) { + List appSceneCostResultValues1 = costTypeMap.get(feeType); + for (int m = 0; m < appSceneCostResultValues1.size(); m++) { + if (FeeTypeEnum.MaterialCost.getCode().equals(feeType)) { + //物料成本 + materialCost = materialCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue())); + //物料单价 + materialUnitPrice = appSceneCostResultValues1.get(m).getPriceOrRate(); + } else if (FeeTypeEnum.LaborCost.getCode().equals(feeType)) { + //人工成本 + laborCost = laborCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue())); + //人工工时、小时费率 + laborHour = laborHour.add(appSceneCostResultValues1.get(m).getHour()); + laborHourRate = laborHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate()); + } else if (FeeTypeEnum.EquipmentFee.getCode().equals(feeType)) { + //设备费用 + equipmentCost = equipmentCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue())); + //设备工时、小时费率 + equipmentHour = equipmentHour.add(appSceneCostResultValues1.get(m).getHour()); + equipmentHourRate = equipmentHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate()); + } else if (FeeTypeEnum.SupplyMaterialFee.getCode().equals(feeType)) { + //辅料费用 + supplyMaterialCost = supplyMaterialCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue())); + //辅料工时、小时费率 + supplyMaterialHour = supplyMaterialHour.add(appSceneCostResultValues1.get(m).getHour()); + supplyMaterialHourRate = supplyMaterialHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate()); + } else if (FeeTypeEnum.DriverFee.getCode().equals(feeType)) { + //燃动费用 + driveCost = driveCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue())); + //燃动工时、小时费率 + driveHour = driveHour.add(appSceneCostResultValues1.get(m).getHour()); + driveHourRate = driveHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate()); + } else if (FeeTypeEnum.LogisticsFee.getCode().equals(feeType)) { + //物流费用 + logisticsCost = logisticsCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue())); + } else if (FeeTypeEnum.OtherFee.getCode().equals(feeType)) { + //其他费用 + otherCost = otherCost.add(new BigDecimal(appSceneCostResultValues1.get(m).getCountValue())); + //其他工时、小时费率 + otherHour = otherHour.add(appSceneCostResultValues1.get(m).getHour()); + otherHourRate = otherHourRate.add(appSceneCostResultValues1.get(m).getPriceOrRate()); + } + } + } + //本阶不同费用类别成本统计 + JSONObject currentLevelCostTypeDetail = new JSONObject(); + currentLevelCostTypeDetail.put(FeeTypeEnum.MaterialCost.getCode(), materialCost); + currentLevelCostTypeDetail.put(FeeTypeEnum.LaborCost.getCode(), laborCost); + currentLevelCostTypeDetail.put(FeeTypeEnum.EquipmentFee.getCode(), equipmentCost); + currentLevelCostTypeDetail.put(FeeTypeEnum.SupplyMaterialFee.getCode(), supplyMaterialCost); + currentLevelCostTypeDetail.put(FeeTypeEnum.DriverFee.getCode(), driveCost); + currentLevelCostTypeDetail.put(FeeTypeEnum.LogisticsFee.getCode(), logisticsCost); + currentLevelCostTypeDetail.put(FeeTypeEnum.OtherFee.getCode(), otherCost); + //统计本阶不同费用类别工时、小时费率 + currentLevelCostTypeDetail.put(HourOrRateTypeEnum.MaterialUnitPrice.getCode(), materialUnitPrice); + currentLevelCostTypeDetail.put(HourOrRateTypeEnum.LaborHour.getCode(), laborHour); + currentLevelCostTypeDetail.put(HourOrRateTypeEnum.LaborHourRate.getCode(), laborHourRate); + currentLevelCostTypeDetail.put(HourOrRateTypeEnum.EquipmentHour.getCode(), equipmentHour); + currentLevelCostTypeDetail.put(HourOrRateTypeEnum.EquipmentHourRate.getCode(), equipmentHourRate); + currentLevelCostTypeDetail.put(HourOrRateTypeEnum.SupplyMaterialHour.getCode(), supplyMaterialHour); + currentLevelCostTypeDetail.put(HourOrRateTypeEnum.SupplyMaterialHourRate.getCode(), supplyMaterialHourRate); + currentLevelCostTypeDetail.put(HourOrRateTypeEnum.DriverHour.getCode(), driveHour); + currentLevelCostTypeDetail.put(HourOrRateTypeEnum.DriverHourRate.getCode(), driveHourRate); + currentLevelCostTypeDetail.put(HourOrRateTypeEnum.OtherHour.getCode(), otherHour); + currentLevelCostTypeDetail.put(HourOrRateTypeEnum.OtherHourRate.getCode(), otherHourRate); + AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(key).parentMarterialNo(currentMaterialCost.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(currentCost.toString()).costDetail(JSON.toJSONString(currentLevelCostTypeDetail)).costType(costType).build(); + standardCostService.iAppSceneCostResultValueService.save(resultValue); } - //本阶不同费用类别成本统计 - JSONObject currentLevelCostTypeDetail = new JSONObject(); - currentLevelCostTypeDetail.put(FeeTypeEnum.MaterialCost.getCode(), materialCost); - currentLevelCostTypeDetail.put(FeeTypeEnum.LaborCost.getCode(), laborCost); - currentLevelCostTypeDetail.put(FeeTypeEnum.EquipmentFee.getCode(), equipmentCost); - currentLevelCostTypeDetail.put(FeeTypeEnum.SupplyMaterialFee.getCode(), supplyMaterialCost); - currentLevelCostTypeDetail.put(FeeTypeEnum.DriverFee.getCode(), driveCost); - currentLevelCostTypeDetail.put(FeeTypeEnum.LogisticsFee.getCode(), logisticsCost); - currentLevelCostTypeDetail.put(FeeTypeEnum.OtherFee.getCode(), otherCost); - //统计本阶不同费用类别工时、小时费率 - currentLevelCostTypeDetail.put(HourOrRateTypeEnum.MaterialUnitPrice.getCode(), materialUnitPrice); - currentLevelCostTypeDetail.put(HourOrRateTypeEnum.LaborHour.getCode(), laborHour); - currentLevelCostTypeDetail.put(HourOrRateTypeEnum.LaborHourRate.getCode(), laborHourRate); - currentLevelCostTypeDetail.put(HourOrRateTypeEnum.EquipmentHour.getCode(), equipmentHour); - currentLevelCostTypeDetail.put(HourOrRateTypeEnum.EquipmentHourRate.getCode(), equipmentHourRate); - currentLevelCostTypeDetail.put(HourOrRateTypeEnum.SupplyMaterialHour.getCode(), supplyMaterialHour); - currentLevelCostTypeDetail.put(HourOrRateTypeEnum.SupplyMaterialHourRate.getCode(), supplyMaterialHourRate); - currentLevelCostTypeDetail.put(HourOrRateTypeEnum.DriverHour.getCode(), driveHour); - currentLevelCostTypeDetail.put(HourOrRateTypeEnum.DriverHourRate.getCode(), driveHourRate); - currentLevelCostTypeDetail.put(HourOrRateTypeEnum.OtherHour.getCode(), otherHour); - currentLevelCostTypeDetail.put(HourOrRateTypeEnum.OtherHourRate.getCode(), otherHourRate); - AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(key).parentMarterialNo(currentMaterialCost.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(currentCost.toString()).costDetail(JSON.toJSONString(currentLevelCostTypeDetail)).costType(costType).build(); - standardCostService.iAppSceneCostResultValueService.save(resultValue); + //3.计算出所有的单个物料的累计标准成本 + List standardCostList = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, taskType, flowInstanceId); + //【累计成本】的计算 + totalCountCost(standardCostList, topMaterialCode, taskType, taskCode, flowInstanceId); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("计算成本失败"); } - //3.计算出所有的单个物料的累计标准成本 - List standardCostList = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, taskType, flowInstanceId); - //【累计成本】的计算 - totalCountCost(standardCostList, topMaterialCode, taskType, taskCode, flowInstanceId); } /** @@ -620,48 +628,51 @@ public class StandardCostService { * @param flowInstanceId */ private static void totalCountCost(List standardCostList, String topMaterialCode, String taskType, String taskCode, String flowInstanceId) { - - List costStandardDetails = new ArrayList<>(); - //父类对应的子节点(除了最上层节点) - Map> parentMaterialNoMap = standardCostList.stream().filter(appSceneCostResultValue -> appSceneCostResultValue.getParentMarterialNo() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getParentMarterialNo)); - for (int i = 0; i < standardCostList.size(); i++) { - //当前节点及其对应的本阶成本 - AppSceneCostResultValue oldAppSceneCostResultValue = standardCostList.get(i); - BigDecimal totalCost = new BigDecimal(oldAppSceneCostResultValue.getCountValue()); - //循环计算出当前节点的累计成本 - String costDetail = oldAppSceneCostResultValue.getCostDetail(); - //查询当前节点各个类型的成本 - BigDecimal totalMaterialCost = new BigDecimal(0); - BigDecimal totalLabourCost = new BigDecimal(0); - BigDecimal totalEquipmentCost = new BigDecimal(0); - BigDecimal totalSupplyMaterialCost = new BigDecimal(0); - BigDecimal totalDriveCost = new BigDecimal(0); - BigDecimal totalLogisticsCost = new BigDecimal(0); - BigDecimal totalOtherCost = new BigDecimal(0); - JSONObject costDetailJson = JSON.parseObject(costDetail); - TotalResultValue hourOrRateResultValue = loopCount(oldAppSceneCostResultValue, parentMaterialNoMap, totalMaterialCost, totalLabourCost, totalEquipmentCost, totalSupplyMaterialCost, totalDriveCost, totalLogisticsCost, totalOtherCost, totalCost); - costDetailJson.put(TotalCostEnum.TotalMaterialCost.getCode(), hourOrRateResultValue.getTotalMaterialCost()); - costDetailJson.put(TotalCostEnum.TotalLaborCost.getCode(), hourOrRateResultValue.getTotalLabourCost()); - costDetailJson.put(TotalCostEnum.TotalEquipmentFee.getCode(), hourOrRateResultValue.getTotalEquipmentCost()); - costDetailJson.put(TotalCostEnum.TotalSupplyMaterialFee.getCode(), hourOrRateResultValue.getTotalSupplyMaterialCost()); - costDetailJson.put(TotalCostEnum.TotalDriverFee.getCode(), hourOrRateResultValue.getTotalDriveCost()); - costDetailJson.put(TotalCostEnum.TotalLogisticsFee.getCode(), hourOrRateResultValue.getTotalLogisticsCost()); - costDetailJson.put(TotalCostEnum.TotalOtherFee.getCode(), hourOrRateResultValue.getTotalOtherCost()); - costDetailJson.put(TotalCostEnum.TotalStandardCost.getCode(), hourOrRateResultValue.getTotalCost()); - oldAppSceneCostResultValue.setCostDetail(costDetailJson.toJSONString()); - oldAppSceneCostResultValue.setTotalValue(hourOrRateResultValue.getTotalCost().toString()); - standardCostService.iAppSceneCostResultValueService.updateById(oldAppSceneCostResultValue); - //构造单行成本查询记录 - AppSceneCostStandardDetail costStandardDetail = AppSceneCostStandardDetail.builder().materialNumber(oldAppSceneCostResultValue.getMarterialNo()).materialName(oldAppSceneCostResultValue.getMarterialNo()).parentMaterialNumber(oldAppSceneCostResultValue.getParentMarterialNo()) + try { + List costStandardDetails = new ArrayList<>(); + //父类对应的子节点(除了最上层节点) + Map> parentMaterialNoMap = standardCostList.stream().filter(appSceneCostResultValue -> appSceneCostResultValue.getParentMarterialNo() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getParentMarterialNo)); + for (int i = 0; i < standardCostList.size(); i++) { + //当前节点及其对应的本阶成本 + AppSceneCostResultValue oldAppSceneCostResultValue = standardCostList.get(i); + BigDecimal totalCost = new BigDecimal(oldAppSceneCostResultValue.getCountValue()); + //循环计算出当前节点的累计成本 + String costDetail = oldAppSceneCostResultValue.getCostDetail(); + //查询当前节点各个类型的成本 + BigDecimal totalMaterialCost = new BigDecimal(0); + BigDecimal totalLabourCost = new BigDecimal(0); + BigDecimal totalEquipmentCost = new BigDecimal(0); + BigDecimal totalSupplyMaterialCost = new BigDecimal(0); + BigDecimal totalDriveCost = new BigDecimal(0); + BigDecimal totalLogisticsCost = new BigDecimal(0); + BigDecimal totalOtherCost = new BigDecimal(0); + JSONObject costDetailJson = JSON.parseObject(costDetail); + TotalResultValue hourOrRateResultValue = loopCount(oldAppSceneCostResultValue, parentMaterialNoMap, totalMaterialCost, totalLabourCost, totalEquipmentCost, totalSupplyMaterialCost, totalDriveCost, totalLogisticsCost, totalOtherCost, totalCost); + costDetailJson.put(TotalCostEnum.TotalMaterialCost.getCode(), hourOrRateResultValue.getTotalMaterialCost()); + costDetailJson.put(TotalCostEnum.TotalLaborCost.getCode(), hourOrRateResultValue.getTotalLabourCost()); + costDetailJson.put(TotalCostEnum.TotalEquipmentFee.getCode(), hourOrRateResultValue.getTotalEquipmentCost()); + costDetailJson.put(TotalCostEnum.TotalSupplyMaterialFee.getCode(), hourOrRateResultValue.getTotalSupplyMaterialCost()); + costDetailJson.put(TotalCostEnum.TotalDriverFee.getCode(), hourOrRateResultValue.getTotalDriveCost()); + costDetailJson.put(TotalCostEnum.TotalLogisticsFee.getCode(), hourOrRateResultValue.getTotalLogisticsCost()); + costDetailJson.put(TotalCostEnum.TotalOtherFee.getCode(), hourOrRateResultValue.getTotalOtherCost()); + costDetailJson.put(TotalCostEnum.TotalStandardCost.getCode(), hourOrRateResultValue.getTotalCost()); + oldAppSceneCostResultValue.setCostDetail(costDetailJson.toJSONString()); + oldAppSceneCostResultValue.setTotalValue(hourOrRateResultValue.getTotalCost().toString()); + standardCostService.iAppSceneCostResultValueService.updateById(oldAppSceneCostResultValue); + //构造单行成本查询记录 + AppSceneCostStandardDetail costStandardDetail = AppSceneCostStandardDetail.builder().materialNumber(oldAppSceneCostResultValue.getMarterialNo()).materialName(oldAppSceneCostResultValue.getMarterialNo()).parentMaterialNumber(oldAppSceneCostResultValue.getParentMarterialNo()) // .versionNumber() // .level() // .sort() // .figureNumber() - .dosage(oldAppSceneCostResultValue.getNum() != null ? new Double(oldAppSceneCostResultValue.getNum()) : 0).unit(oldAppSceneCostResultValue.getUnit()).materialCost(costDetailJson.getBigDecimal(FeeTypeEnum.MaterialCost.getCode())).laborCost(costDetailJson.getBigDecimal(FeeTypeEnum.LaborCost.getCode())).equipmentCost(costDetailJson.getBigDecimal(FeeTypeEnum.EquipmentFee.getCode())).supplyMaterialCost(costDetailJson.getBigDecimal(FeeTypeEnum.SupplyMaterialFee.getCode())).driveCost(costDetailJson.getBigDecimal(FeeTypeEnum.DriverFee.getCode())).logisticsCost(costDetailJson.getBigDecimal(FeeTypeEnum.LogisticsFee.getCode())).otherCost(costDetailJson.getBigDecimal(FeeTypeEnum.OtherFee.getCode())).currentStandardCost(new BigDecimal(oldAppSceneCostResultValue.getCountValue())).totalMaterialCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalMaterialCost.getCode())).totalLaborCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalLaborCost.getCode())).totalEquipmentCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalEquipmentFee.getCode())).totalSupplyMaterialCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalSupplyMaterialFee.getCode())).totalDriveCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalDriverFee.getCode())).totalLogisticsCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalLogisticsFee.getCode())).totalOtherCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalOtherFee.getCode())).totalStandardCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalStandardCost.getCode())).build(); - costStandardDetails.add(costStandardDetail); + .dosage(oldAppSceneCostResultValue.getNum() != null ? new Double(oldAppSceneCostResultValue.getNum()) : 0).unit(oldAppSceneCostResultValue.getUnit()).materialCost(costDetailJson.getBigDecimal(FeeTypeEnum.MaterialCost.getCode())).laborCost(costDetailJson.getBigDecimal(FeeTypeEnum.LaborCost.getCode())).equipmentCost(costDetailJson.getBigDecimal(FeeTypeEnum.EquipmentFee.getCode())).supplyMaterialCost(costDetailJson.getBigDecimal(FeeTypeEnum.SupplyMaterialFee.getCode())).driveCost(costDetailJson.getBigDecimal(FeeTypeEnum.DriverFee.getCode())).logisticsCost(costDetailJson.getBigDecimal(FeeTypeEnum.LogisticsFee.getCode())).otherCost(costDetailJson.getBigDecimal(FeeTypeEnum.OtherFee.getCode())).currentStandardCost(new BigDecimal(oldAppSceneCostResultValue.getCountValue())).totalMaterialCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalMaterialCost.getCode())).totalLaborCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalLaborCost.getCode())).totalEquipmentCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalEquipmentFee.getCode())).totalSupplyMaterialCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalSupplyMaterialFee.getCode())).totalDriveCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalDriverFee.getCode())).totalLogisticsCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalLogisticsFee.getCode())).totalOtherCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalOtherFee.getCode())).totalStandardCost(costDetailJson.getBigDecimal(TotalCostEnum.TotalStandardCost.getCode())).createTime(new Date()).build(); + costStandardDetails.add(costStandardDetail); + } + //更新结果集到标准成本单行查询中去 + standardCostService.iAppSceneCostStandardDetailService.saveBatch(costStandardDetails); + } catch (Exception e) { + e.printStackTrace(); } - //更新结果集到标准成本单行查询中去 - standardCostService.iAppSceneCostStandardDetailService.saveBatch(costStandardDetails); } /** diff --git a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/vo/AppSceneCostCountVO.java b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/vo/AppSceneCostCountVO.java new file mode 100644 index 0000000..66c2209 --- /dev/null +++ b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/vo/AppSceneCostCountVO.java @@ -0,0 +1,14 @@ +package com.zzsmart.qomo.kn.cost.manage.vo; + +import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostCount; +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class AppSceneCostCountVO extends AppSceneCostCount { + /** + * 状态名称 + */ + private String statusName; +}