Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
563e8d4096
|
|
@ -1,11 +1,27 @@
|
|||
package com.czg;
|
||||
|
||||
import com.czg.account.entity.SysMenu;
|
||||
import com.czg.account.entity.SysRolesMenus;
|
||||
import com.czg.account.service.SysMenuService;
|
||||
import com.czg.account.service.SysRolesMenusService;
|
||||
import com.czg.annotation.SaAdminCheckPermission;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
|
|
@ -15,9 +31,42 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|||
@EnableTransactionManagement
|
||||
@MapperScan("com.czg.service.account.mapper")
|
||||
@EnableDubbo
|
||||
public class AccountApplication {
|
||||
@Slf4j
|
||||
public class AccountApplication implements CommandLineRunner {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AccountApplication.class, args);
|
||||
}
|
||||
@Autowired
|
||||
private RequestMappingHandlerMapping requestMappingHandlerMapping;
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
@Autowired
|
||||
private SysRolesMenusService sysRolesMenusService;
|
||||
|
||||
public void run(String... args) {
|
||||
Map<RequestMappingInfo, HandlerMethod> handlerMethods = this.requestMappingHandlerMapping.getHandlerMethods();
|
||||
handlerMethods.forEach((key, value) -> {
|
||||
Method method = value.getMethod();
|
||||
SaAdminCheckPermission annotation = AnnotationUtils.getAnnotation(method, SaAdminCheckPermission.class);
|
||||
if (annotation == null) return;
|
||||
for (String s : annotation.value()) {
|
||||
long count = sysMenuService.queryChain().eq(SysMenu::getPermission, s).count();
|
||||
if (count > 0) {
|
||||
continue;
|
||||
}
|
||||
SysMenu sysMenu = new SysMenu();
|
||||
sysMenu.setPermission(s);
|
||||
sysMenu.setName(s);
|
||||
sysMenu.setType(2);
|
||||
sysMenuService.save(sysMenu);
|
||||
SysRolesMenus sysRolesMenus = new SysRolesMenus();
|
||||
sysRolesMenus.setMenuId(sysMenu.getMenuId());
|
||||
sysRolesMenus.setRoleId(1L);
|
||||
sysRolesMenusService.save(sysRolesMenus);
|
||||
log.info("接口菜单添加成功, 菜单名称: {}, 菜单权限: {}", sysMenu.getName(), sysMenu.getPermission());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,14 @@ import com.czg.account.entity.SysRole;
|
|||
import com.czg.account.service.SysRoleService;
|
||||
import com.czg.annotation.SaAdminCheckPermission;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* 角色管理
|
||||
|
|
@ -37,6 +40,18 @@ public class RoleController {
|
|||
return CzgResult.success(roleService.getList(pageDTO, key, startTime, endTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色对应的菜单
|
||||
* 权限标识: role:menu
|
||||
* @param id 角色id
|
||||
* @return 分页数据
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "role:menu")
|
||||
@GetMapping("/menu")
|
||||
public CzgResult<List<Long>> getRoleMenu(@RequestParam Integer id) {
|
||||
return CzgResult.success(roleService.getRoleMenu(StpKit.USER.getLoginIdAsLong(), id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增角色
|
||||
* 权限标识: role:add
|
||||
|
|
|
|||
|
|
@ -44,6 +44,10 @@ public class MenuAddDTO {
|
|||
* 组件
|
||||
*/
|
||||
private String component;
|
||||
/**
|
||||
* 组件名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 菜单排序
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -38,6 +38,10 @@ public class MenuEditDTO {
|
|||
* 组件
|
||||
*/
|
||||
private String component;
|
||||
/**
|
||||
* 组件名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 菜单排序
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -39,12 +39,6 @@ public class ShopUserAddDTO {
|
|||
*/
|
||||
private Integer sex;
|
||||
|
||||
/**
|
||||
* 用户Id
|
||||
*/
|
||||
@NotNull(message = "用户id不为空")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 账户积分
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -24,4 +24,6 @@ public interface SysRoleService extends IService<SysRole> {
|
|||
Boolean add(RoleAddDTO roleAddDTO);
|
||||
|
||||
Boolean edit(RoleEditDTO roleEditDTO);
|
||||
|
||||
List<Long> getRoleMenu(long loginIdAsLong, Integer id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,12 +109,11 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
|
|||
|
||||
@Override
|
||||
public Boolean add(Long shopId, ShopUserAddDTO shopUserAddDTO) {
|
||||
long userCount = userInfoService.queryChain().eq(UserInfo::getId, shopUserAddDTO.getUserId()).count();
|
||||
if (userCount == 0) {
|
||||
throw new ApiNotPrintException("用户信息不存在");
|
||||
}
|
||||
long count = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, shopUserAddDTO.getUserId()).count();
|
||||
if (count > 0) {
|
||||
UserInfo userInfo = userInfoService.queryChain().eq(UserInfo::getPhone, shopUserAddDTO.getPhone()).one();
|
||||
if (userInfo == null) {
|
||||
userInfo = BeanUtil.copyProperties(shopUserAddDTO, UserInfo.class);
|
||||
userInfoService.save(userInfo);
|
||||
}else {
|
||||
throw new ApiNotPrintException("此用户已存在");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,6 +67,15 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> imp
|
|||
return page(new Page<>(pageDTO.page(), pageDTO.size()), queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getRoleMenu(long userId, Integer id) {
|
||||
SysRole role = queryChain().eq(SysRole::getId, id).eq(SysRole::getCreateUserId, userId).one();
|
||||
if (role == null) {
|
||||
throw new ApiNotPrintException("角色不存在");
|
||||
}
|
||||
return sysRolesMenusService.queryChain().eq(SysRolesMenus::getRoleId, id).list().stream().map(SysRolesMenus::getMenuId).toList();
|
||||
}
|
||||
|
||||
public boolean addMenu(Long roleId, List<Long> menuIds) {
|
||||
long count = sysMenuService.queryChain().in(SysMenu::getMenuId, menuIds).count();
|
||||
if (count != menuIds.size()) {
|
||||
|
|
|
|||
|
|
@ -23,13 +23,15 @@ public class Main {
|
|||
// packageName 指定生成代码项目
|
||||
// tableName 指定需要生成的表
|
||||
|
||||
// String servicePackageName = "system";
|
||||
// String servicePackageName = "account";
|
||||
// String servicePackageName = "product";
|
||||
// String packageName = "system";
|
||||
String packageName = "account";
|
||||
// String packageName = "product";
|
||||
// String packageName = "order";
|
||||
|
||||
String tableName = "tb_shop_table";
|
||||
String author = "zs";
|
||||
String tableName = "tb_shop_coupon_product";
|
||||
String author = "ww";
|
||||
//是否生成DTO实体 默认生成
|
||||
boolean isGenerateDto = true;
|
||||
|
||||
//配置数据源
|
||||
HikariDataSource dataSource = new HikariDataSource();
|
||||
|
|
@ -53,12 +55,14 @@ public class Main {
|
|||
serviceGenerator.generate();
|
||||
|
||||
//默认生成全参数DTO
|
||||
if(isGenerateDto){
|
||||
GlobalConfig dtoConfig = createDtoGlobalConfig(currentWorkingDirectory + "/cash-common/cash-common-service",
|
||||
basePackage + packageName, "tb", tableName);
|
||||
Generator dtoGenerator = new Generator(dataSource, dtoConfig);
|
||||
dtoConfig.setAuthor(author);
|
||||
dtoGenerator.generate();
|
||||
}
|
||||
}
|
||||
|
||||
public static GlobalConfig createGlobalConfigUseStyle(String projectPath, String packageName, String tablePrefix, String... tableNames) {
|
||||
//创建配置内容
|
||||
|
|
|
|||
Loading…
Reference in New Issue