9 changed files with 0 additions and 1621 deletions
@ -1,157 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.config.PublicConfig; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.service.*; |
|||
import com.dreamchaser.depository_manage.utils.DateUtil; |
|||
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|||
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.test.context.junit4.SpringRunner; |
|||
|
|||
import java.text.SimpleDateFormat; |
|||
import java.util.*; |
|||
import java.util.concurrent.*; |
|||
|
|||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
|||
@RunWith(SpringRunner.class) |
|||
public class BarChartTest { |
|||
|
|||
|
|||
@Autowired |
|||
MaterialTypeService materialTypeService; |
|||
|
|||
@Autowired |
|||
DepositoryRecordService depositoryRecordService; |
|||
|
|||
@Autowired |
|||
MaterialService materialService; |
|||
|
|||
@Autowired |
|||
DepositoryService depositoryService; |
|||
|
|||
@Autowired |
|||
RoleService roleService; |
|||
|
|||
/** |
|||
* 获取本月之前的月份 |
|||
* |
|||
* @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; |
|||
} |
|||
|
|||
@Test |
|||
public void main() { |
|||
Map<String, String> map = new HashMap<>(); |
|||
map.put("username", "302304"); |
|||
map.put("password", "123456789"); |
|||
map.put("captcha", "528765"); |
|||
map.put("captchaId", "UksBSXVFy0xVZbXUC4dQ"); |
|||
// JSONObject jsonObject = PublicConfig.baseLogin(map);
|
|||
// UserByPort userByPort = JSONObject.toJavaObject((JSONObject) jsonObject.get("usercont"), UserByPort.class);
|
|||
Map<Object, Object> barChartData = getBarChartDataByDateType(28L,"1", "day"); |
|||
System.out.println(barChartData); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
/** |
|||
* 获取入库或出库数据 |
|||
* |
|||
* @param depositoryId 要查看的仓库id |
|||
* @param type 类型(1入库2出库) |
|||
* @param dateType 日期类型(month按月,day按天(月初至今)) |
|||
* @return |
|||
*/ |
|||
public Map<Object, Object> getBarChartDataByDateType(Long depositoryId, String type, String dateType) { |
|||
// 获取至今的日期名称
|
|||
List<String> dayNames = new ArrayList<>(); |
|||
List<Long> dayTimeSpaces = new ArrayList<>(); |
|||
if ("month".equals(dateType)) { |
|||
//获取获取系统的当前日历对象
|
|||
|
|||
Map<String, Object> monthBeginToNow = DateUtil.getPreviousMonth(); |
|||
|
|||
// 获取至今的日期名称
|
|||
dayNames = ObjectFormatUtil.objToList(monthBeginToNow.get("monthNames"), String.class); |
|||
Collections.reverse(dayNames); |
|||
// 获取至今的日期时间戳
|
|||
dayTimeSpaces = ObjectFormatUtil.objToList(monthBeginToNow.get("months"), Long.class); |
|||
Collections.reverse(dayTimeSpaces); |
|||
|
|||
} else if ("day".equals(dateType)) { |
|||
//获取获取系统的当前日历对象
|
|||
Map<String, Object> monthBeginToNow = DateUtil.getMonthBeginToNow(); |
|||
// 获取至今的日期名称
|
|||
dayNames = ObjectFormatUtil.objToList(monthBeginToNow.get("dayName"), String.class); |
|||
// 获取至今的日期时间戳
|
|||
dayTimeSpaces = ObjectFormatUtil.objToList(monthBeginToNow.get("dayTimeSpace"), Long.class); |
|||
dayTimeSpaces.add(Calendar.getInstance().getTimeInMillis()); |
|||
} |
|||
// 每天各仓库入库数目
|
|||
Map<Object, Object> show_data = new HashMap<>(); |
|||
Map<String, Object> data = getBarChartDataForApplicationRecord(type, depositoryId, dayTimeSpaces); |
|||
show_data.put("data", data); |
|||
show_data.put("dayNames", dayNames); |
|||
return show_data; |
|||
} |
|||
|
|||
/** |
|||
* 根据日期获取出入库的数量(用于柱状图) |
|||
*/ |
|||
public Map<String, Object> getBarChartDataForApplicationRecord(String type, Long depositoryId, List<Long> days) { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("type", "bar"); |
|||
Map<String, Object> emphasisItem = new HashMap<>(); |
|||
emphasisItem.put("focus", "series"); |
|||
map.put("emphasis", emphasisItem); |
|||
Map<String, Object> labelItem = new HashMap<>(); |
|||
labelItem.put("show", true); |
|||
labelItem.put("position", "inside"); |
|||
map.put("label", labelItem); |
|||
int i; |
|||
List<Double> drCountbyDrName = new ArrayList<>(); |
|||
|
|||
for (i = 0; i < days.size() - 1; i++) { |
|||
// 遍历 Map并计算各仓库的入库数
|
|||
// 获取一段时间内的库存额度
|
|||
Double depositoryRecordByDate = depositoryRecordService.findApplicationRecordByDate(days.get(i + 1), days.get(i), ObjectFormatUtil.toInteger(type), depositoryId); |
|||
drCountbyDrName.add(depositoryRecordByDate); |
|||
} |
|||
map.put("data", drCountbyDrName); |
|||
return map; |
|||
} |
|||
|
|||
} |
|||
@ -1,21 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.dreamchaser.depository_manage.config.PublicConfig; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import org.junit.Test; |
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
import java.util.List; |
|||
|
|||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
|||
@RunWith(SpringRunner.class) |
|||
public class InterfaceTest { |
|||
|
|||
@Test |
|||
public void run() { |
|||
List<UserByPort> userByPortList = PublicConfig.findUserByAdminorgAndPosition(116L, "设备员", null, null); |
|||
System.out.println(userByPortList); |
|||
} |
|||
} |
|||
@ -1,251 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.config.PublicConfig; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.pojo.InventoryByDname; |
|||
import com.dreamchaser.depository_manage.security.pool.RedisPool; |
|||
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.MaterialTypeService; |
|||
import com.dreamchaser.depository_manage.utils.DateUtil; |
|||
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|||
import com.fasterxml.jackson.core.JsonProcessingException; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
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(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
|||
@RunWith(SpringRunner.class) |
|||
public class InventoryLineChartTest { |
|||
|
|||
|
|||
@Autowired |
|||
MaterialTypeService materialTypeService; |
|||
|
|||
@Autowired |
|||
DepositoryRecordService depositoryRecordService; |
|||
|
|||
@Autowired |
|||
MaterialService materialService; |
|||
|
|||
@Autowired |
|||
DepositoryService depositoryService; |
|||
|
|||
@Autowired |
|||
RedisPool redisPool; |
|||
|
|||
@Test |
|||
public void main() { |
|||
Map<Object, Object> day = getLineOrBarChartDataForInventory(41L, "day", "line"); |
|||
System.out.println(day); |
|||
} |
|||
|
|||
/** |
|||
* 获取折线图数据 |
|||
* |
|||
* @param depositoryId 待获取仓库Id |
|||
* @param dateType 日期类型(day按天month按月) |
|||
* @return |
|||
*/ |
|||
public Map<Object, Object> getLineOrBarChartDataForInventory(Long depositoryId, String dateType, String echartType) { |
|||
// 声明仓库库存数据
|
|||
Map<Object, Object> show_data = new HashMap<>(); |
|||
|
|||
// redisKey
|
|||
String redisKey = "depositoryId:" + depositoryId; |
|||
|
|||
// 获取至今的日期名称
|
|||
List<String> dayNames = new ArrayList<>(); |
|||
List<Long> dayTimeSpaces = new ArrayList<>(); |
|||
if ("month".equals(dateType)) { |
|||
//获取获取系统的当前日历对象
|
|||
|
|||
Map<String, Object> monthBeginToNow = DateUtil.getPreviousMonth(); |
|||
|
|||
// 获取至今的日期名称
|
|||
dayNames = ObjectFormatUtil.objToList(monthBeginToNow.get("monthNames"), String.class); |
|||
Collections.reverse(dayNames); |
|||
// 获取至今的日期时间戳
|
|||
dayTimeSpaces = ObjectFormatUtil.objToList(monthBeginToNow.get("months"), Long.class); |
|||
Collections.reverse(dayTimeSpaces); |
|||
|
|||
} else if ("day".equals(dateType)) { |
|||
//获取获取系统的当前日历对象
|
|||
Map<String, Object> monthBeginToNow = DateUtil.getMonthBeginToNow(); |
|||
// 获取至今的日期名称
|
|||
dayNames = ObjectFormatUtil.objToList(monthBeginToNow.get("dayName"), String.class); |
|||
// 获取至今的日期时间戳
|
|||
dayTimeSpaces = ObjectFormatUtil.objToList(monthBeginToNow.get("dayTimeSpace"), Long.class); |
|||
dayTimeSpaces.add(Calendar.getInstance().getTimeInMillis()); |
|||
} |
|||
|
|||
Set<Object> keys = redisPool.getRedisTemplateByDb(15).opsForHash().keys(redisKey); |
|||
|
|||
// 声明仓库入库数据列表
|
|||
List<Double> applicationInDataList = new ArrayList<>(); |
|||
// 声明仓库出库数据列表
|
|||
List<Double> applicationOutDataList = new ArrayList<>(); |
|||
// 声明仓库库存数据列表
|
|||
List<Double> inventoryList = new ArrayList<>(); |
|||
|
|||
// 获取当前仓库的库存值
|
|||
Double depositoryInventory = materialService.findInventorySumForDepository(depositoryId); |
|||
|
|||
if (keys.contains("inventory:" + dateType)) { |
|||
// 如果redis中存在当前值
|
|||
Object inventory = redisPool.getRedisTemplateByDb(15).opsForHash().get(redisKey, "inventory:" + dateType); |
|||
if (inventory != null) { |
|||
inventoryList = JSONArray.parseArray(inventory.toString(), Double.class); |
|||
} |
|||
} else { |
|||
if (keys.contains("in:" + dateType)) { |
|||
// 如果包含入库数据
|
|||
Object applicationInDataForRedis = redisPool.getRedisTemplateByDb(15).opsForHash().get(redisKey, "in:" + dateType); |
|||
if (applicationInDataForRedis != null) { |
|||
applicationInDataList = JSONArray.parseArray(applicationInDataForRedis.toString(), Double.class); |
|||
Double depositoryRecordByDate = depositoryRecordService.findApplicationRecordByDate(dayTimeSpaces.get(dayTimeSpaces.size() - 1), dayTimeSpaces.get(dayTimeSpaces.size() - 2), 1, depositoryId); |
|||
applicationInDataList.add(depositoryRecordByDate); |
|||
} else { |
|||
for (int i = 0; i < dayTimeSpaces.size() - 1; i++) { |
|||
// 遍历 Map并计算各仓库的入库数
|
|||
// 获取一段时间内的库存额度
|
|||
Double depositoryRecordByDate = depositoryRecordService.findApplicationRecordByDate(dayTimeSpaces.get(i + 1), dayTimeSpaces.get(i), 1, depositoryId); |
|||
applicationInDataList.add(depositoryRecordByDate); |
|||
} |
|||
} |
|||
} else { |
|||
for (int i = 0; i < dayTimeSpaces.size() - 1; i++) { |
|||
// 遍历 Map并计算各仓库的入库数
|
|||
// 获取一段时间内的库存额度
|
|||
Double depositoryRecordByDate = depositoryRecordService.findApplicationRecordByDate(dayTimeSpaces.get(i + 1), dayTimeSpaces.get(i), 1, depositoryId); |
|||
applicationInDataList.add(depositoryRecordByDate); |
|||
} |
|||
} |
|||
|
|||
if (keys.contains("out:" + dateType)) { |
|||
// 如果包含出库数据
|
|||
Object applicationOutDataForRedis = redisPool.getRedisTemplateByDb(15).opsForHash().get(redisKey, "out:" + dateType); |
|||
if (applicationOutDataForRedis != null) { |
|||
applicationOutDataList = JSONArray.parseArray(applicationOutDataForRedis.toString(), Double.class); |
|||
Double depositoryRecordByDate = depositoryRecordService.findApplicationRecordByDate(dayTimeSpaces.get(dayTimeSpaces.size() - 1), dayTimeSpaces.get(dayTimeSpaces.size() - 2), 2, depositoryId); |
|||
applicationOutDataList.add(depositoryRecordByDate); |
|||
} else { |
|||
for (int i = 0; i < dayTimeSpaces.size() - 1; i++) { |
|||
// 遍历 Map并计算各仓库的入库数
|
|||
// 获取一段时间内的库存额度
|
|||
Double depositoryRecordByDate = depositoryRecordService.findApplicationRecordByDate(dayTimeSpaces.get(i + 1), dayTimeSpaces.get(i), 2, depositoryId); |
|||
applicationOutDataList.add(depositoryRecordByDate); |
|||
} |
|||
} |
|||
} else { |
|||
for (int i = 0; i < dayTimeSpaces.size() - 1; i++) { |
|||
// 遍历 Map并计算各仓库的入库数
|
|||
// 获取一段时间内的库存额度
|
|||
Double depositoryRecordByDate = depositoryRecordService.findApplicationRecordByDate(dayTimeSpaces.get(i + 1), dayTimeSpaces.get(i), 2, depositoryId); |
|||
applicationOutDataList.add(depositoryRecordByDate); |
|||
} |
|||
} |
|||
} |
|||
inventoryList.add(depositoryInventory); |
|||
if (inventoryList.size() <= 1) { |
|||
// 如果没有
|
|||
inventoryList.add(depositoryInventory); |
|||
for (int i = applicationInDataList.size() - 1; i > 0; i--) { |
|||
// 入库数
|
|||
Double inQuantity = applicationInDataList.get(i); |
|||
// 出库数
|
|||
Double outQuantity = applicationOutDataList.get(i); |
|||
depositoryInventory = depositoryInventory - inQuantity + outQuantity; |
|||
inventoryList.add(depositoryInventory); |
|||
} |
|||
Collections.reverse(inventoryList); |
|||
} |
|||
|
|||
List<Double> inventoryListCopy = new ArrayList<>(); |
|||
ObjectMapper objectMap = new ObjectMapper(); |
|||
try { |
|||
inventoryListCopy = objectMap.readValue(objectMap.writeValueAsString(inventoryList), List.class); |
|||
} catch (JsonProcessingException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
inventoryListCopy.remove(inventoryListCopy.size() - 1); |
|||
redisPool.getRedisTemplateByDb(15).opsForHash().put(redisKey, "inventory:" + dateType, JSONObject.toJSONString(inventoryListCopy)); |
|||
if (applicationInDataList.size() > 0) { |
|||
applicationInDataList.remove(applicationInDataList.size() - 1); |
|||
redisPool.getRedisTemplateByDb(15).opsForHash().put(redisKey, "in:" + dateType, JSONObject.toJSONString(applicationInDataList)); |
|||
|
|||
} |
|||
if (applicationOutDataList.size() > 0) { |
|||
applicationOutDataList.remove(applicationOutDataList.size() - 1); |
|||
redisPool.getRedisTemplateByDb(15).opsForHash().put(redisKey, "out:" + dateType, JSONObject.toJSONString(applicationOutDataList)); |
|||
} |
|||
redisPool.getRedisTemplateByDb(15).expire(redisKey, DateUtil.getSecondsNextEarlyMorning(), TimeUnit.SECONDS); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
if ("line".equals(echartType)) { |
|||
map.put("type", "line"); |
|||
Map<String, Object> areaStyleItem = new HashMap<>(); |
|||
map.put("areaStyle", areaStyleItem); |
|||
} else if ("bar".equals(echartType)) { |
|||
map.put("type", "bar"); |
|||
Map<String, Object> emphasisItem = new HashMap<>(); |
|||
emphasisItem.put("focus", "series"); |
|||
map.put("emphasis", emphasisItem); |
|||
Map<String, Object> labelItem = new HashMap<>(); |
|||
labelItem.put("show", true); |
|||
labelItem.put("position", "inside"); |
|||
map.put("label", labelItem); |
|||
} |
|||
|
|||
map.put("data", inventoryList); |
|||
show_data.put("data", map); |
|||
show_data.put("dayNames", dayNames); |
|||
return show_data; |
|||
} |
|||
|
|||
/** |
|||
* 获取当前折线图的具体数据 |
|||
* |
|||
* @param type 查看类型(1入库2出库) |
|||
* @param days 查询日期 |
|||
* @param depositoryId 仓库id |
|||
* @return |
|||
*/ |
|||
public Map<String, Object> getLineOrBarChartDataForApplicationRecord(String type, List<Long> days, Long depositoryId, String echartType) { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
if ("line".equals(echartType)) { |
|||
map.put("type", "line"); |
|||
Map<String, Object> areaStyleItem = new HashMap<>(); |
|||
map.put("areaStyle", areaStyleItem); |
|||
} else if ("bar".equals(echartType)) { |
|||
map.put("type", "bar"); |
|||
Map<String, Object> emphasisItem = new HashMap<>(); |
|||
emphasisItem.put("focus", "series"); |
|||
map.put("emphasis", emphasisItem); |
|||
Map<String, Object> labelItem = new HashMap<>(); |
|||
labelItem.put("show", true); |
|||
labelItem.put("position", "inside"); |
|||
map.put("label", labelItem); |
|||
} |
|||
int i; |
|||
List<Double> drCountbyDrName = new ArrayList<>(); |
|||
for (i = 0; i < days.size() - 1; i++) { |
|||
// 遍历 Map并计算各仓库的入库数
|
|||
// 获取一段时间内的库存额度
|
|||
Double depositoryRecordByDate = depositoryRecordService.findApplicationRecordByDate(days.get(i + 1), days.get(i), ObjectFormatUtil.toInteger(type), depositoryId); |
|||
drCountbyDrName.add(depositoryRecordByDate); |
|||
} |
|||
map.put("data", drCountbyDrName); |
|||
return map; |
|||
} |
|||
|
|||
} |
|||
@ -1,430 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.config.PublicConfig; |
|||
import com.dreamchaser.depository_manage.entity.Depository; |
|||
import com.dreamchaser.depository_manage.entity.MaterialType; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.exception.MyException; |
|||
import com.dreamchaser.depository_manage.pojo.InventoryByMTAndDepository; |
|||
import com.dreamchaser.depository_manage.security.pool.RedisPool; |
|||
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.MaterialTypeService; |
|||
import com.dreamchaser.depository_manage.utils.DateUtil; |
|||
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.data.redis.core.RedisTemplate; |
|||
import org.springframework.test.context.junit4.SpringRunner; |
|||
|
|||
import java.text.SimpleDateFormat; |
|||
import java.util.*; |
|||
import java.util.concurrent.*; |
|||
|
|||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
|||
@RunWith(SpringRunner.class) |
|||
public class InventorySunburstDataTest { |
|||
|
|||
|
|||
@Autowired |
|||
MaterialTypeService materialTypeService; |
|||
|
|||
@Autowired |
|||
DepositoryRecordService depositoryRecordService; |
|||
|
|||
@Autowired |
|||
MaterialService materialService; |
|||
|
|||
@Autowired |
|||
DepositoryService depositoryService; |
|||
|
|||
@Autowired |
|||
RedisPool redisPool; |
|||
|
|||
|
|||
@Test |
|||
public void main() { |
|||
String type = "2"; |
|||
String dayName = "6月"; |
|||
String dayNumberString = dayName.split("月")[0]; |
|||
// Map<String, Object> sunBurstDataForInventoryByMonth = getSunBurstDataForInventoryByMonth(dayName, "办公用品", 40);
|
|||
// System.out.println(JSONObject.toJSONString(sunBurstDataForInventoryByMonth));
|
|||
|
|||
System.out.println(Calendar.getInstance().get(Calendar.MONTH)); |
|||
// 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) { |
|||
// 定义结果集
|
|||
Map<String, Object> result = new HashMap<String, Object>(); |
|||
|
|||
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 = 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)); |
|||
|
|||
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 type 查看类型(1入库2出库3库存) |
|||
* @param start 开始时间 |
|||
* @param end 结束时间 |
|||
* @param materialTypeAll 当前查看物料类型 |
|||
* @param depositoryId 当前查看仓库id |
|||
* @return |
|||
*/ |
|||
public Map<String, Object> getSunBurstDataForApplication(String dayName, String type, Long start, Long end, List<MaterialType> materialTypeAll, Integer depositoryId) { |
|||
|
|||
Map<String, Object> result = new HashMap<>(); |
|||
|
|||
int maxThreadSize = materialTypeAll.size(); |
|||
|
|||
int threadSize = Runtime.getRuntime().availableProcessors(); |
|||
|
|||
if (maxThreadSize < threadSize) { |
|||
maxThreadSize = threadSize * 2; |
|||
} |
|||
|
|||
ExecutorService exs = new ThreadPoolExecutor(threadSize, maxThreadSize, 100, TimeUnit.SECONDS, new LinkedBlockingQueue<>(maxThreadSize)); |
|||
|
|||
// 结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
|
|||
List<Object> resultForData = new ArrayList<>(); |
|||
int openThreadSize = 0; |
|||
for (MaterialType materialType : materialTypeAll) { |
|||
Future<Object> future = null; |
|||
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); |
|||
openThreadSize++; |
|||
} |
|||
|
|||
double sum = 0.0; |
|||
for (int i = 0; i < openThreadSize; i++) { |
|||
Object obj = null; |
|||
try { |
|||
obj = completionService.take().get(); |
|||
sum = ObjectFormatUtil.sum(sum, ObjectFormatUtil.toDouble(ObjectFormatUtil.objToMap(obj, String.class, Object.class).get("value"))); |
|||
} catch (InterruptedException | ExecutionException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
resultForData.add(obj); |
|||
} |
|||
result.put("children", resultForData); |
|||
result.put("name", dayName); |
|||
result.remove("month"); |
|||
result.put("value", sum); |
|||
// 用于生产随机的颜色
|
|||
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); |
|||
result.put("sunburstDataType", type); |
|||
return result; |
|||
} |
|||
|
|||
/** |
|||
* 用于获取当前类别名称下当前月份的出入库的旭日图数据 |
|||
* |
|||
* @param dayName 当前月份 |
|||
* @param type 类型(1入库2出库) |
|||
* @param start 开始 |
|||
* @param end 结束 |
|||
* @param mtName 类别名称 |
|||
* @return |
|||
*/ |
|||
public Map<String, Object> getSunBurstDataByMtName(String dayName, String type, Long start, Long end, String mtName, Integer depositoryId) { |
|||
List<MaterialType> materialTypeByNames = materialTypeService.findMaterialTypeByName(mtName); |
|||
MaterialType materialType = null; |
|||
if (materialTypeByNames.size() > 0) { |
|||
materialType = materialTypeByNames.get(0); |
|||
} else { |
|||
throw new MyException("错误,不存在当前名称的类型"); |
|||
} |
|||
List<MaterialType> childMaterialTypeList = materialTypeService.findChildForMaterialTypeByParent(materialType.getOldId()); |
|||
|
|||
|
|||
int threadSize = PublicConfig.availableVirtualMachine; |
|||
|
|||
int maxThreadSize = childMaterialTypeList.size(); |
|||
if (maxThreadSize < threadSize) { |
|||
maxThreadSize = threadSize * 2; |
|||
} |
|||
ExecutorService exs = new ThreadPoolExecutor(threadSize, maxThreadSize, 100, TimeUnit.SECONDS, new LinkedBlockingQueue<>(maxThreadSize)); |
|||
|
|||
// 结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
|
|||
int runThreadSize = 0; |
|||
for (MaterialType value : childMaterialTypeList) { |
|||
Future<Object> submit = completionService.submit(new getSunBurstDataForApplicationByDepository(type, start, end, value, depositoryId)); |
|||
runThreadSize++; |
|||
futureList.add(submit); |
|||
} |
|||
|
|||
double sum = 0.0; |
|||
List<Object> resultForData = new ArrayList<>(); |
|||
for (int i = 0; i < runThreadSize; i++) { |
|||
Object obj = null; |
|||
try { |
|||
obj = completionService.take().get(); |
|||
resultForData.add(obj); |
|||
sum = ObjectFormatUtil.sum(sum, ObjectFormatUtil.toDouble(ObjectFormatUtil.objToMap(obj, String.class, Object.class).get("value"))); |
|||
} catch (InterruptedException | ExecutionException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
Map<String, Object> result = new HashMap<>(); |
|||
result.put("children", resultForData); |
|||
result.put("name", dayName); |
|||
result.remove("month"); |
|||
result.put("value", sum); |
|||
// 用于生产随机的颜色
|
|||
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); |
|||
return result; |
|||
} |
|||
|
|||
/** |
|||
* 用于具体执行查询出入库旭日图的多线程类 |
|||
*/ |
|||
class getSunBurstDataForApplicationByDepository implements Callable<Object> { |
|||
|
|||
|
|||
String type; |
|||
Long start; |
|||
Long end; |
|||
MaterialType materialType; |
|||
Integer depositoryId; |
|||
|
|||
public getSunBurstDataForApplicationByDepository(String type, Long start, Long end, MaterialType materialType, Integer depositoryId) { |
|||
this.type = type; |
|||
this.start = start; |
|||
this.end = end; |
|||
this.materialType = materialType; |
|||
this.depositoryId = depositoryId; |
|||
} |
|||
|
|||
@Override |
|||
public Object call() throws Exception { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("type", ObjectFormatUtil.toInteger(type)); |
|||
map.put("start", start); |
|||
map.put("end", end); |
|||
map.put("depository_id", depositoryId); |
|||
map.put("oldId", materialType.getOldId()); |
|||
Map<String, Object> result = new HashMap<>(); |
|||
Double materialCountByMonth = depositoryRecordService.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; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 用于具体执行查询库存旭日图的多线程类 |
|||
*/ |
|||
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; |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -1,117 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
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.MaterialTypeService; |
|||
import com.dreamchaser.depository_manage.utils.DateUtil; |
|||
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 java.util.*; |
|||
|
|||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
|||
@RunWith(SpringRunner.class) |
|||
public class LineChartTest { |
|||
|
|||
|
|||
@Autowired |
|||
MaterialTypeService materialTypeService; |
|||
|
|||
@Autowired |
|||
DepositoryRecordService depositoryRecordService; |
|||
|
|||
@Autowired |
|||
MaterialService materialService; |
|||
|
|||
@Autowired |
|||
DepositoryService depositoryService; |
|||
|
|||
|
|||
@Test |
|||
public void main() { |
|||
Map<Object, Object> day = getLineOrBarChartData(28L, "1", "day","bar"); |
|||
System.out.println(day); |
|||
} |
|||
|
|||
/** |
|||
* 获取折线图数据 |
|||
* @param depositoryId 待获取仓库Id |
|||
* @param type 查看类型(1入库2出库) |
|||
* @param dateType 日期类型(day按天month按月) |
|||
* @return |
|||
*/ |
|||
public Map<Object, Object> getLineOrBarChartData(Long depositoryId, String type, String dateType, String echartType) { |
|||
|
|||
|
|||
// 获取至今的日期名称
|
|||
List<String> dayNames = new ArrayList<>(); |
|||
List<Long> dayTimeSpaces = new ArrayList<>(); |
|||
if ("month".equals(dateType)) { |
|||
//获取获取系统的当前日历对象
|
|||
|
|||
Map<String, Object> monthBeginToNow = DateUtil.getPreviousMonth(); |
|||
|
|||
// 获取至今的日期名称
|
|||
dayNames = ObjectFormatUtil.objToList(monthBeginToNow.get("monthNames"), String.class); |
|||
Collections.reverse(dayNames); |
|||
// 获取至今的日期时间戳
|
|||
dayTimeSpaces = ObjectFormatUtil.objToList(monthBeginToNow.get("months"), Long.class); |
|||
Collections.reverse(dayTimeSpaces); |
|||
|
|||
} else if ("day".equals(dateType)) { |
|||
//获取获取系统的当前日历对象
|
|||
Map<String, Object> monthBeginToNow = DateUtil.getMonthBeginToNow(); |
|||
// 获取至今的日期名称
|
|||
dayNames = ObjectFormatUtil.objToList(monthBeginToNow.get("dayName"), String.class); |
|||
// 获取至今的日期时间戳
|
|||
dayTimeSpaces = ObjectFormatUtil.objToList(monthBeginToNow.get("dayTimeSpace"), Long.class); |
|||
dayTimeSpaces.add(Calendar.getInstance().getTimeInMillis()); |
|||
} |
|||
// 每天仓库出入库数目
|
|||
Map<Object, Object> show_data = new HashMap<>(); |
|||
Map<String, Object> applicationRecordByDate = getLineOrBarChartDataForApplicationRecord(type, dayTimeSpaces, depositoryId,echartType); |
|||
show_data.put("data",applicationRecordByDate); |
|||
show_data.put("dayNames",dayNames); |
|||
return show_data; |
|||
} |
|||
|
|||
/** |
|||
* 获取当前折线图的具体数据 |
|||
* @param type 查看类型(1入库2出库) |
|||
* @param days 查询日期 |
|||
* @param depositoryId 仓库id |
|||
* @return |
|||
*/ |
|||
public Map<String, Object> getLineOrBarChartDataForApplicationRecord(String type, List<Long> days, Long depositoryId, String echartType) { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
if("line".equals(echartType)){ |
|||
map.put("type", "line"); |
|||
Map<String, Object> areaStyleItem = new HashMap<>(); |
|||
map.put("areaStyle", areaStyleItem); |
|||
}else if("bar".equals(echartType)){ |
|||
map.put("type", "bar"); |
|||
Map<String, Object> emphasisItem = new HashMap<>(); |
|||
emphasisItem.put("focus", "series"); |
|||
map.put("emphasis", emphasisItem); |
|||
Map<String, Object> labelItem = new HashMap<>(); |
|||
labelItem.put("show", true); |
|||
labelItem.put("position", "inside"); |
|||
map.put("label", labelItem); |
|||
} |
|||
int i; |
|||
List<Double> drCountbyDrName = new ArrayList<>(); |
|||
for (i = 0; i < days.size() - 1; i++) { |
|||
// 遍历 Map并计算各仓库的入库数
|
|||
// 获取一段时间内的库存额度
|
|||
Double depositoryRecordByDate = depositoryRecordService.findApplicationRecordByDate(days.get(i + 1), days.get(i), ObjectFormatUtil.toInteger(type), depositoryId); |
|||
drCountbyDrName.add(depositoryRecordByDate); |
|||
} |
|||
map.put("data", drCountbyDrName); |
|||
return map; |
|||
} |
|||
} |
|||
@ -1,38 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.dreamchaser.depository_manage.entity.Administration; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.hrNew_mapper.AdministrativeMapper; |
|||
import com.dreamchaser.depository_manage.hrNew_mapper.UserMapper; |
|||
import com.dreamchaser.depository_manage.service.AdministrativeService; |
|||
import com.dreamchaser.depository_manage.service.UserService; |
|||
import com.dreamchaser.depository_manage.utils.EncryptionAlgorithmUtil; |
|||
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.*; |
|||
|
|||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
|||
@RunWith(SpringRunner.class) |
|||
public class MoreDatasourceTest { |
|||
@Autowired |
|||
private UserService userService; |
|||
|
|||
@Autowired |
|||
private AdministrativeService administrativeService; |
|||
|
|||
@Test |
|||
public void test(){ |
|||
UserByPort userByWorkWechat = userService.findUserByWorkWechat("PangFuZhen"); |
|||
EncryptionAlgorithmUtil encryptionAlgorithmUtil = new EncryptionAlgorithmUtil(); |
|||
Map<String, String> userKeyAndUserToken = encryptionAlgorithmUtil.getUserKeyAndUserToken(userByWorkWechat); |
|||
System.out.println(userKeyAndUserToken); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
@ -1,318 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.config.QyWxConfig; |
|||
import com.dreamchaser.depository_manage.pojo.ApplicationOutRecordP; |
|||
import com.dreamchaser.depository_manage.pojo.callBackXml.approvalCallBackXml.*; |
|||
import com.dreamchaser.depository_manage.security.pool.RedisPool; |
|||
import com.dreamchaser.depository_manage.service.DepositoryRecordService; |
|||
import com.dreamchaser.depository_manage.utils.*; |
|||
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.*; |
|||
|
|||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
|||
@RunWith(SpringRunner.class) |
|||
public class QyWxCallBackTest { |
|||
|
|||
@Autowired |
|||
DepositoryRecordService depositoryRecordService; |
|||
|
|||
@Autowired |
|||
RedisPool redisPool; |
|||
|
|||
public void callback(ApprovalInfo approvalInfo) { |
|||
|
|||
|
|||
// 获取当前审批的编号
|
|||
String spNo = approvalInfo.getSpNo(); |
|||
|
|||
// 获取当前审批关联的主订单
|
|||
String mainId = (String) redisPool.getRedisTemplateByDb(14).opsForHash().get("wms_QyWxMessage_" + spNo, "mainId"); |
|||
|
|||
// 获取所有审批流程信息
|
|||
List<ApprovalInfo_SpRecord> spRecord_list = approvalInfo.getSpRecord(); |
|||
|
|||
// 获取审批流程信息
|
|||
ApprovalInfo_SpRecord as = null; |
|||
// 获取审批节点详情
|
|||
ApprovalInfo_Details approvalInfo_details = null; |
|||
// 定义当前流程审批时间
|
|||
String as_SpTime = ""; |
|||
// 定义当前审批流程是是否要通过仓储中心
|
|||
boolean flagForFirst = true; // 默认通过
|
|||
|
|||
// 设置当前审批是否为仓库管理员(1为部门负责人,2为仓储中心,3为仓库管理员)
|
|||
int flagForDepository = 1; // 默认为部门负责人
|
|||
|
|||
// 定义当前审批人的企业微信uid列表
|
|||
List<String> approverQyWxUid = new ArrayList<>(); |
|||
|
|||
|
|||
// 定义已完成审批的节点数
|
|||
int approval_complete_count = 0; |
|||
|
|||
|
|||
// 定义当前审批流程的节点总数
|
|||
int approval_count = spRecord_list.size(); |
|||
|
|||
// 获取审批申请状态变化类型:1-提单;2-同意;3-驳回;4-转审;5-催办;6-撤销;8-通过后撤销;10-添加备注
|
|||
String spStatus = approvalInfo.getStatuChangeEvent(); |
|||
|
|||
// 获取当前处理的节点及审批的节点数
|
|||
for (ApprovalInfo_SpRecord approvalInfo_SpRecord : spRecord_list) { |
|||
|
|||
// 获取当前审批节点详情。当节点为标签或上级时,一个节点可能有多个分支
|
|||
List<ApprovalInfo_Details> details = approvalInfo_SpRecord.getDetails(); |
|||
|
|||
// 定义审批操作时间
|
|||
String spTime = ""; |
|||
// 定义审批操作状态
|
|||
String ad_SpStatus = ""; |
|||
// 定义审批详情
|
|||
ApprovalInfo_Details ap_detail = null; |
|||
|
|||
// 用于获取当前审批的最新节点
|
|||
for (ApprovalInfo_Details ad : details) { |
|||
|
|||
// 获取节点分支审批人审批操作时间,0为尚未操作
|
|||
spTime = ad.getSpTime(); |
|||
|
|||
// 如果当前审批节点已经处理
|
|||
if (!("0".equals(spTime))) { |
|||
|
|||
// 添加当前审批节点人的uid
|
|||
approverQyWxUid.add(ad.getApprover().getUserId()); |
|||
|
|||
// 设置当前处理的详情
|
|||
ap_detail = ad; |
|||
// 设置当前审批的状态
|
|||
ad_SpStatus = ad.getSpStatus(); |
|||
// 已审批节点数+1
|
|||
approval_complete_count++; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
|
|||
if (!"0".equals(spTime)) { |
|||
// 如果已经操作
|
|||
|
|||
// 盘点当前审批状态是否为回调时操作状态
|
|||
if (ad_SpStatus.equals(spStatus)) { |
|||
// 将当前审批进行暂存
|
|||
if (as == null) { |
|||
// 如果是当前并没有获取到审批节点
|
|||
as = approvalInfo_SpRecord; |
|||
as_SpTime = spTime; |
|||
approvalInfo_details = ap_detail; |
|||
} else { |
|||
// 如果已经获取到审批节点
|
|||
|
|||
// 获取当前审批节点处理时间
|
|||
long aLong = ObjectFormatUtil.toLong(spTime); |
|||
|
|||
// 获取之前节点的审批时间
|
|||
long aLong1 = ObjectFormatUtil.toLong(as_SpTime); |
|||
|
|||
if (aLong >= aLong1) { |
|||
// 如果当前审批节点是最近处理
|
|||
|
|||
// 更新当前审批节点
|
|||
as = approvalInfo_SpRecord; |
|||
as_SpTime = spTime; |
|||
approvalInfo_details = ap_detail; |
|||
flagForFirst = false; // 设置当前节点不是第一个节点
|
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
// 1-审批中;2-已同意;3-已驳回;4-已转审
|
|||
if (!("1".equals(spStatus))) { |
|||
// 如果当前已经审批过
|
|||
if (QyWxConfig.out_approval_template_id.equals(approvalInfo.getTemplateId())) { |
|||
// 如果是物料出库申请审批
|
|||
|
|||
// 获取要进行判断的节点
|
|||
ApprovalInfo_SpRecord approvalInfo_spRecord = null; |
|||
if (spRecord_list.size() > 1 && spRecord_list.size() < 4) { |
|||
// 如果是除中心仓下办公用品库以外的仓库
|
|||
approvalInfo_spRecord = spRecord_list.get(1); // 获取该审批节点
|
|||
} |
|||
if (approvalInfo_spRecord != null) { |
|||
// 获取第二个节点中审批人信息
|
|||
List<ApprovalInfo_Details> details = approvalInfo_spRecord.getDetails(); |
|||
// 定义当前是否为标签
|
|||
boolean flagForLabel = true; // 默认为标签
|
|||
|
|||
// 获取当前的主订单
|
|||
ApplicationOutRecordP applicationOutRecordPById = depositoryRecordService.findApplicationOutRecordPById(ObjectFormatUtil.toLong(mainId)); |
|||
if(applicationOutRecordPById == null){ |
|||
return; |
|||
} |
|||
if (Integer.compare(applicationOutRecordPById.getFlagForOpenDepository(), 2) == 0) { |
|||
// 如果是申请的开放仓库
|
|||
|
|||
// 获取当时发送审批时其他部门负责人Id
|
|||
String otherDepartmentIdList = (String) redisPool.getRedisTemplateByDb(14).opsForHash().get("wms_QyWxMessage_" + spNo, "otherDepartmentIdList"); |
|||
if (otherDepartmentIdList != null) { |
|||
for (ApprovalInfo_Details ad : details |
|||
) { |
|||
// 获取当前节点审批人userId
|
|||
String approver = ad.getApprover().getUserId(); |
|||
flagForLabel = flagForLabel && otherDepartmentIdList.contains(approver); |
|||
} |
|||
} |
|||
} else { |
|||
flagForLabel = false; |
|||
} |
|||
|
|||
|
|||
if (!flagForLabel && approval_count < 3) { |
|||
// 如果第二个节点不是标签节点且总节点数小于3个
|
|||
|
|||
if (approval_complete_count > 1) { |
|||
// 如果完成审批的节点数大于1
|
|||
flagForDepository = 3; |
|||
|
|||
// 如果已经完成该审批记录,则进行删除
|
|||
redisPool.getRedisTemplateByDb(14).delete("wms_QyWxMessage_" + spNo); |
|||
} else { |
|||
// 如果当前是第一个节点
|
|||
flagForFirst = false; |
|||
} |
|||
|
|||
} else { |
|||
// 如果第二个节点是标签节点
|
|||
if (approval_complete_count > 2) { |
|||
// 如果完成审批的节点数大于2
|
|||
flagForDepository = 3; |
|||
// 如果已经完成该审批记录,则进行删除
|
|||
redisPool.getRedisTemplateByDb(14).delete("wms_QyWxMessage_" + spNo); |
|||
} else { |
|||
// 如果当前并不是标签节点后
|
|||
flagForDepository = 2; |
|||
} |
|||
|
|||
} |
|||
} |
|||
else { |
|||
// 如果为空则代表是中心仓下的办公用品库
|
|||
|
|||
int size = approverQyWxUid.size(); |
|||
if (size == 1) { |
|||
// 如果当前审批节点为第一个即部门负责人
|
|||
flagForFirst = true; |
|||
flagForDepository = 11; |
|||
}else if(size == 2){ |
|||
// 如果当前审批节点为第二个即平衡岗
|
|||
flagForFirst = true; |
|||
flagForDepository = 12; |
|||
} |
|||
else if(size == 3){ |
|||
// 如果当前审批节点为综合办负责人
|
|||
flagForFirst = false; |
|||
flagForDepository = 2; |
|||
}else{ |
|||
// 如果不是有操作的审批节点
|
|||
flagForDepository = 3; |
|||
} |
|||
} |
|||
|
|||
ApprovalInfo_Details finalApprovalInfo_details = approvalInfo_details; |
|||
boolean finalFlagForFirst = flagForFirst; |
|||
int finalFlagForDepository = flagForDepository; |
|||
depositoryRecordService.reviewByQyWxApprovalOut(mainId, finalApprovalInfo_details, "0a7ffa452096d330934052105a67794a", spStatus, approvalInfo.getSpNo(), finalFlagForFirst, finalFlagForDepository); |
|||
|
|||
} |
|||
// 开启一个线程用于进行下步操作
|
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
@Test |
|||
public void someTest() { |
|||
|
|||
ApprovalInfo approvalInfo = new ApprovalInfo(); |
|||
approvalInfo.setTemplateId("3WKiKVCzyLv3Y1LaHZxp4DimQEpCdvYP52HsAUtF"); |
|||
approvalInfo.setSpNo("202307250018"); |
|||
|
|||
|
|||
// 模拟第一个节点(部门负责人)
|
|||
List<ApprovalInfo_SpRecord> spRecord_list = new ArrayList<>(); |
|||
ApprovalInfo_SpRecord asr1 = new ApprovalInfo_SpRecord(); |
|||
asr1.setSpStatus("2"); |
|||
List<ApprovalInfo_Details> approvalInfo_Details1 = new ArrayList<>(); |
|||
ApprovalInfo_Details ad1 = new ApprovalInfo_Details(); |
|||
ad1.setSpStatus("2"); |
|||
ad1.setSpTime("1690267027000"); |
|||
ApprovalInfo_Details_Approver approver1 = new ApprovalInfo_Details_Approver(); |
|||
approver1.setUserId("WoBenShanLiang_3"); |
|||
ad1.setApprover(approver1); |
|||
approvalInfo_Details1.add(ad1); |
|||
asr1.setDetails(approvalInfo_Details1); |
|||
|
|||
// 模拟第二个节点(宋倩倩,平衡岗)
|
|||
ApprovalInfo_SpRecord asr2 = new ApprovalInfo_SpRecord(); |
|||
asr2.setSpStatus("1"); |
|||
List<ApprovalInfo_Details> approvalInfo_Details2 = new ArrayList<>(); |
|||
ApprovalInfo_Details ad2 = new ApprovalInfo_Details(); |
|||
ad2.setSpStatus("1"); |
|||
ad2.setSpTime("0"); |
|||
ApprovalInfo_Details_Approver approver2 = new ApprovalInfo_Details_Approver(); |
|||
approver2.setUserId("XinPing"); |
|||
ad2.setApprover(approver2); |
|||
approvalInfo_Details2.add(ad2); |
|||
asr2.setDetails(approvalInfo_Details2); |
|||
|
|||
// 模拟第三个节点(综合办负责人)(仓储负责人)
|
|||
ApprovalInfo_SpRecord asr3 = new ApprovalInfo_SpRecord(); |
|||
asr3.setSpStatus("1"); |
|||
List<ApprovalInfo_Details> approvalInfo_Details3 = new ArrayList<>(); |
|||
ApprovalInfo_Details ad3 = new ApprovalInfo_Details(); |
|||
ad3.setSpStatus("1"); |
|||
ad3.setSpTime("0"); |
|||
ApprovalInfo_Details_Approver approver3 = new ApprovalInfo_Details_Approver(); |
|||
approver3.setUserId("SiKai"); |
|||
ad3.setApprover(approver3); |
|||
approvalInfo_Details3.add(ad3); |
|||
asr3.setDetails(approvalInfo_Details3); |
|||
|
|||
// 模拟第四个节点(仓库管理员)
|
|||
ApprovalInfo_SpRecord asr4 = new ApprovalInfo_SpRecord(); |
|||
asr4.setSpStatus("1"); |
|||
List<ApprovalInfo_Details> approvalInfo_Details4 = new ArrayList<>(); |
|||
ApprovalInfo_Details ad4 = new ApprovalInfo_Details(); |
|||
ad4.setSpStatus("1"); |
|||
ad4.setSpTime("0"); |
|||
ApprovalInfo_Details_Approver approver4 = new ApprovalInfo_Details_Approver(); |
|||
approver4.setUserId("PangFuZhen"); |
|||
ad4.setApprover(approver4); |
|||
approvalInfo_Details4.add(ad4); |
|||
asr4.setDetails(approvalInfo_Details4); |
|||
|
|||
|
|||
spRecord_list.add(asr1); |
|||
spRecord_list.add(asr2); |
|||
// spRecord_list.add(asr3);
|
|||
// spRecord_list.add(asr4);
|
|||
approvalInfo.setSpRecord(spRecord_list); |
|||
|
|||
approvalInfo.setStatuChangeEvent("2"); |
|||
|
|||
|
|||
callback(approvalInfo); |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
@ -1,42 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.dreamchaser.depository_manage.depository_mapper.DepositoryRecordMapper; |
|||
import com.dreamchaser.depository_manage.entity.ApplicationOutRecordMin; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.pojo.ApplicationOutRecordMinP; |
|||
import com.dreamchaser.depository_manage.service.DepositoryRecordService; |
|||
import com.dreamchaser.depository_manage.service.UserService; |
|||
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.Scanner; |
|||
|
|||
@RunWith(SpringRunner.class) |
|||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
|||
public class SomeTest { |
|||
@Autowired |
|||
private QyWxOperationService qyWxOperationService; |
|||
|
|||
@Autowired |
|||
private DepositoryRecordMapper depositoryRecordMapper; |
|||
|
|||
@Autowired |
|||
private UserService userService; |
|||
|
|||
@Test |
|||
public void sendQyWxMsg() { |
|||
String a = "w,e,a,q,b"; |
|||
String[] split = a.split(","); |
|||
for (String next : split) { |
|||
if ("q".equals(next)) { |
|||
return; |
|||
} |
|||
System.out.println(next); |
|||
} |
|||
|
|||
} |
|||
} |
|||
@ -1,247 +0,0 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.config.PublicConfig; |
|||
import com.dreamchaser.depository_manage.entity.MaterialType; |
|||
import com.dreamchaser.depository_manage.exception.MyException; |
|||
import com.dreamchaser.depository_manage.security.pool.RedisPool; |
|||
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.MaterialTypeService; |
|||
import com.dreamchaser.depository_manage.utils.DateUtil; |
|||
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|||
import org.apache.ibatis.jdbc.Null; |
|||
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(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
|||
@RunWith(SpringRunner.class) |
|||
public class SunburstChartTest { |
|||
|
|||
|
|||
@Autowired |
|||
MaterialTypeService materialTypeService; |
|||
|
|||
@Autowired |
|||
DepositoryRecordService depositoryRecordService; |
|||
|
|||
@Autowired |
|||
MaterialService materialService; |
|||
|
|||
@Autowired |
|||
DepositoryService depositoryService; |
|||
|
|||
@Autowired |
|||
RedisPool redisPool; |
|||
|
|||
|
|||
@Test |
|||
public void main() { |
|||
|
|||
String type = "2"; |
|||
// 获取本月之前的月份
|
|||
Map<String, Object> previousMonth = DateUtil.getPreviousMonth(); |
|||
// 获取月份的时间戳
|
|||
List<Long> months = ObjectFormatUtil.objToList(previousMonth.get("months"), Long.class); |
|||
// 获取月份名称
|
|||
List<Object> sourceList = ObjectFormatUtil.objToList(previousMonth.get("sourceList"), Object.class); |
|||
// 结果集
|
|||
List<MaterialType> materialTypeNoParent = materialTypeService.findMaterialTypeNoParent(); |
|||
|
|||
Map<String, Object> sourceListTask = getSunBurstDataForApplication("7月", type, months.get(2), months.get(1), materialTypeNoParent, 56); |
|||
System.out.println(JSONObject.toJSONString(sourceListTask)); |
|||
// 用于返回结果
|
|||
|
|||
|
|||
// Map<String, Object> sunBurstDataByMtName = getSunBurstDataByMtName("7月", "1", months.get(2), months.get(1), "化验器具");
|
|||
// System.out.println(sunBurstDataByMtName);
|
|||
} |
|||
|
|||
/** |
|||
* 用于获取出入库的旭日图数据 |
|||
* |
|||
* @param dayName 当前月份名称 |
|||
* @param type 查看类型 |
|||
* @param start 开始时间 |
|||
* @param end 结束时间 |
|||
* @param materialTypeAll 当前查看物料类型 |
|||
* @return |
|||
*/ |
|||
public Map<String, Object> getSunBurstDataForApplication(String dayName, String type, Long start, Long end, List<MaterialType> materialTypeAll, Integer depositoryId) { |
|||
|
|||
Map<String, Object> result = new HashMap<>(); |
|||
List<Object> resultForData = new ArrayList<>(); |
|||
double sum = 0.0; |
|||
|
|||
int maxThreadSize = materialTypeAll.size(); |
|||
|
|||
int threadSize = Runtime.getRuntime().availableProcessors(); |
|||
|
|||
ExecutorService exs = new ThreadPoolExecutor(threadSize, maxThreadSize, 100, TimeUnit.SECONDS, new LinkedBlockingQueue<>(maxThreadSize)); |
|||
|
|||
// 结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
|
|||
|
|||
for (MaterialType materialType : materialTypeAll) { |
|||
// 测试
|
|||
Future<Object> future = completionService.submit(new getSunBurstDataForApplicationByDepository(type, start, end, materialType, depositoryId)); |
|||
futureList.add(future); |
|||
} |
|||
|
|||
for (int i = 0; i < materialTypeAll.size(); i++) { |
|||
Object obj = null; |
|||
try { |
|||
obj = completionService.take().get(); |
|||
sum = ObjectFormatUtil.sum(sum, ObjectFormatUtil.toDouble(ObjectFormatUtil.objToMap(obj, String.class, Object.class).get("value"))); |
|||
} catch (InterruptedException | ExecutionException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
resultForData.add(obj); |
|||
} |
|||
|
|||
|
|||
result.put("children", resultForData); |
|||
result.put("name", dayName); |
|||
result.remove("month"); |
|||
result.put("value", sum); |
|||
// 用于生产随机的颜色
|
|||
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); |
|||
return result; |
|||
} |
|||
|
|||
/** |
|||
* 用于获取当前类别名称下当前月份的出入库的旭日图数据 |
|||
* |
|||
* @param dayName 当前月份 |
|||
* @param type 类型(1入库2出库) |
|||
* @param start 开始 |
|||
* @param end 结束 |
|||
* @param mtName 类别名称 |
|||
* @return |
|||
*/ |
|||
public Map<String, Object> getSunBurstDataByMtName(String dayName, String type, Long start, Long end, String mtName, Integer depositoryId) { |
|||
List<MaterialType> materialTypeByNames = materialTypeService.findMaterialTypeByName(mtName); |
|||
MaterialType materialType = null; |
|||
if (materialTypeByNames.size() > 0) { |
|||
materialType = materialTypeByNames.get(0); |
|||
} else { |
|||
throw new MyException("错误,不存在当前名称的类型"); |
|||
} |
|||
List<MaterialType> childMaterialTypeList = materialTypeService.findChildForMaterialTypeByParent(materialType.getOldId()); |
|||
|
|||
|
|||
int threadSize = PublicConfig.availableVirtualMachine; |
|||
|
|||
int maxThreadSize = childMaterialTypeList.size(); |
|||
if (maxThreadSize < threadSize) { |
|||
maxThreadSize = threadSize * 2; |
|||
} |
|||
ExecutorService exs = new ThreadPoolExecutor(threadSize, maxThreadSize, 100, TimeUnit.SECONDS, new LinkedBlockingQueue<>(maxThreadSize)); |
|||
|
|||
// 结果集
|
|||
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|||
// 1.定义CompletionService
|
|||
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|||
|
|||
int runThreadSize = 0; |
|||
for (MaterialType value : childMaterialTypeList) { |
|||
Future<Object> submit = completionService.submit(new getSunBurstDataForApplicationByDepository(type, start, end, value, depositoryId)); |
|||
runThreadSize++; |
|||
futureList.add(submit); |
|||
} |
|||
|
|||
double sum = 0.0; |
|||
List<Object> resultForData = new ArrayList<>(); |
|||
for (int i = 0; i < runThreadSize; i++) { |
|||
Object obj = null; |
|||
try { |
|||
obj = completionService.take().get(); |
|||
resultForData.add(obj); |
|||
sum = ObjectFormatUtil.sum(sum, ObjectFormatUtil.toDouble(ObjectFormatUtil.objToMap(obj, String.class, Object.class).get("value"))); |
|||
} catch (InterruptedException | ExecutionException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
Map<String, Object> result = new HashMap<>(); |
|||
result.put("children", resultForData); |
|||
result.put("name", dayName); |
|||
result.remove("month"); |
|||
result.put("value", sum); |
|||
// 用于生产随机的颜色
|
|||
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); |
|||
return result; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于具体执行查询旭日图的多线程类 |
|||
*/ |
|||
class getSunBurstDataForApplicationByDepository implements Callable<Object> { |
|||
|
|||
|
|||
String type; |
|||
Long start; |
|||
Long end; |
|||
MaterialType materialType; |
|||
Integer depositoryId; |
|||
|
|||
public getSunBurstDataForApplicationByDepository(String type, Long start, Long end, MaterialType materialType, Integer depositoryId) { |
|||
this.type = type; |
|||
this.start = start; |
|||
this.end = end; |
|||
this.materialType = materialType; |
|||
this.depositoryId = depositoryId; |
|||
} |
|||
|
|||
@Override |
|||
public Object call() throws Exception { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
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("end", end); |
|||
map.put("depositoryId", depositoryId); |
|||
map.put("oldId", materialType.getOldId()); |
|||
Map<String, Object> result = new HashMap<>(); |
|||
Double materialCountByMonth = depositoryRecordService.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; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue