MesElectricTorqueController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. package com.jeesite.modules.mes.web;
  2. import java.util.ArrayList;
  3. import java.util.Date;
  4. import java.util.List;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import com.jeesite.common.lang.StringUtils;
  8. import com.jeesite.modules.mes.entity.*;
  9. import com.jeesite.modules.mes.resp.BindMaterialResp;
  10. import com.jeesite.modules.mes.resp.ParamsResp;
  11. import com.jeesite.modules.mes.service.*;
  12. import com.jeesite.modules.mes.util.CommonUitl;
  13. import com.jeesite.modules.utils.DateLocalUtils;
  14. import org.apache.shiro.authz.annotation.RequiresPermissions;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Controller;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import org.springframework.ui.Model;
  19. import org.springframework.util.ObjectUtils;
  20. import org.springframework.validation.annotation.Validated;
  21. import org.springframework.web.bind.annotation.*;
  22. import com.jeesite.common.config.Global;
  23. import com.jeesite.common.collect.ListUtils;
  24. import com.jeesite.common.entity.Page;
  25. import com.jeesite.common.lang.DateUtils;
  26. import com.jeesite.common.utils.excel.ExcelExport;
  27. import com.jeesite.common.utils.excel.annotation.ExcelField.Type;
  28. import org.springframework.web.multipart.MultipartFile;
  29. import com.jeesite.common.web.BaseController;
  30. /**
  31. * 电批过程参数Controller
  32. * @author mes
  33. * @version 2024-05-12
  34. */
  35. @Controller
  36. @RequestMapping(value = "${adminPath}/mes/mesElectricTorque")
  37. public class MesElectricTorqueController extends BaseController {
  38. @Autowired
  39. private MesElectricTorqueService mesElectricTorqueService;
  40. @Autowired
  41. private MesElectricTorqueInfoService mesElectricTorqueInfoService;
  42. @Autowired
  43. private MesProductRecordService mesProductRecordService;
  44. @Autowired
  45. private MesLineProcessMaterialService mesLineProcessMaterialService;
  46. @Autowired
  47. private MesMaterialPrebindService mesMaterialPrebindService;
  48. @Autowired
  49. private MesToolLifeService mesToolLifeService;
  50. @Autowired
  51. private MesProductOprnoService mesProductOprnoService;
  52. /**
  53. * 获取数据
  54. */
  55. @ModelAttribute
  56. public MesElectricTorque get(String id, boolean isNewRecord) {
  57. return mesElectricTorqueService.get(id, isNewRecord);
  58. }
  59. /**
  60. * 查询列表
  61. */
  62. @RequestMapping(value = {"list", ""})
  63. public String list(MesElectricTorque mesElectricTorque, Model model) {
  64. model.addAttribute("mesElectricTorque", mesElectricTorque);
  65. // MesElectricTorque mesElectricTorque1 = new MesElectricTorque();
  66. // mesElectricTorque.setBatchId(mesElectricTorque.getBatchId());
  67. // MesElectricTorque mlInfo = mesElectricTorqueService.get(mesElectricTorque);
  68. // model.addAttribute("mlInfo", mlInfo);
  69. return "modules/mes/mesElectricTorqueList";
  70. }
  71. /**
  72. * 查询列表数据
  73. */
  74. @RequestMapping(value = "listData")
  75. @ResponseBody
  76. public Page<MesElectricTorque> listData(MesElectricTorque mesElectricTorque, HttpServletRequest request, HttpServletResponse response) {
  77. mesElectricTorque.setPage(new Page<>(request, response));
  78. Page<MesElectricTorque> page = mesElectricTorqueService.findPage(mesElectricTorque);
  79. return page;
  80. }
  81. /**
  82. * 查看编辑表单
  83. */
  84. @RequestMapping(value = "form")
  85. public String form(MesElectricTorque mesElectricTorque, Model model) {
  86. model.addAttribute("mesElectricTorque", mesElectricTorque);
  87. return "modules/mes/mesElectricTorqueForm";
  88. }
  89. /**
  90. * 保存数据
  91. */
  92. @PostMapping(value = "save")
  93. @ResponseBody
  94. public String save(@Validated MesElectricTorque mesElectricTorque) {
  95. mesElectricTorqueService.save(mesElectricTorque);
  96. return renderResult(Global.TRUE, text("保存电批过程参数成功!"));
  97. }
  98. /**
  99. * 导出数据
  100. */
  101. @RequestMapping(value = "exportData")
  102. public void exportData(MesElectricTorque mesElectricTorque, HttpServletResponse response) {
  103. List<MesElectricTorque> list = mesElectricTorqueService.findList(mesElectricTorque);
  104. String fileName = "电批过程参数" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
  105. try(ExcelExport ee = new ExcelExport("电批过程参数", MesElectricTorque.class)){
  106. ee.setDataList(list).write(response, fileName);
  107. }
  108. }
  109. /**
  110. * 下载模板
  111. */
  112. @RequestMapping(value = "importTemplate")
  113. public void importTemplate(HttpServletResponse response) {
  114. MesElectricTorque mesElectricTorque = new MesElectricTorque();
  115. List<MesElectricTorque> list = ListUtils.newArrayList(mesElectricTorque);
  116. String fileName = "电批过程参数模板.xlsx";
  117. try(ExcelExport ee = new ExcelExport("电批过程参数", MesElectricTorque.class, Type.IMPORT)){
  118. ee.setDataList(list).write(response, fileName);
  119. }
  120. }
  121. /**
  122. * 导入数据
  123. */
  124. @ResponseBody
  125. @PostMapping(value = "importData")
  126. public String importData(MultipartFile file) {
  127. try {
  128. String message = mesElectricTorqueService.importData(file);
  129. return renderResult(Global.TRUE, "posfull:"+message);
  130. } catch (Exception ex) {
  131. return renderResult(Global.FALSE, "posfull:"+ex.getMessage());
  132. }
  133. }
  134. /**
  135. * 删除数据
  136. */
  137. @RequestMapping(value = "delete")
  138. @ResponseBody
  139. public String delete(MesElectricTorque mesElectricTorque) {
  140. mesElectricTorqueService.delete(mesElectricTorque);
  141. return renderResult(Global.TRUE, text("删除电批过程参数成功!"));
  142. }
  143. /**
  144. * 电批扭力参数批量上传
  145. */
  146. @RequestMapping(value = "batchSave")
  147. @ResponseBody
  148. @Transactional
  149. public String batchSave(@RequestBody MesElectricTorque mesElectricTorque) {
  150. if (mesElectricTorque == null
  151. || ("").equals(mesElectricTorque.getOprno())
  152. || ("").equals(mesElectricTorque.getLineSn())){
  153. return renderResult(Global.FALSE, text("操作失败!缺少参数值!"));
  154. }
  155. //创建时间
  156. Date createDate = DateLocalUtils.getCurrentTimeReturnDate();
  157. List<MesElectricTorque> list = mesElectricTorque.getData();
  158. //一级表扭力过程参数批次表生成
  159. MesElectricTorqueInfo mesElectricTorqueInfo = new MesElectricTorqueInfo();
  160. mesElectricTorqueInfo.setSn(mesElectricTorque.getSn());
  161. mesElectricTorqueInfo.setOprno(mesElectricTorque.getOprno());
  162. mesElectricTorqueInfo.setLineSn(mesElectricTorque.getLineSn());
  163. mesElectricTorqueInfo.setCreateDate(createDate);
  164. mesElectricTorqueInfo.setCount(list == null || list.isEmpty() ? 0 : list.size());
  165. mesElectricTorqueInfo.setBatch(DateLocalUtils.generateBatch());
  166. mesElectricTorqueInfoService.save(mesElectricTorqueInfo);
  167. if (list!= null && list.size() > 0){
  168. for (MesElectricTorque dtl : list) {
  169. MesElectricTorque extend = new MesElectricTorque();
  170. extend.setSn(mesElectricTorque.getSn());
  171. extend.setOprno(mesElectricTorque.getOprno());
  172. extend.setLineSn(mesElectricTorque.getLineSn());
  173. extend.setNumber(dtl.getNumber());
  174. extend.setTask(dtl.getTask());
  175. extend.setElapsedTime(dtl.getElapsedTime());
  176. extend.setTorsion(dtl.getTorsion());
  177. extend.setResult(dtl.getResult());
  178. extend.setCreateDate(createDate);
  179. extend.setBatchId(mesElectricTorqueInfo.getId());
  180. mesElectricTorqueService.save(extend);
  181. }
  182. }
  183. if(mesElectricTorque.getOprno().equals("OP060")){
  184. List<String> crafts = new ArrayList<>();
  185. crafts.add("400008");
  186. List<BindMaterialResp> bmlists = mesLineProcessMaterialService.getBindMaterial(mesElectricTorque.getOprno(), mesElectricTorque.getLineSn());
  187. // 更新绑定的物料
  188. if(!ListUtils.isEmpty(bmlists)){
  189. for (BindMaterialResp bindMaterialResp:bmlists){
  190. if(!StringUtils.isEmpty(bindMaterialResp.getBatchSn())){
  191. Integer lastTimes = Integer.valueOf(bindMaterialResp.getLastTimes());
  192. if(lastTimes >= 1){ // 更新数量
  193. if(crafts.contains(bindMaterialResp.getCraft())){
  194. MesMaterialPrebind mesMaterialPrebind = bindMaterialResp.getMesMaterialPrebind();
  195. mesMaterialPrebind.setLastTimes(lastTimes - 1);
  196. mesMaterialPrebindService.update(mesMaterialPrebind);
  197. }
  198. }
  199. }
  200. }
  201. }
  202. // 更新批头寿命
  203. List<MesToolLife> tools = mesToolLifeService.getToolLifeList(mesElectricTorque.getOprno(),mesElectricTorque.getLineSn());
  204. if(!ListUtils.isEmpty(tools)){
  205. for (MesToolLife mesToolLife:tools){
  206. Integer curLife = mesToolLife.getCurLife() - mesToolLife.getConsumeLife();
  207. curLife = curLife > 0?curLife:0;
  208. mesToolLife.setCurLife(curLife);
  209. mesToolLifeService.update(mesToolLife);
  210. }
  211. }
  212. }
  213. String newOprno = CommonUitl.formatOprno(mesElectricTorque.getOprno());
  214. // 如果其他电批枪的结果都不为UDF,则更新总结果
  215. if("OP310".equals(newOprno)) {
  216. List<ParamsResp> params = new ArrayList<>();
  217. ParamsResp paramsResp1 = new ParamsResp();
  218. paramsResp1.setCraft("400001");
  219. paramsResp1.setResult("OK");
  220. paramsResp1.setVal("");
  221. params.add(paramsResp1);
  222. MesProductOprno mesProductOprno = new MesProductOprno();
  223. mesProductOprno.setSn(mesElectricTorque.getSn());
  224. mesProductOprno.setOprno(newOprno);
  225. mesProductOprno.setLineSn("XT");
  226. MesProductOprno mesProductOprno1 = mesProductOprnoService.findInfo(mesProductOprno);
  227. System.out.println(mesProductOprno1);
  228. if(ObjectUtils.isEmpty(mesProductOprno1)){
  229. //添加子工位表
  230. mesProductOprnoService.save(mesProductOprno);
  231. mesProductOprno1 = mesProductOprnoService.findInfo(mesProductOprno);
  232. }
  233. mesProductOprno1.setResult2("OK");
  234. mesProductOprnoService.save(mesProductOprno1);
  235. // 全有结果
  236. if(mesProductOprno1.getResult1()!=null && !StringUtils.isEmpty(mesProductOprno1.getResult1()) && mesProductOprno1.getResult2()!=null && !StringUtils.isEmpty(mesProductOprno1.getResult2())) {
  237. String lastRet = "NG";
  238. if (mesProductOprno1.getResult1().equals("OK") && mesProductOprno1.getResult2().equals("OK")) {
  239. lastRet = "OK";
  240. }
  241. // 2.判断物料批次是否符合绑定
  242. List<BindMaterialResp> bmlists = mesLineProcessMaterialService.getBindMaterial(mesElectricTorque.getOprno(), "XT");
  243. // 总结果产线要求写死“OK”
  244. mesProductRecordService.updateRecordResult(mesElectricTorque.getSn(), "OP310", "100000", "", lastRet, "System", params, "XT", true, bmlists);
  245. }
  246. }
  247. return renderResult(Global.TRUE, text("操作成功!"));
  248. }
  249. /**
  250. * 检验是否合格
  251. */
  252. @RequestMapping(value = "check")
  253. @ResponseBody
  254. public String check(@RequestBody MesElectricTorque mesElectricTorque) {
  255. String oprno = mesElectricTorque.getOprno();
  256. String lineSn = mesElectricTorque.getLineSn();
  257. String sn = mesElectricTorque.getSn();
  258. if ("".equals(oprno) || "".equals(lineSn) || "".equals(sn)){
  259. return renderResult(Global.FALSE, text("操作失败,缺少参数值!"));
  260. }
  261. return renderResult(Global.TRUE, text("删除电批过程参数成功!"));
  262. }
  263. }