Browse Source

优化部分页面展示

lwx_dev
erdanergou 3 years ago
parent
commit
7006f8a650
  1. 1
      src/main/java/com/dreamchaser/depository_manage/service/impl/CompanyServiceImpl.java
  2. 35
      src/test/java/com/dreamchaser/depository_manage/TestOther.java
  3. 198
      src/test/java/com/dreamchaser/depository_manage/TestQyWxAdministration.java
  4. 174
      src/test/java/com/dreamchaser/depository_manage/TestQywxSplitInventoryAll.java

1
src/main/java/com/dreamchaser/depository_manage/service/impl/CompanyServiceImpl.java

@ -13,7 +13,6 @@ import com.dreamchaser.depository_manage.pojo.RoleAndDepository;
import com.dreamchaser.depository_manage.service.CompanyService;
import com.dreamchaser.depository_manage.utils.HttpUtils;
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil;
import com.sun.org.apache.xml.internal.security.Init;
import org.apache.http.protocol.HTTP;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.factory.annotation.Autowired;

35
src/test/java/com/dreamchaser/depository_manage/TestOther.java

@ -1,35 +0,0 @@
package com.dreamchaser.depository_manage;
import com.alibaba.fastjson.JSONObject;
import com.dreamchaser.depository_manage.config.PortConfig;
import com.dreamchaser.depository_manage.config.QyWxConfig;
import com.dreamchaser.depository_manage.entity.ApplicationOutRecordMin;
import com.dreamchaser.depository_manage.entity.UserByPort;
import com.dreamchaser.depository_manage.entity.qywxDepartment;
import com.dreamchaser.depository_manage.mapper.DepositoryRecordMapper;
import com.dreamchaser.depository_manage.pojo.ApplicationInRecordP;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RunWith(SpringRunner.class)
@SpringBootTest
public class TestOther {
@Autowired
DepositoryRecordMapper depositoryRecordMapper;
@Test
public void Test(){
}
}

198
src/test/java/com/dreamchaser/depository_manage/TestQyWxAdministration.java

@ -1,198 +0,0 @@
package com.dreamchaser.depository_manage;
import com.alibaba.fastjson.JSONObject;
import com.dreamchaser.depository_manage.config.QyWxConfig;
import com.dreamchaser.depository_manage.entity.MaterialType;
import com.dreamchaser.depository_manage.entity.ThreeAboutMan;
import com.dreamchaser.depository_manage.entity.qywxDepartment;
import com.dreamchaser.depository_manage.service.impl.QyWxOperationService;
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 TestQyWxAdministration {
@Test
public void Test() {
// 获取所有企业微信的部门列表
List<qywxDepartment> qyWxDepartmentListAll = QyWxConfig.getQyWxDepartmentList("8b283ea8ba44697a18c763443c257db5", 51);
// 设置用于开启线程的部门列表
List<qywxDepartment> qyWxDepartmentList = new ArrayList<>();
// 定义分页数量
double size = 20.0;
// 定义线程数
int threadSize = (int) Math.ceil(qyWxDepartmentListAll.size() / size);
// 开启对应数量的线程
ExecutorService exs = Executors.newFixedThreadPool(threadSize);
// 1.定义CompletionService
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs);
// 线程结果集
List<Future<Object>> futureList = new ArrayList<Future<Object>>();
for (int i = 0; i < qyWxDepartmentListAll.size(); i++) {
// 获取当前类型
qywxDepartment qywxDepartment = qyWxDepartmentListAll.get(i);
if (((i + 1) % 20) == 0) { // 如果有100个开启线程进行处理
qyWxDepartmentList.add(qywxDepartment);
InitDepartmentTree taskTest = new InitDepartmentTree(qyWxDepartmentList, qyWxDepartmentListAll);
Future<Object> future = completionService.submit(taskTest);
futureList.add(future); // 添加到结果集
qyWxDepartmentList = new ArrayList<>(); // 情况列表
} else {
// 添加id到列表中
if (Integer.compare(qywxDepartment.getParentid(), 3) == 0) {
qyWxDepartmentList.add(qywxDepartment);
}
}
}
if (qyWxDepartmentList.size() > 0) {
// 如果有剩余,开启线程进行处理
InitDepartmentTree taskTest = new InitDepartmentTree(qyWxDepartmentList, qyWxDepartmentListAll);
Future<Object> future = completionService.submit(taskTest);
futureList.add(future);
}
// 树结构结果集
List<Object> list = new ArrayList<>();
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);
}
System.out.println(JSONObject.toJSONString(list));
}
@Test
public void Test2(){
List<Integer> qyWxDepartmentIdList = QyWxConfig.getQyWxDepartmentIdList("8b283ea8ba44697a18c763443c257db5", 51);
System.out.println(qyWxDepartmentIdList);
}
/**
* 用于构造树形模板
*
* @param qywxDepartment
* @param children
* @return
*/
public Map<String, Object> InitTree(qywxDepartment qywxDepartment, List<Object> children) {
if (qywxDepartment != null) {
Map<String, Object> map = new HashMap<>();
map.put("title", qywxDepartment.getName());
map.put("id", qywxDepartment.getId());
map.put("children", children);
return map;
} else {
return null;
}
}
/**
* 用于创建部门树结构
*/
class InitDepartmentTree implements Callable<Object> {
/**
* 用于开启线程的部门列表
*/
List<qywxDepartment> qywxDepartmentList;
/**
* 全部部门列表
*/
List<qywxDepartment> qywxDepartmentListAll;
public InitDepartmentTree(List<qywxDepartment> qywxDepartmentList, List<qywxDepartment> qywxDepartmentListAll) {
this.qywxDepartmentList = qywxDepartmentList;
this.qywxDepartmentListAll = qywxDepartmentListAll;
}
@Override
public Object call() throws Exception {
ExecutorService exs = Executors.newFixedThreadPool(qywxDepartmentList.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 < qywxDepartmentList.size(); i++) {
qywxDepartment qywxDepartment = qywxDepartmentList.get(i);
// 开启线程
Future<Object> submit = completionService.submit(new buildDepartmentTree(qywxDepartmentListAll, qywxDepartment));
futureList.add(submit);
}
// 收集结果
for (int i = 0; i < qywxDepartmentList.size(); i++) {
Object result = null;
try {
result = completionService.take().get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
list.add(result);
}
return list;
}
}
/**
* 构造树结构对象
*/
class buildDepartmentTree implements Callable<Object> {
// 所有部门列表
List<qywxDepartment> qywxDepartmentList;
// 当前部门
qywxDepartment qywxDepartment;
public buildDepartmentTree(List<qywxDepartment> qywxDepartmentList, qywxDepartment qywxDepartment) {
this.qywxDepartmentList = qywxDepartmentList;
this.qywxDepartment = qywxDepartment;
}
@Override
public Object call() throws Exception {
List<Object> children = new ArrayList<>();
for (qywxDepartment department : qywxDepartmentList) {
// 如果该部门是当前部门的子部门
if (Integer.compare(qywxDepartment.getId(), department.getParentid()) == 0) {
Map<String, Object> stringObjectMap = InitTree(department, null);
children.add(stringObjectMap);
}
}
return InitTree(qywxDepartment, children);
}
}
}

174
src/test/java/com/dreamchaser/depository_manage/TestQywxSplitInventoryAll.java

@ -1,174 +0,0 @@
package com.dreamchaser.depository_manage;
import com.dreamchaser.depository_manage.entity.MaterialAndPlace;
import com.dreamchaser.depository_manage.entity.SplitInfo;
import com.dreamchaser.depository_manage.entity.SplitInventory;
import com.dreamchaser.depository_manage.mapper.PlaceMapper;
import com.dreamchaser.depository_manage.mapper.SplitUnitMapper;
import com.dreamchaser.depository_manage.service.SplitUnitService;
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.HashMap;
import java.util.Map;
@SpringBootTest
@RunWith(SpringRunner.class)
public class TestQywxSplitInventoryAll {
@Autowired
SplitUnitMapper splitUnitMapper;
@Autowired
PlaceMapper placeMapper;
@Test
public void Test(){
Map<String,Object> map = new HashMap<>();
map.put("mid","6");
map.put("pid","8");
MaterialAndPlace placeAndMaterialByMidAndPid = placeMapper.findPlaceAndMaterialByMidAndPid(map);
int allInventoryForSplitInfo = findAllInventoryForSplitInfo(-1, placeAndMaterialByMidAndPid, 4, 0, true);
System.out.println(allInventoryForSplitInfo);
}
public int findAllInventoryForSplitInfo(Integer splitInfoId, MaterialAndPlace materialAndPlace, Integer baseSplitInfoId, int saveQuantity, boolean allQuantityFlag) {
if (allQuantityFlag) {
// 用于标志是否第一次计算
boolean flag = false;
// 获取当前基础单位
SplitInfo baseSplitInfo = splitUnitMapper.findSplitInfoById(baseSplitInfoId);
// 获取当前基础单位的库存
Map<String, Object> paramForSplitInventory = new HashMap<>();
paramForSplitInventory.put("iid", materialAndPlace.getId());
// 如果当前获取的为对应基础单位的所有库存
// 如果是第一次计算
if (Integer.compare(saveQuantity, 0) == 0) {
// 如果是第一次计算
paramForSplitInventory.put("sid", baseSplitInfoId);
// 当前基础单位的库存
SplitInventory baseSplitInventory = splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory);
if (baseSplitInventory != null) {
saveQuantity += baseSplitInventory.getSaveQuantity();
}
}
if (Integer.compare(-1, splitInfoId) != 0) {
flag = true;
// 获取当前记录的子记录
SplitInfo splitInfoByParentId = splitUnitMapper.findSplitInfoByParentId(splitInfoId);
paramForSplitInventory.put("sid", splitInfoId);
SplitInventory splitInventoryByIidAndSid = splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory);
if (splitInventoryByIidAndSid != null) {
saveQuantity += splitInventoryByIidAndSid.getSaveQuantity() * splitInfoByParentId.getQuantity();
}
}
if (baseSplitInfo.getParentId() != null && !flag) {
// 如果有父级且是第一次
// 获取其父级
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(baseSplitInfo.getParentId());
return findAllInventoryForSplitInfo(parentSplitInfo.getId(), materialAndPlace, baseSplitInfoId, saveQuantity, allQuantityFlag);
} else {
if (flag) {
// 如果不是第一次
// 获取当前的拆单记录
SplitInfo splitInfo = splitUnitMapper.findSplitInfoById(splitInfoId);
if (splitInfo.getParentId() != null) {
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId());
return findAllInventoryForSplitInfo(parentSplitInfo.getId(), materialAndPlace, baseSplitInfoId, saveQuantity, allQuantityFlag);
} else {
int splitInfoScaleQuantity = findSplitInfoScaleQuantity(baseSplitInfo, -1);
return saveQuantity + materialAndPlace.getQuantity() * splitInfoScaleQuantity;
}
} else {
int splitInfoScaleQuantity = findSplitInfoScaleQuantity(baseSplitInfo, -1);
return saveQuantity + materialAndPlace.getQuantity() * splitInfoScaleQuantity;
}
}
}
else {
// 如果不是获取所有库存
// 获取当前基础单位
SplitInfo baseSplitInfo = splitUnitMapper.findSplitInfoById(baseSplitInfoId);
// 获取当前基础单位的库存
Map<String, Object> paramForSplitInventory = new HashMap<>();
paramForSplitInventory.put("iid", materialAndPlace.getId());
// 如果当前获取的为对应基础单位的所有库存
if (Integer.compare(saveQuantity, 0) == 0) {
// 如果是第一次计算
paramForSplitInventory.put("sid", baseSplitInfoId);
// 当前基础单位的库存
SplitInventory baseSplitInventory = splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory);
saveQuantity += baseSplitInventory.getSaveQuantity();
}
// 获取当前拆单记录与基础拆单记录之间的进制
int splitInfoScaleQuantity = findSplitInfoScaleQuantity(baseSplitInfo, splitInfoId);
paramForSplitInventory.put("sid", splitInfoId);
// 获取当前拆单记录的库存
SplitInventory splitInventory = splitUnitMapper.findSplitInventoryByIidAndSid(paramForSplitInventory);
saveQuantity += splitInventory.getSaveQuantity() * splitInfoScaleQuantity;
// 获取当前的子类
SplitInfo splitInfoByParentId = splitUnitMapper.findSplitInfoByParentId(splitInfoId);
if (splitInfoByParentId != null && Integer.compare(splitInfoByParentId.getId(), baseSplitInfoId) != 0) {
// 如果有子类
return findAllInventoryForSplitInfo(splitInfoByParentId.getId(), materialAndPlace, baseSplitInfoId, saveQuantity, allQuantityFlag);
} else {
// 如果没有
return saveQuantity;
}
}
}
public int findSplitInfoScaleQuantity(SplitInfo splitInfo, Integer parentSplitInfoId) {
int quantity = 1; // 定义进制
if (parentSplitInfoId != null && Integer.compare(-1, parentSplitInfoId) != 0) {
// 如果待查询的父级不是顶级
if (Integer.compare(splitInfo.getParentId(), parentSplitInfoId) == 0) {
// 如果当前拆单记录是目标拆单单位
quantity *= splitInfo.getQuantity();
return quantity;
} else {
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(splitInfo.getParentId());
return quantity * findSplitInfoScaleQuantity(splitInfoById, parentSplitInfoId);
}
} else {
quantity *= splitInfo.getQuantity();
if (splitInfo.getParentId() != null) {
SplitInfo splitInfoById = splitUnitMapper.findSplitInfoById(splitInfo.getParentId());
return quantity * findSplitInfoScaleQuantity(splitInfoById, parentSplitInfoId);
} else {
return quantity;
}
}
}
}
Loading…
Cancel
Save