Bladeren bron

Merge branch '20250516-wyp-accountSync' of Server/growth-manager into master

wangyunpeng 1 maand geleden
bovenliggende
commit
37297c5903

+ 12 - 0
api-module/src/main/java/com/tzld/piaoquan/api/controller/contentplatform/ContentPlatformCooperateAccountController.java

@@ -1,5 +1,7 @@
 package com.tzld.piaoquan.api.controller.contentplatform;
 
+import com.tzld.piaoquan.api.annotation.JwtIgnore;
+import com.tzld.piaoquan.api.job.ContentPlatformGzhAccountJob;
 import com.tzld.piaoquan.api.model.param.IdParam;
 import com.tzld.piaoquan.api.model.param.contentplatform.CooperateAccountListParam;
 import com.tzld.piaoquan.api.model.param.contentplatform.CooperateAccountSaveParam;
@@ -24,6 +26,8 @@ public class ContentPlatformCooperateAccountController {
 
     @Autowired
     ContentPlatformCooperateAccountService cooperateAccountService;
+    @Autowired
+    ContentPlatformGzhAccountJob job;
 
     @ApiOperation(value = "公众号列表")
     @PostMapping("/gzh/list")
@@ -69,4 +73,12 @@ public class ContentPlatformCooperateAccountController {
         cooperateAccountService.gzhDelete(param.getId());
         return CommonResponse.success();
     }
+
+    @ApiOperation(value = "公众号账号信息同步", hidden = true)
+    @GetMapping("/job/syncGzhAccountInfoJob")
+    @JwtIgnore
+    public CommonResponse<String> syncGzhAccountInfoJob(String id) {
+        job.syncGzhAccountInfoJob(id);
+        return CommonResponse.success();
+    }
 }

+ 63 - 0
api-module/src/main/java/com/tzld/piaoquan/api/job/ContentPlatformGzhAccountJob.java

@@ -0,0 +1,63 @@
+package com.tzld.piaoquan.api.job;
+
+import com.alibaba.fastjson.JSONObject;
+import com.tzld.piaoquan.api.component.AigcApiService;
+import com.tzld.piaoquan.api.dao.mapper.contentplatform.ContentPlatformGzhAccountMapper;
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformGzhAccount;
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformGzhAccountExample;
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+@Slf4j
+@Component
+public class ContentPlatformGzhAccountJob {
+
+    @Autowired
+    private ContentPlatformGzhAccountMapper gzhAccountMapper;
+    @Autowired
+    private AigcApiService aigcApiService;
+
+    @XxlJob("syncGzhAccountInfoJob")
+    public ReturnT<String> syncGzhAccountInfoJob(String param) {
+        List<ContentPlatformGzhAccount> accountList;
+        if (StringUtils.hasText(param)) {
+            ContentPlatformGzhAccount account = gzhAccountMapper.selectByPrimaryKey(Long.valueOf(param));
+            accountList = new ArrayList<>();
+            accountList.add(account);
+        } else {
+            accountList = getNeedSyncAccountInfo();
+        }
+        if (accountList.isEmpty()) {
+            return ReturnT.SUCCESS;
+        }
+        for (ContentPlatformGzhAccount account : accountList) {
+            log.info("同步公众号数据统计:{}", account.getGhId());
+            JSONObject accountInfo = aigcApiService.getAccountDetail(account.getExternalId());
+            if (Objects.isNull(accountInfo)) {
+                continue;
+            }
+            String newName = accountInfo.getString("name");
+            if (account.getName().equals(newName) || !StringUtils.hasText(newName)) {
+                continue;
+            }
+            account.setName(accountInfo.getString("name"));
+            gzhAccountMapper.updateByPrimaryKeySelective(account);
+        }
+
+        return ReturnT.SUCCESS;
+    }
+
+    private List<ContentPlatformGzhAccount> getNeedSyncAccountInfo() {
+        ContentPlatformGzhAccountExample example = new ContentPlatformGzhAccountExample();
+        example.createCriteria().andExternalIdIsNotNull();
+        return gzhAccountMapper.selectByExample(example);
+    }
+}