|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.wms.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.metadata.OrderItem; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.entity.Parameter; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.entity.Shelves; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.param.LocMastInitParam; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.dto.LocPicDto; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.LocDetl; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.LocMast; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.Mat; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.service.LocDetlService; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.service.LocMastService; | 
|---|
|  |  |  | import com.zy.asrs.framework.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.Cools; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.framework.common.DateUtils; | 
|---|
|  |  |  | import com.zy.asrs.common.web.BaseController; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import static jdk.nashorn.api.scripting.ScriptUtils.convert; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | public class LocMastController extends BaseController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocMastService locMastService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocDetlService locDetlService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${wcs.url}") | 
|---|
|  |  |  | private String WCS_URL; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/locMast/{id}/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestParam(required = false) String condition, | 
|---|
|  |  |  | @RequestParam(required = false) String timeRange, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param) { | 
|---|
|  |  |  | LambdaQueryWrapper<LocMast> wrapper = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | wrapper.eq(LocMast::getHostId, getHostId()); | 
|---|
|  |  |  | if (!Cools.isEmpty(condition)) { | 
|---|
|  |  |  | wrapper.like(LocMast::getLocNo, condition); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(timeRange)) { | 
|---|
|  |  |  | String[] range = timeRange.split(RANGE_TIME_LINK); | 
|---|
|  |  |  | wrapper.ge(LocMast::getAppeTime, DateUtils.convert(range[0])); | 
|---|
|  |  |  | wrapper.le(LocMast::getAppeTime, DateUtils.convert(range[1])); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(param.get("loc_no"))) { | 
|---|
|  |  |  | wrapper.eq(LocMast::getLocNo, param.get("loc_no")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | excludeTrash(param); | 
|---|
|  |  |  | QueryWrapper<LocMast> wrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | wrapper.eq("host_id",getHostId()); | 
|---|
|  |  |  | //wrapper.eq(LocMast::getHostId, getHostId()); | 
|---|
|  |  |  | convert(param, wrapper); | 
|---|
|  |  |  | //if (!Cools.isEmpty(condition)) { | 
|---|
|  |  |  | //    wrapper.like(LocMast::getLocNo, condition); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | //if (!Cools.isEmpty(timeRange)) { | 
|---|
|  |  |  | //    String[] range = timeRange.split(RANGE_TIME_LINK); | 
|---|
|  |  |  | //    wrapper.ge(LocMast::getAppeTime, DateUtils.convert(range[0])); | 
|---|
|  |  |  | //    wrapper.le(LocMast::getAppeTime, DateUtils.convert(range[1])); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | //if (!Cools.isEmpty(param.get("loc_no"))) { | 
|---|
|  |  |  | //    wrapper.eq(LocMast::getLocNo, param.get("loc_no")); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | //if (!Cools.isEmpty(param.get("loc_sts"))) { | 
|---|
|  |  |  | //    wrapper.eq(LocMast::getLocSts, param.get("loc_sts")); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | return R.ok(locMastService.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 { | 
|---|
|  |  |  | wrapper.like(entry.getKey(), val); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping(value = "/group/empty/stock") | 
|---|
|  |  |  | @ManagerAuth(memo = "获取同组货架的空库位") | 
|---|
|  |  |  | public R getGroupEmptyStock(@RequestParam(required = false) String sourceLocNo) { | 
|---|
|  |  |  | return R.ok().add(locMastService.queryGroupEmptyStock(sourceLocNo, getHostId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/locMast/update/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | @RequestMapping(value = "/locMast/update/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "库位修改") | 
|---|
|  |  |  | public R update(LocMast locMast){ | 
|---|
|  |  |  | if (Cools.isEmpty(locMast) || null==locMast.getLocNo()){ | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | locMastService.updateById(locMast); | 
|---|
|  |  |  | LocMast oldLocMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, locMast.getLocNo()).eq(LocMast::getHostId, getHostId())); | 
|---|
|  |  |  | if (locMast.getLocSts().equals("F") && (oldLocMast.getLocSts().equals("D") || oldLocMast.getLocSts().equals("O"))) { | 
|---|
|  |  |  | return R.error("当前操作已被阻止,请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 有物料时修改为空库位或者空板库位,则删除库存明细 | 
|---|
|  |  |  | if (oldLocMast.getLocSts().equals("R") || oldLocMast.getLocSts().equals("F")) { | 
|---|
|  |  |  | if (locMast.getLocSts().equals("O") || locMast.getLocSts().equals("D")) { | 
|---|
|  |  |  | locDetlService.remove(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocNo, locMast.getLocNo())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | locMast.setModiUser(getUserId()); | 
|---|
|  |  |  | locMast.setModiTime(new Date()); | 
|---|
|  |  |  | locMastService.update(locMast,new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, locMast.getLocNo()).eq(LocMast::getHostId, getHostId())); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok().add(vos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/locMast/init/pwd") | 
|---|
|  |  |  | public R locMastInitPwd(@RequestParam(required = false) String pwd) { | 
|---|
|  |  |  | if (Cools.isEmpty(pwd)) { | 
|---|
|  |  |  | return R.error("请输入口令"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok().add(Parameter.get().getLocMastInitPwd().equals(pwd)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/locMast/init/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "初始化库位") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R init(LocMastInitParam param) { | 
|---|
|  |  |  | Long hostId = getHostId(); | 
|---|
|  |  |  | List<LocMast> list = new ArrayList<>(); | 
|---|
|  |  |  | for (int r=param.getStartRow(); r<=param.getEndRow(); r++){ | 
|---|
|  |  |  | for (int b=param.getStartBay(); b<=param.getEndBay(); b++) { | 
|---|
|  |  |  | for (int l=param.getStartLev(); l<=param.getEndLev(); l++) { | 
|---|
|  |  |  | // 获取库位号 | 
|---|
|  |  |  | String locNo = String.format("%02d", r) + String.format("%03d", b) + String.format("%02d", l); | 
|---|
|  |  |  | // 获取堆垛机号 | 
|---|
|  |  |  | int crnNo = 0; | 
|---|
|  |  |  | Shelves shelves = new Shelves(param.getEndRow() - param.getStartRow() + 1, param.getCrnAmount()); | 
|---|
|  |  |  | for (List<Integer> node : shelves.nodes){ | 
|---|
|  |  |  | if (node.contains(r)) { | 
|---|
|  |  |  | crnNo = shelves.nodes.indexOf(node) + 1; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | LocMast locMast = new LocMast(); | 
|---|
|  |  |  | locMast.setLocNo(locNo); | 
|---|
|  |  |  | locMast.setLocSts("O"); | 
|---|
|  |  |  | locMast.setRow1(r); // 排 | 
|---|
|  |  |  | locMast.setBay1(b); // 列 | 
|---|
|  |  |  | locMast.setLev1(l); // 层 | 
|---|
|  |  |  | locMast.setCrnNo(crnNo); // 堆垛机 | 
|---|
|  |  |  | locMast.setLocType1(param.getLocType1()); | 
|---|
|  |  |  | locMast.setLocType2(param.getLocType2()); | 
|---|
|  |  |  | locMast.setLocType3(param.getLocType3()); | 
|---|
|  |  |  | locMast.setAppeUser(getUserId()); | 
|---|
|  |  |  | locMast.setAppeTime(new Date()); | 
|---|
|  |  |  | locMast.setModiUser(getUserId()); | 
|---|
|  |  |  | locMast.setModiTime(new Date()); | 
|---|
|  |  |  | locMast.setHostId(hostId); | 
|---|
|  |  |  | locMast.setWhsType(0L); | 
|---|
|  |  |  | list.add(locMast); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | locMastService.remove(new LambdaQueryWrapper<LocMast>().eq(LocMast::getHostId, hostId)); | 
|---|
|  |  |  | locDetlService.remove(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getHostId, hostId)); | 
|---|
|  |  |  | for (LocMast locMast : list) { | 
|---|
|  |  |  | locMastService.save(locMast); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("初始化成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/locMast/picUrl") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R getPicUrl(@RequestParam String locNo) { | 
|---|
|  |  |  | LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>() | 
|---|
|  |  |  | .eq(LocMast::getLocNo, locNo) | 
|---|
|  |  |  | .eq(LocMast::getHostId, getHostId())); | 
|---|
|  |  |  | if (locMast == null) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<LocPicDto> list = new ArrayList<>(); | 
|---|
|  |  |  | String picStr = locMast.getPic(); | 
|---|
|  |  |  | if (Cools.isEmpty(picStr)) { | 
|---|
|  |  |  | return R.ok().add(list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<String> pics = JSON.parseArray(picStr, String.class); | 
|---|
|  |  |  | for (String pic : pics) { | 
|---|
|  |  |  | List<String> picList = new ArrayList<>(); | 
|---|
|  |  |  | String[] split = pic.split("_"); | 
|---|
|  |  |  | String picPath = split[0]; | 
|---|
|  |  |  | String locNoStr = ""; | 
|---|
|  |  |  | if (split.length > 1) { | 
|---|
|  |  |  | locNoStr = split[1]; | 
|---|
|  |  |  | picPath += "_" + locNoStr; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | picList.add("http://" + WCS_URL + "/image/" + picPath + "-1.jpg"); | 
|---|
|  |  |  | picList.add("http://" + WCS_URL + "/image/" + picPath + "-2.jpg"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LocPicDto locPicDto = new LocPicDto(); | 
|---|
|  |  |  | locPicDto.setLocNo(locNoStr); | 
|---|
|  |  |  | locPicDto.setPics(picList); | 
|---|
|  |  |  | list.add(locPicDto); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok().add(list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/wrkLastno/export/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "库位明细导出") | 
|---|
|  |  |  | public synchronized R export(@RequestBody JSONObject param){ | 
|---|
|  |  |  | List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); | 
|---|
|  |  |  | QueryWrapper<LocMast> wrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | Map<String, Object> map = excludeTrash(param.getJSONObject("locMast")); | 
|---|
|  |  |  | String row = ""; | 
|---|
|  |  |  | if (map.get("row") != null) { | 
|---|
|  |  |  | String chooseRow = (String) map.get("row"); | 
|---|
|  |  |  | if (chooseRow.length() == 1) { | 
|---|
|  |  |  | row = "0" + chooseRow; | 
|---|
|  |  |  | map.remove("row"); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | row = chooseRow; | 
|---|
|  |  |  | map.remove("row"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | convert(map, wrapper); | 
|---|
|  |  |  | //        if (!row.equals("")){ | 
|---|
|  |  |  | //            wrapper.and() | 
|---|
|  |  |  | //                    .where("loc_no like '" +row +"%'"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | List<LocMast> list = locMastService.list(wrapper); | 
|---|
|  |  |  | return R.ok(exportSupport(list, fields)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|