MesJbLogController.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. package com.jeesite.modules.mes.web;
  2. import java.util.List;
  3. import java.util.Map;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import com.jeesite.common.collect.ListUtils;
  7. import com.jeesite.common.collect.MapUtils;
  8. import com.jeesite.modules.mes.entity.*;
  9. import com.jeesite.modules.mes.resp.CommonResp;
  10. import com.jeesite.modules.mes.service.MesBatchSnService;
  11. import com.jeesite.modules.mes.service.MesProductService;
  12. import com.jeesite.modules.mes.service.MesShippRecordService;
  13. import com.jeesite.modules.sys.entity.User;
  14. import com.jeesite.modules.sys.utils.UserUtils;
  15. import org.apache.shiro.authz.annotation.RequiresPermissions;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.stereotype.Controller;
  18. import org.springframework.transaction.annotation.Transactional;
  19. import org.springframework.ui.Model;
  20. import org.springframework.util.ObjectUtils;
  21. import org.springframework.util.StringUtils;
  22. import org.springframework.validation.annotation.Validated;
  23. import org.springframework.web.bind.annotation.ModelAttribute;
  24. import org.springframework.web.bind.annotation.PostMapping;
  25. import org.springframework.web.bind.annotation.RequestMapping;
  26. import org.springframework.web.bind.annotation.ResponseBody;
  27. import com.jeesite.common.config.Global;
  28. import com.jeesite.common.entity.Page;
  29. import com.jeesite.common.web.BaseController;
  30. import com.jeesite.modules.mes.service.MesJbLogService;
  31. /**
  32. * 批次解绑记录表Controller
  33. * @author mes
  34. * @version 2024-04-12
  35. */
  36. @Controller
  37. @RequestMapping(value = "${adminPath}/mes/mesJbLog")
  38. public class MesJbLogController extends BaseController {
  39. @Autowired
  40. private MesJbLogService mesJbLogService;
  41. @Autowired
  42. private MesBatchSnService mesBatchSnService;
  43. @Autowired
  44. private MesProductService mesProductService;
  45. @Autowired
  46. private MesShippRecordService mesShippRecordService;
  47. /**
  48. * 获取数据
  49. */
  50. @ModelAttribute
  51. public MesJbLog get(String id, boolean isNewRecord) {
  52. return mesJbLogService.get(id, isNewRecord);
  53. }
  54. /**
  55. * 查询列表
  56. */
  57. @RequiresPermissions("mes:mesJbLog:view")
  58. @RequestMapping(value = {"list", ""})
  59. public String list(MesJbLog mesJbLog, Model model) {
  60. model.addAttribute("mesJbLog", mesJbLog);
  61. return "modules/mes/mesJbLogList";
  62. }
  63. /**
  64. * 查询列表数据
  65. */
  66. @RequiresPermissions("mes:mesJbLog:view")
  67. @RequestMapping(value = "listData")
  68. @ResponseBody
  69. public Page<MesJbLog> listData(MesJbLog mesJbLog, HttpServletRequest request, HttpServletResponse response) {
  70. mesJbLog.setPage(new Page<>(request, response));
  71. Page<MesJbLog> page = mesJbLogService.findPage(mesJbLog);
  72. return page;
  73. }
  74. /**
  75. * 查看编辑表单
  76. */
  77. @RequiresPermissions("mes:mesJbLog:view")
  78. @RequestMapping(value = "form")
  79. public String form(MesJbLog mesJbLog, Model model) {
  80. model.addAttribute("mesJbLog", mesJbLog);
  81. return "modules/mes/mesJbLogForm";
  82. }
  83. /**
  84. * 保存数据
  85. */
  86. @RequiresPermissions("mes:mesJbLog:edit")
  87. @PostMapping(value = "save")
  88. @ResponseBody
  89. public String save(@Validated MesJbLog mesJbLog) {
  90. mesJbLogService.save(mesJbLog);
  91. return renderResult(Global.TRUE, text("保存批次解绑记录表成功!"));
  92. }
  93. @RequiresPermissions("mes:mesJbLog:api")
  94. @RequestMapping(value = "ulist")
  95. @ResponseBody
  96. public CommonResp ulist(HttpServletRequest req, HttpServletResponse response) {
  97. CommonResp<Page> resp = new CommonResp<>();
  98. User user = UserUtils.getUser();
  99. MesJbLog mesJbLog = new MesJbLog();
  100. mesJbLog.setCreateBy(user.getUserCode());
  101. mesJbLog.setPage(new Page<>(req, response));
  102. Page<MesJbLog> page = mesJbLogService.findPage(mesJbLog);
  103. resp.setData(page);
  104. resp.setResult(Global.TRUE);
  105. return resp;
  106. }
  107. @RequiresPermissions("mes:mesJbLog:api")
  108. @RequestMapping(value = "getBatchInfo")
  109. @ResponseBody
  110. public CommonResp getBatchInfo(HttpServletRequest req) {
  111. CommonResp<List<MesProduct>> resp = new CommonResp<>();
  112. String batchSn = req.getParameter("batchSn");
  113. MesBatchSn mesBatchSn = new MesBatchSn();
  114. mesBatchSn.setBatchSn(batchSn);
  115. MesBatchSn mbs = mesBatchSnService.findInfo(mesBatchSn);
  116. if(ObjectUtils.isEmpty(mbs)){
  117. resp.setResult(Global.FALSE);
  118. resp.setMessage("批次信息不存在");
  119. return resp;
  120. }
  121. // if(mbs.getNums()==0){
  122. // resp.setResult(Global.FALSE);
  123. // resp.setMessage("当前批次未绑定工件");
  124. // return resp;
  125. // }
  126. MesProduct mesProduct = new MesProduct();;
  127. mesProduct.setBatchSn(batchSn);
  128. List<MesProduct> mp = mesProductService.findList(mesProduct);
  129. resp.setData(mp);
  130. resp.setResult(Global.TRUE);
  131. return resp;
  132. }
  133. @RequiresPermissions("mes:mesJbLog:api")
  134. @PostMapping(value = "addSave")
  135. @Transactional
  136. @ResponseBody
  137. public CommonResp addSave(HttpServletRequest req) {
  138. String batchSn = req.getParameter("batchSn");
  139. String sn = req.getParameter("sn");
  140. CommonResp<Map<String, Object>> resp = new CommonResp<>();
  141. Map<String, Object> map = MapUtils.newHashMap();
  142. resp.setResult(Global.FALSE);
  143. if(StringUtils.isEmpty(batchSn) ||StringUtils.isEmpty(sn)){
  144. resp.setMessage("参数错误");
  145. return resp;
  146. }
  147. MesBatchSn mesBatchSn = new MesBatchSn();
  148. mesBatchSn.setBatchSn(batchSn);
  149. MesBatchSn mbs = mesBatchSnService.findInfo(mesBatchSn);
  150. if(ObjectUtils.isEmpty(mbs)){
  151. resp.setMessage("批次码信息不存在");
  152. return resp;
  153. }
  154. MesShippRecord mesShippRecord =new MesShippRecord();
  155. mesShippRecord.setBatchSn(batchSn);
  156. List<MesShippRecord> msr = mesShippRecordService.findList(mesShippRecord);
  157. if(!ListUtils.isEmpty(msr)){
  158. resp.setMessage("当前批次已出货,不能解绑");
  159. return resp;
  160. }
  161. MesProduct mesProduct = new MesProduct();
  162. mesProduct.setBatchSn(batchSn);
  163. mesProduct.setSn(sn);
  164. MesProduct mp = mesProductService.findInfo(mesProduct);
  165. if(ObjectUtils.isEmpty(mp)){
  166. resp.setMessage("当前工件已解绑");
  167. return resp;
  168. }
  169. mp.setBatchSn("");
  170. mp.setBindDate(null);
  171. mp.setBindBy("");
  172. mesProductService.save(mp);
  173. MesJbLog mesJbLog = new MesJbLog();
  174. mesJbLog.setBatchSn(batchSn);
  175. mesJbLog.setSn(sn);
  176. mesJbLogService.save(mesJbLog);
  177. mbs.setNums(mbs.getNums()-1);
  178. mesBatchSnService.save(mbs);
  179. resp.setResult(Global.TRUE);
  180. resp.setMessage("操作成功");
  181. return resp;
  182. }
  183. }