Explorar el Código

添加缺失字段

songyh hace 4 años
padre
commit
5ec5dc16c5
Se han modificado 14 ficheros con 703 adiciones y 15 borrados
  1. 3 0
      jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java
  2. 7 1
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/entity/AiBytedanceAdvertiserStrategy.java
  3. 93 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/enums/BytedanceCreativeMatTypeEnum.java
  4. 12 2
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/mapper/ByteDanceVideoInfoMapper.java
  5. 32 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/mapper/xml/ByteDanceVideoInfoMapper.xml
  6. 4 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/service/IByteDanceVideoInfoService.java
  7. 42 6
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/service/impl/AiBytedanceAdvertiserStrategyServiceImpl.java
  8. 12 2
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/service/impl/ByteDanceVideoInfoServiceImpl.java
  9. 0 4
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/aa.java
  10. 111 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/entity/UserAllocation.java
  11. 44 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/mapper/UserAllocationMapper.java
  12. 158 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/mapper/xml/UserAllocationMapper.xml
  13. 43 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/service/IUserAllocationService.java
  14. 142 0
      jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/service/impl/UserAllocationServiceImpl.java

+ 3 - 0
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -352,6 +352,9 @@ public class DateUtils extends PropertyEditorSupport {
     public static String formatDateTime() {
         return datetimeFormat.get().format(getCalendar().getTime());
     }
+    public static String formatDateTime(Long time) {
+        return datetimeFormat.get().format(time);
+    }
 
     /**
      * 获取时间字符串

+ 7 - 1
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/entity/AiBytedanceAdvertiserStrategy.java

@@ -47,6 +47,12 @@ public class AiBytedanceAdvertiserStrategy{
 	 * 单个广告组下的计划最大创建数
 	 */
 	private Integer campaignAdCnt;
+	/**广告类型*/
+	private String advertisingType;
+	/**账户预算类型*/
+	private String accountBudgetMode;
+	/**账户预算*/
+	private Integer accountBudget;
 	/**组预算类型*/
 	private String campaignBudgetMode;
 	/**组预算*/
@@ -177,7 +183,7 @@ public class AiBytedanceAdvertiserStrategy{
 	private String adFlowControlMode;
 	/**预算类型*/
 	private String adBudgetMode;
-	/**预算*/
+	/**计划预算*/
 	private Integer adBudget;
 	/**投放时间类型*/
 	private String adScheduleType;

+ 93 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/enums/BytedanceCreativeMatTypeEnum.java

@@ -0,0 +1,93 @@
+package org.jeecg.modules.bytedance.advertise.enums;
+
+public enum BytedanceCreativeMatTypeEnum {
+    /**
+     * 13 23 分别是历史遗漏素材,归类到上新素材中
+     * type字段 第一位创意创建方式,第二位素材获取方式
+     * 快手创意素材获取类型
+     */
+    BYTEDANCE_CREATIVE_MAT_TYPE_ENUM_NEW("1","上新",-60*8L,-5L),
+    BYTEDANCE_CREATIVE_MAT_TYPE_ENUM_HIGH_QUALITY("2","高质量",-28*60*24L,-1*60*24L),
+    BYTEDANCE_CREATIVE_MAT_TYPE_ENUM_MISSING("3","上新",-60*60*24L,-1*60*24L),
+    BYTEDANCE_CREATIVE_MAT_TYPE_ENUM_HISTORY("4","历史",-60*60*24L,-1*60*24L);
+
+    /**
+     * 类型
+     */
+    private String type;
+    /**
+     * 名称
+     */
+    private String name;
+    /**
+     * 素材查询的时间区间
+     */
+    private Long videoGetStartTime;
+    private Long videoGetEndTime;
+
+    BytedanceCreativeMatTypeEnum(String type, String name,Long videoGetStartTime,Long videoGetEndTime) {
+        this.type = type;
+        this.name = name;
+        this.videoGetStartTime = videoGetStartTime;
+        this.videoGetEndTime = videoGetEndTime;
+    }
+
+    public static String getNameByType(String type) {
+        for (BytedanceCreativeMatTypeEnum createTypeEnum : BytedanceCreativeMatTypeEnum.values()) {
+            if (createTypeEnum.getType().equals(type)) {
+                return createTypeEnum.getName();
+            }
+        }
+        return "";
+    }
+
+    public static Long getStartTimeByType(String type) {
+        for (BytedanceCreativeMatTypeEnum createTypeEnum : BytedanceCreativeMatTypeEnum.values()) {
+            if (createTypeEnum.getType().equals(type)) {
+                return createTypeEnum.getVideoGetStartTime();
+            }
+        }
+        return -60*8L;
+    }
+
+    public static Long getEndTimeByType(String type) {
+        for (BytedanceCreativeMatTypeEnum createTypeEnum : BytedanceCreativeMatTypeEnum.values()) {
+            if (createTypeEnum.getType().equals(type)) {
+                return createTypeEnum.getVideoGetEndTime();
+            }
+        }
+        return -5L;
+    }
+
+    public String getType() {
+        return this.type;
+    }
+
+    public String getName() {
+        return this.name;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public void setName(String value) {
+        this.name = value;
+    }
+
+    public Long getVideoGetStartTime() {
+        return videoGetStartTime;
+    }
+
+    public void setVideoGetStartTime(Long videoGetStartTime) {
+        this.videoGetStartTime = videoGetStartTime;
+    }
+
+    public Long getVideoGetEndTime() {
+        return videoGetEndTime;
+    }
+
+    public void setVideoGetEndTime(Long videoGetEndTime) {
+        this.videoGetEndTime = videoGetEndTime;
+    }
+}

+ 12 - 2
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/mapper/ByteDanceVideoInfoMapper.java

@@ -13,9 +13,19 @@ import java.util.List;
  * @Version: V1.0
  */
 public interface ByteDanceVideoInfoMapper extends BaseMapper<ByteDanceVideoInfo> {
-
     void replaceBatch(@Param(value = "videoList") List<ByteDanceVideoInfo> videoInfoList);
-
     void updateVideoVerticalType();
     void updateVideoHorizonType();
+
+    /**
+     * 查询规定时间段内尚未创建创意的素材信息
+     * @param accountId
+     * @param startTime
+     * @param endTime
+     * @param videoCnt
+     * @return
+     */
+    List<ByteDanceVideoInfo> getNewVideoByParams(@Param(value = "accountId") Long accountId, @Param(value = "startTime")String startTime, @Param(value = "endTime")String endTime, @Param(value = "videoCnt")Long videoCnt,@Param(value = "creativeCnt")Long creativeCnt);
+
+    List<ByteDanceVideoInfo> topMatByParams(@Param(value = "projectId")Long projectId, @Param(value = "accountId")Long accountId, @Param(value = "startTime")String startTime, @Param(value = "endTime")String endTime, @Param(value = "videoCnt")Long videoCnt);
 }

+ 32 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/mapper/xml/ByteDanceVideoInfoMapper.xml

@@ -66,4 +66,36 @@
         where height &lt; width and type is null
         and (width between 1280 and 2560)  and (height between 720 and 1440)
     </update>
+    <select id="getNewVideoByParams"
+            resultType="org.jeecg.modules.bytedance.advertise.entity.ByteDanceVideoInfo">
+        select video.*,
+        (select count(1)
+        from ctop_bytedance_creative c
+        where c.video_id = video.vid and c.account_id = '${accountId}') as creativeCnt
+        from ctop_bytedance_video_info video
+        where account_id = #{accountId}
+        and material_upload_time &gt;= #{startTime}
+        and material_upload_time &lt;= #{endTime}
+        and cmi.id is not null
+        having creativeCnt &lt;= #{creativeCnt}
+        order by material_upload_time desc
+        limit #{videoCnt}
+    </select>
+    <select id="topMatByParams" resultType="org.jeecg.modules.bytedance.advertise.entity.ByteDanceVideoInfo">
+        select video.*
+        from (select report.material_id, sum(cost) as totalCost, report.account_id
+        from ctop_bytedance_report_material_daily report
+        left join ctop_user_allocation cua on report.account_id = cua.account_id
+        where cua.project_id = #{projectId}
+        and report.stat_datetime &gt;= #{startTime}
+        and report.stat_datetime &lt;= #{endTime}
+        group by report.material_id
+        order by sum(report.cost) desc) a
+        left join ctop_bytedance_video_info video
+        on a.material_id = video.material_id and video.account_id = a.account_id
+        left join ctop_material_info cmi on cmi.code = video.signature
+        where video.account_id = #{accountId}
+        and cmi.id is not null
+        limit #{videoCnt}
+    </select>
 </mapper>

+ 4 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/service/IByteDanceVideoInfoService.java

@@ -18,4 +18,8 @@ public interface IByteDanceVideoInfoService extends IService<ByteDanceVideoInfo>
     ByteDanceVideoInfo getOneByParams(Long materialId);
 
     void updateMaterialType();
+
+    List<ByteDanceVideoInfo> listByParams(Long accountId, String startTime, String endTime, Long videoCnt,long creativeCnt);
+
+    List<ByteDanceVideoInfo> topMatByParams(Long projectId, Long accountId, String startTime, String endTime, Long videoCnt);
 }

+ 42 - 6
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/service/impl/AiBytedanceAdvertiserStrategyServiceImpl.java

@@ -2,17 +2,20 @@ package org.jeecg.modules.bytedance.advertise.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
-import org.checkerframework.checker.units.qual.A;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.DateUtils;
 import org.jeecg.modules.bytedance.advertise.dockapi.marketing;
 import org.jeecg.modules.bytedance.advertise.entity.AiBytedanceAdvertiserStrategy;
+import org.jeecg.modules.bytedance.advertise.entity.ByteDanceVideoInfo;
 import org.jeecg.modules.bytedance.advertise.entity.UpdAdStaOrCpaOrBudget;
-import org.jeecg.modules.bytedance.advertise.entity.UpdPriceVo;
+import org.jeecg.modules.bytedance.advertise.enums.BytedanceCreativeMatTypeEnum;
 import org.jeecg.modules.bytedance.advertise.mapper.AiBytedanceAdvertiserStrategyMapper;
 import org.jeecg.modules.bytedance.advertise.service.IAiBytedanceAdvertiserStrategyService;
+import org.jeecg.modules.bytedance.advertise.service.IByteDanceVideoInfoService;
 import org.jeecg.modules.bytedance.common.entity.CtopOauthToken;
+import org.jeecg.modules.bytedance.common.entity.UserAllocation;
 import org.jeecg.modules.bytedance.common.service.ICtopOauthTokenService;
-import org.jeecg.modules.bytedance.common.utils.Check;
+import org.jeecg.modules.bytedance.common.service.IUserAllocationService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -35,7 +38,8 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
 
     @Resource
     private AiBytedanceAdvertiserStrategyMapper aiBytedanceAdvertiserStrategyMapper;
-
+    @Autowired
+    private IUserAllocationService userAllocationService;
 
 
 
@@ -46,16 +50,48 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
             log.info("token获取失败=>accountId:{}", token.getAccountId());
             return videoCnt;
         }
-        //TODO 需要添加定时获取视频+图片的定时任务
+
+        UserAllocation userAllocation = userAllocationService.getByAccountId(strategy.getAccountId());
+        if(null == userAllocation||userAllocation.getAccountStatus()!=0){
+            log.info("此账户不存在或者已经被关闭=>accountId:{}", token.getAccountId());
+            return videoCnt;
+        }
+        //查询相应的素材信息
+        Long timeStart = BytedanceCreativeMatTypeEnum.getStartTimeByType(createType.toString());
+        Long timeEnd = BytedanceCreativeMatTypeEnum.getEndTimeByType(createType.toString());
+        Long now = System.currentTimeMillis();
+        String startTime = DateUtils.formatDateTime(now + timeStart * 60 * 1000L);
+        String endTime = DateUtils.formatDateTime(now + timeEnd * 60 * 1000L);
+        List<ByteDanceVideoInfo> videoInfos = getVideoInfoByCreateType(userAllocation.getProjectId(),strategy,startTime,endTime,createType,videoCnt);
+        if(null == videoInfos||videoInfos.isEmpty()){
+            log.info("获取视频素材为空=>accountId:{}", token.getAccountId());
+            return videoCnt;
+        }
+        //
         /**
          * 1:创建组
          * 查询当前账户排列到的dp链接标识号
+         *
          */
-
         //2:创建计划
         //3:创建创意
         return videoCnt;
     }
+    @Autowired
+    private IByteDanceVideoInfoService videoInfoService;
+    private List<ByteDanceVideoInfo> getVideoInfoByCreateType(Long projectId,AiBytedanceAdvertiserStrategy strategy, String startTime, String endTime, Integer createType, Long videoCnt) {
+        //1:上新素材 2:跑量素材 3:遗漏素材 4:打捞素材
+        if(createType == 1||createType == 3){
+            return videoInfoService.listByParams(strategy.getAccountId(),startTime,endTime,videoCnt,0);
+        }else if(createType == 2){
+            startTime = startTime.substring(0,10);
+            endTime = endTime.substring(0,10);
+            return videoInfoService.topMatByParams(projectId,strategy.getAccountId(),startTime,endTime,videoCnt);
+        }else if(createType == 4){
+            return videoInfoService.listByParams(strategy.getAccountId(),startTime,endTime,videoCnt,20);
+        }
+        return null;
+    }
 
 
     /**

+ 12 - 2
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/service/impl/ByteDanceVideoInfoServiceImpl.java

@@ -5,10 +5,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.jeecg.modules.bytedance.advertise.entity.ByteDanceVideoInfo;
 import org.jeecg.modules.bytedance.advertise.mapper.ByteDanceVideoInfoMapper;
 import org.jeecg.modules.bytedance.advertise.service.IByteDanceVideoInfoService;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.List;
 
 /**
@@ -20,7 +20,7 @@ import java.util.List;
 @Service
 @Primary
 public class ByteDanceVideoInfoServiceImpl extends ServiceImpl<ByteDanceVideoInfoMapper, ByteDanceVideoInfo> implements IByteDanceVideoInfoService {
-    @Autowired
+    @Resource
     private ByteDanceVideoInfoMapper videoInfoMapper;
 
     @Override
@@ -41,4 +41,14 @@ public class ByteDanceVideoInfoServiceImpl extends ServiceImpl<ByteDanceVideoInf
         videoInfoMapper.updateVideoVerticalType();
         videoInfoMapper.updateVideoHorizonType();
     }
+
+    @Override
+    public List<ByteDanceVideoInfo> listByParams(Long accountId, String startTime, String endTime, Long videoCnt,long creativeCnt) {
+        return videoInfoMapper.getNewVideoByParams(accountId,startTime,endTime,videoCnt,creativeCnt);
+    }
+
+    @Override
+    public List<ByteDanceVideoInfo> topMatByParams(Long projectId, Long accountId, String startTime, String endTime, Long videoCnt) {
+        return videoInfoMapper.topMatByParams(projectId,accountId,startTime,endTime,videoCnt);
+    }
 }

+ 0 - 4
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/aa.java

@@ -1,4 +0,0 @@
-package org.jeecg.modules.bytedance.common;
-
-public class aa {
-}

+ 111 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/entity/UserAllocation.java

@@ -0,0 +1,111 @@
+package org.jeecg.modules.bytedance.common.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+import org.jeecg.common.aspect.annotation.Dict;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 用户分配
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2019-08-08
+ */
+@Data
+@TableName("ctop_user_allocation")
+public class UserAllocation implements Serializable {
+
+    /**
+     * 主键ID
+     */
+    @TableId(type = IdType.AUTO)
+    private Long id;
+    /**
+     * 登陆人id
+     */
+    private String userId;
+    private String userName;
+    /**
+     * 账户id --授权
+     */
+    private Long accountId;
+    /**
+     * 广告主ID
+     */
+    @Dict(dicCode = "id", dictTable = "ctop_advertiser", dicText = "name")
+    private String advertiserId;
+    private String systemType;
+    /**
+     * 项目id
+     */
+    @Dict(dicCode = "id", dictTable = "ctop_project", dicText = "project_name")
+    private Long projectId;
+
+    /**
+     * 输入账号  --登陆
+     */
+    private String accountName;
+
+    /**
+     * 预警 金额
+     */
+    private BigDecimal warningAmount;
+
+    /**
+     * 预警 比例
+     */
+    private BigDecimal warningProportion;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    /**
+     * 授权名称
+     */
+    private String authName;
+
+
+    /**
+     * 0 启动
+     * 1 禁用
+     */
+    private Integer accountStatus;
+
+    /**
+     * 检测链接预警
+     * 0 启动
+     * 1 禁用
+     */
+    private Integer monitoringLink;
+
+    /**
+     * 检测链接预警
+     * 0 启动
+     * 1 禁用
+     */
+    private Integer landingPage;
+
+    /**
+     * 是否开启删评论
+     * 0 启动
+     * 1 禁用
+     */
+    private Integer deleteComment;
+
+    /**
+     * 修改时间
+     */
+    private Date updateTime;
+    /**
+     * 平台类型 1 头条 2快手
+     */
+    private String mediaId;
+}

+ 44 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/mapper/UserAllocationMapper.java

@@ -0,0 +1,44 @@
+package org.jeecg.modules.bytedance.common.mapper;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+import org.jeecg.modules.bytedance.common.entity.UserAllocation;
+
+import java.util.List;
+
+/**
+ * @Description: 用户分配
+ * @Author: jeecg-boot
+ * @Date: 2019-08-08
+ * @Version: V1.0
+ */
+public interface UserAllocationMapper extends BaseMapper<UserAllocation> {
+    List<UserAllocation> selectAccountListByProjectId(@Param("projectId") Long projectId);
+
+    String queryAdvertiserId(@Param("accountId") Long accountId);
+
+    String queryUserIdByAccountId(@Param("accountId") Long accountId);
+
+    List<JSONObject> getAccountListByProject(@Param("projectId") Long projectId);
+
+    List<JSONObject> getUserIdListByProjectId(@Param("projectId") Long projectId);
+
+    List<JSONObject> getAccountIdListByUserId(@Param("userId") Long userId);
+
+    List<JSONObject> getAccountIdsByUserId(@Param("userId") String userId);
+
+    List<JSONObject> getAllAccountIdsByMediaId(@Param("mediaId") String mediaId);
+
+    Long getProjectIdByAccountId(@Param("accountId") Long accountId);
+
+    UserAllocation getUserAllocation(@Param("accountId") Long accountId);
+
+    JSONObject getSwitchStatusByAccount(@Param("accountId") Long accountId);
+
+    List<Long>  queryAccountsByDeleteComment();
+
+    List<UserAllocation> listByMediaId(@Param("mediaId")String mediaId, @Param("accountStatus")Integer accountStatus);
+
+    List<JSONObject> getAccountListByProjectList(@Param("list") List list);
+}

+ 158 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/mapper/xml/UserAllocationMapper.xml

@@ -0,0 +1,158 @@
+<?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="org.jeecg.modules.bytedance.common.mapper.UserAllocationMapper">
+
+    <select id="selectAccountListByProjectId" resultType="org.jeecg.modules.bytedance.common.entity.UserAllocation">
+        select
+        a.user_id as userId,
+        a.user_name as userName,
+        a.auth_name as authName,
+        a.account_id as accountId
+        from
+        ctop_user_allocation a
+        left join ctop_project b on a.project_id = b.id
+        where b.id = #{projectId}
+    </select>
+
+    <select id="queryAdvertiserId" resultType="String">
+        select
+            distinct advertiser_id
+        from
+            ctop_user_allocation
+        where account_id=#{accountId}
+    </select>
+    <select id="queryUserIdByAccountId" resultType="String">
+        select
+            distinct user_id
+        from
+            ctop_user_allocation
+        where account_id=#{accountId}
+    </select>
+
+    <select id="getAccountListByProject" resultType="com.alibaba.fastjson.JSONObject">
+       select
+       t1.account_id as 'accountId',
+       (select  realname  from sys_user where  id = t1.user_id ) as 'userName',
+       t1.auth_name as 'authName'
+       from ctop_user_allocation t1
+       where t1.project_id = #{projectId}
+       order by t1.create_time desc
+    </select>
+
+    <select id="getAccountListByProjectList" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        t1.project_id as 'projectId',
+        t1.account_id as 'accountId',
+        (select realname from sys_user where id = t1.user_id ) as 'userName',
+        t1.auth_name as 'authName',
+        t1.account_status as 'accountStatus'
+        from ctop_user_allocation t1
+        where t1.project_id in
+        <foreach collection="list" item="item" separator=","
+                 open="(" close=")">
+            #{item}
+        </foreach>
+
+
+        order by t1.create_time desc
+    </select>
+
+
+    <select id="getUserIdListByProjectId" resultType="com.alibaba.fastjson.JSONObject">
+   SELECT t1.user_id as 'userId',
+    t1.account_id as 'accountId',
+    t1.user_name  as 'userName'
+    from  ctop_kuaishou_advertiser_base_info t1  LEFT JOIN
+    ctop_user_allocation  t2
+    ON t1.account_id = t2.account_id
+    WHERE t2.project_id = #{projectId}
+    AND t2.account_status = 0
+    GROUP BY t1.user_id;
+    </select>
+
+
+    <select id="getAccountIdListByUserId" resultType="com.alibaba.fastjson.JSONObject">
+    SELECT
+    t1.account_id as 'accountId',
+    t1.auth_name  as 'authName',
+    t1.user_name as 'userName'
+    from ctop_user_allocation   t1  LEFT JOIN
+    ctop_kuaishou_advertiser_base_info t2
+    ON t1.account_id = t2.account_id
+    WHERE t2.user_id = #{userId}
+    AND t1.account_status = 0
+    </select>
+
+    <select id="getAccountIdsByUserId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            allocation.account_id,
+            allocation.auth_name,
+            project.project_name as project_name
+        FROM
+            ctop_user_allocation allocation
+            left join ctop_project project on allocation.project_id = project.id
+        WHERE
+            allocation.user_id = #{userId}
+          and allocation.account_status=0
+    </select>
+
+
+    <select id="getAllAccountIdsByMediaId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            account_id,
+            auth_name,
+            project_name
+        FROM
+            ctop_user_allocation
+        WHERE
+            media_id=#{mediaId}
+          and account_status=0
+    </select>
+
+    <select id="getProjectIdByAccountId" resultType="java.lang.Long">
+    select  project_id  from  ctop_user_allocation
+    where account_id = #{accountId}
+    limit 1
+    </select>
+
+    <select id="getUserAllocation" resultType="org.jeecg.modules.bytedance.common.entity.UserAllocation">
+    select  *  from  ctop_user_allocation
+    where account_id=#{accountId}
+    limit 1
+    </select>
+
+    <select id="getSwitchStatusByAccount" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            monitoring_link,
+            landing_page
+        FROM
+            ctop_user_allocation
+        WHERE
+            account_id = #{accountId}
+    </select>
+
+    <select id="queryAccountsByDeleteComment" resultType="java.lang.Long">
+        SELECT
+            account_id
+        FROM
+            ctop_user_allocation
+        WHERE
+            media_id = 2
+          AND account_status = 0
+          AND delete_comment = 0
+    </select>
+    <select id="listByMediaId" resultType="org.jeecg.modules.bytedance.common.entity.UserAllocation">
+        select a.* from ctop_user_allocation a
+        left join ctop_project p on p.id = a.project_id
+        where
+        1=1
+        <if test="null!=accountStatus">
+            and a.account_status = #{accountStatus}
+        </if>
+        <if test="null!=mediaId">
+            and p.media_id = #{mediaId}
+        </if>
+    </select>
+
+
+</mapper>

+ 43 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/service/IUserAllocationService.java

@@ -0,0 +1,43 @@
+package org.jeecg.modules.bytedance.common.service;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.bytedance.common.entity.UserAllocation;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description: 用户分配
+ * @Author: jeecg-boot
+ * @Date: 2019-08-08
+ * @Version: V1.0
+ */
+public interface IUserAllocationService extends IService<UserAllocation> {
+
+    UserAllocation getByAccountId(Long accountId);
+
+    List<UserAllocation> getByParams(Long projectId, String systemType,Integer accountStatus);
+
+    List<UserAllocation> getByMediaId(String mediaId);
+
+    List<UserAllocation> listByMediaId(String mediaId, int accountStatus);
+
+    String getAdvertiserIdByAccountId(Long accountId);
+
+    List<JSONObject> getAccountListByProject(Long projectId);
+
+    List<JSONObject> getUserIdListByProjectId(Long projectId);
+
+    List<JSONObject> getAccountIdListByUserId(Long userId);
+
+    List<JSONObject> getAccountIdsByUserId(String userId);
+
+    List<UserAllocation> getUserAllocations(String mediaId ,int switchType);
+
+    JSONObject getSwitchStatusByAccount(Long accountId);
+
+    List<Long> getAccountsByDeleteComment();
+
+    Map<Long, List<JSONObject>> getAccountListByProjectList(List<JSONObject> projectList);
+}

+ 142 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/service/impl/UserAllocationServiceImpl.java

@@ -0,0 +1,142 @@
+package org.jeecg.modules.bytedance.common.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.jeecg.modules.bytedance.common.entity.UserAllocation;
+import org.jeecg.modules.bytedance.common.mapper.UserAllocationMapper;
+import org.jeecg.modules.bytedance.common.service.IUserAllocationService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description: 用户分配
+ * @Author: jeecg-boot
+ * @Date: 2019-08-08
+ * @Version: V1.0
+ */
+@Service
+public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper, UserAllocation> implements IUserAllocationService {
+
+    @Resource
+    UserAllocationMapper userAllocationMapper;
+
+    @Override
+    public UserAllocation getByAccountId(Long accountId) {
+        QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("account_id", accountId + "").orderByDesc("id").last("limit 1");
+        return this.getOne(queryWrapper);
+    }
+
+    @Override
+    public List<UserAllocation> getByParams(Long projectId, String systemType, Integer accountStatus) {
+        QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
+        if (null != projectId && projectId != 0) {
+            queryWrapper.eq("project_id", projectId);
+        }
+        if (null != systemType && !"".equals(systemType.trim())) {
+            queryWrapper.eq("system_type", systemType);
+        }
+        if (null != accountStatus) {
+            queryWrapper.eq("account_status", accountStatus);
+        }
+        queryWrapper.orderByDesc("id");
+        return this.list(queryWrapper);
+    }
+
+    @Override
+    public List<UserAllocation> getByMediaId(String mediaId) {
+        QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
+        if ("".equals(mediaId)) {
+            queryWrapper.eq("media_id", mediaId);
+        }
+        return this.list(queryWrapper);
+    }
+
+    @Override
+    public List<UserAllocation> listByMediaId(String mediaId, int accountStatus) {
+        return userAllocationMapper.listByMediaId(mediaId, accountStatus);
+    }
+
+    @Override
+    public String getAdvertiserIdByAccountId(Long accountId) {
+        return userAllocationMapper.queryAdvertiserId(accountId);
+    }
+
+    @Override
+    public List<JSONObject> getAccountListByProject(Long projectId) {
+        return userAllocationMapper.getAccountListByProject(projectId);
+    }
+
+    /**
+     * 获取项目下的所有userId
+     *
+     * @param projectId
+     * @return
+     */
+    @Override
+    public List<JSONObject> getUserIdListByProjectId(Long projectId) {
+        return userAllocationMapper.getUserIdListByProjectId(projectId);
+    }
+
+    @Override
+    public List<JSONObject> getAccountIdListByUserId(Long userId) {
+        return userAllocationMapper.getAccountIdListByUserId(userId);
+    }
+
+    @Override
+    public List<JSONObject> getAccountIdsByUserId(String userId) {
+        List<JSONObject> result = new ArrayList<>();
+        if (userId.equals("e9ca23d68d884d4ebb19d07889727dae")) {
+            result = userAllocationMapper.getAllAccountIdsByMediaId("2");
+        } else {
+            result = userAllocationMapper.getAccountIdsByUserId(userId);
+
+        }
+        return result;
+    }
+
+    @Override
+    public List<UserAllocation> getUserAllocations(String mediaId, int switchType) {
+        QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("media_id", mediaId);
+        queryWrapper.eq("account_status", 0);
+        queryWrapper.eq("monitoring_link", 0);
+        queryWrapper.orderByDesc("create_time");
+        return this.list(queryWrapper);
+    }
+
+    @Override
+    public JSONObject getSwitchStatusByAccount(Long accountId) {
+        return userAllocationMapper.getSwitchStatusByAccount(accountId);
+    }
+
+    @Override
+    public List<Long> getAccountsByDeleteComment() {
+        return userAllocationMapper.queryAccountsByDeleteComment();
+    }
+
+    @Override
+    public Map<Long, List<JSONObject>> getAccountListByProjectList(List<JSONObject> projectList) {
+        Map<Long, List<JSONObject>> map = new HashMap<>();
+        List list = new ArrayList();
+        for (int i = 0; i < projectList.size(); i++) {
+            JSONObject jsonObject = projectList.get(i);
+            list.add(jsonObject.getLong("projectId"));
+            map.put(jsonObject.getLong("projectId"), new ArrayList<>());
+        }
+        List<JSONObject> jsonList = userAllocationMapper.getAccountListByProjectList(list);
+        for (int i = 0; i < jsonList.size(); i++) {
+            JSONObject jsonObject = jsonList.get(i);
+            Long projectId = jsonObject.getLong("projectId");
+            List<JSONObject> jsonObjects = map.get(projectId);
+            jsonObjects.add(jsonObject);
+        }
+        return map;
+    }
+}