Sfoglia il codice sorgente

账户配置信息 查询列表接口修改

zhaoxian 4 anni fa
parent
commit
45574aa611

+ 5 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/AiKuaishouAdvertiserStrategyMapper.java

@@ -1,7 +1,11 @@
 package cn.com.ctop.kuaishou.modules.ai.mapper;
 
 import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.github.pagehelper.PageInfo;
+
+import java.util.List;
 
 /**
  * 快手账户策略设置信息表
@@ -11,4 +15,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface AiKuaishouAdvertiserStrategyMapper extends BaseMapper<AiKuaishouAdvertiserStrategy> {
 
+    List<AiKuaishouAdvertiserStrategy> queryList(AiKuaishouAdvertiserStrategy aiKuaishouAdvertiserStrategy);
 }

+ 14 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/AiKuaishouAdvertiserStrategyMapper.xml

@@ -2,4 +2,18 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.ctop.kuaishou.modules.ai.mapper.AiKuaishouAdvertiserStrategyMapper">
 
+    <select id="queryList" resultType="cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy">
+        SELECT *
+        FROM ctop_ai_kuaishou_advertiser_strategy
+        <where>
+            <if test="accountId != null">
+                and account_id = #{accountId}
+            </if>
+            <if test="userId != null">
+                and user_id = #{userId}
+            </if>
+        </where>
+        order by create_time desc
+    </select>
+
 </mapper>

+ 4 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IAiKuaishouAdvertiserStrategyService.java

@@ -1,7 +1,9 @@
 package cn.com.ctop.kuaishou.modules.ai.service;
 
 import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.github.pagehelper.PageInfo;
 
 import java.util.List;
 import java.util.Map;
@@ -26,4 +28,6 @@ public interface IAiKuaishouAdvertiserStrategyService extends IService<AiKuaisho
     Map<String, Object> aiHistoricalMissingMaterial(Long accountId);
 
     List<AiKuaishouAdvertiserStrategy> getAllEffectStrategy();
+
+    PageInfo<AiKuaishouAdvertiserStrategy> queryList(AiKuaishouAdvertiserStrategy aiKuaishouAdvertiserStrategy);
 }

+ 45 - 35
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouAdvertiserStrategyServiceImpl.java

@@ -14,6 +14,7 @@ import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouVideoRelateCreativesS
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.github.pagehelper.PageInfo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -23,25 +24,28 @@ import java.util.Map;
 
 /**
  * 快手账户策略设置信息表
+ *
  * @author jeecg-boot
- * @date   2021-01-25
  * @version V1.0
+ * @date 2021-01-25
  */
 @Service
 public class AiKuaishouAdvertiserStrategyServiceImpl extends ServiceImpl<AiKuaishouAdvertiserStrategyMapper, AiKuaishouAdvertiserStrategy> implements IAiKuaishouAdvertiserStrategyService {
-    public static final String TEST_CREATIVE_URL= "http://139.186.27.96:31012/ai_historical_missing_material";
-    public static final String TEST_PROGRAM_CREATIVE_URL= "http://139.186.27.96:31012/ai_programme_new_material";
+    public static final String TEST_CREATIVE_URL = "http://139.186.27.96:31012/ai_historical_missing_material";
+    public static final String TEST_PROGRAM_CREATIVE_URL = "http://139.186.27.96:31012/ai_programme_new_material";
     @Autowired
     private IUserAllocationService userAllocationService;
     @Autowired
     private IKuaiShouVideoGetService videoGetService;
     @Autowired
     private IKuaishouVideoRelateCreativesService relateCreativesService;
+    @Autowired
+    private AiKuaishouAdvertiserStrategyMapper kuaishouAdvertiserStrategyMapper;
 
     @Override
     public AiKuaishouAdvertiserStrategy getByAccountId(Long accountId) {
-        QueryWrapper<AiKuaishouAdvertiserStrategy>queryWrapper =new QueryWrapper<>();
-        queryWrapper.eq("account_id",accountId);
+        QueryWrapper<AiKuaishouAdvertiserStrategy> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("account_id", accountId);
         queryWrapper.orderByDesc("id");
         queryWrapper.last("limit 1");
         return this.getOne(queryWrapper);
@@ -49,79 +53,85 @@ public class AiKuaishouAdvertiserStrategyServiceImpl extends ServiceImpl<AiKuais
 
     @Override
     public Map<String, Object> testCreate(Long accountId) {
-        Map<String,Object>result = new HashMap<>();
-        if(null == accountId||accountId == 0){
+        Map<String, Object> result = new HashMap<>();
+        if (null == accountId || accountId == 0) {
             ResultMapUtils.setResultMap(result, StatusCode.COMMON_PARAM_ERROR);
             return result;
         }
         AiKuaishouAdvertiserStrategy aiKuaishouAdvertiserStrategy = this.getByAccountId(accountId);
-        if(null == aiKuaishouAdvertiserStrategy||null == aiKuaishouAdvertiserStrategy.getStatus()||aiKuaishouAdvertiserStrategy.getStatus()!=1){
+        if (null == aiKuaishouAdvertiserStrategy || null == aiKuaishouAdvertiserStrategy.getStatus() || aiKuaishouAdvertiserStrategy.getStatus() != 1) {
             ResultMapUtils.setResultMap(result, StatusCode.COMMON_PARAM_ERROR);
             return result;
         }
         UserAllocation allocation = userAllocationService.getByAccountId(accountId);
-        if(null == allocation){
+        if (null == allocation) {
             ResultMapUtils.setResultMap(result, StatusCode.COMMON_PARAM_ERROR);
             return result;
         }
         JSONObject params = new JSONObject();
-        params.put("account_id",accountId);
-        params.put("test_video_cnt",1);
+        params.put("account_id", accountId);
+        params.put("test_video_cnt", 1);
         String request = null;
         //程序化
-        if(aiKuaishouAdvertiserStrategy.getOpenProgramCreate() == 1){
-            request = HttpUtils.httpPostRequest(TEST_PROGRAM_CREATIVE_URL,params,new HashMap<>());
-        }else{
+        if (aiKuaishouAdvertiserStrategy.getOpenProgramCreate() == 1) {
+            request = HttpUtils.httpPostRequest(TEST_PROGRAM_CREATIVE_URL, params, new HashMap<>());
+        } else {
             request = HttpUtils.httpPostRequest(TEST_CREATIVE_URL, params, new HashMap<>());
         }
         JSONObject requestObject = JSONObject.parseObject(request);
         String message = requestObject.getString("message");
         Integer code = requestObject.getInteger("code");
-        result.put("code",code);
-        result.put("message",message);
+        result.put("code", code);
+        result.put("message", message);
         return result;
     }
+
     @Override
     public Map<String, Object> aiHistoricalMissingMaterial(Long accountId) {
-        Map<String,Object>result = new HashMap<>();
-        if(null == accountId||accountId == 0){
-            ResultMapUtils.setResultMap(result,StatusCode.COMMON_PARAM_ERROR);
+        Map<String, Object> result = new HashMap<>();
+        if (null == accountId || accountId == 0) {
+            ResultMapUtils.setResultMap(result, StatusCode.COMMON_PARAM_ERROR);
             return result;
         }
         AiKuaishouAdvertiserStrategy strategy = this.getByAccountId(accountId);
-        if(null == strategy||strategy.getStatus()!=1){
-            ResultMapUtils.setResultMap(result,StatusCode.KUAISHOU_AI_STRATEGY_HAS_NOT_EXIST);
+        if (null == strategy || strategy.getStatus() != 1) {
+            ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_AI_STRATEGY_HAS_NOT_EXIST);
             return result;
         }
         this.historicalMissingMaterialCreateCreative(strategy);
-        ResultMapUtils.setResultMap(result,StatusCode.COMMON_SUCCESS);
+        ResultMapUtils.setResultMap(result, StatusCode.COMMON_SUCCESS);
         return result;
     }
 
     @Override
     public List<AiKuaishouAdvertiserStrategy> getAllEffectStrategy() {
-        QueryWrapper<AiKuaishouAdvertiserStrategy>queryWrapper= new QueryWrapper<>();
-        queryWrapper.eq("status",1);
+        QueryWrapper<AiKuaishouAdvertiserStrategy> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("status", 1);
         queryWrapper.orderByDesc("id");
         return this.list(queryWrapper);
     }
 
-    private Map<String,Object> historicalMissingMaterialCreateCreative(AiKuaishouAdvertiserStrategy strategy) {
-        Map<String,Object>result =new HashMap<>();
+    @Override
+    public PageInfo<AiKuaishouAdvertiserStrategy> queryList(AiKuaishouAdvertiserStrategy aiKuaishouAdvertiserStrategy) {
+        return new PageInfo<>(kuaishouAdvertiserStrategyMapper.queryList(aiKuaishouAdvertiserStrategy));
+    }
+
+    private Map<String, Object> historicalMissingMaterialCreateCreative(AiKuaishouAdvertiserStrategy strategy) {
+        Map<String, Object> result = new HashMap<>();
         //判定是否单一应用
-        if(strategy.getSingleAppid()==1){
+        if (strategy.getSingleAppid() == 1) {
             //TODO 参数拼接
-            Map<String,Object>params =new HashMap<>();
+            Map<String, Object> params = new HashMap<>();
             //1:直接查询历史素材
             List<JSONObject> materialList = relateCreativesService.getVideoZeroListByMap(params);
             if (Check.isNull(materialList)) {
-                ResultMapUtils.setResultMap(result,StatusCode.KUAISHOU_AI_STRATEGY_HAS_NO_HISTORY_MATERIAL);
+                ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_AI_STRATEGY_HAS_NO_HISTORY_MATERIAL);
                 return result;
             }
             materialList = videoGetService.getVideoInfoAndImageList(materialList);
             //补充遗漏素材
-            JSONObject hisMatParams = formatHisMatParams(strategy,materialList,"补充遗漏素材");
-        }else{
+            JSONObject hisMatParams = formatHisMatParams(strategy, materialList, "补充遗漏素材");
+        } else {
             //
 
         }
@@ -130,10 +140,10 @@ public class AiKuaishouAdvertiserStrategyServiceImpl extends ServiceImpl<AiKuais
 
     private JSONObject formatHisMatParams(AiKuaishouAdvertiserStrategy strategy, List<JSONObject> materialList, String fixString) {
         JSONObject result = new JSONObject();
-        result.put("video",materialList);
-        result.put("operation_type",1);
-        result.put("account_id",strategy.getAccountId());
-        result.put("ai_strategy_remark",fixString);
+        result.put("video", materialList);
+        result.put("operation_type", 1);
+        result.put("account_id", strategy.getAccountId());
+        result.put("ai_strategy_remark", fixString);
 
         return result;
     }

+ 28 - 25
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/AiKuaishouAdvertiserStrategyController.java

@@ -12,20 +12,26 @@ import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouAppMultipleBidsService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouVideoRelateCreativesService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
-import org.jeecg.common.system.query.QueryGenerator;
-import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.modules.system.service.ISysRoleService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 快手账户策略设置信息表
@@ -59,34 +65,31 @@ public class AiKuaishouAdvertiserStrategyController {
      * @return
      */
     @GetMapping(value = "/list")
-    public Result<IPage<AiKuaishouAdvertiserStrategy>> queryPageList(AiKuaishouAdvertiserStrategy aiKuaishouAdvertiserStrategy,
-                                                                     @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
-                                                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
-                                                                     HttpServletRequest req) {
-        Result<IPage<AiKuaishouAdvertiserStrategy>> result = new Result<>();
-        QueryWrapper<AiKuaishouAdvertiserStrategy> queryWrapper = QueryGenerator.initQueryWrapper(aiKuaishouAdvertiserStrategy, req.getParameterMap());
+    public Result<PageInfo<AiKuaishouAdvertiserStrategy>> queryPageList(AiKuaishouAdvertiserStrategy aiKuaishouAdvertiserStrategy,
+                                                      @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                      HttpServletRequest req) {
+        Result<PageInfo<AiKuaishouAdvertiserStrategy>> result = new Result<>();
         String roleCode = sysRoleService.getRoleCodeByUserId(aiKuaishouAdvertiserStrategy.getUserId());
-        if (!CtopRoleCodeConstant.COMMON_ROLE_CODE_ADMIN.equals(roleCode)) {
-            queryWrapper.eq("user_id", aiKuaishouAdvertiserStrategy.getUserId());
+        if (CtopRoleCodeConstant.COMMON_ROLE_CODE_ADMIN.equals(roleCode)) {
+            aiKuaishouAdvertiserStrategy.setUserId(null);
         }
-        Page<AiKuaishouAdvertiserStrategy> page = new Page<>(pageNo, pageSize);
-        queryWrapper.orderByDesc("id");
-        IPage<AiKuaishouAdvertiserStrategy> pageList = aiKuaishouAdvertiserStrategyService.page(page, queryWrapper);
-        List<AiKuaishouAdvertiserStrategy> records = pageList.getRecords();
+        PageHelper.startPage(pageNo, pageSize);
+        PageInfo<AiKuaishouAdvertiserStrategy> pageInfo = aiKuaishouAdvertiserStrategyService.queryList(aiKuaishouAdvertiserStrategy);
+        List<AiKuaishouAdvertiserStrategy> list = pageInfo.getList();
         List<AiKuaishouAdvertiserStrategy> setData = new ArrayList<>();
-        if (null != records && !records.isEmpty()) {
-            records.forEach(record -> {
+        if (null != list && !list.isEmpty()) {
+            list.forEach(record -> {
                 Long accountId = record.getAccountId();
                 UserAllocation allocation = allocationService.getByAccountId(accountId);
                 if (null != allocation) {
                     record.setAuthName(allocation.getAuthName());
                 }
-                setData.add(record);
             });
-            pageList.setRecords(setData);
         }
+        pageInfo.setList(list);
         result.setSuccess(true);
-        result.setResult(pageList);
+        result.setResult(pageInfo);
         return result;
     }