package com.jcdm.main.om.productionOrde.service.impl; import java.util.List; import java.util.stream.Collectors; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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"); @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; } }