|
@@ -19,12 +19,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
|
|
@Slf4j
|
|
|
@RestController
|
|
|
-@RequestMapping("/MaterialRefuse")
|
|
|
+@RequestMapping("/MaterialRefuse/")
|
|
|
public class MaterialRefuseController {
|
|
|
@Autowired
|
|
|
private IMaterialRefuseService materialRefuseService;
|
|
@@ -34,9 +35,10 @@ public class MaterialRefuseController {
|
|
|
private IKuaiShouUpdateService updateService;
|
|
|
@Autowired
|
|
|
private IKuaiShouCreativeService creativeService;
|
|
|
+ static ExecutorService executorService = Executors.newFixedThreadPool(15);
|
|
|
|
|
|
|
|
|
- @GetMapping(value = "/getRefuseCreative")
|
|
|
+ @GetMapping(value = "getRefuseCreative")
|
|
|
public Result<IPage<KuaiShouCreative>> getRefuseCreative(KuaiShouCreative creative,
|
|
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
|
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
|
@@ -58,13 +60,36 @@ public class MaterialRefuseController {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- @PostMapping(value = "/updateCreative")
|
|
|
- public Map<String, Object> updateCreative(@RequestBody JSONObject jsonObject) {
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
+
|
|
|
+ @GetMapping(value = "syncCreative")
|
|
|
+ public Result<Boolean> syncCreative(Long accountId, Long campaignId) {
|
|
|
+ Result<Boolean> result = new Result<>();
|
|
|
+ try {
|
|
|
+ QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("account_id", accountId);
|
|
|
+ queryWrapper.eq("media_id", 2);
|
|
|
+ queryWrapper.orderByDesc("create_time");
|
|
|
+ queryWrapper.last("limit 1");
|
|
|
+ CtopOauthToken ctopOauthToken = oauthTokenMapper.selectOne(queryWrapper);
|
|
|
+ if (Check.isNull(ctopOauthToken)) {
|
|
|
+ throw new Exception("未获取到授权信息");
|
|
|
+ }
|
|
|
+ creativeService.syncCreative(accountId, ctopOauthToken.getAccessToken(), campaignId);
|
|
|
+ result.setSuccess(true);
|
|
|
+ } catch (Exception e) {
|
|
|
+ result.setSuccess(false);
|
|
|
+ result.setMessage(e.getMessage());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping(value = "updateCreative")
|
|
|
+ public Result<Boolean> updateCreative(@RequestBody JSONObject jsonObject) {
|
|
|
+ Result<Boolean> result = new Result<>();
|
|
|
if (Check.isNull(jsonObject)) {
|
|
|
- map.put("code", -1);
|
|
|
- map.put("message", "入参为空");
|
|
|
- return map;
|
|
|
+ result.setSuccess(false);
|
|
|
+ result.setMessage("入参为空");
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
Long accountId = jsonObject.getLong("accountId");
|
|
@@ -75,34 +100,33 @@ public class MaterialRefuseController {
|
|
|
queryWrapper.last("limit 1");
|
|
|
CtopOauthToken ctopOauthToken = oauthTokenMapper.selectOne(queryWrapper);
|
|
|
if (Check.isNull(ctopOauthToken)) {
|
|
|
- map.put("code", -1);
|
|
|
- map.put("message", "未获取授权信息");
|
|
|
- return map;
|
|
|
+ result.setSuccess(false);
|
|
|
+ result.setMessage("未获取到授权信息");
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
Map<String, Object> creativeMap = updateService.updateCreative(ctopOauthToken.getAccessToken(), accountId, jsonObject);
|
|
|
if (Check.isNullMap(creativeMap)) {
|
|
|
-
|
|
|
- map.put("code", -1);
|
|
|
- map.put("message", "修改失败,返回为空");
|
|
|
- return map;
|
|
|
+ result.setSuccess(false);
|
|
|
+ result.setMessage("修改失败,返回为空");
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
if ((Integer) creativeMap.get("code") != 0) {
|
|
|
- map.put("code", -1);
|
|
|
- map.put("message", creativeMap.get("message"));
|
|
|
- return map;
|
|
|
+ result.setSuccess(false);
|
|
|
+ result.setMessage((String) creativeMap.get("message"));
|
|
|
+ return result;
|
|
|
}
|
|
|
+ result.setSuccess(true);
|
|
|
|
|
|
- return null;
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
- @PostMapping(value = "/batchUpdateCreative")
|
|
|
- public Result<JSONObject> batchUpdateCreative(@RequestBody JSONObject jsonObject) {
|
|
|
+ @PostMapping(value = "batchUpdateCreative")
|
|
|
+ public Result<Boolean> batchUpdateCreative(@RequestBody JSONObject jsonObject) {
|
|
|
|
|
|
- Result<JSONObject> result = new Result<>();
|
|
|
- JSONObject returnJson = new JSONObject();
|
|
|
+ Result<Boolean> result = new Result<>();
|
|
|
if (Check.isNull(jsonObject)) {
|
|
|
result.setSuccess(false);
|
|
|
result.setMessage("入参为空");
|
|
@@ -122,42 +146,68 @@ public class MaterialRefuseController {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ Integer type = jsonObject.getInteger("type");
|
|
|
+ if (Check.isNull(type)) {
|
|
|
+ result.setSuccess(false);
|
|
|
+ result.setMessage("请选择修改类型");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
JSONArray creativeArr = jsonObject.getJSONArray("creativeArr");
|
|
|
- Integer successCount = 0;
|
|
|
- Integer failCount = 0;
|
|
|
- if (!Check.isNull(creativeArr)) {
|
|
|
-
|
|
|
- for (int i = 0; i < creativeArr.size(); i++) {
|
|
|
- JSONObject creativeJson = creativeArr.getJSONObject(i);
|
|
|
- if (!Check.isNull(creativeJson)) {
|
|
|
- Long creativeId = creativeJson.getLong("creativeId");
|
|
|
- JSONObject requestJson = new JSONObject();
|
|
|
- requestJson.put("creativeId", creativeId);
|
|
|
+ if (Check.isNull(creativeArr)) {
|
|
|
+ result.setSuccess(false);
|
|
|
+ result.setMessage("请选择修改创意");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0; i < creativeArr.size(); i++) {
|
|
|
+ JSONObject creativeJson = creativeArr.getJSONObject(i);
|
|
|
+ if (!Check.isNull(creativeJson)) {
|
|
|
+ Long creativeId = creativeJson.getLong("creativeId");
|
|
|
+ JSONObject requestJson = new JSONObject();
|
|
|
+ requestJson.put("creativeId", creativeId);
|
|
|
+ if (type == 0) { // 替换修改广告语
|
|
|
String description = creativeJson.getString("description");
|
|
|
- if (!Check.isNull(description)) {
|
|
|
- requestJson.put("description", convertMoString(description));
|
|
|
+ requestJson.put("description", convertMoString(description));
|
|
|
+ } else if (type == 1) { // 替换广告语
|
|
|
+ String updateDescription = jsonObject.getString("updateDescription");
|
|
|
+ String updateActionBarText = jsonObject.getString("updateActionBarText");
|
|
|
+ if (Check.isNull(updateDescription) && Check.isNull(updateActionBarText)) {
|
|
|
+ result.setSuccess(false);
|
|
|
+ result.setMessage("广告语和行动号召按钮不能同时为空");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(updateDescription)) {
|
|
|
+ requestJson.put("description", updateDescription);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(updateActionBarText)) {
|
|
|
+ requestJson.put("actionBarText", updateActionBarText);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ executorService.submit(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
Map<String, Object> creativeMap = updateService.updateCreative(ctopOauthToken.getAccessToken(), accountId, requestJson);
|
|
|
Integer code = (Integer) creativeMap.get("code");
|
|
|
if (code == 0) {
|
|
|
log.info("拒审重提成功,accountId:{},creativeId:{}", accountId, creativeId);
|
|
|
- successCount += 1;
|
|
|
-
|
|
|
} else {
|
|
|
log.info("拒审重提失败,accountId:{},creativeId:{}", accountId, creativeId);
|
|
|
- failCount += 1;
|
|
|
}
|
|
|
}
|
|
|
+ });
|
|
|
|
|
|
- }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- returnJson.put("successCount", successCount);
|
|
|
- returnJson.put("failCount", failCount);
|
|
|
|
|
|
result.setSuccess(true);
|
|
|
- result.setResult(returnJson);
|
|
|
+ result.setMessage("异步执行中,请稍后查看");
|
|
|
return result;
|
|
|
}
|
|
|
|