jz.kai преди 2 години
родител
ревизия
77a4fd9024

+ 1 - 0
common/src/main/java/com/jpsoft/excellent/modules/base/dao/IncidentDAO.java

@@ -20,4 +20,5 @@ public interface IncidentDAO {
 	List<Incident> search(Map<String,Object> searchParams,List<Sort> sortList);
 	List<IncidentStepOrgDTO> searchStepOrg(Map<String,Object> searchParams, List<Sort> sortList);
 	List<Incident> findTodayListByWarnTime(String startTime, String endTime);
+	int getCount(String areaId, String isFinished, Boolean isTimeout, String dateStart, String dateEnd);
 }

+ 1 - 0
common/src/main/java/com/jpsoft/excellent/modules/base/service/IncidentService.java

@@ -18,4 +18,5 @@ public interface IncidentService {
 	Page<Incident> pageSearch(Map<String, Object> searchParams,int pageNum,int pageSize,boolean count,List<Sort> sortList);
 	Page<IncidentStepOrgDTO> pageSearchStepOrg(Map<String, Object> searchParams, int pageNum, int pageSize, boolean count, List<Sort> sortList);
 	List<Incident> findTodayListByWarnTime(String startTime, String endTime);
+	int getCount(String areaId, String isFinished, Boolean isTimeout, String dateStart, String dateEnd);
 }

+ 5 - 0
common/src/main/java/com/jpsoft/excellent/modules/base/service/impl/IncidentServiceImpl.java

@@ -84,4 +84,9 @@ public class IncidentServiceImpl implements IncidentService {
 		// TODO Auto-generated method stub
 		return incidentDAO.findTodayListByWarnTime(startTime, endTime);
 	}
+
+	@Override
+	public int getCount(String areaId, String isFinished, Boolean isTimeout, String dateStart, String dateEnd) {
+		return incidentDAO.getCount(areaId, isFinished, isTimeout, dateStart, dateEnd);
+	}
 }

+ 30 - 0
common/src/main/resources/mapper/base/Incident.xml

@@ -285,4 +285,34 @@
 		and ((warn_date_1 >= #{startTime} and warn_date_1 < #{endTime}) or (warn_date_2 >= #{startTime} and warn_date_2 < #{endTime}) or (warn_date_3 >= #{startTime} and warn_date_3 < #{endTime}))
 		]]>
 	</select>
+	<select id="getCount" resultType="int">
+		SELECT COUNT(id_) FROM base_incident
+		WHERE del_flag = 0
+		<if test="areaId != null">
+			AND area_id = #{areaId}
+		</if>
+		<if test="isFinished != null">
+			AND is_finished = #{isFinished}
+		</if>
+		<if test="isTimeout == false">
+			<![CDATA[
+			AND update_time < DATE_ADD(alloted_date,INTERVAL 1 DAY)
+			]]>
+		</if>
+		<if test="isTimeout == true">
+			<![CDATA[
+			AND update_time >= DATE_ADD(alloted_date,INTERVAL 1 DAY)
+			]]>
+		</if>
+		<if test="dateStart != null">
+			<![CDATA[
+			and create_time >= #{dateStart}
+			]]>
+		</if>
+		<if test="dateEnd != null">
+			<![CDATA[
+			and create_time < #{dateEnd}
+			]]>
+		</if>
+	</select>
 </mapper>

+ 184 - 0
web/src/main/java/com/jpsoft/excellent/modules/base/controller/ReportsController.java

@@ -0,0 +1,184 @@
+package com.jpsoft.excellent.modules.base.controller;
+
+import com.github.pagehelper.Page;
+import com.jpsoft.excellent.config.OSSConfig;
+import com.jpsoft.excellent.modules.base.dto.FeedbackOpinionReportDTO;
+import com.jpsoft.excellent.modules.base.entity.Area;
+import com.jpsoft.excellent.modules.base.entity.Incident;
+import com.jpsoft.excellent.modules.base.service.AreaService;
+import com.jpsoft.excellent.modules.base.service.IncidentService;
+import com.jpsoft.excellent.modules.common.dto.MessageResult;
+import com.jpsoft.excellent.modules.common.dto.Sort;
+import com.jpsoft.excellent.modules.common.utils.OSSUtil;
+import com.jpsoft.excellent.modules.common.utils.PojoUtils;
+import com.jpsoft.excellent.modules.sys.entity.DataDictionary;
+import com.jpsoft.excellent.modules.sys.service.DataDictionaryService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+@RestController
+@RequestMapping("/base/reports")
+@Api(description = "报表")
+public class ReportsController {
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private OSSConfig ossConfig;
+    @Autowired
+    private DataDictionaryService dataDictionaryService;
+    @Autowired
+    private IncidentService incidentService;
+
+    @ApiOperation(value="案件区域报表")
+    @RequestMapping(value = "reportArea",method = RequestMethod.POST)
+    public MessageResult reportArea(Date[] reportDate){
+        MessageResult msgResult = new MessageResult<>();
+        List<Map> mapList = new ArrayList<>();
+
+        try{
+            mapList = reportAreaData(reportDate);
+
+            msgResult.setResult(true);
+            msgResult.setData(mapList);
+        }
+        catch(Exception ex){
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="导出案件区域报表")
+    @RequestMapping(value = "reportAreaXls",method = RequestMethod.POST)
+    public String reportAreaXls(Date[] reportDate){
+        String downloadUrl = "";
+
+        //新建文档
+        Workbook workbook = new HSSFWorkbook();
+        Sheet sheet = workbook.createSheet();
+
+        //单元格样式
+        sheet.setDefaultColumnWidth(15);
+        sheet.setDefaultRowHeight((short) 400);
+
+        Font fontTitle = workbook.createFont();
+        fontTitle.setFontName("宋体");
+        fontTitle.setFontHeightInPoints((short) 11);
+        fontTitle.setBold(true);
+
+        CellStyle cellStyleTitle = workbook.createCellStyle();
+        cellStyleTitle.setBorderTop(BorderStyle.THIN);
+        cellStyleTitle.setBorderBottom(BorderStyle.THIN);
+        cellStyleTitle.setBorderLeft(BorderStyle.THIN);
+        cellStyleTitle.setBorderRight(BorderStyle.THIN);
+        cellStyleTitle.setVerticalAlignment(VerticalAlignment.CENTER);
+        cellStyleTitle.setAlignment(HorizontalAlignment.CENTER);
+        cellStyleTitle.setFont(fontTitle);
+
+        Font fontContent = workbook.createFont();
+        fontContent.setFontName("宋体");
+        fontContent.setFontHeightInPoints((short) 11);
+
+        CellStyle cellStyleContent = workbook.createCellStyle();
+        cellStyleContent.setBorderTop(BorderStyle.THIN);
+        cellStyleContent.setBorderBottom(BorderStyle.THIN);
+        cellStyleContent.setBorderLeft(BorderStyle.THIN);
+        cellStyleContent.setBorderRight(BorderStyle.THIN);
+        cellStyleContent.setVerticalAlignment(VerticalAlignment.CENTER);
+        cellStyleContent.setAlignment(HorizontalAlignment.CENTER);
+        cellStyleContent.setFont(fontContent);
+
+        //表头
+        Row rowTitle = sheet.createRow(0);
+        String[] titles = new String[]{"所属区域","总案件数","按时办结数","超期办结数","未办结数"};
+        for (int i=0;i<titles.length;i++) {
+            Cell cell = rowTitle.createCell(i);
+            cell.setCellValue(titles[i]);
+            cell.setCellStyle(cellStyleTitle);
+        }
+
+        //写入数据
+        List<Map> mapList = reportAreaData(reportDate);
+        for(int i=0; i<mapList.size(); i++){
+            Map<String,Object> map = mapList.get(i);
+
+            Row row = sheet.createRow(i+1);
+            row.createCell(0);
+            row.createCell(1);
+            row.createCell(2);
+            row.createCell(3);
+            row.createCell(4);
+
+            row.getCell(0).setCellValue(map.get("areaName").toString());
+            row.getCell(1).setCellValue(map.get("total").toString());
+            row.getCell(2).setCellValue(map.get("noTimeout").toString());
+            row.getCell(3).setCellValue(map.get("timeout").toString());
+            row.getCell(4).setCellValue(map.get("unfinished").toString());
+
+            row.getCell(0).setCellStyle(cellStyleContent);
+            row.getCell(1).setCellStyle(cellStyleContent);
+            row.getCell(2).setCellStyle(cellStyleContent);
+            row.getCell(3).setCellStyle(cellStyleContent);
+            row.getCell(4).setCellStyle(cellStyleContent);
+        }
+
+        ByteArrayOutputStream output = new ByteArrayOutputStream();
+        try {
+            workbook.write(output);
+
+            byte[] buffer = output.toByteArray();
+            ByteArrayInputStream input = new ByteArrayInputStream(buffer);
+
+            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmm");
+            String now = sdf2.format(new Date());
+            String fileName = "案件区域报表.xls";
+            downloadUrl = OSSUtil.upload(ossConfig,"InsuranceReport",fileName,input);
+        }
+        catch (Exception ex){
+            logger.error(ex.getMessage(),ex);
+        }
+
+        return downloadUrl;
+    }
+
+    private List<Map> reportAreaData(Date[] reportDate){
+        List<Map> mapList = new ArrayList<>();
+
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar calendar = new GregorianCalendar();
+        calendar.setTime(reportDate[1]);
+        calendar.add(calendar.DATE,1);
+
+        List<DataDictionary> dataDictionaryList = dataDictionaryService.findByCatalogName("区域");
+        for(DataDictionary dataDictionary : dataDictionaryList){
+            Integer total = incidentService.getCount(dataDictionary.getValue(),null,null,sdf.format(reportDate[0]),sdf.format(calendar.getTime()));
+            Integer noTimeout = incidentService.getCount(dataDictionary.getValue(),"0",false,sdf.format(reportDate[0]),sdf.format(calendar.getTime()));
+            Integer timeout = incidentService.getCount(dataDictionary.getValue(),"0",true,sdf.format(reportDate[0]),sdf.format(calendar.getTime()));
+            Integer unfinished = incidentService.getCount(dataDictionary.getValue(),"1",null,sdf.format(reportDate[0]),sdf.format(calendar.getTime()));
+
+            Map<String,Object> map = new HashMap<>();
+            map.put("areaName",dataDictionary.getName());
+            map.put("total",total);
+            map.put("noTimeout",noTimeout);
+            map.put("timeout",timeout);
+            map.put("unfinished",unfinished);
+
+            mapList.add(map);
+        }
+
+        return mapList;
+    }
+}