|
|
|
@ -130,13 +130,12 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
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); |
|
|
|
List<Depository> list = depositoryMapper.findDepositoryByCondition(map); |
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
Depository depository = list.get(i); |
|
|
|
for (Depository depository : list) { |
|
|
|
if (!depository.getAdminorg().isEmpty()) { |
|
|
|
Administration company = LinkInterfaceUtil.getCompany(ObjectFormatUtil.toInteger(depository.getAdminorg()), userByPort); |
|
|
|
depository.setAdminorgName(company.getName()); |
|
|
|
@ -154,10 +153,10 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
@Override |
|
|
|
public Integer findCountByCondition(Map<String, Object> 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 depositoryMapper.findCountByCondition(map); |
|
|
|
} |
|
|
|
|
|
|
|
@ -255,6 +254,42 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
return depositoryMapper.changeStateToDeletedByIds(ids); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询当前仓库的最上层仓库 |
|
|
|
* |
|
|
|
* @param depositoryId 当前仓库 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Depository findTopDepositoryByDepository(Integer depositoryId) { |
|
|
|
Depository depositoryById = depositoryMapper.findDepositoryById(depositoryId); |
|
|
|
if (Integer.compare(0, depositoryById.getParentId()) == 0) { |
|
|
|
// 如果当前仓库没有父级仓库
|
|
|
|
return depositoryById; |
|
|
|
} else { |
|
|
|
// 如果不是最高
|
|
|
|
|
|
|
|
// 获取所有仓库
|
|
|
|
List<Depository> depositoryAll = depositoryMapper.findDepositoryAll(); |
|
|
|
return findParentDepository(depositoryById, depositoryAll); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Depository findParentDepository(Depository depository, List<Depository> depositoryList) { |
|
|
|
for (Depository d : depositoryList |
|
|
|
) { |
|
|
|
if (Integer.compare(depository.getParentId(), d.getId()) == 0) { |
|
|
|
if(Integer.compare(0,d.getParentId()) == 0){ |
|
|
|
return d; |
|
|
|
}else{ |
|
|
|
return findParentDepository(d,depositoryList); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 计算未删除仓库综合 |
|
|
|
* |
|
|
|
@ -335,9 +370,9 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Object> InitTreeMenus(String adminorg,UserByPort userByPort) { |
|
|
|
public List<Object> InitTreeMenus(String adminorg, UserByPort userByPort) { |
|
|
|
List<Object> list = new ArrayList<>(); |
|
|
|
list = buildTree_New(InitTreeMenus_New(adminorg,userByPort),0); |
|
|
|
list = buildTree_New(InitTreeMenus_New(adminorg, userByPort), 0); |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
@ -353,7 +388,7 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
return depositoryMapper.selectDepositoryByIds(ids); |
|
|
|
} |
|
|
|
|
|
|
|
public List<Object> InitTreeMenus_New(String adminorg,UserByPort userByPort) { |
|
|
|
public List<Object> InitTreeMenus_New(String adminorg, UserByPort userByPort) { |
|
|
|
// 定义结果集
|
|
|
|
List<Object> list = new ArrayList<>(); |
|
|
|
|
|
|
|
@ -383,7 +418,7 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
Depository depository = depositoryAll.get(i); |
|
|
|
if (((i + 1) % 10) == 0) { // 如果有10个开启线程进行处理
|
|
|
|
depositoryIdList.add(depository.getId()); |
|
|
|
Future<Object> future = completionService.submit(new Task(depositoryIdList,adminorg,userByPort)); |
|
|
|
Future<Object> future = completionService.submit(new Task(depositoryIdList, adminorg, userByPort)); |
|
|
|
openThreadSize++; |
|
|
|
futureList.add(future); // 添加到结果集
|
|
|
|
depositoryIdList = new ArrayList<>(); // 情况列表
|
|
|
|
@ -395,7 +430,7 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
|
|
|
|
if (depositoryIdList.size() > 0) { |
|
|
|
// 如果有剩余,开启线程进行处理
|
|
|
|
Future<Object> future = completionService.submit(new Task(depositoryIdList,adminorg,userByPort)); |
|
|
|
Future<Object> future = completionService.submit(new Task(depositoryIdList, adminorg, userByPort)); |
|
|
|
futureList.add(future); |
|
|
|
openThreadSize++; |
|
|
|
} |
|
|
|
@ -417,7 +452,7 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
JSONObject jsonObject = new JSONObject((Map<String, Object>) list.get(i)); |
|
|
|
Integer parentId = jsonObject.getInteger("parentId"); |
|
|
|
if(Integer.compare(parentId,0) != 0) { |
|
|
|
if (Integer.compare(parentId, 0) != 0) { |
|
|
|
if (!checkList(list, parentId)) { |
|
|
|
// 如果当前列表中不存在其父级
|
|
|
|
Depository depositoryById = depositoryMapper.findDepositoryById(parentId); |
|
|
|
@ -425,102 +460,9 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 用于执行线程任务
|
|
|
|
class Task implements Callable<Object> { |
|
|
|
|
|
|
|
// 仓库
|
|
|
|
List<Integer> depositoryIdList; |
|
|
|
// 部门
|
|
|
|
String adminorg; |
|
|
|
// 当前登录用户
|
|
|
|
UserByPort userByPort; |
|
|
|
|
|
|
|
public Task(List<Integer> depositoryIdList,String adminorg,UserByPort userByPort){ |
|
|
|
this.depositoryIdList = depositoryIdList; |
|
|
|
this.adminorg = adminorg; |
|
|
|
this.userByPort = userByPort; |
|
|
|
} |
|
|
|
@Override |
|
|
|
public Object call() throws Exception { |
|
|
|
/** |
|
|
|
* 获取当前仓库id对应的仓库 |
|
|
|
*/ |
|
|
|
List<Depository> depositories = depositoryMapper.selectDepositoryByIds(depositoryIdList); |
|
|
|
|
|
|
|
// 获取当前用户管理的仓库
|
|
|
|
List<RoleAndDepository> depositoryAndRole = roleMapper.findDepositoryAndRole(userByPort.getId()); |
|
|
|
|
|
|
|
|
|
|
|
// 定义树结构结果集
|
|
|
|
List<Object> list = new ArrayList<>(); |
|
|
|
// 定义线程池
|
|
|
|
ExecutorService exs = Executors.newFixedThreadPool(depositories.size()); |
|
|
|
// 线程结果集
|
|
|
|
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|
|
|
|
|
|
|
// 1.定义CompletionService用于获取结果
|
|
|
|
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|
|
|
|
|
|
|
// 定义开启线程数
|
|
|
|
Integer openThreadSize = 0; |
|
|
|
for (int i = 0; i < depositories.size(); i++) { |
|
|
|
Depository depository = depositories.get(i); |
|
|
|
if("".equals(adminorg)||"361".equals(adminorg)){ // 如果不按部门分类或是仓储中心人员,则全部加载
|
|
|
|
Future<Object> submit = completionService.submit(new PlaceTask(depository)); |
|
|
|
futureList.add(submit); |
|
|
|
openThreadSize++; |
|
|
|
}else{ |
|
|
|
if(adminorg.equals(depository.getAdminorg()) || checkDidInDepositoryIdList(depository.getId(),depositoryAndRole)){ |
|
|
|
Future<Object> submit = completionService.submit(new PlaceTask(depository)); |
|
|
|
futureList.add(submit); |
|
|
|
openThreadSize++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
for (int i = 0; i < openThreadSize; i++) { |
|
|
|
Object result = null; |
|
|
|
try { |
|
|
|
result = completionService.take().get(); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} catch (ExecutionException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
list.add(result); |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 用于给仓库添加对应的库位 |
|
|
|
*/ |
|
|
|
class PlaceTask implements Callable<Object>{ |
|
|
|
|
|
|
|
Depository d; |
|
|
|
|
|
|
|
PlaceTask(Depository d){ |
|
|
|
this.d = d; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Object call() throws Exception { |
|
|
|
// 获取当前仓库下的库位
|
|
|
|
List<Object> objectList = AddPlaceByDid(d); |
|
|
|
|
|
|
|
// 将其构造成对应的树形结构类型
|
|
|
|
Map<String, Object> map = InitTreeMenus2(d, objectList); |
|
|
|
return map; |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 在仓库后添加库位信息
|
|
|
|
public List<Object> AddPlaceByDid(Depository d) { |
|
|
|
if (d != null) { |
|
|
|
@ -557,7 +499,6 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 构造树形组件数据模板
|
|
|
|
public Map<String, Object> InitTreeMenus2(Depository d, List<Object> children) { |
|
|
|
if (d != null) { |
|
|
|
@ -565,21 +506,21 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
map.put("title", d.getDname()); |
|
|
|
map.put("id", d.getId()); |
|
|
|
map.put("children", children); |
|
|
|
map.put("parentId",d.getParentId()); |
|
|
|
map.put("parentId", d.getParentId()); |
|
|
|
return map; |
|
|
|
} else { |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 用于构造树结构 |
|
|
|
* @param list 树列表 |
|
|
|
* |
|
|
|
* @param list 树列表 |
|
|
|
* @param parentId 父级id |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public List<Object> buildTree_New(List<Object> list,Integer parentId){ |
|
|
|
public List<Object> buildTree_New(List<Object> list, Integer parentId) { |
|
|
|
// 定义树结构
|
|
|
|
List<Object> result = new ArrayList<>(); |
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
@ -587,7 +528,7 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
JSONObject jsonObject = new JSONObject((Map<String, Object>) list.get(i)); |
|
|
|
// 获取当前父级id
|
|
|
|
Long parentId1 = jsonObject.getLong("parentId"); |
|
|
|
if(Long.compare(parentId,parentId1) == 0){ // 如果当前类型是其父类
|
|
|
|
if (Long.compare(parentId, parentId1) == 0) { // 如果当前类型是其父类
|
|
|
|
List<Object> objectList = buildTree_New(list, jsonObject.getInteger("id")); // 获取当前类型的子类
|
|
|
|
JSONArray children = jsonObject.getJSONArray("children"); |
|
|
|
children.addAll(objectList); |
|
|
|
@ -599,15 +540,16 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 判断当前父级id是否在列表中 |
|
|
|
* |
|
|
|
* @param list |
|
|
|
* @param parentId |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public Boolean checkList(List<Object> list,Integer parentId){ |
|
|
|
public Boolean checkList(List<Object> list, Integer parentId) { |
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
JSONObject jsonObject = new JSONObject((Map<String, Object>) list.get(i)); |
|
|
|
Integer pid = jsonObject.getInteger("id"); |
|
|
|
if(Integer.compare(pid,parentId) == 0){ |
|
|
|
if (Integer.compare(pid, parentId) == 0) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -616,11 +558,12 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 用于判断当前仓库是否是用户所管理的仓库 |
|
|
|
* |
|
|
|
* @param depositoryId 仓库id |
|
|
|
* @param list 用户管理仓库列表 |
|
|
|
* @param list 用户管理仓库列表 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public boolean checkDidInDepositoryIdList(Integer depositoryId,List<RoleAndDepository> list){ |
|
|
|
public boolean checkDidInDepositoryIdList(Integer depositoryId, List<RoleAndDepository> list) { |
|
|
|
for (RoleAndDepository roleAndDepository : list) { |
|
|
|
if (Integer.compare(depositoryId, roleAndDepository.getDepositoryId()) == 0) { |
|
|
|
// 是其所管理的仓库
|
|
|
|
@ -630,7 +573,6 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 获取当前部门以及公共仓库 |
|
|
|
* |
|
|
|
@ -645,6 +587,7 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据仓库构造库位的树形选择框 |
|
|
|
* |
|
|
|
* @param depositoryId 仓库id |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@ -711,32 +654,35 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取仓库对应的二维码 |
|
|
|
* |
|
|
|
* @param did |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public String findQrCodeByDepository(Integer did) { |
|
|
|
Map<String,Object> map = new HashMap<>(); |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
// 1为库位2为仓库
|
|
|
|
map.put("flag",2); |
|
|
|
map.put("depositoryId",did); |
|
|
|
map.put("flag", 2); |
|
|
|
map.put("depositoryId", did); |
|
|
|
return qrCodeMapper.selectQrCodeByDepositoryOrPlace(map); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 用于添加仓库与二维码的对应关系 |
|
|
|
* |
|
|
|
* @param map |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Integer addQrCodeByDepository(Map<String, Object> map) { |
|
|
|
// 1为库位2为仓库
|
|
|
|
map.put("flag",2); |
|
|
|
map.put("flag", 2); |
|
|
|
return qrCodeMapper.addQrCodeByPidOrDid(map); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取每个仓库以及对应 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@ -744,11 +690,7 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
return depositoryMapper.getToDayInventoryByDNameTest(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean hasDepository(List<Depository> list,Depository o){ |
|
|
|
private boolean hasDepository(List<Depository> list, Depository o) { |
|
|
|
boolean flag = false; |
|
|
|
for (Depository depository : list) { |
|
|
|
if (depository.getCode().equals(o.getCode())) { |
|
|
|
@ -759,6 +701,96 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
return flag; |
|
|
|
} |
|
|
|
|
|
|
|
// 用于执行线程任务
|
|
|
|
class Task implements Callable<Object> { |
|
|
|
|
|
|
|
// 仓库
|
|
|
|
List<Integer> depositoryIdList; |
|
|
|
// 部门
|
|
|
|
String adminorg; |
|
|
|
// 当前登录用户
|
|
|
|
UserByPort userByPort; |
|
|
|
|
|
|
|
public Task(List<Integer> depositoryIdList, String adminorg, UserByPort userByPort) { |
|
|
|
this.depositoryIdList = depositoryIdList; |
|
|
|
this.adminorg = adminorg; |
|
|
|
this.userByPort = userByPort; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Object call() throws Exception { |
|
|
|
/** |
|
|
|
* 获取当前仓库id对应的仓库 |
|
|
|
*/ |
|
|
|
List<Depository> depositories = depositoryMapper.selectDepositoryByIds(depositoryIdList); |
|
|
|
|
|
|
|
// 获取当前用户管理的仓库
|
|
|
|
List<RoleAndDepository> depositoryAndRole = roleMapper.findDepositoryAndRole(userByPort.getId()); |
|
|
|
|
|
|
|
|
|
|
|
// 定义树结构结果集
|
|
|
|
List<Object> list = new ArrayList<>(); |
|
|
|
// 定义线程池
|
|
|
|
ExecutorService exs = Executors.newFixedThreadPool(depositories.size()); |
|
|
|
// 线程结果集
|
|
|
|
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|
|
|
|
|
|
|
// 1.定义CompletionService用于获取结果
|
|
|
|
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|
|
|
|
|
|
|
// 定义开启线程数
|
|
|
|
Integer openThreadSize = 0; |
|
|
|
for (int i = 0; i < depositories.size(); i++) { |
|
|
|
Depository depository = depositories.get(i); |
|
|
|
if ("".equals(adminorg) || "361".equals(adminorg)) { // 如果不按部门分类或是仓储中心人员,则全部加载
|
|
|
|
Future<Object> submit = completionService.submit(new PlaceTask(depository)); |
|
|
|
futureList.add(submit); |
|
|
|
openThreadSize++; |
|
|
|
} else { |
|
|
|
if (adminorg.equals(depository.getAdminorg()) || checkDidInDepositoryIdList(depository.getId(), depositoryAndRole)) { |
|
|
|
Future<Object> submit = completionService.submit(new PlaceTask(depository)); |
|
|
|
futureList.add(submit); |
|
|
|
openThreadSize++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
for (int i = 0; i < openThreadSize; i++) { |
|
|
|
Object result = null; |
|
|
|
try { |
|
|
|
result = completionService.take().get(); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} catch (ExecutionException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
list.add(result); |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 用于给仓库添加对应的库位 |
|
|
|
*/ |
|
|
|
class PlaceTask implements Callable<Object> { |
|
|
|
|
|
|
|
Depository d; |
|
|
|
|
|
|
|
PlaceTask(Depository d) { |
|
|
|
this.d = d; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Object call() throws Exception { |
|
|
|
// 获取当前仓库下的库位
|
|
|
|
List<Object> objectList = AddPlaceByDid(d); |
|
|
|
|
|
|
|
// 将其构造成对应的树形结构类型
|
|
|
|
Map<String, Object> map = InitTreeMenus2(d, objectList); |
|
|
|
return map; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|