| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.api.ApiController; |
| | | import com.baomidou.mybatisplus.extension.api.R; |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.example.jz.modle.entity.User; |
| | | import com.example.jz.service.UserService; |
| | | import com.example.jz.utils.Md5Utils; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | /** |
| | | * 用户表(User)表控制层 |
| | | * |
| | | * @author makejava |
| | | * @author 安瑾然 |
| | | * @since 2022-07-11 16:35:57 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("user") |
| | | @Api(tags = "用户管理") |
| | | public class UserController extends ApiController { |
| | | /** |
| | | * 服务对象 |
| | | */ |
| | | @Resource |
| | | private UserService userService; |
| | | |
| | | @Autowired |
| | | public void setUserService(UserService userService) { |
| | | this.userService = userService; |
| | | } |
| | | |
| | | /** |
| | | * 分页查询所有数据 |
| | |
| | | * @return 所有数据 |
| | | */ |
| | | @GetMapping |
| | | @ApiOperation("分页查询所有数据") |
| | | public R selectAll(Page<User> page, User user) { |
| | | return success(this.userService.page(page, new QueryWrapper<>(user))); |
| | | } |
| | |
| | | * @return 单条数据 |
| | | */ |
| | | @GetMapping("{id}") |
| | | @ApiOperation("通过主键查询单条数据") |
| | | public R selectOne(@PathVariable Serializable id) { |
| | | return success(this.userService.getById(id)); |
| | | } |
| | | |
| | | /** |
| | | * 新增数据 |
| | | * |
| | | * @param user 实体对象 |
| | | * @return 新增结果 |
| | | */ |
| | | @PostMapping |
| | | public R insert(@RequestBody User user) { |
| | | return success(this.userService.save(user)); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 修改结果 |
| | | */ |
| | | @PutMapping |
| | | @ApiOperation("修改用户数据") |
| | | public R update(@RequestBody User user) { |
| | | return success(this.userService.updateById(user)); |
| | | return success(userService.updateById(user)); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 删除结果 |
| | | */ |
| | | @DeleteMapping |
| | | @ApiOperation("删除用户数据") |
| | | public R delete(@RequestParam("idList") List<Long> idList) { |
| | | return success(this.userService.removeByIds(idList)); |
| | | } |
| | | |
| | | /** |
| | | * 添加管理员 |
| | | * |
| | | * @param id 用户id |
| | | * @param username 管理员用户名 |
| | | * @param password 管理员密码 |
| | | * @return |
| | | */ |
| | | @PostMapping("/addAdmin/{id}") |
| | | @ApiOperation("添加管理员") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String"), |
| | | @ApiImplicitParam(name = "username", value = "用户名", required = true, dataType = "String") |
| | | }) |
| | | public R addAdmin(@PathVariable Serializable id, String username, String password) { |
| | | User user = userService.getById(id).setLoginUsername(username).setLoginPassword(Md5Utils.md5(password)).setRole(1); |
| | | return success(userService.updateById(user)); |
| | | } |
| | | |
| | | /** |
| | | * 重置管理员密码 |
| | | * |
| | | * @param id 用户id |
| | | * @return |
| | | */ |
| | | @GetMapping("/resetPassword/{id}") |
| | | @ApiOperation("重置管理员密码") |
| | | public R resetPassword(@PathVariable Serializable id) { |
| | | User user = userService.getById(id); |
| | | // 重置初始密码为身份证后六位 |
| | | user.setLoginPassword(Md5Utils.md5(user.getUserIdcard().substring(user.getUserIdcard().length() - 6))); |
| | | return success(userService.updateById(user)); |
| | | } |
| | | } |