Merge branch 'feature/mall_product' of https://gitee.com/zhijiantianya/ruoyi-vue-pro

# Conflicts:
#	yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/coupon/CouponTemplateApiImpl.java
This commit is contained in:
YunaiV 2023-10-24 19:09:01 +08:00
commit 52e735f360
31 changed files with 146 additions and 282 deletions

View File

@ -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);
}
}

View File

@ -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>

View File

@ -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")

View File

@ -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;
}
}

View File

@ -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) {

View File

@ -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)) {

View File

@ -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);
}

View File

@ -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;
}

View File

@ -1,35 +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 org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
* 优惠劵模版 API 接口实现类
*
* @author HUIHUI
*/
@Service
@Validated
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));
}
}

View File

@ -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));

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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")

View File

@ -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);
}

View File

@ -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)

View File

@ -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));
}
}

View File

@ -45,6 +45,13 @@ public interface BargainActivityService {
*/
void updateBargainActivityStock(Long id, Integer count);
/**
* 关闭砍价活动
*
* @param id 砍价活动编号
*/
void closeBargainActivityById(Long id);
/**
* 删除砍价活动
*

View File

@ -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) {

View File

@ -36,7 +36,12 @@ public interface CombinationActivityService {
*/
void updateCombinationActivity(@Valid CombinationActivityUpdateReqVO updateReqVO);
// TODO @puhui999这里少了一个关闭活动的接口因为关闭的活动才可以删除
/**
* 关闭拼团活动
*
* @param id 拼团活动编号
*/
void closeCombinationActivityById(Long id);
/**
* 删除拼团活动

View File

@ -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);
}

View File

@ -98,6 +98,6 @@ public interface CouponTemplateService {
* @param ids 优惠券模版编号
* @return 优惠券模版列表
*/
List<CouponTemplateDO> getCouponTemplateListByIds(Collection<Long> ids);
List<CouponTemplateDO> getCouponTemplateList(Collection<Long> ids);
}

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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 是否在活动时间范围内

View File

@ -12,8 +12,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
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 @puhui999signInRecord=record
MemberSignInRecordDO signInRecord = new MemberSignInRecordDO().setUserId(userId)
.setDay(Integer.parseInt(Long.toString(day))) // 设置签到天数 TODO @puhui999day 应该跟着第几天签到走不是累加哈另外 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 @puhui999signInConfig 可以改成 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;
}
}

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -26,7 +26,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;
@ -140,7 +139,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;