wujian
2024-02-22 268beb4ebc1e5b8d4ad715b71cd64a0944073a87
提交 | 用户 | 时间
268beb 1 package com.jcdm.main.om.productionOrde.service.impl;
W 2
3 import java.util.List;
4 import java.util.stream.Collectors;
5
6 import com.jcdm.common.core.domain.AjaxResult;
7 import com.jcdm.common.utils.DateUtils;
8 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
9 import com.jcdm.main.om.productionOrde.mapper.OmProductionOrdeInfoMapper;
10 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Service;
13
14 /**
15  * 生产工单Service业务层处理
16  * 
17  * @author ruimin
18  * @date 2023-12-11
19  */
20 @Service
21 public class OmProductionOrdeInfoServiceImpl implements IOmProductionOrdeInfoService
22 {
23     @Autowired
24     private OmProductionOrdeInfoMapper omProductionOrdeInfoMapper;
25
26     @Autowired
27     private IOmProductionOrdeInfoService omProductionOrdeInfoService;
28
29     /**
30      * 查询生产工单
31      * 
32      * @param id 生产工单主键
33      * @return 生产工单
34      */
35     @Override
36     public OmProductionOrdeInfo selectOmProductionOrdeInfoById(Long id)
37     {
38         return omProductionOrdeInfoMapper.selectOmProductionOrdeInfoById(id);
39     }
40
41     /**
42      * 查询生产工单列表
43      * 
44      * @param omProductionOrdeInfo 生产工单
45      * @return 生产工单
46      */
47     @Override
48     public List<OmProductionOrdeInfo> selectOmProductionOrdeInfoList(OmProductionOrdeInfo omProductionOrdeInfo)
49     {
50         return omProductionOrdeInfoMapper.selectOmProductionOrdeInfoList(omProductionOrdeInfo);
51     }
52
53     /**
54      * 新增生产工单
55      * 
56      * @param omProductionOrdeInfo 生产工单
57      * @return 结果
58      */
59     @Override
60     public int insertOmProductionOrdeInfo(OmProductionOrdeInfo omProductionOrdeInfo)
61     {
62         omProductionOrdeInfo.setCreateTime(DateUtils.getNowDate());
63         Integer streamNumber = omProductionOrdeInfoMapper.getMaxStreamNumber();
64         omProductionOrdeInfo.setStreamNumber(String.valueOf(streamNumber+1));
65         return omProductionOrdeInfoMapper.insertOmProductionOrdeInfo(omProductionOrdeInfo);
66     }
67
68     /**
69      * 修改生产工单
70      * 
71      * @param omProductionOrdeInfo 生产工单
72      * @return 结果
73      */
74     @Override
75     public int updateOmProductionOrdeInfo(OmProductionOrdeInfo omProductionOrdeInfo)
76     {
77         omProductionOrdeInfo.setUpdateTime(DateUtils.getNowDate());
78         return omProductionOrdeInfoMapper.updateOmProductionOrdeInfo(omProductionOrdeInfo);
79     }
80
81     /**
82      * 批量删除生产工单
83      * 
84      * @param ids 需要删除的生产工单主键
85      * @return 结果
86      */
87     @Override
88     public int deleteOmProductionOrdeInfoByIds(Long[] ids)
89     {
90         return omProductionOrdeInfoMapper.deleteOmProductionOrdeInfoByIds(ids);
91     }
92
93     /**
94      * 删除生产工单信息
95      * 
96      * @param id 生产工单主键
97      * @return 结果
98      */
99     @Override
100     public int deleteOmProductionOrdeInfoById(Long id)
101     {
102         return omProductionOrdeInfoMapper.deleteOmProductionOrdeInfoById(id);
103     }
104
105     @Override
106     public AjaxResult upDownMove(OmProductionOrdeInfo omProductionOrdeInfo) {
107         long currentId = omProductionOrdeInfo.getFrontEndId();
108         List<OmProductionOrdeInfo> omProductionOrdeInfos = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(omProductionOrdeInfo);
109         List<Long> idList = omProductionOrdeInfos.stream()
110                 .map(OmProductionOrdeInfo::getId) // 提取id属性
111                 .collect(Collectors.toList());
112         int index = idList.indexOf(currentId);
113         long moveId = 0L;
114         try {
115             if(omProductionOrdeInfo.getFlag().equals("up")){
116                 moveId = idList.get(index - 1);
117             }else {
118                 moveId = idList.get(index + 1);
119             }
120         }catch (Exception e){
121             return AjaxResult.error("当前工单为最后一个或第一个,无法移动");
122         }
123         OmProductionOrdeInfo  currentInfo = new OmProductionOrdeInfo();
124         currentInfo.setId(currentId);
125         List<OmProductionOrdeInfo> currentOrdeInfos = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(currentInfo);
126         String currentStreamNumber = currentOrdeInfos.get(0).getStreamNumber();
127         OmProductionOrdeInfo  moveInfo = new OmProductionOrdeInfo();
128         moveInfo.setId(moveId);
129         List<OmProductionOrdeInfo> moveOrdeInfos = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(moveInfo);
130         String moveStreamNumber = moveOrdeInfos.get(0).getStreamNumber();
131         moveOrdeInfos.get(0).setStreamNumber(currentStreamNumber);
132         omProductionOrdeInfoService.updateOmProductionOrdeInfo(moveOrdeInfos.get(0));
133         currentOrdeInfos.get(0).setStreamNumber(moveStreamNumber);
134         omProductionOrdeInfoService.updateOmProductionOrdeInfo(currentOrdeInfos.get(0));
135         return AjaxResult.success("移动成功");
136     }
137 }