|
@@ -7,11 +7,15 @@ import com.diagbot.entity.JWT;
|
|
import com.diagbot.entity.Organization;
|
|
import com.diagbot.entity.Organization;
|
|
import com.diagbot.entity.User;
|
|
import com.diagbot.entity.User;
|
|
import com.diagbot.entity.UserOrganization;
|
|
import com.diagbot.entity.UserOrganization;
|
|
|
|
+import com.diagbot.entity.UserRole;
|
|
|
|
+import com.diagbot.entity.wrapper.MenuWrapper;
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
import com.diagbot.exception.CommonException;
|
|
import com.diagbot.exception.CommonException;
|
|
import com.diagbot.exception.ServiceErrorCode;
|
|
import com.diagbot.exception.ServiceErrorCode;
|
|
|
|
+import com.diagbot.mapper.MenuMapper;
|
|
import com.diagbot.mapper.OrganizationMapper;
|
|
import com.diagbot.mapper.OrganizationMapper;
|
|
import com.diagbot.mapper.UserOrganizationMapper;
|
|
import com.diagbot.mapper.UserOrganizationMapper;
|
|
|
|
+import com.diagbot.mapper.UserRoleMapper;
|
|
import com.diagbot.service.impl.UserServiceImpl;
|
|
import com.diagbot.service.impl.UserServiceImpl;
|
|
import com.diagbot.util.BeanUtil;
|
|
import com.diagbot.util.BeanUtil;
|
|
import com.diagbot.util.ListUtil;
|
|
import com.diagbot.util.ListUtil;
|
|
@@ -51,6 +55,10 @@ public class UserFacade extends UserServiceImpl {
|
|
OrganizationMapper organizationMapper;
|
|
OrganizationMapper organizationMapper;
|
|
@Autowired
|
|
@Autowired
|
|
UserOrganizationMapper userOrganizationMapper;
|
|
UserOrganizationMapper userOrganizationMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ UserRoleMapper userRoleMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ MenuMapper menuMapper;
|
|
|
|
|
|
public User createUser(UserSaveVO userSaveVO){
|
|
public User createUser(UserSaveVO userSaveVO){
|
|
User user = new User();
|
|
User user = new User();
|
|
@@ -68,7 +76,27 @@ public class UserFacade extends UserServiceImpl {
|
|
PasswordEncoder passwordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
|
PasswordEncoder passwordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
|
String entryPassword= passwordEncoder.encode(user.getPassword());
|
|
String entryPassword= passwordEncoder.encode(user.getPassword());
|
|
user.setPassword(entryPassword);
|
|
user.setPassword(entryPassword);
|
|
- this.save(user);
|
|
|
|
|
|
+// this.save(user);
|
|
|
|
+
|
|
|
|
+ // 机构相关业务
|
|
|
|
+ doOrganization(userSaveVO, user);
|
|
|
|
+
|
|
|
|
+ //权限相关业务
|
|
|
|
+ doPermisson(userSaveVO, user);
|
|
|
|
+ return user;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //如果机构已存在,只要添加用户与机构的映射即可;如果机构不存在,先添加机构信息
|
|
|
|
+ public void doPermisson(UserSaveVO userSaveVO, User user) {
|
|
|
|
+ UserRole userRole = new UserRole();
|
|
|
|
+ userRole.setUserId(user.getId());
|
|
|
|
+ userRole.setRoleId(1L);
|
|
|
|
+ userRole.setGmtCreate(new Date());
|
|
|
|
+ userRoleMapper.insert(userRole);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //如果机构已存在,只要添加用户与机构的映射即可;如果机构不存在,先添加机构信息
|
|
|
|
+ public void doOrganization(UserSaveVO userSaveVO, User user) {
|
|
Map<String, Object> paramMap = new HashMap<>();
|
|
Map<String, Object> paramMap = new HashMap<>();
|
|
String name = userSaveVO.getOrganization();
|
|
String name = userSaveVO.getOrganization();
|
|
paramMap.put("name", name);
|
|
paramMap.put("name", name);
|
|
@@ -83,12 +111,12 @@ public class UserFacade extends UserServiceImpl {
|
|
} else {
|
|
} else {
|
|
orgId = list.get(0).getId();
|
|
orgId = list.get(0).getId();
|
|
}
|
|
}
|
|
|
|
+
|
|
UserOrganization userOrganization = new UserOrganization();
|
|
UserOrganization userOrganization = new UserOrganization();
|
|
userOrganization.setUserId(user.getId());
|
|
userOrganization.setUserId(user.getId());
|
|
userOrganization.setOrganizationId(orgId);
|
|
userOrganization.setOrganizationId(orgId);
|
|
userOrganization.setGmtCreate(new Date());
|
|
userOrganization.setGmtCreate(new Date());
|
|
userOrganizationMapper.insert(userOrganization);
|
|
userOrganizationMapper.insert(userOrganization);
|
|
- return user;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
//@Cacheable(value = "UserName", key = "'username:'+#p0")
|
|
//@Cacheable(value = "UserName", key = "'username:'+#p0")
|
|
@@ -111,13 +139,38 @@ public class UserFacade extends UserServiceImpl {
|
|
throw new CommonException(ServiceErrorCode.GET_TOKEN_FAIL);
|
|
throw new CommonException(ServiceErrorCode.GET_TOKEN_FAIL);
|
|
}
|
|
}
|
|
LoginDTO loginDTO=new LoginDTO();
|
|
LoginDTO loginDTO=new LoginDTO();
|
|
|
|
+ //添加用户
|
|
loginDTO.setUser(user);
|
|
loginDTO.setUser(user);
|
|
|
|
+ //添加token
|
|
loginDTO.setToken(jwt.getAccess_token());
|
|
loginDTO.setToken(jwt.getAccess_token());
|
|
|
|
+ //添加机构信息
|
|
Organization org = organizationMapper.getByUserId(user.getId());
|
|
Organization org = organizationMapper.getByUserId(user.getId());
|
|
loginDTO.setOrganization(org);
|
|
loginDTO.setOrganization(org);
|
|
|
|
+ //添加菜单信息
|
|
|
|
+ List<MenuWrapper> menuList = menuMapper.getByRole(user.getId());
|
|
|
|
+ getMenuStruct(menuList);
|
|
|
|
+ loginDTO.setMenuWrappers(menuList);
|
|
return RespDTO.onSuc(loginDTO);
|
|
return RespDTO.onSuc(loginDTO);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @Description: 递归获取菜单结构
|
|
|
|
+ * @Author: ztg
|
|
|
|
+ * @Date: 2018/9/14 13:56
|
|
|
|
+ */
|
|
|
|
+ public void getMenuStruct(List<MenuWrapper> menuList) {
|
|
|
|
+ for(MenuWrapper m : menuList) {
|
|
|
|
+ m.setSubMenuList(recursion(m));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<MenuWrapper> recursion(MenuWrapper m) {
|
|
|
|
+ List<MenuWrapper> subMenu = menuMapper.getSubMenuById(m.getId());
|
|
|
|
+ for (MenuWrapper sub : subMenu) {
|
|
|
|
+ sub.setSubMenuList(recursion(sub));
|
|
|
|
+ }
|
|
|
|
+ return subMenu;
|
|
|
|
+ }
|
|
|
|
|
|
public RespDTO resetPassword(String username, String password, String diffPassword) {
|
|
public RespDTO resetPassword(String username, String password, String diffPassword) {
|
|
if (StringUtil.isBlank(username)){
|
|
if (StringUtil.isBlank(username)){
|