| | |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.core.common.DateUtils; |
| | | import com.zy.asrs.entity.ManLocDetl; |
| | | import com.zy.asrs.entity.Order; |
| | | import com.zy.asrs.entity.OrderDetl; |
| | | import com.zy.asrs.entity.Pakout; |
| | | import com.zy.asrs.entity.param.OrderDomainParam; |
| | | import com.zy.asrs.service.ManLocDetlService; |
| | | import com.zy.asrs.service.OrderDetlService; |
| | | import com.zy.asrs.service.OrderService; |
| | | import com.zy.asrs.service.PakoutService; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.BaseRes; |
| | |
| | | import com.core.common.R; |
| | | import com.zy.common.web.BaseController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.*; |
| | |
| | | |
| | | @Autowired |
| | | private PakoutService pakoutService; |
| | | @Autowired |
| | | private OrderService orderService; |
| | | @Autowired |
| | | private OrderDetlService orderDetlService; |
| | | @Autowired |
| | | private ManLocDetlService manLocDetlService; |
| | | |
| | | @RequestMapping(value = "/pakout/{id}/auth") |
| | | @ManagerAuth |
| | |
| | | |
| | | @RequestMapping(value = "/pakout/add/auth") |
| | | @ManagerAuth |
| | | public R add(Pakout pakout) { |
| | | pakoutService.insert(pakout); |
| | | return R.ok(); |
| | | public R add(@RequestBody OrderDomainParam param) { |
| | | if (Cools.isEmpty(param)){ |
| | | return R.error("数据异常"); |
| | | } |
| | | if (!Cools.isEmpty(param.getOrderNo())){ |
| | | Order order = orderService.selectOne(new EntityWrapper<Order>() |
| | | .eq("order_no", param.getOrderNo()) |
| | | ); |
| | | if (Cools.isEmpty(order)){ |
| | | return R.error("单据不存在"); |
| | | } |
| | | List<OrderDetl> orderDetls =orderDetlService.selectList(new EntityWrapper<OrderDetl>() |
| | | .eq("order_no", param.getOrderNo()) |
| | | ); |
| | | if (Cools.isEmpty(orderDetls)){ |
| | | return R.error("单据明细为空"); |
| | | } |
| | | for (OrderDetl orderDetl : orderDetls){ |
| | | List<ManLocDetl> manLocDetls=null; |
| | | try{ |
| | | if (Cools.isEmpty(orderDetl.getBatch())){ |
| | | manLocDetls = manLocDetlService.selectList(new EntityWrapper<ManLocDetl>() |
| | | .eq("matnr",orderDetl.getMatnr()) |
| | | ); |
| | | }else { |
| | | manLocDetls = manLocDetlService.selectList(new EntityWrapper<ManLocDetl>() |
| | | .eq("matnr",orderDetl.getMatnr()) |
| | | .eq("batch",orderDetl.getBatch()) |
| | | ); |
| | | } |
| | | }catch (Exception e){ |
| | | return R.error("添加拣货单失败"); |
| | | } |
| | | |
| | | if (!Cools.isEmpty(manLocDetls)){ |
| | | for (ManLocDetl manLocDetl:manLocDetls){ |
| | | Double statusAnfme = 0.0; |
| | | if (Cools.isEmpty(manLocDetl.getStatus())){ |
| | | manLocDetl.setStatus(1); |
| | | } |
| | | try{ |
| | | if (manLocDetl.getStatus$().equals("禁用")){ |
| | | if (Cools.isEmpty(manLocDetl.getBatch())){ |
| | | List<Pakout> manPakOuts = pakoutService.selectList(new EntityWrapper<Pakout>() |
| | | .eq("loc_no", manLocDetl.getLocNo()) |
| | | .eq("matnr", manLocDetl.getMatnr()) |
| | | .eq("status",0) |
| | | ); |
| | | if (!Cools.isEmpty(manPakOuts)){ |
| | | for (Pakout manPakOut:manPakOuts){ |
| | | statusAnfme=statusAnfme+manPakOut.getAnfme(); |
| | | } |
| | | } |
| | | }else { |
| | | List<Pakout> manPakOuts = pakoutService.selectList(new EntityWrapper<Pakout>() |
| | | .eq("loc_no", manLocDetl.getLocNo()) |
| | | .eq("matnr", manLocDetl.getMatnr()) |
| | | .eq("batch",manLocDetl.getBatch()) |
| | | .eq("status",0) |
| | | ); |
| | | if (!Cools.isEmpty(manPakOuts)){ |
| | | for (Pakout manPakOut:manPakOuts){ |
| | | statusAnfme=statusAnfme+manPakOut.getAnfme(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | return R.error("查询库存禁用数量失败"); |
| | | } |
| | | Wrapper<ManLocDetl> wrapper = new EntityWrapper<ManLocDetl>() |
| | | .eq("loc_no", manLocDetl.getLocNo()) |
| | | .eq("matnr", manLocDetl.getMatnr()); |
| | | if (orderDetl.getAnfme() > manLocDetl.getAnfme()-statusAnfme){ |
| | | if (addPakOUT(manLocDetl,param.getOrderNo()).equals(R.ok())){ |
| | | manLocDetl.setStatus(0); |
| | | try{ |
| | | if (Cools.isEmpty(manLocDetl.getBatch())){ |
| | | manLocDetlService.update(manLocDetl,wrapper.eq("modi_time",manLocDetl.getModiTime())); |
| | | }else { |
| | | manLocDetlService.update(manLocDetl,wrapper.eq("batch",manLocDetl.getBatch())); |
| | | } |
| | | }catch (Exception e){ |
| | | return R.error("更新库存失败"); |
| | | } |
| | | orderDetl.setAnfme(orderDetl.getAnfme()-manLocDetl.getAnfme()); |
| | | }else { |
| | | return R.error("添加拣货单失败"); |
| | | } |
| | | }else if (orderDetl.getAnfme()-manLocDetl.getAnfme()-statusAnfme==0){ |
| | | if (addPakOUT(manLocDetl,param.getOrderNo()).equals(R.ok())){ |
| | | manLocDetl.setStatus(0); |
| | | try{ |
| | | if (Cools.isEmpty(manLocDetl.getBatch())){ |
| | | manLocDetlService.update(manLocDetl,wrapper.eq("modi_time",manLocDetl.getModiTime())); |
| | | }else { |
| | | manLocDetlService.update(manLocDetl,wrapper.eq("batch",manLocDetl.getBatch())); |
| | | } |
| | | }catch (Exception e){ |
| | | return R.error("更新库存失败"); |
| | | } |
| | | orderDetl.setAnfme(orderDetl.getAnfme()-manLocDetl.getAnfme()); |
| | | }else { |
| | | return R.error("添加拣货单失败"); |
| | | } |
| | | }else if (orderDetl.getAnfme()<manLocDetl.getAnfme()-statusAnfme){ |
| | | Double a=manLocDetl.getAnfme(); |
| | | manLocDetl.setAnfme(orderDetl.getAnfme()); |
| | | if (addPakOUT(manLocDetl,param.getOrderNo()).equals(R.ok())){ |
| | | orderDetl.setAnfme(orderDetl.getAnfme()-manLocDetl.getAnfme()); |
| | | manLocDetl.setStatus(0); |
| | | manLocDetl.setAnfme(a); |
| | | try{ |
| | | if (Cools.isEmpty(manLocDetl.getBatch())){ |
| | | manLocDetlService.update(manLocDetl,wrapper.eq("modi_time",manLocDetl.getModiTime())); |
| | | }else { |
| | | manLocDetlService.update(manLocDetl,wrapper.eq("batch",manLocDetl.getBatch())); |
| | | } |
| | | }catch (Exception e){ |
| | | return R.error("更新库存失败"); |
| | | } |
| | | |
| | | }else { |
| | | return R.error("添加拣货单失败"); |
| | | } |
| | | }else { |
| | | return R.error("系统出错,请联系管理员"); |
| | | } |
| | | if (orderDetl.getAnfme()==0){ |
| | | break; |
| | | } |
| | | } |
| | | if (orderDetl.getAnfme()!=0){ |
| | | ManLocDetl manLocDetl=new ManLocDetl(); |
| | | manLocDetl.setAnfme(0.0); |
| | | manLocDetl.setMatnr(orderDetl.getMatnr()); |
| | | manLocDetl.setMaktx(orderDetl.getMaktx()); |
| | | manLocDetl.setMemo(orderDetl.getMemo()+"库存不足"); |
| | | if (addPakOUT(manLocDetl,param.getOrderNo()).equals(R.ok())){ |
| | | continue; |
| | | }else { |
| | | return R.error("添加拣货单失败"); |
| | | } |
| | | } |
| | | }else { |
| | | ManLocDetl manLocDetl=new ManLocDetl(); |
| | | manLocDetl.setAnfme(0.0); |
| | | manLocDetl.setMatnr(orderDetl.getMatnr()); |
| | | manLocDetl.setMaktx(orderDetl.getMaktx()); |
| | | manLocDetl.setMemo(orderDetl.getMemo()+"无库存"); |
| | | if (addPakOUT(manLocDetl,param.getOrderNo()).equals(R.ok())){ |
| | | continue; |
| | | }else { |
| | | return R.error("添加拣货单失败"); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | orderService.updateSettle(order.getId(),(long)2,null); |
| | | }else { |
| | | return R.error("单据编号异常"); |
| | | } |
| | | return R.ok("拣货单添加成功"); |
| | | } |
| | | |
| | | @RequestMapping(value = "/pakout/update/auth") |
| | | private R addPakOUT(ManLocDetl manLocDetl,String OrderNo){ |
| | | Pakout manPakOut=new Pakout(); |
| | | manPakOut.setWrkNo(OrderNo+"-"+System.currentTimeMillis()); |
| | | manPakOut.setWrkSts((long)1); |
| | | manPakOut.setAnfme(manLocDetl.getAnfme()); |
| | | manPakOut.setLocNo(manLocDetl.getLocNo()); |
| | | manPakOut.setNodeId(manLocDetl.getNodeId()); |
| | | manPakOut.setMatnr(manLocDetl.getMatnr()); |
| | | manPakOut.setMaktx(manLocDetl.getMaktx()); |
| | | manPakOut.setSpecs(manLocDetl.getSpecs()); |
| | | manPakOut.setUnit(manLocDetl.getUnit()); |
| | | manPakOut.setBarcode(manLocDetl.getBarcode()); |
| | | manPakOut.setDocNum(OrderNo); |
| | | manPakOut.setStatus(0); |
| | | manPakOut.setCreateTime(new Date()); |
| | | if (!Cools.isEmpty(manLocDetl.getBatch())){ |
| | | manPakOut.setBatch(manLocDetl.getBatch()); |
| | | manPakOut.setUpdateTime(new Date()); |
| | | }else { |
| | | manPakOut.setUpdateTime(manLocDetl.getModiTime());//用于识别货物 |
| | | } |
| | | |
| | | manPakOut.setMemo(manLocDetl.getMemo()); |
| | | if (Cools.isEmpty(pakoutService.selectOne(new EntityWrapper<Pakout>().eq("doc_num",OrderNo)))){ |
| | | manPakOut.setName(manLocDetl.getMaktx()); |
| | | } |
| | | try{ |
| | | if (!pakoutService.insert(manPakOut)){ |
| | | return R.error("添加拣货明细失败,请联系管理员"); |
| | | } |
| | | }catch (Exception e){ |
| | | return R.error("添加拣货明细失败,请联系管理员"); |
| | | } |
| | | return R.ok(); |
| | | |
| | | } |
| | | |
| | | @RequestMapping(value = "/pakout/update/auth") |
| | | @ManagerAuth |
| | | public R update(Pakout pakout){ |
| | | if (Cools.isEmpty(pakout) || null==pakout.getMatnr()){ |
| | |
| | | } |
| | | |
| | | @RequestMapping(value = "/pakout/delete/auth") |
| | | @ManagerAuth |
| | | public R delete(@RequestParam(value="ids[]") Long[] ids){ |
| | | for (Long id : ids){ |
| | | pakoutService.deleteById(id); |
| | | @ManagerAuth(memo = "手动删除订单") |
| | | public R delete(@RequestParam String docNum){ |
| | | try{ |
| | | pakoutService.deletePakout(docNum); |
| | | }catch (Exception e){ |
| | | return R.error(e+""); |
| | | } |
| | | return R.ok(); |
| | | return R.ok("拣货单删除成功"); |
| | | } |
| | | |
| | | @RequestMapping(value = "/pakout/export/auth") |