|  |  | 
 |  |  | package com.zy.asrs.wms.asrs.controller; | 
 |  |  |  | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
 |  |  | import com.zy.asrs.framework.common.Cools; | 
 |  |  | import com.zy.asrs.framework.common.R; | 
 |  |  | import com.zy.asrs.framework.exception.CoolException; | 
 |  |  | import com.zy.asrs.wms.asrs.entity.MatField; | 
 |  |  | import com.zy.asrs.wms.asrs.entity.OrderType; | 
 |  |  | import com.zy.asrs.wms.asrs.entity.enums.OrderSettleType; | 
 |  |  | import com.zy.asrs.wms.asrs.entity.param.CreateOrderParam; | 
 |  |  | import com.zy.asrs.wms.asrs.entity.param.UpdateOrderParam; | 
 |  |  | import com.zy.asrs.wms.asrs.entity.template.OrderTemplate; | 
 |  |  | import com.zy.asrs.wms.asrs.service.MatFieldService; | 
 |  |  | import com.zy.asrs.wms.asrs.service.OrderTypeService; | 
 |  |  | import com.zy.asrs.wms.common.annotation.OperationLog; | 
 |  |  | import com.zy.asrs.wms.common.domain.BaseParam; | 
 |  |  | import com.zy.asrs.wms.common.domain.KeyValVo; | 
 |  |  | import com.zy.asrs.wms.common.domain.PageParam; | 
 |  |  | import com.zy.asrs.wms.asrs.entity.Order; | 
 |  |  | import com.zy.asrs.wms.asrs.service.OrderService; | 
 |  |  | import com.zy.asrs.wms.system.controller.BaseController; | 
 |  |  | import com.zy.asrs.wms.utils.ExcelUtil; | 
 |  |  | import com.zy.asrs.wms.utils.Utils; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.security.access.prepost.PreAuthorize; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  | import org.springframework.web.bind.annotation.*; | 
 |  |  | import org.springframework.web.multipart.MultipartFile; | 
 |  |  |  | 
 |  |  | import javax.servlet.http.HttpServletResponse; | 
 |  |  | import java.util.*; | 
 |  |  |  | 
 |  |  | @RestController | 
 |  |  | @RequestMapping("/api") | 
 |  |  | public class OrderController extends BaseController { | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private OrderService orderService; | 
 |  |  |     @Autowired | 
 |  |  |     private OrderTypeService orderTypeService; | 
 |  |  |     @Autowired | 
 |  |  |     private MatFieldService matFieldService; | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:list')") | 
 |  |  |     @PostMapping("/order/page") | 
 |  |  |     public R page(@RequestBody Map<String, Object> map) { | 
 |  |  |         BaseParam baseParam = buildParam(map, BaseParam.class); | 
 |  |  |         PageParam<Order, BaseParam> pageParam = new PageParam<>(baseParam, Order.class); | 
 |  |  |         return R.ok().add(orderService.page(pageParam, pageParam.buildWrapper(true))); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:list')") | 
 |  |  |     @PostMapping("/order/in/page") | 
 |  |  |     public R pageIn(@RequestBody Map<String, Object> map) { | 
 |  |  |         String condition = map.getOrDefault("condition", "").toString(); | 
 |  |  |         BaseParam baseParam = buildParam(map, BaseParam.class); | 
 |  |  |         PageParam<Order, BaseParam> pageParam = new PageParam<>(baseParam, Order.class); | 
 |  |  | //        QueryWrapper<Order> wrapper = pageParam.buildWrapper(true); | 
 |  |  |         QueryWrapper<Order> wrapper = new QueryWrapper<>(); | 
 |  |  |  | 
 |  |  |         ArrayList<Long> types = new ArrayList<>(); | 
 |  |  |         for (OrderType orderType : orderTypeService.list(new LambdaQueryWrapper<OrderType>().eq(OrderType::getType, 1))) { | 
 |  |  |             types.add(orderType.getId()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         wrapper.in("order_type", types); | 
 |  |  |  | 
 |  |  |         if (!Cools.isEmpty(condition)) { | 
 |  |  |             wrapper.and(wrapper1 -> { | 
 |  |  |                 wrapper1.or().like("order_no", condition); | 
 |  |  |                 wrapper1.or().like("memo", condition); | 
 |  |  |             }); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Object paramObj = map.get("_param"); | 
 |  |  |         if(paramObj != null) { | 
 |  |  |             Map param = (Map) paramObj; | 
 |  |  |             for (Object value : param.entrySet()) { | 
 |  |  |                 Map.Entry entry = (Map.Entry) value; | 
 |  |  |                 String paramKey = Utils.toSymbolCase(entry.getKey().toString(), '_'); | 
 |  |  |                 if (entry.getValue() != null) { | 
 |  |  |                     wrapper.like(paramKey, entry.getValue()); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return R.ok().add(orderService.page(pageParam, wrapper)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:list')") | 
 |  |  |     @PostMapping("/order/out/page") | 
 |  |  |     public R pageOut(@RequestBody Map<String, Object> map) { | 
 |  |  |         String condition = map.getOrDefault("condition", "").toString(); | 
 |  |  |         BaseParam baseParam = buildParam(map, BaseParam.class); | 
 |  |  |         PageParam<Order, BaseParam> pageParam = new PageParam<>(baseParam, Order.class); | 
 |  |  | //        QueryWrapper<Order> wrapper = pageParam.buildWrapper(true); | 
 |  |  |         QueryWrapper<Order> wrapper = new QueryWrapper<>(); | 
 |  |  |  | 
 |  |  |         ArrayList<Long> types = new ArrayList<>(); | 
 |  |  |         for (OrderType orderType : orderTypeService.list(new LambdaQueryWrapper<OrderType>().eq(OrderType::getType, 2))) { | 
 |  |  |             types.add(orderType.getId()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         wrapper.in("order_type", types); | 
 |  |  |  | 
 |  |  |         if (map.containsKey("orderOut")) { | 
 |  |  |             wrapper.isNull("wave_id"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if (!Cools.isEmpty(condition)) { | 
 |  |  |             wrapper.and(wrapper1 -> { | 
 |  |  |                 wrapper1.or().like("order_no", condition); | 
 |  |  |                 wrapper1.or().like("memo", condition); | 
 |  |  |             }); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Object paramObj = map.get("_param"); | 
 |  |  |         if(paramObj != null) { | 
 |  |  |             Map param = (Map) paramObj; | 
 |  |  |             for (Object value : param.entrySet()) { | 
 |  |  |                 Map.Entry entry = (Map.Entry) value; | 
 |  |  |                 String paramKey = Utils.toSymbolCase(entry.getKey().toString(), '_'); | 
 |  |  |                 if (entry.getValue() != null) { | 
 |  |  |                     wrapper.like(paramKey, entry.getValue()); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return R.ok().add(orderService.page(pageParam, wrapper)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:list')") | 
 |  |  |     @PostMapping("/order/list") | 
 |  |  |     public R list(@RequestBody Map<String, Object> map) { | 
 |  |  |         return R.ok().add(orderService.list()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:list')") | 
 |  |  |     @GetMapping("/order/{id}") | 
 |  |  |     public R get(@PathVariable("id") Long id) { | 
 |  |  |         return R.ok().add(orderService.getById(id)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:save')") | 
 |  |  |     @OperationLog("添加订单") | 
 |  |  |     @PostMapping("/order/save") | 
 |  |  |     @Transactional | 
 |  |  |     public R save(@RequestBody CreateOrderParam param) { | 
 |  |  |         orderService.createOrder(param); | 
 |  |  |         return R.ok("添加成功"); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:update')") | 
 |  |  |     @OperationLog("修改订单") | 
 |  |  |     @PostMapping("/order/update") | 
 |  |  |     @Transactional | 
 |  |  |     public R update(@RequestBody UpdateOrderParam param) { | 
 |  |  |         orderService.updateOrder(param); | 
 |  |  |         return R.ok("修改成功"); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:remove')") | 
 |  |  |     @OperationLog("删除订单") | 
 |  |  |     @PostMapping("/order/remove/{ids}") | 
 |  |  |     @Transactional | 
 |  |  |     public R remove(@PathVariable Long[] ids) { | 
 |  |  |         for (Long id : ids) { | 
 |  |  |             boolean result = orderService.deleteOrder(id); | 
 |  |  |             if (!result) { | 
 |  |  |                 throw new CoolException("删除失败"); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return R.ok("删除成功"); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:list')") | 
 |  |  |     @PostMapping("/order/query") | 
 |  |  |     public R query(@RequestParam(required = false) String condition) { | 
 |  |  |         List<KeyValVo> vos = new ArrayList<>(); | 
 |  |  |         LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<>(); | 
 |  |  |         if (!Cools.isEmpty(condition)) { | 
 |  |  |             wrapper.like(Order::getOrderNo, condition); | 
 |  |  |         } | 
 |  |  |         orderService.page(new Page<>(1, 30), wrapper).getRecords().forEach( | 
 |  |  |                 item -> vos.add(new KeyValVo(item.getId(), item.getOrderNo())) | 
 |  |  |         ); | 
 |  |  |         return R.ok().add(vos); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:list')") | 
 |  |  |     @PostMapping("/order/export") | 
 |  |  |     public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { | 
 |  |  |         String ioModel = map.getOrDefault("ioModel", "").toString(); | 
 |  |  |         List<Order> list = orderService.list(); | 
 |  |  |         if (!Cools.isEmpty(ioModel)) { | 
 |  |  |             LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<>(); | 
 |  |  |             ArrayList<Long> types = new ArrayList<>(); | 
 |  |  |             for (OrderType orderType : orderTypeService.list(new LambdaQueryWrapper<OrderType>().eq(OrderType::getType, ioModel.equals("in") ? 1 : 2))) { | 
 |  |  |                 types.add(orderType.getId()); | 
 |  |  |             } | 
 |  |  |             wrapper.in(Order::getOrderType, types); | 
 |  |  |             list = orderService.list(wrapper); | 
 |  |  |         } | 
 |  |  |         ExcelUtil.build(ExcelUtil.create(list, Order.class), response); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:list')") | 
 |  |  |     @PostMapping("/order/exportTemplate") | 
 |  |  |     public void exportTemplate(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { | 
 |  |  |         ArrayList<OrderTemplate> list = new ArrayList<>(); | 
 |  |  |         List<MatField> locFields = matFieldService.getLocFields(); | 
 |  |  |         ExcelUtil.build(ExcelUtil.create(list, OrderTemplate.class, locFields), response); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PostMapping("/order/upload") | 
 |  |  |     public R upload(@RequestParam("file") MultipartFile file) { | 
 |  |  |         List<OrderTemplate> list = ExcelUtil.parseExcelFile(file, OrderTemplate.class); | 
 |  |  |  | 
 |  |  |         HashMap<String, Object> map = new HashMap<>(); | 
 |  |  |         for (OrderTemplate orderTemplate : list) { | 
 |  |  |             if (!map.containsKey(orderTemplate.getOrderNo())) { | 
 |  |  |                 OrderType orderType = orderTypeService.getOne(new LambdaQueryWrapper<OrderType>().eq(OrderType::getName, orderTemplate.getOrderType())); | 
 |  |  |                 if (orderType == null) { | 
 |  |  |                     throw new CoolException("订单类型不存在"); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 HashMap<String, Object> paramMap = new HashMap<>(); | 
 |  |  |                 ArrayList<HashMap<String, Object>> paramList = new ArrayList<>(); | 
 |  |  |                 paramList.add(paramMap); | 
 |  |  |  | 
 |  |  |                 paramMap.put("matnr", orderTemplate.getMatnr()); | 
 |  |  |                 paramMap.put("batch", orderTemplate.getBatch()); | 
 |  |  |                 paramMap.put("anfme", orderTemplate.getAnfme()); | 
 |  |  |                 paramMap.put("memo", orderTemplate.getMemo()); | 
 |  |  |                 paramMap.putAll(orderTemplate.getDynamicFields()); | 
 |  |  |  | 
 |  |  |                 CreateOrderParam orderParam = new CreateOrderParam(); | 
 |  |  |                 orderParam.setOrderNo(orderTemplate.getOrderNo()); | 
 |  |  |                 orderParam.setOrderType(orderType.getId()); | 
 |  |  |                 orderParam.setOrderSettle(OrderSettleType.INIT.val()); | 
 |  |  |                 orderParam.setList(paramList); | 
 |  |  |  | 
 |  |  |                 map.put(orderTemplate.getOrderNo(), orderParam); | 
 |  |  |             }else { | 
 |  |  |                 CreateOrderParam orderParam = (CreateOrderParam) map.get(orderTemplate.getOrderNo()); | 
 |  |  |  | 
 |  |  |                 HashMap<String, Object> paramMap = new HashMap<>(); | 
 |  |  |                 paramMap.put("matnr", orderTemplate.getMatnr()); | 
 |  |  |                 paramMap.put("batch", orderTemplate.getBatch()); | 
 |  |  |                 paramMap.put("anfme", orderTemplate.getAnfme()); | 
 |  |  |                 paramMap.put("memo", orderTemplate.getMemo()); | 
 |  |  |                 paramMap.putAll(orderTemplate.getDynamicFields()); | 
 |  |  |  | 
 |  |  |                 List<HashMap<String, Object>> paramList = orderParam.getList(); | 
 |  |  |                 paramList.add(paramMap); | 
 |  |  |  | 
 |  |  |                 orderParam.setList(paramList); | 
 |  |  |                 map.put(orderTemplate.getOrderNo(), orderParam); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         ArrayList<CreateOrderParam> orderParams = new ArrayList<>(); | 
 |  |  |         for (Map.Entry<String, Object> entry : map.entrySet()) { | 
 |  |  |             CreateOrderParam orderParam = (CreateOrderParam) entry.getValue(); | 
 |  |  |             orderParams.add(orderParam); | 
 |  |  |         } | 
 |  |  |         orderService.createOrder(orderParams); | 
 |  |  |         return R.ok(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } | 
 |  |  | package com.zy.asrs.wms.asrs.controller;
 | 
 |  |  | 
 | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 | 
 |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
 |  |  | import com.zy.asrs.framework.common.Cools;
 | 
 |  |  | import com.zy.asrs.framework.common.R;
 | 
 |  |  | import com.zy.asrs.framework.exception.CoolException;
 | 
 |  |  | import com.zy.asrs.wms.asrs.entity.*;
 | 
 |  |  | import com.zy.asrs.wms.asrs.entity.enums.OrderSettleType;
 | 
 |  |  | import com.zy.asrs.wms.asrs.entity.param.CreateOrderParam;
 | 
 |  |  | import com.zy.asrs.wms.asrs.entity.param.UpdateOrderParam;
 | 
 |  |  | import com.zy.asrs.wms.asrs.entity.template.OrderTemplate;
 | 
 |  |  | import com.zy.asrs.wms.asrs.service.*;
 | 
 |  |  | import com.zy.asrs.wms.asrs.service.impl.OrderDetlServiceImpl;
 | 
 |  |  | import com.zy.asrs.wms.common.annotation.CacheData;
 | 
 |  |  | import com.zy.asrs.wms.common.annotation.OperationLog;
 | 
 |  |  | import com.zy.asrs.wms.common.domain.BaseParam;
 | 
 |  |  | import com.zy.asrs.wms.common.domain.KeyValVo;
 | 
 |  |  | import com.zy.asrs.wms.common.domain.PageParam;
 | 
 |  |  | import com.zy.asrs.wms.system.controller.BaseController;
 | 
 |  |  | import com.zy.asrs.wms.utils.ExcelUtil;
 | 
 |  |  | import com.zy.asrs.wms.utils.Utils;
 | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
 |  |  | import org.springframework.security.access.prepost.PreAuthorize;
 | 
 |  |  | import org.springframework.transaction.annotation.Transactional;
 | 
 |  |  | import org.springframework.web.bind.annotation.*;
 | 
 |  |  | import org.springframework.web.multipart.MultipartFile;
 | 
 |  |  | 
 | 
 |  |  | import javax.servlet.http.HttpServletResponse;
 | 
 |  |  | import java.util.*;
 | 
 |  |  | 
 | 
 |  |  | @RestController
 | 
 |  |  | @RequestMapping("/api")
 | 
 |  |  | public class OrderController extends BaseController {
 | 
 |  |  | 
 | 
 |  |  |     @Autowired
 | 
 |  |  |     private OrderService orderService;
 | 
 |  |  |     @Autowired
 | 
 |  |  |     private OrderTypeService orderTypeService;
 | 
 |  |  |     @Autowired
 | 
 |  |  |     private MatFieldService matFieldService;
 | 
 |  |  |     @Autowired
 | 
 |  |  |     private OrderDetlServiceImpl orderDetlService;
 | 
 |  |  |     @Autowired
 | 
 |  |  |     private CacheSiteService cacheSiteService;
 | 
 |  |  |     @Autowired
 | 
 |  |  |     private WaveService waveService;
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:list')")
 | 
 |  |  |     @PostMapping("/order/page")
 | 
 |  |  |     @CacheData(tableName = {"man_order"})
 | 
 |  |  |     public R page(@RequestBody Map<String, Object> map) {
 | 
 |  |  |         BaseParam baseParam = buildParam(map, BaseParam.class);
 | 
 |  |  |         PageParam<Order, BaseParam> pageParam = new PageParam<>(baseParam, Order.class);
 | 
 |  |  |         return R.ok().add(orderService.page(pageParam, pageParam.buildWrapper(true)));
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:list')")
 | 
 |  |  |     @PostMapping("/order/in/page")
 | 
 |  |  | //    @CacheData(tableName = {"man_order", "man_order_type"})
 | 
 |  |  |     public R pageIn(@RequestBody Map<String, Object> map) {
 | 
 |  |  |         String condition = map.getOrDefault("condition", "").toString();
 | 
 |  |  |         BaseParam baseParam = buildParam(map, BaseParam.class);
 | 
 |  |  |         PageParam<Order, BaseParam> pageParam = new PageParam<>(baseParam, Order.class);
 | 
 |  |  | //        QueryWrapper<Order> wrapper = pageParam.buildWrapper(true);
 | 
 |  |  |         QueryWrapper<Order> wrapper = new QueryWrapper<>();
 | 
 |  |  | 
 | 
 |  |  |         ArrayList<Long> types = new ArrayList<>();
 | 
 |  |  |         for (OrderType orderType : orderTypeService.list(new LambdaQueryWrapper<OrderType>().in(OrderType::getType, 1))) {
 | 
 |  |  |             types.add(orderType.getId());
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  |         wrapper.in("order_type", types).eq("deleted", 0);
 | 
 |  |  | 
 | 
 |  |  |         if (!Cools.isEmpty(condition)) {
 | 
 |  |  |             wrapper.and(wrapper1 -> {
 | 
 |  |  |                 wrapper1.or().like("order_no", condition);
 | 
 |  |  |                 wrapper1.or().like("memo", condition);
 | 
 |  |  |             });
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  |         Object paramObj = map.get("_param");
 | 
 |  |  |         if (paramObj != null) {
 | 
 |  |  |             Map param = (Map) paramObj;
 | 
 |  |  |             for (Object value : param.entrySet()) {
 | 
 |  |  |                 Map.Entry entry = (Map.Entry) value;
 | 
 |  |  |                 String paramKey = Utils.toSymbolCase(entry.getKey().toString(), '_');
 | 
 |  |  |                 if (entry.getValue() != null) {
 | 
 |  |  |                     wrapper.like(paramKey, entry.getValue());
 | 
 |  |  |                 }
 | 
 |  |  |             }
 | 
 |  |  |         }
 | 
 |  |  |         wrapper.orderByDesc("create_time");
 | 
 |  |  | 
 | 
 |  |  |         return R.ok().add(orderService.page(pageParam, wrapper));
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:list')")
 | 
 |  |  |     @PostMapping("/order/out/page")
 | 
 |  |  | //    @CacheData(tableName = {"man_order", "man_order_type"})
 | 
 |  |  |     public R pageOut(@RequestBody Map<String, Object> map) {
 | 
 |  |  |         String condition = map.getOrDefault("condition", "").toString();
 | 
 |  |  |         BaseParam baseParam = buildParam(map, BaseParam.class);
 | 
 |  |  |         PageParam<Order, BaseParam> pageParam = new PageParam<>(baseParam, Order.class);
 | 
 |  |  | //        QueryWrapper<Order> wrapper = pageParam.buildWrapper(true);
 | 
 |  |  |         QueryWrapper<Order> wrapper = new QueryWrapper<>();
 | 
 |  |  | 
 | 
 |  |  |         ArrayList<Long> types = new ArrayList<>();
 | 
 |  |  |         for (OrderType orderType : orderTypeService.list(new LambdaQueryWrapper<OrderType>().eq(OrderType::getType, 2))) {
 | 
 |  |  |             types.add(orderType.getId());
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  |         wrapper.in("order_type", types);
 | 
 |  |  | 
 | 
 |  |  |         if (map.containsKey("orderOut")) {
 | 
 |  |  |             wrapper.isNull("wave_id");
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  |         if (!Cools.isEmpty(condition)) {
 | 
 |  |  |             wrapper.and(wrapper1 -> {
 | 
 |  |  |                 wrapper1.or().like("order_no", condition);
 | 
 |  |  |                 wrapper1.or().like("memo", condition);
 | 
 |  |  |             });
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  |         Object paramObj = map.get("_param");
 | 
 |  |  |         if(paramObj != null) {
 | 
 |  |  |             Map param = (Map) paramObj;
 | 
 |  |  |             for (Object value : param.entrySet()) {
 | 
 |  |  |                 Map.Entry entry = (Map.Entry) value;
 | 
 |  |  |                 String paramKey = Utils.toSymbolCase(entry.getKey().toString(), '_');
 | 
 |  |  |                 if (entry.getValue() != null) {
 | 
 |  |  |                     wrapper.like(paramKey, entry.getValue());
 | 
 |  |  |                 }
 | 
 |  |  |             }
 | 
 |  |  |         }
 | 
 |  |  |         wrapper.orderByDesc("create_time");
 | 
 |  |  |         return R.ok().add(orderService.page(pageParam, wrapper));
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:list')")
 | 
 |  |  |     @PostMapping("/order/list")
 | 
 |  |  | //    @CacheData(tableName = {"man_order"})
 | 
 |  |  |     public R list(@RequestBody Map<String, Object> map) {
 | 
 |  |  |         return R.ok().add(orderService.list());
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:list')")
 | 
 |  |  |     @GetMapping("/order/{id}")
 | 
 |  |  | //    @CacheData(tableName = {"man_order"})
 | 
 |  |  |     public R get(@PathVariable("id") Long id) {
 | 
 |  |  |         Order order = orderService.getById(id);
 | 
 |  |  |         List<OrderDetl> detls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>().eq(OrderDetl::getOrderId, order.getId()));
 | 
 |  |  |         if (!detls.isEmpty()) {
 | 
 |  |  |             Double sum = detls.stream().mapToDouble(OrderDetl::getAnfme).sum();
 | 
 |  |  |             order.setWaitQty(sum);
 | 
 |  |  |         }
 | 
 |  |  |         if (!Objects.isNull(order.getWaveId())) {
 | 
 |  |  |             Wave wave = waveService.getById(order.getWaveId());
 | 
 |  |  |             if (!Objects.isNull(wave)) {
 | 
 |  |  |                 order.setSite(wave.getSite());
 | 
 |  |  |             }
 | 
 |  |  |         }
 | 
 |  |  |         return R.ok().add(order);
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:save')")
 | 
 |  |  |     @OperationLog("添加订单")
 | 
 |  |  |     @PostMapping("/order/save")
 | 
 |  |  |     @Transactional
 | 
 |  |  |     public R save(@RequestBody CreateOrderParam param) {
 | 
 |  |  |         orderService.createOrder(param);
 | 
 |  |  |         return R.ok("添加成功");
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:update')")
 | 
 |  |  |     @OperationLog("修改订单")
 | 
 |  |  |     @PostMapping("/order/update")
 | 
 |  |  |     @Transactional
 | 
 |  |  |     public R update(@RequestBody UpdateOrderParam param) {
 | 
 |  |  |         orderService.updateOrder(param);
 | 
 |  |  |         return R.ok("修改成功");
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:remove')")
 | 
 |  |  |     @OperationLog("删除订单")
 | 
 |  |  |     @PostMapping("/order/remove/{ids}")
 | 
 |  |  |     @Transactional
 | 
 |  |  |     public R remove(@PathVariable Long[] ids) {
 | 
 |  |  |         for (Long id : ids) {
 | 
 |  |  |             boolean result = orderService.deleteOrder(id);
 | 
 |  |  |             if (!result) {
 | 
 |  |  |                 throw new CoolException("删除失败");
 | 
 |  |  |             }
 | 
 |  |  |         }
 | 
 |  |  |         return R.ok("删除成功");
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:list')")
 | 
 |  |  |     @PostMapping("/order/query")
 | 
 |  |  |     public R query(@RequestParam(required = false) String condition) {
 | 
 |  |  |         List<KeyValVo> vos = new ArrayList<>();
 | 
 |  |  |         LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<>();
 | 
 |  |  |         if (!Cools.isEmpty(condition)) {
 | 
 |  |  |             wrapper.like(Order::getOrderNo, condition);
 | 
 |  |  |         }
 | 
 |  |  |         orderService.page(new Page<>(1, 30), wrapper).getRecords().forEach(
 | 
 |  |  |                 item -> vos.add(new KeyValVo(item.getId(), item.getOrderNo()))
 | 
 |  |  |         );
 | 
 |  |  |         return R.ok().add(vos);
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:list')")
 | 
 |  |  |     @PostMapping("/order/export")
 | 
 |  |  |     public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
 | 
 |  |  |         String ioModel = map.getOrDefault("ioModel", "").toString();
 | 
 |  |  |         map.remove("ioModel");
 | 
 |  |  | 
 | 
 |  |  |         BaseParam baseParam = buildParam(map, BaseParam.class);
 | 
 |  |  |         PageParam<Order, BaseParam> pageParam = new PageParam<>(baseParam, Order.class);
 | 
 |  |  |         QueryWrapper<Order> queryWrapper = pageParam.buildWrapper(true);
 | 
 |  |  | 
 | 
 |  |  |         List<Order> list = orderService.list(queryWrapper);
 | 
 |  |  |         if (!Cools.isEmpty(ioModel)) {
 | 
 |  |  |             ArrayList<Long> types = new ArrayList<>();
 | 
 |  |  |             for (OrderType orderType : orderTypeService.list(new LambdaQueryWrapper<OrderType>().eq(OrderType::getType, ioModel.equals("in") ? 1 : 2))) {
 | 
 |  |  |                 types.add(orderType.getId());
 | 
 |  |  |             }
 | 
 |  |  |             queryWrapper.in("order_type", types);
 | 
 |  |  |             list = orderService.list(queryWrapper);
 | 
 |  |  |         }
 | 
 |  |  |         ExcelUtil.build(ExcelUtil.create(list, Order.class), response);
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PreAuthorize("hasAuthority('asrs:order:list')")
 | 
 |  |  |     @PostMapping("/order/exportTemplate")
 | 
 |  |  |     public void exportTemplate(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
 | 
 |  |  |         ArrayList<OrderTemplate> list = new ArrayList<>();
 | 
 |  |  |         List<MatField> locFields = matFieldService.getLocFields();
 | 
 |  |  |         ExcelUtil.build(ExcelUtil.create(list, OrderTemplate.class, locFields), response);
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  |     @PostMapping("/order/upload")
 | 
 |  |  |     public R upload(@RequestParam("file") MultipartFile file) {
 | 
 |  |  |         List<OrderTemplate> list = ExcelUtil.parseExcelFile(file, OrderTemplate.class);
 | 
 |  |  | 
 | 
 |  |  |         HashMap<String, Object> map = new HashMap<>();
 | 
 |  |  |         for (OrderTemplate orderTemplate : list) {
 | 
 |  |  |             if (!map.containsKey(orderTemplate.getOrderNo())) {
 | 
 |  |  |                 OrderType orderType = orderTypeService.getOne(new LambdaQueryWrapper<OrderType>().eq(OrderType::getName, orderTemplate.getOrderType()));
 | 
 |  |  |                 if (orderType == null) {
 | 
 |  |  |                     throw new CoolException("订单类型不存在");
 | 
 |  |  |                 }
 | 
 |  |  | 
 | 
 |  |  |                 HashMap<String, Object> paramMap = new HashMap<>();
 | 
 |  |  |                 ArrayList<HashMap<String, Object>> paramList = new ArrayList<>();
 | 
 |  |  |                 paramList.add(paramMap);
 | 
 |  |  | 
 | 
 |  |  |                 paramMap.put("matnr", orderTemplate.getMatnr());
 | 
 |  |  |                 paramMap.put("batch", orderTemplate.getBatch());
 | 
 |  |  |                 paramMap.put("anfme", orderTemplate.getAnfme());
 | 
 |  |  |                 paramMap.put("memo", orderTemplate.getMemo());
 | 
 |  |  |                 paramMap.putAll(orderTemplate.getDynamicFields());
 | 
 |  |  | 
 | 
 |  |  |                 CreateOrderParam orderParam = new CreateOrderParam();
 | 
 |  |  |                 orderParam.setOrderNo(orderTemplate.getOrderNo());
 | 
 |  |  |                 orderParam.setOrderType(orderType.getId());
 | 
 |  |  |                 orderParam.setOrderSettle(OrderSettleType.INIT.val());
 | 
 |  |  |                 orderParam.setList(paramList);
 | 
 |  |  | 
 | 
 |  |  |                 map.put(orderTemplate.getOrderNo(), orderParam);
 | 
 |  |  |             }else {
 | 
 |  |  |                 CreateOrderParam orderParam = (CreateOrderParam) map.get(orderTemplate.getOrderNo());
 | 
 |  |  | 
 | 
 |  |  |                 HashMap<String, Object> paramMap = new HashMap<>();
 | 
 |  |  |                 paramMap.put("matnr", orderTemplate.getMatnr());
 | 
 |  |  |                 paramMap.put("batch", orderTemplate.getBatch());
 | 
 |  |  |                 paramMap.put("anfme", orderTemplate.getAnfme());
 | 
 |  |  |                 paramMap.put("memo", orderTemplate.getMemo());
 | 
 |  |  |                 paramMap.putAll(orderTemplate.getDynamicFields());
 | 
 |  |  | 
 | 
 |  |  |                 List<HashMap<String, Object>> paramList = orderParam.getList();
 | 
 |  |  |                 paramList.add(paramMap);
 | 
 |  |  | 
 | 
 |  |  |                 orderParam.setList(paramList);
 | 
 |  |  |                 map.put(orderTemplate.getOrderNo(), orderParam);
 | 
 |  |  |             }
 | 
 |  |  |         }
 | 
 |  |  | 
 | 
 |  |  |         ArrayList<CreateOrderParam> orderParams = new ArrayList<>();
 | 
 |  |  |         for (Map.Entry<String, Object> entry : map.entrySet()) {
 | 
 |  |  |             CreateOrderParam orderParam = (CreateOrderParam) entry.getValue();
 | 
 |  |  |             orderParams.add(orderParam);
 | 
 |  |  |         }
 | 
 |  |  |         orderService.createOrder(orderParams);
 | 
 |  |  |         return R.ok();
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  | }
 |