Browse Source

智投助手定时任务

zhaotx 8 months ago
parent
commit
82a3238b91

+ 0 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/controller/FeishuController.java

@@ -64,7 +64,6 @@ public class FeishuController {
     public void test(@RequestBody String str) throws Exception {
         ztPolicyRunService.test();
 
-
     }
 
     private void sendFs(){

+ 1 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/entity/ZtPolicy.java

@@ -25,7 +25,7 @@ public class ZtPolicy {
     private Integer isDeleted;
 
     //托管目标过滤条件
-    private Integer businessLine;
+    private List<Integer> businessLine;
     private String businessLineName;
     private List<String> appId;
     private List<String> appName;

+ 30 - 2
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/ZtPolicyMapper.java

@@ -15,9 +15,9 @@ public interface ZtPolicyMapper {
     List<ZtPolicyTargetIds> getTargetIds(@Param("policyId") Long policyId);
 
     @DS("selectdb")
-    List<String> advFilterList(
+    List<JSONObject> advFilterList(
                                @Param("appId") List<String> appId,
-                               @Param("businessLine") Integer businessLine,
+                               @Param("businessLine") List<Integer> businessLine,
                                @Param("businessMethod") List<String> businessMethod,
                                @Param("optimizerId") List<Long> optimizerId,
                                @Param("deptId") List<Long> deptId,
@@ -25,6 +25,26 @@ public interface ZtPolicyMapper {
     );
 
     @DS("selectdb")
+    List<JSONObject> adProjFilterList(
+            @Param("appId") List<String> appId,
+            @Param("businessLine") List<Integer> businessLine,
+            @Param("businessMethod") List<String> businessMethod,
+            @Param("optimizerId") List<Long> optimizerId,
+            @Param("deptId") List<Long> deptId,
+            @Param("movieId") List<String> movieId
+    );
+
+    @DS("selectdb")
+    List<JSONObject> adPromFilterList(
+            @Param("appId") List<String> appId,
+            @Param("businessLine") List<Integer> businessLine,
+            @Param("businessMethod") List<String> businessMethod,
+            @Param("optimizerId") List<Long> optimizerId,
+            @Param("deptId") List<Long> deptId,
+            @Param("movieId") List<String> movieId
+    );
+
+    @DS("selectdb")
     List<String> advListFromAdvIds(@Param("policyId") Long policyId);
     @DS("selectdb")
     List<JSONObject> projectListFromAdvIds(@Param("policyId") Long policyId);
@@ -66,6 +86,14 @@ public interface ZtPolicyMapper {
     int insertActionLog(List<ZtActionLog> list);
 
 
+    List<String> businessLineName(List<Integer> businessLine);
+    List<JSONObject> advertiserTargetNameInfo(List<String> targetIds);
+    @DS("selectdb")
+    List<JSONObject> projectTargetNameInfo(List<String> targetIds);
+    @DS("selectdb")
+    List<JSONObject> promotionTargetNameInfo(List<String> targetIds);
+
+
 
 
 }

+ 166 - 5
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/ZtPolicyMapper.xml

@@ -128,7 +128,7 @@
         from deepthink.zt_policy_target_ids
         where policy_config_id = #{policyId}
     </select>
-    <select id="advFilterList" resultType="java.lang.String">
+    <select id="advFilterList" resultType="com.alibaba.fastjson.JSONObject">
         select distinct tb1.advertiser_id from
         (select ma_appid, advertiser_id
         from application.media_ad_report_daily where stat_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 9 DAY)
@@ -159,8 +159,125 @@
                     #{item}
                 </foreach>
             </if>
-            <if test="businessLine != null and businessLine > 0">
-                and tb3.business_line = #{businessLine}
+            <if test="businessLine != null and businessLine.size > 0">
+                and tb3.business_line in
+                <foreach collection="businessLine" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="optimizerId != null and optimizerId.size > 0">
+                and tb4.user_id in
+                <foreach collection="optimizerId" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="deptId != null and deptId.size > 0">
+                and tb4.dept_id in
+                <foreach collection="deptId" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="movieId != null and movieId.size > 0">
+                and tb6.standard_movie_id in
+                <foreach collection="movieId" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+        </where>
+    </select>
+    <select id="adProjFilterList" resultType="com.alibaba.fastjson.JSONObject">
+        select distinct tb1.advertiser_id, tb1.a_id from
+        (select ma_appid, advertiser_id, a_id
+        from application.media_ad_report_daily where stat_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 9 DAY)
+        group by ma_appid, advertiser_id, a_id
+        having sum(show_num)>0
+        ) tb1
+        join (select advertiser_id, advertiser_name, user_id, ma_appid from tidb.deepthink.advertiser_bind_info) tb2
+        on tb1.advertiser_id = tb2.advertiser_id
+        left join tidb.deepthink.mini_app_info tb3 on tb1.ma_appid = tb3.app_id
+        left join tidb.deepthink.sys_user tb4 on tb2.user_id = tb4.user_id
+        left join (select advertiser_id, movie_id
+        from application.media_ad_report_daily
+        where stat_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 9 DAY)
+        group by advertiser_id, movie_id
+        ) tb5 on tb1.advertiser_id = tb5.advertiser_id
+        left join (select distinct moive_id, standard_movie_id
+        from tidb.deepthink.all_moive) tb6 on tb5.movie_id = tb6.moive_id
+        <where>
+            <if test="appId != null and appId.size > 0">
+                and tb3.app_id in
+                <foreach collection="appId" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="businessMethod != null and businessMethod.size > 0">
+                and tb3.business_method in
+                <foreach collection="businessMethod" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="businessLine != null and businessLine.size > 0">
+                and tb3.business_line in
+                <foreach collection="businessLine" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="optimizerId != null and optimizerId.size > 0">
+                and tb4.user_id in
+                <foreach collection="optimizerId" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="deptId != null and deptId.size > 0">
+                and tb4.dept_id in
+                <foreach collection="deptId" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="movieId != null and movieId.size > 0">
+                and tb6.standard_movie_id in
+                <foreach collection="movieId" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+        </where>
+    </select>
+    <select id="adPromFilterList" resultType="com.alibaba.fastjson.JSONObject">
+        select distinct tb1.advertiser_id, tb1.ad_id from
+        (select ma_appid, advertiser_id, ad_id
+        from application.media_ad_report_daily where stat_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 9 DAY)
+        group by ma_appid, advertiser_id, ad_id
+        having sum(show_num)>0
+        ) tb1
+        join (select advertiser_id, advertiser_name, user_id, ma_appid from tidb.deepthink.advertiser_bind_info) tb2
+        on tb1.advertiser_id = tb2.advertiser_id
+        left join tidb.deepthink.mini_app_info tb3 on tb1.ma_appid = tb3.app_id
+        left join tidb.deepthink.sys_user tb4 on tb2.user_id = tb4.user_id
+        left join (select advertiser_id, movie_id
+        from application.media_ad_report_daily
+        where stat_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 9 DAY)
+        group by advertiser_id, movie_id
+        ) tb5 on tb1.advertiser_id = tb5.advertiser_id
+        left join (select distinct moive_id, standard_movie_id
+        from tidb.deepthink.all_moive) tb6 on tb5.movie_id = tb6.moive_id
+        <where>
+            <if test="appId != null and appId.size > 0">
+                and tb3.app_id in
+                <foreach collection="appId" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="businessMethod != null and businessMethod.size > 0">
+                and tb3.business_method in
+                <foreach collection="businessMethod" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="businessLine != null and businessLine.size > 0">
+                and tb3.business_line in
+                <foreach collection="businessLine" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
             </if>
             <if test="optimizerId != null and optimizerId.size > 0">
                 and tb4.user_id in
@@ -182,6 +299,7 @@
             </if>
         </where>
     </select>
+
     <select id="advListFromAdvIds" resultType="java.lang.String">
         select tb2.advertiser_id
         from tidb.deepthink.zt_policy_target_ids tb1
@@ -261,7 +379,7 @@
                  from application.media_ad_report_hourly
                  where stat_date = #{date}
                  <if test="hour != null and hour > 0">
-                     and `hour``=#{hour}
+                     and `hour`=#{hour}
                  </if>
              </if>
              group by advertiser_id, a_id, ad_id
@@ -276,7 +394,7 @@
                 from application.user_data_report_hourly
                 where stat_date = #{date}
                 <if test="hour != null and hour > 0">
-                    and `hour``=#{hour}
+                    and `hour`=#{hour}
                 </if>
             </if>
             group by advertiser_id, a_id, ad_id
@@ -351,4 +469,47 @@
             #{item}
         </foreach>
     </select>
+    <select id="businessLineName" resultType="java.lang.String">
+        select dict_name
+        from deepthink.dt_dictionary
+        where select_key='business_line'
+        and dict_key in
+        <foreach collection="list" item="item" open="(" close=")" separator=",">
+            #{item}
+        </foreach>
+    </select>
+
+    <select id="advertiserTargetNameInfo" resultType="com.alibaba.fastjson.JSONObject">
+        select advertiser_id as advertiserId, advertiser_name as advertiserName,
+               advertiser_id as targetId, advertiser_name as targetName
+        from deepthink.advertiser_bind_info
+        where advertiser_id in
+        <foreach collection="list" item="item" open="(" close=")" separator=",">
+            #{item}
+        </foreach>
+    </select>
+    <select id="projectTargetNameInfo" resultType="com.alibaba.fastjson.JSONObject">
+        select tb1.advertiser_id as advertiserId, tb2.advertiser_name as advertiserName,
+        a_id as targetId, a_name as targetName
+        from application.media_ad_report_daily tb1
+        left join tidb.deepthink.advertiser_bind_info tb2 on tb1.advertiser_id = tb2.advertiser_id
+        where stat_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 9 DAY)
+        and a_id in
+        <foreach collection="list" item="item" open="(" close=")" separator=",">
+            #{item}
+        </foreach>
+        group by 1,2,3,4
+    </select>
+    <select id="promotionTargetNameInfo" resultType="com.alibaba.fastjson.JSONObject">
+        select tb1.advertiser_id as advertiserId, tb2.advertiser_name as advertiserName,
+        ad_id as targetId, ad_name as targetName
+        from application.media_ad_report_daily
+        left join tidb.deepthink.advertiser_bind_info tb2 on tb1.advertiser_id = tb2.advertiser_id
+        where stat_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 9 DAY)
+        and ad_id in
+        <foreach collection="list" item="item" open="(" close=")" separator=",">
+            #{item}
+        </foreach>
+        group by 1,2,3,4
+    </select>
 </mapper>

+ 78 - 18
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/ZtPolicyRunServiceImpl.java

@@ -42,9 +42,12 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
     ReportsAdPushMapper reportsAdPushMapper;
     public static final String ERROR_HOOK_URL="https://open.feishu.cn/open-apis/bot/v2/hook/a0fcfb57-c053-47bd-b1e7-b826f44841e4";
 
+    public static final String FEISHU_TEMPLATE_ID="AAq2UGaOU2L1l";
+    public static final String FEISHU_TEMPLATE_VERSION="1.0.4";
+
     @Override
     public void test() {
-        run(15L);
+        run(30021L);
     };
 
     @Override
@@ -140,6 +143,8 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
                         Long startDateLong = Long.parseLong(startDate.replaceAll("-", ""));
                         requestParams.put("startDate", startDateLong);
                         requestParams.put("endDate", startDateLong);
+                    }else {
+                        FeishuRobotUtil.sendTextToWebhook("智投助手任务失败:判断条件配置错误,策略ID: "+policyId, ERROR_HOOK_URL);
                     }
                 }else {
                     if (taskTimeType == 11){
@@ -152,6 +157,8 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
                         int H = lastHour.getHour(); // 0-23,不补零
                         requestParams.put("date", date);
                         requestParams.put("hour", H);
+                    }else {
+                        FeishuRobotUtil.sendTextToWebhook("智投助手任务失败:判断条件配置错误,策略ID: "+policyId, ERROR_HOOK_URL);
                     }
                 }
                 for (int index = 0; index < policy.getTargetResIds().size(); ) {
@@ -334,16 +341,42 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
                     continue;
                 }
                 //飞书通知所有的一起发送,但是记录可以分开记录
-                StringBuffer feishuMessageTextSb = new StringBuffer();
-                feishuMessageTextSb.append("智投助手触发预警\n");
-                feishuMessageTextSb.append("触发策略名称:").append(policy.getName()).append("\n");
-                feishuMessageTextSb.append("触发预警广告账号:\n");
-                for (String executeTarget : executeTargetList){
-                    feishuMessageTextSb.append(executeTarget+"\n");
+
+                JSONObject fsTemplateMessage = new JSONObject();
+                List<String> businessLineName = ztPolicyConfigMapper.businessLineName(policy.getBusinessLine());
+                fsTemplateMessage.put("businessLineName", String.join(",", businessLineName));
+                String targetRangeText = "巨量的";
+                if (policy.getManagedDimension() == 1){
+                    targetRangeText += "广告账号";
+                }else if (policy.getManagedDimension() == 2){
+                    targetRangeText += "广告项目";
+                }else if (policy.getManagedDimension() == 3){
+                    targetRangeText += "广告计划";
                 }
-                String fsMessage = feishuMessageTextSb.toString();
-                Integer fsSendType = action.getActionRuleJsonObject().getInteger("fsSendType");//1飞书应用单发 2群机器人
+                fsTemplateMessage.put("targetRangeText", targetRangeText);
+                fsTemplateMessage.put("targetCount", executeTargetList.size());
+                List<String> cText = policy.getConditions().stream().map(ZtPolicyCondition::getDescriptionZh).collect(Collectors.toList());
+                fsTemplateMessage.put("conditions", String.join(",", cText));
+                List<JSONObject> fsExecuteTargetList = new ArrayList<>();
+                //最多发送前一百条
+                List<String> subTargetIds = executeTargetList.subList(0, Math.min(99, executeTargetList.size()));
+                if (policy.getManagedDimension() == 1){
+                    fsExecuteTargetList = ztPolicyConfigMapper.advertiserTargetNameInfo(subTargetIds);
+                }else  if (policy.getManagedDimension() == 2){
+                    fsExecuteTargetList = ztPolicyConfigMapper.projectTargetNameInfo(subTargetIds);
+                }else if (policy.getManagedDimension() == 3){
+                    fsExecuteTargetList = ztPolicyConfigMapper.promotionTargetNameInfo(subTargetIds);
+                }
+
+                fsTemplateMessage.put("executeTargetList", fsExecuteTargetList);
+                fsTemplateMessage.put("policyName", policy.getName());
+                fsTemplateMessage.put("dataDate", DateUtils.getNowDate("yyyy-MM-dd HH:mm:ss"));
+                //todo 这个上线时候要换成线上的!!
+                fsTemplateMessage.put("runActionLogUrl", "http://test.deepthink.artlinkworld.cn/authorization/assistant/triggerRecord?runId="+runId);
+//                fsTemplateMessage.put("runActionLogUrl", "https://deepthink.artlinkworld.cn/authorization/assistant/triggerRecord?runId="+runId);
 
+
+                Integer fsSendType = action.getActionRuleJsonObject().getInteger("fsSendType");//1飞书应用单发 2群机器人
                 recordOperation(policyId, "0", action.getId(), operateFreqCircle);//频控记录
                 if (fsSendType == 1){//单发,发给策略的创建人
                     Long userId = policy.getCreateUserId();
@@ -361,7 +394,12 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
                         if (!phonenumbers.isEmpty()){
                             Map<String, String> phoneUseridMap = FeishuRobotUtil.getFsUserIds(FeishuRobotUtil.getFsZtTenantToken(), phonenumbers);
                             if (phoneUseridMap != null) {
-                                FeishuRobotUtil.sendTextToDt(fsMessage, new ArrayList<>(phoneUseridMap.values()));
+                                String token = FeishuRobotUtil.getFsZtTenantToken();
+                                for (String fsUserId: phoneUseridMap.values()){
+                                    FeishuRobotUtil.sendTemplateMessageToFeishuUser(FEISHU_TEMPLATE_ID, FEISHU_TEMPLATE_VERSION,
+                                            token, fsTemplateMessage, fsUserId
+                                            );
+                                }
                                 recordActionSuccess(actionLog);
                             }else {
                                 recordActionError(actionLog, "未找到飞书用户ID信息");
@@ -376,14 +414,13 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
                         }
                         recordActionError(actionLog, message);
                     }
-                    // 整理这里可能遇到的错误点,写入action_log
 
                 }else {
                     // 频次、时间段拦截, 频次拦截key: policyId_targetId
                     List<String> fsHookUrls = action.getActionRuleJsonObject().getJSONArray("fsHookUrls").toJavaList(String.class);
                     for (String hookUrl : fsHookUrls){
                         try {
-                            FeishuRobotUtil.sendTextToWebhook(fsMessage, hookUrl);
+                            FeishuRobotUtil.sendTemplateMessageToFeishuWebhook(FEISHU_TEMPLATE_ID, FEISHU_TEMPLATE_VERSION, fsTemplateMessage, hookUrl);
                             recordActionSuccess(actionLog);
                         }catch (Exception e){
                             String message = e.getMessage();
@@ -548,7 +585,7 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
         ZtPolicy policy = null;
         if (policyId != null){
             policy = ztPolicyConfigMapper.getPolicyDetail(policyId);
-            if (policy.getManagedDimension()==1 && policy.getTargetScope()==1){
+            if (policy.getTargetScope()==1){
                 List<ZtPolicyTargetFilter> filterList = ztPolicyConfigMapper.getTargetFilters(policyId);
                 Map<Integer, List<ZtPolicyTargetFilter>> scopeFilterMap =
                         filterList.stream().collect(Collectors.groupingBy(ZtPolicyTargetFilter::getFilterKey));
@@ -558,8 +595,7 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
                     if (key == 1){
                         policy.setAppId(value.stream().map(ZtPolicyTargetFilter::getFilterValue).collect(Collectors.toList()));
                     }else if (key == 2){
-                        Integer businessLine = Integer.parseInt(value.get(0).getFilterValue());
-                        policy.setBusinessLine(businessLine);
+                        policy.setBusinessLine(value.stream().map(f -> Integer.valueOf(f.getFilterValue())).collect(Collectors.toList()));
                     }else if (key == 3){
                         policy.setBusinessMethod(value.stream().map(ZtPolicyTargetFilter::getFilterValue).collect(Collectors.toList()));
                     }else if (key == 4){
@@ -575,9 +611,33 @@ public class ZtPolicyRunServiceImpl implements IZtPolicyRunService {
                     }
                 }
 
-                List<String> resIds = ztPolicyConfigMapper.advFilterList(policy.getAppId(), policy.getBusinessLine(),
-                        policy.getBusinessMethod(), policy.getOptimizerId(), policy.getDeptId(), policy.getMovieId());
-                policy.setTargetResIds(resIds);
+                Map<String, String> targetFromAdvertiserId = new HashMap<>();
+                List<String> rList = new ArrayList<>();
+                List<JSONObject> resIds = Collections.emptyList();
+                if (policy.getManagedDimension() == 1){
+                    resIds = ztPolicyConfigMapper.advFilterList(policy.getAppId(), policy.getBusinessLine(),
+                            policy.getBusinessMethod(), policy.getOptimizerId(), policy.getDeptId(), policy.getMovieId());
+                    for (JSONObject resId : resIds) {
+                        rList.add(resId.getString("advertiser_id"));
+                        targetFromAdvertiserId.put(resId.getString("advertiser_id"), resId.getString("advertiser_id"));
+                    }
+                }else if (policy.getManagedDimension() == 2){
+                    resIds = ztPolicyConfigMapper.adProjFilterList(policy.getAppId(), policy.getBusinessLine(),
+                            policy.getBusinessMethod(), policy.getOptimizerId(), policy.getDeptId(), policy.getMovieId());
+                    for (JSONObject resId : resIds) {
+                        rList.add(resId.getString("a_id"));
+                        targetFromAdvertiserId.put(resId.getString("a_id"), resId.getString("advertiser_id"));
+                    }
+                }else  if (policy.getManagedDimension() == 3){
+                    resIds = ztPolicyConfigMapper.adPromFilterList(policy.getAppId(), policy.getBusinessLine(),
+                            policy.getBusinessMethod(), policy.getOptimizerId(), policy.getDeptId(), policy.getMovieId());
+                    for (JSONObject resId : resIds) {
+                        rList.add(resId.getString("ad_id"));
+                        targetFromAdvertiserId.put(resId.getString("ad_id"), resId.getString("advertiser_id"));
+                    }
+                }
+                policy.setTargetResIds(rList);
+                policy.setTargetFromAdvertiserId(targetFromAdvertiserId);
             }else {
                 List<ZtPolicyTargetIds> ids =  ztPolicyConfigMapper.getTargetIds(policyId);
                 policy.setTargetScopeIds(ids.stream().map(ZtPolicyTargetIds::getTargetId).collect(Collectors.toList()));

+ 82 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/utils/FeishuRobotUtil.java

@@ -5,6 +5,7 @@ import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.http.HttpEntity;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
@@ -19,6 +20,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+@Slf4j
 public class FeishuRobotUtil {
 
     public static final String fs_zt_appid = "cli_a75d0ab0f538100e"; //智投助手应用
@@ -251,4 +253,84 @@ public class FeishuRobotUtil {
         }
 
     }
+
+    public static void sendTemplateMessageToFeishuUser(String templateId, String templateVersion, String token, JSONObject template_variable, String receive_id) {
+        JSONObject content = new JSONObject();
+        JSONObject contentData = new JSONObject();
+        contentData.put("template_id",templateId);
+        contentData.put("template_version_name", templateVersion);
+        contentData.put("template_variable", template_variable);
+        content.put("type", "template");
+        content.put("data", contentData);
+
+        JSONObject request = new JSONObject();
+        request.put("receive_id", receive_id);
+        request.put("msg_type", "interactive");
+        request.put("content", content.toJSONString());
+        //发送
+        try (CloseableHttpClient client = HttpClients.createDefault()){
+            HttpPost httpPost = new HttpPost("https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=user_id");
+            httpPost.setHeader("Authorization", "Bearer "+token);
+            HttpEntity entity = new StringEntity(request.toJSONString(), "UTF-8");
+            httpPost.setEntity(entity);
+            httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
+            CloseableHttpResponse respon = client.execute(httpPost);
+            System.out.println("发送结果: "+ EntityUtils.toString(respon.getEntity(), "UTF-8"));
+        }catch (IOException e){
+            log.error("发送飞书消息失败", e);
+        }
+    }
+
+    public static void sendTemplateMessageToFeishuChatGroup(String templateId, String templateVersion, String token, JSONObject template_variable, String chatid) {
+        JSONObject content = new JSONObject();
+        JSONObject contentData = new JSONObject();
+        contentData.put("template_id",templateId);
+        contentData.put("template_version_name", templateVersion);
+        contentData.put("template_variable", template_variable);
+        content.put("type", "template");
+        content.put("data", contentData);
+
+        JSONObject request = new JSONObject();
+        request.put("receive_id", chatid);
+        request.put("msg_type", "interactive");
+        request.put("content", content.toJSONString());
+        //发送
+        try (CloseableHttpClient client = HttpClients.createDefault()){
+            HttpPost httpPost = new HttpPost("https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=chat_id");
+            httpPost.setHeader("Authorization", "Bearer "+token);
+            HttpEntity entity = new StringEntity(request.toJSONString(), "UTF-8");
+            httpPost.setEntity(entity);
+            httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
+            CloseableHttpResponse respon = client.execute(httpPost);
+            System.out.println("发送结果: "+ EntityUtils.toString(respon.getEntity(), "UTF-8"));
+        }catch (IOException e){
+            log.error("发送飞书消息失败", e);
+        }
+    }
+
+    public static void sendTemplateMessageToFeishuWebhook(String templateId, String templateVersion, JSONObject template_variable, String hookUrl) {
+        JSONObject content = new JSONObject();
+        JSONObject contentData = new JSONObject();
+        contentData.put("template_id",templateId);
+        contentData.put("template_version_name", templateVersion);
+        contentData.put("template_variable", template_variable);
+        content.put("type", "template");
+        content.put("data", contentData);
+
+
+        JSONObject request = new JSONObject();
+        request.put("msg_type", "interactive");
+        request.put("card", content.toJSONString());
+        //发送
+        try (CloseableHttpClient client = HttpClients.createDefault()){
+            HttpPost httpPost = new HttpPost(hookUrl);
+            HttpEntity entity = new StringEntity(request.toJSONString(), "UTF-8");
+            httpPost.setEntity(entity);
+            httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
+            CloseableHttpResponse respon = client.execute(httpPost);
+            System.out.println("发送结果: "+ EntityUtils.toString(respon.getEntity(), "UTF-8"));
+        }catch (IOException e){
+            log.error("发送飞书消息失败", e);
+        }
+    }
 }

+ 6 - 4
job-bytedance/src/main/resources/application.yml

@@ -85,7 +85,9 @@ spring:
         master:
           url: jdbc:mysql://172.16.0.117:3390/media_api?characterEncoding=UTF-8&useUnicode=true&useSSL=false
 #          url: jdbc:mysql://8.147.135.80:3390/media_api?characterEncoding=UTF-8&useUnicode=true&allowMultiQueries=true&useSSL=false
+#          url: jdbc:mysql://123.57.9.211:3306/media_api?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2B8&useSSL=false
           username: yanfa
+#          username: root
           password: hr@2025..
           driver-class-name: com.mysql.jdbc.Driver
         selectdb:
@@ -159,10 +161,10 @@ mybatis-plus:
       # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
     #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
 
-#logging:
-#  level:
-#    root: info
-#  config: classpath:logback-dev.xml
+logging:
+  level:
+    cn.com.ctop.job.bytedance: debug
+    org.springframework: warn
 
 xxl:
   job: