|
@@ -8,12 +8,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.pig4cloud.pig.admin.api.dto.SysPublicParamDTO;
|
|
|
+import com.pig4cloud.pig.admin.api.feign.RemoteParamService;
|
|
|
import com.pig4cloud.pig.common.core.exception.BusinessException;
|
|
|
import com.pig4cloud.pig.common.core.util.R;
|
|
|
+import com.pig4cloud.pig.common.core.util.ip.IPUtils;
|
|
|
import com.pig4cloud.pig.marketing.api.dto.app.*;
|
|
|
import com.pig4cloud.pig.marketing.api.entity.*;
|
|
|
import com.pig4cloud.pig.marketing.api.vo.app.*;
|
|
|
-import com.pig4cloud.pig.marketing.api.vo.config.GetMarketingGlobalConfigVO;
|
|
|
import com.pig4cloud.pig.marketing.mapper.*;
|
|
|
import com.pig4cloud.pig.marketing.service.MarketingAppsService;
|
|
|
import com.pig4cloud.pig.marketing.service.MarketingConfigService;
|
|
@@ -27,8 +29,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.io.IOException;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.pig4cloud.pig.marketing.api.MarketingConfigConstants.*;
|
|
|
+
|
|
|
/**
|
|
|
* @author: lwh
|
|
|
* @date: 2025-07-22
|
|
@@ -60,7 +65,8 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
|
|
|
private final MarketingGroupIpMapper groupIpMapper;
|
|
|
|
|
|
- private final MarketingConfigService marketingConfigService;
|
|
|
+ private final RemoteParamService remoteParamService;
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -267,20 +273,30 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
Map<String, MarketingApps> localAppMap = localApps.stream()
|
|
|
.collect(Collectors.toMap(MarketingApps::getAppId, app -> app));
|
|
|
|
|
|
- // 4. 处理新增和更新
|
|
|
+ // 4. 获取全局配置
|
|
|
+ AtomicReference<Integer> triggerRule = new AtomicReference<>();
|
|
|
+ AtomicReference<String> triggerNum = new AtomicReference<>("");
|
|
|
+ R<ArrayList<SysPublicParamDTO>> ParamDTO = remoteParamService.getParamList(Arrays.asList(TRIGGER_RULE, TRIGGER_NUM));
|
|
|
+
|
|
|
+ ParamDTO.getData().forEach(param -> {
|
|
|
+ if (TRIGGER_RULE.equals(param.getPublicKey())) {
|
|
|
+ triggerRule.set(Integer.valueOf(param.getPublicValue()));
|
|
|
+ } else if (TRIGGER_NUM.equals(param.getPublicKey())) {
|
|
|
+ triggerNum.set(param.getPublicValue());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 5. 处理新增和更新
|
|
|
for (MarketingApps app : appList) {
|
|
|
MarketingApps localApp = localAppMap.get(app.getAppId());
|
|
|
|
|
|
if (localApp == null) {
|
|
|
- // 获取全局配置信息
|
|
|
- GetMarketingGlobalConfigVO globalConfig = marketingConfigService.getMarketingGlobalConfig();
|
|
|
-
|
|
|
// 4.1 本地不存在,新增
|
|
|
app.setStatus( true);
|
|
|
app.setDomainLimit(false);
|
|
|
app.setLaunch( true);
|
|
|
- app.setTriggerRule(globalConfig.getTriggerRule());
|
|
|
- app.setTriggerNum(globalConfig.getTriggerNum());
|
|
|
+ app.setTriggerRule(triggerRule.get());
|
|
|
+ app.setTriggerNum(triggerNum.get());
|
|
|
appsMapper.insert(app);
|
|
|
addCount++;
|
|
|
} else {
|
|
@@ -383,6 +399,12 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
default -> null;
|
|
|
};
|
|
|
List<PageStatAppFirstMktDataVO> records = appsMapper.statAppFirstMktData(page, reqDto.getAppId(), startTime);
|
|
|
+
|
|
|
+ for (PageStatAppFirstMktDataVO record : records) {
|
|
|
+ String ip = record.getIp();
|
|
|
+ String region = IPUtils.getIpRegion(ip);
|
|
|
+ record.setRegion(region);
|
|
|
+ }
|
|
|
page.setRecords(records);
|
|
|
return page;
|
|
|
}
|
|
@@ -493,13 +515,35 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
if (ipDto.getId() != null && (ipDto.getModify()==null || !ipDto.getModify())){
|
|
|
continue;
|
|
|
}
|
|
|
+ // 去除无用数据
|
|
|
+ if (ipDto.getSourceType() == 1){
|
|
|
+ ipDto.setIpMode(null);
|
|
|
+ ipDto.setStartIp(null);
|
|
|
+ ipDto.setEndIp( null);
|
|
|
+
|
|
|
+ // 查询分组是否存在
|
|
|
+ MarketingConfigGroup group = groupMapper.selectOne(Wrappers.<MarketingConfigGroup>lambdaQuery()
|
|
|
+ .eq(MarketingConfigGroup::getId, ipDto.getGroupId())
|
|
|
+ .eq(MarketingConfigGroup::getGroupType, 1)
|
|
|
+ );
|
|
|
+ if (group == null){
|
|
|
+ throw new BusinessException("分组ID:"+ipDto.getGroupId()+"不存在");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ ipDto.setGroupId(null);
|
|
|
+ ipDto.setGroupName(null);
|
|
|
+ if (ipDto.getIpMode() == 1){
|
|
|
+ ipDto.setEndIp(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
// 查询ip表和ip分组表中是否存在
|
|
|
- if (checkIp(ipDto, appId)){
|
|
|
+ if (checkIp(ipDto, appId, false)){
|
|
|
if (ipDto.getIpMode() == 1){
|
|
|
throw new BusinessException("ip:"+ipDto.getStartIp()+"已存在");
|
|
|
}
|
|
|
- throw new BusinessException("ip:"+ipDto.getStartIp()+"/"+ipDto.getEndIp()+"已存在");
|
|
|
+ String[] end = ipDto.getEndIp().split("\\.");
|
|
|
+ throw new BusinessException("ip:"+ipDto.getStartIp()+"/"+end[3]+"已存在");
|
|
|
}
|
|
|
|
|
|
// 执行新增或修改
|
|
@@ -533,7 +577,24 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if (checkDomain(domainDto, appId)){
|
|
|
+ // 去除无用数据
|
|
|
+ if (domainDto.getSourceType() == 1){
|
|
|
+ domainDto.setDomain(null);
|
|
|
+
|
|
|
+ // 查询分组是否存在
|
|
|
+ MarketingConfigGroup group = groupMapper.selectOne(Wrappers.<MarketingConfigGroup>lambdaQuery()
|
|
|
+ .eq(MarketingConfigGroup::getId, domainDto.getGroupId())
|
|
|
+ .eq(MarketingConfigGroup::getGroupType, 2)
|
|
|
+ );
|
|
|
+ if (group == null){
|
|
|
+ throw new BusinessException("分组ID:"+domainDto.getGroupId()+"不存在");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ domainDto.setGroupId(null);
|
|
|
+ domainDto.setGroupName(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (checkDomain(domainDto, appId, false)){
|
|
|
throw new BusinessException("域名:"+domainDto.getDomain()+"已存在");
|
|
|
}
|
|
|
|
|
@@ -558,13 +619,14 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
* @param ipDto IP
|
|
|
* @return 是否存在
|
|
|
*/
|
|
|
- public boolean checkIp(MarketingAppsIpDTO ipDto, Long appId) {
|
|
|
- List<Long> groupIds = getAppRelatedGroupIds(appId, true);
|
|
|
+ @Override
|
|
|
+ public Boolean checkIp(MarketingAppsIpDTO ipDto, Long appId, Boolean isConfig) {
|
|
|
+ List<Long> groupIds = getAppRelatedGroupIds(appId, true, isConfig);
|
|
|
if (ipDto.getSourceType().equals(1)){
|
|
|
return groupIds.contains(ipDto.getGroupId());
|
|
|
}
|
|
|
// 1. 检查应用IP表
|
|
|
- if (checkAppsIpExists(ipDto, appId)) {
|
|
|
+ if (checkAppsIpExists(ipDto, appId, isConfig)) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -578,8 +640,8 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
* @param appId 应用ID
|
|
|
* @return 是否存在
|
|
|
*/
|
|
|
- public Boolean checkDomain(MarketingAppsDomainDTO domainDTO, Long appId) {
|
|
|
- List<Long> groupIds = getAppRelatedGroupIds(appId, false); // 需要实现获取应用关联的分组ID列表
|
|
|
+ public Boolean checkDomain(MarketingAppsDomainDTO domainDTO, Long appId, Boolean isConfig) {
|
|
|
+ List<Long> groupIds = getAppRelatedGroupIds(appId, false, isConfig); // 需要实现获取应用关联的分组ID列表
|
|
|
if (domainDTO.getSourceType().equals(1)){
|
|
|
// 来自分组
|
|
|
return groupIds.contains(domainDTO.getGroupId());
|
|
@@ -587,9 +649,10 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
|
|
|
// 1. 检查应用域名表
|
|
|
LambdaQueryWrapper<MarketingAppsDomain> appsQuery = new LambdaQueryWrapper<>();
|
|
|
- appsQuery.eq(MarketingAppsDomain::getAppId, appId)
|
|
|
+ appsQuery.eq(appId != null, MarketingAppsDomain::getAppId, appId)
|
|
|
.eq(MarketingAppsDomain::getSourceType, 2)
|
|
|
- .eq(MarketingAppsDomain::getDomain, domainDTO.getDomain());
|
|
|
+ .eq(MarketingAppsDomain::getDomain, domainDTO.getDomain())
|
|
|
+ .eq(MarketingAppsDomain::getConfig, isConfig);
|
|
|
if (appsDomainMapper.selectCount(appsQuery) > 0) {
|
|
|
return true;
|
|
|
}
|
|
@@ -607,12 +670,15 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
/**
|
|
|
* 检查应用IP表中是否存在冲突
|
|
|
*/
|
|
|
- private Boolean checkAppsIpExists(MarketingAppsIpDTO ipDto,Long appId){
|
|
|
+ private Boolean checkAppsIpExists(MarketingAppsIpDTO ipDto,Long appId, Boolean isConfig){
|
|
|
// 1、校验该appId应用下ip表,及ip分组表中,是否存在该ip
|
|
|
// 1.1、校验marketing_apps_ip表,appId=appId,是否包含
|
|
|
// 1.2、校验marketing_group_ip表,是否包含ip,如果包含查出分组id,在查看appId下是否包含这个分组
|
|
|
QueryWrapper<MarketingAppsIp> query = new QueryWrapper<>();
|
|
|
- query.eq("app_id", appId).eq("source_type",2);
|
|
|
+ query.eq("source_type",2).eq("config", isConfig?1:0);
|
|
|
+ if (appId != null){
|
|
|
+ query.eq("app_id", appId);
|
|
|
+ }
|
|
|
|
|
|
// 单IP模式检查
|
|
|
if (ipDto.getIpMode() == 1) {
|
|
@@ -701,11 +767,12 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
/**
|
|
|
* 获取应用关联的所有分组ID
|
|
|
*/
|
|
|
- private List<Long> getAppRelatedGroupIds(Long appId, Boolean isIp) {
|
|
|
+ private List<Long> getAppRelatedGroupIds(Long appId, Boolean isIp, Boolean isConfig) {
|
|
|
// 示例实现,实际需根据业务调整
|
|
|
if (isIp) {
|
|
|
LambdaQueryWrapper<MarketingAppsIp> query = new LambdaQueryWrapper<>();
|
|
|
- query.eq(MarketingAppsIp::getAppId, appId)
|
|
|
+ query.eq(appId!=null ,MarketingAppsIp::getAppId, appId)
|
|
|
+ .eq(MarketingAppsIp::getConfig, isConfig)
|
|
|
.eq(MarketingAppsIp::getSourceType, 1) // 来源类型为分组
|
|
|
.select(MarketingAppsIp::getGroupId)
|
|
|
.groupBy(MarketingAppsIp::getGroupId);
|
|
@@ -714,7 +781,8 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
.toList();
|
|
|
}else {
|
|
|
LambdaQueryWrapper<MarketingAppsDomain> query = new LambdaQueryWrapper<>();
|
|
|
- query.eq(MarketingAppsDomain::getAppId, appId)
|
|
|
+ query.eq(appId!=null, MarketingAppsDomain::getAppId, appId)
|
|
|
+ .eq(MarketingAppsDomain::getConfig, isConfig)
|
|
|
.eq(MarketingAppsDomain::getSourceType, 1) // 来源类型为分组
|
|
|
.select(MarketingAppsDomain::getGroupId)
|
|
|
.groupBy(MarketingAppsDomain::getGroupId);
|