yumeng 2 minggu lalu
induk
melakukan
e881e8dbd9

+ 55 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/entity/AdqAdvertiserInfo.java

@@ -0,0 +1,55 @@
+package cn.com.ctop.common.module.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * ADQ广告主信息
+ *
+ * @author jeecg-boot
+ * @date 2024-01-01
+ */
+@Data
+@TableName("adq_advertiser_info")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "adq_advertiser_info对象", description = "ADQ广告主信息")
+public class AdqAdvertiserInfo implements Serializable {
+
+    @TableId(type = IdType.AUTO)
+    @ApiModelProperty(value = "主键ID")
+    private Long id;
+
+    @ApiModelProperty(value = "账户ID")
+    private Long accountId;
+
+    @ApiModelProperty(value = "广告主名称")
+    private String advertiserName;
+
+    @ApiModelProperty(value = "公司名称")
+    private String corporationName;
+
+    @ApiModelProperty(value = "认证状态")
+    private String systemStatus;
+
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "更新时间")
+    private Date updateTime;
+}

+ 7 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/entity/UserAllocation.java

@@ -161,4 +161,11 @@ public class UserAllocation implements Serializable {
     @Excel(name = "平台类型 1 头条 2快手", width = 15)
     @ApiModelProperty(value = "平台类型 1 头条 2快手")
     private String mediaId;
+
+    /**
+     * ADQ管家账户ID
+     */
+    @Excel(name = "ADQ管家账户ID", width = 15)
+    @ApiModelProperty(value = "ADQ管家账户ID")
+    private Long adminAdvertiserId;
 }

+ 36 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/AdqAccountClaimMapper.java

@@ -0,0 +1,36 @@
+package cn.com.ctop.common.module.mapper;
+
+import cn.com.ctop.common.module.entity.AdqAdvertiserInfo;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * ADQ账户认领 Mapper
+ *
+ * @author jeecg-boot
+ */
+public interface AdqAccountClaimMapper extends BaseMapper<AdqAdvertiserInfo> {
+
+    /**
+     * 查询未认领的ADQ账户(在adq_advertiser_info中但不在ctop_user_allocation中,media_id=16)
+     */
+    List<JSONObject> queryUnclaimedAccounts(@Param("accountIdList") List<Long> accountIdList,
+                                            @Param("advertiserName") String advertiserName,
+                                            @Param("pageNo") Integer pageNo,
+                                            @Param("pageSize") Integer pageSize);
+
+    /**
+     * 查询未认领账户总数
+     */
+    Long countUnclaimedAccounts(@Param("accountIdList") List<Long> accountIdList,
+                                @Param("advertiserName") String advertiserName);
+
+    /**
+     * 查询media_id=16的项目列表(过滤当前用户有权限的项目)
+     */
+    List<JSONObject> queryAdqProjects(@Param("projectName") String projectName,
+                                      @Param("userId") String userId);
+}

+ 65 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/xml/AdqAccountClaimMapper.xml

@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.com.ctop.common.module.mapper.AdqAccountClaimMapper">
+
+    <!-- 查询未认领的ADQ账户 -->
+    <select id="queryUnclaimedAccounts" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            a.id AS 'id',
+            a.account_id AS 'accountId',
+            a.account_id AS 'advertiserName',
+            a.corporation_name AS 'corporationName',
+            a.system_status AS 'systemStatus',
+            a.admin_advertiser_id AS 'adminAdvertiserId',
+            a.create_time AS 'createTime'
+        FROM adq_advertiser_info a
+        LEFT JOIN ctop_user_allocation ua
+            ON a.account_id = ua.account_id AND ua.media_id = '16'
+        WHERE ua.id IS NULL
+        <if test="accountIdList != null and accountIdList.size() > 0">
+            AND a.account_id IN
+            <foreach collection="accountIdList" item="item" separator="," open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="advertiserName != null and advertiserName != ''">
+            AND a.advertiser_name LIKE CONCAT('%', #{advertiserName}, '%')
+        </if>
+        ORDER BY a.create_time DESC
+        LIMIT #{pageNo}, #{pageSize}
+    </select>
+
+    <!-- 查询未认领账户总数 -->
+    <select id="countUnclaimedAccounts" resultType="java.lang.Long">
+        SELECT COUNT(1)
+        FROM adq_advertiser_info a
+        LEFT JOIN ctop_user_allocation ua
+            ON a.account_id = ua.account_id AND ua.media_id = '16'
+        WHERE ua.id IS NULL
+        <if test="accountIdList != null and accountIdList.size() > 0">
+            AND a.account_id IN
+            <foreach collection="accountIdList" item="item" separator="," open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="advertiserName != null and advertiserName != ''">
+            AND a.advertiser_name LIKE CONCAT('%', #{advertiserName}, '%')
+        </if>
+    </select>
+
+    <!-- 查询media_id=16的项目列表(过滤当前用户有权限的项目) -->
+    <select id="queryAdqProjects" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT DISTINCT
+            p.id AS 'projectId',
+            p.project_name AS 'projectName',
+            p.advertiser_id AS 'advertiserId'
+        FROM ctop_project p
+        INNER JOIN ctop_project_member pm ON p.id = pm.project_id AND pm.user_id = #{userId}
+        WHERE p.media_id = '16'
+        <if test="projectName != null and projectName != ''">
+            AND p.project_name LIKE CONCAT('%', #{projectName}, '%')
+        </if>
+        ORDER BY p.create_time DESC
+    </select>
+
+</mapper>

+ 30 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/IAdqAccountClaimService.java

@@ -0,0 +1,30 @@
+package cn.com.ctop.common.module.service;
+
+import cn.com.ctop.common.module.entity.AdqAdvertiserInfo;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+import java.util.List;
+
+/**
+ * ADQ账户认领 Service
+ *
+ * @author jeecg-boot
+ */
+public interface IAdqAccountClaimService extends IService<AdqAdvertiserInfo> {
+
+    /**
+     * 分页查询未认领的ADQ账户
+     */
+    JSONObject queryUnclaimedAccounts(String accountIds, String advertiserName, Integer pageNo, Integer pageSize);
+
+    /**
+     * 查询media_id=16的项目列表(过滤当前用户有权限的项目)
+     */
+    List<JSONObject> queryAdqProjects(String projectName, String userId);
+
+    /**
+     * 批量认领账户
+     */
+    void batchClaimAccounts(JSONObject claimData) throws Exception;
+}

+ 124 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/impl/AdqAccountClaimServiceImpl.java

@@ -0,0 +1,124 @@
+package cn.com.ctop.common.module.service.impl;
+
+import cn.com.ctop.common.module.entity.AdqAdvertiserInfo;
+import cn.com.ctop.common.module.entity.Project;
+import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.mapper.AdqAccountClaimMapper;
+import cn.com.ctop.common.module.mapper.UserAllocationMapper;
+import cn.com.ctop.common.module.service.IAdqAccountClaimService;
+import cn.com.ctop.common.module.service.IProjectService;
+import cn.com.ctop.common.module.utils.Check;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.system.vo.LoginUser;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * ADQ账户认领 Service实现
+ *
+ * @author jeecg-boot
+ */
+@Slf4j
+@Service
+public class AdqAccountClaimServiceImpl extends ServiceImpl<AdqAccountClaimMapper, AdqAdvertiserInfo> implements IAdqAccountClaimService {
+
+    @Resource
+    private AdqAccountClaimMapper adqAccountClaimMapper;
+
+    @Autowired
+    private UserAllocationMapper userAllocationMapper;
+
+    @Autowired
+    private IProjectService projectService;
+
+    @Override
+    public JSONObject queryUnclaimedAccounts(String accountIds, String advertiserName, Integer pageNo, Integer pageSize) {
+        JSONObject result = new JSONObject();
+        int offset = (pageNo - 1) * pageSize;
+        // 解析多个账户ID(支持逗号、换行、空格分隔)
+        List<Long> accountIdList = null;
+        if (accountIds != null && !accountIds.trim().isEmpty()) {
+            accountIdList = Arrays.stream(accountIds.split("[,,\\s\\n]+"))
+                    .map(String::trim)
+                    .filter(s -> !s.isEmpty())
+                    .map(Long::parseLong)
+                    .collect(Collectors.toList());
+        }
+        List<JSONObject> list = adqAccountClaimMapper.queryUnclaimedAccounts(accountIdList, advertiserName, offset, pageSize);
+        Long total = adqAccountClaimMapper.countUnclaimedAccounts(accountIdList, advertiserName);
+        result.put("records", list);
+        result.put("total", total);
+        result.put("current", pageNo);
+        result.put("size", pageSize);
+        return result;
+    }
+
+    @Override
+    public List<JSONObject> queryAdqProjects(String projectName, String userId) {
+        return adqAccountClaimMapper.queryAdqProjects(projectName, userId);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void batchClaimAccounts(JSONObject claimData) throws Exception {
+        Long projectId = claimData.getLong("projectId");
+        JSONArray accountIds = claimData.getJSONArray("accountIds");
+
+        if (Check.isNull(projectId)) {
+            throw new Exception("请选择项目");
+        }
+        if (Check.isNull(accountIds) || accountIds.isEmpty()) {
+            throw new Exception("请选择要认领的账户");
+        }
+
+        // 获取项目信息
+        Project project = projectService.getById(projectId);
+        if (Check.isNull(project)) {
+            throw new Exception("项目不存在");
+        }
+
+        // 获取当前登录用户
+        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        String userId = loginUser.getId();
+        String userName = loginUser.getRealname();
+
+        for (int i = 0; i < accountIds.size(); i++) {
+            JSONObject accountObj = accountIds.getJSONObject(i);
+            Long accountId = accountObj.getLong("accountId");
+            String advertiserName = accountObj.getString("advertiserName");
+            Long adminAdvertiserId = accountObj.getLong("adminAdvertiserId");
+
+            // 创建UserAllocation记录
+            UserAllocation allocation = new UserAllocation();
+            allocation.setUserId(userId);
+            allocation.setUserName(userName);
+            allocation.setAccountId(accountId);
+            allocation.setProjectId(projectId);
+            allocation.setMediaId("16");
+            allocation.setAdvertiserId(project.getAdvertiserId());
+            allocation.setAuthName(advertiserName);
+            allocation.setAccountStatus(0);
+            allocation.setWarningAmount(null);
+            allocation.setWarningProportion(null);
+            allocation.setDeleteComment(1);
+            allocation.setAutoDelivery(0);
+            allocation.setAdminAdvertiserId(adminAdvertiserId);
+            allocation.setCreateTime(new Date());
+            allocation.setUpdateTime(new Date());
+
+            userAllocationMapper.insert(allocation);
+        }
+    }
+}

+ 95 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/AdqAccountClaimController.java

@@ -0,0 +1,95 @@
+package org.jeecg.modules.ctop.controller;
+
+import cn.com.ctop.common.module.service.IAdqAccountClaimService;
+import com.alibaba.fastjson.JSONObject;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.vo.LoginUser;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+
+/**
+ * 腾讯ADQ账户认领
+ *
+ * @author jeecg-boot
+ */
+@Slf4j
+@Api(tags = "腾讯ADQ账户认领")
+@RestController
+@RequestMapping("/ctop/adqAccountClaim")
+public class AdqAccountClaimController {
+
+    @Autowired
+    private IAdqAccountClaimService adqAccountClaimService;
+
+    /**
+     * 查询未认领的ADQ账户列表
+     */
+    @ApiOperation(value = "查询未认领的ADQ账户", notes = "查询在adq_advertiser_info中且不在ctop_user_allocation中的账户")
+    @GetMapping(value = "/unclaimedList")
+    public Result<JSONObject> queryUnclaimedAccounts(
+            @RequestParam(name = "accountIds", required = false) String accountIds,
+            @RequestParam(name = "advertiserName", required = false) String advertiserName,
+            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+        Result<JSONObject> result = new Result<>();
+        try {
+            JSONObject data = adqAccountClaimService.queryUnclaimedAccounts(accountIds, advertiserName, pageNo, pageSize);
+            result.setSuccess(true);
+            result.setResult(data);
+        } catch (Exception e) {
+            log.error("查询未认领账户失败", e);
+            result.setSuccess(false);
+            result.setMessage("查询失败:" + e.getMessage());
+        }
+        return result;
+    }
+
+    /**
+     * 查询腾讯ADQ项目列表(media_id=16,且当前用户有权限的项目)
+     */
+    @ApiOperation(value = "查询腾讯ADQ项目列表", notes = "查询media_id=16且当前用户在ctop_project_member中的项目")
+    @GetMapping(value = "/projectList")
+    public Result<List<JSONObject>> queryAdqProjects(
+            @RequestParam(name = "projectName", required = false) String projectName,
+            HttpServletRequest req) {
+        Result<List<JSONObject>> result = new Result<>();
+        try {
+            LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+            String userId = loginUser.getId();
+            List<JSONObject> projects = adqAccountClaimService.queryAdqProjects(projectName, userId);
+            result.setSuccess(true);
+            result.setResult(projects);
+        } catch (Exception e) {
+            log.error("查询项目列表失败", e);
+            result.setSuccess(false);
+            result.setMessage("查询失败:" + e.getMessage());
+        }
+        return result;
+    }
+
+    /**
+     * 批量认领账户
+     */
+    @ApiOperation(value = "批量认领账户", notes = "将选中的ADQ账户认领到指定项目下")
+    @PostMapping(value = "/batchClaim")
+    public Result<Object> batchClaimAccounts(@RequestBody JSONObject claimData) {
+        Result<Object> result = new Result<>();
+        try {
+            adqAccountClaimService.batchClaimAccounts(claimData);
+            result.setSuccess(true);
+            result.setMessage("账户认领成功");
+        } catch (Exception e) {
+            log.error("批量认领账户失败", e);
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+}