|
@@ -1,27 +1,34 @@
|
|
package com.hb.proj.sys.service;
|
|
package com.hb.proj.sys.service;
|
|
|
|
|
|
-import com.hb.proj.model.RolePO;
|
|
|
|
-import com.hb.proj.model.RoleVO;
|
|
|
|
-import com.hb.proj.model.UserRolePO;
|
|
|
|
-import com.hb.xframework.dao.core.SpringJdbcDAO;
|
|
|
|
-import com.hb.xframework.dao.util.PageModel;
|
|
|
|
-import com.hb.xframework.dao.util.UUIDHexGenerator;
|
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
-import java.util.Date;
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.Set;
|
|
|
|
+
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import com.hb.proj.model.UserRolePO;
|
|
|
|
+import com.hb.xframework.dao.core.SpringJdbcDAO;
|
|
|
|
+import com.hb.xframework.dao.util.UUIDHexGenerator;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class UserRoleService {
|
|
public class UserRoleService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private SpringJdbcDAO dao;
|
|
private SpringJdbcDAO dao;
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private RoleService roleService;
|
|
private RoleService roleService;
|
|
|
|
+
|
|
|
|
+ public Set<String> loadByUserId(String userId){
|
|
|
|
+ Map<String,Object> mapping=dao.queryForMapping("select user_id,role_id from tsys_user_role where user_id=?","role_id", "user_id", userId);
|
|
|
|
+ if(mapping==null||mapping.size()==0) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ return mapping.keySet();
|
|
|
|
+ }
|
|
|
|
+
|
|
public List<String> queryByUserId(String userId) {
|
|
public List<String> queryByUserId(String userId) {
|
|
List<UserRolePO> list =dao.queryForList("select * from tsys_user_role where user_id=?",UserRolePO.class,userId);
|
|
List<UserRolePO> list =dao.queryForList("select * from tsys_user_role where user_id=?",UserRolePO.class,userId);
|
|
List<String> listS = new ArrayList<String>();
|
|
List<String> listS = new ArrayList<String>();
|
|
@@ -40,14 +47,23 @@ public class UserRoleService {
|
|
}
|
|
}
|
|
public String add(UserRolePO userRolePO) {
|
|
public String add(UserRolePO userRolePO) {
|
|
UUIDHexGenerator uuid=UUIDHexGenerator.getInstance();
|
|
UUIDHexGenerator uuid=UUIDHexGenerator.getInstance();
|
|
- userRolePO.setMidId(uuid.generate());
|
|
|
|
|
|
+ userRolePO.setUrId(uuid.generate());
|
|
dao.insert(userRolePO,"tsys_user_role");
|
|
dao.insert(userRolePO,"tsys_user_role");
|
|
- return userRolePO.getMidId();
|
|
|
|
|
|
+ return userRolePO.getUrId();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void add(String userId,Set<String> roleIds) {
|
|
|
|
+ dao.exeUpdate("delete from tsys_user_role where user_id=?",userId); //先清除旧的角色绑定
|
|
|
|
+ UUIDHexGenerator uuid=UUIDHexGenerator.getInstance();
|
|
|
|
+ for(String roleId : roleIds) {
|
|
|
|
+ dao.exeUpdate("insert into tsys_user_role(ur_id,user_id,role_id) values(?,?,?)", uuid.generate(),userId,roleId);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- public boolean delete(String midId) {
|
|
|
|
- String sql="delete from tsys_user_role where mid_id=?";
|
|
|
|
- dao.exeUpdate(sql,midId);
|
|
|
|
|
|
+ public boolean delete(String urId) {
|
|
|
|
+ String sql="delete from tsys_user_role where ur_id=?";
|
|
|
|
+ dao.exeUpdate(sql,urId);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
public boolean deleteByUserId(String userId) {
|
|
public boolean deleteByUserId(String userId) {
|