|
@@ -18,10 +18,11 @@ import com.pig4cloud.pig.marketing.api.entity.*;
|
|
|
import com.pig4cloud.pig.marketing.api.vo.app.*;
|
|
|
import com.pig4cloud.pig.marketing.mapper.*;
|
|
|
import com.pig4cloud.pig.marketing.service.MarketingAppsService;
|
|
|
-import lombok.AllArgsConstructor;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import okhttp3.*;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -41,17 +42,17 @@ import static com.pig4cloud.pig.marketing.api.MarketingConfigConstants.TRIGGER_R
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-@AllArgsConstructor
|
|
|
+@RequiredArgsConstructor
|
|
|
public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
|
|
|
|
|
|
// 从配置文件读取URL
|
|
|
-// @Value("${marketing.app.url}")
|
|
|
- private static final String getAppListUrl = "http://192.168.3.17:2888/ipa/getApps";
|
|
|
+ @Value("${marketing.app.url}")
|
|
|
+ private String getAppListUrl;
|
|
|
|
|
|
// 从配置文件读取accessKey
|
|
|
-// @Value("${marketing.app.access-key}")
|
|
|
- private static final String accessKey = "4ea5ba93-d222-45dc-862a-1c7fc7789d11";
|
|
|
+ @Value("${marketing.app.access-key}")
|
|
|
+ private String accessKey;
|
|
|
|
|
|
private final MarketingAppsMapper appsMapper;
|
|
|
|
|
@@ -281,10 +282,13 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
int deleteCount = 0;
|
|
|
|
|
|
// 1. 获取lafa服务应用的appId集合
|
|
|
- Set<String> lafaAppIds = appList.stream()
|
|
|
- .map(MarketingApps::getAppId)
|
|
|
- .collect(Collectors.toSet());
|
|
|
-
|
|
|
+ // 1. 获取lafa服务应用的appId集合 - 添加空值检查
|
|
|
+ Set<String> lafaAppIds = new HashSet<>();
|
|
|
+ if (appList != null && !appList.isEmpty()) {
|
|
|
+ lafaAppIds = appList.stream()
|
|
|
+ .map(MarketingApps::getAppId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ }
|
|
|
// 2. 查询本地数据库中所有未删除的应用
|
|
|
List<MarketingApps> localApps = appsMapper.selectList(new QueryWrapper<>());
|
|
|
|
|
@@ -293,52 +297,63 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
.collect(Collectors.toMap(MarketingApps::getAppId, app -> app));
|
|
|
|
|
|
// 4. 获取全局配置
|
|
|
- AtomicReference<Integer> triggerRule = new AtomicReference<>();
|
|
|
- AtomicReference<String> triggerNum = new AtomicReference<>("");
|
|
|
+ AtomicReference<Integer> triggerRule = new AtomicReference<>(1);
|
|
|
+ AtomicReference<String> triggerNum = new AtomicReference<>("1");
|
|
|
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());
|
|
|
- }
|
|
|
- });
|
|
|
+ // 添加空值检查,防止空指针异常
|
|
|
+ if (ParamDTO != null && ParamDTO.getData() != null) {
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (appList != null) {
|
|
|
+ // 5. 处理新增和更新
|
|
|
+ for (MarketingApps app : appList) {
|
|
|
+ MarketingApps localApp = localAppMap.get(app.getAppId());
|
|
|
|
|
|
- // 5. 处理新增和更新
|
|
|
- for (MarketingApps app : appList) {
|
|
|
- MarketingApps localApp = localAppMap.get(app.getAppId());
|
|
|
-
|
|
|
- if (localApp == null) {
|
|
|
- // 4.1 本地不存在,新增
|
|
|
- app.setStatus( true);
|
|
|
- app.setDomainLimit(false);
|
|
|
- app.setLaunch( true);
|
|
|
- app.setTriggerRule(triggerRule.get());
|
|
|
- app.setTriggerNum(triggerNum.get());
|
|
|
- appsMapper.insert(app);
|
|
|
- addCount++;
|
|
|
- } else {
|
|
|
- // 4.2 本地存在,判断是否需要更新
|
|
|
- // 复制ID(本地自增ID)和创建时间(保留原始创建时间)
|
|
|
- app.setId(localApp.getId());
|
|
|
-
|
|
|
- // 对比是否有变化
|
|
|
- if (!isSameApp(app, localApp)) {
|
|
|
- appsMapper.updateById(app);
|
|
|
- updateCount++;
|
|
|
+ if (localApp == null) {
|
|
|
+
|
|
|
+ MarketingApps existingApp = appsMapper.selectOne(
|
|
|
+ new QueryWrapper<MarketingApps>().eq("app_id", app.getAppId())
|
|
|
+ );
|
|
|
+
|
|
|
+ if (existingApp == null) {
|
|
|
+ // 4.1 本地不存在,新增
|
|
|
+ app.setStatus(true);
|
|
|
+ app.setDomainLimit(false);
|
|
|
+ app.setLaunch(true);
|
|
|
+ app.setTriggerRule(triggerRule.get());
|
|
|
+ app.setTriggerNum(triggerNum.get());
|
|
|
+ appsMapper.insert(app);
|
|
|
+ addCount++;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 4.2 本地存在,判断是否需要更新
|
|
|
+ // 复制ID(本地自增ID)和创建时间(保留原始创建时间)
|
|
|
+ app.setId(localApp.getId());
|
|
|
+
|
|
|
+ // 对比是否有变化
|
|
|
+ if (!isSameApp(app, localApp)) {
|
|
|
+ appsMapper.updateById(app);
|
|
|
+ updateCount++;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // 5. 处理删除:本地存在但A服务不存在的应用,标记为删除
|
|
|
- for (MarketingApps localApp : localApps) {
|
|
|
- if (!lafaAppIds.contains(localApp.getAppId())) {
|
|
|
- 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++;
|
|
|
+ // 6. 处理删除:本地存在但A服务不存在的应用,标记为删除
|
|
|
+ for (MarketingApps localApp : localApps) {
|
|
|
+ if (!lafaAppIds.contains(localApp.getAppId())) {
|
|
|
+ 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++;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -515,7 +530,8 @@ public class MarketingAppsServiceImpl implements MarketingAppsService {
|
|
|
Objects.equals(newApp.getAppImg(), oldApp.getAppImg()) &&
|
|
|
Objects.equals(newApp.getAppUrl(), oldApp.getAppUrl()) &&
|
|
|
Objects.equals(newApp.getBackupUrl(), oldApp.getBackupUrl()) &&
|
|
|
- Objects.equals(newApp.getDomainType(), oldApp.getDomainType());
|
|
|
+ Objects.equals(newApp.getDomainType(), oldApp.getDomainType()) &&
|
|
|
+ Objects.equals(newApp.getBundle(), oldApp.getBundle());
|
|
|
}
|
|
|
|
|
|
/**
|