diff --git a/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryController.java b/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryController.java index b0666724..c951e5a5 100644 --- a/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryController.java +++ b/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryController.java @@ -599,8 +599,7 @@ public class DepositoryController { } - } - else { + } else { // 获取本周至今仓库的入/出库数量 Future futureForBarChartData = completionService.submit(new distributeTasks(depositoryAllNameAndId, type, 1, userByPort, depositoryName)); @@ -1172,12 +1171,60 @@ public class DepositoryController { } } + @PostMapping("/setManagerRole") + public RestResponse setManagerRole(@RequestBody Map map, HttpServletRequest request) { + if (map.containsKey("permissionType") && map.containsKey("setType")) { + // 获取当前登录的用户 + String token = request.getHeader("user-token"); + if (token == null) { + token = (String) request.getSession().getAttribute("userToken"); + } + UserByPort userToken = AuthenticationTokenPool.getUserToken(token); + map.put("userId", userToken.getId()); + map.put("uid", userToken.getId()); + // 需要添加的数量 + Integer count = ObjectFormatUtil.toInteger(map.get("count")); + // 操作时影响的行数 + Integer integer = 0; + if (count == 0) { + // 如果要删除 + map.put("depositoryIds", new ArrayList<>()); + integer = roleService.delManangerForPermission(map); + count = integer; + } else { + // 如果不是删除 + integer = roleService.setManagerForRole(map); + } + return CrudUtil.insertHandle(count, integer); + } else { + throw new MyException("缺少必要参数"); + } + } + + /** + * 获取当前条件下的可见仓库 + * + * @param map + * @return + */ @PostMapping("/findWarehouseVisiblePermission") public RestResponse findWarehouseVisiblePermission(@RequestBody Map map) { List list = roleService.findDepositoryIdForWarehouseVisiblePermissionByCondition(map); return new RestResponse(list); } + /** + * 获取当前条件下用户管理的仓库 + * + * @param map + * @return + */ + @PostMapping("/findWareHouseForManager") + public RestResponse findWareHouseForManager(@RequestBody Map map) { + Map result = roleService.findWareHouseForManager(map); + return new RestResponse(result); + } + /** * 用于获取当前仓库的所有子类 * diff --git a/src/main/java/com/dreamchaser/depository_manage/controller/PageController.java b/src/main/java/com/dreamchaser/depository_manage/controller/PageController.java index fd831a51..3704ad7e 100644 --- a/src/main/java/com/dreamchaser/depository_manage/controller/PageController.java +++ b/src/main/java/com/dreamchaser/depository_manage/controller/PageController.java @@ -2794,7 +2794,7 @@ public class PageController { } UserByPort userToken = AuthenticationTokenPool.getUserToken(token); ModelAndView mv = new ModelAndView(); - mv.setViewName("pages/company/company-out"); + mv.setViewName("pages/company/company-out_back"); List administrationPList = LinkInterfaceUtil.findAllCompany(userKey, token); mv.addObject("administrationPList", administrationPList); mv.addObject("level", 3); diff --git a/src/main/java/com/dreamchaser/depository_manage/mapper/RoleMapper.java b/src/main/java/com/dreamchaser/depository_manage/mapper/RoleMapper.java index 411ccf3d..5e3130c6 100644 --- a/src/main/java/com/dreamchaser/depository_manage/mapper/RoleMapper.java +++ b/src/main/java/com/dreamchaser/depository_manage/mapper/RoleMapper.java @@ -95,6 +95,7 @@ public interface RoleMapper { /** * 根据类型id获取userId + * * @param mtId * @return */ @@ -175,43 +176,63 @@ public interface RoleMapper { Integer deleteRoleAndMaterialTypeById(Integer id); + /** + * 根据条件删除用户管理的仓库 + * @param map + * @return + */ + Integer deleteRoleAndDepositoryByCondition(Map map); + + /** + * 根据条件删除用户管理的物料类型 + * @param map + * @return + */ + Integer deleteRoleAndMaterialTypeByCondition(Map map); + + /** * 用于添加添加仓库可见范围 + * * @param map 添加具体数据 * @return */ - Integer addWarehouseVisiblePermission(Map map); + Integer addWarehouseVisiblePermission(Map map); /** * 根据条件查询可见范围的数量 + * * @param map 待查询数据 * @return */ - Integer findWarehouseVisiblePermissionCountByCondition(Map map); + Integer findWarehouseVisiblePermissionCountByCondition(Map map); /** * 根据条件删除仓库可见范围 + * * @param map * @return */ - Integer delWarehouseVisiblePermissionByCondition(Map map); + Integer delWarehouseVisiblePermissionByCondition(Map map); /** * 根据条件获取在可视范围内的仓库id + * * @param map * @return */ - List findDepositoryIdForWarehouseVisiblePermissionByCondition(Map map); + List findDepositoryIdForWarehouseVisiblePermissionByCondition(Map map); /** * 根据条件获取可视范围内的仓库数量 + * * @param map * @return */ - Integer findDepositoryIDCountForWarehouseVisiblePermissionByCondition(Map map); + Integer findDepositoryIDCountForWarehouseVisiblePermissionByCondition(Map map); } diff --git a/src/main/java/com/dreamchaser/depository_manage/mapper/RoleMapper.xml b/src/main/java/com/dreamchaser/depository_manage/mapper/RoleMapper.xml index 659587f9..a716c617 100644 --- a/src/main/java/com/dreamchaser/depository_manage/mapper/RoleMapper.xml +++ b/src/main/java/com/dreamchaser/depository_manage/mapper/RoleMapper.xml @@ -94,19 +94,16 @@ - INSERT INTO postoruserrole ( - id, classes, role,userid,did - ) VALUES ( - #{id}, - #{classes}, - #{authority}, - #{userid}, - #{depositoryId} - ) + INSERT ignore INTO postoruserrole (id, classes, role, userid, did) + VALUES (#{id}, + #{classes}, + #{authority}, + #{userid}, + #{depositoryId}) - INSERT INTO postoruserrole ( + INSERT ignore INTO postoruserrole ( id, classes, role,userid,did ) VALUES @@ -121,18 +118,15 @@ - INSERT INTO mtanduserrole ( - id, classes,uid,mtid - ) VALUES ( - #{id}, - #{classes}, - #{userid}, - #{mtid} - ) + INSERT ignore INTO mtanduserrole (id, classes, uid, mtid) + VALUES (#{id}, + #{classes}, + #{userid}, + #{mtid}) - INSERT INTO mtanduserrole ( + INSERT ignore INTO mtanduserrole ( id, classes,uid,mtid ) VALUES @@ -154,16 +148,29 @@ - delete from postoruserrole WHERE id = #{id} + delete + from postoruserrole + WHERE id = #{id} - delete from mtanduserrole WHERE id = #{id} + delete + from mtanduserrole + WHERE id = #{id} @@ -323,8 +358,50 @@ + + delete from postoruserrole + where classes = #{classes} + + and userid in + + #{userid} + + + + and userid = #{userId} + + + and did in + + #{did} + + + + + + + delete from mtanduserrole + where classes = #{classes} + + and uid in + + #{userid} + + + + and uid = #{uid} + + + and mtid in + + #{mtid} + + + + + - - diff --git a/src/main/java/com/dreamchaser/depository_manage/pojo/RoleAndMaterialType.java b/src/main/java/com/dreamchaser/depository_manage/pojo/RoleAndMaterialType.java index c76b1b60..4314efc6 100644 --- a/src/main/java/com/dreamchaser/depository_manage/pojo/RoleAndMaterialType.java +++ b/src/main/java/com/dreamchaser/depository_manage/pojo/RoleAndMaterialType.java @@ -15,7 +15,7 @@ public class RoleAndMaterialType { /** * 类型id */ - private Integer mtid; + private Long mtid; /** * 类型名称 */ diff --git a/src/main/java/com/dreamchaser/depository_manage/service/RoleService.java b/src/main/java/com/dreamchaser/depository_manage/service/RoleService.java index f797a7ad..e8cef7e7 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/RoleService.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/RoleService.java @@ -164,20 +164,42 @@ public interface RoleService { /** - * 用于删除权限 + * 用于添加管理权限 + * @param map 添加具体数据 + * @return + */ + Integer setManagerForRole(Map map); + + + /** + * 用于删除开放仓库 * @param map 待删除数据 */ Integer delWarehouseVisiblePermission(Map map); + /** + * 用于删除权限 + * @param map 待删除数据 + * @return + */ + Integer delManangerForPermission(Map map); + /** - * 根据调剂获取在可视范围内的仓库id - * @param map 待查询调剂 + * 根据条件获取在可视范围内的仓库id + * @param map 待查询条件 * @return */ List findDepositoryIdForWarehouseVisiblePermissionByCondition(Map map); + /** + * 根据条件获取管理的的仓库id + * @param map 待查询条件 + * @return + */ + Map findWareHouseForManager(Map map); + /** * 用于查询当前用户所被赋予的可见仓库 * @param userToken 待查询用户 diff --git a/src/main/java/com/dreamchaser/depository_manage/service/impl/CompanyServiceImpl.java b/src/main/java/com/dreamchaser/depository_manage/service/impl/CompanyServiceImpl.java index 4f667696..94a42193 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/impl/CompanyServiceImpl.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/impl/CompanyServiceImpl.java @@ -265,6 +265,7 @@ public class CompanyServiceImpl implements CompanyService { */ @Override public JSONArray BuildOrgAndPostThree(String userKey,String token) { + JSONArray orgAndPostThree = LinkInterfaceUtil.getOrgAndPostThree(userKey,token); // 将获取到的json字符串进行修改为使用的结构 String replace = JSONObject.toJSONString(orgAndPostThree).replace("name", "title").replace("child", "children"); diff --git a/src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialServiceImpl.java b/src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialServiceImpl.java index 1dc8ba03..7a009b23 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialServiceImpl.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialServiceImpl.java @@ -130,7 +130,7 @@ public class MaterialServiceImpl implements MaterialService { if (map.containsKey("barCode")) { materialMapper.addBarCodeAndMcode(map); } - map.put("createTime",System.currentTimeMillis()); + map.put("createTime", System.currentTimeMillis()); return materialMapper.insertMaterial(map); } @@ -183,7 +183,7 @@ public class MaterialServiceImpl implements MaterialService { Long producedDate = DateUtil.DateTimeByDayToTimeStamp(map.get("producedDate").toString()); map.put("producedDate", producedDate); } - map.put("updateTime",System.currentTimeMillis()); + map.put("updateTime", System.currentTimeMillis()); return materialMapper.updateMaterial(map); } @@ -683,9 +683,9 @@ public class MaterialServiceImpl implements MaterialService { */ @Override public Integer changeStateToDeletedById(Integer id) { - Map map = new HashMap<>(); - map.put("id",id); - map.put("updateTime",System.currentTimeMillis()); + Map map = new HashMap<>(); + map.put("id", id); + map.put("updateTime", System.currentTimeMillis()); return materialMapper.changeStateToDeletedById(map); } @@ -697,9 +697,9 @@ public class MaterialServiceImpl implements MaterialService { */ @Override public Integer changeStateToDeletedByIds(List ids) { - Map map = new HashMap<>(); - map.put("list",ids); - map.put("updateTime",System.currentTimeMillis()); + Map map = new HashMap<>(); + map.put("list", ids); + map.put("updateTime", System.currentTimeMillis()); return materialMapper.changeStateToDeletedByIds(map); } @@ -731,7 +731,7 @@ public class MaterialServiceImpl implements MaterialService { */ @Override public Integer updateStateByParam(Map map) { - map.put("updateTime",System.currentTimeMillis()); + map.put("updateTime", System.currentTimeMillis()); return materialMapper.updateStateByParam(map); } @@ -743,7 +743,7 @@ public class MaterialServiceImpl implements MaterialService { */ @Override public Integer updateStateByTypeId(Map map) { - map.put("updateTime",System.currentTimeMillis()); + map.put("updateTime", System.currentTimeMillis()); return materialMapper.updateStateByTypeId(map); } @@ -870,7 +870,7 @@ public class MaterialServiceImpl implements MaterialService { int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1); BigDecimal bigDecimal = BigDecimal.valueOf(inventory.getPrice() / scale); double split_price = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - amounts = ObjectFormatUtil.sum(amounts,split_price * saveQuantity); + amounts = ObjectFormatUtil.sum(amounts, split_price * saveQuantity); unit = splitInfo.getNewUnit(); } @@ -2361,8 +2361,8 @@ public class MaterialServiceImpl implements MaterialService { e.printStackTrace(); } redisPool.getRedisTemplateByDb(15).opsForList().rightPush("wms_materialTree_result", JSON.toJSONString(result)); - redisPool.getRedisTemplateByDb(15).expire("wms_materialTree_result", DateUtil.getSecondsNextEarlyMorning(), TimeUnit.SECONDS); } + redisPool.getRedisTemplateByDb(15).expire("wms_materialTree_result", DateUtil.getSecondsNextEarlyMorning(), TimeUnit.SECONDS); // 关闭线程池 PublicConfig.closeThreadPool(exs); } @@ -2643,6 +2643,7 @@ public class MaterialServiceImpl implements MaterialService { /** * 用于完成出库任务时获取对应的库存数据 + * * @param map * @return */ @@ -2664,7 +2665,7 @@ public class MaterialServiceImpl implements MaterialService { } } else { // 如果不是默认库位 - map.put("placeId",pid); + map.put("placeId", pid); List placeAndMaterialByCondition = placeService.findPlaceAndMaterialByCondition(map); for (MaterialAndPlaceForViewP materialAndPlaceForViewP : placeAndMaterialByCondition) { midList.add(materialAndPlaceForViewP.getMid()); diff --git a/src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialTypeServiceImpl.java b/src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialTypeServiceImpl.java index 68a48c7d..a8f19a0a 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialTypeServiceImpl.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialTypeServiceImpl.java @@ -1,11 +1,14 @@ package com.dreamchaser.depository_manage.service.impl; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.dreamchaser.depository_manage.config.PublicConfig; import com.dreamchaser.depository_manage.entity.MaterialType; import com.dreamchaser.depository_manage.mapper.MaterialTypeMapper; +import com.dreamchaser.depository_manage.security.pool.RedisPool; import com.dreamchaser.depository_manage.service.MaterialTypeService; +import com.dreamchaser.depository_manage.utils.DateUtil; import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -22,34 +25,37 @@ import java.util.concurrent.*; public class MaterialTypeServiceImpl implements MaterialTypeService { @Autowired MaterialTypeMapper materialTypeMapper; + @Autowired + private RedisPool redisPool; /** * 插入一条物料类型记录 + * * @param map 参数map * @return 受影响的数量 */ @Override - public Integer insertMaterialType(Map map) { - if("".equals(map.get("materialTypeId"))){ - map.put("parentId",0); - }else{ - map.put("parentId",map.get("materialTypeId")); + public Integer insertMaterialType(Map map) { + if ("".equals(map.get("materialTypeId"))) { + map.put("parentId", 0); + } else { + map.put("parentId", map.get("materialTypeId")); map.remove("materialTypeId"); } Object oldId = map.get("oldId"); - if(oldId == null) { - Long parentId =Long.valueOf(map.get("parentId").toString()); + if (oldId == null) { + Long parentId = Long.valueOf(map.get("parentId").toString()); MaterialType materialTypeById = materialTypeMapper.findMaterialTypeByOldId(parentId); Integer size = 0; String firstName = ""; - if(materialTypeById == null){ + if (materialTypeById == null) { List materialTypeByParent = materialTypeMapper.findMaterialTypeByParent(Long.valueOf("0")); size = materialTypeByParent.size(); - }else{ + } else { List materialTypeByParent = materialTypeMapper.findMaterialTypeByParent(materialTypeById.getOldId()); size = materialTypeByParent.size(); firstName = materialTypeById.getOldId().toString(); - map.put("parentId",materialTypeById.getOldId()); + map.put("parentId", materialTypeById.getOldId()); } map.put("oldId", firstName + String.format("%02d", size + 1)); } @@ -58,45 +64,48 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { /** * 根据条件查询对应记录数目 + * * @param map * @return 对应数目 */ @Override public Integer findMaterialTypeCountByCondition(Map map) { Object state = 1; - if(map.containsKey("state")){ + if (map.containsKey("state")) { state = map.get("state"); } - map.put("state",state); + map.put("state", state); return materialTypeMapper.findMaterialTypeCountByCondition(map); } /** * 根据条件查询物料类型 + * * @param map * @return 符合条件的记录 */ @Override public List findMaterialTypeByCondition(Map map) { - Integer size = 10,page=1; - if (map.containsKey("size")){ - size= ObjectFormatUtil.toInteger(map.get("size")); + Integer size = 10, page = 1; + if (map.containsKey("size")) { + size = ObjectFormatUtil.toInteger(map.get("size")); map.put("size", size); } - if (map.containsKey("page")){ - page=ObjectFormatUtil.toInteger(map.get("page")); - map.put("begin",(page-1)*size); + if (map.containsKey("page")) { + page = ObjectFormatUtil.toInteger(map.get("page")); + map.put("begin", (page - 1) * size); } Object state = 1; - if(map.containsKey("state")){ + if (map.containsKey("state")) { state = map.get("state"); } - map.put("state",state); + map.put("state", state); return materialTypeMapper.findMaterialTypeByCondition(map); } /** * 查询所有物料类型 + * * @return 所有记录 */ @Override @@ -107,6 +116,7 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { /** * 查询所有顶级类型 + * * @return */ @Override @@ -116,6 +126,7 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { /** * 根据主键id完全删除记录 + * * @param id * @return 受影响数目 */ @@ -126,6 +137,7 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { /** * 根据多个主键id删除记录 + * * @param ids * @return 受影响数目 */ @@ -136,12 +148,13 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { /** * 修改物料类型 + * * @param map * @return 受影响条数 */ @Override public Integer updateMaterialType(Map map) { - if(map.containsKey("parentId")) { + if (map.containsKey("parentId")) { String parentId = (String) map.get("parentId"); if (parentId.isEmpty()) { map.put("parentId", 0); @@ -152,6 +165,7 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { /** * 根据主键id查询对应物料类型 + * * @param id * @return 对应记录 */ @@ -162,6 +176,7 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { /** * 根据类型名称查询物料类型 + * * @param name * @return */ @@ -177,6 +192,7 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { /** * 根据主键id将物料类型状态修改为删除 + * * @param id * @return 受影响条数 */ @@ -187,6 +203,7 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { /** * 根据多个主键ids将物料类型状态修改为删除 + * * @param ids * @return 受影响条数 */ @@ -197,6 +214,7 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { /** * 根据条件更改类型状态 + * * @param map * @return */ @@ -208,6 +226,7 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { /** * 获取当前类别下的所有类别 + * * @param mtId 待查询类别Id * @return */ @@ -228,12 +247,30 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { /** * 构造树形选择框 + * * @return */ @Override public List InitTreeMenus() { List list = new ArrayList<>(); - list = buildTree_New(InitTreeMenus_New(),Long.valueOf(0)); + List wms_materialTree_result = redisPool.getRedisTemplateByDb(15).opsForList().range("wms_materialTypeTree_result", 0, -1); + if (wms_materialTree_result != null && wms_materialTree_result.size() != 0) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + for (String s : wms_materialTree_result) { + JSONObject jsonObject = JSONObject.parseObject(s); + list.add(jsonObject); + } + return list; + } + list = buildTree_New(InitTreeMenus_New(), 0L); + for (Object obj : list) { + redisPool.getRedisTemplateByDb(15).opsForList().rightPush("wms_materialTypeTree_result", JSON.toJSONString(obj)); + } + redisPool.getRedisTemplateByDb(15).expire("wms_materialTypeTree_result", DateUtil.getSecondsNextEarlyMorning(), TimeUnit.SECONDS); return list; } @@ -300,43 +337,14 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { return list; } - // 用于执行测试新算法 - class TaskTest_New implements Callable { - - // 待处理的物料类型id列表 - List materialTypeIdList; - - public TaskTest_New(List materialTypeByCondition) { - this.materialTypeIdList = materialTypeByCondition; - } - - @Override - public Object call() throws Exception { - - // 定义树结构结果集 - List list = new ArrayList<>(); - // 查询当前物料类型id列表中的物料类型 - List materialTypeByOldIds = materialTypeMapper.findMaterialTypeByOldIds(materialTypeIdList); - - for (int i = 0; i < materialTypeByOldIds.size(); i++) { - MaterialType mt = materialTypeByOldIds.get(i); - Map map = InitTreeMenus(mt, new ArrayList<>()); - list.add(map); - } - return list; - } - - - } - // 构造树形组件数据模板 public Map InitTreeMenus(MaterialType mt, List children) { if (mt != null) { Map map = new HashMap<>(); map.put("title", mt.getTname()); map.put("id", mt.getOldId()); - map.put("parentId",mt.getParentId()); - map.put("children",children); + map.put("parentId", mt.getParentId()); + map.put("children", children); return map; } else { return null; @@ -345,11 +353,12 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { /** * 用于构造树结构 - * @param list 树列表 + * + * @param list 树列表 * @param parentId 父级id * @return */ - public List buildTree_New(List list,Long parentId){ + public List buildTree_New(List list, Long parentId) { // 定义树结构 List result = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { @@ -357,7 +366,7 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { JSONObject jsonObject = new JSONObject((Map) list.get(i)); // 获取当前父级id Long parentId1 = jsonObject.getLong("parentId"); - if(Long.compare(parentId,parentId1) == 0){ // 如果当前类型是其父类 + if (Long.compare(parentId, parentId1) == 0) { // 如果当前类型是其父类 List objectList = buildTree_New(list, jsonObject.getLong("id")); // 获取当前类型的子类 JSONArray children = jsonObject.getJSONArray("children"); children.addAll(objectList); @@ -367,5 +376,34 @@ public class MaterialTypeServiceImpl implements MaterialTypeService { return result; } + // 用于执行测试新算法 + class TaskTest_New implements Callable { + + // 待处理的物料类型id列表 + List materialTypeIdList; + + public TaskTest_New(List materialTypeByCondition) { + this.materialTypeIdList = materialTypeByCondition; + } + + @Override + public Object call() throws Exception { + + // 定义树结构结果集 + List list = new ArrayList<>(); + // 查询当前物料类型id列表中的物料类型 + List materialTypeByOldIds = materialTypeMapper.findMaterialTypeByOldIds(materialTypeIdList); + + for (int i = 0; i < materialTypeByOldIds.size(); i++) { + MaterialType mt = materialTypeByOldIds.get(i); + Map map = InitTreeMenus(mt, new ArrayList<>()); + list.add(map); + } + return list; + } + + + } + } diff --git a/src/main/java/com/dreamchaser/depository_manage/service/impl/RoleServiceImpl.java b/src/main/java/com/dreamchaser/depository_manage/service/impl/RoleServiceImpl.java index 6da0e7bd..1b139076 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/impl/RoleServiceImpl.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/impl/RoleServiceImpl.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Service public class RoleServiceImpl implements RoleService { @@ -284,11 +285,9 @@ public class RoleServiceImpl implements RoleService { // 获取当前赋值的权限类型 String type = (String) map.get("type"); // 定义返回结果 - Integer result = 0; + int result = 0; // 用于插入权限列表 Map paramForInsert = new HashMap<>(); - - if ("person".equals(type)) { // 如果是对人员赋权 paramForInsert.put("type", 1); @@ -323,7 +322,79 @@ public class RoleServiceImpl implements RoleService { result += (roleMapper.addWarehouseVisiblePermission(paramForInsert) - paramCount); } } + return result; + } + + /** + * 用于添加管理权限 + * + * @param map 添加具体数据 + * @return + */ + @Override + public Integer setManagerForRole(Map map) { + // 获取当前赋值的权限类型 + String setType = (String) map.get("setType"); + String permissionType = (String) map.get("permissionType"); + // 定义返回结果 + int result = 0; + // 用于插入权限列表 + Map paramForInsert = new HashMap<>(); + if ("person".equals(setType)) { + // 如果是对人员赋权 + paramForInsert.put("classes", 1); + } else if ("post".equals(setType)) { + // 如果是对岗位赋权 + paramForInsert.put("classes", 2); + } else { + throw new MyException("未知参数错误"); + } + // 获取当前要处理的数量 + Integer count = ObjectFormatUtil.toInteger(map.get("count")); + List userIds = (List) map.get("userIds"); + paramForInsert.put("uidList", userIds); + if ("depository".equals(permissionType)) { + // 获取当前要处理用于及其仓库的数量 + Integer countByCondition = roleMapper.findRoleAndDepositoryCountByCondition(paramForInsert); + if (countByCondition > count) { + // 当前数量小于已存在的数量,则代表权限删除 + result = countByCondition - delManangerForPermission(map); + } else { + paramForInsert.put("depositoryIds", map.get("roleIds")); + // 用于查询当前可见的仓库id数量 + Map paramForCount = new HashMap<>(); + paramForCount.put("classes", paramForInsert.get("classes")); + for (Object userId : userIds + ) { + paramForInsert.put("userid", userId); + paramForCount.put("userId", userId); + Integer paramCount = roleMapper.findRoleAndDepositoryCountByCondition(paramForCount); + result += (roleMapper.addUserOrPostRoleAndDepositorys(paramForInsert) + paramCount); + } + } + } else if ("materialType".equals(permissionType)) { + // 获取当前要处理用于及其物料类型的数量 + Integer countByCondition = roleMapper.findRoleAndMaterialTypeCountByCondition(paramForInsert); + if (countByCondition > count) { + // 当前数量小于已存在的数量,则代表权限删除 + result = countByCondition - delManangerForPermission(map); + } else { + paramForInsert.put("mtIds", map.get("roleIds")); + // 用于查询当前可见的仓库id数量 + Map paramForCount = new HashMap<>(); + paramForCount.put("classes", paramForInsert.get("classes")); + for (Object userId : userIds + ) { + paramForInsert.put("userid", userId); + paramForCount.put("uid", userId); + Integer paramCount = roleMapper.findRoleAndMaterialTypeCountByCondition(paramForCount); + result += (roleMapper.addUserOrPostRoleAndMaterialTypes(paramForInsert) + paramCount); + } + } + } else { + throw new MyException("未知参数错误"); + } return result; } @@ -336,7 +407,6 @@ public class RoleServiceImpl implements RoleService { @Override public Integer delWarehouseVisiblePermission(Map map) { // 获取当前赋值的权限类型 - Map paramForDelete = new HashMap<>(); Integer integer = 0; String type = (String) map.get("type"); @@ -363,16 +433,99 @@ public class RoleServiceImpl implements RoleService { ) { paramForDelete.put("uid", uid); // 获取当前用户所拥有的权限 - List depositoryIdList = roleMapper.findDepositoryIdForWarehouseVisiblePermissionByCondition(paramForDelete); // 获取当前已拥有的与新拥有的差集 - depositoryIdList.removeAll(depositoryIds); - paramForDelete.put("depositoryIdList", depositoryIdList); + List depositoryIdList = roleMapper.findDepositoryIdForWarehouseVisiblePermissionByCondition(paramForDelete); + List depositoryIdsString = depositoryIds.stream().map(Object::toString).collect(Collectors.toList()); + List depositoryIdListString = depositoryIdList.stream().map(Object::toString).collect(Collectors.toList()); + depositoryIdListString.removeAll(depositoryIdsString); + paramForDelete.put("depositoryIdList", depositoryIdListString); integer += roleMapper.delWarehouseVisiblePermissionByCondition(paramForDelete); } } return integer; } + /** + * 用于删除权限 + * + * @param map + * @return + */ + @Override + public Integer delManangerForPermission(Map map) { + // 获取当前赋值的权限类型 + Map paramForDelete = new HashMap<>(); + Integer integer = 0; + String setType = (String) map.get("setType"); + String permissionType = (String) map.get("permissionType"); + if ("person".equals(setType)) { + // 如果是对人员赋权 + paramForDelete.put("classes", 1); + } else if ("post".equals(setType)) { + // 如果是对岗位赋权 + paramForDelete.put("classes", 2); + } else { + throw new MyException("未知参数错误"); + } + List userIds = (List) map.get("userIds"); + if ("depository".equals(permissionType)) { + List depositoryIds = (List) map.get("roleIds"); + if (depositoryIds.size() == 0) { + // 如果是要删除所有的 + paramForDelete.put("userIdList", userIds); + // 删除当前所有的权限 + integer = roleMapper.deleteRoleAndDepositoryByCondition(paramForDelete); + } else { + // 如果不是所有 + for (Object uid : userIds + ) { + paramForDelete.put("userId", uid); + // 获取当前用户所拥有的权限 + List depositoryIdList = new ArrayList<>(); + List roleAndDepositoryByCondition = roleMapper.findRoleAndDepositoryByCondition(paramForDelete); + for (RoleAndDepository roleAndDepository : roleAndDepositoryByCondition) { + depositoryIdList.add(roleAndDepository.getDepositoryId()); + } + // 获取当前已拥有的与新拥有的差集 + List depositoryIdsString = depositoryIds.stream().map(Object::toString).collect(Collectors.toList()); + List depositoryIdListString = depositoryIdList.stream().map(Object::toString).collect(Collectors.toList()); + depositoryIdListString.removeAll(depositoryIdsString); + paramForDelete.put("depositoryIdList", depositoryIdListString); + integer += roleMapper.deleteRoleAndDepositoryByCondition(paramForDelete); + } + } + } else if ("materialType".equals(permissionType)) { + List materialTypeIds = (List) map.get("roleIds"); + if (materialTypeIds.size() == 0) { + // 如果是要删除所有的 + paramForDelete.put("userIdList", userIds); + // 删除当前所有的权限 + integer = roleMapper.deleteRoleAndMaterialTypeByCondition(paramForDelete); + } else { + // 如果不是所有 + for (Object uid : userIds + ) { + paramForDelete.put("uid", uid); + // 获取当前用户所拥有的权限 + List materialTypeIdList = new ArrayList<>(); + List roleAndMaterialTypeByCondition = roleMapper.findRoleAndMaterialTypeByCondition(paramForDelete); + for (RoleAndMaterialType roleAndMaterialType : roleAndMaterialTypeByCondition) { + materialTypeIdList.add(roleAndMaterialType.getMtid()); + } + // 获取当前已拥有的与新拥有的差集 + List materialTypeIdsString = materialTypeIds.stream().map(Object::toString).collect(Collectors.toList()); + List materialTypeIdListString = materialTypeIdList.stream().map(Object::toString).collect(Collectors.toList()); + materialTypeIdListString.removeAll(materialTypeIdsString); + paramForDelete.put("materialTypeIdList", materialTypeIdListString); + integer += roleMapper.deleteRoleAndMaterialTypeByCondition(paramForDelete); + } + } + } else { + throw new MyException("未知参数错误"); + } + return integer; + } + /** * 根据调剂获取在可视范围内的仓库id * @@ -388,27 +541,64 @@ public class RoleServiceImpl implements RoleService { } else if ("post".equals(type)) { // 如果是对岗位赋权 map.put("type", 2); - } - else { + } else { throw new MyException("未知参数错误"); } return roleMapper.findDepositoryIdForWarehouseVisiblePermissionByCondition(map); } + /** + * 根据条件获取管理的的仓库id + * + * @param map 待查询条件 + * @return + */ + @Override + public Map findWareHouseForManager(Map map) { + String type = (String) map.get("type"); + if ("person".equals(type)) { + // 如果是对人员赋权 + map.put("classes", 1); + } else if ("post".equals(type)) { + // 如果是对岗位赋权 + map.put("classes", 2); + } else { + throw new MyException("未知参数错误"); + } + map.put("uid", map.get("userId")); + List roleAndDepositoryByCondition = roleMapper.findRoleAndDepositoryByCondition(map); + List dResult = new ArrayList<>(); + for (RoleAndDepository roleAndDepository : roleAndDepositoryByCondition) { + dResult.add(roleAndDepository.getDepositoryId()); + } + List roleAndMaterialTypeByCondition = roleMapper.findRoleAndMaterialTypeByCondition(map); + List mtResult = new ArrayList<>(); + for (RoleAndMaterialType roleAndMaterialType : roleAndMaterialTypeByCondition) { + mtResult.add(roleAndMaterialType.getMtid()); + } + Map result = new HashMap<>(); + result.put("depository", dResult); + result.put("materialType", mtResult); + + + return result; + } + /** * 用于查询当前用户所被赋予的可见仓库 + * * @param userToken 待查询用户 * @return */ @Override public List findDepositoryIdForWareHouseVisiblePermissionByUser(UserByPort userToken) { - Map paramForFindDepositoryId = new HashMap<>(); - paramForFindDepositoryId.put("type",1); - paramForFindDepositoryId.put("uid",userToken.getId()); + Map paramForFindDepositoryId = new HashMap<>(); + paramForFindDepositoryId.put("type", 1); + paramForFindDepositoryId.put("uid", userToken.getId()); // 查询该用户是否存在单独设置的仓库 List depositoryIdListForPerson = roleMapper.findDepositoryIdForWarehouseVisiblePermissionByCondition(paramForFindDepositoryId); - paramForFindDepositoryId.put("type",2); - paramForFindDepositoryId.put("uid",userToken.getPosition()); + paramForFindDepositoryId.put("type", 2); + paramForFindDepositoryId.put("uid", userToken.getPosition()); // 查询该用户职位是否存在设计的仓库 List depositoryIdListForPost = roleMapper.findDepositoryIdForWarehouseVisiblePermissionByCondition(paramForFindDepositoryId); // 取并集 @@ -417,6 +607,7 @@ public class RoleServiceImpl implements RoleService { /** * 用于查询当前用户所拥有及所管理的仓库 + * * @param userToken 待查询用户 * @return */ @@ -427,13 +618,14 @@ public class RoleServiceImpl implements RoleService { // 获取额外的设置的仓库 List depositoryIdForWareHouseVisiblePermissionByUser = findDepositoryIdForWareHouseVisiblePermissionByUser(userToken); // 取并集 - depositoryIdList = (List) CollectionUtils.union(depositoryIdForWareHouseVisiblePermissionByUser,depositoryIdList); + depositoryIdList = (List) CollectionUtils.union(depositoryIdForWareHouseVisiblePermissionByUser, depositoryIdList); return depositoryIdList; } /** * 用于查询当前用户部门所拥有的仓库 + * * @param userToken 待查询用户 * @return */ @@ -446,11 +638,11 @@ public class RoleServiceImpl implements RoleService { } // 获取当前所有的仓库 List depositoryAll = depositoryMapper.findDepositoryAll(); - for (Depository depository:depositoryAll + for (Depository depository : depositoryAll ) { Integer parentId = depository.getParentId(); Integer id = depository.getId(); - if(depositoryIdList.contains(parentId) && !depositoryIdList.contains(id)){ + if (depositoryIdList.contains(parentId) && !depositoryIdList.contains(id)) { depositoryIdList.add(id); } } @@ -466,9 +658,6 @@ public class RoleServiceImpl implements RoleService { } - - - /** * 获取当前仓库的子仓库 * diff --git a/src/main/resources/templates/pages/company/company-out_back.html b/src/main/resources/templates/pages/company/company-out_back.html index 8e1e9e23..16c5e575 100644 --- a/src/main/resources/templates/pages/company/company-out_back.html +++ b/src/main/resources/templates/pages/company/company-out_back.html @@ -9,85 +9,182 @@ +
-
- - -
- 搜索信息 -
-
- -
-
- -
- -
-
-
- -
- +
+
+
+
    +
  • 人员
  • +
  • 岗位
  • +
+
+
+ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
-
-
- -
+ +
+
+
+
- +
-
- - - - - - - -
- - + +
+ + diff --git a/src/test/java/com/dreamchaser/depository_manage/OtherTest.java b/src/test/java/com/dreamchaser/depository_manage/OtherTest.java index d83b2c6e..50efd030 100644 --- a/src/test/java/com/dreamchaser/depository_manage/OtherTest.java +++ b/src/test/java/com/dreamchaser/depository_manage/OtherTest.java @@ -33,6 +33,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @RunWith(SpringRunner.class) @@ -113,25 +114,28 @@ public class OtherTest { return null; } - @Test - public void someTest(){ - boolean flag = true; - Depository depositoryById = depositoryMapper.findDepositoryById(28); - Depository depositoryTop = depositoryById; - if (Integer.compare(depositoryById.getParentId(), 0) != 0) { - // 如果不是 - List depositoryAll = depositoryMapper.findDepositoryAll(); - depositoryTop = findParentDepository(depositoryById, depositoryAll); - } - if (!depositoryTop.getDname().contains("前置仓")) { - // 如果不是前置仓下的仓库 - flag = false; - } - System.out.println(flag); - System.out.println(depositoryById); - System.out.println(depositoryTop); + + @Test + public void someTest(){ + List list = new ArrayList<>(); + List list1 = new ArrayList<>(); + list1.add(1); + list1.add(2); + list1.add(3); + list1.add(4); + list.add(4L); + list.add(5L); + list.add(6L); + list.add(7L); + list.add(1L); + List collect = list.stream().map(Object::toString).collect(Collectors.toList()); + List collect1 = list1.stream().map(Object::toString).collect(Collectors.toList()); + System.out.println(collect); + collect.removeAll(collect1); + System.out.println(collect); + System.out.println(collect1); } @Test