|  | @ -1,5 +1,6 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.service.channel;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.jw.dailyReport.dao.BaseDailyReportDetailDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.dailyReport.dao.BaseDailyReportUploadDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
	
	
		
			
				|  | @ -30,9 +31,8 @@ import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.util.Date;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | import java.util.stream.Collectors;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * Created by Bing on 2022/7/26.
 | 
	
	
		
			
				|  | @ -259,4 +259,119 @@ public class DailyReportService {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void dailyReportMonth(){
 | 
	
		
			
				|  |  |         String sql = " select dict_value from wlyy_hospital_sys_dict where dict_name='BOOS_ADMIN_SENDER'  ";
 | 
	
		
			
				|  |  |         List<String> boosSenderIds = jdbcTemplate.queryForList(sql, String.class);
 | 
	
		
			
				|  |  |         String boosID = " ";
 | 
	
		
			
				|  |  |         if (boosSenderIds.size() > 0) {
 | 
	
		
			
				|  |  |             boosID = boosSenderIds.get(0);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql = "select id,name,mobile from base_doctor where del=1 and identity=0 and id<>'"+boosID+"' ";
 | 
	
		
			
				|  |  |         List<Map<String,Object>> patientList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         Date lastMonth= DateUtil.getNextMonthReturnDate(new Date(),-1);
 | 
	
		
			
				|  |  |         String monthStartDay = DateUtil.getFristDayOfMonthThisDate(lastMonth);
 | 
	
		
			
				|  |  |         String monthEndDay = DateUtil.getLastDayOfMonthThisDate(lastMonth);
 | 
	
		
			
				|  |  |         sql = " select dict_value from  wlyy_hospital_sys_dict where dict_name='healthUpload' and dict_code='healthUpload' ";
 | 
	
		
			
				|  |  |         List<String> dictValues = jdbcTemplate.queryForList(sql,String.class);
 | 
	
		
			
				|  |  |         JSONObject doubtTypeObj = new JSONObject();
 | 
	
		
			
				|  |  |         if (dictValues.size()>0){
 | 
	
		
			
				|  |  |             doubtTypeObj = JSONObject.parseObject(dictValues.get(0)).getJSONObject("dailyReportDoubtTypeName");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String monthStr = DateUtil.dateToStr(lastMonth,"MM");
 | 
	
		
			
				|  |  |         for (Map<String,Object>tmp:patientList){
 | 
	
		
			
				|  |  |             String msg = "{name},{month}月份月报:效能异常:{doubtTotal}次,请假:{leaveHour}个小时,未上报:{weishangbao}次,{doubtTypeMsg},项目催促:{xmcc}次,效能异常超过3次扣绩效! ";
 | 
	
		
			
				|  |  |             String user = tmp.get("id").toString();
 | 
	
		
			
				|  |  |             String name = null==tmp.get("name")?"":tmp.get("name").toString();
 | 
	
		
			
				|  |  |             String mobile = null==tmp.get("mobile")?"":tmp.get("mobile").toString();
 | 
	
		
			
				|  |  |             //效能异常
 | 
	
		
			
				|  |  |            sql = "select count(distinct d1.id)from base_doctor_daily_report_upload d1 INNER JOIN base_doctor doc on d1.doctor_id = doc.id " +
 | 
	
		
			
				|  |  |                     "INNER JOIN base_doctor_hospital dh on doc.id = dh.doctor_code and dh.del=1  " +
 | 
	
		
			
				|  |  |                     "LEFT JOIN base_daily_report_detail de on d1.id = de.report_id " +
 | 
	
		
			
				|  |  |                     "where doc.del=1 and doc.identity=0 and doc.id='"+user+"' and d1.report_date>='"+monthStartDay+"' and d1.report_date<='"+monthEndDay+"'  and de.doubt=1 ";
 | 
	
		
			
				|  |  |            Integer doubtTotal = jdbcTemplate.queryForObject(sql,Integer.class);
 | 
	
		
			
				|  |  |            if (doubtTotal>3){
 | 
	
		
			
				|  |  |                continue;
 | 
	
		
			
				|  |  |            }
 | 
	
		
			
				|  |  |             //请假
 | 
	
		
			
				|  |  |             Double leaveHour = 0d;
 | 
	
		
			
				|  |  |             sql = " select sum(cast(IFNULL(leave_hour,IFNULL(leave_hour,0)) as decimal(18,2))) from base_doctor_daily_report_upload up where up.doctor_id='"+user+"' and up.report_date>='"+monthStartDay+"' and up.report_date<='"+monthEndDay+"' ";
 | 
	
		
			
				|  |  |             leaveHour = jdbcTemplate.queryForObject(sql,Double.class);
 | 
	
		
			
				|  |  |             leaveHour = null==leaveHour?0:leaveHour;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //未上报
 | 
	
		
			
				|  |  |             Long weishangbao=0l;
 | 
	
		
			
				|  |  |             Long workDays=0l;
 | 
	
		
			
				|  |  |             if (StringUtils.isNotBlank(monthStartDay)&&StringUtils.isNotBlank(monthEndDay)) {
 | 
	
		
			
				|  |  |                 workDays = DateUtil.getWorkDays(monthStartDay, monthEndDay);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             sql = " select count(id) from base_doctor_daily_report_upload up where up.doctor_id='"+user+"' and up.report_date>='"+monthStartDay+"' and up.report_date<='"+monthEndDay+"' ";
 | 
	
		
			
				|  |  |             Long yishangbao = jdbcTemplate.queryForObject(sql,Long.class);
 | 
	
		
			
				|  |  |             weishangbao = (workDays-yishangbao)<0?0:workDays-yishangbao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             sql = " select count(distinct up.id) as total,rd.doubt_type " +
 | 
	
		
			
				|  |  |                     " from base_doctor_daily_report_upload up  " +
 | 
	
		
			
				|  |  |                     "INNER JOIN base_doctor doc on up.doctor_id = doc.id and doc.del=1 " +
 | 
	
		
			
				|  |  |                     "Inner JOIN base_doctor_hospital dh on doc.id = dh.doctor_code and dh.del=1 " +
 | 
	
		
			
				|  |  |                     "LEFT JOIN base_daily_report_detail rd on up.id = rd.report_id " +
 | 
	
		
			
				|  |  |                     "LEFT join base_daily_report_item i on i.id = rd.report_item_id and i.del=1 and up.state=1 where 1=1 " +
 | 
	
		
			
				|  |  |                     " and doc.id='"+user+"' and up.report_date>='"+monthStartDay+"' and up.report_date<='"+monthEndDay+"'  group by rd.doubt_type";
 | 
	
		
			
				|  |  |             List<Map<String,Object>> doubtTypeList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |             List<Map<String,Object>> personDoubtList = new ArrayList<>();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             for (Map<String,Object>doubtTmp:doubtTypeList){
 | 
	
		
			
				|  |  |                 if (doubtTmp.get("doubt_type")==null){
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     String doubtType = doubtTmp.get("doubt_type").toString();
 | 
	
		
			
				|  |  |                     if(doubtTypeObj.containsKey(doubtType)){
 | 
	
		
			
				|  |  |                         doubtTmp.put("doubtTypeName",doubtTypeObj.get(doubtType));
 | 
	
		
			
				|  |  |                     }else {
 | 
	
		
			
				|  |  |                         doubtTmp.put("doubtTypeName","其他");
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     personDoubtList.add(doubtTmp);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             List<String> doubtListStr = personDoubtList.stream().map(e -> e.get("doubt_type").toString()).collect(Collectors.toList());
 | 
	
		
			
				|  |  |             for (String key:doubtTypeObj.keySet()){
 | 
	
		
			
				|  |  |                 if (!doubtListStr.contains(key)){
 | 
	
		
			
				|  |  |                     Map<String,Object>doubtTmp = new HashMap<>();
 | 
	
		
			
				|  |  |                     doubtTmp.put("doubt_type",key);
 | 
	
		
			
				|  |  |                     doubtTmp.put("doubtTypeName",doubtTypeObj.get(key));
 | 
	
		
			
				|  |  |                     doubtTmp.put("total",0);
 | 
	
		
			
				|  |  |                     personDoubtList.add(doubtTmp);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             personDoubtList.sort((Comparator.comparing(e->e.get("doubt_type").toString())));
 | 
	
		
			
				|  |  |             List<String> doubtTypeMsgs = new ArrayList<>();
 | 
	
		
			
				|  |  |             for (Map<String,Object> personDoubt:personDoubtList ){
 | 
	
		
			
				|  |  |                 String doubtName = personDoubt.get("doubtTypeName").toString();
 | 
	
		
			
				|  |  |                 String total = personDoubt.get("total").toString();
 | 
	
		
			
				|  |  |                 doubtTypeMsgs.add(doubtName+total+"次");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             String doubtTypeMsg = doubtTypeMsgs.stream().map(String::valueOf).collect(Collectors.joining(","));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //项目催促
 | 
	
		
			
				|  |  |             Integer xmcc=0;
 | 
	
		
			
				|  |  |             sql = " select count(id) from base_daily_urging_record where receive_doctor='"+user+"' and create_time>='"+monthStartDay +" 00:00:00' and create_time<='"+monthEndDay+" 23:59:59' ";
 | 
	
		
			
				|  |  |             xmcc = jdbcTemplate.queryForObject(sql,Integer.class);
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  |                 WxEnterpriseUserDO enterpriseUserDO = wxEnterpriseUserDao.findByEnterpriseIdAndMobile(wechatId, mobile);
 | 
	
		
			
				|  |  |                 if (enterpriseUserDO == null) {
 | 
	
		
			
				|  |  |                     logger.info("该用户" + name + "没有企业微信手机号,无法推送模版消息,用户ID:" + user + "wechatId:" + wechatId);
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     String title = "月报反馈";
 | 
	
		
			
				|  |  |                     String des = msg.replace("{name}",name).replace("{name}",name).replace("{month}",monthStr+"")
 | 
	
		
			
				|  |  |                             .replace("{doubtTotal}",doubtTotal+"").replace("{leaveHour}",leaveHour+"")
 | 
	
		
			
				|  |  |                             .replace("{weishangbao}",weishangbao+"").replace("{doubtTypeMsg}",doubtTypeMsg).replace("{xmcc}",xmcc+"");
 | 
	
		
			
				|  |  |                     logger.info(des);
 | 
	
		
			
				|  |  |                     String url = "https://ehr.yihu.com/hlwyy/zjxl/dailyReport/#/home/index";
 | 
	
		
			
				|  |  |                     String res = enterpriseService.sendTWMesByDoctor(wechatId, user, title, des, url);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }catch (Exception e){
 | 
	
		
			
				|  |  |                 e.printStackTrace();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |