Commit d87c9ac8 authored by tangf's avatar tangf

Merge remote-tracking branch 'origin/master'

parents cf536232 4d25a0fc
package com.pangding.web.tright.controller;
import com.pangding.web.tright.currency.Result;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/roles")
public class RoleController {
@Autowired
RoleService roleServiceImpl;
@Autowired
RoleDao roleDao;
/**
* 新增角色
* @param roleDto
* @return
*/
@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;
}
/**
* 修改角色信息
* @param roleDto
* @return
*/
@RequestMapping(value = "/update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object updateRole(@RequestBody RoleDto roleDto){
roleServiceImpl.saveRole(roleDto);
Result result = new Result(0,"SUCCESS",null);
return result;
}
/**
* 查询角色列表
* @return
*/
@RequestMapping(value = "/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object listRoles(){
Result result = new Result(0,"SUCCESS",null);
return result;
}
/**
* 根据ID查询角色
* @param id
* @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);
return result;
}
/**
* 删除角色
* @param id
* @return
*/
@RequestMapping(value = "/delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object delete(@PathVariable Long id){
roleServiceImpl.deleteRole(id);
Result result = new Result(0,"SUCCESS",null);
return result;
}
}
package com.pangding.web.tright.controller;
import com.pangding.web.tright.currency.Result;
import com.pangding.web.tright.vo.TrightVo;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/tright")
public class TrightController {
Result result = new Result();
/**
* 新增权限
* @param trightVo
* @return
*/
@RequestMapping(value = "/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object saveTright(@RequestBody TrightVo trightVo){
return result;
}
/**
* 修改权限信息
* @param trightVo
* @return
*/
@RequestMapping(value = "/update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object updateTright(@RequestBody TrightVo trightVo){
return result;
}
/**
* 查询权限列表
* @return
*/
@RequestMapping(value = "/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object listTrights(){
return result;
}
/**
* 查询一级权限
* @return
*/
@RequestMapping(value = "/parent", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object parentTrights(){
return result;
}
/**
* 查询所有权限
* @return
*/
@RequestMapping(value = "/all", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object allTrights(){
return result;
}
/**
* 根据ID查询权限
* @param id
* @return
*/
@RequestMapping(value = "/role", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object tright(@PathVariable Long id){
return null;
}
/**
* 删除权限
* @param id
* @return
*/
@RequestMapping(value = "/delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object delete(@PathVariable Long id){
return result;
}
}
package com.pangding.web.tright.controller;
import com.pangding.web.tright.currency.Result;
import com.pangding.web.tright.dao.UserDao;
import com.pangding.web.tright.dto.UserDto;
import com.pangding.web.tright.service.UserService;
import com.pangding.web.tright.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/users")
public class UserController {
@Autowired
UserService userServiceImpl;
@Autowired
private UserDao userDao;
/**
* 新增用户
* @param userDto
* @return
*/
@RequestMapping(value = "/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object saveUser(@RequestBody UserDto userDto){
UserVo u = userServiceImpl.getUser(userDto.getUserName());
if (u != null) {
throw new IllegalArgumentException(userDto.getUserName() + "已存在");
}
UserVo userVo = userServiceImpl.saveUser(userDto);
Result result = new Result(0,"SUCCESS",userVo);
return result;
}
/**
* 修改用户信息
* @param userDto
* @return
*/
@RequestMapping(value = "/update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object updateUser(@RequestBody UserDto userDto){
UserVo userVo = userServiceImpl.updateUser(userDto);
Result result = new Result(0,"SUCCESS",userVo);
return result;
}
/**
* 查询用户列表
* @return
*/
@RequestMapping(value = "/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object listUsers(){
Result result = new Result(0,"SUCCESS",null);
return result;
}
/**
* 根据ID查询用户
* @param id
* @return
*/
@RequestMapping(value = "/user", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object user(@PathVariable Long id){
UserVo userVo = userDao.getById(id);
Result result = new Result(0,"SUCCESS",userVo);
return result;
}
}
package com.pangding.web.tright.currency;
import java.io.Serializable;
public class Result implements Serializable {
private Integer code;//状态码
private String message;//消息
private Object data;//
public Result(Integer code, String message, Object data) {
this.code = code;
this.message = message;
this.data = data;
}
public Result() {}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Object getObject() {
return data;
}
public void setObject(Object data) {
this.data = data;
}
}
package com.pangding.web.tright.dao;
import com.pangding.web.tright.vo.RoleVo;
import java.util.List;
public interface RoleDao {
int save(RoleVo roleVo);
RoleVo getRole(String name);
int update(RoleVo roleVo);
int deleteRole(Long id);
int deleteRoleUser(Long roleId);
RoleVo getById(Long id);
int deleteRoleTright(Long roleId);
int saveRolePermission(Long roleId, List<Long> trights);
}
package com.pangding.web.tright.dao;
import com.pangding.web.tright.vo.UserVo;
import java.util.List;
public interface UserDao {
int save(UserVo userVo);
UserVo getUser(String username);
int update(UserVo userVo);
int deleteUserRole(Long userId);
int saveUserRoles(Long userId, List<Long> roleIds);
UserVo getById(Long id);
}
package com.pangding.web.tright.dto;
import com.pangding.web.tright.vo.RoleVo;
import java.util.List;
public class RoleDto extends RoleVo {
private List<Long> trightIds;
public List<Long> getTrightIds() {
return trightIds;
}
public void setTrightIds(List<Long> trightIds) {
this.trightIds = trightIds;
}
}
package com.pangding.web.tright.dto;
import com.pangding.web.tright.vo.UserVo;
import java.util.List;
public class UserDto extends UserVo {
private List<Long> roleIds;
public List<Long> getRoleIds() {
return roleIds;
}
public void setRoleIds(List<Long> roleIds) {
this.roleIds = roleIds;
}
}
package com.pangding.web.tright.service;
import com.pangding.web.tright.dto.RoleDto;
public interface RoleService {
void saveRole(RoleDto roleDto);
void deleteRole(Long id);
}
package com.pangding.web.tright.service;
public interface TrightService {
}
package com.pangding.web.tright.service;
import com.pangding.web.tright.dto.UserDto;
import com.pangding.web.tright.vo.UserVo;
public interface UserService {
UserVo saveUser(UserDto userDto);
UserVo updateUser(UserDto userDto);
UserVo getUser(String username);
String passwordEncoder(String credentials, String salt);
}
package com.pangding.web.tright.service.impl;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
@Service
public class RoleServiceImpl implements RoleService {
@Autowired
RoleDao roleDao;
@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);
}
saveRoleTright(role.getTrID(), roleDto.getTrightIds());
}
private void saveRoleTright(Long roleId, List<Long> trights) {
roleDao.deleteRoleTright(roleId);
trights.remove(0L);
if (!CollectionUtils.isEmpty(trights)) {
roleDao.saveRolePermission(roleId, trights);
}
}
@Override
public void deleteRole(Long id) {
roleDao.deleteRoleUser(id);
roleDao.deleteRole(id);
}
}
package com.pangding.web.tright.service.impl;
import org.springframework.stereotype.Service;
@Service
public class TrightServiceImpl {
}
package com.pangding.web.tright.service.impl;
import com.pangding.web.tright.dao.UserDao;
import com.pangding.web.tright.dto.UserDto;
import com.pangding.web.tright.service.UserService;
import com.pangding.web.tright.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
@Autowired
UserDao userDao;
@Override
public UserVo saveUser(UserDto userDto) {
UserVo userVo = userDto;
//
userDao.save(userVo);
saveUserRoles(userVo.getTuID(), userDto.getRoleIds());
return userVo;
}
private void saveUserRoles(Long userId, List<Long> roleIds) {
if (roleIds != null) {
userDao.deleteUserRole(userId);
if (!CollectionUtils.isEmpty(roleIds)) {
userDao.saveUserRoles(userId, roleIds);
}
}
}
@Override
public UserVo updateUser(UserDto userDto) {
userDao.update(userDto);
saveUserRoles(userDto.getTuID(), userDto.getRoleIds());
return userDto;
}
@Override
public UserVo getUser(String username) {
return userDao.getUser(username);
}
@Override
public String passwordEncoder(String credentials, String salt) {
return null;
}
}
package com.pangding.web.tright.utils;
public class UserUtil {
}
package com.pangding.web.tright.vo;
import java.io.Serializable;
import java.util.Date;
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;
}
public void setTrID(Long trID) {
this.trID = trID;
}
public Long getParentTrID() {
return parentTrID;
}
public void setParentTrID(Long parentTrID) {
this.parentTrID = parentTrID;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getDescribe() {
return describe;
}
public void setDescribe(String describe) {
this.describe = describe;
}
}
package com.pangding.web.tright.vo;
import java.io.Serializable;
/**
* 权限表
*/
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;//操作字段(表字段...)
public Long getTrID() {
return trID;
}
public void setTrID(Long trID) {
this.trID = trID;
}
public Long getSysID() {
return sysID;
}
public void setSysID(Long sysID) {
this.sysID = sysID;
}
public Long getModuleID() {
return moduleID;
}
public void setModuleID(Long moduleID) {
this.moduleID = moduleID;
}
public String getModuleName() {
return moduleName;
}
public void setModuleName(String moduleName) {
this.moduleName = moduleName;
}
public Integer getMenuOrFunc() {
return menuOrFunc;
}
public void setMenuOrFunc(Integer menuOrFunc) {
this.menuOrFunc = menuOrFunc;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
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 getDialogTitle() {
return dialogTitle;
}
public void setDialogTitle(String dialogTitle) {
this.dialogTitle = dialogTitle;
}
public Integer getDialogWidth() {
return dialogWidth;
}
public void setDialogWidth(Integer dialogWidth) {
this.dialogWidth = dialogWidth;
}
public Integer getDialogHeight() {
return dialogHeight;
}
public void setDialogHeight(Integer dialogHeight) {
this.dialogHeight = dialogHeight;
}
public String getOperatOrField() {
return operatOrField;
}
public void setOperatOrField(String operatOrField) {
this.operatOrField = operatOrField;
}
}
package com.pangding.web.tright.vo;
import java.io.Serializable;
import java.util.Date;
public class UserVo implements Serializable {
private Long tuID;//主键ID
private String userName;//用户名
private String password;//密码
private String phoneNumber;//手机号
private Date createTime;//创建时间
private Date loginTime;//登录时间
private Date lastLoginTime;//上次登录时间
private Integer count;//登录次数
public Long getTuID() {
return tuID;
}
public void setTuID(Long tuID) {
this.tuID = tuID;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getLoginTime() {
return loginTime;
}
public void setLoginTime(Date loginTime) {
this.loginTime = loginTime;
}
public Date getLastLoginTime() {
return lastLoginTime;
}
public void setLastLoginTime(Date lastLoginTime) {
this.lastLoginTime = lastLoginTime;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
}
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