|
@ -12,7 +12,6 @@ import com.yihu.jw.base.dao.saas.SaasDao;
|
|
|
import com.yihu.jw.base.service.org.BaseOrgUserService;
|
|
|
import com.yihu.jw.base.service.org.OrgTree;
|
|
|
import com.yihu.jw.base.service.org.OrgTreeService;
|
|
|
import com.yihu.jw.base.service.org.*;
|
|
|
import com.yihu.jw.base.util.ConstantUtils;
|
|
|
import com.yihu.jw.base.util.JavaBeanUtils;
|
|
|
import com.yihu.jw.entity.base.org.BaseOrgUserDO;
|
|
@ -74,7 +73,7 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
private WlyyUserAreaDao userAreaDao;
|
|
|
@Autowired
|
|
|
private WlyyUserEquipmentDao userEquipmentDao;
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
@Autowired
|
|
@ -82,7 +81,7 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
|
|
|
@Value("${configDefault.saasId}")
|
|
|
private String defaultSaasId;
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
|
|
|
|
|
@ -93,16 +92,16 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
|
|
|
public UserDO registerWithIdcard(UserDO userDO) {
|
|
|
userDO.setSalt(randomString(5));
|
|
|
if (StringUtils.isEmpty(userDO.getEnabled())){
|
|
|
if (StringUtils.isEmpty(userDO.getEnabled())) {
|
|
|
userDO.setEnabled(true);
|
|
|
}else {
|
|
|
} else {
|
|
|
userDO.setEnabled(userDO.getEnabled());
|
|
|
}
|
|
|
userDO.setLocked(false);
|
|
|
userDO.setLoginFailureCount(0);
|
|
|
String password = userDO.getPassword();
|
|
|
if (StringUtils.isEmpty(password)) {
|
|
|
password = userDO.getIdcard().substring(userDO.getIdcard().length()-6,userDO.getIdcard().length());
|
|
|
password = userDO.getIdcard().substring(userDO.getIdcard().length() - 6, userDO.getIdcard().length());
|
|
|
}
|
|
|
userDO.setPassword(MD5.md5Hex(password + "{" + userDO.getSalt() + "}"));
|
|
|
return userDao.save(userDO);
|
|
@ -121,7 +120,7 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
userDO.setLoginFailureCount(0);
|
|
|
String password = userDO.getPassword();
|
|
|
if (StringUtils.isEmpty(password)) {
|
|
|
password = userDO.getMobile().substring(userDO.getMobile().length()-6, userDO.getMobile().length());
|
|
|
password = userDO.getMobile().substring(userDO.getMobile().length() - 6, userDO.getMobile().length());
|
|
|
}
|
|
|
userDO.setPassword(MD5.md5Hex(password + "{" + userDO.getSalt() + "}"));
|
|
|
return userDao.save(userDO);
|
|
@ -163,11 +162,12 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
|
|
|
/**
|
|
|
* 判断用户名是否存在
|
|
|
*
|
|
|
* @param username
|
|
|
* @return
|
|
|
*/
|
|
|
public Boolean existUserName(String username){
|
|
|
if(StringUtils.isEmpty(username)) {
|
|
|
public Boolean existUserName(String username) {
|
|
|
if (StringUtils.isEmpty(username)) {
|
|
|
return null;
|
|
|
}
|
|
|
return userDao.existsByUsername(username);
|
|
@ -191,9 +191,10 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
Map<String, Object> userinfo = new HashedMap();
|
|
|
|
|
|
UserDO user = userDao.findOne(id);
|
|
|
System.out.println("用户信息:" + user);
|
|
|
RoleDO role = null;
|
|
|
if (user != null ) {
|
|
|
if(!user.getEnabled()){
|
|
|
if (user != null) {
|
|
|
if (!user.getEnabled()) {
|
|
|
throw new Exception("用户已失效!");
|
|
|
}
|
|
|
userinfo.put("id", user.getId());
|
|
@ -206,10 +207,10 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
userinfo.put("roleCode", role.getCode());
|
|
|
userinfo.put("system", role.getSystem());
|
|
|
|
|
|
if (role.getType()==1) {
|
|
|
if (role.getType() == 1) {
|
|
|
//平台管理员信息获取
|
|
|
|
|
|
} else if (role.getType()==2) {
|
|
|
} else if (role.getType() == 2) {
|
|
|
//saas平台管理员信息获取
|
|
|
if (org.apache.commons.lang3.StringUtils.isNotBlank(user.getId())) {
|
|
|
SaasDO saas = saasDao.findOne(user.getSaasId());
|
|
@ -219,31 +220,31 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
userinfo.put("saas", ss);
|
|
|
}
|
|
|
|
|
|
} else if (role.getType()==3) {
|
|
|
} else if (role.getType() == 3) {
|
|
|
//機構管理員信息獲取
|
|
|
String sql = "SELECT " +
|
|
|
" g.code AS orgCode, " +
|
|
|
" g.province_code AS provinceCode, " +
|
|
|
" g.province_name AS privinceName, " +
|
|
|
" g.city_code AS cityCode, " +
|
|
|
" g.city_name AS cityName, " +
|
|
|
" g.town_code AS townCode, " +
|
|
|
" g.town_name AS townName, " +
|
|
|
" g.street_code AS streetCode, " +
|
|
|
" g.street_name AS streetName, " +
|
|
|
" g.name, " +
|
|
|
" address " +
|
|
|
" FROM " +
|
|
|
" base_org g " +
|
|
|
" JOIN base_org_user u ON g.`code` = u.org_code " +
|
|
|
" WHERE " +
|
|
|
" u.user_id = '" + id + "'";
|
|
|
List<Map<String, Object>> org = jdbcTemplate.queryForList(sql);
|
|
|
if (org != null && org.size() > 0) {
|
|
|
userinfo.put("org", org.get(0));
|
|
|
} else {
|
|
|
userinfo.put("org", null);
|
|
|
}
|
|
|
" g.code AS orgCode, " +
|
|
|
" g.province_code AS provinceCode, " +
|
|
|
" g.province_name AS privinceName, " +
|
|
|
" g.city_code AS cityCode, " +
|
|
|
" g.city_name AS cityName, " +
|
|
|
" g.town_code AS townCode, " +
|
|
|
" g.town_name AS townName, " +
|
|
|
" g.street_code AS streetCode, " +
|
|
|
" g.street_name AS streetName, " +
|
|
|
" g.name, " +
|
|
|
" address " +
|
|
|
" FROM " +
|
|
|
" base_org g " +
|
|
|
" JOIN base_org_user u ON g.`code` = u.org_code " +
|
|
|
" WHERE " +
|
|
|
" u.user_id = '" + id + "'";
|
|
|
List<Map<String, Object>> org = jdbcTemplate.queryForList(sql);
|
|
|
if (org != null && org.size() > 0) {
|
|
|
userinfo.put("org", org.get(0));
|
|
|
} else {
|
|
|
userinfo.put("org", null);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//機構管理員信息獲取
|
|
@ -270,40 +271,40 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
} else {
|
|
|
userinfo.put("org", null);
|
|
|
}
|
|
|
|
|
|
//密码过期
|
|
|
userinfo.put("authPw",findDoctorPwlimitDate(id));
|
|
|
|
|
|
//密码过期
|
|
|
userinfo.put("authPw", findDoctorPwlimitDate(id));
|
|
|
System.out.println("信息==>" + JSON.toJSONString(userinfo));
|
|
|
return userinfo;
|
|
|
}
|
|
|
|
|
|
public com.alibaba.fastjson.JSONObject findDoctorPwlimitDate(String user){
|
|
|
|
|
|
public com.alibaba.fastjson.JSONObject findDoctorPwlimitDate(String user) {
|
|
|
String key = "base:authPw:user:" + user;
|
|
|
String authPw = redisTemplate.opsForValue().get(key);
|
|
|
com.alibaba.fastjson.JSONObject valueJson = null;
|
|
|
if(org.apache.commons.lang3.StringUtils.isNotBlank(authPw)){
|
|
|
|
|
|
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);
|
|
|
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 {
|
|
|
} else {
|
|
|
valueJson = new com.alibaba.fastjson.JSONObject();
|
|
|
valueJson.put("isChanged",false);
|
|
|
valueJson.put("isChanged", false);
|
|
|
}
|
|
|
return valueJson;
|
|
|
}
|
|
@ -349,7 +350,7 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
//组装用户与机构的关联关系
|
|
|
List<BaseOrgUserDO> orgList = new ArrayList<>();
|
|
|
BaseOrgUserDO orgUserDO = null;
|
|
|
if(!CollectionUtils.isEmpty(org)){
|
|
|
if (!CollectionUtils.isEmpty(org)) {
|
|
|
for (Object obj : org) {
|
|
|
try {
|
|
|
orgUserDO = objectMapper.readValue(obj.toString(), BaseOrgUserDO.class);
|
|
@ -365,9 +366,9 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
}
|
|
|
//area:[{"city":"","cityName":"","town":"","townName":"","hospital":"","hospitalName":""}]
|
|
|
//用户所属区域添加
|
|
|
if (area!=null&&area.size()!=0){
|
|
|
if (area != null && area.size() != 0) {
|
|
|
userAreaDao.deleteByUserId(userDO.getId());
|
|
|
for (int i=0;i<area.size();i++){
|
|
|
for (int i = 0; i < area.size(); i++) {
|
|
|
JSONObject object = area.getJSONObject(i);
|
|
|
WlyyUserAreaDO userAreaDO = new WlyyUserAreaDO();
|
|
|
userAreaDO.setUserId(userDO.getId());
|
|
@ -375,7 +376,7 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
userAreaDO.setCityName(object.getString("cityName"));
|
|
|
userAreaDO.setTown(object.getString("town"));
|
|
|
userAreaDO.setTownName(object.getString("townName"));
|
|
|
if (!StringUtils.isEmpty(object.getString("hospital"))){
|
|
|
if (!StringUtils.isEmpty(object.getString("hospital"))) {
|
|
|
userAreaDO.setHospital(object.getString("hospital"));
|
|
|
userAreaDO.setHospitalName(object.getString("hospitalName"));
|
|
|
}
|
|
@ -387,9 +388,9 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
}
|
|
|
//用户所管设备添加
|
|
|
//equipment:[{"equipmentId":"","equipmentName":""}]
|
|
|
if (equipment!=null&&equipment.size()!=0){
|
|
|
if (equipment != null && equipment.size() != 0) {
|
|
|
userEquipmentDao.deleteByUserId(userDO.getId());
|
|
|
for (int i=0;i<equipment.size();i++){
|
|
|
for (int i = 0; i < equipment.size(); i++) {
|
|
|
JSONObject object = equipment.getJSONObject(i);
|
|
|
WlyyUserEquipmentDO userEquipmentDO = new WlyyUserEquipmentDO();
|
|
|
userEquipmentDO.setDel(1);
|
|
@ -398,7 +399,7 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
userEquipmentDO.setCityName(object.getString("cityName"));
|
|
|
userEquipmentDO.setTown(object.getString("town"));
|
|
|
userEquipmentDO.setTownName(object.getString("townName"));
|
|
|
if (!StringUtils.isEmpty(object.getString("hospital"))){
|
|
|
if (!StringUtils.isEmpty(object.getString("hospital"))) {
|
|
|
userEquipmentDO.setHospital(object.getString("hospital"));
|
|
|
userEquipmentDO.setHospitalName(object.getString("hospitalName"));
|
|
|
}
|
|
@ -410,8 +411,8 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
}
|
|
|
}
|
|
|
JSONObject returnMsg = new JSONObject();
|
|
|
returnMsg.put("username",userDO.getUsername());
|
|
|
returnMsg.put("password",userDO.getIdcard().substring(userDO.getIdcard().length()-6,userDO.getIdcard().length()));
|
|
|
returnMsg.put("username", userDO.getUsername());
|
|
|
returnMsg.put("password", userDO.getIdcard().substring(userDO.getIdcard().length() - 6, userDO.getIdcard().length()));
|
|
|
result.put("response", ConstantUtils.SUCCESS);
|
|
|
result.put("msg", returnMsg);
|
|
|
return result;
|
|
@ -481,9 +482,9 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
|
|
|
//area:[{"city":"","cityName":"","town":"","townName":"","hospital":"","hospitalName":""}]
|
|
|
//用户所属区域添加
|
|
|
if (area!=null&&area.size()!=0){
|
|
|
if (area != null && area.size() != 0) {
|
|
|
userAreaDao.deleteByUserId(userDO.getId());
|
|
|
for (int i=0;i<area.size();i++){
|
|
|
for (int i = 0; i < area.size(); i++) {
|
|
|
JSONObject object = area.getJSONObject(i);
|
|
|
WlyyUserAreaDO userAreaDO = new WlyyUserAreaDO();
|
|
|
userAreaDO.setUserId(userDO.getId());
|
|
@ -491,7 +492,7 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
userAreaDO.setCityName(object.getString("cityName"));
|
|
|
userAreaDO.setTown(object.getString("town"));
|
|
|
userAreaDO.setTownName(object.getString("townName"));
|
|
|
if (!StringUtils.isEmpty(object.getString("hospital"))){
|
|
|
if (!StringUtils.isEmpty(object.getString("hospital"))) {
|
|
|
userAreaDO.setHospital(object.getString("hospital"));
|
|
|
userAreaDO.setHospitalName(object.getString("hospitalName"));
|
|
|
}
|
|
@ -503,9 +504,9 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
}
|
|
|
//用户所管设备添加
|
|
|
//equipment:[{"equipmentId":"","equipmentName":""}]
|
|
|
if (equipment!=null&&equipment.size()!=0){
|
|
|
if (equipment != null && equipment.size() != 0) {
|
|
|
userEquipmentDao.deleteByUserId(userDO.getId());
|
|
|
for (int i=0;i<equipment.size();i++){
|
|
|
for (int i = 0; i < equipment.size(); i++) {
|
|
|
JSONObject object = equipment.getJSONObject(i);
|
|
|
WlyyUserEquipmentDO userEquipmentDO = new WlyyUserEquipmentDO();
|
|
|
userEquipmentDO.setDel(1);
|
|
@ -514,7 +515,7 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
userEquipmentDO.setCityName(object.getString("cityName"));
|
|
|
userEquipmentDO.setTown(object.getString("town"));
|
|
|
userEquipmentDO.setTownName(object.getString("townName"));
|
|
|
if (!StringUtils.isEmpty(object.getString("hospital"))){
|
|
|
if (!StringUtils.isEmpty(object.getString("hospital"))) {
|
|
|
userEquipmentDO.setHospital(object.getString("hospital"));
|
|
|
userEquipmentDO.setHospitalName(object.getString("hospitalName"));
|
|
|
}
|
|
@ -533,22 +534,23 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
|
|
|
/**
|
|
|
* 获取单个用户信息
|
|
|
*
|
|
|
* @param userId 用户id
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getOneUserInfo(String userId) throws Exception{
|
|
|
public JSONObject getOneUserInfo(String userId) throws Exception {
|
|
|
JSONObject result = new JSONObject();
|
|
|
if(StringUtils.isEmpty(userId)){
|
|
|
result.put("msg","parameter userId is null ");
|
|
|
result.put("response",ConstantUtils.FAIL);
|
|
|
if (StringUtils.isEmpty(userId)) {
|
|
|
result.put("msg", "parameter userId is null ");
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//用户基本信息
|
|
|
UserDO user = userDao.findOne(userId);
|
|
|
if(null == user){
|
|
|
result.put("msg","User not exist for id:" + userId);
|
|
|
result.put("response",ConstantUtils.FAIL);
|
|
|
if (null == user) {
|
|
|
result.put("msg", "User not exist for id:" + userId);
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
return result;
|
|
|
}
|
|
|
//用户角色
|
|
@ -561,31 +563,32 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
List<WlyyUserEquipmentDO> userEquipmentDOList = userEquipmentDao.findAllByUserId(userId);
|
|
|
|
|
|
//用户关联的机构
|
|
|
List<BaseOrgUserDO> orgList = baseOrgUserService.findAllByUserId(user.getId());
|
|
|
List<BaseOrgUserDO> orgList = baseOrgUserService.findAllByUserId(user.getId());
|
|
|
JSONObject userInfo = new JSONObject();
|
|
|
userInfo.put("user",user);
|
|
|
userInfo.put("role",roleDO);
|
|
|
userInfo.put("userArea",userAreaDOList);
|
|
|
userInfo.put("userEquipment",userEquipmentDOList);
|
|
|
userInfo.put("org",orgList);
|
|
|
result.put("response",ConstantUtils.SUCCESS);
|
|
|
result.put("msg",userInfo);
|
|
|
userInfo.put("user", user);
|
|
|
userInfo.put("role", roleDO);
|
|
|
userInfo.put("userArea", userAreaDOList);
|
|
|
userInfo.put("userEquipment", userEquipmentDOList);
|
|
|
userInfo.put("org", orgList);
|
|
|
result.put("response", ConstantUtils.SUCCESS);
|
|
|
result.put("msg", userInfo);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 租户只能给用户归属到自己租户底下的机构
|
|
|
* 机构管理员只能属于一个租户
|
|
|
*
|
|
|
* @param saasid
|
|
|
* @param userId
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject generateUserOrgTree(String saasid,String userId,String roleId) throws IOException {
|
|
|
public JSONObject generateUserOrgTree(String saasid, String userId, String roleId) throws IOException {
|
|
|
JSONObject result = new JSONObject();
|
|
|
List<OrgTree> orgList = new ArrayList<>();
|
|
|
// 有归属租户加载saas底下的所有机构树列表,角色为机构管理员时不需要选管理机构
|
|
|
String admin ="admin";
|
|
|
if(!StringUtils.isEmpty(saasid) && !StringUtils.endsWithIgnoreCase(admin,roleId)){
|
|
|
String admin = "admin";
|
|
|
if (!StringUtils.isEmpty(saasid) && !StringUtils.endsWithIgnoreCase(admin, roleId)) {
|
|
|
StringBuilder sql = new StringBuilder("SELECT " +
|
|
|
" tree.* " +
|
|
|
" FROM " +
|
|
@ -597,12 +600,12 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
" and saas.saasid = '{saasid}' " +
|
|
|
" and (tree.code = org.code or tree.code = org.province_code or tree.code = org.city_code or tree.code = town_code) " +
|
|
|
" ORDER BY tree.name;");
|
|
|
orgList = jdbcTemplate.query(sql.toString().replace("{saasid}",saasid),new BeanPropertyRowMapper(OrgTree.class));
|
|
|
orgList = jdbcTemplate.query(sql.toString().replace("{saasid}", saasid), new BeanPropertyRowMapper(OrgTree.class));
|
|
|
}
|
|
|
if(!StringUtils.isEmpty(userId)){// 用户不为空表示修改,需要筛选出用户已经选择过的机构,设置checked为true
|
|
|
if (!StringUtils.isEmpty(userId)) {// 用户不为空表示修改,需要筛选出用户已经选择过的机构,设置checked为true
|
|
|
Set<String> codeSet = baseOrgUserService.findorgCodeListByUserId(userId);
|
|
|
orgList.forEach( one -> {
|
|
|
if(codeSet.contains(one.getCode())){
|
|
|
orgList.forEach(one -> {
|
|
|
if (codeSet.contains(one.getCode())) {
|
|
|
one.setChecked(true);
|
|
|
}
|
|
|
});
|
|
@ -619,11 +622,11 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
orgList = jdbcTemplate.query(sql.toString().replace("{userId}",userId),new BeanPropertyRowMapper(OrgTree.class));*/
|
|
|
}
|
|
|
|
|
|
if(!CollectionUtils.isEmpty(orgList)){
|
|
|
String tree = orgTreeService.makeTree(orgList,false,true);
|
|
|
result.put("msg",objectMapper.readValue(tree,JSONArray.class));
|
|
|
}else{
|
|
|
result.put("msg",orgList);
|
|
|
if (!CollectionUtils.isEmpty(orgList)) {
|
|
|
String tree = orgTreeService.makeTree(orgList, false, true);
|
|
|
result.put("msg", objectMapper.readValue(tree, JSONArray.class));
|
|
|
} else {
|
|
|
result.put("msg", orgList);
|
|
|
}
|
|
|
result.put("response", ConstantUtils.SUCCESS);
|
|
|
return result;
|
|
@ -632,34 +635,35 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
/**
|
|
|
* 租户只能给用户归属到自己租户底下的机构
|
|
|
* 机构管理员只能属于一个租户,增加社区树
|
|
|
*
|
|
|
* @param saasid
|
|
|
* @param userId
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject orgChoiceInfo(String saasid,String userId,String roleId) throws IOException {
|
|
|
public JSONObject orgChoiceInfo(String saasid, String userId, String roleId) throws IOException {
|
|
|
JSONObject result = new JSONObject();
|
|
|
List<OrgTree> orgList = new ArrayList<>();
|
|
|
String admin = "admin";
|
|
|
// 有归属租户加载saas底下的所有机构树列表,角色为机构管理员时不需要选管理机构
|
|
|
if(!StringUtils.isEmpty(saasid) && !StringUtils.endsWithIgnoreCase(admin,roleId)){
|
|
|
if (!StringUtils.isEmpty(saasid) && !StringUtils.endsWithIgnoreCase(admin, roleId)) {
|
|
|
StringBuilder sql = new StringBuilder("SELECT tree.* FROM org_tree tree, base_org org, base_org_saas saas WHERE org.code = saas.org_code and 'null'= '{saasid}';");
|
|
|
// StringBuilder sql = new StringBuilder("SELECT tree.* FROM base_org base , org_tree tree WHERE base.`code` = tree.code ");
|
|
|
orgList = jdbcTemplate.query(sql.toString().replace("{saasid}","null"),new BeanPropertyRowMapper(OrgTree.class));
|
|
|
// StringBuilder sql = new StringBuilder("SELECT tree.* FROM base_org base , org_tree tree WHERE base.`code` = tree.code ");
|
|
|
orgList = jdbcTemplate.query(sql.toString().replace("{saasid}", "null"), new BeanPropertyRowMapper(OrgTree.class));
|
|
|
}
|
|
|
if(!StringUtils.isEmpty(userId)){// 用户不为空表示修改,需要筛选出用户已经选择过的机构,设置checked为true
|
|
|
if (!StringUtils.isEmpty(userId)) {// 用户不为空表示修改,需要筛选出用户已经选择过的机构,设置checked为true
|
|
|
Set<String> codeSet = baseOrgUserService.findorgCodeListByUserId(userId);
|
|
|
orgList.forEach( one -> {
|
|
|
if(codeSet.contains(one.getCode())){
|
|
|
orgList.forEach(one -> {
|
|
|
if (codeSet.contains(one.getCode())) {
|
|
|
one.setChecked(true);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if(!CollectionUtils.isEmpty(orgList)){
|
|
|
String tree = orgTreeService.makeTree(orgList,false,true);
|
|
|
result.put("msg",objectMapper.readValue(tree,JSONArray.class));
|
|
|
}else{
|
|
|
result.put("msg",orgList);
|
|
|
if (!CollectionUtils.isEmpty(orgList)) {
|
|
|
String tree = orgTreeService.makeTree(orgList, false, true);
|
|
|
result.put("msg", objectMapper.readValue(tree, JSONArray.class));
|
|
|
} else {
|
|
|
result.put("msg", orgList);
|
|
|
}
|
|
|
result.put("response", ConstantUtils.SUCCESS);
|
|
|
return result;
|
|
@ -668,28 +672,29 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
|
|
|
/**
|
|
|
* 用户修改密码
|
|
|
*
|
|
|
* @param userId
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject updatePwd(String userId,String pwd,String oldpwd){
|
|
|
public JSONObject updatePwd(String userId, String pwd, String oldpwd) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
UserDO user = userDao.findOne(userId);
|
|
|
if(null == user){
|
|
|
if (null == user) {
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
result.put("msg","user not exist for id : " + userId);
|
|
|
result.put("msg", "user not exist for id : " + userId);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
String orgPwMd5 = MD5.md5Hex(oldpwd + "{" + user.getSalt() + "}");
|
|
|
if(!orgPwMd5.equals(user.getPassword())){
|
|
|
if (!orgPwMd5.equals(user.getPassword())) {
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
result.put("msg","旧密码不正确!");
|
|
|
result.put("msg", "旧密码不正确!");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isEmpty(pwd)){
|
|
|
if (StringUtils.isEmpty(pwd)) {
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
result.put("msg","新密码不能为空!");
|
|
|
result.put("msg", "新密码不能为空!");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@ -700,68 +705,69 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
user.setPassword(MD5.md5Hex(pwd + "{" + user.getSalt() + "}"));
|
|
|
userDao.save(user);
|
|
|
|
|
|
result.put("response",ConstantUtils.SUCCESS);
|
|
|
result.put("response", ConstantUtils.SUCCESS);
|
|
|
result.put("msg", "修改成功");
|
|
|
|
|
|
|
|
|
//设置用户密码过期时间
|
|
|
saveUserPwlimitDate(userId);
|
|
|
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public boolean saveUserPwlimitDate(String user){
|
|
|
|
|
|
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());
|
|
|
valueJson.put("updateTime", new Date().getTime());
|
|
|
valueJson.put("isChanged", true);
|
|
|
redisTemplate.opsForValue().set(key, valueJson.toJSONString());
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 用户重置密码
|
|
|
*
|
|
|
* @param userId
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject resetPassword(String userId){
|
|
|
public JSONObject resetPassword(String userId) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
UserDO user = userDao.findOne(userId);
|
|
|
if(null == user){
|
|
|
if (null == user) {
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
result.put("msg","user not exist for id : " + userId);
|
|
|
result.put("msg", "user not exist for id : " + userId);
|
|
|
return result;
|
|
|
}
|
|
|
// registerWithIdcard(user);
|
|
|
String idcard = user.getIdcard();
|
|
|
String mobile = user.getMobile();
|
|
|
String password = null;
|
|
|
|
|
|
if(!StringUtils.isEmpty(password)&&idcard.length()>10){
|
|
|
password = idcard.substring(idcard.length()-6,idcard.length());
|
|
|
}else if(!StringUtils.isEmpty(mobile)&&mobile.length()>=11){
|
|
|
password = mobile.substring(mobile.length()-6,mobile.length());
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isEmpty(password)){
|
|
|
|
|
|
if (!StringUtils.isEmpty(password) && idcard.length() > 10) {
|
|
|
password = idcard.substring(idcard.length() - 6, idcard.length());
|
|
|
} else if (!StringUtils.isEmpty(mobile) && mobile.length() >= 11) {
|
|
|
password = mobile.substring(mobile.length() - 6, mobile.length());
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isEmpty(password)) {
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
|
|
|
user.setSalt(randomString(5));
|
|
|
user.setEnabled(true);
|
|
|
user.setLocked(false);
|
|
|
user.setLoginFailureCount(0);
|
|
|
if ("iottest".equals(springProfile)||//物联网
|
|
|
"iotprod".equals(springProfile)||//物联网
|
|
|
"iotprodIn".equals(springProfile)//物联网
|
|
|
if ("iottest".equals(springProfile) ||//物联网
|
|
|
"iotprod".equals(springProfile) ||//物联网
|
|
|
"iotprodIn".equals(springProfile)//物联网
|
|
|
) {
|
|
|
password = "a"+password+"*";
|
|
|
password = "a" + password + "*";
|
|
|
}
|
|
|
user.setPassword(MD5.md5Hex(password + "{" + user.getSalt() + "}"));
|
|
|
userDao.save(user);
|
|
|
saveUserPwlimitDate(userId);
|
|
|
result.put("response",ConstantUtils.SUCCESS);
|
|
|
result.put("response", ConstantUtils.SUCCESS);
|
|
|
result.put("msg", password);
|
|
|
return result;
|
|
|
}
|
|
@ -769,11 +775,12 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
|
|
|
/**
|
|
|
* 判断用户账号是否存在
|
|
|
*
|
|
|
* @param code
|
|
|
* @return
|
|
|
*/
|
|
|
public Boolean existUsername(String code){
|
|
|
if(StringUtils.isEmpty(code)) {
|
|
|
public Boolean existUsername(String code) {
|
|
|
if (StringUtils.isEmpty(code)) {
|
|
|
return null;
|
|
|
}
|
|
|
return userDao.existsByUsername(code);
|
|
@ -782,58 +789,61 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
|
|
|
/**
|
|
|
* 生效或失效单个用户
|
|
|
*
|
|
|
* @param userId
|
|
|
* @param lock
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject lockOrUnlocakUser(String userId,boolean lock){
|
|
|
public JSONObject lockOrUnlocakUser(String userId, boolean lock) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
if(StringUtils.isEmpty(userId) || StringUtils.isEmpty(lock)){
|
|
|
result.put("msg","parameter id or del is null");
|
|
|
result.put("response",ConstantUtils.FAIL);
|
|
|
if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(lock)) {
|
|
|
result.put("msg", "parameter id or del is null");
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
return result;
|
|
|
}
|
|
|
UserDO user = userDao.findOne(userId);
|
|
|
if( null == user ){
|
|
|
result.put("msg","user not exist for id:" + userId);
|
|
|
result.put("response",ConstantUtils.FAIL);
|
|
|
if (null == user) {
|
|
|
result.put("msg", "user not exist for id:" + userId);
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
return result;
|
|
|
}
|
|
|
user.setLocked(lock);
|
|
|
user.setLockedDate(new Date());
|
|
|
this.save(user);
|
|
|
result.put("response",ConstantUtils.SUCCESS);
|
|
|
result.put("response", ConstantUtils.SUCCESS);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 生效或失效单个用户
|
|
|
*
|
|
|
* @param userId
|
|
|
* @param lock
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject enableOrDisable(String userId,boolean lock){
|
|
|
public JSONObject enableOrDisable(String userId, boolean lock) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
if(StringUtils.isEmpty(userId) || StringUtils.isEmpty(lock)){
|
|
|
result.put("msg","parameter id or del is null");
|
|
|
result.put("response",ConstantUtils.FAIL);
|
|
|
if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(lock)) {
|
|
|
result.put("msg", "parameter id or del is null");
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
return result;
|
|
|
}
|
|
|
UserDO user = userDao.findOne(userId);
|
|
|
if( null == user ){
|
|
|
result.put("msg","user not exist for id:" + userId);
|
|
|
result.put("response",ConstantUtils.FAIL);
|
|
|
if (null == user) {
|
|
|
result.put("msg", "user not exist for id:" + userId);
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
return result;
|
|
|
}
|
|
|
user.setEnabled(lock);
|
|
|
this.save(user);
|
|
|
result.put("response",ConstantUtils.SUCCESS);
|
|
|
result.put("response", ConstantUtils.SUCCESS);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 用户信息列表
|
|
|
*
|
|
|
* @param name
|
|
|
* @param saasid
|
|
|
* @param roleId
|
|
@ -842,7 +852,7 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public JSONObject userInfoList(String name,String saasid,String roleId,int page,int size,String wechatId) throws Exception {
|
|
|
public JSONObject userInfoList(String name, String saasid, String roleId, int page, int size, String wechatId) throws Exception {
|
|
|
JSONObject result = new JSONObject();
|
|
|
/* int start = 0 == page ? page++ : (page - 1) * size;
|
|
|
int end = 0 == size ? 15 : page * size;*/
|
|
@ -899,7 +909,7 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
// result.put("msg", JavaBeanUtils.getInstance().mapListJson(list));
|
|
|
|
|
|
|
|
|
String finalSql="SELECT\n" +
|
|
|
String finalSql = "SELECT\n" +
|
|
|
"\t\t\tusr . ID AS \"id\",\n" +
|
|
|
"\t\t\tusr . NAME AS \"realName\",\n" +
|
|
|
"\t\t\tusr .username AS \"username\",\n" +
|
|
@ -918,32 +928,32 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
"\t\tbase_role ROLE\n" +
|
|
|
"\tWHERE\n" +
|
|
|
"\t\tusr .saas_id = saas. ID\n" +
|
|
|
"\tAND usr .role_id = ROLE . ID\n" ;
|
|
|
if(!realName.equals(null) && !realName.equals("")){
|
|
|
finalSql = finalSql + " and usr . NAME LIKE '%"+realName+"%'";
|
|
|
}
|
|
|
if(!saasidValue.equals(null) && !saasidValue.equals("")){
|
|
|
finalSql = finalSql + " and saas. id = '"+saasidValue+"'";
|
|
|
}
|
|
|
if(!roleIdValue.equals(null) && !roleIdValue.equals("")){
|
|
|
finalSql = finalSql + " and usr .role_id = '"+roleIdValue+"'";
|
|
|
}
|
|
|
finalSql = finalSql + " ORDER BY usr .create_time DESC";
|
|
|
Logger.getAnonymousLogger().info("finalSql="+finalSql);
|
|
|
"\tAND usr .role_id = ROLE . ID\n";
|
|
|
if (!realName.equals(null) && !realName.equals("")) {
|
|
|
finalSql = finalSql + " and usr . NAME LIKE '%" + realName + "%'";
|
|
|
}
|
|
|
if (!saasidValue.equals(null) && !saasidValue.equals("")) {
|
|
|
finalSql = finalSql + " and saas. id = '" + saasidValue + "'";
|
|
|
}
|
|
|
if (!roleIdValue.equals(null) && !roleIdValue.equals("")) {
|
|
|
finalSql = finalSql + " and usr .role_id = '" + roleIdValue + "'";
|
|
|
}
|
|
|
finalSql = finalSql + " ORDER BY usr .create_time DESC";
|
|
|
Logger.getAnonymousLogger().info("finalSql=" + finalSql);
|
|
|
String sql = finalSql
|
|
|
.replace("{realName}","%" + realName + "%")
|
|
|
.replace("{saasid}",saasidValue)
|
|
|
.replace("{roleId}",roleIdValue);
|
|
|
.replace("{realName}", "%" + realName + "%")
|
|
|
.replace("{saasid}", saasidValue)
|
|
|
.replace("{roleId}", roleIdValue);
|
|
|
|
|
|
List<Map<String, Object>> list=null;
|
|
|
if ("xm_ykyy_wx".equalsIgnoreCase(wechatId)){
|
|
|
List<Map<String, Object>> list = null;
|
|
|
if ("xm_ykyy_wx".equalsIgnoreCase(wechatId)) {
|
|
|
|
|
|
if (flag){
|
|
|
sql+=" LIMIT " + (page - 1) * size + "," + size + "";
|
|
|
Logger.getAnonymousLogger().info("sql="+sql);
|
|
|
if (flag) {
|
|
|
sql += " LIMIT " + (page - 1) * size + "," + size + "";
|
|
|
Logger.getAnonymousLogger().info("sql=" + sql);
|
|
|
list = jdbcTemplate.queryForList(sql);
|
|
|
}else {
|
|
|
String oracleSql="SELECT\n" +
|
|
|
} else {
|
|
|
String oracleSql = "SELECT\n" +
|
|
|
"\t*\n" +
|
|
|
"FROM\n" +
|
|
|
"\t(\n" +
|
|
@ -952,21 +962,21 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
"\t\tFROM\n" +
|
|
|
"\t\t\t(";
|
|
|
|
|
|
oracleSql+=sql;
|
|
|
oracleSql += sql;
|
|
|
|
|
|
oracleSql+="\t\t\t) A\n" +
|
|
|
oracleSql += "\t\t\t) A\n" +
|
|
|
"\t\tWHERE\n" +
|
|
|
" ROWNUM <="+page*size +
|
|
|
" ROWNUM <=" + page * size +
|
|
|
"\t) \n" +
|
|
|
"WHERE\n" +
|
|
|
"\tROWNUM >= "+(page-1)*size;
|
|
|
Logger.getAnonymousLogger().info("oracleSql="+oracleSql);
|
|
|
"\tROWNUM >= " + (page - 1) * size;
|
|
|
Logger.getAnonymousLogger().info("oracleSql=" + oracleSql);
|
|
|
list = jdbcTemplate.queryForList(oracleSql);
|
|
|
}
|
|
|
|
|
|
}else {
|
|
|
sql+=" LIMIT " + (page - 1) * size + "," + size + "";
|
|
|
Logger.getAnonymousLogger().info("sql="+sql);
|
|
|
} else {
|
|
|
sql += " LIMIT " + (page - 1) * size + "," + size + "";
|
|
|
Logger.getAnonymousLogger().info("sql=" + sql);
|
|
|
list = jdbcTemplate.queryForList(sql);
|
|
|
}
|
|
|
|
|
@ -980,22 +990,22 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
|
|
|
"WHERE " +
|
|
|
" usr.saas_id = saas.id " +
|
|
|
" AND " +
|
|
|
" usr.role_id = role.id " ;
|
|
|
if(!realName.equals(null) && !realName.equals("")){
|
|
|
countSql = countSql + " and usr . NAME LIKE '%"+realName+"%'";
|
|
|
}
|
|
|
if(!saasidValue.equals(null) && !saasidValue.equals("")){
|
|
|
countSql = countSql + " and saas. id = '"+saasidValue+"'";
|
|
|
}
|
|
|
if(!roleIdValue.equals(null) && !roleIdValue.equals("")){
|
|
|
countSql = countSql + " and usr .role_id = '"+roleIdValue+"'";
|
|
|
}
|
|
|
Logger.getAnonymousLogger().info("countSql="+countSql);
|
|
|
" usr.role_id = role.id ";
|
|
|
if (!realName.equals(null) && !realName.equals("")) {
|
|
|
countSql = countSql + " and usr . NAME LIKE '%" + realName + "%'";
|
|
|
}
|
|
|
if (!saasidValue.equals(null) && !saasidValue.equals("")) {
|
|
|
countSql = countSql + " and saas. id = '" + saasidValue + "'";
|
|
|
}
|
|
|
if (!roleIdValue.equals(null) && !roleIdValue.equals("")) {
|
|
|
countSql = countSql + " and usr .role_id = '" + roleIdValue + "'";
|
|
|
}
|
|
|
Logger.getAnonymousLogger().info("countSql=" + countSql);
|
|
|
String finalCountSql = countSql
|
|
|
.replace("{realName}", "%" + realName + "%")
|
|
|
.replace("{saasid}", saasidValue )
|
|
|
.replace("{roleId}", roleIdValue );
|
|
|
Logger.getAnonymousLogger().info("finalCountSql="+finalCountSql);
|
|
|
.replace("{saasid}", saasidValue)
|
|
|
.replace("{roleId}", roleIdValue);
|
|
|
Logger.getAnonymousLogger().info("finalCountSql=" + finalCountSql);
|
|
|
Integer count = jdbcTemplate.queryForObject(finalCountSql, Integer.class);
|
|
|
result.put("count", count);
|
|
|
result.put("msg", JavaBeanUtils.getInstance().mapListJson(list));
|