新增权限管理相关接口
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package com.macro.mall.bo;
|
||||
|
||||
import com.macro.mall.model.UmsAdmin;
|
||||
import com.macro.mall.model.UmsPermission;
|
||||
import com.macro.mall.model.UmsResource;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
@@ -16,18 +16,17 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class AdminUserDetails implements UserDetails {
|
||||
private UmsAdmin umsAdmin;
|
||||
private List<UmsPermission> permissionList;
|
||||
public AdminUserDetails(UmsAdmin umsAdmin,List<UmsPermission> permissionList) {
|
||||
private List<UmsResource> resourceList;
|
||||
public AdminUserDetails(UmsAdmin umsAdmin,List<UmsResource> resourceList) {
|
||||
this.umsAdmin = umsAdmin;
|
||||
this.permissionList = permissionList;
|
||||
this.resourceList = resourceList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
//返回当前用户的权限
|
||||
return permissionList.stream()
|
||||
.filter(permission -> permission.getValue()!=null)
|
||||
.map(permission ->new SimpleGrantedAuthority(permission.getValue()))
|
||||
//返回当前用户的角色
|
||||
return resourceList.stream()
|
||||
.map(role ->new SimpleGrantedAuthority(role.getId()+":"+role.getName()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +1,56 @@
|
||||
package com.macro.mall.config;
|
||||
|
||||
import com.macro.mall.model.UmsResource;
|
||||
import com.macro.mall.security.component.DynamicSecurityService;
|
||||
import com.macro.mall.security.config.SecurityConfig;
|
||||
import com.macro.mall.service.UmsAdminService;
|
||||
import com.macro.mall.service.UmsResourceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.access.ConfigAttribute;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* mall-security模块相关配置
|
||||
* Created by macro on 2019/11/5.
|
||||
* Created by macro on 2019/11/9.
|
||||
*/
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@EnableGlobalMethodSecurity(prePostEnabled=true)
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
public class MallSecurityConfig extends SecurityConfig {
|
||||
|
||||
@Autowired
|
||||
private UmsAdminService adminService;
|
||||
@Autowired
|
||||
private UmsResourceService resourceService;
|
||||
|
||||
@Bean
|
||||
public UserDetailsService userDetailsService() {
|
||||
//获取登录用户信息
|
||||
return username -> adminService.loadUserByUsername(username);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DynamicSecurityService dynamicSecurityService() {
|
||||
return new DynamicSecurityService() {
|
||||
@Override
|
||||
public Map<String, ConfigAttribute> loadDataSource() {
|
||||
Map<String, ConfigAttribute> map = new ConcurrentHashMap<>();
|
||||
List<UmsResource> resourceList = resourceService.listAll();
|
||||
for (UmsResource resource : resourceList) {
|
||||
map.put(resource.getUrl(), new org.springframework.security.access.SecurityConfig(resource.getId() + ":" + resource.getName()));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.macro.mall.service.PmsBrandService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -30,7 +29,6 @@ public class PmsBrandController {
|
||||
@ApiOperation(value = "获取全部品牌列表")
|
||||
@RequestMapping(value = "/listAll", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:brand:read')")
|
||||
public CommonResult<List<PmsBrand>> getList() {
|
||||
return CommonResult.success(brandService.listAllBrand());
|
||||
}
|
||||
@@ -38,7 +36,6 @@ public class PmsBrandController {
|
||||
@ApiOperation(value = "添加品牌")
|
||||
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:brand:create')")
|
||||
public CommonResult create(@Validated @RequestBody PmsBrandParam pmsBrand, BindingResult result) {
|
||||
CommonResult commonResult;
|
||||
int count = brandService.createBrand(pmsBrand);
|
||||
@@ -53,7 +50,6 @@ public class PmsBrandController {
|
||||
@ApiOperation(value = "更新品牌")
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:brand:update')")
|
||||
public CommonResult update(@PathVariable("id") Long id,
|
||||
@Validated @RequestBody PmsBrandParam pmsBrandParam,
|
||||
BindingResult result) {
|
||||
@@ -70,7 +66,6 @@ public class PmsBrandController {
|
||||
@ApiOperation(value = "删除品牌")
|
||||
@RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:brand:delete')")
|
||||
public CommonResult delete(@PathVariable("id") Long id) {
|
||||
int count = brandService.deleteBrand(id);
|
||||
if (count == 1) {
|
||||
@@ -83,7 +78,6 @@ public class PmsBrandController {
|
||||
@ApiOperation(value = "根据品牌名称分页获取品牌列表")
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:brand:read')")
|
||||
public CommonResult<CommonPage<PmsBrand>> getList(@RequestParam(value = "keyword", required = false) String keyword,
|
||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
|
||||
@@ -94,7 +88,6 @@ public class PmsBrandController {
|
||||
@ApiOperation(value = "根据编号查询品牌信息")
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:brand:read')")
|
||||
public CommonResult<PmsBrand> getItem(@PathVariable("id") Long id) {
|
||||
return CommonResult.success(brandService.getBrand(id));
|
||||
}
|
||||
@@ -102,7 +95,6 @@ public class PmsBrandController {
|
||||
@ApiOperation(value = "批量删除品牌")
|
||||
@RequestMapping(value = "/delete/batch", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:brand:delete')")
|
||||
public CommonResult deleteBatch(@RequestParam("ids") List<Long> ids) {
|
||||
int count = brandService.deleteBrand(ids);
|
||||
if (count > 0) {
|
||||
@@ -115,7 +107,6 @@ public class PmsBrandController {
|
||||
@ApiOperation(value = "批量更新显示状态")
|
||||
@RequestMapping(value = "/update/showStatus", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:brand:update')")
|
||||
public CommonResult updateShowStatus(@RequestParam("ids") List<Long> ids,
|
||||
@RequestParam("showStatus") Integer showStatus) {
|
||||
int count = brandService.updateShowStatus(ids, showStatus);
|
||||
@@ -129,7 +120,6 @@ public class PmsBrandController {
|
||||
@ApiOperation(value = "批量更新厂家制造商状态")
|
||||
@RequestMapping(value = "/update/factoryStatus", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:brand:update')")
|
||||
public CommonResult updateFactoryStatus(@RequestParam("ids") List<Long> ids,
|
||||
@RequestParam("factoryStatus") Integer factoryStatus) {
|
||||
int count = brandService.updateFactoryStatus(ids, factoryStatus);
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.macro.mall.service.PmsProductCategoryService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -31,7 +30,6 @@ public class PmsProductCategoryController {
|
||||
@ApiOperation("添加产品分类")
|
||||
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:productCategory:create')")
|
||||
public CommonResult create(@Validated @RequestBody PmsProductCategoryParam productCategoryParam,
|
||||
BindingResult result) {
|
||||
int count = productCategoryService.create(productCategoryParam);
|
||||
@@ -45,7 +43,6 @@ public class PmsProductCategoryController {
|
||||
@ApiOperation("修改商品分类")
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:productCategory:update')")
|
||||
public CommonResult update(@PathVariable Long id,
|
||||
@Validated
|
||||
@RequestBody PmsProductCategoryParam productCategoryParam,
|
||||
@@ -61,7 +58,6 @@ public class PmsProductCategoryController {
|
||||
@ApiOperation("分页查询商品分类")
|
||||
@RequestMapping(value = "/list/{parentId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:productCategory:read')")
|
||||
public CommonResult<CommonPage<PmsProductCategory>> getList(@PathVariable Long parentId,
|
||||
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
|
||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
|
||||
@@ -72,7 +68,6 @@ public class PmsProductCategoryController {
|
||||
@ApiOperation("根据id获取商品分类")
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:productCategory:read')")
|
||||
public CommonResult<PmsProductCategory> getItem(@PathVariable Long id) {
|
||||
PmsProductCategory productCategory = productCategoryService.getItem(id);
|
||||
return CommonResult.success(productCategory);
|
||||
@@ -81,7 +76,6 @@ public class PmsProductCategoryController {
|
||||
@ApiOperation("删除商品分类")
|
||||
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:productCategory:delete')")
|
||||
public CommonResult delete(@PathVariable Long id) {
|
||||
int count = productCategoryService.delete(id);
|
||||
if (count > 0) {
|
||||
@@ -94,7 +88,6 @@ public class PmsProductCategoryController {
|
||||
@ApiOperation("修改导航栏显示状态")
|
||||
@RequestMapping(value = "/update/navStatus", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:productCategory:update')")
|
||||
public CommonResult updateNavStatus(@RequestParam("ids") List<Long> ids, @RequestParam("navStatus") Integer navStatus) {
|
||||
int count = productCategoryService.updateNavStatus(ids, navStatus);
|
||||
if (count > 0) {
|
||||
@@ -107,7 +100,6 @@ public class PmsProductCategoryController {
|
||||
@ApiOperation("修改显示状态")
|
||||
@RequestMapping(value = "/update/showStatus", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:productCategory:update')")
|
||||
public CommonResult updateShowStatus(@RequestParam("ids") List<Long> ids, @RequestParam("showStatus") Integer showStatus) {
|
||||
int count = productCategoryService.updateShowStatus(ids, showStatus);
|
||||
if (count > 0) {
|
||||
@@ -120,7 +112,6 @@ public class PmsProductCategoryController {
|
||||
@ApiOperation("查询所有一级分类及子分类")
|
||||
@RequestMapping(value = "/list/withChildren", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:productCategory:read')")
|
||||
public CommonResult<List<PmsProductCategoryWithChildrenItem>> listWithChildren() {
|
||||
List<PmsProductCategoryWithChildrenItem> list = productCategoryService.listWithChildren();
|
||||
return CommonResult.success(list);
|
||||
|
||||
@@ -10,7 +10,6 @@ import com.macro.mall.service.PmsProductService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -31,7 +30,6 @@ public class PmsProductController {
|
||||
@ApiOperation("创建商品")
|
||||
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:product:create')")
|
||||
public CommonResult create(@RequestBody PmsProductParam productParam, BindingResult bindingResult) {
|
||||
int count = productService.create(productParam);
|
||||
if (count > 0) {
|
||||
@@ -44,7 +42,6 @@ public class PmsProductController {
|
||||
@ApiOperation("根据商品id获取商品编辑信息")
|
||||
@RequestMapping(value = "/updateInfo/{id}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:product:read')")
|
||||
public CommonResult<PmsProductResult> getUpdateInfo(@PathVariable Long id) {
|
||||
PmsProductResult productResult = productService.getUpdateInfo(id);
|
||||
return CommonResult.success(productResult);
|
||||
@@ -53,7 +50,6 @@ public class PmsProductController {
|
||||
@ApiOperation("更新商品")
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:product:update')")
|
||||
public CommonResult update(@PathVariable Long id, @RequestBody PmsProductParam productParam, BindingResult bindingResult) {
|
||||
int count = productService.update(id, productParam);
|
||||
if (count > 0) {
|
||||
@@ -66,7 +62,6 @@ public class PmsProductController {
|
||||
@ApiOperation("查询商品")
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:product:read')")
|
||||
public CommonResult<CommonPage<PmsProduct>> getList(PmsProductQueryParam productQueryParam,
|
||||
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
|
||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
|
||||
@@ -85,7 +80,6 @@ public class PmsProductController {
|
||||
@ApiOperation("批量修改审核状态")
|
||||
@RequestMapping(value = "/update/verifyStatus", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:product:update')")
|
||||
public CommonResult updateVerifyStatus(@RequestParam("ids") List<Long> ids,
|
||||
@RequestParam("verifyStatus") Integer verifyStatus,
|
||||
@RequestParam("detail") String detail) {
|
||||
@@ -100,7 +94,6 @@ public class PmsProductController {
|
||||
@ApiOperation("批量上下架")
|
||||
@RequestMapping(value = "/update/publishStatus", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:product:update')")
|
||||
public CommonResult updatePublishStatus(@RequestParam("ids") List<Long> ids,
|
||||
@RequestParam("publishStatus") Integer publishStatus) {
|
||||
int count = productService.updatePublishStatus(ids, publishStatus);
|
||||
@@ -114,7 +107,6 @@ public class PmsProductController {
|
||||
@ApiOperation("批量推荐商品")
|
||||
@RequestMapping(value = "/update/recommendStatus", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:product:update')")
|
||||
public CommonResult updateRecommendStatus(@RequestParam("ids") List<Long> ids,
|
||||
@RequestParam("recommendStatus") Integer recommendStatus) {
|
||||
int count = productService.updateRecommendStatus(ids, recommendStatus);
|
||||
@@ -128,7 +120,6 @@ public class PmsProductController {
|
||||
@ApiOperation("批量设为新品")
|
||||
@RequestMapping(value = "/update/newStatus", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:product:update')")
|
||||
public CommonResult updateNewStatus(@RequestParam("ids") List<Long> ids,
|
||||
@RequestParam("newStatus") Integer newStatus) {
|
||||
int count = productService.updateNewStatus(ids, newStatus);
|
||||
@@ -142,7 +133,6 @@ public class PmsProductController {
|
||||
@ApiOperation("批量修改删除状态")
|
||||
@RequestMapping(value = "/update/deleteStatus", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasAuthority('pms:product:delete')")
|
||||
public CommonResult updateDeleteStatus(@RequestParam("ids") List<Long> ids,
|
||||
@RequestParam("deleteStatus") Integer deleteStatus) {
|
||||
int count = productService.updateDeleteStatus(ids, deleteStatus);
|
||||
|
||||
@@ -4,10 +4,12 @@ import com.macro.mall.common.api.CommonPage;
|
||||
import com.macro.mall.common.api.CommonResult;
|
||||
import com.macro.mall.dto.UmsAdminLoginParam;
|
||||
import com.macro.mall.dto.UmsAdminParam;
|
||||
import com.macro.mall.dto.UpdateAdminPasswordParam;
|
||||
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 com.macro.mall.service.UmsRoleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -30,12 +32,14 @@ import java.util.Map;
|
||||
@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;
|
||||
@Autowired
|
||||
private UmsAdminService adminService;
|
||||
@Autowired
|
||||
private UmsRoleService roleService;
|
||||
|
||||
@ApiOperation(value = "用户注册")
|
||||
@RequestMapping(value = "/register", method = RequestMethod.POST)
|
||||
@@ -81,11 +85,15 @@ public class UmsAdminController {
|
||||
@RequestMapping(value = "/info", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult getAdminInfo(Principal principal) {
|
||||
if(principal==null){
|
||||
return CommonResult.unauthorized(null);
|
||||
}
|
||||
String username = principal.getName();
|
||||
UmsAdmin umsAdmin = adminService.getAdminByUsername(username);
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("username", umsAdmin.getUsername());
|
||||
data.put("roles", new String[]{"TEST"});
|
||||
data.put("menus", roleService.getMenuList(umsAdmin.getId()));
|
||||
data.put("icon", umsAdmin.getIcon());
|
||||
return CommonResult.success(data);
|
||||
}
|
||||
@@ -100,10 +108,10 @@ public class UmsAdminController {
|
||||
@ApiOperation("根据用户名或姓名分页获取用户列表")
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult<CommonPage<UmsAdmin>> list(@RequestParam(value = "name", required = false) String name,
|
||||
public CommonResult<CommonPage<UmsAdmin>> list(@RequestParam(value = "keyword", required = false) String keyword,
|
||||
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
|
||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
|
||||
List<UmsAdmin> adminList = adminService.list(name, pageSize, pageNum);
|
||||
List<UmsAdmin> adminList = adminService.list(keyword, pageSize, pageNum);
|
||||
return CommonResult.success(CommonPage.restPage(adminList));
|
||||
}
|
||||
|
||||
@@ -126,6 +134,24 @@ public class UmsAdminController {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
|
||||
@ApiOperation("修改指定用户密码")
|
||||
@RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult updatePassword(@RequestBody UpdateAdminPasswordParam updatePasswordParam) {
|
||||
int status = adminService.updatePassword(updatePasswordParam);
|
||||
if (status > 0) {
|
||||
return CommonResult.success(status);
|
||||
} else if (status == -1) {
|
||||
return CommonResult.failed("提交参数不合法");
|
||||
} else if (status == -2) {
|
||||
return CommonResult.failed("找不到该用户");
|
||||
} else if (status == -3) {
|
||||
return CommonResult.failed("旧密码错误");
|
||||
} else {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("删除指定用户信息")
|
||||
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@@ -137,6 +163,19 @@ public class UmsAdminController {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
|
||||
@ApiOperation("修改帐号状态")
|
||||
@RequestMapping(value = "/updateStatus/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult updateStatus(@PathVariable Long id,@RequestParam(value = "status") Integer status) {
|
||||
UmsAdmin umsAdmin = new UmsAdmin();
|
||||
umsAdmin.setStatus(status);
|
||||
int count = adminService.update(id,umsAdmin);
|
||||
if (count > 0) {
|
||||
return CommonResult.success(count);
|
||||
}
|
||||
return CommonResult.failed();
|
||||
}
|
||||
|
||||
@ApiOperation("给用户分配角色")
|
||||
@RequestMapping(value = "/role/update", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.macro.mall.controller;
|
||||
|
||||
import com.macro.mall.common.api.CommonPage;
|
||||
import com.macro.mall.common.api.CommonResult;
|
||||
import com.macro.mall.dto.UmsMenuNode;
|
||||
import com.macro.mall.model.UmsMenu;
|
||||
import com.macro.mall.service.UmsMenuService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后台菜单管理Controller
|
||||
* Created by macro on 2020/2/4.
|
||||
*/
|
||||
@Controller
|
||||
@Api(tags = "UmsMenuController", description = "后台菜单管理")
|
||||
@RequestMapping("/menu")
|
||||
public class UmsMenuController {
|
||||
|
||||
@Autowired
|
||||
private UmsMenuService menuService;
|
||||
|
||||
@ApiOperation("添加后台菜单")
|
||||
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult create(@RequestBody UmsMenu umsMenu) {
|
||||
int count = menuService.create(umsMenu);
|
||||
if (count > 0) {
|
||||
return CommonResult.success(count);
|
||||
} else {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("修改后台菜单")
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult update(@PathVariable Long id,
|
||||
@RequestBody UmsMenu umsMenu) {
|
||||
int count = menuService.update(id, umsMenu);
|
||||
if (count > 0) {
|
||||
return CommonResult.success(count);
|
||||
} else {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("根据ID获取菜单详情")
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult<UmsMenu> getItem(@PathVariable Long id) {
|
||||
UmsMenu umsMenu = menuService.getItem(id);
|
||||
return CommonResult.success(umsMenu);
|
||||
}
|
||||
|
||||
@ApiOperation("根据ID删除后台菜单")
|
||||
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult delete(@PathVariable Long id) {
|
||||
int count = menuService.delete(id);
|
||||
if (count > 0) {
|
||||
return CommonResult.success(count);
|
||||
} else {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("分页查询后台菜单")
|
||||
@RequestMapping(value = "/list/{parentId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult<CommonPage<UmsMenu>> list(@PathVariable Long parentId,
|
||||
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
|
||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
|
||||
List<UmsMenu> menuList = menuService.list(parentId, pageSize, pageNum);
|
||||
return CommonResult.success(CommonPage.restPage(menuList));
|
||||
}
|
||||
|
||||
@ApiOperation("树形结构返回所有菜单列表")
|
||||
@RequestMapping(value = "/treeList", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult<List<UmsMenuNode>> treeList() {
|
||||
List<UmsMenuNode> list = menuService.treeList();
|
||||
return CommonResult.success(list);
|
||||
}
|
||||
|
||||
@ApiOperation("修改菜单显示状态")
|
||||
@RequestMapping(value = "/updateHidden/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult updateHidden(@PathVariable Long id, @RequestParam("hidden") Integer hidden) {
|
||||
int count = menuService.updateHidden(id, hidden);
|
||||
if (count > 0) {
|
||||
return CommonResult.success(count);
|
||||
} else {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.macro.mall.controller;
|
||||
|
||||
import com.macro.mall.common.api.CommonResult;
|
||||
import com.macro.mall.model.UmsResourceCategory;
|
||||
import com.macro.mall.service.UmsResourceCategoryService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后台资源分类管理Controller
|
||||
* Created by macro on 2020/2/5.
|
||||
*/
|
||||
@Controller
|
||||
@Api(tags = "UmsResourceCategoryController", description = "后台资源分类管理")
|
||||
@RequestMapping("/resourceCategory")
|
||||
public class UmsResourceCategoryController {
|
||||
@Autowired
|
||||
private UmsResourceCategoryService resourceCategoryService;
|
||||
|
||||
@ApiOperation("查询所有后台资源分类")
|
||||
@RequestMapping(value = "/listAll", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult<List<UmsResourceCategory>> listAll() {
|
||||
List<UmsResourceCategory> resourceList = resourceCategoryService.listAll();
|
||||
return CommonResult.success(resourceList);
|
||||
}
|
||||
|
||||
@ApiOperation("添加后台资源分类")
|
||||
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult create(@RequestBody UmsResourceCategory umsResourceCategory) {
|
||||
int count = resourceCategoryService.create(umsResourceCategory);
|
||||
if (count > 0) {
|
||||
return CommonResult.success(count);
|
||||
} else {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("修改后台资源分类")
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult update(@PathVariable Long id,
|
||||
@RequestBody UmsResourceCategory umsResourceCategory) {
|
||||
int count = resourceCategoryService.update(id, umsResourceCategory);
|
||||
if (count > 0) {
|
||||
return CommonResult.success(count);
|
||||
} else {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("根据ID删除后台资源")
|
||||
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult delete(@PathVariable Long id) {
|
||||
int count = resourceCategoryService.delete(id);
|
||||
if (count > 0) {
|
||||
return CommonResult.success(count);
|
||||
} else {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.macro.mall.controller;
|
||||
|
||||
import com.macro.mall.common.api.CommonPage;
|
||||
import com.macro.mall.common.api.CommonResult;
|
||||
import com.macro.mall.model.UmsResource;
|
||||
import com.macro.mall.security.component.DynamicSecurityMetadataSource;
|
||||
import com.macro.mall.service.UmsResourceService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后台资源管理Controller
|
||||
* Created by macro on 2020/2/4.
|
||||
*/
|
||||
@Controller
|
||||
@Api(tags = "UmsResourceController", description = "后台资源管理")
|
||||
@RequestMapping("/resource")
|
||||
public class UmsResourceController {
|
||||
|
||||
@Autowired
|
||||
private UmsResourceService resourceService;
|
||||
@Autowired
|
||||
private DynamicSecurityMetadataSource dynamicSecurityMetadataSource;
|
||||
|
||||
@ApiOperation("添加后台资源")
|
||||
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult create(@RequestBody UmsResource umsResource) {
|
||||
int count = resourceService.create(umsResource);
|
||||
dynamicSecurityMetadataSource.clearDataSource();
|
||||
if (count > 0) {
|
||||
return CommonResult.success(count);
|
||||
} else {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("修改后台资源")
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult update(@PathVariable Long id,
|
||||
@RequestBody UmsResource umsResource) {
|
||||
int count = resourceService.update(id, umsResource);
|
||||
dynamicSecurityMetadataSource.clearDataSource();
|
||||
if (count > 0) {
|
||||
return CommonResult.success(count);
|
||||
} else {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("根据ID获取资源详情")
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult<UmsResource> getItem(@PathVariable Long id) {
|
||||
UmsResource umsResource = resourceService.getItem(id);
|
||||
return CommonResult.success(umsResource);
|
||||
}
|
||||
|
||||
@ApiOperation("根据ID删除后台资源")
|
||||
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult delete(@PathVariable Long id) {
|
||||
int count = resourceService.delete(id);
|
||||
dynamicSecurityMetadataSource.clearDataSource();
|
||||
if (count > 0) {
|
||||
return CommonResult.success(count);
|
||||
} else {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("分页模糊查询后台资源")
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult<CommonPage<UmsResource>> list(@RequestParam(required = false) Long categoryId,
|
||||
@RequestParam(required = false) String nameKeyword,
|
||||
@RequestParam(required = false) String urlKeyword,
|
||||
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
|
||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
|
||||
List<UmsResource> resourceList = resourceService.list(categoryId,nameKeyword, urlKeyword, pageSize, pageNum);
|
||||
return CommonResult.success(CommonPage.restPage(resourceList));
|
||||
}
|
||||
|
||||
@ApiOperation("查询所有后台资源")
|
||||
@RequestMapping(value = "/listAll", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult<List<UmsResource>> listAll() {
|
||||
List<UmsResource> resourceList = resourceService.listAll();
|
||||
return CommonResult.success(resourceList);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.macro.mall.controller;
|
||||
|
||||
import com.macro.mall.common.api.CommonPage;
|
||||
import com.macro.mall.common.api.CommonResult;
|
||||
import com.macro.mall.model.UmsPermission;
|
||||
import com.macro.mall.model.UmsRole;
|
||||
import com.macro.mall.model.*;
|
||||
import com.macro.mall.service.UmsRoleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -77,11 +77,66 @@ public class UmsRoleController {
|
||||
}
|
||||
|
||||
@ApiOperation("获取所有角色")
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/listAll", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object list() {
|
||||
public CommonResult<List<UmsRole>> listAll() {
|
||||
List<UmsRole> roleList = roleService.list();
|
||||
return CommonResult.success(roleList);
|
||||
}
|
||||
|
||||
@ApiOperation("根据角色名称分页获取角色列表")
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult<CommonPage<UmsRole>> list(@RequestParam(value = "keyword", required = false) String keyword,
|
||||
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
|
||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
|
||||
List<UmsRole> roleList = roleService.list(keyword, pageSize, pageNum);
|
||||
return CommonResult.success(CommonPage.restPage(roleList));
|
||||
}
|
||||
|
||||
@ApiOperation("修改角色状态")
|
||||
@RequestMapping(value = "/updateStatus/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult updateStatus(@PathVariable Long id, @RequestParam(value = "status") Integer status) {
|
||||
UmsRole umsRole = new UmsRole();
|
||||
umsRole.setStatus(status);
|
||||
int count = roleService.update(id, umsRole);
|
||||
if (count > 0) {
|
||||
return CommonResult.success(count);
|
||||
}
|
||||
return CommonResult.failed();
|
||||
}
|
||||
|
||||
@ApiOperation("获取角色相关菜单")
|
||||
@RequestMapping(value = "/listMenu/{roleId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult<List<UmsMenu>> listMenu(@PathVariable Long roleId) {
|
||||
List<UmsMenu> roleList = roleService.listMenu(roleId);
|
||||
return CommonResult.success(roleList);
|
||||
}
|
||||
|
||||
@ApiOperation("获取角色相关资源")
|
||||
@RequestMapping(value = "/listResource/{roleId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult<List<UmsResource>> listResource(@PathVariable Long roleId) {
|
||||
List<UmsResource> roleList = roleService.listResource(roleId);
|
||||
return CommonResult.success(roleList);
|
||||
}
|
||||
|
||||
@ApiOperation("给角色分配菜单")
|
||||
@RequestMapping(value = "/allocMenu", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult allocMenu(@RequestParam Long roleId, @RequestParam List<Long> menuIds) {
|
||||
int count = roleService.allocMenu(roleId, menuIds);
|
||||
return CommonResult.success(count);
|
||||
}
|
||||
|
||||
@ApiOperation("给角色分配资源")
|
||||
@RequestMapping(value = "/allocResource", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult allocResource(@RequestParam Long roleId, @RequestParam List<Long> resourceIds) {
|
||||
int count = roleService.allocResource(roleId, resourceIds);
|
||||
return CommonResult.success(count);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,5 +10,8 @@ import java.util.List;
|
||||
* Created by macro on 2018/4/26.
|
||||
*/
|
||||
public interface CmsPrefrenceAreaProductRelationDao {
|
||||
/**
|
||||
* 批量创建
|
||||
*/
|
||||
int insertList(@Param("list") List<CmsPrefrenceAreaProductRelation> prefrenceAreaProductRelationList);
|
||||
}
|
||||
|
||||
@@ -10,5 +10,8 @@ import java.util.List;
|
||||
* Created by macro on 2018/4/26.
|
||||
*/
|
||||
public interface CmsSubjectProductRelationDao {
|
||||
/**
|
||||
* 批量创建
|
||||
*/
|
||||
int insertList(@Param("list") List<CmsSubjectProductRelation> subjectProductRelationList);
|
||||
}
|
||||
|
||||
@@ -10,5 +10,8 @@ import java.util.List;
|
||||
* Created by macro on 2018/10/12.
|
||||
*/
|
||||
public interface OmsOrderOperateHistoryDao {
|
||||
/**
|
||||
* 批量创建
|
||||
*/
|
||||
int insertList(@Param("list") List<OmsOrderOperateHistory> orderOperateHistoryList);
|
||||
}
|
||||
|
||||
@@ -10,5 +10,8 @@ import java.util.List;
|
||||
* Created by macro on 2018/4/26.
|
||||
*/
|
||||
public interface PmsMemberPriceDao {
|
||||
/**
|
||||
* 批量创建
|
||||
*/
|
||||
int insertList(@Param("list") List<PmsMemberPrice> memberPriceList);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.macro.mall.dao;
|
||||
|
||||
import com.macro.mall.model.UmsAdminRoleRelation;
|
||||
import com.macro.mall.model.UmsPermission;
|
||||
import com.macro.mall.model.UmsResource;
|
||||
import com.macro.mall.model.UmsRole;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -31,4 +32,9 @@ public interface UmsAdminRoleRelationDao {
|
||||
* 获取用户所有权限(包括+-权限)
|
||||
*/
|
||||
List<UmsPermission> getPermissionList(@Param("adminId") Long adminId);
|
||||
|
||||
/**
|
||||
* 获取用户所有可访问资源
|
||||
*/
|
||||
List<UmsResource> getResourceList(@Param("adminId") Long adminId);
|
||||
}
|
||||
|
||||
19
mall-admin/src/main/java/com/macro/mall/dao/UmsRoleDao.java
Normal file
19
mall-admin/src/main/java/com/macro/mall/dao/UmsRoleDao.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.macro.mall.dao;
|
||||
|
||||
import com.macro.mall.model.UmsMenu;
|
||||
import com.macro.mall.model.UmsResource;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后台用户角色自定义Dao
|
||||
* Created by macro on 2020/2/2.
|
||||
*/
|
||||
public interface UmsRoleDao {
|
||||
List<UmsMenu> getMenuList(@Param("adminId") Long adminId);
|
||||
|
||||
List<UmsMenu> getMenuListByRoleId(@Param("roleId") Long roleId);
|
||||
|
||||
List<UmsResource> getResourceListByRoleId(@Param("roleId") Long roleId);
|
||||
}
|
||||
17
mall-admin/src/main/java/com/macro/mall/dto/UmsMenuNode.java
Normal file
17
mall-admin/src/main/java/com/macro/mall/dto/UmsMenuNode.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.macro.mall.dto;
|
||||
|
||||
import com.macro.mall.model.UmsMenu;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后台菜单节点封装
|
||||
* Created by macro on 2020/2/4.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class UmsMenuNode extends UmsMenu {
|
||||
private List<UmsMenuNode> children;
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import lombok.Setter;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后台权限节点封装
|
||||
* Created by macro on 2018/9/30.
|
||||
*/
|
||||
public class UmsPermissionNode extends UmsPermission {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.macro.mall.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* 修改用户名密码参数
|
||||
* Created by macro on 2019/10/9.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class UpdateAdminPasswordParam {
|
||||
@ApiModelProperty(value = "用户名", required = true)
|
||||
@NotEmpty(message = "用户名不能为空")
|
||||
private String username;
|
||||
@ApiModelProperty(value = "旧密码", required = true)
|
||||
@NotEmpty(message = "旧密码不能为空")
|
||||
private String oldPassword;
|
||||
@ApiModelProperty(value = "新密码", required = true)
|
||||
@NotEmpty(message = "新密码不能为空")
|
||||
private String newPassword;
|
||||
}
|
||||
@@ -10,25 +10,49 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 产品分类Service
|
||||
* 商品分类Service
|
||||
* Created by macro on 2018/4/26.
|
||||
*/
|
||||
public interface PmsProductCategoryService {
|
||||
/**
|
||||
* 创建商品分类
|
||||
*/
|
||||
@Transactional
|
||||
int create(PmsProductCategoryParam pmsProductCategoryParam);
|
||||
|
||||
/**
|
||||
* 修改商品分类
|
||||
*/
|
||||
@Transactional
|
||||
int update(Long id, PmsProductCategoryParam pmsProductCategoryParam);
|
||||
|
||||
/**
|
||||
* 分页获取商品分类
|
||||
*/
|
||||
List<PmsProductCategory> getList(Long parentId, Integer pageSize, Integer pageNum);
|
||||
|
||||
/**
|
||||
* 删除商品分类
|
||||
*/
|
||||
int delete(Long id);
|
||||
|
||||
/**
|
||||
* 根据ID获取商品分类
|
||||
*/
|
||||
PmsProductCategory getItem(Long id);
|
||||
|
||||
/**
|
||||
* 批量修改导航状态
|
||||
*/
|
||||
int updateNavStatus(List<Long> ids, Integer navStatus);
|
||||
|
||||
/**
|
||||
* 批量修改显示状态
|
||||
*/
|
||||
int updateShowStatus(List<Long> ids, Integer showStatus);
|
||||
|
||||
/**
|
||||
* 以层级形式获取商品分类
|
||||
*/
|
||||
List<PmsProductCategoryWithChildrenItem> listWithChildren();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.macro.mall.service;
|
||||
|
||||
import com.macro.mall.dto.UmsAdminParam;
|
||||
import com.macro.mall.dto.UpdateAdminPasswordParam;
|
||||
import com.macro.mall.model.UmsAdmin;
|
||||
import com.macro.mall.model.UmsPermission;
|
||||
import com.macro.mall.model.UmsResource;
|
||||
import com.macro.mall.model.UmsRole;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -46,7 +48,7 @@ public interface UmsAdminService {
|
||||
/**
|
||||
* 根据用户名或昵称分页查询用户
|
||||
*/
|
||||
List<UmsAdmin> list(String name, Integer pageSize, Integer pageNum);
|
||||
List<UmsAdmin> list(String keyword, Integer pageSize, Integer pageNum);
|
||||
|
||||
/**
|
||||
* 修改指定用户信息
|
||||
@@ -69,6 +71,11 @@ public interface UmsAdminService {
|
||||
*/
|
||||
List<UmsRole> getRoleList(Long adminId);
|
||||
|
||||
/**
|
||||
* 获取指定用户的可访问资源
|
||||
*/
|
||||
List<UmsResource> getResourceList(Long adminId);
|
||||
|
||||
/**
|
||||
* 修改用户的+-权限
|
||||
*/
|
||||
@@ -80,6 +87,11 @@ public interface UmsAdminService {
|
||||
*/
|
||||
List<UmsPermission> getPermissionList(Long adminId);
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
int updatePassword(UpdateAdminPasswordParam updatePasswordParam);
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.macro.mall.service;
|
||||
|
||||
import com.macro.mall.dto.UmsMenuNode;
|
||||
import com.macro.mall.model.UmsMenu;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后台菜单管理Service
|
||||
* Created by macro on 2020/2/2.
|
||||
*/
|
||||
public interface UmsMenuService {
|
||||
/**
|
||||
* 创建后台菜单
|
||||
*/
|
||||
int create(UmsMenu umsMenu);
|
||||
|
||||
/**
|
||||
* 修改后台菜单
|
||||
*/
|
||||
int update(Long id, UmsMenu umsMenu);
|
||||
|
||||
/**
|
||||
* 根据ID获取菜单详情
|
||||
*/
|
||||
UmsMenu getItem(Long id);
|
||||
|
||||
/**
|
||||
* 根据ID删除菜单
|
||||
*/
|
||||
int delete(Long id);
|
||||
|
||||
/**
|
||||
* 分页查询后台菜单
|
||||
*/
|
||||
List<UmsMenu> list(Long parentId, Integer pageSize, Integer pageNum);
|
||||
|
||||
/**
|
||||
* 树形结构返回所有菜单列表
|
||||
*/
|
||||
List<UmsMenuNode> treeList();
|
||||
|
||||
/**
|
||||
* 修改菜单显示状态
|
||||
*/
|
||||
int updateHidden(Long id, Integer hidden);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.macro.mall.service;
|
||||
|
||||
import com.macro.mall.model.UmsResourceCategory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后台资源分类管理Service
|
||||
* Created by macro on 2020/2/5.
|
||||
*/
|
||||
public interface UmsResourceCategoryService {
|
||||
|
||||
/**
|
||||
* 获取所有资源分类
|
||||
*/
|
||||
List<UmsResourceCategory> listAll();
|
||||
|
||||
/**
|
||||
* 创建资源分类
|
||||
*/
|
||||
int create(UmsResourceCategory umsResourceCategory);
|
||||
|
||||
/**
|
||||
* 修改资源分类
|
||||
*/
|
||||
int update(Long id, UmsResourceCategory umsResourceCategory);
|
||||
|
||||
/**
|
||||
* 删除资源分类
|
||||
*/
|
||||
int delete(Long id);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.macro.mall.service;
|
||||
|
||||
import com.macro.mall.model.UmsResource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后台资源管理Service
|
||||
* Created by macro on 2020/2/2.
|
||||
*/
|
||||
public interface UmsResourceService {
|
||||
/**
|
||||
* 添加资源
|
||||
*/
|
||||
int create(UmsResource umsResource);
|
||||
|
||||
/**
|
||||
* 修改资源
|
||||
*/
|
||||
int update(Long id, UmsResource umsResource);
|
||||
|
||||
/**
|
||||
* 获取资源详情
|
||||
*/
|
||||
UmsResource getItem(Long id);
|
||||
|
||||
/**
|
||||
* 删除资源
|
||||
*/
|
||||
int delete(Long id);
|
||||
|
||||
/**
|
||||
* 分页查询资源
|
||||
*/
|
||||
List<UmsResource> list(Long categoryId, String nameKeyword, String urlKeyword, Integer pageSize, Integer pageNum);
|
||||
|
||||
/**
|
||||
* 查询全部资源
|
||||
*/
|
||||
List<UmsResource> listAll();
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.macro.mall.service;
|
||||
|
||||
import com.macro.mall.model.UmsMenu;
|
||||
import com.macro.mall.model.UmsPermission;
|
||||
import com.macro.mall.model.UmsResource;
|
||||
import com.macro.mall.model.UmsRole;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -38,7 +40,39 @@ public interface UmsRoleService {
|
||||
int updatePermission(Long roleId, List<Long> permissionIds);
|
||||
|
||||
/**
|
||||
* 获取角色列表
|
||||
* 获取所有角色列表
|
||||
*/
|
||||
List<UmsRole> list();
|
||||
|
||||
/**
|
||||
* 分页获取角色列表
|
||||
*/
|
||||
List<UmsRole> list(String keyword, Integer pageSize, Integer pageNum);
|
||||
|
||||
/**
|
||||
* 根据管理员ID获取对应菜单
|
||||
*/
|
||||
List<UmsMenu> getMenuList(Long adminId);
|
||||
|
||||
/**
|
||||
* 获取角色相关菜单
|
||||
*/
|
||||
List<UmsMenu> listMenu(Long roleId);
|
||||
|
||||
/**
|
||||
* 获取角色相关资源
|
||||
*/
|
||||
List<UmsResource> listResource(Long roleId);
|
||||
|
||||
/**
|
||||
* 给角色分配菜单
|
||||
*/
|
||||
@Transactional
|
||||
int allocMenu(Long roleId, List<Long> menuIds);
|
||||
|
||||
/**
|
||||
* 给角色分配资源
|
||||
*/
|
||||
@Transactional
|
||||
int allocResource(Long roleId, List<Long> resourceIds);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.macro.mall.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.macro.mall.dao.*;
|
||||
import com.macro.mall.dto.PmsProductParam;
|
||||
@@ -8,7 +9,6 @@ import com.macro.mall.dto.PmsProductResult;
|
||||
import com.macro.mall.mapper.*;
|
||||
import com.macro.mall.model.*;
|
||||
import com.macro.mall.service.PmsProductService;
|
||||
import io.swagger.annotations.Example;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -21,6 +21,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 商品管理Service实现类
|
||||
@@ -71,7 +72,7 @@ public class PmsProductServiceImpl implements PmsProductService {
|
||||
PmsProduct product = productParam;
|
||||
product.setId(null);
|
||||
productMapper.insertSelective(product);
|
||||
//根据促销类型设置价格:、阶梯价格、满减价格
|
||||
//根据促销类型设置价格:会员价格、阶梯价格、满减价格
|
||||
Long productId = product.getId();
|
||||
//会员价格
|
||||
relateAndInsertList(memberPriceDao, productParam.getMemberPriceList(), productId);
|
||||
@@ -139,11 +140,7 @@ public class PmsProductServiceImpl implements PmsProductService {
|
||||
productFullReductionMapper.deleteByExample(fullReductionExample);
|
||||
relateAndInsertList(productFullReductionDao, productParam.getProductFullReductionList(), id);
|
||||
//修改sku库存信息
|
||||
PmsSkuStockExample skuStockExample = new PmsSkuStockExample();
|
||||
skuStockExample.createCriteria().andProductIdEqualTo(id);
|
||||
skuStockMapper.deleteByExample(skuStockExample);
|
||||
handleSkuStockCode(productParam.getSkuStockList(),id);
|
||||
relateAndInsertList(skuStockDao, productParam.getSkuStockList(), id);
|
||||
handleUpdateSkuStockList(id, productParam);
|
||||
//修改商品参数,添加自定义商品规格
|
||||
PmsProductAttributeValueExample productAttributeValueExample = new PmsProductAttributeValueExample();
|
||||
productAttributeValueExample.createCriteria().andProductIdEqualTo(id);
|
||||
@@ -163,6 +160,49 @@ public class PmsProductServiceImpl implements PmsProductService {
|
||||
return count;
|
||||
}
|
||||
|
||||
private void handleUpdateSkuStockList(Long id, PmsProductParam productParam) {
|
||||
//当前的sku信息
|
||||
List<PmsSkuStock> currSkuList = productParam.getSkuStockList();
|
||||
//当前没有sku直接删除
|
||||
if(CollUtil.isEmpty(currSkuList)){
|
||||
PmsSkuStockExample skuStockExample = new PmsSkuStockExample();
|
||||
skuStockExample.createCriteria().andProductIdEqualTo(id);
|
||||
skuStockMapper.deleteByExample(skuStockExample);
|
||||
return;
|
||||
}
|
||||
//获取初始sku信息
|
||||
PmsSkuStockExample skuStockExample = new PmsSkuStockExample();
|
||||
skuStockExample.createCriteria().andProductIdEqualTo(id);
|
||||
List<PmsSkuStock> oriStuList = skuStockMapper.selectByExample(skuStockExample);
|
||||
//获取新增sku信息
|
||||
List<PmsSkuStock> insertSkuList = currSkuList.stream().filter(item->item.getId()==null).collect(Collectors.toList());
|
||||
//获取需要更新的sku信息
|
||||
List<PmsSkuStock> updateSkuList = currSkuList.stream().filter(item->item.getId()!=null).collect(Collectors.toList());
|
||||
List<Long> updateSkuIds = updateSkuList.stream().map(PmsSkuStock::getId).collect(Collectors.toList());
|
||||
//获取需要删除的sku信息
|
||||
List<PmsSkuStock> removeSkuList = oriStuList.stream().filter(item-> !updateSkuIds.contains(item.getId())).collect(Collectors.toList());
|
||||
handleSkuStockCode(insertSkuList,id);
|
||||
handleSkuStockCode(updateSkuList,id);
|
||||
//新增sku
|
||||
if(CollUtil.isNotEmpty(insertSkuList)){
|
||||
relateAndInsertList(skuStockDao, insertSkuList, id);
|
||||
}
|
||||
//删除sku
|
||||
if(CollUtil.isNotEmpty(removeSkuList)){
|
||||
List<Long> removeSkuIds = removeSkuList.stream().map(PmsSkuStock::getId).collect(Collectors.toList());
|
||||
PmsSkuStockExample removeExample = new PmsSkuStockExample();
|
||||
removeExample.createCriteria().andIdIn(removeSkuIds);
|
||||
skuStockMapper.deleteByExample(removeExample);
|
||||
}
|
||||
//修改sku
|
||||
if(CollUtil.isNotEmpty(updateSkuList)){
|
||||
for (PmsSkuStock pmsSkuStock : updateSkuList) {
|
||||
skuStockMapper.updateByPrimaryKeySelective(pmsSkuStock);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PmsProduct> list(PmsProductQueryParam productQueryParam, Integer pageSize, Integer pageNum) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
@@ -260,70 +300,6 @@ public class PmsProductServiceImpl implements PmsProductService {
|
||||
return productMapper.selectByExample(productExample);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 旧版创建
|
||||
*/
|
||||
public int createOld(PmsProductParam productParam) {
|
||||
int count;
|
||||
//创建商品
|
||||
PmsProduct product = productParam;
|
||||
product.setId(null);
|
||||
productMapper.insertSelective(product);
|
||||
//根据促销类型设置价格:、阶梯价格、满减价格
|
||||
Long productId = product.getId();
|
||||
//会员价格
|
||||
List<PmsMemberPrice> memberPriceList = productParam.getMemberPriceList();
|
||||
if (!CollectionUtils.isEmpty(memberPriceList)) {
|
||||
for (PmsMemberPrice pmsMemberPrice : memberPriceList) {
|
||||
pmsMemberPrice.setId(null);
|
||||
pmsMemberPrice.setProductId(productId);
|
||||
}
|
||||
memberPriceDao.insertList(memberPriceList);
|
||||
}
|
||||
//阶梯价格
|
||||
List<PmsProductLadder> productLadderList = productParam.getProductLadderList();
|
||||
if (!CollectionUtils.isEmpty(productLadderList)) {
|
||||
for (PmsProductLadder productLadder : productLadderList) {
|
||||
productLadder.setId(null);
|
||||
productLadder.setProductId(productId);
|
||||
}
|
||||
productLadderDao.insertList(productLadderList);
|
||||
}
|
||||
//满减价格
|
||||
List<PmsProductFullReduction> productFullReductionList = productParam.getProductFullReductionList();
|
||||
if (!CollectionUtils.isEmpty(productFullReductionList)) {
|
||||
for (PmsProductFullReduction productFullReduction : productFullReductionList) {
|
||||
productFullReduction.setId(null);
|
||||
productFullReduction.setProductId(productId);
|
||||
}
|
||||
productFullReductionDao.insertList(productFullReductionList);
|
||||
}
|
||||
//添加sku库存信息
|
||||
List<PmsSkuStock> skuStockList = productParam.getSkuStockList();
|
||||
if (!CollectionUtils.isEmpty(skuStockList)) {
|
||||
for (PmsSkuStock skuStock : skuStockList) {
|
||||
skuStock.setId(null);
|
||||
skuStock.setProductId(productId);
|
||||
}
|
||||
skuStockDao.insertList(skuStockList);
|
||||
}
|
||||
//添加商品参数,添加自定义商品规格
|
||||
List<PmsProductAttributeValue> productAttributeValueList = productParam.getProductAttributeValueList();
|
||||
if (!CollectionUtils.isEmpty(productAttributeValueList)) {
|
||||
for (PmsProductAttributeValue productAttributeValue : productAttributeValueList) {
|
||||
productAttributeValue.setId(null);
|
||||
productAttributeValue.setProductId(productId);
|
||||
}
|
||||
productAttributeValueDao.insertList(productAttributeValueList);
|
||||
}
|
||||
//关联专题
|
||||
relateAndInsertList(subjectProductRelationDao, productParam.getSubjectProductRelationList(), productId);
|
||||
//关联优选
|
||||
relateAndInsertList(prefrenceAreaProductRelationDao, productParam.getPrefrenceAreaProductRelationList(), productId);
|
||||
count = 1;
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 建立和插入关系表操作
|
||||
*
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.macro.mall.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.macro.mall.bo.AdminUserDetails;
|
||||
import com.macro.mall.dao.UmsAdminPermissionRelationDao;
|
||||
import com.macro.mall.dao.UmsAdminRoleRelationDao;
|
||||
import com.macro.mall.dto.UmsAdminParam;
|
||||
import com.macro.mall.dto.UpdateAdminPasswordParam;
|
||||
import com.macro.mall.mapper.UmsAdminLoginLogMapper;
|
||||
import com.macro.mall.mapper.UmsAdminMapper;
|
||||
import com.macro.mall.mapper.UmsAdminPermissionRelationMapper;
|
||||
@@ -147,13 +150,13 @@ public class UmsAdminServiceImpl implements UmsAdminService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UmsAdmin> list(String name, Integer pageSize, Integer pageNum) {
|
||||
public List<UmsAdmin> list(String keyword, Integer pageSize, Integer pageNum) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
UmsAdminExample example = new UmsAdminExample();
|
||||
UmsAdminExample.Criteria criteria = example.createCriteria();
|
||||
if (!StringUtils.isEmpty(name)) {
|
||||
criteria.andUsernameLike("%" + name + "%");
|
||||
example.or(example.createCriteria().andNickNameLike("%" + name + "%"));
|
||||
if (!StringUtils.isEmpty(keyword)) {
|
||||
criteria.andUsernameLike("%" + keyword + "%");
|
||||
example.or(example.createCriteria().andNickNameLike("%" + keyword + "%"));
|
||||
}
|
||||
return adminMapper.selectByExample(example);
|
||||
}
|
||||
@@ -161,8 +164,18 @@ public class UmsAdminServiceImpl implements UmsAdminService {
|
||||
@Override
|
||||
public int update(Long id, UmsAdmin admin) {
|
||||
admin.setId(id);
|
||||
//密码已经加密处理,需要单独修改
|
||||
admin.setPassword(null);
|
||||
UmsAdmin rawAdmin = adminMapper.selectByPrimaryKey(id);
|
||||
if(rawAdmin.getPassword().equals(admin.getPassword())){
|
||||
//与原加密密码相同的不需要修改
|
||||
admin.setPassword(null);
|
||||
}else{
|
||||
//与原加密密码不同的需要加密修改
|
||||
if(StrUtil.isEmpty(admin.getPassword())){
|
||||
admin.setPassword(null);
|
||||
}else{
|
||||
admin.setPassword(passwordEncoder.encode(admin.getPassword()));
|
||||
}
|
||||
}
|
||||
return adminMapper.updateByPrimaryKeySelective(admin);
|
||||
}
|
||||
|
||||
@@ -197,6 +210,11 @@ public class UmsAdminServiceImpl implements UmsAdminService {
|
||||
return adminRoleRelationDao.getRoleList(adminId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UmsResource> getResourceList(Long adminId) {
|
||||
return adminRoleRelationDao.getResourceList(adminId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updatePermission(Long adminId, List<Long> permissionIds) {
|
||||
//删除原所有权限关系
|
||||
@@ -239,12 +257,35 @@ public class UmsAdminServiceImpl implements UmsAdminService {
|
||||
return adminRoleRelationDao.getPermissionList(adminId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updatePassword(UpdateAdminPasswordParam param) {
|
||||
if(StrUtil.isEmpty(param.getUsername())
|
||||
||StrUtil.isEmpty(param.getOldPassword())
|
||||
||StrUtil.isEmpty(param.getNewPassword())){
|
||||
return -1;
|
||||
}
|
||||
UmsAdminExample example = new UmsAdminExample();
|
||||
example.createCriteria().andUsernameEqualTo(param.getUsername());
|
||||
List<UmsAdmin> adminList = adminMapper.selectByExample(example);
|
||||
if(CollUtil.isEmpty(adminList)){
|
||||
return -2;
|
||||
}
|
||||
UmsAdmin umsAdmin = adminList.get(0);
|
||||
if(!passwordEncoder.matches(param.getOldPassword(),umsAdmin.getPassword())){
|
||||
return -3;
|
||||
}
|
||||
umsAdmin.setPassword(passwordEncoder.encode(param.getNewPassword()));
|
||||
adminMapper.updateByPrimaryKey(umsAdmin);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username){
|
||||
//获取用户信息
|
||||
UmsAdmin admin = getAdminByUsername(username);
|
||||
if (admin != null) {
|
||||
List<UmsPermission> permissionList = getPermissionList(admin.getId());
|
||||
return new AdminUserDetails(admin,permissionList);
|
||||
List<UmsResource> resourceList = getResourceList(admin.getId());
|
||||
return new AdminUserDetails(admin,resourceList);
|
||||
}
|
||||
throw new UsernameNotFoundException("用户名或密码错误");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.macro.mall.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.macro.mall.dto.UmsMenuNode;
|
||||
import com.macro.mall.mapper.UmsMenuMapper;
|
||||
import com.macro.mall.model.*;
|
||||
import com.macro.mall.service.UmsMenuService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 后台菜单管理Service实现类
|
||||
* Created by macro on 2020/2/2.
|
||||
*/
|
||||
@Service
|
||||
public class UmsMenuServiceImpl implements UmsMenuService {
|
||||
@Autowired
|
||||
private UmsMenuMapper menuMapper;
|
||||
|
||||
@Override
|
||||
public int create(UmsMenu umsMenu) {
|
||||
umsMenu.setCreateTime(new Date());
|
||||
updateLevel(umsMenu);
|
||||
return menuMapper.insert(umsMenu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改菜单层级
|
||||
*/
|
||||
private void updateLevel(UmsMenu umsMenu) {
|
||||
if (umsMenu.getParentId() == 0) {
|
||||
//没有父菜单时为一级菜单
|
||||
umsMenu.setLevel(0);
|
||||
} else {
|
||||
//有父菜单时选择根据父菜单level设置
|
||||
UmsMenu parentMenu = menuMapper.selectByPrimaryKey(umsMenu.getParentId());
|
||||
if (parentMenu != null) {
|
||||
umsMenu.setLevel(parentMenu.getLevel() + 1);
|
||||
} else {
|
||||
umsMenu.setLevel(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Long id, UmsMenu umsMenu) {
|
||||
umsMenu.setId(id);
|
||||
updateLevel(umsMenu);
|
||||
return menuMapper.updateByPrimaryKeySelective(umsMenu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UmsMenu getItem(Long id) {
|
||||
return menuMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Long id) {
|
||||
return menuMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UmsMenu> list(Long parentId, Integer pageSize, Integer pageNum) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
UmsMenuExample example = new UmsMenuExample();
|
||||
example.setOrderByClause("sort desc");
|
||||
example.createCriteria().andParentIdEqualTo(parentId);
|
||||
return menuMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UmsMenuNode> treeList() {
|
||||
List<UmsMenu> menuList = menuMapper.selectByExample(new UmsMenuExample());
|
||||
List<UmsMenuNode> result = menuList.stream()
|
||||
.filter(menu -> menu.getParentId().equals(0L))
|
||||
.map(menu -> covertMenuNode(menu, menuList)).collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateHidden(Long id, Integer hidden) {
|
||||
UmsMenu umsMenu = new UmsMenu();
|
||||
umsMenu.setId(id);
|
||||
umsMenu.setHidden(hidden);
|
||||
return menuMapper.updateByPrimaryKeySelective(umsMenu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将UmsMenu转化为UmsMenuNode并设置children属性
|
||||
*/
|
||||
private UmsMenuNode covertMenuNode(UmsMenu menu, List<UmsMenu> menuList) {
|
||||
UmsMenuNode node = new UmsMenuNode();
|
||||
BeanUtils.copyProperties(menu, node);
|
||||
List<UmsMenuNode> children = menuList.stream()
|
||||
.filter(subMenu -> subMenu.getParentId().equals(menu.getId()))
|
||||
.map(subMenu -> covertMenuNode(subMenu, menuList)).collect(Collectors.toList());
|
||||
node.setChildren(children);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.macro.mall.service.impl;
|
||||
|
||||
import com.macro.mall.mapper.UmsResourceCategoryMapper;
|
||||
import com.macro.mall.model.UmsResourceCategory;
|
||||
import com.macro.mall.model.UmsResourceCategoryExample;
|
||||
import com.macro.mall.service.UmsResourceCategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后台资源分类管理Service实现类
|
||||
* Created by macro on 2020/2/5.
|
||||
*/
|
||||
@Service
|
||||
public class UmsResourceCategoryServiceImpl implements UmsResourceCategoryService {
|
||||
@Autowired
|
||||
private UmsResourceCategoryMapper resourceCategoryMapper;
|
||||
|
||||
@Override
|
||||
public List<UmsResourceCategory> listAll() {
|
||||
UmsResourceCategoryExample example = new UmsResourceCategoryExample();
|
||||
example.setOrderByClause("sort desc");
|
||||
return resourceCategoryMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int create(UmsResourceCategory umsResourceCategory) {
|
||||
umsResourceCategory.setCreateTime(new Date());
|
||||
return resourceCategoryMapper.insert(umsResourceCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Long id, UmsResourceCategory umsResourceCategory) {
|
||||
umsResourceCategory.setId(id);
|
||||
return resourceCategoryMapper.updateByPrimaryKeySelective(umsResourceCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Long id) {
|
||||
return resourceCategoryMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.macro.mall.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.macro.mall.mapper.UmsResourceMapper;
|
||||
import com.macro.mall.model.UmsResource;
|
||||
import com.macro.mall.model.UmsResourceExample;
|
||||
import com.macro.mall.service.UmsResourceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后台资源管理Service实现类
|
||||
* Created by macro on 2020/2/2.
|
||||
*/
|
||||
@Service
|
||||
public class UmsResourceServiceImpl implements UmsResourceService {
|
||||
@Autowired
|
||||
private UmsResourceMapper resourceMapper;
|
||||
@Override
|
||||
public int create(UmsResource umsResource) {
|
||||
umsResource.setCreateTime(new Date());
|
||||
return resourceMapper.insert(umsResource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Long id, UmsResource umsResource) {
|
||||
umsResource.setId(id);
|
||||
return resourceMapper.updateByPrimaryKeySelective(umsResource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UmsResource getItem(Long id) {
|
||||
return resourceMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Long id) {
|
||||
return resourceMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UmsResource> list(Long categoryId, String nameKeyword, String urlKeyword, Integer pageSize, Integer pageNum) {
|
||||
PageHelper.startPage(pageNum,pageSize);
|
||||
UmsResourceExample example = new UmsResourceExample();
|
||||
UmsResourceExample.Criteria criteria = example.createCriteria();
|
||||
if(categoryId!=null){
|
||||
criteria.andCategoryIdEqualTo(categoryId);
|
||||
}
|
||||
if(StrUtil.isNotEmpty(nameKeyword)){
|
||||
criteria.andNameLike('%'+nameKeyword+'%');
|
||||
}
|
||||
if(StrUtil.isNotEmpty(urlKeyword)){
|
||||
criteria.andUrlLike('%'+urlKeyword+'%');
|
||||
}
|
||||
return resourceMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UmsResource> listAll() {
|
||||
return resourceMapper.selectByExample(new UmsResourceExample());
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,17 @@
|
||||
package com.macro.mall.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.macro.mall.dao.UmsRoleDao;
|
||||
import com.macro.mall.dao.UmsRolePermissionRelationDao;
|
||||
import com.macro.mall.mapper.UmsRoleMapper;
|
||||
import com.macro.mall.mapper.UmsRoleMenuRelationMapper;
|
||||
import com.macro.mall.mapper.UmsRolePermissionRelationMapper;
|
||||
import com.macro.mall.mapper.UmsRoleResourceRelationMapper;
|
||||
import com.macro.mall.model.*;
|
||||
import com.macro.mall.service.UmsRoleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -23,11 +28,16 @@ public class UmsRoleServiceImpl implements UmsRoleService {
|
||||
@Autowired
|
||||
private UmsRolePermissionRelationMapper rolePermissionRelationMapper;
|
||||
@Autowired
|
||||
private UmsRoleMenuRelationMapper roleMenuRelationMapper;
|
||||
@Autowired
|
||||
private UmsRoleResourceRelationMapper roleResourceRelationMapper;
|
||||
@Autowired
|
||||
private UmsRolePermissionRelationDao rolePermissionRelationDao;
|
||||
@Autowired
|
||||
private UmsRoleDao roleDao;
|
||||
@Override
|
||||
public int create(UmsRole role) {
|
||||
role.setCreateTime(new Date());
|
||||
role.setStatus(1);
|
||||
role.setAdminCount(0);
|
||||
role.setSort(0);
|
||||
return roleMapper.insert(role);
|
||||
@@ -36,7 +46,7 @@ public class UmsRoleServiceImpl implements UmsRoleService {
|
||||
@Override
|
||||
public int update(Long id, UmsRole role) {
|
||||
role.setId(id);
|
||||
return roleMapper.updateByPrimaryKey(role);
|
||||
return roleMapper.updateByPrimaryKeySelective(role);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,4 +82,61 @@ public class UmsRoleServiceImpl implements UmsRoleService {
|
||||
public List<UmsRole> list() {
|
||||
return roleMapper.selectByExample(new UmsRoleExample());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UmsRole> list(String keyword, Integer pageSize, Integer pageNum) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
UmsRoleExample example = new UmsRoleExample();
|
||||
if (!StringUtils.isEmpty(keyword)) {
|
||||
example.createCriteria().andNameLike("%" + keyword + "%");
|
||||
}
|
||||
return roleMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UmsMenu> getMenuList(Long adminId) {
|
||||
return roleDao.getMenuList(adminId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UmsMenu> listMenu(Long roleId) {
|
||||
return roleDao.getMenuListByRoleId(roleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UmsResource> listResource(Long roleId) {
|
||||
return roleDao.getResourceListByRoleId(roleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int allocMenu(Long roleId, List<Long> menuIds) {
|
||||
//先删除原有关系
|
||||
UmsRoleMenuRelationExample example=new UmsRoleMenuRelationExample();
|
||||
example.createCriteria().andRoleIdEqualTo(roleId);
|
||||
roleMenuRelationMapper.deleteByExample(example);
|
||||
//批量插入新关系
|
||||
for (Long menuId : menuIds) {
|
||||
UmsRoleMenuRelation relation = new UmsRoleMenuRelation();
|
||||
relation.setRoleId(roleId);
|
||||
relation.setMenuId(menuId);
|
||||
roleMenuRelationMapper.insert(relation);
|
||||
}
|
||||
return menuIds.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int allocResource(Long roleId, List<Long> resourceIds) {
|
||||
//先删除原有关系
|
||||
UmsRoleResourceRelationExample example=new UmsRoleResourceRelationExample();
|
||||
example.createCriteria().andRoleIdEqualTo(roleId);
|
||||
roleResourceRelationMapper.deleteByExample(example);
|
||||
//批量插入新关系
|
||||
for (Long resourceId : resourceIds) {
|
||||
UmsRoleResourceRelation relation = new UmsRoleResourceRelation();
|
||||
relation.setRoleId(roleId);
|
||||
relation.setResourceId(resourceId);
|
||||
roleResourceRelationMapper.insert(relation);
|
||||
}
|
||||
return resourceIds.size();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user