From 566c2710eb23b37944265507568c48bca9e40549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=9A=93=E9=9B=AF?= <18868469283@qq.com> Date: Fri, 11 Jan 2019 10:32:10 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86=E6=8E=A7?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mall/controller/UmsAdminController.java | 178 ++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 代码库/mall-admin/src/main/java/com/sock/mall/controller/UmsAdminController.java diff --git a/代码库/mall-admin/src/main/java/com/sock/mall/controller/UmsAdminController.java b/代码库/mall-admin/src/main/java/com/sock/mall/controller/UmsAdminController.java new file mode 100644 index 0000000..62bd2af --- /dev/null +++ b/代码库/mall-admin/src/main/java/com/sock/mall/controller/UmsAdminController.java @@ -0,0 +1,178 @@ +package com.macro.mall.controller; + +import com.macro.mall.dto.CommonResult; +import com.macro.mall.dto.UmsAdminLoginParam; +import com.macro.mall.dto.UmsAdminParam; +import com.macro.mall.model.UmsAdmin; +import com.macro.mall.model.UmsPermission; +import com.macro.mall.model.UmsRole; +import com.macro.mall.service.UmsAdminService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.security.Principal; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * ̨û + */ +@Controller +@Api(tags = "UmsAdminController", description = "̨û") +@RequestMapping("/admin") +public class UmsAdminController { + @Autowired + private UmsAdminService adminService;//̨û + @Value("${jwt.tokenHeader}") + private String tokenHeader; + @Value("${jwt.tokenHead}") + private String tokenHead; + + @ApiOperation(value = "ûע") + @RequestMapping(value = "/register", method = RequestMethod.POST) + @ResponseBody + public Object register(@RequestBody UmsAdminParam umsAdminParam, BindingResult result) { + UmsAdmin umsAdmin = adminService.register(umsAdminParam);//û + if (umsAdmin == null) { + new CommonResult().failed(); + } + return new CommonResult().success(umsAdmin); + } + + @ApiOperation(value = "¼Ժ󷵻token") + @RequestMapping(value = "/login", method = RequestMethod.POST) + @ResponseBody + public Object login(@RequestBody UmsAdminLoginParam umsAdminLoginParam, BindingResult result) {//¼ + String token = adminService.login(umsAdminLoginParam.getUsername(), umsAdminLoginParam.getPassword());//û¼token + if (token == null) { + return new CommonResult().validateFailed("û"); + } + Map tokenMap = new HashMap<>();//µĹϣ洢tokenֵ + tokenMap.put("token", token); + tokenMap.put("tokenHead", tokenHead); + return new CommonResult().success(tokenMap); + } + + @ApiOperation(value = "ˢtoken") + @RequestMapping(value = "/token/refresh", method = RequestMethod.GET) + @ResponseBody + public Object refreshToken(HttpServletRequest request) {//Http + String token = request.getHeader(tokenHeader);//ȡͷ + String refreshToken = adminService.refreshToken(token); + if (refreshToken == null) { + return new CommonResult().failed(); + } + Map tokenMap = new HashMap<>(); + tokenMap.put("token", token); + tokenMap.put("tokenHead", tokenHead); + return new CommonResult().success(tokenMap); + } + + @ApiOperation(value = "ȡǰ¼ûϢ") + @RequestMapping(value = "/info", method = RequestMethod.GET) + @ResponseBody + public Object getAdminInfo(Principal principal) {//ȡûϢ + /*AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();*/ + String username = principal.getName(); + UmsAdmin umsAdmin = adminService.getAdminByUsername(username); + Map data = new HashMap<>(); + data.put("username", umsAdmin.getUsername()); + data.put("roles", new String[]{"TEST"});//ûɫ + data.put("icon", umsAdmin.getIcon());//ûͷ + return new CommonResult().success(data); + } + + @ApiOperation(value = "˳") + @RequestMapping(value = "/logout", method = RequestMethod.POST) + @ResponseBody + public Object logout() { + return new CommonResult().success(null); + } + + @ApiOperation("ûҳȡûб") + @RequestMapping(value = "/list",method = RequestMethod.GET) + @ResponseBody + public Object list(@RequestParam(value = "name",required = false) String name,//û + @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize, + @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){ + List adminList = adminService.list(name,pageSize,pageNum); + return new CommonResult().pageSuccess(adminList); + } + + @ApiOperation("ȡָûϢ") + @RequestMapping(value = "/{id}",method = RequestMethod.GET) + @ResponseBody + public Object getItem(@PathVariable Long id){//idȡûϢ + UmsAdmin admin = adminService.getItem(id); + return new CommonResult().success(admin); + } + + @ApiOperation("ȡָûϢ") + @RequestMapping(value = "/update/{id}",method = RequestMethod.POST) + @ResponseBody + public Object update(@PathVariable Long id,@RequestBody UmsAdmin admin){ + int count = adminService.update(id,admin); + if(count>0){ + return new CommonResult().success(count); + } + return new CommonResult().failed(); + } + + @ApiOperation("ɾָûϢ") + @RequestMapping(value = "/delete/{id}",method = RequestMethod.POST) + @ResponseBody + public Object delete(@PathVariable Long id){ + int count = adminService.delete(id); + if(count>0){ + return new CommonResult().success(count); + } + return new CommonResult().failed(); + } + + @ApiOperation("ûɫ") + @RequestMapping(value = "/role/update",method = RequestMethod.POST) + @ResponseBody + public Object updateRole(@RequestParam("adminId") Long adminId,//½ɫ + @RequestParam("roleIds") List roleIds){ + int count = adminService.updateRole(adminId,roleIds); + if(count>=0){ + return new CommonResult().success(count); + } + return new CommonResult().failed(); + } + + @ApiOperation("ȡָûĽɫ") + @RequestMapping(value = "/role/{adminId}",method = RequestMethod.GET) + @ResponseBody + public Object getRoleList(@PathVariable Long adminId){//ȡָûɫб + List roleList = adminService.getRoleList(adminId); + return new CommonResult().success(roleList); + } + + @ApiOperation("û+ - Ȩ") + @RequestMapping(value = "/permission/update",method = RequestMethod.POST) + @ResponseBody + public Object updatePermission(@RequestParam Long adminId, + @RequestParam("permissionIds") List permissionIds){ + int count = adminService.updatePermission(adminId,permissionIds); + if(count>0){ + return new CommonResult().success(count); + } + return new CommonResult().failed(); + } + + @ApiOperation("ȡûȨޣ+ - Ȩޣ") + @RequestMapping(value = "/permission/{adminId}",method = RequestMethod.GET) + @ResponseBody + public Object getPermissionList(@PathVariable Long adminId){ + List permissionList = adminService.getPermissionList(adminId); + return new CommonResult().success(permissionList); + } +} \ No newline at end of file