KuaishouLaunchCreativeServiceImpl.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package com.ruixuan.launch.service.impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.ruixuan.common.core.domain.ResultResponse;
  4. import com.ruixuan.common.utils.Check;
  5. import com.ruixuan.common.utils.DateUtils;
  6. import com.ruixuan.common.utils.KuaishouAPIConstant;
  7. import com.ruixuan.launch.entity.KuaishouLaunchCreative;
  8. import com.ruixuan.launch.entity.KuaishouLaunchCreativeRecord;
  9. import com.ruixuan.launch.mapper.KuaishouLaunchCreativeMapper;
  10. import com.ruixuan.launch.mapper.KuaishouLaunchCreativeRecordMapper;
  11. import com.ruixuan.launch.service.IKuaishouLaunchCreativeService;
  12. import com.ruixuan.launch.unitls.APIUtil;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.UUID;
  20. /**
  21. * 广告创意信息Service业务层处理
  22. *
  23. * @author ruoyi
  24. * @date 2022-07-05
  25. */
  26. @Slf4j
  27. @Service
  28. public class KuaishouLaunchCreativeServiceImpl implements IKuaishouLaunchCreativeService {
  29. @Autowired
  30. private KuaishouLaunchCreativeMapper kuaishouLaunchCreativeMapper;
  31. @Autowired
  32. private KuaishouLaunchCreativeRecordMapper kuaishouLaunchCreativeRecordMapper;
  33. /**
  34. * 查询广告创意信息
  35. *
  36. * @param id 广告创意信息主键
  37. * @return 广告创意信息
  38. */
  39. @Override
  40. public KuaishouLaunchCreative selectKuaishouLaunchCreativeById(String id) {
  41. return kuaishouLaunchCreativeMapper.selectKuaishouLaunchCreativeById(id);
  42. }
  43. /**
  44. * 查询广告创意信息列表
  45. *
  46. * @param kuaishouLaunchCreative 广告创意信息
  47. * @return 广告创意信息
  48. */
  49. @Override
  50. public List<KuaishouLaunchCreative> selectKuaishouLaunchCreativeList(KuaishouLaunchCreative kuaishouLaunchCreative) {
  51. return kuaishouLaunchCreativeMapper.selectKuaishouLaunchCreativeList(kuaishouLaunchCreative);
  52. }
  53. /**
  54. * 新增广告创意信息
  55. */
  56. @Override
  57. public ResultResponse insertKuaishouLaunchCreative(JSONObject requestJson, String token) {
  58. Map<String, Object> param = new HashMap<String, Object>();
  59. param.put("advertiser_id", requestJson.getLong("accountId"));
  60. param.put("unit_id", requestJson.getLong("unitId"));
  61. param.put("name", requestJson.getString("creativeName"));
  62. Integer liveCreativeType = requestJson.getInteger("liveCreativeType");
  63. if (Check.isNotNull(liveCreativeType) && liveCreativeType == 1) {
  64. param.put("cover_url", "");
  65. param.put("cover_width", 0);
  66. param.put("cover_height", 0);
  67. param.put("photo_id", 0);
  68. param.put("creative_material_type", 0);
  69. param.put("action_bar", "");
  70. param.put("description", "");
  71. } else {
  72. param.put("cover_url", requestJson.getString("coverUrl"));
  73. param.put("cover_width", requestJson.getLong("coverWidth"));
  74. param.put("cover_height", requestJson.getLong("coverHeight"));
  75. param.put("photo_id", requestJson.getLong("photoId"));
  76. param.put("creative_material_type", requestJson.getInteger("creativeMaterialType"));
  77. param.put("action_bar", requestJson.getString("actionBar"));
  78. param.put("description", requestJson.getString("description"));
  79. }
  80. if (Check.isNotNull(requestJson.getString("recommendation"))) {
  81. param.put("recommendation", requestJson.getString("recommendation"));
  82. }
  83. if (Check.isNotNull(liveCreativeType)) {
  84. param.put("live_creative_type", liveCreativeType);
  85. }
  86. if (Check.isNotNull(requestJson.getString("newExposeText"))) {
  87. JSONObject newExposeTag = new JSONObject();
  88. newExposeTag.put("text", requestJson.getString("newExposeText"));
  89. newExposeTag.put("url", requestJson.getString("newExposeUrl"));
  90. param.put("new_expose_tag", newExposeTag);
  91. }
  92. Long creativeId = -1L;
  93. KuaishouLaunchCreativeRecord record = JSONObject.parseObject(requestJson.toJSONString(), KuaishouLaunchCreativeRecord.class);
  94. JSONObject result = APIUtil.getApiResult(KuaishouAPIConstant.CREATE_CREATIVE, token, param);
  95. if (result.getInteger("code") == 0) {
  96. result = result.getJSONObject("data");
  97. JSONObject detail = result.getJSONArray("detail").getJSONObject(0);
  98. KuaishouLaunchCreative creative = JSONObject.parseObject(requestJson.toJSONString(), KuaishouLaunchCreative.class);
  99. creativeId = detail.getLong("id");
  100. creative.setCreativeId(creativeId);
  101. creative.setId(UUID.randomUUID().toString().replace("-", ""));
  102. creative.setStatDate(DateUtils.getDate());
  103. kuaishouLaunchCreativeMapper.insertKuaishouLaunchCreative(creative);
  104. record.setMessage("success");
  105. record.setCreativeId(creativeId);
  106. } else {
  107. record.setMessage(result.getString("message"));
  108. log.error("广告创意创建失败,账户{},{}", requestJson.getLong("accountId"), result.toJSONString());
  109. }
  110. record.setStrategyId(requestJson.getLong("id"));
  111. record.setStatDate(DateUtils.getDate());
  112. record.setId(UUID.randomUUID().toString().replace("-", ""));
  113. kuaishouLaunchCreativeRecordMapper.insertKuaishouLaunchCreativeRecord(record);
  114. return ResultResponse.error("创建失败," + result.getString("message"));
  115. }
  116. /**
  117. * 修改广告创意信息
  118. *
  119. * @param kuaishouLaunchCreative 广告创意信息
  120. * @return 结果
  121. */
  122. @Override
  123. public int updateKuaishouLaunchCreative(KuaishouLaunchCreative kuaishouLaunchCreative) {
  124. return kuaishouLaunchCreativeMapper.updateKuaishouLaunchCreative(kuaishouLaunchCreative);
  125. }
  126. }