package com.jcdm.main.om.productionOrde.service.impl; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.stream.Collectors; import cn.hutool.core.util.ObjectUtil; import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.jcdm.common.core.domain.AjaxResult; import com.jcdm.common.utils.DateUtils; import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo; import com.jcdm.main.om.productionOrde.mapper.OmProductionOrdeInfoMapper; import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService; import com.jcdm.main.restful.factoryMes.service.RestfulService; import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** * 生产工单Service业务层处理 * * @author ruimin * @date 2023-12-11 */ @Slf4j @Service public class OmProductionOrdeInfoServiceImpl extends ServiceImpl implements IOmProductionOrdeInfoService { private static final Logger logger = LoggerFactory.getLogger("sys-user"); public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @Autowired private OmProductionOrdeInfoMapper omProductionOrdeInfoMapper; @Autowired private IOmProductionOrdeInfoService omProductionOrdeInfoService; /** * 查询生产工单 * * @param id 生产工单主键 * @return 生产工单 */ @Override public OmProductionOrdeInfo selectOmProductionOrdeInfoById(Long id) { return omProductionOrdeInfoMapper.selectOmProductionOrdeInfoById(id); } /** * 查询生产工单列表 * * @param omProductionOrdeInfo 生产工单 * @return 生产工单 */ @Override public List selectOmProductionOrdeInfoList(OmProductionOrdeInfo omProductionOrdeInfo) { return omProductionOrdeInfoMapper.selectOmProductionOrdeInfoList(omProductionOrdeInfo); } /** * 新增生产工单 * * @param omProductionOrdeInfo 生产工单 * @return 结果 */ @Override public int insertOmProductionOrdeInfo(OmProductionOrdeInfo omProductionOrdeInfo) { omProductionOrdeInfo.setCreateTime(DateUtils.getNowDate()); Integer streamNumber = omProductionOrdeInfoMapper.getMaxStreamNumber(); omProductionOrdeInfo.setStreamNumber(String.valueOf(streamNumber+1)); return omProductionOrdeInfoMapper.insertOmProductionOrdeInfo(omProductionOrdeInfo); } /** * 修改生产工单 * * @param omProductionOrdeInfo 生产工单 * @return 结果 */ @Override public int updateOmProductionOrdeInfo(OmProductionOrdeInfo omProductionOrdeInfo) { omProductionOrdeInfo.setUpdateTime(DateUtils.getNowDate()); return omProductionOrdeInfoMapper.updateOmProductionOrdeInfo(omProductionOrdeInfo); } /** * 批量删除生产工单 * * @param ids 需要删除的生产工单主键 * @return 结果 */ @Override public int deleteOmProductionOrdeInfoByIds(Long[] ids) { return omProductionOrdeInfoMapper.deleteOmProductionOrdeInfoByIds(ids); } /** * 删除生产工单信息 * * @param id 生产工单主键 * @return 结果 */ @Override public int deleteOmProductionOrdeInfoById(Long id) { return omProductionOrdeInfoMapper.deleteOmProductionOrdeInfoById(id); } @Override public AjaxResult upDownMove(OmProductionOrdeInfo omProductionOrdeInfo) { long currentId = omProductionOrdeInfo.getFrontEndId(); List omProductionOrdeInfos = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(omProductionOrdeInfo); List idList = omProductionOrdeInfos.stream() .map(OmProductionOrdeInfo::getId) // 提取id属性 .collect(Collectors.toList()); int index = idList.indexOf(currentId); long moveId = 0L; try { if(omProductionOrdeInfo.getFlag().equals("up")){ moveId = idList.get(index - 1); }else { moveId = idList.get(index + 1); } }catch (Exception e){ return AjaxResult.error("当前工单为最后一个或第一个,无法移动"); } OmProductionOrdeInfo currentInfo = new OmProductionOrdeInfo(); currentInfo.setId(currentId); List currentOrdeInfos = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(currentInfo); String currentStreamNumber = currentOrdeInfos.get(0).getStreamNumber(); OmProductionOrdeInfo moveInfo = new OmProductionOrdeInfo(); moveInfo.setId(moveId); List moveOrdeInfos = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(moveInfo); String moveStreamNumber = moveOrdeInfos.get(0).getStreamNumber(); moveOrdeInfos.get(0).setStreamNumber(currentStreamNumber); omProductionOrdeInfoService.updateOmProductionOrdeInfo(moveOrdeInfos.get(0)); currentOrdeInfos.get(0).setStreamNumber(moveStreamNumber); omProductionOrdeInfoService.updateOmProductionOrdeInfo(currentOrdeInfos.get(0)); return AjaxResult.success("移动成功"); } @Override public void overrideSaveBatch(List omProductionOrdeInfoList) { try { this.saveBatch(omProductionOrdeInfoList); }catch (Exception e){ return; } } @Override public AjaxResult receivingWorkOrders() { return null; } @Override public AjaxResult trolleyYardBinDing(OmProductionOrdeInfo omProductionOrdeInfo) { OmProductionOrdeInfo clearTrolleyYard = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper().eq(OmProductionOrdeInfo::getTrolleyYard, omProductionOrdeInfo.getTrolleyYard())); if(clearTrolleyYard!=null){ clearTrolleyYard.setTrolleyYard(""); omProductionOrdeInfoService.saveOrUpdate(clearTrolleyYard); } OmProductionOrdeInfo one = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper().eq(OmProductionOrdeInfo::getProductNum, omProductionOrdeInfo.getProductNum())); one.setTrolleyYard(omProductionOrdeInfo.getTrolleyYard()); omProductionOrdeInfoService.saveOrUpdate(one); logger.info("绑定pack码{}到小车:{}",omProductionOrdeInfo.getProductNum(),omProductionOrdeInfo.getTrolleyYard()); return AjaxResult.success(); } @Override public AjaxResult getCarCodeSize(OmProductionOrdeInfo omProductionOrdeInfo) { // omProductionOrdeInfo. return null; } @Override public AjaxResult findBytrolleyYardGetOne(OmProductionOrdeInfo omProductionOrdeInfo) { String str = ""; OmProductionOrdeInfo one = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper().eq(OmProductionOrdeInfo::getTrolleyYard, omProductionOrdeInfo.getTrolleyYard())); if(one == null){ str = "2"; }else { str = one.getProductNum(); } return AjaxResult.success(str); } @Override public List checkCarCode(OmProductionOrdeInfo omProductionOrdeInfo) { List list = omProductionOrdeInfoService.list(new LambdaQueryWrapper().eq(OmProductionOrdeInfo::getProductNum, omProductionOrdeInfo.getProductNum()).isNotNull(OmProductionOrdeInfo::getTrolleyYard)); return list; } @Override public AjaxResult workReportingByStation(OmProductionOrdeInfo info) { OmProductionOrdeInfo omProductionOrdeInfo = omProductionOrdeInfoService.getById(info.getId()); logger.info("OP230报工开始-工厂MES异步方法"); String reportResult = RestfulService.getWorkReportResultFeedback(omProductionOrdeInfo.getProductNum(), info.getStationCode(), format.format(new Date())); JSONObject jsonObject = new JSONObject(reportResult); String code = jsonObject.getStr("code"); String status = jsonObject.getJSONObject("data").getStr("resultCode"); if("success".equals(code)&&"S".equals(status)){ //如果成功,执行报工成功方法,修改是否报工为1,添加报工时间 this.updateOrderByProductNum("1",omProductionOrdeInfo.getProductNum(),info.getStationCode()); }else{ //解析工厂mes返回结果,如果失败,执行报工失败方法,修改是否报工为2,添加报工时间 this.updateOrderByProductNum("2",omProductionOrdeInfo.getProductNum(),info.getStationCode()); } return null; } @Override public void updateOrderByProductNum(String onlineCompletionMark, String productNum, String stationCode) { LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); if(stationCode.contains("M1OP100")){ updateWrapper.set(OmProductionOrdeInfo::getOnlineCompletionMark,onlineCompletionMark); updateWrapper.set(OmProductionOrdeInfo::getActualStartTime,new Date()); } if(stationCode.equals("MOP220")){ updateWrapper.set(OmProductionOrdeInfo::getSfResult,onlineCompletionMark); } updateWrapper.eq(OmProductionOrdeInfo::getProductNum,productNum); OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo(); omProductionOrdeInfoService.update(omProductionOrdeInfo,updateWrapper); } @Override public OmProductionOrdeInfo getLastOrder() { return omProductionOrdeInfoMapper.getLastOrder(); } @Override public List listLoopLine(OmProductionOrdeInfo omProductionOrdeInfo) { return omProductionOrdeInfoMapper.listLoopLine(omProductionOrdeInfo); } }