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.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;
@ -25,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;
@ -36,6 +38,7 @@ import javax.annotation.Resource;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@Service
@ -52,6 +55,9 @@ public class MaterialService {
@Qualifier("syncOAThreadPool")
ThreadPoolTaskExecutor syncOAThreadPool;
@Resource
MaterialCategoryService materialCategoryService;
/**
* 申请物料
*
@ -169,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) {
@ -183,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())){
@ -198,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());
@ -210,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("最小物料类别不能为空");
@ -283,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("未设置对应分类"));
@ -303,8 +326,9 @@ public class MaterialService {
* @param data
*/
@Transactional(rollbackFor = Exception.class)
public void sysnToOa(List<AddMaterialMainDTO> data) {
Map<String, Object> result = getHttpMap();
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 -> {
@ -325,7 +349,7 @@ public class MaterialService {
material.put("MREMA", u.getMaterialDesc());
material.put("MMANU", u.getMaterialBrand());
material.put("ATTYP", relCategoryCode);
material.put("ERNAM", SessionUtil.getUserCode());
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());
@ -359,7 +383,6 @@ public class MaterialService {
result.put("List", list);
log.info("物料申请-JSON" + JSONArray.toJSONString(list));
HttpUtils httpUtils = new HttpUtils();
try {
String url = NacosConfig.getNacosConfig().getOaUrl();
String reqResult = httpUtils.doPost(url, JSON.toJSONString(result));
JSONObject jsonObject = JSONObject.parseObject(reqResult);
@ -374,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;
}