|  |  |  | 
|---|
|  |  |  | import com.core.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.core.common.*; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.entity.DocType; | 
|---|
|  |  |  | import com.zy.asrs.entity.Order; | 
|---|
|  |  |  | import com.zy.asrs.entity.OrderDetl; | 
|---|
|  |  |  | import com.zy.asrs.entity.*; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.OrderDomainParam; | 
|---|
|  |  |  | import com.zy.asrs.service.DocTypeService; | 
|---|
|  |  |  | import com.zy.asrs.service.OrderDetlService; | 
|---|
|  |  |  | import com.zy.asrs.service.OrderService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.zy.asrs.entity.result.WrkTraceVo; | 
|---|
|  |  |  | import com.zy.asrs.service.*; | 
|---|
|  |  |  | import com.zy.asrs.utils.FileSaveExampleUtil; | 
|---|
|  |  |  | 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.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | private SnowflakeIdWorker snowflakeIdWorker; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DocTypeService docTypeService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R formAdd(@RequestBody OrderDomainParam param){ | 
|---|
|  |  |  | if(Cools.isEmpty(param.getOrderNo())){ | 
|---|
|  |  |  | param.setOrderNo("HAND" + snowflakeIdWorker.nextId()); | 
|---|
|  |  |  | String prefix = ""; | 
|---|
|  |  |  | DocType docType = docTypeService.selectById(param.getDocType()); | 
|---|
|  |  |  | if(!Cools.isEmpty(docType)){ | 
|---|
|  |  |  | prefix = docType.getPakin() == 1 ? "RK" : "CK"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | param.setOrderNo(prefix + snowflakeIdWorker.nextId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Order order = orderService.selectByNo(param.getOrderNo()); | 
|---|
|  |  |  | if (order != null) { | 
|---|
|  |  |  | 
|---|
|  |  |  | 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) | 
|---|
|  |  |  | .add("lackQty", lackQty) | 
|---|
|  |  |  | .add("endQty",endQty) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // ------------------------------------------------------------------------------------------------ | 
|---|
|  |  |  | 
|---|
|  |  |  | if (Cools.isEmpty(order) || null == order.getId()){ | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //订单完结前,判断是否存在作业中数据,存在则不能完结 | 
|---|
|  |  |  | if(order.getSettle() == 4){ | 
|---|
|  |  |  | int wrkCount = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("order_no",order.getOrderNo())); | 
|---|
|  |  |  | int pakinCount = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("order_no",order.getOrderNo())); | 
|---|
|  |  |  | if (wrkCount > 0 || pakinCount > 0) { | 
|---|
|  |  |  | throw new CoolException("存在作业中数据,不能完结。请检查入库通知档和工作档"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | order.setUpdateBy(getUserId()); | 
|---|
|  |  |  | order.setUpdateTime(new Date()); | 
|---|
|  |  |  | if (!orderService.updateById(order)) { | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/order/insert/labelUp/file/auth") | 
|---|
|  |  |  | //    @ManagerAuth | 
|---|
|  |  |  | public R insertLabelUpFile(@RequestParam("orderId") String orderId,@RequestParam MultipartFile file){ | 
|---|
|  |  |  | String[] split = orderId.split("-"); | 
|---|
|  |  |  | int id = Integer.parseInt(split[1]); | 
|---|
|  |  |  | System.out.println("---开始---"); | 
|---|
|  |  |  | String savePath = "D:/order/labelUp/file/"+id+"/"; // 指定保存文件的路径 | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | FileSaveExampleUtil.saveFile(file, savePath); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/order/view/labelUp/file/auth") | 
|---|
|  |  |  | //    @ManagerAuth | 
|---|
|  |  |  | public R viewLabelUpFile(@RequestParam("orderId") Long orderId){ | 
|---|
|  |  |  | //        int id = Integer.parseInt(orderId); | 
|---|
|  |  |  | String savePath = "D:/order/labelUp/file/"+orderId+"/"; // 指定保存文件的路径 | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | List<FileSaveExampleUtil.FileDTO> fileDTOS = FileSaveExampleUtil.viewFileList(savePath); | 
|---|
|  |  |  | return R.ok(fileDTOS); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|