| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.OrderDomainParam; |
| | | |
| | | import com.zy.asrs.entity.result.WrkTraceVo; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.MatExcelListener; |
| | | import com.zy.asrs.utils.OrderExcelListener; |
| | | import com.zy.common.entity.MatExcel; |
| | | import com.zy.common.entity.OrderExcel; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.common.web.BaseController; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | @RestController |
| | | public class OrderController extends BaseController { |
| | |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private WaitPakinService waitPakinService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private WrkMastLogService wrkMastLogService; |
| | | |
| | | @RequestMapping(value = "/order/nav/list/auth") |
| | | @ManagerAuth |
| | |
| | | @ManagerAuth(memo = "手动添加订单") |
| | | @Transactional |
| | | public R formAdd(@RequestBody OrderDomainParam param){ |
| | | int status = 0; |
| | | if(Cools.isEmpty(param.getOrderNo())){ |
| | | String prefix = ""; |
| | | DocType docType = docTypeService.selectById(param.getDocType()); |
| | | if(!Cools.isEmpty(docType)){ |
| | | prefix = docType.getPakin() == 1 ? "RK" : "CK"; |
| | | status = (prefix.equals("RK") ? 1 : (prefix.equals("CK") ? 2 : 0)); |
| | | } |
| | | param.setOrderNo(prefix + snowflakeIdWorker.nextId()); |
| | | } else { |
| | | DocType docType = docTypeService.selectById(param.getDocType()); |
| | | if(!Cools.isEmpty(docType)){ |
| | | status = (docType.getPakin() == 1 ? 1 : 2 ); |
| | | } |
| | | } |
| | | |
| | | Order order = orderService.selectByNo(param.getOrderNo()); |
| | | if (order != null) { |
| | | return R.error("单据编号已存在"); |
| | |
| | | now, // 添加时间 |
| | | getUserId(), // 修改人员 |
| | | now, // 修改时间 |
| | | null // 备注 |
| | | null, // 备注 |
| | | status |
| | | ); |
| | | if (!orderService.insert(order)) { |
| | | throw new CoolException("保存订单主档失败"); |
| | | } |
| | | List<DetlDto> list = new ArrayList<>(); |
| | | for (OrderDetl orderDetl : param.getOrderDetlList()) { |
| | | DetlDto dto = new DetlDto(orderDetl.getMatnr(), orderDetl.getBatch()); |
| | | DetlDto dto = new DetlDto(orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getBrand(), |
| | | orderDetl.getStandby1(),orderDetl.getStandby2(),orderDetl.getStandby3(), |
| | | orderDetl.getBoxType1(),orderDetl.getBoxType2(),orderDetl.getBoxType3()); |
| | | if (DetlDto.has(list, dto)) { |
| | | OrderDetl item = orderDetlService.selectItem(order.getId(), orderDetl.getMatnr(), orderDetl.getBatch()); |
| | | OrderDetl item = orderDetlService.selectItem(order.getId(), orderDetl.getMatnr(), orderDetl.getBatch(),orderDetl.getBrand(),orderDetl.getStandby1(),orderDetl.getStandby2(),orderDetl.getStandby3(), |
| | | orderDetl.getBoxType1(),orderDetl.getBoxType2(),orderDetl.getBoxType3()); |
| | | item.setAnfme(item.getAnfme() + orderDetl.getAnfme()); |
| | | if (!orderDetlService.updateById(item)) { |
| | | throw new CoolException("保存订单明细档失败"); |
| | |
| | | orderDetl.setUpdateTime(now); |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | orderDetl.setPakinPakoutStatus(status); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | throw new CoolException("保存订单明细档失败"); |
| | | } |
| | |
| | | // 2.重组数据 |
| | | List<DetlDto> list = new ArrayList<>(); |
| | | for (OrderDetl orderDetl : param.getOrderDetlList()) { |
| | | DetlDto dto = new DetlDto(orderDetl.getMatnr(), orderDetl.getBatch()); |
| | | DetlDto dto = new DetlDto(orderDetl.getMatnr(), orderDetl.getBatch(),orderDetl.getBrand(), |
| | | orderDetl.getStandby1(),orderDetl.getStandby2(),orderDetl.getStandby3(), |
| | | orderDetl.getBoxType1(),orderDetl.getBoxType2(),orderDetl.getBoxType3()); |
| | | if (DetlDto.has(list, dto)) { |
| | | OrderDetl item = orderDetlService.selectItem(order.getId(), orderDetl.getMatnr(), orderDetl.getBatch()); |
| | | OrderDetl item = orderDetlService.selectItem(order.getId(), orderDetl.getMatnr(), orderDetl.getBatch(),orderDetl.getBrand(), |
| | | orderDetl.getStandby1(),orderDetl.getStandby2(),orderDetl.getStandby3(), |
| | | orderDetl.getBoxType1(),orderDetl.getBoxType2(),orderDetl.getBoxType3()); |
| | | item.setAnfme(item.getAnfme() + orderDetl.getAnfme()); |
| | | if (!orderDetlService.updateById(item)) { |
| | | throw new CoolException("保存订单明细档失败"); |
| | |
| | | } |
| | | } |
| | | return R.ok("订单修改成功"); |
| | | } |
| | | |
| | | @PostMapping(value = "/order/wrk/trace/auth") |
| | | @ManagerAuth |
| | | public R orderWrkTrace(@RequestParam("orderId") Long orderId) { |
| | | Order order = orderService.selectById(orderId); |
| | | if (null == order) { |
| | | return R.error("单据不存在"); |
| | | } |
| | | // 数量统计 |
| | | List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(orderId); |
| | | double totalQty = 0; |
| | | double wrkQty = 0; |
| | | double lackQty = 0; |
| | | double endQty = 0; |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | totalQty = totalQty + orderDetl.getAnfme(); |
| | | wrkQty = wrkQty + orderDetl.getWorkQty(); |
| | | endQty = endQty + orderDetl.getQty(); |
| | | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getWorkQty()).orElse(0.0D); |
| | | if (issued > 0.0) { |
| | | List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getOrigin(), null); |
| | | for (LocDetl locDetl : locDetls) { |
| | | if (issued > 0) { |
| | | issued = issued - locDetl.getAnfme(); |
| | | } else { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (issued > 0.0) { |
| | | lackQty = lackQty + issued; |
| | | } |
| | | } |
| | | // 任务追溯 |
| | | List<WrkTraceVo> wrkTraceVos = new ArrayList<>(); |
| | | List<WrkDetl> wrkDetls = wrkDetlService.selectAndLogByOrderNoGroupByMatnrOfSum(order.getOrderNo()); |
| | | for (WrkDetl wrkDetl : wrkDetls) { |
| | | WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", wrkDetl.getWrkNo()).eq("io_time", wrkDetl.getIoTime())); |
| | | if (wrkMast == null) { |
| | | WrkMastLog wrkMastLog = wrkMastLogService.selectOne(new EntityWrapper<WrkMastLog>().eq("wrk_no", wrkDetl.getWrkNo()).eq("io_time", wrkDetl.getIoTime())); |
| | | if (wrkMastLog.getIoType()==103){ |
| | | wrkMastLog = wrkMastLogService.selectOne(new EntityWrapper<WrkMastLog>().eq("wrk_no", wrkDetl.getWrkNo()).eq("io_time", wrkDetl.getIoTime()).eq("io_type",53)); |
| | | } |
| | | if (wrkMastLog != null) { |
| | | wrkMast = new WrkMast(); |
| | | BeanUtils.copyProperties(wrkMastLog, wrkMast); |
| | | } else { |
| | | continue; |
| | | } |
| | | } |
| | | boolean exist = false; |
| | | for (WrkTraceVo vo : wrkTraceVos) { |
| | | if (vo.getWrkNo().equals(wrkMast.getWrkNo()) && vo.getIoTimeStr().equals(DateUtils.convert(wrkMast.getIoTime()))) { |
| | | vo.getWrkDetls().add(wrkDetl); |
| | | exist = true; |
| | | } |
| | | } |
| | | if (!exist) { |
| | | WrkTraceVo vo = new WrkTraceVo(wrkMast.getWrkNo(), DateUtils.convert(wrkMast.getIoTime()), wrkMast, wrkDetl); |
| | | wrkTraceVos.add(vo); |
| | | } |
| | | } |
| | | if (!Cools.isEmpty(wrkTraceVos) && wrkTraceVos.size() > 1) { |
| | | wrkTraceVos.sort((o1, o2) -> (int) (o2.getWrkMast().getIoTime().getTime() - o1.getWrkMast().getIoTime().getTime())); |
| | | } |
| | | return R.ok().add(Cools |
| | | .add("list", wrkTraceVos) |
| | | .add("orderNo", order.getOrderNo()) |
| | | .add("totalQty", totalQty) |
| | | .add("wrkQty", wrkQty+endQty) |
| | | .add("lackQty", lackQty) |
| | | .add("endQty",endQty) |
| | | ); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * excel导入模板下载 |
| | | */ |
| | | @RequestMapping(value = "/orders/excel/import/mould") |
| | | public void matExcelImportMould(HttpServletResponse response) throws IOException { |
| | | List<OrderExcel> excels = new ArrayList<>(); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | String fileName = URLEncoder.encode("单据Excel导入模板", "UTF-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | EasyExcel.write(response.getOutputStream(), OrderExcel.class) |
| | | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) |
| | | .sheet("sheet1") |
| | | .doWrite(excels); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 单据导入 |
| | | * @author Ryan |
| | | * @date 2026/1/8 17:17 |
| | | * @param file |
| | | * @return com.core.common.R |
| | | */ |
| | | @PostMapping(value = "/orders/excel/import/auth") |
| | | @ManagerAuth(memo = "单据导入") |
| | | @Transactional |
| | | public R matExcelImport(MultipartFile file) throws IOException { |
| | | OrderExcelListener listener = new OrderExcelListener(getUserId()); |
| | | EasyExcel.read(file.getInputStream(), OrderExcel.class, listener).sheet().doRead(); |
| | | return R.ok("成功同步" + listener.getTotal() + "条商品数据"); |
| | | } |
| | | |
| | | |
| | | @RequestMapping(value = "/order/update/auth") |
| | | @ManagerAuth |
| | | public R update(Order order){ |