zouyu
4 天以前 e1284aa3b1b400ecebb59126d7110a3bb4a6b000
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
package com.ruoyi.inspect.aspect;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.basic.pojo.IfsInventoryQuantity;
import com.ruoyi.common.utils.api.MesApiUtils;
import com.ruoyi.inspect.pojo.IfsSplitOrderRecord;
import com.ruoyi.inspect.service.IfsSplitOrderRecordService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
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.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
 
/**
 * 执行ifs移库操作后,同步推送mes实时库存
 */
@Aspect
@Slf4j
@Component
public class MoveLocationAfterPushMesStockAspect {
 
    @Autowired
    private IfsSplitOrderRecordService ifsSplitOrderRecordService;
 
    @Autowired
    private MesApiUtils mesApiUtils;
 
    private final static String LOCATION_NO = "WG-02-001";//mes外购合格库位
 
    @AfterReturning(value = "execution(* com.ruoyi.inspect.service.impl.InsOrderServiceImpl.moveRawMaterial(..))")
    @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
    public void doAfterReturning(JoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs();
        if(Objects.nonNull(args) && args.length>0) {
            IfsInventoryQuantity ifsInventoryQuantity = BeanUtil.toBean(args[0], IfsInventoryQuantity.class);
            if(Objects.nonNull(ifsInventoryQuantity) && ifsInventoryQuantity.getIsSplitOrder()==1){
                //查询对应批号的拆分记录
                IfsSplitOrderRecord one = ifsSplitOrderRecordService.getOne(Wrappers.<IfsSplitOrderRecord>lambdaQuery()
                        .eq(IfsSplitOrderRecord::getPartNo, ifsInventoryQuantity.getPartNo())
                        .eq(IfsSplitOrderRecord::getLotBatchNo, ifsInventoryQuantity.getUpdateBatchNo())
                        .eq(IfsSplitOrderRecord::getLineNo, ifsInventoryQuantity.getLineNo())
                        .eq(IfsSplitOrderRecord::getReleaseNo, ifsInventoryQuantity.getReleaseNo())
                        .eq(IfsSplitOrderRecord::getReceiptNo, ifsInventoryQuantity.getReceiptNo())
                        .eq(IfsSplitOrderRecord::getOrderNo, ifsInventoryQuantity.getOrderNo())
                        .last("limit 1")
                );
                if(Objects.nonNull(one)){
                    //同步MES实时库存
                    Map<String, Object> requestMap = new HashMap<>();
                    requestMap.put("partNo", one.getPartNo()); // 零件编号
                    requestMap.put("systemNo", one.getSystemNo()); // 系统编号
                    requestMap.put("spec", one.getSpec()); // 规格
                    requestMap.put("partBatchNo", one.getLotBatchNo()); // 零件批号
                    requestMap.put("stockQuantity", one.getLength()); // 库存数量1
                    requestMap.put("qty", one.getQtyStock()); // 库存数量2
                    requestMap.put("insulationColor", one.getInsulationColor()); // 绝缘颜色
                    requestMap.put("outerColor", one.getOuterColor()); // 外护颜色
                    requestMap.put("letteringInfo", one.getLetteringInfo()); // 印字信息
                    requestMap.put("reelNumber", one.getDrumNo()); // 盘号
                    requestMap.put("locationNo", LOCATION_NO); // 库位编号
                    requestMap.put("customerOrderNo", one.getOrderNo()); // 销售订单号
                    requestMap.put("stockSource", one.getStockSource()); // 库存来源
                    requestMap.put("remark", one.getRemark()); // 备注
 
                    String jsonStr = JSONUtil.toJsonStr(Collections.singletonList(requestMap));
                    boolean b = mesApiUtils.batchAddStock(jsonStr);
                    //同步成功,更新同步状态
                    if(b){
                        ifsSplitOrderRecordService.update(null,Wrappers.<IfsSplitOrderRecord>lambdaUpdate()
                                .set(IfsSplitOrderRecord::getSyncStatus,1)
                                .eq(IfsSplitOrderRecord::getId,one.getId()));
                    }
                }
            }
        }
    }
 
}