优化成本计算接口

This commit is contained in:
wangqiong
2024-08-02 08:59:09 +08:00
parent 339cf044a8
commit 1a2dee14e4
7 changed files with 364 additions and 230 deletions
@@ -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<AppSceneCostCou
//@AutoLog(value = "app_scene_cost_count-分页列表查询")
@ApiOperation(value = "标准成本计算-分页列表查询", notes = "标准成本计算-分页列表查询")
@GetMapping(value = "/list")
public Result<IPage<AppSceneCostCount>> queryPageList(AppSceneCostCount appSceneCostCount, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
public Result<IPage<AppSceneCostCountVO>> queryPageList(AppSceneCostCount appSceneCostCount, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
QueryWrapper<AppSceneCostCount> queryWrapper = QueryGenerator.initQueryWrapper(appSceneCostCount, req.getParameterMap());
Page<AppSceneCostCount> page = new Page<AppSceneCostCount>(pageNo, pageSize);
IPage<AppSceneCostCount> pageList = appSceneCostCountService.page(page, queryWrapper);
return Result.OK(pageList);
IPage<AppSceneCostCountVO> pageList1 = new Page<>();
BeanUtils.copyProperties(pageList, pageList1);
List<AppSceneCostCountVO>list=new ArrayList<>();
for(int i=0;i<pageList.getRecords().size();i++){
AppSceneCostCount appSceneCostCount1 = pageList.getRecords().get(i);
AppSceneCostCountVO appSceneCostCountVO = new AppSceneCostCountVO();
BeanUtils.copyProperties(appSceneCostCount1, appSceneCostCountVO);
appSceneCostCountVO.setStatusName(CostCountStatusEnum.getTextByValue(appSceneCostCount1.getStatus()));
list.add(appSceneCostCountVO);
}
pageList1.setRecords(list);
return Result.OK(pageList1);
}
/**
@@ -64,7 +79,7 @@ public class AppSceneCostCountController extends JeecgController<AppSceneCostCou
*/
@AutoLog(value = "app_scene_cost_count-添加")
@ApiOperation(value = "添加标准成本计算任务", notes = "添加标准成本计算任务")
@RequiresPermissions("com.zzsmart.qomo.kn.cost.manage:app_scene_cost_count:addCostCountTask")
// @RequiresPermissions("com.zzsmart.qomo.kn.cost.manage:app_scene_cost_count:addCostCountTask")
@PostMapping(value = "/addCostCountTask")
public Result<String> addCostCountTask(@RequestBody AppSceneCostCount appSceneCostCount) {
appSceneCostCountService.addCostCountTask(appSceneCostCount);
@@ -1,23 +1,18 @@
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
@@ -28,56 +23,82 @@ import lombok.experimental.Accessors;
@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")
public class AppSceneCostCount implements Serializable {
private static final long serialVersionUID = 1L;
/**主键*/
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "主键")
private Integer id;
/**物料编号*/
/**
* 物料编号
*/
@Excel(name = "物料编号", width = 15)
@ApiModelProperty(value = "物料编号")
private String materialNo;
/**图号*/
/**
* 图号
*/
@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*/
/**
* 标准成本计算流程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)
@ApiModelProperty(value = "状态")
private Integer status;
/**模型版本*/
/**
* 模型版本
*/
@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")
@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")
@ApiModelProperty(value = "更新时间")
@@ -35,7 +35,7 @@ public class AppSceneCostResultValue implements Serializable {
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
@TableId(type = IdType.AUTO)
@ApiModelProperty(value = "主键")
private Integer id;
/**
@@ -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)
@@ -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;
}
}
@@ -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,6 +472,7 @@ public class StandardCostService {
* 5.标准成本计算任务
*/
public static void standardCostTask(TaskExecutionContext parameters) {
try {
//获取任务流程相关信息
FlowTaskInfoVO flowTaskInfoVO = analysisFlowTaskInfo(parameters);
//获取最上层的物料号
@@ -608,6 +612,10 @@ public class StandardCostService {
List<AppSceneCostResultValue> standardCostList = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, taskType, flowInstanceId);
//【累计成本】的计算
totalCountCost(standardCostList, topMaterialCode, taskType, taskCode, flowInstanceId);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("计算成本失败");
}
}
/**
@@ -620,7 +628,7 @@ public class StandardCostService {
* @param flowInstanceId
*/
private static void totalCountCost(List<AppSceneCostResultValue> standardCostList, String topMaterialCode, String taskType, String taskCode, String flowInstanceId) {
try {
List<AppSceneCostStandardDetail> costStandardDetails = new ArrayList<>();
//父类对应的子节点(除了最上层节点)
Map<String, List<AppSceneCostResultValue>> parentMaterialNoMap = standardCostList.stream().filter(appSceneCostResultValue -> appSceneCostResultValue.getParentMarterialNo() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getParentMarterialNo));
@@ -657,11 +665,14 @@ public class StandardCostService {
// .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();
.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();
}
}
/**
@@ -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;
}