package com.billion.main.da.service.impl; import java.text.SimpleDateFormat; import java.util.Arrays; 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.om.domain.OmOrderScheduling; 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; import com.billion.main.da.domain.DaMaterialCollection; import com.billion.main.da.service.IDaMaterialCollectionService; /** * 物料采集Service业务层处理 * * @author Billion-Yi * @date 2024-11-22 */ @Slf4j @Service public class DaMaterialCollectionServiceImpl extends ServiceImpl implements IDaMaterialCollectionService { @Autowired private DaMaterialCollectionMapper daMaterialCollectionMapper; @Autowired public IBsBomChildInfoService bsBomChildInfoService; @Autowired public IOmOrderSchedulingService omOrderSchedulingService; /** * 查询物料采集 * * @param id 物料采集主键 * @return 物料采集 */ @Override public DaMaterialCollection selectDaMaterialCollectionById(Long id) { return daMaterialCollectionMapper.selectDaMaterialCollectionById(id); } /** * 查询物料采集列表 * * @param daMaterialCollection 物料采集 * @return 物料采集 */ @Override public List selectDaMaterialCollectionList(DaMaterialCollection daMaterialCollection) { return daMaterialCollectionMapper.selectDaMaterialCollectionList(daMaterialCollection); } /** * 新增物料采集 * * @param daMaterialCollection 物料采集 * @return 结果 */ @Override public void insertDaMaterialCollection(DaMaterialCollection 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( Constants.PLC1.contains(daMaterialCollection.getLocationCode()) || Constants.C005.equals(daMaterialCollection.getLocationCode()) || Constants.C060.equals(daMaterialCollection.getLocationCode()) ) {omOrderScheduling.setRemarks("Head");} else if( Constants.PLC2.contains(daMaterialCollection.getLocationCode()) || Constants.OP005.equals(daMaterialCollection.getLocationCode()) || Constants.OP310.equals(daMaterialCollection.getLocationCode())) {omOrderScheduling.setRemarks("Body");} else if(Constants.P010.equals(daMaterialCollection.getLocationCode())) {omOrderScheduling.setRemarks("Pre");} List omOrderSchedulingList = omOrderSchedulingService.selectOmOrderSchedulingList(omOrderScheduling); String OrderNumber = omOrderSchedulingList.get(0).getWorkOrderNo(); bsBomChildInfo.setLocationCode(daMaterialCollection.getLocationCode()); bsBomChildInfo.setBomCode(OrderNumber); String[] parts = daMaterialCollection.getParamValue().split("#"); String targetValue = parts[1]; // 取第二个元素(索引1) bsBomChildInfo.setMaterialCode(targetValue); List bsBomChildInfoList = bsBomChildInfoService.selectBsBomChildInfoList(bsBomChildInfo); String MaterialCode = bsBomChildInfoList.get(0).getMaterialCode(); String MaterialName = bsBomChildInfoList.get(0).getMaterialName(); daMaterialCollection1.setMaterialCode(MaterialCode); daMaterialCollection1.setMaterialName(MaterialName); this.save(daMaterialCollection1); collectMT.setMaterial1(MaterialName); collectMT.setOrderNumber(OrderNumber); 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(daMaterialCollection); } @Override public void plusSave(DaMaterialCollection 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()); omOrderScheduling.setSfcCode(daMaterialCollection.getSfcCode()); if( Constants.PLC1.contains(daMaterialCollection.getLocationCode()) || Constants.C005.equals(daMaterialCollection.getLocationCode()) || Constants.C060.equals(daMaterialCollection.getLocationCode()) ) {omOrderScheduling.setRemarks("Head");} else if( Constants.PLC2.contains(daMaterialCollection.getLocationCode()) || Constants.OP005.equals(daMaterialCollection.getLocationCode()) || Constants.OP310.equals(daMaterialCollection.getLocationCode())) {omOrderScheduling.setRemarks("Body");} else if(Constants.P010.equals(daMaterialCollection.getLocationCode())) {omOrderScheduling.setRemarks("Pre");} List omOrderSchedulingList = omOrderSchedulingService.selectOmOrderSchedulingList(omOrderScheduling); String OrderNumber = omOrderSchedulingList.get(0).getWorkOrderNo(); String[] parts = daMaterialCollection.getParamValue().split("#"); String targetValue = parts[1]; // 取第二个元素(索引1) daMaterialCollection1.setMaterialCode(targetValue); daMaterialCollection1.setMaterialName(daMaterialCollection.getParamName()); this.save(daMaterialCollection1); collectMT.setMaterial1(daMaterialCollection.getMaterialName()); collectMT.setOrderNumber(OrderNumber); 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("推送失败"); } } /** * 修改物料采集 * * @param daMaterialCollection 物料采集 * @return 结果 */ @Override public int updateDaMaterialCollection(DaMaterialCollection daMaterialCollection) { return daMaterialCollectionMapper.updateDaMaterialCollection(daMaterialCollection); } /** * 批量删除物料采集 * * @param ids 需要删除的物料采集主键 * @return 结果 */ @Override public int deleteDaMaterialCollectionByIds(Long[] ids) { return daMaterialCollectionMapper.deleteDaMaterialCollectionByIds(ids); } /** * 删除物料采集信息 * * @param id 物料采集主键 * @return 结果 */ @Override public int deleteDaMaterialCollectionById(Long id) { return daMaterialCollectionMapper.deleteDaMaterialCollectionById(id); } }