pbom增加字段来源状态

This commit is contained in:
10002327 2024-08-09 15:49:34 +08:00
parent 6d77ac079f
commit eb4e33a749
10 changed files with 310 additions and 9 deletions

View File

@ -0,0 +1,20 @@
package com.nflg.product.bomnew.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author luohj
* @date 2024/8/9 09:25:44
*/
@AllArgsConstructor
@Getter
public enum PbomSourceStatusEnum implements ValueEnum<Integer> {
EBOM(1, "EBOM导入"),
PBOM(2, "PBOM创建"),
E_P(3, "E->P修改");
private final Integer value;
private final String description;
}

View File

@ -239,6 +239,10 @@ public class BomNewPbomChildEntity implements Serializable {
@ApiModelProperty(value = "来源 1-ebom转换 2-dqbom转换 3-从SAP导入") @ApiModelProperty(value = "来源 1-ebom转换 2-dqbom转换 3-从SAP导入")
private Integer source; private Integer source;
@TableField(value = "source_status")
@ApiModelProperty(value = "来源状态1-EBOM导入、2-PBOM创建、3-E->P修改")
private Integer sourceStatus;
private static final long serialVersionUID = -76633783850936076L; private static final long serialVersionUID = -76633783850936076L;
} }

View File

@ -370,6 +370,10 @@ public class BomNewPbomParentEntity implements Serializable {
@ApiModelProperty(value = "来源 1-ebom转换 2-dqbom转换 3-从SAP导入 4-复制") @ApiModelProperty(value = "来源 1-ebom转换 2-dqbom转换 3-从SAP导入 4-复制")
private Integer source; private Integer source;
@TableField(value = "source_status")
@ApiModelProperty(value = "来源状态1-EBOM导入、2-PBOM创建、3-E->P修改")
private Integer sourceStatus;
private static final long serialVersionUID = -31999878274445137L; private static final long serialVersionUID = -31999878274445137L;
} }

View File

@ -293,6 +293,12 @@ public class BomNewPbomParentVO extends BaseMaterialVO implements Serializable {
@ApiModelProperty("所有父级的rowId") @ApiModelProperty("所有父级的rowId")
private Set<Long> allParentRowIds = new HashSet<>(); private Set<Long> allParentRowIds = new HashSet<>();
@ApiModelProperty(value = "来源状态1-EBOM导入、2-PBOM创建、3-E->P修改")
private Integer sourceStatus;
@ApiModelProperty(value = "来源状态1-EBOM导入、2-PBOM创建、3-E->P修改")
private String sourceStatusName;
private String materialNoAndProjectType; private String materialNoAndProjectType;

View File

@ -5,18 +5,17 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.*;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.mzt.logapi.context.LogRecordContext; import com.mzt.logapi.context.LogRecordContext;
import com.nflg.product.base.core.conmon.util.SessionUtil; import com.nflg.product.base.core.conmon.util.SessionUtil;
@ -356,6 +355,8 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
child.setSapOrderNum(BomUtil.generateSapOrderNum(child.getProjectType(), child.getMaterialCategoryCode() child.setSapOrderNum(BomUtil.generateSapOrderNum(child.getProjectType(), child.getMaterialCategoryCode()
, child.getFacCode(), child.getMaterialNo(), child.getBomExist())); , child.getFacCode(), child.getMaterialNo(), child.getBomExist()));
child.setSapState(null); child.setSapState(null);
child.setSourceStatusName(EnumUtils.getEnumDescription(PbomSourceStatusEnum.class,child.getSourceStatus()));
} }
} }
} }
@ -377,7 +378,28 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
if (CollUtil.isNotEmpty(paramDTO.getChildList())) { if (CollUtil.isNotEmpty(paramDTO.getChildList())) {
List<BomNewPbomChildEntity> childList = Convert.toList(BomNewPbomChildEntity.class, paramDTO.getChildList()); List<BomNewPbomChildEntity> childList = Convert.toList(BomNewPbomChildEntity.class, paramDTO.getChildList());
childList.forEach(u -> u.setParentRowId(paramDTO.getBomRowId())); List<Long> childIds = paramDTO.getChildList().stream().map(BomNewPbomParentVO::getRowId).collect(Collectors.toList());
List<BomNewPbomChildEntity> pChildList = Lists.newArrayList();
if(!childIds.isEmpty()){
pChildList = pbomChildService.list(Wrappers.<BomNewPbomChildEntity>lambdaQuery().in(BomNewPbomChildEntity::getRowId,childIds));
}
Map<Long,BomNewPbomChildEntity> childMap = pChildList.stream().collect(Collectors.toMap(BomNewPbomChildEntity::getRowId,Function.identity()));
List<String> fieldList = Lists.newArrayList("projectType","materialNo","drawingNo","num","unitWeight","remark");
childList.forEach(u -> {
u.setParentRowId(paramDTO.getBomRowId());
if(u.getRowId() == null){
u.setSourceStatus(PbomSourceStatusEnum.PBOM.getValue());
}else{
BomNewPbomChildEntity oChild = childMap.get(u.getRowId());
//判断是否有变更记录
String re = new CompareUtils<BomNewPbomChildEntity>().compare(oChild,u,fieldList,false);
//修改记录如果原先是 EBOM导入 状态变更为E->P修改
if(Objects.equals(PbomSourceStatusEnum.EBOM.getValue(),oChild.getSourceStatus()) && StrUtil.isNotBlank(re)){
u.setSourceStatus(PbomSourceStatusEnum.E_P.getValue());
}
}
});
pbomChildService.saveOrUpdateBatch(childList); pbomChildService.saveOrUpdateBatch(childList);
parent.setBomExist(1); parent.setBomExist(1);
} else { } else {

View File

@ -132,6 +132,7 @@ public class EBomToPBomFor31 extends EBomToPbomBase {
childEnt.setFacCode(facCode); childEnt.setFacCode(facCode);
childEnt.setIdentityNo(StrUtil.join("-", parentEnt.getMaterialNo(), eb.getMaterialNo())); childEnt.setIdentityNo(StrUtil.join("-", parentEnt.getMaterialNo(), eb.getMaterialNo()));
childEnt.setSource(PbomSourceEnum.FROM_EBOM.getValue()); childEnt.setSource(PbomSourceEnum.FROM_EBOM.getValue());
childEnt.setSourceStatus(PbomSourceStatusEnum.EBOM.getValue());
this.pBomChildResult.add(childEnt); this.pBomChildResult.add(childEnt);
} }
} }

View File

@ -221,6 +221,7 @@ public abstract class EBomToPbomBase {
pBomParent.setDeptRowId(SessionUtil.getDepartRowId()); pBomParent.setDeptRowId(SessionUtil.getDepartRowId());
pBomParent.setCreatedBy(SessionUtil.getUserCode()); pBomParent.setCreatedBy(SessionUtil.getUserCode());
pBomParent.setSource(PbomSourceEnum.FROM_EBOM.getValue()); pBomParent.setSource(PbomSourceEnum.FROM_EBOM.getValue());
pBomParent.setSourceStatus(PbomSourceStatusEnum.EBOM.getValue());
if (Objects.nonNull(oldParent)) { if (Objects.nonNull(oldParent)) {
oldParent.setExpireEndTime(LocalDateTime.now()); oldParent.setExpireEndTime(LocalDateTime.now());
oldParent.setLastVersionIs(0); oldParent.setLastVersionIs(0);

View File

@ -6,10 +6,7 @@ import cn.hutool.core.convert.Convert;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.nflg.product.base.core.conmon.util.SessionUtil; import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.bomnew.constant.PBomEditStatusEnum; import com.nflg.product.bomnew.constant.*;
import com.nflg.product.bomnew.constant.PBomStatusEnum;
import com.nflg.product.bomnew.constant.PbomSourceEnum;
import com.nflg.product.bomnew.constant.UserJobEnum;
import com.nflg.product.bomnew.pojo.entity.BomNewPbomChildEntity; import com.nflg.product.bomnew.pojo.entity.BomNewPbomChildEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity; import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
import com.nflg.product.bomnew.pojo.vo.BomNewPbomParentVO; import com.nflg.product.bomnew.pojo.vo.BomNewPbomParentVO;
@ -101,6 +98,7 @@ public class PBomUpgrade {
pbomParent.setTechnologyUserCode(SessionUtil.getUserCode()); pbomParent.setTechnologyUserCode(SessionUtil.getUserCode());
pbomParent.setRemark(""); pbomParent.setRemark("");
pbomParent.setSource(PbomSourceEnum.FROM_CHANGE.getValue()); pbomParent.setSource(PbomSourceEnum.FROM_CHANGE.getValue());
pbomParent.setSourceStatus(PbomSourceStatusEnum.PBOM.getValue());
pbomParent.setReleaseTime(null); pbomParent.setReleaseTime(null);
pbomParent.setReleaseUserName(null); pbomParent.setReleaseUserName(null);
pbomParent.setSapState(1); pbomParent.setSapState(1);
@ -137,6 +135,7 @@ public class PBomUpgrade {
child.setCreatedBy(SessionUtil.getUserCode()); child.setCreatedBy(SessionUtil.getUserCode());
child.setModifyTime(null); child.setModifyTime(null);
child.setSource(PbomSourceEnum.FROM_CHANGE.getValue()); child.setSource(PbomSourceEnum.FROM_CHANGE.getValue());
child.setSourceStatus(PbomSourceStatusEnum.PBOM.getValue());
child.setRemark(""); child.setRemark("");
this.childResult.add(child); this.childResult.add(child);
} }

View File

@ -0,0 +1,63 @@
package com.nflg.product.bomnew.util;
/**
* packageName com.nflg.product.bomnew.util
*
* @author luohj
* @className CompareNode
* @date 2024/8/9 0009
* @description TODO
*/
public class CompareNode {
/**
* 字段
*/
private String fieldKey;
/**
* 字段值
*/
private Object fieldValue;
/**
* 字段名称
*/
private String fieldName;
/**
* 字段类型
*/
private String type;
public String getFieldKey() {
return fieldKey;
}
public void setFieldKey(String fieldKey) {
this.fieldKey = fieldKey;
}
public Object getFieldValue() {
return fieldValue;
}
public void setFieldValue(Object fieldValue) {
this.fieldValue = fieldValue;
}
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}

View File

@ -0,0 +1,181 @@
package com.nflg.product.bomnew.util;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.interfaces.Compare;
import com.google.common.collect.Lists;
import com.nflg.product.bomnew.pojo.entity.BomNewPbomChildEntity;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.*;
/**
* packageName com.nflg.product.bomnew.util
*
* @author luohj
* @className CompareUtils
* @date 2024/8/9 0009
* @description TODO
*/
public class CompareUtils <T> {
private static final String COMMA = "";
/**
* 属性比较
*
* @param source 源数据对象
* @param target 目标数据对象
* @return 对应属性值的比较变化
*/
public String compare(T source, T target) {
return compare(source, target, null,true);
}
/**
* 属性比较
*
* @param source 源数据对象
* @param target 目标数据对象
* @param ignoreCompareFields 忽略比较的字段
* @param isIgnore true是要忽略的字段 false仅对比的字段值
* @return 对应属性值的比较变化
*/
public String compare(T source, T target, List<String> ignoreCompareFields,boolean isIgnore) {
if (Objects.isNull(source) && Objects.isNull(target)) {
return "";
}
Map<String, CompareNode> sourceMap = this.getFiledValueMap(source);
Map<String, CompareNode> targetMap = this.getFiledValueMap(target);
if (sourceMap.isEmpty() && targetMap.isEmpty()) {
return "";
}
// 如果源数据为空则只显示目标数据不显示属性变化情况
if (sourceMap.isEmpty()) {
return doEmpty(targetMap, ignoreCompareFields,isIgnore);
}
// 如果源数据为空则显示属性变化情况
String s = doCompare(sourceMap, targetMap, ignoreCompareFields,isIgnore);
if (!s.endsWith(COMMA)) {
return s;
}
return s.substring(0, s.length() - 1);
}
private String doEmpty(Map<String, CompareNode> targetMap, List<String> ignoreCompareFields,boolean isIgnore) {
StringBuilder sb = new StringBuilder();
Collection<CompareNode> values = targetMap.values();
int size = values.size();
int current = 0;
for (CompareNode node : values) {
current++;
Object o = Optional.ofNullable(node.getFieldValue()).orElse("");
if (Objects.nonNull(ignoreCompareFields)) {
if(isIgnore){
if(ignoreCompareFields.contains(node.getFieldKey())){
continue;
}
}else{
if(!ignoreCompareFields.contains(node.getFieldKey())){
continue;
}
}
}
if (o.toString().length() > 0) {
sb.append("[" + node.getFieldName() + "" + o + "]");
if (current < size) {
sb.append(COMMA);
}
}
}
return sb.toString();
}
private String doCompare(Map<String, CompareNode> sourceMap, Map<String, CompareNode> targetMap, List<String> ignoreCompareFields,boolean isIgnore) {
StringBuilder sb = new StringBuilder();
Set<String> keys = sourceMap.keySet();
int size = keys.size();
int current = 0;
BigDecimal zero = new BigDecimal(0);
for (String key : keys) {
current++;
CompareNode sn = sourceMap.get(key);
CompareNode tn = targetMap.get(key);
if (Objects.nonNull(ignoreCompareFields)) {
if(isIgnore){
if(ignoreCompareFields.contains(sn.getFieldKey())){
continue;
}
}else{
if(!ignoreCompareFields.contains(sn.getFieldKey())){
continue;
}
}
}
String sv = Optional.ofNullable(sn.getFieldValue()).orElse("").toString();
String tv = Optional.ofNullable(tn.getFieldValue()).orElse("").toString();
if(Objects.equals("java.math.BigDecimal",sn.getType())){
if(Convert.toBigDecimal(sv,zero).compareTo(Convert.toBigDecimal(tv,zero)) != 0){
sb.append(String.format("[%s%s -> %s]", sn.getFieldName(), sv, tv));
if (current < size) {
sb.append(COMMA);
}
}
}else{
// 只有两者属性值不一致时, 才显示变化情况
if (!sv.equals(tv)) {
sb.append(String.format("[%s%s -> %s]", sn.getFieldName(), sv, tv));
if (current < size) {
sb.append(COMMA);
}
}
}
}
return sb.toString();
}
private Map<String, CompareNode> getFiledValueMap(T t) {
if (Objects.isNull(t)) {
return Collections.emptyMap();
}
Field[] fields = t.getClass().getDeclaredFields();
if (Objects.isNull(fields) || fields.length == 0) {
return Collections.emptyMap();
}
Map<String, CompareNode> map = new LinkedHashMap();
for (Field field : fields) {
field.setAccessible(true);
try {
String fieldKey = field.getName();
CompareNode node = new CompareNode();
node.setFieldKey(fieldKey);
node.setFieldValue(field.get(t));
node.setFieldName(fieldKey);
node.setType(field.getType().getName());
map.put(field.getName(), node);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
return map;
}
public static void main(String[] args) {
BomNewPbomChildEntity p1 = new BomNewPbomChildEntity();
p1.setRowId(1l);
p1.setSourceStatus(2);
BomNewPbomChildEntity p2 = new BomNewPbomChildEntity();
p2.setRowId(1l);
p2.setSourceStatus(2);
String re = new CompareUtils<BomNewPbomChildEntity>().compare(p1,p2,Lists.newArrayList("rowId","sourceStatus","identityNo"),false);
System.out.println("re:"+re);
}
}