| 
					
				 | 
			
			
				@ -1,10 +1,19 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.base.service.user; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.fasterxml.jackson.databind.ObjectMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.base.dao.role.BaseRoleMenuDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.base.dao.role.RoleDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.base.dao.saas.SaasDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.base.dao.user.UserDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.base.service.org.BaseOrgSaasService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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.util.ConstantUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.base.util.JavaBeanUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.org.BaseOrgUserDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.role.RoleDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.saas.SaasDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.user.UserDO; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -12,13 +21,16 @@ import com.yihu.mysql.query.BaseJpaService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.utils.security.MD5; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.collections.map.HashedMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.BeanPropertyRowMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.JdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.util.CollectionUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.util.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Service - 后台管理员 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -38,6 +50,22 @@ public class UserService extends BaseJpaService<UserDO, UserDao> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private JdbcTemplate jdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private ObjectMapper objectMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseOrgUserService baseOrgUserService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private OrgTreeService orgTreeService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseOrgSaasService baseOrgSaasService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${configDefault.saasId}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String defaultSaasId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public UserDO registerWithIdcard(UserDO userDO) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        userDO.setSalt(randomString(5)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        userDO.setEnabled(true); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -53,6 +81,7 @@ public class UserService extends BaseJpaService<UserDO, UserDao> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 手机号作为账号,初始密码为手机号后6位 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param userDO 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -63,7 +92,7 @@ public class UserService extends BaseJpaService<UserDO, UserDao> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        userDO.setLoginFailureCount(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String password = userDO.getPassword(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isEmpty(password)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            password =  userDO.getMobile().substring(0, 5); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            password = userDO.getMobile().substring(0, 5); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        userDO.setPassword(MD5.md5Hex(password + "{" + userDO.getSalt() + "}")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return userDao.save(userDO); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -72,6 +101,7 @@ public class UserService extends BaseJpaService<UserDO, UserDao> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 根据用户手机号查找(手机号为登录账号) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param mobile 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -81,6 +111,7 @@ public class UserService extends BaseJpaService<UserDO, UserDao> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 根据id查找用户 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -90,11 +121,12 @@ public class UserService extends BaseJpaService<UserDO, UserDao> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 判断手机号是否存在 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param mobile 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Boolean existMobile(String mobile){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isEmpty(mobile)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Boolean existMobile(String mobile) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isEmpty(mobile)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return userDao.existsByMobile(mobile); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -114,80 +146,427 @@ public class UserService extends BaseJpaService<UserDO, UserDao> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 用户管理,获取用户基本信息列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param name 模糊查询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param name   模糊查询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param saasId 精准匹配,为空查全部 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param roleId 精准匹配,为空查全部 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public List<Map<String,Object>> queryBaseUserInfoList(String name,String saasId,String roleId){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String,Object>> result = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public List<Map<String, Object>> queryBaseUserInfoList(String name, String saasId, String roleId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> result = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Map<String,Object> findUserBaseInfo(String id){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Map<String, Object> findUserBaseInfo(String id) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String,Object> userinfo = new HashedMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String, Object> userinfo = new HashedMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        UserDO user = userDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        RoleDO role = roleDao.findByCode(user.getRoleCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(user!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            userinfo.put("id",user.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            userinfo.put("name",user.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        userinfo.put("id", user.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        userinfo.put("name", user.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        userinfo.put("role", role.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        userinfo.put("roleCode", role.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        userinfo.put("system", role.getSystem()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (user != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            userinfo.put("id", user.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            userinfo.put("name", user.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //获取角色 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        RoleDO role = roleDao.findOne(user.getRoleCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(role!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            userinfo.put("role",role.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            userinfo.put("roleCode",role.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            userinfo.put("system",role.getSystem()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if("admin".equals(role.getCode())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }else if("saasAdmin".equals(role.getCode())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(org.apache.commons.lang3.StringUtils.isNotBlank(user.getId())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    SaasDO saas = saasDao.findOne(user.getSaasId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Map<String,Object> ss = new HashedMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    ss.put("id",saas.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    ss.put("name",saas.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    userinfo.put("saas",ss); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (role != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            userinfo.put("role", role.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            userinfo.put("roleCode", role.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            userinfo.put("system", role.getSystem()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if ("admin".equals(role.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if ("admin".equals(role.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } else if ("saasAdmin".equals(role.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } else if ("saasAdmin".equals(role.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (org.apache.commons.lang3.StringUtils.isNotBlank(user.getId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        SaasDO saas = saasDao.findOne(user.getSaasId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Map<String, Object> ss = new HashedMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        ss.put("id", saas.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        ss.put("name", saas.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        userinfo.put("saas", ss); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (org.apache.commons.lang3.StringUtils.isNotBlank(user.getId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        SaasDO saas = saasDao.findOne(user.getSaasId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Map<String, Object> ss = new HashedMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        ss.put("id", saas.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        ss.put("name", saas.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        userinfo.put("saas", ss); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } else if ("hosAdmin".equals(role.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return userinfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }else if("hosAdmin".equals(role.getCode())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 创建用户 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param jsonData 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject createUser(String jsonData) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isEmpty(jsonData)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("msg", "parameter jsonData is null"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("response", ConstantUtils.FAIL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObject = JSONObject.parseObject(jsonData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject user = jsonObject.getJSONObject("user"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray org = jsonObject.getJSONArray("org"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //归属租户为默认租户,表示用户为超级管理员,不需要机构 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (null == user || CollectionUtils.isEmpty(org) && !user.getString("saasId").equalsIgnoreCase(defaultSaasId)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("msg", "parameter user or org of jsonData is null"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("response", ConstantUtils.FAIL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //组装用户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        UserDO userDO = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            userDO = objectMapper.readValue(user.toJSONString(), UserDO.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (IOException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("msg", "convert user jsonObject to UserDO failed," + e.getCause()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("response", ConstantUtils.FAIL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        registerWithIdcard(userDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //组装用户与机构的关联关系 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<BaseOrgUserDO> orgList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BaseOrgUserDO orgUserDO = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(!CollectionUtils.isEmpty(org)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (Object obj : org) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    orgUserDO = objectMapper.readValue(obj.toString(), BaseOrgUserDO.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    orgUserDO.setUserId(userDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    orgList.add(orgUserDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } catch (IOException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    result.put("msg", "convert org jsonObject to BaseOrgUserDO failed," + e.getCause()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    result.put("response", ConstantUtils.FAIL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            baseOrgUserService.batchInsert(orgList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject returnMsg = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        returnMsg.put("username",userDO.getUsername()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        returnMsg.put("password",userDO.getSalt()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("response", ConstantUtils.SUCCESS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("msg", returnMsg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 修改用户 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param jsonData 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject updateUser(String jsonData) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isEmpty(jsonData)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("msg", "parameter jsonData is null"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("response", ConstantUtils.FAIL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObject = JSONObject.parseObject(jsonData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject user = jsonObject.getJSONObject("user"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray org = jsonObject.getJSONArray("org"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (null == user ||  CollectionUtils.isEmpty(org) && !user.getString("saasId").equalsIgnoreCase(defaultSaasId)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("msg", "parameter user or org of jsonData is null"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("response", ConstantUtils.FAIL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //修改用户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        UserDO userDO = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            userDO = objectMapper.readValue(user.toJSONString(), UserDO.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            UserDO oldUser = userDao.findOne(userDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            userDO.setPassword(oldUser.getPassword()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (IOException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("msg", "convert user jsonObject to UserDO failed," + e.getCause()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("response", ConstantUtils.FAIL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        this.save(userDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (!CollectionUtils.isEmpty(org)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //修改用户机构关联关系 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Set<Object> roleIdList = baseOrgUserService.findIdListByUserId(userDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            BaseOrgUserDO orgUserDO = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                for (Object obj : org) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    orgUserDO = objectMapper.readValue(obj.toString(), BaseOrgUserDO.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    orgUserDO.setUserId(userDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (roleIdList.contains(orgUserDO.getId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        roleIdList.remove(orgUserDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    orgUserDO.setUserId(userDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    baseOrgUserService.save(orgUserDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } catch (IOException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                result.put("msg", "convert org jsonObject to BaseOrgUserDO failed," + e.getCause()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                result.put("response", ConstantUtils.FAIL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 表示没有删除,只有修改 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (roleIdList.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                baseOrgUserService.delete(roleIdList.toArray()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return userinfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("response", ConstantUtils.SUCCESS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("msg", userDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    public Map<String,Object> findUserMenu(String id){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取单个用户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param userId 用户id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //用户基本信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        UserDO user = userDao.findOne(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(null == user){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("msg","User not exist for id:" + userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("response",ConstantUtils.FAIL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("response",ConstantUtils.SUCCESS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("msg",user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 租户只能给用户归属到自己租户底下的机构 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 机构管理员只能属于一个租户 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param saasid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param userId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject generateUserOrgTree(String saasid,String userId,String roleCode) throws IOException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<OrgTree> orgList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 有归属租户加载saas底下的所有机构树列表,角色为机构管理员时不需要选管理机构 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(!StringUtils.isEmpty(saasid) && !StringUtils.endsWithIgnoreCase(RoleDO.BaseRoleType.admin.toString(),roleCode)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            StringBuilder sql = new StringBuilder("SELECT " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "  tree.* " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    " FROM " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "  org_tree tree, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "  base_org org, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "  base_org_saas saas " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    " WHERE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "  org.code = saas.org_code " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    " 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)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else if(!StringUtils.isEmpty(userId)){// 用户不为空表示修改,需要筛选出用户已经选择过的机构,设置checked为true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Set<String> codeSet = baseOrgUserService.findorgCodeListByUserId(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            orgList.forEach( one -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(codeSet.contains(one.getCode())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    one.setChecked(true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          /*  StringBuilder sql = new StringBuilder("SELECT tree.* " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "FROM " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "  org_tree tree, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "  base_org org, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "  base_org_user user " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "WHERE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "  org.code = user.org_code " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "  AND user.user_id = '{userId}' " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "  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("{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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("response", ConstantUtils.SUCCESS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 用户重置密码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param userId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject resetPassword(String userId){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        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; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        registerWithIdcard(user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("response",ConstantUtils.SUCCESS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("msg", user.getSalt()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 判断用户账号是否存在 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Boolean existUsername(String code){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isEmpty(code)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return userDao.existsByUsername(code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 生效或失效单个用户 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param userId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param lock 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        UserDO user = userDao.findOne(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 用户信息列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param saasid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param roleCode 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param page 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param size 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject userInfoList(String name,String saasid,String roleCode,int page,int size) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int start = 0 == page ? page++ : (page - 1) * size; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int end = 0 == size ? 15 : page * size; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String realName = null == name ? "" : name; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String saasidValue = null == saasid ? "" : saasid; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String roleCodeValue = null == roleCode ? "" : roleCode; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "SELECT " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  user.id as id, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  user.name as realName, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  user.username as username, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  case user.locked when 0 then '已失效' when 1 then '生效中' end status, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  user.mobile, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  saas.name as saasName, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  role.name as roleName " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " FROM " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  base_user user, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  base_saas saas, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  base_role role " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " WHERE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  user.saas_id = saas.id " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  AND " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  user.role_code = role.code " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " and (user.name like '{realName}' or '' ='{realName}') " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  and (saas.id = '{saasid}' or '' = '{saasid}') " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  and ( user.role_code = '{roleCode}' or '' = '{roleCode}') " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " ORDER BY user.create_time DESC" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  limit {start},{end} "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String finalSql = sql 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                .replace("{realName}","%" + realName + "%") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                .replace("{saasid}",saasidValue) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                .replace("{roleCode}",roleCodeValue) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                .replace("{start}",String.valueOf(start)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                .replace("{end}",String.valueOf(end)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String countSql = "SELECT " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  count(user.id) " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "FROM " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  base_user user, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  base_saas saas, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  base_role role " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "WHERE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  user.saas_id = saas.id " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  AND " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  user.role_code = role.code " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " and (user.name like '{realName}' or '' ='{realName}') " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  and (saas.id = '{saasid}' or '' = '{saasid}') " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  and ( user.role_code = '{roleCode}' or '' = '{roleCode}') "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String finalCountSql = countSql 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                .replace("{realName}", "%" + realName + "%") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                .replace("{saasid}",  saasidValue ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                .replace("{roleCode}",  roleCodeValue ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> list = jdbcTemplate.queryForList(finalSql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer count = jdbcTemplate.queryForObject(finalCountSql, Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("count", count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("msg", JavaBeanUtils.getInstance().mapListJson(list)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |