MesErpScheduleController.java 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. package com.jeesite.modules.mes.web;
  2. import com.jeesite.common.config.Global;
  3. import com.jeesite.common.entity.Page;
  4. import com.jeesite.common.lang.StringUtils;
  5. import com.jeesite.common.web.BaseController;
  6. import com.jeesite.modules.mes.entity.MesErpSchedule;
  7. import com.jeesite.modules.mes.entity.MesLine;
  8. import com.jeesite.modules.mes.erp.ErpProductionOrder;
  9. import com.jeesite.modules.mes.erp.ErpProductionOrderService;
  10. import com.jeesite.modules.mes.erp.KingdeeErpProperties;
  11. import com.jeesite.modules.mes.service.MesErpScheduleService;
  12. import com.jeesite.modules.mes.service.MesLineService;
  13. import org.apache.shiro.authz.annotation.Logical;
  14. import org.apache.shiro.authz.annotation.RequiresPermissions;
  15. import org.springframework.stereotype.Controller;
  16. import org.springframework.ui.Model;
  17. import org.springframework.validation.annotation.Validated;
  18. import org.springframework.web.bind.annotation.ModelAttribute;
  19. import org.springframework.web.bind.annotation.PostMapping;
  20. import org.springframework.web.bind.annotation.RequestMapping;
  21. import org.springframework.web.bind.annotation.ResponseBody;
  22. import javax.servlet.http.HttpServletRequest;
  23. import javax.servlet.http.HttpServletResponse;
  24. import java.time.YearMonth;
  25. import java.util.HashMap;
  26. import java.util.List;
  27. import java.util.Map;
  28. /**
  29. * ERP排产计划Controller
  30. */
  31. @Controller
  32. @RequestMapping(value = "${adminPath}/mes/mesErpSchedule")
  33. public class MesErpScheduleController extends BaseController {
  34. private final MesErpScheduleService mesErpScheduleService;
  35. private final MesLineService mesLineService;
  36. private final ErpProductionOrderService erpProductionOrderService;
  37. private final KingdeeErpProperties erpProperties;
  38. public MesErpScheduleController(MesErpScheduleService mesErpScheduleService,
  39. MesLineService mesLineService,
  40. ErpProductionOrderService erpProductionOrderService,
  41. KingdeeErpProperties erpProperties) {
  42. this.mesErpScheduleService = mesErpScheduleService;
  43. this.mesLineService = mesLineService;
  44. this.erpProductionOrderService = erpProductionOrderService;
  45. this.erpProperties = erpProperties;
  46. }
  47. @ModelAttribute
  48. public MesErpSchedule get(String id, boolean isNewRecord) {
  49. return mesErpScheduleService.get(id, isNewRecord);
  50. }
  51. @RequiresPermissions("mes:mesErpSchedule:view")
  52. @RequestMapping(value = {"list", ""})
  53. public String list(MesErpSchedule mesErpSchedule, Model model) {
  54. model.addAttribute("mesErpSchedule", mesErpSchedule);
  55. List<String> scheduleMaterialNumbers = erpProperties.getScheduleMaterialNumbers();
  56. model.addAttribute("scheduleMaterialNumbersText", String.join(" / ", scheduleMaterialNumbers));
  57. return "modules/mes/mesErpScheduleList";
  58. }
  59. @RequiresPermissions(value = {"mes:mesErpSchedule:view", "mes:erpProductionOrder:view"}, logical = Logical.OR)
  60. @RequestMapping(value = "selectOrder")
  61. public String selectOrder(ErpProductionOrder erpProductionOrder, Model model) {
  62. model.addAttribute("erpProductionOrder", erpProductionOrder);
  63. List<String> scheduleMaterialNumbers = erpProperties.getScheduleMaterialNumbers();
  64. model.addAttribute("scheduleMaterialNumbersText", String.join(" / ", scheduleMaterialNumbers));
  65. return "modules/mes/mesErpScheduleSelectOrder";
  66. }
  67. @RequiresPermissions(value = {"mes:mesErpSchedule:view", "mes:erpProductionOrder:view"}, logical = Logical.OR)
  68. @RequestMapping(value = "selectOrderData")
  69. @ResponseBody
  70. public Page<ErpProductionOrder> selectOrderData(ErpProductionOrder erpProductionOrder,
  71. HttpServletRequest request, HttpServletResponse response) {
  72. Page<ErpProductionOrder> page = new Page<>(request, response);
  73. int pageSize = page.getPageSize() > 0 ? page.getPageSize() : 20;
  74. int pageNo = page.getPageNo() > 0 ? page.getPageNo() : 1;
  75. int startRow = (pageNo - 1) * pageSize;
  76. List<ErpProductionOrder> list = erpProductionOrderService.findScheduleOrderPageList(
  77. erpProductionOrder.getBillNo(), startRow, pageSize);
  78. page.setList(list);
  79. page.setCount(startRow + list.size() + (list.size() == pageSize ? 1 : 0));
  80. return page;
  81. }
  82. @RequiresPermissions("mes:mesErpSchedule:view")
  83. @RequestMapping(value = "listData")
  84. @ResponseBody
  85. public Page<MesErpSchedule> listData(MesErpSchedule mesErpSchedule,
  86. HttpServletRequest request, HttpServletResponse response) {
  87. mesErpSchedule.setPage(new Page<>(request, response));
  88. return mesErpScheduleService.findPage(mesErpSchedule);
  89. }
  90. @RequiresPermissions("mes:mesErpSchedule:view")
  91. @RequestMapping(value = "board")
  92. public String board(String month, Model model) {
  93. String monthVal = StringUtils.isNotBlank(month) ? month.trim() : YearMonth.now().toString();
  94. model.addAttribute("month", monthVal);
  95. return "modules/mes/mesErpScheduleBoard";
  96. }
  97. @RequiresPermissions("mes:mesErpSchedule:view")
  98. @RequestMapping(value = "boardData")
  99. @ResponseBody
  100. public Map<String, Object> boardData(String month) {
  101. Map<String, Object> map = new HashMap<>();
  102. try {
  103. Map<String, Object> data = mesErpScheduleService.buildBoardDataForMonth(month);
  104. map.put("result", Global.TRUE);
  105. map.put("data", data);
  106. } catch (Exception ex) {
  107. map.put("result", Global.FALSE);
  108. map.put("message", ex.getMessage());
  109. }
  110. return map;
  111. }
  112. @RequiresPermissions("mes:mesErpSchedule:view")
  113. @RequestMapping(value = "detail")
  114. public String detail(MesErpSchedule mesErpSchedule, Model model) {
  115. Map<String, Object> detail = mesErpScheduleService.buildScheduleDetail(mesErpSchedule);
  116. model.addAttribute("mesErpSchedule", detail.get("schedule"));
  117. model.addAttribute("stationStats", detail.get("stationStats"));
  118. model.addAttribute("totalOkQty", detail.get("totalOkQty"));
  119. model.addAttribute("stationCount", detail.get("stationCount"));
  120. MesErpSchedule schedule = (MesErpSchedule) detail.get("schedule");
  121. String boardMonth = "";
  122. if (schedule != null && StringUtils.isNotBlank(schedule.getScheduleStartDate())
  123. && schedule.getScheduleStartDate().length() >= 7) {
  124. boardMonth = schedule.getScheduleStartDate().substring(0, 7);
  125. }
  126. model.addAttribute("boardMonth", boardMonth);
  127. return "modules/mes/mesErpScheduleDetail";
  128. }
  129. @RequiresPermissions(value = {"mes:mesErpSchedule:view", "mes:erpProductionOrder:view"}, logical = Logical.OR)
  130. @RequestMapping(value = "form")
  131. public String form(MesErpSchedule mesErpSchedule, Model model) {
  132. if (mesErpSchedule.getIsNewRecord()
  133. && StringUtils.isNotBlank(mesErpSchedule.getErpBillNo())) {
  134. MesErpSchedule fromErp = mesErpScheduleService.buildFromErpEntry(
  135. mesErpSchedule.getErpBillNo(), mesErpSchedule.getErpEntryId());
  136. copyErpFields(mesErpSchedule, fromErp);
  137. }
  138. MesLine lineQuery = new MesLine();
  139. lineQuery.setStatus(MesLine.STATUS_NORMAL);
  140. List<MesLine> lines = mesLineService.findList(lineQuery);
  141. model.addAttribute("lines", lines);
  142. model.addAttribute("mesErpSchedule", mesErpSchedule);
  143. return "modules/mes/mesErpScheduleForm";
  144. }
  145. @RequiresPermissions("mes:mesErpSchedule:view")
  146. @RequestMapping(value = "erpEntryData")
  147. @ResponseBody
  148. public Map<String, Object> erpEntryData(String erpBillNo, String erpEntryId) {
  149. MesErpSchedule schedule = mesErpScheduleService.buildFromErpEntry(erpBillNo, erpEntryId);
  150. Map<String, Object> map = new HashMap<>();
  151. map.put("result", Global.TRUE);
  152. map.put("data", schedule);
  153. return map;
  154. }
  155. @RequiresPermissions(value = {"mes:mesErpSchedule:view", "mes:erpProductionOrder:view"}, logical = Logical.OR)
  156. @PostMapping(value = "save")
  157. @ResponseBody
  158. public String save(@Validated MesErpSchedule mesErpSchedule) {
  159. mesErpScheduleService.save(mesErpSchedule);
  160. return renderResult(Global.TRUE, text("保存ERP排产计划成功!"));
  161. }
  162. @RequiresPermissions(value = {"mes:mesErpSchedule:view", "mes:erpProductionOrder:view"}, logical = Logical.OR)
  163. @RequestMapping(value = "delete")
  164. @ResponseBody
  165. public String delete(MesErpSchedule mesErpSchedule) {
  166. mesErpScheduleService.delete(mesErpSchedule);
  167. return renderResult(Global.TRUE, text("删除ERP排产计划成功!"));
  168. }
  169. private void copyErpFields(MesErpSchedule target, MesErpSchedule source) {
  170. target.setErpBillNo(source.getErpBillNo());
  171. target.setErpEntryId(source.getErpEntryId());
  172. target.setErpSeq(source.getErpSeq());
  173. target.setMaterialNumber(source.getMaterialNumber());
  174. target.setMaterialName(source.getMaterialName());
  175. target.setInventoryCategory(source.getInventoryCategory());
  176. target.setWorkshopName(source.getWorkshopName());
  177. target.setOrderQty(source.getOrderQty());
  178. target.setErpPlanStartDate(source.getErpPlanStartDate());
  179. target.setErpPlanFinishDate(source.getErpPlanFinishDate());
  180. target.setLineId(source.getLineId());
  181. target.setLineSn(source.getLineSn());
  182. target.setLineTitle(source.getLineTitle());
  183. target.setScheduledQtySum(source.getScheduledQtySum());
  184. target.setRemainQty(source.getRemainQty());
  185. target.setScheduleStartDate(source.getScheduleStartDate());
  186. target.setScheduleEndDate(source.getScheduleEndDate());
  187. }
  188. }