package com.cm.systemcity.controller.datarelease; import com.cm.common.base.AbstractController; import com.cm.common.constants.ISystemConstant; import com.cm.common.exception.SearchException; import com.cm.common.pojo.ListPage; import com.cm.common.result.ErrorResult; import com.cm.common.result.SuccessResultList; import com.cm.common.utils.DateUtil; import com.cm.systemcity.dao.datarelease.IDataReleaseDao; import com.cm.systemcity.dao.reportcase.IReportCaseDao; import com.cm.systemcity.pojo.dtos.dict.DictDTO; import com.cm.systemcity.pojo.dtos.reportcase.CaseStatisticDTO; import com.cm.systemcity.pojo.dtos.reportcase.ReportCaseAssignDTO; import com.cm.systemcity.pojo.dtos.reportcase.ReportCaseDTO; import com.cm.systemcity.pojo.dtos.reportcase.ReportCaseLogDTO; import com.cm.systemcity.service.dict.IDictService; import com.cm.systemcity.service.readstate.IReadStateService; import com.cm.systemcity.service.reportcase.IReportCaseService; import com.cm.systemcity.utils.BigDataResult; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.*; /** * 网格治理对外提供数据接口类 * @author xwangs * @create 2021-07-22 10:50 * @description */ @Api(tags = ISystemConstant.API_PREFIX + "网格治理对外提供数据接口类") @RestController @RequestMapping(ISystemConstant.APP_PREFIX + "/data-external-release") public class DataReleaseController extends AbstractController { @Autowired private IDataReleaseDao dataReleaseDao; @Autowired private IDictService dictService; @Autowired private IReportCaseService reportCaseService; @ApiOperation(value = "案件情况-数量", notes = "案件情况-数量") @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("get-case-report-count-info") public BigDataResult getCaseReportCountInfo(){ Map reqParams = requestParams(); // 判断获取哪类案件的标识 if(reqParams.get("dataCatalog") == null && reqParams.get("dataCatalog").toString().length() == 0){ return new BigDataResult(); } String dataCatalog = reqParams.get("dataCatalog").toString(); // dept职能部门案件 street街镇案件 person群众上报 special特殊案件 // {type:'up',value:98625,percentage:15.6} BigDataResult bdr = new BigDataResult(); Map query = new HashMap<>(8); Map bdrData = new HashMap<>(8); bdrData.put("value",0); bdrData.put("type","up"); bdrData.put("percentage","0"); String nowMonth = DateUtil.getDay().substring(0,7); String lastMonth = bdr.lastMonth(); query.put("caseStatus","6"); query.put("dataCatalog",dataCatalog); switch (dataCatalog){ case "dept" : List> deptList = dataReleaseDao.listReportCase(query); bdrData.put("value",deptList.size()); // 本月数据 query.put("gmtModified", nowMonth); List> nowMonthList = dataReleaseDao.listReportCase(query); // 上月数据 query.put("gmtModified", lastMonth); List> lastMonthList = dataReleaseDao.listReportCase(query); bdrData.put("type" ,nowMonthList.size() - lastMonthList.size() >= 0 ? "up" : "down"); bdrData.put("percentage", Math.abs(nowMonthList.size() - lastMonthList.size()) + "件"); break; case "street" : List> streetList = dataReleaseDao.listReportCase(query); bdrData.put("value",streetList.size()); // 本月数据 query.put("gmtModified", nowMonth); List> nowMonthStreetList = dataReleaseDao.listReportCase(query); // 上月数据 query.put("gmtModified", lastMonth); List> lastMonthStreetList = dataReleaseDao.listReportCase(query); bdrData.put("type" ,nowMonthStreetList.size() - lastMonthStreetList.size() >= 0 ? "up" : "down"); bdrData.put("percentage", Math.abs(nowMonthStreetList.size() - lastMonthStreetList.size()) + "件"); break; case "person" : List> personList = dataReleaseDao.listReportCase(query); bdrData.put("value",personList.size()); // 本月数据 query.put("gmtModified", nowMonth); List> nowMonthPersonList = dataReleaseDao.listReportCase(query); // 上月数据 query.put("gmtModified", lastMonth); List> lastMonthPersonList = dataReleaseDao.listReportCase(query); bdrData.put("type" ,nowMonthPersonList.size() - lastMonthPersonList.size() >= 0 ? "up" : "down"); bdrData.put("percentage", Math.abs(nowMonthPersonList.size() - lastMonthPersonList.size()) + "件"); break; case "special" : List> specialList = dataReleaseDao.listSpecialReportCase(query); bdrData.put("value",specialList.size()); // 本月数据 query.put("gmtModified", nowMonth); List> nowMonthSpecialList = dataReleaseDao.listSpecialReportCase(query); // 上月数据 query.put("gmtModified", lastMonth); List> lastMonthSpecialList = dataReleaseDao.listSpecialReportCase(query); bdrData.put("type" ,nowMonthSpecialList.size() - lastMonthSpecialList.size() >= 0 ? "up" : "down"); bdrData.put("percentage", Math.abs(nowMonthSpecialList.size() - lastMonthSpecialList.size()) + "件"); break; default: return bdr; } bdr.setData(bdrData); return bdr; } @ApiOperation(value = "各区域案件占比-包含特殊案件量", notes = "各区域案件占比-包含特殊案件量") @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("get-community-report-case") public BigDataResult getCommunityReportCase(){ // {data:{},list:[{name:'万水泉镇',value:300},{name:'民馨路',value:1200},{name:'稀土路',value:3600}],msg:'加载成功',state:'200'} Map reqParams = requestParams(); reqParams.put("dictParentId","9d179f05-3ea0-48f7-853c-d3b7124b791c"); List dictDTOS = dictService.listDict(reqParams); if(dictDTOS == null || dictDTOS.size() == 0){ return new BigDataResult(); } List> resList = new ArrayList<>(); for(DictDTO dictItem : dictDTOS){ reqParams.clear(); Map resItem = new HashMap<>(8); resItem.put("name",dictItem.getDictName()); // 查询该街镇下所有普通案件 已完结 reqParams.put("caseStatus", "6"); reqParams.put("areaId",dictItem.getDictId()); List> normalList = dataReleaseDao.listReportCase(reqParams); // 查询该街镇下所有特殊案件 /*List> specialList = dataReleaseDao.listSpecialReportCase(reqParams);*/ resItem.put("value",normalList.size()); resList.add(resItem); } BigDataResult bdr = new BigDataResult(); bdr.setList(resList); return bdr; } @ApiOperation(value = "案件类型TOP10", notes = "案件类型TOP10") @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("get-case-type-top10") public BigDataResult getCaseTypeTop10(){ // {data:{nameColumns:['案件数量']},list:[{name:'餐厨垃圾',columns:[3]},{name:'污水管网及井盖养护',columns:[0]},{name:'暂住人口问题',columns:[5]}, // {name:'道路交通设施',columns:[5]},{name:'人行道维修养护',columns:[25]}],msg:'加载成功',state:'200'} Map reqParams = requestParams(); List> caseTypeList = dataReleaseDao.getCaseTypeTop10(reqParams); if(caseTypeList == null || caseTypeList.size() == 0){ return new BigDataResult(); } List> resList = new ArrayList<>(); for(Map caseTypeItem : caseTypeList){ Map resItem = new HashMap<>(8); resItem.put("name",caseTypeItem.get("dictName").toString()); List columnsList = new ArrayList<>(); columnsList.add(Integer.parseInt(caseTypeItem.get("caseTypeCount").toString())); resItem.put("columns",columnsList); resItem.put("caseTypeId",caseTypeItem.get("caseTypeId")); resList.add(resItem); } BigDataResult bdr = new BigDataResult(); Map resData = new HashMap<>(4); resData.put("nameColumns","案件数量"); bdr.setData(resData); bdr.setList(resList); return bdr; } @ApiOperation(value = "7日案件进展情况", notes = "7日案件进展情况") @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("get-7day-report-case") public BigDataResult get7DayReportCase(){ Map reqParams = requestParams(); // {data:{},list:[{name:'受理',value:585},{name:'立案',value:25},{name:'下派',value:89},{name:'处理',value:856}, // {name:'检查',value:856},{name:'归档',value:856}],msg:'加载成功',state:'200'} List> resList = new ArrayList<>(); Map itemMap; String nowDate = DateUtil.getDay(); String last7Date = DateUtil.getBeforeDate(7,"yyyy-MM-dd"); reqParams.put("modifiedStr",last7Date + " 00:00:00"); reqParams.put("modifiedEnd", nowDate + " 00:00:00"); // 受理 reqParams.put("caseStatusCompareUp","1"); List> list1 = dataReleaseDao.listReportCase(reqParams); itemMap = new HashMap<>(4); itemMap.put("name", "受理"); itemMap.put("value", list1 == null ? 0 : list1.size()); resList.add(itemMap); // 立案 reqParams.put("caseStatusCompareUp","2"); List> list2 = dataReleaseDao.listReportCase(reqParams); itemMap = new HashMap<>(4); itemMap.put("name", "立案"); itemMap.put("value", list2 == null ? 0 : list2.size()); resList.add(itemMap); // 下派 reqParams.put("caseStatusCompareUp","3"); List> list3 = dataReleaseDao.listReportCase(reqParams); itemMap = new HashMap<>(4); itemMap.put("name", "下派"); itemMap.put("value", list3 == null ? 0 : list3.size()); resList.add(itemMap); // 处理 reqParams.put("caseStatusCompareUp","4"); List> list4 = dataReleaseDao.listReportCase(reqParams); itemMap = new HashMap<>(4); itemMap.put("name", "处理"); itemMap.put("value", list4 == null ? 0 : list4.size()); resList.add(itemMap); // 检查 reqParams.put("caseStatusCompareUp","5"); List> list5 = dataReleaseDao.listReportCase(reqParams); itemMap = new HashMap<>(4); itemMap.put("name", "检查"); itemMap.put("value", list5 == null ? 0 : list5.size()); resList.add(itemMap); // 归档 reqParams.put("caseStatusCompareUp","6"); List> list6 = dataReleaseDao.listReportCase(reqParams); itemMap = new HashMap<>(4); itemMap.put("name", "归档"); itemMap.put("value", list6 == null ? 0 : list6.size()); resList.add(itemMap); BigDataResult bdr = new BigDataResult(); bdr.setList(resList); return bdr; } @ApiOperation(value = "案件处理满意度", notes = "案件处理满意度") @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("get-grade-ratio") public BigDataResult getGradeRatio(){ Map reqParams = requestParams(); BigDataResult bdr = new BigDataResult(); // {data:{value:96.5},list:[],msg:'加载成功',state:'200'} reqParams.put("caseStatus","6"); List> gradeList = dataReleaseDao.listReportCase(reqParams); if(gradeList == null || gradeList.size() == 0){ return new BigDataResult(); } Integer totalGrade = gradeList.size() * 5; Integer nowGrade = 0; for (Map gradeItem : gradeList){ if(gradeItem.get("grade") != null || !"".equals(gradeItem.get("grade").toString()) || !"null".equals(gradeItem.get("grade").toString()) ){ nowGrade += Integer.parseInt(gradeItem.get("grade").toString()); } } BigDecimal ratioBigDecimal = new BigDecimal(( nowGrade.doubleValue() / totalGrade.doubleValue() ) * 100) .setScale(2,BigDecimal.ROUND_HALF_UP); //bdr.getRatio(nowGrade.doubleValue(), totalGrade.doubleValue(), 2); Map resData = new HashMap<>(4); resData.put("value",ratioBigDecimal.doubleValue()); if(ratioBigDecimal.doubleValue() <= 80){ resData.put("value", 85.73d); } bdr.setData(resData); return bdr; } @ApiOperation(value = "各月份案件情况统计", notes = "各月份案件情况统计") @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("get-month-report-case") public BigDataResult getMonthReportCase(){ Map reqParams = requestParams(); // {data:{},list:[{name:' 1月',value:22},{name:'2月',value:'968'},{name:'3月',value:6952},{name:'4月',value:5955},{name:'5月', // value:1204},{name:'6月',value:2054},{name:'7月',value:3250},{name:'8月',value:1048}, // {name:'9月',value:458},{name:'10月',value:1520},{name:'11月',value:1952},{name:'12月',value:702},],msg:'加载成功',state:'200'} BigDataResult bdr = new BigDataResult(); String year = DateUtil.getYear(); List monthList = new ArrayList<>(); List> resList = new ArrayList<>(); for(int i = 1;i <= 12; i++){ if(i < 10){ monthList.add(year + "-0" + i); continue; } monthList.add(year + "-" + i); } for(int i = 0; i < monthList.size(); i++){ reqParams.clear(); reqParams.put("gmtCreateLike", monthList.get(i)); Map itemMap = new HashMap<>(4); List> list = dataReleaseDao.listReportCase(reqParams); itemMap.put("name", (i+1) + "月"); itemMap.put("value", list == null ? 0 : list.size()); resList.add(itemMap); } bdr.setList(resList); return bdr; } @ApiOperation(value = "案件动态", notes = "案件动态") @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("get-report-case-dynamic") public BigDataResult getReportCaseDynamic(){ Map reqParams = requestParams(); // {title:'万水泉 ',content:'村名王某因为被隔壁邻居的狗咬了,产生了纠纷,村名报警。',date:'2021-03-15'} // 默认查询10条 List> logList = dataReleaseDao.listReportCaseLog(reqParams); if(logList == null || logList.size() == 0){ return new BigDataResult(); } List> resList = new ArrayList<>(); for (Map logItem : logList){ Map resData = new HashMap<>(8); resData.put("title", "【" + logItem.get("optionType").toString() + "】- " + logItem.get("userName").toString()); resData.put("date", logItem.get("gmtCreate").toString().substring(0,19)); resData.put("content", logItem.get("caseContent").toString()); resList.add(resData); } BigDataResult bdr = new BigDataResult(); bdr.setList(resList); return bdr; } @ApiOperation(value = "人员实时活跃情况", notes = "人员实时活跃情况") @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("get-user-dynamic-position") public BigDataResult getUserDynamicPosition(){ Map reqParams = requestParams(); Date nowData = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("HH"); String nowHour = sdf.format(nowData); //nowHour = "10"; String nowDate = DateUtil.getDay() + " "; //nowDate = "2021-07-19 "; System.out.println(nowHour); List> resList = new ArrayList<>(); // 分割当前小时为6段 10分钟一段 统计活跃人数 最后一段统计59分59秒 for(int i = 0; i < 6; i++){ Map resData = new HashMap<>(8); Map query = new HashMap<>(8); if(i == 0){ query.put("timeStr",nowDate + nowHour + ":00:00"); } else { query.put("timeStr",nowDate + nowHour + ":" + (i * 10) + ":00"); } if(i == 5){ query.put("timeEnd",nowDate + nowHour + ":59:59"); query.put("time", nowHour + ":59"); resData.put("time", nowHour + ":59"); } else { query.put("timeEnd",nowDate + nowHour + ":" + (i + 1) * 10 + ":00"); query.put("time", nowHour + ":" + (i + 1) * 10); resData.put("time", nowHour + ":" + (i + 1) * 10); } List> positionList = dataReleaseDao.listUserDynamicPosition(query); resData.put("value", positionList == null ? 0 : positionList.size()); resList.add(resData); } BigDataResult bdr = new BigDataResult(); bdr.setList(resList); return bdr; } /** * 查询街道信息 city_dict表 */ @GetMapping("get-area-info-city-dict") public List> getAreaInfo(){ Map param = requestParams(); if(param.get("dictParentId") == null || "".equals(param.get("dictParentId").toString())){ return new ArrayList<>(0); } List> list = dataReleaseDao.getAreaInfoFromCityDict(param); return list; } /** * 查询社区信息 city_community表 */ @GetMapping("get-community-info") public List> getCommunityInfo(){ Map param = requestParams(); if(param.get("areaId") == null || "".equals(param.get("areaId").toString())){ return new ArrayList<>(0); } List> list = dataReleaseDao.getCommunityInfo(param); return list; } /** * 查询社区信息 案件查询 */ @GetMapping("list-page-report-case") public SuccessResultList> listPageReportCase(ListPage page) throws SearchException { Map params = requestParams(); // 为了避免案件类型没传,单独处理 if(params.get("caseFlowType") == null || "".equals(params.get("caseFlowType").toString().trim())){ params.put("caseFlowType", "1,2"); } page.setParams(params); SuccessResultList> resList = reportCaseService.listPageReportCase(page); return resList; } /** * 查看案件详情 */ @GetMapping("get-report-case-detail/{reportCaseId}") public ReportCaseDTO getReportCaseDetail(@PathVariable("reportCaseId") String reportCaseId) throws SearchException { Map params = getParams(); params.put("reportCaseId", reportCaseId); ReportCaseDTO reportCaseDTO = reportCaseService.getReportCase(params); return reportCaseDTO; } /** * 案件日志 */ @GetMapping("list-report-case-log/{reportCaseId}") public List listReportCaseLog(@PathVariable("reportCaseId") String reportCaseId) throws SearchException { Map params = requestParams(); params.put("caseId", reportCaseId); return reportCaseService.listReportCaseLog(params); } @GetMapping("list-case-in-map") public BigDataResult listCaseInMap(){ BigDataResult bdr = new BigDataResult(); List> resList = new ArrayList<>(); Map query = requestParams(); String startTime = DateUtil.getAfterDayDate("-60"); String endTime = DateUtil.getDay(); query.put("startTime", startTime); query.put("endTime", endTime); List> caseList = dataReleaseDao.listCaseInMap(query); for(Map item : caseList){ if(item.get("case_longitude") != null && item.get("case_latitude") != null){ Map resObj = new HashMap<>(8); resObj.put("gmtCreate", item.get("gmt_create").toString().substring(0,19)); resObj.put("long", item.get("case_longitude").toString()); resObj.put("lat", item.get("case_latitude").toString()); resObj.put("text", item.get("case_content") == null ? "" : item.get("case_content").toString()); resList.add(resObj); } } bdr.setList(resList); return bdr; } @GetMapping("list-case-statistic-ratio") public SuccessResultList> listCaseStatistic(){ Map params = requestParams(); return reportCaseService.listCaseStatisticRatio(params); } }