Merge remote-tracking branch 'origin/feature/mall_product' into feature/mall_product
This commit is contained in:
commit
5f29399cf4
|
@ -1,5 +1,6 @@
|
|||
package cn.iocoder.yudao.framework.common.enums;
|
||||
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
@ -34,4 +35,12 @@ public enum CommonStatusEnum implements IntArrayValuable {
|
|||
return ARRAYS;
|
||||
}
|
||||
|
||||
public static boolean isEnable(Integer status) {
|
||||
return ObjUtil.equal(ENABLE.status, status);
|
||||
}
|
||||
|
||||
public static boolean isDisable(Integer status) {
|
||||
return ObjUtil.equal(DISABLE.status, status);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,11 +28,6 @@
|
|||
<artifactId>yudao-module-member-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-module-promotion-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 业务组件 -->
|
||||
<dependency>
|
||||
|
|
|
@ -11,8 +11,6 @@ import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
|||
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
|
||||
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
|
||||
import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
|
||||
import cn.iocoder.yudao.module.promotion.api.coupon.CouponTemplateApi;
|
||||
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
@ -45,9 +43,6 @@ public class ProductSpuController {
|
|||
@Resource
|
||||
private ProductSkuService productSkuService;
|
||||
|
||||
@Resource
|
||||
private CouponTemplateApi couponTemplateApi;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建商品 SPU")
|
||||
@PreAuthorize("@ss.hasPermission('product:spu:create')")
|
||||
|
@ -92,11 +87,7 @@ public class ProductSpuController {
|
|||
}
|
||||
// 查询商品 SKU
|
||||
List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spu.getId());
|
||||
// 查询优惠卷
|
||||
// TODO @puhui999:优惠劵的信息,要不交给前端读取?主要是为了避免商品依赖 promotion 模块哈;
|
||||
List<CouponTemplateRespDTO> couponTemplateList = couponTemplateApi.getCouponTemplateListByIds(
|
||||
spu.getGiveCouponTemplateIds());
|
||||
return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespVO(spu, skus, couponTemplateList));
|
||||
return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespVO(spu, skus));
|
||||
}
|
||||
|
||||
@GetMapping("/list-all-simple")
|
||||
|
|
|
@ -96,9 +96,6 @@ public class ProductSpuBaseVO {
|
|||
@NotNull(message = "商品赠送积分不能为空")
|
||||
private Integer giveIntegral;
|
||||
|
||||
@Schema(description = "赠送的优惠劵数组包含优惠券编号和名称")
|
||||
private List<GiveCouponTemplate> giveCouponTemplates;
|
||||
|
||||
@Schema(description = "分销类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
||||
@NotNull(message = "商品分销类型不能为空")
|
||||
private Boolean subCommissionType;
|
||||
|
@ -111,16 +108,4 @@ public class ProductSpuBaseVO {
|
|||
@Schema(description = "虚拟销量", example = "66")
|
||||
private Integer virtualSalesCount;
|
||||
|
||||
@Schema(description = "管理后台 - 商品 SPU 赠送的优惠卷")
|
||||
@Data
|
||||
public static class GiveCouponTemplate {
|
||||
|
||||
@Schema(description = "模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "优惠劵名", requiredMode = Schema.RequiredMode.REQUIRED, example = "春节送送送")
|
||||
private String name;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
|
|||
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
||||
import cn.iocoder.yudao.module.product.enums.DictTypeConstants;
|
||||
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Named;
|
||||
|
@ -101,14 +100,8 @@ public interface ProductSpuConvert {
|
|||
|
||||
List<AppProductSpuDetailRespVO.Sku> convertListForGetSpuDetail(List<ProductSkuDO> skus);
|
||||
|
||||
List<ProductSpuDetailRespVO.GiveCouponTemplate> convertList04(List<CouponTemplateRespDTO> couponTemplateList);
|
||||
|
||||
default ProductSpuDetailRespVO convertForSpuDetailRespVO(ProductSpuDO spu, List<ProductSkuDO> skus,
|
||||
List<CouponTemplateRespDTO> couponTemplateList) {
|
||||
ProductSpuDetailRespVO respVO = convert03(spu);
|
||||
respVO.setSkus(ProductSkuConvert.INSTANCE.convertList(skus));
|
||||
respVO.setGiveCouponTemplates(convertList04(couponTemplateList));
|
||||
return respVO;
|
||||
default ProductSpuDetailRespVO convertForSpuDetailRespVO(ProductSpuDO spu, List<ProductSkuDO> skus) {
|
||||
return convert03(spu).setSkus(ProductSkuConvert.INSTANCE.convertList(skus));
|
||||
}
|
||||
|
||||
default List<ProductSpuDetailRespVO> convertForSpuDetailRespListVO(List<ProductSpuDO> spus, List<ProductSkuDO> skus) {
|
||||
|
|
|
@ -17,9 +17,6 @@ import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
|
|||
import cn.iocoder.yudao.module.product.service.brand.ProductBrandService;
|
||||
import cn.iocoder.yudao.module.product.service.category.ProductCategoryService;
|
||||
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
|
||||
import cn.iocoder.yudao.module.promotion.api.coupon.CouponTemplateApi;
|
||||
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -28,10 +25,10 @@ import org.springframework.validation.annotation.Validated;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getMinValue;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue;
|
||||
import static cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO.CATEGORY_LEVEL;
|
||||
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
|
||||
|
||||
|
@ -55,19 +52,12 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|||
@Resource
|
||||
private ProductCategoryService categoryService;
|
||||
|
||||
@Resource
|
||||
@Lazy
|
||||
private CouponTemplateApi couponTemplateApi;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createSpu(ProductSpuCreateReqVO createReqVO) {
|
||||
// 校验分类、品牌
|
||||
validateCategory(createReqVO.getCategoryId());
|
||||
brandService.validateProductBrand(createReqVO.getBrandId());
|
||||
// 校验优惠券
|
||||
Set<Long> giveCouponTemplateIds = convertSet(createReqVO.getGiveCouponTemplates(), ProductSpuCreateReqVO.GiveCouponTemplate::getId);
|
||||
validateCouponTemplate(giveCouponTemplateIds);
|
||||
// 校验 SKU
|
||||
List<ProductSkuCreateOrUpdateReqVO> skuSaveReqList = createReqVO.getSkus();
|
||||
productSkuService.validateSkuList(skuSaveReqList, createReqVO.getSpecType());
|
||||
|
@ -75,8 +65,6 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|||
ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO);
|
||||
// 初始化 SPU 中 SKU 相关属性
|
||||
initSpuFromSkus(spu, skuSaveReqList);
|
||||
// 设置优惠券
|
||||
spu.setGiveCouponTemplateIds(CollUtil.newArrayList(giveCouponTemplateIds));
|
||||
// 插入 SPU
|
||||
productSpuMapper.insert(spu);
|
||||
// 插入 SKU
|
||||
|
@ -93,9 +81,6 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|||
// 校验分类、品牌
|
||||
validateCategory(updateReqVO.getCategoryId());
|
||||
brandService.validateProductBrand(updateReqVO.getBrandId());
|
||||
// 校验优惠券
|
||||
Set<Long> giveCouponTemplateIds = convertSet(updateReqVO.getGiveCouponTemplates(), ProductSpuUpdateReqVO.GiveCouponTemplate::getId);
|
||||
validateCouponTemplate(giveCouponTemplateIds);
|
||||
// 校验SKU
|
||||
List<ProductSkuCreateOrUpdateReqVO> skuSaveReqList = updateReqVO.getSkus();
|
||||
productSkuService.validateSkuList(skuSaveReqList, updateReqVO.getSpecType());
|
||||
|
@ -103,8 +88,6 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|||
// 更新 SPU
|
||||
ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO);
|
||||
initSpuFromSkus(updateObj, skuSaveReqList);
|
||||
// 设置优惠券
|
||||
updateObj.setGiveCouponTemplateIds(CollUtil.newArrayList(giveCouponTemplateIds));
|
||||
productSpuMapper.updateById(updateObj);
|
||||
// 批量更新 SKU
|
||||
productSkuService.updateSkuList(updateObj.getId(), updateReqVO.getSkus());
|
||||
|
@ -138,10 +121,6 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|||
// 默认商品浏览量
|
||||
spu.setBrowseCount(0);
|
||||
}
|
||||
// 如果活动顺序为空则默认初始化
|
||||
if (CollUtil.isEmpty(spu.getActivityOrders())) {
|
||||
spu.setActivityOrders(Arrays.stream(PromotionTypeEnum.ARRAYS).boxed().collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -157,13 +136,6 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|||
}
|
||||
}
|
||||
|
||||
private void validateCouponTemplate(Collection<Long> ids) {
|
||||
List<CouponTemplateRespDTO> couponTemplateList = couponTemplateApi.getCouponTemplateListByIds(ids);
|
||||
if (couponTemplateList.size() != ids.size()) {
|
||||
throw exception(SPU_SAVE_FAIL_COUPON_TEMPLATE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProductSpuDO> validateSpuList(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package cn.iocoder.yudao.module.promotion.api.coupon;
|
||||
|
||||
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 优惠劵模版 API 接口
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
public interface CouponTemplateApi {
|
||||
|
||||
/**
|
||||
* 获得优惠券模版的精简信息列表
|
||||
*
|
||||
* @param ids 优惠券模版编号
|
||||
* @return 优惠券模版的精简信息列表
|
||||
*/
|
||||
List<CouponTemplateRespDTO> getCouponTemplateListByIds(Collection<Long> ids);
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package cn.iocoder.yudao.module.promotion.api.coupon.dto;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 优惠券模版 Response DTO
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class CouponTemplateRespDTO {
|
||||
/**
|
||||
* 模板编号,自增唯一
|
||||
*/
|
||||
|
||||
private Long id;
|
||||
/**
|
||||
* 优惠劵名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 枚举 {@link CommonStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package cn.iocoder.yudao.module.promotion.enums.banner;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import cn.iocoder.yudao.module.promotion.enums.bargain.BargainRecordStatusEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
|
@ -22,7 +21,8 @@ public enum BannerPositionEnum implements IntArrayValuable {
|
|||
DISCOUNT_POSITION(4, "限时折扣页"),
|
||||
REWARD_POSITION(5, "满减送页");
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BargainRecordStatusEnum::getStatus).toArray();
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BannerPositionEnum::getPosition).toArray();
|
||||
|
||||
/**
|
||||
* 值
|
||||
*/
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package cn.iocoder.yudao.module.promotion.api.coupon;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.convert.coupon.CouponTemplateConvert;
|
||||
import cn.iocoder.yudao.module.promotion.service.coupon.CouponTemplateService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 优惠劵模版 API 接口实现类
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Service
|
||||
public class CouponTemplateApiImpl implements CouponTemplateApi {
|
||||
|
||||
@Resource
|
||||
private CouponTemplateService couponTemplateService;
|
||||
|
||||
@Override
|
||||
public List<CouponTemplateRespDTO> getCouponTemplateListByIds(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) { // 防御一下
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return CouponTemplateConvert.INSTANCE.convertList(couponTemplateService.getCouponTemplateListByIds(ids));
|
||||
}
|
||||
|
||||
}
|
|
@ -23,7 +23,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|||
|
||||
@Tag(name = "管理后台 - Banner 管理")
|
||||
@RestController
|
||||
@RequestMapping("/market/banner")
|
||||
@RequestMapping("/promotion/banner")
|
||||
@Validated
|
||||
public class BannerController {
|
||||
|
||||
|
@ -32,14 +32,14 @@ public class BannerController {
|
|||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建 Banner")
|
||||
@PreAuthorize("@ss.hasPermission('market:banner:create')")
|
||||
@PreAuthorize("@ss.hasPermission('promotion:banner:create')")
|
||||
public CommonResult<Long> createBanner(@Valid @RequestBody BannerCreateReqVO createReqVO) {
|
||||
return success(bannerService.createBanner(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新 Banner")
|
||||
@PreAuthorize("@ss.hasPermission('market:banner:update')")
|
||||
@PreAuthorize("@ss.hasPermission('promotion:banner:update')")
|
||||
public CommonResult<Boolean> updateBanner(@Valid @RequestBody BannerUpdateReqVO updateReqVO) {
|
||||
bannerService.updateBanner(updateReqVO);
|
||||
return success(true);
|
||||
|
@ -48,7 +48,7 @@ public class BannerController {
|
|||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除 Banner")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('market:banner:delete')")
|
||||
@PreAuthorize("@ss.hasPermission('promotion:banner:delete')")
|
||||
public CommonResult<Boolean> deleteBanner(@RequestParam("id") Long id) {
|
||||
bannerService.deleteBanner(id);
|
||||
return success(true);
|
||||
|
@ -57,7 +57,7 @@ public class BannerController {
|
|||
@GetMapping("/get")
|
||||
@Operation(summary = "获得 Banner")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('market:banner:query')")
|
||||
@PreAuthorize("@ss.hasPermission('promotion:banner:query')")
|
||||
public CommonResult<BannerRespVO> getBanner(@RequestParam("id") Long id) {
|
||||
BannerDO banner = bannerService.getBanner(id);
|
||||
return success(BannerConvert.INSTANCE.convert(banner));
|
||||
|
@ -65,7 +65,7 @@ public class BannerController {
|
|||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得 Banner 分页")
|
||||
@PreAuthorize("@ss.hasPermission('market:banner:query')")
|
||||
@PreAuthorize("@ss.hasPermission('promotion:banner:query')")
|
||||
public CommonResult<PageResult<BannerRespVO>> getBannerPage(@Valid BannerPageReqVO pageVO) {
|
||||
PageResult<BannerDO> pageResult = bannerService.getBannerPage(pageVO);
|
||||
return success(BannerConvert.INSTANCE.convertPage(pageResult));
|
||||
|
|
|
@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.controller.admin.banner.vo;
|
|||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.promotion.enums.banner.BannerPositionEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
|
@ -29,6 +30,7 @@ public class BannerBaseVO {
|
|||
|
||||
@Schema(description = "position", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "position 不能为空")
|
||||
@InEnum(BannerPositionEnum.class)
|
||||
private Integer position;
|
||||
|
||||
@Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
|
|
|
@ -59,6 +59,15 @@ public class BargainActivityController {
|
|||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/close")
|
||||
@Operation(summary = "关闭砍价活动")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('promotion:bargain-activity:close')")
|
||||
public CommonResult<Boolean> closeSeckillActivity(@RequestParam("id") Long id) {
|
||||
bargainActivityService.closeBargainActivityById(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除砍价活动")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
|
|
|
@ -59,6 +59,15 @@ public class CombinationActivityController {
|
|||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/close")
|
||||
@Operation(summary = "关闭拼团活动")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('promotion:combination-activity:close')")
|
||||
public CommonResult<Boolean> closeSeckillActivity(@RequestParam("id") Long id) {
|
||||
combinationActivityService.closeCombinationActivityById(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除拼团活动")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
|
|
|
@ -5,8 +5,6 @@ import cn.iocoder.yudao.module.promotion.controller.app.banner.vo.AppBannerRespV
|
|||
import cn.iocoder.yudao.module.promotion.convert.banner.BannerConvert;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.banner.BannerDO;
|
||||
import cn.iocoder.yudao.module.promotion.service.banner.BannerService;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
@ -14,11 +12,9 @@ import org.springframework.validation.annotation.Validated;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/promotion/banner")
|
||||
|
@ -26,20 +22,6 @@ import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsync
|
|||
@Validated
|
||||
public class AppBannerController {
|
||||
|
||||
// TODO @puhui999:这个目前不缓存,也没问题,因为首页没用到。
|
||||
/**
|
||||
* {@link AppBannerRespVO} 缓存,通过它异步刷新 {@link #getBannerList0(Integer)} 所要的首页数据
|
||||
*/
|
||||
private final LoadingCache<Integer, List<AppBannerRespVO>> bannerListCache = buildAsyncReloadingCache(Duration.ofSeconds(10L),
|
||||
new CacheLoader<Integer, List<AppBannerRespVO>>() {
|
||||
|
||||
@Override
|
||||
public List<AppBannerRespVO> load(Integer position) {
|
||||
return getBannerList0(position);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@Resource
|
||||
private BannerService bannerService;
|
||||
|
||||
|
@ -47,12 +29,8 @@ public class AppBannerController {
|
|||
@Operation(summary = "获得 banner 列表")
|
||||
@Parameter(name = "position", description = "Banner position", example = "1")
|
||||
public CommonResult<List<AppBannerRespVO>> getBannerList(@RequestParam("position") Integer position) {
|
||||
return success(bannerListCache.getUnchecked(position));
|
||||
}
|
||||
|
||||
private List<AppBannerRespVO> getBannerList0(Integer position) {
|
||||
List<BannerDO> bannerList = bannerService.getBannerListByPosition(position);
|
||||
return BannerConvert.INSTANCE.convertList01(bannerList);
|
||||
return success(BannerConvert.INSTANCE.convertList01(bannerList));
|
||||
}
|
||||
|
||||
@PutMapping("/add-browse-count")
|
||||
|
|
|
@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.promotion.convert.coupon;
|
|||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateCreateReqVO;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplatePageReqVO;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateRespVO;
|
||||
|
@ -59,6 +58,4 @@ public interface CouponTemplateConvert {
|
|||
}
|
||||
}
|
||||
|
||||
List<CouponTemplateRespDTO> convertList(List<CouponTemplateDO> list);
|
||||
|
||||
}
|
||||
|
|
|
@ -6,13 +6,12 @@ import cn.iocoder.yudao.module.promotion.enums.banner.BannerPositionEnum;
|
|||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
// TODO @puhui999:表名改成 promotion_banner,然后有序加下;另外,sql 给我下哈;还有那个 position 字典,嘿嘿。
|
||||
/**
|
||||
* banner DO
|
||||
*
|
||||
* @author xia
|
||||
*/
|
||||
@TableName("market_banner")
|
||||
@TableName("promotion_banner")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
|
|
|
@ -75,8 +75,4 @@ public interface CouponTemplateMapper extends BaseMapperX<CouponTemplateDO> {
|
|||
return canTakeConsumer;
|
||||
}
|
||||
|
||||
default List<CouponTemplateDO> selectListByIds(Collection<Long> ids) {
|
||||
return selectList(new LambdaQueryWrapperX<CouponTemplateDO>().in(CouponTemplateDO::getId, ids));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,6 +45,13 @@ public interface BargainActivityService {
|
|||
*/
|
||||
void updateBargainActivityStock(Long id, Integer count);
|
||||
|
||||
/**
|
||||
* 关闭砍价活动
|
||||
*
|
||||
* @param id 砍价活动编号
|
||||
*/
|
||||
void closeBargainActivityById(Long id);
|
||||
|
||||
/**
|
||||
* 删除砍价活动
|
||||
*
|
||||
|
|
|
@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.promotion.service.bargain;
|
|||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
@ -96,6 +95,19 @@ public class BargainActivityServiceImpl implements BargainActivityService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void closeBargainActivityById(Long id) {
|
||||
// 校验砍价活动是否存在
|
||||
BargainActivityDO activity = validateBargainActivityExists(id);
|
||||
if (CommonStatusEnum.isDisable(activity.getStatus())) {
|
||||
throw exception(BARGAIN_ACTIVITY_STATUS_DISABLE);
|
||||
}
|
||||
|
||||
bargainActivityMapper.updateById(new BargainActivityDO().setId(id)
|
||||
.setStatus(CommonStatusEnum.DISABLE.getStatus()));
|
||||
}
|
||||
|
||||
private void validateBargainConflict(Long spuId, Long activityId) {
|
||||
// 查询所有开启的砍价活动
|
||||
List<BargainActivityDO> activityList = bargainActivityMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
|
@ -121,7 +133,7 @@ public class BargainActivityServiceImpl implements BargainActivityService {
|
|||
// 校验存在
|
||||
BargainActivityDO activityDO = validateBargainActivityExists(id);
|
||||
// 校验状态
|
||||
if (ObjectUtil.equal(activityDO.getStatus(), CommonStatusEnum.ENABLE.getStatus())) {
|
||||
if (CommonStatusEnum.isEnable(activityDO.getStatus())) {
|
||||
throw exception(BARGAIN_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END);
|
||||
}
|
||||
|
||||
|
@ -153,7 +165,7 @@ public class BargainActivityServiceImpl implements BargainActivityService {
|
|||
if (activity == null) {
|
||||
throw exception(BARGAIN_ACTIVITY_NOT_EXISTS);
|
||||
}
|
||||
if (ObjUtil.notEqual(activity.getStatus(), CommonStatusEnum.ENABLE.getStatus())) {
|
||||
if (CommonStatusEnum.isDisable(activity.getStatus())) {
|
||||
throw exception(BARGAIN_ACTIVITY_STATUS_CLOSED);
|
||||
}
|
||||
if (activity.getStock() <= 0) {
|
||||
|
|
|
@ -36,7 +36,12 @@ public interface CombinationActivityService {
|
|||
*/
|
||||
void updateCombinationActivity(@Valid CombinationActivityUpdateReqVO updateReqVO);
|
||||
|
||||
// TODO @puhui999:这里少了一个关闭活动的接口;因为关闭的活动,才可以删除
|
||||
/**
|
||||
* 关闭拼团活动
|
||||
*
|
||||
* @param id 拼团活动编号
|
||||
*/
|
||||
void closeCombinationActivityById(Long id);
|
||||
|
||||
/**
|
||||
* 删除拼团活动
|
||||
|
|
|
@ -138,6 +138,20 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
|
|||
updateCombinationProduct(updateObj, updateReqVO.getProducts());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void closeCombinationActivityById(Long id) {
|
||||
// 校验活动是否存在
|
||||
CombinationActivityDO activity = validateCombinationActivityExists(id);
|
||||
if (CommonStatusEnum.isDisable(activity.getStatus())) {
|
||||
throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE_NOT_UPDATE);
|
||||
}
|
||||
|
||||
// 关闭活动
|
||||
combinationActivityMapper.updateById(new CombinationActivityDO().setId(id)
|
||||
.setStatus(CommonStatusEnum.DISABLE.getStatus()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新拼团商品
|
||||
*
|
||||
|
@ -172,9 +186,9 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteCombinationActivity(Long id) {
|
||||
// 校验存在
|
||||
CombinationActivityDO activityDO = validateCombinationActivityExists(id);
|
||||
CombinationActivityDO activity = validateCombinationActivityExists(id);
|
||||
// 校验状态
|
||||
if (ObjectUtil.equal(activityDO.getStatus(), CommonStatusEnum.ENABLE.getStatus())) {
|
||||
if (CommonStatusEnum.isEnable(activity.getStatus())) {
|
||||
throw exception(COMBINATION_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END);
|
||||
}
|
||||
|
||||
|
|
|
@ -98,6 +98,6 @@ public interface CouponTemplateService {
|
|||
* @param ids 优惠券模版编号
|
||||
* @return 优惠券模版列表
|
||||
*/
|
||||
List<CouponTemplateDO> getCouponTemplateListByIds(Collection<Long> ids);
|
||||
List<CouponTemplateDO> getCouponTemplateList(Collection<Long> ids);
|
||||
|
||||
}
|
||||
|
|
|
@ -128,8 +128,8 @@ public class CouponTemplateServiceImpl implements CouponTemplateService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<CouponTemplateDO> getCouponTemplateListByIds(Collection<Long> ids) {
|
||||
return couponTemplateMapper.selectListByIds(ids);
|
||||
public List<CouponTemplateDO> getCouponTemplateList(Collection<Long> ids) {
|
||||
return couponTemplateMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -147,8 +147,8 @@ public class DiscountActivityServiceImpl implements DiscountActivityService {
|
|||
@Override
|
||||
public void deleteDiscountActivity(Long id) {
|
||||
// 校验存在
|
||||
DiscountActivityDO discountActivity = validateDiscountActivityExists(id);
|
||||
if (!discountActivity.getStatus().equals(CommonStatusEnum.ENABLE.getStatus())) { // 未关闭的活动,不能删除噢
|
||||
DiscountActivityDO activity = validateDiscountActivityExists(id);
|
||||
if (CommonStatusEnum.isEnable(activity.getStatus())) { // 未关闭的活动,不能删除噢
|
||||
throw exception(DISCOUNT_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED);
|
||||
}
|
||||
|
||||
|
|
|
@ -296,7 +296,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
|||
public SeckillValidateJoinRespDTO validateJoinSeckill(Long activityId, Long skuId, Integer count) {
|
||||
// 1.1 校验秒杀活动是否存在
|
||||
SeckillActivityDO activity = validateSeckillActivityExists(activityId);
|
||||
if (ObjectUtil.notEqual(activity.getStatus(), CommonStatusEnum.ENABLE.getStatus())) {
|
||||
if (CommonStatusEnum.isDisable(activity.getStatus())) {
|
||||
throw exception(SECKILL_JOIN_ACTIVITY_STATUS_CLOSED);
|
||||
}
|
||||
// 1.2 是否在活动时间范围内
|
||||
|
|
|
@ -12,8 +12,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO
|
|||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -44,31 +43,32 @@ public interface MemberSignInRecordConvert {
|
|||
|
||||
AppMemberSignInRecordRespVO coverRecordToAppRecordVo(MemberSignInRecordDO memberSignInRecordDO);
|
||||
|
||||
default MemberSignInRecordDO convert(Long userId, MemberSignInRecordDO firstRecord, List<MemberSignInConfigDO> signInConfigs) {
|
||||
// 1. 计算今天是第几天签到
|
||||
long day = ChronoUnit.DAYS.between(firstRecord.getCreateTime(), LocalDateTime.now());
|
||||
// 2. 初始化签到信息
|
||||
// TODO @puhui999:signInRecord=》record
|
||||
MemberSignInRecordDO signInRecord = new MemberSignInRecordDO().setUserId(userId)
|
||||
.setDay(Integer.parseInt(Long.toString(day))) // 设置签到天数 TODO @puhui999:day 应该跟着第几天签到走;不是累加哈;另外 long 转 int,应该 (int) day 就可以了。。。
|
||||
.setPoint(0) // 设置签到积分默认为
|
||||
.setExperience(0); // 设置签到经验默认为 0
|
||||
// 3. 获取签到对应的积分数
|
||||
MemberSignInConfigDO lastConfig = signInConfigs.get(signInConfigs.size() - 1); // 最大签到天数
|
||||
if (day > lastConfig.getDay()) { // 超出范围按第一天的经验计算
|
||||
// TODO @puhui999:不能直接取 0,万一它 day 不匹配哈。就是第一天没奖励。。。
|
||||
signInRecord.setPoint(signInConfigs.get(0).getPoint());
|
||||
signInRecord.setExperience(signInConfigs.get(0).getExperience());
|
||||
return signInRecord;
|
||||
default MemberSignInRecordDO convert(Long userId, MemberSignInRecordDO lastRecord, List<MemberSignInConfigDO> configs) {
|
||||
// 1. 计算是第几天签到
|
||||
configs.sort(Comparator.comparing(MemberSignInConfigDO::getDay));
|
||||
MemberSignInConfigDO lastConfig = CollUtil.getLast(configs); // 最大签到天数配置
|
||||
// 1.2. 计算今天是第几天签到
|
||||
int day = 1;
|
||||
// TODO @puhui999:要判断是不是昨天签到的;是否是昨天的判断,可以抽个方法到 util 里
|
||||
if (lastRecord != null) {
|
||||
day = lastRecord.getDay() + 1;
|
||||
}
|
||||
// TODO @puhui999:signInConfig 可以改成 config;
|
||||
MemberSignInConfigDO signInConfig = CollUtil.findOne(signInConfigs, config -> ObjUtil.equal(config.getDay(), day));
|
||||
if (signInConfig == null) {
|
||||
return signInRecord;
|
||||
// 1.3 判断是否超出了最大签到配置
|
||||
if (day > lastConfig.getDay()) {
|
||||
day = 1; // 超过最大配置的天数,重置到第一天。(也就是说开启下一轮签到)
|
||||
}
|
||||
signInRecord.setPoint(signInConfig.getPoint());
|
||||
signInRecord.setExperience(signInConfig.getExperience());
|
||||
return signInRecord;
|
||||
|
||||
// 2.1 初始化签到信息
|
||||
MemberSignInRecordDO record = new MemberSignInRecordDO().setUserId(userId)
|
||||
.setDay(day).setPoint(0).setExperience(0);
|
||||
// 2.2 获取签到对应的积分
|
||||
MemberSignInConfigDO config = CollUtil.findOne(configs, item -> ObjUtil.equal(item.getDay(), record.getDay()));
|
||||
if (config == null) {
|
||||
return record;
|
||||
}
|
||||
record.setPoint(config.getPoint());
|
||||
record.setExperience(config.getExperience());
|
||||
return record;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,50 +35,31 @@ public interface MemberSignInRecordMapper extends BaseMapperX<MemberSignInRecord
|
|||
.orderByDesc(MemberSignInRecordDO::getId));
|
||||
}
|
||||
|
||||
// TODO @puhui999:这 2 个方法,是不是一个 first;一个 last 就可以了。。
|
||||
/**
|
||||
* 获取用户最近的签到记录信息,根据签到时间倒序
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @return 签到记录列表
|
||||
*/
|
||||
default MemberSignInRecordDO selectLastRecordByUserIdDesc(Long userId) {
|
||||
default MemberSignInRecordDO selectLastRecordByUserId(Long userId) {
|
||||
return selectOne(new QueryWrapper<MemberSignInRecordDO>()
|
||||
.eq("user_id", userId)
|
||||
.orderByDesc("create_time")
|
||||
.last("limit 1"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户最早的签到记录信息,根据签到时间倒序
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @return 签到记录列表
|
||||
*/
|
||||
default MemberSignInRecordDO selectLastRecordByUserIdAsc(Long userId) {
|
||||
return selectOne(new QueryWrapper<MemberSignInRecordDO>()
|
||||
.eq("user_id", userId)
|
||||
.orderByAsc("create_time")
|
||||
.last("limit 1"));
|
||||
}
|
||||
|
||||
default Long selectCountByUserId(Long userId) {
|
||||
// TODO @puhui999:可以使用 selectCount 里面允许传递字段的方法
|
||||
return selectCount(new LambdaQueryWrapperX<MemberSignInRecordDO>()
|
||||
.eq(MemberSignInRecordDO::getUserId, userId));
|
||||
return selectCount(MemberSignInRecordDO::getUserId, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的签到记录列表信息,根据签到时间倒序
|
||||
* 获取用户的签到记录列表信息
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @return 签到记录信息
|
||||
*/
|
||||
// TODO @puhui999:这个排序,可以交给 service 哈;
|
||||
default List<MemberSignInRecordDO> selectListByUserId(Long userId) {
|
||||
return selectList(new LambdaQueryWrapperX<MemberSignInRecordDO>()
|
||||
.eq(MemberSignInRecordDO::getUserId, userId)
|
||||
.orderByDesc(MemberSignInRecordDO::getCreateTime));
|
||||
return selectList(MemberSignInRecordDO::getUserId, userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -58,36 +58,38 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
|
|||
@Override
|
||||
public AppMemberSignInRecordSummaryRespVO getSignInRecordSummary(Long userId) {
|
||||
// 1. 初始化默认返回信息
|
||||
// TODO @puhui999:这里 vo 改成 summary 会更好理解;
|
||||
AppMemberSignInRecordSummaryRespVO vo = new AppMemberSignInRecordSummaryRespVO();
|
||||
vo.setTotalDay(0);
|
||||
vo.setContinuousDay(0);
|
||||
vo.setTodaySignIn(false);
|
||||
AppMemberSignInRecordSummaryRespVO summary = new AppMemberSignInRecordSummaryRespVO();
|
||||
summary.setTotalDay(0);
|
||||
summary.setContinuousDay(0);
|
||||
summary.setTodaySignIn(false);
|
||||
|
||||
// 2. 获取用户签到的记录数
|
||||
Long signCount = signInRecordMapper.selectCountByUserId(userId);
|
||||
if (ObjUtil.equal(signCount, 0L)) {
|
||||
return vo;
|
||||
return summary;
|
||||
}
|
||||
vo.setTotalDay(signCount.intValue()); // 设置总签到天数
|
||||
summary.setTotalDay(signCount.intValue()); // 设置总签到天数
|
||||
|
||||
// 3. 校验当天是否有签到
|
||||
// TODO @puhui999:是不是 signInRecord 可以精简成 record 哈;另外,Desc 貌似可以去掉哈;最后一条了;
|
||||
MemberSignInRecordDO signInRecord = signInRecordMapper.selectLastRecordByUserIdDesc(userId);
|
||||
if (signInRecord == null) {
|
||||
return vo;
|
||||
MemberSignInRecordDO lastRecord = signInRecordMapper.selectLastRecordByUserId(userId);
|
||||
if (lastRecord == null) {
|
||||
return summary;
|
||||
}
|
||||
vo.setTodaySignIn(DateUtils.isToday(signInRecord.getCreateTime()));
|
||||
summary.setTodaySignIn(DateUtils.isToday(lastRecord.getCreateTime()));
|
||||
|
||||
// 4. 校验今天是否签到,没有签到则直接返回
|
||||
if (!vo.getTodaySignIn()) {
|
||||
return vo;
|
||||
if (!summary.getTodaySignIn()) {
|
||||
return summary;
|
||||
}
|
||||
// 4.1. 判断连续签到天数
|
||||
// TODO @puhui999:连续签到,可以基于 signInRecord 的 day 和当前时间判断呀?
|
||||
// TODO @puhui999:连续签到,可以基于 lastRecord 的 day 和当前时间判断呀?按 day 统计连续签到天数可能不准确
|
||||
// 1. day 只是记录第几天签到的有可能不连续,比如第一次签到是周一,第二次签到是周三这样 lastRecord 的 day 为 2 但是并不是连续的两天
|
||||
// 2. day 超出签到规则的最大天数会重置到从第一天开始签到(我理解为开始下一轮,类似一周签到七天七天结束下周又从周一开始签到)
|
||||
// 1. 回复:周三签到,day 要归 1 呀。连续签到哈;
|
||||
List<MemberSignInRecordDO> signInRecords = signInRecordMapper.selectListByUserId(userId);
|
||||
vo.setContinuousDay(calculateConsecutiveDays(signInRecords));
|
||||
return vo;
|
||||
signInRecords.sort(Comparator.comparing(MemberSignInRecordDO::getCreateTime).reversed()); // 根据签到时间倒序
|
||||
summary.setContinuousDay(calculateConsecutiveDays(signInRecords));
|
||||
return summary;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,17 +146,14 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public MemberSignInRecordDO createSignRecord(Long userId) {
|
||||
// 1. 获取当前用户最近的签到
|
||||
MemberSignInRecordDO lastRecord = signInRecordMapper.selectLastRecordByUserIdDesc(userId);
|
||||
MemberSignInRecordDO lastRecord = signInRecordMapper.selectLastRecordByUserId(userId);
|
||||
// 1.1. 判断是否重复签到
|
||||
validateSigned(lastRecord);
|
||||
|
||||
// 2. 获取当前用户最早的一次前端记录,用于计算今天是第几天签到
|
||||
MemberSignInRecordDO firstRecord = signInRecordMapper.selectLastRecordByUserIdAsc(userId);
|
||||
// 2.1. 获取所有的签到规则
|
||||
List<MemberSignInConfigDO> signInConfigs = signInConfigService.getSignInConfigList(CommonStatusEnum.ENABLE.getStatus());
|
||||
signInConfigs.sort(Comparator.comparing(MemberSignInConfigDO::getDay));
|
||||
// 2.2. 组合数据
|
||||
MemberSignInRecordDO record = MemberSignInRecordConvert.INSTANCE.convert(userId, firstRecord, signInConfigs);
|
||||
MemberSignInRecordDO record = MemberSignInRecordConvert.INSTANCE.convert(userId, lastRecord, signInConfigs);
|
||||
|
||||
// 3. 插入签到记录
|
||||
signInRecordMapper.insert(record);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package cn.iocoder.yudao.module.member.service.auth;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils;
|
||||
import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration;
|
||||
|
@ -48,8 +47,6 @@ public class MemberAuthServiceTest extends BaseDbAndRedisUnitTest {
|
|||
@MockBean
|
||||
private SocialUserApi socialUserApi;
|
||||
@MockBean
|
||||
private WxMaService wxMaService;
|
||||
@MockBean
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
@Resource
|
||||
|
|
|
@ -23,10 +23,10 @@ import cn.iocoder.yudao.module.system.service.member.MemberService;
|
|||
import cn.iocoder.yudao.module.system.service.oauth2.OAuth2TokenService;
|
||||
import cn.iocoder.yudao.module.system.service.social.SocialUserService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.xingyuv.captcha.model.common.ResponseModel;
|
||||
import com.xingyuv.captcha.model.vo.CaptchaVO;
|
||||
import com.xingyuv.captcha.service.CaptchaService;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -85,7 +85,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|||
throw exception(AUTH_LOGIN_BAD_CREDENTIALS);
|
||||
}
|
||||
// 校验是否禁用
|
||||
if (ObjectUtil.notEqual(user.getStatus(), CommonStatusEnum.ENABLE.getStatus())) {
|
||||
if (CommonStatusEnum.isDisable(user.getStatus())) {
|
||||
createLoginLog(user.getId(), username, logTypeEnum, LoginResultEnum.USER_DISABLED);
|
||||
throw exception(AUTH_LOGIN_USER_DISABLED);
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ public class OAuth2ClientServiceImpl implements OAuth2ClientService {
|
|||
if (client == null) {
|
||||
throw exception(OAUTH2_CLIENT_NOT_EXISTS);
|
||||
}
|
||||
if (ObjectUtil.notEqual(client.getStatus(), CommonStatusEnum.ENABLE.getStatus())) {
|
||||
if (CommonStatusEnum.isDisable(client.getStatus())) {
|
||||
throw exception(OAUTH2_CLIENT_DISABLE);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.springframework.util.Assert;
|
|||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
@ -144,7 +143,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService {
|
|||
if (channelDO == null) {
|
||||
throw exception(SMS_CHANNEL_NOT_EXISTS);
|
||||
}
|
||||
if (!Objects.equals(channelDO.getStatus(), CommonStatusEnum.ENABLE.getStatus())) {
|
||||
if (CommonStatusEnum.isDisable(channelDO.getStatus())) {
|
||||
throw exception(SMS_CHANNEL_DISABLE);
|
||||
}
|
||||
return channelDO;
|
||||
|
|
|
@ -111,31 +111,31 @@ public class SocialUserServiceImpl implements SocialUserService {
|
|||
* 授权获得对应的社交用户
|
||||
* 如果授权失败,则会抛出 {@link ServiceException} 异常
|
||||
*
|
||||
* @param type 社交平台的类型 {@link SocialTypeEnum}
|
||||
* @param socialType 社交平台的类型 {@link SocialTypeEnum}
|
||||
* @param userType 用户类型
|
||||
* @param code 授权码
|
||||
* @param state state
|
||||
* @return 授权用户
|
||||
*/
|
||||
@NotNull
|
||||
public SocialUserDO authSocialUser(Integer type, Integer userType, String code, String state) {
|
||||
public SocialUserDO authSocialUser(Integer socialType, Integer userType, String code, String state) {
|
||||
// 优先从 DB 中获取,因为 code 有且可以使用一次。
|
||||
// 在社交登录时,当未绑定 User 时,需要绑定登录,此时需要 code 使用两次
|
||||
SocialUserDO socialUser = socialUserMapper.selectByTypeAndCodeAnState(type, code, state);
|
||||
SocialUserDO socialUser = socialUserMapper.selectByTypeAndCodeAnState(socialType, code, state);
|
||||
if (socialUser != null) {
|
||||
return socialUser;
|
||||
}
|
||||
|
||||
// 请求获取
|
||||
AuthUser authUser = socialClientService.getAuthUser(type, userType, code, state);
|
||||
AuthUser authUser = socialClientService.getAuthUser(socialType, userType, code, state);
|
||||
Assert.notNull(authUser, "三方用户不能为空");
|
||||
|
||||
// 保存到 DB 中
|
||||
socialUser = socialUserMapper.selectByTypeAndOpenid(type, authUser.getUuid());
|
||||
socialUser = socialUserMapper.selectByTypeAndOpenid(socialType, authUser.getUuid());
|
||||
if (socialUser == null) {
|
||||
socialUser = new SocialUserDO();
|
||||
}
|
||||
socialUser.setType(type).setCode(code).setState(state) // 需要保存 code + state 字段,保证后续可查询
|
||||
socialUser.setType(socialType).setCode(code).setState(state) // 需要保存 code + state 字段,保证后续可查询
|
||||
.setOpenid(authUser.getUuid()).setToken(authUser.getToken().getAccessToken()).setRawTokenInfo((toJsonString(authUser.getToken())))
|
||||
.setNickname(authUser.getNickname()).setAvatar(authUser.getAvatar()).setRawUserInfo(toJsonString(authUser.getRawUserInfo()));
|
||||
if (socialUser.getId() == null) {
|
||||
|
|
|
@ -15,17 +15,15 @@ import com.xingyuv.jushauth.model.AuthCallback;
|
|||
import com.xingyuv.jushauth.model.AuthResponse;
|
||||
import com.xingyuv.jushauth.model.AuthUser;
|
||||
import com.xingyuv.jushauth.request.AuthRequest;
|
||||
import com.xingyuv.jushauth.utils.AuthStateUtils;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.randomLong;
|
||||
import static cn.hutool.core.util.RandomUtil.randomString;
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
|
@ -36,6 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
import static org.mockito.Mockito.*;
|
||||
|
||||
@Import(SocialUserServiceImpl.class)
|
||||
@Disabled // TODO 芋艿:后续统一修复
|
||||
public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
|
@ -49,38 +48,40 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||
@MockBean
|
||||
private YudaoAuthRequestFactory authRequestFactory;
|
||||
|
||||
@Test
|
||||
public void testGetAuthorizeUrl() {
|
||||
try (MockedStatic<AuthStateUtils> authStateUtilsMock = mockStatic(AuthStateUtils.class)) {
|
||||
// 准备参数
|
||||
Integer type = SocialTypeEnum.WECHAT_MP.getType();
|
||||
String redirectUri = "sss";
|
||||
// mock 获得对应的 AuthRequest 实现
|
||||
AuthRequest authRequest = mock(AuthRequest.class);
|
||||
when(authRequestFactory.get(eq("WECHAT_MP"))).thenReturn(authRequest);
|
||||
// mock 方法
|
||||
authStateUtilsMock.when(AuthStateUtils::createState).thenReturn("aoteman");
|
||||
when(authRequest.authorize(eq("aoteman"))).thenReturn("https://www.iocoder.cn?redirect_uri=yyy");
|
||||
|
||||
// 调用
|
||||
String url = socialUserService.getAuthorizeUrl(type, redirectUri);
|
||||
// 断言
|
||||
assertEquals("https://www.iocoder.cn?redirect_uri=sss", url);
|
||||
}
|
||||
}
|
||||
// TODO 芋艿:后续统一修复
|
||||
// @Test
|
||||
// public void testGetAuthorizeUrl() {
|
||||
// try (MockedStatic<AuthStateUtils> authStateUtilsMock = mockStatic(AuthStateUtils.class)) {
|
||||
// // 准备参数
|
||||
// Integer type = SocialTypeEnum.WECHAT_MP.getType();
|
||||
// String redirectUri = "sss";
|
||||
// // mock 获得对应的 AuthRequest 实现
|
||||
// AuthRequest authRequest = mock(AuthRequest.class);
|
||||
// when(authRequestFactory.get(eq("WECHAT_MP"))).thenReturn(authRequest);
|
||||
// // mock 方法
|
||||
// authStateUtilsMock.when(AuthStateUtils::createState).thenReturn("aoteman");
|
||||
// when(authRequest.authorize(eq("aoteman"))).thenReturn("https://www.iocoder.cn?redirect_uri=yyy");
|
||||
//
|
||||
// // 调用
|
||||
// String url = socialUserService.getAuthorizeUrl(type, redirectUri);
|
||||
// // 断言
|
||||
// assertEquals("https://www.iocoder.cn?redirect_uri=sss", url);
|
||||
// }
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testAuthSocialUser_exists() {
|
||||
// 准备参数
|
||||
Integer type = SocialTypeEnum.GITEE.getType();
|
||||
Integer socialType = SocialTypeEnum.GITEE.getType();
|
||||
Integer userType = randomEle(SocialTypeEnum.values()).getType();
|
||||
String code = "tudou";
|
||||
String state = "yuanma";
|
||||
// mock 方法
|
||||
SocialUserDO socialUser = randomPojo(SocialUserDO.class).setType(type).setCode(code).setState(state);
|
||||
SocialUserDO socialUser = randomPojo(SocialUserDO.class).setType(socialType).setCode(code).setState(state);
|
||||
socialUserMapper.insert(socialUser);
|
||||
|
||||
// 调用
|
||||
SocialUserDO result = socialUserService.authSocialUser(type, code, state);
|
||||
SocialUserDO result = socialUserService.authSocialUser(socialType, userType, code, state);
|
||||
// 断言
|
||||
assertPojoEquals(socialUser, result);
|
||||
}
|
||||
|
@ -88,7 +89,8 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||
@Test
|
||||
public void testAuthSocialUser_authFailure() {
|
||||
// 准备参数
|
||||
Integer type = SocialTypeEnum.GITEE.getType();
|
||||
Integer socialType = SocialTypeEnum.GITEE.getType();
|
||||
Integer userType = randomEle(SocialTypeEnum.values()).getType();
|
||||
// mock 方法
|
||||
AuthRequest authRequest = mock(AuthRequest.class);
|
||||
when(authRequestFactory.get(anyString())).thenReturn(authRequest);
|
||||
|
@ -97,14 +99,15 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||
|
||||
// 调用并断言
|
||||
assertServiceException(
|
||||
() -> socialUserService.authSocialUser(type, randomString(10), randomString(10)),
|
||||
() -> socialUserService.authSocialUser(socialType, userType, randomString(10), randomString(10)),
|
||||
SOCIAL_USER_AUTH_FAILURE, "模拟失败");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthSocialUser_insert() {
|
||||
// 准备参数
|
||||
Integer type = SocialTypeEnum.GITEE.getType();
|
||||
Integer socialType = SocialTypeEnum.GITEE.getType();
|
||||
Integer userType = randomEle(SocialTypeEnum.values()).getType();
|
||||
String code = "tudou";
|
||||
String state = "yuanma";
|
||||
// mock 方法
|
||||
|
@ -115,9 +118,9 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||
when(authRequest.login(any(AuthCallback.class))).thenReturn(authResponse);
|
||||
|
||||
// 调用
|
||||
SocialUserDO result = socialUserService.authSocialUser(type, code, state);
|
||||
SocialUserDO result = socialUserService.authSocialUser(socialType, userType, code, state);
|
||||
// 断言
|
||||
assertBindSocialUser(type, result, authResponse.getData());
|
||||
assertBindSocialUser(socialType, result, authResponse.getData());
|
||||
assertEquals(code, result.getCode());
|
||||
assertEquals(state, result.getState());
|
||||
}
|
||||
|
@ -125,11 +128,12 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||
@Test
|
||||
public void testAuthSocialUser_update() {
|
||||
// 准备参数
|
||||
Integer type = SocialTypeEnum.GITEE.getType();
|
||||
Integer socialType = SocialTypeEnum.GITEE.getType();
|
||||
Integer userType = randomEle(SocialTypeEnum.values()).getType();
|
||||
String code = "tudou";
|
||||
String state = "yuanma";
|
||||
// mock 数据
|
||||
socialUserMapper.insert(randomPojo(SocialUserDO.class).setType(type).setOpenid("test_openid"));
|
||||
socialUserMapper.insert(randomPojo(SocialUserDO.class).setType(socialType).setOpenid("test_openid"));
|
||||
// mock 方法
|
||||
AuthRequest authRequest = mock(AuthRequest.class);
|
||||
when(authRequestFactory.get(eq(SocialTypeEnum.GITEE.getSource()))).thenReturn(authRequest);
|
||||
|
@ -139,9 +143,9 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||
when(authRequest.login(any(AuthCallback.class))).thenReturn(authResponse);
|
||||
|
||||
// 调用
|
||||
SocialUserDO result = socialUserService.authSocialUser(type, code, state);
|
||||
SocialUserDO result = socialUserService.authSocialUser(socialType, userType, code, state);
|
||||
// 断言
|
||||
assertBindSocialUser(type, result, authResponse.getData());
|
||||
assertBindSocialUser(socialType, result, authResponse.getData());
|
||||
assertEquals(code, result.getCode());
|
||||
assertEquals(state, result.getState());
|
||||
}
|
||||
|
@ -183,9 +187,9 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||
// 准备参数
|
||||
SocialUserBindReqDTO reqDTO = new SocialUserBindReqDTO()
|
||||
.setUserId(1L).setUserType(UserTypeEnum.ADMIN.getValue())
|
||||
.setType(SocialTypeEnum.GITEE.getType()).setCode("test_code").setState("test_state");
|
||||
.setSocialType(SocialTypeEnum.GITEE.getType()).setCode("test_code").setState("test_state");
|
||||
// mock 数据:获得社交用户
|
||||
SocialUserDO socialUser = randomPojo(SocialUserDO.class).setType(reqDTO.getType())
|
||||
SocialUserDO socialUser = randomPojo(SocialUserDO.class).setType(reqDTO.getSocialType())
|
||||
.setCode(reqDTO.getCode()).setState(reqDTO.getState());
|
||||
socialUserMapper.insert(socialUser);
|
||||
// mock 数据:用户可能之前已经绑定过该社交类型
|
||||
|
|
Loading…
Reference in New Issue