1、EBOM 生成PBOM 生成变更通知单

2、PBOM发布 生成变更通知单
This commit is contained in:
10001392 2024-07-30 16:11:50 +08:00
parent 769c083cdd
commit bdce2a4421
15 changed files with 772 additions and 13 deletions

View File

@ -73,6 +73,9 @@ public class EbomApi extends BaseApi {
private BomNewPbomParentService bomNewPbomParentService;
private NotNullAnnotationPlugin notNullPlugin;
@Resource
private BomNewNoticeNumService bomNewNoticeNumService;
@PostMapping("workDetailsListByPage")
@ApiOperation("Ebom-工作明细列表")
@ -532,4 +535,26 @@ public class EbomApi extends BaseApi {
public ResultVO<List<CheckBomProjectTypeVO>> checkProjectType(@Valid @RequestBody @NotEmpty List<Long> bomRowIds) {
return ResultVO.success(bomNewEbomParentService.checkProjectType(bomRowIds));
}
@PostMapping("generateNoticeNum")
@ApiOperation("生成变更通知单")
public ResultVO<Boolean> generateNoticeNum(@RequestBody EBomUpgradeChangesParamDTO param) {
VUtils.isTure(CollUtil.isEmpty(param.getBomRowIds())).throwMessage("请选择要生成变更通知单的物料");
VUtils.isTure(ObjectUtil.isEmpty(param.getNumType())).throwMessage("变更通知单单据类型不能为空");
bomNewEbomParentService.generateNoticeNum(param);
return ResultVO.success(true);
}
/**
* OA审批结束后回调更新变更通知单字段
* @param paramDto
* @return
*/
@PostMapping("updateNoticeNumOaStatus")
public ResultVO<Boolean> updateNoticeNumOaStatus(@RequestBody OaNoticeNumParamDto paramDto) {
VUtils.isTure(ObjectUtil.isEmpty(paramDto.getInstId())).throwMessage("instId不能为空");
bomNewNoticeNumService.updateNoticeNumOaStatus(paramDto);
return ResultVO.success(true);
}
}

View File

@ -2,6 +2,7 @@ package com.nflg.product.bomnew.api.user;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mzt.logapi.context.LogRecordContext;
import com.mzt.logapi.starter.annotation.LogRecord;
@ -361,4 +362,13 @@ public class PBomApi extends BaseApi {
public ResultVO<List<OperationErrorMsgVO>> getSapError(@Valid @RequestParam("rowId") @NotNull Long rowId) {
return ResultVO.success(bomNewPbomParentService.getSapError(rowId));
}
@PostMapping("generateNoticeNum")
@ApiOperation("生成变更通知单")
public ResultVO<Boolean> generateNoticeNum(@RequestBody EBomUpgradeChangesParamDTO param) {
VUtils.isTure(CollUtil.isEmpty(param.getBomRowIds())).throwMessage("请选择要生成变更通知单的物料");
VUtils.isTure(ObjectUtil.isEmpty(param.getNumType())).throwMessage("变更通知单单据类型不能为空");
bomNewPbomParentService.generateNoticeNum(param);
return ResultVO.success(true);
}
}

View File

@ -105,12 +105,8 @@ public class NacosConfig {
@Value("${crm.password}")
private String crmPassword;
@Value("${oa.bom.noticeNum.url}")
private String bomNoticeUrl;
public static NacosConfig getNacosConfig(){
return SpringContextUtils.getBean(NacosConfig.class);

View File

@ -0,0 +1,11 @@
package com.nflg.product.bomnew.mapper.master;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nflg.product.bomnew.pojo.entity.BomNewNoticeNumDetailEntity;
/**
* @author makejava
*/
public interface BomNewNoticeNumDetailMapper extends BaseMapper<BomNewNoticeNumDetailEntity> {
}

View File

@ -0,0 +1,11 @@
package com.nflg.product.bomnew.mapper.master;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nflg.product.bomnew.pojo.entity.BomNewNoticeNumEntity;
/**
* @author makejava
*/
public interface BomNewNoticeNumMapper extends BaseMapper<BomNewNoticeNumEntity> {
}

View File

@ -18,4 +18,7 @@ public class EBomUpgradeChangesParamDTO {
@ApiModelProperty("通知单号")
private String noticeNums;
@ApiModelProperty("单据类型 1=新建通知单 2=关联已有通知单")
private Integer numType;
}

View File

@ -0,0 +1,12 @@
package com.nflg.product.bomnew.pojo.dto;
import lombok.Data;
@Data
public class OaNoticeNumParamDto {
private Long instId;
private String receiveDept;
}

View File

@ -0,0 +1,84 @@
package com.nflg.product.bomnew.pojo.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* t_bom_new_notice_num_detail
* 变更通知单明细表
*
* @author makejava
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "com-nflg-product-bomnew-pojo-main-entity-BomNewNoticeNumDetailEntity")
@TableName(value = "t_bom_new_notice_num_detail")
public class BomNewNoticeNumDetailEntity implements Serializable {
/**
* 行ID 雪花
*/
@TableId(value = "row_id", type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "行ID 雪花")
private Long rowId;
/**
* 行ID 雪花抬头行ID
*/
@ApiModelProperty(value = "header_row_id")
private Long headerRowId;
/**
* 物料编码
*/
@TableField(value = "material_no")
@ApiModelProperty(value = "物料编码")
private String materialNo;
/**
* 图号
*/
@TableField(value = "drawing_no")
@ApiModelProperty(value = "图号")
private String drawingNo;
/**
* 名称
*/
@TableField(value = "material_name")
@ApiModelProperty(value = "名称")
private String materialName;
/**
* 上级编码
*/
@TableField(value = "parent_material_no")
@ApiModelProperty(value = "上级编码")
private String parentMaterialNo;
/**
* 变更内容 1=BOM物料增加 2=BOM物料减少 3=BOM物料替换 4=BOM物料数量变更 5=BOM项目类别变更
*/
@TableField(value = "change_type")
@ApiModelProperty(value = "变更内容 1=BOM物料增加 2=BOM物料减少 3=BOM物料替换 4=BOM物料数量变更 5=BOM项目类别变更")
private Integer changeType;
/**
* 变更内容 1=BOM物料增加 2=BOM物料减少 3=BOM物料替换 4=BOM物料数量变更 5=BOM项目类别变更
*/
@TableField(value = "change_content")
@ApiModelProperty(value = "变更内容 1=BOM物料增加 2=BOM物料减少 3=BOM物料替换 4=BOM物料数量变更 5=BOM项目类别变更")
private String changeContent;
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,135 @@
package com.nflg.product.bomnew.pojo.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* t_bom_new_notice_num
* 变更通知单表
*
* @author makejava
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "com-nflg-product-bomnew-pojo-main-entity-BomNewNoticeNumEntity")
@TableName(value = "t_bom_new_notice_num")
public class BomNewNoticeNumEntity implements Serializable {
/**
* 行ID 雪花
*/
@TableId(value = "row_id", type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "行ID 雪花")
private Long rowId;
/**
* 抬头物料编码
*/
@TableField(value = "material_no")
@ApiModelProperty(value = "抬头物料编码")
private String materialNo;
/**
* 来源行ID(EBOM或者PBOM)
*/
@TableField(value = "source_row_id")
@ApiModelProperty(value = "来源行ID(EBOM或者PBOM)")
private Long sourceRowId;
/**
* 来源类型 1=EBOM 2=PBOM
*/
@TableField(value = "source_type")
@ApiModelProperty(value = "来源类型 1=EBOM 2=PBOM")
private Integer sourceType;
/**
* 单据类型 1=新建通知单 2=关联已有通知单
*/
@TableField(value = "num_type")
@ApiModelProperty(value = "单据类型 1=新建通知单 2=关联已有通知单")
private Integer numType;
/**
* 通知单号
*/
@TableField(value = "notice_num")
@ApiModelProperty(value = "通知单号")
private String noticeNum;
/**
* 升版说明
*/
@TableField(value = "change_desc")
@ApiModelProperty(value = "升版说明")
private String changeDesc;
/**
* 通知内容
*/
@TableField(value = "notice_content")
@ApiModelProperty(value = "通知内容")
private String noticeContent;
/**
* 通知标题
*/
@TableField(value = "notice_title")
@ApiModelProperty(value = "通知标题")
private String noticeTitle;
/**
* 流程ID
*/
@TableField(value = "oa_row_id")
@ApiModelProperty(value = "流程ID")
private Long oaRowId;
/**
* 流程状态 1=待提交 2=审批中 3=已结束
*/
@TableField(value = "oa_status")
@ApiModelProperty(value = "流程状态 1=待提交 2=审批中 3=已结束")
private Integer oaStatus;
/**
* 接收部门
*/
@TableField(value = "receive_dept")
@ApiModelProperty(value = "接收部门")
private String receiveDept;
/**
* 创建人名称
*/
@TableField(value = "created_name")
@ApiModelProperty(value = "创建人名称")
private String createdName;
/**
* 创建人编码
*/
@TableField(value = "created_by")
@ApiModelProperty(value = "创建人编码")
private String createdBy;
/**
* 创建时间
*/
@TableField(value = "created_time")
@ApiModelProperty(value = "创建时间")
private LocalDateTime createdTime;
private static final long serialVersionUID = 1L;
}

View File

@ -107,7 +107,14 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
@Resource
private BomNewSapErrorMsgService bomNewSapErrorMsgService;
@Resource
private BomNewEbomParentFormalService bomNewEbomParentFormalService;
@Resource
private BomNewEbomChildFormalService bomNewEbomChildFormalService;
@Resource
private BomNewNoticeNumService bomNewNoticeNumService;
@Resource
private BomNewNoticeNumDetailService bomNewNoticeNumDetailService;
public List<BomNewEbomParentVO> getParentChild( Long rowId) {
@ -1229,7 +1236,9 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
newParent.setRowId(IdWorker.getId());
newParent.setLastVersionIs(1);
newParent.setCurrentVersion(VersionUtil.getNextVersionForSmallVersion(parent.getCurrentVersion()));
newParent.setExceptionStatus(StrUtil.isBlank(paramDTO.getNoticeNums())? EBomExceptionStatusEnum.EXCEPT_NO_11.getValue():EBomExceptionStatusEnum.OK.getValue());
// newParent.setExceptionStatus(StrUtil.isBlank(paramDTO.getNoticeNums())? EBomExceptionStatusEnum.EXCEPT_NO_11.getValue():EBomExceptionStatusEnum.OK.getValue());
// 20240728 变更通知单改到生成PBOMEBOM通知单和PBOM发布PBOM通知单填写了
newParent.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue());
newParent.setChangeDesc(paramDTO.getChangeDesc());
newParent.setNoticeNums(paramDTO.getNoticeNums());
newParent.setStatus(EBomStatusEnum.WAIT_CHECK.getValue());
@ -2940,4 +2949,154 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
.update();
}
}
/**
* 生成变更通知单
* @param param
*/
@Transactional(rollbackFor = Exception.class)
public void generateNoticeNum(EBomUpgradeChangesParamDTO param) {
List<BomNewEbomParentFormalEntity> parentList = bomNewEbomParentFormalService.lambdaQuery().in(BomNewEbomParentFormalEntity::getRowId, param.getBomRowIds()).list();
for (int i = 0; i < parentList.size(); i++) {
BomNewEbomParentFormalEntity parent = parentList.get(i);
List<BomNewEbomParentFormalEntity> versionList = bomNewEbomParentFormalService.lambdaQuery().eq(BomNewEbomParentFormalEntity::getMaterialNo, parent.getMaterialNo()).orderByDesc(BomNewEbomParentFormalEntity::getRowId).list();
// 只有一个版本无需生成变更通知单
if (versionList.size() == 1) {
log.info("物料编码:{}只有一个版本,无需生成变更通知单", parent.getMaterialNo());
continue;
}
BomNewEbomParentFormalEntity newestParent = versionList.get(0); // 最新版
BomNewEbomParentFormalEntity lastParent = versionList.get(1); // 上一版本
BomNewNoticeNumEntity saveEntity = new BomNewNoticeNumEntity();
saveEntity.setRowId(IdWorker.getId());
saveEntity.setMaterialNo(newestParent.getMaterialNo());
saveEntity.setSourceRowId(newestParent.getRowId());
saveEntity.setSourceType(1);
saveEntity.setNumType(param.getNumType());
saveEntity.setChangeDesc(param.getChangeDesc());
saveEntity.setNoticeContent(newestParent.getMaterialDesc() + "BOM变更由EBOM发起详见下方明细");
saveEntity.setNoticeTitle("关于" + newestParent.getMaterialDesc() + "BOM变更的通知");
saveEntity.setOaStatus(1); // 待提交
saveEntity.setCreatedName(SessionUtil.getRealName());
saveEntity.setCreatedBy(SessionUtil.getUserCode());
saveEntity.setCreatedTime(LocalDateTime.now());
// 关联已有通知单
if (param.getNumType() == 2) {
saveEntity.setNoticeNum(param.getNoticeNums());
} else {
saveEntity.setNoticeNum(bomNewNoticeNumService.generateNoticeNum());
}
bomNewNoticeNumService.save(saveEntity);
// 新建通知单
if (param.getNumType() == 1) {
List<BomNewEbomChildFormalEntity> newestChildList = bomNewEbomChildFormalService.lambdaQuery().eq(BomNewEbomChildFormalEntity::getParentRowId, newestParent.getRowId()).list();
List<BomNewEbomChildFormalEntity> lastChildList = bomNewEbomChildFormalService.lambdaQuery().eq(BomNewEbomChildFormalEntity::getParentRowId, lastParent.getRowId()).list();
List<String> newestMaterialNos = newestChildList.stream().map(BomNewEbomChildFormalEntity::getMaterialNo).collect(Collectors.toList());
List<String> lastMaterialNos = lastChildList.stream().map(BomNewEbomChildFormalEntity::getMaterialNo).collect(Collectors.toList());
// 假设旧版 [1,2,3,4,5] 新版 [3,4,5,6,7]
// 旧版和新版的交集 -> [3,4,5]
List<String> intersection =new ArrayList<>(lastMaterialNos);
intersection.retainAll(newestMaterialNos);
// 旧版相对于新版的差集 -> [1,2]
List<String> difference = new ArrayList<>(lastMaterialNos);
difference.removeAll(newestMaterialNos);
// 新版相对于旧版的差集 -> [6,7]
List<String> difference2 = new ArrayList<>(newestMaterialNos);
difference2.removeAll(lastMaterialNos);
List<BomNewNoticeNumDetailEntity> saveDetailList = new ArrayList<>();
// 物料变更的场景有5种物料增加物料减少物料替代改物料数量改物料项目类别
// 两个差集元素的个数不等则认为 difference2 的物料是增加difference 的物料是减少
if (difference.size() != difference2.size()) {
difference.forEach(remove -> {
BomNewEbomChildFormalEntity removeEntity = lastChildList.stream().filter(item -> item.getMaterialNo().equals(remove)).findFirst().orElse(null);
if (ObjectUtil.isNotEmpty(removeEntity)) {
BomNewNoticeNumDetailEntity saveDetail = new BomNewNoticeNumDetailEntity();
saveDetail.setRowId(IdWorker.getId());
saveDetail.setHeaderRowId(saveEntity.getRowId());
saveDetail.setMaterialNo(removeEntity.getMaterialNo());
saveDetail.setDrawingNo(removeEntity.getDrawingNo());
saveDetail.setMaterialName(removeEntity.getMaterialName());
saveDetail.setParentMaterialNo("");
saveDetail.setChangeType(2);
saveDetail.setChangeContent("BOM物料减少");
saveDetailList.add(saveDetail);
}
});
difference2.forEach(add -> {
BomNewEbomChildFormalEntity addEntity = newestChildList.stream().filter(item -> item.getMaterialNo().equals(add)).findFirst().orElse(null);
if (ObjectUtil.isNotEmpty(addEntity)) {
BomNewNoticeNumDetailEntity saveDetail = new BomNewNoticeNumDetailEntity();
saveDetail.setRowId(IdWorker.getId());
saveDetail.setHeaderRowId(saveEntity.getRowId());
saveDetail.setMaterialNo(addEntity.getMaterialNo());
saveDetail.setDrawingNo(addEntity.getDrawingNo());
saveDetail.setMaterialName(addEntity.getMaterialName());
saveDetail.setParentMaterialNo("");
saveDetail.setChangeType(1);
saveDetail.setChangeContent("BOM物料增加");
saveDetailList.add(saveDetail);
}
});
} else {
// 个数相等则认为 difference2 difference 的替代物料
if (CollectionUtil.isNotEmpty(difference2)) {
difference2.forEach(replace -> {
BomNewEbomChildFormalEntity replaceEntity = newestChildList.stream().filter(item -> item.getMaterialNo().equals(replace)).findFirst().orElse(null);
if (ObjectUtil.isNotEmpty(replaceEntity)) {
BomNewNoticeNumDetailEntity saveDetail = new BomNewNoticeNumDetailEntity();
saveDetail.setRowId(IdWorker.getId());
saveDetail.setHeaderRowId(saveEntity.getRowId());
saveDetail.setMaterialNo(replaceEntity.getMaterialNo());
saveDetail.setDrawingNo(replaceEntity.getDrawingNo());
saveDetail.setMaterialName(replaceEntity.getMaterialName());
saveDetail.setParentMaterialNo("");
saveDetail.setChangeType(3);
saveDetail.setChangeContent("BOM物料替换");
saveDetailList.add(saveDetail);
}
});
}
}
// 遍历交集如果旧版和新版物料的数量不等则认为是改物料数量如果旧版和新版物料的项目类别不一致则认为是改物料项目类别
intersection.forEach(entity -> {
BomNewEbomChildFormalEntity lastChild = lastChildList.stream().filter(item -> item.getMaterialNo().equals(entity)).findFirst().orElse(null);
BomNewEbomChildFormalEntity newestChild = newestChildList.stream().filter(item -> item.getMaterialNo().equals(entity)).findFirst().orElse(null);
if (ObjectUtil.isNotEmpty(newestChild.getNum()) && newestChild.getNum().compareTo(lastChild.getNum()) != 0) {
BomNewNoticeNumDetailEntity saveDetail = new BomNewNoticeNumDetailEntity();
saveDetail.setRowId(IdWorker.getId());
saveDetail.setHeaderRowId(saveEntity.getRowId());
saveDetail.setMaterialNo(newestChild.getMaterialNo());
saveDetail.setDrawingNo(newestChild.getDrawingNo());
saveDetail.setMaterialName(newestChild.getMaterialName());
saveDetail.setParentMaterialNo("");
saveDetail.setChangeType(4);
saveDetail.setChangeContent("BOM物料数量变更");
saveDetailList.add(saveDetail);
}
if (ObjectUtil.isNotEmpty(newestChild.getProjectType()) && !newestChild.getProjectType().equals(lastChild.getProjectType())) {
BomNewNoticeNumDetailEntity saveDetail = new BomNewNoticeNumDetailEntity();
saveDetail.setRowId(IdWorker.getId());
saveDetail.setHeaderRowId(saveEntity.getRowId());
saveDetail.setMaterialNo(newestChild.getMaterialNo());
saveDetail.setDrawingNo(newestChild.getDrawingNo());
saveDetail.setMaterialName(newestChild.getMaterialName());
saveDetail.setParentMaterialNo("");
saveDetail.setChangeType(5);
saveDetail.setChangeContent("BOM项目类别变更");
saveDetailList.add(saveDetail);
}
});
bomNewNoticeNumDetailService.saveBatch(saveDetailList);
bomNewNoticeNumService.sync2Oa(saveEntity, saveDetailList);
}
}
}
}

View File

@ -0,0 +1,17 @@
package com.nflg.product.bomnew.service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nflg.product.bomnew.mapper.master.BomNewNoticeNumDetailMapper;
import com.nflg.product.bomnew.pojo.entity.BomNewNoticeNumDetailEntity;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* @author makejava
*/
@Service
public class BomNewNoticeNumDetailService extends ServiceImpl<BomNewNoticeNumDetailMapper, BomNewNoticeNumDetailEntity> {
}

View File

@ -0,0 +1,126 @@
package com.nflg.product.bomnew.service;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.base.core.exception.NflgBusinessException;
import com.nflg.product.bomnew.config.NacosConfig;
import com.nflg.product.bomnew.mapper.master.BomNewNoticeNumMapper;
import com.nflg.product.bomnew.pojo.dto.OaNoticeNumParamDto;
import com.nflg.product.bomnew.pojo.dto.OaResult;
import com.nflg.product.bomnew.pojo.entity.BomNewNoticeNumDetailEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewNoticeNumEntity;
import com.nflg.product.bomnew.util.HttpUtils;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import nflg.product.common.constant.STATE;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author makejava
*/
@Slf4j
@Service
public class BomNewNoticeNumService extends ServiceImpl<BomNewNoticeNumMapper, BomNewNoticeNumEntity> {
@Synchronized
@Transactional(rollbackFor = Exception.class)
public String generateNoticeNum() {
// 通知单号格式"MJT"+8位数字例如MJT24070801
// 意思是2024年7月8日第1份通知单
// 如果01到99共100个流水号不够用就要考虑升级到3位流水号
SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
String today = sdf.format(new Date());
BomNewNoticeNumEntity one = this.lambdaQuery().like(BomNewNoticeNumEntity::getNoticeNum, "MJT" + today)
.orderByDesc(BomNewNoticeNumEntity::getCreatedTime).last(" limit 1").one();
if (ObjectUtil.isNotEmpty(one)) {
String numStr = one.getNoticeNum().substring(9);
int thisNum = Integer.parseInt(numStr) + 1;
String thisNumStr = "";
if (thisNum <= 99) {
thisNumStr = String.format("%02d", thisNum);
} else if (thisNum <= 999) {
thisNumStr = String.format("%03d", thisNum);
} else {
log.info("【MJT生成流水号】超限{}", thisNum);
}
return "MJT" + today + thisNumStr;
}
return "MJT" + today + "01";
}
public void sync2Oa(BomNewNoticeNumEntity saveEntity, List<BomNewNoticeNumDetailEntity> saveDetailList) {
if (CollectionUtil.isEmpty(saveDetailList)) {
return;
}
String employeeNo = SessionUtil.getUserCode();
String summary = NacosConfig.getNacosConfig().getSummary();
String url = NacosConfig.getNacosConfig().getBomNoticeUrl();
Map<String, Object> main = new HashMap<>();
main.put("employeeNo", employeeNo);
main.put("summary", summary);
main.put("noticeNum", saveEntity.getNoticeNum());
main.put("noticeContent", saveEntity.getNoticeContent());
List<Map<String, Object>> bomList = new ArrayList<>(saveDetailList.size());
saveDetailList.forEach(saveDetail -> {
Map<String, Object> bom = new HashMap<>();
bom.put("Fth", saveDetail.getDrawingNo()); // 图号
bom.put("Fbm", saveDetail.getMaterialNo()); // 编码
bom.put("Fmc", saveDetail.getMaterialName()); // 名称
bom.put("Fsjbm", saveDetail.getParentMaterialNo()); // 上级编码
bom.put("Fbgrn", saveDetail.getChangeContent()); // 变更内容
bom.put("F", "1"); // 改BOM 1是 2否
bomList.add(bom);
});
main.put("bomList", bomList);
log.info("发起变更通知单-JSON" + JSONArray.toJSONString(main));
HttpUtils httpUtils = new HttpUtils();
try {
String reqResult = httpUtils.doPost(url, JSON.toJSONString(main));
JSONObject jsonObject = JSONObject.parseObject(reqResult);
log.info("发起变更通知单-OA返回" + JSONObject.toJSONString(jsonObject));
Boolean postResult = jsonObject.getBoolean("success");
if (postResult) {
String resultData = jsonObject.getString("data");
List<OaResult> da = JSON.parseArray(resultData, OaResult.class);
handlerResult(da, saveEntity);
} else {
String message = jsonObject.getString("message");
message = StrUtil.isNotBlank(message) ? message : "";
throw new NflgBusinessException(STATE.BusinessError, "同步OA出错".concat(message));
}
} catch (Exception ex) {
throw new NflgBusinessException(STATE.BusinessError, "同步OA出错" + ex.getMessage());
}
}
private void handlerResult(List<OaResult> da, BomNewNoticeNumEntity saveEntity) {
if (CollectionUtil.isNotEmpty(da)) {
BomNewNoticeNumEntity updateEntity = new BomNewNoticeNumEntity();
updateEntity.setRowId(saveEntity.getRowId());
updateEntity.setOaRowId(da.get(0).getInstId());
updateEntity.setOaStatus(2);
this.updateById(updateEntity);
}
}
public void updateNoticeNumOaStatus(OaNoticeNumParamDto paramDto) {
log.info("OA审批结束后回调更新变更通知单字段: {}", JSON.toJSONString(paramDto));
this.lambdaUpdate().eq(BomNewNoticeNumEntity::getOaRowId, paramDto.getInstId())
.set(BomNewNoticeNumEntity::getReceiveDept, paramDto.getReceiveDept())
.set(BomNewNoticeNumEntity::getOaStatus, 3)
.update();
}
}

View File

@ -2,9 +2,11 @@ package com.nflg.product.bomnew.service;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
@ -110,11 +112,14 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
@Resource
private BomNewSapErrorMsgService bomNewSapErrorMsgService;
@Resource
private BomNewPbomParentFormalService bomNewPbomParentFormalService;
@Resource
private BomNewPbomChildFormalService bomNewPbomChildFormalService;
@Resource
private BomNewNoticeNumService bomNewNoticeNumService;
@Resource
private BomNewNoticeNumDetailService bomNewNoticeNumDetailService;
/**
* pbom-工作列表
@ -1501,4 +1506,161 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
public List<BomNewPbomParentVO> getReverseBoms(Long parentRowId) {
return this.getBaseMapper().getReverseBoms(parentRowId);
}
/**
* 生成变更通知单
* @param param
*/
@Transactional(rollbackFor = Exception.class)
public void generateNoticeNum(EBomUpgradeChangesParamDTO param) {
List<BomNewPbomParentFormalEntity> parentList = bomNewPbomParentFormalService.lambdaQuery().in(BomNewPbomParentFormalEntity::getRowId, param.getBomRowIds()).list();
for (int i = 0; i < parentList.size(); i++) {
BomNewPbomParentFormalEntity parent = parentList.get(i);
List<BomNewPbomParentFormalEntity> versionList = bomNewPbomParentFormalService.lambdaQuery().eq(BomNewPbomParentFormalEntity::getMaterialNo, parent.getMaterialNo()).orderByDesc(BomNewPbomParentFormalEntity::getRowId).list();
// 只有一个版本无需生成变更通知单
if (versionList.size() == 1) {
log.info("物料编码:{}只有一个版本,无需生成变更通知单", parent.getMaterialNo());
continue;
}
// 已经在 EBOM 发起过变更通知单PBOM 无需再生成变更通知单
List<BomNewNoticeNumEntity> exists = bomNewNoticeNumService.lambdaQuery().eq(BomNewNoticeNumEntity::getSourceRowId, versionList.get(0).getSourceRowId()).list();
if (CollectionUtil.isNotEmpty(exists)) {
log.info("物料编码:{}已经在EBOM生成过变更通知单无需再生成变更通知单", parent.getMaterialNo());
continue;
}
BomNewPbomParentFormalEntity newestParent = versionList.get(0); // 最新版
BomNewPbomParentFormalEntity lastParent = versionList.get(1); // 上一版本
BomNewNoticeNumEntity saveEntity = new BomNewNoticeNumEntity();
saveEntity.setRowId(IdWorker.getId());
saveEntity.setMaterialNo(newestParent.getMaterialNo());
saveEntity.setSourceRowId(newestParent.getRowId());
saveEntity.setSourceType(2);
saveEntity.setNumType(param.getNumType());
saveEntity.setChangeDesc(param.getChangeDesc());
saveEntity.setNoticeContent(newestParent.getMaterialDesc() + "BOM变更由PBOM发起详见下方明细");
saveEntity.setNoticeTitle("关于" + newestParent.getMaterialDesc() + "BOM变更的通知");
saveEntity.setOaStatus(1); // 待提交
saveEntity.setCreatedName(SessionUtil.getRealName());
saveEntity.setCreatedBy(SessionUtil.getUserCode());
saveEntity.setCreatedTime(LocalDateTime.now());
// 关联已有通知单
if (param.getNumType() == 2) {
saveEntity.setNoticeNum(param.getNoticeNums());
} else {
saveEntity.setNoticeNum(bomNewNoticeNumService.generateNoticeNum());
}
bomNewNoticeNumService.save(saveEntity);
// 新建通知单
if (param.getNumType() == 1) {
List<BomNewPbomChildFormalEntity> newestChildList = bomNewPbomChildFormalService.lambdaQuery().eq(BomNewPbomChildFormalEntity::getParentRowId, newestParent.getRowId()).list();
List<BomNewPbomChildFormalEntity> lastChildList = bomNewPbomChildFormalService.lambdaQuery().eq(BomNewPbomChildFormalEntity::getParentRowId, lastParent.getRowId()).list();
List<String> newestMaterialNos = newestChildList.stream().map(BomNewPbomChildFormalEntity::getMaterialNo).collect(Collectors.toList());
List<String> lastMaterialNos = lastChildList.stream().map(BomNewPbomChildFormalEntity::getMaterialNo).collect(Collectors.toList());
// 假设旧版 [1,2,3,4,5] 新版 [3,4,5,6,7]
// 旧版和新版的交集 -> [3,4,5]
List<String> intersection =new ArrayList<>(lastMaterialNos);
intersection.retainAll(newestMaterialNos);
// 旧版相对于新版的差集 -> [1,2]
List<String> difference = new ArrayList<>(lastMaterialNos);
difference.removeAll(newestMaterialNos);
// 新版相对于旧版的差集 -> [6,7]
List<String> difference2 = new ArrayList<>(newestMaterialNos);
difference2.removeAll(lastMaterialNos);
List<BomNewNoticeNumDetailEntity> saveDetailList = new ArrayList<>();
// 物料变更的场景有5种物料增加物料减少物料替代改物料数量改物料项目类别
// 两个差集元素的个数不等则认为 difference2 的物料是增加difference 的物料是减少
if (difference.size() != difference2.size()) {
difference.forEach(remove -> {
BomNewPbomChildFormalEntity removeEntity = lastChildList.stream().filter(item -> item.getMaterialNo().equals(remove)).findFirst().orElse(null);
if (ObjectUtil.isNotEmpty(removeEntity)) {
BomNewNoticeNumDetailEntity saveDetail = new BomNewNoticeNumDetailEntity();
saveDetail.setRowId(IdWorker.getId());
saveDetail.setHeaderRowId(saveEntity.getRowId());
saveDetail.setMaterialNo(removeEntity.getMaterialNo());
saveDetail.setDrawingNo(removeEntity.getDrawingNo());
saveDetail.setMaterialName(removeEntity.getMaterialName());
saveDetail.setParentMaterialNo("");
saveDetail.setChangeType(2);
saveDetail.setChangeContent("BOM物料减少");
saveDetailList.add(saveDetail);
}
});
difference2.forEach(add -> {
BomNewPbomChildFormalEntity addEntity = newestChildList.stream().filter(item -> item.getMaterialNo().equals(add)).findFirst().orElse(null);
if (ObjectUtil.isNotEmpty(addEntity)) {
BomNewNoticeNumDetailEntity saveDetail = new BomNewNoticeNumDetailEntity();
saveDetail.setRowId(IdWorker.getId());
saveDetail.setHeaderRowId(saveEntity.getRowId());
saveDetail.setMaterialNo(addEntity.getMaterialNo());
saveDetail.setDrawingNo(addEntity.getDrawingNo());
saveDetail.setMaterialName(addEntity.getMaterialName());
saveDetail.setParentMaterialNo("");
saveDetail.setChangeType(1);
saveDetail.setChangeContent("BOM物料增加");
saveDetailList.add(saveDetail);
}
});
} else {
// 个数相等则认为 difference2 difference 的替代物料
if (CollectionUtil.isNotEmpty(difference2)) {
difference2.forEach(replace -> {
BomNewPbomChildFormalEntity replaceEntity = newestChildList.stream().filter(item -> item.getMaterialNo().equals(replace)).findFirst().orElse(null);
if (ObjectUtil.isNotEmpty(replaceEntity)) {
BomNewNoticeNumDetailEntity saveDetail = new BomNewNoticeNumDetailEntity();
saveDetail.setRowId(IdWorker.getId());
saveDetail.setHeaderRowId(saveEntity.getRowId());
saveDetail.setMaterialNo(replaceEntity.getMaterialNo());
saveDetail.setDrawingNo(replaceEntity.getDrawingNo());
saveDetail.setMaterialName(replaceEntity.getMaterialName());
saveDetail.setParentMaterialNo("");
saveDetail.setChangeType(3);
saveDetail.setChangeContent("BOM物料替换");
saveDetailList.add(saveDetail);
}
});
}
}
// 遍历交集如果旧版和新版物料的数量不等则认为是改物料数量如果旧版和新版物料的项目类别不一致则认为是改物料项目类别
intersection.forEach(entity -> {
BomNewPbomChildFormalEntity lastChild = lastChildList.stream().filter(item -> item.getMaterialNo().equals(entity)).findFirst().orElse(null);
BomNewPbomChildFormalEntity newestChild = newestChildList.stream().filter(item -> item.getMaterialNo().equals(entity)).findFirst().orElse(null);
if (ObjectUtil.isNotEmpty(newestChild.getNum()) && newestChild.getNum().compareTo(lastChild.getNum()) != 0) {
BomNewNoticeNumDetailEntity saveDetail = new BomNewNoticeNumDetailEntity();
saveDetail.setRowId(IdWorker.getId());
saveDetail.setHeaderRowId(saveEntity.getRowId());
saveDetail.setMaterialNo(newestChild.getMaterialNo());
saveDetail.setDrawingNo(newestChild.getDrawingNo());
saveDetail.setMaterialName(newestChild.getMaterialName());
saveDetail.setParentMaterialNo("");
saveDetail.setChangeType(4);
saveDetail.setChangeContent("BOM物料数量变更");
saveDetailList.add(saveDetail);
}
if (ObjectUtil.isNotEmpty(newestChild.getProjectType()) && !newestChild.getProjectType().equals(lastChild.getProjectType())) {
BomNewNoticeNumDetailEntity saveDetail = new BomNewNoticeNumDetailEntity();
saveDetail.setRowId(IdWorker.getId());
saveDetail.setHeaderRowId(saveEntity.getRowId());
saveDetail.setMaterialNo(newestChild.getMaterialNo());
saveDetail.setDrawingNo(newestChild.getDrawingNo());
saveDetail.setMaterialName(newestChild.getMaterialName());
saveDetail.setParentMaterialNo("");
saveDetail.setChangeType(5);
saveDetail.setChangeContent("BOM项目类别变更");
saveDetailList.add(saveDetail);
}
});
bomNewNoticeNumDetailService.saveBatch(saveDetailList);
bomNewNoticeNumService.sync2Oa(saveEntity, saveDetailList);
}
}
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nflg.product.bomnew.mapper.master.BomNewNoticeNumDetailMapper">
</mapper>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nflg.product.bomnew.mapper.master.BomNewNoticeNumMapper">
</mapper>