13 changed files with 0 additions and 2733 deletions
@ -1,147 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.dreamchaser.depository_manage.entity.*; |
|||
import com.dreamchaser.depository_manage.pojo.ApplicationInRecordP; |
|||
import com.dreamchaser.depository_manage.pojo.ApplicationOutRecordP; |
|||
import com.dreamchaser.depository_manage.pojo.DepositoryRecordP; |
|||
import com.dreamchaser.depository_manage.pojo.InventoryP; |
|||
import com.dreamchaser.depository_manage.service.DepositoryRecordService; |
|||
import com.dreamchaser.depository_manage.service.DepositoryService; |
|||
import com.dreamchaser.depository_manage.service.MaterialService; |
|||
import com.dreamchaser.depository_manage.service.StockTakingService; |
|||
import com.dreamchaser.depository_manage.utils.LinkInterfaceUtil; |
|||
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|||
import org.junit.Test; |
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@SpringBootTest |
|||
@RunWith(SpringRunner.class) |
|||
public class TestFoFindDepositoryMaterial { |
|||
|
|||
@Autowired |
|||
DepositoryService depositoryService; |
|||
|
|||
@Autowired |
|||
DepositoryRecordService depositoryRecordService; |
|||
|
|||
@Autowired |
|||
MaterialService materialService; |
|||
|
|||
@Autowired |
|||
StockTakingService stockTakingService; |
|||
|
|||
@Test |
|||
public void Test(){ |
|||
UserByPort userByPort = LinkInterfaceUtil.FindUserById(78, null); |
|||
Boolean allSonDepository = findAllSonDepositoryOfRelevancy("48",null); |
|||
System.out.println(allSonDepository); |
|||
|
|||
} |
|||
|
|||
|
|||
/** |
|||
* 根据父级编号查询所有关联信息 |
|||
* |
|||
* @param did |
|||
* @return |
|||
*/ |
|||
public Boolean findAllSonDepositoryOfRelevancy(String did, HttpServletRequest request) { |
|||
// 判断当前仓库是否存在物料
|
|||
boolean materialByDepository = findMaterialByDepository(did); |
|||
// 判断当前仓库是否有相关订单
|
|||
boolean depositoryRecord = findDepositoryRecord(did); |
|||
if (materialByDepository || depositoryRecord) { |
|||
return true; |
|||
} |
|||
// 查询当前仓库
|
|||
Depository depositoryById = depositoryService.findDepositoryById(ObjectFormatUtil.toInteger(did)); |
|||
// 查询当前仓库及子仓库
|
|||
List<Integer> childForDepositoryByParent = findChildForDepositoryByParent(depositoryById); |
|||
List<Depository> depositories = depositoryService.selectDepositoryRecordByIds(childForDepositoryByParent); |
|||
for (Depository depository : depositories) { |
|||
String depositoryId = depository.getId().toString(); |
|||
if (findMaterialByDepository(depositoryId) || findDepositoryRecord(depositoryId)) { |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* 根据仓库编号判断该仓库是否有物品 |
|||
* |
|||
* @param depositoryId 待查询仓库id |
|||
* @return |
|||
*/ |
|||
public boolean findMaterialByDepository(String depositoryId) { |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("state", 1); |
|||
param.put("depositoryId", depositoryId); |
|||
List<InventoryP> materialPByCondition = materialService.findInventory(param); |
|||
return materialPByCondition.size() > 0; |
|||
} |
|||
|
|||
/** |
|||
* 根据仓库编号查询与其有关的订单信息 |
|||
* @param depositoryId 待查询仓库id |
|||
* @return |
|||
*/ |
|||
public Boolean findDepositoryRecord(String depositoryId) { |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("depositoryId", depositoryId); |
|||
List<ApplicationInRecordP> inRecordPList = depositoryRecordService.findApplicationInRecordByDepository(depositoryId); |
|||
List<ApplicationOutRecordP> outRecordPList = depositoryRecordService.findApplicationOutRecordByDepository(depositoryId); |
|||
List<StockTaking> stockTakingList = stockTakingService.findStockTakingByCondition(param); |
|||
return inRecordPList.size() > 0 || outRecordPList.size() > 0 || stockTakingList.size() > 0; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于获取当前仓库的所有子类 |
|||
* @param d 待查询仓库 |
|||
* @return |
|||
*/ |
|||
public List<Integer> findChildForDepositoryByParent(Depository d) { |
|||
// 用于存储最终返回结果
|
|||
List<Integer> result = new ArrayList<>(); |
|||
result.add(d.getId()); |
|||
// 父级
|
|||
List<Integer> parentId = new ArrayList<>(); |
|||
parentId.add(d.getId()); |
|||
// 查询所有仓库正常使用的仓库
|
|||
List<Depository> depositoryAll = depositoryService.findDepositoryAll(); |
|||
for (Depository depository : depositoryAll) { |
|||
if (isTrueForParent(parentId, depository.getParentId())) { |
|||
parentId.add(depository.getId()); |
|||
result.add(depository.getId()); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
/** |
|||
* 判断当前id是否在ids中 |
|||
* |
|||
* @param parentList 父级列表 |
|||
* @param id 待判断id |
|||
* @return |
|||
*/ |
|||
public Boolean isTrueForParent(List<Integer> parentList, Integer id) { |
|||
for (Integer aLong : parentList) { |
|||
if (Long.compare(aLong, id) == 0) { |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
} |
|||
@ -1,320 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.entity.Depository; |
|||
import com.dreamchaser.depository_manage.entity.Place; |
|||
import com.dreamchaser.depository_manage.entity.User; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.mapper.DepositoryMapper; |
|||
import com.dreamchaser.depository_manage.mapper.PlaceMapper; |
|||
import com.dreamchaser.depository_manage.mapper.RoleMapper; |
|||
import com.dreamchaser.depository_manage.pojo.RoleAndDepository; |
|||
import com.dreamchaser.depository_manage.utils.LinkInterfaceUtil; |
|||
import org.junit.Test; |
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
import java.util.*; |
|||
import java.util.concurrent.*; |
|||
|
|||
@SpringBootTest |
|||
@RunWith(SpringRunner.class) |
|||
public class TestForDepositoryTree { |
|||
|
|||
@Autowired |
|||
DepositoryMapper depositoryMapper; |
|||
|
|||
@Autowired |
|||
PlaceMapper placeMapper; |
|||
|
|||
@Autowired |
|||
RoleMapper roleMapper; |
|||
@Test |
|||
public void test(){ |
|||
UserByPort userByPort = LinkInterfaceUtil.FindUserById(6235, null); |
|||
List<Object> objectList1 = InitTreeMenus("102",userByPort); |
|||
System.out.println(JSONObject.toJSONString(objectList1)); |
|||
} |
|||
public List<Object> InitTreeMenus(String adminorg, UserByPort userByPort) { |
|||
// 定义结果集
|
|||
List<Object> list = new ArrayList<>(); |
|||
|
|||
// 定义仓库id列表
|
|||
List<Integer> depositoryIdList = new ArrayList<>(); |
|||
// 获取所有仓库
|
|||
List<Depository> depositoryAll = depositoryMapper.findDepositoryAll(); |
|||
Integer totalVal = depositoryAll.size(); |
|||
|
|||
// 定义分页数量
|
|||
double size = 10.0; |
|||
|
|||
// 定义线程数
|
|||
Integer threadSize = (int) Math.ceil(totalVal / size); |
|||
|
|||
// 定义开启线程数目
|
|||
Integer openThreadSize = 0; |
|||
// 开启对应数量的线程
|
|||
ExecutorService exs = Executors.newFixedThreadPool(threadSize); |
|||
// 线程结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
|
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
for (int i = 0; i < depositoryAll.size(); i++) { |
|||
// 获取当前类型
|
|||
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)); |
|||
openThreadSize++; |
|||
futureList.add(future); // 添加到结果集
|
|||
depositoryIdList = new ArrayList<>(); // 情况列表
|
|||
} else { |
|||
// 添加id到列表中
|
|||
depositoryIdList.add(depository.getId()); |
|||
} |
|||
} |
|||
|
|||
if (depositoryIdList.size() > 0) { |
|||
// 如果有剩余,开启线程进行处理
|
|||
Future<Object> future = completionService.submit(new Task(depositoryIdList,adminorg,userByPort)); |
|||
futureList.add(future); |
|||
openThreadSize++; |
|||
} |
|||
|
|||
// 3.获取结果
|
|||
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.addAll((Collection<?>) result); |
|||
} |
|||
exs.shutdown(); |
|||
// 获取当前用户所管理的仓库
|
|||
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 (!checkList(list, parentId)) { |
|||
// 如果当前列表中不存在其父级
|
|||
Depository depositoryById = depositoryMapper.findDepositoryById(parentId); |
|||
list.add(InitTreeMenus2(depositoryById, new ArrayList<>())); |
|||
} |
|||
} |
|||
} |
|||
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; |
|||
} |
|||
} |
|||
|
|||
|
|||
// 在仓库后添加库位信息
|
|||
public List<Object> AddPlaceByDid(Depository d) { |
|||
if (d != null) { |
|||
// 获取当前仓库下的所有库位
|
|||
List<Object> result = new ArrayList<>(); |
|||
// 获取该仓库的排
|
|||
List<Integer> placeXByDid = placeMapper.findPlaceXByDid(d.getId()); |
|||
if (placeXByDid.size() > 0) { |
|||
for (int i = 1; i <= placeXByDid.get(0); i++) { |
|||
Map<String, Object> placeX = new HashMap<>(); |
|||
placeX.put("title", "第" + i + "排货架"); |
|||
placeX.put("id", -1); |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("did", d.getId()); |
|||
param.put("x", i); |
|||
List<Place> placeByCondition = placeMapper.findPlaceByCondition(param); |
|||
if (placeByCondition.size() > 0) { |
|||
List<Object> children = new ArrayList<>(); |
|||
for (int k = 1; k <= placeByCondition.size(); k++) { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("title", placeByCondition.get(k - 1).getCode()); |
|||
map.put("id", d.getId() + "-" + placeByCondition.get(k - 1).getId()); |
|||
children.add(map); |
|||
} |
|||
placeX.put("children", children); |
|||
} |
|||
// 获取该仓库该排的列数
|
|||
result.add(placeX); |
|||
} |
|||
} |
|||
return result; |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
|
|||
// 构造树形组件数据模板
|
|||
public Map<String, Object> InitTreeMenus2(Depository d, List<Object> children) { |
|||
if (d != null) { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("title", d.getDname()); |
|||
map.put("id", d.getId()); |
|||
map.put("children", children); |
|||
map.put("parentId",d.getParentId()); |
|||
return map; |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于构造树结构 |
|||
* @param list 树列表 |
|||
* @param parentId 父级id |
|||
* @return |
|||
*/ |
|||
public List<Object> buildTree_New(List<Object> list,Integer parentId){ |
|||
// 定义树结构
|
|||
List<Object> result = new ArrayList<>(); |
|||
for (int i = 0; i < list.size(); i++) { |
|||
// 构造为jsonObject类
|
|||
JSONObject jsonObject = new JSONObject((Map<String, Object>) list.get(i)); |
|||
// 获取当前父级id
|
|||
Long parentId1 = jsonObject.getLong("parentId"); |
|||
if(Long.compare(parentId,parentId1) == 0){ // 如果当前类型是其父类
|
|||
List<Object> objectList = buildTree_New(list, jsonObject.getInteger("id")); // 获取当前类型的子类
|
|||
JSONArray children = jsonObject.getJSONArray("children"); |
|||
children.addAll(objectList); |
|||
result.add(jsonObject); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 判断当前父级id是否在列表中 |
|||
* @param list |
|||
* @param parentId |
|||
* @return |
|||
*/ |
|||
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){ |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于判断当前仓库是否是用户所管理的仓库 |
|||
* @param depositoryId 仓库id |
|||
* @param list 用户管理仓库列表 |
|||
* @return |
|||
*/ |
|||
public boolean checkDidInDepositoryIdList(Integer depositoryId,List<RoleAndDepository> list){ |
|||
for (RoleAndDepository roleAndDepository : list) { |
|||
if (Integer.compare(depositoryId, roleAndDepository.getDepositoryId()) == 0) { |
|||
// 是其所管理的仓库
|
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
@ -1,218 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.entity.Depository; |
|||
import com.dreamchaser.depository_manage.entity.Group; |
|||
import com.dreamchaser.depository_manage.entity.GroupInfo; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.mapper.GroupMapper; |
|||
import com.dreamchaser.depository_manage.pojo.RoleAndDepository; |
|||
import org.junit.Test; |
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
import java.util.*; |
|||
import java.util.concurrent.*; |
|||
|
|||
@SpringBootTest |
|||
@RunWith(SpringRunner.class) |
|||
public class TestForGroupTree { |
|||
|
|||
@Autowired |
|||
GroupMapper groupMapper; |
|||
|
|||
@Test |
|||
public void Test(){ |
|||
List<Object> list = InitTreeMenus(""); |
|||
System.out.println(JSONObject.toJSONString(list)); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于构造组合树 |
|||
* @param gname |
|||
* @return |
|||
*/ |
|||
public List<Object> InitTreeMenus(String gname) { |
|||
// 定义结果集
|
|||
List<Object> list = new ArrayList<>(); |
|||
|
|||
// 获取所有使用中的组合
|
|||
List<Group> allGroupOnly = groupMapper.findAllGroupOnly(gname); |
|||
|
|||
// 获取当前总数
|
|||
Integer totalVal = allGroupOnly.size(); |
|||
|
|||
// 定义分页数量
|
|||
double size = 10.0; |
|||
|
|||
// 定义线程数
|
|||
Integer threadSize = (int) Math.ceil(totalVal / size); |
|||
|
|||
// 定义开启线程数目
|
|||
Integer openThreadSize = 0; |
|||
// 开启对应数量的线程
|
|||
ExecutorService exs = Executors.newFixedThreadPool(threadSize); |
|||
// 线程结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
|
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
|
|||
|
|||
// 定义组合id列表
|
|||
List<Integer> groupIdList = new ArrayList<>(); |
|||
|
|||
|
|||
for (int i = 0; i < allGroupOnly.size(); i++) { |
|||
Group group = allGroupOnly.get(i); |
|||
if (((i + 1) % 10) == 0) { // 如果有10个开启线程进行处理
|
|||
groupIdList.add(group.getId()); |
|||
Future<Object> future = completionService.submit(new Task(groupIdList)); |
|||
openThreadSize++; |
|||
futureList.add(future); // 添加到结果集
|
|||
groupIdList = new ArrayList<>(); // 情况列表
|
|||
} else { |
|||
// 添加id到列表中
|
|||
groupIdList.add(group.getId()); |
|||
} |
|||
} |
|||
if (groupIdList.size() > 0) { |
|||
// 如果有剩余,开启线程进行处理
|
|||
Future<Object> future = completionService.submit(new Task(groupIdList)); |
|||
futureList.add(future); |
|||
openThreadSize++; |
|||
} |
|||
|
|||
for (int i = 0; i < openThreadSize; i++) { |
|||
Object result = null; |
|||
try { |
|||
result = completionService.take().get(); |
|||
} catch (InterruptedException | ExecutionException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
list.addAll((Collection<?>) result); |
|||
} |
|||
return list; |
|||
} |
|||
|
|||
// 用于执行线程任务
|
|||
class Task implements Callable<Object> { |
|||
|
|||
// 组合id列表
|
|||
List<Integer> groupIdList; |
|||
|
|||
|
|||
public Task(List<Integer> groupIdList){ |
|||
this.groupIdList = groupIdList; |
|||
|
|||
} |
|||
@Override |
|||
public Object call() throws Exception { |
|||
/** |
|||
* 获取当前组合id对应的组合 |
|||
*/ |
|||
List<Group> groupByGids = groupMapper.findGroupByGids(groupIdList); |
|||
|
|||
// 开启对应数量的线程
|
|||
ExecutorService exs = Executors.newFixedThreadPool(groupByGids.size()); |
|||
// 线程结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
|
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
|
|||
|
|||
// 定义结果集
|
|||
List<Object> list = new ArrayList<>(); |
|||
|
|||
for (int i = 0; i < groupByGids.size(); i++) { |
|||
// 获取组合具体信息
|
|||
Group group = groupByGids.get(i); |
|||
// 开启线程
|
|||
Future<Object> submit = completionService.submit(new TaskForGroupInfo(group)); |
|||
futureList.add(submit); |
|||
} |
|||
|
|||
for (int i = 0; i < groupByGids.size(); i++) { |
|||
Object result = null; |
|||
try { |
|||
result = completionService.take().get(); |
|||
} catch (InterruptedException | ExecutionException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
list.add(result); |
|||
} |
|||
return list; |
|||
} |
|||
} |
|||
|
|||
class TaskForGroupInfo implements Callable<Object>{ |
|||
|
|||
Group group; |
|||
TaskForGroupInfo(Group group){ |
|||
this.group = group; |
|||
} |
|||
|
|||
@Override |
|||
public Object call() throws Exception |
|||
{ |
|||
// 用于获取当前组合的具体信息
|
|||
Map<String,Object> paramForGroup = new HashMap<>(); |
|||
paramForGroup.put("gid",group.getId()); |
|||
// 获取当前组合的具体信息
|
|||
List<GroupInfo> groupByCondition = groupMapper.findGroupByCondition(paramForGroup); |
|||
// 定义子类结果集
|
|||
List<Object> resultForChildren = new ArrayList<>(); |
|||
for (GroupInfo groupInfo : groupByCondition) { |
|||
Map<String, Object> stringObjectMap = InitTreeMenus(groupInfo); |
|||
resultForChildren.add(stringObjectMap); |
|||
} |
|||
Map<String, Object> stringObjectMap = InitTreeMenus(group, resultForChildren); |
|||
return stringObjectMap; |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
/** |
|||
* 构造树形组件数据模板 |
|||
* @param g 组合 |
|||
* @param children 子类 |
|||
* @return |
|||
*/ |
|||
public Map<String, Object> InitTreeMenus(Group g, List<Object> children) { |
|||
if (g != null) { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("title", g.getGname()); |
|||
map.put("id", g.getId()); |
|||
map.put("children", children); |
|||
return map; |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 构造树形组件的子组件模板 |
|||
* @param g 组合详细信息 |
|||
* @return |
|||
*/ |
|||
public Map<String, Object> InitTreeMenus(GroupInfo g) { |
|||
if (g != null) { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("title", g.getMname()); |
|||
map.put("id", g.getId()); |
|||
return map; |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
@ -1,172 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.config.PortConfig; |
|||
import com.dreamchaser.depository_manage.entity.*; |
|||
import com.dreamchaser.depository_manage.pojo.AdministrationP; |
|||
import com.dreamchaser.depository_manage.service.impl.CompanyServiceImpl; |
|||
import com.dreamchaser.depository_manage.utils.HttpUtils; |
|||
import com.sun.org.apache.xml.internal.security.Init; |
|||
import org.apache.http.protocol.HTTP; |
|||
import org.junit.Test; |
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
import javax.management.relation.RelationSupport; |
|||
import java.io.IOException; |
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.concurrent.*; |
|||
|
|||
@SpringBootTest |
|||
@RunWith(SpringRunner.class) |
|||
public class TestForManagerTree { |
|||
|
|||
@Test |
|||
public void test(){ |
|||
|
|||
List<ThreeAboutMan> allUserByAdministration = findAllUserByAdministration("309", null); |
|||
// 开启对应数量的线程
|
|||
ExecutorService exs = Executors.newFixedThreadPool(allUserByAdministration.size()); |
|||
// 结果集
|
|||
List<Object> list = new ArrayList<>(); |
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
|
|||
// 开启对应数目的线程
|
|||
for (int i = 0; i < allUserByAdministration.size(); i++) { |
|||
ThreeAboutMan threeAboutMan = allUserByAdministration.get(i); |
|||
// 开启线程
|
|||
Future<Object> submit = completionService.submit(new InitManagerTree(threeAboutMan)); |
|||
futureList.add(submit); |
|||
} |
|||
|
|||
// 收集结果
|
|||
for (int i = 0; i < allUserByAdministration.size(); i++) { |
|||
Object result = null; |
|||
try { |
|||
result = completionService.take().get(); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} catch (ExecutionException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
list.add(result); |
|||
} |
|||
System.out.println(JSONObject.toJSONString(list)); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于构造人员树 |
|||
*/ |
|||
class InitManagerTree implements Callable<Object>{ |
|||
|
|||
ThreeAboutMan threeAboutMan; |
|||
|
|||
InitManagerTree(ThreeAboutMan threeAboutMan){ |
|||
this.threeAboutMan = threeAboutMan; |
|||
} |
|||
|
|||
@Override |
|||
public Object call() throws Exception { |
|||
// 获取当前树结构的children
|
|||
List<Object> children = InitTrees(threeAboutMan); |
|||
// 构造结构
|
|||
Map<String, Object> map = InitTree(threeAboutMan, children); |
|||
return map; |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于获取行政组织树(包括成员) |
|||
* @param id 查询id |
|||
* @param userToken 登录用户 |
|||
* @return |
|||
*/ |
|||
public List<ThreeAboutMan> findAllUserByAdministration(String id,UserByPort userToken){ |
|||
String url = PortConfig.external_url +"/org/govthreeaboutman"; |
|||
Map<String,Object> map = new HashMap<>(); |
|||
map.put("id",id); |
|||
map.put("level",0); |
|||
map.put("all",1); |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url,paramObject, HTTP.UTF_8,userToken); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = (JSONObject) jsonObject.get("data"); |
|||
JSONArray list = (JSONArray) data.get("three"); |
|||
if(list == null){ |
|||
list = new JSONArray(); |
|||
} |
|||
List<ThreeAboutMan> threeAboutManList = new ArrayList<>(); |
|||
for (int i = 0; i < list.size(); i++) { |
|||
ThreeAboutMan threeAboutMan = JSONObject.toJavaObject((JSON) list.get(i), ThreeAboutMan.class); |
|||
threeAboutManList.add(threeAboutMan); |
|||
} |
|||
return threeAboutManList; |
|||
} |
|||
|
|||
/** |
|||
* 用于构造人员列表 |
|||
* @param threeAboutMan |
|||
* @return |
|||
*/ |
|||
public List<Object> InitTrees(ThreeAboutMan threeAboutMan){ |
|||
// 获取当前部门的部门负责人
|
|||
List<Object> result = new ArrayList<>(); |
|||
List<ThreeAboutMan> child = threeAboutMan.getChild(); |
|||
if(child != null){ |
|||
for (int i = 0; i < child.size(); i++) { |
|||
ThreeAboutMan threeAboutMan1 = child.get(i); |
|||
if(Integer.compare(threeAboutMan1.getIsman(),1) == 0){ |
|||
// 如果当前数据是部门
|
|||
|
|||
// 递归查询当前树
|
|||
List<Object> childrenList = InitTrees(threeAboutMan1); |
|||
Map<String, Object> map = InitTree(threeAboutMan1, childrenList); |
|||
result.add(map); |
|||
}else{ |
|||
// 如果是人员
|
|||
|
|||
Map<String,Object> children = new HashMap<>(); |
|||
children.put("title",threeAboutMan1.getName()); |
|||
children.put("id",threeAboutMan1.getNumber()); |
|||
result.add(children); |
|||
} |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于构造树形模板 |
|||
* @param threeAboutMan |
|||
* @param children |
|||
* @return |
|||
*/ |
|||
public Map<String,Object> InitTree(ThreeAboutMan threeAboutMan,List<Object> children){ |
|||
if (threeAboutMan != null) { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("title", threeAboutMan.getName()); |
|||
map.put("id", threeAboutMan.getNumber()); |
|||
map.put("children", children); |
|||
return map; |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
@ -1,264 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
|
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.entity.*; |
|||
import com.dreamchaser.depository_manage.mapper.MaterialMapper; |
|||
import com.dreamchaser.depository_manage.mapper.MaterialTypeMapper; |
|||
import com.dreamchaser.depository_manage.service.*; |
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.data.redis.core.RedisTemplate; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
import java.util.*; |
|||
import java.util.concurrent.*; |
|||
|
|||
@SpringBootTest |
|||
@RunWith(SpringRunner.class) |
|||
public class TestForMaterialTree { |
|||
|
|||
|
|||
@Autowired |
|||
MaterialService materialService; |
|||
|
|||
@Autowired |
|||
MaterialMapper materialMapper; |
|||
|
|||
@Autowired |
|||
MaterialTypeMapper materialTypeMapper; |
|||
|
|||
@Autowired |
|||
RedisTemplate<String, String> redisTemplate; |
|||
|
|||
@org.junit.Test |
|||
public void test1(){ |
|||
List<Object> objectList = buildTree_New(InitTree_Test_New(), Long.valueOf(0)); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于深度拷贝列表 |
|||
* |
|||
* @param oldList |
|||
* @param <T> |
|||
* @return |
|||
*/ |
|||
public static <T> List<T> deepCopy(List<T> oldList) { |
|||
List<T> newList = (List<T>) Arrays.asList(new Object[oldList.size()]); |
|||
Collections.copy(newList, oldList); |
|||
return newList; |
|||
} |
|||
|
|||
/** |
|||
* 用于构造物料树结构 |
|||
* @return |
|||
*/ |
|||
public List<Object> InitTree_Test_New() { |
|||
// 获取所有物料类型
|
|||
List<MaterialType> materialTypeAll = materialTypeMapper.findMaterialTypeAll(); |
|||
// 物料总数
|
|||
Integer totalVal = materialTypeAll.size(); |
|||
|
|||
// 定义分页数量
|
|||
double size = 100.0; |
|||
|
|||
// 定义线程数
|
|||
Integer threadSize = (int) Math.ceil(totalVal / size); |
|||
|
|||
// 开启对应数量的线程
|
|||
ExecutorService exs = Executors.newFixedThreadPool(threadSize); |
|||
// 树结构结果集
|
|||
List<Object> list = new ArrayList<>(); |
|||
// 线程结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
|
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
// 物料类型id列表
|
|||
List<Long> materialTypeList = new ArrayList<>(); |
|||
for (int i = 0; i < materialTypeAll.size(); i++) { |
|||
// 获取当前类型
|
|||
MaterialType materialType = materialTypeAll.get(i); |
|||
if (((i + 1) % 100) == 0) { // 如果有100个开启线程进行处理
|
|||
materialTypeList.add(materialType.getOldId()); |
|||
Future<Object> future = completionService.submit(new TaskTest_New(materialTypeList)); |
|||
futureList.add(future); // 添加到结果集
|
|||
materialTypeList = new ArrayList<>(); // 情况列表
|
|||
} else { |
|||
// 添加id到列表中
|
|||
materialTypeList.add(materialType.getOldId()); |
|||
} |
|||
} |
|||
|
|||
if (materialTypeList.size() > 0) { |
|||
// 如果有剩余,开启线程进行处理
|
|||
Future<Object> future = completionService.submit(new TaskTest_New(materialTypeList)); |
|||
futureList.add(future); |
|||
} |
|||
|
|||
// 3.获取结果
|
|||
for (int i = 0; i < threadSize; i++) { |
|||
Object result = null; |
|||
try { |
|||
result = completionService.take().get(); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} catch (ExecutionException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
list.addAll((Collection<?>) result); |
|||
} |
|||
// 进行最终的封装
|
|||
return list; |
|||
} |
|||
|
|||
// 用于执行测试新算法
|
|||
class TaskTest_New implements Callable<Object> { |
|||
|
|||
// 待处理的物料类型id列表
|
|||
List<Long> materialTypeIdList; |
|||
|
|||
public TaskTest_New(List<Long> materialTypeByCondition) { |
|||
this.materialTypeIdList = materialTypeByCondition; |
|||
} |
|||
|
|||
@Override |
|||
public Object call() throws Exception { |
|||
|
|||
// 定义树结构结果集
|
|||
List<Object> list = new ArrayList<>(); |
|||
// 查询当前物料类型id列表中的物料类型
|
|||
List<Material> materialByTypeIds = materialMapper.findMaterialByTypeIds(materialTypeIdList); |
|||
// 查询当前物料类型所包含的物料
|
|||
List<MaterialType> materialTypeByOldIds = materialTypeMapper.findMaterialTypeByOldIds(materialTypeIdList); |
|||
|
|||
// 定义线程集
|
|||
ExecutorService exs = Executors.newFixedThreadPool(materialTypeByOldIds.size()); |
|||
// 定义线程结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
|
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
|
|||
for (int i = 0; i < materialTypeByOldIds.size(); i++) { |
|||
// 获取当前物料类型
|
|||
MaterialType mt = materialTypeByOldIds.get(i); |
|||
// 开启对应线程
|
|||
Future<Object> future = completionService.submit(new MtTaskTest_New(mt, materialByTypeIds)); |
|||
// 添加到线程结果列表
|
|||
futureList.add(future); |
|||
} |
|||
// 3.获取结果
|
|||
for (int i = 0; i < materialTypeIdList.size(); 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 MtTaskTest_New implements Callable<Object> { |
|||
|
|||
MaterialType mt; // 物料类型
|
|||
List<Material> materiaList; // 物料列表
|
|||
|
|||
public MtTaskTest_New(MaterialType mt, List<Material> materiaList) { |
|||
this.mt = mt; |
|||
this.materiaList = materiaList; |
|||
} |
|||
|
|||
@Override |
|||
public Object call() throws Exception { |
|||
|
|||
// 开启对应数量的线程
|
|||
List<Material> materialList = new ArrayList<>(); |
|||
for (int i = 0; i < materiaList.size(); i++) { |
|||
Material material = materiaList.get(i); |
|||
// 如果当前物料是当前物料类型下的物料
|
|||
if (Long.compare(material.getMaterialTypeId(), mt.getOldId()) == 0) { |
|||
materialList.add(material); |
|||
} |
|||
} |
|||
// 将物料打包成树结构对应结果
|
|||
List<Object> objectList = AddMaterialByType_New(materialList); |
|||
// 封装成对应的结构
|
|||
Map<String, Object> objectMap = InitTreeMenus_New(mt, objectList); |
|||
return objectMap; |
|||
} |
|||
} |
|||
|
|||
// 构造树形组件数据模板
|
|||
public Map<String, Object> InitTreeMenus_New(MaterialType mt, List<Object> children) { |
|||
if (mt != null) { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("title", mt.getTname()); |
|||
map.put("id", mt.getOldId()); |
|||
map.put("parentId",mt.getParentId()); |
|||
map.put("children", children); |
|||
return map; |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
// 在类别后添加物料名称
|
|||
public List<Object> AddMaterialByType_New(List<Material> materialList) { |
|||
List<Object> result = new ArrayList<>(); |
|||
for (int i = 0; i < materialList.size(); i++) { |
|||
Material material = materialList.get(i); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
String version = material.getVersion(); |
|||
if (version == null) { |
|||
version = ""; |
|||
} |
|||
|
|||
String title = material.getMname() + ",规格型号: " + version; |
|||
map.put("title", title); |
|||
map.put("id", material.getId()); |
|||
result.add(map); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
/** |
|||
* 用于构造树结构 |
|||
* @param list 树列表 |
|||
* @param parentId 父级id |
|||
* @return |
|||
*/ |
|||
public List<Object> buildTree_New(List<Object> list,Long parentId){ |
|||
// 定义树结构
|
|||
List<Object> result = new ArrayList<>(); |
|||
for (int i = 0; i < list.size(); i++) { |
|||
// 构造为jsonObject类
|
|||
JSONObject jsonObject = new JSONObject((Map<String, Object>) list.get(i)); |
|||
// 获取当前父级id
|
|||
Long parentId1 = jsonObject.getLong("parentId"); |
|||
if(Long.compare(parentId,parentId1) == 0){ // 如果当前类型是其父类
|
|||
List<Object> objectList = buildTree_New(list, jsonObject.getLong("id")); // 获取当前类型的子类
|
|||
JSONArray children = jsonObject.getJSONArray("children"); |
|||
children.addAll(objectList); |
|||
result.add(jsonObject); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
@ -1,174 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.entity.Material; |
|||
import com.dreamchaser.depository_manage.entity.MaterialType; |
|||
import com.dreamchaser.depository_manage.mapper.MaterialTypeMapper; |
|||
import com.dreamchaser.depository_manage.service.MaterialTypeService; |
|||
import com.dreamchaser.depository_manage.service.impl.MaterialTypeServiceImpl; |
|||
import org.junit.Test; |
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.data.redis.core.RedisTemplate; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
import java.util.*; |
|||
import java.util.concurrent.*; |
|||
|
|||
@SpringBootTest |
|||
@RunWith(SpringRunner.class) |
|||
public class TestForMaterialTypeTree { |
|||
@Autowired |
|||
MaterialTypeMapper materialTypeMapper; |
|||
|
|||
@Autowired |
|||
private RedisTemplate<String, String> redisTemplateForHash; |
|||
|
|||
@Test |
|||
public void Test(){ |
|||
String key = "user:6235"; |
|||
String minRecord = (String) redisTemplateForHash.opsForHash().get(key,"minRecord"); |
|||
if(minRecord != null){ |
|||
// 获取子订单键值
|
|||
String[] split = minRecord.replace("[","").replace("]","").split(","); |
|||
for (int i = 0; i < split.length; i++) { |
|||
System.out.println(split[i]); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
public List<Object> InitTreeMenus() { |
|||
// 获取所有物料类型
|
|||
List<MaterialType> materialTypeAll = materialTypeMapper.findMaterialTypeAll(); |
|||
// 物料总数
|
|||
Integer totalVal = materialTypeAll.size(); |
|||
|
|||
// 定义分页数量
|
|||
double size = 100.0; |
|||
|
|||
// 定义线程数
|
|||
Integer threadSize = (int) Math.ceil(totalVal / size); |
|||
|
|||
// 定义开启线程数
|
|||
Integer openThreadSize = 0; |
|||
|
|||
// 开启对应数量的线程
|
|||
ExecutorService exs = Executors.newFixedThreadPool(threadSize); |
|||
// 树结构结果集
|
|||
List<Object> list = new ArrayList<>(); |
|||
// 线程结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
|
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
// 物料类型id列表
|
|||
List<Long> materialTypeList = new ArrayList<>(); |
|||
for (int i = 0; i < materialTypeAll.size(); i++) { |
|||
// 获取当前类型
|
|||
MaterialType materialType = materialTypeAll.get(i); |
|||
if (((i + 1) % 100) == 0) { // 如果有100个开启线程进行处理
|
|||
materialTypeList.add(materialType.getOldId()); |
|||
Future<Object> future = completionService.submit(new TaskTest_New(materialTypeList)); |
|||
openThreadSize++; |
|||
futureList.add(future); // 添加到结果集
|
|||
materialTypeList = new ArrayList<>(); // 情况列表
|
|||
} else { |
|||
// 添加id到列表中
|
|||
materialTypeList.add(materialType.getOldId()); |
|||
} |
|||
} |
|||
|
|||
if (materialTypeList.size() > 0) { |
|||
// 如果有剩余,开启线程进行处理
|
|||
Future<Object> future = completionService.submit(new TaskTest_New(materialTypeList)); |
|||
futureList.add(future); |
|||
openThreadSize++; |
|||
} |
|||
|
|||
// 3.获取结果
|
|||
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.addAll((Collection<?>) result); |
|||
} |
|||
exs.shutdown(); |
|||
// 进行最终的封装
|
|||
return list; |
|||
} |
|||
|
|||
// 用于执行测试新算法
|
|||
class TaskTest_New implements Callable<Object> { |
|||
|
|||
// 待处理的物料类型id列表
|
|||
List<Long> materialTypeIdList; |
|||
|
|||
public TaskTest_New(List<Long> materialTypeByCondition) { |
|||
this.materialTypeIdList = materialTypeByCondition; |
|||
} |
|||
|
|||
@Override |
|||
public Object call() throws Exception { |
|||
|
|||
// 定义树结构结果集
|
|||
List<Object> list = new ArrayList<>(); |
|||
// 查询当前物料类型id列表中的物料类型
|
|||
List<MaterialType> materialTypeByOldIds = materialTypeMapper.findMaterialTypeByOldIds(materialTypeIdList); |
|||
|
|||
for (int i = 0; i < materialTypeByOldIds.size(); i++) { |
|||
MaterialType mt = materialTypeByOldIds.get(i); |
|||
Map<String, Object> map = InitTreeMenus(mt, new ArrayList<>()); |
|||
list.add(map); |
|||
} |
|||
return list; |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
// 构造树形组件数据模板
|
|||
public Map<String, Object> InitTreeMenus(MaterialType mt, List<Object> children) { |
|||
if (mt != null) { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("title", mt.getTname()); |
|||
map.put("id", mt.getOldId()); |
|||
map.put("parentId",mt.getParentId()); |
|||
map.put("children",children); |
|||
return map; |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 用于构造树结构 |
|||
* @param list 树列表 |
|||
* @param parentId 父级id |
|||
* @return |
|||
*/ |
|||
public List<Object> buildTree_New(List<Object> list,Long parentId){ |
|||
// 定义树结构
|
|||
List<Object> result = new ArrayList<>(); |
|||
for (int i = 0; i < list.size(); i++) { |
|||
// 构造为jsonObject类
|
|||
JSONObject jsonObject = new JSONObject((Map<String, Object>) list.get(i)); |
|||
// 获取当前父级id
|
|||
Long parentId1 = jsonObject.getLong("parentId"); |
|||
if(Long.compare(parentId,parentId1) == 0){ // 如果当前类型是其父类
|
|||
List<Object> objectList = buildTree_New(list, jsonObject.getLong("id")); // 获取当前类型的子类
|
|||
JSONArray children = jsonObject.getJSONArray("children"); |
|||
children.addAll(objectList); |
|||
result.add(jsonObject); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
} |
|||
@ -1,59 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.EPSON.EPDM.EPDMEnumrations; |
|||
import com.dreamchaser.depository_manage.EPSON.EPDM.EPDMMediaLayoutRange; |
|||
import com.dreamchaser.depository_manage.config.PortConfig; |
|||
import com.dreamchaser.depository_manage.config.QyWxConfig; |
|||
import com.dreamchaser.depository_manage.controller.EPSON.AddMediaLayoutDlg; |
|||
import com.dreamchaser.depository_manage.controller.EPSON.PrintSettingsDlg; |
|||
import com.dreamchaser.depository_manage.entity.Depository; |
|||
import com.dreamchaser.depository_manage.entity.EPSON.EPDM.MEDIA_LAYOUT; |
|||
import com.dreamchaser.depository_manage.entity.qywxDepartment; |
|||
import com.dreamchaser.depository_manage.service.DepositoryService; |
|||
import com.dreamchaser.depository_manage.service.impl.EPSON.EPDM.EPDMWrapper; |
|||
import com.dreamchaser.depository_manage.service.impl.EPSON.EPDM.EPDMWrapperImpl; |
|||
import com.sun.jna.*; |
|||
import com.sun.jna.ptr.IntByReference; |
|||
import com.sun.jna.win32.W32APIOptions; |
|||
import org.junit.Test; |
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
import java.io.*; |
|||
import java.util.ArrayList; |
|||
import java.util.Collections; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 专用于测试琐碎实例 |
|||
*/ |
|||
@SpringBootTest |
|||
@RunWith(SpringRunner.class) |
|||
public class TestForOther { |
|||
|
|||
@Autowired |
|||
DepositoryService depositoryService; |
|||
|
|||
@Test |
|||
public void Test() throws IOException { |
|||
// 51
|
|||
|
|||
// qywxDepartment qyWxDepartment = QyWxConfig.getQyWxDepartment("123456789", 73);
|
|||
// System.out.println(qyWxDepartment.getDepartment_leader().get(0));
|
|||
// Map<String, Object> portInfo = PortConfig.findUserByQyWxUserId("WoBenShanLiang_3");
|
|||
// System.out.println(portInfo);
|
|||
|
|||
|
|||
Depository topDepositoryByDepository = depositoryService.findTopDepositoryByDepository(10); |
|||
System.out.println(topDepositoryByDepository); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
@ -1,273 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.entity.Material; |
|||
import com.dreamchaser.depository_manage.entity.MaterialType; |
|||
import com.dreamchaser.depository_manage.mapper.MaterialMapper; |
|||
import com.dreamchaser.depository_manage.mapper.MaterialTypeMapper; |
|||
import com.dreamchaser.depository_manage.service.MaterialService; |
|||
import org.apache.poi.ss.formula.functions.T; |
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.data.redis.core.RedisTemplate; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
import java.util.*; |
|||
import java.util.concurrent.*; |
|||
|
|||
@SpringBootTest |
|||
@RunWith(SpringRunner.class) |
|||
public class TestForSelectMaterialByName { |
|||
|
|||
@Autowired |
|||
MaterialService materialService; |
|||
|
|||
@Autowired |
|||
MaterialMapper materialMapper; |
|||
|
|||
@Autowired |
|||
MaterialTypeMapper materialTypeMapper; |
|||
|
|||
@Autowired |
|||
RedisTemplate<String, String> redisTemplate; |
|||
|
|||
@org.junit.Test |
|||
public void test1() { |
|||
List<Object> list = buildTreeForSelectName(InitTreeForSelectName("切四A菇")); |
|||
System.out.println(JSONObject.toJSONString(list)); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于深度拷贝列表 |
|||
* |
|||
* @param oldList |
|||
* @param <T> |
|||
* @return |
|||
*/ |
|||
public static <T> List<T> deepCopy(List<T> oldList) { |
|||
List<T> newList = (List<T>) Arrays.asList(new Object[oldList.size()]); |
|||
Collections.copy(newList, oldList); |
|||
return newList; |
|||
} |
|||
|
|||
/** |
|||
* 用于构造物料树结构(通过物料名称搜索) |
|||
* |
|||
* @return |
|||
*/ |
|||
public List<Object> InitTreeForSelectName(String mname) { |
|||
// 获取所有物料类型
|
|||
List<MaterialType> materialTypeAll = materialTypeMapper.findMaterialTypeAll(); |
|||
// 物料总数
|
|||
Integer totalVal = materialTypeAll.size(); |
|||
|
|||
// 定义分页数量
|
|||
double size = 100.0; |
|||
|
|||
// 定义线程数
|
|||
Integer threadSize = (int) Math.ceil(totalVal / size); |
|||
|
|||
// 开启对应数量的线程
|
|||
ExecutorService exs = Executors.newFixedThreadPool(threadSize); |
|||
// 树结构结果集
|
|||
List<Object> list = new ArrayList<>(); |
|||
// 线程结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
|
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
// 物料类型id列表
|
|||
List<Long> materialTypeList = new ArrayList<>(); |
|||
for (int i = 0; i < materialTypeAll.size(); i++) { |
|||
// 获取当前类型
|
|||
MaterialType materialType = materialTypeAll.get(i); |
|||
if (((i + 1) % 100) == 0) { // 如果有100个开启线程进行处理
|
|||
materialTypeList.add(materialType.getOldId()); |
|||
Future<Object> future = completionService.submit(new TaskTestForSelectMname(materialTypeList, mname)); |
|||
futureList.add(future); // 添加到结果集
|
|||
materialTypeList = new ArrayList<>(); // 情况列表
|
|||
} else { |
|||
// 添加id到列表中
|
|||
materialTypeList.add(materialType.getOldId()); |
|||
} |
|||
} |
|||
|
|||
if (materialTypeList.size() > 0) { |
|||
// 如果有剩余,开启线程进行处理
|
|||
Future<Object> future = completionService.submit(new TaskTestForSelectMname(materialTypeList, mname)); |
|||
futureList.add(future); |
|||
} |
|||
|
|||
// 3.获取结果
|
|||
for (int i = 0; i < threadSize; i++) { |
|||
Object result = null; |
|||
try { |
|||
result = completionService.take().get(); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} catch (ExecutionException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
list.addAll((Collection<?>) result); |
|||
} |
|||
// 进行最终的封装
|
|||
return list; |
|||
} |
|||
|
|||
// 用于执行测试新算法(通过物料名称搜索)
|
|||
class TaskTestForSelectMname implements Callable<Object> { |
|||
|
|||
// 待处理的物料类型id列表
|
|||
List<Long> materialTypeIdList; |
|||
String mname; |
|||
|
|||
public TaskTestForSelectMname(List<Long> materialTypeByCondition, String mname) { |
|||
this.materialTypeIdList = materialTypeByCondition; |
|||
this.mname = mname; |
|||
} |
|||
|
|||
@Override |
|||
public Object call() throws Exception { |
|||
|
|||
// 定义树结构结果集
|
|||
List<Object> list = new ArrayList<>(); |
|||
// 查询当前物料类型id列表中的物料类型
|
|||
Map<String, Object> paramForMnameAndMtid = new HashMap<>(); |
|||
paramForMnameAndMtid.put("list", materialTypeIdList); |
|||
paramForMnameAndMtid.put("mname", mname); |
|||
List<Material> materialByTypeIds = materialMapper.findMaterialByTypeIdsAndMname(paramForMnameAndMtid); |
|||
// 查询当前物料类型所包含的物料
|
|||
List<MaterialType> materialTypeByOldIds = materialTypeMapper.findMaterialTypeByOldIds(materialTypeIdList); |
|||
|
|||
// 定义线程集
|
|||
ExecutorService exs = Executors.newFixedThreadPool(materialTypeByOldIds.size()); |
|||
// 定义线程结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
|
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
|
|||
for (int i = 0; i < materialTypeByOldIds.size(); i++) { |
|||
// 获取当前物料类型
|
|||
MaterialType mt = materialTypeByOldIds.get(i); |
|||
// 开启对应线程
|
|||
Future<Object> future = completionService.submit(new MtTaskTestForSelectMname(mt, materialByTypeIds, mname)); |
|||
// 添加到线程结果列表
|
|||
futureList.add(future); |
|||
} |
|||
// 3.获取结果
|
|||
for (int i = 0; i < materialTypeIdList.size(); 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 MtTaskTestForSelectMname implements Callable<Object> { |
|||
|
|||
MaterialType mt; // 物料类型
|
|||
List<Material> materiaList; // 物料列表
|
|||
String mname; |
|||
|
|||
public MtTaskTestForSelectMname(MaterialType mt, List<Material> materiaList, String mname) { |
|||
this.mt = mt; |
|||
this.materiaList = materiaList; |
|||
this.mname = mname; |
|||
} |
|||
|
|||
@Override |
|||
public Object call() throws Exception { |
|||
|
|||
// 开启对应数量的线程
|
|||
List<Material> materialList = new ArrayList<>(); |
|||
for (int i = 0; i < materiaList.size(); i++) { |
|||
Material material = materiaList.get(i); |
|||
// 如果当前物料是当前物料类型下的物料
|
|||
if (Long.compare(material.getMaterialTypeId(), mt.getOldId()) == 0) { |
|||
materialList.add(material); |
|||
} |
|||
} |
|||
// 将物料打包成树结构对应结果
|
|||
List<Object> objectList = AddMaterialByTypeForSelectMname(materialList); |
|||
// 封装成对应的结构
|
|||
Map<String, Object> objectMap = InitTreeMenusForSelectName(mt, objectList); |
|||
return objectMap; |
|||
} |
|||
} |
|||
|
|||
// 构造树形组件数据模板(通过物料名称搜索)
|
|||
public Map<String, Object> InitTreeMenusForSelectName(MaterialType mt, List<Object> children) { |
|||
if (mt != null) { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("title", mt.getTname()); |
|||
map.put("id", mt.getOldId()); |
|||
map.put("parentId", mt.getParentId()); |
|||
map.put("children", children); |
|||
return map; |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
// 在类别后添加物料名称(通过物料名称搜索)
|
|||
public List<Object> AddMaterialByTypeForSelectMname(List<Material> materialList) { |
|||
List<Object> result = new ArrayList<>(); |
|||
for (int i = 0; i < materialList.size(); i++) { |
|||
Material material = materialList.get(i); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
String version = material.getVersion(); |
|||
if (version == null) { |
|||
version = ""; |
|||
} |
|||
|
|||
String title = material.getMname() + ",规格型号: " + version; |
|||
map.put("title", title); |
|||
map.put("id", material.getId()); |
|||
result.add(map); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
/** |
|||
* 用于构造树结构(通过物料名称搜索) |
|||
* |
|||
* @param list 树列表 |
|||
* @return |
|||
*/ |
|||
public List<Object> buildTreeForSelectName(List<Object> list) { |
|||
// 定义树结构
|
|||
List<Object> result = new ArrayList<>(); |
|||
for (int i = 0; i < list.size(); i++) { |
|||
// 构造为jsonObject类
|
|||
JSONObject jsonObject = new JSONObject((Map<String, Object>) list.get(i)); |
|||
JSONArray children = jsonObject.getJSONArray("children"); |
|||
if(children.size() > 0){ |
|||
result.add(jsonObject); |
|||
} |
|||
// // 获取当前父级id
|
|||
// Long parentId1 = jsonObject.getLong("parentId");
|
|||
// if (Long.compare(parentId, parentId1) == 0) { // 如果当前类型是其父类
|
|||
// List<Object> objectList = buildTreeForSelectName(list, jsonObject.getLong("id")); // 获取当前类型的子类
|
|||
// JSONArray children = jsonObject.getJSONArray("children");
|
|||
// children.addAll(objectList);
|
|||
// result.add(jsonObject);
|
|||
// }
|
|||
|
|||
} |
|||
return result; |
|||
} |
|||
} |
|||
@ -1,259 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.mapper.DepositoryMapper; |
|||
import com.dreamchaser.depository_manage.mapper.DepositoryRecordMapper; |
|||
import com.dreamchaser.depository_manage.mapper.MaterialTypeMapper; |
|||
import com.dreamchaser.depository_manage.mapper.RoleMapper; |
|||
import com.dreamchaser.depository_manage.pojo.InventoryByDname; |
|||
import com.dreamchaser.depository_manage.service.DepositoryRecordService; |
|||
import com.dreamchaser.depository_manage.service.DepositoryService; |
|||
import com.dreamchaser.depository_manage.service.MaterialTypeService; |
|||
import com.dreamchaser.depository_manage.utils.DateUtil; |
|||
import com.dreamchaser.depository_manage.utils.LinkInterfaceUtil; |
|||
import org.junit.Test; |
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
import java.text.SimpleDateFormat; |
|||
import java.util.*; |
|||
|
|||
@SpringBootTest |
|||
@RunWith(SpringRunner.class) |
|||
public class TestForThisWeekInventory { |
|||
|
|||
|
|||
@Autowired |
|||
MaterialTypeService materialTypeService; |
|||
|
|||
@Autowired |
|||
DepositoryRecordService depositoryRecordService; |
|||
|
|||
@Autowired |
|||
DepositoryRecordMapper depositoryRecordMapper; |
|||
|
|||
@Autowired |
|||
DepositoryMapper depositoryMapper; |
|||
|
|||
@Autowired |
|||
MaterialTypeMapper materialTypeMapper; |
|||
|
|||
@Autowired |
|||
DepositoryService depositoryService; |
|||
|
|||
@Autowired |
|||
RoleMapper roleMapper; |
|||
@Test |
|||
public void test(){ |
|||
|
|||
|
|||
UserByPort userByPort = LinkInterfaceUtil.FindUserById(78, null); |
|||
//获取获取系统的当前日历对象
|
|||
Calendar instance = Calendar.getInstance(); |
|||
int weekDay = instance.get(Calendar.DAY_OF_WEEK); |
|||
weekDay = weekDay - 1; // 具体周几
|
|||
//只获取今天
|
|||
Map<String, Integer> depositoryAllNameAndId = depositoryService.findDepositoryAllNameAndId(userByPort); |
|||
// 获取遍历器
|
|||
Iterator it = depositoryAllNameAndId.keySet().iterator(); |
|||
// 获取日期
|
|||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|||
Long now = DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime())); |
|||
instance.add(Calendar.DATE, 1); |
|||
// 明天
|
|||
Long tomorrow = DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime())); |
|||
// 仓库名称列表
|
|||
List<String> depositoryName = new ArrayList<>(); |
|||
// 各仓库对应入库数目
|
|||
Map<String, Integer> yesterdayData = new HashMap<>(); |
|||
Map<String, Object> show_data = new HashMap<>(); |
|||
// 各仓库当前库存数目
|
|||
Map<String, Object> todayInventory = new HashMap<>(); |
|||
instance.add(Calendar.DATE, -2); |
|||
Long yesterday = DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime())); |
|||
while (it.hasNext()) { |
|||
// 遍历 Map并计算各仓库的入库数
|
|||
Object key = it.next(); |
|||
// 添加仓库名称
|
|||
depositoryName.add(key.toString()); |
|||
// 获取仓库对应的id
|
|||
Integer val = (Integer) depositoryAllNameAndId.get(key); |
|||
// 获取今天内的入/出库,额度
|
|||
Integer depositoryRecordByDate1 = depositoryRecordService.findApplicationRecordByDate(tomorrow, now, Integer.parseInt("1"), val); |
|||
todayInventory.put(key.toString(), depositoryRecordByDate1); |
|||
//获取昨天的入/出库,额度
|
|||
Integer yesterdayInData = depositoryRecordService.findApplicationRecordByDate(now, yesterday, Integer.parseInt("1"), val); |
|||
// 添加到结果集
|
|||
yesterdayData.put(key.toString(), yesterdayInData); |
|||
List<Integer> drCountbyDrName = new ArrayList<>(); |
|||
drCountbyDrName.add(depositoryRecordByDate1); |
|||
show_data.put(key.toString(), ((ArrayList<Integer>) drCountbyDrName).clone()); |
|||
} |
|||
System.out.println(yesterdayData); |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
public Map<String, Object> getThisWeekInventoryByDName(DepositoryService depositoryService, DepositoryRecordService depositoryRecordService, UserByPort user) { |
|||
Calendar instance = Calendar.getInstance(); |
|||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|||
int weekDay = instance.get(Calendar.DAY_OF_WEEK); |
|||
weekDay = weekDay - 1; |
|||
// 获取所有仓库名称
|
|||
Map<String, Integer> depositoryAllNameAndId = depositoryService.findDepositoryAllNameAndId(user); |
|||
Iterator it = depositoryAllNameAndId.keySet().iterator(); |
|||
//result用来接收每个仓库每天的库存
|
|||
List<Integer> result = new ArrayList<>(); |
|||
// map用来存储仓库与库存的映射
|
|||
Map<String, Object> map = new HashMap<>(); |
|||
// 只获取当天
|
|||
List<InventoryByDname> toDayInventoryByDNameTest = depositoryService.getToDayInventoryByDNameTest(); |
|||
System.out.println("当前仓库中的库存记录为:"+JSONObject.toJSONString(toDayInventoryByDNameTest)); |
|||
if (weekDay == 1) { |
|||
while (it.hasNext()) { |
|||
int i; |
|||
String key = it.next().toString(); |
|||
String dname = key.split(",")[0]; |
|||
Integer inventoryByDname = getInventoryByDname(dname, toDayInventoryByDNameTest); |
|||
result.add(inventoryByDname); |
|||
map.put(key, ((ArrayList<Integer>) result).clone()); |
|||
result.clear(); |
|||
} |
|||
} else { |
|||
int now = instance.get(Calendar.DAY_OF_WEEK) - 1 == 0 ? 7 : instance.get(Calendar.DAY_OF_WEEK) - 1; |
|||
List<Long> days = new ArrayList<>(); |
|||
days.add(DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime()))); |
|||
Boolean flag = false; |
|||
while (now - 1 > 0) { |
|||
now--; |
|||
instance.add(Calendar.DATE, -1); |
|||
long format = DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime())); |
|||
days.add(format); |
|||
} |
|||
while (it.hasNext()) { |
|||
int i; |
|||
String key = it.next().toString(); |
|||
int j = 0; |
|||
|
|||
// 获取今天容量
|
|||
String dname = key.split(",")[0]; |
|||
Integer inventoryByDname = getInventoryByDname(dname, toDayInventoryByDNameTest); |
|||
result.add(inventoryByDname); |
|||
// 判断当天是否有出入口记录
|
|||
|
|||
Calendar IsInOut = Calendar.getInstance(); |
|||
Long start = DateUtil.DateTimeByDayToTimeStamp(formatter.format(IsInOut.getTime())); |
|||
IsInOut.add(Calendar.DATE, 1); |
|||
Long end = DateUtil.DateTimeByDayToTimeStamp(formatter.format(IsInOut.getTime())); |
|||
// 判断今天是否有出入库记录
|
|||
Integer inCount = depositoryRecordService.findApplicationInRecordByDate(end, start, null); |
|||
Integer OutCount = depositoryRecordService.findApplicationOutRecordByDate(end, start, null); |
|||
if (inCount > 0 || OutCount > 0) { |
|||
flag = true; |
|||
} |
|||
for (i = 0; i < days.size() - 1; i++) { |
|||
// 获取本周周一日期
|
|||
String mondayOnThisWeek = DateUtil.getMondayOnThisWeek(); |
|||
if (mondayOnThisWeek.equals(DateUtil.TimeStampToDateTime(days.get(i)))) { |
|||
break; |
|||
} |
|||
// 当前日期额度
|
|||
Integer aDouble = result.get(j++); |
|||
// 获取当前仓库
|
|||
Integer val = (Integer) depositoryAllNameAndId.get(key); |
|||
// 如果今天有出入库记录
|
|||
if (flag) { |
|||
Integer inRecordByDate = depositoryRecordService.findApplicationInRecordByDate(end, start, val); |
|||
Integer OutRecordByDate = depositoryRecordService.findApplicationOutRecordByDate(end, start, val); |
|||
aDouble = aDouble - inRecordByDate + OutRecordByDate; |
|||
flag = false; |
|||
} |
|||
// 获取一段时间内的入库额度
|
|||
//测试
|
|||
Integer depositoryRecordByDateByIn1 = depositoryRecordService.findApplicationInRecordByDate(days.get(i), days.get(i + 1), val); |
|||
// 获取一段时间内的出库额度
|
|||
Integer depositoryRecordByDateByOut1 = depositoryRecordService.findApplicationOutRecordByDate(days.get(i), days.get(i + 1), val); |
|||
Integer warehouserCount1 = (int)aDouble - depositoryRecordByDateByIn1 + depositoryRecordByDateByOut1; |
|||
result.add(warehouserCount1); |
|||
} |
|||
Collections.reverse(result); |
|||
map.put(key.toString(), ((ArrayList<Integer>) result).clone()); |
|||
result.clear(); |
|||
} |
|||
} |
|||
return map; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
/** |
|||
* 获取本月之前的月份 |
|||
* |
|||
* @return |
|||
*/ |
|||
public static Map<String, Object> getPreviousMonth() { |
|||
Calendar instance = Calendar.getInstance(); |
|||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|||
Map<String, Object> source = new HashMap<>(); |
|||
List<Object> sourceList = new ArrayList<>(); |
|||
int month = instance.get(Calendar.MONTH) + 1; |
|||
ArrayList<Object> months = new ArrayList<>(); |
|||
while (month > 0) { |
|||
instance.set(Calendar.MONTH, month); |
|||
instance.set(Calendar.DAY_OF_MONTH, 1); |
|||
source.put("month", month + "月"); |
|||
months.add(DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime()))); |
|||
month--; |
|||
sourceList.add(((HashMap<String, Object>) source).clone()); |
|||
} |
|||
instance.set(Calendar.MONTH, month); |
|||
instance.set(Calendar.DAY_OF_MONTH, 1); |
|||
months.add(DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime()))); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("months", months); |
|||
map.put("sourceList", sourceList); |
|||
return map; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取当前仓库下的库存 |
|||
* @param dname |
|||
* @param list |
|||
* @return |
|||
*/ |
|||
public Integer getInventoryByDname(String dname,List<InventoryByDname> list){ |
|||
for (InventoryByDname inventoryByDname : list) { |
|||
if (dname.equals(inventoryByDname.getDname())) { |
|||
return inventoryByDname.getInventory(); |
|||
} |
|||
} |
|||
return 0; |
|||
} |
|||
/** |
|||
* 获取上周一到本周一的日期 |
|||
* |
|||
* @return |
|||
*/ |
|||
public static List<Long> getLastTimeInterval() { |
|||
Calendar calendar = Calendar.getInstance(); |
|||
ArrayList<Long> lastTime = new ArrayList<>(); |
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|||
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1; |
|||
int offset1 = 1 - dayOfWeek; |
|||
calendar.add(Calendar.DATE, offset1 - 7); |
|||
lastTime.add(DateUtil.DateTimeByDayToTimeStamp(sdf.format(calendar.getTime()))); |
|||
for (int i = 0; i < 7; i++) { |
|||
calendar.add(Calendar.DATE, 1); |
|||
lastTime.add(DateUtil.DateTimeByDayToTimeStamp(sdf.format(calendar.getTime()))); |
|||
} |
|||
return lastTime; |
|||
} |
|||
|
|||
} |
|||
|
|||
@ -1,153 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.dreamchaser.depository_manage.entity.Depository; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.pojo.InventoryByDname; |
|||
import com.dreamchaser.depository_manage.service.DepositoryRecordService; |
|||
import com.dreamchaser.depository_manage.service.DepositoryService; |
|||
import com.dreamchaser.depository_manage.utils.DateUtil; |
|||
import com.dreamchaser.depository_manage.utils.LinkInterfaceUtil; |
|||
import org.junit.Test; |
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
import java.text.SimpleDateFormat; |
|||
import java.util.*; |
|||
|
|||
@SpringBootTest |
|||
@RunWith(SpringRunner.class) |
|||
public class TestForgetBeforeInventoryByMonth { |
|||
|
|||
@Autowired |
|||
DepositoryService depositoryService; |
|||
|
|||
@Autowired |
|||
DepositoryRecordService depositoryRecordService; |
|||
|
|||
@Test |
|||
public void test(){ |
|||
Map<String,Object> todayInventory = new HashMap<>(); |
|||
UserByPort userByPort = LinkInterfaceUtil.FindUserById(78, null); |
|||
List<Object> beforeInventoryByMonth = getBeforeInventoryByMonth(depositoryService, todayInventory, depositoryRecordService, userByPort); |
|||
} |
|||
|
|||
|
|||
public List<Object> getBeforeInventoryByMonth(DepositoryService depositoryService, Map<String,Object> todayInventory, DepositoryRecordService depositoryRecordService, UserByPort userByPort) { |
|||
List<Depository> depositoryAll = depositoryService.findDepositoryByAdminorgAndUser(userByPort); |
|||
// 获取该用户管理的仓库
|
|||
Map<String, Object> previousMonth = getPreviousMonth(); |
|||
List<Object> months = (List<Object>) previousMonth.get("months"); |
|||
List<Object> sourceList = (List<Object>) previousMonth.get("sourceList"); |
|||
Calendar instance = Calendar.getInstance(); |
|||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|||
instance.add(Calendar.MONTH, 1); |
|||
instance.set(Calendar.DATE, 1); |
|||
List<Integer> result = new ArrayList<>(); |
|||
String month = formatter.format(instance.getTime()); |
|||
List<InventoryByDname> toDayInventoryByDNameTest = depositoryService.getToDayInventoryByDNameTest(); |
|||
for (int i = 0; i < depositoryAll.size(); i++) { |
|||
String dname = depositoryAll.get(i).getDname(); |
|||
Integer todayDepositoryInventory = getInventoryByDname(dname,toDayInventoryByDNameTest); |
|||
result.add(todayDepositoryInventory); |
|||
todayInventory.put(dname,todayDepositoryInventory); |
|||
((Map<String, Object>) sourceList.get(0)).put(dname, result.get(i)); |
|||
} |
|||
for (int num = 0; num < months.size() - 1; num++) { |
|||
int k = 0; |
|||
for (int j = 0; j < depositoryAll.size(); j++) { |
|||
// 获取该仓库本月库存
|
|||
Map<String, Object> parmIn = new HashMap<>(); |
|||
Map<String, Object> parmOut = new HashMap<>(); |
|||
// 获取每月入库总额
|
|||
parmIn.put("type", 1); |
|||
parmIn.put("state", "已入库"); |
|||
parmIn.put("depository_id", depositoryAll.get(j).getId()); |
|||
parmIn.put("start", months.get(num + 1)); |
|||
parmIn.put("end", months.get(num)); |
|||
// 获取每月出库总额
|
|||
parmOut.put("type", 2); |
|||
parmOut.put("state", "已出库"); |
|||
parmOut.put("depository_id", depositoryAll.get(j).getId()); |
|||
parmOut.put("start", months.get(num + 1)); |
|||
parmOut.put("end", months.get(num)); |
|||
// 获取月份中入库物料的总额
|
|||
// 测试
|
|||
Integer wareHouseInCountByMonth1 = depositoryRecordService.findMaterialCountByMonth2(parmIn); |
|||
// 获取月份中出库物料的总额
|
|||
// 测试
|
|||
Integer wareHouseOutCountByMonth1 = depositoryRecordService.findMaterialCountByMonth2(parmOut); |
|||
// 获取当前月库存容量
|
|||
// 测试
|
|||
Integer wareHouseCount1 = result.get(k++) - wareHouseInCountByMonth1 + wareHouseOutCountByMonth1; |
|||
|
|||
result.add(wareHouseCount1); |
|||
((Map<String, Object>) sourceList.get(num)).put(depositoryAll.get(j).getDname(), wareHouseCount1); |
|||
} |
|||
for (int i = 0; i < depositoryAll.size(); i++) { |
|||
result.remove(0); |
|||
} |
|||
} |
|||
System.out.println("之前:"); |
|||
System.out.println(sourceList); |
|||
System.out.println(result); |
|||
for (int i = 0; i < depositoryAll.size(); i++) { |
|||
String dname = depositoryAll.get(i).getDname(); |
|||
Integer todayDepositoryInventory = getInventoryByDname(dname,toDayInventoryByDNameTest); |
|||
((Map<String, Object>) sourceList.get(0)).put(dname, todayDepositoryInventory); |
|||
} |
|||
System.out.println("之后:"); |
|||
System.out.println(sourceList); |
|||
List<String> barSource = new ArrayList<>(); |
|||
barSource.add("month"); |
|||
for (int i = 0; i < depositoryAll.size(); i++) { |
|||
barSource.add(depositoryAll.get(i).getDname()); |
|||
} |
|||
sourceList.add(barSource); |
|||
return sourceList; |
|||
} |
|||
/** |
|||
* 获取当前仓库下的库存 |
|||
* @param dname |
|||
* @param list |
|||
* @return |
|||
*/ |
|||
public Integer getInventoryByDname(String dname,List<InventoryByDname> list){ |
|||
for (InventoryByDname inventoryByDname : list) { |
|||
if (dname.equals(inventoryByDname.getDname())) { |
|||
return inventoryByDname.getInventory(); |
|||
} |
|||
} |
|||
return 0; |
|||
} |
|||
|
|||
/** |
|||
* 获取本月之前的月份 |
|||
* |
|||
* @return |
|||
*/ |
|||
public static Map<String, Object> getPreviousMonth() { |
|||
Calendar instance = Calendar.getInstance(); |
|||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM"); |
|||
Map<String, Object> source = new HashMap<>(); |
|||
List<Object> sourceList = new ArrayList<>(); |
|||
int month = instance.get(Calendar.MONTH) + 1; |
|||
ArrayList<Object> months = new ArrayList<>(); |
|||
while (month > 0) { |
|||
instance.set(Calendar.MONTH, month); |
|||
instance.set(Calendar.DAY_OF_MONTH, -1); |
|||
source.put("month", month + "月"); |
|||
months.add(DateUtil.DateTimeByMonthToTimeStamp(formatter.format(instance.getTime()))); |
|||
month--; |
|||
sourceList.add(((HashMap<String, Object>) source).clone()); |
|||
} |
|||
instance.set(Calendar.MONTH, month); |
|||
instance.set(Calendar.DAY_OF_MONTH, 1); |
|||
months.add(DateUtil.DateTimeByMonthToTimeStamp(formatter.format(instance.getTime()))); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("months", months); |
|||
map.put("sourceList", sourceList); |
|||
return map; |
|||
} |
|||
} |
|||
@ -1,174 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.dreamchaser.depository_manage.entity.MaterialType; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.service.DepositoryRecordService; |
|||
import com.dreamchaser.depository_manage.service.DepositoryService; |
|||
import com.dreamchaser.depository_manage.service.MaterialTypeService; |
|||
import com.dreamchaser.depository_manage.utils.DateUtil; |
|||
import com.dreamchaser.depository_manage.utils.LinkInterfaceUtil; |
|||
import org.junit.Test; |
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
import java.text.SimpleDateFormat; |
|||
import java.util.*; |
|||
import java.util.concurrent.*; |
|||
|
|||
@SpringBootTest |
|||
@RunWith(SpringRunner.class) |
|||
public class TestForgetMapData { |
|||
|
|||
@Autowired |
|||
MaterialTypeService materialTypeService; |
|||
@Autowired |
|||
DepositoryRecordService depositoryRecordService; |
|||
@Autowired |
|||
DepositoryService depositoryService; |
|||
|
|||
|
|||
@Test |
|||
public void Test(){ |
|||
UserByPort userByPort = LinkInterfaceUtil.FindUserById(78, null); |
|||
Map<String, Integer> depositoryAllNameAndId = depositoryService.findDepositoryAllNameAndId(userByPort); |
|||
Iterator it = depositoryAllNameAndId.keySet().iterator(); |
|||
List<String> depositoryName = new ArrayList<>(); |
|||
// 各仓库对应入库数目
|
|||
Map<String, Integer> yesterdayData = new HashMap<>(); |
|||
// 每天各仓库入库数目
|
|||
Map<String, Object> show_data = new HashMap<>(); |
|||
// 各仓库当前库存数目
|
|||
Map<String, Object> todayInventory = new HashMap<>(); |
|||
//获取获取系统的当前日历对象
|
|||
Calendar instance = Calendar.getInstance(); |
|||
// 获取日期
|
|||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|||
Long now = DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime())); |
|||
instance.add(Calendar.DATE, 1); |
|||
Long tomorrow = DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime())); |
|||
instance.add(Calendar.DATE, -2); |
|||
String yesterday = formatter.format(instance.getTime()); |
|||
while (it.hasNext()) { |
|||
// 遍历 Map并计算各仓库的入库数
|
|||
Object key = it.next(); |
|||
depositoryName.add(key.toString()); |
|||
Integer val = (Integer) depositoryAllNameAndId.get(key); |
|||
// 获取一段时间内的库存额度
|
|||
Integer depositoryRecordByDate1 = depositoryRecordService.findApplicationRecordByDate(tomorrow, now, Integer.parseInt("1"), val); |
|||
Integer toDayInventoryByDName = depositoryService.getToDayInventoryByDName(key.toString()); |
|||
todayInventory.put(key.toString(), toDayInventoryByDName); |
|||
yesterdayData.put(key.toString(), depositoryRecordByDate1); |
|||
List<Integer> drCountbyDrName = new ArrayList<>(); |
|||
drCountbyDrName.add(depositoryRecordByDate1); |
|||
show_data.put(key.toString(), ((ArrayList<Integer>) drCountbyDrName).clone()); |
|||
} |
|||
} |
|||
|
|||
// 中国地图数据
|
|||
public Map<String, Object> getMapData(String type){ |
|||
List<Object> mapDataList = new ArrayList<>(); |
|||
Map<String, Object> previousMonth1 = getPreviousMonth(); |
|||
List<Object> sourceList1 = (List<Object>) previousMonth1.get("sourceList"); |
|||
ArrayList<Object> title = new ArrayList<>(); |
|||
title.add("product"); |
|||
for (int i = sourceList1.size() - 1; i >= 0; i--) { |
|||
title.add(((Map<String, Object>) sourceList1.get(i)).get("month")); |
|||
} |
|||
mapDataList.add(title); |
|||
|
|||
// 获取所有顶级类别
|
|||
List<MaterialType> materialTypeAll = materialTypeService.findMaterialTypeNoParent(); |
|||
// 定义对应数量的线程池
|
|||
ExecutorService exs = Executors.newFixedThreadPool(materialTypeAll.size()); |
|||
// 结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
|
|||
for (int i = 0; i < materialTypeAll.size(); i++) { |
|||
MaterialType mt = materialTypeAll.get(i); |
|||
Future<Object> future = completionService.submit(new findMapData(previousMonth1,type,mt)); |
|||
futureList.add(future); |
|||
} |
|||
for (int i = 0; i < materialTypeAll.size(); i++) { |
|||
Object result = null; |
|||
try { |
|||
result = completionService.take().get(); |
|||
} catch (InterruptedException | ExecutionException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
mapDataList.add(result); |
|||
} |
|||
Map<String,Object> mapData =new HashMap<>(); |
|||
mapData.put("mapDataList", mapDataList); |
|||
return mapData; |
|||
} |
|||
|
|||
class findMapData implements Callable<Object>{ |
|||
String type ; |
|||
MaterialType mt; |
|||
Map<String, Object> previousMonth1; |
|||
findMapData( Map<String, Object> previousMonth1,String type ,MaterialType mt){ |
|||
this.previousMonth1 = previousMonth1; |
|||
this.type = type; |
|||
this.mt = mt; |
|||
} |
|||
|
|||
@Override |
|||
public Object call() throws Exception { |
|||
List<Object> productData = new ArrayList<>(); |
|||
List<Object> months1 = (List<Object>) previousMonth1.get("months"); |
|||
productData.add(mt.getTname()); |
|||
for (int j = months1.size() - 1; j > 0; j--) { |
|||
Map<String, Object> parm = new HashMap<>(); |
|||
parm.put("type", Integer.parseInt(type)); |
|||
if (Integer.parseInt(type) == 1) { |
|||
parm.put("state", "已入库"); |
|||
} else if (Integer.parseInt(type) == 2) { |
|||
parm.put("state", "已出库"); |
|||
} |
|||
parm.put("start", months1.get(j)); |
|||
parm.put("end", months1.get(j - 1)); |
|||
parm.put("oldId", mt.getOldId()); |
|||
//根据条件获取月份中物料的总额
|
|||
// 测试
|
|||
Integer materialCountByMonth1 = depositoryRecordService.findMaterialCountByMonth2(parm); |
|||
productData.add(materialCountByMonth1); |
|||
} |
|||
return productData; |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取本月之前的月份 |
|||
* |
|||
* @return |
|||
*/ |
|||
public static Map<String, Object> getPreviousMonth() { |
|||
Calendar instance = Calendar.getInstance(); |
|||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|||
Map<String, Object> source = new HashMap<>(); |
|||
List<Object> sourceList = new ArrayList<>(); |
|||
int month = instance.get(Calendar.MONTH) + 1; |
|||
ArrayList<Object> months = new ArrayList<>(); |
|||
while (month > 0) { |
|||
instance.set(Calendar.MONTH, month); |
|||
instance.set(Calendar.DAY_OF_MONTH, 1); |
|||
source.put("month", month + "月"); |
|||
months.add(DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime()))); |
|||
month--; |
|||
sourceList.add(((HashMap<String, Object>) source).clone()); |
|||
} |
|||
instance.set(Calendar.MONTH, month); |
|||
instance.set(Calendar.DAY_OF_MONTH, 1); |
|||
months.add(DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime()))); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("months", months); |
|||
map.put("sourceList", sourceList); |
|||
return map; |
|||
} |
|||
|
|||
} |
|||
@ -1,302 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.entity.MaterialType; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.mapper.DepositoryMapper; |
|||
import com.dreamchaser.depository_manage.mapper.DepositoryRecordMapper; |
|||
import com.dreamchaser.depository_manage.mapper.MaterialTypeMapper; |
|||
import com.dreamchaser.depository_manage.mapper.RoleMapper; |
|||
import com.dreamchaser.depository_manage.service.DepositoryRecordService; |
|||
import com.dreamchaser.depository_manage.service.DepositoryService; |
|||
import com.dreamchaser.depository_manage.service.MaterialTypeService; |
|||
import com.dreamchaser.depository_manage.utils.DateUtil; |
|||
import com.dreamchaser.depository_manage.utils.LinkInterfaceUtil; |
|||
import lombok.Data; |
|||
import org.junit.Test; |
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.data.redis.core.RedisTemplate; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
import java.text.SimpleDateFormat; |
|||
import java.util.*; |
|||
import java.util.concurrent.*; |
|||
|
|||
@SpringBootTest |
|||
@RunWith(SpringRunner.class) |
|||
public class TestForgetShowData { |
|||
|
|||
@Autowired |
|||
MaterialTypeService materialTypeService; |
|||
|
|||
@Autowired |
|||
DepositoryRecordService depositoryRecordService; |
|||
|
|||
@Autowired |
|||
DepositoryRecordMapper depositoryRecordMapper; |
|||
|
|||
@Autowired |
|||
DepositoryMapper depositoryMapper; |
|||
|
|||
@Autowired |
|||
MaterialTypeMapper materialTypeMapper; |
|||
|
|||
@Autowired |
|||
DepositoryService depositoryService; |
|||
|
|||
@Autowired |
|||
RoleMapper roleMapper; |
|||
|
|||
@Autowired |
|||
RedisTemplate<String, String> redisTemplate; |
|||
|
|||
|
|||
@Test |
|||
public void Test() { |
|||
UserByPort userByPort = LinkInterfaceUtil.FindUserById(78, null); |
|||
Map<String, Integer> map = new HashMap<>(); |
|||
List<String> depositoryName = new ArrayList<>(); |
|||
Map<String, Object> showData = getShowData("1", userByPort, map, depositoryName); |
|||
System.out.println(JSONObject.toJSONString(showData)); |
|||
} |
|||
|
|||
// 用于获取折线图
|
|||
|
|||
public Map<String, Object> getShowData(String type, UserByPort userByPort, Map<String, Integer> yesterdayData, List<String> depositoryName) { |
|||
// 获取各仓库名称以及id
|
|||
Map<String, Integer> depositoryAllNameAndId = depositoryService.findDepositoryAllNameAndId(userByPort); |
|||
// 获取遍历器
|
|||
Iterator it = depositoryAllNameAndId.keySet().iterator(); |
|||
// 仓库名称列表
|
|||
//获取获取系统的当前日历对象
|
|||
Calendar instance = Calendar.getInstance(); |
|||
// 获取日期
|
|||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|||
int now = instance.get(Calendar.DAY_OF_WEEK) - 1 == 0 ? 7 : instance.get(Calendar.DAY_OF_WEEK) - 1; |
|||
List<Long> days = new ArrayList<>(); // 周一至今的每天
|
|||
instance.add(Calendar.DATE, 1); |
|||
days.add(DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime()))); |
|||
instance.add(Calendar.DATE, -1); |
|||
days.add(DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime()))); |
|||
while (now - 1 > 0) { |
|||
now--; |
|||
instance.add(Calendar.DATE, -1); |
|||
Long format = DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime())); |
|||
days.add(format); |
|||
} |
|||
|
|||
// 定义线程
|
|||
ExecutorService exs = Executors.newFixedThreadPool(depositoryAllNameAndId.size()); |
|||
// 结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
|
|||
// 每天各仓库入库数目
|
|||
Map<String, Object> show_data = new HashMap<>(); |
|||
while (it.hasNext()) { |
|||
Object next = it.next(); |
|||
getApplicationRecordByDate getApplicationRecordByDate = new getApplicationRecordByDate(type, next, days, depositoryAllNameAndId); |
|||
getApplicationRecordByDate.setShow_data(show_data); |
|||
getApplicationRecordByDate.setDepositoryName(depositoryName); |
|||
getApplicationRecordByDate.setYesterdayData(yesterdayData); |
|||
Future<Object> future = completionService.submit(getApplicationRecordByDate); |
|||
futureList.add(future); |
|||
} |
|||
|
|||
for (int i = 0; i < depositoryAllNameAndId.size(); i++) { |
|||
Object result = null; |
|||
try { |
|||
result = completionService.take().get(); |
|||
} catch (InterruptedException | ExecutionException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
return show_data; |
|||
} |
|||
|
|||
@Data |
|||
class getApplicationRecordByDate implements Callable<Object> { |
|||
Object key; |
|||
List<Long> days; |
|||
Map<String, Integer> depositoryAllNameAndId; |
|||
List<String> depositoryName; |
|||
Map<String, Integer> yesterdayData; |
|||
String type; |
|||
Map<String, Object> show_data; |
|||
|
|||
getApplicationRecordByDate(String type, Object key, List<Long> days, Map<String, Integer> depositoryAllNameAndId) { |
|||
this.key = key; |
|||
this.depositoryAllNameAndId = depositoryAllNameAndId; |
|||
this.days = days; |
|||
this.type = type; |
|||
} |
|||
|
|||
@Override |
|||
public Object call() throws Exception { |
|||
int i; |
|||
List<Integer> drCountbyDrName = new ArrayList<>(); |
|||
for (i = days.size() - 1; i > 0; i--) { |
|||
// 遍历 Map并计算各仓库的入库数
|
|||
if (i == days.size() - 1) { |
|||
depositoryName.add(key.toString()); |
|||
} |
|||
Integer val = depositoryAllNameAndId.get(key); |
|||
// 获取一段时间内的库存额度
|
|||
Integer depositoryRecordByDate1 = depositoryRecordService.findApplicationRecordByDate(days.get(i - 1), days.get(i), Integer.parseInt(type), val); |
|||
drCountbyDrName.add(depositoryRecordByDate1); |
|||
if (i == 2) { |
|||
yesterdayData.put(key.toString(), depositoryRecordByDate1); |
|||
} |
|||
} |
|||
show_data.put(key.toString(), drCountbyDrName); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
//获取本月及之前月份各种类别入/出库总量
|
|||
public List<Object> getSourceList(String type) { |
|||
|
|||
Map<String, Object> previousMonth = getPreviousMonth(); |
|||
List<Object> months = (List<Object>) previousMonth.get("months"); |
|||
List<Object> sourceList = (List<Object>) previousMonth.get("sourceList"); |
|||
ExecutorService exs = Executors.newFixedThreadPool(months.size()); |
|||
// 结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
for (int num = 0; num < months.size() - 1; num++) { |
|||
Map<String, Object> map = (Map<String, Object>) sourceList.get(num); |
|||
Future<Object> future = completionService.submit(new getSourceListTask(map, type, months.get(num + 1).toString(), months.get(num).toString())); |
|||
futureList.add(future); |
|||
} |
|||
for (int i = 0; i < months.size() - 1; i++) { |
|||
Object result = null; |
|||
try { |
|||
result = completionService.take(); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
List<String> barSource = new ArrayList<>(); |
|||
barSource.add("month"); |
|||
List<MaterialType> materialTypeAll = materialTypeService.findMaterialTypeNoParent(); |
|||
for (int i = 0; i < materialTypeAll.size(); i++) { |
|||
barSource.add(materialTypeAll.get(i).getTname()); |
|||
} |
|||
sourceList.add(barSource); |
|||
return sourceList; |
|||
} |
|||
|
|||
|
|||
// 具体执行getSourceList逻辑
|
|||
class getSourceListTask implements Callable<Object> { |
|||
|
|||
String type; |
|||
String start; |
|||
String end; |
|||
Map<String, Object> map; |
|||
|
|||
getSourceListTask(Map<String, Object> map, String type, String start, String end) { |
|||
this.map = map; |
|||
this.type = type; |
|||
this.start = start; |
|||
this.end = end; |
|||
} |
|||
|
|||
@Override |
|||
public Object call() throws Exception { |
|||
List<MaterialType> materialTypeAll = materialTypeService.findMaterialTypeNoParent(); |
|||
ExecutorService exs = Executors.newFixedThreadPool(materialTypeAll.size()); |
|||
// 结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
|
|||
for (int j = 0; j < materialTypeAll.size(); j++) { |
|||
Map<String, Object> parm = new HashMap<>(); |
|||
parm.put("type", Integer.parseInt(type)); |
|||
if (Integer.parseInt(type) == 1) { |
|||
parm.put("state", "已入库"); |
|||
} else if (Integer.parseInt(type) == 2) { |
|||
parm.put("state", "已出库"); |
|||
} |
|||
parm.put("start", start); |
|||
parm.put("end", end); |
|||
parm.put("oldId", materialTypeAll.get(j).getOldId()); |
|||
//根据条件获取月份中物料的总额
|
|||
// 测试
|
|||
|
|||
Future<Object> future = completionService.submit(new findMaterialCountTaskForSourceList(parm)); |
|||
futureList.add(future); |
|||
} |
|||
for (int i = 0; i < materialTypeAll.size(); i++) { |
|||
Object result = null; |
|||
try { |
|||
result = completionService.take().get(); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} catch (ExecutionException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
map.putAll((Map<? extends String, ?>) result); |
|||
} |
|||
return map; |
|||
} |
|||
} |
|||
|
|||
|
|||
// 根据条件获取月份中物料的总额用于sourcelist
|
|||
class findMaterialCountTaskForSourceList implements Callable<Object> { |
|||
|
|||
Map<String, Object> map; |
|||
|
|||
findMaterialCountTaskForSourceList(Map<String, Object> map) { |
|||
this.map = map; |
|||
} |
|||
|
|||
@Override |
|||
public Object call() throws Exception { |
|||
Map<String, Object> result = new HashMap<>(); |
|||
Integer materialCountByMonth1 = depositoryRecordService.findMaterialCountByMonth2(map); |
|||
Long oldId = Long.valueOf(map.get("oldId").toString()); |
|||
MaterialType materialTypeByOldId = materialTypeService.findMaterialTypeByOldId(oldId); |
|||
result.put(materialTypeByOldId.getTname(), materialCountByMonth1); |
|||
return result; |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取本月之前的月份 |
|||
* |
|||
* @return |
|||
*/ |
|||
public static Map<String, Object> getPreviousMonth() { |
|||
Calendar instance = Calendar.getInstance(); |
|||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|||
Map<String, Object> source = new HashMap<>(); |
|||
List<Object> sourceList = new ArrayList<>(); |
|||
int month = instance.get(Calendar.MONTH) + 1; |
|||
ArrayList<Object> months = new ArrayList<>(); |
|||
while (month > 0) { |
|||
instance.set(Calendar.MONTH, month); |
|||
instance.set(Calendar.DAY_OF_MONTH, 1); |
|||
source.put("month", month + "月"); |
|||
months.add(DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime()))); |
|||
month--; |
|||
sourceList.add(((HashMap<String, Object>) source).clone()); |
|||
} |
|||
instance.set(Calendar.MONTH, month); |
|||
instance.set(Calendar.DAY_OF_MONTH, 1); |
|||
months.add(DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime()))); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("months", months); |
|||
map.put("sourceList", sourceList); |
|||
return map; |
|||
} |
|||
|
|||
} |
|||
@ -1,218 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.dreamchaser.depository_manage.entity.MaterialType; |
|||
import com.dreamchaser.depository_manage.mapper.MaterialTypeMapper; |
|||
import com.dreamchaser.depository_manage.service.DepositoryRecordService; |
|||
import com.dreamchaser.depository_manage.service.DepositoryService; |
|||
import com.dreamchaser.depository_manage.service.MaterialTypeService; |
|||
import com.dreamchaser.depository_manage.utils.DateUtil; |
|||
import org.junit.Test; |
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
import java.text.ParseException; |
|||
import java.text.SimpleDateFormat; |
|||
import java.util.*; |
|||
import java.util.concurrent.*; |
|||
|
|||
@SpringBootTest |
|||
@RunWith(SpringRunner.class) |
|||
public class TestForgetSourceList { |
|||
|
|||
@Autowired |
|||
DepositoryRecordService depositoryRecordService; |
|||
|
|||
@Autowired |
|||
DepositoryService depositoryService; |
|||
|
|||
@Autowired |
|||
MaterialTypeService materialTypeService; |
|||
|
|||
@Autowired |
|||
MaterialTypeMapper materialTypeMapper; |
|||
|
|||
|
|||
@Test |
|||
public void Test(){ |
|||
List<Object> sourceList = getSourceList("1"); |
|||
System.out.println(sourceList); |
|||
// getPreviousMonth();
|
|||
} |
|||
|
|||
// 根据id获取子类
|
|||
public List<Long> findChildForMaterialTypeByParent(MaterialType mt) { |
|||
List<Long> result = new ArrayList<>(); |
|||
result.add(mt.getOldId()); |
|||
List<Long> parentId = new ArrayList<>(); |
|||
parentId.add(mt.getOldId()); |
|||
List<MaterialType> materialTypeAll = materialTypeMapper.findMaterialTypeAll(); |
|||
for (int i = 0; i < materialTypeAll.size(); i++) { |
|||
MaterialType materialType = materialTypeAll.get(i); |
|||
if (isTrueForParent(parentId, materialType.getParentId())) { |
|||
parentId.add(materialType.getOldId()); |
|||
result.add(materialType.getOldId()); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
public Boolean isTrueForParent(List<Long> parentList, Long id) { |
|||
for (Long aLong : parentList) { |
|||
if (Long.compare(aLong, id) == 0) { |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
//获取本月及之前月份各种类别入/出库总量
|
|||
public List<Object> getSourceList(String type){ |
|||
|
|||
List<MaterialType> materialTypeAll = materialTypeService.findMaterialTypeNoParent(); |
|||
Map<String, Object> previousMonth = getPreviousMonth(); |
|||
List<Object> months = (List<Object>) previousMonth.get("months"); |
|||
List<Object> sourceList = (List<Object>) previousMonth.get("sourceList"); |
|||
ExecutorService exs = Executors.newFixedThreadPool(months.size()); |
|||
// 结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
for (int num = 0; num < months.size() - 1; num++) { |
|||
Map<String,Object> map = (Map<String, Object>) sourceList.get(num); |
|||
Future<Object> future = completionService.submit(new getSourceListTask(map,type,months.get(num + 1).toString(),months.get(num).toString(),materialTypeAll)); |
|||
futureList.add(future); |
|||
} |
|||
for (int i = 0; i < months.size() - 1; i++) { |
|||
Object result = null; |
|||
try { |
|||
result = completionService.take(); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
List<String> barSource = new ArrayList<>(); |
|||
barSource.add("month"); |
|||
for (int i = 0; i < materialTypeAll.size(); i++) { |
|||
barSource.add(materialTypeAll.get(i).getTname()); |
|||
} |
|||
sourceList.add(barSource); |
|||
return sourceList; |
|||
} |
|||
|
|||
|
|||
// 具体执行getSourceList逻辑
|
|||
class getSourceListTask implements Callable<Object> { |
|||
|
|||
String type; |
|||
String start; |
|||
String end; |
|||
Map<String,Object> map; |
|||
List<MaterialType> materialTypeAll; |
|||
getSourceListTask(Map<String,Object> map, String type, String start, String end,List<MaterialType> materialTypeAll){ |
|||
this.map = map; |
|||
this.type = type; |
|||
this.start = start; |
|||
this.end = end; |
|||
this.materialTypeAll = materialTypeAll; |
|||
} |
|||
@Override |
|||
public Object call() throws Exception { |
|||
ExecutorService exs = Executors.newFixedThreadPool(materialTypeAll.size()); |
|||
// 结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
|
|||
for (int j = 0; j < materialTypeAll.size(); j++) { |
|||
Map<String, Object> parm = new HashMap<>(); |
|||
parm.put("type", Integer.parseInt(type)); |
|||
if (Integer.parseInt(type) == 1) { |
|||
parm.put("state", "已入库"); |
|||
} else if (Integer.parseInt(type) == 2) { |
|||
parm.put("state", "已出库"); |
|||
} |
|||
parm.put("start",start); |
|||
parm.put("end", end); |
|||
parm.put("oldId", materialTypeAll.get(j).getOldId()); |
|||
//根据条件获取月份中物料的总额
|
|||
// 测试
|
|||
|
|||
Future<Object> future = completionService.submit(new findMaterialCountTaskForSourceList(parm)); |
|||
futureList.add(future); |
|||
} |
|||
for (int i = 0; i < materialTypeAll.size(); i++) { |
|||
Object result = null; |
|||
try { |
|||
result = completionService.take().get(); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} catch (ExecutionException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
map.putAll((Map<? extends String, ?>) result); |
|||
} |
|||
return map; |
|||
} |
|||
} |
|||
|
|||
|
|||
// 根据条件获取月份中物料的总额用于sourcelist
|
|||
class findMaterialCountTaskForSourceList implements Callable<Object> { |
|||
|
|||
Map<String,Object> map; |
|||
findMaterialCountTaskForSourceList(Map<String,Object> map){ |
|||
this.map = map; |
|||
} |
|||
@Override |
|||
public Object call() throws Exception { |
|||
Map<String,Object> result = new HashMap<>(); |
|||
Integer materialCountByMonth1 = depositoryRecordService.findMaterialCountByMonth2(map); |
|||
Long oldId = Long.valueOf(map.get("oldId").toString()); |
|||
MaterialType materialTypeByOldId = materialTypeService.findMaterialTypeByOldId(oldId); |
|||
result.put(materialTypeByOldId.getTname(),materialCountByMonth1); |
|||
return result; |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取本月之前的月份 |
|||
* |
|||
* @return |
|||
*/ |
|||
public static Map<String, Object> getPreviousMonth() { |
|||
Calendar instance = Calendar.getInstance(); |
|||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM"); |
|||
Map<String, Object> source = new HashMap<>(); |
|||
List<Object> sourceList = new ArrayList<>(); |
|||
int month = instance.get(Calendar.MONTH) + 1; |
|||
// 获取下个月
|
|||
instance.add(Calendar.MONTH,1); |
|||
Long nextMonth = DateUtil.DateTimeByMonthToTimeStamp(formatter.format(instance.getTime())); |
|||
ArrayList<Object> months = new ArrayList<>(); |
|||
months.add(nextMonth); |
|||
instance.add(Calendar.MONTH,-1); |
|||
|
|||
while (month > 0) { |
|||
instance.set(Calendar.MONTH, month); |
|||
instance.set(Calendar.DAY_OF_MONTH, -1); |
|||
source.put("month", month + "月"); |
|||
months.add(DateUtil.DateTimeByMonthToTimeStamp(formatter.format(instance.getTime()))); |
|||
month--; |
|||
sourceList.add(((HashMap<String, Object>) source).clone()); |
|||
} |
|||
instance.set(Calendar.MONTH, month); |
|||
instance.add(Calendar.MONTH, 1); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("months", months); |
|||
map.put("sourceList", sourceList); |
|||
return map; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
Loading…
Reference in new issue