提交 | 用户 | 时间
|
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 |
|
22c9e0
|
124 |
@GetMapping("/mozuReceivingWorkOrders") |
1ebf2a
|
125 |
public AjaxResult mozuReceivingWorkOrders(OmProductionOrdeInfo paramOrder) throws Exception { |
22c9e0
|
126 |
String paramProductNum = ""; |
09ceef
|
127 |
Object productTypeObjcet = miloService.readFromOpcUa("MOZU1." + paramOrder.getLineCode() + ".ProductType").getValue();//产品类型 |
1ebf2a
|
128 |
if (ObjectUtil.isNull(productTypeObjcet)) { |
C |
129 |
return AjaxResult.error("接单失败,PLC未传输生产类型,请联系管理员"); |
|
130 |
} |
|
131 |
String productType = productTypeObjcet.toString();//产品类型 |
|
132 |
String materialCode = Constants.materialMap.get(productType); |
|
133 |
|
22c9e0
|
134 |
OmProductionOrdeInfo lastOrder = omProductionOrdeInfoService.getLastOrder(); |
1ebf2a
|
135 |
String orderJsonString = RestfulService.getProductionWorkOrderRequest(lastOrder.getProductNum(), "M1OP100",materialCode); |
22c9e0
|
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"))); |
ab6314
|
144 |
if(check.isEmpty()){ |
22c9e0
|
145 |
try { |
A |
146 |
log.info("请求工厂MES工单:入参pack{}出参pack:{}", paramProductNum, dataObject.getStr("productNum")); |
|
147 |
OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo(); |
|
148 |
omProductionOrdeInfo.setWorkOrderNo(dataObject.getStr("productionOrderNum")); |
|
149 |
omProductionOrdeInfo.setProductNum(dataObject.getStr("productNum")); |
|
150 |
omProductionOrdeInfo.setStationCode(dataObject.getStr("stationCode")); |
|
151 |
omProductionOrdeInfo.setMaterialCode(dataObject.getStr("materialCode")); |
653b17
|
152 |
omProductionOrdeInfo.setPlanQty(Long.valueOf(dataObject.getStr("plannedQuantity"))); |
22c9e0
|
153 |
omProductionOrdeInfo.setOnlineCompletionMark("0"); |
A |
154 |
omProductionOrdeInfo.setSfResult("0"); |
|
155 |
omProductionOrdeInfo.setProductCode(dataObject.getStr("model")); |
|
156 |
omProductionOrdeInfo.setCreateTime(new Date()); |
|
157 |
omProductionOrdeInfo.setCreateUser("工厂MES"); |
|
158 |
omProductionOrdeInfoService.save(omProductionOrdeInfo); |
ab6314
|
159 |
|
22c9e0
|
160 |
//写PLC |
ab6314
|
161 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier("MOZU1." + paramOrder.getLineCode() + ".WorkOrderNumber").value(dataObject.getStr("productionOrderNum")).build()); |
C |
162 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier("MOZU1." + paramOrder.getLineCode() + ".ModuleCode").value(dataObject.getStr("productNum")).build()); |
22c9e0
|
163 |
} catch (Exception e) { |
A |
164 |
throw new RuntimeException(e); |
|
165 |
} |
ab6314
|
166 |
}else{ |
C |
167 |
return AjaxResult.error("工单重复,请重新接收"); |
22c9e0
|
168 |
} |
A |
169 |
}else { |
|
170 |
return AjaxResult.error("接单失败,请联系管理员"); |
|
171 |
} |
|
172 |
return AjaxResult.success(dataObject.getStr("productNum")); |
|
173 |
} |
|
174 |
|
0ca254
|
175 |
@GetMapping(value = "/jieBang/{id}") |
A |
176 |
public AjaxResult jieBang(@PathVariable("id") Long id) |
|
177 |
{ |
|
178 |
OmProductionOrdeInfo byId = omProductionOrdeInfoService.getById(id); |
|
179 |
byId.setTrolleyYard(""); |
|
180 |
return success(omProductionOrdeInfoService.saveOrUpdate(byId)); |
|
181 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* 获取生产工单详细信息 |
|
185 |
*/ |
|
186 |
@PreAuthorize("@ss.hasPermi('om:productionOrde:query')") |
|
187 |
@GetMapping(value = "/{id}") |
|
188 |
public AjaxResult getInfo(@PathVariable("id") Long id) |
|
189 |
{ |
|
190 |
return success(omProductionOrdeInfoService.selectOmProductionOrdeInfoById(id)); |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* 新增生产工单 |
|
195 |
*/ |
|
196 |
@PreAuthorize("@ss.hasPermi('om:productionOrde:add')") |
|
197 |
@Log(title = "生产工单", businessType = BusinessType.INSERT) |
|
198 |
@PostMapping |
|
199 |
public AjaxResult add(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo) |
|
200 |
{ |
|
201 |
return toAjax(omProductionOrdeInfoService.insertOmProductionOrdeInfo(omProductionOrdeInfo)); |
|
202 |
} |
|
203 |
|
|
204 |
/** |
|
205 |
* 修改生产工单 |
|
206 |
*/ |
|
207 |
@PreAuthorize("@ss.hasPermi('om:productionOrde:edit')") |
|
208 |
@Log(title = "生产工单", businessType = BusinessType.UPDATE) |
|
209 |
@PutMapping |
|
210 |
public AjaxResult edit(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo) |
|
211 |
{ |
|
212 |
return toAjax(omProductionOrdeInfoService.updateOmProductionOrdeInfo(omProductionOrdeInfo)); |
|
213 |
} |
|
214 |
|
|
215 |
/** |
|
216 |
* 删除生产工单 |
|
217 |
*/ |
|
218 |
@PreAuthorize("@ss.hasPermi('om:productionOrde:remove')") |
|
219 |
@Log(title = "生产工单", businessType = BusinessType.DELETE) |
|
220 |
@DeleteMapping("/{ids}") |
|
221 |
public AjaxResult remove(@PathVariable Long[] ids) |
|
222 |
{ |
|
223 |
return toAjax(omProductionOrdeInfoService.deleteOmProductionOrdeInfoByIds(ids)); |
|
224 |
} |
|
225 |
|
|
226 |
/** |
|
227 |
* table列上移下移 |
|
228 |
*/ |
|
229 |
@Log(title = "生产工单", businessType = BusinessType.DELETE) |
|
230 |
@GetMapping("/upDownMove") |
|
231 |
public AjaxResult upDownMove(OmProductionOrdeInfo omProductionOrdeInfo) |
|
232 |
{ |
|
233 |
return omProductionOrdeInfoService.upDownMove(omProductionOrdeInfo); |
|
234 |
} |
|
235 |
|
|
236 |
@PostMapping("/importData") |
|
237 |
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception |
|
238 |
{ |
|
239 |
ExcelUtil<OmProductionOrdeInfo> util = new ExcelUtil<OmProductionOrdeInfo>(OmProductionOrdeInfo.class); |
|
240 |
List<OmProductionOrdeInfo> ordeInfo = util.importExcel(file.getInputStream()); |
|
241 |
for (OmProductionOrdeInfo omProductionOrdeInfo : ordeInfo) { |
|
242 |
omProductionOrdeInfo.setCreateTime(new Date()); |
|
243 |
omProductionOrdeInfo.setCreateBy("工厂MES"); |
|
244 |
} |
|
245 |
omProductionOrdeInfoService.overrideSaveBatch(ordeInfo); |
|
246 |
return AjaxResult.success(); |
|
247 |
} |
|
248 |
|
|
249 |
@PostMapping("/importTemplate") |
|
250 |
public void importTemplate(HttpServletResponse response) |
|
251 |
{ |
|
252 |
ExcelUtil<OmProductionOrdeInfoExcelImport> util = new ExcelUtil<OmProductionOrdeInfoExcelImport>(OmProductionOrdeInfoExcelImport.class); |
|
253 |
util.importTemplateExcel(response, "订单数据"); |
|
254 |
} |
|
255 |
|
|
256 |
@PostMapping("/trolleyYardBinDing") |
|
257 |
public AjaxResult trolleyYardBinDing(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo) |
|
258 |
{ |
|
259 |
return omProductionOrdeInfoService.trolleyYardBinDing(omProductionOrdeInfo); |
|
260 |
} |
|
261 |
|
|
262 |
@PostMapping("/getCarCodeSize") |
|
263 |
public AjaxResult getCarCodeSize(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo) |
|
264 |
{ |
|
265 |
return omProductionOrdeInfoService.getCarCodeSize(omProductionOrdeInfo); |
|
266 |
} |
|
267 |
|
|
268 |
@PostMapping("/findBytrolleyYardGetOne") |
|
269 |
public AjaxResult findBytrolleyYardGetOne(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo) |
|
270 |
{ |
|
271 |
return omProductionOrdeInfoService.findBytrolleyYardGetOne(omProductionOrdeInfo); |
|
272 |
} |
|
273 |
|
|
274 |
@GetMapping("/workReportingByStation/{id}/{stationCode}") |
|
275 |
public AjaxResult workReportingByStation(@PathVariable("id") Long id, @PathVariable("stationCode") String stationCode) |
|
276 |
{ |
|
277 |
OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo(); |
|
278 |
omProductionOrdeInfo.setId(id); |
|
279 |
omProductionOrdeInfo.setStationCode(stationCode); |
|
280 |
return omProductionOrdeInfoService.workReportingByStation(omProductionOrdeInfo); |
|
281 |
} |
|
282 |
} |