Merge remote-tracking branch 'origin/feature/DM/nflg-bom' into feature/DM/nflg-bom

This commit is contained in:
大米 2024-06-21 18:59:43 +08:00
commit bf5797669d
5 changed files with 183 additions and 57 deletions

View File

@ -0,0 +1,28 @@
package com.nflg.product.bomnew.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author 曹鹏飞
* @date 2024/6/21 13:57:30
*/
@Getter
@AllArgsConstructor
public enum MaterialMainGetTypeEnum {
ZZ(1, "自制"),
WX(2, "外协"),
CG(3, "采购");
private final Integer code;
private final String description;
public static MaterialMainGetTypeEnum findCodeByDescription(String description) {
for (MaterialMainGetTypeEnum valueEnum : MaterialMainGetTypeEnum.values()) {
if (valueEnum.getDescription().equals(description)) {
return valueEnum;
}
}
return null;
}
}

View File

@ -0,0 +1,24 @@
package com.nflg.product.bomnew.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author 曹鹏飞
* @date 2024/6/21 13:56:32
*/
@Getter
@AllArgsConstructor
public enum MaterialRelCategoryCodeEnum {
relCategoryCode_11("11", "采购物料"),
relCategoryCode_21("21", "制作物料"),
relCategoryCode_22("22", "制作物料-发货直发制作包、非图纸物料"),
relCategoryCode_31("31", "整机物料"),
relCategoryCode_41("41", "配件"),
relCategoryCode_51("51", "劳保办公用品"),
relCategoryCode_61("61", "服务"),
relCategoryCode_71("71", "工具工装");
private final String relCategoryCode;
private final String description;
}

View File

@ -1,5 +1,6 @@
package com.nflg.product.bomnew.excel;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
@ -19,6 +20,7 @@ import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.nflg.product.bomnew.pojo.vo.*;
import com.nflg.product.bomnew.util.VUtils;
import org.apache.poi.ss.usermodel.*;
import com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy;
import org.apache.poi.ss.util.CellRangeAddress;
@ -353,7 +355,8 @@ public class ExportDeviceHelper {
public void buildList(List<OptionalEbomImportVO> listTable, WriteSheet sheet, ExcelWriter writer, AtomicInteger tableNoCounting) {
if (CollectionUtil.isEmpty(listTable)) {
return;
VUtils.isTure(true).throwMessage("设备下无数据");
}
List<ImportExcelField> items = new ArrayList<>();
@ -368,11 +371,21 @@ public class ExportDeviceHelper {
List<OptionalEbomImportVO> list2 = item1.getChild();
if(CollUtil.isEmpty(list2)){
continue;
}
for (OptionalEbomImportVO item2 : list2) {
{
String opChildName = item2.getOptionName();
String optionChildDrawingNo = item2.getOptionDrawingNo();
List<OptionalEbomImportChildVO> list3 = item2.getChild();
if(CollUtil.isEmpty(list3)){
continue;
}
for (OptionalEbomImportChildVO item3 : list3) {
ImportExcelField excelField = new ImportExcelField();
excelField.setCellFirst(StrUtil.format("{} {}",optionChildDrawingNo,opChildName));

View File

@ -15,7 +15,10 @@ import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.base.core.exception.NflgBusinessException;
import com.nflg.product.bomnew.client.MaterialMainClient;
import com.nflg.product.bomnew.config.NacosConfig;
import com.nflg.product.bomnew.constant.MaterialMainGetTypeEnum;
import com.nflg.product.bomnew.constant.MaterialRelCategoryCodeEnum;
import com.nflg.product.bomnew.pojo.dto.*;
import com.nflg.product.bomnew.pojo.entity.MaterialCategoryEntity;
import com.nflg.product.bomnew.pojo.entity.MaterialMainEntity;
import com.nflg.product.bomnew.util.FlowUtil;
import com.nflg.product.bomnew.util.HttpUtils;
@ -23,6 +26,7 @@ import com.nflg.product.bomnew.util.ListCommonUtil;
import com.nflg.product.bomnew.util.VUtils;
import lombok.extern.slf4j.Slf4j;
import nflg.product.common.constant.STATE;
import nflg.product.common.dto.LoginUserInfoDTO;
import nflg.product.common.vo.ResultVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Qualifier;
@ -51,6 +55,9 @@ public class MaterialService {
@Qualifier("syncOAThreadPool")
ThreadPoolTaskExecutor syncOAThreadPool;
@Resource
MaterialCategoryService materialCategoryService;
/**
* 申请物料
*
@ -168,9 +175,12 @@ public class MaterialService {
@Transactional(rollbackFor = Exception.class)
//****************************************本地生成不调主数据**************************************************
public Map<String,AddVirtrualMaterialDTO> batchAddMaterial(List<AddVirtrualMaterialDTO> mds){
public Map<String, AddVirtrualMaterialDTO> batchAddMaterial(List<AddVirtrualMaterialDTO> mds, LoginUserInfoDTO userInfo) {
List<MaterialMainEntity> resultList=new ArrayList<>();
Set<String> categoryCodeList = mds.stream().map(AddVirtrualMaterialDTO::getMaterialCategoryCode).collect(Collectors.toSet());
List<MaterialCategoryEntity> categoryEntityList = materialCategoryService.lambdaQuery().in(MaterialCategoryEntity::getCategoryCode, categoryCodeList).list();
List<AddMaterialMainDTO> syncOaEnts=new ArrayList<>();
Map<String,AddVirtrualMaterialDTO> result = new HashMap<>();
for (AddVirtrualMaterialDTO md :mds) {
@ -182,14 +192,14 @@ public class MaterialService {
ma.setMaterialName(md.getMaterialName());
ma.setMaterialDesc(md.getMaterialDesc());
ma.setMaterialCategoryCode(md.getMaterialCategoryCode());
ma.setCreatedBy(SessionUtil.getUserCode());
ma.setCreatedBy(userInfo.getUserCode());
ma.setCreatedTime(LocalDateTime.now());
ma.setUpdatedBy(SessionUtil.getUserCode());
ma.setUpdatedBy(userInfo.getUserCode());
ma.setUpdatedTime(LocalDateTime.now());
ma.setMaterialClass(0);
ma.setProcessState(0);
ma.setApplyUserCode(SessionUtil.getRealName());
ma.setApplyDeptName(SessionUtil.getDepartName());
// ma.setProcessState(0);
ma.setApplyUserCode(userInfo.getRealName());
ma.setApplyDeptName(userInfo.getDepartName());
ma.setMaterialUnit("PC");
ma.setProcessState(10);
if(StrUtil.isNotBlank(md.getProjectType())){
@ -197,10 +207,21 @@ public class MaterialService {
}
resultList.add(ma);
AddMaterialMainDTO ent=new AddMaterialMainDTO();
BeanUtil.copyProperties(ma,ent);
AddMaterialMainDTO ent = new AddMaterialMainDTO();
BeanUtil.copyProperties(ma, ent);
ent.setRelCategoryCode(relMaterialCategory);
ent.setReuseOfOnceState(0);
Optional<MaterialCategoryEntity> optional = categoryEntityList.stream().filter(item -> item.getCategoryCode().equals(md.getMaterialCategoryCode())).findFirst();
optional.ifPresent(item -> {
List<String> parentRowIdList = Arrays.stream(item.getParentTree().split(",")).collect(Collectors.toList());
List<MaterialCategoryEntity> list = materialCategoryService.lambdaQuery().in(MaterialCategoryEntity::getRowId, parentRowIdList).list();
List<String> categoryNameList = list.stream().map(MaterialCategoryEntity::getCategoryName).collect(Collectors.toList());
String categoryTreeName = String.join("/", categoryNameList);
ent.setCategoryNameTree(categoryTreeName);
ent.setRelCategoryCode(item.getRelCategoryCode());
});
syncOaEnts.add(ent);
md.setMaterialNo(ma.getMaterialNo());
@ -209,11 +230,14 @@ public class MaterialService {
materialMainService.saveOrUpdateBatch(resultList);
initCategoryInfo(syncOaEnts);
//同步OA
sysnToOa(syncOaEnts);
// CompletableFuture.runAsync(() -> sysnToOa(syncOaEnts),syncOAThreadPool);
CompletableFuture.runAsync(() -> sysnToOa(syncOaEnts, userInfo), syncOAThreadPool);
return result;
}
public Map<String, AddVirtrualMaterialDTO> batchAddMaterial(List<AddVirtrualMaterialDTO> mds) {
return batchAddMaterial(mds, SessionUtil.getUser());
}
private void checkMaterial(List<AddVirtrualMaterialDTO> mds){
List<AddVirtrualMaterialDTO> noCateGoryCodes = mds.stream().filter(u -> StrUtil.isBlank(u.getMaterialCategoryCode())).collect(Collectors.toList());
VUtils.isTure(CollUtil.isNotEmpty(noCateGoryCodes)).throwMessage("最小物料类别不能为空");
@ -282,7 +306,7 @@ public class MaterialService {
* @param materialCategoryCode
* @return
*/
public String generateMaterialNo(String materialCategoryCode ,String preCategory) {
public synchronized String generateMaterialNo(String materialCategoryCode, String preCategory) {
// String preCategory =materialMainService.getBaseMapper().getMaterialCategory(materialCategoryCode);
if (StrUtil.isBlank(preCategory)) {
throw new NflgBusinessException(STATE.ParamErr, materialCategoryCode.concat("未设置对应分类"));
@ -302,46 +326,63 @@ public class MaterialService {
* @param data
*/
@Transactional(rollbackFor = Exception.class)
public void sysnToOa(List<AddMaterialMainDTO> data) {
Map<String, Object> result = getHttpMap();
List<Map<String, String>> list = new ArrayList<>();
data.forEach(u -> {
Map<String, String> material = new LinkedHashMap<>();
String relCategoryCode = u.getRelCategoryCode();
material.put("MATNR", u.getMaterialNo());
material.put("MAKTX", StrUtil.isNotBlank(u.getShortMaterialDesc()) ? u.getShortMaterialDesc() : u.getMaterialDesc());
material.put("dl", u.getSecondMaterialCategoryCode());
material.put("xl", u.getThirdMaterialCategoryCode());
material.put("xfl", u.getFourthMaterialCategoryCode());
material.put("xl_copy", u.getThirdMaterialCategoryCode());
material.put("MATKL", u.getThirdMaterialCategoryCode());
material.put("MNAME", u.getMaterialName());
material.put("MNUMB", u.getDrawingNo());
material.put("MTEXT", u.getMaterialTexture());
material.put("MSPEC", u.getMaterialSpecifications());
material.put("MREMA", u.getMaterialDesc());
material.put("MMANU", u.getMaterialBrand());
material.put("ATTYP", relCategoryCode);
material.put("ERNAM", SessionUtil.getUserCode());
material.put("MEINS", u.getMaterialUnit());
material.put("DUPLICATEITEMS", u.getReuseOfOnceState().equals(1) ? "2" : "1");// 是否一次性使用物料 0:否1
material.put("categoryTreeName", u.getCategoryNameTree());
//流程类型 1|自制;2|外协;3|采购
material.put("materialGetType","1");
if (StringUtils.isNotEmpty(String.valueOf(u.getUseOfYear()))) {
material.put("USAGEYEAR", String.valueOf(u.getUseOfYear()));
}
material.put("picUrl", u.getPicUrl());
list.add(material);
});
result.put("List", list);
log.info("物料申请-JSON" + JSONArray.toJSONString(list));
HttpUtils httpUtils = new HttpUtils();
public void sysnToOa(List<AddMaterialMainDTO> data, LoginUserInfoDTO userInfo) {
try {
Map<String, Object> result = getHttpMap(userInfo.getUserCode());
List<Map<String, String>> list = new ArrayList<>();
data.forEach(u -> {
Map<String, String> material = new LinkedHashMap<>();
String relCategoryCode = u.getRelCategoryCode();
material.put("MATNR", u.getMaterialNo());
material.put("MAKTX", StrUtil.isNotBlank(u.getShortMaterialDesc()) ? u.getShortMaterialDesc() : u.getMaterialDesc());
material.put("dl", u.getSecondMaterialCategoryCode());
material.put("xl", u.getThirdMaterialCategoryCode());
material.put("xfl", u.getFourthMaterialCategoryCode());
material.put("xl_copy", u.getThirdMaterialCategoryCode());
material.put("MATKL", u.getThirdMaterialCategoryCode());
material.put("MNAME", u.getMaterialName());
material.put("MNUMB", u.getDrawingNo());
material.put("MTEXT", u.getMaterialTexture());
material.put("MSPEC", u.getMaterialSpecifications());
material.put("MREMA", u.getMaterialDesc());
material.put("MMANU", u.getMaterialBrand());
material.put("ATTYP", relCategoryCode);
material.put("ERNAM", userInfo.getUserCode());
material.put("MEINS", u.getMaterialUnit());
material.put("DUPLICATEITEMS", u.getReuseOfOnceState().equals(1) ? "2" : "1");// 是否一次性使用物料 0:否1
material.put("categoryTreeName", u.getCategoryNameTree());
material.put("FWEIGHT", u.getMaterialWeight());
if (StringUtils.isNotEmpty(relCategoryCode)) {
if (relCategoryCode.equals(MaterialRelCategoryCodeEnum.relCategoryCode_21.getRelCategoryCode()) || relCategoryCode.equals(MaterialRelCategoryCodeEnum.relCategoryCode_22.getRelCategoryCode())) {
material.put("materialGetType", String.valueOf(u.getMaterialGetType()));
}
if (relCategoryCode.equals(MaterialRelCategoryCodeEnum.relCategoryCode_71.getRelCategoryCode())) {
if ("701301".equals(u.getMaterialCategoryCode())) {
material.put("materialGetType", String.valueOf(u.getMaterialGetType()));
} else if ("701303".equals(u.getMaterialCategoryCode())) {
// 701303 虽然按照采购形式申请但是OA流程类型 强制按照 自制
material.put("materialGetType", String.valueOf(MaterialMainGetTypeEnum.ZZ.getCode()));
} else {
material.put("materialGetType", String.valueOf(MaterialMainGetTypeEnum.CG.getCode()));
}
}
}
if (StringUtils.isNotEmpty(String.valueOf(u.getUseOfYear()))) {
material.put("USAGEYEAR", String.valueOf(u.getUseOfYear()));
}
material.put("picUrl", u.getPicUrl());
// 中类小类细分类若有分类代码和名称都传给OA
handleCategoryCodeAndName(material, u);
list.add(material);
});
result.put("List", list);
log.info("物料申请-JSON" + JSONArray.toJSONString(list));
HttpUtils httpUtils = new HttpUtils();
String url = NacosConfig.getNacosConfig().getOaUrl();
String reqResult = httpUtils.doPost(url, JSON.toJSONString(result));
JSONObject jsonObject = JSONObject.parseObject(reqResult);
@ -356,16 +397,16 @@ public class MaterialService {
message = StrUtil.isNotBlank(message) ? message : "";
throw new NflgBusinessException(STATE.BusinessError, "同步OA出错".concat(message));
}
// return null;
// return null;
} catch (Exception ex) {
log.error("同步OA出错",ex);
log.error("同步OA出错", ex);
throw new NflgBusinessException(STATE.BusinessError, "同步OA出错" + ex.getMessage());
}
}
public Map<String, Object> getHttpMap() {
public Map<String, Object> getHttpMap(String userCode) {
Map<String, Object> result = new LinkedHashMap<>();
result.put("userid", SessionUtil.getUserCode());
result.put("userid", userCode);
result.put("summary", NacosConfig.getNacosConfig().getSummary());
return result;
}
@ -397,4 +438,24 @@ public class MaterialService {
materialMainService.updateBatchById(entityList);
}
private void handleCategoryCodeAndName(Map<String, String> material, AddMaterialMainDTO materialMainVO) {
String categoryNameTree = materialMainVO.getCategoryNameTree();
String[] trees = categoryNameTree.split("/");
if (trees.length >= 4 && Objects.nonNull(materialMainVO.getFourthMaterialCategoryCode())) {
material.put("ThinTypeCode", materialMainVO.getFourthMaterialCategoryCode());
// material.put("ThinTypeDes", trees[3]);
// 细分类可能也含/所以用截取到末尾方式
int startIndex = (trees[0] + "/" + trees[1] + "/" + trees[2] + "/").length();
material.put("ThinTypeDes", categoryNameTree.substring(startIndex));
}
if (trees.length >= 3 && Objects.nonNull(materialMainVO.getThirdMaterialCategoryCode())) {
material.put("SmallTypeCode", materialMainVO.getThirdMaterialCategoryCode());
material.put("SmallTypeDes", trees[2]);
}
if (trees.length >= 2 && Objects.nonNull(materialMainVO.getSecondMaterialCategoryCode())) {
material.put("MiddleTypeCode", materialMainVO.getSecondMaterialCategoryCode());
material.put("MiddleTypeDes", trees[1]);
}
material.put("ATTYPDES", trees[0]);
}
}

View File

@ -103,7 +103,7 @@
t1.choose_status,
t2.choose_status as option_status from
t_optional_ebom_config_r as t2 LEFT JOIN t_optional_ebom_import_child as t1 on t2.option_row_id=t1.row_id
where t1.is_enable=1 and t2.parent_row_id=#{rowId}
where t1.is_enable=1 and t1.is_del=0 and t2.parent_row_id=#{rowId}
@ -131,7 +131,7 @@
t1.choose_status,
t2.choose_status as option_status from
t_optional_ebom_config_r as t2 LEFT JOIN t_optional_ebom_import_child as t1 on t2.option_row_id=t1.row_id
where t1.is_enable=1 and t2.choose_status =1 and t2.parent_row_id=#{rowId} and t1.material_name!='无'
where t1.is_enable=1 and t1.is_del=0 and t2.choose_status =1 and t2.parent_row_id=#{rowId} and t1.material_name!='无'
</select>