mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
充值活动->优惠活动单元测试完善
This commit is contained in:
+1
-1
@@ -25,7 +25,7 @@ import org.springframework.test.context.jdbc.Sql;
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseDbAndRedisUnitTest.Application.class)
|
||||
@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件
|
||||
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) // 每个单元测试结束后,清理 DB
|
||||
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) // 每个单元测试方法结束后,清理 DB
|
||||
public class BaseDbAndRedisUnitTest {
|
||||
|
||||
@Import({
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.cf.imes.framework.test.core.ut;
|
||||
|
||||
import com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceAutoConfigure;
|
||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
||||
import com.cf.imes.framework.datasource.config.ChenfengDataSourceAutoConfiguration;
|
||||
import com.cf.imes.framework.mybatis.config.ChenfengMybatisAutoConfiguration;
|
||||
import com.cf.imes.framework.redis.config.ChenfengRedisAutoConfiguration;
|
||||
import com.cf.imes.framework.test.config.RedisTestConfiguration;
|
||||
import com.cf.imes.framework.test.config.SqlInitializationTestConfiguration;
|
||||
import org.redisson.spring.starter.RedissonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
|
||||
/**
|
||||
* 依赖内存 DB + Redis 的单元测试
|
||||
*
|
||||
* 相比 {@link BaseDbUnitTest} 来说,额外增加了内存 Redis
|
||||
*
|
||||
* @author 晨丰科技
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseDbClearAfterClassAndRedisUnitTest.Application.class)
|
||||
@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件
|
||||
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_CLASS) // 每个单元测试类结束后,清理 DB
|
||||
public class BaseDbClearAfterClassAndRedisUnitTest {
|
||||
|
||||
@Import({
|
||||
// DB 配置类
|
||||
ChenfengDataSourceAutoConfiguration.class, // 自己的 DB 配置类
|
||||
DataSourceAutoConfiguration.class, // Spring DB 自动配置类
|
||||
DataSourceTransactionManagerAutoConfiguration.class, // Spring 事务自动配置类
|
||||
DruidDataSourceAutoConfigure.class, // Druid 自动配置类
|
||||
SqlInitializationTestConfiguration.class, // SQL 初始化
|
||||
// MyBatis 配置类
|
||||
ChenfengMybatisAutoConfiguration.class, // 自己的 MyBatis 配置类
|
||||
MybatisPlusAutoConfiguration.class, // MyBatis 的自动配置类
|
||||
|
||||
// Redis 配置类
|
||||
RedisTestConfiguration.class, // Redis 测试配置类,用于启动 RedisServer
|
||||
ChenfengRedisAutoConfiguration.class, // 自己的 Redis 配置类
|
||||
RedisAutoConfiguration.class, // Spring Redis 自动配置类
|
||||
RedissonAutoConfiguration.class, // Redisson 自动高配置类
|
||||
})
|
||||
public static class Application {
|
||||
}
|
||||
|
||||
}
|
||||
+143
-164
@@ -1,164 +1,143 @@
|
||||
//package com.cf.imes.module.system.controller.admin.funds.recharge;
|
||||
//
|
||||
//import com.cf.imes.framework.common.pojo.PageResult;
|
||||
//import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargePageReqVO;
|
||||
//import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeSaveReqVO;
|
||||
//import com.cf.imes.module.system.dal.dataobject.funds.recharge.GiftMoneyDetailsDO;
|
||||
//import com.cf.imes.module.system.enums.recharge.RechargeGiftTypeEnum;
|
||||
//import com.cf.imes.module.system.enums.recharge.RechargeTypeEnum;
|
||||
//import com.cf.imes.module.system.service.funds.recharge.RechargeActiveService;
|
||||
//import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
//import org.springframework.http.MediaType;
|
||||
//import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
//import org.springframework.test.web.servlet.MockMvc;
|
||||
//
|
||||
//import java.math.BigDecimal;
|
||||
//import java.time.LocalDateTime;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import static org.mockito.ArgumentMatchers.any;
|
||||
//import static org.mockito.ArgumentMatchers.anyLong;
|
||||
//import static org.mockito.Mockito.doNothing;
|
||||
//import static org.mockito.Mockito.times;
|
||||
//import static org.mockito.Mockito.verify;
|
||||
//import static org.mockito.Mockito.when;
|
||||
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||
//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
//
|
||||
///**
|
||||
// * @author Gqr
|
||||
// * @since 2025/10/27 9:29
|
||||
// */
|
||||
//@WebMvcTest(controllers = RechargeActiveController.class, excludeAutoConfiguration = SecurityAutoConfiguration.class)
|
||||
//class RechargeActiveControllerTest {
|
||||
// @Autowired
|
||||
// private MockMvc mockMvc;
|
||||
//
|
||||
// @MockitoBean
|
||||
// private RechargeActiveService rechargeActiveService;
|
||||
//
|
||||
// @Autowired
|
||||
// private ObjectMapper objectMapper;
|
||||
//
|
||||
// @Test
|
||||
// void testCreateRechargeActive() throws Exception {
|
||||
// RechargeSaveReqVO vo = new RechargeSaveReqVO();
|
||||
// vo.setActivityName("充值活动");
|
||||
// vo.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// vo.setRechargeType(RechargeTypeEnum.ALIPAY.getStatus());
|
||||
// vo.setRechargeAmount(BigDecimal.valueOf(100));
|
||||
// vo.setGiftAmount(BigDecimal.valueOf(100));
|
||||
// LocalDateTime now = LocalDateTime.now();
|
||||
// vo.setStartTime(now);
|
||||
// vo.setEndTime(now);
|
||||
//
|
||||
// // mock Service 返回
|
||||
// when(rechargeActiveService.create(any())).thenReturn(100L);
|
||||
//
|
||||
// mockMvc.perform(put("/system/recharge-active")
|
||||
// .contentType(MediaType.APPLICATION_JSON)
|
||||
// .content(objectMapper.writeValueAsString(vo)))
|
||||
// .andExpect(status().isOk())
|
||||
// .andExpect(jsonPath("$.data").value(100));
|
||||
//
|
||||
// // 验证 Service 调用
|
||||
// verify(rechargeActiveService, times(1)).create(any());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void testUpdateRechargeActive() throws Exception {
|
||||
// RechargeSaveReqVO vo = new RechargeSaveReqVO();
|
||||
// vo.setId(1L);
|
||||
// vo.setActivityName("更新充值活动");
|
||||
// vo.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// vo.setRechargeType(RechargeTypeEnum.ALIPAY.getStatus());
|
||||
// vo.setRechargeAmount(BigDecimal.valueOf(100));
|
||||
// vo.setGiftAmount(BigDecimal.valueOf(100));
|
||||
// LocalDateTime now = LocalDateTime.now();
|
||||
// vo.setStartTime(now);
|
||||
// vo.setEndTime(now);
|
||||
//
|
||||
// // mock Service 返回
|
||||
// doNothing().when(rechargeActiveService).update(any());
|
||||
//
|
||||
// mockMvc.perform(post("/system/recharge-active")
|
||||
// .contentType(MediaType.APPLICATION_JSON)
|
||||
// .content(objectMapper.writeValueAsString(vo)))
|
||||
// .andExpect(status().isOk())
|
||||
// .andExpect(jsonPath("$.data").value(true));
|
||||
//
|
||||
// // 验证 Service 调用
|
||||
// verify(rechargeActiveService, times(1)).update(any());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void testDeleteRechargeActive() throws Exception {
|
||||
// Long id = 3L;
|
||||
// doNothing().when(rechargeActiveService).delete(anyLong());
|
||||
//
|
||||
// mockMvc.perform(delete("/system/recharge-active/{id}", id))
|
||||
// .andExpect(status().isOk())
|
||||
// .andExpect(jsonPath("$.data").value(true));
|
||||
//
|
||||
// verify(rechargeActiveService, times(1)).delete(id);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void testGetRechargeActive() throws Exception {
|
||||
// Long id = 123L;
|
||||
// GiftMoneyDetailsDO mockDO = new GiftMoneyDetailsDO()
|
||||
// .setId(id);
|
||||
// when(rechargeActiveService.get(id)).thenReturn(mockDO);
|
||||
//
|
||||
// mockMvc.perform(get("/system/recharge-active/{id}", id))
|
||||
// .andExpect(status().isOk())
|
||||
// .andExpect(jsonPath("$.data.id").value(123L));
|
||||
//
|
||||
// verify(rechargeActiveService, times(1)).get(id);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void testGetRechargeActivePage() throws Exception {
|
||||
// RechargePageReqVO reqVO = new RechargePageReqVO();
|
||||
// PageResult<GiftMoneyDetailsDO> mockPage = new PageResult<>();
|
||||
// mockPage.setTotal(1L);
|
||||
// mockPage.setList(List.of(new GiftMoneyDetailsDO().setId(1L)));
|
||||
// when(rechargeActiveService.getPage(any())).thenReturn(mockPage);
|
||||
//
|
||||
// mockMvc.perform(get("/system/recharge-active/page")
|
||||
// .contentType(MediaType.APPLICATION_JSON)
|
||||
// .content(objectMapper.writeValueAsString(reqVO)))
|
||||
// .andExpect(status().isOk())
|
||||
// .andExpect(jsonPath("$.data.list[0].id").value(1L));
|
||||
//
|
||||
// verify(rechargeActiveService, times(1)).getPage(any());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void testGetAvailableRechargeActivePage_success() throws Exception {
|
||||
// // 模拟 service 返回数据
|
||||
// GiftMoneyDetailsDO mockDO = new GiftMoneyDetailsDO();
|
||||
// mockDO.setId(1L);
|
||||
// mockDO.setRechargeAmount(new BigDecimal("50.00"));
|
||||
// mockDO.setActivityName("新人充值活动");
|
||||
//
|
||||
// when(rechargeActiveService.getAvailableRechargeActiveList())
|
||||
// .thenReturn(List.of(mockDO));
|
||||
//
|
||||
// // 发起请求
|
||||
// mockMvc.perform(get("/system/recharge-active/available")
|
||||
// .contentType(MediaType.APPLICATION_JSON))
|
||||
// .andExpect(status().isOk())
|
||||
// .andExpect(jsonPath("$.code").value(0)) // CommonResult.success 通常 code=0
|
||||
// .andExpect(jsonPath("$.data[0].activityName").value("新人充值活动"))
|
||||
// .andExpect(jsonPath("$.data[0].rechargeAmount").value(50.00));
|
||||
// }
|
||||
//}
|
||||
package com.cf.imes.module.system.controller.admin.funds.productpromotion;
|
||||
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.module.system.controller.admin.funds.productpromotion.vo.ProductPromotionPageReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.productpromotion.vo.ProductPromotionSaveReqVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.funds.productpromotion.ProductPromotionDO;
|
||||
import com.cf.imes.module.system.enums.pay.DurationUnitEnum;
|
||||
import com.cf.imes.module.system.service.funds.productpromotion.ProductPromotionService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
* @since 2025/10/27 9:29
|
||||
*/
|
||||
@WebMvcTest(controllers = ProductPromotionController.class, excludeAutoConfiguration = SecurityAutoConfiguration.class)
|
||||
class ProductPromotionControllerTest {
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@MockitoBean
|
||||
private ProductPromotionService productPromotionService;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Test
|
||||
void testCreateRechargeActive() throws Exception {
|
||||
ProductPromotionSaveReqVO vo = new ProductPromotionSaveReqVO();
|
||||
vo.setActivityName("充值活动");
|
||||
vo.setProductId(1L);
|
||||
vo.setPurchaseDuration(1);
|
||||
vo.setPurchaseDurationUnit(DurationUnitEnum.YEAR.getCode());
|
||||
vo.setGiftDuration(1);
|
||||
vo.setGiftDurationUnit(DurationUnitEnum.DAY.getCode());
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
vo.setStartTime(now);
|
||||
vo.setEndTime(now);
|
||||
|
||||
// mock Service 返回
|
||||
when(productPromotionService.create(any())).thenReturn(100L);
|
||||
|
||||
mockMvc.perform(put("/system/product/promotion")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(vo)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data").value(100));
|
||||
|
||||
// 验证 Service 调用
|
||||
verify(productPromotionService, times(1)).create(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateRechargeActive() throws Exception {
|
||||
ProductPromotionSaveReqVO vo = new ProductPromotionSaveReqVO();
|
||||
vo.setActivityName("更新充值活动");
|
||||
vo.setProductId(2L);
|
||||
vo.setPurchaseDuration(2);
|
||||
vo.setPurchaseDurationUnit(DurationUnitEnum.YEAR.getCode());
|
||||
vo.setGiftDuration(2);
|
||||
vo.setGiftDurationUnit(DurationUnitEnum.DAY.getCode());
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
vo.setStartTime(now);
|
||||
vo.setEndTime(now);
|
||||
|
||||
// mock Service 返回
|
||||
doNothing().when(productPromotionService).update(any());
|
||||
|
||||
mockMvc.perform(post("/system/product/promotion")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(vo)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data").value(true));
|
||||
|
||||
// 验证 Service 调用
|
||||
verify(productPromotionService, times(1)).update(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteRechargeActive() throws Exception {
|
||||
Long id = 3L;
|
||||
doNothing().when(productPromotionService).delete(anyLong());
|
||||
|
||||
mockMvc.perform(delete("/system/product/promotion/{id}", id))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data").value(true));
|
||||
|
||||
verify(productPromotionService, times(1)).delete(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetRechargeActive() throws Exception {
|
||||
Long id = 123L;
|
||||
ProductPromotionDO mockDO = new ProductPromotionDO()
|
||||
.setId(id);
|
||||
when(productPromotionService.get(id)).thenReturn(mockDO);
|
||||
|
||||
mockMvc.perform(get("/system/product/promotion/{id}", id))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.id").value(123L));
|
||||
|
||||
verify(productPromotionService, times(1)).get(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetRechargeActivePage() throws Exception {
|
||||
ProductPromotionPageReqVO reqVO = new ProductPromotionPageReqVO();
|
||||
PageResult<ProductPromotionDO> mockPage = new PageResult<>();
|
||||
mockPage.setTotal(1L);
|
||||
mockPage.setList(List.of(new ProductPromotionDO().setId(1L)));
|
||||
when(productPromotionService.getPage(any())).thenReturn(mockPage);
|
||||
|
||||
mockMvc.perform(get("/system/product/promotion/page")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(reqVO)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.list[0].id").value(1L));
|
||||
|
||||
verify(productPromotionService, times(1)).getPage(any());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package com.cf.imes.module.system.service.funds.advertisement;
|
||||
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.framework.test.core.ut.BaseDbAndRedisUnitTest;
|
||||
import com.cf.imes.framework.test.core.ut.BaseDbClearAfterClassAndRedisUnitTest;
|
||||
import com.cf.imes.module.infra.api.file.FileApi;
|
||||
import com.cf.imes.module.system.controller.admin.funds.advertisement.vo.AdvertisementPageReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.advertisement.vo.AdvertisementRePublishReqVO;
|
||||
@@ -51,7 +51,7 @@ import static org.mockito.Mockito.when;
|
||||
*/
|
||||
@Import(AdvertisementServiceImpl.class)
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class AdvertisementServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||
class AdvertisementServiceImplTest extends BaseDbClearAfterClassAndRedisUnitTest {
|
||||
@Resource
|
||||
private AdvertisementService advertisementService;
|
||||
|
||||
|
||||
+285
@@ -0,0 +1,285 @@
|
||||
package com.cf.imes.module.system.service.funds.productpromotion;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.framework.test.core.ut.BaseDbClearAfterClassAndRedisUnitTest;
|
||||
import com.cf.imes.module.system.controller.admin.funds.productpromotion.vo.ProductPromotionPageReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.productpromotion.vo.ProductPromotionSaveReqVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.funds.productpromotion.ProductPromotionDO;
|
||||
import com.cf.imes.module.system.dal.dataobject.funds.products.ProductsDO;
|
||||
import com.cf.imes.module.system.dal.mysql.funds.productpromotion.ProductPromotionMapper;
|
||||
import com.cf.imes.module.system.enums.pay.DurationUnitEnum;
|
||||
import com.cf.imes.module.system.service.funds.products.ProductsDetailService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static com.cf.imes.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static com.cf.imes.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static com.cf.imes.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static com.cf.imes.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static com.cf.imes.module.system.enums.ErrorCodeConstants.PRODUCT_PROMOTION_ACTIVE_NAME_IS_EXIST;
|
||||
import static com.cf.imes.module.system.enums.ErrorCodeConstants.PRODUCT_PROMOTION_NO_EXIST;
|
||||
import static com.cf.imes.module.system.enums.ErrorCodeConstants.PRODUCT_PROMOTION_PURCHASEDURATION_IS_EXIST;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
* @since 2025/10/24 11:20
|
||||
*/
|
||||
@Import(ProductPromotionServiceImpl.class)
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class ProductPromotionServiceImplTest extends BaseDbClearAfterClassAndRedisUnitTest {
|
||||
@Resource
|
||||
private ProductPromotionServiceImpl productPromotionService;
|
||||
|
||||
@Resource
|
||||
private ProductPromotionMapper productPromotionMapper;
|
||||
|
||||
@MockitoBean
|
||||
private ProductsDetailService productsDetailService;
|
||||
|
||||
private static ProductPromotionDO createDO;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void testCreate() {
|
||||
ProductPromotionSaveReqVO reqVO = randomPojo(ProductPromotionSaveReqVO.class, o -> {
|
||||
o.setId(null);
|
||||
o.setActivityName("充值送活动");
|
||||
o.setPurchaseDuration(1);
|
||||
o.setPurchaseDurationUnit(DurationUnitEnum.YEAR.getCode());
|
||||
o.setProductId(1L);
|
||||
o.setGiftDuration(1);
|
||||
o.setGiftDurationUnit(DurationUnitEnum.DAY.getCode());
|
||||
o.setStartTime(LocalDateTime.now());
|
||||
o.setEndTime(LocalDateTime.now().plusDays(1));
|
||||
});
|
||||
|
||||
ProductsDO productsDO = new ProductsDO();
|
||||
productsDO.setId(1L);
|
||||
productsDO.setProductName("产品名称");
|
||||
when(productsDetailService.validateProductExist(any())).thenReturn(productsDO);
|
||||
|
||||
Long id = productPromotionService.create(reqVO);
|
||||
|
||||
// 校验数据库插入结果
|
||||
createDO = productPromotionMapper.selectById(id);
|
||||
assertNotNull(createDO);
|
||||
assertEquals("充值送活动", createDO.getActivityName());
|
||||
assertEquals(1, createDO.getPurchaseDuration());
|
||||
assertEquals(DurationUnitEnum.YEAR.getCode(), createDO.getPurchaseDurationUnit());
|
||||
assertEquals(1, createDO.getGiftDuration());
|
||||
assertEquals(DurationUnitEnum.DAY.getCode(), createDO.getGiftDurationUnit());
|
||||
|
||||
// 再次插入相同活动名称,断言异常
|
||||
assertServiceException(() -> productPromotionService.create(reqVO), PRODUCT_PROMOTION_ACTIVE_NAME_IS_EXIST);
|
||||
|
||||
// 再次插入相同产品-相同购买时长和单位,断言异常
|
||||
reqVO.setActivityName("充值送活动1");
|
||||
assertServiceException(() -> productPromotionService.create(reqVO), PRODUCT_PROMOTION_PURCHASEDURATION_IS_EXIST, reqVO.getPurchaseDuration(), DurationUnitEnum.getDesc(reqVO.getPurchaseDurationUnit()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void testUpdate_not_exist() {
|
||||
ProductPromotionSaveReqVO reqVO = new ProductPromotionSaveReqVO();
|
||||
reqVO.setId(321L);
|
||||
|
||||
assertServiceException(() -> productPromotionService.update(reqVO),
|
||||
PRODUCT_PROMOTION_NO_EXIST);
|
||||
|
||||
reqVO.setId(null);
|
||||
|
||||
assertServiceException(() -> productPromotionService.update(reqVO),
|
||||
PRODUCT_PROMOTION_NO_EXIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void testUpdate() {
|
||||
|
||||
// 插入
|
||||
ProductPromotionDO createDO1 = new ProductPromotionDO();
|
||||
createDO1.setId(null);
|
||||
createDO1.setActivityName("充值送活动新");
|
||||
createDO1.setPurchaseDuration(1);
|
||||
createDO1.setPurchaseDurationUnit(DurationUnitEnum.YEAR.getCode());
|
||||
createDO1.setProductId(2L);
|
||||
createDO1.setProductName("产品名称2");
|
||||
createDO1.setGiftDuration(1);
|
||||
createDO1.setGiftDurationUnit(DurationUnitEnum.DAY.getCode());
|
||||
createDO1.setStartTime(LocalDateTime.now());
|
||||
createDO1.setEndTime(LocalDateTime.now().plusDays(1));
|
||||
|
||||
productPromotionMapper.insert(createDO1);
|
||||
|
||||
ProductPromotionSaveReqVO reqVO = new ProductPromotionSaveReqVO();
|
||||
reqVO.setId(createDO1.getId());
|
||||
reqVO.setActivityName("充值送活动");
|
||||
assertServiceException(() -> productPromotionService.update(reqVO),
|
||||
PRODUCT_PROMOTION_ACTIVE_NAME_IS_EXIST);
|
||||
|
||||
ProductsDO productsDO = new ProductsDO();
|
||||
productsDO.setId(2L);
|
||||
productsDO.setProductName("产品名称2");
|
||||
when(productsDetailService.validateProductExist(any())).thenReturn(productsDO);
|
||||
|
||||
// 更新成功
|
||||
ProductPromotionSaveReqVO update = BeanUtil.copyProperties(createDO1, ProductPromotionSaveReqVO.class);
|
||||
assertDoesNotThrow(() -> productPromotionService.update(update));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void testGet_not_exist() {
|
||||
assertServiceException(() -> productPromotionService.get(null), PRODUCT_PROMOTION_NO_EXIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void testGetPage_success() {
|
||||
ProductPromotionDO detail = randomPojo(ProductPromotionDO.class, o -> {
|
||||
o.setId(null);
|
||||
o.setActivityName("晨丰分页活动");
|
||||
o.setPurchaseDuration(3);
|
||||
o.setPurchaseDurationUnit(DurationUnitEnum.YEAR.getCode());
|
||||
o.setGiftDuration(4);
|
||||
o.setGiftDurationUnit(DurationUnitEnum.DAY.getCode());
|
||||
o.setRemark("晨丰备注1");
|
||||
});
|
||||
|
||||
productPromotionMapper.insert(detail);
|
||||
|
||||
// 不匹配 ActivityName
|
||||
productPromotionMapper.insert(cloneIgnoreId(detail, o -> o.setActivityName("新分页活动")));
|
||||
|
||||
// 不匹配 RechargeGiftType
|
||||
productPromotionMapper.insert(cloneIgnoreId(detail, o -> o.setPurchaseDuration(4)));
|
||||
|
||||
// 不匹配 GiftAmount
|
||||
productPromotionMapper.insert(cloneIgnoreId(detail, o -> o.setGiftDuration(5)));
|
||||
|
||||
// 不匹配 RechargeAmount
|
||||
productPromotionMapper.insert(cloneIgnoreId(detail, o -> o.setRemark("晨丰备1注")));
|
||||
|
||||
// 被逻辑删除
|
||||
productPromotionMapper.insert(cloneIgnoreId(detail, o -> o.setDeleted(true)));
|
||||
|
||||
// ============ 构造查询参数 ============
|
||||
ProductPromotionPageReqVO reqVO = new ProductPromotionPageReqVO();
|
||||
reqVO.setActivityName("晨丰");
|
||||
reqVO.setPurchaseDuration(3);
|
||||
reqVO.setGiftDuration(4);
|
||||
reqVO.setRemark("晨丰备注");
|
||||
reqVO.setPageNo(1);
|
||||
reqVO.setPageSize(10);
|
||||
|
||||
// ============ 调用方法 ============
|
||||
PageResult<ProductPromotionDO> pageResult = productPromotionService.getPage(reqVO);
|
||||
|
||||
// ============ 断言结果 ============
|
||||
assertEquals(1, pageResult.getTotal(), "分页结果数量应为1");
|
||||
assertEquals(1, pageResult.getList().size(), "分页列表长度应为1");
|
||||
assertPojoEquals(detail, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void testDelete() {
|
||||
assertDoesNotThrow(() -> productPromotionService.delete(createDO.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void testDelete_not_exist() {
|
||||
assertServiceException(() -> productPromotionService.delete(null), PRODUCT_PROMOTION_NO_EXIST);
|
||||
assertServiceException(() -> productPromotionService.delete(321L), PRODUCT_PROMOTION_NO_EXIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void testGetAvailableRechargeActiveList() {
|
||||
// 当前时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
Long productId = 1000L;
|
||||
|
||||
// 1️⃣ 有效活动(时间区间内)
|
||||
ProductPromotionDO valid = new ProductPromotionDO();
|
||||
valid.setActivityName("有效活动");
|
||||
valid.setProductId(productId);
|
||||
valid.setProductName("产品名称");
|
||||
valid.setPurchaseDuration(1);
|
||||
valid.setPurchaseDurationUnit(DurationUnitEnum.YEAR.getCode());
|
||||
valid.setGiftDuration(1);
|
||||
valid.setGiftDurationUnit(DurationUnitEnum.DAY.getCode());
|
||||
valid.setStartTime(now.minusDays(1));
|
||||
valid.setEndTime(now.plusDays(1));
|
||||
valid.setDeleted(false);
|
||||
productPromotionMapper.insert(valid);
|
||||
|
||||
// 2️⃣ 未开始活动
|
||||
ProductPromotionDO notStarted = new ProductPromotionDO();
|
||||
notStarted.setActivityName("未开始活动");
|
||||
notStarted.setProductId(productId);
|
||||
notStarted.setProductName("产品名称");
|
||||
notStarted.setPurchaseDuration(2);
|
||||
notStarted.setPurchaseDurationUnit(DurationUnitEnum.YEAR.getCode());
|
||||
notStarted.setGiftDuration(2);
|
||||
notStarted.setGiftDurationUnit(DurationUnitEnum.DAY.getCode());
|
||||
notStarted.setStartTime(now.plusDays(1));
|
||||
notStarted.setEndTime(now.plusDays(2));
|
||||
notStarted.setDeleted(false);
|
||||
productPromotionMapper.insert(notStarted);
|
||||
|
||||
// 3️⃣ 已过期活动
|
||||
ProductPromotionDO expired = new ProductPromotionDO();
|
||||
expired.setActivityName("已过期活动");
|
||||
expired.setProductId(productId);
|
||||
expired.setProductName("产品名称");
|
||||
expired.setPurchaseDuration(3);
|
||||
expired.setPurchaseDurationUnit(DurationUnitEnum.YEAR.getCode());
|
||||
expired.setGiftDuration(3);
|
||||
expired.setGiftDurationUnit(DurationUnitEnum.DAY.getCode());
|
||||
expired.setStartTime(now.minusDays(5));
|
||||
expired.setEndTime(now.minusDays(1));
|
||||
expired.setDeleted(false);
|
||||
productPromotionMapper.insert(expired);
|
||||
|
||||
// 4️⃣ 被逻辑删除的活动
|
||||
ProductPromotionDO deleted = new ProductPromotionDO();
|
||||
deleted.setActivityName("被删除活动");
|
||||
deleted.setProductId(productId);
|
||||
deleted.setProductName("产品名称");
|
||||
deleted.setPurchaseDuration(4);
|
||||
deleted.setPurchaseDurationUnit(DurationUnitEnum.YEAR.getCode());
|
||||
deleted.setGiftDuration(4);
|
||||
deleted.setGiftDurationUnit(DurationUnitEnum.DAY.getCode());
|
||||
deleted.setStartTime(now.minusDays(1));
|
||||
deleted.setEndTime(now.plusDays(1));
|
||||
deleted.setDeleted(true);
|
||||
productPromotionMapper.insert(deleted);
|
||||
|
||||
// 执行被测方法
|
||||
List<ProductPromotionDO> result = productPromotionService.getAvailableProductPromotionList(productId);
|
||||
|
||||
// 验证结果
|
||||
assertEquals(1, result.size(), "只应返回一个有效活动");
|
||||
assertEquals("有效活动", result.get(0).getActivityName());
|
||||
}
|
||||
|
||||
}
|
||||
-252
@@ -1,252 +0,0 @@
|
||||
//package com.cf.imes.module.system.service.funds.recharge;
|
||||
//
|
||||
//import cn.hutool.core.bean.BeanUtil;
|
||||
//import com.cf.imes.framework.common.pojo.PageResult;
|
||||
//import com.cf.imes.framework.test.core.ut.BaseDbAndRedisUnitTest;
|
||||
//import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargePageReqVO;
|
||||
//import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeSaveReqVO;
|
||||
//import com.cf.imes.module.system.dal.dataobject.funds.recharge.GiftMoneyDetailsDO;
|
||||
//import com.cf.imes.module.system.dal.mysql.funds.recharge.GiftMoneyDetailsMapper;
|
||||
//import com.cf.imes.module.system.enums.recharge.RechargeGiftTypeEnum;
|
||||
//import com.cf.imes.module.system.enums.recharge.RechargeTypeEnum;
|
||||
//import jakarta.annotation.Resource;
|
||||
//import org.junit.jupiter.api.MethodOrderer;
|
||||
//import org.junit.jupiter.api.Order;
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//import org.junit.jupiter.api.TestMethodOrder;
|
||||
//import org.springframework.context.annotation.Import;
|
||||
//
|
||||
//import java.math.BigDecimal;
|
||||
//import java.time.LocalDateTime;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import static com.cf.imes.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
//import static com.cf.imes.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
//import static com.cf.imes.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
//import static com.cf.imes.framework.test.core.util.RandomUtils.randomPojo;
|
||||
//import static com.cf.imes.module.system.enums.ErrorCodeConstants.RECHARGE_ACTIVE_NAME_IS_EXIST;
|
||||
//import static com.cf.imes.module.system.enums.ErrorCodeConstants.RECHARGE_ACTIVE_NO_EXIST;
|
||||
//import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
//import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
//import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
//
|
||||
///**
|
||||
// * @author Gqr
|
||||
// * @since 2025/10/24 11:20
|
||||
// */
|
||||
//@Import(RechargeActiveServiceImpl.class)
|
||||
//@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
//class RechargeActiveServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||
// @Resource
|
||||
// private RechargeActiveService rechargeActiveService;
|
||||
//
|
||||
// @Resource
|
||||
// private GiftMoneyDetailsMapper giftMoneyDetailsMapper;
|
||||
//
|
||||
// private static GiftMoneyDetailsDO createDO;
|
||||
//
|
||||
// @Test
|
||||
// @Order(1)
|
||||
// void testCreate() {
|
||||
// RechargeSaveReqVO reqVO = randomPojo(RechargeSaveReqVO.class, o -> {
|
||||
// o.setId(null);
|
||||
// o.setActivityName("充值送活动");
|
||||
// o.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// o.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
// o.setRechargeAmount(BigDecimal.valueOf(100));
|
||||
// o.setGiftAmount(BigDecimal.valueOf(20));
|
||||
// });
|
||||
//
|
||||
// Long id = rechargeActiveService.create(reqVO);
|
||||
//
|
||||
// // 校验数据库插入结果
|
||||
// createDO = giftMoneyDetailsMapper.selectById(id);
|
||||
// assertNotNull(createDO);
|
||||
// assertEquals("充值送活动", createDO.getActivityName());
|
||||
// assertEquals(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus(), createDO.getRechargeType());
|
||||
// assertEquals(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus(), createDO.getRechargeGiftType());
|
||||
// assertEquals(new BigDecimal("100.000"), createDO.getRechargeAmount());
|
||||
// assertEquals(new BigDecimal("20.000"), createDO.getGiftAmount());
|
||||
//
|
||||
// // 再次插入相同活动名称,断言异常
|
||||
// assertServiceException(() -> rechargeActiveService.create(reqVO),
|
||||
// RECHARGE_ACTIVE_NAME_IS_EXIST);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @Order(2)
|
||||
// void testUpdate_not_exist() {
|
||||
// RechargeSaveReqVO reqVO = new RechargeSaveReqVO();
|
||||
// reqVO.setId(321L);
|
||||
//
|
||||
// assertServiceException(() -> rechargeActiveService.update(reqVO),
|
||||
// RECHARGE_ACTIVE_NO_EXIST);
|
||||
//
|
||||
// reqVO.setId(null);
|
||||
//
|
||||
// assertServiceException(() -> rechargeActiveService.update(reqVO),
|
||||
// RECHARGE_ACTIVE_NO_EXIST);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @Order(2)
|
||||
// void testUpdate() {
|
||||
//
|
||||
// // 插入
|
||||
// createDO.setId(null);
|
||||
// createDO.setActivityName("充值送活动新");
|
||||
// createDO.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// createDO.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
// createDO.setRechargeAmount(BigDecimal.valueOf(100));
|
||||
// createDO.setGiftAmount(BigDecimal.valueOf(20));
|
||||
// giftMoneyDetailsMapper.insert(createDO);
|
||||
//
|
||||
// RechargeSaveReqVO reqVO = new RechargeSaveReqVO();
|
||||
// reqVO.setId(createDO.getId());
|
||||
// reqVO.setActivityName("充值送活动");
|
||||
// assertServiceException(() -> rechargeActiveService.update(reqVO),
|
||||
// RECHARGE_ACTIVE_NAME_IS_EXIST);
|
||||
//
|
||||
// // 更新成功
|
||||
// RechargeSaveReqVO update = BeanUtil.copyProperties(createDO, RechargeSaveReqVO.class);
|
||||
// assertDoesNotThrow(() -> rechargeActiveService.update(update));
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// @Order(3)
|
||||
// void testGet_not_exist() {
|
||||
// assertServiceException(() -> rechargeActiveService.get(null), RECHARGE_ACTIVE_NO_EXIST);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @Order(4)
|
||||
// void testGet() {
|
||||
// assertNotNull(rechargeActiveService.getDefaultNull(createDO.getId()));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @Order(5)
|
||||
// void testGetPage_success() {
|
||||
// GiftMoneyDetailsDO detail = randomPojo(GiftMoneyDetailsDO.class, o -> {
|
||||
// o.setId(null);
|
||||
// o.setActivityName("晨丰分页活动");
|
||||
// o.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// o.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
// o.setRechargeAmount(BigDecimal.valueOf(100).setScale(3));
|
||||
// o.setGiftAmount(BigDecimal.valueOf(20).setScale(3));
|
||||
// });
|
||||
//
|
||||
// giftMoneyDetailsMapper.insert(detail);
|
||||
//
|
||||
// // 不匹配 ActivityName
|
||||
// giftMoneyDetailsMapper.insert(cloneIgnoreId(detail, o -> o.setActivityName("新分页活动")));
|
||||
//
|
||||
// // 不匹配 RechargeGiftType
|
||||
// giftMoneyDetailsMapper.insert(cloneIgnoreId(detail, o -> o.setRechargeGiftType(RechargeGiftTypeEnum.FULL_X_GIVE_X.getStatus())));
|
||||
//
|
||||
// // 不匹配 GiftAmount
|
||||
// giftMoneyDetailsMapper.insert(cloneIgnoreId(detail, o -> o.setGiftAmount(BigDecimal.valueOf(99))));
|
||||
//
|
||||
// // 不匹配 RechargeAmount
|
||||
// giftMoneyDetailsMapper.insert(cloneIgnoreId(detail, o -> o.setRechargeAmount(BigDecimal.valueOf(99))));
|
||||
//
|
||||
// // 被逻辑删除
|
||||
// giftMoneyDetailsMapper.insert(cloneIgnoreId(detail, o -> o.setDeleted(true)));
|
||||
//
|
||||
// // ============ 构造查询参数 ============
|
||||
// RechargePageReqVO reqVO = new RechargePageReqVO();
|
||||
// reqVO.setActivityName("晨丰");
|
||||
// reqVO.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// reqVO.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
// reqVO.setRechargeAmount(BigDecimal.valueOf(100));
|
||||
// reqVO.setGiftAmount(BigDecimal.valueOf(20));
|
||||
// reqVO.setPageNo(1);
|
||||
// reqVO.setPageSize(10);
|
||||
//
|
||||
// // ============ 调用方法 ============
|
||||
// PageResult<GiftMoneyDetailsDO> pageResult = rechargeActiveService.getPage(reqVO);
|
||||
//
|
||||
// // ============ 断言结果 ============
|
||||
// assertEquals(1, pageResult.getTotal(), "分页结果数量应为1");
|
||||
// assertEquals(1, pageResult.getList().size(), "分页列表长度应为1");
|
||||
// assertPojoEquals(detail, pageResult.getList().get(0));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @Order(6)
|
||||
// void testDelete() {
|
||||
// assertDoesNotThrow(() -> rechargeActiveService.delete(createDO.getId()));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @Order(7)
|
||||
// void testDelete_not_exist() {
|
||||
// assertServiceException(() -> rechargeActiveService.delete(null), RECHARGE_ACTIVE_NO_EXIST);
|
||||
// assertServiceException(() -> rechargeActiveService.delete(321L), RECHARGE_ACTIVE_NO_EXIST);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @Order(8)
|
||||
// void testGetAvailableRechargeActiveList() {
|
||||
// // 当前时间
|
||||
// LocalDateTime now = LocalDateTime.now();
|
||||
//
|
||||
// // 1️⃣ 有效活动(时间区间内)
|
||||
// GiftMoneyDetailsDO valid = new GiftMoneyDetailsDO();
|
||||
// valid.setActivityName("有效活动");
|
||||
// valid.setRechargeAmount(new java.math.BigDecimal("100.000"));
|
||||
// valid.setGiftAmount(new java.math.BigDecimal("10.000"));
|
||||
// valid.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// valid.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
// valid.setStartTime(now.minusDays(1));
|
||||
// valid.setEndTime(now.plusDays(1));
|
||||
// valid.setDeleted(false);
|
||||
// giftMoneyDetailsMapper.insert(valid);
|
||||
//
|
||||
// // 2️⃣ 未开始活动
|
||||
// GiftMoneyDetailsDO notStarted = new GiftMoneyDetailsDO();
|
||||
// notStarted.setActivityName("未开始活动");
|
||||
// notStarted.setRechargeAmount(new java.math.BigDecimal("100.000"));
|
||||
// notStarted.setGiftAmount(new java.math.BigDecimal("10.000"));
|
||||
// notStarted.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// notStarted.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
// notStarted.setStartTime(now.plusDays(1));
|
||||
// notStarted.setEndTime(now.plusDays(2));
|
||||
// notStarted.setDeleted(false);
|
||||
// giftMoneyDetailsMapper.insert(notStarted);
|
||||
//
|
||||
// // 3️⃣ 已过期活动
|
||||
// GiftMoneyDetailsDO expired = new GiftMoneyDetailsDO();
|
||||
// expired.setActivityName("已过期活动");
|
||||
// expired.setRechargeAmount(new java.math.BigDecimal("100.000"));
|
||||
// expired.setGiftAmount(new java.math.BigDecimal("10.000"));
|
||||
// expired.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// expired.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
// expired.setStartTime(now.minusDays(5));
|
||||
// expired.setEndTime(now.minusDays(1));
|
||||
// expired.setDeleted(false);
|
||||
// giftMoneyDetailsMapper.insert(expired);
|
||||
//
|
||||
// // 4️⃣ 被逻辑删除的活动
|
||||
// GiftMoneyDetailsDO deleted = new GiftMoneyDetailsDO();
|
||||
// deleted.setActivityName("被删除活动");
|
||||
// deleted.setRechargeAmount(new java.math.BigDecimal("100.000"));
|
||||
// deleted.setGiftAmount(new java.math.BigDecimal("10.000"));
|
||||
// deleted.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// deleted.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
// deleted.setStartTime(now.minusDays(1));
|
||||
// deleted.setEndTime(now.plusDays(1));
|
||||
// deleted.setDeleted(true);
|
||||
// giftMoneyDetailsMapper.insert(deleted);
|
||||
//
|
||||
// // 执行被测方法
|
||||
// List<GiftMoneyDetailsDO> result = rechargeActiveService.getAvailableRechargeActiveList();
|
||||
//
|
||||
// // 验证结果
|
||||
// assertEquals(1, result.size(), "只应返回一个有效活动");
|
||||
// assertEquals("有效活动", result.get(0).getActivityName());
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@@ -35,3 +35,7 @@ DELETE FROM "system_notify_template";
|
||||
DELETE FROM "system_notify_message";
|
||||
DELETE FROM "process";
|
||||
DELETE FROM "process_group";
|
||||
DELETE FROM "products";
|
||||
DELETE FROM "products_details";
|
||||
DELETE FROM "product_promotion";
|
||||
DELETE FROM "advertisement";
|
||||
@@ -714,13 +714,15 @@ CREATE TABLE IF NOT EXISTS "products_details" (
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '产品购买信息表 products_details';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "gift_money_details" (
|
||||
CREATE TABLE IF NOT EXISTS "product_promotion" (
|
||||
"id" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY COMMENT '主键,自增ID',
|
||||
"activity_name" VARCHAR(32) NOT NULL COMMENT '活动名称',
|
||||
"recharge_gift_type" TINYINT NOT NULL COMMENT '赠送类型:0满X送X;1每满X送X',
|
||||
"recharge_type" TINYINT NOT NULL COMMENT '充值类型:0微信、支付宝;1微信;2支付宝',
|
||||
"recharge_amount" DECIMAL(10, 3) NOT NULL COMMENT '充值金额',
|
||||
"gift_amount" DECIMAL(10, 3) NOT NULL COMMENT '赠送金额',
|
||||
"product_id" BIGINT NOT NULL COMMENT '关联产品id',
|
||||
"product_name" VARCHAR(64) NOT NULL COMMENT '关联产品名称',
|
||||
"purchase_duration" INT NOT NULL COMMENT '购买时长',
|
||||
"purchase_duration_unit" TINYINT NOT NULL COMMENT '购买时长单位',
|
||||
"gift_duration" INT COMMENT '赠送时长',
|
||||
"gift_duration_unit" TINYINT COMMENT '赠送时长单位',
|
||||
"start_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '开始时间',
|
||||
"end_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '结束时间',
|
||||
"remark" VARCHAR(1024) DEFAULT NULL COMMENT '备注',
|
||||
@@ -730,7 +732,7 @@ CREATE TABLE IF NOT EXISTS "gift_money_details" (
|
||||
"update_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
"deleted" BIT NOT NULL DEFAULT FALSE COMMENT '是否删除:0否 1是',
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '赠送金规则明细表(base表)';
|
||||
) COMMENT '优惠活动(base表)';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "advertisement" (
|
||||
"id" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY COMMENT '主键,根据ID号规则生成',
|
||||
|
||||
Reference in New Issue
Block a user