feat: 中类、小类、细分类(若有),分类代码和名称都传给OA

This commit is contained in:
曹鹏飞 2024-06-21 15:43:18 +08:00
parent c04fa487d8
commit 3905ac75bd
1 changed files with 88 additions and 65 deletions

View File

@ -18,6 +18,7 @@ import com.nflg.product.bomnew.config.NacosConfig;
import com.nflg.product.bomnew.constant.MaterialMainGetTypeEnum; import com.nflg.product.bomnew.constant.MaterialMainGetTypeEnum;
import com.nflg.product.bomnew.constant.MaterialRelCategoryCodeEnum; import com.nflg.product.bomnew.constant.MaterialRelCategoryCodeEnum;
import com.nflg.product.bomnew.pojo.dto.*; 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.pojo.entity.MaterialMainEntity;
import com.nflg.product.bomnew.util.FlowUtil; import com.nflg.product.bomnew.util.FlowUtil;
import com.nflg.product.bomnew.util.HttpUtils; import com.nflg.product.bomnew.util.HttpUtils;
@ -25,6 +26,7 @@ import com.nflg.product.bomnew.util.ListCommonUtil;
import com.nflg.product.bomnew.util.VUtils; import com.nflg.product.bomnew.util.VUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import nflg.product.common.constant.STATE; import nflg.product.common.constant.STATE;
import nflg.product.common.dto.LoginUserInfoDTO;
import nflg.product.common.vo.ResultVO; import nflg.product.common.vo.ResultVO;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
@ -36,6 +38,7 @@ import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@ -52,6 +55,9 @@ public class MaterialService {
@Qualifier("syncOAThreadPool") @Qualifier("syncOAThreadPool")
ThreadPoolTaskExecutor syncOAThreadPool; ThreadPoolTaskExecutor syncOAThreadPool;
@Resource
MaterialCategoryService materialCategoryService;
/** /**
* 申请物料 * 申请物料
* *
@ -169,9 +175,12 @@ public class MaterialService {
@Transactional(rollbackFor = Exception.class) @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<>(); 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<>(); List<AddMaterialMainDTO> syncOaEnts=new ArrayList<>();
Map<String,AddVirtrualMaterialDTO> result = new HashMap<>(); Map<String,AddVirtrualMaterialDTO> result = new HashMap<>();
for (AddVirtrualMaterialDTO md :mds) { for (AddVirtrualMaterialDTO md :mds) {
@ -183,14 +192,14 @@ public class MaterialService {
ma.setMaterialName(md.getMaterialName()); ma.setMaterialName(md.getMaterialName());
ma.setMaterialDesc(md.getMaterialDesc()); ma.setMaterialDesc(md.getMaterialDesc());
ma.setMaterialCategoryCode(md.getMaterialCategoryCode()); ma.setMaterialCategoryCode(md.getMaterialCategoryCode());
ma.setCreatedBy(SessionUtil.getUserCode()); ma.setCreatedBy(userInfo.getUserCode());
ma.setCreatedTime(LocalDateTime.now()); ma.setCreatedTime(LocalDateTime.now());
ma.setUpdatedBy(SessionUtil.getUserCode()); ma.setUpdatedBy(userInfo.getUserCode());
ma.setUpdatedTime(LocalDateTime.now()); ma.setUpdatedTime(LocalDateTime.now());
ma.setMaterialClass(0); ma.setMaterialClass(0);
ma.setProcessState(0); // ma.setProcessState(0);
ma.setApplyUserCode(SessionUtil.getRealName()); ma.setApplyUserCode(userInfo.getRealName());
ma.setApplyDeptName(SessionUtil.getDepartName()); ma.setApplyDeptName(userInfo.getDepartName());
ma.setMaterialUnit("PC"); ma.setMaterialUnit("PC");
ma.setProcessState(10); ma.setProcessState(10);
if(StrUtil.isNotBlank(md.getProjectType())){ if(StrUtil.isNotBlank(md.getProjectType())){
@ -198,10 +207,21 @@ public class MaterialService {
} }
resultList.add(ma); resultList.add(ma);
AddMaterialMainDTO ent=new AddMaterialMainDTO(); AddMaterialMainDTO ent = new AddMaterialMainDTO();
BeanUtil.copyProperties(ma,ent); BeanUtil.copyProperties(ma, ent);
ent.setRelCategoryCode(relMaterialCategory); ent.setRelCategoryCode(relMaterialCategory);
ent.setReuseOfOnceState(0); 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); syncOaEnts.add(ent);
md.setMaterialNo(ma.getMaterialNo()); md.setMaterialNo(ma.getMaterialNo());
@ -210,11 +230,14 @@ public class MaterialService {
materialMainService.saveOrUpdateBatch(resultList); materialMainService.saveOrUpdateBatch(resultList);
initCategoryInfo(syncOaEnts); initCategoryInfo(syncOaEnts);
//同步OA //同步OA
sysnToOa(syncOaEnts); CompletableFuture.runAsync(() -> sysnToOa(syncOaEnts, userInfo), syncOAThreadPool);
// CompletableFuture.runAsync(() -> sysnToOa(syncOaEnts),syncOAThreadPool);
return result; return result;
} }
public Map<String, AddVirtrualMaterialDTO> batchAddMaterial(List<AddVirtrualMaterialDTO> mds) {
return batchAddMaterial(mds, SessionUtil.getUser());
}
private void checkMaterial(List<AddVirtrualMaterialDTO> mds){ private void checkMaterial(List<AddVirtrualMaterialDTO> mds){
List<AddVirtrualMaterialDTO> noCateGoryCodes = mds.stream().filter(u -> StrUtil.isBlank(u.getMaterialCategoryCode())).collect(Collectors.toList()); List<AddVirtrualMaterialDTO> noCateGoryCodes = mds.stream().filter(u -> StrUtil.isBlank(u.getMaterialCategoryCode())).collect(Collectors.toList());
VUtils.isTure(CollUtil.isNotEmpty(noCateGoryCodes)).throwMessage("最小物料类别不能为空"); VUtils.isTure(CollUtil.isNotEmpty(noCateGoryCodes)).throwMessage("最小物料类别不能为空");
@ -283,7 +306,7 @@ public class MaterialService {
* @param materialCategoryCode * @param materialCategoryCode
* @return * @return
*/ */
public String generateMaterialNo(String materialCategoryCode ,String preCategory) { public synchronized String generateMaterialNo(String materialCategoryCode, String preCategory) {
// String preCategory =materialMainService.getBaseMapper().getMaterialCategory(materialCategoryCode); // String preCategory =materialMainService.getBaseMapper().getMaterialCategory(materialCategoryCode);
if (StrUtil.isBlank(preCategory)) { if (StrUtil.isBlank(preCategory)) {
throw new NflgBusinessException(STATE.ParamErr, materialCategoryCode.concat("未设置对应分类")); throw new NflgBusinessException(STATE.ParamErr, materialCategoryCode.concat("未设置对应分类"));
@ -303,63 +326,63 @@ public class MaterialService {
* @param data * @param data
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void sysnToOa(List<AddMaterialMainDTO> data) { public void sysnToOa(List<AddMaterialMainDTO> data, LoginUserInfoDTO userInfo) {
Map<String, Object> result = getHttpMap(); try {
Map<String, Object> result = getHttpMap(userInfo.getUserCode());
List<Map<String, String>> list = new ArrayList<>(); List<Map<String, String>> list = new ArrayList<>();
data.forEach(u -> { data.forEach(u -> {
Map<String, String> material = new LinkedHashMap<>(); Map<String, String> material = new LinkedHashMap<>();
String relCategoryCode = u.getRelCategoryCode(); String relCategoryCode = u.getRelCategoryCode();
material.put("MATNR", u.getMaterialNo()); material.put("MATNR", u.getMaterialNo());
material.put("MAKTX", StrUtil.isNotBlank(u.getShortMaterialDesc()) ? u.getShortMaterialDesc() : u.getMaterialDesc()); material.put("MAKTX", StrUtil.isNotBlank(u.getShortMaterialDesc()) ? u.getShortMaterialDesc() : u.getMaterialDesc());
material.put("dl", u.getSecondMaterialCategoryCode()); material.put("dl", u.getSecondMaterialCategoryCode());
material.put("xl", u.getThirdMaterialCategoryCode()); material.put("xl", u.getThirdMaterialCategoryCode());
material.put("xfl", u.getFourthMaterialCategoryCode()); material.put("xfl", u.getFourthMaterialCategoryCode());
material.put("xl_copy", u.getThirdMaterialCategoryCode()); material.put("xl_copy", u.getThirdMaterialCategoryCode());
material.put("MATKL", u.getThirdMaterialCategoryCode()); material.put("MATKL", u.getThirdMaterialCategoryCode());
material.put("MNAME", u.getMaterialName()); material.put("MNAME", u.getMaterialName());
material.put("MNUMB", u.getDrawingNo()); material.put("MNUMB", u.getDrawingNo());
material.put("MTEXT", u.getMaterialTexture()); material.put("MTEXT", u.getMaterialTexture());
material.put("MSPEC", u.getMaterialSpecifications()); material.put("MSPEC", u.getMaterialSpecifications());
material.put("MREMA", u.getMaterialDesc()); material.put("MREMA", u.getMaterialDesc());
material.put("MMANU", u.getMaterialBrand()); material.put("MMANU", u.getMaterialBrand());
material.put("ATTYP", relCategoryCode); material.put("ATTYP", relCategoryCode);
material.put("ERNAM", SessionUtil.getUserCode()); material.put("ERNAM", userInfo.getUserCode());
material.put("MEINS", u.getMaterialUnit()); material.put("MEINS", u.getMaterialUnit());
material.put("DUPLICATEITEMS", u.getReuseOfOnceState().equals(1) ? "2" : "1");// 是否一次性使用物料 0:否1 material.put("DUPLICATEITEMS", u.getReuseOfOnceState().equals(1) ? "2" : "1");// 是否一次性使用物料 0:否1
material.put("categoryTreeName", u.getCategoryNameTree()); material.put("categoryTreeName", u.getCategoryNameTree());
material.put("FWEIGHT", u.getMaterialWeight()); material.put("FWEIGHT", u.getMaterialWeight());
if (StringUtils.isNotEmpty(relCategoryCode)) { if (StringUtils.isNotEmpty(relCategoryCode)) {
if (relCategoryCode.equals(MaterialRelCategoryCodeEnum.relCategoryCode_21.getRelCategoryCode()) || relCategoryCode.equals(MaterialRelCategoryCodeEnum.relCategoryCode_22.getRelCategoryCode())) { 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())); material.put("materialGetType", String.valueOf(u.getMaterialGetType()));
} else if ("701303".equals(u.getMaterialCategoryCode())) { }
// 701303 虽然按照采购形式申请但是OA流程类型 强制按照 自制
material.put("materialGetType", String.valueOf(MaterialMainGetTypeEnum.ZZ.getCode())); if (relCategoryCode.equals(MaterialRelCategoryCodeEnum.relCategoryCode_71.getRelCategoryCode())) {
} else { if ("701301".equals(u.getMaterialCategoryCode())) {
material.put("materialGetType", String.valueOf(MaterialMainGetTypeEnum.CG.getCode())); 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()))) { if (StringUtils.isNotEmpty(String.valueOf(u.getUseOfYear()))) {
material.put("USAGEYEAR", String.valueOf(u.getUseOfYear())); material.put("USAGEYEAR", String.valueOf(u.getUseOfYear()));
} }
material.put("picUrl", u.getPicUrl()); material.put("picUrl", u.getPicUrl());
// 中类小类细分类若有分类代码和名称都传给OA // 中类小类细分类若有分类代码和名称都传给OA
handleCategoryCodeAndName(material, u); handleCategoryCodeAndName(material, u);
list.add(material); list.add(material);
}); });
result.put("List", list); result.put("List", list);
log.info("物料申请-JSON" + JSONArray.toJSONString(list)); log.info("物料申请-JSON" + JSONArray.toJSONString(list));
HttpUtils httpUtils = new HttpUtils(); HttpUtils httpUtils = new HttpUtils();
try {
String url = NacosConfig.getNacosConfig().getOaUrl(); String url = NacosConfig.getNacosConfig().getOaUrl();
String reqResult = httpUtils.doPost(url, JSON.toJSONString(result)); String reqResult = httpUtils.doPost(url, JSON.toJSONString(result));
JSONObject jsonObject = JSONObject.parseObject(reqResult); JSONObject jsonObject = JSONObject.parseObject(reqResult);
@ -374,16 +397,16 @@ public class MaterialService {
message = StrUtil.isNotBlank(message) ? message : ""; message = StrUtil.isNotBlank(message) ? message : "";
throw new NflgBusinessException(STATE.BusinessError, "同步OA出错".concat(message)); throw new NflgBusinessException(STATE.BusinessError, "同步OA出错".concat(message));
} }
// return null; // return null;
} catch (Exception ex) { } catch (Exception ex) {
log.error("同步OA出错",ex); log.error("同步OA出错", ex);
throw new NflgBusinessException(STATE.BusinessError, "同步OA出错" + ex.getMessage()); 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<>(); Map<String, Object> result = new LinkedHashMap<>();
result.put("userid", SessionUtil.getUserCode()); result.put("userid", userCode);
result.put("summary", NacosConfig.getNacosConfig().getSummary()); result.put("summary", NacosConfig.getNacosConfig().getSummary());
return result; return result;
} }