diff --git a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/collection/CollectionUtils.java b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/collection/CollectionUtils.java index b99c32cb..a438820e 100644 --- a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/collection/CollectionUtils.java +++ b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/collection/CollectionUtils.java @@ -203,4 +203,38 @@ public class CollectionUtils extends org.springframework.util.CollectionUtils { } return list.get(0); } + + + /** + * 将新旧列表转换为差异列表 + * @param newList 新列表 + * @param oldList 旧列表 + * @param primaryKeyFunc 唯一标识获取方法 + */ + public static DiffListVO convertToDiffList(List newList, List oldList, Function primaryKeyFunc) { + DiffListVO result = new DiffListVO<>(); + // 全新增 + if (CollectionUtils.isEmptyElement(oldList)) { + return result.setAdd(newList); + } + // 全删除 + if (CollectionUtils.isEmptyElement(newList)) { + return result.setDel(oldList); + } + + Set newKeys = newList.stream().map(primaryKeyFunc).collect(Collectors.toSet()); + Set oldKeys = oldList.stream().map(primaryKeyFunc).collect(Collectors.toSet()); + + // 不在旧列表则为新增 + List addList = newList.stream().filter(item -> !oldKeys.contains(primaryKeyFunc.apply(item))).filter(Objects::nonNull).collect(Collectors.toList()); + result.setAdd(addList); + // 不在新列表则为删除 + List delList = oldList.stream().filter(item -> !newKeys.contains(primaryKeyFunc.apply(item))).filter(Objects::nonNull).collect(Collectors.toList()); + result.setDel(delList); + // 在新列表,又在旧列表,则为更新 + List updateList = newList.stream().filter(item -> oldKeys.contains(primaryKeyFunc.apply(item))).filter(Objects::nonNull).collect(Collectors.toList()); + result.setUpdate(updateList); + + return result; + } } diff --git a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/collection/DiffListVO.java b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/collection/DiffListVO.java new file mode 100644 index 00000000..53523ba0 --- /dev/null +++ b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/collection/DiffListVO.java @@ -0,0 +1,39 @@ +package com.ruoyi.common.utils.collection; + +import lombok.Data; + +import java.util.List; + +/** + * 新旧差异列表 + * @author wjh + * 2024/11/2 + */ +@Data +public class DiffListVO { + List addList; + List updateList; + List delList; + + public DiffListVO setAdd(List list) { + this.addList = list; + return this; + } + public DiffListVO setUpdate(List list) { + this.updateList = list; + return this; + } + public DiffListVO setDel(List list) { + this.delList = list; + return this; + } + public int getAddCount() { + return CollectionUtils.isEmptyElement(addList) ? 0 : addList.size(); + } + public int getUpdateCount() { + return CollectionUtils.isEmptyElement(updateList) ? 0 : updateList.size(); + } + public int getDelCount() { + return CollectionUtils.isEmptyElement(delList) ? 0 : delList.size(); + } +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/domain/VipVO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/domain/VipVO.java index 02411ed4..315f9db4 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/domain/VipVO.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/domain/VipVO.java @@ -1,5 +1,9 @@ package com.ruoyi.ss.vip.domain; +import java.util.List; + +import com.ruoyi.ss.store.domain.StoreVo; + import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -13,9 +17,6 @@ public class VipVO extends Vip{ @ApiModelProperty("用户名称") private String userName; - @ApiModelProperty("店铺名称") - private String storeName; - @ApiModelProperty("VIP等级名称") private String vipLevelName; @@ -24,4 +25,7 @@ public class VipVO extends Vip{ @ApiModelProperty("VIP商户ID") private Long vipMchId; + + @ApiModelProperty("店铺列表") + private List storeList; } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/mapper/VipMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/mapper/VipMapper.xml index 251755ef..6a9ec14b 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/mapper/VipMapper.xml +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/mapper/VipMapper.xml @@ -4,7 +4,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + + + select @@ -15,7 +17,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" sv.start_time, sv.end_time, sv.discount, - sv.store_ids + sv.store_ids, if(su.is_real, su.real_name, su.user_name) as user_name, svl.name as vip_level_name, svl.mch_id as vip_mch_id @@ -33,7 +35,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and sv.discount = #{query.discount} and sv.store_ids = #{query.storeIds} and if(su.is_real, su.real_name, su.user_name) like concat('%',#{query.userName},'%') - and ss.name like concat('%',#{query.storeName},'%') and svl.name like concat('%',#{query.vipLevelName},'%') and sv.id != #{query.excludeId} @@ -68,17 +69,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" insert into ss_vip user_id, - store_id, level_id, - expire_time, create_time, + start_time, + end_time, + discount, + store_ids, #{userId}, - #{storeId}, #{levelId}, - #{expireTime}, #{createTime}, + #{startTime}, + #{endTime}, + #{discount}, + #{storeIds, typeHandler=com.ruoyi.system.mapper.typehandler.LongSplitListTypeHandler}, @@ -92,10 +97,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" user_id = #{data.userId}, - store_id = #{data.storeId}, level_id = #{data.levelId}, - expire_time = #{data.expireTime}, create_time = #{data.createTime}, + start_time = #{data.startTime}, + end_time = #{data.endTime}, + discount = #{data.discount}, + store_ids = #{data.storeIds, typeHandler=com.ruoyi.system.mapper.typehandler.LongSplitListTypeHandler}, diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/VipAssembler.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/VipAssembler.java new file mode 100644 index 00000000..40f84a02 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/VipAssembler.java @@ -0,0 +1,16 @@ +package com.ruoyi.ss.vip.service; + +import com.ruoyi.ss.vip.domain.VipVO; + +import java.util.List; + +/** + * @author wjh + * 2025/1/16 + */ +public interface VipAssembler { + + // 拼接店铺信息 + void assembleStoreList(List list); + +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipAssemblerImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipAssemblerImpl.java new file mode 100644 index 00000000..6ea752ca --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipAssemblerImpl.java @@ -0,0 +1,38 @@ +package com.ruoyi.ss.vip.service.impl; + +import com.ruoyi.common.utils.collection.CollectionUtils; +import com.ruoyi.ss.store.domain.StoreVo; +import com.ruoyi.ss.store.service.StoreService; +import com.ruoyi.ss.vip.domain.VipVO; +import com.ruoyi.ss.vip.service.VipAssembler; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class VipAssemblerImpl implements VipAssembler { + + @Autowired + private StoreService storeService; + + @Override + public void assembleStoreList(List list) { + if (CollectionUtils.isEmptyElement(list)) { + return; + } + + List storeIds = list.stream().map(VipVO::getStoreIds).flatMap(Collection::stream).collect(Collectors.toList()); + List storeList = storeService.selectStoreByIds(storeIds); + + for (VipVO vip : list) { + List vipStoreList = storeList.stream() + .filter(store -> vip.getStoreIds().contains(store.getStoreId())) + .collect(Collectors.toList()); + vip.setStoreList(vipStoreList); + } + } + +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipValidatorImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipValidatorImpl.java index 59d7c1d5..0868cd15 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipValidatorImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipValidatorImpl.java @@ -1,5 +1,10 @@ package com.ruoyi.ss.vip.service.impl; +import java.util.Objects; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + import com.ruoyi.common.utils.ServiceUtil; import com.ruoyi.ss.store.service.StoreValidator; import com.ruoyi.ss.user.service.UserValidator; @@ -8,10 +13,6 @@ import com.ruoyi.ss.vip.domain.VipQuery; import com.ruoyi.ss.vip.domain.VipVO; import com.ruoyi.ss.vip.service.VipService; import com.ruoyi.ss.vip.service.VipValidator; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.Objects; /** * @author wjh @@ -38,7 +39,6 @@ public class VipValidatorImpl implements VipValidator { public void beforeCheck(Vip data) { ServiceUtil.assertion(data == null, "参数错误"); - this.checkRepeatUserStore(data.getId(), data.getUserId(), data.getStoreId()); } @@ -47,7 +47,6 @@ public class VipValidatorImpl implements VipValidator { if (vo == null) { return; } - this.checkRepeatUserStore(vo.getId(), vo.getUserId(), vo.getStoreId()); this.checkMch(vo.getStoreMchId(), vo.getVipMchId()); } @@ -67,13 +66,12 @@ public class VipValidatorImpl implements VipValidator { * @param userId 用户ID * @param storeId 店铺ID */ - private void checkRepeatUserStore(Long id, Long userId, Long storeId) { - if (userId == null || storeId == null) { + private void checkRepeatUserStore(Long id, Long userId) { + if (userId == null) { return; } VipQuery query = new VipQuery(); query.setUserId(userId); - query.setStoreId(storeId); query.setExcludeId(id); ServiceUtil.assertion(vipService.selectCount(query) > 0, "当前用户已经是店铺VIP,无法重复绑定");; } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/domain/VipLevel.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/domain/VipLevel.java index 525a989f..73f9ad43 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/domain/VipLevel.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/domain/VipLevel.java @@ -49,18 +49,6 @@ public class VipLevel extends BaseEntity @Size(max = 1000, message = "描述文本长度不能超过1000个字符") private String description; - @Excel(name = "价格") - @ApiModelProperty("价格") - @NotNull(message = "价格不允许为空", groups = {ValidGroup.Create.class, ValidGroup.FrontCreate.class}) - @Min(value = 0, message = "价格不允许小于0") - private BigDecimal price; - - @Excel(name = "时长(天)") - @ApiModelProperty("时长(天)") - @NotNull(message = "时长不允许为空", groups = {ValidGroup.Create.class, ValidGroup.FrontCreate.class}) - @Min(value = 0, message = "时长不允许小于0天") - private Long time; - @Excel(name = "可用店铺ID列表") @ApiModelProperty("可用店铺ID列表") @NotNull(message = "可用店铺ID列表不允许为空", groups = {ValidGroup.Create.class, ValidGroup.FrontCreate.class}) diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/domain/VipLevelVO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/domain/VipLevelVO.java index 69754b5a..9a0283aa 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/domain/VipLevelVO.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/domain/VipLevelVO.java @@ -1,8 +1,14 @@ package com.ruoyi.ss.vipLevel.domain; +import com.ruoyi.ss.store.domain.StoreVo; +import com.ruoyi.ss.vipLevelSku.domain.VipLevelSkuVO; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import javax.validation.Valid; +import javax.validation.constraints.Size; +import java.util.List; + /** * @author wjh * 2024/12/9 @@ -13,4 +19,12 @@ public class VipLevelVO extends VipLevel{ @ApiModelProperty("商户名称") private String mchName; + @ApiModelProperty("店铺列表") + private List storeList; + + @ApiModelProperty("SKU列表") + @Size(min = 1, message = "SKU列表不能为空") + @Valid + private List skuList; + } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/mapper/VipLevelMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/mapper/VipLevelMapper.xml index 34a637fb..d52d5692 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/mapper/VipLevelMapper.xml +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/mapper/VipLevelMapper.xml @@ -4,7 +4,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + + + select @@ -14,10 +16,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" svl.discount, svl.create_time, svl.description, - svl.price, - svl.time, svl.store_ids, - svl.status + svl.status, if (mch.is_real, mch.real_name, mch.user_name) as mch_name from ss_vip_level svl left join sm_user mch on mch.user_id = svl.mch_id @@ -56,14 +56,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" insert into ss_vip_level mch_id, - name, + `name`, discount, create_time, - description, - price, - time, + `description`, store_ids, - status, + `status`, #{mchId}, @@ -71,9 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{discount}, #{createTime}, #{description}, - #{price}, - #{time}, - #{storeIds}, + #{storeIds, typeHandler=com.ruoyi.system.mapper.typehandler.LongSplitListTypeHandler}, #{status}, @@ -88,14 +84,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" mch_id = #{data.mchId}, - name = #{data.name}, + `name` = #{data.name}, discount = #{data.discount}, create_time = #{data.createTime}, - description = #{data.description}, - price = #{data.price}, - time = #{data.time}, - store_ids = #{data.storeIds}, - status = #{data.status}, + `description` = #{data.description}, + store_ids = #{data.storeIds, typeHandler=com.ruoyi.system.mapper.typehandler.LongSplitListTypeHandler}, + `status` = #{data.status}, diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/VipLevelAssembler.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/VipLevelAssembler.java new file mode 100644 index 00000000..b4d429aa --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/VipLevelAssembler.java @@ -0,0 +1,12 @@ +package com.ruoyi.ss.vipLevel.service; + +import com.ruoyi.ss.vipLevel.domain.VipLevelVO; + +import java.util.List; + +public interface VipLevelAssembler { + + void assembleStoreList(List list); + + void assembleSkuList(List list); +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/VipLevelConverter.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/VipLevelConverter.java new file mode 100644 index 00000000..c8cb0b53 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/VipLevelConverter.java @@ -0,0 +1,9 @@ +package com.ruoyi.ss.vipLevel.service; + +/** + * @author wjh + * 2025/1/16 + */ +public interface VipLevelConverter { + +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/VipLevelService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/VipLevelService.java index 88458e39..a66a4ba4 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/VipLevelService.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/VipLevelService.java @@ -1,9 +1,9 @@ package com.ruoyi.ss.vipLevel.service; -import java.util.List; -import com.ruoyi.ss.vipLevel.domain.VipLevel; -import com.ruoyi.ss.vipLevel.domain.VipLevelVO; import com.ruoyi.ss.vipLevel.domain.VipLevelQuery; +import com.ruoyi.ss.vipLevel.domain.VipLevelVO; + +import java.util.List; /** * 会员等级Service接口 @@ -35,7 +35,7 @@ public interface VipLevelService * @param vipLevel 会员等级 * @return 结果 */ - public int insertVipLevel(VipLevel vipLevel); + public int insertVipLevel(VipLevelVO vipLevel); /** * 修改会员等级 @@ -43,7 +43,7 @@ public interface VipLevelService * @param vipLevel 会员等级 * @return 结果 */ - public int updateVipLevel(VipLevel vipLevel); + public int updateVipLevel(VipLevelVO vipLevel); /** * 批量删除会员等级 diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/impl/VipLevelAssemblerImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/impl/VipLevelAssemblerImpl.java new file mode 100644 index 00000000..490d6363 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/impl/VipLevelAssemblerImpl.java @@ -0,0 +1,65 @@ +package com.ruoyi.ss.vipLevel.service.impl; + +import com.ruoyi.common.utils.collection.CollectionUtils; +import com.ruoyi.ss.store.domain.StoreVo; +import com.ruoyi.ss.store.service.StoreService; +import com.ruoyi.ss.vipLevel.domain.VipLevelVO; +import com.ruoyi.ss.vipLevel.service.VipLevelAssembler; +import com.ruoyi.ss.vipLevelSku.domain.VipLevelSkuVO; +import com.ruoyi.ss.vipLevelSku.service.VipLevelSkuService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Service +public class VipLevelAssemblerImpl implements VipLevelAssembler { + + @Autowired + private StoreService storeService; + + @Autowired + private VipLevelSkuService vipLevelSkuService; + + @Override + public void assembleStoreList(List list) { + if (CollectionUtils.isEmptyElement(list)) { + return; + } + + List storeIds = list.stream().map(VipLevelVO::getStoreIds).flatMap(Collection::stream).collect(Collectors.toList()); + List storeList = storeService.selectStoreByIds(storeIds); + + for (VipLevelVO vipLevel : list) { + List vipLevelStoreList = storeList.stream() + .filter(store -> vipLevel.getStoreIds().contains(store.getStoreId())) + .collect(Collectors.toList()); + vipLevel.setStoreList(vipLevelStoreList); + } + } + + @Override + public void assembleSkuList(List list) { + if (CollectionUtils.isEmptyElement(list)) { + return; + } + + List levelIds = list.stream().map(VipLevelVO::getId).collect(Collectors.toList()); + + Map> group = vipLevelSkuService.selectByLevelIds(levelIds) + .stream().collect(Collectors.groupingBy(VipLevelSkuVO::getLevelId)); + + + for (VipLevelVO vipLevel : list) { + List vipLevelSkuList = group.get(vipLevel.getId()); + if (vipLevelSkuList == null) { + vipLevelSkuList = Collections.emptyList(); + } + vipLevel.setSkuList(vipLevelSkuList); + } + } +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/impl/VipLevelConverterImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/impl/VipLevelConverterImpl.java new file mode 100644 index 00000000..7d5980e9 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/impl/VipLevelConverterImpl.java @@ -0,0 +1,12 @@ +package com.ruoyi.ss.vipLevel.service.impl; + +import com.ruoyi.ss.vipLevel.service.VipLevelConverter; +import org.springframework.stereotype.Service; + +/** + * @author wjh + * 2025/1/16 + */ +@Service +public class VipLevelConverterImpl implements VipLevelConverter { +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/impl/VipLevelServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/impl/VipLevelServiceImpl.java index b8562a14..fff955ed 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/impl/VipLevelServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/service/impl/VipLevelServiceImpl.java @@ -1,17 +1,21 @@ package com.ruoyi.ss.vipLevel.service.impl; +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.collection.CollectionUtils; +import com.ruoyi.common.utils.collection.DiffListVO; +import com.ruoyi.ss.vipLevel.domain.VipLevelQuery; +import com.ruoyi.ss.vipLevel.domain.VipLevelVO; +import com.ruoyi.ss.vipLevel.mapper.VipLevelMapper; +import com.ruoyi.ss.vipLevel.service.VipLevelService; +import com.ruoyi.ss.vipLevel.service.VipLevelValidator; +import com.ruoyi.ss.vipLevelSku.domain.VipLevelSkuVO; +import com.ruoyi.ss.vipLevelSku.service.VipLevelSkuService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.support.TransactionTemplate; + import java.util.Collections; import java.util.List; -import com.ruoyi.common.utils.DateUtils; -import com.ruoyi.common.utils.collection.CollectionUtils; -import com.ruoyi.ss.vipLevel.service.VipLevelValidator; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import com.ruoyi.ss.vipLevel.mapper.VipLevelMapper; -import com.ruoyi.ss.vipLevel.domain.VipLevel; -import com.ruoyi.ss.vipLevel.domain.VipLevelVO; -import com.ruoyi.ss.vipLevel.domain.VipLevelQuery; -import com.ruoyi.ss.vipLevel.service.VipLevelService; /** * 会员等级Service业务层处理 @@ -28,6 +32,12 @@ public class VipLevelServiceImpl implements VipLevelService @Autowired private VipLevelValidator vipLevelValidator; + @Autowired + private VipLevelSkuService vipLevelSkuService; + + @Autowired + private TransactionTemplate transactionTemplate; + /** * 查询会员等级 * @@ -59,10 +69,22 @@ public class VipLevelServiceImpl implements VipLevelService * @return 结果 */ @Override - public int insertVipLevel(VipLevel vipLevel) - { - vipLevel.setCreateTime(DateUtils.getNowDate()); - return vipLevelMapper.insertVipLevel(vipLevel); + public int insertVipLevel(VipLevelVO vipLevel) { + + Integer result = transactionTemplate.execute(status -> { + // 主表 + vipLevel.setCreateTime(DateUtils.getNowDate()); + int insert = vipLevelMapper.insertVipLevel(vipLevel); + + if (insert == 1) { + // SKU表 + this.batchUpdateSku(vipLevel); + } + + return insert; + }); + + return result == null ? 0 : result; } /** @@ -72,9 +94,48 @@ public class VipLevelServiceImpl implements VipLevelService * @return 结果 */ @Override - public int updateVipLevel(VipLevel vipLevel) - { - return vipLevelMapper.updateVipLevel(vipLevel); + public int updateVipLevel(VipLevelVO vipLevel) { + Integer result = transactionTemplate.execute(status -> { + // 主表 + int update = vipLevelMapper.updateVipLevel(vipLevel); + + if (update == 1) { + // SKU表 + this.batchUpdateSku(vipLevel); + } + + return update; + }); + + return result == null ? 0 : result; + } + + private int batchUpdateSku(VipLevelVO level) { + if (level == null) { + return 0; + } + // 分离出新旧数据 + List newList = level.getSkuList(); + if (CollectionUtils.isNotEmptyElement(newList)) { + for (VipLevelSkuVO sku : newList) { + sku.setLevelId(level.getId()); + } + } + List oldList = vipLevelSkuService.selectByLevelId(level.getId()); + DiffListVO diff = CollectionUtils.convertToDiffList(newList, oldList, VipLevelSkuVO::getId); + + int result = 0; + if (diff.getAddCount() > 0) { + result += vipLevelSkuService.batchInsert(diff.getAddList()); + } + if (diff.getUpdateCount() > 0) { + result += vipLevelSkuService.batchUpdate(diff.getAddList()); + } + if (diff.getDelCount() > 0) { + result += vipLevelSkuService.deleteVipLevelSkuByIds(CollectionUtils.map(diff.getDelList(), VipLevelSkuVO::getId)); + } + + return result; } /** diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/domain/VipLevelSku.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/domain/VipLevelSku.java new file mode 100644 index 00000000..c0690739 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/domain/VipLevelSku.java @@ -0,0 +1,35 @@ +package com.ruoyi.ss.vipLevelSku.domain; + +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * VIP等级定价对象 ss_vip_level_sku + * + * @author ruoyi + * @date 2025-01-16 + */ +@Data +public class VipLevelSku extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + private Long id; + + @Excel(name = "VIP等级ID") + @ApiModelProperty("VIP等级ID") + private Long levelId; + + @Excel(name = "价格") + @ApiModelProperty("价格") + private BigDecimal price; + + @Excel(name = "时长(天)") + @ApiModelProperty("时长(天)") + private Integer time; + +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/domain/VipLevelSkuQuery.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/domain/VipLevelSkuQuery.java new file mode 100644 index 00000000..524103c9 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/domain/VipLevelSkuQuery.java @@ -0,0 +1,18 @@ +package com.ruoyi.ss.vipLevelSku.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author wjh + * 2025/1/16 + */ +@Data +public class VipLevelSkuQuery extends VipLevelSkuVO{ + + @ApiModelProperty("等级ID列表") + private List levelIds; + +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/domain/VipLevelSkuVO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/domain/VipLevelSkuVO.java new file mode 100644 index 00000000..a7383251 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/domain/VipLevelSkuVO.java @@ -0,0 +1,11 @@ +package com.ruoyi.ss.vipLevelSku.domain; + +import lombok.Data; + +/** + * @author wjh + * 2025/1/16 + */ +@Data +public class VipLevelSkuVO extends VipLevelSku { +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/mapper/VipLevelSkuMapper.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/mapper/VipLevelSkuMapper.java new file mode 100644 index 00000000..55ed1823 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/mapper/VipLevelSkuMapper.java @@ -0,0 +1,68 @@ +package com.ruoyi.ss.vipLevelSku.mapper; + +import com.ruoyi.ss.vipLevelSku.domain.VipLevelSku; +import com.ruoyi.ss.vipLevelSku.domain.VipLevelSkuQuery; +import com.ruoyi.ss.vipLevelSku.domain.VipLevelSkuVO; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * VIP等级定价Mapper接口 + * + * @author ruoyi + * @date 2025-01-16 + */ +public interface VipLevelSkuMapper +{ + /** + * 查询VIP等级定价 + * + * @param id VIP等级定价主键 + * @return VIP等级定价 + */ + VipLevelSkuVO selectVipLevelSkuById(Long id); + + /** + * 查询VIP等级定价列表 + * + * @param query VIP等级定价 + * @return VIP等级定价集合 + */ + List selectVipLevelSkuList(@Param("query")VipLevelSkuQuery query); + + /** + * 新增VIP等级定价 + * + * @param vipLevelSku VIP等级定价 + * @return 结果 + */ + int insertVipLevelSku(VipLevelSku vipLevelSku); + + /** + * 修改VIP等级定价 + * + * @param vipLevelSku VIP等级定价 + * @return 结果 + */ + public int updateVipLevelSku(@Param("data") VipLevelSku vipLevelSku); + + /** + * 删除VIP等级定价 + * + * @param id VIP等级定价主键 + * @return 结果 + */ + int deleteVipLevelSkuById(Long id); + + /** + * 批量删除VIP等级定价 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteVipLevelSkuByIds(@Param("ids") List ids); + + int batchInsert(@Param("list") List list); + int batchUpdate(@Param("list") List list); +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/mapper/VipLevelSkuMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/mapper/VipLevelSkuMapper.xml new file mode 100644 index 00000000..2b806a27 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/mapper/VipLevelSkuMapper.xml @@ -0,0 +1,176 @@ + + + + + + + + select + svls.id, + svls.level_id, + svls.price, + svls.time, + svls.create_time, + svls.update_time + from ss_vip_level_sku svls + + + + and svls.id = #{query.id} + and svls.level_id = #{query.levelId} + + and svls.level_id in + + #{item} + + + ${query.params.dataScope} + + + + + + + + insert into ss_vip_level_sku + + id, + level_id, + price, + `time`, + create_time, + update_time, + + + #{id}, + #{levelId}, + #{price}, + #{time}, + #{createTime}, + #{updateTime}, + + + + + insert into ss_vip_level_sku + + level_id, + price, + `time`, + create_time, + update_time, + + values + + + #{i.levelId}, + default, + #{i.price}, + default, + #{i.time}, + default, + #{i.createTime}, + default, + #{i.updateTime}, + default, + + + + + + update ss_vip_level_sku + + + + + WHEN #{item.id} THEN #{item.levelId} + + + WHEN #{item.id} THEN `level_id` + + + + + + + WHEN #{item.id} THEN #{item.price} + + + WHEN #{item.id} THEN `price` + + + + + + + WHEN #{item.id} THEN #{item.time} + + + WHEN #{item.id} THEN `time` + + + + + + + WHEN #{item.id} THEN #{item.createTime} + + + WHEN #{item.id} THEN `create_time` + + + + + + + WHEN #{item.id} THEN #{item.updateTime} + + + WHEN #{item.id} THEN `update_time` + + + + + where id in + + #{item.id} + + + + + update ss_vip_level_sku + + + + where id = #{data.id} + + + + level_id = #{data.levelId}, + price = #{data.price}, + time = #{data.time}, + create_time = #{data.createTime}, + update_time = #{data.updateTime}, + + + + delete from ss_vip_level_sku where id = #{id} + + + + delete from ss_vip_level_sku where id in + + #{id} + + + diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/service/VipLevelSkuService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/service/VipLevelSkuService.java new file mode 100644 index 00000000..5e79c026 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/service/VipLevelSkuService.java @@ -0,0 +1,82 @@ +package com.ruoyi.ss.vipLevelSku.service; + +import com.ruoyi.ss.vipLevelSku.domain.VipLevelSku; +import com.ruoyi.ss.vipLevelSku.domain.VipLevelSkuQuery; +import com.ruoyi.ss.vipLevelSku.domain.VipLevelSkuVO; + +import java.util.List; + +/** + * VIP等级定价Service接口 + * + * @author ruoyi + * @date 2025-01-16 + */ +public interface VipLevelSkuService +{ + /** + * 查询VIP等级定价 + * + * @param id VIP等级定价主键 + * @return VIP等级定价 + */ + public VipLevelSkuVO selectVipLevelSkuById(Long id); + + /** + * 查询VIP等级定价列表 + * + * @param vipLevelSku VIP等级定价 + * @return VIP等级定价集合 + */ + public List selectVipLevelSkuList(VipLevelSkuQuery vipLevelSku); + + /** + * 新增VIP等级定价 + * + * @param vipLevelSku VIP等级定价 + * @return 结果 + */ + public int insertVipLevelSku(VipLevelSku vipLevelSku); + + /** + * 修改VIP等级定价 + * + * @param vipLevelSku VIP等级定价 + * @return 结果 + */ + public int updateVipLevelSku(VipLevelSku vipLevelSku); + + /** + * 批量删除VIP等级定价 + * + * @param ids 需要删除的VIP等级定价主键集合 + * @return 结果 + */ + public int deleteVipLevelSkuByIds(List ids); + + /** + * 删除VIP等级定价信息 + * + * @param id VIP等级定价主键 + * @return 结果 + */ + public int deleteVipLevelSkuById(Long id); + + /** + * 根据等级id查询 + * @param levelId + * @return + */ + List selectByLevelId(Long levelId); + + int batchInsert(List list); + + int batchUpdate(List list); + + /** + * 根据等级id查询 + * @param levelIds + * @return + */ + List selectByLevelIds(List levelIds); +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/service/impl/VipLevelSkuServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/service/impl/VipLevelSkuServiceImpl.java new file mode 100644 index 00000000..2d805ccf --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/service/impl/VipLevelSkuServiceImpl.java @@ -0,0 +1,146 @@ +package com.ruoyi.ss.vipLevelSku.service.impl; + +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.collection.CollectionUtils; +import com.ruoyi.ss.vipLevelSku.domain.VipLevelSku; +import com.ruoyi.ss.vipLevelSku.domain.VipLevelSkuQuery; +import com.ruoyi.ss.vipLevelSku.domain.VipLevelSkuVO; +import com.ruoyi.ss.vipLevelSku.mapper.VipLevelSkuMapper; +import com.ruoyi.ss.vipLevelSku.service.VipLevelSkuService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Collections; +import java.util.Date; +import java.util.List; + +/** + * VIP等级定价Service业务层处理 + * + * @author ruoyi + * @date 2025-01-16 + */ +@Service +public class VipLevelSkuServiceImpl implements VipLevelSkuService +{ + @Autowired + private VipLevelSkuMapper vipLevelSkuMapper; + + /** + * 查询VIP等级定价 + * + * @param id VIP等级定价主键 + * @return VIP等级定价 + */ + @Override + public VipLevelSkuVO selectVipLevelSkuById(Long id) + { + return vipLevelSkuMapper.selectVipLevelSkuById(id); + } + + /** + * 查询VIP等级定价列表 + * + * @param vipLevelSku VIP等级定价 + * @return VIP等级定价 + */ + @Override + public List selectVipLevelSkuList(VipLevelSkuQuery vipLevelSku) + { + return vipLevelSkuMapper.selectVipLevelSkuList(vipLevelSku); + } + + /** + * 新增VIP等级定价 + * + * @param vipLevelSku VIP等级定价 + * @return 结果 + */ + @Override + public int insertVipLevelSku(VipLevelSku vipLevelSku) + { + vipLevelSku.setCreateTime(DateUtils.getNowDate()); + return vipLevelSkuMapper.insertVipLevelSku(vipLevelSku); + } + + /** + * 修改VIP等级定价 + * + * @param vipLevelSku VIP等级定价 + * @return 结果 + */ + @Override + public int updateVipLevelSku(VipLevelSku vipLevelSku) + { + vipLevelSku.setUpdateTime(DateUtils.getNowDate()); + return vipLevelSkuMapper.updateVipLevelSku(vipLevelSku); + } + + /** + * 批量删除VIP等级定价 + * + * @param ids 需要删除的VIP等级定价主键 + * @return 结果 + */ + @Override + public int deleteVipLevelSkuByIds(List ids) + { + return vipLevelSkuMapper.deleteVipLevelSkuByIds(ids); + } + + /** + * 删除VIP等级定价信息 + * + * @param id VIP等级定价主键 + * @return 结果 + */ + @Override + public int deleteVipLevelSkuById(Long id) + { + return vipLevelSkuMapper.deleteVipLevelSkuById(id); + } + + @Override + public List selectByLevelId(Long levelId) { + if (levelId == null) { + return Collections.emptyList(); + } + VipLevelSkuQuery query = new VipLevelSkuQuery(); + query.setLevelId(levelId); + return vipLevelSkuMapper.selectVipLevelSkuList(query); + } + + @Override + public int batchInsert(List list) { + if (CollectionUtils.isEmptyElement(list)) { + return 0; + } + Date now = DateUtils.getNowDate(); + for (VipLevelSku sku : list) { + sku.setCreateTime(now); + } + return vipLevelSkuMapper.batchInsert(list); + } + + @Override + public int batchUpdate(List list) { + if (CollectionUtils.isEmptyElement(list)) { + return 0; + } + Date now = DateUtils.getNowDate(); + for (VipLevelSku sku : list) { + sku.setUpdateTime(now); + } + return vipLevelSkuMapper.batchUpdate(list); + } + + @Override + public List selectByLevelIds(List levelIds) { + if (CollectionUtils.isEmptyElement(levelIds)) { + return Collections.emptyList(); + } + VipLevelSkuQuery query = new VipLevelSkuQuery(); + query.setLevelIds(levelIds); + return vipLevelSkuMapper.selectVipLevelSkuList(query); + } +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrder.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrder.java new file mode 100644 index 00000000..0f94d00a --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrder.java @@ -0,0 +1,90 @@ +package com.ruoyi.ss.vipOrder.domain; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; +import org.springframework.format.annotation.DateTimeFormat; + +/** + * 会员订单对象 ss_vip_order + * + * @author ruoyi + * @date 2025-01-16 + */ +@Data +public class VipOrder extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + private Long id; + + @Excel(name = "订单编号") + @ApiModelProperty("订单编号") + private String orderNo; + + @Excel(name = "用户ID") + @ApiModelProperty("用户ID") + private Long userId; + + @Excel(name = "商户ID") + @ApiModelProperty("商户ID") + private Long mchId; + + @Excel(name = "VIP等级ID") + @ApiModelProperty("VIP等级ID") + private Long levelId; + + @Excel(name = "下单时的等级名称") + @ApiModelProperty("下单时的等级名称") + private String levelName; + + @Excel(name = "下单时的折扣") + @ApiModelProperty("下单时的折扣") + private BigDecimal levelDiscount; + + @Excel(name = "下单时的可用店铺列表") + @ApiModelProperty("下单时的可用店铺列表") + private String levelStoreIds; + + @Excel(name = "VIP定价ID") + @ApiModelProperty("VIP定价ID") + private Long skuId; + + @Excel(name = "下单时的购买时长(天)") + @ApiModelProperty("下单时的购买时长(天)") + private Long skuTime; + + @Excel(name = "订单金额") + @ApiModelProperty("订单金额") + private BigDecimal amount; + + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "订单过期时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty("订单过期时间") + private LocalDateTime expireTime; + + @Excel(name = "支付订单ID") + @ApiModelProperty("支付订单ID") + private Long payId; + + @Excel(name = "订单状态", readConverterExp = "1=待支付,2=支付成功,3=已取消") + @ApiModelProperty("订单状态") + private String status; + + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "取消时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty("取消时间") + private LocalDateTime cancelTime; + + @Excel(name = "取消原因") + @ApiModelProperty("取消原因") + private String cancelReason; + +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrderQuery.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrderQuery.java new file mode 100644 index 00000000..538d37cc --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrderQuery.java @@ -0,0 +1,11 @@ +package com.ruoyi.ss.vipOrder.domain; + +import lombok.Data; + +/** + * @author wjh + * 2025/1/16 + */ +@Data +public class VipOrderQuery extends VipOrderVO{ +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrderVO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrderVO.java new file mode 100644 index 00000000..16bbc2a1 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrderVO.java @@ -0,0 +1,21 @@ +package com.ruoyi.ss.vipOrder.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * @author wjh + * 2025/1/16 + */ +@Data +public class VipOrderVO extends VipOrder{ + + + @ApiModelProperty("支付渠道名称") + private String channelName; + + @ApiModelProperty("支付时间") + private LocalDateTime payTime; +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/mapper/VipOrderMapper.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/mapper/VipOrderMapper.java new file mode 100644 index 00000000..1591946b --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/mapper/VipOrderMapper.java @@ -0,0 +1,64 @@ +package com.ruoyi.ss.vipOrder.mapper; + +import java.util.List; +import com.ruoyi.ss.vipOrder.domain.VipOrder; +import com.ruoyi.ss.vipOrder.domain.VipOrderVO; +import com.ruoyi.ss.vipOrder.domain.VipOrderQuery; +import org.apache.ibatis.annotations.Param; + +/** + * 会员订单Mapper接口 + * + * @author ruoyi + * @date 2025-01-16 + */ +public interface VipOrderMapper +{ + /** + * 查询会员订单 + * + * @param id 会员订单主键 + * @return 会员订单 + */ + VipOrderVO selectVipOrderById(Long id); + + /** + * 查询会员订单列表 + * + * @param query 会员订单 + * @return 会员订单集合 + */ + List selectVipOrderList(@Param("query")VipOrderQuery query); + + /** + * 新增会员订单 + * + * @param vipOrder 会员订单 + * @return 结果 + */ + int insertVipOrder(VipOrder vipOrder); + + /** + * 修改会员订单 + * + * @param vipOrder 会员订单 + * @return 结果 + */ + public int updateVipOrder(@Param("data") VipOrder vipOrder); + + /** + * 删除会员订单 + * + * @param id 会员订单主键 + * @return 结果 + */ + int deleteVipOrderById(Long id); + + /** + * 批量删除会员订单 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteVipOrderByIds(Long[] ids); +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/mapper/VipOrderMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/mapper/VipOrderMapper.xml new file mode 100644 index 00000000..ce58f8f2 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/mapper/VipOrderMapper.xml @@ -0,0 +1,138 @@ + + + + + + + + select + svo.id, + svo.order_no, + svo.user_id, + svo.mch_id, + svo.level_id, + svo.level_name, + svo.level_discount, + svo.level_store_ids, + svo.sku_id, + svo.sku_time, + svo.amount, + svo.expire_time, + svo.pay_id, + svo.status, + svo.cancel_time, + svo.cancel_reason, + svo.create_time, + spb.pay_time as pay_time, + sc.name as channel_name + from ss_vip_order svo + left join ss_pay_bill spb on spb.pay_id = svo.pay_id + left join sm_channel sc on sc.channel_id = spb.channel_id + + + + and svo.id = #{query.id} + and svo.order_no like concat('%', #{query.orderNo}, '%') + and svo.user_id = #{query.userId} + and svo.mch_id = #{query.mchId} + and svo.level_id = #{query.levelId} + and svo.level_name like concat('%', #{query.levelName}, '%') + and svo.sku_id = #{query.skuId} + and svo.pay_id = #{query.payId} + and svo.status = #{query.status} + and svo.cancel_reason like concat('%', #{query.cancelReason}, '%') + ${query.params.dataScope} + + + + + + + + insert into ss_vip_order + + order_no, + user_id, + mch_id, + level_id, + level_name, + level_discount, + level_store_ids, + sku_id, + sku_time, + amount, + expire_time, + pay_id, + `status`, + cancel_time, + cancel_reason, + create_time, + + + #{orderNo}, + #{userId}, + #{mchId}, + #{levelId}, + #{levelName}, + #{levelDiscount}, + #{levelStoreIds}, + #{skuId}, + #{skuTime}, + #{amount}, + #{expireTime}, + #{payId}, + #{status}, + #{cancelTime}, + #{cancelReason}, + #{createTime}, + + + + + update ss_vip_order + + + + where id = #{data.id} + + + + order_no = #{data.orderNo}, + user_id = #{data.userId}, + mch_id = #{data.mchId}, + level_id = #{data.levelId}, + level_name = #{data.levelName}, + level_discount = #{data.levelDiscount}, + level_store_ids = #{data.levelStoreIds}, + sku_id = #{data.skuId}, + sku_time = #{data.skuTime}, + amount = #{data.amount}, + expire_time = #{data.expireTime}, + pay_id = #{data.payId}, + `status` = #{data.status}, + cancel_time = #{data.cancelTime}, + cancel_reason = #{data.cancelReason}, + create_time = #{data.createTime}, + + + + delete from ss_vip_order where id = #{id} + + + + delete from ss_vip_order where id in + + #{id} + + + diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/VipOrderService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/VipOrderService.java new file mode 100644 index 00000000..eeba1abe --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/VipOrderService.java @@ -0,0 +1,63 @@ +package com.ruoyi.ss.vipOrder.service; + +import java.util.List; +import com.ruoyi.ss.vipOrder.domain.VipOrder; +import com.ruoyi.ss.vipOrder.domain.VipOrderVO; +import com.ruoyi.ss.vipOrder.domain.VipOrderQuery; + +/** + * 会员订单Service接口 + * + * @author ruoyi + * @date 2025-01-16 + */ +public interface VipOrderService +{ + /** + * 查询会员订单 + * + * @param id 会员订单主键 + * @return 会员订单 + */ + public VipOrderVO selectVipOrderById(Long id); + + /** + * 查询会员订单列表 + * + * @param vipOrder 会员订单 + * @return 会员订单集合 + */ + public List selectVipOrderList(VipOrderQuery vipOrder); + + /** + * 新增会员订单 + * + * @param vipOrder 会员订单 + * @return 结果 + */ + public int insertVipOrder(VipOrder vipOrder); + + /** + * 修改会员订单 + * + * @param vipOrder 会员订单 + * @return 结果 + */ + public int updateVipOrder(VipOrder vipOrder); + + /** + * 批量删除会员订单 + * + * @param ids 需要删除的会员订单主键集合 + * @return 结果 + */ + public int deleteVipOrderByIds(Long[] ids); + + /** + * 删除会员订单信息 + * + * @param id 会员订单主键 + * @return 结果 + */ + public int deleteVipOrderById(Long id); +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/impl/VipOrderServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/impl/VipOrderServiceImpl.java new file mode 100644 index 00000000..b7820717 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/impl/VipOrderServiceImpl.java @@ -0,0 +1,97 @@ +package com.ruoyi.ss.vipOrder.service.impl; + +import java.util.List; +import com.ruoyi.common.utils.DateUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ruoyi.ss.vipOrder.mapper.VipOrderMapper; +import com.ruoyi.ss.vipOrder.domain.VipOrder; +import com.ruoyi.ss.vipOrder.domain.VipOrderVO; +import com.ruoyi.ss.vipOrder.domain.VipOrderQuery; +import com.ruoyi.ss.vipOrder.service.VipOrderService; + +/** + * 会员订单Service业务层处理 + * + * @author ruoyi + * @date 2025-01-16 + */ +@Service +public class VipOrderServiceImpl implements VipOrderService +{ + @Autowired + private VipOrderMapper vipOrderMapper; + + /** + * 查询会员订单 + * + * @param id 会员订单主键 + * @return 会员订单 + */ + @Override + public VipOrderVO selectVipOrderById(Long id) + { + return vipOrderMapper.selectVipOrderById(id); + } + + /** + * 查询会员订单列表 + * + * @param vipOrder 会员订单 + * @return 会员订单 + */ + @Override + public List selectVipOrderList(VipOrderQuery vipOrder) + { + return vipOrderMapper.selectVipOrderList(vipOrder); + } + + /** + * 新增会员订单 + * + * @param vipOrder 会员订单 + * @return 结果 + */ + @Override + public int insertVipOrder(VipOrder vipOrder) + { + vipOrder.setCreateTime(DateUtils.getNowDate()); + return vipOrderMapper.insertVipOrder(vipOrder); + } + + /** + * 修改会员订单 + * + * @param vipOrder 会员订单 + * @return 结果 + */ + @Override + public int updateVipOrder(VipOrder vipOrder) + { + return vipOrderMapper.updateVipOrder(vipOrder); + } + + /** + * 批量删除会员订单 + * + * @param ids 需要删除的会员订单主键 + * @return 结果 + */ + @Override + public int deleteVipOrderByIds(Long[] ids) + { + return vipOrderMapper.deleteVipOrderByIds(ids); + } + + /** + * 删除会员订单信息 + * + * @param id 会员订单主键 + * @return 结果 + */ + @Override + public int deleteVipOrderById(Long id) + { + return vipOrderMapper.deleteVipOrderById(id); + } +} diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/mch/MchVipLevelController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/mch/MchVipLevelController.java index 27ba24f4..49668e1e 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/mch/MchVipLevelController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/mch/MchVipLevelController.java @@ -1,12 +1,9 @@ package com.ruoyi.web.controller.mch; -import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.ValidGroup; import com.ruoyi.common.core.page.TableDataInfo; -import com.ruoyi.common.enums.BusinessType; -import com.ruoyi.ss.vipLevel.domain.VipLevel; import com.ruoyi.ss.vipLevel.domain.VipLevelQuery; import com.ruoyi.ss.vipLevel.domain.VipLevelVO; import com.ruoyi.ss.vipLevel.service.VipLevelService; @@ -54,14 +51,14 @@ public class MchVipLevelController extends BaseController { @ApiModelProperty("新增VIP等级") @PostMapping - public AjaxResult add(@RequestBody @Validated(ValidGroup.FrontCreate.class) VipLevel data) { + public AjaxResult add(@RequestBody @Validated(ValidGroup.FrontCreate.class) VipLevelVO data) { data.setMchId(getUserId()); return toAjax(vipLevelService.insertVipLevel(data)); } @ApiModelProperty("修改VIP等级") @PutMapping - public AjaxResult update(@RequestBody @Validated(ValidGroup.FrontUpdate.class) VipLevel data) { + public AjaxResult update(@RequestBody @Validated(ValidGroup.FrontUpdate.class) VipLevelVO data) { if (!vipLevelValidator.canOpera(data.getId(), getUserId())) { return error("您无权操作该数据"); } diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipController.java index 11a52856..c86de747 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipController.java @@ -1,27 +1,23 @@ package com.ruoyi.web.controller.ss; -import java.util.List; -import javax.servlet.http.HttpServletResponse; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.common.enums.BusinessType; -import com.ruoyi.ss.vip.domain.Vip; -import com.ruoyi.ss.vip.domain.VipVO; -import com.ruoyi.ss.vip.domain.VipQuery; -import com.ruoyi.ss.vip.service.VipService; -import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.ss.vip.domain.Vip; +import com.ruoyi.ss.vip.domain.VipQuery; +import com.ruoyi.ss.vip.domain.VipVO; +import com.ruoyi.ss.vip.service.VipAssembler; +import com.ruoyi.ss.vip.service.VipService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.Collections; +import java.util.List; /** * 会员Controller @@ -36,6 +32,9 @@ public class VipController extends BaseController @Autowired private VipService vipService; + @Autowired + private VipAssembler vipAssembler; + /** * 查询会员列表 */ @@ -46,6 +45,7 @@ public class VipController extends BaseController startPage(); startOrderBy(); List list = vipService.selectVipList(query); + vipAssembler.assembleStoreList(list); return getDataTable(list); } @@ -69,7 +69,10 @@ public class VipController extends BaseController @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { - return success(vipService.selectVipById(id)); + VipVO vip = vipService.selectVipById(id); + List list = Collections.singletonList(vip); + vipAssembler.assembleStoreList(list); + return success(vip); } /** diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipLevelController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipLevelController.java index b03e6997..c3917952 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipLevelController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipLevelController.java @@ -1,30 +1,24 @@ package com.ruoyi.web.controller.ss; -import java.util.List; -import javax.servlet.http.HttpServletResponse; - -import com.ruoyi.common.core.domain.ValidGroup; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.common.enums.BusinessType; -import com.ruoyi.ss.vipLevel.domain.VipLevel; -import com.ruoyi.ss.vipLevel.domain.VipLevelVO; -import com.ruoyi.ss.vipLevel.domain.VipLevelQuery; -import com.ruoyi.ss.vipLevel.service.VipLevelService; -import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.domain.ValidGroup; import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.ss.vipLevel.domain.VipLevelQuery; +import com.ruoyi.ss.vipLevel.domain.VipLevelVO; +import com.ruoyi.ss.vipLevel.service.VipLevelAssembler; +import com.ruoyi.ss.vipLevel.service.VipLevelService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.Collections; +import java.util.List; /** * 会员等级Controller @@ -39,6 +33,9 @@ public class VipLevelController extends BaseController @Autowired private VipLevelService vipLevelService; + @Autowired + private VipLevelAssembler vipLevelAssembler; + /** * 查询会员等级列表 */ @@ -49,6 +46,7 @@ public class VipLevelController extends BaseController startPage(); startOrderBy(); List list = vipLevelService.selectVipLevelList(query); + vipLevelAssembler.assembleStoreList(list); return getDataTable(list); } @@ -85,7 +83,11 @@ public class VipLevelController extends BaseController @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { - return success(vipLevelService.selectVipLevelById(id)); + VipLevelVO level = vipLevelService.selectVipLevelById(id); + List list = Collections.singletonList(level); + vipLevelAssembler.assembleStoreList(list); + vipLevelAssembler.assembleSkuList(list); + return success(level); } /** @@ -94,7 +96,7 @@ public class VipLevelController extends BaseController @PreAuthorize("@ss.hasPermi('ss:vipLevel:add')") @Log(title = "会员等级", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) VipLevel vipLevel) + public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) VipLevelVO vipLevel) { return toAjax(vipLevelService.insertVipLevel(vipLevel)); } @@ -105,7 +107,7 @@ public class VipLevelController extends BaseController @PreAuthorize("@ss.hasPermi('ss:vipLevel:edit')") @Log(title = "会员等级", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody @Validated(ValidGroup.Update.class) VipLevel vipLevel) + public AjaxResult edit(@RequestBody @Validated(ValidGroup.Update.class) VipLevelVO vipLevel) { return toAjax(vipLevelService.updateVipLevel(vipLevel)); } diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipLevelSkuController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipLevelSkuController.java new file mode 100644 index 00000000..1c992358 --- /dev/null +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipLevelSkuController.java @@ -0,0 +1,101 @@ +package com.ruoyi.web.controller.ss; + +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.ss.vipLevelSku.domain.VipLevelSku; +import com.ruoyi.ss.vipLevelSku.domain.VipLevelSkuQuery; +import com.ruoyi.ss.vipLevelSku.domain.VipLevelSkuVO; +import com.ruoyi.ss.vipLevelSku.service.VipLevelSkuService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * VIP等级定价Controller + * + * @author ruoyi + * @date 2025-01-16 + */ +@RestController +@RequestMapping("/ss/vipLevelSku") +public class VipLevelSkuController extends BaseController +{ + @Autowired + private VipLevelSkuService vipLevelSkuService; + + /** + * 查询VIP等级定价列表 + */ + @PreAuthorize("@ss.hasPermi('ss:vipLevelSku:list')") + @GetMapping("/list") + public TableDataInfo list(VipLevelSkuQuery query) + { + startPage(); + startOrderBy(); + List list = vipLevelSkuService.selectVipLevelSkuList(query); + return getDataTable(list); + } + + /** + * 导出VIP等级定价列表 + */ + @PreAuthorize("@ss.hasPermi('ss:vipLevelSku:export')") + @Log(title = "VIP等级定价", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, VipLevelSkuQuery query) + { + List list = vipLevelSkuService.selectVipLevelSkuList(query); + ExcelUtil util = new ExcelUtil(VipLevelSkuVO.class); + util.exportExcel(response, list, "VIP等级定价数据"); + } + + /** + * 获取VIP等级定价详细信息 + */ + @PreAuthorize("@ss.hasPermi('ss:vipLevelSku:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(vipLevelSkuService.selectVipLevelSkuById(id)); + } + + /** + * 新增VIP等级定价 + */ + @PreAuthorize("@ss.hasPermi('ss:vipLevelSku:add')") + @Log(title = "VIP等级定价", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody VipLevelSku vipLevelSku) + { + return toAjax(vipLevelSkuService.insertVipLevelSku(vipLevelSku)); + } + + /** + * 修改VIP等级定价 + */ + @PreAuthorize("@ss.hasPermi('ss:vipLevelSku:edit')") + @Log(title = "VIP等级定价", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody VipLevelSku vipLevelSku) + { + return toAjax(vipLevelSkuService.updateVipLevelSku(vipLevelSku)); + } + + /** + * 删除VIP等级定价 + */ + @PreAuthorize("@ss.hasPermi('ss:vipLevelSku:remove')") + @Log(title = "VIP等级定价", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable List ids) + { + return toAjax(vipLevelSkuService.deleteVipLevelSkuByIds(ids)); + } +} diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipOrderController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipOrderController.java new file mode 100644 index 00000000..918ee806 --- /dev/null +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipOrderController.java @@ -0,0 +1,107 @@ +package com.ruoyi.web.controller.ss; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.ss.vipOrder.domain.VipOrder; +import com.ruoyi.ss.vipOrder.domain.VipOrderVO; +import com.ruoyi.ss.vipOrder.domain.VipOrderQuery; +import com.ruoyi.ss.vipOrder.service.VipOrderService; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.page.TableDataInfo; + +/** + * 会员订单Controller + * + * @author ruoyi + * @date 2025-01-16 + */ +@RestController +@RequestMapping("/ss/vipOrder") +public class VipOrderController extends BaseController +{ + @Autowired + private VipOrderService vipOrderService; + + /** + * 查询会员订单列表 + */ + @PreAuthorize("@ss.hasPermi('ss:vipOrder:list')") + @GetMapping("/list") + public TableDataInfo list(VipOrderQuery query) + { + startPage(); + startOrderBy(); + List list = vipOrderService.selectVipOrderList(query); + return getDataTable(list); + } + + /** + * 导出会员订单列表 + */ + @PreAuthorize("@ss.hasPermi('ss:vipOrder:export')") + @Log(title = "会员订单", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, VipOrderQuery query) + { + List list = vipOrderService.selectVipOrderList(query); + ExcelUtil util = new ExcelUtil(VipOrderVO.class); + util.exportExcel(response, list, "会员订单数据"); + } + + /** + * 获取会员订单详细信息 + */ + @PreAuthorize("@ss.hasPermi('ss:vipOrder:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(vipOrderService.selectVipOrderById(id)); + } + + /** + * 新增会员订单 + */ + @PreAuthorize("@ss.hasPermi('ss:vipOrder:add')") + @Log(title = "会员订单", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody VipOrder vipOrder) + { + return toAjax(vipOrderService.insertVipOrder(vipOrder)); + } + + /** + * 修改会员订单 + */ + @PreAuthorize("@ss.hasPermi('ss:vipOrder:edit')") + @Log(title = "会员订单", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody VipOrder vipOrder) + { + return toAjax(vipOrderService.updateVipOrder(vipOrder)); + } + + /** + * 删除会员订单 + */ + @PreAuthorize("@ss.hasPermi('ss:vipOrder:remove')") + @Log(title = "会员订单", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(vipOrderService.deleteVipOrderByIds(ids)); + } +}