|  | @ -7,12 +7,14 @@ import com.yihu.jw.entity.base.patient.BasePatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.score.BaseEvaluateDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.score.BaseEvaluateScoreDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.words.BaseSensitiveDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.message.BaseBannerDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.message.BaseBannerDoctorDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.message.BaseUserMessageDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.message.BaseUserMsgContentDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.evaluate.score.dao.BaseEvaluateDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.evaluate.score.dao.BaseEvaluateScoreDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.message.dao.BaseBannerDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.message.dao.BaseBannerDoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.message.dao.BaseUserMessageDao;
 | 
	
	
		
			
				|  | @ -21,6 +23,7 @@ import com.yihu.jw.hospital.prescription.dao.BaseSensitiveDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.Envelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.MixEnvelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.ObjEnvelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.rm.base.BaseRequestMapping;
 | 
	
		
			
				|  |  | import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
	
		
			
				|  | @ -34,12 +37,15 @@ import org.hibernate.dialect.Ingres9Dialect;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | import org.springframework.data.jpa.provider.HibernateUtils;
 | 
	
		
			
				|  |  | import org.springframework.data.redis.core.StringRedisTemplate;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import javax.swing.plaf.PanelUI;
 | 
	
		
			
				|  |  | import javax.transaction.Transactional;
 | 
	
		
			
				|  |  | import java.io.IOException;
 | 
	
		
			
				|  |  | import java.lang.annotation.ElementType;
 | 
	
		
			
				|  |  | import java.text.SimpleDateFormat;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | @Service
 | 
	
	
		
			
				|  | @ -67,6 +73,12 @@ public class BaseUserMsgService extends BaseJpaService<BaseUserMessageDO, BaseUs
 | 
	
		
			
				|  |  |     private BaseBannerDao bannerDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseSensitiveDao baseSensitiveDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private StringRedisTemplate redisTemplate;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseBannerDoctorService baseBannerDoctorService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Value("${wechat.id}")
 | 
	
		
			
				|  |  |     private String wxId;
 | 
	
	
		
			
				|  | @ -75,29 +87,66 @@ public class BaseUserMsgService extends BaseJpaService<BaseUserMessageDO, BaseUs
 | 
	
		
			
				|  |  |     @Value("${wechat.flag}")
 | 
	
		
			
				|  |  |     private boolean flag;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //患者给医生自身留言接口
 | 
	
		
			
				|  |  |     public void leaveMessage(String content, String reciverId, String reciverName, String senderId, Integer type) {
 | 
	
		
			
				|  |  |     public ObjEnvelop leaveMessage(String content, String reciverId, String reciverName, String senderId, Integer type, String key, String value)
 | 
	
		
			
				|  |  |             throws IOException
 | 
	
		
			
				|  |  |     {
 | 
	
		
			
				|  |  |         BaseUserMessageDO baseUserMessageDO = new BaseUserMessageDO();
 | 
	
		
			
				|  |  |         BasePatientDO patientDO= basePatientDao.findById(senderId);
 | 
	
		
			
				|  |  |         String senderName=null;
 | 
	
		
			
				|  |  |         if(null!=patientDO){
 | 
	
		
			
				|  |  |             senderName = patientDO.getName();
 | 
	
		
			
				|  |  |         ObjEnvelop objEnvelop = new ObjEnvelop();
 | 
	
		
			
				|  |  |         boolean checkTimeOut = checkGiveTimeOut(senderId, reciverId);
 | 
	
		
			
				|  |  |         if ((StringUtils.isNotBlank(key)) && (StringUtils.isNotBlank(value))) {
 | 
	
		
			
				|  |  |             if (this.baseBannerDoctorService.verifyCaptcha(key, value))
 | 
	
		
			
				|  |  |             {
 | 
	
		
			
				|  |  |                 checkTimeOut = true;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             else
 | 
	
		
			
				|  |  |             {
 | 
	
		
			
				|  |  |                 objEnvelop.setMessage("验证码错误");
 | 
	
		
			
				|  |  |                 objEnvelop.setStatus(Integer.valueOf(78));
 | 
	
		
			
				|  |  |                 return objEnvelop;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String relationCode=UUID.randomUUID().toString();
 | 
	
		
			
				|  |  |         baseUserMessageDO.setContent(content);
 | 
	
		
			
				|  |  |         baseUserMessageDO.setSender(senderId);
 | 
	
		
			
				|  |  |         baseUserMessageDO.setSenderName(senderName);
 | 
	
		
			
				|  |  |         baseUserMessageDO.setReceiver(reciverId);
 | 
	
		
			
				|  |  |         baseUserMessageDO.setReceiverName(reciverName);
 | 
	
		
			
				|  |  |         baseUserMessageDO.setRelationCode(relationCode);
 | 
	
		
			
				|  |  |         baseUserMessageDO.setRelationName("留言");
 | 
	
		
			
				|  |  |         baseUserMessageDO.setRelationType(1);
 | 
	
		
			
				|  |  |         baseUserMessageDO.setStatus(1);
 | 
	
		
			
				|  |  |         baseUserMessageDO.setDel(1);
 | 
	
		
			
				|  |  |         baseUserMessageDO.setType(type);
 | 
	
		
			
				|  |  |         baseUserMessageDO.setIsRead(0);
 | 
	
		
			
				|  |  |         baseUserMessageDao.save(baseUserMessageDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         boolean checkTimes = checkGiveTimes(senderId, reciverId);
 | 
	
		
			
				|  |  |         if (checkTimes)
 | 
	
		
			
				|  |  |         {
 | 
	
		
			
				|  |  |             if (checkTimeOut)
 | 
	
		
			
				|  |  |             {
 | 
	
		
			
				|  |  |                 BasePatientDO patientDO = this.basePatientDao.findById(senderId);
 | 
	
		
			
				|  |  |                 String senderName = null;
 | 
	
		
			
				|  |  |                 if (null != patientDO) {
 | 
	
		
			
				|  |  |                     senderName = patientDO.getName();
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 String relationCode = UUID.randomUUID().toString();
 | 
	
		
			
				|  |  |                 baseUserMessageDO.setContent(content);
 | 
	
		
			
				|  |  |                 baseUserMessageDO.setSender(senderId);
 | 
	
		
			
				|  |  |                 baseUserMessageDO.setSenderName(senderName);
 | 
	
		
			
				|  |  |                 baseUserMessageDO.setReceiver(reciverId);
 | 
	
		
			
				|  |  |                 baseUserMessageDO.setReceiverName(reciverName);
 | 
	
		
			
				|  |  |                 baseUserMessageDO.setRelationCode(relationCode);
 | 
	
		
			
				|  |  |                 baseUserMessageDO.setRelationName("留言");
 | 
	
		
			
				|  |  |                 baseUserMessageDO.setRelationType(Integer.valueOf(1));
 | 
	
		
			
				|  |  |                 baseUserMessageDO.setStatus(Integer.valueOf(1));
 | 
	
		
			
				|  |  |                 baseUserMessageDO.setDel(Integer.valueOf(1));
 | 
	
		
			
				|  |  |                 baseUserMessageDO.setType(type);
 | 
	
		
			
				|  |  |                 baseUserMessageDO.setIsRead(Integer.valueOf(0));
 | 
	
		
			
				|  |  |                 this.baseUserMessageDao.save(baseUserMessageDO);
 | 
	
		
			
				|  |  |                 objEnvelop.setStatus(Integer.valueOf(200));
 | 
	
		
			
				|  |  |                 objEnvelop.setMessage("留言成功");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             else
 | 
	
		
			
				|  |  |             {
 | 
	
		
			
				|  |  |                 objEnvelop.setMessage("生成验证码");
 | 
	
		
			
				|  |  |                 objEnvelop.setStatus(Integer.valueOf(76));
 | 
	
		
			
				|  |  |                 objEnvelop.setObj(baseBannerDoctorService.generateCaptcha());
 | 
	
		
			
				|  |  |                 return objEnvelop;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         else
 | 
	
		
			
				|  |  |         {
 | 
	
		
			
				|  |  |             objEnvelop.setMessage("当天留言已达规定次数");
 | 
	
		
			
				|  |  |             objEnvelop.setStatus(Integer.valueOf(77));
 | 
	
		
			
				|  |  |             return objEnvelop;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return objEnvelop;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     //回复留言接口
 | 
	
		
			
				|  |  |     @Transactional
 | 
	
	
		
			
				|  | @ -423,5 +472,49 @@ public class BaseUserMsgService extends BaseJpaService<BaseUserMessageDO, BaseUs
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return sql.toString();
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     public boolean checkGiveTimeOut(String sender, String reciver)
 | 
	
		
			
				|  |  |     {
 | 
	
		
			
				|  |  |         List<BaseUserMessageDO> baseBannerDoctorDOS = this.baseUserMessageDao.getMessageByPatientAndDoctor(reciver, sender);
 | 
	
		
			
				|  |  |         WlyyHospitalSysDictDO wlyyHospitalSysDictDO = this.wlyyHospitalSysDictDao.findById("leave_message_timeout");
 | 
	
		
			
				|  |  |         if (null != baseBannerDoctorDOS)
 | 
	
		
			
				|  |  |         {
 | 
	
		
			
				|  |  |             BaseUserMessageDO lastOne = (BaseUserMessageDO)baseBannerDoctorDOS.get(0);
 | 
	
		
			
				|  |  |             Date lastDate = lastOne.getCreateTime();
 | 
	
		
			
				|  |  |             long timeOut = wlyyHospitalSysDictDO.getDictValue() != null ? Long.valueOf(wlyyHospitalSysDictDO.getDictValue()).longValue() : 5L;
 | 
	
		
			
				|  |  |             Date current = new Date();
 | 
	
		
			
				|  |  |             if (current.getTime() - lastDate.getTime() > timeOut * 1000L * 60L) {
 | 
	
		
			
				|  |  |                 return true;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             return false;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return true;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public boolean checkGiveTimes(String patientId, String doctorId)
 | 
	
		
			
				|  |  |     {
 | 
	
		
			
				|  |  |         boolean flag = false;
 | 
	
		
			
				|  |  |         StringBuffer sql = new StringBuffer();
 | 
	
		
			
				|  |  |         sql.append("select t.sender as \"sender\",t.receiver as \"receiver\" from base_user_message t");
 | 
	
		
			
				|  |  |         sql.append(" where 1=1 ");
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(patientId)) {
 | 
	
		
			
				|  |  |             sql.append(" and t.sender = '" + patientId + "'");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(doctorId)) {
 | 
	
		
			
				|  |  |             sql.append(" and t.receiver = '" + doctorId + "'");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         Date date = new Date();
 | 
	
		
			
				|  |  |         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
 | 
	
		
			
				|  |  |         String strDate = format.format(date);
 | 
	
		
			
				|  |  |         sql.append(" and t.create_time > '" + strDate + " 00:00:00' and t.create_time<'" + strDate + " 23:59:59'");
 | 
	
		
			
				|  |  |         List<Map<String, Object>> list = this.hibenateUtils.createSQLQuery(sql.toString());
 | 
	
		
			
				|  |  |         WlyyHospitalSysDictDO wlyyHospitalSysDictDO = this.wlyyHospitalSysDictDao.findById("leave_message_times");
 | 
	
		
			
				|  |  |         long countTimes = 5L;
 | 
	
		
			
				|  |  |         if (wlyyHospitalSysDictDO != null) {
 | 
	
		
			
				|  |  |             countTimes = wlyyHospitalSysDictDO.getDictValue() == null ? countTimes : Long.valueOf(wlyyHospitalSysDictDO.getDictValue()).longValue();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (list.size() > countTimes) {
 | 
	
		
			
				|  |  |             return false;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return true;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |