|  | @ -29,6 +29,8 @@ import java.util.UUID;
 | 
	
		
			
				|  |  | import java.util.concurrent.TimeUnit;
 | 
	
		
			
				|  |  | import javax.imageio.ImageIO;
 | 
	
		
			
				|  |  | import javax.transaction.Transactional;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import org.apache.commons.lang.StringUtils;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.data.redis.core.StringRedisTemplate;
 | 
	
		
			
				|  |  | import org.springframework.data.redis.core.ValueOperations;
 | 
	
	
		
			
				|  | @ -64,10 +66,12 @@ public class BaseBannerDoctorService
 | 
	
		
			
				|  |  |         ObjEnvelop objEnvelop = new ObjEnvelop();
 | 
	
		
			
				|  |  |         BasePatientDO basePatientDO = this.patientDao.findById(patientId);
 | 
	
		
			
				|  |  |         boolean checkTimeOut = checkGiveTimeOut(patientId, doctor);
 | 
	
		
			
				|  |  |         boolean checkMessageTimeout = checkMessageTimeOut(patientId,doctor);
 | 
	
		
			
				|  |  |         if ((org.apache.commons.lang.StringUtils.isNotBlank(key)) && (org.apache.commons.lang.StringUtils.isNotBlank(value))) {
 | 
	
		
			
				|  |  |             if (verifyCaptcha(key, value))
 | 
	
		
			
				|  |  |             {
 | 
	
		
			
				|  |  |                 checkTimeOut = true;
 | 
	
		
			
				|  |  |                 checkMessageTimeout = true;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             else
 | 
	
		
			
				|  |  |             {
 | 
	
	
		
			
				|  | @ -118,6 +122,33 @@ public class BaseBannerDoctorService
 | 
	
		
			
				|  |  |                     baseUserMessageDO.setType(type);
 | 
	
		
			
				|  |  |                     baseUserMessageDO.setIsRead(Integer.valueOf(0));
 | 
	
		
			
				|  |  |                     this.baseUserMessageDao.save(baseUserMessageDO);
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     if(checkMessageTimes(patientId,doctor)){
 | 
	
		
			
				|  |  |                         if (checkMessageTimeout){
 | 
	
		
			
				|  |  |                             BaseUserMessageDO baseUserMessageDO = new BaseUserMessageDO();
 | 
	
		
			
				|  |  |                             baseUserMessageDO.setReceiver(doctor);
 | 
	
		
			
				|  |  |                             baseUserMessageDO.setContent(content);
 | 
	
		
			
				|  |  |                             baseUserMessageDO.setReceiverName(doctorName);
 | 
	
		
			
				|  |  |                             baseUserMessageDO.setRelationCode(relationCode);
 | 
	
		
			
				|  |  |                             baseUserMessageDO.setSender(patientId);
 | 
	
		
			
				|  |  |                             baseUserMessageDO.setSenderName(patientName);
 | 
	
		
			
				|  |  |                             baseUserMessageDO.setRelationName("赠送锦旗");
 | 
	
		
			
				|  |  |                             baseUserMessageDO.setRelationType(Integer.valueOf(2));
 | 
	
		
			
				|  |  |                             baseUserMessageDO.setStatus(Integer.valueOf(1));
 | 
	
		
			
				|  |  |                             baseUserMessageDO.setDel(Integer.valueOf(1));
 | 
	
		
			
				|  |  |                             baseUserMessageDO.setType(type);
 | 
	
		
			
				|  |  |                             baseUserMessageDO.setIsRead(Integer.valueOf(0));
 | 
	
		
			
				|  |  |                             objEnvelop.setMessage("success");
 | 
	
		
			
				|  |  |                         }else {
 | 
	
		
			
				|  |  |                             objEnvelop.setMessage("生成验证码");
 | 
	
		
			
				|  |  |                             objEnvelop.setObj(generateCaptcha());
 | 
	
		
			
				|  |  |                             return objEnvelop;
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }else {
 | 
	
		
			
				|  |  |                         objEnvelop.setMessage("当天总送锦旗留言次数已达上限");
 | 
	
		
			
				|  |  |                         objEnvelop.setStatus(Integer.valueOf(77));
 | 
	
		
			
				|  |  |                         return objEnvelop;
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             else
 | 
	
	
		
			
				|  | @ -319,4 +350,52 @@ public class BaseBannerDoctorService
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return pass;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public boolean checkMessageTimeOut(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 checkMessageTimes(String patientId, String doctorId)
 | 
	
		
			
				|  |  |     {
 | 
	
		
			
				|  |  |         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;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |