package cn.com.lzt.sign.service.impl; import cn.com.lzt.sign.entity.TBDecision; import cn.com.lzt.sign.service.TBDecisionService; import cn.com.lzt.sysmsg.service.SysMsgServiceI; import com.daju.mix.dto.ArchivesDTO; import com.daju.mix.dto.DecisionDTO; import org.apache.commons.lang.StringUtils; import org.jeecgframework.core.common.service.impl.CommonServiceImpl; import org.jeecgframework.core.constant.Globals; import org.jeecgframework.web.system.service.SystemService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; import javax.transaction.Transactional; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @Service("tBDecisionService") @Transactional public class TBDecisionServiceImpl extends CommonServiceImpl implements TBDecisionService { // add-刘梦祥-2022年8月5日14:31:50(签报业务添加系统消息提示) @Autowired private SysMsgServiceI sysMsgService; @Resource SystemService systemService; public boolean timerTaskTBDecision() throws ParseException { SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); Calendar calendar = Calendar.getInstance(); /* HOUR_OF_DAY 指示一天中的小时 */ calendar.setTime(date); calendar.add(Calendar.HOUR_OF_DAY, -1); Date date1 = calendar.getTime(); String dateStart = sdf1.format(date1); String dateEnd = sdf1.format(date); //公厕人流量异常(十分钟内进出差多余50的) String sql_rl = "SELECT\n" + "\tREPLACE (uuid(), '-', '') uuid,\n" + "\ttptr.`code`,\n" + "\ttptr.in_num,\n" + "\ttptr.out_num,\n" + "\ttptr.update_time,\n" + "\ttbap.manager_id,\n" + "\ttbap.`name`\n" + "FROM\n" + "\tt_public_toilet_ridership tptr\n" + "LEFT JOIN t_b_archives_place tbap ON tbap.id = tptr.`code`\n" + "WHERE\n" + "\ttptr.update_time > '"+dateStart+"'\n" + "AND tptr.update_time < '"+dateEnd+"'\n" + "ORDER BY\n" + "\ttptr.update_time DESC;"; try { List departList = systemService.findListbySql(sql_rl); // add-刘梦祥-2022年11月9日10:54:11(暂存每个公厕的客流数据) Map> toiletCodeMap = new HashMap<>(); for (Object[] objects : departList) { if(objects[1] != null){ if(toiletCodeMap.containsKey(objects[1].toString())){ toiletCodeMap.get(objects[1].toString()).add(objects); }else{ List objects1 = new ArrayList<>(); objects1.add(objects); toiletCodeMap.put(objects[1].toString(),objects1); } } } List collectList = new ArrayList<>(); // 遍历处理每个公厕的客流数据 for (String toiletCode:toiletCodeMap.keySet()){ List objects = toiletCodeMap.get(toiletCode); // 由于要做相减操作,所以至少客流数据要大于1 if(objects.size()>1){ for (int i = 0; i < objects.size() -1 ; i++) { int inNum1 = Integer.parseInt(objects.get(i)[2].toString()); int outNum1 = Integer.parseInt(objects.get(i)[3].toString()); int inNum2 = Integer.parseInt(objects.get(i + 1)[2].toString()); int outNum2 = Integer.parseInt(objects.get(i + 1)[3].toString()); // 测试要求一个小时内的客流差大于300时发出报警 if(Math.abs((inNum1 - inNum2) - (outNum1 - outNum2)) > 50){ TBDecision sta = new TBDecision(); sta.setId(objects.get(i)[0].toString()); sta.setDecisionCode("decision001"); sta.setDecisionCont("公厕人流量异常"); sta.setDecisionBrace(objects.get(0)[6].toString() + "公厕" + dateStart + "人流量过多,请保洁员到现场清理。"); sta.setDecisionContType("保洁作业"); sta.setDecisionType("公厕辅助决策"); sta.setDecisionUserId(objects.get(0)[5].toString()); sta.setDecisionDate(date); collectList.add(sta); } } } } for(int i=0;i出现异常请注意处理:"+e.getMessage()); } //公厕环境异常 String sql_hj = "SELECT replace(uuid(),'-','') id,IF(ttoghgd.TYPE='1','decision002','decision003'),IF(ttoghgd.TYPE='1','公厕环境异常','垃圾厢房环境异常'),\n" + " CONCAT( '在',update_time, '的时间点',\n" + " IF(ttoghgd.NH3>5,'氨气指数异常,',''),\n" + " IF(ttoghgd.H2S>5,'硫化氢指数异常,',''),\n" + " IF(ttoghgd.NO2>5,'二氧化氮指数异常,',''),\n" + " IF(ttoghgd.SO2>5,'二氧化硫指数异常,',''),\n" + " IF(ttoghgd.PM25>25,'PM2.5指数异常,',''),\n" + " IF(ttoghgd.CO2>700,'二氧化碳指数异常,',''),\n" + " IF(ttoghgd.temperature>50,'温度指数异常,',''),\n" + " IF(ttoghgd.humidity>100,'湿度指数异常,',''), '请安排工作人员及时检查。'),IF(ttoghgd.TYPE='1','保洁作业','清运作业'),IF(ttoghgd.TYPE='1','公厕辅助决策','垃圾厢房辅助决策') , \n" + " tbap.manager_id userid, \n" + " tbap.`name` toiletName \n" + " FROM t_toilet_or_garbage_house_gas_detection ttoghgd LEFT JOIN t_b_archives_place tbap ON tbap.id = ttoghgd.`code` where (ttoghgd.NH3 >5 or ttoghgd.H2S >5 OR ttoghgd.NO2>5 OR ttoghgd.SO2>5 OR ttoghgd.PM25>25 OR ttoghgd.CO2>700 OR ttoghgd.temperature >50 OR ttoghgd.humidity>100 )\n" + " and ttoghgd.update_time>'"+dateStart+"' and ttoghgd.update_time<'"+dateEnd+"' "; try { List departList = systemService.findListbySql(sql_hj); List collectList = departList.stream().map(e -> { TBDecision sta = new TBDecision(); if(e[0]!=null){ sta.setId(e[0].toString()); } if(e[1]!=null){ sta.setDecisionCode(e[1].toString()); } if(e[2]!=null){ sta.setDecisionCont(e[2].toString()); } if(e[3]!=null && e[7] != null){ sta.setDecisionBrace(e[7] + "公厕" + e[3]); } if(e[4]!=null){ sta.setDecisionContType(e[4].toString()); } if(e[5]!=null){ sta.setDecisionType(e[5].toString()); } if(e[6]!=null){ sta.setDecisionUserId(e[6].toString()); } sta.setDecisionDate(date); return sta; }).collect(Collectors.toList()); for(int i=0;i出现异常请注意处理:"+e.getMessage()); } //公厕能耗or耗材异常 String sql_nh = " SELECT replace(uuid(),'-','') id,'decision004','公厕能耗或耗材异常',\n" + " CONCAT( '在',tbth.create_date, '的时间点',IF(tbth.water_consumption>10,'用水量异常,',''),\n" + " IF(tbth.electricity_consumption>10,'用电量异常,',''),\n" + " IF(tbth.liquid_soap>10,'洗手液用量异常,',''),\n" + " IF(tbth.disinfectant>10,'消毒液用量异常,',''),\n" + " IF(tbth.tissue>10,'纸巾用量异常,',''),'请安排工作人员及时检查。'),'保洁作业','公厕辅助决策' , \n" + " tbaa.manage_man_id userid, \n" + " tbaa.`name` toiletName \n" + " FROM t_b_toilet_history tbth left join t_b_archives_area tbaa on tbaa.id = tbth.toilet_id \n" + " where tbth.create_date>'"+dateStart+"' and tbth.create_date<'"+dateEnd+"' and tbth.type = '2'\n" + " and ( tbth.water_consumption>10 or tbth.electricity_consumption>10 or tbth.liquid_soap>10 or tbth.disinfectant>10 or tbth.tissue>10)\n"; try { List departList = systemService.findListbySql(sql_nh); List collectList = departList.stream().map(e -> { TBDecision sta = new TBDecision(); if(e[0]!=null){ sta.setId(e[0].toString()); } if(e[1]!=null){ sta.setDecisionCode(e[1].toString()); } if(e[2]!=null){ sta.setDecisionCont(e[2].toString()); } if(e[3]!=null && e[7] != null){ sta.setDecisionBrace(e[7] + "公厕" + e[3]); } if(e[4]!=null){ sta.setDecisionContType(e[4].toString()); } if(e[5]!=null){ sta.setDecisionType(e[5].toString()); } if(e[6]!=null){ sta.setDecisionUserId(e[6].toString()); } sta.setDecisionDate(date); return sta; }).collect(Collectors.toList()); for(int i=0;i出现异常请注意处理:"+e.getMessage()); } return true; } @Override public List getInspectorInfos(String scheduleType,String startDate,String endDate) { // 待修改 String sql = "SELECT id,concat(decision_cont,decision_brace),DATE_FORMAT(decision_date, '%Y-%m-%d') FROM t_b_decision where decision_cont_type = '"+scheduleType+"' "; // add-2022年12月5日17:11:32-刘梦祥(经确认辅助决策添加时间过滤条件) if(StringUtils.isNotEmpty(startDate) || StringUtils.isNotEmpty(endDate)){ if(StringUtils.isNotEmpty(startDate)){ sql += " and decision_date > '"+startDate+"'"; } if(StringUtils.isNotEmpty(endDate)){ sql += " and decision_date < '"+endDate+"'"; } }else{ sql += " and DATE_FORMAT(decision_date, '%Y-%m-%d') = CURDATE();"; } List list = systemService.findListbySql(sql); List collectList = list.stream().map(e -> { DecisionDTO sta = new DecisionDTO(); if(e[0]!=null){ sta.setId(e[0].toString()); } if(e[1]!=null){ sta.setAdvisement(e[1].toString()); } if(e[2]!=null){ sta.setTime(e[2].toString()); } return sta; }).collect(Collectors.toList()); return collectList; } @Override public List getArchives(String id) { String sql = "SELECT " + " DATE_FORMAT( create_date, '%m-%d' ), " + " sum( tissue ), sum( disinfectant ), sum( liquid_soap ), sum( cleaning ) " + "FROM " + " t_b_toilet_history " + "WHERE " + " create_date > date_sub( DATE_FORMAT( now(), '%Y-%m-%d' ), INTERVAL 5 DAY ) " + " AND ( " + " toilet_id = ( SELECT id FROM t_b_archives_place WHERE id = '"+id+"' ) " + " OR toilet_id = ( SELECT id FROM t_b_archives_toilets WHERE id = '"+id+"' )) " + " GROUP BY " + " DATE_FORMAT( create_date, '%Y-%m-%d' ) " + "ORDER BY " + " DATE_FORMAT( " + " create_date, " + " '%Y-%m-%d' " + " )"; List list = systemService.findListbySql(sql); List collectList = list.stream().map(e -> { ArchivesDTO sta = new ArchivesDTO(); if(e[0]!=null){ sta.setYLabels(e[0].toString()); } // sta.setChartValues("[{100, 100, 100, 100},{"+e[1].toString()+","+e[2].toString()+","+e[3].toString()+","+e[4].toString()+"}]"); Map data = new HashMap(); data.put("Total","100"); data.put("Consumpition",e[1].toString()); sta.setTissue(data); data = new HashMap(); data.put("Total","100"); data.put("Consumpition",e[2].toString()); sta.setDisinfectant(data); data = new HashMap(); data.put("Total","100"); data.put("Consumpition",e[3].toString()); sta.setHandSoap(data); data = new HashMap(); data.put("Total","100"); data.put("Consumpition",e[4].toString()); sta.setDetergent(data); return sta; }).collect(Collectors.toList()); return collectList; } }