Compare commits

...

4 Commits

Author SHA1 Message Date
MentatBot
6cbcf13447 Fix: Skip execution of scheduled tasks for disabled tenants
This update addresses the issue where scheduled tasks were being executed for disabled tenants. The `TenantJobAspect` class has been modified to check the status of each tenant before executing the task. If a tenant is disabled, the task will be skipped for that tenant.

Changes:
- Added a check in `TenantJobAspect` to verify tenant status before task execution.
- Introduced a new test `testTenantJobAspect_skipDisabledTenants` in `TenantServiceImplTest` to ensure the aspect correctly skips disabled tenants.
2024-08-16 07:24:48 +00:00
YunaiV
c21ee3ebf6 【功能优化】添加商品属性时允许选择已有的属性值 2024-08-14 22:00:52 +08:00
YunaiV
458235e444 Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/ruoyi-vue-pro
# Conflicts:
#	yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java
#	yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java
2024-08-14 21:54:49 +08:00
YunaiV
664abe7062 【功能优化】添加商品属性时允许选择已有的属性值 2024-08-14 00:44:14 +08:00
7 changed files with 67 additions and 6 deletions

View File

@@ -5,6 +5,8 @@ import cn.hutool.core.exceptions.ExceptionUtil;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkService;
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
import cn.iocoder.yudao.module.system.service.tenant.TenantService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
@@ -29,6 +31,7 @@ import java.util.concurrent.ConcurrentHashMap;
public class TenantJobAspect {
private final TenantFrameworkService tenantFrameworkService;
private final TenantService tenantService;
@Around("@annotation(tenantJob)")
public String around(ProceedingJoinPoint joinPoint, TenantJob tenantJob) {
@@ -44,6 +47,10 @@ public class TenantJobAspect {
// TODO 芋艿:先通过 parallel 实现并行1多个租户是一条执行日志2异常的情况
TenantUtils.execute(tenantId, () -> {
try {
TenantDO tenant = tenantService.getTenant(tenantId);
if (tenant.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())) {
return; // Skip disabled tenants
}
joinPoint.proceed();
} catch (Throwable e) {
results.put(tenantId, ExceptionUtil.getRootCauseMessage(e));
@@ -53,4 +60,4 @@ public class TenantJobAspect {
return JsonUtils.toJsonString(results);
}
}
}

View File

@@ -17,8 +17,10 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@Tag(name = "管理后台 - 商品属性项")
@RestController
@@ -70,4 +72,12 @@ public class ProductPropertyController {
return success(BeanUtils.toBean(pageResult, ProductPropertyRespVO.class));
}
@GetMapping("/simple-list")
@Operation(summary = "获得属性项精简列表")
public CommonResult<List<ProductPropertyRespVO>> getPropertySimpleList() {
List<ProductPropertyDO> list = productPropertyService.getPropertyList();
return success(convertList(list, property -> new ProductPropertyRespVO() // 只返回 id、name 属性
.setId(property.getId()).setName(property.getName())));
}
}

View File

@@ -17,8 +17,11 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.singleton;
@Tag(name = "管理后台 - 商品属性值")
@RestController
@@ -70,4 +73,13 @@ public class ProductPropertyValueController {
return success(BeanUtils.toBean(pageResult, ProductPropertyValueRespVO.class));
}
@GetMapping("/simple-list")
@Operation(summary = "获得属性值精简列表")
@Parameter(name = "propertyId", description = "属性项编号", required = true, example = "1024")
public CommonResult<List<ProductPropertyValueRespVO>> getPropertyValueSimpleList(@RequestParam("propertyId") Long propertyId) {
List<ProductPropertyValueDO> list = productPropertyValueService.getPropertyValueListByPropertyId(singleton(propertyId));
return success(convertList(list, value -> new ProductPropertyValueRespVO() // 只返回 id、name 属性
.setId(value.getId()).setName(value.getName())));
}
}

View File

@@ -39,10 +39,6 @@ public class ProductPropertyDO extends BaseDO {
* 名称
*/
private String name;
/**
* 状态
*/
private Integer status;
/**
* 备注
*/

View File

@@ -62,4 +62,11 @@ public interface ProductPropertyService {
*/
List<ProductPropertyDO> getPropertyList(Collection<Long> ids);
/**
* 获得指定状态的属性项列表
*
* @return 属性项列表
*/
List<ProductPropertyDO> getPropertyList();
}

View File

@@ -109,4 +109,9 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
return productPropertyMapper.selectBatchIds(ids);
}
@Override
public List<ProductPropertyDO> getPropertyList() {
return productPropertyMapper.selectList();
}
}

View File

@@ -403,13 +403,37 @@ public class TenantServiceImplTest extends BaseDbUnitTest {
}));
}
@Test
public void testTenantJobAspect_skipDisabledTenants() {
// mock 租户
TenantDO enabledTenant = randomPojo(TenantDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
TenantDO disabledTenant = randomPojo(TenantDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()));
tenantMapper.insert(enabledTenant);
tenantMapper.insert(disabledTenant);
// mock tenantService
when(tenantService.getTenant(enabledTenant.getId())).thenReturn(enabledTenant);
when(tenantService.getTenant(disabledTenant.getId())).thenReturn(disabledTenant);
// mock tenantFrameworkService
when(tenantFrameworkService.getTenantIds()).thenReturn(Arrays.asList(enabledTenant.getId(), disabledTenant.getId()));
// mock joinPoint
ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
// 调用
TenantJobAspect aspect = new TenantJobAspect(tenantFrameworkService, tenantService);
aspect.around(joinPoint, mock(TenantJob.class));
// 断言
verify(joinPoint, times(1)).proceed();
}
@Test
public void testHandleTenantMenu_disable() {
// 准备参数
TenantMenuHandler handler = mock(TenantMenuHandler.class);
// mock 禁用
when(tenantProperties.getEnable()).thenReturn(false);
// 调用
tenantService.handleTenantMenu(handler);
// 断言