bobol
6 months ago
18 changed files with 860 additions and 132 deletions
@ -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); |
||||
|
} |
||||
|
} |
||||
} |
} |
||||
|
@ -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); |
||||
|
} |
||||
|
} |
@ -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; |
||||
|
|
||||
|
} |
@ -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); |
||||
|
} |
@ -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); |
||||
|
} |
||||
|
} |
@ -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> |
Loading…
Reference in new issue