Ver código fonte

1.7.5认证通视频查询优化

JiangChongBo 2 anos atrás
pai
commit
e14e9e096a

+ 1 - 0
src/main/java/com/caimei/AdminApplication.java

@@ -10,6 +10,7 @@ import org.springframework.context.annotation.EnableMBeanExport;
 import org.springframework.context.annotation.Import;
 import org.springframework.jmx.support.RegistrationPolicy;
 import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
 import javax.servlet.MultipartConfigElement;
 

+ 8 - 1
src/main/java/com/caimei/controller/admin/auth/AuthApi.java

@@ -837,4 +837,11 @@ public class AuthApi {
     public ResponseJson<ChallengeRoundVo> getInfoById(Integer videoId) {
         return authService.getInfoById(videoId);
     }
-}
+    @GetMapping("/getDyVidoInfo")
+    public ResponseJson getDyVidoInfo(@CurrentUser SysUser sysUser){
+        Integer userIdentity = sysUser.getUserIdentity();
+        Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null;
+        return authService.getDyVidoInfo(authUserId);
+    }
+
+    }

+ 4 - 0
src/main/java/com/caimei/mapper/cmMapper/AuthMapper.java

@@ -173,4 +173,8 @@ public interface AuthMapper {
     void upStatusById(Integer id);
 
     String getReleaseTime(@Param("userName")String userName );
+
+    List<ChallengeRoundVo> getRoundlist();
+
+    void upVidoInfoById(Integer videoId,@Param("diggCount")String diggCount,@Param("playCount") String playCount);
 }

+ 3 - 1
src/main/java/com/caimei/service/auth/AuthService.java

@@ -296,4 +296,6 @@ public interface AuthService {
      */
      ResponseJson<ChallengeRoundVo> getInfoById(Integer videoId);
 
-}
+     ResponseJson getDyVidoInfo(Integer authUserId);
+
+    }

+ 92 - 4
src/main/java/com/caimei/service/auth/impl/AuthServiceImpl.java

@@ -3,6 +3,7 @@ package com.caimei.service.auth.impl;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.caimei.annotation.CurrentUser;
 import com.caimei.components.RedisService;
 import com.caimei.config.FastDfsClient;
 import com.caimei.mapper.cmMapper.AuthMapper;
@@ -31,6 +32,7 @@ import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.utils.URIBuilder;
 import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
 import org.apache.http.entity.mime.MultipartEntityBuilder;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
@@ -1144,6 +1146,44 @@ public class AuthServiceImpl implements AuthService {
         return resultList;
     }
 
+    /**
+     * 根据item_id获取单个(多个)视频信息
+     * @param openId
+     * @param accessToken
+     * itemId 多个用,隔开
+     * @return
+     */
+    public String getVideoDataByItemId(String openId, String accessToken,String itemId) {
+        String requestUrl = "https://open.douyin.com/video/data/?open_id="+openId;
+        CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
+        HttpPost hp = new HttpPost(requestUrl);
+        hp.addHeader("access-token", accessToken);
+        hp.addHeader("Content-Type", "application/json");
+//        List<NameValuePair> list = new ArrayList<>();
+//        list.add(new BasicNameValuePair("item_ids",jsonArray.toString()));
+//        JSONObject json = new JSONObject();
+//        json.put("item_ids",itemId);
+//        json.put("item_ids",itemid1);
+        //   "{\"item_ids\":[\"@9VwTweWaBd0jMWGuNYwqEc791GHuNf6KPZx5qgiiLVQbbvf860zdRmYqig357zEBpu0x/J8bThza3PQPj7FY1Q==\"]}"
+        String s="{\"item_ids\":["+"\""+itemId+"\""+"]}";
+        hp.setEntity(new StringEntity(s,"UTF-8"));
+        String datastr=null;
+        try {
+            CloseableHttpResponse execute = closeableHttpClient.execute(hp);
+            HttpEntity entity = execute.getEntity();
+            String result = EntityUtils.toString(entity, StandardCharsets.UTF_8);
+            JSONObject params=JSONObject.parseObject(result);
+            datastr=params.getString("data");
+//            JSONObject data=JSONObject.parseObject(datastr);
+//            String list=data.getString("list");
+//            System.out.println(list);
+            EntityUtils.consume(entity);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return datastr;
+    }
+
     /**
      * 生成随机数
      *
@@ -1279,7 +1319,7 @@ public class AuthServiceImpl implements AuthService {
         }
         List<ChallengeRoundVo> publishedVideoListNoRanking = authMapper.getPublishedVideoListNoRanking(clubUserName, status, authUserId, activityTime.getStartTime(), activityTime.getEndTime());
        //获取不排名的数据
-        if(publishedVideoListNoRanking.size()>0){
+        if(publishedVideoListNoRanking.size()>0&&listChallengeRoundVo.size()>0){
            for (ChallengeRoundVo noRanking:publishedVideoListNoRanking) {
                noRanking.setRankingStatus(0);
                if(StringUtils.isEmpty(noRanking.getDiggCount())){
@@ -1290,7 +1330,18 @@ public class AuthServiceImpl implements AuthService {
                }
                collect.add(noRanking);
            }
-       }
+       }else{
+            for (ChallengeRoundVo noRanking:publishedVideoListNoRanking) {
+                noRanking.setRankingStatus(1);
+                if(StringUtils.isEmpty(noRanking.getDiggCount())){
+                    noRanking.setDiggCount("0");
+                }
+                if(StringUtils.isEmpty(noRanking.getPlayCount())){
+                    noRanking.setPlayCount("0");
+                }
+                collect.add(noRanking);
+            }
+        }
         PageInfo<ChallengeRoundVo> pageDa = new PageInfo<>(collect);
         return ResponseJson.success(pageDa);
     }
@@ -1373,7 +1424,7 @@ public class AuthServiceImpl implements AuthService {
         //获取不排名的数据
         List<ChallengeRoundVo> publishedVideoListNoRanking = authMapper.getPublishedVideoNoRanking(mobile,authParty,status,authUserId,activityTime.getStartTime(),activityTime.getEndTime());
         //获取不排名的数据
-        if(publishedVideoListNoRanking.size()>0){
+        if(publishedVideoListNoRanking.size()>0&&listChallengeRoundVo.size()>0){
             for (ChallengeRoundVo noRanking:publishedVideoListNoRanking) {
                 noRanking.setRankingStatus(0);
                 if(StringUtils.isEmpty(noRanking.getDiggCount())){
@@ -1384,6 +1435,17 @@ public class AuthServiceImpl implements AuthService {
                 }
                 collect.add(noRanking);
             }
+        }else{
+            for (ChallengeRoundVo noRanking:publishedVideoListNoRanking) {
+                noRanking.setRankingStatus(1);
+                if(StringUtils.isEmpty(noRanking.getDiggCount())){
+                    noRanking.setDiggCount("0");
+                }
+                if(StringUtils.isEmpty(noRanking.getPlayCount())){
+                    noRanking.setPlayCount("0");
+                }
+                collect.add(noRanking);
+            }
         }
         return ResponseJson.success(pageDa);
     }
@@ -1706,5 +1768,31 @@ public class AuthServiceImpl implements AuthService {
     public ResponseJson<ChallengeRoundVo> getInfoById(Integer videoId) {
         return ResponseJson.success(authMapper.getChallengeRoundInfo(videoId));
     }
-
+    @Override
+    public ResponseJson getDyVidoInfo(Integer authUserId){
+        // 获取供应商用户id
+//        Integer userIdentity = sysUser.getUserIdentity();
+//        Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null;
+        String dyopenId=null;
+        String DYaccessToken=null;
+        if(redisService.getExpireTime("DyopenId")>0&&redisService.getExpireTime("DYaccessToken")>0){
+            dyopenId=redisService.get("DyopenId").toString();
+            DYaccessToken=redisService.get("DYaccessToken").toString();
+        }
+        //获取供应商下面所有机构发的视频
+        List<ChallengeRoundVo> roundlist = authMapper.getRoundlist();
+        //根据item_id更新视频数据(点赞量,播放量)
+        for (ChallengeRoundVo chall:roundlist) {
+            String data = getVideoDataByItemId(dyopenId, DYaccessToken, chall.getItemId());
+            JSONObject paramslist = JSONObject.parseObject(data);
+            String resultList=paramslist.getString("list");
+            List<DyVideoInfoVo> listDyVideoInfoVo= JSONArray.parseArray(resultList, DyVideoInfoVo.class);
+            if(listDyVideoInfoVo!=null&&listDyVideoInfoVo.size()>0){
+                StatisticsVo StatisticsVo= JSONObject.parseObject(listDyVideoInfoVo.get(0).getStatistics(), StatisticsVo.class);
+                //更新视频数据到数据库
+                authMapper.upVidoInfoById(chall.getId(),StatisticsVo.getDigg_count(),StatisticsVo.getPlay_count());
+            }
+        }
+        return ResponseJson.success();
+    }
 }

+ 68 - 0
src/main/java/com/caimei/task/DyInfoTask.java

@@ -0,0 +1,68 @@
+package com.caimei.task;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.caimei.annotation.CurrentUser;
+import com.caimei.components.RedisService;
+import com.caimei.mapper.cmMapper.AuthMapper;
+import com.caimei.model.po.SysUser;
+import com.caimei.model.vo.ChallengeRoundVo;
+import com.caimei.model.vo.DyVideoInfoVo;
+import com.caimei.model.vo.StatisticsVo;
+import com.caimei.service.auth.impl.AuthServiceImpl;
+import lombok.AllArgsConstructor;
+import lombok.NoArgsConstructor;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Slf4j
+@Configuration
+@EnableScheduling
+@NoArgsConstructor
+@AllArgsConstructor
+public class DyInfoTask {
+    @Resource
+    private RedisService redisService;
+
+    @Resource
+    private AuthMapper authMapper;
+
+    @Resource
+    private AuthServiceImpl authServiceImpl;
+
+    @Scheduled(cron = "0 0 2 * * ?")
+    public void getDyVidoInfo(){
+        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>开始执行,ldmLatestClubId:" );
+        // 获取供应商用户id
+//        Integer userIdentity = sysUser.getUserIdentity();
+//        Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null;
+        String dyopenId=null;
+        String DYaccessToken=null;
+        if(redisService.getExpireTime("DyopenId")>0&&redisService.getExpireTime("DYaccessToken")>0){
+            dyopenId=redisService.get("DyopenId").toString();
+            DYaccessToken=redisService.get("DYaccessToken").toString();
+        }
+        //获取供应商下面所有机构发的视频
+        List<ChallengeRoundVo> roundlist = authMapper.getRoundlist();
+        //根据item_id更新视频数据(点赞量,播放量)
+        for (ChallengeRoundVo chall:roundlist) {
+            String data = authServiceImpl.getVideoDataByItemId(dyopenId, DYaccessToken, chall.getItemId());
+            JSONObject paramslist = JSONObject.parseObject(data);
+            String resultList=paramslist.getString("list");
+            List<DyVideoInfoVo> listDyVideoInfoVo= JSONArray.parseArray(resultList, DyVideoInfoVo.class);
+            if(listDyVideoInfoVo!=null&&listDyVideoInfoVo.size()>0){
+                StatisticsVo StatisticsVo= JSONObject.parseObject(listDyVideoInfoVo.get(0).getStatistics(), StatisticsVo.class);
+                //更新视频数据到数据库
+                authMapper.upVidoInfoById(chall.getId(),StatisticsVo.getDigg_count(),StatisticsVo.getPlay_count());
+            }
+        }
+    }
+}

+ 16 - 6
src/main/resources/mapper/AuthMapper.xml

@@ -657,7 +657,7 @@
         where startTime  &lt;#{releaseTime}  and  endTime &gt;#{releaseTime} and status=1
     </select>
     <select id="getPublishedVideoList" resultType="com.caimei.model.vo.ChallengeRoundVo">
-        select cr.id,cr.userName,cr.itemId,cr.title,cr.ossName,cr.ossUrl,cr.cover,cr.releaseTime,cr.status,cr.shareId,cr.authId,cba.authParty,cr.dyCommand
+        select cr.id,cr.userName,cr.itemId,cr.title,cr.ossName,cr.ossUrl,cr.cover,cr.releaseTime,cr.status,cr.shareId,cr.authId,cba.authParty,cr.dyCommand,cr.diggCount,cr.playCount
         from cm_challenge_round cr
         left join cm_brand_auth cba on cr.authId=cba.id
         left join cm_challenge_activity cca on cca.authUserId=cr.authUserId
@@ -669,7 +669,7 @@
        and  cr.releaseTime &gt;#{startTime} and  cr.releaseTime&lt;#{endTime}
     </select>
     <select id="getPublishedVideoListNoRanking" resultType="com.caimei.model.vo.ChallengeRoundVo">
-        select cr.id,cr.userName,cr.itemId,cr.title,cr.ossName,cr.ossUrl,cr.cover,cr.releaseTime,cr.status,cr.shareId,cr.authId,cba.authParty,cr.dyCommand
+        select cr.id,cr.userName,cr.itemId,cr.title,cr.ossName,cr.ossUrl,cr.cover,cr.releaseTime,cr.status,cr.shareId,cr.authId,cba.authParty,cr.dyCommand,cr.diggCount,cr.playCount
         from cm_challenge_round cr
         left join cm_brand_auth cba on cr.authId=cba.id
         left join cm_challenge_activity cca on cca.authUserId=cr.authUserId
@@ -681,7 +681,7 @@
         and  (cr.releaseTime &lt;#{startTime} or  cr.releaseTime &gt;#{endTime})
     </select>
     <select id="getPublishedVideo" resultType="com.caimei.model.vo.ChallengeRoundVo">
-        select cr.id,cr.userName,cr.itemId,cr.title,cr.ossName,cr.ossUrl,cr.cover,cr.releaseTime,cr.status,cr.shareId,cr.authId,cba.authParty,cr.dyCommand
+        select cr.id,cr.userName,cr.itemId,cr.title,cr.ossName,cr.ossUrl,cr.cover,cr.releaseTime,cr.status,cr.shareId,cr.authId,cba.authParty,cr.dyCommand,cr.diggCount,cr.playCount
         from cm_challenge_round cr
         left join cm_brand_auth cba on cr.authId=cba.id
         left join cm_challenge_activity cca on cca.authUserId=cr.authUserId
@@ -698,7 +698,7 @@
         </if>
     </select>
     <select id="getPublishedVideoNoRanking" resultType="com.caimei.model.vo.ChallengeRoundVo">
-        select cr.id,cr.userName,cr.itemId,cr.title,cr.ossName,cr.ossUrl,cr.cover,cr.releaseTime,cr.status,cr.shareId,cr.authId,cba.authParty,cr.dyCommand
+        select cr.id,cr.userName,cr.itemId,cr.title,cr.ossName,cr.ossUrl,cr.cover,cr.releaseTime,cr.status,cr.shareId,cr.authId,cba.authParty,cr.dyCommand,cr.diggCount,cr.playCount
         from cm_challenge_round cr
         left join cm_brand_auth cba on cr.authId=cba.id
         left join cm_challenge_activity cca on cca.authUserId=cr.authUserId
@@ -767,7 +767,7 @@
         where authId=#{authId}
     </update>
     <select id="getAuthPartylist" resultType="com.caimei.model.vo.ChallengeRoundVo">
-        select cr.id,cr.userName,cr.itemId,cr.title,cr.ossName,cr.ossUrl,cr.cover,cr.releaseTime,cr.status,cr.shareId, cr.authId,cba.authParty,cr.dyCommand
+        select cr.id,cr.userName,cr.itemId,cr.title,cr.ossName,cr.ossUrl,cr.cover,cr.releaseTime,cr.status,cr.shareId, cr.authId,cba.authParty,cr.dyCommand,cr.diggCount,cr.playCount
         from cm_challenge_round cr left join cm_brand_auth cba
         on cr.authId=cba.id
         where cr.authUserId=#{authUserId}
@@ -783,7 +783,7 @@
         where id = #{videoID}
     </delete>
     <select id="getChallengeRoundInfo" resultType="com.caimei.model.vo.ChallengeRoundVo">
-        select cr.id,cr.userName,cr.itemId,cr.title,cr.ossName,cr.ossUrl,cr.cover,cr.releaseTime,cr.status,cr.shareId, cr.authId,cr.dyCommand
+        select cr.id,cr.userName,cr.itemId,cr.title,cr.ossName,cr.ossUrl,cr.cover,cr.releaseTime,cr.status,cr.shareId, cr.authId,cr.dyCommand,cr.diggCount,cr.playCount
         from cm_challenge_round cr
         where cr.id=#{videoID}
     </select>
@@ -797,4 +797,14 @@
         from cm_challenge_round cr
         where cr.userName=#{userName}
     </select>
+    <select id="getRoundlist" resultType="com.caimei.model.vo.ChallengeRoundVo">
+        select cr.id,cr.userName,cr.itemId,cr.title,cr.ossName,cr.ossUrl,cr.cover,cr.releaseTime,cr.status,cr.shareId, cr.authId,cr.dyCommand,cr.diggCount,cr.playCount
+        from cm_challenge_round cr
+    </select>
+    <update id="upVidoInfoById">
+        update cm_challenge_round set
+            diggCount=#{diggCount},
+            playCount=#{playCount}
+        where id=#{videoId}
+    </update>
 </mapper>