|
@@ -1,11 +1,16 @@
|
|
|
package org.jeecg.modules.adweb.quota.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.LambdaUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
+import org.apache.ibatis.reflection.property.PropertyNamer;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
|
import org.jeecg.common.util.FastJsonUtil;
|
|
@@ -28,6 +33,13 @@ import java.util.Objects;
|
|
|
public class ResourceQuotaServiceImpl extends ServiceImpl<ResourceQuotaMapper, ResourceQuota>
|
|
|
implements IResourceQuotaService {
|
|
|
|
|
|
+ // ResourceQuota entity对应的数据库列名称
|
|
|
+ private static final String DB_COLUMN_CUSTOMS_DATA_USAGE =
|
|
|
+ StringUtils.camelToUnderline(
|
|
|
+ PropertyNamer.methodToProperty(
|
|
|
+ LambdaUtils.extract(ResourceQuota::getCustomsDataUsage)
|
|
|
+ .getImplMethodName()));
|
|
|
+
|
|
|
@Value("${resource-quota.default-website-quota}")
|
|
|
private int defaultWebsiteQuota;
|
|
|
|
|
@@ -86,6 +98,32 @@ public class ResourceQuotaServiceImpl extends ServiceImpl<ResourceQuotaMapper, R
|
|
|
adwebSiteService.getAllSiteIdByUid(uid).size());
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Pair<Integer, Integer> getAIPowerQuota(String uid) {
|
|
|
+ // TODO
|
|
|
+ return Pair.of(this.getResourceQuota(uid).getAiPowerQuota(), 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Pair<Integer, Integer> getCustomsDataQuota(String uid) {
|
|
|
+ ResourceQuota resourceQuota = this.getResourceQuota(uid);
|
|
|
+ return Pair.of(resourceQuota.getCustomsDataQuota(), resourceQuota.getCustomsDataUsage());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean consumeCustomsDataQuota(String uid) {
|
|
|
+ Wrapper<ResourceQuota> updateWrapper =
|
|
|
+ Wrappers.lambdaUpdate(ResourceQuota.class)
|
|
|
+ .eq(ResourceQuota::getUid, uid)
|
|
|
+ .setSql(
|
|
|
+ StringUtils.isNotBlank(DB_COLUMN_CUSTOMS_DATA_USAGE),
|
|
|
+ String.format(
|
|
|
+ "%s = %s + 1",
|
|
|
+ DB_COLUMN_CUSTOMS_DATA_USAGE,
|
|
|
+ DB_COLUMN_CUSTOMS_DATA_USAGE));
|
|
|
+ return this.update(updateWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取用户{@link ResourceQuota}记录
|
|
|
*
|