浏览代码

修改监测链接、出价、定向模板接口接口、获取监测链接接口

yumeng 4 年之前
父节点
当前提交
171bc1f1e0

+ 228 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/DingPanController.java

@@ -0,0 +1,228 @@
+package cn.com.ctop.kuaishou.modules.batch.controller;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCreative;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
+import cn.com.ctop.kuaishou.modules.batch.service.*;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/kuaishou/dingpan")
+public class DingPanController {
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+    @Autowired
+    private IKuaishouInterfaceService interfaceService;
+    @Autowired
+    private IKuaiShouGroupService groupService;
+    @Autowired
+    private IKuaiShouCreativeService creativeService;
+    @Autowired
+    private IBatchService batchService;
+    @Autowired
+    private IKuaiShouUpdateService updateService;
+    @Autowired
+    private IKuaiShouGroupTemplateService groupTemplateService;
+
+    /**
+     * 获取创意监测链接
+     *
+     * @param accountId
+     * @param unitId
+     * @return
+     */
+    @GetMapping(value = "/getClickTrackUrlByUnitId")
+    public Result<String> getClickTrackUrlByUnitId(Long accountId, Long unitId) {
+        Result<String> result = new Result<>();
+        try {
+            if (Check.isNull(accountId)) {
+                throw new Exception("请输入账户id");
+            }
+            if (Check.isNull(unitId)) {
+                throw new Exception("请输入组id");
+            }
+            CtopOauthToken token = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(token)) {
+                throw new Exception("未获取到账户授权信息");
+            }
+            groupService.getCreativeByUnit(token.getAccessToken(), token.getAccountId(), unitId);
+            String clickTrackUr = creativeService.getClickTrackUrl(accountId, unitId);
+            result.setSuccess(true);
+            result.setResult(clickTrackUr);
+
+        } catch (Exception e) {
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
+    /**
+     * 修改监测链接
+     *
+     * @param accountId
+     * @param unitId
+     * @param clickTrackUr
+     * @return
+     */
+    @GetMapping(value = "/updateClickTrackUrlByUnitId")
+    public Result<String> updateClickTrackUrlByUnitId(Long accountId, Long unitId, String clickTrackUr) {
+        Result<String> result = new Result<>();
+        try {
+            if (Check.isNull(accountId)) {
+                throw new Exception("请输入账户id");
+            }
+            if (Check.isNull(unitId)) {
+                throw new Exception("请输入组id");
+            }
+            if (Check.isNull(clickTrackUr)) {
+                throw new Exception("请输入监测链接");
+            }
+            CtopOauthToken token = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(token)) {
+                throw new Exception("未获取到账户授权信息");
+            }
+            List<KuaiShouCreative> creatives = creativeService.getCreativeListByAccountIdAndUnitId(accountId, unitId);
+            if (Check.isNull(creatives)) {
+                throw new Exception("此组下暂无创意");
+            }
+            for (KuaiShouCreative creative : creatives) {
+                JSONObject json = new JSONObject();
+                json.put("creativeId", creative.getCreativeId());
+                if (creative.getCreativeMaterialType() == 1) {
+                    json.put("clickTrackUrl", clickTrackUr);
+                } else if (creative.getCreativeMaterialType() == 4) {
+                    json.put("impressionUrl", clickTrackUr);
+                    json.put("clickTrackUrl", clickTrackUr);
+                }
+                batchService.updateCreative(json, token);
+            }
+            result.setSuccess(true);
+            result.setResult("修改成功");
+        } catch (Exception e) {
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
+    @GetMapping(value = "/updateTemplate")
+    public Result<String> updateTemplate(Long accountId, Long unitId, Long templateId) {
+        Result<String> result = new Result<>();
+        try {
+            if (Check.isNull(accountId)) {
+                throw new Exception("请输入账户id");
+            }
+            if (Check.isNull(unitId)) {
+                throw new Exception("请输入组id");
+            }
+            if (Check.isNull(templateId)) {
+                throw new Exception("请输入模板Id");
+            }
+            CtopOauthToken token = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(token)) {
+                throw new Exception("未获取到账户授权信息");
+            }
+            groupService.getGroupByUnitId(token.getAccessToken(), token.getAccountId(), unitId);
+            KuaiShouGroup kuaiShouGroup = groupService.selectGroupByUnitId(accountId, unitId);
+            if (Check.isNull(kuaiShouGroup)) {
+                throw new Exception("组信息为空");
+            }
+            Integer sceneId = JSONArray.parseArray(kuaiShouGroup.getSceneId()).getInteger(0);
+            JSONObject unitJson = new JSONObject();
+            unitJson.put("advertiser_id", accountId);
+            unitJson.put("unit_id", unitId);
+            if (sceneId != 5) {
+                unitJson.put("template_id", templateId);
+            } else {
+                JSONObject unionJson = groupTemplateService.getUnionJson(templateId);
+                if (Check.isNullMap(unionJson)) {
+                    throw new Exception("根据定向模板未获取到相关信息");
+                }
+                unitJson.put("target", unionJson);
+            }
+            JSONObject jsonObject = updateService.updateUnit(token.getAccessToken(), unitJson);
+            Integer code = jsonObject.getInteger("code");
+            if (code == 0) {
+                result.setSuccess(true);
+                result.setMessage("修改成功");
+            } else {
+                result.setSuccess(false);
+                result.setMessage(jsonObject.getString("message"));
+            }
+        } catch (Exception e) {
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
+    /**
+     * 修改出价
+     *
+     * @param accountId
+     * @param unitId
+     * @param bid
+     * @param bidType
+     * @return
+     */
+    @GetMapping(value = "/updateBid")
+    public Result<String> updateBid(Long accountId, Long unitId, Long bid, Integer bidType) {
+        Result<String> result = new Result<>();
+        try {
+            if (Check.isNull(accountId)) {
+                throw new Exception("请输入账户id");
+            }
+            if (Check.isNull(unitId)) {
+                throw new Exception("请输入组id");
+            }
+            if (Check.isNull(bidType)) {
+                throw new Exception("请输入出价类型");
+            }
+            if (Check.isNull(bid)) {
+                throw new Exception("请输入出价");
+            }
+            CtopOauthToken token = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(token)) {
+                throw new Exception("未获取到账户授权信息");
+            }
+
+            JSONObject unitJson = new JSONObject();
+            unitJson.put("advertiser_id", accountId);
+            unitJson.put("unit_id", unitId);
+            if (bidType == 2) {
+                unitJson.put("bid", bid);
+            } else if (bidType == 10) {
+                unitJson.put("cpa_bid", bid);
+            }
+            JSONObject jsonObject = updateService.updateUnit(token.getAccessToken(), unitJson);
+            Integer code = jsonObject.getInteger("code");
+            if (code == 0) {
+                result.setSuccess(true);
+                result.setMessage("修改成功");
+            } else {
+                result.setSuccess(false);
+                result.setMessage(jsonObject.getString("message"));
+            }
+        } catch (Exception e) {
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
+}

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouCreativeMapper.java

@@ -32,4 +32,6 @@ public interface KuaiShouCreativeMapper extends BaseMapper<KuaiShouCreative> {
     Integer getNewDataByAccountIdAndDate(Long accountId, String statDate);
     Integer getNewDataByAccountIdAndDate(Long accountId, String statDate);
 
 
     Integer getRejectedCountsforAccountId(Long accountId);
     Integer getRejectedCountsforAccountId(Long accountId);
+
+    String getClickTrackUrl(@Param("accountId") Long accountId, @Param("unitId") Long unitId);
 }
 }

+ 8 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouCreativeMapper.xml

@@ -161,5 +161,13 @@
      where  account_id = #{accountId}
      where  account_id = #{accountId}
      and  status = 42
      and  status = 42
     </select>
     </select>
+    <select id="getClickTrackUrl" resultType="java.lang.String">
+        select  click_track_url  from ctop_kuaishou_creative
+        where  account_id = #{accountId}
+        and unit_id = #{unitId}
+        order by creative_create_time desc
+        limit 1
+
+    </select>
 
 
 </mapper>
 </mapper>

+ 4 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouCreativeService.java

@@ -66,4 +66,8 @@ public interface IKuaiShouCreativeService extends IService<KuaiShouCreative> {
     List<KuaiShouCreative> getByParams(Long accountId, String photoId, Integer putStatus);
     List<KuaiShouCreative> getByParams(Long accountId, String photoId, Integer putStatus);
 
 
     Integer getNewDataByAccountIdAndDate(Long accountId, String statDate);
     Integer getNewDataByAccountIdAndDate(Long accountId, String statDate);
+
+    String getClickTrackUrl(Long accountId, Long unitId);
+
+    List<KuaiShouCreative> getCreativeListByAccountIdAndUnitId(Long accountId, Long unitId);
 }
 }

+ 13 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouCreativeServiceImpl.java

@@ -290,5 +290,18 @@ public class KuaiShouCreativeServiceImpl extends ServiceImpl<KuaiShouCreativeMap
         return kuaiShouCreativeMapper.getNewDataByAccountIdAndDate(accountId, statDate);
         return kuaiShouCreativeMapper.getNewDataByAccountIdAndDate(accountId, statDate);
     }
     }
 
 
+    @Override
+    public String getClickTrackUrl(Long accountId, Long unitId) {
+        return kuaiShouCreativeMapper.getClickTrackUrl(accountId, unitId);
+    }
+
+    @Override
+    public List<KuaiShouCreative> getCreativeListByAccountIdAndUnitId(Long accountId, Long unitId) {
+        QueryWrapper<KuaiShouCreative> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("account_id", accountId);
+        queryWrapper.eq("unit_id", unitId);
+        return this.list(queryWrapper);
+    }
+
 
 
 }
 }