diff --git a/src/main/java/com/dreamchaser/depository_manage/controller/PlaceController.java b/src/main/java/com/dreamchaser/depository_manage/controller/PlaceController.java index 7d39304a..b45e757b 100644 --- a/src/main/java/com/dreamchaser/depository_manage/controller/PlaceController.java +++ b/src/main/java/com/dreamchaser/depository_manage/controller/PlaceController.java @@ -71,6 +71,7 @@ public class PlaceController { /** * 用于创建库位 + * * @param map * @return */ @@ -87,7 +88,7 @@ public class PlaceController { String min = (String) map.get("min"); String max = (String) map.get("max"); // String code = String.format("%02d", place_x) + String.format("%02d", place_y) + String.format("%02d", place_z); - String code = String.format("%02d", place_x) + String.format("%02d", place_z); + String code = String.format("%02d", place_x) + String.format("%02d", place_z); insert.put("x", place_x); // insert.put("y", place_y); insert.put("z", place_z); @@ -107,12 +108,11 @@ public class PlaceController { } else { insert.put("max", 0); } - insert.put("state",1); - insert.put("quantity",0); - insert.put("flagType",1); + insert.put("state", 1); + insert.put("quantity", 0); + insert.put("flagType", 1); success += placeService.InsertPlace(insert); - } - else if("list".equals(type)){ + } else if ("list".equals(type)) { //获取起始、终止行 Integer place_start_x = ObjectFormatUtil.toInteger(map.get("place_start_x")); Integer place_end_x = ObjectFormatUtil.toInteger(map.get("place_end_x")); @@ -124,50 +124,48 @@ public class PlaceController { Integer place_end_z = ObjectFormatUtil.toInteger(map.get("place_end_z")); // 计算所需库位数目 // total = (place_end_x - place_start_x) * (place_end_y - place_start_y) * (place_end_z - place_start_z); - total = (place_end_x - place_start_x + 1) * (place_end_z - place_start_z + 1); + total = (place_end_x - place_start_x + 1) * (place_end_z - place_start_z + 1); String min = (String) map.get("min"); String max = (String) map.get("max"); Depository depository = depositoryService.findDepositoryById(ObjectFormatUtil.toInteger(map.get("depositoryId"))); String depositoryCode = depository.getCode(); for (int i = place_start_x; i <= place_end_x; i++) { // for (int j = place_start_y; j < place_end_y; j++) { - for (int k = place_start_z; k <= place_end_z; k++) { + for (int k = place_start_z; k <= place_end_z; k++) { // String code = String.format("%02d", i) + String.format("%02d", j) + String.format("%02d", k); - String code = String.format("%02d", i) + String.format("%02d", k); - insert.put("x",i); + String code = String.format("%02d", i) + String.format("%02d", k); + insert.put("x", i); // insert.put("y",j); - insert.put("z",k); - insert.put("code",code); - String kingdeeCode = depositoryCode.substring(depositoryCode.length() - 2) + code; - insert.put("did", map.get("depositoryId")); - insert.put("kingdeecode", kingdeeCode); - insert.put("min",min); - insert.put("max",max); - insert.put("state",1); - insert.put("quantity",0); - insert.put("flagType",1); - success += placeService.InsertPlace(insert); - } + insert.put("z", k); + insert.put("code", code); + String kingdeeCode = depositoryCode.substring(depositoryCode.length() - 2) + code; + insert.put("did", map.get("depositoryId")); + insert.put("kingdeecode", kingdeeCode); + insert.put("min", min); + insert.put("max", max); + insert.put("state", 1); + insert.put("quantity", 0); + insert.put("flagType", 1); + success += placeService.InsertPlace(insert); + } // } } - } - else{ + } else { throw new MyException("所需请求参数缺失!"); } if ("one".equals(type)) { return CrudUtil.insertHandle(success, 1); - } else if("list".equals(type)){ - return CrudUtil.insertHandle(success,total); - }else{ + } else if ("list".equals(type)) { + return CrudUtil.insertHandle(success, total); + } else { throw new MyException("请求参数错误!"); } } - @PostMapping("/addTray") - public RestResponse addTray(@RequestBody Map map){ + public RestResponse addTray(@RequestBody Map map) { String type = (String) map.get("type"); Map insert = new HashMap<>(); Integer success = 0; @@ -180,7 +178,12 @@ public class PlaceController { insert.put("min", 0); } if (!"".equals(max)) { - insert.put("max", map.get("max")); + Double maxQuantity = ObjectFormatUtil.toDouble(max); + if (maxQuantity >= 999999999) { + insert.put("max", 999999999); + } else { + insert.put("max", map.get("max")); + } } else { insert.put("max", 0); } @@ -189,46 +192,48 @@ public class PlaceController { // 获取当前仓库的托盘数量 Integer countForTray = placeService.findPlaceCoutnByTypeForFlag(2, ObjectFormatUtil.toInteger(depositoryId)); if ("one".equals(type)) { - String code = "F"+String.format("%02d",countForTray+1); + String code = "F" + String.format("%02d", countForTray + 1); insert.put("code", code); - insert.put("state",1); - insert.put("quantity",0); - insert.put("flagType",2); + insert.put("state", 1); + insert.put("quantity", 0); + insert.put("flagType", 2); success += placeService.InsertPlace(insert); - }else if("list".equals(type)){ + } else if ("list".equals(type)) { Integer num = ObjectFormatUtil.toInteger(map.get("num")); - insert.put("state",1); - insert.put("quantity",0); - insert.put("flagType",2); + insert.put("state", 1); + insert.put("quantity", 0); + insert.put("flagType", 2); total = num; for (int i = 1; i <= num; i++) { - String code = "F"+String.format("%02d",countForTray+i); + String code = "F" + String.format("%02d", countForTray + i); insert.put("code", code); success += placeService.InsertPlace(insert); } } if ("one".equals(type)) { return CrudUtil.insertHandle(success, 1); - } else if("list".equals(type)){ - return CrudUtil.insertHandle(success,total); - }else{ + } else if ("list".equals(type)) { + return CrudUtil.insertHandle(success, total); + } else { throw new MyException("请求参数错误!"); } } + /** * 将库位状态改为删除 + * * @param map * @return */ @PostMapping("/deletePlace") - public RestResponse deletePlace(@RequestBody Map map){ - if (map.containsKey("id")){ - Integer id= ObjectFormatUtil.toInteger(map.get("id")); - return CrudUtil.deleteHandle(placeService.changeStateToDeletedById(id),1); - }else if (map.containsKey("ids")){ - List ids=(List) map.get("ids"); - return CrudUtil.deleteHandle(placeService.changeStateToDeletedByIds(ids),ids.size()); - }else { + public RestResponse deletePlace(@RequestBody Map map) { + if (map.containsKey("id")) { + Integer id = ObjectFormatUtil.toInteger(map.get("id")); + return CrudUtil.deleteHandle(placeService.changeStateToDeletedById(id), 1); + } else if (map.containsKey("ids")) { + List ids = (List) map.get("ids"); + return CrudUtil.deleteHandle(placeService.changeStateToDeletedByIds(ids), ids.size()); + } else { throw new MyException("所需请求参数缺失!"); } } @@ -237,11 +242,11 @@ public class PlaceController { * 修改库位信息 */ @PostMapping("/place_edit") - public RestResponse placeEdit(@RequestBody Map map){ - if(map.containsKey("state")){ - map.put("state",1); - }else{ - map.put("state",2); + public RestResponse placeEdit(@RequestBody Map map) { + if (map.containsKey("state")) { + map.put("state", 1); + } else { + map.put("state", 2); } Object id = map.get("id"); // 获取当前修改的库位 @@ -251,22 +256,22 @@ public class PlaceController { // Integer place_y = ObjectFormatUtil.toInteger(map.get("place_y")); Integer place_z = ObjectFormatUtil.toInteger(map.get("place_z")); String newCode = ""; - if(Integer.compare(placeById.getX(),place_x) != 0 || Integer.compare(placeById.getZ(),place_z) != 0){ + if (Integer.compare(placeById.getX(), place_x) != 0 || Integer.compare(placeById.getZ(), place_z) != 0) { // 如果更改了行层 // String code = String.format("%02d", place_x) + String.format("%02d", place_y) + String.format("%02d", place_z); - newCode = String.format("%02d", place_x) + String.format("%02d", place_z); - }else{ - newCode = (String)map.get("code"); + newCode = String.format("%02d", place_x) + String.format("%02d", place_z); + } else { + newCode = (String) map.get("code"); } String oldCode = placeById.getCode(); - if(!newCode.equals(oldCode)){ + if (!newCode.equals(oldCode)) { // 如果编码发生改变 // 获取当前修改后的库位编码是否存在 Place placeByDidAndCode = placeService.findPlaceByDidAndCode(placeById.getDid(), newCode); - if(placeByDidAndCode != null){ + if (placeByDidAndCode != null) { // 如果存在 - return new RestResponse("",12345,new StatusInfo("修改失败","该编码或位置已经存在")); + return new RestResponse("", 12345, new StatusInfo("修改失败", "该编码或位置已经存在")); } } String min = (String) map.get("min"); @@ -275,7 +280,7 @@ public class PlaceController { // update.put("y", place_y); update.put("z", place_z); update.put("code", newCode); - update.put("kingdeecode",placeById.getKingdeecode().substring(0,2) + newCode); + update.put("kingdeecode", placeById.getKingdeecode().substring(0, 2) + newCode); update.put("oldCode", oldCode); update.put("did", map.get("did")); if (!"".equals(min)) { @@ -284,26 +289,31 @@ public class PlaceController { update.put("min", 0); } if (!"".equals(max)) { - update.put("max", map.get("max")); + Double maxQuantity = ObjectFormatUtil.toDouble(max); + if (maxQuantity >= 999999999) { + update.put("max", 999999999); + } else { + update.put("max", map.get("max")); + } } else { - update.put("max", 500); + update.put("max", 50000); } update.put("id", id); - return CrudUtil.insertHandle(placeService.UpdatePlace(update),1); + return CrudUtil.insertHandle(placeService.UpdatePlace(update), 1); } @PostMapping("/tray_edit") - public RestResponse trayEdit(@RequestBody Map map){ - if(map.containsKey("state")){ - map.put("state",1); - }else{ - map.put("state",2); + public RestResponse trayEdit(@RequestBody Map map) { + if (map.containsKey("state")) { + map.put("state", 1); + } else { + map.put("state", 2); } String code = (String) map.get("code"); Integer depositoryId = ObjectFormatUtil.toInteger(map.get("did")); Place placeByDidAndCode = placeService.findPlaceByDidAndCode(depositoryId, code); - if(placeByDidAndCode != null){ - return new RestResponse("",12345,new StatusInfo("修改失败","该编码已经存在")); + if (placeByDidAndCode != null) { + return new RestResponse("", 12345, new StatusInfo("修改失败", "该编码已经存在")); } Map update = new HashMap<>(); String min = (String) map.get("min"); @@ -314,30 +324,36 @@ public class PlaceController { update.put("min", 0); } if (!"".equals(max)) { - update.put("max", map.get("max")); + Double maxQuantity = ObjectFormatUtil.toDouble(max); + if (maxQuantity >= 999999999) { + update.put("max", 999999999); + } else { + update.put("max", map.get("max")); + } } else { - update.put("max", 500); + update.put("max", 50000); } - update.put("code",code); + update.put("code", code); update.put("id", map.get("id")); - return CrudUtil.insertHandle(placeService.UpdatePlace(update),1); } + return CrudUtil.insertHandle(placeService.UpdatePlace(update), 1); + } @PostMapping("/editPlaceState") - public RestResponse editPlaceState(@RequestBody Map map) { + public RestResponse editPlaceState(@RequestBody Map map) { if (map.containsKey("state")) { map.put("state", 1); } else { map.put("state", 2); } - return CrudUtil.insertHandle(placeService.editPlaceState(map),1); + return CrudUtil.insertHandle(placeService.editPlaceState(map), 1); } // 根据物料编号获取库位 @PostMapping("/findPlaceByMid") - public RestResponse findPlaceByMid(@RequestBody Map map, HttpServletRequest request){ + public RestResponse findPlaceByMid(@RequestBody Map map, HttpServletRequest request) { String token = request.getHeader("user-token"); - if(token == null){ + if (token == null) { token = (String) request.getSession().getAttribute("userToken"); } UserByPort userToken = AuthenticationTokenPool.getUserToken(token); @@ -355,18 +371,18 @@ public class PlaceController { depositoryIdList.add(depository.getId()); } for (RoleAndDepository depository : depositoryAndRole) { - if(!depositoryIdList.contains(depository.getDepositoryId())){ + if (!depositoryIdList.contains(depository.getDepositoryId())) { depositoryIdList.add(depository.getDepositoryId()); } } List inventoryPList = new ArrayList<>(); - for (Integer depositoryId:depositoryIdList - ) { + for (Integer depositoryId : depositoryIdList + ) { param.put("depositoryId", depositoryId); // 查找当前用户部门仓库中是否存在该物料 inventoryPList.addAll(materialService.findInventory(param)); } - for (Integer depositoryId:depositoryIdList){ + for (Integer depositoryId : depositoryIdList) { for (InventoryP inventory : inventoryPList) { List placeByMidAndDid = placeService.findPlaceByMidAndDid(inventory.getId(), depositoryId); for (PlaceP placeP : placeByMidAndDid) { @@ -380,18 +396,19 @@ public class PlaceController { } return new RestResponse(placeList); } + // 根据物料编码以及仓库编号获取具体库位 @PostMapping("/findPlaceByMcodeAndDid") - public RestResponse findPlaceByMcodeAndDid(@RequestBody Map map,HttpServletRequest request){ + public RestResponse findPlaceByMcodeAndDid(@RequestBody Map map, HttpServletRequest request) { List inventory = materialService.findInventory(map); List placeList = new ArrayList<>(); - if(inventory.size() > 0){ // 如果有当前物料 + if (inventory.size() > 0) { // 如果有当前物料 for (int i = 0; i < inventory.size(); i++) { InventoryP materialP = inventory.get(i); List placeByMidAndDid = placeService.findPlaceByMidAndDid(materialP.getId(), ObjectFormatUtil.toInteger(map.get("depositoryId"))); for (int j = 0; j < placeByMidAndDid.size(); j++) { int index = placeList.indexOf(placeByMidAndDid.get(j)); - if(index == -1){ + if (index == -1) { placeList.add(placeByMidAndDid.get(j)); } } @@ -402,7 +419,7 @@ public class PlaceController { // 构造仓库二维码 @PostMapping("/createQrCode") - public RestResponse createQrCode(@RequestBody Map map) { + public RestResponse createQrCode(@RequestBody Map map) { Integer pid = ObjectFormatUtil.toInteger(map.get("pid")); @@ -411,7 +428,7 @@ public class PlaceController { // 二维码保存信息 Place placeById = placeService.findPlaceById(pid); Depository depositoryById = depositoryService.findDepositoryById(placeById.getDid()); - return RestResponse.CreateBarCode(qrCode,depositoryById.getDname() + "-" + placeById.getCode()); + return RestResponse.CreateBarCode(qrCode, depositoryById.getDname() + "-" + placeById.getCode()); } catch (IOException e) { return new RestResponse("err: " + e.getMessage(), 678, new StatusInfo("失败", "请联系开发人员")); } @@ -420,39 +437,39 @@ public class PlaceController { // 用于扫描入库位置 @PostMapping("/qywxApplicationInScanQrCode") - public RestResponse qywxApplicationInScanQrCode(@RequestBody Map map,HttpServletRequest request){ + public RestResponse qywxApplicationInScanQrCode(@RequestBody Map map, HttpServletRequest request) { // 获取扫描的码值 String qrCode = (String) map.get("qrCode"); // 根据二维码获取对应位置信息 PidOrDidAndCode locationByQrCode = placeService.findLocationByQrCode(qrCode); - Map result = new HashMap<>(); - result.put("flag",0); - if(locationByQrCode != null){ + Map result = new HashMap<>(); + result.put("flag", 0); + if (locationByQrCode != null) { // 获取当前标志位(1为库位2为仓库) Integer flag = locationByQrCode.getFlag(); - if(Integer.compare(1,flag) == 0){ + if (Integer.compare(1, flag) == 0) { // 如果当前位置为库位 // 获取当前库位 Place place = placeService.findPlaceById(Integer.parseInt(locationByQrCode.getPid().toString())); PlaceP placeP = new PlaceP(place); - if(Integer.compare(0,placeP.getId()) == 0){ + if (Integer.compare(0, placeP.getId()) == 0) { // 如果是默认库位 placeP.setDepositoryName("默认库位-0000"); - }else { + } else { Depository depository = depositoryService.findDepositoryById(placeP.getDid()); - placeP.setDepositoryName(depository.getDname() + "-"+placeP.getCode()); + placeP.setDepositoryName(depository.getDname() + "-" + placeP.getCode()); } - result.put("flag",1); - result.put("place",placeP); - }else { + result.put("flag", 1); + result.put("place", placeP); + } else { // 如果当前位置为仓库 // 获取当前仓库 Depository depository = depositoryService.findDepositoryById(Integer.parseInt(locationByQrCode.getDepositoryId().toString())); - result.put("flag",2); - result.put("depository",depository); + result.put("flag", 2); + result.put("depository", depository); } } return new RestResponse(result);