提交 | 用户 | 时间
|
0ca254
|
1 |
package com.jcdm.main.om.productionOrde.controller; |
A |
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Date; |
|
5 |
import java.util.List; |
35c489
|
6 |
import java.util.concurrent.CompletableFuture; |
0ca254
|
7 |
import javax.servlet.http.HttpServletResponse; |
A |
8 |
|
35c489
|
9 |
import cn.hutool.core.util.ObjectUtil; |
0ca254
|
10 |
import cn.hutool.json.JSONObject; |
A |
11 |
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
12 |
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
13 |
import com.jcdm.common.core.domain.entity.SysUser; |
|
14 |
import com.jcdm.common.core.domain.model.LoginUser; |
|
15 |
import com.jcdm.common.utils.ServletUtils; |
|
16 |
import com.jcdm.common.utils.StringUtils; |
22c9e0
|
17 |
import com.jcdm.framework.websocket.WebSocketUsers; |
35c489
|
18 |
import com.jcdm.main.constant.Constants; |
0ca254
|
19 |
import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo; |
A |
20 |
import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfoExcelImport; |
|
21 |
import com.jcdm.main.om.productionOrde.mapper.OmProductionOrdeInfoMapper; |
|
22 |
import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService; |
|
23 |
import com.jcdm.main.restful.factoryMes.service.RestfulService; |
22c9e0
|
24 |
import com.kangaroohy.milo.model.ReadWriteEntity; |
A |
25 |
import com.kangaroohy.milo.service.MiloService; |
0ca254
|
26 |
import lombok.extern.slf4j.Slf4j; |
A |
27 |
import org.aspectj.weaver.loadtime.Aj; |
|
28 |
import org.slf4j.Logger; |
|
29 |
import org.slf4j.LoggerFactory; |
|
30 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
31 |
import org.springframework.beans.factory.annotation.Autowired; |
|
32 |
import org.springframework.web.bind.annotation.GetMapping; |
|
33 |
import org.springframework.web.bind.annotation.PostMapping; |
|
34 |
import org.springframework.web.bind.annotation.PutMapping; |
|
35 |
import org.springframework.web.bind.annotation.DeleteMapping; |
|
36 |
import org.springframework.web.bind.annotation.PathVariable; |
|
37 |
import org.springframework.web.bind.annotation.RequestBody; |
|
38 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
39 |
import org.springframework.web.bind.annotation.RestController; |
|
40 |
import com.jcdm.common.annotation.Log; |
|
41 |
import com.jcdm.common.core.controller.BaseController; |
|
42 |
import com.jcdm.common.core.domain.AjaxResult; |
|
43 |
import com.jcdm.common.enums.BusinessType; |
|
44 |
import com.jcdm.common.utils.poi.ExcelUtil; |
|
45 |
import com.jcdm.common.core.page.TableDataInfo; |
|
46 |
import org.springframework.web.multipart.MultipartFile; |
|
47 |
|
|
48 |
/** |
|
49 |
* 生产工单Controller |
|
50 |
* |
|
51 |
* @author ruimin |
|
52 |
* @date 2023-12-11 |
|
53 |
*/ |
|
54 |
@Slf4j |
|
55 |
@RestController |
|
56 |
@RequestMapping("/om/productionOrde") |
|
57 |
public class OmProductionOrdeInfoController extends BaseController |
|
58 |
{ |
|
59 |
private static final Logger logger = LoggerFactory.getLogger("sys-user"); |
|
60 |
|
|
61 |
@Autowired |
|
62 |
private IOmProductionOrdeInfoService omProductionOrdeInfoService; |
22c9e0
|
63 |
|
A |
64 |
@Autowired |
|
65 |
private MiloService miloService; |
0ca254
|
66 |
|
A |
67 |
/** |
|
68 |
* 查询生产工单列表 |
|
69 |
*/ |
|
70 |
@PreAuthorize("@ss.hasPermi('om:productionOrde:list')") |
|
71 |
@GetMapping("/list") |
|
72 |
public TableDataInfo list(OmProductionOrdeInfo omProductionOrdeInfo) |
|
73 |
{ |
|
74 |
startPage(); |
|
75 |
// List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getWorkOrderNo, "W_202403120001")); |
|
76 |
List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(omProductionOrdeInfo); |
|
77 |
return getDataTable(list); |
|
78 |
} |
|
79 |
|
|
80 |
@GetMapping("/checkCarCode") |
|
81 |
public AjaxResult checkCarCode(OmProductionOrdeInfo omProductionOrdeInfo) |
|
82 |
{ |
|
83 |
Integer i = 0; |
|
84 |
List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, omProductionOrdeInfo.getProductNum())); |
|
85 |
if(StringUtils.isNotBlank(list.get(0).getTrolleyYard())){ |
|
86 |
i = 1; |
|
87 |
} |
|
88 |
return AjaxResult.success(i); |
|
89 |
} |
|
90 |
|
|
91 |
@GetMapping("/checkYzSfcCode") |
|
92 |
public AjaxResult checkYzSfcCode(OmProductionOrdeInfo omProductionOrdeInfo) |
|
93 |
{ |
|
94 |
Integer i = 0; |
|
95 |
List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, omProductionOrdeInfo.getProductNum())); |
|
96 |
if(StringUtils.isNotBlank(list.get(0).getSpareField2())){ |
|
97 |
i = 1; |
|
98 |
} |
|
99 |
return AjaxResult.success(i); |
|
100 |
} |
|
101 |
|
|
102 |
@GetMapping("/bindYzSfcFlag") |
|
103 |
public AjaxResult bindYzSfcFlag(OmProductionOrdeInfo omProductionOrdeInfo) |
|
104 |
{ |
|
105 |
List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, omProductionOrdeInfo.getProductNum())); |
|
106 |
list.get(0).setSpareField2("1"); |
|
107 |
omProductionOrdeInfoService.saveOrUpdate(list.get(0)); |
|
108 |
return AjaxResult.success(null); |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* 导出生产工单列表 |
|
113 |
*/ |
|
114 |
@PreAuthorize("@ss.hasPermi('om:productionOrde:export')") |
|
115 |
@Log(title = "生产工单", businessType = BusinessType.EXPORT) |
|
116 |
@PostMapping("/export") |
|
117 |
public void export(HttpServletResponse response, OmProductionOrdeInfo omProductionOrdeInfo) |
|
118 |
{ |
|
119 |
List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(omProductionOrdeInfo); |
|
120 |
ExcelUtil<OmProductionOrdeInfo> util = new ExcelUtil<OmProductionOrdeInfo>(OmProductionOrdeInfo.class); |
|
121 |
util.exportExcel(response, list, "生产工单数据"); |
|
122 |
} |
|
123 |
|
|
124 |
@GetMapping("/receivingWorkOrders") |
6d32c5
|
125 |
public AjaxResult receivingWorkOrders() throws Exception { |
0ca254
|
126 |
String paramProductNum = ""; |
6d32c5
|
127 |
Object productTypeObjcet = miloService.readFromOpcUa("thoroughfare" + "." + "device" + ".ProductType").getValue();//产品类型 |
35c489
|
128 |
if (ObjectUtil.isNull(productTypeObjcet)) { |
C |
129 |
return AjaxResult.error("接单失败,PLC未传输生产类型,请联系管理员"); |
|
130 |
} |
|
131 |
String productType = productTypeObjcet.toString();//产品类型 |
|
132 |
String materialCode = Constants.materialMap.get(productType); |
0ca254
|
133 |
// 查询最新的工单信息 |
22c9e0
|
134 |
OmProductionOrdeInfo lastOrder = omProductionOrdeInfoService.getLastOrder(); |
35c489
|
135 |
String orderJsonString = RestfulService.getProductionWorkOrderRequest(lastOrder.getProductNum(), "M1OP100",materialCode); |
0ca254
|
136 |
JSONObject jsonObject = new JSONObject(orderJsonString); |
A |
137 |
// 从JSONObject中获取data对象 |
|
138 |
JSONObject dataObject = jsonObject.getJSONObject("data"); |
|
139 |
String code = jsonObject.getStr("code"); |
|
140 |
// 判断接单是否成功 |
|
141 |
if(code.equals("success")){ |
|
142 |
logger.info("请求工厂MES工单:入参pack{}出参pack:{}",paramProductNum,dataObject.getStr("productNum")); |
|
143 |
List<OmProductionOrdeInfo> check = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum,dataObject.getStr("productNum"))); |
|
144 |
if(check.size() == 0){ |
|
145 |
OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo(); |
|
146 |
omProductionOrdeInfo.setWorkOrderNo(dataObject.getStr("productionOrderNum")); |
|
147 |
omProductionOrdeInfo.setProductNum(dataObject.getStr("productNum")); |
|
148 |
omProductionOrdeInfo.setStationCode(dataObject.getStr("stationCode")); |
|
149 |
omProductionOrdeInfo.setMaterialCode(dataObject.getStr("materialCode")); |
|
150 |
omProductionOrdeInfo.setOnlineCompletionMark("0"); |
|
151 |
omProductionOrdeInfo.setSfResult("0"); |
|
152 |
if(dataObject.getStr("model").equals("PE01A")){ |
|
153 |
omProductionOrdeInfo.setProductCode("1P102S"); |
|
154 |
}else { |
|
155 |
omProductionOrdeInfo.setProductCode(dataObject.getStr("model")); |
|
156 |
} |
|
157 |
omProductionOrdeInfo.setCreateTime(new Date()); |
|
158 |
omProductionOrdeInfo.setCreateUser("工厂MES"); |
|
159 |
omProductionOrdeInfoService.save(omProductionOrdeInfo); |
|
160 |
} |
|
161 |
}else { |
|
162 |
return AjaxResult.error("接单失败,请联系管理员"); |
|
163 |
} |
|
164 |
return AjaxResult.success(dataObject.getStr("productNum")); |
|
165 |
} |
|
166 |
|
22c9e0
|
167 |
@GetMapping("/mozuReceivingWorkOrders") |
A |
168 |
public AjaxResult mozuReceivingWorkOrders(OmProductionOrdeInfo paramOrder) |
|
169 |
{ |
|
170 |
String paramProductNum = ""; |
|
171 |
OmProductionOrdeInfo lastOrder = omProductionOrdeInfoService.getLastOrder(); |
|
172 |
String orderJsonString = RestfulService.getProductionWorkOrderRequest(lastOrder.getProductNum(), "OP230"); |
|
173 |
JSONObject jsonObject = new JSONObject(orderJsonString); |
|
174 |
// 从JSONObject中获取data对象 |
|
175 |
JSONObject dataObject = jsonObject.getJSONObject("data"); |
|
176 |
String code = jsonObject.getStr("code"); |
|
177 |
// 判断接单是否成功 |
|
178 |
if(code.equals("success")){ |
|
179 |
logger.info("请求工厂MES工单:入参pack{}出参pack:{}",paramProductNum,dataObject.getStr("productNum")); |
|
180 |
List<OmProductionOrdeInfo> check = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum,dataObject.getStr("productNum"))); |
|
181 |
if(check.size() == 0){ |
|
182 |
try { |
|
183 |
log.info("请求工厂MES工单:入参pack{}出参pack:{}", paramProductNum, dataObject.getStr("productNum")); |
|
184 |
OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo(); |
|
185 |
omProductionOrdeInfo.setWorkOrderNo(dataObject.getStr("productionOrderNum")); |
|
186 |
omProductionOrdeInfo.setProductNum(dataObject.getStr("productNum")); |
|
187 |
omProductionOrdeInfo.setStationCode(dataObject.getStr("stationCode")); |
|
188 |
omProductionOrdeInfo.setMaterialCode(dataObject.getStr("materialCode")); |
|
189 |
omProductionOrdeInfo.setOnlineCompletionMark("0"); |
|
190 |
omProductionOrdeInfo.setSfResult("0"); |
|
191 |
omProductionOrdeInfo.setProductCode(dataObject.getStr("model")); |
|
192 |
omProductionOrdeInfo.setCreateTime(new Date()); |
|
193 |
omProductionOrdeInfo.setCreateUser("工厂MES"); |
|
194 |
omProductionOrdeInfoService.save(omProductionOrdeInfo); |
|
195 |
//写PLC |
|
196 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier("MOZU1." + paramOrder.getLineCode() + ".MES_WorkOrderNumber").value(dataObject.getStr("productionOrderNum")).build()); |
|
197 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier("MOZU1." + paramOrder.getLineCode() + ".MES_ModuleCode").value(dataObject.getStr("productNum")).build()); |
|
198 |
} catch (Exception e) { |
|
199 |
throw new RuntimeException(e); |
|
200 |
} |
|
201 |
} |
|
202 |
}else { |
|
203 |
return AjaxResult.error("接单失败,请联系管理员"); |
|
204 |
} |
|
205 |
return AjaxResult.success(dataObject.getStr("productNum")); |
|
206 |
} |
|
207 |
|
0ca254
|
208 |
@GetMapping(value = "/jieBang/{id}") |
A |
209 |
public AjaxResult jieBang(@PathVariable("id") Long id) |
|
210 |
{ |
|
211 |
OmProductionOrdeInfo byId = omProductionOrdeInfoService.getById(id); |
|
212 |
byId.setTrolleyYard(""); |
|
213 |
return success(omProductionOrdeInfoService.saveOrUpdate(byId)); |
|
214 |
} |
|
215 |
|
|
216 |
/** |
|
217 |
* 获取生产工单详细信息 |
|
218 |
*/ |
|
219 |
@PreAuthorize("@ss.hasPermi('om:productionOrde:query')") |
|
220 |
@GetMapping(value = "/{id}") |
|
221 |
public AjaxResult getInfo(@PathVariable("id") Long id) |
|
222 |
{ |
|
223 |
return success(omProductionOrdeInfoService.selectOmProductionOrdeInfoById(id)); |
|
224 |
} |
|
225 |
|
|
226 |
/** |
|
227 |
* 新增生产工单 |
|
228 |
*/ |
|
229 |
@PreAuthorize("@ss.hasPermi('om:productionOrde:add')") |
|
230 |
@Log(title = "生产工单", businessType = BusinessType.INSERT) |
|
231 |
@PostMapping |
|
232 |
public AjaxResult add(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo) |
|
233 |
{ |
|
234 |
return toAjax(omProductionOrdeInfoService.insertOmProductionOrdeInfo(omProductionOrdeInfo)); |
|
235 |
} |
|
236 |
|
|
237 |
/** |
|
238 |
* 修改生产工单 |
|
239 |
*/ |
|
240 |
@PreAuthorize("@ss.hasPermi('om:productionOrde:edit')") |
|
241 |
@Log(title = "生产工单", businessType = BusinessType.UPDATE) |
|
242 |
@PutMapping |
|
243 |
public AjaxResult edit(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo) |
|
244 |
{ |
|
245 |
return toAjax(omProductionOrdeInfoService.updateOmProductionOrdeInfo(omProductionOrdeInfo)); |
|
246 |
} |
|
247 |
|
|
248 |
/** |
|
249 |
* 删除生产工单 |
|
250 |
*/ |
|
251 |
@PreAuthorize("@ss.hasPermi('om:productionOrde:remove')") |
|
252 |
@Log(title = "生产工单", businessType = BusinessType.DELETE) |
|
253 |
@DeleteMapping("/{ids}") |
|
254 |
public AjaxResult remove(@PathVariable Long[] ids) |
|
255 |
{ |
|
256 |
return toAjax(omProductionOrdeInfoService.deleteOmProductionOrdeInfoByIds(ids)); |
|
257 |
} |
|
258 |
|
|
259 |
/** |
|
260 |
* table列上移下移 |
|
261 |
*/ |
|
262 |
@Log(title = "生产工单", businessType = BusinessType.DELETE) |
|
263 |
@GetMapping("/upDownMove") |
|
264 |
public AjaxResult upDownMove(OmProductionOrdeInfo omProductionOrdeInfo) |
|
265 |
{ |
|
266 |
return omProductionOrdeInfoService.upDownMove(omProductionOrdeInfo); |
|
267 |
} |
|
268 |
|
|
269 |
@PostMapping("/importData") |
|
270 |
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception |
|
271 |
{ |
|
272 |
ExcelUtil<OmProductionOrdeInfo> util = new ExcelUtil<OmProductionOrdeInfo>(OmProductionOrdeInfo.class); |
|
273 |
List<OmProductionOrdeInfo> ordeInfo = util.importExcel(file.getInputStream()); |
|
274 |
for (OmProductionOrdeInfo omProductionOrdeInfo : ordeInfo) { |
|
275 |
omProductionOrdeInfo.setCreateTime(new Date()); |
|
276 |
omProductionOrdeInfo.setCreateBy("工厂MES"); |
|
277 |
} |
|
278 |
omProductionOrdeInfoService.overrideSaveBatch(ordeInfo); |
|
279 |
return AjaxResult.success(); |
|
280 |
} |
|
281 |
|
|
282 |
@PostMapping("/importTemplate") |
|
283 |
public void importTemplate(HttpServletResponse response) |
|
284 |
{ |
|
285 |
ExcelUtil<OmProductionOrdeInfoExcelImport> util = new ExcelUtil<OmProductionOrdeInfoExcelImport>(OmProductionOrdeInfoExcelImport.class); |
|
286 |
util.importTemplateExcel(response, "订单数据"); |
|
287 |
} |
|
288 |
|
|
289 |
@PostMapping("/trolleyYardBinDing") |
|
290 |
public AjaxResult trolleyYardBinDing(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo) |
|
291 |
{ |
|
292 |
return omProductionOrdeInfoService.trolleyYardBinDing(omProductionOrdeInfo); |
|
293 |
} |
|
294 |
|
|
295 |
@PostMapping("/getCarCodeSize") |
|
296 |
public AjaxResult getCarCodeSize(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo) |
|
297 |
{ |
|
298 |
return omProductionOrdeInfoService.getCarCodeSize(omProductionOrdeInfo); |
|
299 |
} |
|
300 |
|
|
301 |
@PostMapping("/findBytrolleyYardGetOne") |
|
302 |
public AjaxResult findBytrolleyYardGetOne(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo) |
|
303 |
{ |
|
304 |
return omProductionOrdeInfoService.findBytrolleyYardGetOne(omProductionOrdeInfo); |
|
305 |
} |
|
306 |
|
|
307 |
@GetMapping("/workReportingByStation/{id}/{stationCode}") |
|
308 |
public AjaxResult workReportingByStation(@PathVariable("id") Long id, @PathVariable("stationCode") String stationCode) |
|
309 |
{ |
|
310 |
OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo(); |
|
311 |
omProductionOrdeInfo.setId(id); |
|
312 |
omProductionOrdeInfo.setStationCode(stationCode); |
|
313 |
return omProductionOrdeInfoService.workReportingByStation(omProductionOrdeInfo); |
|
314 |
} |
|
315 |
} |