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

Merged
bgy merged 15 commits from bgy into dev 2024-07-29 10:07:32 +00:00
16 changed files with 726 additions and 246 deletions
Showing only changes of commit 1030034e41 - Show all commits
@@ -1,28 +1,25 @@
package com.zzsmart.qomo.kn.cost.manage.entity; 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.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; 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 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.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; 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_result_value * @Description: app_scene_cost_result_value
* @Author: jeecg-boot * @Author: jeecg-boot
* @Date: 2024-07-23 * @Date: 2024-07-25
* @Version: V1.0 * @Version: V1.0
*/ */
@Data @Data
@@ -30,48 +27,92 @@ import lombok.experimental.Accessors;
@TableName("app_scene_cost_result_value") @TableName("app_scene_cost_result_value")
@Accessors(chain = true) @Accessors(chain = true)
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@ApiModel(value="app_scene_cost_result_value对象", description="app_scene_cost_result_value") @ApiModel(value = "app_scene_cost_result_value对象", description = "app_scene_cost_result_value")
public class AppSceneCostResultValue implements Serializable { public class AppSceneCostResultValue implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/**主键*/ /**
@TableId(type = IdType.ASSIGN_ID) * 主键
*/
@TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "主键") @ApiModelProperty(value = "主键")
private Integer id; private Integer id;
/**所属最上级物料号*/ /**
@Excel(name = "所属最上级物料号", width = 15) * 所属最上级物料号
*/
@Excel(name = "所属最上级物料号", width = 15)
@ApiModelProperty(value = "所属最上级物料号") @ApiModelProperty(value = "所属最上级物料号")
private String belongTopMaterialNo; private String belongTopMaterialNo;
/**物料编号*/ /**
@Excel(name = "物料编号", width = 15) * 物料编号
*/
@Excel(name = "物料编号", width = 15)
@ApiModelProperty(value = "物料编号") @ApiModelProperty(value = "物料编号")
private String marterialNo; private String marterialNo;
/**父类物料编号*/ /**
@Excel(name = "父类物料编号", width = 15) * 父类物料编号
*/
@Excel(name = "父类物料编号", width = 15)
@ApiModelProperty(value = "父类物料编号") @ApiModelProperty(value = "父类物料编号")
private String parentMarterialNo; private String parentMarterialNo;
/**任务类型*/ /**
@Excel(name = "任务类型", width = 15) * 数量
*/
@Excel(name = "数量", width = 15)
@ApiModelProperty(value = "数量")
private Integer num;
/**
* 单位
*/
@Excel(name = "单位", width = 15)
@ApiModelProperty(value = "单位")
private String unit;
/**
* 任务类型
*/
@Excel(name = "任务类型", width = 15)
@ApiModelProperty(value = "任务类型") @ApiModelProperty(value = "任务类型")
private String taskType; private String taskType;
/**任务代码*/ /**
@Excel(name = "任务代码", width = 15) * 任务代码
*/
@Excel(name = "任务代码", width = 15)
@ApiModelProperty(value = "任务代码") @ApiModelProperty(value = "任务代码")
private String taskCode; private String taskCode;
/**流程id*/ /**
@Excel(name = "流程id", width = 15) * 流程id
*/
@Excel(name = "流程id", width = 15)
@ApiModelProperty(value = "流程id") @ApiModelProperty(value = "流程id")
private String flowInstanceId; private String flowInstanceId;
/**计算结果值(多个值通过字段拼接)*/ /**
@Excel(name = "计算结果值(多个值通过字段拼接)", width = 15) * 本阶成本
@ApiModelProperty(value = "计算结果值(多个值通过字段拼接)") */
@Excel(name = "本阶成本", width = 15)
@ApiModelProperty(value = "本阶成本")
private String countValue; private String countValue;
/**创建时间*/ /**
@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 = "创建时间") @ApiModelProperty(value = "创建时间")
private Date createTime; private Date createTime;
/**创建人*/ /**
* 创建人
*/
@ApiModelProperty(value = "创建人") @ApiModelProperty(value = "创建人")
private Integer createBy; private Integer createBy;
/**
* 总计成本
*/
@Excel(name = "总计成本", width = 15)
@ApiModelProperty(value = "总计成本")
private String totalValue;
/**
* 成本类别
*/
@Excel(name = "成本类别", width = 15)
@ApiModelProperty(value = "成本类别")
private String costType;
} }
@@ -0,0 +1,58 @@
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 FeeTypeEnum {
EquipmentFee("EquipmentFee", "机器折旧费"), SupplyMaterialFee("SupplyMaterialFee", "辅料费"), DriverFee("DriverFee", "水电费"), OtherFee("OtherFee", "其他费用"), LogisticsFee("LogisticsFee", "物流费");
private final String code;
private final String text;
FeeTypeEnum(String code, String text) {
this.code = code;
this.text = text;
}
public String getCode() {
return code;
}
public String getText() {
return text;
}
/**
* 根据code获取text
*
* @param codeNo
* @return
*/
public static String getTextByCode(String codeNo) {
for (FeeTypeEnum value : FeeTypeEnum.values()) {
if (value.getCode().equals(codeNo)) {
return value.getText();
}
}
return codeNo.toString();
}
/**
* 根据text获取code
*
* @param textStr
* @return
*/
public static String getCodeByText(String textStr) {
for (FeeTypeEnum value : FeeTypeEnum.values()) {
if (value.getText().equals(textStr)) {
return value.getText();
}
}
return textStr;
}
}
@@ -8,39 +8,33 @@ package com.zzsmart.qomo.kn.cost.manage.enums;
* @Created wangqiong * @Created wangqiong
*/ */
public enum StandardStageEnum { public enum StandardStageEnum {
INIT("A", "初始"), INIT("A", "初始"), FIRST_BATCH("B", "首批"), MASS_PRODUCTION("C", "量产");
FIRST_BATCH("B", "首批"),
MASS_PRODUCTION("C", "量产"),
;
private final String code; private final String code;
private final String text; private final String text;
StandardStageEnum(String code, String text) StandardStageEnum(String code, String text) {
{
this.code = code; this.code = code;
this.text = text; this.text = text;
} }
public String getCode() public String getCode() {
{
return code; return code;
} }
public String getText() public String getText() {
{
return text; return text;
} }
/** /**
* 根据code获取text * 根据code获取text
*
* @param codeNo * @param codeNo
* @return * @return
*/ */
public static String getTextByCode(String codeNo){ public static String getTextByCode(String codeNo) {
for (StandardStageEnum value : StandardStageEnum.values()) { for (StandardStageEnum value : StandardStageEnum.values()) {
if (value.getCode().equals(codeNo)){ if (value.getCode().equals(codeNo)) {
return value.getText(); return value.getText();
} }
} }
@@ -49,12 +43,13 @@ public enum StandardStageEnum {
/** /**
* 根据text获取code * 根据text获取code
*
* @param textStr * @param textStr
* @return * @return
*/ */
public static String getCodeByText(String textStr){ public static String getCodeByText(String textStr) {
for (StandardStageEnum value : StandardStageEnum.values()) { for (StandardStageEnum value : StandardStageEnum.values()) {
if (value.getText().equals(textStr)){ if (value.getText().equals(textStr)) {
return value.getText(); return value.getText();
} }
} }
@@ -1,5 +1,6 @@
package com.zzsmart.qomo.kn.cost.manage.mapper; package com.zzsmart.qomo.kn.cost.manage.mapper;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsmart.qomo.kn.cost.manage.entity.CostMaterialBom; import com.zzsmart.qomo.kn.cost.manage.entity.CostMaterialBom;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@@ -26,4 +27,8 @@ public interface CostMaterialBomMapper extends BaseMapper<CostMaterialBom> {
*/ */
@Select("${selectCommand}") @Select("${selectCommand}")
List<CostMaterialBom> customSelect(@Param("selectCommand") String selectCommand); List<CostMaterialBom> customSelect(@Param("selectCommand") String selectCommand);
@Select("${selectSql}")
JSONObject customSelectOne(@Param("selectSql") String selectSql);
} }
@@ -0,0 +1,489 @@
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.vo.FlowTaskInfoVO;
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 javax.annotation.PostConstruct;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
@Slf4j
public class StandardCostService {
/**
* 物料BOM信息
*/
@Autowired
CostMaterialBomMapper costMaterialBomMapper;
/**
* 小时费率
*/
@Autowired
IHourRateService iHourRateService;
/**
* 采购单价
*/
@Autowired
CostPurchasePriceService costPurchasePriceService;
/**
* 工序
*/
@Autowired
CostMaterialProcessHoursService costMaterialProcessHoursService;
/**
* 标准成本计算结果
*/
@Autowired
IAppSceneCostResultValueService iAppSceneCostResultValueService;
public static StandardCostService standardCostService;
@PostConstruct
public void init() {
standardCostService = this;
standardCostService.costMaterialBomMapper = this.costMaterialBomMapper;
standardCostService.costPurchasePriceService = this.costPurchasePriceService;
standardCostService.iHourRateService = this.iHourRateService;
standardCostService.costMaterialProcessHoursService = this.costMaterialProcessHoursService;
standardCostService.iAppSceneCostResultValueService = this.iAppSceneCostResultValueService;
}
/**
* 1.物料编号输入任务
*/
public static void materialInputTask(TaskExecutionContext parameters) {
try {
//获取任务流程相关信息
FlowTaskInfoVO flowTaskInfoVO = analysisFlowTaskInfo(parameters);
//获取最上层的物料号
String topMaterialCode = flowTaskInfoVO.getTopMaterialCode();
//获取任务类型
String taskType = parameters.getTaskType();
//获取任务代码
String taskCode = flowTaskInfoVO.getTaskCode();
//获取流程id
String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
//1.查询出所有满足物料编号的物料(BOM物料)
String sql = flowTaskInfoVO.getSqlString();
List<CostMaterialBom> list = standardCostService.costMaterialBomMapper.customSelect(sql);
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();
standardCostService.iAppSceneCostResultValueService.save(appSceneCostResultValue);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* 获取任务流程相关信息
*
* @param parameters
* @return
*/
private static FlowTaskInfoVO analysisFlowTaskInfo(TaskExecutionContext parameters) {
FlowTaskInfoVO flowTaskInfoVO = new FlowTaskInfoVO();
if (parameters != null) {
String s = parameters.toString();
String[] split = s.split(",");
for (int i = 0; i < split.length; i++) {
String s1 = split[i];
if (s1.contains("taskType")) {
String[] split1 = s1.split("=");
flowTaskInfoVO.setTaskType(split1[1]);
} else if (s1.contains("taskCode")) {
String[] split1 = s1.split(":");
flowTaskInfoVO.setTaskCode(split1[1]);
} else if (s1.contains("flowInstanceId")) {
String[] split1 = s1.split("=");
flowTaskInfoVO.setFlowInstanceId(split1[1]);
} else if (s1.contains("sqlString")) {
String[] split1 = s1.split(":");
flowTaskInfoVO.setSqlString(split1[1]);
}
}
}
//通过任务流程id查询流程定义信息(qomo_flow_definition)
flowTaskInfoVO = queryFlowDefinitionByFlowInstanceId(flowTaskInfoVO);
return flowTaskInfoVO;
}
/**
* @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 topMaterialCode = jsonObject1.getString("topMaterialCode");
flowTaskInfoVO.setTopMaterialCode(topMaterialCode);
}
}
return flowTaskInfoVO;
}
/**
* 2. 物料成本任务
*/
public static void materialCostTask(TaskExecutionContext parameters) {
try {
//获取任务流程相关信息
FlowTaskInfoVO flowTaskInfoVO = analysisFlowTaskInfo(parameters);
//获取最上层的物料号
String topMaterialCode = flowTaskInfoVO.getTopMaterialCode();
//获取任务类型
String taskType = parameters.getTaskType();
//获取任务代码
String taskCode = flowTaskInfoVO.getTaskCode();
//获取流程id
String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
//1.查询出物料编号对应的下所有的BOM信息
List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, "MaterialInput", flowInstanceId);
//2.计算出所有的单个物料的物料成本
//2.1查询出物料的单价和采购数量
List<String> MarterialNoList = new ArrayList<>();
if (list != null && list.size() > 0) {
MarterialNoList = list.stream().filter(s -> s.getMarterialNo() != null).map(AppSceneCostResultValue::getMarterialNo).collect(Collectors.toList());
}
//查询物料的采购价
Map<String, BigDecimal> purchasePriceMap = standardCostService.costPurchasePriceService.getMinCostPurchasePriceByMaterialNo(MarterialNoList);
for (int i = 0; i < list.size(); i++) {
AppSceneCostResultValue appSceneCostResultValue = list.get(i);
String marterialNo = appSceneCostResultValue.getMarterialNo();
Integer num = appSceneCostResultValue.getNum();
if (marterialNo != null) {
BigDecimal price = purchasePriceMap.get(marterialNo);
BigDecimal number = new BigDecimal(num.toString());
//单价乘以数量
BigDecimal totalCost = price.multiply(number);
//2.2计算出人工成本并存储到成本结果数据表中
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
standardCostService.iAppSceneCostResultValueService.save(resultValue);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* 3.人工成本任务
*/
public static void laborCostTask(TaskExecutionContext parameters) {
try {
//获取任务流程相关信息
FlowTaskInfoVO flowTaskInfoVO = analysisFlowTaskInfo(parameters);
//获取最上层的物料号
String topMaterialCode = flowTaskInfoVO.getTopMaterialCode();
//获取任务类型
String taskType = parameters.getTaskType();
//获取任务代码
String taskCode = flowTaskInfoVO.getTaskCode();
//获取流程id
String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
String sql = flowTaskInfoVO.getSqlString();
JSONObject jsonObject = standardCostService.costMaterialBomMapper.customSelectOne(sql);
BigDecimal hourRate = new BigDecimal("0");
if (jsonObject != null) {
HourRate rate = JSON.toJavaObject(jsonObject, HourRate.class);
hourRate = rate.getLaborHourRate();
}
//1.查询出物料编号对应的下所有的BOM信息
List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, "MaterialInput", flowInstanceId);
//2.计算出所有的单个物料的人工成本
//2.1查询出物料的人员工时和人工小时费率(涉及:小时费率表和工序表)
List<String> MarterialNoList = new ArrayList<>();
if (list != null && list.size() > 0) {
MarterialNoList = list.stream().filter(s -> s.getMarterialNo() != null).map(AppSceneCostResultValue::getMarterialNo).collect(Collectors.toList());
}
//查询工序工时
Map<String, List<CostMaterialProcessHours>> processHoursMap = standardCostService.costMaterialProcessHoursService.getProcessHoursByMaterialNo(MarterialNoList);
for (int i = 0; i < list.size(); i++) {
AppSceneCostResultValue appSceneCostResultValue = list.get(i);
String marterialNo = appSceneCostResultValue.getMarterialNo();
if (marterialNo != null) {
BigDecimal totalCost = new BigDecimal("0.0");
List<CostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
for (int j = 0; j < costMaterialProcessHours.size(); j++) {
CostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
BigDecimal laborHours = processHours.getLaborHours();
//计算总人工成本
totalCost = totalCost.add(laborHours.multiply(hourRate));
}
}
//2.2计算出人工成本并存储到成本结果数据表中
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
standardCostService.iAppSceneCostResultValueService.save(resultValue);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* 4.制造费用成本任务
*/
public static void manufacturingCostTask(TaskExecutionContext parameters) {
try {
//获取任务流程相关信息
FlowTaskInfoVO flowTaskInfoVO = analysisFlowTaskInfo(parameters);
//获取最上层的物料号
String topMaterialCode = flowTaskInfoVO.getTopMaterialCode();
//获取任务类型
String taskType = parameters.getTaskType();
//获取任务代码
String taskCode = flowTaskInfoVO.getTaskCode();
//获取流程id
String flowInstanceId = flowTaskInfoVO.getFlowInstanceId();
/**
* 费用类别
*/
String feeType = flowTaskInfoVO.getFeeType();
/**
* 小时费率
*/
String sql = flowTaskInfoVO.getSqlString();
JSONObject jsonObject = standardCostService.costMaterialBomMapper.customSelectOne(sql);
BigDecimal hourRate = new BigDecimal("0");
if (jsonObject != null) {
HourRate rate = JSON.toJavaObject(jsonObject, HourRate.class);
hourRate = rate.getLaborHourRate();
}
//1.查询出物料编号对应的下所有的BOM信息
List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, "MaterialInput", flowInstanceId);
//2.根据费用类型进行不同的费用计算
//查询工序工时
List<String> MarterialNoList = new ArrayList<>();
if (list != null && list.size() > 0) {
MarterialNoList = list.stream().filter(s -> s.getMarterialNo() != null).map(AppSceneCostResultValue::getMarterialNo).collect(Collectors.toList());
}
Map<String, List<CostMaterialProcessHours>> processHoursMap = standardCostService.costMaterialProcessHoursService.getProcessHoursByMaterialNo(MarterialNoList);
//2.1机器折旧费(机器工时*费率)
if (FeeTypeEnum.EquipmentFee.getCode().equals(feeType)) {
for (int i = 0; i < list.size(); i++) {
AppSceneCostResultValue appSceneCostResultValue = list.get(i);
String marterialNo = appSceneCostResultValue.getMarterialNo();
if (marterialNo != null) {
BigDecimal totalCost = new BigDecimal("0.0");
List<CostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
for (int j = 0; j < costMaterialProcessHours.size(); j++) {
CostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
BigDecimal laborHours = processHours.getDeviceHours();
//计算机器成本
totalCost = totalCost.add(laborHours.multiply(hourRate));
}
}
//2.2计算机器成本并存储到成本结果数据表中
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
standardCostService.iAppSceneCostResultValueService.save(resultValue);
}
}
} else if (FeeTypeEnum.SupplyMaterialFee.getCode().equals(feeType)) {
//机物料消耗(辅料工时*费率)
for (int i = 0; i < list.size(); i++) {
AppSceneCostResultValue appSceneCostResultValue = list.get(i);
String marterialNo = appSceneCostResultValue.getMarterialNo();
if (marterialNo != null) {
BigDecimal totalCost = new BigDecimal("0.0");
List<CostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
for (int j = 0; j < costMaterialProcessHours.size(); j++) {
CostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
//TODO 辅料工时来源
BigDecimal laborHours = processHours.getLaborHours();
//机物料消耗
totalCost = totalCost.add(laborHours.multiply(hourRate));
}
}
//2.2计算机物料消耗存储到成本结果数据表中
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
standardCostService.iAppSceneCostResultValueService.save(resultValue);
}
}
} else if (FeeTypeEnum.DriverFee.getCode().equals(feeType)) {
//2.3水电费(燃动力工时*费率)
for (int i = 0; i < list.size(); i++) {
AppSceneCostResultValue appSceneCostResultValue = list.get(i);
String marterialNo = appSceneCostResultValue.getMarterialNo();
if (marterialNo != null) {
BigDecimal totalCost = new BigDecimal("0.0");
List<CostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
for (int j = 0; j < costMaterialProcessHours.size(); j++) {
CostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
//TODO 燃动力工时来源
BigDecimal laborHours = processHours.getLaborHours();
//机物料消耗
totalCost = totalCost.add(laborHours.multiply(hourRate));
}
}
//2.2计算机物料消耗存储到成本结果数据表中
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
standardCostService.iAppSceneCostResultValueService.save(resultValue);
}
}
} else if (FeeTypeEnum.OtherFee.getCode().equals(feeType)) {
//2.4其他制费(其他工时*费率)
for (int i = 0; i < list.size(); i++) {
AppSceneCostResultValue appSceneCostResultValue = list.get(i);
String marterialNo = appSceneCostResultValue.getMarterialNo();
if (marterialNo != null) {
BigDecimal totalCost = new BigDecimal("0.0");
List<CostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
for (int j = 0; j < costMaterialProcessHours.size(); j++) {
CostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
//TODO 其他工时来源
BigDecimal laborHours = processHours.getLaborHours();
//机物料消耗
totalCost = totalCost.add(laborHours.multiply(hourRate));
}
}
//2.2计算机物料消耗存储到成本结果数据表中
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalCost + "").build();
standardCostService.iAppSceneCostResultValueService.save(resultValue);
}
}
} else if (FeeTypeEnum.LogisticsFee.getCode().equals(feeType)) {
//查出所有的机器折旧费、机物料消耗、水电费、其他制费
list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, "ManufacturingCost", flowInstanceId);
//2.5物流费((机器折旧+机物料消耗+水电费+其他制费)*10.16%)
//按照物料编号进行分组
Map<String, List<AppSceneCostResultValue>> materialNoMap = list.stream().collect(Collectors.groupingBy(AppSceneCostResultValue::getMarterialNo));
for (String key : materialNoMap.keySet()) {
List<AppSceneCostResultValue> appSceneCostResultValues = materialNoMap.get(key);
BigDecimal totalCost = new BigDecimal("0.0");
for (int j = 0; j < appSceneCostResultValues.size(); j++) {
AppSceneCostResultValue appSceneCostResultValue = appSceneCostResultValues.get(j);
String countValue = appSceneCostResultValue.getCountValue();
if (countValue != null) {
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();
standardCostService.iAppSceneCostResultValueService.save(resultValue);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* 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();
//1.查询出物料编号对应的下所有的BOM信息
List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, null, flowInstanceId);
//2.计算出所有的单个物料的本阶的标准成本(标准成本=物料成本+人工成本+制造费用)
//按照物料编号进行分组
Map<String, List<AppSceneCostResultValue>> materialNoMap = list.stream().collect(Collectors.groupingBy(AppSceneCostResultValue::getMarterialNo));
for (String key : materialNoMap.keySet()) {
List<AppSceneCostResultValue> appSceneCostResultValues = materialNoMap.get(key);
//本阶成本
BigDecimal currentCost = new BigDecimal("0.0");
for (int j = 0; j < appSceneCostResultValues.size(); j++) {
AppSceneCostResultValue appSceneCostResultValue = appSceneCostResultValues.get(j);
String countValue = appSceneCostResultValue.getCountValue();
if (countValue != null) {
currentCost = currentCost.add(new BigDecimal(countValue));
}
}
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(key).parentMarterialNo(appSceneCostResultValues.get(0).getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(currentCost.toString()).build();
standardCostService.iAppSceneCostResultValueService.save(resultValue);
}
//3.计算出所有的单个物料的累计标准成本
List<AppSceneCostResultValue> standardCostList = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, taskType, flowInstanceId);
//循环算出各个物料的累计成本
totalCountCost(standardCostList, topMaterialCode, taskType, taskCode, flowInstanceId);
}
/**
* 循环算出各个物料的累计成本
*
* @param standardCostList
* @param topMaterialCode
* @param taskType
* @param taskCode
* @param flowInstanceId
*/
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);
}
}
/**
* 递归计算出累计成本
*
* @param appSceneCostResultValue
* @param parentMaterialNoMap
* @param topMaterialCode
* @param taskType
* @param taskCode
* @param flowInstanceId
*/
private static BigDecimal loopCount(AppSceneCostResultValue appSceneCostResultValue, Map<String, List<AppSceneCostResultValue>> parentMaterialNoMap, String topMaterialCode, String taskType, String taskCode, String flowInstanceId, BigDecimal totalCost) {
String marterialNo = appSceneCostResultValue.getMarterialNo();
if (parentMaterialNoMap.containsKey(marterialNo)) {
List<AppSceneCostResultValue> appSceneCostResultValues = parentMaterialNoMap.get(marterialNo);
for (int j = 0; j < appSceneCostResultValues.size(); j++) {
AppSceneCostResultValue appSceneCostResultValue1 = appSceneCostResultValues.get(j);
String countValue = appSceneCostResultValue1.getCountValue();
if (countValue != null) {
totalCost = totalCost.add(new BigDecimal(countValue));
}
loopCount(appSceneCostResultValue1, parentMaterialNoMap, topMaterialCode, taskType, taskCode, flowInstanceId, totalCost);
}
}
return totalCost;
}
}
@@ -17,7 +17,7 @@
package com.zzsmart.qomo.kn.cost.manage.plugin.laborcost; package com.zzsmart.qomo.kn.cost.manage.plugin.laborcost;
import com.zzsmart.qomo.kn.cost.manage.plugin.materialinput.StandardCostService; import com.zzsmart.qomo.kn.cost.manage.plugin.StandardCostService;
import com.zzsmart.qomo.plugin.task.api.*; import com.zzsmart.qomo.plugin.task.api.*;
import com.zzsmart.qomo.plugin.task.api.parameters.AbstractParameters; import com.zzsmart.qomo.plugin.task.api.parameters.AbstractParameters;
@@ -17,17 +17,9 @@
package com.zzsmart.qomo.kn.cost.manage.plugin.manufacturingcost; package com.zzsmart.qomo.kn.cost.manage.plugin.manufacturingcost;
import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostResultValue; import com.zzsmart.qomo.kn.cost.manage.plugin.StandardCostService;
import com.zzsmart.qomo.kn.cost.manage.entity.CostMaterialBom;
import com.zzsmart.qomo.kn.cost.manage.mapper.CostMaterialBomMapper;
import com.zzsmart.qomo.kn.cost.manage.plugin.materialinput.StandardCostService;
import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostResultValueService;
import com.zzsmart.qomo.plugin.task.api.*; import com.zzsmart.qomo.plugin.task.api.*;
import com.zzsmart.qomo.plugin.task.api.parameters.AbstractParameters; import com.zzsmart.qomo.plugin.task.api.parameters.AbstractParameters;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import java.util.List;
/** /**
* 制造费用成本任务 * 制造费用成本任务
@@ -17,17 +17,9 @@
package com.zzsmart.qomo.kn.cost.manage.plugin.materialcost; package com.zzsmart.qomo.kn.cost.manage.plugin.materialcost;
import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostResultValue; import com.zzsmart.qomo.kn.cost.manage.plugin.StandardCostService;
import com.zzsmart.qomo.kn.cost.manage.entity.CostMaterialBom;
import com.zzsmart.qomo.kn.cost.manage.mapper.CostMaterialBomMapper;
import com.zzsmart.qomo.kn.cost.manage.plugin.materialinput.StandardCostService;
import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostResultValueService;
import com.zzsmart.qomo.plugin.task.api.*; import com.zzsmart.qomo.plugin.task.api.*;
import com.zzsmart.qomo.plugin.task.api.parameters.AbstractParameters; import com.zzsmart.qomo.plugin.task.api.parameters.AbstractParameters;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import java.util.List;
/** /**
* 物料成本计算任务 * 物料成本计算任务
@@ -62,9 +54,9 @@ public class MaterialCostTask extends AbstractTask {
@Override @Override
public void handle(TaskCallBack taskCallBack) throws TaskException { public void handle(TaskCallBack taskCallBack) throws TaskException {
log.info("Full EmptyTask parameters: {}", taskRequest); log.info("Full EmptyTask parameters: {}", taskExecutionContext);
try { try {
StandardCostService.materialCostTask(taskRequest); StandardCostService.materialCostTask(taskExecutionContext);
} catch (Exception e) { } catch (Exception e) {
//运行失败退出 //运行失败退出
setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE); setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE);
@@ -17,6 +17,7 @@
package com.zzsmart.qomo.kn.cost.manage.plugin.materialinput; package com.zzsmart.qomo.kn.cost.manage.plugin.materialinput;
import com.zzsmart.qomo.kn.cost.manage.plugin.StandardCostService;
import com.zzsmart.qomo.plugin.task.api.*; import com.zzsmart.qomo.plugin.task.api.*;
import com.zzsmart.qomo.plugin.task.api.parameters.AbstractParameters; import com.zzsmart.qomo.plugin.task.api.parameters.AbstractParameters;
@@ -1,169 +0,0 @@
package com.zzsmart.qomo.kn.cost.manage.plugin.materialinput;
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.mapper.CostMaterialBomMapper;
import com.zzsmart.qomo.kn.cost.manage.service.CostMaterialProcessHoursService;
import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostResultValueService;
import com.zzsmart.qomo.kn.cost.manage.service.IHourRateService;
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 javax.annotation.PostConstruct;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
@Slf4j
public class StandardCostService {
/**
* 物料BOM信息
*/
@Autowired
CostMaterialBomMapper costMaterialBomMapper;
/**
* 小时费率
*/
@Autowired
IHourRateService iHourRateService;
/**
* 工序
*/
@Autowired
CostMaterialProcessHoursService costMaterialProcessHoursService;
/**
* 标准成本计算结果
*/
@Autowired
IAppSceneCostResultValueService iAppSceneCostResultValueService;
public static StandardCostService standardCostService;
@PostConstruct
public void init() {
standardCostService = this;
standardCostService.costMaterialBomMapper = this.costMaterialBomMapper;
standardCostService.iHourRateService = this.iHourRateService;
standardCostService.costMaterialProcessHoursService = this.costMaterialProcessHoursService;
standardCostService.iAppSceneCostResultValueService = this.iAppSceneCostResultValueService;
}
/**
* 物料编号输入任务
*/
public static void materialInputTask(TaskExecutionContext parameters) {
try {
//获取最上层的物料号
String materialCode = "";
//获取任务类型
String taskType = "";
//获取任务代码
String taskCode = "";
//获取流程id
String flowInstanceId = "1";
//1.查询出所有满足物料编号的物料(BOM物料)
String sql = "select * from app_scene_cost_material_bom ";
List<CostMaterialBom> list = standardCostService.costMaterialBomMapper.customSelect(sql);
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(materialCode).marterialNo(material.getMaterialCode()).parentMarterialNo(material.getParentMaterialCode()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).build();
standardCostService.iAppSceneCostResultValueService.save(appSceneCostResultValue);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* 物料成本任务
*/
public static void materialCostTask(TaskExecutionContext parameters) {
//1.查询出物料编号对应的下所有的BOM信息
//2.计算出所有的单个物料的物料成本
//2.1查询出物料的单价和采购数量
//2.2计算出物料成本并存储到成本结果数据表中
}
/**
* 人工成本任务
*/
public static void laborCostTask(TaskExecutionContext parameters) {
try {
//获取最上层的物料号
String topMaterialCode = "";
//获取任务类型
String taskType = "";
//获取上一节点任务类型
String lastTaskType = "LaborCost";
//获取任务代码
String taskCode = "";
//获取流程id
String flowInstanceId = "1";
//人工费率
BigDecimal laborRate = new BigDecimal("0.0");
//1.查询出物料编号对应的下所有的BOM信息
List<AppSceneCostResultValue> list = standardCostService.iAppSceneCostResultValueService.getResultValueByTopMaterialNo(topMaterialCode, lastTaskType, flowInstanceId);
//2.计算出所有的单个物料的人工成本
//2.1查询出物料的人员工时和人工小时费率(涉及:小时费率表和工序表)
List<String> MarterialNoList = new ArrayList<>();
if (list != null && list.size() > 0) {
MarterialNoList = list.stream().filter(s -> s.getMarterialNo() != null).map(AppSceneCostResultValue::getMarterialNo).collect(Collectors.toList());
}
//查询工序工时
Map<String, List<CostMaterialProcessHours>> processHoursMap = standardCostService.costMaterialProcessHoursService.getProcessHoursByMaterialNo(MarterialNoList);
for (int i = 0; i < list.size(); i++) {
AppSceneCostResultValue appSceneCostResultValue = list.get(i);
String marterialNo = appSceneCostResultValue.getMarterialNo();
if (marterialNo != null) {
BigDecimal totalLaborCost = new BigDecimal("0.0");
List<CostMaterialProcessHours> costMaterialProcessHours = processHoursMap.get(marterialNo);
if (costMaterialProcessHours != null && costMaterialProcessHours.size() > 0) {
for (int j = 0; j < costMaterialProcessHours.size(); j++) {
CostMaterialProcessHours processHours = costMaterialProcessHours.get(j);
BigDecimal laborHours = processHours.getLaborHours();
//计算总人工成本
totalLaborCost.add(laborHours.multiply(laborRate));
}
}
//2.2计算出人工成本并存储到成本结果数据表中
AppSceneCostResultValue resultValue = AppSceneCostResultValue.builder().belongTopMaterialNo(topMaterialCode).marterialNo(marterialNo).parentMarterialNo(appSceneCostResultValue.getParentMarterialNo()).taskType(taskType).taskCode(taskCode).flowInstanceId(flowInstanceId).countValue(totalLaborCost + "").build();
standardCostService.iAppSceneCostResultValueService.save(resultValue);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* 制造费用成本任务
*/
public static void manufacturingCostTask(TaskExecutionContext parameters) {
//1.查询出物料编号对应的下所有的BOM信息
//2.根据费用类型进行不同的费用计算
//2.1机器折旧费(机器工时*费率)
//2.2机物料消耗费(辅料工时*费率)
//2.3水电费(燃动力工时*费率)
//2.4其他制费(其他工时*费率)
//2.5物流费((机器折旧+机物料消耗+水电费+其他制费)*10.16%)
}
/**
* 标准成本计算任务
*/
public static void standardCostTask(TaskExecutionContext parameters) {
//1.查询出物料编号对应的下所有的BOM信息
//2.计算出所有的单个物料的本阶的标准成本(标准成本=物料成本+人工成本+制造费用)
//3.计算出所有的单个物料的累计标准成本
}
}
@@ -17,12 +17,9 @@
package com.zzsmart.qomo.kn.cost.manage.plugin.standardcost; package com.zzsmart.qomo.kn.cost.manage.plugin.standardcost;
import com.zzsmart.qomo.kn.cost.manage.mapper.CostMaterialBomMapper; import com.zzsmart.qomo.kn.cost.manage.plugin.StandardCostService;
import com.zzsmart.qomo.kn.cost.manage.plugin.materialinput.StandardCostService;
import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostResultValueService;
import com.zzsmart.qomo.plugin.task.api.*; import com.zzsmart.qomo.plugin.task.api.*;
import com.zzsmart.qomo.plugin.task.api.parameters.AbstractParameters; import com.zzsmart.qomo.plugin.task.api.parameters.AbstractParameters;
import org.springframework.beans.factory.annotation.Autowired;
/** /**
* 标准成本计算任务 * 标准成本计算任务
@@ -1,8 +1,13 @@
package com.zzsmart.qomo.kn.cost.manage.service; package com.zzsmart.qomo.kn.cost.manage.service;
import com.zzsmart.qomo.kn.cost.manage.entity.CostMaterialProcessHours;
import com.zzsmart.qomo.kn.cost.manage.entity.CostPurchasePrice; import com.zzsmart.qomo.kn.cost.manage.entity.CostPurchasePrice;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/** /**
* <p> * <p>
* 物料采购单价 服务类 * 物料采购单价 服务类
@@ -12,5 +17,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @since 2024-06-19 * @since 2024-06-19
*/ */
public interface CostPurchasePriceService extends IService<CostPurchasePrice> { public interface CostPurchasePriceService extends IService<CostPurchasePrice> {
/**
* 查询满足物料编号的最低采购价
*/
Map<String, BigDecimal> getMinCostPurchasePriceByMaterialNo(List<String> materialNos);
} }
@@ -17,5 +17,5 @@ public interface IAppSceneCostResultValueService extends IService<AppSceneCostRe
* @param topMaterialCode * @param topMaterialCode
* @return * @return
*/ */
List<AppSceneCostResultValue> getResultValueByTopMaterialNo(String topMaterialCode,String lastTaskType,String flowInstanceId); List<AppSceneCostResultValue> getResultValueByTopMaterialNo(String topMaterialCode,String taskType,String flowInstanceId);
} }
@@ -39,6 +39,9 @@ public class AppSceneCostResultValueServiceImpl extends ServiceImpl<AppSceneCost
if (topMaterialCode != null && !topMaterialCode.equals("") && lastTaskType != null && !lastTaskType.equals("") && flowInstanceId != null && !flowInstanceId.equals("")) { if (topMaterialCode != null && !topMaterialCode.equals("") && lastTaskType != null && !lastTaskType.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("task_type", lastTaskType).eq("flow_instance_id", flowInstanceId);
result = appSceneCostResultValueMapper.selectList(queryWrapper); 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);
result = appSceneCostResultValueMapper.selectList(queryWrapper);
} }
return result; return result;
} }
@@ -1,11 +1,21 @@
package com.zzsmart.qomo.kn.cost.manage.service.impl; package com.zzsmart.qomo.kn.cost.manage.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzsmart.qomo.kn.cost.manage.entity.CostMaterialProcessHours;
import com.zzsmart.qomo.kn.cost.manage.entity.CostPurchasePrice; import com.zzsmart.qomo.kn.cost.manage.entity.CostPurchasePrice;
import com.zzsmart.qomo.kn.cost.manage.mapper.CostPurchasePriceMapper; import com.zzsmart.qomo.kn.cost.manage.mapper.CostPurchasePriceMapper;
import com.zzsmart.qomo.kn.cost.manage.service.CostPurchasePriceService; import com.zzsmart.qomo.kn.cost.manage.service.CostPurchasePriceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* <p> * <p>
* 物料采购单价 服务实现类 * 物料采购单价 服务实现类
@@ -16,5 +26,26 @@ import org.springframework.stereotype.Service;
*/ */
@Service @Service
public class CostPurchasePriceServiceImpl extends ServiceImpl<CostPurchasePriceMapper, CostPurchasePrice> implements CostPurchasePriceService { public class CostPurchasePriceServiceImpl extends ServiceImpl<CostPurchasePriceMapper, CostPurchasePrice> implements CostPurchasePriceService {
@Autowired
CostPurchasePriceMapper costPurchasePriceMapper;
/**
* 查询满足物料编号的最低采购价
*
* @param materialNos
*/
@Override
public Map<String, BigDecimal> getMinCostPurchasePriceByMaterialNo(List<String> materialNos) {
Map<String, BigDecimal> map = new HashMap<>();
QueryWrapper<CostPurchasePrice> queryWrapper = new QueryWrapper();
if (materialNos != null && materialNos.size() > 0) {
queryWrapper.in("material_code", materialNos);
List<CostPurchasePrice> costPurchasePrices = costPurchasePriceMapper.selectList(queryWrapper);
for (int i = 0; i < costPurchasePrices.size(); i++) {
CostPurchasePrice costPurchasePrice = costPurchasePrices.get(i);
map.put(costPurchasePrice.getMaterialCode(), costPurchasePrice.getMinPurchasePrice());
}
}
return map;
}
} }
@@ -0,0 +1,37 @@
package com.zzsmart.qomo.kn.cost.manage.vo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FlowTaskInfoVO {
/**
* 最顶层物料编号
*/
private String topMaterialCode;
/**
* 获取任务类型
*/
private String taskType;
/**
* 获取任务代码
*/
private String taskCode;
/**
* 获取流程id
*/
private String flowInstanceId;
/**
* SQL查询语句
*/
private String sqlString;
/**
* 费用类别
*/
private String feeType;
}