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