Commit a9114029 by yw

项目初始化

parent 97555703
package cn.datax.service.system.api.dto;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
@Data
public class UserPasswordDto implements Serializable {
private static final long serialVersionUID=1L;
@NotBlank(message = "主键ID不能为空")
private String id;
@NotBlank(message = "密码不能为空")
private String password;
@NotBlank(message = "旧密码不能为空")
private String oldPassword;
}
......@@ -4,6 +4,8 @@ import cn.datax.common.core.R;
import cn.datax.common.validate.ValidateGroupForSave;
import cn.datax.common.validate.ValidateGroupForUpdate;
import cn.datax.service.system.api.dto.DeptDto;
import cn.datax.service.system.api.entity.DeptEntity;
import cn.datax.service.system.mapstruct.DeptMapper;
import cn.datax.service.system.service.DeptService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -21,18 +23,22 @@ import cn.datax.common.base.BaseController;
* @since 2019-09-04
*/
@RestController
@RequestMapping("/dept")
@RequestMapping("/depts")
public class DeptController extends BaseController {
@Autowired
private DeptService deptService;
@Autowired
private DeptMapper deptMapper;
@GetMapping("/{id}")
public R getDeptById(@PathVariable String id) {
return R.ok().setData(deptService.getById(id));
DeptEntity deptEntity = deptService.getById(id);
return R.ok().setData(deptMapper.toVO(deptEntity));
}
@GetMapping("/list")
@GetMapping()
public R getDeptList() {
return R.ok().setData(deptService.list(Wrappers.emptyWrapper()));
}
......@@ -43,8 +49,8 @@ public class DeptController extends BaseController {
return R.ok();
}
@PutMapping()
public R updateDept(@RequestBody @Validated({ValidateGroupForUpdate.class}) DeptDto dept) {
@PutMapping("/{id}")
public R updateDept(@PathVariable String id, @RequestBody @Validated({ValidateGroupForUpdate.class}) DeptDto dept) {
deptService.updateDept(dept);
return R.ok();
}
......
......@@ -4,6 +4,8 @@ import cn.datax.common.core.R;
import cn.datax.common.validate.ValidateGroupForSave;
import cn.datax.common.validate.ValidateGroupForUpdate;
import cn.datax.service.system.api.dto.MenuDto;
import cn.datax.service.system.api.entity.MenuEntity;
import cn.datax.service.system.mapstruct.MenuMapper;
import cn.datax.service.system.service.MenuService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -21,18 +23,22 @@ import cn.datax.common.base.BaseController;
* @since 2019-09-11
*/
@RestController
@RequestMapping("/menu")
@RequestMapping("/menus")
public class MenuController extends BaseController {
@Autowired
private MenuService menuService;
@Autowired
private MenuMapper menuMapper;
@GetMapping("/{id}")
public R getMenuById(@PathVariable String id) {
return R.ok().setData(menuService.getById(id));
MenuEntity menuEntity = menuService.getById(id);
return R.ok().setData(menuMapper.toVO(menuEntity));
}
@GetMapping("/list")
@GetMapping()
public R getMenuList() {
return R.ok().setData(menuService.list(Wrappers.emptyWrapper()));
}
......@@ -43,8 +49,8 @@ public class MenuController extends BaseController {
return R.ok();
}
@PutMapping()
public R updateMenu(@RequestBody @Validated({ValidateGroupForUpdate.class}) MenuDto menu) {
@PutMapping("/{id}")
public R updateMenu(@PathVariable String id, @RequestBody @Validated({ValidateGroupForUpdate.class}) MenuDto menu) {
menuService.updateMenu(menu);
return R.ok();
}
......
......@@ -5,7 +5,11 @@ import cn.datax.common.validate.ValidateGroupForSave;
import cn.datax.common.validate.ValidateGroupForUpdate;
import cn.datax.service.system.api.dto.PostDto;
import cn.datax.service.system.api.entity.PostEntity;
import cn.datax.service.system.mapstruct.PostMapper;
import cn.datax.service.system.service.PostService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -23,20 +27,29 @@ import cn.datax.common.base.BaseController;
* @since 2019-09-11
*/
@RestController
@RequestMapping("/post")
@RequestMapping("/posts")
public class PostController extends BaseController {
@Autowired
private PostService postService;
@Autowired
private PostMapper postMapper;
@GetMapping("/{id}")
public R getPostById(@PathVariable String id) {
return R.ok().setData(postService.getById(id));
PostEntity postEntity = postService.getById(id);
return R.ok().setData(postMapper.toVO(postEntity));
}
@GetMapping("/page")
public R getPostPage(Page page, PostEntity post) {
return R.ok().setData(postService.page(page, Wrappers.query(post)));
public R getPostPage(@RequestParam(value="pageNum", defaultValue="1") Integer pageNum,
@RequestParam(value="pageSize", defaultValue="20") Integer pageSize,
PostEntity post) {
QueryWrapper<PostEntity> queryWrapper = Wrappers.emptyWrapper();
queryWrapper.like(StrUtil.isNotBlank(post.getPostName()), "post_name", post.getPostName());
IPage<PostEntity> page = postService.page(new Page<>(pageNum, pageSize), queryWrapper);
return R.ok().setData(page);
}
@PostMapping()
......@@ -45,8 +58,8 @@ public class PostController extends BaseController {
return R.ok();
}
@PutMapping()
public R updatePost(@RequestBody @Validated({ValidateGroupForUpdate.class}) PostDto post) {
@PutMapping("/{id}")
public R updatePost(@PathVariable String id, @RequestBody @Validated({ValidateGroupForUpdate.class}) PostDto post) {
postService.updatePost(post);
return R.ok();
}
......
......@@ -5,7 +5,11 @@ import cn.datax.common.validate.ValidateGroupForSave;
import cn.datax.common.validate.ValidateGroupForUpdate;
import cn.datax.service.system.api.dto.RoleDto;
import cn.datax.service.system.api.entity.RoleEntity;
import cn.datax.service.system.mapstruct.RoleMapper;
import cn.datax.service.system.service.RoleService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -23,12 +27,15 @@ import cn.datax.common.base.BaseController;
* @since 2019-09-04
*/
@RestController
@RequestMapping("/role")
@RequestMapping("/roles")
public class RoleController extends BaseController {
@Autowired
private RoleService roleService;
@Autowired
private RoleMapper roleMapper;
/**
* 通过ID查询角色信息
* @param id
......@@ -36,18 +43,25 @@ public class RoleController extends BaseController {
*/
@GetMapping("/{id}")
public R getRoleById(@PathVariable String id) {
return R.ok().setData(roleService.getById(id));
RoleEntity roleEntity = roleService.getById(id);
return R.ok().setData(roleMapper.toVO(roleEntity));
}
/**
*分页查询角色信息
* @param page current=1&size=20
* 分页查询角色信息
* @param pageNum
* @param pageSize
* @param role
* @return
*/
@GetMapping("/page")
public R getRolePage(Page page, RoleEntity role) {
return R.ok().setData(roleService.page(page, Wrappers.query(role)));
public R getRolePage(@RequestParam(value="pageNum", defaultValue="1") Integer pageNum,
@RequestParam(value="pageSize", defaultValue="20") Integer pageSize,
RoleEntity role) {
QueryWrapper<RoleEntity> queryWrapper = Wrappers.emptyWrapper();
queryWrapper.like(StrUtil.isNotBlank(role.getRoleName()), "role_name", role.getRoleName());
IPage<RoleEntity> page = roleService.page(new Page<>(pageNum, pageSize), queryWrapper);
return R.ok().setData(page);
}
/**
......@@ -66,8 +80,8 @@ public class RoleController extends BaseController {
* @param role
* @return
*/
@PutMapping()
public R updateRole(@RequestBody @Validated({ValidateGroupForUpdate.class}) RoleDto role) {
@PutMapping("/{id}")
public R updateRole(@PathVariable String id, @RequestBody @Validated({ValidateGroupForUpdate.class}) RoleDto role) {
roleService.updateRole(role);
return R.ok();
}
......
......@@ -4,23 +4,21 @@ import cn.datax.common.core.R;
import cn.datax.common.validate.ValidateGroupForSave;
import cn.datax.common.validate.ValidateGroupForUpdate;
import cn.datax.service.system.api.dto.UserDto;
import cn.datax.service.system.api.dto.UserPasswordDto;
import cn.datax.service.system.api.entity.UserEntity;
import cn.datax.service.system.mapstruct.UserMapper;
import cn.datax.service.system.service.UserService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import cn.datax.common.base.BaseController;
import java.security.Principal;
/**
* <p>
* 前端控制器
......@@ -30,7 +28,7 @@ import java.security.Principal;
* @since 2019-09-04
*/
@RestController
@RequestMapping("/user")
@RequestMapping("/users")
public class UserController extends BaseController {
@Autowired
......@@ -39,12 +37,6 @@ public class UserController extends BaseController {
@Autowired
private UserMapper userMapper;
@GetMapping("/token")
public Principal tokenUser() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
return authentication;
}
@GetMapping("/{id}")
public R getUserById(@PathVariable String id) {
UserEntity userEntity = userService.getById(id);
......@@ -56,6 +48,7 @@ public class UserController extends BaseController {
@RequestParam(value="pageSize", defaultValue="20") Integer pageSize,
UserDto user) {
QueryWrapper<UserEntity> queryWrapper = Wrappers.emptyWrapper();
queryWrapper.like(StrUtil.isNotBlank(user.getUsername()), "username", user.getUsername());
IPage<UserEntity> page = userService.page(new Page<>(pageNum, pageSize), queryWrapper);
page.getRecords().stream().map(userMapper::toVO);
return R.ok().setData(page);
......@@ -67,12 +60,18 @@ public class UserController extends BaseController {
return R.ok();
}
@PutMapping()
public R updateUser(@RequestBody @Validated({ValidateGroupForUpdate.class}) UserDto user) {
@PutMapping("/{id}")
public R updateUser(@PathVariable String id, @RequestBody @Validated({ValidateGroupForUpdate.class}) UserDto user) {
userService.updateUser(user);
return R.ok();
}
@PutMapping("/{id}/password")
public R updateUserPassword(@PathVariable String id, @RequestBody @Validated UserPasswordDto user) {
userService.updateUserPassword(user);
return R.ok();
}
@DeleteMapping("/{id}")
public R deleteUser(@PathVariable String id) {
userService.deleteUserById(id);
......
......@@ -2,6 +2,7 @@ package cn.datax.service.system.service;
import cn.datax.common.base.BaseService;
import cn.datax.service.system.api.dto.UserDto;
import cn.datax.service.system.api.dto.UserPasswordDto;
import cn.datax.service.system.api.entity.UserEntity;
/**
......@@ -19,4 +20,6 @@ public interface UserService extends BaseService<UserEntity> {
void updateUser(UserDto user);
void deleteUserById(String id);
void updateUserPassword(UserPasswordDto user);
}
package cn.datax.service.system.service.impl;
import cn.datax.common.exception.DataException;
import cn.datax.service.system.api.dto.UserDto;
import cn.datax.service.system.api.dto.UserPasswordDto;
import cn.datax.service.system.api.entity.UserDeptEntity;
import cn.datax.service.system.api.entity.UserEntity;
import cn.datax.service.system.api.entity.UserPostEntity;
......@@ -12,8 +14,10 @@ import cn.datax.service.system.dao.UserRoleDao;
import cn.datax.service.system.mapstruct.UserMapper;
import cn.datax.service.system.service.UserService;
import cn.datax.common.base.BaseServiceImpl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
......@@ -46,6 +50,8 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
@Transactional(rollbackFor = Exception.class)
public void saveUser(UserDto userDto) {
UserEntity user = userMapper.toEntity(userDto);
String passwordEncode = new BCryptPasswordEncoder().encode(user.getPassword());
user.setPassword(passwordEncode);
baseMapper.insert(user);
insertBatchRole(userDto.getRoles(), user.getId());
insertBatchDept(userDto.getDepts(), user.getId());
......@@ -107,4 +113,14 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
baseMapper.deleteById(id);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateUserPassword(UserPasswordDto userPasswordDto) {
UserEntity userEntity = baseMapper.selectById(userPasswordDto.getId());
if(!StrUtil.equals(userEntity.getPassword(), new BCryptPasswordEncoder().encode(userPasswordDto.getOldPassword()))){
throw new DataException("旧密码不正确");
}
// todo xml写更新密码sql
}
}
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