|
|
@ -44,30 +44,174 @@ public class InventorySunburstDataTest { |
|
|
@Test |
|
|
@Test |
|
|
public void main() { |
|
|
public void main() { |
|
|
String type = "2"; |
|
|
String type = "2"; |
|
|
|
|
|
String dayName = "6月"; |
|
|
|
|
|
String dayNumberString = dayName.split("月")[0]; |
|
|
|
|
|
Map<String, Object> sunBurstDataForInventoryByMonth = getSunBurstDataForInventoryByMonth(dayName, "办公用品", 40); |
|
|
|
|
|
System.out.println(JSONObject.toJSONString(sunBurstDataForInventoryByMonth)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// int dayNumber = Integer.parseInt(dayNumberString);
|
|
|
|
|
|
// 获取本月之前的月份
|
|
|
|
|
|
// Map<String, Object> previousMonth = DateUtil.getPreviousMonth();
|
|
|
|
|
|
// 获取月份的时间戳
|
|
|
|
|
|
// List<Long> months = ObjectFormatUtil.objToList(previousMonth.get("months"), Long.class);
|
|
|
|
|
|
// 获取开始时间
|
|
|
|
|
|
// Long start = months.get(months.size() - dayNumber - 1);
|
|
|
|
|
|
// 获取结束时间
|
|
|
|
|
|
// Long end = months.get(0);
|
|
|
|
|
|
// List<MaterialType> materialTypeNoParent = materialTypeService.findMaterialTypeNoParent();
|
|
|
|
|
|
// Map<String, Object> sunBurstDataForApplication = getSunBurstDataForApplication(dayName, "1", start, end, materialTypeNoParent, 40);
|
|
|
|
|
|
// System.out.println(sunBurstDataForApplication);
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 用于获取库存旭日图数据 |
|
|
|
|
|
* @param dayName 待获取日期名称 |
|
|
|
|
|
* @param mtName 待查询物料类型 |
|
|
|
|
|
* @param depositoryId 待查询仓库 |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
public Map<String, Object> getSunBurstDataForInventoryByMonth(String dayName, String mtName, Integer depositoryId) { |
|
|
|
|
|
|
|
|
|
|
|
String dayNumberString = dayName.split("月")[0]; |
|
|
|
|
|
int dayNumber = Integer.parseInt(dayNumberString); |
|
|
// 获取本月之前的月份
|
|
|
// 获取本月之前的月份
|
|
|
Map<String, Object> previousMonth = DateUtil.getPreviousMonth(); |
|
|
Map<String, Object> previousMonth = DateUtil.getPreviousMonth(); |
|
|
// 获取月份的时间戳
|
|
|
// 获取月份的时间戳
|
|
|
List<Long> months = ObjectFormatUtil.objToList(previousMonth.get("months"), Long.class); |
|
|
List<Long> months = ObjectFormatUtil.objToList(previousMonth.get("months"), Long.class); |
|
|
List<MaterialType> materialTypeNoParent = materialTypeService.findMaterialTypeNoParent(); |
|
|
List<MaterialType> materialTypeList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
// 获取开始时间
|
|
|
|
|
|
Long start = months.get(months.size() - dayNumber - 1); |
|
|
|
|
|
// 获取结束时间
|
|
|
|
|
|
Long end = months.get(0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> sourceListTask = getSunBurstDataForApplication("7月", type, months.get(2), months.get(1), materialTypeNoParent); |
|
|
/** |
|
|
System.out.println(JSONObject.toJSONString(sourceListTask)); |
|
|
* 用于执行获取旭日图数据的线程类 |
|
|
|
|
|
*/ |
|
|
|
|
|
class TemporaryClass implements Callable<Map<String, Object>> { |
|
|
|
|
|
private String type; |
|
|
|
|
|
private List<MaterialType> materialTypeList; |
|
|
|
|
|
|
|
|
|
|
|
public TemporaryClass(String type, List<MaterialType> materialTypeList) { |
|
|
|
|
|
this.type = type; |
|
|
|
|
|
this.materialTypeList = materialTypeList; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public Map<String, Object> call() throws Exception { |
|
|
|
|
|
Map<String, Object> data = getSunBurstDataForApplication(dayName, type, start, end, materialTypeList, depositoryId); |
|
|
|
|
|
return data; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 定义线程池
|
|
|
|
|
|
ExecutorService exs = new ThreadPoolExecutor(3, 6, 100, TimeUnit.SECONDS, new LinkedBlockingQueue<>(6)); |
|
|
|
|
|
if (mtName == null || "".equals(mtName)) { |
|
|
|
|
|
// 获取要执行的物料类型列表
|
|
|
|
|
|
materialTypeList = materialTypeService.findMaterialTypeNoParent(); |
|
|
|
|
|
} else { |
|
|
|
|
|
List<MaterialType> materialTypeByNames = materialTypeService.findMaterialTypeByName(mtName); |
|
|
|
|
|
MaterialType materialType = null; |
|
|
|
|
|
if (materialTypeByNames.size() > 0) { |
|
|
|
|
|
materialType = materialTypeByNames.get(0); |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new MyException("错误,不存在当前名称的类型"); |
|
|
|
|
|
} |
|
|
|
|
|
materialTypeList = materialTypeService.findChildForMaterialTypeByParent(materialType.getOldId()); |
|
|
|
|
|
} |
|
|
|
|
|
// 结果集
|
|
|
|
|
|
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|
|
|
|
|
// 1.定义CompletionService
|
|
|
|
|
|
CompletionService<Map<String, Object>> completionService = new ExecutorCompletionService<Map<String, Object>>(exs); |
|
|
|
|
|
|
|
|
|
|
|
// 获取入库的旭日图数据
|
|
|
|
|
|
Future<Map<String, Object>> applicationInThread = completionService.submit(new TemporaryClass("1", materialTypeList)); |
|
|
|
|
|
// 获取出库的旭日图数据
|
|
|
|
|
|
Future<Map<String, Object>> applicationOutThread = completionService.submit(new TemporaryClass("2", materialTypeList)); |
|
|
|
|
|
// 获取当前库存的旭日图数据
|
|
|
|
|
|
Future<Map<String, Object>> InventoryThread = completionService.submit(new TemporaryClass("3", materialTypeList)); |
|
|
|
|
|
Map<String, Object> result = new HashMap<String, Object>(); |
|
|
|
|
|
try { |
|
|
|
|
|
// 获取入库的旭日图数据列表
|
|
|
|
|
|
List<Object> applicationInDataList = ObjectFormatUtil.objToList(applicationInThread.get().get("children"), Object.class); |
|
|
|
|
|
// 获取出库的旭日图数据列表
|
|
|
|
|
|
List<Object> applicationOutDataList = ObjectFormatUtil.objToList(applicationOutThread.get().get("children"), Object.class); |
|
|
|
|
|
// 获取库存的旭日图数据列表
|
|
|
|
|
|
List<Object> inventoryDataList = ObjectFormatUtil.objToList(InventoryThread.get().get("children"), Object.class); |
|
|
|
|
|
PublicConfig.closeThreadPool(exs); |
|
|
|
|
|
// 用于存储入库时的旭日图具体数据
|
|
|
|
|
|
Map<String, Double> applicationInData = new HashMap<>(); |
|
|
|
|
|
// 用于存储出库时的旭日图具体数据
|
|
|
|
|
|
Map<String, Double> applicationOutData = new HashMap<>(); |
|
|
|
|
|
// 用于存储库存时的旭日图具体数据
|
|
|
|
|
|
Map<String, Double> inventoryData = new HashMap<>(); |
|
|
|
|
|
for (int i = 0; i < applicationInDataList.size(); i++) { |
|
|
|
|
|
// 循环获取所有出库、入库、库存的旭日图对应类型与其值
|
|
|
|
|
|
Map<String, Object> applicationInDataMap = ObjectFormatUtil.objToMap(applicationInDataList.get(i), String.class, Object.class); |
|
|
|
|
|
applicationInData.put((String) applicationInDataMap.get("name"), ObjectFormatUtil.toDouble(applicationInDataMap.get("value"))); |
|
|
|
|
|
Map<String, Object> applicationOutDataMap = ObjectFormatUtil.objToMap(applicationOutDataList.get(i), String.class, Object.class); |
|
|
|
|
|
applicationOutData.put((String) applicationOutDataMap.get("name"), ObjectFormatUtil.toDouble(applicationOutDataMap.get("value"))); |
|
|
|
|
|
Map<String, Object> inventoryDataMap = ObjectFormatUtil.objToMap(inventoryDataList.get(i), String.class, Object.class); |
|
|
|
|
|
inventoryData.put((String) inventoryDataMap.get("name"), ObjectFormatUtil.toDouble(inventoryDataMap.get("value"))); |
|
|
|
|
|
} |
|
|
|
|
|
double sumInventory = 0.0; |
|
|
|
|
|
List<Object> resultData = new ArrayList<>(); |
|
|
|
|
|
// 用于生产随机的颜色
|
|
|
|
|
|
Random random = new Random(); |
|
|
|
|
|
|
|
|
|
|
|
for (String key : inventoryData.keySet()) { |
|
|
|
|
|
Map<String, Object> resultDataItem = new HashMap<>(); |
|
|
|
|
|
// 获取当前类型库存
|
|
|
|
|
|
double value = inventoryData.get(key); |
|
|
|
|
|
// 获取当前类型入库数
|
|
|
|
|
|
double inQuantity = applicationInData.get(key); |
|
|
|
|
|
// 获取当前类型出库数
|
|
|
|
|
|
double outQuantity = applicationOutData.get(key); |
|
|
|
|
|
// 获取计算后的库存(库存+出库-入库)
|
|
|
|
|
|
double inventory = ObjectFormatUtil.subtract(ObjectFormatUtil.sum(value, outQuantity), inQuantity); |
|
|
|
|
|
resultDataItem.put("name", key); |
|
|
|
|
|
resultDataItem.put("value", inventory); |
|
|
|
|
|
Map<String, String> itemStyle = new HashMap<>(); |
|
|
|
|
|
int r = random.nextInt(256); |
|
|
|
|
|
int g = random.nextInt(256); |
|
|
|
|
|
int b = random.nextInt(256); |
|
|
|
|
|
itemStyle.put("color", "rgb(" + r + "," + g + "," + b + ")"); |
|
|
|
|
|
resultDataItem.put("itemStyle", itemStyle); |
|
|
|
|
|
// 更新当前类型库存数
|
|
|
|
|
|
sumInventory = ObjectFormatUtil.sum(sumInventory, inventory); |
|
|
|
|
|
resultData.add(resultDataItem); |
|
|
|
|
|
} |
|
|
|
|
|
result.put("children", resultData); |
|
|
|
|
|
result.put("value", sumInventory); |
|
|
|
|
|
result.put("name", dayName); |
|
|
|
|
|
Map<String, String> itemStyle = new HashMap<>(); |
|
|
|
|
|
int r = random.nextInt(256); |
|
|
|
|
|
int g = random.nextInt(256); |
|
|
|
|
|
int b = random.nextInt(256); |
|
|
|
|
|
itemStyle.put("color", "rgb(" + r + "," + g + "," + b + ")"); |
|
|
|
|
|
result.put("itemStyle", itemStyle); |
|
|
|
|
|
} catch (InterruptedException | ExecutionException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
} |
|
|
} |
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 用于获取出入库的旭日图数据 |
|
|
* 用于获取旭日图数据 |
|
|
* |
|
|
* |
|
|
* @param dayName 当前月份名称 |
|
|
* @param dayName 当前月份名称 |
|
|
* @param type 查看类型 |
|
|
* @param type 查看类型(1入库2出库3库存) |
|
|
* @param start 开始时间 |
|
|
* @param start 开始时间 |
|
|
* @param end 结束时间 |
|
|
* @param end 结束时间 |
|
|
* @param materialTypeAll 当前查看物料类型 |
|
|
* @param materialTypeAll 当前查看物料类型 |
|
|
|
|
|
* @param depositoryId 当前查看仓库id |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
public Map<String, Object> getSunBurstDataForApplication(String dayName, String type, Long start, Long end, List<MaterialType> materialTypeAll) { |
|
|
public Map<String, Object> getSunBurstDataForApplication(String dayName, String type, Long start, Long end, List<MaterialType> materialTypeAll, Integer depositoryId) { |
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
|
|
|
|
@ -75,6 +219,10 @@ public class InventorySunburstDataTest { |
|
|
|
|
|
|
|
|
int threadSize = Runtime.getRuntime().availableProcessors(); |
|
|
int threadSize = Runtime.getRuntime().availableProcessors(); |
|
|
|
|
|
|
|
|
|
|
|
if (maxThreadSize < threadSize) { |
|
|
|
|
|
maxThreadSize = threadSize * 2; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
ExecutorService exs = new ThreadPoolExecutor(threadSize, maxThreadSize, 100, TimeUnit.SECONDS, new LinkedBlockingQueue<>(maxThreadSize)); |
|
|
ExecutorService exs = new ThreadPoolExecutor(threadSize, maxThreadSize, 100, TimeUnit.SECONDS, new LinkedBlockingQueue<>(maxThreadSize)); |
|
|
|
|
|
|
|
|
// 结果集
|
|
|
// 结果集
|
|
|
@ -83,13 +231,20 @@ public class InventorySunburstDataTest { |
|
|
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|
|
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|
|
|
|
|
|
|
|
List<Object> resultForData = new ArrayList<>(); |
|
|
List<Object> resultForData = new ArrayList<>(); |
|
|
|
|
|
int openThreadSize = 0; |
|
|
for (MaterialType materialType : materialTypeAll) { |
|
|
for (MaterialType materialType : materialTypeAll) { |
|
|
// 测试
|
|
|
Future<Object> future = null; |
|
|
Future<Object> future = completionService.submit(new getSunBurstDataForApplicationByDepository(type, start, end, materialType)); |
|
|
if ("3".equals(type)) { |
|
|
|
|
|
future = completionService.submit(new getSunBurstDataForInventoryByDepository(materialType, depositoryId)); |
|
|
|
|
|
} else { |
|
|
|
|
|
future = completionService.submit(new getSunBurstDataForApplicationByDepository(type, start, end, materialType, depositoryId)); |
|
|
|
|
|
} |
|
|
futureList.add(future); |
|
|
futureList.add(future); |
|
|
|
|
|
openThreadSize++; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
double sum = 0.0; |
|
|
double sum = 0.0; |
|
|
for (int i = 0; i < materialTypeAll.size(); i++) { |
|
|
for (int i = 0; i < openThreadSize; i++) { |
|
|
Object obj = null; |
|
|
Object obj = null; |
|
|
try { |
|
|
try { |
|
|
obj = completionService.take().get(); |
|
|
obj = completionService.take().get(); |
|
|
@ -111,6 +266,7 @@ public class InventorySunburstDataTest { |
|
|
int b = random.nextInt(256); |
|
|
int b = random.nextInt(256); |
|
|
itemStyle.put("color", "rgb(" + r + "," + g + "," + b + ")"); |
|
|
itemStyle.put("color", "rgb(" + r + "," + g + "," + b + ")"); |
|
|
result.put("itemStyle", itemStyle); |
|
|
result.put("itemStyle", itemStyle); |
|
|
|
|
|
result.put("sunburstDataType", type); |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -124,7 +280,7 @@ public class InventorySunburstDataTest { |
|
|
* @param mtName 类别名称 |
|
|
* @param mtName 类别名称 |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
public Map<String, Object> getSunBurstDataByMtName(String dayName, String type, Long start, Long end, String mtName) { |
|
|
public Map<String, Object> getSunBurstDataByMtName(String dayName, String type, Long start, Long end, String mtName, Integer depositoryId) { |
|
|
List<MaterialType> materialTypeByNames = materialTypeService.findMaterialTypeByName(mtName); |
|
|
List<MaterialType> materialTypeByNames = materialTypeService.findMaterialTypeByName(mtName); |
|
|
MaterialType materialType = null; |
|
|
MaterialType materialType = null; |
|
|
if (materialTypeByNames.size() > 0) { |
|
|
if (materialTypeByNames.size() > 0) { |
|
|
@ -150,7 +306,7 @@ public class InventorySunburstDataTest { |
|
|
|
|
|
|
|
|
int runThreadSize = 0; |
|
|
int runThreadSize = 0; |
|
|
for (MaterialType value : childMaterialTypeList) { |
|
|
for (MaterialType value : childMaterialTypeList) { |
|
|
Future<Object> submit = completionService.submit(new getSunBurstDataForApplicationByDepository(type, start, end, value)); |
|
|
Future<Object> submit = completionService.submit(new getSunBurstDataForApplicationByDepository(type, start, end, value, depositoryId)); |
|
|
runThreadSize++; |
|
|
runThreadSize++; |
|
|
futureList.add(submit); |
|
|
futureList.add(submit); |
|
|
} |
|
|
} |
|
|
@ -183,10 +339,8 @@ public class InventorySunburstDataTest { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 用于具体执行查询旭日图的多线程类 |
|
|
* 用于具体执行查询出入库旭日图的多线程类 |
|
|
*/ |
|
|
*/ |
|
|
class getSunBurstDataForApplicationByDepository implements Callable<Object> { |
|
|
class getSunBurstDataForApplicationByDepository implements Callable<Object> { |
|
|
|
|
|
|
|
|
@ -195,26 +349,23 @@ public class InventorySunburstDataTest { |
|
|
Long start; |
|
|
Long start; |
|
|
Long end; |
|
|
Long end; |
|
|
MaterialType materialType; |
|
|
MaterialType materialType; |
|
|
|
|
|
Integer depositoryId; |
|
|
|
|
|
|
|
|
public getSunBurstDataForApplicationByDepository(String type, Long start, Long end, MaterialType materialType) { |
|
|
public getSunBurstDataForApplicationByDepository(String type, Long start, Long end, MaterialType materialType, Integer depositoryId) { |
|
|
this.type = type; |
|
|
this.type = type; |
|
|
this.start = start; |
|
|
this.start = start; |
|
|
this.end = end; |
|
|
this.end = end; |
|
|
this.materialType = materialType; |
|
|
this.materialType = materialType; |
|
|
|
|
|
this.depositoryId = depositoryId; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Object call() throws Exception { |
|
|
public Object call() throws Exception { |
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
map.put("type", ObjectFormatUtil.toInteger(type)); |
|
|
map.put("type", ObjectFormatUtil.toInteger(type)); |
|
|
if (ObjectFormatUtil.toInteger(type) == 1) { |
|
|
|
|
|
map.put("state", "已入库"); |
|
|
|
|
|
} else if (ObjectFormatUtil.toInteger(type) == 2) { |
|
|
|
|
|
map.put("state", "已出库"); |
|
|
|
|
|
} |
|
|
|
|
|
map.put("start", start); |
|
|
map.put("start", start); |
|
|
map.put("end", end); |
|
|
map.put("end", end); |
|
|
map.put("depositoryId", "41"); |
|
|
map.put("depository_id", depositoryId); |
|
|
map.put("oldId", materialType.getOldId()); |
|
|
map.put("oldId", materialType.getOldId()); |
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
Double materialCountByMonth = depositoryRecordService.calMaterialTypeTopCount(map); |
|
|
Double materialCountByMonth = depositoryRecordService.calMaterialTypeTopCount(map); |
|
|
@ -232,4 +383,40 @@ public class InventorySunburstDataTest { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 用于具体执行查询库存旭日图的多线程类 |
|
|
|
|
|
*/ |
|
|
|
|
|
class getSunBurstDataForInventoryByDepository implements Callable<Object> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MaterialType materialType; |
|
|
|
|
|
Integer depositoryId; |
|
|
|
|
|
|
|
|
|
|
|
public getSunBurstDataForInventoryByDepository(MaterialType materialType, Integer depositoryId) { |
|
|
|
|
|
this.materialType = materialType; |
|
|
|
|
|
this.depositoryId = depositoryId; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public Object call() throws Exception { |
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
|
map.put("depositoryId", depositoryId); |
|
|
|
|
|
map.put("oldId", materialType.getOldId()); |
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
|
Double materialCountByMonth = materialService.calMaterialTypeTopCount(map); |
|
|
|
|
|
result.put("name", materialType.getTname()); |
|
|
|
|
|
result.put("value", materialCountByMonth); |
|
|
|
|
|
Map<String, String> itemStyle = new HashMap<>(); |
|
|
|
|
|
// 用于生产随机的颜色
|
|
|
|
|
|
Random random = new Random(); |
|
|
|
|
|
int r = random.nextInt(256); |
|
|
|
|
|
int g = random.nextInt(256); |
|
|
|
|
|
int b = random.nextInt(256); |
|
|
|
|
|
itemStyle.put("color", "rgb(" + r + "," + g + "," + b + ")"); |
|
|
|
|
|
result.put("itemStyle", itemStyle); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|