zouyu
10 天以前 c935e18fab3604e493de29b164ea4019244bb182
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/IfsPartPropsRecordServiceImpl.java
@@ -1,6 +1,10 @@
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;
@@ -16,12 +20,14 @@
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.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
/**
@@ -42,6 +48,9 @@
    @Autowired
    private IfsSplitOrderRecordMapper ifsSplitOrderRecordMapper;
    @Autowired
    private IfsPartPropsRecordMapper ifsPartPropsRecordMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -78,6 +87,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
    public IfsPartPropsRecord getOneByIfsId(Long ifsId) {
        //查询ifs订单信息
        IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(ifsId);
@@ -104,17 +114,66 @@
            ifsPartPropsRecord.setLetteringInfo(splitRecord.getLetteringInfo());
            ifsPartPropsRecord.setInsulationColor(splitRecord.getInsulationColor());
            ifsPartPropsRecord.setOuterColor(splitRecord.getOuterColor());
            ifsPartPropsRecord.setDrumNo(splitRecord.getDrumNo());
            ifsPartPropsRecord.setDrumNo(splitRecord.getDrumNo());
            return ifsPartPropsRecord;
        }
        return this.getOne(Wrappers.<IfsPartPropsRecord>lambdaQuery().eq(IfsPartPropsRecord::getIfsInventoryId,ifsId).last("limit 1"));
        //查询批次属性记录
        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);
    }
    @Override
    public IfsPartPropsRecordDTO getIfsPartProps(IfsInventoryQuantityDto ifsPartPropsRecordDTO) {
        validateParams(ifsPartPropsRecordDTO);
        ifsPartPropsRecordDTO.setOrderType(OrderType.WG.getValue());
        return baseMapper.selectOneByContract(ifsPartPropsRecordDTO);
    }
    void validateParams(IfsInventoryQuantityDto ifsPartPropsRecordDTO){
        if(Objects.isNull(ifsPartPropsRecordDTO)){
            throw new RuntimeException("传入参数不能为空");
        }
        if(StringUtils.isBlank(ifsPartPropsRecordDTO.getContract())){
            throw new RuntimeException("工厂域不能为空");
        }
        if(StringUtils.isBlank(ifsPartPropsRecordDTO.getUpdateBatchNo())){
            throw new RuntimeException("批次号不能为空");
        }
        if(StringUtils.isBlank(ifsPartPropsRecordDTO.getPartNo())){
            throw new RuntimeException("零件号不能为空");
        }
    }
}