| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.LocDetl; |
| | | import com.zy.asrs.entity.OrderDetl; |
| | | import com.zy.asrs.entity.result.StoPreTab; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.common.model.LocDto; |
| | | import com.zy.common.model.TaskDto; |
| | | import com.zy.common.web.BaseController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * Created by vincent on 2022/3/26 |
| | |
| | | private WorkService workService; |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | | private ManPakOutService manPakOutService; |
| | | @Autowired |
| | | private ManLocDetlService manLocDetlService; |
| | | |
| | | |
| | | @PostMapping("/out/pakout/orderDetlIds/auth") |
| | | @ManagerAuth |
| | | public R pakoutOrderDetlIds(@RequestParam Long orderId) throws InterruptedException { |
| | | Thread.sleep(200); |
| | | return R.ok().add(orderDetlService.selectByOrderId(orderId).stream().map(OrderDetl::getId).distinct().collect(Collectors.toList())); |
| | | } |
| | | |
| | | @PostMapping("/out/pakout/preview/auth") |
| | | @ManagerAuth |
| | |
| | | } |
| | | List<OrderDetl> orderDetls = orderDetlService.selectBatchIds(ids); |
| | | List<LocDto> locDtos = new ArrayList<>(); |
| | | |
| | | Set<String> exist = new HashSet<>(); |
| | | |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getQty()).orElse(0.0D); |
| | | if (issued <= 0.0D) { continue; } |
| | | List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), null); |
| | | List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), null, exist); |
| | | for (LocDetl locDetl : locDetls) { |
| | | if (issued > 0) { |
| | | LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(), |
| | | issued >= locDetl.getAnfme() ? locDetl.getAnfme() : issued); |
| | | List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locDetl.getLocNo(), issued >= locDetl.getAnfme() ? 101 : 103); |
| | | // LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(), |
| | | // locDetl.getAnfme(), issued < locDetl.getAnfme()? issued : locDetl.getAnfme()); |
| | | // //速腾只有全板,所以只能101全板出库 |
| | | // List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locDetl.getLocNo(), 101); |
| | | locDto.setStaNos(staNos); |
| | | locDto.setManu(locDetl.getManu()); |
| | | locDtos.add(locDto); |
| | | exist.add(locDetl.getLocNo()); |
| | | // 剩余待出数量递减 |
| | | issued = issued - locDetl.getAnfme(); |
| | | } else { |
| | |
| | | } |
| | | if (issued > 0) { |
| | | LocDto locDto = new LocDto(null, orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), issued); |
| | | // LocDto locDto = new LocDto(null, orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), 0.0,issued); |
| | | locDto.setLack(Boolean.TRUE); |
| | | locDtos.add(locDto); |
| | | } |
| | |
| | | @PostMapping("/out/pakout/auth") |
| | | @ManagerAuth(memo = "订单出库") |
| | | public synchronized R pakout(@RequestBody List<LocDto> locDtos) throws InterruptedException { |
| | | if (Cools.isEmpty(locDtos)) { |
| | | return R.parse(BaseRes.PARAM); |
| | | int[][] is=new int[locDtos.size()][2]; |
| | | for (int i=0;i<locDtos.size();i++){ |
| | | LocDto locDto=locDtos.get(locDtos.size()-1-i); |
| | | if (locDto.getLocNo()==null || locDto.getManu().equals("平库")){ |
| | | is[i][0]=1; |
| | | }else { |
| | | is[i][0]=0; |
| | | } |
| | | is[i][1]=locDtos.size()-1-i; |
| | | } |
| | | boolean refuse = true; |
| | | for (LocDto locDto : locDtos) { |
| | | if (!locDto.isLack()) { |
| | | refuse = !refuse; |
| | | for (int[] i:is){ |
| | | if (i[0]==1){ |
| | | locDtos.remove(i[1]); |
| | | } |
| | | } |
| | | if (refuse) { |
| | | if (Cools.isEmpty(locDtos)) { |
| | | return R.error("立库参数为空,请生成拣货单,平库拣货出库"); |
| | | } |
| | | boolean lack = true; |
| | | for (LocDto locDto : locDtos) { |
| | | if (!locDto.isLack()) { |
| | | lack = false; |
| | | break; |
| | | } |
| | | } |
| | | if (lack) { |
| | | return R.error("库存不足"); |
| | | } |
| | | |
| | | Thread.sleep(500L); |
| | | Thread.sleep(1000L); |
| | | |
| | | List<TaskDto> taskDtos = new ArrayList<>(); |
| | | // 根据 (库位 & 出库站) 分组; 理想状态:一组为一次出库任务 |
| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @PostMapping("/out/pakout2/auth") |
| | | @ManagerAuth(memo = "生成拣货单") |
| | | public synchronized R pakout2(@RequestBody List<LocDto> locDtos) throws InterruptedException { |
| | | int[][] is = new int[locDtos.size()][2]; |
| | | for (int i = 0; i < locDtos.size(); i++) { |
| | | LocDto locDto = locDtos.get(locDtos.size() - 1 - i); |
| | | if (locDto.getLocNo() == null || locDto.getManu().equals("立库")) { |
| | | is[i][0] = 1; |
| | | } else { |
| | | is[i][0] = 0; |
| | | } |
| | | is[i][1] = locDtos.size() - 1 - i; |
| | | } |
| | | for (int[] i : is) { |
| | | if (i[0] == 1) { |
| | | locDtos.remove(i[1]); |
| | | } |
| | | } |
| | | if (Cools.isEmpty(locDtos)) { |
| | | return R.error("平库参数为空,没有生成拣货单"); |
| | | } |
| | | boolean lack = true; |
| | | for (LocDto locDto : locDtos) { |
| | | if (!locDto.isLack()) { |
| | | lack = false; |
| | | break; |
| | | } |
| | | } |
| | | if (lack) { |
| | | return R.error("库存不足"); |
| | | } |
| | | for (LocDto locDto:locDtos){ |
| | | ManLocDetl manLocDetl = manLocDetlService.selectItem(locDto.getLocNo(), locDto.getMatnr(), locDto.getBatch()); |
| | | if (!(locDto.getAnfme()>manLocDetl.getAnfme())) { |
| | | manLocDetl.setStatus(0); |
| | | if (manLocDetlService.update(manLocDetl, new EntityWrapper<ManLocDetl>().eq("uuid", manLocDetl.getUuid()))) { |
| | | if (addPakOUT(locDto).equals(R.ok())) { |
| | | Order order = orderService.selectByNo(locDto.getOrderNo()); |
| | | if (Cools.isEmpty(order)){ |
| | | return R.error("查询订单失败,请联系管理员"+locDto.getOrderNo()); |
| | | } |
| | | if (order.getSettle()==1){ |
| | | if (!orderService.updateSettle(order.getId(),2L,null)){ |
| | | return R.error("修改订单状态失败,请联系管理员"+locDto.getOrderNo()); |
| | | } |
| | | } |
| | | OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>().eq("order_no", locDto.getOrderNo()).eq("matnr", locDto.getMatnr())); |
| | | if (Cools.isEmpty(orderDetl)){ |
| | | return R.error("查询订单明细失败,请联系管理员"+locDto.getOrderNo()+locDto.getMatnr()); |
| | | } |
| | | orderDetl.setWorkQty(orderDetl.getWorkQty()+locDto.getAnfme()); |
| | | if (!orderDetlService.update(orderDetl,new EntityWrapper<OrderDetl>().eq("order_no", locDto.getOrderNo()).eq("matnr", locDto.getMatnr()))){ |
| | | return R.error("修改订单明细失败,请联系管理员"+locDto.getOrderNo()+locDto.getMatnr()); |
| | | } |
| | | } else { |
| | | return R.error("添加拣货明细失败,请联系管理员"+locDto.getOrderNo()+locDto.getMatnr()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | private R addPakOUT(LocDto locDto){ |
| | | ManPakOut manPakOut=new ManPakOut(); |
| | | manPakOut.setWrkNo(locDto.getOrderNo()+"-"+System.currentTimeMillis()); |
| | | manPakOut.setWrkSts((long)1); |
| | | manPakOut.setAnfme(locDto.getAnfme()); |
| | | manPakOut.setLocNo(locDto.getLocNo()); |
| | | manPakOut.setMatnr(locDto.getMatnr()); |
| | | manPakOut.setMaktx(locDto.getMaktx()); |
| | | manPakOut.setDocNum(locDto.getOrderNo()); |
| | | manPakOut.setStatus(0); |
| | | manPakOut.setCreateTime(new Date()); |
| | | manPakOut.setBatch(locDto.getBatch()); |
| | | manPakOut.setUpdateTime(new Date()); |
| | | if (Cools.isEmpty(manPakOutService.selectOne(new EntityWrapper<ManPakOut>().eq("doc_num",locDto.getOrderNo())))){ |
| | | manPakOut.setName(locDto.getMaktx()); |
| | | } |
| | | try{ |
| | | if (!manPakOutService.insert(manPakOut)){ |
| | | return R.error("添加拣货明细失败,请联系管理员"); |
| | | } |
| | | }catch (Exception e){ |
| | | return R.error("添加拣货明细失败,请联系管理员"); |
| | | } |
| | | return R.ok(); |
| | | |
| | | } |
| | | |
| | | |
| | | } |