提交 | 用户 | 时间
|
0ca254
|
1 |
package com.jcdm.main.om.productionOrde.service.impl; |
A |
2 |
|
|
3 |
import java.text.SimpleDateFormat; |
|
4 |
import java.util.Date; |
|
5 |
import java.util.List; |
|
6 |
import java.util.stream.Collectors; |
|
7 |
|
|
8 |
import cn.hutool.core.util.ObjectUtil; |
|
9 |
import cn.hutool.json.JSONObject; |
|
10 |
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
11 |
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
12 |
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
13 |
import com.jcdm.common.core.domain.AjaxResult; |
|
14 |
import com.jcdm.common.utils.DateUtils; |
|
15 |
import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo; |
|
16 |
import com.jcdm.main.om.productionOrde.mapper.OmProductionOrdeInfoMapper; |
|
17 |
import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService; |
|
18 |
import com.jcdm.main.restful.factoryMes.service.RestfulService; |
|
19 |
import lombok.extern.slf4j.Slf4j; |
|
20 |
import org.slf4j.Logger; |
|
21 |
import org.slf4j.LoggerFactory; |
|
22 |
import org.springframework.beans.factory.annotation.Autowired; |
|
23 |
import org.springframework.stereotype.Service; |
|
24 |
|
|
25 |
/** |
|
26 |
* 生产工单Service业务层处理 |
|
27 |
* |
|
28 |
* @author ruimin |
|
29 |
* @date 2023-12-11 |
|
30 |
*/ |
|
31 |
@Slf4j |
|
32 |
@Service |
|
33 |
public class OmProductionOrdeInfoServiceImpl extends ServiceImpl<OmProductionOrdeInfoMapper,OmProductionOrdeInfo> implements IOmProductionOrdeInfoService |
|
34 |
{ |
|
35 |
private static final Logger logger = LoggerFactory.getLogger("sys-user"); |
|
36 |
public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
37 |
|
|
38 |
@Autowired |
|
39 |
private OmProductionOrdeInfoMapper omProductionOrdeInfoMapper; |
|
40 |
|
|
41 |
@Autowired |
|
42 |
private IOmProductionOrdeInfoService omProductionOrdeInfoService; |
|
43 |
|
|
44 |
/** |
|
45 |
* 查询生产工单 |
|
46 |
* |
|
47 |
* @param id 生产工单主键 |
|
48 |
* @return 生产工单 |
|
49 |
*/ |
|
50 |
@Override |
|
51 |
public OmProductionOrdeInfo selectOmProductionOrdeInfoById(Long id) |
|
52 |
{ |
|
53 |
return omProductionOrdeInfoMapper.selectOmProductionOrdeInfoById(id); |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* 查询生产工单列表 |
|
58 |
* |
|
59 |
* @param omProductionOrdeInfo 生产工单 |
|
60 |
* @return 生产工单 |
|
61 |
*/ |
|
62 |
@Override |
|
63 |
public List<OmProductionOrdeInfo> selectOmProductionOrdeInfoList(OmProductionOrdeInfo omProductionOrdeInfo) |
|
64 |
{ |
|
65 |
return omProductionOrdeInfoMapper.selectOmProductionOrdeInfoList(omProductionOrdeInfo); |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* 新增生产工单 |
|
70 |
* |
|
71 |
* @param omProductionOrdeInfo 生产工单 |
|
72 |
* @return 结果 |
|
73 |
*/ |
|
74 |
@Override |
|
75 |
public int insertOmProductionOrdeInfo(OmProductionOrdeInfo omProductionOrdeInfo) |
|
76 |
{ |
|
77 |
omProductionOrdeInfo.setCreateTime(DateUtils.getNowDate()); |
|
78 |
Integer streamNumber = omProductionOrdeInfoMapper.getMaxStreamNumber(); |
|
79 |
omProductionOrdeInfo.setStreamNumber(String.valueOf(streamNumber+1)); |
|
80 |
return omProductionOrdeInfoMapper.insertOmProductionOrdeInfo(omProductionOrdeInfo); |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* 修改生产工单 |
|
85 |
* |
|
86 |
* @param omProductionOrdeInfo 生产工单 |
|
87 |
* @return 结果 |
|
88 |
*/ |
|
89 |
@Override |
|
90 |
public int updateOmProductionOrdeInfo(OmProductionOrdeInfo omProductionOrdeInfo) |
|
91 |
{ |
|
92 |
omProductionOrdeInfo.setUpdateTime(DateUtils.getNowDate()); |
|
93 |
return omProductionOrdeInfoMapper.updateOmProductionOrdeInfo(omProductionOrdeInfo); |
|
94 |
} |
|
95 |
|
|
96 |
/** |
|
97 |
* 批量删除生产工单 |
|
98 |
* |
|
99 |
* @param ids 需要删除的生产工单主键 |
|
100 |
* @return 结果 |
|
101 |
*/ |
|
102 |
@Override |
|
103 |
public int deleteOmProductionOrdeInfoByIds(Long[] ids) |
|
104 |
{ |
|
105 |
return omProductionOrdeInfoMapper.deleteOmProductionOrdeInfoByIds(ids); |
|
106 |
} |
|
107 |
|
|
108 |
/** |
|
109 |
* 删除生产工单信息 |
|
110 |
* |
|
111 |
* @param id 生产工单主键 |
|
112 |
* @return 结果 |
|
113 |
*/ |
|
114 |
@Override |
|
115 |
public int deleteOmProductionOrdeInfoById(Long id) |
|
116 |
{ |
|
117 |
return omProductionOrdeInfoMapper.deleteOmProductionOrdeInfoById(id); |
|
118 |
} |
|
119 |
|
|
120 |
@Override |
|
121 |
public AjaxResult upDownMove(OmProductionOrdeInfo omProductionOrdeInfo) { |
|
122 |
long currentId = omProductionOrdeInfo.getFrontEndId(); |
|
123 |
List<OmProductionOrdeInfo> omProductionOrdeInfos = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(omProductionOrdeInfo); |
|
124 |
List<Long> idList = omProductionOrdeInfos.stream() |
|
125 |
.map(OmProductionOrdeInfo::getId) // 提取id属性 |
|
126 |
.collect(Collectors.toList()); |
|
127 |
int index = idList.indexOf(currentId); |
|
128 |
long moveId = 0L; |
|
129 |
try { |
|
130 |
if(omProductionOrdeInfo.getFlag().equals("up")){ |
|
131 |
moveId = idList.get(index - 1); |
|
132 |
}else { |
|
133 |
moveId = idList.get(index + 1); |
|
134 |
} |
|
135 |
}catch (Exception e){ |
|
136 |
return AjaxResult.error("当前工单为最后一个或第一个,无法移动"); |
|
137 |
} |
|
138 |
OmProductionOrdeInfo currentInfo = new OmProductionOrdeInfo(); |
|
139 |
currentInfo.setId(currentId); |
|
140 |
List<OmProductionOrdeInfo> currentOrdeInfos = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(currentInfo); |
|
141 |
String currentStreamNumber = currentOrdeInfos.get(0).getStreamNumber(); |
|
142 |
OmProductionOrdeInfo moveInfo = new OmProductionOrdeInfo(); |
|
143 |
moveInfo.setId(moveId); |
|
144 |
List<OmProductionOrdeInfo> moveOrdeInfos = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(moveInfo); |
|
145 |
String moveStreamNumber = moveOrdeInfos.get(0).getStreamNumber(); |
|
146 |
moveOrdeInfos.get(0).setStreamNumber(currentStreamNumber); |
|
147 |
omProductionOrdeInfoService.updateOmProductionOrdeInfo(moveOrdeInfos.get(0)); |
|
148 |
currentOrdeInfos.get(0).setStreamNumber(moveStreamNumber); |
|
149 |
omProductionOrdeInfoService.updateOmProductionOrdeInfo(currentOrdeInfos.get(0)); |
|
150 |
return AjaxResult.success("移动成功"); |
|
151 |
} |
|
152 |
|
|
153 |
@Override |
|
154 |
public void overrideSaveBatch(List<OmProductionOrdeInfo> omProductionOrdeInfoList) { |
|
155 |
try { |
|
156 |
this.saveBatch(omProductionOrdeInfoList); |
|
157 |
}catch (Exception e){ |
|
158 |
return; |
|
159 |
} |
|
160 |
} |
|
161 |
|
|
162 |
@Override |
|
163 |
public AjaxResult receivingWorkOrders() { |
|
164 |
return null; |
|
165 |
} |
|
166 |
|
|
167 |
@Override |
|
168 |
public AjaxResult trolleyYardBinDing(OmProductionOrdeInfo omProductionOrdeInfo) { |
|
169 |
OmProductionOrdeInfo clearTrolleyYard = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getTrolleyYard, omProductionOrdeInfo.getTrolleyYard())); |
|
170 |
if(clearTrolleyYard!=null){ |
|
171 |
clearTrolleyYard.setTrolleyYard(""); |
|
172 |
omProductionOrdeInfoService.saveOrUpdate(clearTrolleyYard); |
|
173 |
} |
|
174 |
OmProductionOrdeInfo one = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, omProductionOrdeInfo.getProductNum())); |
|
175 |
one.setTrolleyYard(omProductionOrdeInfo.getTrolleyYard()); |
|
176 |
omProductionOrdeInfoService.saveOrUpdate(one); |
|
177 |
logger.info("绑定pack码{}到小车:{}",omProductionOrdeInfo.getProductNum(),omProductionOrdeInfo.getTrolleyYard()); |
|
178 |
|
|
179 |
return AjaxResult.success(); |
|
180 |
} |
|
181 |
|
|
182 |
@Override |
|
183 |
public AjaxResult getCarCodeSize(OmProductionOrdeInfo omProductionOrdeInfo) { |
|
184 |
// omProductionOrdeInfo. |
|
185 |
return null; |
|
186 |
} |
|
187 |
|
|
188 |
@Override |
|
189 |
public AjaxResult findBytrolleyYardGetOne(OmProductionOrdeInfo omProductionOrdeInfo) { |
|
190 |
String str = ""; |
|
191 |
OmProductionOrdeInfo one = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getTrolleyYard, omProductionOrdeInfo.getTrolleyYard())); |
|
192 |
if(one == null){ |
|
193 |
str = "2"; |
|
194 |
}else { |
|
195 |
str = one.getProductNum(); |
|
196 |
} |
|
197 |
return AjaxResult.success(str); |
|
198 |
} |
|
199 |
|
|
200 |
@Override |
|
201 |
public List<OmProductionOrdeInfo> checkCarCode(OmProductionOrdeInfo omProductionOrdeInfo) { |
|
202 |
List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, omProductionOrdeInfo.getProductNum()).isNotNull(OmProductionOrdeInfo::getTrolleyYard)); |
|
203 |
return list; |
|
204 |
} |
|
205 |
|
|
206 |
@Override |
|
207 |
public AjaxResult workReportingByStation(OmProductionOrdeInfo info) { |
|
208 |
OmProductionOrdeInfo omProductionOrdeInfo = omProductionOrdeInfoService.getById(info.getId()); |
|
209 |
logger.info("OP230报工开始-工厂MES异步方法"); |
|
210 |
String reportResult = RestfulService.getWorkReportResultFeedback(omProductionOrdeInfo.getProductNum(), info.getStationCode(), format.format(new Date())); |
|
211 |
JSONObject jsonObject = new JSONObject(reportResult); |
|
212 |
String code = jsonObject.getStr("code"); |
|
213 |
String status = jsonObject.getJSONObject("data").getStr("resultCode"); |
|
214 |
if("success".equals(code)&&"S".equals(status)){ |
|
215 |
//如果成功,执行报工成功方法,修改是否报工为1,添加报工时间 |
|
216 |
this.updateOrderByProductNum("1",omProductionOrdeInfo.getProductNum(),info.getStationCode()); |
|
217 |
}else{ |
|
218 |
//解析工厂mes返回结果,如果失败,执行报工失败方法,修改是否报工为2,添加报工时间 |
|
219 |
this.updateOrderByProductNum("2",omProductionOrdeInfo.getProductNum(),info.getStationCode()); |
|
220 |
} |
|
221 |
return null; |
|
222 |
} |
|
223 |
|
|
224 |
@Override |
|
225 |
public void updateOrderByProductNum(String onlineCompletionMark, String productNum, String stationCode) { |
|
226 |
LambdaUpdateWrapper<OmProductionOrdeInfo> updateWrapper = new LambdaUpdateWrapper<>(); |
e4f9cb
|
227 |
if(stationCode.contains("M1OP100")){ |
0ca254
|
228 |
updateWrapper.set(OmProductionOrdeInfo::getOnlineCompletionMark,onlineCompletionMark); |
A |
229 |
updateWrapper.set(OmProductionOrdeInfo::getActualStartTime,new Date()); |
|
230 |
} |
e4f9cb
|
231 |
if(stationCode.equals("MOP220")){ |
0ca254
|
232 |
updateWrapper.set(OmProductionOrdeInfo::getSfResult,onlineCompletionMark); |
A |
233 |
} |
|
234 |
updateWrapper.eq(OmProductionOrdeInfo::getProductNum,productNum); |
|
235 |
OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo(); |
|
236 |
omProductionOrdeInfoService.update(omProductionOrdeInfo,updateWrapper); |
|
237 |
} |
22c9e0
|
238 |
|
A |
239 |
@Override |
|
240 |
public OmProductionOrdeInfo getLastOrder() { |
|
241 |
return omProductionOrdeInfoMapper.getLastOrder(); |
|
242 |
} |
0ca254
|
243 |
} |