package com.jcdm.main.om.productionOrde.service.impl; import java.util.List; import java.util.stream.Collectors; 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 org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** * 生产工单Service业务层处理 * * @author ruimin * @date 2023-12-11 */ @Service public class OmProductionOrdeInfoServiceImpl implements IOmProductionOrdeInfoService { @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("移动成功"); } }