2
0

fix: 可用套餐

This commit is contained in:
caiyuchao
2025-03-14 10:58:57 +08:00
parent 4c059f6a27
commit 3d7c2cb156
5 changed files with 61 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
package org.wfc.user.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
@@ -84,4 +85,8 @@ public class UAccountPackage extends BaseData {
@Schema(description = "上行限速启用")
private Boolean upLimitEnable;
@Schema(description = "上行限速启用")
@TableField(exist = false)
private Integer status;
}

View File

@@ -0,0 +1,20 @@
package org.wfc.user.domain.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @description: 套餐状态
* @author: cyc
* @since: 2025-03-14
*/
@Getter
@AllArgsConstructor
public enum PackageStatusEnum {
INVALID(0, "未生效"),
VALID(1, "生效");
private final Integer code;
private final String desc;
}

View File

@@ -0,0 +1,18 @@
package org.wfc.user.domain.convert;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import org.wfc.user.domain.UAccount;
import org.wfc.user.domain.UAccountPackage;
/**
* @description: AccountPackageConvert
* @author: cyc
* @since: 2025-03-14
*/
@Mapper
public interface AccountPackageConvert {
AccountPackageConvert INSTANCE = Mappers.getMapper(AccountPackageConvert.class);
UAccountPackage toAccountPackage(UAccount account);
}

View File

@@ -7,14 +7,20 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.wfc.common.mybatis.domain.BaseData;
import org.wfc.common.security.utils.SecurityUtils;
import org.wfc.user.domain.UAccount;
import org.wfc.user.domain.UAccountPackage;
import org.wfc.user.domain.constant.PackageStatusEnum;
import org.wfc.user.domain.convert.AccountPackageConvert;
import org.wfc.user.mapper.UAccountMapper;
import org.wfc.user.mapper.UAccountPackageMapper;
import org.wfc.user.service.IUAccountPackageService;
import org.wfc.user.util.AccountUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
/**
@@ -34,11 +40,19 @@ public class UAccountPackageServiceImpl extends ServiceImpl<UAccountPackageMappe
@Override
public List<UAccountPackage> queryList(UAccountPackage uAccountPackage) {
UAccount account = accountMapper.selectOne(Wrappers.<UAccount>lambdaQuery().eq(UAccount::getUserId, SecurityUtils.getLoginUser().getUserid()), false);
if (ObjectUtil.isNull(account)) {
if (ObjectUtil.isNull(account) || !AccountUtil.isPackageValid(account, new Date())) {
return Collections.emptyList();
}
List<UAccountPackage> packages = new ArrayList<>();
// 添加当前生效的
UAccountPackage accountPackage = AccountPackageConvert.INSTANCE.toAccountPackage(account);
accountPackage.setAccountId(account.getId());
accountPackage.setStatus(PackageStatusEnum.VALID.getCode());
packages.add(accountPackage);
uAccountPackage.setAccountId(account.getId());
return this.list(buildQueryWrapper(uAccountPackage));
packages.addAll(this.list(buildQueryWrapper(uAccountPackage)));
return packages;
}
private LambdaQueryWrapper<UAccountPackage> buildQueryWrapper(UAccountPackage bo) {
@@ -63,6 +77,7 @@ public class UAccountPackageServiceImpl extends ServiceImpl<UAccountPackageMappe
lqw.eq(bo.getDownLimitEnable() != null, UAccountPackage::getDownLimitEnable, bo.getDownLimitEnable());
lqw.eq(bo.getUpLimit() != null, UAccountPackage::getUpLimit, bo.getUpLimit());
lqw.eq(bo.getUpLimitEnable() != null, UAccountPackage::getUpLimitEnable, bo.getUpLimitEnable());
lqw.orderByAsc(BaseData::getCreateTime);
return lqw;
}
}

View File

@@ -195,6 +195,7 @@ public class UOrderServiceImpl extends ServiceImpl<UOrderMapper, UOrder> impleme
if (isValid) {
BeanUtils.copyProperties(uPackage, accountPackage);
accountPackage.setId(null);
accountPackage.setCreateTime(null);
accountPackage.setAccountId(account.getId());
accountPackage.setPackageId(order.getPackageId());
accountPackageMapper.insert(accountPackage);