【同步】BOOT 和 CLOUD 的功能
parent
1c95e12aea
commit
c0df6eab4e
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,8 @@
|
||||||
package cn.iocoder.yudao.framework.apilog.core.interceptor;
|
package cn.iocoder.yudao.framework.apilog.core.interceptor;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.io.resource.ResourceUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
|
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.spring.SpringUtils;
|
import cn.iocoder.yudao.framework.common.util.spring.SpringUtils;
|
||||||
|
@ -11,7 +13,11 @@ import org.springframework.util.StopWatch;
|
||||||
import org.springframework.web.method.HandlerMethod;
|
import org.springframework.web.method.HandlerMethod;
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API 访问日志 Interceptor
|
* API 访问日志 Interceptor
|
||||||
|
@ -49,6 +55,8 @@ public class ApiAccessLogInterceptor implements HandlerInterceptor {
|
||||||
StopWatch stopWatch = new StopWatch();
|
StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
request.setAttribute(ATTRIBUTE_STOP_WATCH, stopWatch);
|
request.setAttribute(ATTRIBUTE_STOP_WATCH, stopWatch);
|
||||||
|
// 打印 Controller 路径
|
||||||
|
printHandlerMethodPosition(handlerMethod);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -64,4 +72,32 @@ public class ApiAccessLogInterceptor implements HandlerInterceptor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印 Controller 方法路径
|
||||||
|
*/
|
||||||
|
private void printHandlerMethodPosition(HandlerMethod handlerMethod) {
|
||||||
|
if (handlerMethod == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Method method = handlerMethod.getMethod();
|
||||||
|
Class<?> clazz = method.getDeclaringClass();
|
||||||
|
try {
|
||||||
|
// 获取 method 的 lineNumber
|
||||||
|
List<String> clazzContents = FileUtil.readUtf8Lines(
|
||||||
|
ResourceUtil.getResource(null, clazz).getPath().replace("/target/classes/", "/src/main/java/")
|
||||||
|
+ clazz.getSimpleName() + ".java");
|
||||||
|
Optional<Integer> lineNumber = IntStream.range(0, clazzContents.size())
|
||||||
|
.filter(i -> clazzContents.get(i).contains(" " + method.getName() + "(")) // 简单匹配,不考虑方法重名
|
||||||
|
.mapToObj(i -> i + 1) // 行号从 1 开始
|
||||||
|
.findFirst();
|
||||||
|
if (!lineNumber.isPresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 打印结果
|
||||||
|
System.out.printf("\tController 方法路径:%s(%s.java:%d)\n", clazz.getName(), clazz.getSimpleName(), lineNumber.get());
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
// 忽略异常。原因:仅仅打印,非重要逻辑
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ public enum BpmProcessInstanceStatusEnum implements IntArrayValuable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] array() {
|
public int[] array() {
|
||||||
return new int[0];
|
return ARRAYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.springframework.security.config.annotation.web.configurers.AuthorizeH
|
||||||
* Infra 模块的 Security 配置
|
* Infra 模块的 Security 配置
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false, value = "infraSecurityConfiguration")
|
@Configuration(proxyBeanMethods = false, value = "infraSecurityConfiguration")
|
||||||
public class SecurityConfiguration {
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
@Value("${spring.boot.admin.context-path:''}")
|
@Value("${spring.boot.admin.context-path:''}")
|
||||||
private String adminSeverContextPath;
|
private String adminSeverContextPath;
|
||||||
|
|
|
@ -112,7 +112,7 @@ public class AppProductSpuController {
|
||||||
productBrowseHistoryService.createBrowseHistory(getLoginUserId(), id);
|
productBrowseHistoryService.createBrowseHistory(getLoginUserId(), id);
|
||||||
|
|
||||||
// 拼接返回
|
// 拼接返回
|
||||||
spu.setBrowseCount(spu.getBrowseCount() + spu.getVirtualSalesCount());
|
spu.setSalesCount(spu.getSalesCount() + spu.getVirtualSalesCount());
|
||||||
AppProductSpuDetailRespVO spuVO = BeanUtils.toBean(spu, AppProductSpuDetailRespVO.class)
|
AppProductSpuDetailRespVO spuVO = BeanUtils.toBean(spu, AppProductSpuDetailRespVO.class)
|
||||||
.setSkus(BeanUtils.toBean(skus, AppProductSpuDetailRespVO.Sku.class));
|
.setSkus(BeanUtils.toBean(skus, AppProductSpuDetailRespVO.Sku.class));
|
||||||
// 处理 vip 价格
|
// 处理 vip 价格
|
||||||
|
|
|
@ -26,7 +26,7 @@ public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新 SKU 库存(增加)
|
* 更新 SKU 库存(增加)、销量(减少)
|
||||||
*
|
*
|
||||||
* @param id 编号
|
* @param id 编号
|
||||||
* @param incrCount 增加库存(正数)
|
* @param incrCount 增加库存(正数)
|
||||||
|
@ -34,13 +34,14 @@ public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> {
|
||||||
default void updateStockIncr(Long id, Integer incrCount) {
|
default void updateStockIncr(Long id, Integer incrCount) {
|
||||||
Assert.isTrue(incrCount > 0);
|
Assert.isTrue(incrCount > 0);
|
||||||
LambdaUpdateWrapper<ProductSkuDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<ProductSkuDO>()
|
LambdaUpdateWrapper<ProductSkuDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<ProductSkuDO>()
|
||||||
.setSql(" stock = stock + " + incrCount)
|
.setSql(" stock = stock + " + incrCount
|
||||||
|
+ ", sales_count = sales_count - " + incrCount)
|
||||||
.eq(ProductSkuDO::getId, id);
|
.eq(ProductSkuDO::getId, id);
|
||||||
update(null, lambdaUpdateWrapper);
|
update(null, lambdaUpdateWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新 SKU 库存(减少)
|
* 更新 SKU 库存(减少)、销量(增加)
|
||||||
*
|
*
|
||||||
* @param id 编号
|
* @param id 编号
|
||||||
* @param incrCount 减少库存(负数)
|
* @param incrCount 减少库存(负数)
|
||||||
|
@ -48,10 +49,12 @@ public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> {
|
||||||
*/
|
*/
|
||||||
default int updateStockDecr(Long id, Integer incrCount) {
|
default int updateStockDecr(Long id, Integer incrCount) {
|
||||||
Assert.isTrue(incrCount < 0);
|
Assert.isTrue(incrCount < 0);
|
||||||
|
incrCount = - incrCount; // 取正
|
||||||
LambdaUpdateWrapper<ProductSkuDO> updateWrapper = new LambdaUpdateWrapper<ProductSkuDO>()
|
LambdaUpdateWrapper<ProductSkuDO> updateWrapper = new LambdaUpdateWrapper<ProductSkuDO>()
|
||||||
.setSql(" stock = stock + " + incrCount) // 负数,所以使用 + 号
|
.setSql(" stock = stock - " + incrCount
|
||||||
|
+ ", sales_count = sales_count + " + incrCount)
|
||||||
.eq(ProductSkuDO::getId, id)
|
.eq(ProductSkuDO::getId, id)
|
||||||
.ge(ProductSkuDO::getStock, -incrCount); // cas 逻辑
|
.ge(ProductSkuDO::getStock, incrCount);
|
||||||
return update(null, updateWrapper);
|
return update(null, updateWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,9 +85,19 @@ public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> {
|
||||||
* @param incrCount 增加的库存数量
|
* @param incrCount 增加的库存数量
|
||||||
*/
|
*/
|
||||||
default void updateStock(Long id, Integer incrCount) {
|
default void updateStock(Long id, Integer incrCount) {
|
||||||
|
// 拼接 SQL
|
||||||
|
if (incrCount == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String sql;
|
||||||
|
if (incrCount > 0) {
|
||||||
|
sql = " stock = stock + " + incrCount + ", sales_count = sales_count - " + incrCount;
|
||||||
|
} else {
|
||||||
|
sql = " stock = stock - " + Math.abs(incrCount) + ", sales_count = sales_count + " + Math.abs(incrCount);
|
||||||
|
}
|
||||||
|
// 执行更新
|
||||||
LambdaUpdateWrapper<ProductSpuDO> updateWrapper = new LambdaUpdateWrapper<ProductSpuDO>()
|
LambdaUpdateWrapper<ProductSpuDO> updateWrapper = new LambdaUpdateWrapper<ProductSpuDO>()
|
||||||
// 负数,所以使用 + 号
|
.setSql(sql)
|
||||||
.setSql(" stock = stock +" + incrCount)
|
|
||||||
.eq(ProductSpuDO::getId, id);
|
.eq(ProductSpuDO::getId, id);
|
||||||
update(null, updateWrapper);
|
update(null, updateWrapper);
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BrokerageUserDO getOrCreateBrokerageUser(Long id) {
|
public BrokerageUserDO getOrCreateBrokerageUser(Long id) {
|
||||||
|
// TODO @芋艿:这块优化下;统一到注册时处理;
|
||||||
BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(id);
|
BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(id);
|
||||||
// 特殊:人人分销的情况下,如果分销人为空则创建分销人
|
// 特殊:人人分销的情况下,如果分销人为空则创建分销人
|
||||||
if (brokerageUser == null && ObjUtil.equal(BrokerageEnabledConditionEnum.ALL.getCondition(),
|
if (brokerageUser == null && ObjUtil.equal(BrokerageEnabledConditionEnum.ALL.getCondition(),
|
||||||
|
|
|
@ -13,11 +13,11 @@ import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi;
|
||||||
import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO;
|
import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO;
|
||||||
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
|
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
|
||||||
import cn.iocoder.yudao.module.system.enums.permission.RoleCodeEnum;
|
import cn.iocoder.yudao.module.system.enums.permission.RoleCodeEnum;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.jeecg.modules.jmreport.api.JmReportTokenServiceI;
|
import org.jeecg.modules.jmreport.api.JmReportTokenServiceI;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -133,6 +133,13 @@ public class JmReportTokenServiceImpl implements JmReportTokenServiceI {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getRoles(String token) {
|
public String[] getRoles(String token) {
|
||||||
|
// 设置租户上下文。原因是:/jmreport/** 纯前端地址,不会走 buildLoginUserByToken 逻辑
|
||||||
|
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||||
|
if (loginUser == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
TenantContextHolder.setTenantId(loginUser.getTenantId());
|
||||||
|
|
||||||
// 参见文档 https://help.jeecg.com/jimureport/prodSafe.html 文档
|
// 参见文档 https://help.jeecg.com/jimureport/prodSafe.html 文档
|
||||||
// 适配:如果是本系统的管理员,则转换成 jimu 报表的管理员
|
// 适配:如果是本系统的管理员,则转换成 jimu 报表的管理员
|
||||||
Long userId = SecurityFrameworkUtils.getLoginUserId();
|
Long userId = SecurityFrameworkUtils.getLoginUserId();
|
||||||
|
|
Loading…
Reference in New Issue