|
@@ -4,25 +4,20 @@ package com.pig4cloud.pig.marketing.service.impl;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
-import com.pig4cloud.pig.marketing.api.dto.app.BatchUpdateMarketingAppsDTO;
|
|
|
|
-import com.pig4cloud.pig.marketing.api.dto.app.PageMarketingAppsDTO;
|
|
|
|
-import com.pig4cloud.pig.marketing.api.dto.app.SetMarketingAppsDTO;
|
|
|
|
-import com.pig4cloud.pig.marketing.api.dto.app.UpdateMarketingAppsDTO;
|
|
|
|
-import com.pig4cloud.pig.marketing.api.entity.MarketingApps;
|
|
|
|
-import com.pig4cloud.pig.marketing.api.entity.MarketingAppsDomain;
|
|
|
|
-import com.pig4cloud.pig.marketing.api.entity.MarketingAppsIp;
|
|
|
|
-import com.pig4cloud.pig.marketing.api.entity.MarketingConfigGroup;
|
|
|
|
|
|
+import com.pig4cloud.pig.common.core.util.R;
|
|
|
|
+import com.pig4cloud.pig.marketing.api.dto.app.*;
|
|
|
|
+import com.pig4cloud.pig.marketing.api.entity.*;
|
|
import com.pig4cloud.pig.marketing.api.vo.app.MarketingAppsDomainVO;
|
|
import com.pig4cloud.pig.marketing.api.vo.app.MarketingAppsDomainVO;
|
|
import com.pig4cloud.pig.marketing.api.vo.app.MarketingAppsIpVO;
|
|
import com.pig4cloud.pig.marketing.api.vo.app.MarketingAppsIpVO;
|
|
import com.pig4cloud.pig.marketing.api.vo.app.PageMarketingAppsVO;
|
|
import com.pig4cloud.pig.marketing.api.vo.app.PageMarketingAppsVO;
|
|
-import com.pig4cloud.pig.marketing.mapper.MarketingAppsDomainMapper;
|
|
|
|
-import com.pig4cloud.pig.marketing.mapper.MarketingAppsIpMapper;
|
|
|
|
-import com.pig4cloud.pig.marketing.mapper.MarketingAppsMapper;
|
|
|
|
-import com.pig4cloud.pig.marketing.mapper.MarketingConfigGroupMapper;
|
|
|
|
|
|
+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.MarketingAppsService;
|
|
|
|
+import com.pig4cloud.pig.marketing.service.MarketingConfigService;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import okhttp3.*;
|
|
import okhttp3.*;
|
|
@@ -47,7 +42,7 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
|
|
|
// 从配置文件读取URL
|
|
// 从配置文件读取URL
|
|
// @Value("${marketing.app.url}")
|
|
// @Value("${marketing.app.url}")
|
|
- private static final String getAppListUrl = "http://192.168.80.130:8000/ipa/getApps";
|
|
|
|
|
|
+ private static final String getAppListUrl = "http://192.168.3.17:2888/ipa/getApps";
|
|
|
|
|
|
// 从配置文件读取accessKey
|
|
// 从配置文件读取accessKey
|
|
// @Value("${marketing.app.access-key}")
|
|
// @Value("${marketing.app.access-key}")
|
|
@@ -59,8 +54,15 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
|
|
|
private final MarketingAppsDomainMapper appsDomainMapper;
|
|
private final MarketingAppsDomainMapper appsDomainMapper;
|
|
|
|
|
|
|
|
+ private final MarketingGroupDomainMapper groupDomainMapper;
|
|
|
|
+
|
|
private final MarketingConfigGroupMapper groupMapper;
|
|
private final MarketingConfigGroupMapper groupMapper;
|
|
|
|
|
|
|
|
+ private final MarketingGroupIpMapper groupIpMapper;
|
|
|
|
+
|
|
|
|
+ private final MarketingConfigService marketingConfigService;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 分页查询应用列表
|
|
* 分页查询应用列表
|
|
@@ -68,9 +70,10 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
* @return Page
|
|
* @return Page
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public Page pageMarketingApps(PageMarketingAppsDTO reqDto){
|
|
|
|
|
|
+ public Page pageMarketingApps(PageMarketingAppsDTO reqDto, Boolean status){
|
|
Page page = appsMapper.selectPage(new Page(reqDto.getCurrent(), reqDto.getSize()),
|
|
Page page = appsMapper.selectPage(new Page(reqDto.getCurrent(), reqDto.getSize()),
|
|
Wrappers.<MarketingApps>lambdaQuery()
|
|
Wrappers.<MarketingApps>lambdaQuery()
|
|
|
|
+ .eq(MarketingApps::getStatus, status)
|
|
.like(StrUtil.isNotBlank(reqDto.getAppId()), MarketingApps::getAppId, reqDto.getAppId())
|
|
.like(StrUtil.isNotBlank(reqDto.getAppId()), MarketingApps::getAppId, reqDto.getAppId())
|
|
.like(StrUtil.isNotBlank(reqDto.getAppName()), MarketingApps::getAppName, reqDto.getAppName())
|
|
.like(StrUtil.isNotBlank(reqDto.getAppName()), MarketingApps::getAppName, reqDto.getAppName())
|
|
.like(StrUtil.isNotBlank(reqDto.getDomainType()), MarketingApps::getDomainType, reqDto.getDomainType())
|
|
.like(StrUtil.isNotBlank(reqDto.getDomainType()), MarketingApps::getDomainType, reqDto.getDomainType())
|
|
@@ -118,49 +121,123 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
return page;
|
|
return page;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
- * 删除应用
|
|
|
|
- * @param id 应用id
|
|
|
|
- * @return Long
|
|
|
|
|
|
+ * 根据ID获取应用详情
|
|
|
|
+ * @param id 应用ID
|
|
|
|
+ * @return 应用详情
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public Long delAppById(String id) {
|
|
|
|
- return 0L;
|
|
|
|
|
|
+ public PageMarketingAppsVO getMarketingAppById(Long id) {
|
|
|
|
+ MarketingApps app = appsMapper.selectById(id);
|
|
|
|
+ if (app == null){
|
|
|
|
+ throw new RuntimeException("应用不存在");
|
|
|
|
+ }
|
|
|
|
+ PageMarketingAppsVO appsVO = new PageMarketingAppsVO();
|
|
|
|
+ BeanUtils.copyProperties(app, appsVO);
|
|
|
|
+ // 组装IP
|
|
|
|
+ List<MarketingAppsIp> ips = appsIpMapper.selectList(new QueryWrapper<MarketingAppsIp>().eq("app_id", app.getId()));
|
|
|
|
+ List<MarketingAppsIpVO> ipVOList = new ArrayList<>();
|
|
|
|
+ for (MarketingAppsIp ip : ips) {
|
|
|
|
+ MarketingAppsIpVO ipVO = new MarketingAppsIpVO();
|
|
|
|
+ BeanUtils.copyProperties(ip, ipVO);
|
|
|
|
+ if (ip.getGroupId() != null){
|
|
|
|
+ MarketingConfigGroup group = groupMapper.selectById(ip.getGroupId());
|
|
|
|
+ if (group != null)
|
|
|
|
+ ipVO.setGroupName(group.getGroupName());
|
|
|
|
+ }
|
|
|
|
+ ipVOList.add(ipVO);
|
|
|
|
+ }
|
|
|
|
+ appsVO.setIps(ipVOList);
|
|
|
|
+ // 组装域名
|
|
|
|
+
|
|
|
|
+ List<MarketingAppsDomain> domains = appsDomainMapper.selectList(new QueryWrapper<MarketingAppsDomain>().eq("app_id", app.getId()));
|
|
|
|
+ ArrayList<MarketingAppsDomainVO> domainVOList = new ArrayList<>();
|
|
|
|
+ for (MarketingAppsDomain domain : domains) {
|
|
|
|
+ MarketingAppsDomainVO domainVO = new MarketingAppsDomainVO();
|
|
|
|
+ BeanUtils.copyProperties(domain, domainVO);
|
|
|
|
+ if (domain.getGroupId() != null){
|
|
|
|
+ MarketingConfigGroup group = groupMapper.selectById(domain.getGroupId());
|
|
|
|
+ if (group != null)
|
|
|
|
+ domainVO.setGroupName(group.getGroupName());
|
|
|
|
+ }
|
|
|
|
+ domainVOList.add(domainVO);
|
|
|
|
+ }
|
|
|
|
+ appsVO.setDomains(domainVOList);
|
|
|
|
+ return appsVO;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 设置应用信息
|
|
|
|
- * @param reqDto 更新参数
|
|
|
|
|
|
+ * 批量更新应用信息
|
|
|
|
+ * @param reqDtoList 批量更新参数
|
|
* @return Long
|
|
* @return Long
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public Long setMarketingApps(SetMarketingAppsDTO reqDto) {
|
|
|
|
- return 0L;
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public R batchUpdateMarketingApps(List<BatchUpdateMarketingAppsDTO> reqDtoList) {
|
|
|
|
+ for (BatchUpdateMarketingAppsDTO reqDto : reqDtoList) {
|
|
|
|
+ Long id = reqDto.getId();
|
|
|
|
+ if (reqDto.getId() == null){
|
|
|
|
+ throw new RuntimeException("应用ID不能为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ MarketingApps apps = appsMapper.selectById(id);
|
|
|
|
+ if (apps == null){
|
|
|
|
+ throw new RuntimeException("应用ID:"+id+"不存在");
|
|
|
|
+ }
|
|
|
|
+ if (!apps.getStatus()){
|
|
|
|
+ throw new RuntimeException("应用ID:"+id+"已拉黑,请还原后操作");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 1、更新基本信息
|
|
|
|
+ MarketingApps marketingApps = new MarketingApps();
|
|
|
|
+ BeanUtils.copyProperties(reqDto, marketingApps);
|
|
|
|
+ appsMapper.updateById(marketingApps);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 2. 处理IP信息(包含分组检查)
|
|
|
|
+ handleIpOperations(reqDto, id);
|
|
|
|
+
|
|
|
|
+ // 3. 处理域名信息(包含分组检查)
|
|
|
|
+ handleDomainOperations(reqDto, id);
|
|
|
|
+ }
|
|
|
|
+ return R.ok();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 更新应用信息
|
|
|
|
|
|
+ * 设置应用信息
|
|
* @param reqDto 更新参数
|
|
* @param reqDto 更新参数
|
|
* @return Long
|
|
* @return Long
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public Long updateMarketingApps(UpdateMarketingAppsDTO reqDto) {
|
|
|
|
- return 0L;
|
|
|
|
|
|
+ public Boolean setMarketingAppsInfo(SetMarketingAppsDTO reqDto) {
|
|
|
|
+ MarketingApps app = appsMapper.selectById(reqDto.getId());
|
|
|
|
+ if (app == null){
|
|
|
|
+ throw new RuntimeException("应用不存在");
|
|
|
|
+ }
|
|
|
|
+ if (!app.getStatus()){
|
|
|
|
+ throw new RuntimeException("应用ID:"+app.getId()+"已拉黑,请还原后操作");
|
|
|
|
+ }
|
|
|
|
+ MarketingApps apps = new MarketingApps();
|
|
|
|
+ BeanUtils.copyProperties(reqDto, apps);
|
|
|
|
+ int i = appsMapper.updateById(apps);
|
|
|
|
+ return i>0 ;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 批量更新应用信息
|
|
|
|
- * @param reqDtoList 批量更新参数
|
|
|
|
- * @return Long
|
|
|
|
|
|
+ * 设置应用状态
|
|
|
|
+ * @param reqDto 设置参数
|
|
|
|
+ * @return Boolean
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public List<Long> batchUpdateMarketingApps(List<BatchUpdateMarketingAppsDTO> reqDtoList) {
|
|
|
|
- return List.of();
|
|
|
|
|
|
+ public Boolean setAppStatusById(SetMarketingAppsStatusDTO reqDto) {
|
|
|
|
+ MarketingApps apps = appsMapper.selectById(reqDto.getId());
|
|
|
|
+ if (apps == null) {
|
|
|
|
+ throw new RuntimeException("应用不存在");
|
|
|
|
+ }
|
|
|
|
+ apps.setStatus(reqDto.getStatus());
|
|
|
|
+ return appsMapper.updateById(apps) > 0;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 同步应用列表
|
|
* 同步应用列表
|
|
*
|
|
*
|
|
@@ -195,11 +272,15 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
MarketingApps localApp = localAppMap.get(app.getAppId());
|
|
MarketingApps localApp = localAppMap.get(app.getAppId());
|
|
|
|
|
|
if (localApp == null) {
|
|
if (localApp == null) {
|
|
|
|
+ // 获取全局配置信息
|
|
|
|
+ GetMarketingGlobalConfigVO globalConfig = marketingConfigService.getMarketingGlobalConfig();
|
|
|
|
+
|
|
// 4.1 本地不存在,新增
|
|
// 4.1 本地不存在,新增
|
|
|
|
+ app.setStatus( true);
|
|
app.setDomainLimit(false);
|
|
app.setDomainLimit(false);
|
|
app.setLaunch( true);
|
|
app.setLaunch( true);
|
|
- app.setTriggerRule(1);
|
|
|
|
- app.setTriggerNum(1);
|
|
|
|
|
|
+ app.setTriggerRule(globalConfig.getTriggerRule());
|
|
|
|
+ app.setTriggerNum(globalConfig.getTriggerNum());
|
|
appsMapper.insert(app);
|
|
appsMapper.insert(app);
|
|
addCount++;
|
|
addCount++;
|
|
} else {
|
|
} else {
|
|
@@ -219,6 +300,9 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
for (MarketingApps localApp : localApps) {
|
|
for (MarketingApps localApp : localApps) {
|
|
if (!lafaAppIds.contains(localApp.getAppId())) {
|
|
if (!lafaAppIds.contains(localApp.getAppId())) {
|
|
appsMapper.deleteById(localApp);
|
|
appsMapper.deleteById(localApp);
|
|
|
|
+ // 删除应用关联的IP、域名
|
|
|
|
+ appsIpMapper.delete(Wrappers.<MarketingAppsIp>lambdaQuery().eq(MarketingAppsIp::getAppId, localApp.getId()));
|
|
|
|
+ appsDomainMapper.delete(Wrappers.<MarketingAppsDomain>lambdaQuery().eq(MarketingAppsDomain::getAppId, localApp.getId()));
|
|
deleteCount++;
|
|
deleteCount++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -230,6 +314,60 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 修改应用IP列表
|
|
|
|
+ * @param reqDto 修改参数
|
|
|
|
+ * @return R
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public R modMarketingAppsIps(ModMarketingAppsIpDTO reqDto) {
|
|
|
|
+ Long appId = reqDto.getId();
|
|
|
|
+ if (reqDto.getId() == null) {
|
|
|
|
+ throw new RuntimeException("应用ID不能为空");
|
|
|
|
+ }
|
|
|
|
+ MarketingApps app = appsMapper.selectById(appId);
|
|
|
|
+ if (app == null){
|
|
|
|
+ throw new RuntimeException("应用ID:"+appId+"不存在");
|
|
|
|
+ }
|
|
|
|
+ if (!app.getStatus()){
|
|
|
|
+ throw new RuntimeException("应用ID:"+app.getId()+"已拉黑,请还原后操作");
|
|
|
|
+ }
|
|
|
|
+ BatchUpdateMarketingAppsDTO updateIp = new BatchUpdateMarketingAppsDTO();
|
|
|
|
+ updateIp.setId(appId);
|
|
|
|
+ updateIp.setIps(reqDto.getIps());
|
|
|
|
+ updateIp.setDelIps(reqDto.getDelIps());
|
|
|
|
+ // 处理IP信息
|
|
|
|
+ handleIpOperations(updateIp, appId);
|
|
|
|
+ return R.ok();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改应用域名列表
|
|
|
|
+ * @param reqDto 修改参数
|
|
|
|
+ * @return R
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public R modMarketingAppsDomains(ModMarketingAppsDomainDTO reqDto) {
|
|
|
|
+ Long appId = reqDto.getId();
|
|
|
|
+ if (reqDto.getId() == null){
|
|
|
|
+ throw new RuntimeException("应用ID不能为空");
|
|
|
|
+ }
|
|
|
|
+ MarketingApps app = appsMapper.selectById(appId);
|
|
|
|
+ if (app == null){
|
|
|
|
+ throw new RuntimeException("应用ID:"+appId+"不存在");
|
|
|
|
+ }
|
|
|
|
+ if (!app.getStatus()){
|
|
|
|
+ throw new RuntimeException("应用ID:"+app.getId()+"已拉黑,请还原后操作");
|
|
|
|
+ }
|
|
|
|
+ BatchUpdateMarketingAppsDTO updateDomain = new BatchUpdateMarketingAppsDTO();
|
|
|
|
+ updateDomain.setId(appId);
|
|
|
|
+ updateDomain.setDomains(reqDto.getDomains());
|
|
|
|
+ updateDomain.setDelDomains(reqDto.getDelDomains());
|
|
|
|
+ // 处理域名信息
|
|
|
|
+ handleDomainOperations(updateDomain, appId);
|
|
|
|
+ return R.ok();
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 从lafa服务获取应用列表
|
|
* 从lafa服务获取应用列表
|
|
* @return 应用列表
|
|
* @return 应用列表
|
|
@@ -299,4 +437,239 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
Objects.equals(newApp.getDomainType(), oldApp.getDomainType());
|
|
Objects.equals(newApp.getDomainType(), oldApp.getDomainType());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 处理IP的新增/修改/删除,包含分组存在性检查
|
|
|
|
+ */
|
|
|
|
+ private void handleIpOperations(BatchUpdateMarketingAppsDTO reqDto, Long appId) {
|
|
|
|
+ // 2.1 删除指定IP
|
|
|
|
+ if (reqDto.getDelIps() != null && !reqDto.getDelIps().isEmpty()) {
|
|
|
|
+ appsIpMapper.deleteByIds(reqDto.getDelIps());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 2.2 新增或修改IP
|
|
|
|
+ if (reqDto.getIps() != null && !reqDto.getIps().isEmpty()) {
|
|
|
|
+ for (MarketingAppsIpDTO ipDto : reqDto.getIps()) {
|
|
|
|
+ if (ipDto.getId() != null && (ipDto.getModify()==null || !ipDto.getModify())){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 查询ip表和ip分组表中是否存在
|
|
|
|
+ if (checkIp(ipDto, appId)){
|
|
|
|
+ throw new RuntimeException("ip已存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 执行新增或修改
|
|
|
|
+ MarketingAppsIp appsIp = new MarketingAppsIp();
|
|
|
|
+ BeanUtils.copyProperties(ipDto, appsIp);
|
|
|
|
+ appsIp.setAppId(appId);
|
|
|
|
+
|
|
|
|
+ if (ipDto.getId() == null) {
|
|
|
|
+ appsIp.setConfig(false);
|
|
|
|
+ appsIpMapper.insert(appsIp);
|
|
|
|
+ } else if (ipDto.getModify() != null && ipDto.getModify()) {
|
|
|
|
+ appsIpMapper.updateById(appsIp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 处理域名的新增/修改/删除,包含完整校验逻辑
|
|
|
|
+ */
|
|
|
|
+ private void handleDomainOperations(BatchUpdateMarketingAppsDTO reqDto, Long appId) {
|
|
|
|
+ // 3.1 删除指定域名
|
|
|
|
+ if (reqDto.getDelDomains() != null && !reqDto.getDelDomains().isEmpty()) {
|
|
|
|
+ appsDomainMapper.deleteBatchIds(reqDto.getDelDomains());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 3.2 新增或修改域名
|
|
|
|
+ if (reqDto.getDomains() != null && !reqDto.getDomains().isEmpty()) {
|
|
|
|
+ for (MarketingAppsDomainDTO domainDto : reqDto.getDomains()) {
|
|
|
|
+ if (domainDto.getId() != null && (domainDto.getModify()==null || !domainDto.getModify())){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (checkDomain(domainDto, appId)){
|
|
|
|
+ throw new RuntimeException("域名已存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 执行新增或修改
|
|
|
|
+ MarketingAppsDomain appsDomain = new MarketingAppsDomain();
|
|
|
|
+ BeanUtils.copyProperties(domainDto, appsDomain);
|
|
|
|
+ appsDomain.setAppId(appId);
|
|
|
|
+
|
|
|
|
+ if (domainDto.getId() == null) {
|
|
|
|
+ appsDomain.setConfig(false);
|
|
|
|
+ appsDomainMapper.insert(appsDomain);
|
|
|
|
+ } else if (domainDto.getModify() != null && domainDto.getModify()) {
|
|
|
|
+ appsDomainMapper.updateById(appsDomain);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 判断IP是否已存在(单IP或IP段)
|
|
|
|
+ * @param appId 应用数据ID
|
|
|
|
+ * @param ipDTO IP
|
|
|
|
+ * @return 是否存在
|
|
|
|
+ */
|
|
|
|
+ public boolean checkIp(MarketingAppsIpDTO ipDTO, Long appId) {
|
|
|
|
+ // 1. 检查应用IP表
|
|
|
|
+ if (checkAppsIpExists(ipDTO, appId)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 2. 检查分组IP表(需要关联应用关联的分组)
|
|
|
|
+ return checkGroupIpExists(ipDTO, appId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 判断域名是否已存在
|
|
|
|
+ * @param domainDTO 域名信息DTO
|
|
|
|
+ * @param appId 应用ID
|
|
|
|
+ * @return 是否存在
|
|
|
|
+ */
|
|
|
|
+ public Boolean checkDomain(MarketingAppsDomainDTO domainDTO, Long appId) {
|
|
|
|
+ // 1. 检查应用域名表
|
|
|
|
+ LambdaQueryWrapper<MarketingAppsDomain> appsQuery = new LambdaQueryWrapper<>();
|
|
|
|
+ appsQuery.eq(MarketingAppsDomain::getAppId, appId)
|
|
|
|
+ .eq(MarketingAppsDomain::getDomain, domainDTO.getDomain());
|
|
|
|
+ if (appsDomainMapper.selectCount(appsQuery) > 0) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 2. 检查分组域名表(需要关联应用关联的分组)
|
|
|
|
+ List<Long> groupIds = getAppRelatedGroupIds(appId, false); // 需要实现获取应用关联的分组ID列表
|
|
|
|
+ if (!groupIds.isEmpty()) {
|
|
|
|
+ LambdaQueryWrapper<MarketingGroupDomain> groupQuery = new LambdaQueryWrapper<>();
|
|
|
|
+ groupQuery.in(MarketingGroupDomain::getGroupId, groupIds)
|
|
|
|
+ .eq(MarketingGroupDomain::getDomain, domainDTO.getDomain());
|
|
|
|
+ return groupDomainMapper.selectCount(groupQuery) > 0;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 检查应用IP表中是否存在冲突
|
|
|
|
+ */
|
|
|
|
+ private Boolean checkAppsIpExists(MarketingAppsIpDTO ipDto,Long appId){
|
|
|
|
+ // 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);
|
|
|
|
+
|
|
|
|
+ // 单IP模式检查
|
|
|
|
+ if (ipDto.getIpMode() == 1) {
|
|
|
|
+ String targetIp = ipDto.getStartIp();
|
|
|
|
+ // 检查是否有相同单IP
|
|
|
|
+ query.and(wrapper -> wrapper
|
|
|
|
+ .eq("ip_mode", 1)
|
|
|
|
+ .eq("start_ip", targetIp));
|
|
|
|
+
|
|
|
|
+ // 检查是否被IP段包含
|
|
|
|
+ query.or(wrapper -> wrapper
|
|
|
|
+ .eq("ip_mode", 2)
|
|
|
|
+ .apply("INET_ATON({0}) BETWEEN INET_ATON(start_ip) AND INET_ATON(end_ip)", targetIp));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // IP段模式检查
|
|
|
|
+ if (ipDto.getIpMode() == 2) {
|
|
|
|
+ String startIp = ipDto.getStartIp();
|
|
|
|
+ String endIp = ipDto.getEndIp();
|
|
|
|
+
|
|
|
|
+ // 检查是否与单IP重叠:单IP在输入IP段范围内
|
|
|
|
+ query.and(wrapper -> wrapper
|
|
|
|
+ .eq("ip_mode", 1)
|
|
|
|
+ .apply("INET_ATON(start_ip) BETWEEN INET_ATON({0}) AND INET_ATON({1})", startIp, endIp));
|
|
|
|
+ // 检查是否与IP段重叠:两个IP段有交集
|
|
|
|
+ query.or(wrapper -> wrapper
|
|
|
|
+ .eq("ip_mode", 2)
|
|
|
|
+ .and(w2 -> w2
|
|
|
|
+ .apply("INET_ATON(start_ip) BETWEEN INET_ATON({0}) AND INET_ATON({1})", startIp, endIp)
|
|
|
|
+ .or().apply("INET_ATON(end_ip) BETWEEN INET_ATON({0}) AND INET_ATON({1})", startIp, endIp)
|
|
|
|
+ .or().apply("INET_ATON({0}) BETWEEN INET_ATON(start_ip) AND INET_ATON(end_ip)", startIp)
|
|
|
|
+ )
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return appsIpMapper.selectCount(query) > 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 检查分组IP表中是否存在冲突
|
|
|
|
+ */
|
|
|
|
+ private boolean checkGroupIpExists(MarketingAppsIpDTO ipDTO, Long appId) {
|
|
|
|
+ List<Long> groupIds = getAppRelatedGroupIds(appId, true); // 需要实现获取应用关联的分组ID列表
|
|
|
|
+ if (groupIds.isEmpty()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ QueryWrapper<MarketingGroupIp> query = new QueryWrapper<>();
|
|
|
|
+ query.in("group_id", groupIds);
|
|
|
|
+
|
|
|
|
+ // 单IP模式
|
|
|
|
+ if (ipDTO.getIpMode() == 1) {
|
|
|
|
+ String targetIp = ipDTO.getStartIp();
|
|
|
|
+ // 检查是否有相同单IP
|
|
|
|
+ query.and(wrapper -> wrapper
|
|
|
|
+ .eq("ip_mode", 1)
|
|
|
|
+ .eq("start_ip", targetIp));
|
|
|
|
+
|
|
|
|
+ // 检查是否被IP段包含
|
|
|
|
+ query.or(wrapper -> wrapper
|
|
|
|
+ .eq("ip_mode", 2)
|
|
|
|
+ .apply("INET_ATON({0}) BETWEEN INET_ATON(start_ip) AND INET_ATON(end_ip)", targetIp));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // IP段模式检查
|
|
|
|
+ if (ipDTO.getIpMode() == 2) {
|
|
|
|
+ String startIp = ipDTO.getStartIp();
|
|
|
|
+ String endIp = ipDTO.getEndIp();
|
|
|
|
+
|
|
|
|
+ query.and(wrapper -> wrapper
|
|
|
|
+ .eq("ip_mode", 1)
|
|
|
|
+ .apply("INET_ATON(start_ip) BETWEEN INET_ATON({0}) AND INET_ATON({1})", startIp, endIp));
|
|
|
|
+
|
|
|
|
+ query.or(wrapper -> wrapper
|
|
|
|
+ .eq("ip_mode", 2)
|
|
|
|
+ .and(w2 -> w2
|
|
|
|
+ .apply("INET_ATON(start_ip) BETWEEN INET_ATON({0}) AND INET_ATON({1})", startIp, endIp)
|
|
|
|
+ .or().apply("INET_ATON(end_ip) BETWEEN INET_ATON({0}) AND INET_ATON({1})", startIp, endIp)
|
|
|
|
+ .or().apply("INET_ATON({0}) BETWEEN INET_ATON(start_ip) AND INET_ATON(end_ip)", startIp)
|
|
|
|
+ )
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ return groupIpMapper.selectCount(query) > 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取应用关联的所有分组ID
|
|
|
|
+ */
|
|
|
|
+ private List<Long> getAppRelatedGroupIds(Long appId, Boolean isIp) {
|
|
|
|
+ // 示例实现,实际需根据业务调整
|
|
|
|
+ if (isIp) {
|
|
|
|
+ LambdaQueryWrapper<MarketingAppsIp> query = new LambdaQueryWrapper<>();
|
|
|
|
+ query.eq(MarketingAppsIp::getAppId, appId)
|
|
|
|
+ .eq(MarketingAppsIp::getSourceType, 1) // 来源类型为分组
|
|
|
|
+ .select(MarketingAppsIp::getGroupId)
|
|
|
|
+ .groupBy(MarketingAppsIp::getGroupId);
|
|
|
|
+ return appsIpMapper.selectObjs(query).stream()
|
|
|
|
+ .map(obj -> (Long) obj)
|
|
|
|
+ .toList();
|
|
|
|
+ }else {
|
|
|
|
+ LambdaQueryWrapper<MarketingAppsDomain> query = new LambdaQueryWrapper<>();
|
|
|
|
+ query.eq(MarketingAppsDomain::getAppId, appId)
|
|
|
|
+ .eq(MarketingAppsDomain::getSourceType, 1) // 来源类型为分组
|
|
|
|
+ .select(MarketingAppsDomain::getGroupId)
|
|
|
|
+ .groupBy(MarketingAppsDomain::getGroupId);
|
|
|
|
+ return appsDomainMapper.selectObjs(query).stream()
|
|
|
|
+ .map(obj -> (Long) obj)
|
|
|
|
+ .toList();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|