hdy
2025-03-18 3f23422c13226ce37150afed0b4d8d0309da45d3
billion-main/src/main/java/com/billion/main/da/service/impl/DaMaterialCollectionServiceImpl.java
@@ -1,8 +1,22 @@
package com.billion.main.da.service.impl;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Objects;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.billion.main.bs.domain.BsBomChildInfo;
import com.billion.main.bs.service.IBsBomChildInfoService;
import com.billion.main.constant.Constants;
import com.billion.main.da.domain.CollectMT;
import com.billion.main.da.domain.CollectTrack;
import com.billion.main.om.domain.OmOrderScheduling;
import com.billion.main.om.domain.OmProductionOrderInfo;
import com.billion.main.om.service.IOmOrderSchedulingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.billion.main.da.mapper.DaMaterialCollectionMapper;
@@ -15,12 +29,15 @@
 * @author Billion-Yi
 * @date 2024-11-22
 */
@Slf4j
@Service
public class DaMaterialCollectionServiceImpl extends ServiceImpl<DaMaterialCollectionMapper, DaMaterialCollection> implements IDaMaterialCollectionService
{
    @Autowired
    private DaMaterialCollectionMapper daMaterialCollectionMapper;
    public IBsBomChildInfoService bsBomChildInfoService;
    public IOmOrderSchedulingService omOrderSchedulingService;
    /**
     * 查询物料采集
     * 
@@ -54,7 +71,55 @@
    @Override
    public void insertDaMaterialCollection(DaMaterialCollection daMaterialCollection)
    {
        this.save(daMaterialCollection);
        String url = "http://172.40.161.71:8890/Interaction/CollectMT";
        CollectMT collectMT = new CollectMT();
        DaMaterialCollection  daMaterialCollection1 = new DaMaterialCollection();
        BsBomChildInfo bsBomChildInfo = new BsBomChildInfo();
        OmOrderScheduling omOrderScheduling = new OmOrderScheduling();
        daMaterialCollection1.setSfcCode(daMaterialCollection.getSfcCode());
        daMaterialCollection1.setLocationCode(daMaterialCollection.getLocationCode());
        daMaterialCollection1.setParamValue(daMaterialCollection.getParamValue());
        daMaterialCollection1.setCollectTime(daMaterialCollection.getCollectTime());
        omOrderScheduling.setSfcCode(daMaterialCollection.getSfcCode());
        if(Objects.equals(daMaterialCollection.getLocationCode(), "OP130") || Objects.equals(daMaterialCollection.getLocationCode(), "OP020")){
            daMaterialCollection1.setMaterialCode("");
            daMaterialCollection1.setMaterialName(daMaterialCollection.getMaterialName());
            collectMT.setMaterial1(daMaterialCollection1.getParamName());
        }else{
            bsBomChildInfo.setLocationCode(daMaterialCollection.getLocationCode());
            String materialCode = daMaterialCollection.getSfcCode().length() > 9 ? daMaterialCollection.getSfcCode().substring(0, daMaterialCollection.getSfcCode().length() - 9) : daMaterialCollection.getSfcCode();
            bsBomChildInfo.setMaterialCode(materialCode);
            List<BsBomChildInfo> bsBomChildInfoList = bsBomChildInfoService.selectBsBomChildInfoList(bsBomChildInfo);
            daMaterialCollection1.setMaterialCode(bsBomChildInfoList.get(0).getMaterialCode());
            daMaterialCollection1.setMaterialName(bsBomChildInfoList.get(0).getMaterialName());
            collectMT.setMaterial1(bsBomChildInfoList.get(0).getMaterialName());
        }
        if(Objects.equals(daMaterialCollection.getLocationCode(), Constants.PLC1.toString()) ||
                Objects.equals(daMaterialCollection.getLocationCode(), Constants.C005) ||
                Objects.equals(daMaterialCollection.getLocationCode(), Constants.C060))
        {omOrderScheduling.setRemarks("Head");}
        else if(Objects.equals(daMaterialCollection.getLocationCode(), Constants.PLC2.toString()) ||
                Objects.equals(daMaterialCollection.getLocationCode(), Constants.OP005) ||
                Objects.equals(daMaterialCollection.getLocationCode(), Constants.OP310))
        {omOrderScheduling.setRemarks("Body");}
        else if(Objects.equals(daMaterialCollection.getLocationCode(), Constants.P010))
        {omOrderScheduling.setRemarks("Pre");}
        List<OmOrderScheduling> omOrderSchedulingList = omOrderSchedulingService.selectOmOrderSchedulingList(omOrderScheduling);
        collectMT.setOrderNumber(omOrderSchedulingList.get(0).getWorkOrderNo());
        collectMT.setEngineNumber(daMaterialCollection.getSfcCode());
        collectMT.setStationName(daMaterialCollection.getLocationCode());
        collectMT.setPartsNumber(daMaterialCollection.getParamValue());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        collectMT.setInsertTime(sdf.format(daMaterialCollection.getCollectTime()));
        try {
            HttpResponse response = HttpRequest.post(url).body(JSONUtil.toJsonStr(collectMT)).execute();
            log.info("推送成功,响应报文: {}", response);
        } catch (Exception e) {
            // 记录日志
            log.error("推送失败");
        }
        this.save(daMaterialCollection1);
//        this.save(daMaterialCollection);
    }
    /**