mirror of https://gitee.com/stylefeng/roses
【7.1.6】接口资源添加判断是否是当前系统的接口字段,修复默认的接口资源不能用的问题
parent
dddb3a04f7
commit
7872aebde3
|
@ -61,6 +61,12 @@ public class ApiResourceRequest extends BaseRequest {
|
|||
@ChineseDescription("接口自定义名称,区别于sys_resource表的名称")
|
||||
private String apiAlias;
|
||||
|
||||
/**
|
||||
* 是否是当前系统资源:Y-是,N-否
|
||||
*/
|
||||
@ChineseDescription("是否是当前系统资源:Y-是,N-否")
|
||||
private String currentSystemFlag;
|
||||
|
||||
/**
|
||||
* 资源唯一编码,关联sys_resource表的code
|
||||
*/
|
||||
|
|
|
@ -52,6 +52,13 @@ public class ApiResource extends BaseEntity {
|
|||
@ChineseDescription("接口自定义名称,区别于sys_resource表的名称")
|
||||
private String apiAlias;
|
||||
|
||||
/**
|
||||
* 是否是当前系统资源:Y-是,N-否
|
||||
*/
|
||||
@TableField("current_system_flag")
|
||||
@ChineseDescription("是否是当前系统资源:Y-是,N-否")
|
||||
private String currentSystemFlag;
|
||||
|
||||
/**
|
||||
* 资源唯一编码,关联sys_resource表的code
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.resource.framework;
|
||||
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.service.ApiResourceService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author majianguo
|
||||
* @date 2021/12/2 11:58
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@Order(Integer.MAX_VALUE - 1)
|
||||
public class ApiResourceApplicationRunner implements ApplicationRunner {
|
||||
|
||||
@Autowired
|
||||
private ApiResourceService apiResourceService;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
apiResourceService.refreshTableData();
|
||||
}
|
||||
}
|
|
@ -5,7 +5,6 @@ import cn.stylefeng.roses.kernel.system.api.pojo.resource.ApiGroupRequest;
|
|||
import cn.stylefeng.roses.kernel.system.api.pojo.resource.ApiResourceFieldRequest;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.resource.ApiResourceRequest;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.ApiResourceField;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -107,4 +106,25 @@ public interface ApiResourceService extends IService<ApiResource> {
|
|||
* @date 2021/6/18 下午6:28
|
||||
**/
|
||||
List<ApiResource> dataList(ApiGroupRequest apiGroupRequest);
|
||||
|
||||
/**
|
||||
* 刷新表中的数据
|
||||
* <p>
|
||||
* 把表中的resource_code中的app code和当前启动的app code对应
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/12/2 13:49
|
||||
**/
|
||||
void refreshTableData();
|
||||
|
||||
/**
|
||||
* 根据应用编码更新接口资源
|
||||
*
|
||||
* @param oldAppCode 等待替换的应用编码
|
||||
* @param newAppCode 新应用编码
|
||||
* @param currentSystemFlag 是否是当前系统
|
||||
* @author majianguo
|
||||
* @date 2021/12/2 14:30
|
||||
**/
|
||||
void updateApiResourceByAppCode(String oldAppCode, String newAppCode, String currentSystemFlag);
|
||||
}
|
|
@ -8,6 +8,7 @@ import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
|||
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.SymbolConstant;
|
||||
import cn.stylefeng.roses.kernel.rule.context.ApplicationPropertiesContext;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.pojo.resource.FieldMetadata;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.pojo.resource.ResourceDefinition;
|
||||
|
@ -31,9 +32,9 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
@ -76,7 +77,7 @@ public class ApiResourceServiceImpl extends ServiceImpl<ApiResourceMapper, ApiRe
|
|||
LambdaQueryWrapper<SysResource> sysResourceLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
// 如果是控制器名称,则查询模块下的所有资源
|
||||
if (!apiResourceRequest.getResourceCode().contains("$")) {
|
||||
if (!apiResourceRequest.getResourceCode().contains(SymbolConstant.DOLLAR)) {
|
||||
sysResourceLambdaQueryWrapper.eq(SysResource::getModularCode, apiResourceRequest.getResourceCode());
|
||||
sysResourceLambdaQueryWrapper.eq(SysResource::getViewFlag, YesOrNotEnum.N.getCode());
|
||||
List<SysResource> sysResourceList = sysResourceService.list(sysResourceLambdaQueryWrapper);
|
||||
|
@ -121,6 +122,14 @@ public class ApiResourceServiceImpl extends ServiceImpl<ApiResourceMapper, ApiRe
|
|||
// 设置资源code
|
||||
apiResource.setResourceCode(sysResource.getResourceCode());
|
||||
|
||||
// 是否是当前系统资源
|
||||
String applicationName = ApplicationPropertiesContext.getInstance().getApplicationName();
|
||||
String currentSystemFlag = YesOrNotEnum.N.getCode();
|
||||
if (applicationName.equals(sysResource.getAppCode())) {
|
||||
currentSystemFlag = YesOrNotEnum.Y.getCode();
|
||||
}
|
||||
apiResource.setCurrentSystemFlag(currentSystemFlag);
|
||||
|
||||
// 设置排序
|
||||
if (ObjectUtil.isEmpty(apiResourceRequest.getResourceSort())) {
|
||||
index = index.add(BigDecimal.ONE);
|
||||
|
@ -219,10 +228,7 @@ public class ApiResourceServiceImpl extends ServiceImpl<ApiResourceMapper, ApiRe
|
|||
List<ApiResourceField> apiResourceFields = this.apiResourceFieldService.list(apiResourceFieldLambdaQueryWrapper);
|
||||
|
||||
// 过滤创建时间和创建人
|
||||
apiResourceFields.removeIf(resourceField -> "createTime".equalsIgnoreCase(resourceField.getFieldCode())
|
||||
|| "createUser".equalsIgnoreCase(resourceField.getFieldCode())
|
||||
|| "updateTime".equalsIgnoreCase(resourceField.getFieldCode())
|
||||
|| "updateUser".equalsIgnoreCase(resourceField.getFieldCode()));
|
||||
apiResourceFields.removeIf(resourceField -> "createTime".equalsIgnoreCase(resourceField.getFieldCode()) || "createUser".equalsIgnoreCase(resourceField.getFieldCode()) || "updateTime".equalsIgnoreCase(resourceField.getFieldCode()) || "updateUser".equalsIgnoreCase(resourceField.getFieldCode()));
|
||||
|
||||
List<ApiResourceFieldRequest> apiResourceFieldList = new ArrayList<>();
|
||||
for (ApiResourceField apiResourceField : apiResourceFields) {
|
||||
|
@ -350,6 +356,29 @@ public class ApiResourceServiceImpl extends ServiceImpl<ApiResourceMapper, ApiRe
|
|||
return this.baseMapper.dataList(apiGroupRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshTableData() {
|
||||
LambdaQueryWrapper<ApiResource> apiResourceLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
apiResourceLambdaQueryWrapper.eq(ApiResource::getCurrentSystemFlag, YesOrNotEnum.Y.getCode());
|
||||
apiResourceLambdaQueryWrapper.last("limit 1");
|
||||
ApiResource apiResource = this.getOne(apiResourceLambdaQueryWrapper);
|
||||
if (ObjectUtil.isNotEmpty(apiResource)) {
|
||||
String resourceCode = apiResource.getResourceCode();
|
||||
String oldAppCode = resourceCode.substring(0, resourceCode.indexOf(SymbolConstant.DOLLAR));
|
||||
String newAppCode = ApplicationPropertiesContext.getInstance().getApplicationName();
|
||||
this.updateApiResourceByAppCode(oldAppCode, newAppCode, YesOrNotEnum.Y.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateApiResourceByAppCode(String oldAppCode, String newAppCode, String currentSystemFlag) {
|
||||
LambdaUpdateWrapper<ApiResource> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
lambdaUpdateWrapper.eq(ApiResource::getCurrentSystemFlag, currentSystemFlag);
|
||||
lambdaUpdateWrapper.setSql("resource_code=replace(resource_code, '" + oldAppCode + SymbolConstant.DOLLAR + "', '" + newAppCode + SymbolConstant.DOLLAR + "')");
|
||||
this.update(lambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiResource> findList(ApiResourceRequest apiResourceRequest) {
|
||||
LambdaQueryWrapper<ApiResource> wrapper = this.createWrapper(apiResourceRequest);
|
||||
|
@ -382,6 +411,7 @@ public class ApiResourceServiceImpl extends ServiceImpl<ApiResourceMapper, ApiRe
|
|||
Long apiResourceId = apiResourceRequest.getApiResourceId();
|
||||
Long groupId = apiResourceRequest.getGroupId();
|
||||
String apiAlias = apiResourceRequest.getApiAlias();
|
||||
String currentSystemFlag = apiResourceRequest.getCurrentSystemFlag();
|
||||
String resourceCode = apiResourceRequest.getResourceCode();
|
||||
String lastRequestContent = apiResourceRequest.getLastRequestContent();
|
||||
String lastResponseContent = apiResourceRequest.getLastResponseContent();
|
||||
|
@ -395,6 +425,7 @@ public class ApiResourceServiceImpl extends ServiceImpl<ApiResourceMapper, ApiRe
|
|||
queryWrapper.eq(ObjectUtil.isNotNull(groupId), ApiResource::getGroupId, groupId);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(apiAlias), ApiResource::getApiAlias, apiAlias);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(resourceCode), ApiResource::getResourceCode, resourceCode);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(currentSystemFlag), ApiResource::getCurrentSystemFlag, currentSystemFlag);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(lastRequestContent), ApiResource::getLastRequestContent, lastRequestContent);
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(lastResponseContent), ApiResource::getLastResponseContent, lastResponseContent);
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(resourceSort), ApiResource::getResourceSort, resourceSort);
|
||||
|
|
Loading…
Reference in New Issue