| | |
| | | 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 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.*; |
| | |
| | | private OrderService orderService; |
| | | @Autowired |
| | | private OrderTypeService orderTypeService; |
| | | @Autowired |
| | | private MatFieldService matFieldService; |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:order:list')") |
| | | @PostMapping("/order/page") |
| | |
| | | List<KeyValVo> vos = new ArrayList<>(); |
| | | LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<>(); |
| | | if (!Cools.isEmpty(condition)) { |
| | | wrapper.like(Order::getId, condition); |
| | | wrapper.like(Order::getOrderNo, condition); |
| | | } |
| | | orderService.page(new Page<>(1, 30), wrapper).getRecords().forEach( |
| | | item -> vos.add(new KeyValVo(item.getId(), item.getId())) |
| | | 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 { |
| | | ExcelUtil.build(ExcelUtil.create(orderService.list(), Order.class), response); |
| | | 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(); |
| | | } |
| | | |
| | | } |