123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- package com.sckj.warn.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.sckj.common.core.AjaxResult;
- import com.sckj.common.core.PageResult;
- import com.sckj.common.util.ExcelUtils;
- import com.sckj.common.validate.commons.PageValidate;
- import com.sckj.warn.dto.WarnDTO;
- import com.sckj.warn.entity.TExceptionLog;
- import com.sckj.warn.mapper.TExceptionLogMapper;
- import com.sckj.warn.validate.TExceptionLogCreateValidate;
- import com.sckj.warn.validate.TExceptionLogSearchValidate;
- import com.sckj.warn.validate.TExceptionLogUpdateValidate;
- import com.sckj.warn.vo.TExceptionLogDetailVo;
- import com.sckj.warn.vo.TExceptionLogExportVo;
- import com.sckj.warn.vo.TExceptionLogListedVo;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.springframework.beans.BeanUtils;
- import org.springframework.stereotype.Service;
- import org.springframework.util.Assert;
- import org.springframework.util.CollectionUtils;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletResponse;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.LinkedList;
- import java.util.List;
- /**
- * 异常情况记录实现类
- * @author zhanghao
- */
- @Service
- public class TExceptionLogServiceImpl {
- @Resource
- TExceptionLogMapper tExceptionLogMapper;
- /**
- * 异常情况记录列表
- *
- * @author zhanghao
- * @param pageValidate 分页参数
- * @param searchValidate 搜索参数
- * @return PageResult<TExceptionLogListedVo>
- */
-
- public PageResult<TExceptionLogListedVo> list(PageValidate pageValidate, TExceptionLogSearchValidate searchValidate) {
- Integer page = pageValidate.getPageNo();
- Integer limit = pageValidate.getPageSize();
- QueryWrapper<TExceptionLog> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("del_flag", "1");
- queryWrapper.orderByDesc("id");
- /*数据库时间类型为datetime不可走setSearch()*/
- // if (StringUtils.isNotEmpty(searchValidate.getCreateTimeStart()) && StringUtils.isNotEmpty(searchValidate.getCreateTimeEnd())){
- // queryWrapper.ge("create_time", searchValidate.getCreateTimeStart())
- // .le("create_time", searchValidate.getCreateTimeEnd());
- // }
- //setSearch()时间参数移除
- /*"datetime:createTimeStart-createTimeEnd@create_time:str",
- "datetime:updateTimeStart-updateTimeEnd@update_time:str",*/
- tExceptionLogMapper.setSearch(queryWrapper, searchValidate, new String[]{
- "=:exceptionType@exception_type:int",
- "=:exceptionArea@exception_area:str",
- "=:exceptionLevel@exception_level:str",
- });
- IPage<TExceptionLog> iPage = tExceptionLogMapper.selectPage(new Page<>(page, limit), queryWrapper);
- List<TExceptionLogListedVo> list = new LinkedList<>();
- for(TExceptionLog item : iPage.getRecords()) {
- TExceptionLogListedVo vo = new TExceptionLogListedVo();
- BeanUtils.copyProperties(item, vo);
- vo.setCreateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(item.getCreateTime())); //由于QueryWrapper或IPage的原因导致JsonFormat注解未生效,此处手动转换格式
- list.add(vo);
- }
- return PageResult.iPageHandle(iPage.getTotal(), iPage.getCurrent(), iPage.getSize(), list);
- }
- /**
- * 异常情况记录详情
- *
- * @author zhanghao
- * @param id 主键参数
- * @return TExceptionLog
- */
-
- public TExceptionLogDetailVo detail(Integer id) {
- TExceptionLog model = tExceptionLogMapper.selectOne(
- new QueryWrapper<TExceptionLog>()
- .eq("id", id).eq("del_flag", "1")
- .last("limit 1"));
- Assert.notNull(model, "数据不存在");
- TExceptionLogDetailVo vo = new TExceptionLogDetailVo();
- BeanUtils.copyProperties(model, vo);
- return vo;
- }
- /**
- * 异常情况记录新增
- *
- * @author zhanghao
- * @param createValidate 参数
- */
-
- public void add(TExceptionLogCreateValidate createValidate) {
- TExceptionLog model = new TExceptionLog();
- model.setCreateTime(new Date(System.currentTimeMillis()));//gg
- model.setUpdateTime(new Date(System.currentTimeMillis()));//gg
- model.setExceptionType(createValidate.getExceptionType());
- model.setExceptionLevel(createValidate.getExceptionLevel());
- model.setReportedStatus(createValidate.getReportedStatus());
- model.setBoilerId(createValidate.getBoilerId());
- model.setExceptionDesc(createValidate.getExceptionDesc());
- tExceptionLogMapper.insert(model);
- }
- /**
- * 异常情况记录编辑
- *
- * @author zhanghao
- * @param updateValidate 参数
- */
-
- public void edit(TExceptionLogUpdateValidate updateValidate) {
- TExceptionLog model = tExceptionLogMapper.selectOne(
- new QueryWrapper<TExceptionLog>()
- .eq("id", updateValidate.getId())
- .last("limit 1"));
- Assert.notNull(model, "数据不存在!");
- model.setUpdateTime(new Date(System.currentTimeMillis()));//gg
- tExceptionLogMapper.updateById(model);
- }
- /**
- * 异常情况记录删除
- *
- * @author zhanghao
- * @param id 主键ID
- */
-
- public void del(Integer id) {
- TExceptionLog model = tExceptionLogMapper.selectOne(
- new QueryWrapper<TExceptionLog>()
- .eq("id", id)
- .last("limit 1"));
- Assert.notNull(model, "数据不存在!");
- model.setDelFlag("0");
- tExceptionLogMapper.updateById(model);
- }
-
- public AjaxResult<Object> del_ex(List<Long> ids) {
- List<TExceptionLog> models = tExceptionLogMapper.selectList(
- new QueryWrapper<TExceptionLog>()
- .in("id", ids));
- if (CollectionUtils.isEmpty(models)){
- return AjaxResult.failed("数据不存在");
- }
- TExceptionLog model = new TExceptionLog();
- model.setDelFlag("0");
- tExceptionLogMapper.update(model, new QueryWrapper<TExceptionLog>().in("id", ids));
- return AjaxResult.success();
- }
- /**
- * 异常情况记录导出
- *
- * @author zhanghao
- * @param searchValidate 搜索参数·
- */
- public ByteArrayOutputStream exportTExceptionLog(TExceptionLogSearchValidate searchValidate) {
- Workbook workbook = new XSSFWorkbook();
- Sheet sheet = workbook.createSheet("Persons");
- QueryWrapper<TExceptionLog> queryWrapper = new QueryWrapper<>();
- tExceptionLogMapper.setSearch(queryWrapper, searchValidate, new String[]{
- "=:exceptionType@exception_type:int",
- "=:exceptionArea@exception_area:str",
- "=:exceptionLevel@exception_level:str",
- });
- List<TExceptionLog> tExceptionLogList = tExceptionLogMapper.selectList(new QueryWrapper<TExceptionLog>());
- // 创建标题行
- Row headerRow = sheet.createRow(0);
- String[] columnNames = {"高炉编号", "异常类型", "异常区域", "危害程度", "上报状态", "创建时间"};
- for (int i = 0; i < columnNames.length; i++) {
- Cell cell = headerRow.createCell(i);
- cell.setCellValue(columnNames[i]);
- }
- // 填充数据
- for (int i = 0; i < tExceptionLogList.size(); i++) {
- Row row = sheet.createRow(i + 1);
- TExceptionLog tExceptionLog = tExceptionLogList.get(i);
- row.createCell(0).setCellValue(tExceptionLog.getBoilerId());
- row.createCell(1).setCellValue(tExceptionLog.getExceptionType());
- row.createCell(2).setCellValue(tExceptionLog.getExceptionArea());
- row.createCell(3).setCellValue(tExceptionLog.getExceptionLevel());
- row.createCell(4).setCellValue(tExceptionLog.getReportedStatus().equals("0") ? "未上报" : "已上报");
- row.createCell(5).setCellValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tExceptionLog.getCreateTime()));
- }
- // 将数据写入输出流
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- try {
- workbook.write(outputStream);
- workbook.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return outputStream;
- }
- /***
- * 查询预警统计
- * @return
- */
- public List<WarnDTO> selectWarnStats(){
- return tExceptionLogMapper.selectWarnStats();
- }
- /**
- * 异常统计
- * @param searchValidate
- * @param response
- */
- public void exportExceptionLogList(TExceptionLogSearchValidate searchValidate, HttpServletResponse response){
- List<TExceptionLogExportVo> tExceptionLogExportVos = tExceptionLogMapper.exportExceptionLogList();
- try {
- ExcelUtils.exportExcel(tExceptionLogExportVos, TExceptionLogExportVo.class, "异常统计", "异常统计", response);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- }
|