|
|
|
@ -6150,6 +6150,160 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 用于获取库存旭日图数据 |
|
|
|
* |
|
|
|
* @param dayName 待获取日期名称 |
|
|
|
* @param mtName 待查询物料类型 |
|
|
|
* @param depositoryId 待查询仓库 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public Map<String, Object> getSunBurstDataForInventoryByMonth(String dayName, String mtName, Integer depositoryId) { |
|
|
|
// 定义结果集
|
|
|
|
Map<String, Object> result = new HashMap<String, Object>(); |
|
|
|
|
|
|
|
// 用于生产随机的颜色
|
|
|
|
Random random = new Random(); |
|
|
|
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); |
|
|
|
|
|
|
|
String dayNumberString = dayName.split("月")[0]; |
|
|
|
int dayNumber = Integer.parseInt(dayNumberString); |
|
|
|
// 获取本月之前的月份
|
|
|
|
Map<String, Object> previousMonth = DateUtil.getPreviousMonth(); |
|
|
|
// 获取月份的时间戳
|
|
|
|
List<Long> months = ObjectFormatUtil.objToList(previousMonth.get("months"), Long.class); |
|
|
|
List<MaterialType> materialTypeList = new ArrayList<>(); |
|
|
|
|
|
|
|
// 获取开始时间
|
|
|
|
Long start = months.get(months.size() - dayNumber - 1); |
|
|
|
// 获取结束时间
|
|
|
|
Long end = months.get(0); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 用于执行获取旭日图数据的线程类 |
|
|
|
*/ |
|
|
|
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 = getSunBurstDataByForApplication(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 = materialTypeMapper.findMaterialTypeNoParent(); |
|
|
|
result.put("name", dayName); |
|
|
|
} else { |
|
|
|
List<MaterialType> materialTypeByNames = materialTypeMapper.findMaterialTypeByName(mtName); |
|
|
|
MaterialType materialType = null; |
|
|
|
if (materialTypeByNames.size() > 0) { |
|
|
|
materialType = materialTypeByNames.get(0); |
|
|
|
} else { |
|
|
|
throw new MyException("错误,不存在当前名称的类型"); |
|
|
|
} |
|
|
|
materialTypeList = materialTypeMapper.findMaterialTypeByParent(materialType.getOldId()); |
|
|
|
result.put("name", mtName); |
|
|
|
if (materialTypeList.size() <= 0) { |
|
|
|
double sum = 0.0; |
|
|
|
try { |
|
|
|
Object call = new getSunBurstDataForInventoryByDepository( materialType, depositoryId).call(); |
|
|
|
sum = ObjectFormatUtil.sum(sum, ObjectFormatUtil.toDouble(ObjectFormatUtil.objToMap(call, String.class, Object.class).get("value"))); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
result.put("value", sum); |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 结果集
|
|
|
|
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)); |
|
|
|
|
|
|
|
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<>(); |
|
|
|
|
|
|
|
|
|
|
|
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> itemStyleTemp = new HashMap<>(); |
|
|
|
r = random.nextInt(256); |
|
|
|
g = random.nextInt(256); |
|
|
|
b = random.nextInt(256); |
|
|
|
itemStyleTemp.put("color", "rgb(" + r + "," + g + "," + b + ")"); |
|
|
|
resultDataItem.put("itemStyle", itemStyleTemp); |
|
|
|
// 更新当前类型库存数
|
|
|
|
sumInventory = ObjectFormatUtil.sum(sumInventory, inventory); |
|
|
|
resultData.add(resultDataItem); |
|
|
|
} |
|
|
|
result.put("children", resultData); |
|
|
|
result.put("value", sumInventory); |
|
|
|
|
|
|
|
|
|
|
|
} catch (InterruptedException | ExecutionException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 用于获取当前类别名称下当前月份的出入库的旭日图数据 |
|
|
|
|