| | |
| | | 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.template.WaitPakinTemplate; |
| | | import com.zy.asrs.wms.asrs.service.*; |
| | | import com.zy.asrs.wms.common.annotation.OperationLog; |
| | | import com.zy.asrs.wms.common.domain.BaseParam; |
| | |
| | | import com.zy.asrs.wms.utils.ExcelUtil; |
| | | 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.*; |
| | |
| | | private OrderService orderService; |
| | | @Autowired |
| | | private OrderDetlService orderDetlService; |
| | | @Autowired |
| | | private LocService locService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:waitPakin:list')") |
| | | @PostMapping("/waitPakin/page") |
| | |
| | | return R.ok().add(waitPakinService.getById(id)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:waitPakin:list')") |
| | | @GetMapping("/waitPakin/orderDetlId/{orderDetlId}") |
| | | public R getByOrderDetlId(@PathVariable("orderDetlId") Long orderDetlId) { |
| | | return R.ok().add(waitPakinService.getByOrderDetlId(orderDetlId)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:waitPakin:save')") |
| | | @OperationLog("添加组托通知档") |
| | | @PostMapping("/waitPakin/save") |
| | | @Transactional |
| | | public R save(@RequestBody WaitPakin waitPakin) { |
| | | if (waitPakin.getAnfme() <= 0) { |
| | | return R.error("组托数量错误"); |
| | | } |
| | | |
| | | List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, waitPakin.getBarcode())); |
| | | if (!locList.isEmpty()) { |
| | | return R.error("托盘已在库"); |
| | | } |
| | | |
| | | List<Task> taskList = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getBarcode, waitPakin.getBarcode())); |
| | | if (!taskList.isEmpty()) { |
| | | return R.error("托盘正在入库中"); |
| | | } |
| | | |
| | | if (!waitPakinService.save(waitPakin)) { |
| | | return R.error("添加失败"); |
| | | } |
| | | |
| | | OrderDetl orderDetl = orderDetlService.getById(waitPakin.getDetlId()); |
| | | if (orderDetl == null) { |
| | | throw new CoolException("订单明细不存在"); |
| | | } |
| | | |
| | | //获取订单 |
| | | Order order = orderService.getById(orderDetl.getOrderId()); |
| | | if(order == null){ |
| | | throw new CoolException("订单不存在"); |
| | | } |
| | | |
| | | //更新订单状态 |
| | | if (order.getOrderSettle().equals(OrderSettleType.INIT.val())) { |
| | | order.setOrderSettle(OrderSettleType.WAIT.val()); |
| | | order.setUpdateTime(new Date()); |
| | | if (!orderService.updateById(order)) { |
| | | throw new CoolException("订单数据更新失败"); |
| | | } |
| | | try { |
| | | waitPakinService.comb(waitPakin); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return R.error(e.getMessage()); |
| | | } |
| | | return R.ok("添加成功"); |
| | | } |
| | |
| | | ExcelUtil.build(ExcelUtil.create(waitPakinService.list(), WaitPakin.class), response); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('asrs:waitPakin:list')") |
| | | @PostMapping("/waitPakin/exportTemplate") |
| | | public void exportTemplate(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ArrayList<WaitPakinTemplate> list = new ArrayList<>(); |
| | | ExcelUtil.build(ExcelUtil.create(list, WaitPakinTemplate.class), response); |
| | | } |
| | | |
| | | @PostMapping("/waitPakin/upload") |
| | | public R upload(@RequestParam("file") MultipartFile file) { |
| | | List<WaitPakinTemplate> list = ExcelUtil.parseExcelFile(file, WaitPakinTemplate.class); |
| | | for (WaitPakinTemplate waitPakinTemplate : list) { |
| | | Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNo, waitPakinTemplate.getOrderNo()).eq(Order::getStatus, 1)); |
| | | if (order == null) { |
| | | throw new CoolException("订单不存在"); |
| | | } |
| | | |
| | | LambdaQueryWrapper<OrderDetl> wrapper = new LambdaQueryWrapper<OrderDetl>().eq(OrderDetl::getOrderId, order.getId()); |
| | | if (!Cools.isEmpty(waitPakinTemplate.getBatch())) { |
| | | wrapper.eq(OrderDetl::getBatch, waitPakinTemplate.getBatch()); |
| | | } |
| | | List<OrderDetl> orderDetls = orderDetlService.list(wrapper); |
| | | if (orderDetls.isEmpty()) { |
| | | throw new CoolException("订单明细不存在"); |
| | | } |
| | | |
| | | Long detlId = null; |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | Mat mat = orderDetl.getMat$(); |
| | | if (mat.getMatnr().equals(waitPakinTemplate.getMatnr())) { |
| | | detlId = orderDetl.getId(); |
| | | } |
| | | } |
| | | |
| | | if (detlId == null) { |
| | | throw new CoolException("订单明细不存在"); |
| | | } |
| | | |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | waitPakin.setOrderId(order.getId()); |
| | | waitPakin.setOrderNo(order.getOrderNo()); |
| | | waitPakin.setAnfme(waitPakinTemplate.getAnfme()); |
| | | waitPakin.setBarcode(waitPakinTemplate.getBarcode()); |
| | | waitPakin.setDetlId(detlId); |
| | | waitPakinService.comb(waitPakin); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | } |