|
@@ -1,6 +1,12 @@
|
|
|
package com.sf.admin.controller;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.sf.admin.dto.CommonResult;
|
|
|
+import com.sf.admin.dto.page.CommonPage;
|
|
|
+import com.sf.admin.dto.req.AdminListReqDto;
|
|
|
import com.sf.admin.dto.req.AdminLoginReqDto;
|
|
|
import com.sf.admin.dto.resp.AdminInfoRespDto;
|
|
|
import com.sf.admin.dto.resp.AdminLoginRespDto;
|
|
@@ -12,8 +18,12 @@ import com.sf.admin.entity.UmsRole;
|
|
|
import com.sf.admin.service.*;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.util.DigestUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -35,23 +45,22 @@ public class UmsAdminController {
|
|
|
private final IUmsAdminRoleRelationService adminRoleRelationService;
|
|
|
private final IUmsRoleMenuRelationService roleMenuRelationService;
|
|
|
|
|
|
- // http://localhost:8013/ums/admin/list
|
|
|
-// @GetMapping("/ums/admin/list")
|
|
|
-// public List<UmsAdmin> list(){
|
|
|
-// return umsAdminService.list();
|
|
|
-// }
|
|
|
-
|
|
|
+ // 登录
|
|
|
@PostMapping("/admin/login")
|
|
|
public CommonResult<AdminLoginRespDto> login(@RequestBody AdminLoginReqDto loginReqDto) {
|
|
|
String logined = umsAdminService.login(loginReqDto);
|
|
|
if (logined == null) {
|
|
|
return CommonResult.failed("用户名或密码错误");
|
|
|
}
|
|
|
+ if (logined.equals("disable")) {
|
|
|
+ return CommonResult.failed("用户被封禁,请联系管理员");
|
|
|
+ }
|
|
|
AdminLoginRespDto adminLoginRespDto = AdminLoginRespDto.builder()
|
|
|
.token(logined).tokenHead("SFCC ").build();
|
|
|
return CommonResult.success(adminLoginRespDto);
|
|
|
}
|
|
|
|
|
|
+ // 查询用户信息
|
|
|
@GetMapping("/admin/info")
|
|
|
public CommonResult<AdminInfoRespDto> getAdminInfo(@RequestHeader("Authorization") String token) {
|
|
|
if (token == null) {
|
|
@@ -102,4 +111,84 @@ public class UmsAdminController {
|
|
|
return CommonResult.success(adminInfoRespDto);
|
|
|
}
|
|
|
|
|
|
+ // 登出
|
|
|
+ @PostMapping("/admin/logout")
|
|
|
+ public CommonResult logout(@RequestHeader("Authorization") String token) {
|
|
|
+ // 可以清除token
|
|
|
+ System.out.println(token);
|
|
|
+ return CommonResult.success(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 在方法接收参数时 如果不接收 不会报错 如果接受时参数类型不匹配 会报错
|
|
|
+ // 查询用户列表
|
|
|
+ // http://localhost:8099/admin-api/admin/list?pageNum=1&pageSize=10&name=&phone=&startCount=&endCount=&status=-1&deptId=0&startTime=&endTime=
|
|
|
+ // http://localhost:8013/admin/list
|
|
|
+ @GetMapping("/admin/list")
|
|
|
+ public CommonResult<CommonPage<UmsAdmin>> list(AdminListReqDto reqDto) {
|
|
|
+ System.out.println(reqDto);
|
|
|
+ IPage<UmsAdmin> page = new Page<>(reqDto.getPageNum(), reqDto.getPageSize());
|
|
|
+ LambdaQueryWrapper<UmsAdmin> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ if (reqDto.getStartCount() != null && reqDto.getEndCount() != null) {
|
|
|
+ queryWrapper.gt(UmsAdmin::getCount, reqDto.getStartCount());
|
|
|
+ queryWrapper.lt(UmsAdmin::getCount, reqDto.getEndCount());
|
|
|
+ }
|
|
|
+ List<UmsAdmin> umsAdmins = umsAdminService.page(page, queryWrapper).getRecords();
|
|
|
+ CommonPage<UmsAdmin> commonPage = CommonPage.restPage(umsAdmins, page);
|
|
|
+ return CommonResult.success(commonPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新用户信息
|
|
|
+ // http://localhost:8099/admin-api/admin/update/11
|
|
|
+ @PostMapping("/admin/update/{id}")
|
|
|
+ public CommonResult<Long> update(@PathVariable("id") Long id, @RequestBody UmsAdmin umsAdmin) {
|
|
|
+ boolean updated = umsAdminService.updateById(umsAdmin);
|
|
|
+ if (updated) {
|
|
|
+ return CommonResult.success(id);
|
|
|
+ }
|
|
|
+ return CommonResult.failed("更新失败");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 封禁和激活用户
|
|
|
+ // http://localhost:8099/admin-api/admin/updateStatus/11?status=0
|
|
|
+ @PostMapping("/admin/updateStatus/{id}")
|
|
|
+ public CommonResult<Long> updateStatus(
|
|
|
+ @PathVariable("id") Long id, @RequestParam("status") Integer status) {
|
|
|
+ // update ums_admin set status = '0' where id = 11
|
|
|
+ LambdaUpdateWrapper<UmsAdmin> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.eq(UmsAdmin::getId, id);
|
|
|
+ updateWrapper.set(UmsAdmin::getStatus, status);
|
|
|
+ boolean updated = umsAdminService.update(updateWrapper);
|
|
|
+ if (updated) {
|
|
|
+ return CommonResult.success(id);
|
|
|
+ }
|
|
|
+ return CommonResult.failed("更新状态失败");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 添加用户
|
|
|
+ // http://localhost:8099/admin-api/admin/register
|
|
|
+ @PostMapping("/admin/register")
|
|
|
+ public CommonResult<UmsAdmin> register(@RequestBody UmsAdmin umsAdmin) {
|
|
|
+ LambdaQueryWrapper<UmsAdmin> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(UmsAdmin::getUsername, umsAdmin.getUsername());
|
|
|
+ boolean exists = umsAdminService.exists(queryWrapper);
|
|
|
+ if (exists) {
|
|
|
+ return CommonResult.failed("用户名已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置创建时间
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
+ umsAdmin.setCreateTime(now);
|
|
|
+ // 对密码进行加密
|
|
|
+ String password = umsAdmin.getPassword();
|
|
|
+ String pwd = DigestUtils.md5DigestAsHex(password.getBytes(StandardCharsets.UTF_8));
|
|
|
+ umsAdmin.setPassword(pwd);
|
|
|
+ boolean register = umsAdminService.save(umsAdmin);
|
|
|
+ if (register) {
|
|
|
+ return CommonResult.success(umsAdmin);
|
|
|
+ }
|
|
|
+ return CommonResult.failed("用户添加失败");
|
|
|
+ }
|
|
|
+
|
|
|
}
|