提交 | 用户 | 时间
|
b78728
|
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; |
|
6 |
import java.util.concurrent.CompletableFuture; |
|
7 |
import javax.servlet.http.HttpServletResponse; |
|
8 |
|
|
9 |
import cn.hutool.core.collection.CollUtil; |
|
10 |
import cn.hutool.core.util.ObjectUtil; |
|
11 |
import cn.hutool.json.JSONObject; |
|
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; |
|
18 |
import com.jcdm.framework.websocket.WebSocketUsers; |
|
19 |
import com.jcdm.main.constant.Constants; |
|
20 |
import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo; |
|
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; |
|
25 |
import com.kangaroohy.milo.model.ReadWriteEntity; |
|
26 |
import com.kangaroohy.milo.service.MiloService; |
|
27 |
import lombok.extern.slf4j.Slf4j; |
|
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; |
|
64 |
|
|
65 |
@Autowired |
|
66 |
private MiloService miloService; |
|
67 |
|
|
68 |
/** |
|
69 |
* 查询生产工单列表 |
|
70 |
*/ |
|
71 |
@PreAuthorize("@ss.hasPermi('om:productionOrde:list')") |
|
72 |
@GetMapping("/list") |
|
73 |
public TableDataInfo list(OmProductionOrdeInfo omProductionOrdeInfo) |
|
74 |
{ |
|
75 |
startPage(); |
|
76 |
// List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getWorkOrderNo, "W_202403120001")); |
|
77 |
List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(omProductionOrdeInfo); |
|
78 |
return getDataTable(list); |
|
79 |
} |
|
80 |
|
dd9383
|
81 |
/** |
A |
82 |
* 查询生产工单列表 |
|
83 |
*/ |
|
84 |
@GetMapping("/listLoopLine") |
|
85 |
public TableDataInfo listLoopLine(OmProductionOrdeInfo omProductionOrdeInfo) |
|
86 |
{ |
|
87 |
startPage(); |
|
88 |
List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.listLoopLine(omProductionOrdeInfo); |
|
89 |
return getDataTable(list); |
|
90 |
} |
|
91 |
|
b78728
|
92 |
@GetMapping("/checkCarCode") |
A |
93 |
public AjaxResult checkCarCode(OmProductionOrdeInfo omProductionOrdeInfo) |
|
94 |
{ |
|
95 |
Integer i = 0; |
|
96 |
List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, omProductionOrdeInfo.getProductNum())); |
|
97 |
if(StringUtils.isNotBlank(list.get(0).getTrolleyYard())){ |
|
98 |
i = 1; |
|
99 |
} |
|
100 |
return AjaxResult.success(i); |
|
101 |
} |
|
102 |
|
|
103 |
@GetMapping("/checkYzSfcCode") |
|
104 |
public AjaxResult checkYzSfcCode(OmProductionOrdeInfo omProductionOrdeInfo) |
|
105 |
{ |
|
106 |
Integer i = 0; |
|
107 |
List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, omProductionOrdeInfo.getProductNum())); |
|
108 |
if(StringUtils.isNotBlank(list.get(0).getSpareField2())){ |
|
109 |
i = 1; |
|
110 |
} |
|
111 |
return AjaxResult.success(i); |
|
112 |
} |
|
113 |
|
|
114 |
@GetMapping("/bindYzSfcFlag") |
|
115 |
public AjaxResult bindYzSfcFlag(OmProductionOrdeInfo omProductionOrdeInfo) |
|
116 |
{ |
|
117 |
List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, omProductionOrdeInfo.getProductNum())); |
|
118 |
list.get(0).setSpareField2("1"); |
|
119 |
omProductionOrdeInfoService.saveOrUpdate(list.get(0)); |
|
120 |
return AjaxResult.success(null); |
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* 导出生产工单列表 |
|
125 |
*/ |
|
126 |
@PreAuthorize("@ss.hasPermi('om:productionOrde:export')") |
|
127 |
@Log(title = "生产工单", businessType = BusinessType.EXPORT) |
|
128 |
@PostMapping("/export") |
|
129 |
public void export(HttpServletResponse response, OmProductionOrdeInfo omProductionOrdeInfo) |
|
130 |
{ |
|
131 |
List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(omProductionOrdeInfo); |
|
132 |
ExcelUtil<OmProductionOrdeInfo> util = new ExcelUtil<OmProductionOrdeInfo>(OmProductionOrdeInfo.class); |
|
133 |
util.exportExcel(response, list, "生产工单数据"); |
|
134 |
} |
|
135 |
|
|
136 |
@GetMapping("/mozuReceivingWorkOrders") |
|
137 |
public AjaxResult mozuReceivingWorkOrders(OmProductionOrdeInfo paramOrder) throws Exception { |
|
138 |
String paramProductNum = ""; |
|
139 |
Object productTypeObjcet = miloService.readFromOpcUa("MOZU1." + paramOrder.getLineCode() + ".ProductType").getValue();//产品类型 |
|
140 |
if (ObjectUtil.isNull(productTypeObjcet)) { |
|
141 |
return AjaxResult.error("接单失败,PLC未传输生产类型,请联系管理员!"); |
|
142 |
} |
|
143 |
|
|
144 |
String productType = productTypeObjcet.toString();//产品类型 |
|
145 |
String materialCode = Constants.materialMap.get(productType); |
|
146 |
|
|
147 |
|
|
148 |
//先查询表中是否有剩余工单 |
|
149 |
List<OmProductionOrdeInfo> orderList = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>() |
|
150 |
.eq(OmProductionOrdeInfo::getOrderStatus, Constants.ONE) |
|
151 |
.eq(OmProductionOrdeInfo::getStationCode,paramOrder.getLineCode())//工位 |
|
152 |
.eq(OmProductionOrdeInfo::getProductCode,materialCode));//产品类型 |
|
153 |
if (CollUtil.isNotEmpty(orderList)){ |
|
154 |
Long id = orderList.get(0).getId(); |
|
155 |
String productNum = orderList.get(0).getProductNum();//模组码 |
|
156 |
String orderNum = orderList.get(0).getWorkOrderNo(); |
|
157 |
|
|
158 |
paramProductNum = productNum; |
|
159 |
//下发产品模组码 |
|
160 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier("MOZU1." + paramOrder.getLineCode() + ".WorkOrderNumber").value(orderNum).build()); |
|
161 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier("MOZU1." + paramOrder.getLineCode() + ".ModuleCode").value(productNum).build()); |
|
162 |
|
|
163 |
}else{ |
|
164 |
OmProductionOrdeInfo lastOrder = omProductionOrdeInfoService.getLastOrder(); |
|
165 |
String orderJsonString = RestfulService.getProductionWorkOrderRequest(lastOrder.getProductNum(), "M1OP100",materialCode); |
|
166 |
JSONObject jsonObject = new JSONObject(orderJsonString); |
|
167 |
// 从JSONObject中获取data对象 |
|
168 |
JSONObject dataObject = jsonObject.getJSONObject("data"); |
|
169 |
String code = jsonObject.getStr("code"); |
|
170 |
// 判断接单是否成功 |
|
171 |
if(code.equals("success")){ |
|
172 |
logger.info("请求工厂MES工单:入参pack{}出参pack:{}",paramProductNum,dataObject.getStr("productNum")); |
|
173 |
List<OmProductionOrdeInfo> check = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum,dataObject.getStr("productNum"))); |
|
174 |
if(check.isEmpty()){ |
|
175 |
try { |
|
176 |
log.info("请求工厂MES工单:入参pack{}出参pack:{}", paramProductNum, dataObject.getStr("productNum")); |
|
177 |
OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo(); |
|
178 |
omProductionOrdeInfo.setWorkOrderNo(dataObject.getStr("productionOrderNum")); |
|
179 |
omProductionOrdeInfo.setProductNum(dataObject.getStr("productNum")); |
|
180 |
omProductionOrdeInfo.setStationCode(paramOrder.getLineCode());//工位 |
|
181 |
omProductionOrdeInfo.setProductCode(dataObject.getStr("materialCode")); |
|
182 |
omProductionOrdeInfo.setPlanQty(Long.valueOf(dataObject.getStr("plannedQuantity"))); |
|
183 |
omProductionOrdeInfo.setOnlineCompletionMark("0"); |
|
184 |
omProductionOrdeInfo.setSfResult("0"); |
|
185 |
omProductionOrdeInfo.setProductModel(dataObject.getStr("model")); |
|
186 |
omProductionOrdeInfo.setCreateTime(new Date()); |
|
187 |
omProductionOrdeInfo.setCreateUser("工厂MES"); |
|
188 |
omProductionOrdeInfoService.save(omProductionOrdeInfo); |
|
189 |
|
|
190 |
paramProductNum = dataObject.getStr("productNum"); |
|
191 |
//写PLC |
|
192 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier("MOZU1." + paramOrder.getLineCode() + ".WorkOrderNumber").value(dataObject.getStr("productionOrderNum")).build()); |
|
193 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier("MOZU1." + paramOrder.getLineCode() + ".ModuleCode").value(dataObject.getStr("productNum")).build()); |
|
194 |
} catch (Exception e) { |
|
195 |
throw new RuntimeException(e); |
|
196 |
} |
|
197 |
}else{ |
|
198 |
return AjaxResult.error("工单重复,请重新接收"); |
|
199 |
} |
|
200 |
}else { |
|
201 |
return AjaxResult.error("接单失败,请联系管理员"); |
|
202 |
} |
|
203 |
} |
|
204 |
|
|
205 |
return AjaxResult.success(paramProductNum); |
|
206 |
} |
|
207 |
|
|
208 |
@GetMapping(value = "/jieBang/{id}") |
|
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 |
} |