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; 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; public IBsBomChildInfoService bsBomChildInfoService; 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(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 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 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); } /** * 修改物料采集 * * @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); } }