| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- package com.jeesite.modules.mes.web;
- import java.util.List;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.shiro.authz.annotation.RequiresPermissions;
- import org.springframework.beans.factory.annotation.Autowired;
- 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 com.jeesite.common.codec.EncodeUtils;
- import com.jeesite.common.config.Global;
- import com.jeesite.common.entity.Page;
- import com.jeesite.common.lang.StringUtils;
- import com.jeesite.common.mybatis.mapper.query.QueryType;
- import com.alibaba.fastjson.JSONValidator;
- import com.jeesite.common.service.ServiceException;
- import com.jeesite.common.web.BaseController;
- import com.jeesite.modules.mes.entity.MesDeliveryNote;
- import com.jeesite.modules.mes.entity.MesDeliveryNoteBatch;
- import com.jeesite.modules.mes.entity.MesProduct;
- import com.jeesite.modules.mes.entity.MesProductBatch;
- import com.jeesite.modules.mes.service.MesDeliveryNoteBatchService;
- import com.jeesite.modules.mes.service.MesDeliveryNoteService;
- import com.jeesite.modules.mes.service.MesProductBatchService;
- import com.jeesite.modules.mes.service.MesProductService;
- /**
- * 送货单Controller
- */
- @Controller
- @RequestMapping(value = "${adminPath}/mes/mesDeliveryNote")
- public class MesDeliveryNoteController extends BaseController {
- @Autowired
- private MesDeliveryNoteService mesDeliveryNoteService;
- @Autowired
- private MesDeliveryNoteBatchService mesDeliveryNoteBatchService;
- @Autowired
- private MesProductBatchService mesProductBatchService;
- @Autowired
- private MesProductService mesProductService;
- @ModelAttribute
- public MesDeliveryNote get(String id, boolean isNewRecord) {
- return mesDeliveryNoteService.get(id, isNewRecord);
- }
- @RequiresPermissions("mes:mesDeliveryNote:view")
- @RequestMapping(value = {"list", ""})
- public String list(MesDeliveryNote mesDeliveryNote, Model model) {
- model.addAttribute("mesDeliveryNote", mesDeliveryNote);
- return "modules/mes/mesDeliveryNoteList";
- }
- @RequiresPermissions("mes:mesDeliveryNote:view")
- @RequestMapping(value = "listData")
- @ResponseBody
- public Page<MesDeliveryNote> listData(MesDeliveryNote mesDeliveryNote, HttpServletRequest request, HttpServletResponse response) {
- mesDeliveryNote.setPage(new Page<>(request, response));
- return mesDeliveryNoteService.findPage(mesDeliveryNote);
- }
- @RequiresPermissions("mes:mesDeliveryNote:view")
- @RequestMapping(value = "form")
- public String form(MesDeliveryNote mesDeliveryNote, Model model) {
- model.addAttribute("mesDeliveryNote", mesDeliveryNote);
- return "modules/mes/mesDeliveryNoteForm";
- }
- @RequiresPermissions("mes:mesDeliveryNote:edit")
- @PostMapping(value = "save")
- @ResponseBody
- public String save(@Validated MesDeliveryNote mesDeliveryNote) {
- try {
- mesDeliveryNoteService.save(mesDeliveryNote);
- } catch (ServiceException ex) {
- return renderResult(Global.FALSE, ex.getMessage());
- }
- return renderResult(Global.TRUE, text("保存送货单成功!"));
- }
- @RequiresPermissions("mes:mesDeliveryNote:edit")
- @RequestMapping(value = "delete")
- @ResponseBody
- public String delete(MesDeliveryNote mesDeliveryNote) {
- try {
- mesDeliveryNoteService.delete(mesDeliveryNote);
- } catch (ServiceException ex) {
- return renderResult(Global.FALSE, ex.getMessage());
- }
- return renderResult(Global.TRUE, text("删除送货单成功!"));
- }
- @RequiresPermissions("mes:mesDeliveryNote:view")
- @RequestMapping(value = "bind")
- public String bind(MesDeliveryNote mesDeliveryNote, Model model) {
- model.addAttribute("mesDeliveryNote", mesDeliveryNote);
- return "modules/mes/mesDeliveryNoteBind";
- }
- @RequiresPermissions("mes:mesDeliveryNote:view")
- @RequestMapping(value = "bindListData")
- @ResponseBody
- public Page<MesDeliveryNoteBatch> bindListData(MesDeliveryNoteBatch mesDeliveryNoteBatch, HttpServletRequest request, HttpServletResponse response) {
- mesDeliveryNoteBatch.setPage(new Page<>(request, response));
- return mesDeliveryNoteBatchService.findPage(mesDeliveryNoteBatch);
- }
- @RequiresPermissions("mes:mesDeliveryNote:view")
- @RequestMapping(value = "batchProducts")
- public String batchProducts(String batchSn, Model model) {
- model.addAttribute("batchSn", batchSn);
- return "modules/mes/mesDeliveryNoteProducts";
- }
- @RequiresPermissions("mes:mesDeliveryNote:view")
- @RequestMapping(value = "batchProductData")
- @ResponseBody
- public Page<MesProduct> batchProductData(MesProduct mesProduct, HttpServletRequest request, HttpServletResponse response) {
- String batchSn = mesProduct.getBatchSn();
- mesProduct.setBatchSn(null);
- if (StringUtils.isBlank(batchSn)) {
- mesProduct.getSqlMap().getWhere().and("id", QueryType.EQ, "-1");
- } else {
- mesProduct.getSqlMap().getWhere().and("batch_sn", QueryType.EQ, batchSn);
- }
- String sn = mesProduct.getSn();
- if (StringUtils.isNotBlank(sn)) {
- mesProduct.setSn(null);
- mesProduct.getSqlMap().getWhere().and("sn", QueryType.LIKE, sn);
- }
- mesProduct.setPage(new Page<>(request, response));
- return mesProductService.findPage(mesProduct);
- }
- @RequiresPermissions("mes:mesDeliveryNote:edit")
- @PostMapping(value = "bindBatch")
- @ResponseBody
- public String bindBatch(String deliveryId, String batchIds) {
- try {
- mesDeliveryNoteService.bindBatches(deliveryId, batchIds);
- } catch (ServiceException ex) {
- return renderResult(Global.FALSE, ex.getMessage());
- }
- return renderResult(Global.TRUE, text("绑定成品批次成功!"));
- }
- @RequiresPermissions("mes:mesDeliveryNote:edit")
- @RequestMapping(value = "unbindBatch")
- @ResponseBody
- public String unbindBatch(MesDeliveryNoteBatch mesDeliveryNoteBatch) {
- mesDeliveryNoteBatchService.delete(mesDeliveryNoteBatch);
- return renderResult(Global.TRUE, text("解除绑定成功!"));
- }
- @RequiresPermissions("mes:mesDeliveryNote:view")
- @RequestMapping(value = "batchSelect")
- public String batchSelect(MesProductBatch mesProductBatch, String selectData, Model model) {
- String selectDataJson = EncodeUtils.decodeUrl(selectData);
- if (selectDataJson != null && JSONValidator.from(selectDataJson).validate()) {
- model.addAttribute("selectData", selectDataJson);
- }
- model.addAttribute("mesProductBatch", mesProductBatch);
- return "modules/mes/mesProductBatchSelect";
- }
- @RequiresPermissions("mes:mesDeliveryNote:view")
- @RequestMapping(value = "batchSelectData")
- @ResponseBody
- public Page<MesProductBatch> batchSelectData(MesProductBatch mesProductBatch, HttpServletRequest request, HttpServletResponse response) {
- List<MesDeliveryNoteBatch> boundList = mesDeliveryNoteBatchService.findList(new MesDeliveryNoteBatch());
- if (boundList != null && !boundList.isEmpty()) {
- String[] boundIds = boundList.stream()
- .map(MesDeliveryNoteBatch::getBatchId)
- .filter(StringUtils::isNotBlank)
- .distinct()
- .toArray(String[]::new);
- if (boundIds.length > 0) {
- mesProductBatch.getSqlMap().getWhere().and("id", QueryType.NOT_IN, boundIds);
- }
- }
- mesProductBatch.setPage(new Page<>(request, response));
- return mesProductBatchService.findPage(mesProductBatch);
- }
- }
|