转EBOM合并相同行

This commit is contained in:
大米 2024-01-06 16:08:11 +08:00
parent 849f02d16a
commit 16f53a4fdb
9 changed files with 184 additions and 2 deletions

View File

@ -84,6 +84,27 @@ public class NacosConfig {
@Value("${material.add.url}")
private String addMaterialUrl;
@Value("${crm.token.url}")
private String crmTokenUrl;
@Value("${crm.order.url}")
private String crmOrderUrl;
@Value("${crm.grant_type}")
private String crmGrantType;
@Value("${crm.client_id}")
private String crmClientId;
@Value("${crm.client_secret}")
private String crmClientSecret;
@Value("${crm.username}")
private String crmUsername;
@Value("${crm.password}")
private String crmPassword;

View File

@ -22,4 +22,6 @@ public interface BomNewPbomParentMapper extends BaseMapper<BomNewPbomParentEntit
Page<BomNewPbomParentVO> workDetailsListByPage(Page<BomNewPbomParentQuery> page, @Param("query") BomNewPbomParentQuery query , @Param("userFac") String userFac);
List<BomNewPbomParentVO> getParentChild(@Param("parentRowId") Long parentRowId);
void bomRelease(@Param("releaseUserName")String releaseUserName, @Param("rowIds") List<Long> rowIds );
}

View File

@ -0,0 +1,19 @@
package com.nflg.product.bomnew.pojo.dto;
import lombok.Data;
/**
* crm 获取TONKEN 结果
*/
@Data
public class CrmGetTokenResultDTO {
private String access_token;
private String token_type;
private String signature;
private String instance_url;
}

View File

@ -319,7 +319,7 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
}
}
//动态判断异常
CheckEBomExceptoinDynamic.check(parentChild);
//CheckEBomExceptoinDynamic.check(parentChild);
return parentChild;
}

View File

@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.ImmutableList;
import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.base.core.exception.NflgBusinessException;
import com.nflg.product.bomnew.constant.*;
import com.nflg.product.bomnew.mapper.master.BomNewPbomParentMapper;
@ -73,6 +74,10 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
@Resource
private BomNewMbomDetailService mBomDetailService;
@Resource
private CrmService crmService;
/**
* pbom-工作列表
*
@ -432,6 +437,8 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
*/
@Transactional(rollbackFor = Exception.class)
public Boolean convertToMBom(Long bomRowId) throws ExecutionException, InterruptedException {
//获取CRM订单号
BomNewPbomParentEntity rootParent = this.getById(bomRowId);
List<BomNewPbomParentVO> allChild = getAllBom(bomRowId, 0);
@ -443,6 +450,17 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
if(CollUtil.isNotEmpty(convertToMBom.getMBomDetailResult())){
mBomDetailService.saveOrUpdateBatch(convertToMBom.getMBomDetailResult());
}
//将PBOM改为已发布
List<Long> bomRowIds = allChild.stream().filter(u -> u.getBomRowId() > 0).map(u -> u.getBomRowId()).collect(Collectors.toList());
rootParent.setOrderNo("订单号");
rootParent.setStatus(PBomStatusEnum.PUBLISH.getValue());
this.updateById(rootParent);
if(CollUtil.isNotEmpty(bomRowIds)){
this.getBaseMapper().bomRelease(SessionUtil.getRealName(),bomRowIds);
}
return true;
}
@ -452,7 +470,7 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
* @return
*/
public String getCrmOrderNo(String materialNo){
return "";
return crmService.getOrderNo(materialNo);
}
}

View File

@ -0,0 +1,101 @@
package com.nflg.product.bomnew.service;
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.ImmutableMap;
import com.nflg.product.bomnew.config.NacosConfig;
import com.nflg.product.bomnew.pojo.dto.CrmGetTokenResultDTO;
import com.nflg.product.bomnew.util.HttpUtils;
import com.nflg.product.bomnew.util.VUtils;
import org.springframework.stereotype.Service;
import springfox.documentation.spring.web.json.Json;
import javax.print.attribute.standard.MediaSize;
import java.io.IOException;
import java.util.*;
/**
* CRM 服务
*/
@Service
public class CrmService {
private final Integer expire =2* 60 * 60 * 1000;
private final String tokenCacheKey="CRM-TOKEN-CATCH-KEY";
TimedCache<String, String> crmTokenCache = CacheUtil.newTimedCache(expire);
/**
* 获取token
* @return
* @throws IOException
*/
public String getToken() throws IOException {
try {
if (StrUtil.isBlank(crmTokenCache.get(tokenCacheKey))) {
HttpUtils httpUtils = new HttpUtils();
Map<String, String> paramMp = new HashMap<>();
paramMp.put("grant_type", NacosConfig.getNacosConfig().getCrmGrantType());
paramMp.put("client_id", NacosConfig.getNacosConfig().getCrmClientId());
paramMp.put("username", NacosConfig.getNacosConfig().getCrmUsername());
paramMp.put("password", NacosConfig.getNacosConfig().getCrmPassword());
paramMp.put("client_secret", NacosConfig.getNacosConfig().getCrmClientSecret());
String s = httpUtils.doformPost(NacosConfig.getNacosConfig().getCrmTokenUrl(), paramMp);
CrmGetTokenResultDTO result = JSONObject.parseObject(s, CrmGetTokenResultDTO.class);
if (Objects.nonNull(result) && StrUtil.isNotBlank(result.getAccess_token())) {
crmTokenCache.put(tokenCacheKey, result.getAccess_token());
} else {
VUtils.isTure(true).throwMessage("获取CRM-token 失败");
}
}
return crmTokenCache.get(tokenCacheKey);
}
catch (Exception e) {
VUtils.isTure(true).throwMessage("获取CRM-token 失败:"+e.getMessage());
}
return "";
}
/**
* 获取订单号
* @param materialNo
* @return
*/
public String getOrderNo(String materialNo) {
try {
HttpUtils httpUtils = new HttpUtils();
Map<String, String> paramMp = new HashMap<>();
List<Map<String, String>> reBody = new ArrayList<>();
reBody.add(ImmutableMap.of("matnr", materialNo));
String token = StrUtil.join(" ", "Bearer", getToken());
String orderResult = httpUtils.doPost(NacosConfig.getNacosConfig().getCrmOrderUrl(), JSON.toJSONString(reBody), token);
JSONObject jsonObject = JSONObject.parseObject(orderResult);
String code = jsonObject.getString("code");
if (code == "0") {
String orderMap = jsonObject.getString("orderMap");
if (StrUtil.isNotBlank(orderMap)) {
JSONObject order = JSONObject.parseObject(orderMap);
return Objects.nonNull(order) ? order.getString(materialNo) : "";
}
}
return "";
}
catch (Exception ex){
VUtils.isTure(true).throwMessage("获取订单号失败:"+ex.getMessage());
}
return "";
}
}

View File

@ -372,10 +372,22 @@ public class OriginalBomToEBomConvert extends BaseConvert {
}
private void supplementMaterialInfoForNoMaterialNoByRel(List<BomOriginalListVO> data){
List<BomOriginalListVO> noMateralList = data.stream().filter(u -> StrUtil.isBlank(u.getMaterialNo())).collect(Collectors.toList());
for ( BomOriginalListVO item: noMateralList) {
handlerCommonMaterialForReplace(item);
}
}
/**
* 合并相同物料
*/
private List<BomOriginalListVO> mergeBOM(List<BomOriginalListVO> list) {
//合并补充物料信息
supplementMaterialInfoForNoMaterialNoByRel(list);
List<BomOriginalListVO> result = new ArrayList();
result.addAll(list.stream().filter(u->StrUtil.isBlank(u.getMaterialNo())).collect(Collectors.toList()));
list = list.stream().filter(u -> StrUtil.isNotBlank(u.getMaterialNo())).collect(Collectors.toList());

View File

@ -56,6 +56,7 @@ public class ConvertToMBom {
List<BomNewMbomDetailEntity> mBomDetailResult = new ArrayList<>();
public ConvertToMBom(BomNewPbomParentEntity inRootParent, List<BomNewPbomParentVO> inAllChild) {
this.parent = inRootParent;
this.allChild_1010 = Convert.toList(ConvertToMBomDTO.class, inAllChild);

View File

@ -85,6 +85,14 @@
<select id="getParentChild" resultType="com.nflg.product.bomnew.pojo.vo.BomNewPbomParentVO">
select * from t_bom_new_pbom_child where parent_row_id=#{parentRowId}
</select>
<!--bom发布-->
<update id="bomRelease">
update t_bom_new_pbom_parent set status=4 , release_user_name=#{releaseUserName} , release_time=now()
where row_id in
<foreach collection="rowIds" item="rowId" open="(" close=")" separator=",">
#{rowId}
</foreach>
</update>
</mapper>