|  |  |  | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.DateUtils; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.entity.Node; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.InitPakoutParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.NodeInitPatam; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.PakinParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.result.KeyValueVo; | 
|---|
|  |  |  | import com.zy.asrs.mapper.ManLocDetlMapper; | 
|---|
|  |  |  | import com.zy.asrs.service.NodeService; | 
|---|
|  |  |  | import com.zy.common.entity.NodeExcel; | 
|---|
|  |  |  | import com.zy.common.entity.NodeExcelListener; | 
|---|
|  |  |  | import com.zy.common.entity.Parameter; | 
|---|
|  |  |  | import com.zy.common.utils.ListUtils; | 
|---|
|  |  |  | import com.zy.common.utils.NodeUtils; | 
|---|
|  |  |  | import com.zy.common.utils.TreeUtils; | 
|---|
|  |  |  | 
|---|
|  |  |  | import java.net.URLEncoder; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import static jdk.nashorn.api.scripting.ScriptUtils.convert; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | public class NodeController extends BaseController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | private NodeService nodeService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TreeUtils treeUtils; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ManLocDetlMapper manLocDetlMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/node/{id}/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestParam(required = false)String orderByType, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param){ | 
|---|
|  |  |  | EntityWrapper<Node> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | wrapper.eq("type",3); | 
|---|
|  |  |  | excludeTrash(param); | 
|---|
|  |  |  | convert(param, wrapper); | 
|---|
|  |  |  | hostEq(wrapper); | 
|---|
|  |  |  | if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} | 
|---|
|  |  |  | return R.ok(nodeService.selectPage(new Page<>(curr, limit), wrapper)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestParam(required = false)String orderByType, | 
|---|
|  |  |  | @RequestParam Map<String, Object> param){ | 
|---|
|  |  |  | EntityWrapper<Node> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | wrapper.ne("type",3); | 
|---|
|  |  |  | excludeTrash(param); | 
|---|
|  |  |  | convert(param, wrapper); | 
|---|
|  |  |  | hostEq(wrapper); | 
|---|
|  |  |  | 
|---|
|  |  |  | excludeTrash(param); | 
|---|
|  |  |  | convert(param, wrapper); | 
|---|
|  |  |  | hostEq(wrapper); | 
|---|
|  |  |  | if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} | 
|---|
|  |  |  | return R.parse("0-操作成功").add(nodeService.selectList(wrapper)); | 
|---|
|  |  |  | if (!Cools.isEmpty(orderByField)){ | 
|---|
|  |  |  | wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.parse("0-成功").add(nodeService.selectList(wrapper)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void convert(Map<String, Object> map, EntityWrapper wrapper){ | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/node/add/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R add(Node node) { | 
|---|
|  |  |  | Node node1 = nodeService.selectByUuid(node.getName()); | 
|---|
|  |  |  | if (!Cools.isEmpty(node1)) { | 
|---|
|  |  |  | throw new CoolException("该编号/名称已存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (node.getType() != 1) { | 
|---|
|  |  |  | Node parentNode = nodeService.selectById(node.getParentId()); | 
|---|
|  |  |  | if (parentNode == null || parentNode.getStatus() == 0) { | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/node/update/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R update(Node node){ | 
|---|
|  |  |  | //        Node node1 = nodeService.selectByUuid(node.getName()); | 
|---|
|  |  |  | //        if (!Cools.isEmpty(node1)) { | 
|---|
|  |  |  | //            throw new CoolException("该编号/名称已存在"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | if (Cools.isEmpty(node) || null==node.getId()){ | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | nodeUtils.executePath(node); | 
|---|
|  |  |  | node.setPath(nodeUtils.path.toString()); | 
|---|
|  |  |  | node.setNamePath(nodeUtils.pathName.toString()); | 
|---|
|  |  |  | node.setUuid(node.getName()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | manLocDetlMapper.updateLocNo0(node.getId(),node.getName()); | 
|---|
|  |  |  | node.setUpdateBy(getUserId()); | 
|---|
|  |  |  | node.setUpdateTime(new Date()); | 
|---|
|  |  |  | nodeService.updateById(node); | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok("成功同步"+listener.getTotal()+"个货位"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /*************************************** 入库出相关 ***********************************************/ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/work/stock/pakin") | 
|---|
|  |  |  | @ManagerAuth(memo = "入库") | 
|---|
|  |  |  | public R stockPakin(@RequestBody PakinParam number) { | 
|---|
|  |  |  | Node node = nodeService.selectOne(new EntityWrapper<Node>() | 
|---|
|  |  |  | .eq("id", number.getNodeId())); | 
|---|
|  |  |  | if (node.getType() != 3) { | 
|---|
|  |  |  | return R.error("仅可选择货位"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return nodeService.stockPakin(number, getUserId(), getHostId(),getUser()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/work/stock/pakout") | 
|---|
|  |  |  | @ManagerAuth(memo = "出库") | 
|---|
|  |  |  | public R initPakout(@RequestBody List<InitPakoutParam> params) { | 
|---|
|  |  |  | return nodeService.initPakout(params, getUserId(), getHostId(),getUser()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping(value = "/work/empty/stock") | 
|---|
|  |  |  | public R getGroupEmptyStock(@RequestParam(required = false) String sourceLocNo) { | 
|---|
|  |  |  | List<Node> allEmptys = nodeService.selectList(new EntityWrapper<Node>() | 
|---|
|  |  |  | .eq("type","3")); | 
|---|
|  |  |  | return R.ok().add(allEmptys); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @RequestMapping("/work/move/start") | 
|---|
|  |  |  | @ManagerAuth(memo = "库位移转") | 
|---|
|  |  |  | public R locMoveStart(@RequestParam String sourceLocNo, | 
|---|
|  |  |  | @RequestParam String targetLocNo) { | 
|---|
|  |  |  | nodeService.locMove(sourceLocNo, targetLocNo, getUserId(),getUser()); | 
|---|
|  |  |  | return R.ok("移库启动成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @RequestMapping(value = "/node/select/{id}/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R getById(@PathVariable("id") String id) { | 
|---|
|  |  |  | Node node = nodeService.selectOne(new EntityWrapper<Node>() | 
|---|
|  |  |  | .eq("uuid",id)); | 
|---|
|  |  |  | return R.ok(node); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/node/init/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "平库库位初始化") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R init(NodeInitPatam param) { | 
|---|
|  |  |  | List<Node> list = new ArrayList<>(); | 
|---|
|  |  |  | EntityWrapper<Node> nodeEntityWrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | nodeEntityWrapper.eq("id",param.getValue()); | 
|---|
|  |  |  | nodeEntityWrapper.eq("name",param.getName()); | 
|---|
|  |  |  | //        nodeService.delete(new EntityWrapper<Node>().eq("parent_id",param.getValue())); | 
|---|
|  |  |  | Node node = nodeService.selectOne(nodeEntityWrapper); | 
|---|
|  |  |  | String[] string = node.getNamePath().split(","); | 
|---|
|  |  |  | int tno=1; int no=1; | 
|---|
|  |  |  | for (int b=param.getStartBay(); b<=param.getEndBay(); b++) { | 
|---|
|  |  |  | for (int r=param.getStartRow(); r<=param.getEndRow(); r++){ | 
|---|
|  |  |  | for (int l=param.getStartLev(); l<=param.getEndLev(); l++) { | 
|---|
|  |  |  | // 获取库位号 | 
|---|
|  |  |  | String locNo; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (param.getName().equals("DT-B")){ | 
|---|
|  |  |  | if (b == 2 || b ==4 || b == 7){ | 
|---|
|  |  |  | if (l == 1){ | 
|---|
|  |  |  | locNo = param.getName()+"T-" +String.format("%02d", tno) + String.format("%02d", r) + String.format("%02d", l); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | locNo = null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | locNo = param.getName()+"-" +String.format("%02d", no) + String.format("%02d", r) + String.format("%02d", l); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else if (param.getName().equals("DT-C") || param.getName().equals("DT-D")){ | 
|---|
|  |  |  | if (b == 3 || b ==6 || b == 9 || b == 12 || b == 15 || b == 17 || b == 20 || b == 23){ | 
|---|
|  |  |  | if (l == 1){ | 
|---|
|  |  |  | locNo = param.getName()+"T-" +String.format("%02d", tno) + String.format("%02d", r) + String.format("%02d", l); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | locNo = null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | locNo = param.getName()+"-" +String.format("%02d", no) + String.format("%02d", r) + String.format("%02d", l); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | locNo = param.getName()+String.format("%02d", r) + String.format("%02d", b) + String.format("%02d", l); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //客户要求格式位A-01-01-01 | 
|---|
|  |  |  | StringBuilder sb = new StringBuilder(locNo); | 
|---|
|  |  |  | sb.insert(sb.length()-4,"-"); | 
|---|
|  |  |  | sb.insert(sb.length()-2,"-"); | 
|---|
|  |  |  | locNo = sb.toString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (locNo == null){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Node> nodeList = nodeService.selectList(new EntityWrapper<Node>().eq("name", locNo)); | 
|---|
|  |  |  | if (!Cools.isEmpty(nodeList)){ | 
|---|
|  |  |  | throw new CoolException("库位号重复"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Date now =  new Date(); | 
|---|
|  |  |  | Node node1 = new Node(); | 
|---|
|  |  |  | node1.setUuid(locNo); | 
|---|
|  |  |  | node1.setName(locNo); | 
|---|
|  |  |  | node1.setParentId(node.getId()); | 
|---|
|  |  |  | node1.setParentName(node.getName()); | 
|---|
|  |  |  | node1.setType(3); | 
|---|
|  |  |  | node1.setPath(node.getPath()+","+node.getId()); | 
|---|
|  |  |  | node1.setNamePath(node.getNamePath()+","+node.getName()); | 
|---|
|  |  |  | node1.setLevel(3); | 
|---|
|  |  |  | node1.setStatus(1); | 
|---|
|  |  |  | node1.setCreateBy(getUserId()); | 
|---|
|  |  |  | node1.setCreateTime(now); | 
|---|
|  |  |  | node1.setUpdateBy(getUserId()); | 
|---|
|  |  |  | node1.setUpdateTime(now); | 
|---|
|  |  |  | node1.setRow1(r); | 
|---|
|  |  |  | node1.setBay1(b); | 
|---|
|  |  |  | node1.setLev1(l); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!nodeService.insert(node1)){ | 
|---|
|  |  |  | return R.error("数据插入失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (param.getName().equals("DT-B")){ | 
|---|
|  |  |  | if (b == 2 || b ==4 || b == 7){ | 
|---|
|  |  |  | tno++; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | no++; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else if (param.getName().equals("DT-C") || param.getName().equals("DT-D")){ | 
|---|
|  |  |  | if (b == 3 || b ==6 || b == 9 || b == 12 || b == 15 || b == 17 || b == 20 || b == 23){ | 
|---|
|  |  |  | tno++; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | no++; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        nodeService.delete(new EntityWrapper<Node>().eq("parent_id",param.getValue())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        if (nodeService.insertBatch(list)){ | 
|---|
|  |  |  | //            return R.error("数据插入失败"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | return R.ok("初始化成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/node/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 = "/node/all/get/loc") | 
|---|
|  |  |  | public R getarea(){ | 
|---|
|  |  |  | EntityWrapper<Node> nodeEntityWrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | nodeEntityWrapper.eq("type",2); | 
|---|
|  |  |  | List<Node> list = nodeService.selectList(nodeEntityWrapper); | 
|---|
|  |  |  | List<KeyValueVo> keyValueVoList = new ArrayList<>(); | 
|---|
|  |  |  | for (Node node : list){ | 
|---|
|  |  |  | KeyValueVo vo = new KeyValueVo(); | 
|---|
|  |  |  | vo.setName(node.getName()); | 
|---|
|  |  |  | vo.setValue(node.getId()); | 
|---|
|  |  |  | keyValueVoList.add(vo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(keyValueVoList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @RequestMapping(value = "/node/recommendLoc") | 
|---|
|  |  |  | public R recommendLoc(@RequestParam String matnr){ | 
|---|
|  |  |  | List<String> remmendLoc = nodeService.getRemmendLoc(matnr); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok(remmendLoc); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/node/updateStatus") | 
|---|
|  |  |  | @ManagerAuth(memo = "库位冻结") | 
|---|
|  |  |  | public R updateStockFreeze(@RequestParam String param){ | 
|---|
|  |  |  | List<Node> list = JSONArray.parseArray(param, Node.class); | 
|---|
|  |  |  | if (Cools.isEmpty(list)){ | 
|---|
|  |  |  | return R.error("无数据"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (Node node : list){ | 
|---|
|  |  |  | node.setStatus(0); | 
|---|
|  |  |  | if (nodeService.updateStockFreeze(node.getName(), node.getStatus()) != 1){ | 
|---|
|  |  |  | return R.error(node.getName()+"冻结失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("冻结成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/node/updateDisStatus") | 
|---|
|  |  |  | @ManagerAuth(memo = "库位解除冻结") | 
|---|
|  |  |  | public R updateStockDisFreeze(@RequestParam String param){ | 
|---|
|  |  |  | List<Node> list = JSONArray.parseArray(param, Node.class); | 
|---|
|  |  |  | if (Cools.isEmpty(list)){ | 
|---|
|  |  |  | return R.error("无数据"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (Node node : list){ | 
|---|
|  |  |  | node.setStatus(1); | 
|---|
|  |  |  | if (nodeService.updateStockFreeze(node.getName(), node.getStatus()) != 1){ | 
|---|
|  |  |  | return R.error(node.getName()+"解除冻结失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("解冻成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|