MesDeliveryNoteController.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. package com.jeesite.modules.mes.web;
  2. import java.util.List;
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5. import org.apache.shiro.authz.annotation.RequiresPermissions;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Controller;
  8. import org.springframework.ui.Model;
  9. import org.springframework.validation.annotation.Validated;
  10. import org.springframework.web.bind.annotation.ModelAttribute;
  11. import org.springframework.web.bind.annotation.PostMapping;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.ResponseBody;
  14. import com.jeesite.common.codec.EncodeUtils;
  15. import com.jeesite.common.config.Global;
  16. import com.jeesite.common.entity.Page;
  17. import com.jeesite.common.lang.StringUtils;
  18. import com.jeesite.common.mybatis.mapper.query.QueryType;
  19. import com.alibaba.fastjson.JSONValidator;
  20. import com.jeesite.common.service.ServiceException;
  21. import com.jeesite.common.web.BaseController;
  22. import com.jeesite.modules.mes.entity.MesDeliveryNote;
  23. import com.jeesite.modules.mes.entity.MesDeliveryNoteBatch;
  24. import com.jeesite.modules.mes.entity.MesProduct;
  25. import com.jeesite.modules.mes.entity.MesProductBatch;
  26. import com.jeesite.modules.mes.service.MesDeliveryNoteBatchService;
  27. import com.jeesite.modules.mes.service.MesDeliveryNoteService;
  28. import com.jeesite.modules.mes.service.MesProductBatchService;
  29. import com.jeesite.modules.mes.service.MesProductService;
  30. /**
  31. * 送货单Controller
  32. */
  33. @Controller
  34. @RequestMapping(value = "${adminPath}/mes/mesDeliveryNote")
  35. public class MesDeliveryNoteController extends BaseController {
  36. @Autowired
  37. private MesDeliveryNoteService mesDeliveryNoteService;
  38. @Autowired
  39. private MesDeliveryNoteBatchService mesDeliveryNoteBatchService;
  40. @Autowired
  41. private MesProductBatchService mesProductBatchService;
  42. @Autowired
  43. private MesProductService mesProductService;
  44. @ModelAttribute
  45. public MesDeliveryNote get(String id, boolean isNewRecord) {
  46. return mesDeliveryNoteService.get(id, isNewRecord);
  47. }
  48. @RequiresPermissions("mes:mesDeliveryNote:view")
  49. @RequestMapping(value = {"list", ""})
  50. public String list(MesDeliveryNote mesDeliveryNote, Model model) {
  51. model.addAttribute("mesDeliveryNote", mesDeliveryNote);
  52. return "modules/mes/mesDeliveryNoteList";
  53. }
  54. @RequiresPermissions("mes:mesDeliveryNote:view")
  55. @RequestMapping(value = "listData")
  56. @ResponseBody
  57. public Page<MesDeliveryNote> listData(MesDeliveryNote mesDeliveryNote, HttpServletRequest request, HttpServletResponse response) {
  58. mesDeliveryNote.setPage(new Page<>(request, response));
  59. return mesDeliveryNoteService.findPage(mesDeliveryNote);
  60. }
  61. @RequiresPermissions("mes:mesDeliveryNote:view")
  62. @RequestMapping(value = "form")
  63. public String form(MesDeliveryNote mesDeliveryNote, Model model) {
  64. model.addAttribute("mesDeliveryNote", mesDeliveryNote);
  65. return "modules/mes/mesDeliveryNoteForm";
  66. }
  67. @RequiresPermissions("mes:mesDeliveryNote:edit")
  68. @PostMapping(value = "save")
  69. @ResponseBody
  70. public String save(@Validated MesDeliveryNote mesDeliveryNote) {
  71. try {
  72. mesDeliveryNoteService.save(mesDeliveryNote);
  73. } catch (ServiceException ex) {
  74. return renderResult(Global.FALSE, ex.getMessage());
  75. }
  76. return renderResult(Global.TRUE, text("保存送货单成功!"));
  77. }
  78. @RequiresPermissions("mes:mesDeliveryNote:edit")
  79. @RequestMapping(value = "delete")
  80. @ResponseBody
  81. public String delete(MesDeliveryNote mesDeliveryNote) {
  82. try {
  83. mesDeliveryNoteService.delete(mesDeliveryNote);
  84. } catch (ServiceException ex) {
  85. return renderResult(Global.FALSE, ex.getMessage());
  86. }
  87. return renderResult(Global.TRUE, text("删除送货单成功!"));
  88. }
  89. @RequiresPermissions("mes:mesDeliveryNote:view")
  90. @RequestMapping(value = "bind")
  91. public String bind(MesDeliveryNote mesDeliveryNote, Model model) {
  92. model.addAttribute("mesDeliveryNote", mesDeliveryNote);
  93. return "modules/mes/mesDeliveryNoteBind";
  94. }
  95. @RequiresPermissions("mes:mesDeliveryNote:view")
  96. @RequestMapping(value = "bindListData")
  97. @ResponseBody
  98. public Page<MesDeliveryNoteBatch> bindListData(MesDeliveryNoteBatch mesDeliveryNoteBatch, HttpServletRequest request, HttpServletResponse response) {
  99. mesDeliveryNoteBatch.setPage(new Page<>(request, response));
  100. return mesDeliveryNoteBatchService.findPage(mesDeliveryNoteBatch);
  101. }
  102. @RequiresPermissions("mes:mesDeliveryNote:view")
  103. @RequestMapping(value = "batchProducts")
  104. public String batchProducts(String batchSn, Model model) {
  105. model.addAttribute("batchSn", batchSn);
  106. return "modules/mes/mesDeliveryNoteProducts";
  107. }
  108. @RequiresPermissions("mes:mesDeliveryNote:view")
  109. @RequestMapping(value = "batchProductData")
  110. @ResponseBody
  111. public Page<MesProduct> batchProductData(MesProduct mesProduct, HttpServletRequest request, HttpServletResponse response) {
  112. String batchSn = mesProduct.getBatchSn();
  113. mesProduct.setBatchSn(null);
  114. if (StringUtils.isBlank(batchSn)) {
  115. mesProduct.getSqlMap().getWhere().and("id", QueryType.EQ, "-1");
  116. } else {
  117. mesProduct.getSqlMap().getWhere().and("batch_sn", QueryType.EQ, batchSn);
  118. }
  119. String sn = mesProduct.getSn();
  120. if (StringUtils.isNotBlank(sn)) {
  121. mesProduct.setSn(null);
  122. mesProduct.getSqlMap().getWhere().and("sn", QueryType.LIKE, sn);
  123. }
  124. mesProduct.setPage(new Page<>(request, response));
  125. return mesProductService.findPage(mesProduct);
  126. }
  127. @RequiresPermissions("mes:mesDeliveryNote:edit")
  128. @PostMapping(value = "bindBatch")
  129. @ResponseBody
  130. public String bindBatch(String deliveryId, String batchIds) {
  131. try {
  132. mesDeliveryNoteService.bindBatches(deliveryId, batchIds);
  133. } catch (ServiceException ex) {
  134. return renderResult(Global.FALSE, ex.getMessage());
  135. }
  136. return renderResult(Global.TRUE, text("绑定成品批次成功!"));
  137. }
  138. @RequiresPermissions("mes:mesDeliveryNote:edit")
  139. @RequestMapping(value = "unbindBatch")
  140. @ResponseBody
  141. public String unbindBatch(MesDeliveryNoteBatch mesDeliveryNoteBatch) {
  142. mesDeliveryNoteBatchService.delete(mesDeliveryNoteBatch);
  143. return renderResult(Global.TRUE, text("解除绑定成功!"));
  144. }
  145. @RequiresPermissions("mes:mesDeliveryNote:view")
  146. @RequestMapping(value = "batchSelect")
  147. public String batchSelect(MesProductBatch mesProductBatch, String selectData, Model model) {
  148. String selectDataJson = EncodeUtils.decodeUrl(selectData);
  149. if (selectDataJson != null && JSONValidator.from(selectDataJson).validate()) {
  150. model.addAttribute("selectData", selectDataJson);
  151. }
  152. model.addAttribute("mesProductBatch", mesProductBatch);
  153. return "modules/mes/mesProductBatchSelect";
  154. }
  155. @RequiresPermissions("mes:mesDeliveryNote:view")
  156. @RequestMapping(value = "batchSelectData")
  157. @ResponseBody
  158. public Page<MesProductBatch> batchSelectData(MesProductBatch mesProductBatch, HttpServletRequest request, HttpServletResponse response) {
  159. List<MesDeliveryNoteBatch> boundList = mesDeliveryNoteBatchService.findList(new MesDeliveryNoteBatch());
  160. if (boundList != null && !boundList.isEmpty()) {
  161. String[] boundIds = boundList.stream()
  162. .map(MesDeliveryNoteBatch::getBatchId)
  163. .filter(StringUtils::isNotBlank)
  164. .distinct()
  165. .toArray(String[]::new);
  166. if (boundIds.length > 0) {
  167. mesProductBatch.getSqlMap().getWhere().and("id", QueryType.NOT_IN, boundIds);
  168. }
  169. }
  170. mesProductBatch.setPage(new Page<>(request, response));
  171. return mesProductBatchService.findPage(mesProductBatch);
  172. }
  173. }