Browse Source

修改因completeOutTime导致的问题

lwx_dev
erdanergou 2 years ago
parent
commit
66f17d63a1
  1. 20
      src/main/java/com/dreamchaser/depository_manage/config/PublicConfig.java
  2. 12
      src/main/java/com/dreamchaser/depository_manage/controller/UserController.java
  3. 6
      src/main/java/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml
  4. 2
      src/main/java/com/dreamchaser/depository_manage/service/impl/DepositoryRecordServiceImpl.java
  5. 141
      src/main/resources/templates/pages/depository/inEchart/LineChart.html
  6. 167
      src/test/java/com/dreamchaser/depository_manage/BarChartTest.java

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

@ -610,4 +610,24 @@ public class PublicConfig {
JSONObject data = (JSONObject) jsonObject.get("data");
return data.getJSONArray("list");
}
/**
* 绩效考核系统的登录接口
* @param map
* @return
*/
public static JSONObject baseLogin(Map<String, String> map){
String url = PublicConfig.external_url_6666 + "/base/login";
String jsonString = JSONObject.toJSONString(map);
JSONObject paramObject = JSONObject.parseObject(jsonString);
String post = null;
try {
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, null, null);
} catch (IOException e) {
e.printStackTrace();
}
JSONObject jsonObject = JSONObject.parseObject(post);
JSONObject data = (JSONObject) jsonObject.get("data");
return data;
}
}

12
src/main/java/com/dreamchaser/depository_manage/controller/UserController.java

@ -70,17 +70,7 @@ public class UserController {
// 如果是企业微信跳转
flag = false;
}
String url = PublicConfig.external_url_6666 + "/base/login";
String jsonString = JSONObject.toJSONString(map);
JSONObject paramObject = JSONObject.parseObject(jsonString);
String post = null;
try {
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, null, null);
} catch (IOException e) {
e.printStackTrace();
}
JSONObject jsonObject = JSONObject.parseObject(post);
JSONObject data = (JSONObject) jsonObject.get("data");
JSONObject data = PublicConfig.baseLogin(map);
String userkey = (String) data.get("key");
if (userkey != null) {
String userToken = (String) data.get("token");

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

@ -654,7 +654,7 @@
select
<include refid="ApplicationOutRecordInfo"/>
from applicationOutRecordInfo
where quantity = 0;
where aormquantity = 0;
</select>
@ -1455,8 +1455,8 @@
<if test="checkId != null">
checkId = #{checkId},
</if>
<if test="minRecordCompleteTime != null">
completeOutTime = #{minRecordCompleteTime},
<if test="completeOutTime != null">
completeOutTime = #{completeOutTime},
</if>
<if test="parentId != null ">
parentId = #{parentId},

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

@ -248,7 +248,7 @@ public class DepositoryRecordServiceImpl implements DepositoryRecordService {
if (placeId == null || "".equals(placeId) || "0".equals(placeId)) {
map.put("placeId", 0);
}
double quantity = ObjectFormatUtil.toDouble((String) map.get("quantity")) * 100;
double quantity = ObjectFormatUtil.toDouble(map.get("quantity")) * 100;
Long time = DateUtil.DateTimeToTimeStamp(DateUtil.getSimpleTime(new Date()));
map.put("applicantTime", time);
Integer mid = ObjectFormatUtil.toInteger(map.get("mid"));

141
src/main/resources/templates/pages/depository/inEchart/LineChart.html

@ -0,0 +1,141 @@
<!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">
<button class="layui-btn" lay-submit lay-filter="perMensem">
&emsp;按月&emsp;
</button>
<button class="layui-btn" lay-submit lay-filter="byTheDay">
&emsp;按日&emsp;
</button>
<select id="selectDepositoryForChart" class="form-control">
</select>
<div id="echarts-line" style="background-color:#ffffff;padding: 10px;height: 400px">
</div>
</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 initLineChartByTheDay(){
}
layui.use(['layer', 'element'], function () {
var $ = layui.jquery,
layer = layui.layer,
element = layui.element,
form = layui.form;
// 折线图
let LineChart = echarts.init(document.getElementById('echarts-line'));
let LineChartOption = {
xAxis: {
type: 'category',
data: []
},
yAxis: {
type: 'value'
},
series: [
{
data: [],
type: 'line'
}
]
};
//动态加载相关数据
$(function () {
});
// 按月加载
form.on('submit(perMensem)', function () {
});
// 按天加载
form.on('submit(byTheDay)', function () {
});
$('#selectDepositoryForChart').on('change', function (obj) {
let value = obj.target.value;
});
initLineChartByTheDay = function(req) {
$.ajax({
url: '/repository/layui/echart_back?type=1',
type: 'get',
async: true,
dataType: "json",
complete: function (XHR, TS) {
if (XHR.status !== 200) {
layer.alert("系统繁忙,稍后重试");
}
},
beforeSend: function () {
this.layerIndex = layer.load(0, {shade: [0.5, '#393D49']});
},
success: function (result) {
layer.close(this.layerIndex);
}
})
}
});
</script>
</body>
</html>

167
src/test/java/com/dreamchaser/depository_manage/BarChartTest.java

@ -1,11 +1,9 @@
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.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.service.*;
import com.dreamchaser.depository_manage.utils.DateUtil;
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil;
import lombok.Data;
@ -36,6 +34,9 @@ public class BarChartTest {
@Autowired
DepositoryService depositoryService;
@Autowired
RoleService roleService;
/**
* 获取本月之前的月份
*
@ -72,127 +73,58 @@ public class BarChartTest {
@Test
public void main() {
UserByPort userByPort = PublicConfig.FindUserById(87, null,null);
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 = getBarChartData("2", 41);
System.out.println(barChartData);
}
/**
* 用于获取出入库对照柱状图
* @param userByPort 待获取的当前用户
*
* @return
*/
List<Object> getBarChartData( UserByPort userByPort){
Map<String, Integer> depositoryAllNameAndId = depositoryService.findDepositoryAllNameAndId(userByPort);
int threadSize = 2;
ExecutorService exs = new ThreadPoolExecutor(threadSize, threadSize, 100, TimeUnit.SECONDS, new LinkedBlockingQueue<>(threadSize));
// 结果集
List<Future<Object>> futureList = new ArrayList<Future<Object>>();
Map<Object, Object> getBarChartData(String type, Integer depositoryId) {
// 定义CompletionService
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs);
Future<Object> submitForIn = completionService.submit(new GetBarChartData(depositoryAllNameAndId, "1"));
Future<Object> submitForOut = completionService.submit(new GetBarChartData(depositoryAllNameAndId, "2"));
futureList.add(submitForOut);
futureList.add(submitForIn);
List<Object> result = new ArrayList<>();
for (int i = 0; i < 2; i++) {
Object obj = null;
try {
obj = completionService.take().get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
result.add(obj);
}
return result;
}
/**
* 用于执行柱状图线程
*/
class GetBarChartData implements Callable<Object> {
// 仓库名称与id对应
Map<String, Integer> depositoryAllNameAndId;
// 要查询的类型
String type;
public GetBarChartData(Map<String, Integer> depositoryAllNameAndId, String type) {
this.depositoryAllNameAndId = depositoryAllNameAndId;
this.type = type;
}
@Override
public Object call() throws Exception {
Map<Object, Object> lineChartData = getLineChartData(depositoryAllNameAndId, type);
Map<String,Object> result = new HashMap<>();
if("1".equals(type)){
// 如果是入库
result.put("in",lineChartData);
}else if("2".equals(type)){
// 如果是出库
result.put("out",lineChartData);
}
return result;
}
Map<Object, Object> barChartData = getBarChartData(depositoryId, type);
return barChartData;
}
/**
* 获取入库或出库数据
* @param depositoryAllNameAndId 仓库名称与id对应
* @param type 类型1入库2出库
*
* @param depositoryId 要查看的仓库id
* @param type 类型1入库2出库
* @return
*/
public Map<Object,Object> getLineChartData(Map<String, Integer> depositoryAllNameAndId, String type) {
public Map<Object, Object> getBarChartData(Integer depositoryId, String type) {
// 获取遍历器
Iterator it = depositoryAllNameAndId.keySet().iterator();
//获取获取系统的当前日历对象
Calendar instance = Calendar.getInstance();
// 获取日期
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
int now = instance.get(Calendar.DAY_OF_WEEK) - 1 == 0 ? 7 : instance.get(Calendar.DAY_OF_WEEK) - 1;
List<Long> days = new ArrayList<>(); // 周一至今的每天
instance.add(Calendar.DATE, 1);
days.add(DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime())));
instance.add(Calendar.DATE, -1);
days.add(DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime())));
while (now - 1 > 0) {
now--;
instance.add(Calendar.DATE, -1);
Long format = DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime()));
days.add(format);
}
// 定义线程
int threadSize = depositoryAllNameAndId.size();
ExecutorService exs = new ThreadPoolExecutor(threadSize, threadSize, 100, TimeUnit.SECONDS, new LinkedBlockingQueue<>(threadSize));
// 结果集
List<Future<Object>> futureList = new ArrayList<Future<Object>>();
// 1.定义CompletionService
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs);
Map<String, Object> monthBeginToNow = DateUtil.getMonthBeginToNow();
// 获取至今的日期名称
List<String> dayNames = ObjectFormatUtil.objToList(monthBeginToNow.get("dayName"), String.class);
// 获取至今的日期时间戳
List<Long> dayTimeSpaces = ObjectFormatUtil.objToList(monthBeginToNow.get("dayTimeSpace"), Long.class);
// 定义线程
// 每天各仓库入库数目
Map<Object,Object> show_data = new HashMap<>();
while (it.hasNext()) {
Object next = it.next();
getBarChartDataForApplicationRecord getApplicationRecordByDate = new getBarChartDataForApplicationRecord(type, next.toString(), days, depositoryAllNameAndId);
Future<Object> future = completionService.submit(getApplicationRecordByDate);
futureList.add(future);
}
for (int i = 0; i < depositoryAllNameAndId.size(); i++) {
Object result = null;
try {
result = completionService.take().get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
show_data.putAll((Map<?, ?>) result);
Map<Object, Object> show_data = new HashMap<>();
getBarChartDataForApplicationRecord getApplicationRecordByDate = new getBarChartDataForApplicationRecord(type, depositoryId, dayTimeSpaces);
try {
Object call = getApplicationRecordByDate.call();
show_data.put("data", call);
} catch (Exception e) {
e.printStackTrace();
}
show_data.put("dayNames",dayNames);
return show_data;
}
@ -201,49 +133,38 @@ public class BarChartTest {
*/
@Data
class getBarChartDataForApplicationRecord implements Callable<Object> {
String key;
Integer depositoryId;
List<Long> days;
Map<String, Integer> depositoryAllNameAndId;
String type;
getBarChartDataForApplicationRecord(String type, String key, List<Long> days, Map<String, Integer> depositoryAllNameAndId) {
this.key = key;
this.depositoryAllNameAndId = depositoryAllNameAndId;
getBarChartDataForApplicationRecord(String type, Integer depositoryId, List<Long> days) {
this.days = days;
this.type = type;
this.depositoryId = depositoryId;
}
@Override
public Object call() throws Exception {
Map<Integer, Object> result = new HashMap<>();
Map<String, Object> map = new HashMap<>();
map.put("type", "bar");
Map<String, Object> emphasisItem = new HashMap<>();
emphasisItem.put("focus","series");
emphasisItem.put("focus", "series");
map.put("emphasis", emphasisItem);
Map<String, Object> labelItem = new HashMap<>();
labelItem.put("show",true);
labelItem.put("position","inside");
labelItem.put("show", true);
labelItem.put("position", "inside");
map.put("label", labelItem);
int i;
List<Double> drCountbyDrName = new ArrayList<>();
Integer val = depositoryAllNameAndId.get(key);
for (i = days.size() - 1; i > 0; i--) {
// 遍历 Map并计算各仓库的入库数
// 获取一段时间内的库存额度
Double depositoryRecordByDate1 = depositoryRecordService.findApplicationRecordByDate(days.get(i - 1), days.get(i), ObjectFormatUtil.toInteger(type), val);
if("2".equals(type)){
depositoryRecordByDate1 = -depositoryRecordByDate1;
}
Double depositoryRecordByDate1 = depositoryRecordService.findApplicationRecordByDate( days.get(i),days.get(i - 1), ObjectFormatUtil.toInteger(type), depositoryId);
drCountbyDrName.add(depositoryRecordByDate1);
}
map.put("data", drCountbyDrName);
result.put(val,map);
return result;
return map;
}
}
}

Loading…
Cancel
Save