Browse Source

添加旭日图基本功能

lwx_dev
erdanergou 2 years ago
parent
commit
082a6761ec
  1. 6
      pom.xml
  2. 2
      src/main/java/com/dreamchaser/depository_manage/config/PublicConfig.java
  3. 48
      src/main/java/com/dreamchaser/depository_manage/controller/DepositoryController.java
  4. 106
      src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java
  5. 25
      src/main/java/com/dreamchaser/depository_manage/controller/PageController.java
  6. 3
      src/main/java/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml
  7. 10
      src/main/java/com/dreamchaser/depository_manage/service/DepositoryRecordService.java
  8. 136
      src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java
  9. 23
      src/main/java/com/dreamchaser/depository_manage/utils/DateUtil.java
  10. 2
      src/main/resources/templates/pages/depository/InAndOut_echart/LineOrBarChart.html
  11. 245
      src/main/resources/templates/pages/depository/InAndOut_echart/SunburstChart.html
  12. 24
      src/main/resources/templates/pages/depository/table-in.html
  13. 24
      src/main/resources/templates/pages/depository/table-out.html
  14. 183
      src/test/java/com/dreamchaser/depository_manage/SunburstChartTest.java

6
pom.xml

@ -48,6 +48,12 @@
<version>3.4.2</version> <version>3.4.2</version>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>com.baomidou</groupId>-->
<!-- <artifactId>dynamic-datasource-spring-boot-starter</artifactId>-->
<!-- <version>3.2.0</version>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId> <artifactId>logback-classic</artifactId>

2
src/main/java/com/dreamchaser/depository_manage/config/PublicConfig.java

@ -41,6 +41,8 @@ public class PublicConfig {
// 定义redis加锁的名称 // 定义redis加锁的名称
public static String redis_Lock_name = "Wms_redis_lock"; public static String redis_Lock_name = "Wms_redis_lock";
public static int availableVirtualMachine = Runtime.getRuntime().availableProcessors();
/** /**
* 获取相应部门的部门负责人 * 获取相应部门的部门负责人
* *

48
src/main/java/com/dreamchaser/depository_manage/controller/DepositoryController.java

@ -1261,52 +1261,10 @@ public class DepositoryController {
} }
/**
* 用于获取出入库的柱状图数据
*
* @param map 查询数据
* @param request
* @return
*/
@PostMapping("/getBarChartDataByDateType")
public RestResponse getBarChartDataByDateType(@RequestBody Map<String, String> map, HttpServletRequest request) {
if (!map.containsKey("echartType")) {
throw new MyException("错误,请指定图表类型");
}
String echartType = map.get("echartType");
// 获取要查询的类型(1入库2出库)
String type = map.get("type");
// 声明要查询时的日期类型 day代表按天,month代表按月
String dateType = "day";
if (map.containsKey("dateType")) {
dateType = map.get("dateType");
}
Integer depositoryId = -1;
if (map.containsKey("depositoryId")) {
// 如果选择了仓库,则使用选中的仓库
depositoryId = ObjectFormatUtil.toInteger(map.get("depositoryId"));
} else {
// 如果没选中仓库
String token = request.getHeader("user-token");
if (token == null) {
token = (String) request.getSession().getAttribute("userToken");
}
UserByPort userToken = AuthenticationTokenPool.getUserToken(token);
// 获取当前用户可见的仓库id
List<Integer> depositoryIdForUser = roleService.findDepositoryIdForUser(userToken);
// 如果存在仓库
if (depositoryIdForUser != null && depositoryIdForUser.size() > 0) {
// 默认为第一个
depositoryId = depositoryIdForUser.get(0);
}
}
Map<Object, Object> data = new HashMap<>();
if (depositoryId != -1) {
data = depositoryRecordService.getLineOrBarChartData(depositoryId, type, dateType, echartType);
}
return new RestResponse(data);
}
/** /**
* 用于获取当前仓库的所有子类 * 用于获取当前仓库的所有子类

106
src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java

@ -56,6 +56,10 @@ public class DepositoryRecordController {
private RoleService roleService; private RoleService roleService;
@Autowired
private MaterialTypeService materialTypeService;
@GetMapping("/myApply") @GetMapping("/myApply")
public RestResponse findDepositoryInAndOutRecordPByCondition(@RequestParam Map<String, Object> map, HttpServletRequest request) { public RestResponse findDepositoryInAndOutRecordPByCondition(@RequestParam Map<String, Object> map, HttpServletRequest request) {
String token = request.getHeader("user-token"); String token = request.getHeader("user-token");
@ -2503,4 +2507,106 @@ public class DepositoryRecordController {
return new RestResponse(result); return new RestResponse(result);
} }
/**
* 用于获取出入库的柱状或折线图数据
*
* @param map 查询数据
* @param request
* @return
*/
@PostMapping("/getBarChartDataByDateType")
public RestResponse getBarChartDataByDateType(@RequestBody Map<String, String> map, HttpServletRequest request) {
if (!map.containsKey("echartType")) {
throw new MyException("错误,请指定图表类型");
}
String echartType = map.get("echartType");
// 获取要查询的类型(1入库2出库)
String type = map.get("type");
// 声明要查询时的日期类型 day代表按天,month代表按月
String dateType = "day";
if (map.containsKey("dateType")) {
dateType = map.get("dateType");
}
Integer depositoryId = -1;
if (map.containsKey("depositoryId")) {
// 如果选择了仓库,则使用选中的仓库
depositoryId = ObjectFormatUtil.toInteger(map.get("depositoryId"));
} else {
// 如果没选中仓库
String token = request.getHeader("user-token");
if (token == null) {
token = (String) request.getSession().getAttribute("userToken");
}
UserByPort userToken = AuthenticationTokenPool.getUserToken(token);
// 获取当前用户可见的仓库id
List<Integer> depositoryIdForUser = roleService.findDepositoryIdForUser(userToken);
// 如果存在仓库
if (depositoryIdForUser != null && depositoryIdForUser.size() > 0) {
// 默认为第一个
depositoryId = depositoryIdForUser.get(0);
}
}
Map<Object, Object> data = new HashMap<>();
if (depositoryId != -1) {
data = depositoryRecordService.getLineOrBarChartData(depositoryId, type, dateType, echartType);
}
return new RestResponse(data);
}
/**
* 用于获取出入库的旭日图的数据
* @param map 查询数据
* @param request
* @return
*/
@PostMapping("/getSunBurstDataForApplication")
public RestResponse getSunBurstDataForApplication(@RequestBody Map<String, String> map, HttpServletRequest request) {
// String dateName, String type, Long start, Long end, List<MaterialType> materialTypeAll
if (!map.containsKey("type")) {
throw new MyException("错误,请指定图表类型");
}
// 获取图表类型
String type = map.get("type");
// 获取要查看的日期
String dateName = null;
int month = -1;
if (map.containsKey("dateName")) {
dateName = map.get("dateName");
month = ObjectFormatUtil.toInteger(dateName.split("月")[0]);
} else {
Calendar instance = Calendar.getInstance();
month = instance.get(Calendar.MONTH) + 1;
dateName = month + "月";
}
Integer depositoryId = -1;
if (map.containsKey("depositoryId")) {
// 如果选择了仓库,则使用选中的仓库
depositoryId = ObjectFormatUtil.toInteger(map.get("depositoryId"));
} else {
// 如果没选中仓库
String token = request.getHeader("user-token");
if (token == null) {
token = (String) request.getSession().getAttribute("userToken");
}
UserByPort userToken = AuthenticationTokenPool.getUserToken(token);
// 获取当前用户可见的仓库id
List<Integer> depositoryIdForUser = roleService.findDepositoryIdForUser(userToken);
// 如果存在仓库
if (depositoryIdForUser != null && depositoryIdForUser.size() > 0) {
// 默认为第一个
depositoryId = depositoryIdForUser.get(0);
}
}
// 获取当前month月与下个月的月初
Map<String, Long> timeSpaceMap = DateUtil.getThisMonthTimeSpace(month);
Long start = timeSpaceMap.get("start");
Long end = timeSpaceMap.get("end");
// 获取所有顶级物料类型
List<MaterialType> materialTypeNoParent = materialTypeService.findMaterialTypeNoParent();
Map<String, Object> data = depositoryRecordService.getSunBurstDataByForApplication(dateName, type, start, end, materialTypeNoParent,depositoryId);
return new RestResponse(data);
}
} }

25
src/main/java/com/dreamchaser/depository_manage/controller/PageController.java

@ -3944,8 +3944,14 @@ public class PageController {
} }
@GetMapping("/echartForTable") /**
public ModelAndView echartForTable(String type, String echartType) { * 用于跳转到折线或柱状图
* @param type 要查看的出入库
* @param echartType 图表类型
* @return
*/
@GetMapping("/lineOrBarEchartForTable")
public ModelAndView lineOrBarEchartForTable(String type, String echartType) {
ModelAndView mv = new ModelAndView(); ModelAndView mv = new ModelAndView();
mv.addObject("type", type); mv.addObject("type", type);
mv.addObject("echartType", echartType); mv.addObject("echartType", echartType);
@ -3953,4 +3959,19 @@ public class PageController {
return mv; return mv;
} }
/**
* 用于跳转到折线或柱状图
* @param type 要查看的出入库
* @return
*/
@GetMapping("/sunburstEchartForTable")
public ModelAndView sunburstEchartForTable(String type) {
ModelAndView mv = new ModelAndView();
mv.addObject("type", type);
Map<String, Object> previousMonth = DateUtil.getPreviousMonth();
List<String> monthNames = ObjectFormatUtil.objToList(previousMonth.get("monthNames"), String.class);
mv.addObject("monthNames", monthNames);
mv.setViewName("pages/depository/InAndOut_echart/SunburstChart");
return mv;
}
} }

3
src/main/java/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml

@ -1833,6 +1833,9 @@
<if test="tname != null and tname != ''"> <if test="tname != null and tname != ''">
and tname = #{tname} and tname = #{tname}
</if> </if>
<if test="depository_id != null and depository_id != ''">
and did = #{depository_id}
</if>
<if test="list != null"> <if test="list != null">
and mtid in and mtid in
<foreach collection="list" index="index" item="typeId" open="(" separator="," close=")"> <foreach collection="list" index="index" item="typeId" open="(" separator="," close=")">

10
src/main/java/com/dreamchaser/depository_manage/service/DepositoryRecordService.java

@ -510,6 +510,16 @@ public interface DepositoryRecordService {
Map<Object, Object> getLineOrBarChartData(Integer depositoryId, String type, String dateType, String echartType); Map<Object, Object> getLineOrBarChartData(Integer depositoryId, String type, String dateType, String echartType);
/**
* 用于获取出入库的旭日图数据
* @param dateName 当前月份名称
* @param type 查看类型
* @param start 开始时间
* @param end 结束时间
* @param materialTypeAll 当前查看物料类型
* @return
*/
Map<String, Object> getSunBurstDataByForApplication(String dateName, String type, Long start, Long end, List<MaterialType> materialTypeAll,Integer depositoryId);
} }

136
src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java

@ -5297,10 +5297,10 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
double sumCount = 0; double sumCount = 0;
if (type == 1) { if (type == 1) {
// 如果入库 // 如果入库
sumCount = depositoryRecordMapper.findApplicationInByMonthTest(map) / 100.0; sumCount = ObjectFormatUtil.divide(depositoryRecordMapper.findApplicationInByMonthTest(map) , 100.0,2);
} else { } else {
// 如果出库 // 如果出库
sumCount = depositoryRecordMapper.findApplicationOutByMonth(map) / 100.0; sumCount = ObjectFormatUtil.divide(depositoryRecordMapper.findApplicationOutByMonth(map), 100.0, 2);
} }
return sumCount; return sumCount;
} }
@ -5728,33 +5728,19 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
public List<Long> findChildForMaterialTypeByParent(MaterialType mt) { public List<Long> findChildForMaterialTypeByParent(MaterialType mt) {
List<Long> result = new ArrayList<>(); List<Long> result = new ArrayList<>();
result.add(mt.getOldId()); result.add(mt.getOldId());
List<Long> parentId = new ArrayList<>(); List<Long> parentIdList = new ArrayList<>();
parentId.add(mt.getOldId()); parentIdList.add(mt.getOldId());
List<MaterialType> materialTypeAll = materialTypeMapper.findMaterialTypeAll(); List<MaterialType> materialTypeAll = materialTypeMapper.findMaterialTypeAll();
for (MaterialType materialType : materialTypeAll) { for (MaterialType materialType : materialTypeAll) {
if (isTrueForParent(parentId, materialType.getParentId())) { Long parentId = materialType.getParentId();
parentId.add(materialType.getOldId()); if (parentIdList.contains(parentId)) {
parentIdList.add(materialType.getOldId());
result.add(materialType.getOldId()); result.add(materialType.getOldId());
} }
} }
return result; return result;
} }
/**
* 判断当前id是否在ids中
*
* @param parentList
* @param id
* @return
*/
public Boolean isTrueForParent(List<Long> parentList, Long id) {
for (Long aLong : parentList) {
if (Long.compare(aLong, id) == 0) {
return true;
}
}
return false;
}
/** /**
* 判断当前id是否在ids中 * 判断当前id是否在ids中
@ -5966,4 +5952,112 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
return map; return map;
} }
/**
* 用于获取出入库的旭日图数据
* @param dateName 当前月份名称
* @param type 查看类型
* @param start 开始时间
* @param end 结束时间
* @param materialTypeAll 当前查看物料类型
* @return
*/
public Map<String, Object> getSunBurstDataByForApplication(String dateName, 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();
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<>();
for (MaterialType materialType : materialTypeAll) {
// 测试
Future<Object> future = completionService.submit(new getSunBurstDataForApplicationByDepository(type, start, end, materialType,depositoryId));
futureList.add(future);
}
double sum = 0.0;
for (int i = 0; i < materialTypeAll.size(); i++) {
Object obj = null;
try {
obj = completionService.take().get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
resultForData.add(obj);
if (obj != null) {
sum += ObjectFormatUtil.toDouble(ObjectFormatUtil.objToMap(obj, String.class, Object.class).get("value"));
}
}
result.put("children", resultForData);
result.put("name", dateName);
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 = 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;
}
}
} }

23
src/main/java/com/dreamchaser/depository_manage/utils/DateUtil.java

@ -292,6 +292,7 @@ public class DateUtil {
/** /**
* 获取本月至今每天零时的日期时间戳及日期名称 * 获取本月至今每天零时的日期时间戳及日期名称
*
* @return * @return
*/ */
public static Map<String, Object> getMonthBeginToNow() { public static Map<String, Object> getMonthBeginToNow() {
@ -332,4 +333,26 @@ public class DateUtil {
return result; return result;
} }
/**
* 获取当前月份与下个月份的月初时间
*
* @param month 待获取月份
* @return
*/
public static Map<String, Long> getThisMonthTimeSpace(int month) {
Map<String, Long> result = new HashMap<>();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");
Calendar instance = Calendar.getInstance();
instance.set(Calendar.MONTH, month - 1);
String start = formatter.format(instance.getTime());
Long startTimeSpace = DateUtil.DateTimeByMonthToTimeStamp(start);
instance.add(Calendar.MONTH, 1);
String end = formatter.format(instance.getTime());
Long endTimeSpace = DateUtil.DateTimeByMonthToTimeStamp(end);
result.put("start", startTimeSpace);
result.put("end", endTimeSpace);
return result;
}
} }

2
src/main/resources/templates/pages/depository/InAndOut_echart/LineOrBarChart.html

@ -169,7 +169,7 @@
initBarChartByDateType = function (req) { initBarChartByDateType = function (req) {
$.ajax({ $.ajax({
url: '/repository/getBarChartDataByDateType', url: '/depositoryRecord/getBarChartDataByDateType',
type: 'post', type: 'post',
dataType: "json", dataType: "json",
data: JSON.stringify(req), data: JSON.stringify(req),

245
src/main/resources/templates/pages/depository/InAndOut_echart/SunburstChart.html

@ -0,0 +1,245 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>旭日图</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="/static/lib/layui-v2.8.6/css/layui.css" media="all">
<link rel="stylesheet" href="/static/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
<link rel="stylesheet" href="/static/lib/bootstrap-3.4.1-dist/css/bootstrap.min.css" media="all">
<link rel="stylesheet" href="/static/css/public.css" media="all">
<style>
.top-panel {
border: 1px solid #eceff9;
border-radius: 5px;
text-align: center;
}
.top-panel > .layui-card-body {
height: 60px;
}
.top-panel-number {
line-height: 60px;
font-size: 30px;
border-right: 1px solid #eceff9;
}
.top-panel-tips {
line-height: 30px;
font-size: 12px
}
</style>
</head>
<body>
<div class="layuimini-main">
<div class="layui-colla-item">
<h2 class="layui-colla-title">旭日图</h2>
<div class="layui-colla-content layui-show">
<input id="type" th:value="${type}" style="display:none;">
<select id="selectMonthForChart" class="form-control">
<option th:each="month,iterStar:${monthNames}"
th:value="${month}"
th:text="${month}"></option>
</select>
<select id="selectDepositoryForChart" class="form-control">
</select>
<div id="echarts-sunburst-chart" style="background-color:#ffffff;padding: 10px;height:400px;"></div>
</div>
</div>
</div>
<script src="/static/lib/layui-v2.8.6/layui.js" charset="utf-8"></script>
<script src="/static/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="/static/lib/echarts/echarts.js" charset="utf-8"></script>
<script>
function initSunburstChart() {
}
function getThisUserDepository() {
}
layui.use(['layer', 'element'], function () {
var $ = layui.jquery,
layer = layui.layer,
element = layui.element,
form = layui.form;
let type = $("#type").val();
// 旭日图
var echartSunburstChart = echarts.init(document.getElementById('echarts-sunburst-chart'));
var optionSunburstChart = {
title: {
textStyle: {
fontSize: 14,
align: 'center'
},
subtextStyle: {
align: 'center'
},
},
series: {
type: 'sunburst',
data: [],
radius: [0, '95%'],
sort: undefined,
emphasis: {
focus: 'ancestor'
},
levels: [
{},
{
r0: '15%',
r: '35%',
itemStyle: {
borderWidth: 2
},
label: {
rotate: 'tangential'
}
},
{
r0: '35%',
r: '70%',
label: {
align: 'right'
}
},
{
r0: '70%',
r: '72%',
label: {
position: 'outside',
padding: 3,
silent: false
},
itemStyle: {
borderWidth: 3
}
}
]
},
toolbox: {
feature: {
myFull: {
show: true,
title: '全屏查看',
icon: 'path://M432.45,595.444c0,2.177-4.661,6.82-11.305,6.82c-6.475,0-11.306-4.567-11.306-6.82s4.852-6.812,11.306-6.812C427.841,588.632,432.452,593.191,432.45,595.444L432.45,595.444z M421.155,589.876c-3.009,0-5.448,2.495-5.448,5.572s2.439,5.572,5.448,5.572c3.01,0,5.449-2.495,5.449-5.572C426.604,592.371,424.165,589.876,421.155,589.876L421.155,589.876z M421.146,591.891c-1.916,0-3.47,1.589-3.47,3.549c0,1.959,1.554,3.548,3.47,3.548s3.469-1.589,3.469-3.548C424.614,593.479,423.062,591.891,421.146,591.891L421.146,591.891zM421.146,591.891',
onclick: function (e) {
var opts = e.getOption();
opts.toolbox[0].feature.myFull.show = false;
//window.top表示最顶层iframe 如果在当页面全屏打开 删去window.top即可
window.top.layer.open({
title: false,
type: 1,
area: ["100%", "100%"],
content: '<div id="fullChart" style="width: 100%;height: 100%;padding:30px 0px"></div>',
success: function () {
var fullchart = echarts.init(window.top.document.getElementById('fullChart'));
fullchart.setOption(optionSunburstChart)
}
})
}
},
saveAsImage: {},
dataZoom: {
yAxisIndex: 'none'
},
}
}
};
$(function () {
let req = {};
req.type = type;
getThisUserDepository();
initSunburstChart(req);
});
$('#selectDepositoryForChart').on('change', function (obj) {
let value = obj.target.value;
let req = {};
req.depositoryId = value;
req.dateName = $("#selectMonthForChart").val();
req.type = type;
initSunburstChart(req);
});
$("#selectMonthForChart").on('change',function(obj) {
let value = obj.target.value;
let req = {};
req.dateName = value;
req.type = type;
req.depositoryId = $("#selectDepositoryForChart").val();
initSunburstChart(req);
});
initSunburstChart = function (req) {
$.ajax({
url: '/depositoryRecord/getSunBurstDataForApplication',
type: 'post',
dataType: "json",
data: JSON.stringify(req),
contentType: "application/json;charset=utf-8",
beforeSend: function () {
this.layerIndex = layer.load(0, {shade: [0.5, '#393D49']});
},
success: function (result) {
layer.close(this.layerIndex);
let data = result.data;
optionSunburstChart.series.data = [data];
echartSunburstChart.setOption(optionSunburstChart);
}
})
};
getThisUserDepository = function () {
$.ajax({
url: '/repository/getWareHouseVisiblePermissionByUser',
type: 'get',
dataType: "json",
beforeSend: function () {
this.layerIndex = layer.load(0, {shade: [0.5, '#393D49']});
},
success: function (result) {
layer.close(this.layerIndex);
let data = result.data;
let selectItem = $("#selectDepositoryForChart");
for (let item in data) {
let optionItem = '<option value="' + data[item] + '">' + item + '</option>';
selectItem.append(optionItem)
}
}
})
}
// 设置点击事件
echartSunburstChart.on('click', function(params) {
let name = params.name;
if(name !== ""){
}
});
});
</script>
</body>
</html>

24
src/main/resources/templates/pages/depository/table-in.html

@ -329,30 +329,40 @@
$("#showEchart").append(listItem) $("#showEchart").append(listItem)
}else if(obj.event === "showSunburstEchart"){ }else if(obj.event === "showSunburstEchart"){
console.log("showSunburstEchart") layer.open({
type: 2,
offset: 'r',
anim: 'slideLeft', // 从右往左
area: ['40%', '100%'],
shade: 0.1,
title: "旭日图",
shadeClose: true,
id: 'applicationOutInfoForLeft',
content: '/sunburstEchartForTable?type=1',
});
}else if(obj.event === "showLineEchart"){ }else if(obj.event === "showLineEchart"){
layer.open({ layer.open({
type: 2, type: 2,
offset: 'l', offset: 'r',
anim: 'slideRight', // 从右往左 anim: 'slideLeft', // 从右往左
area: ['40%', '100%'], area: ['40%', '100%'],
shade: 0.1, shade: 0.1,
title: "折线图", title: "折线图",
shadeClose: true, shadeClose: true,
id: 'applicationOutInfoForLeft', id: 'applicationOutInfoForLeft',
content: '/echartForTable?type=1&echartType=line', content: '/lineOrBarEchartForTable?type=1&echartType=line',
}); });
}else if(obj.event === "showBarEchart"){ }else if(obj.event === "showBarEchart"){
layer.open({ layer.open({
type: 2, type: 2,
offset: 'l', offset: 'r',
anim: 'slideRight', // 从右往左 anim: 'slideLeft', // 从右往左
area: ['40%', '100%'], area: ['40%', '100%'],
shade: 0.1, shade: 0.1,
title: "柱状图", title: "柱状图",
shadeClose: true, shadeClose: true,
id: 'applicationOutInfoForLeft', id: 'applicationOutInfoForLeft',
content: '/echartForTable?type=1&echartType=bar', content: '/lineOrBarEchartForTable?type=1&echartType=bar',
}); });
} }

24
src/main/resources/templates/pages/depository/table-out.html

@ -488,30 +488,40 @@
$("#showEchart").append(listItem) $("#showEchart").append(listItem)
}else if(obj.event === "showSunburstEchart"){ }else if(obj.event === "showSunburstEchart"){
console.log("showSunburstEchart") layer.open({
type: 2,
offset: 'r',
anim: 'slideLeft', // 从右往左
area: ['40%', '100%'],
shade: 0.1,
title: "旭日图",
shadeClose: true,
id: 'applicationOutInfoForLeft',
content: '/sunburstEchartForTable?type=2',
});
}else if(obj.event === "showLineEchart"){ }else if(obj.event === "showLineEchart"){
layer.open({ layer.open({
type: 2, type: 2,
offset: 'l', offset: 'r',
anim: 'slideRight', // 从右往左 anim: 'slideLeft', // 从右往左
area: ['40%', '100%'], area: ['40%', '100%'],
shade: 0.1, shade: 0.1,
title: "折线图", title: "折线图",
shadeClose: true, shadeClose: true,
id: 'applicationOutInfoForLeft', id: 'applicationOutInfoForLeft',
content: '/echartForTable?type=2&echartType=line', content: '/lineOrBarEchartForTable?type=2&echartType=line',
}); });
}else if(obj.event === "showBarEchart"){ }else if(obj.event === "showBarEchart"){
layer.open({ layer.open({
type: 2, type: 2,
offset: 'l', offset: 'r',
anim: 'slideRight', // 从右往左 anim: 'slideLeft', // 从右往左
area: ['40%', '100%'], area: ['40%', '100%'],
shade: 0.1, shade: 0.1,
title: "柱状图", title: "柱状图",
shadeClose: true, shadeClose: true,
id: 'applicationOutInfoForLeft', id: 'applicationOutInfoForLeft',
content: '/echartForTable?type=2&echartType=bar', content: '/lineOrBarEchartForTable?type=2&echartType=bar',
}); });
} }

183
src/test/java/com/dreamchaser/depository_manage/SunburstChartTest.java

@ -3,6 +3,7 @@ package com.dreamchaser.depository_manage;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.dreamchaser.depository_manage.entity.MaterialType; import com.dreamchaser.depository_manage.entity.MaterialType;
import com.dreamchaser.depository_manage.service.DepositoryRecordService; 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.MaterialService;
import com.dreamchaser.depository_manage.service.MaterialTypeService; import com.dreamchaser.depository_manage.service.MaterialTypeService;
import com.dreamchaser.depository_manage.utils.DateUtil; import com.dreamchaser.depository_manage.utils.DateUtil;
@ -31,75 +32,76 @@ public class SunburstChartTest {
@Autowired @Autowired
MaterialService materialService; MaterialService materialService;
@Autowired
DepositoryService depositoryService;
@Test @Test
public void main() { public void main() {
String type = "2"; String type = "2";
// 获取本月之前的月份 // 获取本月之前的月份
Map<String, Object> previousMonth = getPreviousMonth(); Map<String, Object> previousMonth = DateUtil.getPreviousMonth();
// 获取月份的时间戳 // 获取月份的时间戳
List<Object> months = (List<Object>) previousMonth.get("months"); List<Long> months = ObjectFormatUtil.objToList(previousMonth.get("months"), Long.class);
// 获取月份名称 // 获取月份名称
List<Object> sourceList = (List<Object>) previousMonth.get("sourceList"); List<Object> sourceList = ObjectFormatUtil.objToList(previousMonth.get("sourceList"), Object.class);
// 结果集 // 结果集
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); List<MaterialType> materialTypeNoParent = materialTypeService.findMaterialTypeNoParent();
int threadSize = months.size();
ExecutorService exs = Executors.newFixedThreadPool(months.size());
// 1.定义CompletionService // 1.定义CompletionService
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); Map<String, Object> map = ObjectFormatUtil.objToMap(sourceList.get(4), String.class, Object.class);
for (int num = 0; num < months.size() - 1; num++) { Map<String, Object> sourceListTask = getSunBurstDataByForApplication("map", type, months.get(2), months.get(1), materialTypeNoParent);
Map<String, Object> map = (Map<String, Object>) sourceList.get(num); System.out.println(JSONObject.toJSONString(sourceListTask));
Future<Object> future = completionService.submit(new getSourceListTask(map,type, months.get(num + 1).toString(), months.get(num).toString()));
futureList.add(future);
}
List<Object> result = new ArrayList<>();
for (int i = 0; i < months.size() - 1; i++) {
Object obj = null;
try {
obj = completionService.take().get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
result.add(obj);
}
// 用于返回结果 // 用于返回结果
System.out.println(JSONObject.toJSONString(result));
} }
// 具体执行getSourceList逻辑 @Test
class getSourceListTask implements Callable<Object> { public void a(){
int month = 7;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");
Calendar instance = Calendar.getInstance();
instance.set(Calendar.MONTH, month - 1);
String end = formatter.format(instance.getTime());
Long endTimeSpace = DateUtil.DateTimeByMonthToTimeStamp(end);
System.out.println("end:"+end);
System.out.println("endTimeSpace:"+endTimeSpace);
instance.add(Calendar.MONTH, 1);
String start = formatter.format(instance.getTime());
Long startTimeSpace = DateUtil.DateTimeByMonthToTimeStamp(formatter.format(instance.getTime()));
System.out.println("start:"+start);
System.out.println("startTimeSpace:"+startTimeSpace);
}
String type;
String start;
String end;
Map<String,Object> map;
getSourceListTask(Map<String,Object> map, String type, String start, String end) { /**
this.map = map; * 用于获取出入库的旭日图数据
this.type = type; * @param dayName 当前月份名称
this.start = start; * @param type 查看类型
this.end = end; * @param start 开始时间
} * @param end 结束时间
* @param materialTypeAll 当前查看物料类型
* @return
*/
public Map<String, Object> getSunBurstDataByForApplication(String dayName, String type, Long start, Long end, List<MaterialType> materialTypeAll) {
@Override Map<String, Object> result = new HashMap<>();
public Object call() throws Exception {
List<MaterialType> materialTypeAll = materialTypeService.findMaterialTypeNoParent(); int maxThreadSize = materialTypeAll.size();
int threadSize = materialTypeAll.size();
ExecutorService exs = new ThreadPoolExecutor(threadSize, threadSize, 100, TimeUnit.SECONDS, new LinkedBlockingQueue<>(threadSize)); 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>>(); List<Future<Object>> futureList = new ArrayList<Future<Object>>();
// 1.定义CompletionService // 1.定义CompletionService
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs);
List<Object> result = new ArrayList<>(); List<Object> resultForData = new ArrayList<>();
for (MaterialType materialType : materialTypeAll) { for (MaterialType materialType : materialTypeAll) {
// 测试 // 测试
Future<Object> future = completionService.submit(new findMaterialCountTaskForSourceList(type,start,end,materialType.getOldId())); Future<Object> future = completionService.submit(new getSunBurstDataForApplicationByDepository(type, start, end, materialType));
futureList.add(future); futureList.add(future);
} }
double sum = 0.0; double sum = 0.0;
@ -107,18 +109,15 @@ public class SunburstChartTest {
Object obj = null; Object obj = null;
try { try {
obj = completionService.take().get(); obj = completionService.take().get();
} catch (InterruptedException e) { } catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace(); e.printStackTrace();
} }
result.add(obj); resultForData.add(obj);
sum+=ObjectFormatUtil.toDouble(((Map<String,Object>)obj).get("value"));
} }
map.put("children",result); result.put("children", resultForData);
map.put("name",map.get("month")); result.put("name", dayName);
map.remove("month"); result.remove("month");
map.put("value",sum); result.put("value", sum);
// 用于生产随机的颜色 // 用于生产随机的颜色
Random random = new Random(); Random random = new Random();
Map<String, String> itemStyle = new HashMap<>(); Map<String, String> itemStyle = new HashMap<>();
@ -126,25 +125,26 @@ public class SunburstChartTest {
int g = random.nextInt(256); int g = random.nextInt(256);
int b = random.nextInt(256); int b = random.nextInt(256);
itemStyle.put("color", "rgb(" + r + "," + g + "," + b + ")"); itemStyle.put("color", "rgb(" + r + "," + g + "," + b + ")");
map.put("itemStyle",itemStyle); result.put("itemStyle", itemStyle);
return map; return result;
}
} }
// 根据条件获取月份中物料的总额用于sourcelist /**
class findMaterialCountTaskForSourceList implements Callable<Object> { * 用于具体执行查询旭日图的多线程类
*/
class getSunBurstDataForApplicationByDepository implements Callable<Object> {
String type; String type;
String start; Long start;
String end; Long end;
Long oldId; MaterialType materialType;
public findMaterialCountTaskForSourceList(String type, String start, String end,Long oldId) { public getSunBurstDataForApplicationByDepository(String type, Long start, Long end, MaterialType materialType) {
this.type = type; this.type = type;
this.start = start; this.start = start;
this.end = end; this.end = end;
this.oldId = oldId; this.materialType = materialType;
} }
@Override @Override
@ -158,12 +158,12 @@ public class SunburstChartTest {
} }
map.put("start", start); map.put("start", start);
map.put("end", end); map.put("end", end);
map.put("oldId", oldId); map.put("depositoryId", "41");
map.put("oldId", materialType.getOldId());
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
Double materialCountByMonth1 = depositoryRecordService.calMaterialTypeTopCount(map); Double materialCountByMonth = depositoryRecordService.calMaterialTypeTopCount(map);
MaterialType materialTypeByOldId = materialTypeService.findMaterialTypeByOldId(oldId); result.put("name", materialType.getTname());
result.put("name",materialTypeByOldId.getTname()); result.put("value", materialCountByMonth);
result.put("value",materialCountByMonth1);
Map<String, String> itemStyle = new HashMap<>(); Map<String, String> itemStyle = new HashMap<>();
// 用于生产随机的颜色 // 用于生产随机的颜色
Random random = new Random(); Random random = new Random();
@ -176,53 +176,4 @@ public class SunburstChartTest {
} }
} }
public List<Long> findChildForMaterialTypeByParent(MaterialType mt) {
List<Long> result = new ArrayList<>();
result.add(mt.getOldId());
List<Long> parentId = new ArrayList<>();
parentId.add(mt.getOldId());
List<MaterialType> materialTypeAll = materialTypeService.findMaterialTypeAll();
for (MaterialType materialType : materialTypeAll) {
if (parentId.contains(materialType.getParentId())) {
parentId.add(materialType.getOldId());
result.add(materialType.getOldId());
}
}
return result;
}
/**
* 获取本月之前的月份
*
* @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;
}
} }

Loading…
Cancel
Save