Browse Source

1、生产数据导出功能完善

develop
bobol 6 months ago
parent
commit
ae39045eed
  1. 3
      lzbi-admin/src/main/resources/application-dev.yml
  2. 3
      lzbi-admin/src/main/resources/application-test.yml
  3. 2
      lzbi-admin/src/main/resources/application.yml
  4. 22
      lzbi-common/src/main/java/com/lzbi/common/constant/BizConstants.java
  5. 119
      lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiHisReportController.java
  6. 5
      lzbi-module/src/main/java/com/lzbi/bi/domain/ExportWeatherReq.java
  7. 13
      lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimeThreeQueryParamVo.java
  8. 3
      lzbi-module/src/main/java/com/lzbi/bi/mapper/LogTimeScaleThreeMapper.java
  9. 238
      lzbi-module/src/main/java/com/lzbi/code/service/LogTimesacleHistoryThreeService.java
  10. 143
      lzbi-module/src/main/java/com/lzbi/report/controller/DcBusiReportRecordController.java
  11. 73
      lzbi-module/src/main/java/com/lzbi/report/domain/DcBusiReportRecord.java
  12. 63
      lzbi-module/src/main/java/com/lzbi/report/mapper/DcBusiReportRecordMapper.java
  13. 146
      lzbi-module/src/main/java/com/lzbi/report/service/DcBusiReportRecordService.java
  14. 13
      lzbi-module/src/main/resources/mapper/LogTimeScaleThreeMapper.xml
  15. 118
      lzbi-module/src/main/resources/mapper/report/DcBusiReportRecordMapper.xml
  16. 5
      lzbi-system/src/main/java/com/lzbi/system/mapper/SysDeptMapper.java
  17. 17
      lzbi-system/src/main/java/com/lzbi/system/service/impl/SysDeptServiceImpl.java
  18. 4
      lzbi-system/src/main/resources/mapper/system/SysDeptMapper.xml

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

@ -201,3 +201,6 @@ patrol-server:
# 消息推送 # 消息推送
message-send: message-send:
url: ${goal-server.message-server}/message/send url: ${goal-server.message-server}/message/send
# 报表文件路径
reportFilePath: D:/ruoyi/report

3
lzbi-admin/src/main/resources/application-test.yml

@ -199,3 +199,6 @@ patrol-server:
# 消息推送 # 消息推送
message-send: message-send:
url: ${goal-server.message-server}/message/send url: ${goal-server.message-server}/message/send
# 报表文件路径
reportFilePath: /data/luenmeilz_bi_backend/report

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

@ -60,7 +60,7 @@ spring:
# 国际化资源文件路径 # 国际化资源文件路径
basename: i18n/messages basename: i18n/messages
profiles: profiles:
active: test active: dev
# 文件上传 # 文件上传
servlet: servlet:
multipart: multipart:

22
lzbi-common/src/main/java/com/lzbi/common/constant/BizConstants.java

@ -5,6 +5,28 @@ package com.lzbi.common.constant;
*/ */
public interface BizConstants { public interface BizConstants {
/**
* 报表记录状态
*/
interface ReportRecordStatus {
/**
* 准备数据
*/
String PREPARE_DATA = "0";
/**
* 未下载
*/
String NOT_DOWNLOAD = "1";
/**
* 已下载
*/
String DOWNLOADED = "2";
/**
* 导出失败
*/
String ERROR = "3";
}
/** /**
* 巡检告警类型 * 巡检告警类型
*/ */

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

@ -13,11 +13,14 @@ import com.lzbi.code.domain.WeatherReportVO;
import com.lzbi.code.service.LogTimesacleHistoryThreeService; import com.lzbi.code.service.LogTimesacleHistoryThreeService;
import com.lzbi.common.core.controller.BaseController; import com.lzbi.common.core.controller.BaseController;
import com.lzbi.common.core.domain.AjaxResult; import com.lzbi.common.core.domain.AjaxResult;
import com.lzbi.common.core.domain.model.LoginUser;
import com.lzbi.common.utils.SecurityUtils;
import com.lzbi.common.utils.StringUtils; import com.lzbi.common.utils.StringUtils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -51,7 +54,7 @@ public class DcBusiHisReportController extends BaseController {
* @return 分页数据 * @return 分页数据
*/ */
@PostMapping("/listReport") @PostMapping("/listReport")
public AjaxResult list(@RequestBody LogTimeThreeQueryParamVo queryVo) { public AjaxResult list(@Validated @RequestBody LogTimeThreeQueryParamVo queryVo) {
String error = validatorator(queryVo); String error = validatorator(queryVo);
if (error != null) { if (error != null) {
return AjaxResult.error(error); return AjaxResult.error(error);
@ -181,108 +184,25 @@ public class DcBusiHisReportController extends BaseController {
return null; 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());
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getDeviceUuid).thenComparing(LogTimescaleHistoryThreeVo::getParamCode)).forEach(vo -> {
String key = vo.getDeviceUuid() + "_" + vo.getParamCode();
Optional<DcDymicReportHeaderVo> first = dcDymicReportHeaderVos.stream().filter(vos -> vos.getColCode().equals(key)).findFirst();
if (first.isPresent()) {
//map.put(first.get().getColName1(), first.get().getColName2());
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()));
List<Map<String, Object>> collect1 = collect.entrySet().stream().map(entry -> {
Map<String, Object> map = new LinkedHashMap<>();
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getTimeStampString).thenComparing(LogTimescaleHistoryThreeVo::getParamCode)).forEach(vo -> {
String key = vo.getDeviceUuid() + "_" + vo.getParamCode();
Optional<DcDymicReportHeaderVo> first = dcDymicReportHeaderVos.stream().filter(vos -> vos.getColCode().equals(key)).findFirst();
if (first.isPresent()) {
map.put("设备名称", first.get().getColName1());
map.put("参数名称", first.get().getColName2());
map.put(vo.getTimeStampString(), vo.getParamValueNum());
}
});
return map;
}).collect(Collectors.toList());
return collect1;
}
/** /**
* "生产设备参数统计明细表导出功能 * "生产设备参数统计明细表导出功能
*/ */
@ApiOperation("生产设备参数统计明细表导出功能--时间纵向") @ApiOperation("生产设备参数统计明细表导出功能--时间纵向")
@PreAuthorize("@ss.hasPermi('report:iot:export')") @PreAuthorize("@ss.hasPermi('report:iot:export')")
@PostMapping("/export") @PostMapping("/export")
public void export(HttpServletResponse response, LogTimeThreeQueryParamVo queryVo) throws IOException { public AjaxResult export(@Validated @RequestBody LogTimeThreeQueryParamVo queryVo) {
List<Map<String, Object>> mapList = getExcellData(queryVo, 2); LoginUser loginUser = SecurityUtils.getLoginUser();
toExcel(response, mapList); logTimesacleHistoryThreeService.getExcellData(queryVo, 2, loginUser);
return AjaxResult.success();
} }
@ApiOperation("生产设备参数统计明细表导出功能-时间横向") @ApiOperation("生产设备参数统计明细表导出功能-时间横向")
@PreAuthorize("@ss.hasPermi('report:iot:export')") @PreAuthorize("@ss.hasPermi('report:iot:export')")
@PostMapping("/export2") @PostMapping("/export2")
public void export2(HttpServletResponse response, LogTimeThreeQueryParamVo queryVo) throws IOException { public AjaxResult export2(@Validated @RequestBody LogTimeThreeQueryParamVo queryVo) {
List<Map<String, Object>> mapList = getExcellData(queryVo, 1); LoginUser loginUser = SecurityUtils.getLoginUser();
// 通过工具类创建writer,默认创建xls格式 logTimesacleHistoryThreeService.getExcellData(queryVo, 1, loginUser);
toExcel(response, mapList); return AjaxResult.success();
}
//获取excel数据 1 excel设备参数为列模式 2 excel时间为列模式 3 浏览器设备参数为列模式
//注意 excel有最大列数显示255 ,超出列数会报错
private List<Map<String, Object>> getExcellData(LogTimeThreeQueryParamVo queryVo, int type) {
// 设置头部数据
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime startTime = LocalDateTime.parse(queryVo.getBeginTime(), dateTimeFormatter);
LocalDateTime endTime = LocalDateTime.parse(queryVo.getEndTime(), dateTimeFormatter);
LocalDate startDate = startTime.toLocalDate();
LocalDate endDate = endTime.toLocalDate();
if (endDate.isBefore(startDate)) {
throw new RuntimeException("结束日期不能小于开始日期");
}
if (startDate.plusMonths(1L).isBefore(endDate)) {
throw new RuntimeException("日期间隔不能大于1个月");
}
DcDymicHeaderQueryVo dcDymicHeaderQueryVo = new DcDymicHeaderQueryVo();
dcDymicHeaderQueryVo.setParamModels(queryVo.getQueryParamClass());
dcDymicHeaderQueryVo.setDeviceUuids(queryVo.getDeviceUuids());
List<DcDymicReportHeaderVo> dcDymicReportHeaderVos = logTimesacleHistoryThreeService.selectHeaderInfo(dcDymicHeaderQueryVo);
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);
}
}
private void toExcel(HttpServletResponse response, List<Map<String, Object>> mapList) throws IOException {
String fileName = "report" + DateUtil.now() + ".xlsx";
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
//ExcelWriter writer = ExcelUtil.getWriter(true);
BigExcelWriter writer = ExcelUtil.getBigWriter();
writer.write(mapList, true);
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
//response.setHeader("Content-Disposition", "attachment;filename="+fileName);
ServletOutputStream out = response.getOutputStream();
writer.flush(out, true);
// 关闭writer,释放内存
writer.close();
//此处记得关闭输出Servlet流
IoUtil.close(out);
} }
@ApiOperation("获取生产IOT系统参数模版列表") @ApiOperation("获取生产IOT系统参数模版列表")
@ -306,12 +226,19 @@ public class DcBusiHisReportController extends BaseController {
return AjaxResult.success(logTimesacleHistoryThreeService.selectAreaElementCascaderByParentId(parentId)); return AjaxResult.success(logTimesacleHistoryThreeService.selectAreaElementCascaderByParentId(parentId));
} }
@ApiOperation("天气报表")
@PreAuthorize("@ss.hasPermi('report:iot:export')")
@PostMapping("/queryWeather")
public AjaxResult queryWeather(@Validated @RequestBody ExportWeatherReq exportWeatherReq) {
return AjaxResult.success(logTimesacleHistoryThreeService.getWeatherReport(exportWeatherReq));
}
@ApiOperation("天气报表") @ApiOperation("天气报表")
@PreAuthorize("@ss.hasPermi('report:iot:export')") @PreAuthorize("@ss.hasPermi('report:iot:export')")
@PostMapping("/exportWeather") @PostMapping("/exportWeather")
public void exportWeather(HttpServletResponse response, ExportWeatherReq exportWeatherReq) throws IOException { public AjaxResult exportWeather(@Validated @RequestBody ExportWeatherReq exportWeatherReq) throws IOException {
List<WeatherReportVO> weatherReport = logTimesacleHistoryThreeService.getWeatherReport(exportWeatherReq); LoginUser loginUser = SecurityUtils.getLoginUser();
com.lzbi.common.utils.poi.ExcelUtil<WeatherReportVO> util = new com.lzbi.common.utils.poi.ExcelUtil<WeatherReportVO>(WeatherReportVO.class); logTimesacleHistoryThreeService.exportWeather(exportWeatherReq, loginUser);
util.exportExcel(response, weatherReport, "天气报表"); return AjaxResult.success();
} }
} }

5
lzbi-module/src/main/java/com/lzbi/bi/domain/ExportWeatherReq.java

@ -2,6 +2,8 @@ package com.lzbi.bi.domain;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank;
/** /**
* @ClassName ExportWeatherReq * @ClassName ExportWeatherReq
* @Description 导出天气报表请求参数 * @Description 导出天气报表请求参数
@ -13,13 +15,16 @@ public class ExportWeatherReq {
/** /**
* 省市区 * 省市区
*/ */
@NotBlank(message = "请选择地区")
private String adcode; private String adcode;
/** /**
* 开始时间 * 开始时间
*/ */
@NotBlank(message = "请选择开始时间")
private String beginTime; private String beginTime;
/** /**
* 结束时间 * 结束时间
*/ */
@NotBlank(message = "请选择结束时间")
private String endTime; private String endTime;
} }

13
lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimeThreeQueryParamVo.java

@ -8,6 +8,7 @@ import lombok.NoArgsConstructor;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
@ -31,21 +32,13 @@ public class LogTimeThreeQueryParamVo {
private String endTime; private String endTime;
/** 中台设备UUID */ /** 中台设备UUID */
@ApiModelProperty(name = "中台设备UUID",notes = "") @ApiModelProperty(name = "中台设备UUID",notes = "")
@NotNull(message = "请选择设备") @NotEmpty(message = "请选择设备")
private List<String> deviceUuids ; private List<String> deviceUuids ;
/** 参数列表 */ /** 参数列表 */
@ApiModelProperty(name = "参数列表",notes = "") @ApiModelProperty(name = "参数列表",notes = "")
private List<String> queryParamCodes ; private List<String> queryParamCodes ;
/** 参数模版列表 */ /** 参数模版列表 */
@ApiModelProperty(name = "参数模版列表",notes = "") @ApiModelProperty(name = "参数模版列表",notes = "")
@NotNull(message = "请选择统计参数") @NotEmpty(message = "请选择统计参数")
private List<String> queryParamClass ; private List<String> queryParamClass ;
//private Integer pageNum;
// private Integer pageSize;
public String getBeginTime() {
return this.beginTime+" 00:00:00";
}
public String getEndTime() {
return this.endTime+" 23:59:59";
}
} }

3
lzbi-module/src/main/java/com/lzbi/bi/mapper/LogTimeScaleThreeMapper.java

@ -1,5 +1,6 @@
package com.lzbi.bi.mapper; package com.lzbi.bi.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore; import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lzbi.bi.domain.*; import com.lzbi.bi.domain.*;
@ -10,7 +11,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@DS("workDB")
@InterceptorIgnore(tenantLine = "true") @InterceptorIgnore(tenantLine = "true")
public interface LogTimeScaleThreeMapper extends BaseMapper<LogTimescaleHistoryThreeVo> { public interface LogTimeScaleThreeMapper extends BaseMapper<LogTimescaleHistoryThreeVo> {

238
lzbi-module/src/main/java/com/lzbi/code/service/LogTimesacleHistoryThreeService.java

@ -1,49 +1,261 @@
package com.lzbi.code.service; package com.lzbi.code.service;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.BigExcelWriter;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson2.JSONArray;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzbi.bi.domain.*; import com.lzbi.bi.domain.*;
import com.lzbi.bi.mapper.LogTimeScaleThreeMapper; import com.lzbi.bi.mapper.LogTimeScaleThreeMapper;
import com.lzbi.code.domain.WeatherReportVO; import com.lzbi.code.domain.WeatherReportVO;
import com.lzbi.common.constant.BizConstants;
import com.lzbi.common.core.domain.model.LoginUser;
import com.lzbi.common.utils.SecurityUtils;
import com.lzbi.report.domain.DcBusiReportRecord;
import com.lzbi.report.service.DcBusiReportRecordService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.MapKey; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List; import java.io.FileOutputStream;
import java.util.Map; import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@DS("workDB")
@Slf4j @Slf4j
@Service @Service
public class LogTimesacleHistoryThreeService extends ServiceImpl<LogTimeScaleThreeMapper, LogTimescaleHistoryThreeVo> implements IService<LogTimescaleHistoryThreeVo> { public class LogTimesacleHistoryThreeService extends ServiceImpl<LogTimeScaleThreeMapper, LogTimescaleHistoryThreeVo> implements IService<LogTimescaleHistoryThreeVo> {
@Value("${reportFilePath}")
private String reportFilePath;
@Autowired
private DcBusiReportRecordService dcBusiReportRecordService;
//@DataScopeCommon(deptAlias = "param") //@DataScopeCommon(deptAlias = "param")
//public List<DeviceHistoryResponseVo> selectVo(DeviceHistoryQueryVo queryVo){ //public List<DeviceHistoryResponseVo> selectVo(DeviceHistoryQueryVo queryVo){
// return baseMapper.selectVo(queryVo); // return baseMapper.selectVo(queryVo);
//} //}
public List<LogTimescaleHistoryThreeVo> selectDetailByQuery(LogTimeThreeQueryParamVo queryVo){ public List<LogTimescaleHistoryThreeVo> selectDetailByQuery(LogTimeThreeQueryParamVo queryVo) {
return baseMapper.selectDetailByQuery(queryVo); queryVo.setDeviceUuids(null);
long time1 = System.currentTimeMillis();
List<LogTimescaleHistoryThreeVo> logTimescaleHistoryThreeVos = baseMapper.selectDetailByQuery(queryVo);
long time2 = System.currentTimeMillis();
log.info("查询耗时:{} s", (time2 - time1) / 1000);
return logTimescaleHistoryThreeVos;
}
/**
* 按月份循环查询
*
* @param queryVo
* @return
*/
public List<LogTimescaleHistoryThreeVo> selectDetailByQuery2(LogTimeThreeQueryParamVo queryVo) {
long time1 = System.currentTimeMillis();
queryVo.setDeviceUuids(null);
List<LogTimescaleHistoryThreeVo> list = new ArrayList<>();
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN);
String beginTimeStr = queryVo.getBeginTime();
String endTimeStr = queryVo.getEndTime();
for (LocalDate beginDate = LocalDate.parse(beginTimeStr, dtf), endDate = LocalDate.parse(endTimeStr, dtf);
beginDate.isBefore(endDate);
beginDate = beginDate.plusMonths(1)) {
queryVo.setBeginTime(beginDate.format(dtf));
queryVo.setEndTime(beginDate.plusMonths(1).format(dtf));
List<LogTimescaleHistoryThreeVo> logTimescaleHistoryThreeVos = baseMapper.selectDetailByQuery(queryVo);
if (!CollectionUtils.isEmpty(logTimescaleHistoryThreeVos)) {
list.addAll(logTimescaleHistoryThreeVos);
}
}
long time2 = System.currentTimeMillis();
log.info("查询耗时:{} s", (time2 - time1) / 1000);
return list;
}
//获取excel数据 1 excel设备参数为列模式 2 excel时间为列模式 3 浏览器设备参数为列模式
//注意 excel有最大列数显示255 ,超出列数会报错
@Async
public void getExcellData(LogTimeThreeQueryParamVo queryVo, int type, LoginUser loginUser) {
String fileName = "生产数据统计报表_";
if (type == 1) {
fileName += "设备列格式_";
} else {
fileName += "时间列格式_";
}
fileName += LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
fileName += ".xlsx";
// 新增报表记录
DcBusiReportRecord dcBusiReportRecord = saveReportRecord(fileName, loginUser);
try {
List<Map<String, Object>> excelData;
// 设置头部数据
DcDymicHeaderQueryVo dcDymicHeaderQueryVo = new DcDymicHeaderQueryVo();
dcDymicHeaderQueryVo.setParamModels(queryVo.getQueryParamClass());
dcDymicHeaderQueryVo.setDeviceUuids(queryVo.getDeviceUuids());
List<DcDymicReportHeaderVo> dcDymicReportHeaderVos = this.selectHeaderInfo(dcDymicHeaderQueryVo);
List<String> collect = dcDymicReportHeaderVos.stream().map(DcDymicReportHeaderVo::getParamCode).collect(Collectors.toList());
queryVo.setQueryParamCodes(collect);
List<LogTimescaleHistoryThreeVo> list = this.selectDetailByQuery2(queryVo);
if (type == 1) {
excelData = getMapListDevice(list, dcDymicReportHeaderVos);
} else {
excelData = getMapList(list, dcDymicReportHeaderVos);
}
toExcel(dcBusiReportRecord, excelData);
// 更新报表记录
dcBusiReportRecord.setStatus(BizConstants.ReportRecordStatus.NOT_DOWNLOAD);
dcBusiReportRecordService.updateDcBusiReportRecord(dcBusiReportRecord);
} catch (IOException e) {
log.error("导出数据异常", e);
// 更新报表记录
dcBusiReportRecord.setStatus(BizConstants.ReportRecordStatus.ERROR);
dcBusiReportRecordService.updateDcBusiReportRecord(dcBusiReportRecord);
}
}
/**
* 新增报表记录
*
* @param fileName 文件名称
* @return
*/
private DcBusiReportRecord saveReportRecord(String fileName, LoginUser loginUser) {
DcBusiReportRecord record = new DcBusiReportRecord();
record.setReportName(fileName);
record.setStatus(BizConstants.ReportRecordStatus.PREPARE_DATA);
record.setCreatedTime(new Date());
record.setCreatedBy(loginUser.getUsername());
record.setDeptId(loginUser.getDeptId());
dcBusiReportRecordService.insertDcBusiReportRecord(record);
return record;
}
///按时间 设备+参数 形成数据--时间分组
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());
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getDeviceUuid).thenComparing(LogTimescaleHistoryThreeVo::getParamCode)).forEach(vo -> {
String key = vo.getDeviceUuid() + "_" + vo.getParamCode();
Optional<DcDymicReportHeaderVo> first = dcDymicReportHeaderVos.stream().filter(vos -> vos.getColCode().equals(key)).findFirst();
if (first.isPresent()) {
//map.put(first.get().getColName1(), first.get().getColName2());
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()));
List<Map<String, Object>> collect1 = collect.entrySet().stream().map(entry -> {
Map<String, Object> map = new LinkedHashMap<>();
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getTimeStampString).thenComparing(LogTimescaleHistoryThreeVo::getParamCode)).forEach(vo -> {
String key = vo.getDeviceUuid() + "_" + vo.getParamCode();
Optional<DcDymicReportHeaderVo> first = dcDymicReportHeaderVos.stream().filter(vos -> vos.getColCode().equals(key)).findFirst();
if (first.isPresent()) {
map.put("设备名称", first.get().getColName1());
map.put("参数名称", first.get().getColName2());
map.put(vo.getTimeStampString(), vo.getParamValueNum());
}
});
return map;
}).collect(Collectors.toList());
log.info("collect1:{}", JSONArray.toJSONString(collect1));
return collect1;
}
private void toExcel(DcBusiReportRecord dcBusiReportRecord, List<Map<String, Object>> mapList) throws IOException {
Path folder = Paths.get(reportFilePath);
if (!Files.exists(folder)) {
Files.createDirectories(folder);
}
OutputStream out = Files.newOutputStream(Paths.get(dcBusiReportRecord.getUrl()));
BigExcelWriter writer = ExcelUtil.getBigWriter();
writer.write(mapList, true);
writer.flush(out, true);
// 关闭writer,释放内存
writer.close();
//此处记得关闭输出流
IoUtil.close(out);
} }
public List<DcDymicReportHeaderVo> selectHeaderInfo(DcDymicHeaderQueryVo queryVo){
public List<DcDymicReportHeaderVo> selectHeaderInfo(DcDymicHeaderQueryVo queryVo) {
return baseMapper.selectHeaderInfo(queryVo); return baseMapper.selectHeaderInfo(queryVo);
} }
public List<Map<String,String>> selectParamModels(){
public List<Map<String, String>> selectParamModels() {
return baseMapper.selectParamModels(); return baseMapper.selectParamModels();
} }
public List<Map<String,String>> selectDevices(Long orgCode){ public List<Map<String, String>> selectDevices(Long orgCode) {
return baseMapper.selectDevices(orgCode); return baseMapper.selectDevices(orgCode);
} }
public List<ElementCascaderVO> selectAreaElementCascaderByParentId(Integer parentId){ public List<ElementCascaderVO> selectAreaElementCascaderByParentId(Integer parentId) {
return baseMapper.selectAreaElementCascaderByParentId(parentId); return baseMapper.selectAreaElementCascaderByParentId(parentId);
} }
public List<WeatherReportVO> getWeatherReport(ExportWeatherReq exportWeatherReq){ public List<WeatherReportVO> getWeatherReport(ExportWeatherReq exportWeatherReq) {
return baseMapper.getWeatherReport(exportWeatherReq); return baseMapper.getWeatherReport(exportWeatherReq);
} }
@Async
public void exportWeather(ExportWeatherReq exportWeatherReq, LoginUser loginUser) {
String fileName = "天气统计报表_";
fileName += LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
fileName += ".xlsx";
// 新增报表记录
DcBusiReportRecord dcBusiReportRecord = saveReportRecord(fileName, loginUser);
try {
List<WeatherReportVO> weatherReportList = baseMapper.getWeatherReport(exportWeatherReq);
List<Map<String, Object>> excelData;
if (CollectionUtils.isEmpty(weatherReportList)) {
excelData = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
map.put("时间", null);
map.put("地区", null);
map.put("天气", null);
map.put("温度", null);
excelData.add(map);
} else {
excelData = weatherReportList.stream().map(weatherReportVO -> {
Map<String, Object> map = new HashMap<>();
map.put("时间", weatherReportVO.getTimestampString());
map.put("地区", weatherReportVO.getCity());
map.put("天气", weatherReportVO.getWeather());
map.put("温度", weatherReportVO.getTemperature());
return map;
}).collect(Collectors.toList());
}
toExcel(dcBusiReportRecord, excelData);
// 更新报表记录
dcBusiReportRecord.setStatus(BizConstants.ReportRecordStatus.NOT_DOWNLOAD);
dcBusiReportRecordService.updateDcBusiReportRecord(dcBusiReportRecord);
} catch (IOException e) {
log.error("导出数据异常", e);
// 更新报表记录
dcBusiReportRecord.setStatus(BizConstants.ReportRecordStatus.ERROR);
dcBusiReportRecordService.updateDcBusiReportRecord(dcBusiReportRecord);
}
}
} }

143
lzbi-module/src/main/java/com/lzbi/report/controller/DcBusiReportRecordController.java

@ -0,0 +1,143 @@
package com.lzbi.report.controller;
import com.lzbi.bi.domain.ExportWeatherReq;
import com.lzbi.code.domain.WeatherReportVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lzbi.common.annotation.Log;
import com.lzbi.common.core.controller.BaseController;
import com.lzbi.common.core.domain.AjaxResult;
import com.lzbi.common.enums.BusinessType;
import com.lzbi.report.domain. DcBusiReportRecord;
import com.lzbi.report.service.DcBusiReportRecordService;
import com.lzbi.common.utils.poi.ExcelUtil;
import com.lzbi.common.core.page.TableDataInfo;
/**
* 报表记录Controller
*
* @author enbo.li
* @date 2024-05-21
*/
@RestController
@RequestMapping("/report/reportRecord")
public class DcBusiReportRecordController extends BaseController
{
@Autowired
private DcBusiReportRecordService dcBusiReportRecordService;
/**
* 查询报表记录列表
*/
@ApiOperation("查询报表记录列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "DcBusiReportRecord", value = "", dataType = "DcBusiReportRecord", dataTypeClass = DcBusiReportRecord.class),
})
@PreAuthorize("@ss.hasPermi('report:reportRecord:list')")
@GetMapping("/list")
public TableDataInfo list(DcBusiReportRecord DcBusiReportRecord)
{
startPage();
List< DcBusiReportRecord> list = dcBusiReportRecordService.selectDcBusiReportRecordList(DcBusiReportRecord);
return getDataTable(list);
}
/**
* 导出报表记录列表
*/
@ApiOperation("导出报表记录列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "DcBusiReportRecord", value = "", dataType = "DcBusiReportRecord", dataTypeClass = DcBusiReportRecord.class),
})
@PreAuthorize("@ss.hasPermi('report:reportRecord:export')")
@Log(title = "报表记录", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response,DcBusiReportRecord DcBusiReportRecord)
{
List<DcBusiReportRecord> list = dcBusiReportRecordService.selectDcBusiReportRecordList(DcBusiReportRecord);
ExcelUtil<DcBusiReportRecord> util = new ExcelUtil<DcBusiReportRecord>(DcBusiReportRecord.class);
util.exportExcel(response, list, "报表记录数据");
}
/**
* 获取报表记录详细信息
*/
@ApiOperation("获取报表记录详细信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "", dataType = "Long", dataTypeClass = Long.class),
})
@PreAuthorize("@ss.hasPermi('report:reportRecord:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return success(dcBusiReportRecordService.selectDcBusiReportRecordById(id));
}
/**
* 新增报表记录
*/
@ApiOperation("新增报表记录")
@ApiImplicitParams({
@ApiImplicitParam(name = "DcBusiReportRecord", value = "", dataType = "DcBusiReportRecord", dataTypeClass = DcBusiReportRecord.class),
})
@PreAuthorize("@ss.hasPermi('report:reportRecord:add')")
@Log(title = "报表记录", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody DcBusiReportRecord DcBusiReportRecord)
{
return toAjax(dcBusiReportRecordService.insertDcBusiReportRecord(DcBusiReportRecord));
}
/**
* 修改报表记录
*/
@ApiOperation("修改报表记录")
@ApiImplicitParams({
@ApiImplicitParam(name = "DcBusiReportRecord", value = "", dataType = "DcBusiReportRecord", dataTypeClass = DcBusiReportRecord.class),
})
@PreAuthorize("@ss.hasPermi('report:reportRecord:edit')")
@Log(title = "报表记录", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody DcBusiReportRecord DcBusiReportRecord)
{
return toAjax(dcBusiReportRecordService.updateDcBusiReportRecord(DcBusiReportRecord));
}
/**
* 删除报表记录
*/
@ApiOperation("删除报表记录")
@ApiImplicitParams({
@ApiImplicitParam(name = "ids", value = "", dataType = "Long", dataTypeClass =Long.class),
})
@PreAuthorize("@ss.hasPermi('report:reportRecord:remove')")
@Log(title = "报表记录", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(dcBusiReportRecordService.deleteDcBusiReportRecordByIds(ids));
}
@ApiOperation("天气报表")
@PreAuthorize("@ss.hasPermi('report:reportRecord:download')")
@PostMapping("/download/{id}")
public void downloadFile(HttpServletResponse response, @PathVariable("id") Long id) throws IOException {
dcBusiReportRecordService.downloadFile(response, id);
}
}

73
lzbi-module/src/main/java/com/lzbi/report/domain/DcBusiReportRecord.java

@ -0,0 +1,73 @@
package com.lzbi.report.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.lzbi.common.annotation.Excel;
import com.lzbi.module.base.BaseModuleEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* 报表记录对象 dc_busi_report_record
*
* @author enbo.li
* @date 2024-05-21
*/
@Data
@Accessors(chain = true)
public class DcBusiReportRecord extends BaseModuleEntity
{
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(type = IdType.AUTO)
private Long id;
/** 报表名称 */
@Excel(name = "报表名称")
@ApiModelProperty(name = "报表名称",notes = "reportName")
private String reportName;
/** 文件路径 */
@Excel(name = "文件路径")
@ApiModelProperty(name = "文件路径",notes = "url")
private String url;
/** 状态 0准备数据 1未下载 2已下载 */
@Excel(name = "状态 0准备数据 1未下载 2已下载")
@ApiModelProperty(name = "状态 0准备数据 1未下载 2已下载",notes = "status")
private String status;
/** 部门ID */
@Excel(name = "部门ID")
@ApiModelProperty(name = "部门ID",notes = "deptId")
private Long deptId;
/** 备注 */
@Excel(name = "备注")
@ApiModelProperty(name = "备注",notes = "remark")
private String remark;
/** 部门名称 */
@TableField(exist = false)
private String deptName;
/** 用户姓名 */
@TableField(exist = false)
private String nickName;
/**
* 创建时间
*/
@ApiModelProperty(name = "创建时间", notes = "")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createdTime;
}

63
lzbi-module/src/main/java/com/lzbi/report/mapper/DcBusiReportRecordMapper.java

@ -0,0 +1,63 @@
package com.lzbi.report.mapper;
import java.util.List;
import com.lzbi.report.domain.DcBusiReportRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* 报表记录Mapper接口
*
* @author enbo.li
* @date 2024-05-21
*/
public interface DcBusiReportRecordMapper extends BaseMapper<DcBusiReportRecord>
{
/**
* 查询报表记录
*
* @param id 报表记录主键
* @return 报表记录
*/
public DcBusiReportRecord selectDcBusiReportRecordById(Long id);
/**
* 查询报表记录列表
*
* @param dcBusiReportRecord 报表记录
* @return 报表记录集合
*/
public List<DcBusiReportRecord> selectDcBusiReportRecordList(DcBusiReportRecord dcBusiReportRecord);
/**
* 新增报表记录
*
* @param dcBusiReportRecord 报表记录
* @return 结果
*/
public int insertDcBusiReportRecord(DcBusiReportRecord dcBusiReportRecord);
/**
* 修改报表记录
*
* @param dcBusiReportRecord 报表记录
* @return 结果
*/
public int updateDcBusiReportRecord(DcBusiReportRecord dcBusiReportRecord);
/**
* 删除报表记录
*
* @param id 报表记录主键
* @return 结果
*/
public int deleteDcBusiReportRecordById(Long id);
/**
* 批量删除报表记录
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteDcBusiReportRecordByIds(Long[] ids);
}

146
lzbi-module/src/main/java/com/lzbi/report/service/DcBusiReportRecordService.java

@ -0,0 +1,146 @@
package com.lzbi.report.service;
import java.io.*;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.lzbi.common.constant.BizConstants;
import org.apache.commons.compress.utils.IOUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.lzbi.report.domain.DcBusiReportRecord;
import com.lzbi.report.mapper.DcBusiReportRecordMapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletResponse;
/**
* 报表记录Service业务层处理
*
* @author enbo.li
* @date 2024-05-21
*/
@Service
public class DcBusiReportRecordService extends ServiceImpl<DcBusiReportRecordMapper, DcBusiReportRecord> implements IService<DcBusiReportRecord>
{
// 雪花算法
private static final Snowflake snowflake = IdUtil.getSnowflake(1, 3);
@Value("${reportFilePath}")
private String reportFilePath;
/**
* 查询报表记录
*
* @param id 报表记录主键
* @return 报表记录
*/
public DcBusiReportRecord selectDcBusiReportRecordById(Long id)
{
return baseMapper.selectDcBusiReportRecordById(id);
}
/**
* 查询报表记录列表
*
* @param dcBusiReportRecord 报表记录
* @return 报表记录
*/
public List<DcBusiReportRecord> selectDcBusiReportRecordList(DcBusiReportRecord dcBusiReportRecord)
{
return baseMapper.selectDcBusiReportRecordList(dcBusiReportRecord);
}
/**
* 新增报表记录
*
* @param dcBusiReportRecord 报表记录
* @return 结果
*/
public int insertDcBusiReportRecord(DcBusiReportRecord dcBusiReportRecord)
{
String url = reportFilePath + "/" + snowflake.nextId();
dcBusiReportRecord.setUrl(url);
return baseMapper.insert(dcBusiReportRecord);
}
/**
* 修改报表记录
*
* @param dcBusiReportRecord 报表记录
* @return 结果
*/
public int updateDcBusiReportRecord(DcBusiReportRecord dcBusiReportRecord)
{
return baseMapper.updateDcBusiReportRecord(dcBusiReportRecord);
}
/**
* 批量删除报表记录
*
* @param ids 需要删除的报表记录主键
* @return 结果
*/
@Transactional(rollbackFor = Exception.class)
public int deleteDcBusiReportRecordByIds(Long[] ids)
{
List<DcBusiReportRecord> dcBusiReportRecords = baseMapper.selectBatchIds(Arrays.asList(ids));
if (!CollectionUtils.isEmpty(dcBusiReportRecords)) {
dcBusiReportRecords.forEach(reportRecord -> {
String url = reportRecord.getUrl();
File file = new File(url);
if (file.exists()) {
file.delete();
}
});
}
return baseMapper.deleteDcBusiReportRecordByIds(ids);
}
/**
* 删除报表记录信息
*
* @param id 报表记录主键
* @return 结果
*/
@Transactional(rollbackFor = Exception.class)
public int deleteDcBusiReportRecordById(Long id)
{
DcBusiReportRecord reportRecord = selectDcBusiReportRecordById(id);
String url = reportRecord.getUrl();
File file = new File(url);
if (file.exists()) {
file.delete();
}
return baseMapper.deleteDcBusiReportRecordById(id);
}
public void downloadFile(HttpServletResponse response, Long id) {
DcBusiReportRecord reportRecord = selectDcBusiReportRecordById(id);
String url = reportRecord.getUrl();
File file = new File(url);
if (!file.exists()) {
return;
}
response.setContentType("application/octet-stream");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition", "attachment;fileName=" + file.getName());
try (InputStream inputStream = Files.newInputStream(file.toPath())) {
IOUtils.copy(inputStream, response.getOutputStream());
} catch (IOException e) {
throw new RuntimeException(e);
}
// 更新状态
reportRecord.setStatus(BizConstants.ReportRecordStatus.DOWNLOADED);
updateDcBusiReportRecord(reportRecord);
}
}

13
lzbi-module/src/main/resources/mapper/LogTimeScaleThreeMapper.xml

@ -41,9 +41,8 @@
param_value_str, param_value_str,
log_srctag, log_srctag,
log_srctype from dc_base_log_history_level3 log_srctype from dc_base_log_history_level3
where timestamp_key BETWEEN to_timestamp(#{beginTime},'yyyy-MM-dd hh24:mi:ss') where
and to_timestamp(#{endTime},'yyyy-MM-dd hh24:mi:ss') param_type='double'
and param_type='double'
and param_code in and param_code in
<foreach collection="queryParamCodes" item="code" open="(" separator="," close=")"> <foreach collection="queryParamCodes" item="code" open="(" separator="," close=")">
#{code} #{code}
@ -55,7 +54,9 @@
#{uuid} #{uuid}
</foreach> </foreach>
</if> </if>
order by timestamp_key desc and timestamp_key &gt;= to_timestamp(#{beginTime},'yyyy-MM-dd')
and timestamp_key &lt; to_timestamp(#{endTime},'yyyy-MM-dd')
order by timestamp_key asc
</select> </select>
<select id="selectHeaderInfo" parameterType="com.lzbi.bi.domain.DcDymicHeaderQueryVo" resultMap="headerQuery"> <select id="selectHeaderInfo" parameterType="com.lzbi.bi.domain.DcDymicHeaderQueryVo" resultMap="headerQuery">
select a.device_name as colName1, select a.device_name as colName1,
@ -127,8 +128,8 @@
MAX(temperature) as temperature MAX(temperature) as temperature
FROM "dc_busi_real_weather_hours" FROM "dc_busi_real_weather_hours"
WHERE adcode = #{adcode} WHERE adcode = #{adcode}
and reporttime BETWEEN to_timestamp(#{beginTime}, 'yyyy-MM-dd hh24:mi:ss') and reporttime &gt;= to_timestamp(#{beginTime},'yyyy-MM-dd')
and to_timestamp(#{endTime}, 'yyyy-MM-dd hh24:mi:ss') and reporttime &lt; to_timestamp(#{endTime},'yyyy-MM-dd')
GROUP BY timestampString GROUP BY timestampString
ORDER BY timestampString ORDER BY timestampString
</select> </select>

118
lzbi-module/src/main/resources/mapper/report/DcBusiReportRecordMapper.xml

@ -0,0 +1,118 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lzbi.report.mapper.DcBusiReportRecordMapper">
<resultMap type="com.lzbi.report.domain.DcBusiReportRecord" id="DcBusiReportRecordResult">
<result property="id" column="id" />
<result property="reportName" column="report_name" />
<result property="url" column="url" />
<result property="status" column="status" />
<result property="deptId" column="dept_id" />
<result property="createdBy" column="created_by" />
<result property="createdTime" column="created_time" />
<result property="updatedBy" column="updated_by" />
<result property="updatedTime" column="updated_time" />
<result property="remark" column="remark" />
<result property="deptName" column="dept_name" />
<result property="nickName" column="nick_name" />
</resultMap>
<sql id="selectDcBusiReportRecordVo">
select id, report_name, url, status, dept_id, created_by, created_time, updated_by, updated_time, remark from dc_busi_report_record
</sql>
<select id="selectDcBusiReportRecordList" parameterType="DcBusiReportRecord" resultMap="DcBusiReportRecordResult">
select
t1.id,
t1.report_name,
t1.url,
t1.status,
t1.dept_id,
t1.created_by,
t1.created_time,
t1.updated_by,
t1.updated_time,
t1.remark,
t2.dept_name,
t3.nick_name
from
dc_busi_report_record t1
left join
sys_dept t2
on
t1.dept_id = t2.dept_id
left join
sys_user t3
on
t1.created_by = t3.user_name
<where>
<if test="status != null and status != ''"> and t1.status = #{status}</if>
<if test="reportName != null and reportName != ''"> and t1.report_name like concat(#{reportName}, '%')</if>
<if test="nickName != null and nickName != ''"> and t3.nick_name like concat(#{nickName}, '%')</if>
</where>
order by
t1.created_time desc
</select>
<select id="selectDcBusiReportRecordById" parameterType="Long" resultMap="DcBusiReportRecordResult">
<include refid="selectDcBusiReportRecordVo"/>
where id = #{id}
</select>
<insert id="insertDcBusiReportRecord" parameterType="DcBusiReportRecord">
insert into dc_busi_report_record
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="reportName != null and reportName != ''">report_name,</if>
<if test="url != null and url != ''">url,</if>
<if test="status != null">status,</if>
<if test="deptId != null">dept_id,</if>
<if test="createdBy != null">created_by,</if>
<if test="createdTime != null">created_time,</if>
<if test="updatedBy != null">updated_by,</if>
<if test="updatedTime != null">updated_time,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="reportName != null and reportName != ''">#{reportName},</if>
<if test="url != null and url != ''">#{url},</if>
<if test="status != null">#{status},</if>
<if test="deptId != null">#{deptId},</if>
<if test="createdBy != null">#{createdBy},</if>
<if test="createdTime != null">#{createdTime},</if>
<if test="updatedBy != null">#{updatedBy},</if>
<if test="updatedTime != null">#{updatedTime},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<update id="updateDcBusiReportRecord" parameterType="DcBusiReportRecord">
update dc_busi_report_record
<trim prefix="SET" suffixOverrides=",">
<if test="reportName != null and reportName != ''">report_name = #{reportName},</if>
<if test="url != null and url != ''">url = #{url},</if>
<if test="status != null">status = #{status},</if>
<if test="deptId != null">dept_id = #{deptId},</if>
<if test="createdBy != null">created_by = #{createdBy},</if>
<if test="createdTime != null">created_time = #{createdTime},</if>
<if test="updatedBy != null">updated_by = #{updatedBy},</if>
<if test="updatedTime != null">updated_time = #{updatedTime},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteDcBusiReportRecordById" parameterType="Long">
delete from dc_busi_report_record where id = #{id}
</delete>
<delete id="deleteDcBusiReportRecordByIds" parameterType="String">
delete from dc_busi_report_record where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

5
lzbi-system/src/main/java/com/lzbi/system/mapper/SysDeptMapper.java

@ -1,7 +1,10 @@
package com.lzbi.system.mapper; package com.lzbi.system.mapper;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Set;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import com.lzbi.common.core.domain.entity.SysDept; import com.lzbi.common.core.domain.entity.SysDept;
@ -123,5 +126,5 @@ public interface SysDeptMapper
List<SysDept> selectDeptListByRoleIds(List<Long> ids); List<SysDept> selectDeptListByRoleIds(List<Long> ids);
List<SysDept> getDeptListByDeptIdList(@Param("deptIdList") List<Long> deptIdList); List<SysDept> selectBatchIds(@Param("ids") Collection<Long> ids);
} }

17
lzbi-system/src/main/java/com/lzbi/system/service/impl/SysDeptServiceImpl.java

@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*; import org.springframework.http.*;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@ -72,7 +73,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
@Override @Override
public List<SysDept> getDeptListByDeptIdList(List<Long> deptIdList) { public List<SysDept> getDeptListByDeptIdList(List<Long> deptIdList) {
return deptMapper.getDeptListByDeptIdList(deptIdList); return deptMapper.selectBatchIds(deptIdList);
} }
/** /**
@ -84,6 +85,20 @@ public class SysDeptServiceImpl implements ISysDeptService {
@Override @Override
public List<TreeSelect> selectDeptTreeList(SysDept dept) { public List<TreeSelect> selectDeptTreeList(SysDept dept) {
List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept); List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
if (CollectionUtils.isEmpty(depts)) {
return new ArrayList<>();
}
String orgType = dept.getOrgType();
if (StringUtils.isNotBlank(orgType)) {
List<String> ancestorsList = depts.stream().map(SysDept::getAncestors).collect(Collectors.toList());
String ancestorsJoinStr = StringUtils.join(ancestorsList, ",");
String[] deptIds = ancestorsJoinStr.split(",");
Set<Long> deptIdSet = Arrays.stream(deptIds).map(Long::valueOf).collect(Collectors.toSet());
List<SysDept> sysDepts = deptMapper.selectBatchIds(deptIdSet);
if (!CollectionUtils.isEmpty(sysDepts)) {
depts.addAll(sysDepts);
}
}
return buildDeptTreeSelect(depts); return buildDeptTreeSelect(depts);
} }

4
lzbi-system/src/main/resources/mapper/system/SysDeptMapper.xml

@ -125,7 +125,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach> </foreach>
order by d.parent_id, d.order_num order by d.parent_id, d.order_num
</select> </select>
<select id="getDeptListByDeptIdList" resultMap="SysDeptResult"> <select id="selectBatchIds" resultMap="SysDeptResult">
select select
dept_id, dept_id,
parent_id, parent_id,
@ -145,7 +145,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
short_name, short_name,
org_type org_type
from sys_dept where dept_id in from sys_dept where dept_id in
<foreach collection="deptIdList" item="deptId" open="(" separator="," close=")"> <foreach collection="ids" item="deptId" open="(" separator="," close=")">
#{deptId} #{deptId}
</foreach> </foreach>
</select> </select>

Loading…
Cancel
Save