|  |  | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson.JSONArray; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
 |  |  | import com.zy.asrs.common.utils.TreeUtils; | 
 |  |  | import com.zy.asrs.common.wms.entity.Mat; | 
 |  |  | import com.zy.asrs.common.wms.entity.*; | 
 |  |  | import com.zy.asrs.common.wms.service.LocDetlService; | 
 |  |  | import com.zy.asrs.common.wms.service.LocMastService; | 
 |  |  | import com.zy.asrs.common.wms.service.MatService; | 
 |  |  | import com.zy.asrs.common.wms.service.WrkMastService; | 
 |  |  | import com.zy.asrs.framework.annotations.ManagerAuth; | 
 |  |  | import com.zy.asrs.framework.common.Cools; | 
 |  |  | import com.zy.asrs.framework.common.R; | 
 |  |  | 
 |  |  |     private MatService matService; | 
 |  |  |     @Autowired | 
 |  |  |     private TreeUtils treeUtils; | 
 |  |  |     @Autowired | 
 |  |  |     private LocDetlService locDetlService; | 
 |  |  |     @Autowired | 
 |  |  |     private LocMastService locMastService; | 
 |  |  |     @Autowired | 
 |  |  |     private WrkMastService wrkMastService; | 
 |  |  |  | 
 |  |  |     @RequestMapping(value = "/mat/{id}/auth") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R get(@PathVariable("id") Long id) { | 
 |  |  |         return R.ok(matService.getById(id)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @RequestMapping(value = "/mat/auth") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R find(@RequestParam("matnr") String matnr) { | 
 |  |  |         Mat one = matService.getOne(new LambdaQueryWrapper<Mat>() | 
 |  |  |                 .eq(Mat::getMatnr, matnr) | 
 |  |  |                 .eq(Mat::getHostId, getHostId())); | 
 |  |  |         if (Cools.isEmpty(one)){ | 
 |  |  |             return R.error("未查询到相关物料"); | 
 |  |  |         } | 
 |  |  |         return R.ok(one); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @RequestMapping(value = "/mat/page/auth") | 
 |  |  | 
 |  |  |                   @RequestParam(required = false) String condition, | 
 |  |  |                   @RequestParam(required = false) String timeRange, | 
 |  |  |                   @RequestParam Map<String, Object> param) { | 
 |  |  |         LambdaQueryWrapper<Mat> wrapper = new LambdaQueryWrapper<>(); | 
 |  |  |         wrapper.eq(Mat::getHostId, getHostId()); | 
 |  |  |         if (!Cools.isEmpty(condition)) { | 
 |  |  |             wrapper.like(Mat::getId, condition); | 
 |  |  |         } | 
 |  |  |         QueryWrapper<Mat> wrapper = new QueryWrapper<>(); | 
 |  |  | //        convert(param, wrapper); | 
 |  |  |         wrapper.eq("host_id", getHostId()); | 
 |  |  | //        if (!Cools.isEmpty(condition)) { | 
 |  |  | //            wrapper.like(Mat::getId, condition); | 
 |  |  | //        } | 
 |  |  |         if (!Cools.isEmpty(timeRange)) { | 
 |  |  |             String[] range = timeRange.split(RANGE_TIME_LINK); | 
 |  |  |             wrapper.ge(Mat::getCreateTime, DateUtils.convert(range[0])); | 
 |  |  |             wrapper.le(Mat::getCreateTime, DateUtils.convert(range[1])); | 
 |  |  |             wrapper.ge("create_time", DateUtils.convert(range[0])); | 
 |  |  |             wrapper.le("create_time", DateUtils.convert(range[1])); | 
 |  |  |         } | 
 |  |  |         Object tagId = param.get("tag_id"); | 
 |  |  |         ArrayList<Long> nodes = new ArrayList<>(); | 
 |  |  | 
 |  |  |             tagId = getOriginTag().getId(); | 
 |  |  |         } | 
 |  |  |         treeUtils.getTagIdList(Long.parseLong(tagId.toString()), nodes); | 
 |  |  |         wrapper.in(Mat::getTagId, nodes); | 
 |  |  |         wrapper.in("tag_id", nodes); | 
 |  |  |         if (!Cools.isEmpty(param.get("matnr"))) { | 
 |  |  |             wrapper.eq(Mat::getMatnr, param.get("matnr")); | 
 |  |  |             wrapper.like("matnr", param.get("matnr")); | 
 |  |  |         } | 
 |  |  |         if (!Cools.isEmpty(param.get("maktx"))) { | 
 |  |  |             wrapper.eq(Mat::getMaktx, param.get("maktx")); | 
 |  |  |             wrapper.like("maktx", param.get("maktx")); | 
 |  |  |         } | 
 |  |  |         if (!Cools.isEmpty(param.get("decrees"))) { | 
 |  |  |             wrapper.like("decrees", param.get("decrees")); | 
 |  |  |         } | 
 |  |  | //        if (!Cools.isEmpty(param.get("owner$"))) { | 
 |  |  | //            wrapper.eq("owner", param.get("owner$")); | 
 |  |  | //        } | 
 |  |  |         param.remove("matnr"); | 
 |  |  |         param.remove("maktx"); | 
 |  |  |         param.remove("decrees"); | 
 |  |  | //        param.remove("owner$"); | 
 |  |  |         allLike(Mat.class, param.keySet(), wrapper, condition); | 
 |  |  |         return R.ok(matService.page(new Page<>(curr, limit), wrapper)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  | //    private <T> void convert(Map<String, Object> map, QueryWrapper<T> wrapper){ | 
 |  |  | //        for (Map.Entry<String, Object> entry : map.entrySet()){ | 
 |  |  | //            String val = String.valueOf(entry.getValue()); | 
 |  |  | //            if (val.contains(RANGE_TIME_LINK)){ | 
 |  |  | //                String[] dates = val.split(RANGE_TIME_LINK); | 
 |  |  | //                wrapper.ge(entry.getKey(), DateUtils.convert(dates[0])); | 
 |  |  | //                wrapper.le(entry.getKey(), DateUtils.convert(dates[1])); | 
 |  |  | //            } else { | 
 |  |  | //                if (entry.getKey().equals("locNo")) { | 
 |  |  | //                    wrapper.eq("loc_no", String.valueOf(entry.getValue())); | 
 |  |  | //                } else { | 
 |  |  | //                    wrapper.like(entry.getKey(), String.valueOf(entry.getValue())); | 
 |  |  | //                } | 
 |  |  | //            } | 
 |  |  | //        } | 
 |  |  | //    } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @RequestMapping(value = "/mat/add/auth") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R add(Mat mat) { | 
 |  |  |         int count = matService.count(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, mat.getMatnr())); | 
 |  |  |         if(count > 0){ | 
 |  |  |             return R.error("当前物料号已存在"); | 
 |  |  |         } | 
 |  |  |         mat.setHostId(getHostId()); | 
 |  |  |         matService.save(mat); | 
 |  |  |         return R.ok(); | 
 |  |  | 
 |  |  |         LambdaQueryWrapper<Mat> wrapper = new LambdaQueryWrapper<>(); | 
 |  |  |         wrapper.eq(Mat::getHostId, getHostId()); | 
 |  |  |         if (!Cools.isEmpty(condition)) { | 
 |  |  |             wrapper.like(Mat::getId, condition); | 
 |  |  |             wrapper.like(Mat::getMatnr, condition); | 
 |  |  |         } | 
 |  |  |         matService.page(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getId()), item.getId()))); | 
 |  |  |         matService.page(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(item.getMatnr(), item.getId()))); | 
 |  |  |         return R.ok().add(vos); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @RequestMapping(value = "/mat/covert/{id}/auth") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R covert(@PathVariable("id") String id) { | 
 |  |  |         Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getId, id).eq(Mat::getHostId, getHostId())); | 
 |  |  |         if (mat == null) { | 
 |  |  |             return R.ok(); | 
 |  |  |         } | 
 |  |  |         OrderDetl orderDetl = new OrderDetl(); | 
 |  |  |         orderDetl.sync(mat); | 
 |  |  |         orderDetl.setAnfme(0.0D); | 
 |  |  |         return R.ok().add(orderDetl); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @RequestMapping(value = "/mat/list/pda/page/auth") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R pdaPageList(@RequestParam(required = true)Long tagId, | 
 |  |  |                          @RequestParam(defaultValue = "1")Integer curr, | 
 |  |  |                          @RequestParam(defaultValue = "10")Integer limit){ | 
 |  |  |         LambdaQueryWrapper<Mat> wrapper = new LambdaQueryWrapper<>(); | 
 |  |  |         wrapper.eq(Mat::getHostId, getHostId()); | 
 |  |  |         wrapper.orderBy(true, false,Mat::getCreateTime); | 
 |  |  |         return R.ok().add(matService.page(new Page<>(curr, limit), wrapper)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @RequestMapping(value = "/mat/pad/search") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R padSearch(@RequestParam("matnr") String matnr) { | 
 |  |  |         List<Mat> list = matService.list(new LambdaQueryWrapper<Mat>() | 
 |  |  |                 .like(Mat::getMatnr, matnr) | 
 |  |  |                 .eq(Mat::getHostId, getHostId())); | 
 |  |  |         if (list.isEmpty()){ | 
 |  |  |             return R.error("未查询到相关物料"); | 
 |  |  |         } | 
 |  |  |         return R.ok(list); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @RequestMapping(value = "/mat/pad/searchLoc") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R padSearchLoc(@RequestParam("matnr") String matnr) { | 
 |  |  |         List<LocDetl> list = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getMatnr, matnr).eq(LocDetl::getHostId, getHostId())); | 
 |  |  |  | 
 |  |  |         ArrayList<LocDetl> locDetls = new ArrayList<>(); | 
 |  |  |         for (LocDetl locDetl : list) { | 
 |  |  |             LocMast one = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, locDetl.getLocNo()).eq(LocMast::getHostId, locDetl.getHostId())); | 
 |  |  |             if (one == null) { | 
 |  |  |                 continue; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             if (!one.getLocSts().equals("F")) { | 
 |  |  |                 continue; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             locDetls.add(locDetl); | 
 |  |  |         } | 
 |  |  |         return R.ok(locDetls); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @GetMapping("/mat/synchronous") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R synchronous(){ | 
 |  |  |         int wrkConut=wrkMastService.count(new LambdaQueryWrapper<WrkMast>()); | 
 |  |  |         if(wrkConut>0){ | 
 |  |  |             return R.error("有工作中的任務,禁止同步库存信息"); | 
 |  |  |         } | 
 |  |  |         List<Mat> mats=matService.list(); | 
 |  |  |         for (Mat mat:mats | 
 |  |  |         ) { | 
 |  |  |             List<LocDetl>locDetls=locDetlService.list(new LambdaQueryWrapper<LocDetl>() | 
 |  |  |                     .eq(LocDetl::getMatnr,mat.getMatnr())); | 
 |  |  |             for (LocDetl locDetl:locDetls | 
 |  |  |             ) { | 
 |  |  |                 locDetl.setMaktx(mat.getMaktx()); | 
 |  |  |  | 
 |  |  |                 if(!Cools.isEmpty(mat.getSpecs())){ | 
 |  |  |                     locDetl.setSpecs(mat.getSpecs()); | 
 |  |  |                 }else{ | 
 |  |  |                     locDetl.setSpecs(""); | 
 |  |  |                 } | 
 |  |  |                 if(!Cools.isEmpty(mat.getModel())){ | 
 |  |  |                     locDetl.setModel(mat.getModel()); | 
 |  |  |                 }else { | 
 |  |  |                     locDetl.setModel(""); | 
 |  |  |                 } | 
 |  |  |                 if(!Cools.isEmpty(mat.getSku())){ | 
 |  |  |                     locDetl.setSku(mat.getSku()); | 
 |  |  |                 }else { | 
 |  |  |                     locDetl.setSku(""); | 
 |  |  |                 } | 
 |  |  |                 //图号 | 
 |  |  |                 if(!Cools.isEmpty(mat.getImgNum())){ | 
 |  |  |                     locDetl.setItemNum(mat.getImgNum()); | 
 |  |  |                 }else { | 
 |  |  |                     locDetl.setItemNum(""); | 
 |  |  |                 } | 
 |  |  | //                if(!Cools.isEmpty(mat.getWeight())){ | 
 |  |  | //                    locDetl.setWeight(Double.parseDouble(mat.getWeight())); | 
 |  |  | //                }else { | 
 |  |  | //                    locDetl.setWeight(0.0); | 
 |  |  | //                } | 
 |  |  | //                if(!Cools.isEmpty(mat.getLength())){ | 
 |  |  | //                    locDetl.setLength(Double.parseDouble(mat.getLength())); | 
 |  |  | //                }else { | 
 |  |  | //                    locDetl.setLength(0.0); | 
 |  |  | //                } | 
 |  |  |                 locDetlService.updateById(locDetl); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return R.ok(); | 
 |  |  |     } | 
 |  |  | } |