| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- package com.jeesite.modules.mes.web;
- import com.jeesite.common.config.Global;
- import com.jeesite.common.entity.Page;
- import com.jeesite.common.lang.StringUtils;
- import com.jeesite.common.web.BaseController;
- import com.jeesite.modules.mes.entity.MesErpSchedule;
- import com.jeesite.modules.mes.entity.MesLine;
- import com.jeesite.modules.mes.erp.ErpProductionOrder;
- import com.jeesite.modules.mes.erp.ErpProductionOrderService;
- import com.jeesite.modules.mes.erp.KingdeeErpProperties;
- import com.jeesite.modules.mes.service.MesErpScheduleService;
- import com.jeesite.modules.mes.service.MesLineService;
- import org.apache.shiro.authz.annotation.Logical;
- import org.apache.shiro.authz.annotation.RequiresPermissions;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.ModelAttribute;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.time.YearMonth;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * ERP排产计划Controller
- */
- @Controller
- @RequestMapping(value = "${adminPath}/mes/mesErpSchedule")
- public class MesErpScheduleController extends BaseController {
- private final MesErpScheduleService mesErpScheduleService;
- private final MesLineService mesLineService;
- private final ErpProductionOrderService erpProductionOrderService;
- private final KingdeeErpProperties erpProperties;
- public MesErpScheduleController(MesErpScheduleService mesErpScheduleService,
- MesLineService mesLineService,
- ErpProductionOrderService erpProductionOrderService,
- KingdeeErpProperties erpProperties) {
- this.mesErpScheduleService = mesErpScheduleService;
- this.mesLineService = mesLineService;
- this.erpProductionOrderService = erpProductionOrderService;
- this.erpProperties = erpProperties;
- }
- @ModelAttribute
- public MesErpSchedule get(String id, boolean isNewRecord) {
- return mesErpScheduleService.get(id, isNewRecord);
- }
- @RequiresPermissions("mes:mesErpSchedule:view")
- @RequestMapping(value = {"list", ""})
- public String list(MesErpSchedule mesErpSchedule, Model model) {
- model.addAttribute("mesErpSchedule", mesErpSchedule);
- List<String> scheduleMaterialNumbers = erpProperties.getScheduleMaterialNumbers();
- model.addAttribute("scheduleMaterialNumbersText", String.join(" / ", scheduleMaterialNumbers));
- return "modules/mes/mesErpScheduleList";
- }
- @RequiresPermissions(value = {"mes:mesErpSchedule:view", "mes:erpProductionOrder:view"}, logical = Logical.OR)
- @RequestMapping(value = "selectOrder")
- public String selectOrder(ErpProductionOrder erpProductionOrder, Model model) {
- model.addAttribute("erpProductionOrder", erpProductionOrder);
- List<String> scheduleMaterialNumbers = erpProperties.getScheduleMaterialNumbers();
- model.addAttribute("scheduleMaterialNumbersText", String.join(" / ", scheduleMaterialNumbers));
- return "modules/mes/mesErpScheduleSelectOrder";
- }
- @RequiresPermissions(value = {"mes:mesErpSchedule:view", "mes:erpProductionOrder:view"}, logical = Logical.OR)
- @RequestMapping(value = "selectOrderData")
- @ResponseBody
- public Page<ErpProductionOrder> selectOrderData(ErpProductionOrder erpProductionOrder,
- HttpServletRequest request, HttpServletResponse response) {
- Page<ErpProductionOrder> page = new Page<>(request, response);
- int pageSize = page.getPageSize() > 0 ? page.getPageSize() : 20;
- int pageNo = page.getPageNo() > 0 ? page.getPageNo() : 1;
- int startRow = (pageNo - 1) * pageSize;
- List<ErpProductionOrder> list = erpProductionOrderService.findScheduleOrderPageList(
- erpProductionOrder.getBillNo(), startRow, pageSize);
- page.setList(list);
- page.setCount(startRow + list.size() + (list.size() == pageSize ? 1 : 0));
- return page;
- }
- @RequiresPermissions("mes:mesErpSchedule:view")
- @RequestMapping(value = "listData")
- @ResponseBody
- public Page<MesErpSchedule> listData(MesErpSchedule mesErpSchedule,
- HttpServletRequest request, HttpServletResponse response) {
- mesErpSchedule.setPage(new Page<>(request, response));
- return mesErpScheduleService.findPage(mesErpSchedule);
- }
- @RequiresPermissions("mes:mesErpSchedule:view")
- @RequestMapping(value = "board")
- public String board(String month, Model model) {
- String monthVal = StringUtils.isNotBlank(month) ? month.trim() : YearMonth.now().toString();
- model.addAttribute("month", monthVal);
- return "modules/mes/mesErpScheduleBoard";
- }
- @RequiresPermissions("mes:mesErpSchedule:view")
- @RequestMapping(value = "boardData")
- @ResponseBody
- public Map<String, Object> boardData(String month) {
- Map<String, Object> map = new HashMap<>();
- try {
- Map<String, Object> data = mesErpScheduleService.buildBoardDataForMonth(month);
- map.put("result", Global.TRUE);
- map.put("data", data);
- } catch (Exception ex) {
- map.put("result", Global.FALSE);
- map.put("message", ex.getMessage());
- }
- return map;
- }
- @RequiresPermissions("mes:mesErpSchedule:view")
- @RequestMapping(value = "detail")
- public String detail(MesErpSchedule mesErpSchedule, Model model) {
- Map<String, Object> detail = mesErpScheduleService.buildScheduleDetail(mesErpSchedule);
- model.addAttribute("mesErpSchedule", detail.get("schedule"));
- model.addAttribute("stationStats", detail.get("stationStats"));
- model.addAttribute("totalOkQty", detail.get("totalOkQty"));
- model.addAttribute("stationCount", detail.get("stationCount"));
- MesErpSchedule schedule = (MesErpSchedule) detail.get("schedule");
- String boardMonth = "";
- if (schedule != null && StringUtils.isNotBlank(schedule.getScheduleStartDate())
- && schedule.getScheduleStartDate().length() >= 7) {
- boardMonth = schedule.getScheduleStartDate().substring(0, 7);
- }
- model.addAttribute("boardMonth", boardMonth);
- return "modules/mes/mesErpScheduleDetail";
- }
- @RequiresPermissions(value = {"mes:mesErpSchedule:view", "mes:erpProductionOrder:view"}, logical = Logical.OR)
- @RequestMapping(value = "form")
- public String form(MesErpSchedule mesErpSchedule, Model model) {
- if (mesErpSchedule.getIsNewRecord()
- && StringUtils.isNotBlank(mesErpSchedule.getErpBillNo())) {
- MesErpSchedule fromErp = mesErpScheduleService.buildFromErpEntry(
- mesErpSchedule.getErpBillNo(), mesErpSchedule.getErpEntryId());
- copyErpFields(mesErpSchedule, fromErp);
- }
- MesLine lineQuery = new MesLine();
- lineQuery.setStatus(MesLine.STATUS_NORMAL);
- List<MesLine> lines = mesLineService.findList(lineQuery);
- model.addAttribute("lines", lines);
- model.addAttribute("mesErpSchedule", mesErpSchedule);
- return "modules/mes/mesErpScheduleForm";
- }
- @RequiresPermissions("mes:mesErpSchedule:view")
- @RequestMapping(value = "erpEntryData")
- @ResponseBody
- public Map<String, Object> erpEntryData(String erpBillNo, String erpEntryId) {
- MesErpSchedule schedule = mesErpScheduleService.buildFromErpEntry(erpBillNo, erpEntryId);
- Map<String, Object> map = new HashMap<>();
- map.put("result", Global.TRUE);
- map.put("data", schedule);
- return map;
- }
- @RequiresPermissions(value = {"mes:mesErpSchedule:view", "mes:erpProductionOrder:view"}, logical = Logical.OR)
- @PostMapping(value = "save")
- @ResponseBody
- public String save(@Validated MesErpSchedule mesErpSchedule) {
- mesErpScheduleService.save(mesErpSchedule);
- return renderResult(Global.TRUE, text("保存ERP排产计划成功!"));
- }
- @RequiresPermissions(value = {"mes:mesErpSchedule:view", "mes:erpProductionOrder:view"}, logical = Logical.OR)
- @RequestMapping(value = "delete")
- @ResponseBody
- public String delete(MesErpSchedule mesErpSchedule) {
- mesErpScheduleService.delete(mesErpSchedule);
- return renderResult(Global.TRUE, text("删除ERP排产计划成功!"));
- }
- private void copyErpFields(MesErpSchedule target, MesErpSchedule source) {
- target.setErpBillNo(source.getErpBillNo());
- target.setErpEntryId(source.getErpEntryId());
- target.setErpSeq(source.getErpSeq());
- target.setMaterialNumber(source.getMaterialNumber());
- target.setMaterialName(source.getMaterialName());
- target.setInventoryCategory(source.getInventoryCategory());
- target.setWorkshopName(source.getWorkshopName());
- target.setOrderQty(source.getOrderQty());
- target.setErpPlanStartDate(source.getErpPlanStartDate());
- target.setErpPlanFinishDate(source.getErpPlanFinishDate());
- target.setLineId(source.getLineId());
- target.setLineSn(source.getLineSn());
- target.setLineTitle(source.getLineTitle());
- target.setScheduledQtySum(source.getScheduledQtySum());
- target.setRemainQty(source.getRemainQty());
- target.setScheduleStartDate(source.getScheduleStartDate());
- target.setScheduleEndDate(source.getScheduleEndDate());
- }
- }
|