瀏覽代碼

公众号-自动回复

wangyunpeng 3 月之前
父節點
當前提交
8c6d6691b4

+ 1 - 2
api-module/src/main/java/com/tzld/piaoquan/api/dao/mapper/contentplatform/ext/ContentPlatformGzhAccountMapperExt.java

@@ -3,7 +3,6 @@ package com.tzld.piaoquan.api.dao.mapper.contentplatform.ext;
 import com.tzld.piaoquan.api.model.param.contentplatform.CooperateAccountListParam;
 import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformAccount;
 import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformGzhAccount;
-import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformGzhAccountExample;
 import com.tzld.piaoquan.api.model.vo.contentplatform.GzhAccountItem;
 import org.apache.ibatis.annotations.Param;
 
@@ -11,7 +10,7 @@ import java.util.List;
 
 public interface ContentPlatformGzhAccountMapperExt {
 
-    List<ContentPlatformAccount> getGhIdExists(@Param("id") Long id, @Param("ghId") String ghId);
+    List<ContentPlatformAccount> getGhIdExists(@Param("createAccountId") Long createAccountId, @Param("ghId") String ghId);
 
     int getCooperateAccountCount(@Param("param") CooperateAccountListParam param,
                                  @Param("createAccountId") Long createAccountId);

+ 2 - 0
api-module/src/main/java/com/tzld/piaoquan/api/dao/mapper/contentplatform/ext/ContentPlatformPlanMapperExt.java

@@ -33,4 +33,6 @@ public interface ContentPlatformPlanMapperExt {
                                             @Param("dt") String dt,
                                             @Param("offset") int offset,
                                             @Param("pageSize") Integer pageSize);
+
+    void batchInsertContentPlatformVideo(@Param("records") List<ContentPlatformVideo> saveList);
 }

+ 16 - 0
api-module/src/main/java/com/tzld/piaoquan/api/service/contentplatform/impl/ContentPlatformCooperateAccountServiceImpl.java

@@ -88,6 +88,11 @@ public class ContentPlatformCooperateAccountServiceImpl implements ContentPlatfo
         if (CollectionUtils.isNotEmpty(ghIdExistList)) {
             throw new CommonException(ExceptionEnum.GZH_EXISTS);
         }
+        // 已存在则可重新授权
+        Long existId = getExistGzhAccountId(loginAccount.getId(), param.getGhId());
+        if (Objects.nonNull(existId)) {
+            param.setId(existId);
+        }
         Long now = System.currentTimeMillis();
         ContentPlatformGzhAccount account = new ContentPlatformGzhAccount();
         account.setName(param.getName());
@@ -104,10 +109,21 @@ public class ContentPlatformCooperateAccountServiceImpl implements ContentPlatfo
             gzhAccountMapper.insertSelective(account);
         } else {
             account.setId(param.getId());
+            account.setStatus(1);
             gzhAccountMapper.updateByPrimaryKeySelective(account);
         }
     }
 
+    private Long getExistGzhAccountId(Long loginUserId, String ghId) {
+        ContentPlatformGzhAccountExample example = new ContentPlatformGzhAccountExample();
+        example.createCriteria().andCreateAccountIdEqualTo(loginUserId).andGhIdEqualTo(ghId);
+        List<ContentPlatformGzhAccount> accountList = gzhAccountMapper.selectByExample(example);
+        if (CollectionUtils.isNotEmpty(accountList)) {
+            return accountList.get(0).getId();
+        }
+        return null;
+    }
+
     @Override
     public GenerateQrcodeVO getGzhAuthQrCode(GzhAuthResultParam param) {
         String qrcodeStr = aigcApiService.generateQrcode(param.getCode());

+ 5 - 3
api-module/src/main/resources/mapper/contentplatform/ext/ContentPlatformGzhAccountMapperExt.xml

@@ -7,9 +7,8 @@
     select *
     from content_platform_gzh_account
     where gh_id = #{ghId}
-    <if test="id!= null">
-      and create_account_id != #{id}
-    </if>
+      and create_account_id != #{createAccountId}
+      and status = 1
     limit 1
   </select>
 
@@ -17,6 +16,7 @@
     select count(1)
     from content_platform_gzh_account
     where create_account_id = #{createAccountId}
+    and status = 1
   </select>
 
   <select id="getCooperateAccountList"
@@ -24,6 +24,7 @@
     select *
     from content_platform_gzh_account
     where create_account_id = #{createAccountId}
+      and status = 1
     order by create_timestamp desc
     limit #{offset}, #{pageSize}
   </select>
@@ -32,6 +33,7 @@
     select id, name
     from content_platform_gzh_account
     where create_account_id = #{createAccountId}
+      and status = 1
     order by create_timestamp desc
   </select>
 

+ 15 - 3
api-module/src/main/resources/mapper/contentplatform/ext/ContentPlatformPlanMapperExt.xml

@@ -27,7 +27,8 @@
             and create_timestamp &lt; #{param.createTimestampEnd}
         </if>
         <if test="param.title != null and param.title != ''">
-            and id in (select plan_id from content_platform_gzh_plan_video where title like concat('%', #{param.title}, '%'))
+            and id in (select plan_id from content_platform_gzh_plan_video where title like concat('%', #{param.title},
+            '%'))
         </if>
     </select>
 
@@ -49,7 +50,8 @@
             and create_timestamp &lt; #{param.createTimestampEnd}
         </if>
         <if test="param.title != null and param.title != ''">
-            and id in (select plan_id from content_platform_gzh_plan_video where title like concat('%', #{param.title}, '%'))
+            and id in (select plan_id from content_platform_gzh_plan_video where title like concat('%', #{param.title},
+            '%'))
         </if>
         order by create_timestamp desc
         limit #{offset}, #{pageSize}
@@ -68,7 +70,8 @@
     </select>
 
     <select id="getVideoMaxDt" resultType="java.lang.String">
-        select max(dt) from content_platform_video
+        select max(dt)
+        from content_platform_video
     </select>
 
     <select id="getVideoCount" resultType="java.lang.Integer">
@@ -97,4 +100,13 @@
         limit #{offset}, #{pageSize}
     </select>
 
+    <insert id="batchInsertContentPlatformVideo">
+        insert into content_platform_video (dt, video_id, category, title, video, score, create_timestamp)
+        values
+        <foreach collection="records" item="item" separator=",">
+            (#{item.dt}, #{item.videoId}, #{item.category}, #{item.title}, #{item.video}, #{item.score},
+            #{item.createTimestamp})
+        </foreach>
+    </insert>
+
 </mapper>

+ 6 - 0
offline-module/pom.xml

@@ -24,6 +24,12 @@
             <version>1.0-SNAPSHOT</version>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>com.tzld.piaoquan</groupId>
+            <artifactId>api-module</artifactId>
+            <version>1.0-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 
     <build>

+ 74 - 0
offline-module/src/main/java/com/tzld/piaoquan/offline/job/ContentPlatformVideoJob.java

@@ -0,0 +1,74 @@
+package com.tzld.piaoquan.offline.job;
+
+import com.aliyun.odps.data.Record;
+import com.tzld.piaoquan.api.dao.mapper.contentplatform.ContentPlatformVideoMapper;
+import com.tzld.piaoquan.api.dao.mapper.contentplatform.ext.ContentPlatformPlanMapperExt;
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideo;
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideoExample;
+import com.tzld.piaoquan.growth.common.utils.DateUtil;
+import com.tzld.piaoquan.growth.common.utils.OdpsUtil;
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Slf4j
+@Component
+public class ContentPlatformVideoJob {
+
+    @Autowired
+    private ContentPlatformPlanMapperExt planMapperExt;
+
+    @Autowired
+    private ContentPlatformVideoMapper videoMapper;
+
+    @XxlJob("syncContentPlatformVideoJob")
+    public ReturnT<String> syncContentPlatformVideoJob(String param) {
+        String dt = DateUtil.getBeforeDayDateString();
+        long videoCount = getVideoCount(dt);
+        if (videoCount > 0) {
+            return ReturnT.SUCCESS;
+        }
+        String sql = String.format("SELECT * FROM loghubods.wecom_cooperation_video_candidate_pool WHERE dt=%s;", dt);
+        List<Record> dataList = OdpsUtil.getOdpsData(sql);
+        Long now = System.currentTimeMillis();
+        if (CollectionUtils.isNotEmpty(dataList)) {
+            List<ContentPlatformVideo> saveList = new ArrayList<>();
+            for (Record record : dataList) {
+                ContentPlatformVideo item = new ContentPlatformVideo();
+                Long videoId = Long.parseLong((String) record.get(0));
+                String category = (String) record.get(1);
+                String title = (String) record.get(2);
+                String videoUrl = (String) record.get(3);
+                Double score = Double.parseDouble((String) record.get(4));
+                item.setDt(dt);
+                item.setVideoId(videoId);
+                item.setCategory(category);
+                item.setTitle(title);
+                item.setVideo(videoUrl);
+                item.setScore(score);
+                item.setCreateTimestamp(now);
+                saveList.add(item);
+            }
+            if (CollectionUtils.isNotEmpty(saveList)) {
+                planMapperExt.batchInsertContentPlatformVideo(saveList);
+            }
+        }
+        return ReturnT.SUCCESS;
+    }
+
+    private long getVideoCount(String dt) {
+        ContentPlatformVideoExample example = new ContentPlatformVideoExample();
+        example.createCriteria().andDtEqualTo(dt);
+        return videoMapper.countByExample(example);
+    }
+
+}
+
+
+