新增模型计算任务相关的接口 #11

Merged
bgy merged 15 commits from bgy into dev 2024-07-29 10:07:32 +00:00
7 changed files with 130 additions and 36 deletions
Showing only changes of commit 2872719a68 - Show all commits
@@ -0,0 +1,26 @@
package com.zzsmart.qomo.kn.cost.manage.controller;
import com.zzsmart.qomo.controller.DataFlowDefinitionController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping
public class FlowDefinitionController {
private static final Logger log = LoggerFactory.getLogger(DataFlowDefinitionController.class);
// @Autowired
// FlowDefinitionService definitionService;
// @GetMapping({"/list"})
// public Result<IPage<FlowDefinition>> queryPageList(FlowDefinition flowDefinition, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
// QueryWrapper<FlowDefinition> queryWrapper = QueryGenerator.initQueryWrapper(flowDefinition, req.getParameterMap());
// Page<FlowDefinition> page = new Page((long) pageNo, (long) pageSize);
// LambdaQueryWrapper<FlowDefinition> wrapper = queryWrapper.lambda();
// wrapper.orderByDesc(FlowDefinition::getCreateTime);
// IPage<FlowDefinition> pageList = definitionService.queryPageList(page, wrapper);
// return Result.OK(pageList);
// }
}
@@ -8,7 +8,10 @@ package com.zzsmart.qomo.kn.cost.manage.enums;
* @Created wangqiong
*/
public enum FeeTypeEnum {
EquipmentFee("EquipmentFee", "机器折旧费"), SupplyMaterialFee("SupplyMaterialFee", "辅料费"), DriverFee("DriverFee", "水电费"), OtherFee("OtherFee", "其他费用"), LogisticsFee("LogisticsFee", "物流费");
LaborCost("LaborCost", "人工成本"),
MaterialCost("MaterialCost", "物料成本"),
EquipmentFee("EquipmentFee", "设备费"), SupplyMaterialFee("SupplyMaterialFee", "辅料费"), DriverFee("DriverFee", "水电费"), OtherFee("OtherFee", "其他费用"), LogisticsFee("LogisticsFee", "物流费");
private final String code;
private final String text;
@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.sql.Blob;
import java.util.List;
/**
@@ -31,4 +32,6 @@ public interface CostMaterialBomMapper extends BaseMapper<CostMaterialBom> {
@Select("${selectSql}")
JSONObject customSelectOne(@Param("selectSql") String selectSql);
@Select("${SelectBlobModel}")
String customSelectBlobModelJson(@Param("SelectBlobModel") String SelectBlobModel);
}
@@ -2,17 +2,13 @@ package com.zzsmart.qomo.kn.cost.manage.plugin;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zzsmart.qomo.dao.entity.FlowDefinition;
import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostResultValue;
import com.zzsmart.qomo.kn.cost.manage.entity.CostMaterialBom;
import com.zzsmart.qomo.kn.cost.manage.entity.CostMaterialProcessHours;
import com.zzsmart.qomo.kn.cost.manage.entity.HourRate;
import com.zzsmart.qomo.kn.cost.manage.enums.FeeTypeEnum;
import com.zzsmart.qomo.kn.cost.manage.mapper.CostMaterialBomMapper;
import com.zzsmart.qomo.kn.cost.manage.service.CostMaterialProcessHoursService;
import com.zzsmart.qomo.kn.cost.manage.service.CostPurchasePriceService;
import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostResultValueService;
import com.zzsmart.qomo.kn.cost.manage.service.IHourRateService;
import com.zzsmart.qomo.kn.cost.manage.service.*;
import com.zzsmart.qomo.kn.cost.manage.vo.FlowTaskInfoVO;
import com.zzsmart.qomo.plugin.task.api.TaskExecutionContext;
import lombok.extern.slf4j.Slf4j;
@@ -34,6 +30,8 @@ public class StandardCostService {
*/
@Autowired
CostMaterialBomMapper costMaterialBomMapper;
@Autowired
CostMaterialBomService costMaterialBomService;
/**
* 小时费率
@@ -61,6 +59,7 @@ public class StandardCostService {
public void init() {
standardCostService = this;
standardCostService.costMaterialBomMapper = this.costMaterialBomMapper;
standardCostService.costMaterialBomService = this.costMaterialBomService;
standardCostService.costPurchasePriceService = this.costPurchasePriceService;
standardCostService.iHourRateService = this.iHourRateService;
standardCostService.costMaterialProcessHoursService = this.costMaterialProcessHoursService;
@@ -85,12 +84,13 @@ public class StandardCostService {
String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
//1.查询出所有满足物料编号的物料(BOM物料)
String sql = flowTaskInfoVO.getSqlString();
List<CostMaterialBom> list = standardCostService.costMaterialBomMapper.customSelect(sql);
log.info("传递过来的SQL语句:" + sql);
List<CostMaterialBom> list = standardCostService.costMaterialBomService.queryAllBomInfoBytopMaterialCode(topMaterialCode);
log.info("Full EmptyTask list: {}", list);
//2.把查询的结果存放在临时表里(表命名规则:前缀_流程id_组件code)
for (int i = 0; list != null && i < list.size(); i++) {
CostMaterialBom material = list.get(i);
AppSceneCostResultValue appSceneCostResultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(material.getMaterialCode()).parentMarterialNo(material.getParentMaterialCode()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).build();
AppSceneCostResultValue appSceneCostResultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(material.getMaterialCode()).parentMarterialNo(material.getParentMaterialCode()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).num(material.getNumber()).build();
standardCostService.iAppSceneCostResultValueService.save(appSceneCostResultValue);
}
} catch (Exception e) {
@@ -113,16 +113,44 @@ public class StandardCostService {
String s1 = split[i];
if (s1.contains("taskType")) {
String[] split1 = s1.split("=");
flowTaskInfoVO.setTaskType(split1[1]);
if (split1[1].contains("\"")) {
split1[1] = split1[1].replaceAll("^\"|\"$", ""); // 去除首尾引号
flowTaskInfoVO.setTaskType(split1[1]);
} else {
flowTaskInfoVO.setTaskType(split1[1]);
}
} else if (s1.contains("taskCode")) {
String[] split1 = s1.split(":");
flowTaskInfoVO.setTaskCode(split1[1]);
if (split1[1].contains("\"")) {
split1[1] = split1[1].replaceAll("^\"|\"$", ""); // 去除首尾引号
flowTaskInfoVO.setTaskCode(split1[1]);
} else {
flowTaskInfoVO.setTaskCode(split1[1]);
}
} else if (s1.contains("flowInstanceId")) {
String[] split1 = s1.split("=");
flowTaskInfoVO.setFlowInstanceId(split1[1]);
if (split1[1].contains("\"")) {
split1[1] = split1[1].replaceAll("^\"|\"$", ""); // 去除首尾引号
flowTaskInfoVO.setFlowInstanceId(split1[1]);
} else {
flowTaskInfoVO.setFlowInstanceId(split1[1]);
}
} else if (s1.contains("sqlString")) {
String[] split1 = s1.split(":");
flowTaskInfoVO.setSqlString(split1[1]);
if (split1[1].contains("\"")) {
split1[1] = split1[1].replaceAll("^\"|\"$", ""); // 去除首尾引号
flowTaskInfoVO.setSqlString(split1[1]);
} else {
flowTaskInfoVO.setSqlString(split1[1]);
}
} else if (s.contains("feeType") && s1.contains("feeType")) {
String[] split1 = s1.split(":");
if (split1[1].contains("\"")) {
split1[1] = split1[1].replaceAll("^\"|\"$", ""); // 去除首尾引号
flowTaskInfoVO.setFeeType(split1[1]);
} else {
flowTaskInfoVO.setFeeType(split1[1]);
}
}
}
}
@@ -135,14 +163,11 @@ public class StandardCostService {
* @param flowTaskInfoVO
*/
private static FlowTaskInfoVO queryFlowDefinitionByFlowInstanceId(FlowTaskInfoVO flowTaskInfoVO) {
String sql = "SELECT A.id,A.`code`,A.`name`,A.version,A.release_state,A.model_json from qomo_flow_definition as A LEFT JOIN qomo_flow_instance AS B ON A.`code`=B.flow_definition_code WHERE B.id=" + flowTaskInfoVO.getFlowInstanceId() + " limit 1";
JSONObject jsonObject = standardCostService.costMaterialBomMapper.customSelectOne(sql);
FlowDefinition flowDefinition = JSON.toJavaObject(jsonObject, FlowDefinition.class);
if (flowDefinition != null) {
log.info("flowDefinition: {}", flowDefinition);
String modelJson = flowDefinition.getModelJson();
JSONObject jsonObject1 = JSON.parseObject(modelJson);
if (jsonObject1 != null) {
String sql = "SELECT A.model_json from qomo_flow_definition as A LEFT JOIN qomo_flow_instance AS B ON A.`code`=B.flow_definition_code WHERE B.id=" + flowTaskInfoVO.getFlowInstanceId() + " limit 1";
String blob = standardCostService.costMaterialBomMapper.customSelectBlobModelJson(sql);
if (blob != null) {
if (blob != null && blob.contains("topMaterialCode")) {
JSONObject jsonObject1 = JSON.parseObject(blob);
String topMaterialCode = jsonObject1.getString("topMaterialCode");
flowTaskInfoVO.setTopMaterialCode(topMaterialCode);
}
@@ -165,6 +190,8 @@ public class StandardCostService {
String taskCode = flowTaskInfoVO.getTaskCode();
//获取流程id
String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
//成本类型
String feeType = FeeTypeEnum.MaterialCost.getCode();
//1.查询出物料编号对应的下所有的BOM信息
List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, "MaterialInput", flowInstanceId);
//2.计算出所有的单个物料的物料成本
@@ -179,7 +206,7 @@ public class StandardCostService {
AppSceneCostResultValue appSceneCostResultValue = list.get(i);
String marterialNo = appSceneCostResultValue.getMarterialNo();
Integer num = appSceneCostResultValue.getNum();
if (marterialNo != null) {
if (marterialNo != null && num != null) {
BigDecimal price = purchasePriceMap.get(marterialNo);
BigDecimal number = new BigDecimal(num.toString());
//单价乘以数量
@@ -209,7 +236,12 @@ public class StandardCostService {
String taskCode = flowTaskInfoVO.getTaskCode();
//获取流程id
String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
String sql = flowTaskInfoVO.getSqlString();
//成本类型
String feeType = FeeTypeEnum.LaborCost.getCode();
String sql1 = flowTaskInfoVO.getSqlString();
log.info("sql1:" + sql1);
String sql = sql1.replaceAll("^\"|\"$", ""); // 去除首尾引号
log.info("sql:" + sql);
JSONObject jsonObject = standardCostService.costMaterialBomMapper.customSelectOne(sql);
BigDecimal hourRate = new BigDecimal("0");
if (jsonObject != null) {
@@ -241,7 +273,7 @@ public class StandardCostService {
}
}
//2.2计算出人工成本并存储到成本结果数据表中
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).build();
standardCostService.iAppSceneCostResultValueService.save(resultValue);
}
}
@@ -273,7 +305,10 @@ public class StandardCostService {
/**
* 小时费率
*/
String sql = flowTaskInfoVO.getSqlString();
String sql1 = flowTaskInfoVO.getSqlString();
log.info("sql1:" + sql1);
String sql = sql1.replaceAll("^\"|\"$", ""); // 去除首尾引号
log.info("sql:" + sql);
JSONObject jsonObject = standardCostService.costMaterialBomMapper.customSelectOne(sql);
BigDecimal hourRate = new BigDecimal("0");
if (jsonObject != null) {
@@ -306,7 +341,7 @@ public class StandardCostService {
}
}
//2.2计算机器成本并存储到成本结果数据表中
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).build();
standardCostService.iAppSceneCostResultValueService.save(resultValue);
}
}
@@ -328,7 +363,7 @@ public class StandardCostService {
}
}
//2.2计算机物料消耗存储到成本结果数据表中
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).build();
standardCostService.iAppSceneCostResultValueService.save(resultValue);
}
}
@@ -350,7 +385,7 @@ public class StandardCostService {
}
}
//2.2计算机物料消耗存储到成本结果数据表中
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).build();
standardCostService.iAppSceneCostResultValueService.save(resultValue);
}
}
@@ -372,7 +407,7 @@ public class StandardCostService {
}
}
//2.2计算机物料消耗存储到成本结果数据表中
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").costType(feeType).build();
standardCostService.iAppSceneCostResultValueService.save(resultValue);
}
}
@@ -392,7 +427,7 @@ public class StandardCostService {
totalCost = totalCost.add(new BigDecimal(countValue));
}
}
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(key).parentMarterialNo(appSceneCostResultValues.get(0).getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost.multiply(new BigDecimal("0.1016")).toString()).build();
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(key).parentMarterialNo(appSceneCostResultValues.get(0).getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost.multiply(new BigDecimal("0.1016")).toString()).costType(feeType).build();
standardCostService.iAppSceneCostResultValueService.save(resultValue);
}
}
@@ -437,7 +472,7 @@ public class StandardCostService {
}
//3.计算出所有的单个物料的累计标准成本
List<AppSceneCostResultValue> standardCostList = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, taskType, flowInstanceId);
//循环算出各个物料的累计成本
//TODO 优化累计成本的计算
totalCountCost(standardCostList, topMaterialCode, taskType, taskCode, flowInstanceId);
}
@@ -453,15 +488,17 @@ public class StandardCostService {
private static void totalCountCost(List<AppSceneCostResultValue> standardCostList, String topMaterialCode, String taskType, String taskCode, String flowInstanceId) {
Map<String, List<AppSceneCostResultValue>> parentMaterialNoMap = standardCostList.stream().filter(appSceneCostResultValue -> appSceneCostResultValue.getParentMarterialNo() != null).collect(Collectors.groupingBy(AppSceneCostResultValue::getParentMarterialNo));
for (int i = 0; i < standardCostList.size(); i++) {
AppSceneCostResultValue appSceneCostResultValue = standardCostList.get(i);
BigDecimal totalCost = new BigDecimal("0.0");
totalCost = loopCount(appSceneCostResultValue, parentMaterialNoMap, topMaterialCode, taskType, taskCode, flowInstanceId, totalCost);
appSceneCostResultValue.setTotalValue(totalCost.toString());
standardCostService.iAppSceneCostResultValueService.save(appSceneCostResultValue);
AppSceneCostResultValue oldAppSceneCostResultValue = standardCostList.get(i);
BigDecimal totalCost = new BigDecimal(oldAppSceneCostResultValue.getCountValue());
totalCost = loopCount(oldAppSceneCostResultValue, parentMaterialNoMap, topMaterialCode, taskType, taskCode, flowInstanceId, totalCost);
oldAppSceneCostResultValue.setTotalValue(totalCost.toString());
standardCostService.iAppSceneCostResultValueService.updateById(oldAppSceneCostResultValue);
//TODO 更新结果集到标准成本单行查询中去
}
}
/**
* //循环算出各个物料的累计成本
* 递归计算出累计成本
*
* @param appSceneCostResultValue
@@ -20,4 +20,11 @@ public interface CostMaterialBomService extends IService<CostMaterialBom> {
* @return
*/
List<CostMaterialBom> queryListResult(String materialNumber);
/**
* 查询最顶层物料编号下所有的物料
* @param topMaterialCode
* @return
*/
List<CostMaterialBom> queryAllBomInfoBytopMaterialCode(String topMaterialCode);
}
@@ -40,7 +40,7 @@ public class AppSceneCostResultValueServiceImpl extends ServiceImpl<AppSceneCost
queryWrapper.eq("belong_top_material_no", topMaterialCode).eq("task_type", lastTaskType).eq("flow_instance_id", flowInstanceId);
result = appSceneCostResultValueMapper.selectList(queryWrapper);
} else if (topMaterialCode != null && !topMaterialCode.equals("") && flowInstanceId != null && !flowInstanceId.equals("")) {
queryWrapper.eq("belong_top_material_no", topMaterialCode).eq("task_type", lastTaskType).eq("flow_instance_id", flowInstanceId);
queryWrapper.eq("belong_top_material_no", topMaterialCode).eq("flow_instance_id", flowInstanceId);
result = appSceneCostResultValueMapper.selectList(queryWrapper);
}
return result;
@@ -40,4 +40,22 @@ public class CostMaterialBomServiceImpl extends ServiceImpl<CostMaterialBomMappe
List list = costMaterialBomMapper.selectList(queryWrapper);
return list;
}
/**
* 查询最顶层物料编号下所有的物料
*
* @param topMaterialCode
* @return
*/
@Override
public List<CostMaterialBom> queryAllBomInfoBytopMaterialCode(String topMaterialCode) {
QueryWrapper queryWrapper = new QueryWrapper();
//TODO 循环遍历查出所有的物料下的物料(包含最上层的物料)
// if (StrUtil.isNotEmpty(topMaterialCode)) {
// // 物料号
// queryWrapper.like("material_code", topMaterialCode);
// }
List list = costMaterialBomMapper.selectList(queryWrapper);
return list;
}
}