zouyu
8 天以前 79841a6a5ecd713a9f02d23552619cbba1c991ad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.ruoyi.inspect.aspect;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.ruoyi.basic.dto.IfsInventoryQuantityDto;
import com.ruoyi.basic.mapper.IfsInventoryQuantityMapper;
import com.ruoyi.basic.pojo.IfsInventoryQuantity;
import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.enums.ContractType;
import com.ruoyi.common.enums.OrderType;
import com.ruoyi.common.utils.api.IfsApiUtils;
import com.ruoyi.inspect.dto.IfsPartPropsRecordDTO;
import com.ruoyi.inspect.service.IfsPartPropsRecordService;
import com.ruoyi.inspect.service.IfsSplitOrderRecordService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.*;
 
/**
 * 外购下单:KJNS域订单免检后,查询ZTNS域相同订单的批次属性并推送到IFS
 */
@Aspect
@Slf4j
@Component
public class PushIfsPartPropsRecordAspect {
 
    @Autowired
    private IfsInventoryQuantityMapper ifsInventoryQuantityMapper;
 
    @Autowired
    private IfsApiUtils ifsApiUtils;
 
    @Autowired
    private IfsPartPropsRecordService ifsPartPropsRecordService;
 
    @Before(value = "execution(* com.ruoyi.inspect.service.impl.RawMaterialOrderServiceImpl.rawOrderRelease(..))")
    @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
    public void doAfterReturning(JoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs();
        if(Objects.nonNull(args) && args.length>0) {
            Long ifsInventoryId = (Long)args[0];
            IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(ifsInventoryId);
            //查询ifs批次属性记录,有则不执行操作
            Map<String, Object> queryMap = new HashMap<>();
            queryMap.put("LOT_BATCH_NO",ifsInventoryQuantity.getUpdateBatchNo());
            queryMap.put("PART_NO",ifsInventoryQuantity.getPartNo());
            Result queryPartLotResult = ifsApiUtils.queryPartLotAttr(ContractType.KJNS.getValue(), JSONUtil.toJsonStr(queryMap));
            if(queryPartLotResult.getCode()==200){
                JSONObject entries = JSONUtil.parseObj(queryPartLotResult.getData());
                JSONArray listInfo = entries.getJSONArray("LIST_INFO");
                //如果订单是KJNS域的外购订单,免检时同步ZTNS域的IFS批次属性
                if(StringUtils.equals(ContractType.KJNS.getValue(),ifsInventoryQuantity.getContract()) && StringUtils.equals(OrderType.WG.getValue(),ifsInventoryQuantity.getOrderType()) && listInfo.isEmpty()){
                    //查询ZTNS域的相同批次订单消息
                    IfsInventoryQuantityDto ifsInventoryQuantityDto = new IfsInventoryQuantityDto();
                    BeanUtil.copyProperties(ifsInventoryQuantity,ifsInventoryQuantityDto);
                    ifsInventoryQuantityDto.setContract(ContractType.ZTNS.getValue());
                    IfsPartPropsRecordDTO oneByContract = ifsPartPropsRecordService.getOneByContract(ifsInventoryQuantityDto);
                    if(Objects.nonNull(oneByContract)){
                        //更新IFS批次属性
                        Map<String, Object> inAttrMap = new HashMap<>();
                        String actionType = "New";
                        inAttrMap.put("RECORD_ID", UUID.randomUUID().toString());
                        inAttrMap.put("SYSCODE", "LIMS");
                        inAttrMap.put("SYSMODEL", "库存物料批次属性修改");
                        HashMap<String, Object> batchInfoMap = new HashMap<>();
                        batchInfoMap.put("CONTRACT",ContractType.KJNS.getValue());//域
                        batchInfoMap.put("PART_NO",oneByContract.getPartNo());//零件号
                        batchInfoMap.put("LOT_BATCH_NO",oneByContract.getLotBatchNo());//批次号
                        batchInfoMap.put("ATTR1",oneByContract.getDrumNo());//载具编号
                        batchInfoMap.put("ATTR2",oneByContract.getStartMeterMark().toString());//起始米标
                        batchInfoMap.put("ATTR3",oneByContract.getEndMeterMark().toString());//截止米标
                        batchInfoMap.put("ATTR4", oneByContract.getOuterColor());//外护颜色
                        batchInfoMap.put("ATTR5",oneByContract.getInsulationColor());//绝缘颜色
                        batchInfoMap.put("ATTR8",oneByContract.getLetteringInfo());//印字信息
                        batchInfoMap.put("ATTR23","车间订单");//入库来源
                        batchInfoMap.put("ATTR24","0");//分割预留数量
                        batchInfoMap.put("ACTION_TYPE",actionType);//操作类型
                        inAttrMap.put("BATCH_INFO", Collections.singletonList(batchInfoMap));
                        Result result = ifsApiUtils.importPartLotAttr(ContractType.KJNS.getValue(), JSONUtil.toJsonStr(inAttrMap));
                        if(result.getCode()!=200){
                            throw new RuntimeException("库存物料批次属性更新失败:"+result.getMessage());
                        }
                    }
                    ifsPartPropsRecordService.save(oneByContract);
                }
            }
        }
    }
 
}