Browse Source

1、新增所有部门树形结构查询接口

2、修改报表导出方法
develop
bobol 9 months ago
parent
commit
9aabf21ef7
  1. 2
      lzbi-admin/src/main/resources/application-dev.yml
  2. 86
      lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiHisReportController.java
  3. 9
      lzbi-module/src/main/java/com/lzbi/common/SelectOptionsControl.java
  4. 1
      lzbi-module/src/main/resources/mapper/asset/DcBaseAssetInfoMapper.xml

2
lzbi-admin/src/main/resources/application-dev.yml

@ -149,7 +149,7 @@ wechat:
goal-server:
# iot平台服务地址
iot: http://10.10.10.56:9010
magic: http://localhost:9012/magic/api
magic: http://10.10.10.56:9012/magic/api
# 外部服务接口
iot-server-api:

86
lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiHisReportController.java

@ -1,16 +1,11 @@
package com.lzbi.bi.controller;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzbi.bi.domain.DcDymicHeaderQueryVo;
import com.lzbi.bi.domain.DcDymicReportHeaderVo;
import com.lzbi.bi.domain.LogTimeThreeQueryParamVo;
@ -18,12 +13,9 @@ import com.lzbi.bi.domain.LogTimescaleHistoryThreeVo;
import com.lzbi.code.service.LogTimesacleHistoryThreeService;
import com.lzbi.common.core.controller.BaseController;
import com.lzbi.common.core.domain.AjaxResult;
import com.lzbi.common.core.page.TableDataInfo;
import com.lzbi.common.utils.DateUtils;
import com.lzbi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -31,7 +23,6 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.*;
import java.util.stream.Collectors;
@ -47,6 +38,7 @@ import java.util.stream.Collectors;
public class DcBusiHisReportController extends BaseController {
@Resource
private LogTimesacleHistoryThreeService logTimesacleHistoryThreeService;
/**
* 分页列表查询
*
@ -78,7 +70,7 @@ public class DcBusiHisReportController extends BaseController {
.sorted(Comparator.comparing(DcDymicReportHeaderVo::getDeviceUUID).thenComparing(DcDymicReportHeaderVo::getParamCode))
.forEach(dcDymicReportHeaderVo -> {
JSONObject ct = new JSONObject();
ct.put("field", "C"+dcDymicReportHeaderVo.getColCode());
ct.put("field", "C" + dcDymicReportHeaderVo.getColCode());
ct.put("title", dcDymicReportHeaderVo.getColName1() + "[" + dcDymicReportHeaderVo.getColName2() + "]");
ct.put("width", 200);
columnMap.put(dcDymicReportHeaderVo.getColCode(), dcDymicReportHeaderVo.getParamCode());
@ -95,7 +87,7 @@ public class DcBusiHisReportController extends BaseController {
.forEach(tVo -> {
String ck = tVo.getDeviceUuid() + "_" + tVo.getParamCode();
if (StringUtils.isNotNull(columnMap.get(ck))) {
jdata.put("C"+ck, tVo.getParamValueNum());
jdata.put("C" + ck, tVo.getParamValueNum());
}
});
@ -140,7 +132,7 @@ public class DcBusiHisReportController extends BaseController {
.sorted(Comparator.comparing(DcDymicReportHeaderVo::getDeviceUUID).thenComparing(DcDymicReportHeaderVo::getParamCode))
.forEach(dcDymicReportHeaderVo -> {
JSONObject ct = new JSONObject();
ct.put("deviceName", "C"+dcDymicReportHeaderVo.getColCode());
ct.put("deviceName", "C" + dcDymicReportHeaderVo.getColCode());
ct.put("paramName", dcDymicReportHeaderVo.getColName1() + "[" + dcDymicReportHeaderVo.getColName2() + "]");
columnMap.put(dcDymicReportHeaderVo.getColCode(), ct);
@ -157,7 +149,7 @@ public class DcBusiHisReportController extends BaseController {
data2.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(entry -> {
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getParamCode)).forEach(vo -> {
JSONObject jsonObject = columnMap.get(vo.getDeviceUuid() + "_" + vo.getParamCode());
if(StringUtils.isNotNull(jsonObject)){
if (StringUtils.isNotNull(jsonObject)) {
jsonObject.put(vo.getTimestampKey().toString(), vo.getParamValueNum());
}
tableDatas.add(jsonObject);
@ -169,38 +161,41 @@ public class DcBusiHisReportController extends BaseController {
return AjaxResult.success(dataInfo);
}
}
private String validatorator(LogTimeThreeQueryParamVo queryVo) {
if (StringUtils.isNull(queryVo.getBeginTime())||StringUtils.isEmpty(queryVo.getBeginTime())) {
if (StringUtils.isNull(queryVo.getBeginTime()) || StringUtils.isEmpty(queryVo.getBeginTime())) {
return "查询失败,开始时间不能为空!";
}
if (StringUtils.isNull(queryVo.getEndTime())||StringUtils.isEmpty(queryVo.getEndTime())) {
if (StringUtils.isNull(queryVo.getEndTime()) || StringUtils.isEmpty(queryVo.getEndTime())) {
return "查询失败,结束时间不能为空!";
}
if (StringUtils.isNull(queryVo.getQueryParamClass())||StringUtils.isEmpty(queryVo.getQueryParamClass())) {
if (StringUtils.isNull(queryVo.getQueryParamClass()) || StringUtils.isEmpty(queryVo.getQueryParamClass())) {
return "查询失败,参数类型不能为空!";
}
return null;
}
///按时间 设备+参数 形成数据--时间分组
private List<Map<String, Object>> getMapList(List<LogTimescaleHistoryThreeVo> list, List<DcDymicReportHeaderVo> dcDymicReportHeaderVos) {
Map<String, List<LogTimescaleHistoryThreeVo>> collect = list.stream().collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimeStampString));
return collect.entrySet().stream().sorted(Map.Entry.comparingByKey()).map(entry -> {
Map<String, Object> map = new LinkedHashMap<>();
map.put("统计时间",entry.getKey());
map.put("统计时间", entry.getKey());
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getDeviceUuid).thenComparing(LogTimescaleHistoryThreeVo::getParamCode)).forEach(vo -> {
String key=vo.getDeviceUuid() + "_" + vo.getParamCode();
String key = vo.getDeviceUuid() + "_" + vo.getParamCode();
Optional<DcDymicReportHeaderVo> first = dcDymicReportHeaderVos.stream().filter(vos -> vos.getColCode().equals(key)).findFirst();
if(first.isPresent()){
if (first.isPresent()) {
//map.put(first.get().getColName1(), first.get().getColName2());
map.put(first.get().getColName1()+'.'+first.get().getColName2(), vo.getParamValueNum());
map.put(first.get().getColName1() + '.' + first.get().getColName2(), vo.getParamValueNum());
}
});
return map;
}).collect(Collectors.toList());
}
/// 设备+参数 形成数据--设备-参数分组
private List<Map<String, Object>> getMapListDevice(List<LogTimescaleHistoryThreeVo> list,List<DcDymicReportHeaderVo> dcDymicReportHeaderVos) {
Map<String, List<LogTimescaleHistoryThreeVo>> collect = list.stream().collect(Collectors.groupingBy(item->item.getDeviceUuid()+"_"+item.getParamCode()));
private List<Map<String, Object>> getMapListDevice(List<LogTimescaleHistoryThreeVo> list, List<DcDymicReportHeaderVo> dcDymicReportHeaderVos) {
Map<String, List<LogTimescaleHistoryThreeVo>> collect = list.stream().collect(Collectors.groupingBy(item -> item.getDeviceUuid() + "_" + item.getParamCode()));
List<Map<String, Object>> collect1 = collect.entrySet().stream().map(entry -> {
Map<String, Object> map = new LinkedHashMap<>();
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getTimestampKey).thenComparing(LogTimescaleHistoryThreeVo::getParamCode)).forEach(vo -> {
@ -221,22 +216,24 @@ public class DcBusiHisReportController extends BaseController {
* "生产设备参数统计明细表导出功能
*/
@ApiOperation("生产设备参数统计明细表导出功能--时间纵向")
@PostMapping ("/export")
@PostMapping("/export")
public void export(HttpServletResponse response, LogTimeThreeQueryParamVo queryVo) throws IOException {
List<Map<String, Object>> mapList=getExcellData(queryVo,2);
toExcel(response,mapList);
List<Map<String, Object>> mapList = getExcellData(queryVo, 2);
toExcel(response, mapList);
}
@ApiOperation("生产设备参数统计明细表导出功能-时间横向")
@PostMapping("/export2")
public void export2(HttpServletResponse response, LogTimeThreeQueryParamVo queryVo) throws IOException {
List<Map<String, Object>> mapList=getExcellData(queryVo,1);
List<Map<String, Object>> mapList = getExcellData(queryVo, 1);
// 通过工具类创建writer,默认创建xls格式
toExcel(response,mapList);
toExcel(response, mapList);
}
//获取excel数据 1 excel设备参数为列模式 2 excel时间为列模式 3 浏览器设备参数为列模式
//注意 excel有最大列数显示255 ,超出列数会报错
private List<Map<String, Object>> getExcellData(LogTimeThreeQueryParamVo queryVo,int type){
private List<Map<String, Object>> getExcellData(LogTimeThreeQueryParamVo queryVo, int type) {
// 设置头部数据,
DcDymicHeaderQueryVo dcDymicHeaderQueryVo = new DcDymicHeaderQueryVo();
dcDymicHeaderQueryVo.setParamModels(queryVo.getQueryParamClass());
@ -245,39 +242,44 @@ public class DcBusiHisReportController extends BaseController {
List<String> collect = dcDymicReportHeaderVos.stream().map(DcDymicReportHeaderVo::getParamCode).collect(Collectors.toList());
queryVo.setQueryParamCodes(collect);
List<LogTimescaleHistoryThreeVo> list = logTimesacleHistoryThreeService.selectDetailByQuery(queryVo);
if(type==1){
return getMapListDevice(list,dcDymicReportHeaderVos);
}else {
return getMapList(list,dcDymicReportHeaderVos);
if (type == 1) {
return getMapListDevice(list, dcDymicReportHeaderVos);
} else {
return getMapList(list, dcDymicReportHeaderVos);
}
}
private void toExcel(HttpServletResponse response,List<Map<String, Object>> mapList) throws IOException {
String fileName ="report"+DateUtil.now() + ".xls";
private void toExcel(HttpServletResponse response, List<Map<String, Object>> mapList) {
// String fileName = "report" + DateUtil.now() + ".xls";
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
ExcelWriter writer = ExcelUtil.getWriter();
ExcelWriter writer = ExcelUtil.getWriter(true);
writer.write(mapList, true);
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
//response.setHeader("Content-Disposition", "attachment;filename="+fileName);
ServletOutputStream out = response.getOutputStream();
// response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
try (ServletOutputStream out = response.getOutputStream()) {
writer.flush(out, true);
// 关闭writer,释放内存
writer.close();
//此处记得关闭输出Servlet流
IoUtil.close(out);
} catch (IOException e) {
e.printStackTrace();
}
}
@ApiOperation("获取生产IOT系统参数模版列表")
@GetMapping("/getParamClass")
public AjaxResult getParamClass(){
return AjaxResult.success(logTimesacleHistoryThreeService.selectParamModels()) ;
public AjaxResult getParamClass() {
return AjaxResult.success(logTimesacleHistoryThreeService.selectParamModels());
}
@ApiOperation("获取生产IOT系统设备列表")
@GetMapping("/getDevicie/{orgCode}")
public AjaxResult selectDevices(@PathVariable Long orgCode) {
if(orgCode==0){
return AjaxResult.success(logTimesacleHistoryThreeService.selectDevices(null)) ;
if (orgCode == 0) {
return AjaxResult.success(logTimesacleHistoryThreeService.selectDevices(null));
}
return AjaxResult.success(logTimesacleHistoryThreeService.selectDevices(orgCode)) ;
return AjaxResult.success(logTimesacleHistoryThreeService.selectDevices(orgCode));
}
}

9
lzbi-module/src/main/java/com/lzbi/common/SelectOptionsControl.java

@ -90,6 +90,11 @@ public class SelectOptionsControl extends BaseController {
List<SysDept> lsysDept = sysDeptService.selectOrg(depId);
return AjaxResult.success(sysDeptService.buildDeptTreeSelect(lsysDept)) ;
}
@ApiOperation("获取所有的部门的树形结构")
@GetMapping("/dept/tree")
public AjaxResult getAllDeptTreeList(){
return AjaxResult.success(sysDeptService.selectDeptTreeList(new SysDept())) ;
}
//
@ApiOperation("获取生产专业的列表")
@GetMapping("/special/list")
@ -105,8 +110,8 @@ public class SelectOptionsControl extends BaseController {
{
DcBaseAssetInfo dcBaseAssetInfo=new DcBaseAssetInfo();
//dcBaseAssetInfo.setAssetClass(assetQueryParams.getFieldCode());
dcBaseAssetInfo.setComanyId(Optional.ofNullable(assetQueryParams.getCompanyID()).orElse(0L));
dcBaseAssetInfo.setDeptId(Optional.ofNullable(assetQueryParams.getOrgID()).orElse(0L));
dcBaseAssetInfo.setComanyId(assetQueryParams.getCompanyID());
dcBaseAssetInfo.setOrgId(assetQueryParams.getOrgID());
return AjaxResult.success(dcBaseAssetInfoService.selectDcBaseAssetInfoList(dcBaseAssetInfo));
}
//根据条件获取统计单元指标列表

1
lzbi-module/src/main/resources/mapper/asset/DcBaseAssetInfoMapper.xml

@ -51,6 +51,7 @@
<if test="assetLevel != null and assetLevel != ''"> and asset_level = #{assetLevel}</if>
<if test="assetType != null and assetType != ''"> and asset_type = #{assetType}</if>
<if test="comanyId != null ">and comany_id = #{comanyId}</if>
<if test="orgId != null ">and org_id = #{orgId}</if>
<if test="deptId != null ">and dept_id = #{deptId}</if>
</where>
ORDER BY COALESCE(updated_time, created_time) DESC

Loading…
Cancel
Save