From 7006f8a650412bc2bb4d86fc75b271e8fbba9aa1 Mon Sep 17 00:00:00 2001 From: erdanergou Date: Tue, 7 Feb 2023 15:22:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CompanyServiceImpl.java | 1 - .../depository_manage/TestOther.java | 35 ---- .../TestQyWxAdministration.java | 198 ------------------ .../TestQywxSplitInventoryAll.java | 174 --------------- 4 files changed, 408 deletions(-) delete mode 100644 src/test/java/com/dreamchaser/depository_manage/TestOther.java delete mode 100644 src/test/java/com/dreamchaser/depository_manage/TestQyWxAdministration.java delete mode 100644 src/test/java/com/dreamchaser/depository_manage/TestQywxSplitInventoryAll.java diff --git a/src/main/java/com/dreamchaser/depository_manage/service/impl/CompanyServiceImpl.java b/src/main/java/com/dreamchaser/depository_manage/service/impl/CompanyServiceImpl.java index 1b7dff5d..fbedcf4c 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/impl/CompanyServiceImpl.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/impl/CompanyServiceImpl.java @@ -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; diff --git a/src/test/java/com/dreamchaser/depository_manage/TestOther.java b/src/test/java/com/dreamchaser/depository_manage/TestOther.java deleted file mode 100644 index 1a7e32c2..00000000 --- a/src/test/java/com/dreamchaser/depository_manage/TestOther.java +++ /dev/null @@ -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(){ - - - } -} diff --git a/src/test/java/com/dreamchaser/depository_manage/TestQyWxAdministration.java b/src/test/java/com/dreamchaser/depository_manage/TestQyWxAdministration.java deleted file mode 100644 index 8a6a5178..00000000 --- a/src/test/java/com/dreamchaser/depository_manage/TestQyWxAdministration.java +++ /dev/null @@ -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 qyWxDepartmentListAll = QyWxConfig.getQyWxDepartmentList("8b283ea8ba44697a18c763443c257db5", 51); - - // 设置用于开启线程的部门列表 - List qyWxDepartmentList = new ArrayList<>(); - - - // 定义分页数量 - double size = 20.0; - - // 定义线程数 - int threadSize = (int) Math.ceil(qyWxDepartmentListAll.size() / size); - - // 开启对应数量的线程 - ExecutorService exs = Executors.newFixedThreadPool(threadSize); - - // 1.定义CompletionService - CompletionService completionService = new ExecutorCompletionService(exs); - - // 线程结果集 - List> futureList = new ArrayList>(); - - - 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 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 future = completionService.submit(taskTest); - futureList.add(future); - } - - // 树结构结果集 - List 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 qyWxDepartmentIdList = QyWxConfig.getQyWxDepartmentIdList("8b283ea8ba44697a18c763443c257db5", 51); - System.out.println(qyWxDepartmentIdList); - } - - /** - * 用于构造树形模板 - * - * @param qywxDepartment - * @param children - * @return - */ - public Map InitTree(qywxDepartment qywxDepartment, List children) { - if (qywxDepartment != null) { - Map 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 { - - /** - * 用于开启线程的部门列表 - */ - List qywxDepartmentList; - - /** - * 全部部门列表 - */ - List qywxDepartmentListAll; - - public InitDepartmentTree(List qywxDepartmentList, List qywxDepartmentListAll) { - this.qywxDepartmentList = qywxDepartmentList; - this.qywxDepartmentListAll = qywxDepartmentListAll; - } - - @Override - public Object call() throws Exception { - ExecutorService exs = Executors.newFixedThreadPool(qywxDepartmentList.size()); - // 结果集 - List list = new ArrayList<>(); - List> futureList = new ArrayList>(); - // 1.定义CompletionService - CompletionService completionService = new ExecutorCompletionService(exs); - - // 开启对应数目的线程 - for (int i = 0; i < qywxDepartmentList.size(); i++) { - qywxDepartment qywxDepartment = qywxDepartmentList.get(i); - // 开启线程 - Future 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 { - - // 所有部门列表 - List qywxDepartmentList; - // 当前部门 - qywxDepartment qywxDepartment; - - public buildDepartmentTree(List qywxDepartmentList, qywxDepartment qywxDepartment) { - this.qywxDepartmentList = qywxDepartmentList; - this.qywxDepartment = qywxDepartment; - } - - @Override - public Object call() throws Exception { - List children = new ArrayList<>(); - for (qywxDepartment department : qywxDepartmentList) { - // 如果该部门是当前部门的子部门 - if (Integer.compare(qywxDepartment.getId(), department.getParentid()) == 0) { - Map stringObjectMap = InitTree(department, null); - children.add(stringObjectMap); - } - } - return InitTree(qywxDepartment, children); - } - } - - -} diff --git a/src/test/java/com/dreamchaser/depository_manage/TestQywxSplitInventoryAll.java b/src/test/java/com/dreamchaser/depository_manage/TestQywxSplitInventoryAll.java deleted file mode 100644 index f1dcf4f4..00000000 --- a/src/test/java/com/dreamchaser/depository_manage/TestQywxSplitInventoryAll.java +++ /dev/null @@ -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 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 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 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; - } - } - } - -}