package com.newfiber.api.mobile.service; import com.newfiber.api.core.utils.NumberUtil; import com.newfiber.api.mobile.model.domain.PatrolProblem; import com.newfiber.api.mobile.model.domain.ProblemStatistical; import com.newfiber.api.pc.dao.EventsManage.ComplaintDao; import com.newfiber.api.pc.model.EventsManage.Complaint; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** * Created by Administrator on 2018/12/12. */ @Service("complaintsStatisticsService") public class ComplaintsStatisticsService { @Autowired private ComplaintDao complaintDao; /**根据时间条件和当前用户sid获取本级河流不同类型问题个数*/ public List<ProblemStatistical> problemStatistics(Map<String, Object> map){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { map.put("st",sdf.parse((String)map.get("startTime"))); map.put("et",sdf.parse((String)map.get("endTime"))); //每种问题个数集合 List<ProblemStatistical> list = complaintDao.problemStatisticalInfo(map); //总问题个数 int total = complaintDao.problemTotal(map); if(total != 0){ for(int i=0;i<list.size();i++){ list.get(i).setTotal(total); list.get(i).setPercentage(NumberUtil.getRoundingNum((list.get(i).getNum()/(double)total),4)*100+"%"); } } return list; }catch (Exception e){ e.printStackTrace(); return null; } } /**根据时间条件和当前用户sid获取下级河流不同类型问题个数*/ public List<ProblemStatistical> problenStatisticsSubordinate(Map<String, Object> map){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { map.put("st",sdf.parse((String)map.get("startTime"))); map.put("et",sdf.parse((String)map.get("endTime"))); //每种问题个数集合 List<ProblemStatistical> list = complaintDao.problemStatisticalSubordinate(map); //总问题个数 int total = complaintDao.problemTotalSubordinate(map); if(total != 0){ for(int i=0;i<list.size();i++){ list.get(i).setTotal(total); list.get(i).setPercentage(NumberUtil.getRoundingNum((list.get(i).getNum()/(double)total),4)*100+"%"); } } return list; }catch (Exception e){ e.printStackTrace(); return null; } } /**本级河长巡查事件统计(根据每条河流计数)*/ public Map<String,Object> InspectEvent(Map<String, Object> map){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Map<String,Object> result = new HashMap<>(); try { //巡查事件结案总个数 int totalFinish = 0; map.put("st",sdf.parse((String)map.get("startTime"))); map.put("et",sdf.parse((String)map.get("endTime"))); //巡查问题总数 int total= complaintDao.problemTotal(map); Integer page = (Integer)map.get("page"); Integer rows = (Integer)map.get("rows"); if(page != null && rows != null){ map.put("startPage",(page-1)*rows); map.put("pageSize",rows); } //本级每条河流问题总数 List<ProblemStatistical> list1 = complaintDao.InspectEvent(map); map.put("problemState",6); //本级每条河流结案总数 List<ProblemStatistical> list2 = complaintDao.InspectEvent(map); for(int i=0;i<list1.size();i++){ totalFinish += list2.get(i).getNum(); list2.get(i).setTotal(list1.get(i).getNum()); if(list1.get(i).getNum() >0){ list2.get(i).setPercentage(NumberUtil.getRoundingNum((list2.get(i).getNum()/(double)list1.get(i).getNum()),4)*100+"%"); } } result.put("dataList",list2); result.put("total",total); result.put("totalFinish",totalFinish); result.put("unfinished",total-totalFinish); result.put("finishingRate",total>0?(NumberUtil.getRoundingNum(totalFinish/(double)total,4)*100+"%"):"0.0%"); }catch (Exception e){ e.printStackTrace(); } return result; } /**下级区域巡查事件统计(根据每个区域计数)*/ public Map<String,Object> InspectEventSubordinate(Map<String, Object> map){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Map<String,Object> result = new HashMap<>(); try { //下级区域巡查事件结案总个数 int totalFinish = 0; map.put("st",sdf.parse((String)map.get("startTime"))); map.put("et",sdf.parse((String)map.get("endTime"))); //下级区域巡查问题总数 int total= complaintDao.problemTotalSubordinate(map); Integer page = (Integer)map.get("page"); Integer rows = (Integer)map.get("rows"); if(page != null && rows != null){ map.put("startPage",(page-1)*rows); map.put("pageSize",rows); } //下级每个区域问题总数 List<ProblemStatistical> list1 = complaintDao.InspectEventSubordinate(map); map.put("problemState",2); //下级每个区域结案总数 List<ProblemStatistical> list2 = complaintDao.InspectEventSubordinate(map); for(int i=0;i<list1.size();i++){ totalFinish += list2.get(i).getNum(); list2.get(i).setTotal(list1.get(i).getNum()); if(list1.get(i).getNum() >0){ list2.get(i).setPercentage(NumberUtil.getRoundingNum((list2.get(i).getNum()/(double)list1.get(i).getNum()),4)*100+"%"); } } result.put("dataList",list2); result.put("total",total); result.put("totalFinish",totalFinish); result.put("unfinished",total-totalFinish); result.put("finishingRate",total>0?(NumberUtil.getRoundingNum(totalFinish/(double)total,4)*100+"%"):"0.0%"); }catch (Exception e){ e.printStackTrace(); } return result; } /**查询河流问题列表*/ public List<PatrolProblem> queryListByRiver(Map<String, Object> map){ List<PatrolProblem> result = new ArrayList<>(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { map.put("st",sdf.parse((String)map.get("startTime"))); map.put("et",sdf.parse((String)map.get("endTime"))); result = complaintDao.queryListByRiver(map); }catch (Exception e){ e.printStackTrace(); } return result; } /**查询区域问题统计*/ public List<ProblemStatistical> problemTotalOfArea(Map<String,Object> map) throws Exception{ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); map.put("st",sdf.parse((String)map.get("startTime"))); map.put("et",sdf.parse((String)map.get("endTime"))); //一个区域下每条河流的问题总数 List<ProblemStatistical> pList = complaintDao.problemTotalOfArea(map); //一个区域下每条河流的问题结案数量 map.put("problemState",2); List<ProblemStatistical> finishList = complaintDao.problemTotalOfArea(map); for(int i=0;i<finishList.size();i++){ finishList.get(i).setTotal(pList.get(i).getNum()); if(finishList.get(i).getUserName() == null) finishList.get(i).setUserName("无"); if(pList.get(i).getNum() >0){ finishList.get(i).setPercentage(NumberUtil.getRoundingNum((finishList.get(i).getNum()/(double)pList.get(i).getNum()),4)*100+"%"); } } return finishList; } /** * 根据行政区划编号查询投诉处理列表 * * @param map --行政区划编号,起止时间 * @return */ public List<Complaint> getComplainListByDivisionNo(Map<String,Object> map) throws ParseException{ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); map.put("st",sdf.parse((String)map.get("startTime"))); map.put("et",sdf.parse((String)map.get("endTime"))); //根据行政区划编号查询投诉列表 return complaintDao.selectByDivisionNoNew(map); } /** * 根据河流编号查询投诉处理列表 * * @param map --行政区划编号,起止时间 * @return */ public List<Complaint> getComplainListByRiverNo(Map<String,Object> map) throws ParseException{ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); map.put("st",sdf.parse((String)map.get("startTime"))); map.put("et",sdf.parse((String)map.get("endTime"))); Integer page = map.get("page")!= null?(Integer) map.get("page"):null; Integer rows = map.get("rows")!= null?(Integer) map.get("rows"):null; Integer startRow = null; if(page != null && rows != null){ startRow = (page-1)*rows; } map.put("startRow",startRow); map.put("rows",rows); //根据行政区划编号查询投诉列表 return complaintDao.selectByRiverNo(map); } }