|  | @@ -7,18 +7,31 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
	
		
			
				|  |  |  import com.ozs.common.core.controller.BaseController;
 | 
	
		
			
				|  |  |  import com.ozs.common.core.domain.AjaxResult;
 | 
	
		
			
				|  |  | +import com.ozs.common.core.domain.entity.SysDept;
 | 
	
		
			
				|  |  |  import com.ozs.common.utils.AppendUtils;
 | 
	
		
			
				|  |  | +import com.ozs.common.utils.StringUtils;
 | 
	
		
			
				|  |  |  import com.ozs.service.entity.BaseCameraManagement;
 | 
	
		
			
				|  |  |  import com.ozs.service.entity.BaseRailwayManagement;
 | 
	
		
			
				|  |  |  import com.ozs.service.entity.MsgAlarm;
 | 
	
		
			
				|  |  |  import com.ozs.service.entity.MsgAlarmFrequency;
 | 
	
		
			
				|  |  | +import com.ozs.service.entity.vo.AlarmStatisticResVo;
 | 
	
		
			
				|  |  | +import com.ozs.service.entity.vo.AlarmStatisticVo;
 | 
	
		
			
				|  |  |  import com.ozs.service.entity.vo.MsgAlarmResp;
 | 
	
		
			
				|  |  |  import com.ozs.service.entity.vo.MsgAlarmVo;
 | 
	
		
			
				|  |  | +import com.ozs.service.mapper.MsgAlarmMapper;
 | 
	
		
			
				|  |  |  import com.ozs.service.service.BaseCameraManagementService;
 | 
	
		
			
				|  |  |  import com.ozs.service.service.BaseRailwayManagementService;
 | 
	
		
			
				|  |  |  import com.ozs.service.service.MsgAlarmFrequencyService;
 | 
	
		
			
				|  |  |  import com.ozs.service.service.MsgAlarmService;
 | 
	
		
			
				|  |  | +import io.swagger.annotations.ApiImplicitParam;
 | 
	
		
			
				|  |  | +import io.swagger.annotations.ApiImplicitParams;
 | 
	
		
			
				|  |  |  import io.swagger.annotations.ApiOperation;
 | 
	
		
			
				|  |  | +import org.apache.poi.hssf.usermodel.HSSFCell;
 | 
	
		
			
				|  |  | +import org.apache.poi.hssf.usermodel.HSSFRow;
 | 
	
		
			
				|  |  | +import org.apache.poi.hssf.usermodel.HSSFSheet;
 | 
	
		
			
				|  |  | +import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 | 
	
		
			
				|  |  | +import org.apache.poi.ss.usermodel.*;
 | 
	
		
			
				|  |  | +import org.apache.poi.ss.util.CellRangeAddress;
 | 
	
		
			
				|  |  |  import org.springframework.beans.BeanUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.util.ObjectUtils;
 | 
	
	
		
			
				|  | @@ -31,6 +44,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
 | 
	
		
			
				|  |  |  import org.springframework.web.bind.annotation.RestController;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import javax.annotation.Resource;
 | 
	
		
			
				|  |  | +import javax.servlet.http.HttpServletRequest;
 | 
	
		
			
				|  |  | +import javax.servlet.http.HttpServletResponse;
 | 
	
		
			
				|  |  | +import java.io.OutputStream;
 | 
	
		
			
				|  |  | +import java.net.URLEncoder;
 | 
	
		
			
				|  |  |  import java.util.ArrayList;
 | 
	
		
			
				|  |  |  import java.util.Date;
 | 
	
		
			
				|  |  |  import java.util.List;
 | 
	
	
		
			
				|  | @@ -50,6 +67,8 @@ public class MsgAlarmController extends BaseController {
 | 
	
		
			
				|  |  |      @Resource
 | 
	
		
			
				|  |  |      MsgAlarmService msgAlarmService;
 | 
	
		
			
				|  |  |      @Resource
 | 
	
		
			
				|  |  | +    MsgAlarmMapper msgAlarmMapper;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  |      MsgAlarmFrequencyService msgAlarmFrequencyService;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      BaseCameraManagementService baseCameraManagementService;
 | 
	
	
		
			
				|  | @@ -208,5 +227,149 @@ public class MsgAlarmController extends BaseController {
 | 
	
		
			
				|  |  |          List<MsgAlarm> list = msgAlarmService.list(wrapper);
 | 
	
		
			
				|  |  |          return AjaxResult.success(list);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * web数据统计
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param alarmStatisticResVo
 | 
	
		
			
				|  |  | +     * @return
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    @PostMapping("/dataStatistic")
 | 
	
		
			
				|  |  | +    @ApiOperation(value = "web数据统计")
 | 
	
		
			
				|  |  | +    @ApiImplicitParams(value = {
 | 
	
		
			
				|  |  | +            @ApiImplicitParam(paramType = "query", name = "railwayCode", value = "线路编码"),
 | 
	
		
			
				|  |  | +            @ApiImplicitParam(paramType = "query", name = "startMonth", value = "起始月份"),
 | 
	
		
			
				|  |  | +            @ApiImplicitParam(paramType = "query", name = "endMonth", value = "结束月份"),
 | 
	
		
			
				|  |  | +            @ApiImplicitParam(paramType = "query", name = "alarmType", value = "灾害类型"),
 | 
	
		
			
				|  |  | +    })
 | 
	
		
			
				|  |  | +    public AjaxResult dataStatistic(@RequestBody AlarmStatisticResVo alarmStatisticResVo) {
 | 
	
		
			
				|  |  | +        Integer pageNum = alarmStatisticResVo.getPageNum().intValue();
 | 
	
		
			
				|  |  | +        Integer pageSize = alarmStatisticResVo.getPageSize().intValue();
 | 
	
		
			
				|  |  | +        IPage<AlarmStatisticVo> page = msgAlarmService.list(alarmStatisticResVo.getRailwayCode(), alarmStatisticResVo.getStartMonth(),
 | 
	
		
			
				|  |  | +                alarmStatisticResVo.getEndMonth(), alarmStatisticResVo.getAlarmType(), pageNum, pageSize);
 | 
	
		
			
				|  |  | +        return AjaxResult.success(page);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * web数据统计 数据导出
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param
 | 
	
		
			
				|  |  | +     * @return
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    @PostMapping("/exportDataStatistic")
 | 
	
		
			
				|  |  | +    @ApiOperation(value = "web数据统计")
 | 
	
		
			
				|  |  | +    public void exportDataStatistic(HttpServletRequest request, HttpServletResponse response, @RequestBody AlarmStatisticResVo alarmStatisticResVo) {
 | 
	
		
			
				|  |  | +        //创建Excel文件
 | 
	
		
			
				|  |  | +        Workbook wb = new HSSFWorkbook();
 | 
	
		
			
				|  |  | +        //生成sheet
 | 
	
		
			
				|  |  | +        Sheet sheet = wb.createSheet("报警数据详情");
 | 
	
		
			
				|  |  | +        //创建行
 | 
	
		
			
				|  |  | +        Row row = null;
 | 
	
		
			
				|  |  | +        //创建列
 | 
	
		
			
				|  |  | +        Cell cell = null;
 | 
	
		
			
				|  |  | +        //创建表头单元格样式
 | 
	
		
			
				|  |  | +        CellStyle cs_header = wb.createCellStyle();
 | 
	
		
			
				|  |  | +        //设置字体样式
 | 
	
		
			
				|  |  | +        Font boldFont = wb.createFont();
 | 
	
		
			
				|  |  | +        //设置文字类型
 | 
	
		
			
				|  |  | +        boldFont.setFontName("宋体");
 | 
	
		
			
				|  |  | +        //设置加粗
 | 
	
		
			
				|  |  | +        boldFont.setBold(true);
 | 
	
		
			
				|  |  | +        //设置文字大小
 | 
	
		
			
				|  |  | +        boldFont.setFontHeightInPoints((short) 16);
 | 
	
		
			
				|  |  | +        //应用设置的字体
 | 
	
		
			
				|  |  | +        cs_header.setFont(boldFont);
 | 
	
		
			
				|  |  | +        //设置边框下、左、右、上
 | 
	
		
			
				|  |  | +        cs_header.setBorderBottom(BorderStyle.THIN);
 | 
	
		
			
				|  |  | +        cs_header.setBorderLeft(BorderStyle.THIN);
 | 
	
		
			
				|  |  | +        cs_header.setBorderRight(BorderStyle.THIN);
 | 
	
		
			
				|  |  | +        cs_header.setBorderTop(BorderStyle.THIN);
 | 
	
		
			
				|  |  | +        //水平居中
 | 
	
		
			
				|  |  | +        cs_header.setAlignment(HorizontalAlignment.CENTER);
 | 
	
		
			
				|  |  | +        //垂直居中
 | 
	
		
			
				|  |  | +        cs_header.setVerticalAlignment(VerticalAlignment.CENTER);
 | 
	
		
			
				|  |  | +        //前景填充色
 | 
	
		
			
				|  |  | +        cs_header.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
 | 
	
		
			
				|  |  | +        //设置前景填充样式
 | 
	
		
			
				|  |  | +        cs_header.setFillPattern(FillPatternType.SOLID_FOREGROUND);
 | 
	
		
			
				|  |  | +        //设置标题
 | 
	
		
			
				|  |  | +        row = sheet.createRow(0);
 | 
	
		
			
				|  |  | +        //设置单元格行高
 | 
	
		
			
				|  |  | +        row.setHeightInPoints(24);
 | 
	
		
			
				|  |  | +        //设置标题
 | 
	
		
			
				|  |  | +        String[] headers = new String[]{
 | 
	
		
			
				|  |  | +                "线路", "时间", "行别", "报警类型", "里程位置", "里程起始范围km", "里程结束范围km"
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +        //逐个设置标题样式
 | 
	
		
			
				|  |  | +        for (int i = 0; i < headers.length; i++) {
 | 
	
		
			
				|  |  | +            //创建单元格
 | 
	
		
			
				|  |  | +            cell = row.createCell(i);
 | 
	
		
			
				|  |  | +            //设置单元格内容
 | 
	
		
			
				|  |  | +            cell.setCellValue(headers[i]);
 | 
	
		
			
				|  |  | +            //设置单元格样式
 | 
	
		
			
				|  |  | +            cell.setCellStyle(cs_header);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //创建文本单元格样式
 | 
	
		
			
				|  |  | +        CellStyle cs_text = wb.createCellStyle();
 | 
	
		
			
				|  |  | +        //创建文字设置
 | 
	
		
			
				|  |  | +        Font textFont = wb.createFont();
 | 
	
		
			
				|  |  | +        //设置文字类型
 | 
	
		
			
				|  |  | +        textFont.setFontName("Consolas");
 | 
	
		
			
				|  |  | +        //设置文字大小
 | 
	
		
			
				|  |  | +        textFont.setFontHeightInPoints((short) 10);
 | 
	
		
			
				|  |  | +        //应用设置
 | 
	
		
			
				|  |  | +        cs_text.setFont(textFont);
 | 
	
		
			
				|  |  | +        //设置边框
 | 
	
		
			
				|  |  | +        cs_text.setBorderBottom(BorderStyle.THIN);
 | 
	
		
			
				|  |  | +        cs_text.setBorderLeft(BorderStyle.THIN);
 | 
	
		
			
				|  |  | +        cs_text.setBorderRight(BorderStyle.THIN);
 | 
	
		
			
				|  |  | +        cs_text.setBorderTop(BorderStyle.THIN);
 | 
	
		
			
				|  |  | +        //水平居中
 | 
	
		
			
				|  |  | +        cs_text.setAlignment(HorizontalAlignment.CENTER);
 | 
	
		
			
				|  |  | +        //垂直居中
 | 
	
		
			
				|  |  | +        cs_text.setVerticalAlignment(VerticalAlignment.CENTER);
 | 
	
		
			
				|  |  | +        //调取数据
 | 
	
		
			
				|  |  | +        List<AlarmStatisticVo> list = msgAlarmMapper.list(alarmStatisticResVo.getRailwayCode(), alarmStatisticResVo.getStartMonth(),
 | 
	
		
			
				|  |  | +                alarmStatisticResVo.getEndMonth(), alarmStatisticResVo.getAlarmType());
 | 
	
		
			
				|  |  | +        //记录总共多少列(由于接口查询出来的实体类集合,所以不好循环,使用)
 | 
	
		
			
				|  |  | +        Integer cellSum = 0;
 | 
	
		
			
				|  |  | +        //将数据写入表格
 | 
	
		
			
				|  |  | +        for (int i = 0; i < list.size(); i++) {
 | 
	
		
			
				|  |  | +            //将实体类集合转成string数组,通过‘,’,获取总共多少列
 | 
	
		
			
				|  |  | +            String[] split = list.get(i).toString().split(",");
 | 
	
		
			
				|  |  | +            cellSum = split.length;
 | 
	
		
			
				|  |  | +            //创建行,由于0行是标题,所以+1
 | 
	
		
			
				|  |  | +            row = sheet.createRow(i + 1);
 | 
	
		
			
				|  |  | +            //实体类集合不太好循环,所以逐一设置,如果是其他则可使用for循环
 | 
	
		
			
				|  |  | +            AlarmStatisticVo wpa = (AlarmStatisticVo) list.get(i);
 | 
	
		
			
				|  |  | +            //row.createCell(0).setCellValue(.get!=null?wpa.getType():'1');
 | 
	
		
			
				|  |  | +            //为每一个单元格设置样式
 | 
	
		
			
				|  |  | +            for (int j = 0; j < cellSum; j++) {
 | 
	
		
			
				|  |  | +                row.getCell(j).setCellStyle(cs_text);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //设置单元格宽度自适应
 | 
	
		
			
				|  |  | +        for (int i = 0; i <= cellSum; i++) {
 | 
	
		
			
				|  |  | +            sheet.autoSizeColumn((short) i, true); //自动调整列宽
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //设置中文文件名称
 | 
	
		
			
				|  |  | +        String fileName = "POIExcel下载测试";//URLEncoder.encode("POIExcel下载测试","UTF-8");
 | 
	
		
			
				|  |  | +        //浏览器默认服务器传过去的是html,不是excel文件
 | 
	
		
			
				|  |  | +        //设置响应类型:传输内容是流,并支持中文
 | 
	
		
			
				|  |  | +        response.setContentType("application/octet-stream;charset=UTF-8");
 | 
	
		
			
				|  |  | +        //设置响应头信息header,下载时以文件附件下载
 | 
	
		
			
				|  |  | +        response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
 | 
	
		
			
				|  |  | +        //输出流对象
 | 
	
		
			
				|  |  | +        OutputStream os;
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            os = response.getOutputStream();
 | 
	
		
			
				|  |  | +            //强制刷新
 | 
	
		
			
				|  |  | +            os.flush();
 | 
	
		
			
				|  |  | +            os.close();
 | 
	
		
			
				|  |  | +            wb.close();
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            e.printStackTrace();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 |