zouyu
2026-05-09 e9e88eefcc8abd2b1e187d28c7666e80307e97cc
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package com.ruoyi.inspect.service.impl;
 
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.TypeReference;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.OrderType;
import com.ruoyi.common.utils.api.IfsApiUtils;
import com.ruoyi.inspect.dto.IfsPartPropsRecordDTO;
import com.ruoyi.inspect.mapper.IfsPartPropsRecordMapper;
import com.ruoyi.inspect.mapper.IfsSplitOrderRecordMapper;
import com.ruoyi.inspect.pojo.IfsPartPropsRecord;
import com.ruoyi.inspect.pojo.IfsSplitOrderRecord;
import com.ruoyi.inspect.service.IfsPartPropsRecordService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
 
import java.math.BigDecimal;
import java.util.*;
 
/**
* @author 27233
* @description 针对表【ifs_part_props_record(ifs订单零件属性记录表)】的数据库操作Service实现
* @createDate 2025-10-23 15:00:34
*/
@Slf4j
@Service
public class IfsPartPropsRecordServiceImpl extends ServiceImpl<IfsPartPropsRecordMapper, IfsPartPropsRecord>
    implements IfsPartPropsRecordService{
 
    @Autowired
    private IfsApiUtils ifsApiUtils;
 
    @Autowired
    private IfsInventoryQuantityMapper ifsInventoryQuantityMapper;
 
    @Autowired
    private IfsSplitOrderRecordMapper ifsSplitOrderRecordMapper;
 
    @Autowired
    private IfsPartPropsRecordMapper ifsPartPropsRecordMapper;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveOrUpdateProps(IfsPartPropsRecordDTO ifsPartPropsRecord) {
        if(Objects.isNull(ifsPartPropsRecord)){
            throw new RuntimeException("参数不能为空");
        }
        //判断是新增还是更新
        String actionType = Objects.isNull(ifsPartPropsRecord.getId())?"New":"Modify";
        Map<String, Object> inAttrMap = new HashMap<>();
        inAttrMap.put("RECORD_ID", UUID.randomUUID().toString());
        inAttrMap.put("SYSCODE", "LIMS");
        inAttrMap.put("SYSMODEL", "库存物料批次属性修改");
        HashMap<String, Object> batchInfoMap = new HashMap<>();
        batchInfoMap.put("CONTRACT",ifsPartPropsRecord.getContract());//域
        batchInfoMap.put("PART_NO",ifsPartPropsRecord.getPartNo());//零件号
        batchInfoMap.put("LOT_BATCH_NO",ifsPartPropsRecord.getLotBatchNo());//批次号
        batchInfoMap.put("ATTR1",ifsPartPropsRecord.getDrumNo());//载具编号
        batchInfoMap.put("ATTR2",ifsPartPropsRecord.getStartMeterMark().toString());//起始米标
        batchInfoMap.put("ATTR3",ifsPartPropsRecord.getEndMeterMark().toString());//截止米标
        batchInfoMap.put("ATTR4", ifsPartPropsRecord.getOuterColor());//外护颜色
        batchInfoMap.put("ATTR5",ifsPartPropsRecord.getInsulationColor());//绝缘颜色
        batchInfoMap.put("ATTR8",ifsPartPropsRecord.getLetteringInfo());//印字信息
        batchInfoMap.put("ATTR23","车间订单");//入库来源
        batchInfoMap.put("ATTR24","0");//分割预留数量
        batchInfoMap.put("ACTION_TYPE",actionType);//操作类型
        inAttrMap.put("BATCH_INFO", Collections.singletonList(batchInfoMap));
        Result result = ifsApiUtils.importPartLotAttr(ifsPartPropsRecord.getContract(),JSONUtil.toJsonStr(inAttrMap));
        if(result.getCode()!=200){
            throw new RuntimeException("库存物料批次属性更新失败:"+result.getMessage());
        }
        return this.saveOrUpdate(ifsPartPropsRecord);
    }
 
 
    @Override
    @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
    public IfsPartPropsRecord getOneByIfsId(Long ifsId) {
        //查询ifs订单信息
        IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(ifsId);
        if(Objects.isNull(ifsInventoryQuantity)){
            throw new RuntimeException("未找到对应的IFS订单信息");
        }
        //判断是否是拆分订单
        if(ifsInventoryQuantity.getIsSplitOrder().equals(1)&& StringUtils.equals(ifsInventoryQuantity.getOrderType(), OrderType.RAW.getValue())){
            //查询拆分记录
            IfsSplitOrderRecord splitRecord = ifsSplitOrderRecordMapper.selectOne(Wrappers.<IfsSplitOrderRecord>lambdaQuery()
                    .eq(IfsSplitOrderRecord::getOrderNo, ifsInventoryQuantity.getOrderNo())
                    .eq(IfsSplitOrderRecord::getPartNo, ifsInventoryQuantity.getPartNo())
                    .eq(IfsSplitOrderRecord::getReleaseNo, ifsInventoryQuantity.getReleaseNo())
                    .eq(IfsSplitOrderRecord::getLineNo, ifsInventoryQuantity.getLineNo())
                    .eq(IfsSplitOrderRecord::getReceiptNo, ifsInventoryQuantity.getReceiptNo())
                    .eq(IfsSplitOrderRecord::getLotBatchNo, ifsInventoryQuantity.getUpdateBatchNo())
                    .eq(IfsSplitOrderRecord::getOrderNo, ifsInventoryQuantity.getOrderNo())
            );
            if(Objects.isNull(splitRecord)){
                throw new RuntimeException("未找到零件的拆分信息");
            }
            IfsPartPropsRecord ifsPartPropsRecord = new IfsPartPropsRecord();
            ifsPartPropsRecord.setDrumNo(splitRecord.getDrumNo());
            ifsPartPropsRecord.setLetteringInfo(splitRecord.getLetteringInfo());
            ifsPartPropsRecord.setInsulationColor(splitRecord.getInsulationColor());
            ifsPartPropsRecord.setOuterColor(splitRecord.getOuterColor());
            return ifsPartPropsRecord;
        }
        //查询批次属性记录
        IfsPartPropsRecord propsRecord = this.getOne(Wrappers.<IfsPartPropsRecord>lambdaQuery().eq(IfsPartPropsRecord::getIfsInventoryId, ifsId).last("limit 1"));
        if(ObjectUtil.isNotEmpty(propsRecord)){
            return propsRecord;
        }
        //查询ifs批次属性记录,有就先新增到数据库
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("LOT_BATCH_NO",ifsInventoryQuantity.getUpdateBatchNo());
        queryMap.put("PART_NO",ifsInventoryQuantity.getPartNo());
        Result queryPartLotResult = ifsApiUtils.queryPartLotAttr(ifsInventoryQuantity.getContract(), JSONUtil.toJsonStr(queryMap));
        if(queryPartLotResult.getCode()==200){
            JSONObject entries = JSONUtil.parseObj(queryPartLotResult.getData());
            JSONArray listInfo = entries.getJSONArray("LIST_INFO");
            if(!listInfo.isEmpty()){
                Map<String,Object> parseObject = com.alibaba.fastjson2.JSONObject.parseObject(JSONUtil.toJsonStr(listInfo.get(0)), new TypeReference<Map<String, Object>>() {}.getType());
                IfsPartPropsRecord ifsPartPropsRecord = new IfsPartPropsRecord();
                ifsPartPropsRecord.setIfsInventoryId(ifsInventoryQuantity.getId());//ifs订单id
                ifsPartPropsRecord.setDrumNo(parseObject.get("ATTR1").toString());//载具编号
                BigDecimal startMeterMark = ObjectUtils.isNotEmpty(parseObject.get("ATTR2"))?new BigDecimal(parseObject.get("ATTR2").toString()):BigDecimal.ZERO;
                BigDecimal endMeterMark = ObjectUtils.isNotEmpty(parseObject.get("ATTR3"))?new BigDecimal(parseObject.get("ATTR3").toString()):BigDecimal.ZERO;
                ifsPartPropsRecord.setStartMeterMark(startMeterMark);//起始米标
                ifsPartPropsRecord.setEndMeterMark(endMeterMark);//截止米标
                ifsPartPropsRecord.setOuterColor(parseObject.get("ATTR4").toString());//外护颜色
                ifsPartPropsRecord.setInsulationColor(parseObject.get("ATTR5").toString());//绝缘颜色
                ifsPartPropsRecord.setLetteringInfo(parseObject.get("ATTR8").toString());//印字信息
                ifsPartPropsRecordMapper.insert(ifsPartPropsRecord);
            }
        }
        return this.getOne(Wrappers.<IfsPartPropsRecord>lambdaQuery().eq(IfsPartPropsRecord::getIfsInventoryId, ifsId).last("limit 1"));
    }
 
    @Override
    public IfsPartPropsRecordDTO getOneByContract(IfsInventoryQuantityDto ifsInventoryQuantityDto) {
        return baseMapper.selectOneByContract(ifsInventoryQuantityDto);
    }
}