Commit 661946b8 authored by zjy's avatar zjy

user/role

parent e45e826a
......@@ -6,10 +6,14 @@ import com.pangding.web.tright.dao.RoleDao;
import com.pangding.web.tright.dto.RoleDto;
import com.pangding.web.tright.service.RoleService;
import com.pangding.web.tright.vo.RoleVo;
import com.yanzuoguang.util.helper.CheckerHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/roles")
public class RoleController {
......@@ -25,9 +29,17 @@ public class RoleController {
*/
@RequestMapping(value = "/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object saveRole(@RequestBody RoleDto roleDto){
roleServiceImpl.saveRole(roleDto);
Result result = new Result(0,"SUCCESS",null);
return result;
String id = roleDto.getId();
String name = roleDto.getName();
if (roleServiceImpl.getRoleById(id) != null){
return new Result(4001, "该角色ID已存在", null);
}
if (roleServiceImpl.getRoleByName(name) != null){
return new Result(4001, "该角色名已存在", null);
}
roleServiceImpl.saveRole((RoleVo)roleDto);
roleServiceImpl.roleAndTright(roleDto);
return new Result(0,"SUCCESS",null);
}
/**
......@@ -37,7 +49,12 @@ public class RoleController {
*/
@RequestMapping(value = "/update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object updateRole(@RequestBody RoleDto roleDto){
roleServiceImpl.saveRole(roleDto);
RoleVo roleVo = roleDto;
if (!roleServiceImpl.checkNameExist(roleVo)){
return new Result(4001,"该角色名已存在",null);
}
roleServiceImpl.saveRole(roleVo);
roleServiceImpl.roleAndTright(roleDto);
Result result = new Result(0,"SUCCESS",null);
return result;
}
......@@ -48,8 +65,22 @@ public class RoleController {
*/
@RequestMapping(value = "/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object listRoles(){
Result result = new Result(0,"SUCCESS",null);
List<RoleVo> roleVoList = roleServiceImpl.getRoleVoList();
List<RoleDto> roleDtoList = new ArrayList(roleVoList.size());
if (roleVoList == null || roleVoList.size() == 0){
return new Result(0,"暂无角色信息",null);
}
for (RoleVo roleVo:roleVoList) {
List<String> trightIdList = roleServiceImpl.getTrightIdList(roleVo.getId());
List<String> trightNameList = new ArrayList(trightIdList.size());
for (String trightId:trightIdList) {
String trightName = roleServiceImpl.getTrightNameByTrightId(trightId);
trightNameList.add(trightName);
}
RoleDto roleDto = roleServiceImpl.makeRoleDto(roleVo,trightIdList,trightNameList);
roleDtoList.add(roleDto);
}
Result result = new Result(0,"SUCCESS",roleDtoList);
return result;
}
......@@ -61,9 +92,16 @@ public class RoleController {
* @return
*/
@RequestMapping(value = "/role", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object role(@PathVariable Long id){
RoleVo roleVo = roleDao.getById(id);
Result result = new Result(0,"SUCCESS",roleVo);
public Object role(@PathVariable String roleId){
RoleVo roleVo = roleServiceImpl.getRoleById(roleId);
List<String> trightIdList = roleServiceImpl.getTrightIdList(roleId);
List<String> trightNameList = new ArrayList(trightIdList.size());
for (String trightId:trightIdList) {
String trightName = roleServiceImpl.getTrightNameByTrightId(trightId);
trightNameList.add(trightName);
}
RoleDto roleDto = roleServiceImpl.makeRoleDto(roleVo,trightIdList,trightNameList);
Result result = new Result(0,"SUCCESS",roleDto);
return result;
}
......@@ -73,8 +111,10 @@ public class RoleController {
* @return
*/
@RequestMapping(value = "/delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object delete(@PathVariable Long id){
roleServiceImpl.deleteRole(id);
public Object delete(@PathVariable String roleId){
roleServiceImpl.deleteRole(roleId);
roleServiceImpl.deleteRoleUser(roleServiceImpl.getRoleUserPKByRoleId(roleId));
roleServiceImpl.deleteRoleTright(roleServiceImpl.getRoleTrightPKByRoleId(roleId));
Result result = new Result(0,"SUCCESS",null);
return result;
}
......
......@@ -8,6 +8,7 @@ import com.pangding.web.tright.currency.Result;
import com.pangding.web.tright.dao.TrightDao;
import com.pangding.web.tright.service.TrightService;
import com.pangding.web.tright.vo.TrightVo;
import org.bouncycastle.jcajce.provider.digest.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
......@@ -30,6 +31,9 @@ public class TrightController {
*/
@RequestMapping(value = "/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object saveTright(@RequestBody TrightVo trightVo){
if (!trightServiceImpl.checkValid(trightVo)){
return new Result(4001,"该权限不合法,请修改权限名或权限url",null);
}
trightServiceImpl.save(trightVo);
Result result = new Result(0,"SUCCESS",null);
return result;
......@@ -42,6 +46,9 @@ public class TrightController {
*/
@RequestMapping(value = "/update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object updateTright(@RequestBody TrightVo trightVo){
if (!trightServiceImpl.checkValid(trightVo)){
return new Result(4001,"该权限不合法,请修改权限名或权限url",null);
}
trightServiceImpl.update(trightVo);
Result result = new Result(0,"SUCCESS",null);
return result;
......
......@@ -16,7 +16,7 @@ import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("/user")
@RequestMapping(value = "/user")
public class UserController {
@Autowired
......@@ -30,13 +30,22 @@ public class UserController {
*/
@RequestMapping(value = "/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object saveUser(@RequestBody UserDto userDto){
//userDto.setPassword();
//检查用户是否存在
UserVo u = userServiceImpl.getUser(userDto);
//存在,直接返回
if (u != null) {
return new Result(4001,"该用户已存在",null);
//throw new IllegalArgumentException(userDto.getUserName() + "已存在");
}
UserVo userVo = userServiceImpl.saveUser(userDto);
Result result = new Result(0,"SUCCESS",userVo);
//不存在,保存用户信息
userDao.create(userDto);
if (userDto.getRoleIds()!=null&&userDto.getRoleIds().size()!=0){
userServiceImpl.userAndRole(userDto);
}
Result result = new Result(0,"SUCCESS",null);
return result;
}
......@@ -46,21 +55,11 @@ public class UserController {
* @return
*/
@RequestMapping(value = "/update", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object updateUser(){//@RequestBody UserDto userDto
UserDto userDto = new UserDto();
userDto.setTuId(11l);
List<Long> longs = new ArrayList<>();
longs.add(1l);
longs.add(11l);
longs.add(111l);
userDto.setRoleIds(longs);
userDto.setUserName("test11234111");
userDto.setPassword("12345612");
userDto.setPhoneNumber("123456789110");
userDto.setCreateTime(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
userDto.setCount(0);
UserVo userVo = userServiceImpl.updateUser(userDto);
Result result = new Result(0,"SUCCESS",userVo);
public Object updateUser(@RequestBody UserDto userDto){
UserVo u = userDto;
userDao.update(u);
userServiceImpl.userAndRole(userDto);
Result result = new Result(0,"SUCCESS",null);
return result;
}
......@@ -71,9 +70,22 @@ public class UserController {
@RequestMapping(value = "/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object listUsers(){
List<UserVo> userVoList = userServiceImpl.listUserVo();
List<UserDto> userDtoList = new ArrayList(userVoList.size());
for (int var1 = 0;var1 < userVoList.size();++var1){
UserVo userVo = userVoList.get(var1);
List<String> roleIdList = userServiceImpl.listRoleIdList(userVo);
List<String> roleList = new ArrayList(roleIdList.size());
for (int var2 = 0;var2 < roleIdList.size();++var2){
String role = userServiceImpl.getRoleByRoleId(roleIdList.get(var2));
roleList.add(role);
}
UserDto userDto = userServiceImpl.makeUserDto(userVo,roleIdList,roleList);
userDtoList.add(userDto);
}
Result result = new Result(0,"SUCCESS",null);
Result result = new Result(0,"SUCCESS",userDtoList);
return result;
}
......@@ -83,11 +95,20 @@ public class UserController {
* @return
*/
@RequestMapping(value = "/user", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object user(){//@PathVariable Long id
public Object user(String userId){//@PathVariable Long id
UserVo vo = userDao.load(null,UserVo.class);
//UserVo userVo = userDao.getById(id);
Result result = new Result(0,"SUCCESS",vo);
UserVo userVo = userServiceImpl.getUserById(userId);
if(userVo == null){
return new Result(4001,"该用户不存在",null);
}
List<String> roleIdList = userServiceImpl.listRoleIdList(userVo);
List<String> roleList = new ArrayList(roleIdList.size());
for (int var2 = 0;var2 < roleIdList.size();++var2){
String role = userServiceImpl.getRoleByRoleId(roleIdList.get(var2));
roleList.add(role);
}
UserDto userDto = userServiceImpl.makeUserDto(userVo,roleIdList,roleList);
Result result = new Result(0,"SUCCESS",userDto);
return result;
}
......
package com.pangding.web.tright.dao;
import com.pangding.web.tright.dto.RoleDto;
import com.pangding.web.tright.vo.RoleTrightRelation;
import com.pangding.web.tright.vo.RoleVo;
import com.yanzuoguang.dao.BaseDao;
import java.util.List;
public interface RoleDao {
public interface RoleDao extends BaseDao {
int save(RoleVo roleVo);
RoleVo getRoleById(String id);
RoleVo getRole(String name);
RoleVo getRoleByName(String name);
int update(RoleVo roleVo);
int deleteRole(Long id);
int checkNameExist(RoleVo roleVo);
int deleteRoleUser(Long roleId);
List<RoleVo> getRoleVoList();
RoleVo getById(Long id);
List<String> getTrightIdList(String roleId);
int deleteRoleTright(Long roleId);
String getTrightNameByTrightId(String trightId);
int saveRoleTright(Long roleId, List<Long> trights);
int update(RoleVo roleVo);
}
package com.pangding.web.tright.dao;
import com.yanzuoguang.dao.BaseDao;
public interface RoleTrightDao extends BaseDao {
String getPKByRoleId(String roleId);
}
package com.pangding.web.tright.dao;
import com.pangding.web.tright.vo.TrightVo;
import com.yanzuoguang.dao.BaseDao;
import java.util.List;
public interface TrightDao {
public interface TrightDao extends BaseDao {
int save(TrightVo trightVo);
int update(TrightVo trightVo);
int checkValid(TrightVo trightVo);
int deleteRoleTright(Long id);
......
package com.pangding.web.tright.dao;
import com.pangding.web.tright.dto.UserDto;
import com.pangding.web.tright.vo.UserRoleRelation;
import com.pangding.web.tright.vo.UserVo;
import com.yanzuoguang.dao.BaseDao;
......@@ -11,12 +12,16 @@ public interface UserDao extends BaseDao {
// int saveUser(UserVo userVo);
//
UserVo getUser(UserVo userVo);
//
// int update(UserVo userVo);
int deleteUserRole(UserRoleRelation userRoleRelation);
List<UserVo> listUserVo();
List<String> getRoleIdList(UserVo userVo);
int saveUserRoles(List<UserRoleRelation> userRoleRelations);
String getRoleByRoleId(String roleId);
// UserVo getById(Long id);
UserVo getUserById(String userId);
}
package com.pangding.web.tright.dao;
import com.yanzuoguang.dao.BaseDao;
public interface UserRoleDao extends BaseDao {
String getPKByRoleId(String roleId);
}
......@@ -9,48 +9,71 @@ import java.util.List;
@Component
public class RoleDaoImpl extends BaseDaoImpl implements RoleDao {
private static final String GET_ROLE_BY_ID = "GET_ROLE_BY_ID";
private static final String GET_ROLE_BY_NAME = "GET_ROLE_BY_NAME";
private static final String CHECK_NAME_EXIST = "CHECK_NAME_EXIST";
private static final String GET_ROLELIST = "GET_ROLEDTO_LIST";
private static final String GET_TRIGHTID_LIST = "GET_TRIGHTID_LIST";
private static final String GET_TRIGHTNAME_BY_TRIGHTID = "GET_TRIGHTNAME_BY_TRIGHTID";
@Override
public int save(RoleVo roleVo) {
return 0;
protected void init() {
register(RoleVo.class);
Table.add(GET_ROLE_BY_ID,"select r.* from pd_role r where 1=1")
.add("id","and r.id = ?");
Table.add(GET_ROLE_BY_NAME,"select r.* from pd_role r where 1=1")
.add("name","and r.name = ?");
Table.add(CHECK_NAME_EXIST,"select count(r.id) from pd_role r where 1=1")
.add("name","and r.name = ?")
.add("id","and r.id <> ?");
Table.add(GET_ROLELIST,"select * from pd_role where 1=1");
Table.add(GET_TRIGHTID_LIST,"select authority_id from pd_role_authority where 1=1")
.add("roleId","and role_id = ?");
Table.add(GET_TRIGHTNAME_BY_TRIGHTID,"select name from pd_authority where 1=1")
.add("trightId","and id = ?");
}
@Override
public RoleVo getRole(String name) {
return null;
public RoleVo getRoleById(String id) {
return this.queryFirst(RoleVo.class,GET_ROLE_BY_ID,id);
}
@Override
public int update(RoleVo roleVo) {
return 0;
public RoleVo getRoleByName(String name) {
return this.queryFirst(RoleVo.class,GET_ROLE_BY_NAME,name);
}
@Override
public int deleteRole(Long id) {
return 0;
public int checkNameExist(RoleVo roleVo) {
return this.queryFirst(int.class,CHECK_NAME_EXIST,roleVo);
}
@Override
public int deleteRoleUser(Long roleId) {
return 0;
public List<RoleVo> getRoleVoList() {
return this.query(RoleVo.class,GET_ROLELIST,null);
}
@Override
public RoleVo getById(Long id) {
return null;
public List<String> getTrightIdList(String roleId) {
return this.query(String.class,GET_TRIGHTID_LIST,roleId);
}
@Override
public int deleteRoleTright(Long roleId) {
return 0;
public String getTrightNameByTrightId(String trightId) {
return this.queryFirst(String.class,GET_TRIGHTNAME_BY_TRIGHTID,trightId);
}
@Override
public int saveRoleTright(Long roleId, List<Long> trights) {
public int update(RoleVo roleVo) {
return 0;
}
@Override
protected void init() {
}
}
package com.pangding.web.tright.dao.impl;
import com.pangding.web.tright.dao.RoleTrightDao;
import com.pangding.web.tright.vo.RoleTrightRelation;
import com.yanzuoguang.dao.Impl.BaseDaoImpl;
import org.springframework.stereotype.Component;
@Component
public class RoleTrightDaoImpl extends BaseDaoImpl implements RoleTrightDao {
private static final String GET_PK_BY_ROLEID = "GET_PK_BY_ROLEID";
@Override
protected void init() {
register(RoleTrightRelation.class);
Table.add(GET_PK_BY_ROLEID,"select id from pd_role_authority where 1=1")
.add("roleId","and role_id = ?");
}
@Override
public String getPKByRoleId(String roleId) {
return this.queryFirst(String.class,GET_PK_BY_ROLEID,roleId);
}
}
......@@ -8,14 +8,22 @@ import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class TrightDaoImpl extends BaseDaoImpl implements TrightDao {
private static final String CHECK_VALID = "CHECK_VALID";
@Override
public int save(TrightVo trightVo) {
return 0;
protected void init() {
register(TrightVo.class);
Table.add(CHECK_VALID,"select count(a.id) from pd_authority a where 1=1")
.add("name","and a.name = ?")
.add("url","and a.url = ?")
.add("id","and a.id <> ?");
}
@Override
public int update(TrightVo trightVo) {
return 0;
public int checkValid(TrightVo trightVo) {
return this.queryFirst(int.class,CHECK_VALID,trightVo);
}
@Override
......@@ -48,8 +56,5 @@ public class TrightDaoImpl extends BaseDaoImpl implements TrightDao {
return null;
}
@Override
protected void init() {
}
}
package com.pangding.web.tright.dao.impl;
import com.pangding.web.tright.dao.UserDao;
import com.pangding.web.tright.dto.UserDto;
import com.pangding.web.tright.vo.UserRoleRelation;
import com.pangding.web.tright.vo.UserVo;
import com.yanzuoguang.dao.DaoConst;
......@@ -12,53 +13,40 @@ import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@Component
public class UserDaoImpl extends BaseDaoImpl implements UserDao {
final String GET_USER = "GET_USER";
final String DELETE_USER_ROLE="deleteUserRole";
final String SAVE_USER_ROLE = "saveUserRoles";
// @Override
// public int saveUser(UserVo userVo) {
//
// String s = this.saveWith(userVo.getClass(),"insert into ",null);
// System.out.println(s);
// return 0;
// }
//
//
// @Override
// public int update(UserVo userVo) {
// return 0;
// }
//
// @Override
// public int deleteUserRole(Long userId) {
// return 0;
// }
//
// @Override
// public int saveUserRoles(Long userId, List<Long> roleIds) {
// return 0;
// }
//
// @Override
// public UserVo getById(Long id) {
// return null;
// }
//
private static final String GET_USER = "GET_USER";
private static final String DELETE_USER_ROLE="deleteUserRole";
private static final String SAVE_USER_ROLE = "saveUserRoles";
private static final String GET_ALL_USERS = "GET_ALL_USERS";
private static final String GET_ROLE_IDS = "GET_ROLE_IDS";
private static final String GET_USER_BY_ID = "GET_USER_BY_ID";
private static final String GET_ROLE_BY_ROLEID = "GET_ROLE_BY_ROLEID";
@Override
protected void init() {
register(UserVo.class);
Table.add(GET_USER, "SELECT p.* FROM pd_user p WHERE 1=1 ")
.add("username", " AND p.user_name = ?");
Table.add(GET_USER, "SELECT id,account,phone,status,remark,create_time,creator FROM pd_user WHERE 1=1 ")
.add("account", " AND account = ?");
Table.add(DELETE_USER_ROLE,"delete from pd_user_role_relation where 1=1")
.add("tu_id","and tu_id = ?");
.add("userId","and user_id = ?");
Table.add(GET_ALL_USERS,"select id,account,phone,status,remark,create_time,creator from pd_user where 1=1");
Table.add(GET_ROLE_IDS,"select role_id from pd_user_role where 1=1")
.add("userId","and user_id = ?");
Table.add(GET_USER_BY_ID,"select id,account,phone,status,remark,create_time,creator from pd_user where 1=1")
.add("userId","and user_id = ?");
Table.add(GET_ROLE_BY_ROLEID,"select name from pd_role where 1=1")
.add("roleId","and id = ?");
}
......@@ -67,22 +55,26 @@ public class UserDaoImpl extends BaseDaoImpl implements UserDao {
return this.queryFirst(UserVo.class, GET_USER, userVo);
}
@Override
public List<UserVo> listUserVo() {
return this.query(UserVo.class,GET_ALL_USERS,null);
}
@Override
public List<String> getRoleIdList(UserVo userVo) {
return this.query(String.class,GET_ROLE_IDS,userVo);
}
@Override
public int deleteUserRole(UserRoleRelation userRoleRelation) {
userRoleRelation.setTru_id(1l);
if (userRoleRelation.getTu_id()!=null) {
return this.updateSql(DELETE_USER_ROLE, userRoleRelation);
}else{
return 0;
}
public String getRoleByRoleId(String roleId) {
return this.queryFirst(String.class,GET_ROLE_BY_ROLEID,roleId);
}
@Override
public int saveUserRoles(List<UserRoleRelation> userRoleRelations) {
//this.create(userRoleRelations);
for (UserRoleRelation userRoleRelation : userRoleRelations) {
//this.save(userRoleRelation);
}
return 0;
public UserVo getUserById(String userId) {
return this.queryFirst(UserVo.class,GET_USER_BY_ID,userId);
}
}
package com.pangding.web.tright.dao.impl;
import com.pangding.web.tright.dao.UserRoleDao;
import com.pangding.web.tright.vo.UserRoleRelation;
import com.yanzuoguang.dao.Impl.BaseDaoImpl;
import org.springframework.stereotype.Component;
@Component
public class UserRoleDaoImpl extends BaseDaoImpl implements UserRoleDao {
private static final String GET_PK_BY_ROLEID = "GET_PK_BY_ROLEID";
@Override
protected void init() {
register(UserRoleRelation.class);
Table.add(GET_PK_BY_ROLEID,"select id from pd_user_role where 1=1")
.add("roleId","and role_id = ?");
}
@Override
public String getPKByRoleId(String roleId) {
return this.queryFirst(String.class,GET_PK_BY_ROLEID,roleId);
}
}
......@@ -6,13 +6,24 @@ import java.util.List;
public class RoleDto extends RoleVo {
private List<Long> trightIds;
private List<String> trightIds;
public List<Long> getTrightIds() {
private List<String> trightNames;
public List<String> getTrightIds() {
return trightIds;
}
public void setTrightIds(List<Long> trightIds) {
public void setTrightIds(List<String> trightIds) {
this.trightIds = trightIds;
}
public List<String> getTrightNames() {
return trightNames;
}
public void setTrightNames(List<String> trightNames) {
this.trightNames = trightNames;
}
}
......@@ -6,13 +6,23 @@ import java.util.List;
public class UserDto extends UserVo {
private List<Long> roleIds;
private List<String> roleIds;
public List<Long> getRoleIds() {
private List<String> roles;
public List<String> getRoleIds() {
return roleIds;
}
public void setRoleIds(List<Long> roleIds) {
public void setRoleIds(List<String> roleIds) {
this.roleIds = roleIds;
}
public List<String> getRoles() {
return roles;
}
public void setRoles(List<String> roles) {
this.roles = roles;
}
}
package com.pangding.web.tright.service;
import com.pangding.web.tright.dto.RoleDto;
import com.pangding.web.tright.vo.RoleVo;
import java.util.List;
public interface RoleService {
void saveRole(RoleDto roleDto);
void saveRole(RoleVo roleVo);
RoleVo getRoleById(String id);
RoleVo getRoleByName(String name);
void roleAndTright(RoleDto roleDto);
Boolean checkNameExist(RoleVo roleVo);
List<RoleVo> getRoleVoList();
List<String> getTrightIdList(String roleId);
String getTrightNameByTrightId(String trightId);
RoleDto makeRoleDto(RoleVo roleVo,List<String> trightIdList,List<String> trightNameList);
void deleteRole(String roleId);
void deleteRoleUser(String roleId);
void deleteRoleTright(String roleId);
String getRoleUserPKByRoleId(String roleId);
void deleteRole(Long id);
String getRoleTrightPKByRoleId(String roleId);
}
......@@ -8,4 +8,6 @@ public interface TrightService {
void update(TrightVo trightVo);
void delete(Long id);
Boolean checkValid(TrightVo trightVo);
}
......@@ -3,13 +3,24 @@ package com.pangding.web.tright.service;
import com.pangding.web.tright.dto.UserDto;
import com.pangding.web.tright.vo.UserVo;
public interface UserService {
import java.lang.reflect.Array;
import java.util.List;
UserVo saveUser(UserDto userDto);
public interface UserService {
UserVo updateUser(UserDto userDto);
void userAndRole(UserDto userDto);
UserVo getUser(UserVo userVo);
String passwordEncoder(String credentials, String salt);
List<UserVo> listUserVo();
List<String> listRoleIdList(UserVo userVo);
String getRoleByRoleId(String roleId);
UserDto makeUserDto(UserVo userVo,List<String> roleIdList,List<String> roleList);
UserVo getUserById(String userId);
}
package com.pangding.web.tright.service.impl;
import com.pangding.web.tright.dao.RoleDao;
import com.pangding.web.tright.dao.RoleTrightDao;
import com.pangding.web.tright.dao.UserRoleDao;
import com.pangding.web.tright.dto.RoleDto;
import com.pangding.web.tright.service.RoleService;
import com.pangding.web.tright.vo.RoleTrightRelation;
import com.pangding.web.tright.vo.RoleVo;
import com.pangding.web.tright.vo.UserRoleRelation;
import com.yanzuoguang.util.helper.CheckerHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Service
public class RoleServiceImpl implements RoleService {
@Autowired
RoleDao roleDao;
@Autowired
UserRoleDao userRoleDaoImpl;
@Autowired
RoleTrightDao roleTrightDaoImpl;
@Override
public void saveRole(RoleVo roleVo) {
roleDao.create(roleVo);
}
@Override
public RoleVo getRoleById(String id) {
return roleDao.getRoleById(id);
}
@Override
public RoleVo getRoleByName(String name) {
return roleDao.getRoleByName(name);
}
@Override
public void roleAndTright(RoleDto roleDto) {
List<String> trightIds = roleDto.getTrightIds();
for (String trightId : trightIds) {
RoleTrightRelation roleTrightRelation = new RoleTrightRelation();
roleTrightRelation.setTrightId(trightId);
roleTrightRelation.setRoleId(roleDto.getId());
roleTrightRelation.setId(UUID.randomUUID().toString());
roleTrightDaoImpl.create(roleTrightRelation);
}
}
@Override
public Boolean checkNameExist(RoleVo roleVo) {
if (roleDao.checkNameExist(roleVo) > 0){return false;}
return true;
}
@Override
public List<RoleVo> getRoleVoList() {
return roleDao.getRoleVoList();
}
@Override
public List<String> getTrightIdList(String roleId) {
return roleDao.getTrightIdList(roleId);
}
@Override
public String getTrightNameByTrightId(String trightId) {
return roleDao.getTrightNameByTrightId(trightId);
}
@Override
public void saveRole(RoleDto roleDto) {
RoleVo role = roleDto;
if (role.getTrId() != null) {// 修改
RoleVo r = roleDao.getRole(role.getRoleName());
if (r != null && r.getTrId() != role.getTrId()) {
throw new IllegalArgumentException(role.getRoleName() + "已存在");
}
roleDao.update(role);
} else {// 新增
RoleVo r = roleDao.getRole(role.getRoleName());
if (r != null) {
throw new IllegalArgumentException(role.getRoleName() + "已存在");
}
roleDao.save(role);
public RoleDto makeRoleDto(RoleVo roleVo, List<String> trightIdList, List<String> trightNameList) {
RoleDto roleDto = (RoleDto) roleVo;
roleDto.setTrightIds(trightIdList);
roleDto.setTrightNames(trightNameList);
return roleDto;
}
@Override
public void deleteRole(String roleId) {
roleDao.remove(roleId);
}
@Override
public void deleteRoleUser(String id) {
if (id != null && id != "") {
userRoleDaoImpl.remove(id);
}
saveRoleTright(role.getTrId(), roleDto.getTrightIds());
}
private void saveRoleTright(Long roleId, List<Long> trights) {
roleDao.deleteRoleTright(roleId);
trights.remove(0L);
if (!CollectionUtils.isEmpty(trights)) {
roleDao.saveRoleTright(roleId, trights);
@Override
public void deleteRoleTright(String id) {
if (id != null && id != "") {
roleTrightDaoImpl.remove(id);
}
}
@Override
public void deleteRole(Long id) {
roleDao.deleteRoleUser(id);
roleDao.deleteRole(id);
public String getRoleUserPKByRoleId(String roleId) {
return userRoleDaoImpl.getPKByRoleId(roleId);
}
@Override
public String getRoleTrightPKByRoleId(String roleId) {
return roleTrightDaoImpl.getPKByRoleId(roleId);
}
}
......@@ -13,7 +13,7 @@ public class TrightServiceImpl implements TrightService {
TrightDao trightDao;
@Override
public void save(TrightVo trightVo) {
trightDao.save(trightVo);
trightDao.create(trightVo);
}
@Override
......@@ -21,6 +21,13 @@ public class TrightServiceImpl implements TrightService {
trightDao.update(trightVo);
}
@Override
public Boolean checkValid(TrightVo trightVo) {
int checkResult = trightDao.checkValid(trightVo);
if(checkResult == 0){return true;}
else{return false;}
}
@Override
public void delete(Long id) {
trightDao.deleteRoleTright(id);
......
......@@ -11,6 +11,7 @@ import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Service
public class UserServiceImpl implements UserService {
......@@ -19,27 +20,27 @@ public class UserServiceImpl implements UserService {
UserDao userDao;
@Override
public UserVo saveUser(UserDto userDto) {
UserVo userVo = userDto;
userDao.create(userVo);
userAndRole(userDto);
return userVo;
}
private void saveUserRoles(List<UserRoleRelation> userRoleRelations) {
userDao.deleteUserRole(userRoleRelations.get(0));
if (!CollectionUtils.isEmpty(userRoleRelations)) {
userDao.saveUserRoles(userRoleRelations);
}
public List<UserVo> listUserVo() {
// return userDao.listUser();
return userDao.listUserVo();
}
@Override
public UserVo updateUser(UserDto userDto) {
userDao.update(userDto);
userAndRole(userDto);
return userDto;
public void userAndRole(UserDto userDto) {
List<String> roleIds = userDto.getRoleIds();//多个角色
for (String roleId : roleIds) {
UserRoleRelation userRoleRelation = new UserRoleRelation();
userRoleRelation.setRoleId(roleId);
userRoleRelation.setUserId(userDto.getId());
userRoleRelation.setId(UUID.randomUUID().toString());
userDao.create(userRoleRelation);
}
}
@Override
public UserVo getUser(UserVo userVo) {
return userDao.getUser(userVo);
......@@ -50,19 +51,26 @@ public class UserServiceImpl implements UserService {
return null;
}
private void userAndRole(UserDto userDto){
if (userDto.getRoleIds()!=null&&userDto.getRoleIds().size()!=0) {
List<Long> longs = userDto.getRoleIds();//多个角色
List<UserRoleRelation> userRoleRelations = new ArrayList<>();
//查询当前用户的ID
//UserVo userVo = userDao.getUser(userDto);
for (Long l : longs) {
UserRoleRelation userRoleRelation = new UserRoleRelation();
userRoleRelation.setTr_id(l);
userRoleRelation.setTu_id(userDto.getTuId());
userRoleRelations.add(userRoleRelation);
}
saveUserRoles(userRoleRelations);
}
@Override
public List<String> listRoleIdList(UserVo userVo) {
return userDao.getRoleIdList(userVo);
}
@Override
public UserDto makeUserDto(UserVo userVo, List<String> roleIdList, List<String> roleList) {
UserDto userDto = (UserDto) userVo;
userDto.setRoleIds(roleIdList);
userDto.setRoles(roleList);
return userDto;
}
@Override
public String getRoleByRoleId(String roleId) {
return userDao.getRoleByRoleId(roleId);
}
@Override
public UserVo getUserById(String userId) {
return userDao.getUserById(userId);
}
}
package com.pangding.web.tright.vo;
import com.yanzuoguang.dao.TableAnnotation;
import java.io.Serializable;
@TableAnnotation("pd_role_authority")
public class RoleTrightRelation implements Serializable {
/*主键id*/
private String id;
@TableAnnotation("role_id")
/*角色id*/
private String roleId;
/*权限id*/
@TableAnnotation("authority_id")
private String trightId;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getRoleId() {
return roleId;
}
public void setRoleId(String roleId) {
this.roleId = roleId;
}
public String getTrightId() {
return trightId;
}
public void setTrightId(String trightId) {
this.trightId = trightId;
}
}
......@@ -7,49 +7,45 @@ import java.util.Date;
@TableAnnotation("pd_role")
public class RoleVo implements Serializable {
private Long trId;//主键ID
private Long parentTrId;//角色父ID
private String roleName;//角色名
private Date createTime;//创建时间
private String describe;//描述
public Long getTrId() {
return trId;
}
private String id;//主键id
public void setTrId(Long trId) {
this.trId = trId;
}
private String pid;//父角色id
private String name;//角色名
public Long getParentTrId() {
return parentTrId;
private String remark;//描述
public String getId() {
return id;
}
public void setParentTrId(Long parentTrId) {
this.parentTrId = parentTrId;
public void setId(String id) {
this.id = id;
}
public String getRoleName() {
return roleName;
public String getPid() {
return pid;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
public void setPid(String pid) {
this.pid = pid;
}
public Date getCreateTime() {
return createTime;
public String getName() {
return name;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
public void setName(String name) {
this.name = name;
}
public String getDescribe() {
return describe;
public String getRemark() {
return remark;
}
public void setDescribe(String describe) {
this.describe = describe;
public void setRemark(String remark) {
this.remark = remark;
}
}
package com.pangding.web.tright.vo;
import com.yanzuoguang.dao.TableAnnotation;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.vo.InitDao;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* 权限表
*/
@TableAnnotation("pd_tright")
public class TrightVo implements Serializable {
private Long trId;//权限ID
private Long sysId;//系统ID
private Long moduleId;//上级模块ID
private String moduleName;//模块名
private Integer menuOrFunc;//菜单/功能(1:菜单,2:功能)
private String alias;//权限别名
private String requestURL;//请求URL
private String requestJur;//请求权限(多个用,分割)
private Integer openWith;//打开方式(1:blankHTML,2:innerHTML,3:dialog)
private String dialogTitle;//对话框标题
private Integer dialogWidth;//对话框宽度
private Integer dialogHeight;//对话框高度
private String operatOrField;//操作字段(表字段...)
@TableAnnotation("pd_authority")
public class TrightVo implements Serializable, InitDao {
//主键id
private String id;
//父权限id
private String pid;
//权限名
private String name;
//权限类型
private String type;
//别名
private String alias;
//权限url
private String url;
@TableAnnotation("open_mode")
//打开方式
private String openMode;
//描述
private String remark;
@TableAnnotation("create_time")
//创建时间
private Timestamp createTime;
public Long getTrId() {
return trId;
public String getId() {
return id;
}
public void setTrId(Long trId) {
this.trId = trId;
public void setId(String id) {
this.id = id;
}
public Long getSysId() {
return sysId;
public String getPid() {
return pid;
}
public void setSysId(Long sysId) {
this.sysId = sysId;
public void setPid(String pid) {
this.pid = pid;
}
public Long getModuleId() {
return moduleId;
public String getName() {
return name;
}
public void setModuleId(Long moduleId) {
this.moduleId = moduleId;
public void setName(String name) {
this.name = name;
}
public String getModuleName() {
return moduleName;
public String getType() {
return type;
}
public void setModuleName(String moduleName) {
this.moduleName = moduleName;
}
public Integer getMenuOrFunc() {
return menuOrFunc;
}
public void setMenuOrFunc(Integer menuOrFunc) {
this.menuOrFunc = menuOrFunc;
public void setType(String type) {
this.type = type;
}
public String getAlias() {
......@@ -71,59 +74,41 @@ public class TrightVo implements Serializable {
this.alias = alias;
}
public String getRequestURL() {
return requestURL;
}
public void setRequestURL(String requestURL) {
this.requestURL = requestURL;
}
public String getRequestJur() {
return requestJur;
}
public void setRequestJur(String requestJur) {
this.requestJur = requestJur;
}
public Integer getOpenWith() {
return openWith;
}
public void setOpenWith(Integer openWith) {
this.openWith = openWith;
public String getUrl() {
return url;
}
public String getDialogTitle() {
return dialogTitle;
public void setUrl(String url) {
this.url = url;
}
public void setDialogTitle(String dialogTitle) {
this.dialogTitle = dialogTitle;
public String getOpenMode() {
return openMode;
}
public Integer getDialogWidth() {
return dialogWidth;
public void setOpenMode(String openMode) {
this.openMode = openMode;
}
public void setDialogWidth(Integer dialogWidth) {
this.dialogWidth = dialogWidth;
public String getRemark() {
return remark;
}
public Integer getDialogHeight() {
return dialogHeight;
public void setRemark(String remark) {
this.remark = remark;
}
public void setDialogHeight(Integer dialogHeight) {
this.dialogHeight = dialogHeight;
public Timestamp getCreateTime() {
return createTime;
}
public String getOperatOrField() {
return operatOrField;
public void setCreateTime(Timestamp createTime) {
this.createTime = createTime;
}
public void setOperatOrField(String operatOrField) {
this.operatOrField = operatOrField;
@Override
public void init() {
String createTimeString = StringHelper.getFirst(DateHelper.getDateTimeString(this.createTime), DateHelper.getNow());
this.createTime = Timestamp.valueOf(createTimeString);
}
}
......@@ -2,36 +2,40 @@ package com.pangding.web.tright.vo;
import com.yanzuoguang.dao.TableAnnotation;
@TableAnnotation("pd_user_role_relation")
public class UserRoleRelation {
@TableAnnotation("tru_id")
private Long tru_id;
@TableAnnotation("tr_id")
private Long tr_id;
@TableAnnotation("tu_id")
private Long tu_id;
public Long getTru_id() {
return tru_id;
import java.io.Serializable;
@TableAnnotation("pd_user_role")
public class UserRoleRelation implements Serializable {
private String id;
@TableAnnotation("user_id")
/*用户id*/
private String userId;
@TableAnnotation("role_id")
/*角色id*/
private String roleId;
public String getId() {
return id;
}
public void setTru_id(Long tru_id) {
this.tru_id = tru_id;
public void setId(String id) {
this.id = id;
}
public Long getTr_id() {
return tr_id;
public String getUserId() {
return userId;
}
public void setTr_id(Long tr_id) {
this.tr_id = tr_id;
public void setUserId(String userId) {
this.userId = userId;
}
public Long getTu_id() {
return tu_id;
public String getRoleId() {
return roleId;
}
public void setTu_id(Long tu_id) {
this.tu_id = tu_id;
public void setRoleId(String roleId) {
this.roleId = roleId;
}
}
......@@ -6,40 +6,44 @@ import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.vo.InitDao;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
@TableAnnotation("pd_user")
public class UserVo implements Serializable, InitDao {
@TableAnnotation("tu_id")
private Long tuId;//主键ID
@TableAnnotation("user_name")
private String userName;//用户名
private String password;//密码
@TableAnnotation("phone_number")
private String phoneNumber;//手机号
/*主键id*/
private String id;
/*账号*/
private String account;
/*密码*/
private String password;
/*手机号*/
private String phone;
/*状态*/
private String status;
/*描述*/
private String remark;
@TableAnnotation("create_time")
private String createTime;//创建时间
@TableAnnotation("login_time")
private String loginTime;//登录时间
@TableAnnotation("last_login_time")
private String lastLoginTime;//上次登录时间
private Integer count;//登录次数
/*创建时间*/
private Timestamp createTime;
/*创建人*/
private String creator;
public Long getTuId() {
return tuId;
public String getId() {
return id;
}
public void setTuId(Long tuId) {
this.tuId = tuId;
public void setId(String id) {
this.id = id;
}
public String getUserName() {
return userName;
public String getAccount() {
return account;
}
public void setUserName(String userName) {
this.userName = userName;
public void setAccount(String account) {
this.account = account;
}
public String getPassword() {
......@@ -50,50 +54,49 @@ public class UserVo implements Serializable, InitDao {
this.password = password;
}
public String getPhoneNumber() {
return phoneNumber;
public String getPhone() {
return phone;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
public void setPhone(String phone) {
this.phone = phone;
}
public String getCreateTime() {
return createTime;
public String getStatus() {
return status;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
public void setStatus(String status) {
this.status = status;
}
public String getLoginTime() {
return loginTime;
public String getRemark() {
return remark;
}
public void setLoginTime(String loginTime) {
this.loginTime = loginTime;
public void setRemark(String remark) {
this.remark = remark;
}
public String getLastLoginTime() {
return lastLoginTime;
public Timestamp getCreateTime() {
return createTime;
}
public void setLastLoginTime(String lastLoginTime) {
this.lastLoginTime = lastLoginTime;
public void setCreateTime(Timestamp createTime) {
this.createTime = createTime;
}
public Integer getCount() {
return count;
public String getCreator() {
return creator;
}
public void setCount(Integer count) {
this.count = count;
public void setCreator(String creator) {
this.creator = creator;
}
@Override
public void init() {
this.createTime = StringHelper.getFirst(this.createTime, DateHelper.getNow());
this.loginTime = StringHelper.getFirst(this.loginTime, DateHelper.getNow());
this.lastLoginTime = StringHelper.getFirst(this.lastLoginTime, DateHelper.getNow());
String createTimeString = StringHelper.getFirst(DateHelper.getDateTimeString(this.createTime), DateHelper.getNow());
this.createTime = Timestamp.valueOf(createTimeString);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment