| | |
| | | package com.example.jz.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | 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.R; |
| | | import com.example.jz.modle.entity.User; |
| | | import com.example.jz.service.UserService; |
| | | import com.example.jz.utils.Md5Utils; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | @GetMapping |
| | | @ApiOperation("分页查询所有数据") |
| | | public R selectAll(Page<User> page, User user) { |
| | | return success(this.userService.page(page, new QueryWrapper<>(user))); |
| | | return R.ok(this.userService.page(page, new QueryWrapper<User>() |
| | | .like(StringUtils.isNotBlank(user.getNickName()),"nick_name",user.getNickName()) |
| | | .or() |
| | | .like(StringUtils.isNotBlank(user.getRealName()),"real_name",user.getRealName()) |
| | | .orderByDesc("ctime"))); |
| | | } |
| | | |
| | | /** |
| | |
| | | @GetMapping("{id}") |
| | | @ApiOperation("通过主键查询单条数据") |
| | | public R selectOne(@PathVariable Serializable id) { |
| | | return success(this.userService.getById(id)); |
| | | return R.ok(this.userService.getById(id)); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PutMapping |
| | | @ApiOperation("修改用户数据") |
| | | public R update(@RequestBody User user) { |
| | | return success(userService.updateById(user)); |
| | | return R.ok(userService.updateById(user)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @DeleteMapping |
| | | @ApiOperation("删除用户数据") |
| | | public R delete(@RequestParam("idList") List<Long> idList) { |
| | | return success(this.userService.removeByIds(idList)); |
| | | public R delete(@RequestParam("id") Integer id) { |
| | | return R.ok(this.userService.removeById(id)); |
| | | } |
| | | |
| | | /** |
| | |
| | | }) |
| | | 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)); |
| | | return R.ok(userService.updateById(user)); |
| | | } |
| | | |
| | | @PostMapping("/add") |
| | | @ApiOperation("添加") |
| | | public R add(@RequestBody User user) { |
| | | user.setCtime(new Date()); |
| | | return R.ok(userService.save(user)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 重置管理员密码 |
| | |
| | | User user = userService.getById(id); |
| | | // 重置初始密码为身份证后六位 |
| | | user.setLoginPassword(Md5Utils.md5(user.getUserIdcard().substring(user.getUserIdcard().length() - 6))); |
| | | return success(userService.updateById(user)); |
| | | return R.ok(userService.updateById(user)); |
| | | } |
| | | } |