|
|
@@ -1,156 +0,0 @@
|
|
|
-package cn.com.ctop.job.adq.data.service.impl;
|
|
|
-
|
|
|
-import cn.com.ctop.job.adq.data.mapper.MovieLevelMapper;
|
|
|
-import cn.com.ctop.job.adq.data.service.IMovieLevelService;
|
|
|
-import cn.com.ctop.job.adq.data.utils.Check;
|
|
|
-import cn.com.ctop.job.adq.data.utils.HttpUtils;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.util.List;
|
|
|
-import java.util.concurrent.ExecutorService;
|
|
|
-import java.util.concurrent.Executors;
|
|
|
-
|
|
|
-
|
|
|
-@Service
|
|
|
-@Slf4j
|
|
|
-public class MovieLevelServiceImpl implements IMovieLevelService {
|
|
|
- @Autowired
|
|
|
- private MovieLevelMapper movieLevelMapper;
|
|
|
- private static ExecutorService executorService = Executors.newFixedThreadPool(3);
|
|
|
-
|
|
|
- @Override
|
|
|
- public void sendMovieLevel() {
|
|
|
- List<JSONObject> movieList = movieLevelMapper.getMovieList();
|
|
|
- if (Check.isNull(movieList)) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- for (int i = 0; i < movieList.size(); i++) {
|
|
|
- JSONObject movieJson = movieList.get(i);
|
|
|
- BigDecimal sumCost = movieJson.getBigDecimal("sumCost");
|
|
|
- if (Check.isNull(sumCost)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- Integer diffDay = movieJson.getInteger("diffDay");
|
|
|
- String videoProjectId = movieJson.getString("videoProjectId");
|
|
|
- String videoProjectName = movieJson.getString("videoProjectName");
|
|
|
- Integer source = movieJson.getInteger("source");
|
|
|
- Integer contentType = movieJson.getInteger("contentType");
|
|
|
- String idNo = getIdNo(contentType, source, videoProjectId);
|
|
|
-
|
|
|
- String level = getLevelByCost(sumCost);
|
|
|
- if (Check.isNull(level)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if ("C".equals(level)) {
|
|
|
- if (diffDay < 8) {
|
|
|
- log.info("项目ID:{},评级为c上线时间小于8天,不执行消息发送", videoProjectId);
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (diffDay == 8 || diffDay == 91) { //当上线为第八天和第九十一天时 发送C评级通知
|
|
|
- // 验证是否已发送此评级的消息通知
|
|
|
- boolean isSend = checkLog(videoProjectId, level);
|
|
|
- if (isSend) {
|
|
|
- insertAndSendLog(videoProjectId, idNo, videoProjectName, level, diffDay - 1);
|
|
|
- } else {
|
|
|
- log.info("此评级消息已发送,项目ID:{},评级:{}", videoProjectId, level);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- } else {
|
|
|
- boolean isSend = checkLog(videoProjectId, level);
|
|
|
- if (isSend) {
|
|
|
- insertAndSendLog(videoProjectId, idNo, videoProjectName, level, diffDay);
|
|
|
- } else {
|
|
|
- log.info("此评级消息已发送,项目ID:{},评级:{}", videoProjectId, level);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private synchronized void insertAndSendLog(String videoProjectId, String idNo, String videoProjectName, String level, Integer diffDay) {
|
|
|
- executorService.submit(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- sendMessage(idNo, videoProjectName, level, diffDay);
|
|
|
- }
|
|
|
- });
|
|
|
- movieLevelMapper.insertSendLog(videoProjectId, level);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public void sendMessage(String videoProjectId, String videoProjectName, String level, Integer diffDay) {
|
|
|
- String url = "https://open.feishu.cn/open-apis/bot/v2/hook/d83f0bf7-add8-462b-b5a2-281a5dfa129c";
|
|
|
- JSONObject param = new JSONObject();
|
|
|
- param.put("msg_type", "interactive");
|
|
|
- JSONObject card = new JSONObject();
|
|
|
- card.put("type", "template");
|
|
|
- JSONObject data = new JSONObject();
|
|
|
- data.put("template_id", "AAqvEjmLDN0jG");
|
|
|
- JSONObject template_variable = new JSONObject();
|
|
|
- template_variable.put("videoProjectId", videoProjectId);
|
|
|
- template_variable.put("videoProjectName", videoProjectName);
|
|
|
- template_variable.put("diffDay", diffDay);
|
|
|
- template_variable.put("videoProjectLevel", level);
|
|
|
- data.put("template_variable", template_variable);
|
|
|
- card.put("data", data);
|
|
|
- param.put("card", card);
|
|
|
- String s = HttpUtils.httpPostRequest(url, param, null);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
- log.info("项目评级发送消息返回:{}", jsonObject);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private String getIdNo(Integer contentType, Integer source, String projectId) {
|
|
|
- String idNo = "";
|
|
|
- String prefix = "DJ_";
|
|
|
- if (contentType != null && contentType == 2) {
|
|
|
- prefix = "MJ_";
|
|
|
- }
|
|
|
- //:1-欢瑞自制,2-欢瑞引入,3-爱奇艺分销,4-穿山甲联盟
|
|
|
- if (source == 1) {
|
|
|
- idNo = prefix + "ZZ" + projectId;
|
|
|
- } else if (source == 2) {
|
|
|
- idNo = prefix + "YR" + projectId;
|
|
|
- } else if (source == 3) {
|
|
|
- idNo = prefix + "FX" + projectId;
|
|
|
- } else {
|
|
|
- idNo = prefix + "CSJ" + projectId;
|
|
|
- }
|
|
|
- return idNo;
|
|
|
- }
|
|
|
-
|
|
|
- private boolean checkLog(String videoProjectId, String level) {
|
|
|
- Integer count = movieLevelMapper.checkLog(videoProjectId, level);
|
|
|
- return count == 0;
|
|
|
- }
|
|
|
-
|
|
|
- private static String getLevelByCost(BigDecimal sumCost) {
|
|
|
- if (sumCost.compareTo(new BigDecimal(1000000)) < 0) {
|
|
|
- return "C";
|
|
|
- }
|
|
|
- if (sumCost.compareTo(new BigDecimal(1000000)) >= 0 && sumCost.compareTo(new BigDecimal(2000000)) < 0) {
|
|
|
- return "B";
|
|
|
- }
|
|
|
- if (sumCost.compareTo(new BigDecimal(2000000)) >= 0 && sumCost.compareTo(new BigDecimal(5000000)) < 0) {
|
|
|
- return "B+";
|
|
|
- }
|
|
|
- if (sumCost.compareTo(new BigDecimal(5000000)) >= 0 && sumCost.compareTo(new BigDecimal(8000000)) < 0) {
|
|
|
- return "A";
|
|
|
- }
|
|
|
- if (sumCost.compareTo(new BigDecimal(8000000)) >= 0 && sumCost.compareTo(new BigDecimal(10000000)) < 0) {
|
|
|
- return "A+";
|
|
|
- }
|
|
|
- if (sumCost.compareTo(new BigDecimal(10000000)) >= 0) {
|
|
|
- return "S";
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
-}
|