Selaa lähdekoodia

修改广告计划预算

yumeng 5 vuotta sitten
vanhempi
commit
766c4b92ef

+ 72 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/BatchController.java

@@ -255,6 +255,76 @@ public class BatchController {
 
 
     /**
+     * 根据比例批量修改广告计划预算
+     *
+     * @param requestJson
+     * @return
+     */
+    @PostMapping(value = "/batchUpdateDayBudgetByProportion")
+    public Result<JSONObject> batchUpdateDayBudgetByProportion(@RequestBody JSONObject requestJson) {
+        Result<JSONObject> result = new Result<>();
+        try {
+            Long accountId = requestJson.getLong("accountId");
+            CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(token)) {
+                throw new Exception("账号信息为空");
+            }
+            BigDecimal proportion = requestJson.getBigDecimal("proportion");
+            if (proportion.compareTo(new BigDecimal(0)) == 0) {
+                throw new Exception("比例不能为0");
+            }
+            String userId = requestJson.getString("userId");
+            JSONArray campaignIds = requestJson.getJSONArray("campaignIds");
+            JSONArray failArr = new JSONArray();
+            if (!Check.isNull(campaignIds)) {
+                for (int i = 0; i < campaignIds.size(); i++) {
+                    Long campaignId = campaignIds.getLong(i);
+                    if (!Check.isNull(campaignId)) {
+                        KuaiShouCampaign campaign = batchService.getCampaignInfo(accountId, campaignId);
+                        if (!Check.isNull(campaign)) {
+                            Long dayBudget = campaign.getDayBudget();
+                            if (Check.isNull(dayBudget)) {
+                                continue;
+                            }
+                            BigDecimal totalFee = new BigDecimal(dayBudget);
+                            Long multiply = 0L;
+                            if (proportion.compareTo(new BigDecimal(0)) == -1) {
+                                BigDecimal absBigDecimal = BigDecimalUtil.absBigDecimal(proportion);
+                                BigDecimal decimal = BigDecimalUtil.multiplyBigDecimal(totalFee, absBigDecimal);
+                                multiply = (BigDecimalUtil.subtractBigDecimal(totalFee, decimal)).longValue();
+                            } else if (proportion.compareTo(new BigDecimal(0)) == 1) {
+                                multiply = (totalFee.multiply(proportion)).longValue();
+                            }
+                            Map<String, Object> updateMap = updateService.updateCampaign(token.getAccessToken(), accountId, campaignId, multiply, userId);
+                            if (!Check.isNull(updateMap)) {
+                                Integer code = (Integer) updateMap.get("code");
+                                if (code != 0) {
+                                    JSONObject failJson = new JSONObject();
+                                    failJson.put("message", updateMap.get("message"));
+                                    failJson.put("campaignName", campaign.getCampaignName());
+                                    failArr.add(failJson);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            JSONObject json = new JSONObject();
+            json.put("totalCount", campaignIds.size());
+            json.put("failCount", failArr.size());
+            json.put("failInfo", failArr);
+            result.setResult(json);
+            result.setSuccess(true);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
+    /**
      * 查询广告组列表
      *
      * @param kuaiShouGroup
@@ -1162,8 +1232,8 @@ public class BatchController {
      * @param id
      * @return
      */
-    @DeleteMapping(value = "/deleteeditDirectionalTemplate")
-    public Result<?> deleteeditDirectionalTemplate(@RequestParam(name = "id", required = true) String id) {
+    @DeleteMapping(value = "/deleteDirectionalTemplate")
+    public Result<?> deleteDirectionalTemplate(@RequestParam(name = "id", required = true) String id) {
         try {
             kuaiShouDirectionalTemplateService.removeById(id);
         } catch (Exception e) {