|  | @ -1,5 +1,6 @@
 | 
												
													
														
															|  | package com.yihu.jw.base.service.user;
 |  | package com.yihu.jw.base.service.user;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | import com.alibaba.fastjson.JSON;
 | 
												
													
														
															|  | import com.alibaba.fastjson.JSONArray;
 |  | import com.alibaba.fastjson.JSONArray;
 | 
												
													
														
															|  | import com.alibaba.fastjson.JSONObject;
 |  | import com.alibaba.fastjson.JSONObject;
 | 
												
													
														
															|  | import com.fasterxml.jackson.databind.ObjectMapper;
 |  | import com.fasterxml.jackson.databind.ObjectMapper;
 | 
												
											
												
													
														
															|  | @ -17,11 +18,15 @@ import com.yihu.jw.entity.base.org.BaseOrgUserDO;
 | 
												
													
														
															|  | import com.yihu.jw.entity.base.role.RoleDO;
 |  | import com.yihu.jw.entity.base.role.RoleDO;
 | 
												
													
														
															|  | import com.yihu.jw.entity.base.saas.SaasDO;
 |  | import com.yihu.jw.entity.base.saas.SaasDO;
 | 
												
													
														
															|  | import com.yihu.jw.entity.base.user.UserDO;
 |  | import com.yihu.jw.entity.base.user.UserDO;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.util.date.DateUtil;
 | 
												
													
														
															|  | import com.yihu.mysql.query.BaseJpaService;
 |  | import com.yihu.mysql.query.BaseJpaService;
 | 
												
													
														
															|  | import com.yihu.utils.security.MD5;
 |  | import com.yihu.utils.security.MD5;
 | 
												
													
														
															|  | import org.apache.commons.collections.map.HashedMap;
 |  | import org.apache.commons.collections.map.HashedMap;
 | 
												
													
														
															|  | import org.springframework.beans.factory.annotation.Autowired;
 |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
												
													
														
															|  | import org.springframework.beans.factory.annotation.Value;
 |  | import org.springframework.beans.factory.annotation.Value;
 | 
												
													
														
															|  | 
 |  | import org.springframework.data.redis.core.StringRedisTemplate;
 | 
												
													
														
															|  | import org.springframework.jdbc.core.BeanPropertyRowMapper;
 |  | import org.springframework.jdbc.core.BeanPropertyRowMapper;
 | 
												
													
														
															|  | import org.springframework.jdbc.core.JdbcTemplate;
 |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
												
													
														
															|  | import org.springframework.stereotype.Service;
 |  | import org.springframework.stereotype.Service;
 | 
												
											
												
													
														
															|  | @ -61,9 +66,15 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     @Autowired
 |  |     @Autowired
 | 
												
													
														
															|  |     private BaseOrgSaasService baseOrgSaasService;
 |  |     private BaseOrgSaasService baseOrgSaasService;
 | 
												
													
														
															|  | 
 |  |     
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private StringRedisTemplate redisTemplate;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     @Value("${configDefault.saasId}")
 |  |     @Value("${configDefault.saasId}")
 | 
												
													
														
															|  |     private String defaultSaasId;
 |  |     private String defaultSaasId;
 | 
												
													
														
															|  | 
 |  |     
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     public UserDO registerWithIdcard(UserDO userDO) {
 |  |     public UserDO registerWithIdcard(UserDO userDO) {
 | 
												
											
												
													
														
															|  | @ -214,9 +225,44 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
 | 
												
													
														
															|  |                     }
 |  |                     }
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  | 
 |  |     
 | 
												
													
														
															|  | 
 |  |     
 | 
												
													
														
															|  | 
 |  |         //密码过期
 | 
												
													
														
															|  | 
 |  |         userinfo.put("authPw",findDoctorPwlimitDate(id));
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         return userinfo;
 |  |         return userinfo;
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  |     
 | 
												
													
														
															|  | 
 |  |     public com.alibaba.fastjson.JSONObject findDoctorPwlimitDate(String user){
 | 
												
													
														
															|  | 
 |  |         String key = "base:authPw:iser:" + user;
 | 
												
													
														
															|  | 
 |  |         String authPw = redisTemplate.opsForValue().get(key);
 | 
												
													
														
															|  | 
 |  |         com.alibaba.fastjson.JSONObject valueJson = null;
 | 
												
													
														
															|  | 
 |  |         if(org.apache.commons.lang3.StringUtils.isNotBlank(authPw)){
 | 
												
													
														
															|  | 
 |  |             
 | 
												
													
														
															|  | 
 |  |             WlyyHospitalSysDictDO wlyyHospitalSysDictDO = wlyyHospitalSysDictDao.findById("pwOverDue");
 | 
												
													
														
															|  | 
 |  |             String code[] = wlyyHospitalSysDictDO.getDictCode().split(",");
 | 
												
													
														
															|  | 
 |  |             Integer maxDateInt = Integer.parseInt(code[0]);
 | 
												
													
														
															|  | 
 |  |             Integer remainDateInt = Integer.parseInt(code[1]);
 | 
												
													
														
															|  | 
 |  |             
 | 
												
													
														
															|  | 
 |  |             valueJson = JSON.parseObject(authPw);
 | 
												
													
														
															|  | 
 |  |             Long updateTimeLong = valueJson.getLong("updateTime");
 | 
												
													
														
															|  | 
 |  |             Date updateTime = new Date();
 | 
												
													
														
															|  | 
 |  |             updateTime.setTime(updateTimeLong);
 | 
												
													
														
															|  | 
 |  |             Date maxDate = DateUtil.getPreDays(updateTime,maxDateInt);
 | 
												
													
														
															|  | 
 |  |             
 | 
												
													
														
															|  | 
 |  |             Long betweenDate = (maxDate.getTime() - new Date().getTime())/(60*60*24*1000);
 | 
												
													
														
															|  | 
 |  |             valueJson.put("betweenDate",betweenDate);
 | 
												
													
														
															|  | 
 |  |             if(betweenDate<remainDateInt){
 | 
												
													
														
															|  | 
 |  |                 valueJson.put("remaind",true);
 | 
												
													
														
															|  | 
 |  |             }else {
 | 
												
													
														
															|  | 
 |  |                 valueJson.put("remaind",false);
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |         }else {
 | 
												
													
														
															|  | 
 |  |             valueJson = new com.alibaba.fastjson.JSONObject();
 | 
												
													
														
															|  | 
 |  |             valueJson.put("isChanged",false);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         return valueJson;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     /**
 |  |     /**
 | 
												
											
												
													
														
															|  | @ -427,6 +473,58 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
 | 
												
													
														
															|  |         return result;
 |  |         return result;
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     /**
 | 
												
													
														
															|  | 
 |  |      * 用户修改密码
 | 
												
													
														
															|  | 
 |  |      * @param userId
 | 
												
													
														
															|  | 
 |  |      * @return
 | 
												
													
														
															|  | 
 |  |      */
 | 
												
													
														
															|  | 
 |  |     public JSONObject updatePwd(String userId,String pwd,String oldpwd){
 | 
												
													
														
															|  | 
 |  |         JSONObject result = new JSONObject();
 | 
												
													
														
															|  | 
 |  |         UserDO user = userDao.findOne(userId);
 | 
												
													
														
															|  | 
 |  |         if(null == user){
 | 
												
													
														
															|  | 
 |  |             result.put("response", ConstantUtils.FAIL);
 | 
												
													
														
															|  | 
 |  |             result.put("msg","user not exist for id : " + userId);
 | 
												
													
														
															|  | 
 |  |             return result;
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |     
 | 
												
													
														
															|  | 
 |  |         String orgPwMd5 = MD5.md5Hex(oldpwd + "{" + user.getSalt() + "}");
 | 
												
													
														
															|  | 
 |  |         if(!orgPwMd5.equals(user.getPassword())){
 | 
												
													
														
															|  | 
 |  |             result.put("response", ConstantUtils.FAIL);
 | 
												
													
														
															|  | 
 |  |             result.put("msg","旧密码不正确!");
 | 
												
													
														
															|  | 
 |  |             return result;
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         if(StringUtils.isEmpty(pwd)){
 | 
												
													
														
															|  | 
 |  |             result.put("response", ConstantUtils.FAIL);
 | 
												
													
														
															|  | 
 |  |             result.put("msg","新密码不能为空!");
 | 
												
													
														
															|  | 
 |  |             return result;
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         user.setSalt(randomString(5));
 | 
												
													
														
															|  | 
 |  |         user.setEnabled(true);
 | 
												
													
														
															|  | 
 |  |         user.setLocked(false);
 | 
												
													
														
															|  | 
 |  |         user.setLoginFailureCount(0);
 | 
												
													
														
															|  | 
 |  |         user.setPassword(MD5.md5Hex(pwd + "{" + user.getSalt() + "}"));
 | 
												
													
														
															|  | 
 |  |         userDao.save(user);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         result.put("response",ConstantUtils.SUCCESS);
 | 
												
													
														
															|  | 
 |  |         result.put("msg", "修改成功");
 | 
												
													
														
															|  | 
 |  |     
 | 
												
													
														
															|  | 
 |  |         //设置用户密码过期时间
 | 
												
													
														
															|  | 
 |  |         saveUserPwlimitDate(userId);
 | 
												
													
														
															|  | 
 |  |         
 | 
												
													
														
															|  | 
 |  |         return result;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  |     
 | 
												
													
														
															|  | 
 |  |     public boolean saveUserPwlimitDate(String user){
 | 
												
													
														
															|  | 
 |  |         String key = "base:authPw:user:" + user;
 | 
												
													
														
															|  | 
 |  |         com.alibaba.fastjson.JSONObject valueJson = new com.alibaba.fastjson.JSONObject();
 | 
												
													
														
															|  | 
 |  |         valueJson.put("updateTime",new Date().getTime());
 | 
												
													
														
															|  | 
 |  |         valueJson.put("isChanged",true);
 | 
												
													
														
															|  | 
 |  |         redisTemplate.opsForValue().set(key,valueJson.toJSONString());
 | 
												
													
														
															|  | 
 |  |         return true;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  |     
 | 
												
													
														
															|  |     /**
 |  |     /**
 | 
												
													
														
															|  |      * 用户重置密码
 |  |      * 用户重置密码
 | 
												
													
														
															|  |      * @param userId
 |  |      * @param userId
 | 
												
											
												
													
														
															|  | @ -444,26 +542,26 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
 | 
												
													
														
															|  |         String idcard = user.getIdcard();
 |  |         String idcard = user.getIdcard();
 | 
												
													
														
															|  |         String mobile = user.getMobile();
 |  |         String mobile = user.getMobile();
 | 
												
													
														
															|  |         String password = null;
 |  |         String password = null;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         
 | 
												
													
														
															|  |         if(!StringUtils.isEmpty(password)&&idcard.length()>10){
 |  |         if(!StringUtils.isEmpty(password)&&idcard.length()>10){
 | 
												
													
														
															|  |             password = idcard.substring(idcard.length()-6,idcard.length());
 |  |             password = idcard.substring(idcard.length()-6,idcard.length());
 | 
												
													
														
															|  |         }else if(!StringUtils.isEmpty(mobile)&&mobile.length()>=11){
 |  |         }else if(!StringUtils.isEmpty(mobile)&&mobile.length()>=11){
 | 
												
													
														
															|  |             password = mobile.substring(mobile.length()-6,mobile.length());
 |  |             password = mobile.substring(mobile.length()-6,mobile.length());
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         
 | 
												
													
														
															|  |         if(StringUtils.isEmpty(password)){
 |  |         if(StringUtils.isEmpty(password)){
 | 
												
													
														
															|  |             result.put("response", ConstantUtils.FAIL);
 |  |             result.put("response", ConstantUtils.FAIL);
 | 
												
													
														
															|  |             result.put("msg","idcard or moblie not exist : " + userId);
 |  |             result.put("msg","idcard or moblie not exist : " + userId);
 | 
												
													
														
															|  |             return result;
 |  |             return result;
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         
 | 
												
													
														
															|  |         user.setSalt(randomString(5));
 |  |         user.setSalt(randomString(5));
 | 
												
													
														
															|  |         user.setEnabled(true);
 |  |         user.setEnabled(true);
 | 
												
													
														
															|  |         user.setLocked(false);
 |  |         user.setLocked(false);
 | 
												
													
														
															|  |         user.setLoginFailureCount(0);
 |  |         user.setLoginFailureCount(0);
 | 
												
													
														
															|  |         user.setPassword(MD5.md5Hex(password + "{" + user.getSalt() + "}"));
 |  |         user.setPassword(MD5.md5Hex(password + "{" + user.getSalt() + "}"));
 | 
												
													
														
															|  |         userDao.save(user);
 |  |         userDao.save(user);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         
 | 
												
													
														
															|  |         result.put("response",ConstantUtils.SUCCESS);
 |  |         result.put("response",ConstantUtils.SUCCESS);
 | 
												
													
														
															|  |         result.put("msg", password);
 |  |         result.put("msg", password);
 | 
												
													
														
															|  |         return result;
 |  |         return result;
 |