Browse Source

批量调整

yumeng 5 năm trước cách đây
mục cha
commit
1be2ac2a1d

+ 25 - 1
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -25,6 +25,30 @@ public class DateUtils extends PropertyEditorSupport {
     private static final long MINUTE_IN_MILLIS = 60 * 1000;
     private static final long SECOND_IN_MILLIS = 1000;
 
+
+    public static boolean compare(String beginDate, String nowDate) throws ParseException {
+        //如果想比较日期则写成"yyyy-MM-dd"就可以了
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        //将字符串形式的时间转化为Date类型的时间
+        Date a = sdf.parse(beginDate);
+        Date b = sdf.parse(nowDate);
+        //Date类的一个方法,如果a早于b返回true,否则返回false
+        if (a.before(b)) {
+            return true;
+        } else {
+            return false;
+        }
+
+		/*
+		 * 如果你不喜欢用上面这个太流氓的方法,也可以根据将Date转换成毫秒
+		if(a.getTime()-b.getTime()<0)
+			return true;
+		else
+			return false;
+		*/
+    }
+
+
     public static String getDateByDateStr(String dateStr) throws ParseException {
         SimpleDateFormat dsdf = new SimpleDateFormat("yyyy-MM-dd");
         Date parse = dsdf.parse(dateStr);
@@ -754,7 +778,7 @@ public class DateUtils extends PropertyEditorSupport {
     }
 
     public static void main(String[] args) throws ParseException {
-        System.out.println(DateUtils.addDay( "2020-01-03",  7));
+        System.out.println(DateUtils.addDay("2020-01-03", 7));
     }
 
     public static Date addDay(Date date, int day) {

+ 7 - 2
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -46,20 +46,24 @@ public class SampleTest {
     private IKuaiShouHistoryReportTaskService reportTaskService;
     @Autowired
     private CtopOauthTokenMapper tokenMapper;
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
 
 
     @Test
     public void kuaisShouReport() {
         try {
 
-            QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
+          /*  QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
             queryWrapper.eq("account_id", 3727345L);
             CtopOauthToken token = tokenMapper.selectOne(queryWrapper);
 
             SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
             Date parse = simpleDateFormat.parse("2020-03-12");
-            kuaishouInterfaceService.getAdvertiserReportDaily(token, parse, parse);
+            kuaishouInterfaceService.getAdvertiserReportDaily(token, parse, parse);*/
+
 
+            oauthTokenService.getKuaiShouRefreshToken(4801802L, "3874f4adb984a371cf92e5fc9a585e6b", 1);
 
 //            reportTaskService.createTask(3727345L, "871fc2c248782a94ad2962c941555abc", "");
 //            reportTaskService.getTaskList();
@@ -140,6 +144,7 @@ public class SampleTest {
 
     @Autowired
     private IBytedanceFundDailyService fundDailyService;
+
     @Test
     public void testLoadJob() {
         String endDate = "2020-04-07";

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

@@ -7,9 +7,11 @@ import cn.com.ctop.common.module.mapper.MaterialInfoMapper;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.BigDecimalUtil;
 import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.RandomUtil;
 import cn.com.ctop.kuaishou.modules.batch.entity.*;
 import cn.com.ctop.kuaishou.modules.batch.entity.vo.SpendVo;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouCampaignMapper;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupMapper;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouTargetingTagsMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.*;
 import com.alibaba.fastjson.JSONArray;
@@ -1536,8 +1538,9 @@ public class BatchController {
                 throw new Exception("请选择需要修改的广告组");
             }
             Long accountId = requestJson.getLong("accountId");
-            Long campaignId = requestJson.getLong("campaignId");
             Long copyToCampaignId = requestJson.getLong("copyToCampaignId");
+
+
             JSONObject returnJson = new JSONObject();
             JSONArray failArr = new JSONArray();
             for (int i = 0; i < unitIds.size(); i++) {
@@ -1545,7 +1548,17 @@ public class BatchController {
                 if (Check.isNull(unitId)) {
                     continue;
                 }
-                JSONObject unitJson = batchService.copyUnit(accountId, campaignId, unitId, copyToCampaignId);
+
+                QueryWrapper<KuaiShouGroup> queryWrapper = new QueryWrapper<>();
+                queryWrapper.eq("account_id", accountId);
+                queryWrapper.eq("unit_id", unitId);
+                KuaiShouGroup group = groupMapper.selectOne(queryWrapper);
+                if (Check.isNull(group)) {
+                    continue;
+                }
+                String unitName = group.getUnitName();
+                group.setUnitName(unitName + RandomUtil.verifyCode());
+                JSONObject unitJson = batchService.copyUnit(group, copyToCampaignId);
                 if (!Check.isNull(unitJson)) {
                     Integer code = unitJson.getInteger("code");
                     if (code != 0) {
@@ -1570,4 +1583,95 @@ public class BatchController {
         return result;
     }
 
+
+    @Autowired
+    private KuaiShouGroupMapper groupMapper;
+
+    @PostMapping(value = "/copyUnit")
+    public Result<JSONObject> copyUnit(@RequestBody JSONObject requestJson) {
+        Result<JSONObject> result = new Result<>();
+        try {
+            JSONObject returnJson = new JSONObject();
+
+            Long accountId = requestJson.getLong("accountId");
+            Long unitId = requestJson.getLong("unitId");
+            Long copyToCampaignId = requestJson.getLong("copyToCampaignId");
+            JSONArray failArr = new JSONArray();
+            Integer createCount = requestJson.getInteger("createCount");
+            if (Check.isNull(createCount) || createCount == 0) {
+                throw new Exception("请选择迭代次数");
+            }
+
+            if (createCount == 1) {
+                JSONObject createJson = batchService.createUnit(requestJson);
+                if (createJson.getInteger("code") != 0) {
+                    JSONObject errJson = new JSONObject();
+                    errJson.put("message", createJson.getString("message"));
+                    errJson.put("unitName", requestJson.getString("unitName"));
+                    failArr.add(errJson);
+
+                }
+            } else if (createCount > 1) {
+                QueryWrapper<KuaiShouGroup> queryWrapper = new QueryWrapper<>();
+                queryWrapper.eq("account_id", accountId);
+                queryWrapper.eq("unit_id", unitId);
+                KuaiShouGroup group = groupMapper.selectOne(queryWrapper);
+                if (Check.isNull(group)) {
+                    throw new Exception("未获取到广告组信息");
+                }
+                String unitName = group.getUnitName();
+                Integer createType = requestJson.getInteger("createType");
+                if (createType == 1) { // 系统生成
+                    for (int i = 0; i < createCount; i++) {
+                        String randomName = unitName + RandomUtil.verifyCode();
+                        group.setUnitName(randomName);
+                        JSONObject copyUnitJson = batchService.copyUnit(group, copyToCampaignId);
+                        if (copyUnitJson.getInteger("code") != 0) {
+                            JSONObject errJson = new JSONObject();
+                            errJson.put("message", copyUnitJson.getString("message"));
+                            returnJson.put("unitName", randomName);
+                            failArr.add(errJson);
+                        }
+                    }
+
+                } else if (createCount == 2) { // 自定义
+                    JSONArray unitNames = requestJson.getJSONArray("unitNames");
+                    if (Check.isNull(unitNames)) {
+                        throw new Exception("请输入广告组名称");
+                    }
+                    if (!Check.isNull(unitNames)) {
+                        for (int i = 0; i < unitNames.size(); i++) {
+                            String copyUnitName = String.valueOf(unitNames.get(i));
+                            if (Check.isNull(copyUnitName)) {
+                                continue;
+                            }
+                            group.setUnitName(copyUnitName);
+                            JSONObject copyUnitJson = batchService.copyUnit(group, copyToCampaignId);
+                            if (copyUnitJson.getInteger("code") != 0) {
+                                JSONObject errJson = new JSONObject();
+                                errJson.put("message", copyUnitJson.getString("message"));
+                                returnJson.put("unitName", copyUnitName);
+                                failArr.add(errJson);
+                            }
+                        }
+
+                    }
+
+                }
+            }
+
+            returnJson.put("failCount", failArr.size());
+            returnJson.put("data", failArr);
+            result.setResult(returnJson);
+            result.setSuccess(true);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
 }

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

@@ -62,13 +62,10 @@ public interface IBatchService {
     /**
      * 批量复制广告组
      *
-     * @param accountId
-     * @param campaignId
-     * @param unitId
      * @param copyToCampaignId
      * @return
      */
-    JSONObject copyUnit(Long accountId, Long campaignId, Long unitId, Long copyToCampaignId);
+    JSONObject copyUnit(KuaiShouGroup group, Long copyToCampaignId);
 
 
     /**
@@ -121,4 +118,14 @@ public interface IBatchService {
      * @return
      */
     JSONObject updateCreative(JSONObject requestJson) throws Exception;
+
+
+    /**
+     * 复制创意
+     *
+     * @param accountId
+     * @param unitId
+     * @param copyUnitId
+     */
+    void copyCreative(Long accountId, Long unitId, Long copyUnitId) throws Exception;
 }

+ 50 - 33
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/BatchServiceImpl.java

@@ -144,7 +144,6 @@ public class BatchServiceImpl implements IBatchService {
 
     @Override
     public JSONObject createUnit(JSONObject requestJson) throws Exception {
-        System.err.println(requestJson);
         Long accountId = requestJson.getLong("accountId");
         CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
         if (Check.isNull(oauthToken)) {
@@ -152,15 +151,16 @@ public class BatchServiceImpl implements IBatchService {
         }
 
         JSONObject unitJson = new JSONObject();
-        String type = requestJson.getString("type");
 
         Long campaignId = requestJson.getLong("campaignId");
         if (Check.isNull(campaignId)) {
             throw new Exception("请选择广告计划");
         }
-        Long copyToCampaignId = requestJson.getLong("copyToCampaignId");
-        if (!Check.isNull(type) && "copy".equals(type)) {
-            unitJson.put("campaign_id", copyToCampaignId);
+
+
+        String type = requestJson.getString("type");
+        if ("copy".equals(type) && !Check.isNull(type)) {
+            unitJson.put("campaign_id", requestJson.getLong("copyToCampaignId"));
         } else {
             unitJson.put("campaign_id", campaignId);
         }
@@ -179,7 +179,21 @@ public class BatchServiceImpl implements IBatchService {
 
         //投放开始时间
         if (!Check.isNull(requestJson.getString("beginTime"))) {
-            unitJson.put("begin_time", requestJson.getString("beginTime"));
+
+            if ("copy".equals(type)) {
+                String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+                boolean beginTimeBoolean = DateUtils.compare(requestJson.getString("beginTime"), nowDate);
+                if (beginTimeBoolean) {
+                    unitJson.put("begin_time", nowDate);
+                } else {
+                    unitJson.put("begin_time", requestJson.getString("beginTime"));
+                }
+
+            } else {
+                unitJson.put("begin_time", requestJson.getString("beginTime"));
+            }
+
+
         }
         // 投放结束时间
         if (!Check.isNull(requestJson.getString("endTime"))) {
@@ -363,7 +377,7 @@ public class BatchServiceImpl implements IBatchService {
                 }
                 String unitName = groupJson.getString("unitName");
                 if (!Check.isNull(unitName)) {
-                    unitJson.put("unit_name", unitName + RandomUtil.verifyCode());
+                    unitJson.put("unit_name", unitName);
                 }
 
                 Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), accountId, unitJson);
@@ -378,6 +392,7 @@ public class BatchServiceImpl implements IBatchService {
                         successJson.put("sceneId", scene_id);
                         successJson.put("ocpxActionType", ocpx_action_type);
                         successArr.add(successJson);
+
                         if (!Check.isNull(type) && "copy".equals(type)) {
                             Long copyUnitId = requestJson.getLong("copyUnitId");
                             if (!Check.isNull(unitId) && !Check.isNull(copyUnitId)) {
@@ -425,21 +440,13 @@ public class BatchServiceImpl implements IBatchService {
 
 
     @Override
-    public JSONObject copyUnit(Long accountId, Long campaignId, Long unitId, Long copyToCampaignId) {
+    public JSONObject copyUnit(KuaiShouGroup group, Long copyToCampaignId) {
         JSONObject returnJson = new JSONObject();
 
         try {
 
-            QueryWrapper<KuaiShouGroup> queryWrapper = new QueryWrapper<>();
-            queryWrapper.eq("account_id", accountId);
-            queryWrapper.eq("unit_id", unitId);
-            KuaiShouGroup group = groupMapper.selectOne(queryWrapper);
-            if (Check.isNull(group)) {
-                throw new Exception("未获取到广告组信息");
-
-            }
 
-            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(group.getAccountId());
             if (Check.isNull(oauthToken)) {
                 throw new Exception("未获取到token信息");
             }
@@ -462,7 +469,15 @@ public class BatchServiceImpl implements IBatchService {
 
                 //投放开始时间
                 if (!Check.isNull(group.getBeginTime())) {
-                    unitJson.put("begin_time", group.getBeginTime());
+
+                    String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+                    boolean beginTimeBoolean = DateUtils.compare(group.getBeginTime(), nowDate);
+                    if (beginTimeBoolean) {
+                        unitJson.put("begin_time", nowDate);
+                    } else {
+                        unitJson.put("begin_time", group.getBeginTime());
+                    }
+
                 }
                 // 投放结束时间
                 if (!Check.isNull(group.getEndTime())) {
@@ -498,8 +513,8 @@ public class BatchServiceImpl implements IBatchService {
 
 
                 QueryWrapper<KuaiShouGroupTarget> targetQueryWrapper = new QueryWrapper<>();
-                targetQueryWrapper.eq("account_id", accountId);
-                targetQueryWrapper.eq("unit_id", unitId);
+                targetQueryWrapper.eq("account_id", group.getAccountId());
+                targetQueryWrapper.eq("unit_id", group.getUnitId());
                 targetQueryWrapper.last("limit 1");
                 KuaiShouGroupTarget groupTarget = targetMapper.selectOne(targetQueryWrapper);
                 if (!Check.isNull(groupTarget)) {
@@ -645,14 +660,10 @@ public class BatchServiceImpl implements IBatchService {
                 }
                 String unitName = group.getUnitName();
                 if (!Check.isNull(unitName)) {
-                    if (campaignId == copyToCampaignId) {
-                        unitJson.put("unit_name", unitName + RandomUtil.verifyCode());
-                    } else {
-                        unitJson.put("unit_name", unitName);
-                    }
+                    unitJson.put("unit_name", unitName);
                 }
 
-                Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), accountId, unitJson);
+                Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), group.getAccountId(), unitJson);
                 if (!Check.isNullMap(returnUnitMap)) {
                     Integer code = (Integer) returnUnitMap.get("code");
                     if (code == 0) {
@@ -665,7 +676,7 @@ public class BatchServiceImpl implements IBatchService {
                             @Override
                             public void run() {
                                 try {
-                                    copyCreative(accountId, unitId, copyUnitId);
+                                    copyCreative(group.getAccountId(), group.getUnitId(), copyUnitId);
                                 } catch (Exception e) {
                                     e.printStackTrace();
                                 }
@@ -700,7 +711,8 @@ public class BatchServiceImpl implements IBatchService {
      * @param accountId
      * @param unitId
      */
-    private void copyCreative(Long accountId, Long unitId, Long copyUnitId) throws Exception {
+    @Override
+    public void copyCreative(Long accountId, Long unitId, Long copyUnitId) throws Exception {
         // 查询当前复制组下的所有非程序化创意
 
         QueryWrapper<KuaiShouCreative> queryWrapper = new QueryWrapper<>();
@@ -755,11 +767,7 @@ public class BatchServiceImpl implements IBatchService {
                         failArr.add(failJson);
                     }
                 }
-
-
             }
-
-
         }
     }
 
@@ -973,7 +981,16 @@ public class BatchServiceImpl implements IBatchService {
         }
         //投放开始时间
         if (!Check.isNull(requestJson.getString("beginTime"))) {
-            unitJson.put("begin_time", requestJson.getString("beginTime"));
+
+            String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+            boolean beginTimeBoolean = DateUtils.compare(requestJson.getString("beginTime"), nowDate);
+            if (beginTimeBoolean) {
+                unitJson.put("begin_time", nowDate);
+            } else {
+                unitJson.put("begin_time", requestJson.getString("beginTime"));
+            }
+
+
         }
         // 投放结束时间
         if (!Check.isNull(requestJson.getString("endTime"))) {