Pārlūkot izejas kodu

Merge branch 'master' into master_material

yumeng 4 gadi atpakaļ
vecāks
revīzija
abcfe6c9ad
20 mainītis faili ar 1147 papildinājumiem un 315 dzēšanām
  1. 2 0
      jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java
  2. 205 0
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/controller/CwjsSaleAssistantInfoController.java
  3. 56 0
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/entity/CwjsSaleAssistantInfo.java
  4. 37 0
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/mapper/CwjsSaleAssistantInfoMapper.java
  5. 83 0
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/mapper/xml/CwjsSaleAssistantInfoMapper.xml
  6. 23 0
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/service/ICwjsSaleAssistantInfoService.java
  7. 78 0
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/service/impl/CwjsSaleAssistantInfoServiceImpl.java
  8. 2 2
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/mapper/xml/ReportSettlementMapper.xml
  9. 8 8
      jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/serviceImpl/SettlementFileInfoServiceImpl.java
  10. 1 1
      jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml
  11. 5 1
      jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/document/mapper/xml/AuditRejectedResubmitMapper.xml
  12. 2 1
      jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/document/mapper/xml/DocumentLibraryMapper.xml
  13. 50 28
      jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/document/service/impl/AuditRejectedResubmitServiceImpl.java
  14. 4 3
      jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/document/service/impl/DocumentLibraryServiceImpl.java
  15. 46 6
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialReportOverViewController.java
  16. 12 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/MaterialReportOverViewMapper.java
  17. 232 175
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/MaterialReportOverViewMapper.xml
  18. 15 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IMaterialReportOverViewService.java
  19. 283 87
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/MaterialReportOverViewServiceImpl.java
  20. 3 3
      jeecg-cloud-module/jeecg-cloud-system-start/src/main/resources/application-dev.yml

+ 2 - 0
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java

@@ -235,6 +235,8 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/document/library/**", "anon");
         filterChainDefinitionMap.put("/rejected/audit/**", "anon");
 
+        filterChainDefinitionMap.put("/cwjsSaleAssistantInfo/**", "anon");
+
         // 添加自己的过滤器并且取名为jwt
         Map<String, Filter> filterMap = new HashMap<>(1);
         filterMap.put("jwt", new JwtFilter());

+ 205 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/controller/CwjsSaleAssistantInfoController.java

@@ -0,0 +1,205 @@
+package org.jeecg.ctop.finance.policy.controller;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang3.StringUtils;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.oConvertUtils;
+import java.util.Date;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.extern.slf4j.Slf4j;
+
+import org.jeecg.ctop.finance.policy.entity.CwjsSaleAssistantInfo;
+import org.jeecg.ctop.finance.policy.service.ICwjsSaleAssistantInfoService;
+import org.jeecg.ctop.finance.policy.utils.Check;
+import org.jeecg.modules.system.service.ISysRoleService;
+import org.jeecgframework.poi.excel.ExcelImportUtil;
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
+import org.jeecgframework.poi.excel.entity.ExportParams;
+import org.jeecgframework.poi.excel.entity.ImportParams;
+import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.servlet.ModelAndView;
+import com.alibaba.fastjson.JSON;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+
+ /**
+ * aaa
+ * @author jeecg-boot
+ * @date   2021-10-18
+ * @version V1.0
+ */
+@Slf4j
+@Api(tags="销售与销售助理关系")
+@RestController
+@RequestMapping("/cwjsSaleAssistantInfo")
+public class CwjsSaleAssistantInfoController {
+	@Autowired
+	private ICwjsSaleAssistantInfoService cwjsSaleAssistantInfoService;
+
+
+	 @Autowired
+	 private ISysRoleService roleService;
+
+
+
+	 /**
+	  * 分页列表查询
+	 * @param cwjsSaleAssistantInfo
+	 * @param pageNo
+	 * @param pageSize
+	 * @param req
+	 * @return
+	 */
+	@ApiOperation(value="销售与销售助理关系-分页列表查询", notes="销售与销售助理对应关系-分页列表查询")
+	@GetMapping(value = "/list")
+	public Result<IPage<CwjsSaleAssistantInfo>> queryPageList(CwjsSaleAssistantInfo cwjsSaleAssistantInfo,
+															  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
+															  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
+															  HttpServletRequest req) {
+		Result<IPage<CwjsSaleAssistantInfo>> result = new Result<>();
+		QueryWrapper<CwjsSaleAssistantInfo> queryWrapper = QueryGenerator.initQueryWrapper(cwjsSaleAssistantInfo, req.getParameterMap());
+		Page<CwjsSaleAssistantInfo> page = new Page<CwjsSaleAssistantInfo>(pageNo, pageSize);
+		IPage<CwjsSaleAssistantInfo> pageList = cwjsSaleAssistantInfoService.page(page, queryWrapper);
+		result.setSuccess(true);
+		result.setResult(pageList);
+		return result;
+	}
+
+	/**
+	  *   添加
+	 * @param cwjsSaleAssistantInfo
+	 * @return
+	 */
+	@ApiOperation(value="销售与销售助理对应关系-添加", notes="销售与销售助理对应关系-添加")
+	@PostMapping(value = "/add")
+	public Result<CwjsSaleAssistantInfo> add(@RequestBody CwjsSaleAssistantInfo cwjsSaleAssistantInfo) {
+		Result<CwjsSaleAssistantInfo> result = new Result<>();
+		try {
+			cwjsSaleAssistantInfoService.save(cwjsSaleAssistantInfo);
+			result.success("添加成功!");
+		} catch (Exception e) {
+			log.error(e.getMessage(),e);
+			result.error500("操作失败");
+		}
+		return result;
+	}
+
+	/**
+	  *  编辑
+	 * @param cwjsSaleAssistantInfo
+	 * @return
+	 */
+	@ApiOperation(value="销售与销售助理对应关系-编辑", notes="销售与销售助理对应关系-编辑")
+	@PostMapping(value = "/edit")
+	public Result<CwjsSaleAssistantInfo> edit(@RequestBody CwjsSaleAssistantInfo cwjsSaleAssistantInfo) {
+		Result<CwjsSaleAssistantInfo> result = new Result<CwjsSaleAssistantInfo>();
+		CwjsSaleAssistantInfo cwjsSaleAssistantInfoEntity = cwjsSaleAssistantInfoService.getById(cwjsSaleAssistantInfo.getId());
+		if(cwjsSaleAssistantInfoEntity==null) {
+			result.error500("未找到对应实体");
+		}else {
+			boolean ok = cwjsSaleAssistantInfoService.updateById(cwjsSaleAssistantInfo);
+			if(ok) {
+				result.success("修改成功!");
+			}
+		}
+
+		return result;
+	}
+
+	/**
+	  *   通过id删除
+	 * @param id
+	 * @return
+	 */
+	@ApiOperation(value="销售与销售助理对应关系-通过id删除", notes="销售与销售助理对应关系-通过id删除")
+	@GetMapping(value = "/delete")
+	public Result<?> delete(@RequestParam(name="id") String id) {
+		try {
+			cwjsSaleAssistantInfoService.removeById(id);
+		} catch (Exception e) {
+			log.error("删除失败",e.getMessage());
+			return Result.error("删除失败!");
+		}
+		return Result.ok("删除成功!");
+	}
+
+	/**
+	 *  批量删除
+	 * @param ids
+	 * @return
+	 */
+	@ApiOperation(value="销售与销售助理对应关系-批量删除", notes="销售与销售助理对应关系-批量删除")
+	@DeleteMapping(value = "/deleteBatch")
+	public Result<CwjsSaleAssistantInfo> deleteBatch(@RequestParam(name="ids") String ids) {
+		Result<CwjsSaleAssistantInfo> result = new Result<>();
+		if(ids==null || "".equals(ids.trim())) {
+			result.error500("参数不识别!");
+		}else {
+			this.cwjsSaleAssistantInfoService.removeByIds(Arrays.asList(ids.split(",")));
+			result.success("删除成功!");
+		}
+		return result;
+	}
+
+	/**
+	  * 通过id查询
+	 * @param id
+	 * @return
+	 */
+	@ApiOperation(value="销售与销售助理对应关系-通过id查询", notes="销售与销售助理对应关系-通过id查询")
+	@GetMapping(value = "/queryById")
+	public Result<CwjsSaleAssistantInfo> queryById(@RequestParam(name="id",required=true) String id) {
+		Result<CwjsSaleAssistantInfo> result = new Result<>();
+		CwjsSaleAssistantInfo cwjsSaleAssistantInfo = cwjsSaleAssistantInfoService.getById(id);
+		if(cwjsSaleAssistantInfo==null) {
+			result.error500("未找到对应实体");
+		}else {
+			result.setResult(cwjsSaleAssistantInfo);
+			result.setSuccess(true);
+		}
+		return result;
+	}
+
+
+
+
+	 @ApiOperation(value="销售/销售助理下拉框", notes="销售/销售助理下拉框")
+	 @GetMapping(value = "/getSaleListByUserDepart")
+	 public Result<IPage<CwjsSaleAssistantInfo>> getSaleListByUserDepart(@RequestParam(name="userId") String userId) {
+	 	//查询用户角色
+		 String roleCode = roleService.getRoleCodeByUserId(userId);
+		 //管理员 查询全部
+		 if (StringUtils.equals("admin",roleCode)){
+		 	userId = null;
+		 }
+		return cwjsSaleAssistantInfoService.getSaleListByUserDepart(userId);
+
+	 }
+
+
+
+	 @ApiOperation(value="政策新增-销售回显下拉框", notes="政策新增-销售回显下拉框")
+	 @GetMapping(value = "/getCwSaleAndAssistantList")
+	 public Result<IPage<CwjsSaleAssistantInfo>> getCwSaleAndAssistantList(@RequestParam(name="userId") String userId) {
+		return cwjsSaleAssistantInfoService.getCwSaleAndAssistantList(userId);
+
+	 }
+
+
+}

+ 56 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/entity/CwjsSaleAssistantInfo.java

@@ -0,0 +1,56 @@
+package org.jeecg.ctop.finance.policy.entity;
+
+import java.io.Serializable;
+import java.util.Date;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.TableField;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+/**
+ * aaa
+ * @author jeecg-boot
+ * @date   2021-10-18
+ * @version V1.0
+ */
+@Data
+@TableName("ctop_cwjs_sale_assistant_info")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value="ctop_cwjs_sale_assistant_info对象", description="销售与销售助理对应关系")
+public class CwjsSaleAssistantInfo {
+    
+	/**id*/
+	@TableId(type = IdType.AUTO)
+    @ApiModelProperty(value = "id")
+	private Integer id;
+	/**销售人员id*/
+    @ApiModelProperty(value = "销售人员id")
+	private String saleId;
+	/**销售人员姓名*/
+    @ApiModelProperty(value = "销售人员姓名")
+	private String saleName;
+	/**销售助理id*/
+    @ApiModelProperty(value = "销售助理id")
+	private String assistantId;
+	/**销售助理名称*/
+    @ApiModelProperty(value = "销售助理名称")
+	private String assistantName;
+	/**是否 删除 0-否 1-是*/
+    @ApiModelProperty(value = "是否 删除 0-否 1-是")
+	private Integer delFlag;
+	/**createTime*/
+    @ApiModelProperty(value = "createTime")
+	private Date createTime;
+	/**updateTime*/
+    @ApiModelProperty(value = "updateTime")
+	private Date updateTime;
+}

+ 37 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/mapper/CwjsSaleAssistantInfoMapper.java

@@ -0,0 +1,37 @@
+package org.jeecg.ctop.finance.policy.mapper;
+
+import java.util.List;
+
+import org.apache.ibatis.annotations.Param;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.jeecg.ctop.finance.policy.entity.CwjsSaleAssistantInfo;
+
+/**
+ * aaa
+ * @author jeecg-boot
+ * 2021-10-18
+ * @version V1.0
+ */
+public interface CwjsSaleAssistantInfoMapper extends BaseMapper<CwjsSaleAssistantInfo> {
+
+    /**
+     * 根据用户部门查看该部门下的人员
+     * @param userId
+     * @return
+     */
+    List <CwjsSaleAssistantInfo> getSaleListByUserDepart(String userId);
+
+    /**
+     * 查询对应销售
+     * @param userId
+     * @return
+     */
+    List <CwjsSaleAssistantInfo> getCwSaleNameList(String userId);
+
+    /**
+     * 查询对应销售助理
+     * @param userId
+     * @return
+     */
+    List <CwjsSaleAssistantInfo> getCwAssistantNameList(String userId);
+}

+ 83 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/mapper/xml/CwjsSaleAssistantInfoMapper.xml

@@ -0,0 +1,83 @@
+<?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.ctop.finance.policy.mapper.CwjsSaleAssistantInfoMapper">
+
+
+    <!-- 根据用户部门查看该部门下的人员-->
+    <select id="getSaleListByUserDepart" resultType="org.jeecg.ctop.finance.policy.entity.CwjsSaleAssistantInfo">
+        SELECT
+            id as saleId,
+            realname as saleName
+        FROM
+            sys_user
+        WHERE
+            STATUS = 1
+          AND del_flag = 0
+          AND org_code IN (
+            SELECT
+                u.org_code
+            FROM
+                sys_user u,
+                sys_depart d
+            WHERE
+                u.org_code = d.org_code
+              AND d.del_flag = 0
+            AND u.status = 1
+            AND u.del_flag = 0
+              <choose>
+                <when test="userId !=null and userId != ''">
+                    AND u.id = #{userId}
+                </when>
+                <otherwise>
+                    AND ( d.depart_name LIKE '%销售%' OR d.depart_name LIKE '%渠道%' )
+                </otherwise>
+              </choose>
+            GROUP BY
+                d.id
+        )
+        ORDER BY
+            create_time
+    </select>
+
+<!--查询对应销售 -->
+    <select id="getCwSaleNameList" resultType="org.jeecg.ctop.finance.policy.entity.CwjsSaleAssistantInfo">
+        SELECT
+            u.id AS sale_id,
+            u.realname AS sale_name
+        FROM
+            sys_user u
+        WHERE
+                u.id IN ( SELECT s.sale_id FROM ctop_cwjs_sale_assistant_info s WHERE s.del_flag = 0
+                            <if test="userId !=null and userId != ''">
+                                AND s.sale_id = #{userId}
+                            </if>
+                        )
+        <if test="userId !=null and userId != ''">
+            OR u.id = #{userId};
+        </if>
+        GROUP BY u.create_time DESC
+
+
+    </select>
+    <!--查询对应销售助理 -->
+    <select id="getCwAssistantNameList" resultType="org.jeecg.ctop.finance.policy.entity.CwjsSaleAssistantInfo">
+        SELECT
+            u.id AS sale_id,
+            u.realname as sale_name
+        FROM
+            sys_user u
+        WHERE
+                u.id IN ( SELECT s.sale_id FROM ctop_cwjs_sale_assistant_info s WHERE s.del_flag = 0
+                            <if test="userId !=null and userId != ''">
+                                AND s.assistant_id = #{userId}
+                            </if>
+                        )
+        <if test="userId !=null and userId != ''">
+            OR u.id = #{userId};
+        </if>
+        GROUP BY u.create_time DESC
+    </select>
+
+
+
+</mapper>

+ 23 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/service/ICwjsSaleAssistantInfoService.java

@@ -0,0 +1,23 @@
+package org.jeecg.ctop.finance.policy.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.ctop.finance.policy.entity.CwjsSaleAssistantInfo;
+import org.jeecg.ctop.finance.settlement.entity.pojo.CtopCwjsSettlementInfo;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
+
+/**
+ * aaa
+ * @author jeecg-boot
+ * 2021-10-18
+ * @version V1.0
+ */
+public interface ICwjsSaleAssistantInfoService extends IService<CwjsSaleAssistantInfo> {
+
+    Result getSaleListByUserDepart(String userId);
+
+    Result getCwSaleAndAssistantList(String userId);
+
+}

+ 78 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/service/impl/CwjsSaleAssistantInfoServiceImpl.java

@@ -0,0 +1,78 @@
+package org.jeecg.ctop.finance.policy.service.impl;
+
+import cn.com.ctop.common.module.mapper.SysRoleMapper;
+import cn.com.ctop.common.module.mapper.SysUserMapper;
+import org.apache.commons.lang3.StringUtils;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.ctop.finance.policy.entity.CwjsSaleAssistantInfo;
+import org.jeecg.ctop.finance.policy.mapper.CwjsSaleAssistantInfoMapper;
+import org.jeecg.ctop.finance.policy.service.ICwjsSaleAssistantInfoService;
+import org.jeecg.ctop.finance.policy.utils.Check;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
+
+/**
+ * aaa
+ * @author jeecg-boot
+ * 2021-10-18
+ * @version V1.0
+ */
+@Service
+public class CwjsSaleAssistantInfoServiceImpl extends ServiceImpl<CwjsSaleAssistantInfoMapper, CwjsSaleAssistantInfo> implements ICwjsSaleAssistantInfoService {
+
+
+    @Resource
+    private  CwjsSaleAssistantInfoMapper cwjsSaleAssistantInfoMapper;
+
+    @Resource
+    private SysRoleMapper roleMapper;
+
+    @Override
+    public Result getSaleListByUserDepart(String userId) {
+        List <CwjsSaleAssistantInfo> list = cwjsSaleAssistantInfoMapper.getSaleListByUserDepart(userId);
+        return Result.successMsg("查询成功。",list);
+    }
+
+
+
+    public Result getCwSaleAndAssistantList(String userId){
+        List<CwjsSaleAssistantInfo> resultList = new ArrayList();
+        String roleCode = roleMapper.getRoleCodeByUserId(userId);
+        //管理员 查询全部
+        if (StringUtils.equals("admin",roleCode)){
+            CwjsSaleAssistantInfo info = new CwjsSaleAssistantInfo();
+            info.setSaleId(userId);
+            info.setSaleName("管理员");
+            resultList.add(info);//追加 管理员
+            userId = null;
+            //查询 销售
+            List <CwjsSaleAssistantInfo> saleList = cwjsSaleAssistantInfoMapper.getCwSaleNameList(userId);
+            resultList.addAll(saleList);
+            //查询助理
+            List <CwjsSaleAssistantInfo> assistantList = cwjsSaleAssistantInfoMapper.getCwAssistantNameList(userId);
+            resultList.addAll(assistantList);
+            resultList = resultList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CwjsSaleAssistantInfo :: getSaleId))),ArrayList :: new));
+            return Result.successMsg("查询成功-管理员。",resultList);
+        }
+        //查询助理
+        List <CwjsSaleAssistantInfo> assistantList = cwjsSaleAssistantInfoMapper.getCwAssistantNameList(userId);
+        //如果该用户是 助理角色 则 对应的销售加自己的id list 必然 > 2
+        if (assistantList.size() < 2){
+            return Result.successMsg("查询成功-销售。",cwjsSaleAssistantInfoMapper.getCwSaleNameList(userId));
+        }
+        return Result.successMsg("查询成功-助理。",assistantList);
+
+
+    }
+
+
+}

+ 2 - 2
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/mapper/xml/ReportSettlementMapper.xml

@@ -54,7 +54,7 @@
         <if test="mediaId !=null and mediaId != ''">
             AND media_id = #{mediaId}
         </if>
-        <if test="sales !=null and sales != ''">
+        <if test='sales !=null and sales.size() >0'>
             AND create_user_id in
             <foreach collection="sales" item="item" separator=","
                      open="(" close=")">
@@ -76,7 +76,7 @@
     <if test="uploadYears !=null and uploadYears != ''">
         AND DATE_FORMAT( date, '%Y-%m' ) =  #{uploadYears}
     </if>
-    <if test="accountIds !=null and accountIds != ''">
+    <if test='accountIds !=null and accountIds.size() >0'>
         AND advertiser_id in
         <foreach collection="accountIds" item="item" separator=","
                  open="(" close=")">

+ 8 - 8
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/serviceImpl/SettlementFileInfoServiceImpl.java

@@ -199,15 +199,15 @@ public class SettlementFileInfoServiceImpl extends ServiceImpl<SettlementFileInf
     public Result getAccountNumAndImgNum(SettlementFileParamsVo paramsVo, SysUser user) {
         Map<String,String> map =  settlementFileInfoMapper.getAccountNumAndImgNum(paramsVo);
         List<String>accountIds = reportSettlementService.getAccountId(paramsVo,user);
-        //过滤消耗为0 的账户 1-头条 2-快手
-        if (paramsVo.getMediaId().equals(1)){
-            accountIds = reportSettlementMapper.getAccountIdBytedanceRepeat(accountIds,paramsVo.getUploadYears());
-        }else if (paramsVo.getMediaId().equals(2)){
-            accountIds = reportSettlementMapper.getAccountIdKuaiShouRepeat(accountIds,paramsVo.getUploadYears());
-        }
-        if(null == accountIds||accountIds.isEmpty()){
+        if (Check.isNull(accountIds)){
             map.put("accountNum","0");
-        }else{
+        }else {
+            //过滤消耗为0 的账户 1-头条 2-快手
+            if (paramsVo.getMediaId().equals(1)){
+                accountIds = reportSettlementMapper.getAccountIdBytedanceRepeat(accountIds,paramsVo.getUploadYears());
+            }else if (paramsVo.getMediaId().equals(2)){
+                accountIds = reportSettlementMapper.getAccountIdKuaiShouRepeat(accountIds,paramsVo.getUploadYears());
+            }
             map.put("accountNum",accountIds.size()+"");
         }
         return Result.successMsg("查询账户数量以及图片数量成功",map);

+ 1 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml

@@ -290,7 +290,7 @@ ORDER BY
         <if test="productId!=null and productId!= '' ">
             and cp.product_id = #{productId}
         </if>
-        <if test="sales !=null and sales != ''">
+        <if test="sales !=null and sales.size() > 0">
             AND cp.sale_id in
             <foreach collection="sales" item="item" separator=","
                      open="(" close=")">

+ 5 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/document/mapper/xml/AuditRejectedResubmitMapper.xml

@@ -19,7 +19,11 @@
     </update>
 
     <update id="updateCreativeResubmitSize">
-        update ctop_kuaishou_creative set submit_size=submit_size+1,copy_writer_id=#{copyWriterId} where creative_id=#{creativeId}
+        update ctop_kuaishou_creative set submit_size=submit_size+1
+        <if test="copyWriterId !=null and copyWriterId!=''">
+            ,copy_writer_id=#{copyWriterId}
+        </if>
+        where creative_id=#{creativeId}
     </update>
 
     <insert id="saveCopyWriterCenter">

+ 2 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/document/mapper/xml/DocumentLibraryMapper.xml

@@ -57,10 +57,11 @@
      </select>
 
     <select id="getDocumentByAccountId" resultType="Map">
-        select copy_writer_id as 'copyWriterId',copy_writer as 'copyWriter' from ctop_document_library  where account_id=#{accountId}
+        select copy_writer_id as 'copyWriterId',copy_writer as 'copyWriter' from ctop_document_library  where account_id=#{accountId} and status=0
         <if test="copyWriterId!=null and copyWriterId!=''">
             and copy_writer_id !=#{copyWriterId}
         </if>
+
      </select>
 
 </mapper>

+ 50 - 28
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/document/service/impl/AuditRejectedResubmitServiceImpl.java

@@ -70,10 +70,12 @@ public class AuditRejectedResubmitServiceImpl implements AuditRejectedResubmitSe
         try {
             log.info(formatter.format(calendar.getTime()));
             creativeList = auditRejectedResubmitMapper.getCreativeList(42, formatter.format(calendar.getTime()));
-            //可重提词组
+            //可重提封面词组
             List<String> submit = auditRejectedResubmitMapper.getRejectThesaurusListByStatus(0);
+            //可重提广告语词组
+            List<String> submit2 = auditRejectedResubmitMapper.getRejectThesaurusListByStatus(1);
             //不可重提词组
-            List<String> resubmit = auditRejectedResubmitMapper.getRejectThesaurusListByStatus(1);
+            List<String> resubmit = auditRejectedResubmitMapper.getRejectThesaurusListByStatus(2);
             creativeList.stream().forEach(obj -> {
                 String reviewDetail = obj.getReviewDetail();
                 List<String> strings = Arrays.asList(reviewDetail.split(";"));
@@ -83,40 +85,60 @@ public class AuditRejectedResubmitServiceImpl implements AuditRejectedResubmitSe
                     log.info("修改为不可重提:{}", reviewDetail);
                     auditRejectedResubmitMapper.updateCreativeResubmit(String.valueOf(obj.getCreativeId()), 1);
                 } else {
+                    //判断是否封面重提
                     Boolean flag2 = isNotSubmit(strings, submit);
-                    if (flag2) {
-                        //重提
-                        log.info("进行重提:{}", reviewDetail);
+                    //判断是否广告语重提
+                    Boolean flag3 = isNotSubmit(strings, submit2);
+                    JSONObject updateJson = new JSONObject();
+                    if (flag2 || flag3) {
                         Integer submit_size = obj.getSubmitSize();
                         if (submit_size < 2) {
-                            JSONObject updateJson = new JSONObject();
+                            //重提
+                            log.info("进行重提:{}", reviewDetail);
+                            String imageToken = null;
+                            List<Map<String, String>> documentByAccountId = null;
                             updateJson.put("creativeId", obj.getCreativeId());
-                            //更换封面
                             CtopOauthToken oauthToken = tokenService.getTokenByAccountId(obj.getAccountId());
-                            JSONObject cutJson = cutFrameService.getCutFrameByVideoMd5(obj.getPhotoId(), obj.getImageToken());
-                            if (!Check.isNull(cutJson)) {
-                                String signature = cutJson.getString("signature");
-                                String url = cutJson.getString("url");
-                                String imageToken = getImageToken(signature, obj.getAccountId(), oauthToken.getAccessToken(), url);
-                                if (!Check.isNull(imageToken)) {
-                                    updateJson.put("imageToken", imageToken);
+                            if (flag2) {
+                                log.info("进行封面重提:{}", reviewDetail);
+                                //更换封面
+                                JSONObject cutJson = cutFrameService.getCutFrameByVideoMd5(obj.getPhotoId(), obj.getImageToken());
+                                if (!Check.isNull(cutJson)) {
+                                    String signature = cutJson.getString("signature");
+                                    String url = cutJson.getString("url");
+                                    imageToken = getImageToken(signature, obj.getAccountId(), oauthToken.getAccessToken(), url);
+                                    if (imageToken != null) {
+                                        updateJson.put("imageToken", imageToken);
+                                    } else {
+                                        log.info("未查询到封面:accountId:{},creativeId:{}", obj.getAccountId(), obj.getCreativeId());
+                                    }
                                 }
                             }
-                            //更换文案
-                            List<Map<String, String>> documentByAccountId = documentLibraryMapper.getDocumentByAccountId(String.valueOf(obj.getAccountId()), obj.getCopyWriterId());
-                            if (!documentByAccountId.isEmpty()) {
-                                updateJson.put("description", documentByAccountId.get(0).get("copyWriter"));
+                            if (flag3) {
+                                //重提
+                                log.info("进行广告语重提:{}", reviewDetail);
+                                //更换文案
+                                documentByAccountId = documentLibraryMapper.getDocumentByAccountId(String.valueOf(obj.getAccountId()), obj.getCopyWriterId());
+                                if (documentByAccountId != null && documentByAccountId.size() > 0) {
+                                    updateJson.put("description", documentByAccountId.get(0).get("copyWriter"));
+                                } else {
+                                    log.info("未查询到广告语:accountId:{},creativeId:{}", obj.getAccountId(), obj.getCreativeId());
+                                }
                             }
-                            Map<String, Object> creativeMap = updateService.updateCreative(oauthToken.getAccessToken(), obj.getAccountId(), updateJson);
-                            Integer code = (Integer) creativeMap.get("code");
-                            if (code == 0) {
-                                //修改重提次数和文案id
-                                auditRejectedResubmitMapper.updateCreativeResubmitSize(obj.getCreativeId(), documentByAccountId.get(0).get("copyWriterId"));
-                                //插入文案关联创意表信息
-                                auditRejectedResubmitMapper.saveCopyWriterCenter(documentByAccountId.get(0).get("copyWriterId"), String.valueOf(obj.getCreativeId()), new Date());
-                                log.info("拒审重提成功,accountId:{},creativeId:{}", obj.getAccountId(), obj.getCreativeId());
-                            } else {
-                                log.info("拒审重提失败,accountId:{},creativeId:{}", obj.getAccountId(), obj.getCreativeId());
+                            if (imageToken != null || (documentByAccountId!=null && documentByAccountId.size() > 0)) {
+                                Map<String, Object> creativeMap = updateService.updateCreative(oauthToken.getAccessToken(), obj.getAccountId(), updateJson);
+                                Integer code = (Integer) creativeMap.get("code");
+                                if (code == 0) {
+                                    //修改重提次数和文案id
+                                    auditRejectedResubmitMapper.updateCreativeResubmitSize(obj.getCreativeId(), documentByAccountId != null && documentByAccountId.size() > 0 ? documentByAccountId.get(0).get("copyWriterId") : null);
+                                    //插入文案关联创意表信息
+                                    if (documentByAccountId !=null && documentByAccountId.size() > 0) {
+                                        auditRejectedResubmitMapper.saveCopyWriterCenter(documentByAccountId.get(0).get("copyWriterId"), String.valueOf(obj.getCreativeId()), new Date());
+                                    }
+                                    log.info("拒审重提成功,accountId:{},creativeId:{}", obj.getAccountId(), obj.getCreativeId());
+                                } else {
+                                    log.info("拒审重提失败,accountId:{},creativeId:{}", obj.getAccountId(), obj.getCreativeId());
+                                }
                             }
                         } else {
                             log.info("重提次数已达上限:accountId:{},creativeId:{}", obj.getAccountId(), obj.getCreativeId());

+ 4 - 3
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/document/service/impl/DocumentLibraryServiceImpl.java

@@ -48,7 +48,10 @@ public class DocumentLibraryServiceImpl implements DocumentLibraryService {
         } catch (Exception e) {
             log.info("读取excel错误:{}", e.toString());
         }
-
+        if (documentList == null || documentList.size() == 0) {
+            result.success("文件为空");
+            return result;
+        }
         try {
             if (accountIds != null && !documentList.isEmpty() && !accountIds.isEmpty()) {
 
@@ -64,8 +67,6 @@ public class DocumentLibraryServiceImpl implements DocumentLibraryService {
                             documentLibraryMapper.saveDocumentLibrary(documentLibraryInfo);
                         }
                     }
-
-
                 }
             }
             result.success("添加成功");

+ 46 - 6
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialReportOverViewController.java

@@ -303,7 +303,7 @@ public class MaterialReportOverViewController {
         result.setSuccess(true);
         return result;
     }
-    @PostMapping("/materialDetailPhotoShow")
+   /* @PostMapping("/materialDetailPhotoShow")
     public Result<Map<String,Object>> materialDetailPhotoShow(@RequestBody JSONObject params){
         Result<Map<String,Object>> result= new Result<>();
         Map<String,Object> map = new HashMap<>();
@@ -311,8 +311,8 @@ public class MaterialReportOverViewController {
         result.setResult(map);
         result.setSuccess(true);
         return result;
-    }
-    @PostMapping("/materialDetailPhotoClick")
+    }*/
+  /*  @PostMapping("/materialDetailPhotoClick")
     public Result<Map<String,Object>> materialDetailPhotoClick(@RequestBody JSONObject params){
         Result<Map<String,Object>> result= new Result<>();
         Map<String,Object> map = new HashMap<>();
@@ -320,7 +320,7 @@ public class MaterialReportOverViewController {
         result.setResult(map);
         result.setSuccess(true);
         return result;
-    }
+    }*/
     @PostMapping("/materialDetailAClick")
     public Result<Map<String,Object>> materialDetailAClick(@RequestBody JSONObject params){
         Result<Map<String,Object>> result= new Result<>();
@@ -330,7 +330,7 @@ public class MaterialReportOverViewController {
         result.setSuccess(true);
         return result;
     }
-    @PostMapping("/materialDetailBClick")
+   /* @PostMapping("/materialDetailBClick")
     public Result<Map<String,Object>> materialDetailBClick(@RequestBody JSONObject params){
         Result<Map<String,Object>> result= new Result<>();
         Map<String,Object> map = new HashMap<>();
@@ -338,7 +338,7 @@ public class MaterialReportOverViewController {
         result.setResult(map);
         result.setSuccess(true);
         return result;
-    }
+    }*/
     @PostMapping("/materialDetailActivation")
     public Result<Map<String,Object>> materialDetailActivation(@RequestBody JSONObject params){
         Result<Map<String,Object>> result= new Result<>();
@@ -366,4 +366,44 @@ public class MaterialReportOverViewController {
         result.setSuccess(true);
         return result;
     }
+    /**  查询人群分析数据列表
+     * @param
+     * @return
+     */
+    @GetMapping("/populationAnalysisList")
+    public Result  populationAnalysisList(@RequestParam String signature){
+        return materialReportOverViewService.populationAnalysisList(signature);
+
+    }
+
+    /**  查询人群分析数据图
+     * @param
+     * @return
+     */
+    @GetMapping("/populationAnalysisChart")
+    public Result  populationAnalysisChart(@RequestParam("signature") String signature){
+        return materialReportOverViewService.populationAnalysisChart(signature);
+
+    }
+
+    /**  最优定向组合
+     * @param
+     * @return
+     */
+    @GetMapping("/optimalCombination")
+    public Result  optimalCombination(@RequestParam("signature") String signature){
+        return materialReportOverViewService.optimalCombination(signature);
+
+    }
+
+    /**  相似素材
+     * @param
+     * @return
+     */
+    @GetMapping("/similarMaterial")
+    public Result  similarMaterial(@RequestParam("signature") String signature){
+        return materialReportOverViewService.similarMaterial(signature);
+
+    }
+
 }

+ 12 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/MaterialReportOverViewMapper.java

@@ -138,4 +138,16 @@ public interface MaterialReportOverViewMapper {
     List<JSONObject> queryBytedanceVideoChat(String md5);
 
     List<JSONObject> queryKuaishouVideoChat(String md5);
+
+    List<Map> populationAnalysisList(@Param("signature") String signature);
+
+    String getActualProb(@Param("signature") String signature,@Param("targetType") String targetType);
+
+    List<Map> populationAnalysisChart(@Param("signature")String signature);
+
+    Map<String,String> optimalCombination(@Param("signature")String signature,@Param("targetType")String targetType);
+
+    Map similarMaterialInfo(@Param("signature")String signature);
+
+    Map<String,String> getSimilarMaterialList(@Param("signature")String signature);
 }

+ 232 - 175
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/MaterialReportOverViewMapper.xml

@@ -148,7 +148,7 @@
         ORDER BY time
 
     </select>
-<!-- 查询素材 上新 数据  快手-->
+    <!-- 查询素材 上新 数据  快手-->
     <select id="queryMaterialCountListKs" resultType="java.util.HashMap">
         SELECT
         count(distinct code) as count ,
@@ -170,7 +170,7 @@
         ORDER BY time
     </select>
 
- <!-- 查询有消耗的素材 头条 -->
+    <!-- 查询有消耗的素材 头条 -->
     <select id="queryMaterialCostList" resultType="long">
         SELECT
         COUNT( distinct m.id) as count
@@ -178,7 +178,8 @@
         ctop_material_info m
         LEFT join ctop_project cp on cp.id = m.project_id
         LEFT JOIN ctop_bytedance_video_info v ON m.CODE = v.signature
-        LEFT JOIN ctop_bytedance_report_material_daily r ON v.account_id = r.account_id AND v.material_id = r.material_id
+        LEFT JOIN ctop_bytedance_report_material_daily r ON v.account_id = r.account_id AND v.material_id =
+        r.material_id
         WHERE
         1 = 1
         AND r.cost > 0
@@ -195,7 +196,7 @@
 
     </select>
 
- <!-- 查询有消耗的素材 快手 -->
+    <!-- 查询有消耗的素材 快手 -->
     <select id="queryMaterialCostListKs" resultType="long">
 
         SELECT
@@ -222,8 +223,8 @@
     <!-- 有效视频-头条 -->
     <select id="selectEffectiveMaterialVideoBytedance" resultType="java.util.HashMap">
         select
-               COUNT(m.id) count,
-               b.effect_date as time
+        COUNT(m.id) count,
+        b.effect_date as time
         from
         ctop_bytedance_video_etl_info b
         LEFT JOIN ctop_material_info m on m.code = b.video_code
@@ -246,8 +247,8 @@
     <!-- 有效视频-快手 -->
     <select id="selectEffectiveMaterialVideoKs" resultType="java.util.HashMap">
         select
-               COUNT(m.id) count,
-             b.effect_date as time
+        COUNT(m.id) count,
+        b.effect_date as time
         from
         ctop_kuaishou_video_etl_info b
         LEFT JOIN ctop_material_info m on m.code = b.video_code
@@ -270,7 +271,7 @@
     <!-- 爆款视频-头条 -->
     <select id="selectHotMaterialVideoBytedance" resultType="java.util.HashMap">
         select
-               COUNT(m.id) count,
+        COUNT(m.id) count,
         b.faddish_date as time
         from
         ctop_bytedance_video_etl_info b
@@ -294,8 +295,8 @@
     <!-- 爆款视频-快手 -->
     <select id="selectHotMaterialVideoKs" resultType="java.util.HashMap">
         select
-            COUNT(m.id) count,
-            b.faddish_date as time
+        COUNT(m.id) count,
+        b.faddish_date as time
         from
         ctop_kuaishou_video_etl_info b
         LEFT JOIN ctop_material_info m on m.code = b.video_code
@@ -315,7 +316,6 @@
     </select>
 
 
-
     <select id="queryNewMaterialCount" resultType="long">
         SELECT
         count(id) from ctop_material_info
@@ -333,6 +333,8 @@
     <select id="queryBytedanceChat" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
         sum(cost) as cost,
+        sum(material_show) as aclick,
+        sum(active) as active,
         stat_datetime as statDate
         FROM
         etl_report_bytedance_video
@@ -354,6 +356,8 @@
     <select id="queryBytedanceChatGroupMonth" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
         sum(cost) as cost,
+        sum(material_show) as aclick,
+        sum(active) as active,
         DATE_FORMAT(stat_datetime, '%Y-%m') as statDate
         FROM
         etl_report_bytedance_video
@@ -375,6 +379,8 @@
     <select id="queryKuaishouChat" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
         sum(charge) as cost,
+        sum(photo_show) as aclick,
+        sum(activation) as active,
         stat_date as statDate
         FROM
         ctop_etl_kuaishou_account_material_report_daily
@@ -396,6 +402,8 @@
     <select id="queryKuaishouChatGroupMonth" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
         sum(charge) as cost,
+        sum(photo_show) as aclick,
+        sum(activation) as active,
         DATE_FORMAT(stat_date, '%Y-%m') as statDate
         FROM
         ctop_etl_kuaishou_account_material_report_daily
@@ -417,14 +425,15 @@
     <select id="queryBytedanceTopMaterial" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
         t1.*,
-        IFNULL((SELECT GROUP_CONCAT(tag_name) from ctop_material_tag_info where code=signature and status=1),"造") as
+        IFNULL((SELECT GROUP_CONCAT(tag_name) from ctop_material_tag_info where code=signature and status=1),"造") as
         tag
         FROM
         (SELECT md5 signature,
-        case when toutiao_url = '' or toutiao_url is null then url end url,
-        cover_url AS coverUrl,
-        material_name AS materialName,
-        sum(cost) AS cost from etl_report_bytedance_video
+        case when toutiao_url = '' or toutiao_url is null then t.url end url,
+        t.cover_url AS coverUrl,
+        t.material_name AS materialName,
+        sum(cost) AS cost from etl_report_bytedance_video t
+        LEFT JOIN ctop_material_info t1 on t.md5=t1.`code`
         where 1=1
         <if test="projects !=null">
             AND project_id IN
@@ -433,6 +442,7 @@
                 #{item}
             </foreach>
         </if>
+        AND t1.`code` is not null
         AND stat_datetime &gt; #{startDate}
         AND stat_datetime &lt;= #{endDate}
         AND md5!=''
@@ -445,12 +455,13 @@
     <select id="queryKuaishouTopDesign" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
         t1.charge as cost
-        <if test="type == 1"> ,t1.shot_name as userName, "摄像" as roleName </if>
-        <if test="type == 2"> ,t1.clip_name as userName, "剪辑" as roleName </if>
-        <if test="type == 3"> ,t1.plan_name as userName, "编导" as roleName </if>
+        <if test="type == 1">,t1.shot_name as userName, "摄像" as roleName</if>
+        <if test="type == 2">,t1.clip_name as userName, "剪辑" as roleName</if>
+        <if test="type == 3">,t1.plan_name as userName, "编导" as roleName</if>
         FROM
         (select sum(charge) as charge,t2.*
-        from ctop_etl_kuaishou_account_material_report_daily t1 LEFT JOIN ctop_etl_kuaishou_video_info t2 ON t1.signature = t2.video_code
+        from ctop_etl_kuaishou_account_material_report_daily t1 LEFT JOIN ctop_etl_kuaishou_video_info t2 ON
+        t1.signature = t2.video_code
         where
         1=1
         AND t1.stat_date &gt;= #{startDate}
@@ -462,30 +473,29 @@
                 #{item}
             </foreach>
         </if>
-        <if test="type == 1"> AND t2.shot_id is not null and t2.shot_id != '' GROUP BY t2.shot_id</if>
-        <if test="type == 2"> AND t2.clip_id is not null and t2.clip_id != '' GROUP BY t2.clip_id</if>
-        <if test="type == 3"> AND t2.plan_id is not null and t2.plan_id != '' GROUP BY t2.plan_id</if>
-        ORDER BY charge desc  LIMIT 10
+        <if test="type == 1">AND t2.shot_id is not null and t2.shot_id != '' GROUP BY t2.shot_id</if>
+        <if test="type == 2">AND t2.clip_id is not null and t2.clip_id != '' GROUP BY t2.clip_id</if>
+        <if test="type == 3">AND t2.plan_id is not null and t2.plan_id != '' GROUP BY t2.plan_id</if>
+        ORDER BY charge desc LIMIT 10
         ) t1
 
 
-
     </select>
 
     <select id="queryBytedanceTopDesign" resultType="com.alibaba.fastjson.JSONObject">
 
         SELECT
         t1.cost
-        <if test="type == 1"> ,t1.shot_name as userName, "摄像" as roleName </if>
-        <if test="type == 2"> ,t1.clip_name as userName, "剪辑" as roleName </if>
-        <if test="type == 3"> ,t1.plan_name as userName, "编导" as roleName </if>
+        <if test="type == 1">,t1.shot_name as userName, "摄像" as roleName</if>
+        <if test="type == 2">,t1.clip_name as userName, "剪辑" as roleName</if>
+        <if test="type == 3">,t1.plan_name as userName, "编导" as roleName</if>
         FROM
         (select sum(cost) as cost,clip_name,plan_name,shot_name
         from etl_report_bytedance_video t1
         where
         1=1
         AND t1.stat_datetime &gt;= #{startDate}
-        AND t1.stat_datetime &lt;=  #{endDate}
+        AND t1.stat_datetime &lt;= #{endDate}
         <if test="projects !=null">
             AND project_id IN
             <foreach collection="projects" item="item" separator=","
@@ -493,10 +503,10 @@
                 #{item}
             </foreach>
         </if>
-        <if test="type == 1"> AND t1.shot_id is not null and t1.shot_id != '' GROUP BY t1.shot_id</if>
-        <if test="type == 2"> AND t1.clip_id is not null and t1.clip_id != '' GROUP BY t1.clip_id</if>
-        <if test="type == 3"> AND t1.plan_id is not null and t1.plan_id != '' GROUP BY t1.plan_id</if>
-        ORDER BY cost desc  LIMIT 10
+        <if test="type == 1">AND t1.shot_id is not null and t1.shot_id != '' GROUP BY t1.shot_id</if>
+        <if test="type == 2">AND t1.clip_id is not null and t1.clip_id != '' GROUP BY t1.clip_id</if>
+        <if test="type == 3">AND t1.plan_id is not null and t1.plan_id != '' GROUP BY t1.plan_id</if>
+        ORDER BY cost desc LIMIT 10
         ) t1
 
     </select>
@@ -504,7 +514,8 @@
     <select id="queryBytedanceTopMaterialNew" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
         t1.*,
-        IFNULL((SELECT GROUP_CONCAT(tag_name) from ctop_material_tag_info where code=signature and status=1),"塑造") as  tag
+        IFNULL((SELECT GROUP_CONCAT(tag_name) from ctop_material_tag_info where code=signature and status=1),"塑造") as
+        tag
         FROM
         (SELECT md5 signature,
         case when toutiao_url = '' or toutiao_url is null then url end url,
@@ -582,7 +593,6 @@
     </select>
 
 
-
     <select id="queryKuaishouTopMaterial" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
         t1.*,
@@ -617,34 +627,34 @@
         </if>
         ORDER BY charge desc LIMIT 5
 
-<!--        SELECT-->
-<!--        t1.*,-->
-<!--        t2.video_name as materialName,-->
-<!--        t2.cover_url as coverUrl,-->
-<!--        t2.url as url ,-->
-<!--        IFNULL((SELECT GROUP_CONCAT(tag_name) from ctop_material_tag_info where code=t1.signature and status=1),"塑造") as-->
-<!--        tag-->
-<!--        FROM-->
-<!--        (select sum(charge) as charge,signature-->
-<!--        from ctop_etl_kuaishou_account_material_report_daily t1-->
-<!--        where-->
-<!--        1=1-->
-<!--        <if test="projects !=null">-->
-<!--            AND project_id IN-->
-<!--            <foreach collection="projects" item="item" separator=","-->
-<!--                     open="(" close=")">-->
-<!--                #{item}-->
-<!--            </foreach>-->
-<!--        </if>-->
-<!--        AND t1.stat_date &gt;= #{startDate}-->
-<!--        AND t1.stat_date &lt;= #{endDate}-->
-<!--        GROUP BY t1.signature-->
-<!--        ORDER BY charge desc-->
-<!--        limit 5-->
-<!--        ) t1-->
-<!--        LEFT JOIN ctop_etl_kuaishou_video_info t2-->
-<!--        ON t1.signature = t2.video_code-->
-<!--        ORDER BY charge desc-->
+        <!--        SELECT-->
+        <!--        t1.*,-->
+        <!--        t2.video_name as materialName,-->
+        <!--        t2.cover_url as coverUrl,-->
+        <!--        t2.url as url ,-->
+        <!--        IFNULL((SELECT GROUP_CONCAT(tag_name) from ctop_material_tag_info where code=t1.signature and status=1),"塑造") as-->
+        <!--        tag-->
+        <!--        FROM-->
+        <!--        (select sum(charge) as charge,signature-->
+        <!--        from ctop_etl_kuaishou_account_material_report_daily t1-->
+        <!--        where-->
+        <!--        1=1-->
+        <!--        <if test="projects !=null">-->
+        <!--            AND project_id IN-->
+        <!--            <foreach collection="projects" item="item" separator=","-->
+        <!--                     open="(" close=")">-->
+        <!--                #{item}-->
+        <!--            </foreach>-->
+        <!--        </if>-->
+        <!--        AND t1.stat_date &gt;= #{startDate}-->
+        <!--        AND t1.stat_date &lt;= #{endDate}-->
+        <!--        GROUP BY t1.signature-->
+        <!--        ORDER BY charge desc-->
+        <!--        limit 5-->
+        <!--        ) t1-->
+        <!--        LEFT JOIN ctop_etl_kuaishou_video_info t2-->
+        <!--        ON t1.signature = t2.video_code-->
+        <!--        ORDER BY charge desc-->
     </select>
 
     <select id="queryKuaishouMaterialReport" resultType="com.alibaba.fastjson.JSONObject">
@@ -803,7 +813,7 @@
                t.material_name                                                                       as materialName,
                t2.`second`,
                '快手'                                                                                  as madia,
-               GROUP_CONCAT((SELECT project_name from ctop_project where id = t.project_id limit 1)) as projectName,
+               GROUP_CONCAT(DISTINCT (SELECT project_name from ctop_project where id = t.project_id limit 1)) as projectName,
                t.create_time                                                                         as createTime,
                t2.size,
                t1.channel_name                                                                       as channelType,
@@ -824,7 +834,9 @@
     </select>
 
     <select id="queryBytedanceVideoChat" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT sum(cost)                           AS cost,
+        SELECT ifnull(sum(cost),0)                           AS cost,
+            		ifnull(SUM(material_show),0)			 as aclick,
+	                        ifnull(SUM(active),0) as activation,
                DATE_FORMAT(stat_datetime, '%Y-%m') AS statDate
         FROM etl_report_bytedance_video
         WHERE md5 = #{md5}
@@ -833,7 +845,9 @@
     </select>
 
     <select id="queryKuaishouVideoChat" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT sum(charge)                     AS cost,
+        SELECT ifnull(sum(charge) ,0)                    AS cost,
+        					ifnull(SUM(aclick),0) as aclick,
+	                        ifnull(SUM(activation),0) as activation,
                DATE_FORMAT(stat_date, '%Y-%m') AS statDate
         FROM ctop_etl_kuaishou_account_material_report_daily
         WHERE signature = #{md5}
@@ -845,9 +859,9 @@
         SELECT
             project_id
         FROM
-            etl_report_bytedance_video
+            ctop_material_info
         WHERE
-            md5 = #{md5}
+            code = #{md5}
           AND project_id IS NOT NULL
         LIMIT 1
     </select>
@@ -866,24 +880,20 @@
     <select id="queryBytedanceCostByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select cost
         from (
-                 SELECT ROUND(sum(cost), 2) cost,
+                 SELECT ifnull(ROUND(sum(cost), 2),0) cost,
                         1 as                num
                  FROM etl_report_bytedance_video
                  WHERE md5 = #{md5}
                  union all
-                 SELECT ROUND(MAX(cost), 2) top,
+                 SELECT ifnull(ROUND(MAX(cost), 2),2) top,
                         2 as                num
                  FROM (
                           SELECT sum(cost) cost
-                          FROM etl_report_bytedance_video
-                          WHERE project_id = #{project}
+                          FROM etl_report_bytedance_video t
+                          LEFT JOIN ctop_material_info t1 on t.md5=t1.code
+                            WHERE t1.project_id =#{project}
                           GROUP BY md5
                       ) t
-                 union all
-                 SELECT ROUND(AVG(cost), 2) average,
-                        3 as                num
-                 FROM etl_report_bytedance_video
-                 WHERE project_id = #{project}
              ) t
         order by num
     </select>
@@ -891,24 +901,20 @@
     <select id="queryBytedanceClickByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select click
         from (
-                 SELECT sum(click) click,
+                 SELECT ifnull(ROUND(sum(click),2),0) click,
                         1 as       num
                  FROM etl_report_bytedance_video
                  WHERE md5 = #{md5}
                  union all
-                 SELECT MAX(click) top,
+                 SELECT ifnull(ROUND(MAX(click),2),0)  top,
                         2 as       num
                  FROM (
                           SELECT sum(click) click
-                          FROM etl_report_bytedance_video
-                          WHERE project_id = #{project}
+                          FROM etl_report_bytedance_video t
+                          LEFT JOIN ctop_material_info t1 on t.md5=t1.code
+                            WHERE t1.project_id =#{project}
                           GROUP BY md5
                       ) t
-                 union all
-                 SELECT ROUND(AVG(click), 0) average,
-                        3 as                 num
-                 FROM etl_report_bytedance_video
-                 WHERE project_id = #{project}
              ) t
         order by num
     </select>
@@ -916,24 +922,21 @@
     <select id="queryBytedanceMaterialShowByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select materialShow
         from (
-                 SELECT sum(material_show) materialShow,
+                 SELECT ifnull(sum(material_show),0) materialShow,
                      1 as num
                  FROM etl_report_bytedance_video
                  WHERE md5 = #{md5}
                  union all
-                 SELECT MAX(materialShow) top,
+                 SELECT ifnull(MAX(materialShow),0) top,
                      2 as num
                  FROM (
                           SELECT sum(material_show) materialShow
-                          FROM etl_report_bytedance_video
-                          WHERE project_id = #{project}
+                          FROM etl_report_bytedance_video t
+                          LEFT JOIN ctop_material_info t1 on t.md5=t1.code
+                            WHERE t1.project_id =#{project}
                           GROUP BY md5
                       ) t
-                 union all
-                 SELECT ROUND(AVG(material_show), 0) average,
-                     3 as num
-                 FROM etl_report_bytedance_video
-                 WHERE project_id = #{project}
+
              ) t
         order by num
 
@@ -951,15 +954,11 @@
             2 as num
         FROM (
                  SELECT round(sum(play100_feed_break) / sum(material_show), 2) play100Rate
-                 FROM etl_report_bytedance_video
-                 WHERE project_id = #{project}
+                 FROM etl_report_bytedance_video t
+                   LEFT JOIN ctop_material_info t1 on t.md5=t1.code
+                   WHERE t1.project_id =#{project}
                  GROUP BY md5
              ) t
-        union all
-        SELECT ifnull(ROUND(sum(play100_feed_break) / sum(material_show), 2),0) average,
-            3 as num
-        FROM etl_report_bytedance_video
-        WHERE project_id = #{project}
              ) t
         order by num
     </select>
@@ -967,24 +966,20 @@
     <select id="queryBytedanceLikeMaterialByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select likeMaterial
         from (
-        SELECT sum(like_material) likeMaterial,
+        SELECT ifnull(sum(like_material),0) likeMaterial,
             1 as num
         FROM etl_report_bytedance_video
         WHERE md5 = #{md5}
         union all
-        SELECT MAX(likeMaterial) top,
+        SELECT ifnull(MAX(likeMaterial),0) top,
             2 as num
         FROM (
                  SELECT sum(like_material) likeMaterial
-                 FROM etl_report_bytedance_video
-                 WHERE project_id = #{project}
+                 FROM etl_report_bytedance_video t
+                          LEFT JOIN ctop_material_info t1 on t.md5=t1.code
+                            WHERE t1.project_id =#{project}
                  GROUP BY md5
              ) t
-        union all
-        SELECT ROUND(AVG(like_material), 0) average,
-            3 as num
-        FROM etl_report_bytedance_video
-        WHERE project_id = #{project}
              ) t
         order by num
     </select>
@@ -992,24 +987,20 @@
     <select id="queryBytedanceCommentMaterialByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select commentMaterial
         from (
-        SELECT sum(comment_material) commentMaterial,
+        SELECT ifnull(sum(comment_material),0) commentMaterial,
             1 as num
         FROM etl_report_bytedance_video
         WHERE md5 = #{md5}
         union all
-        SELECT MAX(commentMaterial) top,
+        SELECT ifnull(MAX(commentMaterial),0) top,
             2 as num
         FROM (
                  SELECT sum(comment_material) commentMaterial
-                 FROM etl_report_bytedance_video
-                 WHERE project_id = #{project}
+                 FROM etl_report_bytedance_video t
+                          LEFT JOIN ctop_material_info t1 on t.md5=t1.code
+                            WHERE t1.project_id =#{project}
                  GROUP BY md5
              ) t
-        union all
-        SELECT ROUND(AVG(comment_material), 0) average,
-            3 as num
-        FROM etl_report_bytedance_video
-        WHERE project_id = #{project}
              ) t
         order by num
     </select>
@@ -1017,24 +1008,20 @@
     <select id="queryBytedanceShareMaterialByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select shareMaterial
         from (
-        SELECT sum(share_material) shareMaterial,
+        SELECT ifnull(sum(share_material),0) shareMaterial,
             1 as num
         FROM etl_report_bytedance_video
         WHERE md5 = #{md5}
         union all
-        SELECT MAX(shareMaterial) top,
+        SELECT ifnull(MAX(shareMaterial),0) top,
             2 as num
         FROM (
                  SELECT sum(share_material) shareMaterial
-                 FROM etl_report_bytedance_video
-                 WHERE project_id = #{project}
+                 FROM etl_report_bytedance_video t
+                          LEFT JOIN ctop_material_info t1 on t.md5=t1.code
+                            WHERE t1.project_id =#{project}
                  GROUP BY md5
              ) t
-        union all
-        SELECT ROUND(AVG(share_material), 0) average,
-            3 as num
-        FROM etl_report_bytedance_video
-        WHERE project_id = #{project}
              ) t
         order by num
     </select>
@@ -1042,24 +1029,20 @@
     <select id="queryBytedanceFollowByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select follow
         from (
-        SELECT sum(follow) follow,
+        SELECT ifnull(sum(follow),0) follow,
             1 as num
         FROM etl_report_bytedance_video
         WHERE md5 = #{md5}
         union all
-        SELECT MAX(follow) top,
+        SELECT ifnull(MAX(follow),0) top,
             2 as num
         FROM (
                  SELECT sum(follow) follow
-                 FROM etl_report_bytedance_video
-                 WHERE project_id = #{project}
+                 FROM etl_report_bytedance_video t
+                          LEFT JOIN ctop_material_info t1 on t.md5=t1.code
+                            WHERE t1.project_id =#{project}
                  GROUP BY md5
              ) t
-        union all
-        SELECT ROUND(AVG(follow), 0) average,
-            3 as num
-        FROM etl_report_bytedance_video
-        WHERE project_id = #{project}
              ) t
         order by num
     </select>
@@ -1069,22 +1052,17 @@
         from (
                  SELECT ROUND(sum(charge), 2) charge,
                         1 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 FROM application.kuaishou_material_video_report_daily_dw
                  WHERE signature = #{md5}
                  union all
                  SELECT ROUND(MAX(charge), 2) top,
                         2 as num
                  FROM (
                           SELECT sum(charge) charge
-                          FROM ctop_etl_kuaishou_account_material_report_daily
+                          FROM application.kuaishou_material_video_report_daily_dw
                           WHERE project_id = #{project}
                           GROUP BY signature
                       ) t
-                 union all
-                 SELECT ROUND(AVG(charge), 2) average,
-                        3 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
-                 WHERE project_id = #{project}
              ) t
         order by num
     </select>
@@ -1092,23 +1070,23 @@
     <select id="queryKuaishouPhotoShowByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select photoShow
         from (
-                 SELECT sum(photo_show) photoShow,
+                 SELECT sum(`show`) photoShow,
                         1 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 FROM application.kuaishou_material_video_report_daily_dw
                  WHERE signature = #{md5}
                  union all
                  SELECT MAX(photoShow) top,
                         2 as num
                  FROM (
-                          SELECT sum(photo_show) photoShow
-                          FROM ctop_etl_kuaishou_account_material_report_daily
+                          SELECT sum(`show`) photoShow
+                          FROM application.kuaishou_material_video_report_daily_dw
                           WHERE project_id = #{project}
                           GROUP BY signature
                       ) t
                  union all
-                 SELECT ROUND(AVG(photo_show), 0) average,
+                 SELECT ROUND(AVG(`show`), 0) average,
                         3 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 FROM application.kuaishou_material_video_report_daily_dw
                  WHERE project_id = #{project}
              ) t
         order by num
@@ -1144,22 +1122,17 @@
         from (
                  SELECT sum(aclick) aclick,
                         1 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 FROM application.kuaishou_material_video_report_daily_dw
                  WHERE signature = #{md5}
                  union all
                  SELECT MAX(aclick) top,
                         2 as num
                  FROM (
                           SELECT sum(aclick) aclick
-                          FROM ctop_etl_kuaishou_account_material_report_daily
+                          FROM application.kuaishou_material_video_report_daily_dw
                           WHERE project_id = #{project}
                           GROUP BY signature
                       ) t
-                 union all
-                 SELECT ROUND(AVG(aclick), 0) average,
-                        3 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
-                 WHERE project_id = #{project}
              ) t
         order by num
     </select>
@@ -1194,22 +1167,17 @@
         from (
                  SELECT sum(activation) activation,
                         1 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 FROM application.kuaishou_material_video_report_daily_dw
                  WHERE signature = #{md5}
                  union all
                  SELECT MAX(activation) top,
                         2 as num
                  FROM (
                           SELECT sum(activation) activation
-                          FROM ctop_etl_kuaishou_account_material_report_daily
+                          FROM application.kuaishou_material_video_report_daily_dw
                           WHERE project_id = #{project}
                           GROUP BY signature
                       ) t
-                 union all
-                 SELECT ROUND(AVG(activation), 0) average,
-                        3 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
-                 WHERE project_id = #{project}
              ) t
         order by num
     </select>
@@ -1217,26 +1185,115 @@
     <select id="queryKuaishouPlay3sRateByMd5" resultType="com.alibaba.fastjson.JSONObject">
         select play3sRate
         from (
-                 SELECT round(sum(play_3s_count) / sum(aclick), 2) play3sRate,
+                 SELECT round(sum(play_3s_ratio*aclick) / sum(aclick), 2) play3sRate,
                         1 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
+                 FROM application.kuaishou_material_video_report_daily_dw
                  WHERE signature = #{md5}
                  union all
                  SELECT ROUND(MAX(play3sRate), 2) top,
                         2 as num
                  FROM (
-                          SELECT sum(play_3s_count) / sum(aclick) play3sRate
-                          FROM ctop_etl_kuaishou_account_material_report_daily
+                          SELECT sum(play_3s_ratio*aclick) / sum(aclick) play3sRate
+                          FROM application.kuaishou_material_video_report_daily_dw
                           WHERE project_id = #{project}
                           GROUP BY signature
                       ) t
-                 union all
-                 SELECT ROUND(sum(play_3s_count) / sum(aclick), 2) average,
-                        3 as num
-                 FROM ctop_etl_kuaishou_account_material_report_daily
-                 WHERE project_id = #{project}
              ) t
         order by num
     </select>
 
+    <select id="populationAnalysisList" resultType="java.util.Map">
+	select 	t2.gender,
+		CASE t2.age WHEN '18-23岁|24-30岁|31-40岁' THEN '18-40'
+    WHEN '24-30岁|31-40岁|41-49岁' THEN '24-49'
+   WHEN '31-40岁|41-49岁|50+岁' THEN '31+'
+    WHEN '不限' THEN '不限' ELSE null END as age,
+            case t2.target_type when 'convert_ratio' then CONCAT(IFNULL(ROUND(t2.combine_estimate_prob*100,2),0),'%') else 0 end 'convertRatio',
+            ( SELECT
+             case t.target_type when 'action_ratio' then CONCAT(IFNULL(ROUND(t.combine_estimate_prob*100,2),0),'%') else 0 end 'actionRatio'
+            from
+            ctop_ai_kuaishou_signature_recommended_target_combine t  where  t.signature=#{signature} and t.target_type='action_ratio' and t.age=t2.age and t.gender=t2.gender
+          ORDER BY t.stat_date DESC,t.gender DESC,t.age ASC LIMIT 0,1 ) as actionRatio
+                from
+            ctop_ai_kuaishou_signature_recommended_target_combine t2  where  t2.signature=#{signature} and  t2.target_type='convert_ratio'
+            ORDER BY t2.stat_date DESC,t2.gender DESC,t2.age ASC LIMIT 0,12
+    </select>
+
+    <select id="getActualProb" resultType="String">
+     SELECT  DISTINCT CONCAT(ROUND(actual_prob*100,2),'%') from ctop_ai_kuaishou_signature_recommended_target_combine t
+      where t.signature=#{signature}  and target_type=#{targetType} ORDER BY stat_date DESC LIMIT 0,1
+    </select>
+
+    <select id="populationAnalysisChart" resultType="java.util.Map">
+
+        SELECT
+      t2.crowd_coverage_cnt as 'crowdCoverageCnt',
+		t2.gender,
+		CASE t2.age WHEN '18-23岁|24-30岁|31-40岁' THEN '18-40'
+            WHEN '24-30岁|31-40岁|41-49岁' THEN '24-49'
+        WHEN '31-40岁|41-49岁|50+岁' THEN '31+'
+         WHEN '不限' THEN '不限' ELSE null END as age,
+            case t2.target_type when 'convert_ratio' then CONCAT(IFNULL(ROUND(t2.combine_estimate_prob*100,2),0),'%') else 0 end 'convertRatio',
+            ( SELECT
+             case t.target_type when 'action_ratio' then CONCAT(IFNULL(ROUND(t.combine_estimate_prob*100,2),0),'%') else 0 end 'actionRatio'
+            from
+            ctop_ai_kuaishou_signature_recommended_target_combine t  where  t.signature=#{signature} and t.target_type='action_ratio' and t.age=t2.age and t.gender=t2.gender
+          ORDER BY t.stat_date DESC,t.gender DESC,t.age ASC LIMIT 0,1 ) as actionRatio
+                from
+            ctop_ai_kuaishou_signature_recommended_target_combine t2  where  t2.signature=#{signature} and  t2.target_type='convert_ratio'
+            ORDER BY  t2.stat_date DESC,actionRatio ASC,convertRatio ASC  LIMIT 0,12
+    </select>
+
+    <select id="optimalCombination" resultType="java.util.Map">
+        SELECT * from (
+    select	t2.gender,
+		CASE t2.age WHEN '18-23岁|24-30岁|31-40岁' THEN '18-40岁'
+    WHEN '24-30岁|31-40岁|41-49岁' THEN '24-49岁'
+   WHEN '31-40岁|41-49岁|50+岁' THEN '31+岁'
+    WHEN '不限' THEN '不限' ELSE null END as age,
+    <if test='targetType=="convert_ratio"'>
+        case t2.target_type when 'convert_ratio' then t2.combine_estimate_prob else 0 end 'convertRatio'
+    </if>
+        <if test='targetType=="action_ratio"'>
+            case t2.target_type when 'action_ratio' then t2.combine_estimate_prob else 0 end 'actionRatio'
+        </if>
+                from
+            ctop_ai_kuaishou_signature_recommended_target_combine t2  where  t2.signature=#{signature} and  t2.target_type=#{targetType}
+
+            ORDER BY t2.stat_date DESC,t2.gender DESC,t2.age ASC LIMIT 0,12 ) t3  where
+        <if test='targetType=="convert_ratio"'>
+            t3.convertRatio >
+        </if>
+        <if test='targetType=="action_ratio"'>
+            t3.actionRatio >
+        </if>
+   (
+        SELECT MAX(tt.actual_prob) FROM(
+        SELECT actual_prob FROM ctop_ai_kuaishou_signature_recommended_target_combine t
+        WHERE t.signature=#{signature} and target_type=#{targetType} ORDER BY stat_date DESC LIMIT 0,12
+        ) tt
+      )   ORDER BY
+        <if test='targetType=="convert_ratio"'>
+            convertRatio desc LIMIT 0,1
+        </if>
+        <if test='targetType=="action_ratio"'>
+           actionRatio desc LIMIT 0,1
+        </if>
+
+    </select>
+
+    <select id="similarMaterialInfo" resultType="java.util.Map">
+           SELECT IFNULL(t2.signature,'') as signature,IFNULL(t2.photo_name,'') as photoName,IFNULL(t2.url,'')  as url, IFNULL(ROUND(SUM(t3.charge),2),0) as charge
+			 from
+         ctop_kuaishou_video_get t2
+        LEFT JOIN ctop_kuaishou_report_daily_material t3 on t2.signature=t3.signature
+        where t2.signature=#{signature} LIMIT 0,1
+    </select>
+
+    <select id="getSimilarMaterialList" resultType="java.util.Map">
+             SELECT IFNULL(t.similar_signature_1,'') as s1, IFNULL(t.similar_signature_2,'')  as s2,IFNULL(t.similar_signature_3,'')  as s3,IFNULL(t.similar_signature_4,'')  as s4,IFNULL(t.similar_signature_5,'')  as s5 from ctop_ai_kuaishou_signature_similar t
+        where t.signature=#{signature} ORDER BY t.stat_date desc LIMIT 0,1
+    </select>
+
+
 </mapper>

+ 15 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IMaterialReportOverViewService.java

@@ -3,6 +3,7 @@ package org.jeecg.modules.ctop.service;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.PageInfo;
+import org.jeecg.common.api.vo.Result;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -53,4 +54,18 @@ public interface IMaterialReportOverViewService {
     Map<String,Object> materialDetailAnalyse(int mediaId, String md5);
 
     List<JSONObject> getMaterialDetailChat(int mediaId, String md5);
+    //查询人群分析数据列表
+    Result populationAnalysisList(String signature);
+    //查询人群分析数据图
+    Result populationAnalysisChart(String signature);
+    /**  最优定向组合
+     * @param
+     * @return
+     */
+    Result optimalCombination(String signature);
+    /**  相似素材
+     * @param
+     * @return
+     */
+    Result similarMaterial(String signature);
 }

+ 283 - 87
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/MaterialReportOverViewServiceImpl.java

@@ -10,9 +10,8 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.constant.AccountReportConstants;
-import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.utils.JsonResourceUtil;
 import org.jeecg.modules.ctop.mapper.MaterialReportOverViewMapper;
@@ -29,6 +28,7 @@ import java.io.OutputStream;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -85,6 +85,10 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
 
     @Override
     public Map<String, Object> getTotalModule(int mediaId, String startDate, String endDate, JSONArray projects) {
+
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        String nowData = sdf.format(new Date());
+
         Map<String, Object> result = new HashMap<>();
         if (projects.isEmpty()) {
             projects = getProjectsByCurrentUser(mediaId);
@@ -93,39 +97,38 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
             //总消耗
             BigDecimal cost = materialReportOverViewMapper.queryBytedanceCost(startDate, endDate, projects);
             //上阶段消耗
-            BigDecimal lastCost = materialReportOverViewMapper.queryBytedanceCost(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate)-1), DateUtils.addDay(startDate, -1), projects);
+            BigDecimal lastCost = materialReportOverViewMapper.queryBytedanceCost(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate) - 1), DateUtils.addDay(startDate, -1), projects);
             result.put("costTotal", cost);
             //同比 (本阶段截止昨天消耗-上一个阶段截止和昨天对应日期的消耗)/上一个阶段截止和昨天对应日期的消耗 X 100%
-            result.put("yearOnYearCompare", countLink(cost,lastCost));
+            result.put("yearOnYearCompare", countLink(cost, lastCost));
             //昨日消耗
-            BigDecimal yesterdayCost = materialReportOverViewMapper.queryBytedanceCost(endDate, endDate, projects);
+            BigDecimal yesterdayCost = materialReportOverViewMapper.queryBytedanceCost(DateUtils.addDay(nowData, -1), DateUtils.addDay(nowData, -1), projects);
             //前天消耗
-            BigDecimal beforeYesterdayCost = materialReportOverViewMapper.queryBytedanceCost(DateUtils.addDay(endDate, -1), DateUtils.addDay(endDate, -1), projects);
+            BigDecimal beforeYesterdayCost = materialReportOverViewMapper.queryBytedanceCost(DateUtils.addDay(nowData, -2), DateUtils.addDay(nowData, -2), projects);
             result.put("yesterdayCost", yesterdayCost);
             //环比 (昨日消耗-前日消耗)/前日消耗 X 100%
-            result.put("chainCompare", countLink(yesterdayCost,beforeYesterdayCost));
+            result.put("chainCompare", countLink(yesterdayCost, beforeYesterdayCost));
 
         } else if (mediaId == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
             //总消耗
             BigDecimal cost = materialReportOverViewMapper.queryKuaishouCost(startDate, endDate, projects);
             //上阶段
-            BigDecimal lastCost = materialReportOverViewMapper.queryKuaishouCost(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate)-1), DateUtils.addDay(startDate, -1), projects);
+            BigDecimal lastCost = materialReportOverViewMapper.queryKuaishouCost(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate) - 1), DateUtils.addDay(startDate, -1), projects);
             result.put("costTotal", cost);
             //同比 (本阶段截止昨天消耗-上一个阶段截止和昨天对应日期的消耗)/上一个阶段截止和昨天对应日期的消耗 X 100%
-            result.put("yearOnYearCompare", countLink(cost,lastCost));
+            result.put("yearOnYearCompare", countLink(cost, lastCost));
             //昨日消耗
-            BigDecimal yesterdayCost = materialReportOverViewMapper.queryKuaishouCost(endDate, endDate, projects);
+            BigDecimal yesterdayCost = materialReportOverViewMapper.queryKuaishouCost(DateUtils.addDay(nowData, -1), DateUtils.addDay(nowData, -1), projects);
             //前天消耗
-            BigDecimal beforeYesterdayCost = materialReportOverViewMapper.queryKuaishouCost(DateUtils.addDay(endDate, -1), DateUtils.addDay(endDate, -1), projects);
+            BigDecimal beforeYesterdayCost = materialReportOverViewMapper.queryKuaishouCost(DateUtils.addDay(nowData, -2), DateUtils.addDay(nowData, -2), projects);
             result.put("yesterdayCost", yesterdayCost);
-            //环比 (昨日消耗-前日消耗)/前日消耗 X 100%
-            result.put("chainCompare", countLink(yesterdayCost,beforeYesterdayCost));
+            //环比 (昨日消耗-前日消耗)/前日消耗 X 100%
+            result.put("chainCompare", countLink(yesterdayCost, beforeYesterdayCost));
         }
         return result;
     }
 
 
-
     @Override
     public Map<String, Object> sumDataVideoNewEffective(int mediaId, String startDate, String endDate, JSONArray projects) {
         Map<String, Object> result = new HashMap<>();
@@ -133,43 +136,43 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
             projects = getProjectsByCurrentUser(mediaId);
         }
         if (mediaId == CtopAdConstant.PLATFORM_TYPE_BYTEDANCE_INT) {
-              //视频上新
-            List<Map<String, String>> videoList = materialReportOverViewMapper.queryMaterialCountList(startDate+" 00:00:00", endDate+" 23:59:59", projects);
+            //视频上新
+            List<Map<String, String>> videoList = materialReportOverViewMapper.queryMaterialCountList(startDate + " 00:00:00", endDate + " 23:59:59", projects);
             //总数
-            long videoTotal = videoList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            result.put("videoList",videoList);
-            result.put("videoTotal",videoTotal);
+            long videoTotal = videoList.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            result.put("videoList", videoList);
+            result.put("videoTotal", videoTotal);
             //素材使用率 = 有消耗的素材 / 总数 * 100%
-            long videoCost = materialReportOverViewMapper.queryMaterialCostList(startDate+" 00:00:00", endDate+" 23:59:59", projects);
-            result.put("useCompare", Check.isNull(videoCost) ? 0: new BigDecimal(videoCost).divide(new BigDecimal(videoTotal),4, RoundingMode.HALF_UP));
+            long videoCost = materialReportOverViewMapper.queryMaterialCostList(startDate + " 00:00:00", endDate + " 23:59:59", projects);
+            result.put("useCompare", Check.isNull(videoCost) ? 0 : new BigDecimal(videoCost).divide(new BigDecimal(videoTotal), 4, RoundingMode.HALF_UP));
             //有效视频
-            List<Map<String, String>> effectiveList = materialReportOverViewMapper.selectEffectiveMaterialVideoBytedance(startDate,endDate, projects);
+            List<Map<String, String>> effectiveList = materialReportOverViewMapper.selectEffectiveMaterialVideoBytedance(startDate, endDate, projects);
             //总数
-            long effectiveTotal = effectiveList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            result.put("effectiveList",effectiveList);
-            result.put("effectiveTotal",effectiveTotal);
+            long effectiveTotal = effectiveList.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            result.put("effectiveList", effectiveList);
+            result.put("effectiveTotal", effectiveTotal);
             //素材有效率 = 有效视频数量 / 视频总数 X 100%
-            result.put("effectiveCompare",Check.isNull(videoCost) ? 0: new BigDecimal(effectiveTotal).divide(new BigDecimal(videoTotal),4, RoundingMode.HALF_UP));
+            result.put("effectiveCompare", Check.isNull(videoCost) ? 0 : new BigDecimal(effectiveTotal).divide(new BigDecimal(videoTotal), 4, RoundingMode.HALF_UP));
 
         } else if (mediaId == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
 
             //视频上新
-            List<Map<String, String>> videoList = materialReportOverViewMapper.queryMaterialCountListKs(startDate+" 00:00:00", endDate+" 23:59:59", projects);
+            List<Map<String, String>> videoList = materialReportOverViewMapper.queryMaterialCountListKs(startDate + " 00:00:00", endDate + " 23:59:59", projects);
             //总数
-            long videoTotal = videoList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            result.put("videoList",videoList);
-            result.put("videoTotal",videoTotal);
+            long videoTotal = videoList.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            result.put("videoList", videoList);
+            result.put("videoTotal", videoTotal);
             //素材使用率 = 有消耗的素材 / 总数 * 100%
-            long videoCost = materialReportOverViewMapper.queryMaterialCostListKs(startDate+" 00:00:00", endDate+" 23:59:59", projects);
-            result.put("useCompare", Check.isNull(videoCost) ? 0: new BigDecimal(videoCost).divide(new BigDecimal(videoTotal),4, RoundingMode.HALF_UP));
+            long videoCost = materialReportOverViewMapper.queryMaterialCostListKs(startDate + " 00:00:00", endDate + " 23:59:59", projects);
+            result.put("useCompare", Check.isNull(videoCost) ? 0 : new BigDecimal(videoCost).divide(new BigDecimal(videoTotal), 4, RoundingMode.HALF_UP));
             //有效视频
-            List<Map<String, String>> effectiveList = materialReportOverViewMapper.selectEffectiveMaterialVideoKs(startDate,endDate, projects);
+            List<Map<String, String>> effectiveList = materialReportOverViewMapper.selectEffectiveMaterialVideoKs(startDate, endDate, projects);
             //总数
-            long effectiveTotal = effectiveList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            result.put("effectiveList",effectiveList);
-            result.put("effectiveTotal",effectiveTotal);
+            long effectiveTotal = effectiveList.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            result.put("effectiveList", effectiveList);
+            result.put("effectiveTotal", effectiveTotal);
             //素材有效率 = 有效视频数量 / 视频总数 X 100%
-            result.put("effectiveCompare",Check.isNull(videoTotal) ? 0 : new BigDecimal(effectiveTotal).divide(new BigDecimal(videoTotal),4, RoundingMode.HALF_UP));
+            result.put("effectiveCompare", Check.isNull(videoTotal) ? 0 : new BigDecimal(effectiveTotal).divide(new BigDecimal(videoTotal), 4, RoundingMode.HALF_UP));
 
         }
         return result;
@@ -178,61 +181,58 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
     //爆款视频
     @Override
     public Map<String, Object> sumDataVideoHot(int mediaId, String startDate, String endDate, JSONArray projects) {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        String nowData = sdf.format(new Date());
         Map<String, Object> result = new HashMap<>();
         if (projects.isEmpty()) {
             projects = getProjectsByCurrentUser(mediaId);
         }
         if (mediaId == CtopAdConstant.PLATFORM_TYPE_BYTEDANCE_INT) {
             //爆款视频
-            List<Map<String, String>> hotList = materialReportOverViewMapper.selectHotMaterialVideoBytedance(startDate,endDate, projects);
+            List<Map<String, String>> hotList = materialReportOverViewMapper.selectHotMaterialVideoBytedance(startDate, endDate, projects);
             //总数
-            long hotTotal = hotList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            result.put("hotList",hotList);
-            result.put("hotTotal",hotTotal);
+            long hotTotal = hotList.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            result.put("hotList", hotList);
+            result.put("hotTotal", hotTotal);
             //上阶段
-            List<Map<String, String>> lastHostList = materialReportOverViewMapper.selectHotMaterialVideoBytedance(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate)-1), DateUtils.addDay(startDate, -1), projects);
-            long lastHotTotal = lastHostList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            List<Map<String, String>> lastHostList = materialReportOverViewMapper.selectHotMaterialVideoBytedance(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate) - 1), DateUtils.addDay(startDate, -1), projects);
+            long lastHotTotal = lastHostList.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
             //同比 (本阶段截止昨天的爆款视频数量-上一个阶段截止和昨天对应日期的爆款视频数量)/上一个阶段截止和昨天对应日期的爆款视频数量X 100%
-            result.put("hotYearOnYearCompare", countLink(new BigDecimal(hotTotal),new BigDecimal(lastHotTotal)));
+            result.put("hotYearOnYearCompare", countLink(new BigDecimal(hotTotal), new BigDecimal(lastHotTotal)));
             //昨日消耗
-            List<Map<String, String>> yesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoBytedance(endDate,endDate, projects);
+            List<Map<String, String>> yesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoBytedance(DateUtils.addDay(nowData, -1), DateUtils.addDay(nowData, -1), projects);
             //前天消耗
-            List<Map<String, String>> beforeYesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoBytedance(DateUtils.addDay(endDate, -1), DateUtils.addDay(endDate, -1), projects);
-            long yesterday = yesterdayHost.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            long before = beforeYesterdayHost.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            //环比 (昨日-前日)/前日消耗 X 100%
-            result.put("hostCompare", countLink(new BigDecimal(yesterday),new BigDecimal(before)));
+            List<Map<String, String>> beforeYesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoBytedance(DateUtils.addDay(nowData, -2), DateUtils.addDay(nowData, -2), projects);
+            long yesterday = yesterdayHost.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            long before = beforeYesterdayHost.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            //环比 (昨日-前日)/前日消耗 X 100%
+            result.put("hostCompare", countLink(new BigDecimal(yesterday), new BigDecimal(before)));
 
         } else if (mediaId == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
             //爆款视频
-            List<Map<String, String>> hotList = materialReportOverViewMapper.selectHotMaterialVideoKs(startDate,endDate, projects);
+            List<Map<String, String>> hotList = materialReportOverViewMapper.selectHotMaterialVideoKs(startDate, endDate, projects);
             //总数
-            long hotTotal = hotList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            result.put("hotList",hotList);
-            result.put("hotTotal",hotTotal);
+            long hotTotal = hotList.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            result.put("hotList", hotList);
+            result.put("hotTotal", hotTotal);
             //上阶段
-            List<Map<String, String>> lastHostList = materialReportOverViewMapper.selectHotMaterialVideoKs(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate)-1), DateUtils.addDay(startDate, -1), projects);
-            long lastHotTotal = lastHostList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            List<Map<String, String>> lastHostList = materialReportOverViewMapper.selectHotMaterialVideoKs(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate) - 1), DateUtils.addDay(startDate, -1), projects);
+            long lastHotTotal = lastHostList.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
             //同比 (本阶段截止昨天的爆款视频数量-上一个阶段截止和昨天对应日期的爆款视频数量)/上一个阶段截止和昨天对应日期的爆款视频数量X 100%
-            result.put("hotYearOnYearCompare", countLink(new BigDecimal(hotTotal),new BigDecimal(lastHotTotal)));
+            result.put("hotYearOnYearCompare", countLink(new BigDecimal(hotTotal), new BigDecimal(lastHotTotal)));
             //昨日消耗
-            List<Map<String, String>> yesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoKs(endDate,endDate, projects);
+            List<Map<String, String>> yesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoKs(DateUtils.addDay(nowData, -1), DateUtils.addDay(nowData, -1), projects);
             //前天消耗
-            List<Map<String, String>> beforeYesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoKs(DateUtils.addDay(endDate, -1), DateUtils.addDay(endDate, -1), projects);
-            long yesterday = yesterdayHost.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            long before = beforeYesterdayHost.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
-            //环比 (昨日-前日)/前日消耗 X 100%
-            result.put("hostCompare", countLink(new BigDecimal(yesterday),new BigDecimal(before)));
+            List<Map<String, String>> beforeYesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoKs(DateUtils.addDay(nowData, -2), DateUtils.addDay(nowData, -2), projects);
+            long yesterday = yesterdayHost.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            long before = beforeYesterdayHost.stream().collect(Collectors.summarizingInt(s -> Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
+            //环比 (昨日-前日)/前日消耗 X 100%
+            result.put("hostCompare", countLink(new BigDecimal(yesterday), new BigDecimal(before)));
         }
         return result;
     }
 
 
-
-
-
-
-
     @Override
     public List<JSONObject> getTotalChat(int mediaId, String startDate, String endDate, JSONArray projects) {
         List<JSONObject> result = new ArrayList<>();
@@ -306,7 +306,7 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
 
     @Override
     public void exportBytedanceExcel(JSONObject requestBody, HttpServletRequest request, HttpServletResponse response) {
-        JSONArray projects= requestBody.getJSONArray("projects");
+        JSONArray projects = requestBody.getJSONArray("projects");
         if (projects.isEmpty()) {
             projects = getProjectsByCurrentUser(requestBody.getInteger("mediaId"));
         }
@@ -328,8 +328,8 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
         columns.add(3, "projectName");
 
         List<JSONObject> excelData = materialReportOverViewMapper.queryBytedanceMaterialReport(filed, requestBody.getString("startDate"), requestBody.getString("endDate"),
-                projects, requestBody.getString("md5"),requestBody.getString("target")==null?"cost":requestBody.getString("target")
-                , requestBody.getString("order")==null?"desc":requestBody.getString("order"));
+                projects, requestBody.getString("md5"), requestBody.getString("target") == null ? "cost" : requestBody.getString("target")
+                , requestBody.getString("order") == null ? "desc" : requestBody.getString("order"));
 
         if (null != excelData && excelData.isEmpty()) {
             return;
@@ -359,7 +359,7 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
 
     @Override
     public void exportKuaishouExcel(JSONObject requestBody, HttpServletRequest request, HttpServletResponse response) {
-        JSONArray projects= requestBody.getJSONArray("projects");
+        JSONArray projects = requestBody.getJSONArray("projects");
         if (projects.isEmpty()) {
             projects = getProjectsByCurrentUser(requestBody.getInteger("mediaId"));
         }
@@ -375,8 +375,8 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
         List<String> titles = getfileIds(AccountReportConstants.getKuaishouVideoReportDict(), columns2);
         String filedAll = JsonResourceUtil.joinAllFiled(AccountReportConstants.getKuaishouVideoReportMap());
         List<JSONObject> excelData = materialReportOverViewMapper.queryKuaishouMaterialReport(filedAll, requestBody.getString("startDate"), requestBody.getString("endDate"),
-                projects, requestBody.getString("channelType"),requestBody.getString("md5"), requestBody.getString("target")==null?"cost":requestBody.getString("target")
-                , requestBody.getString("order")==null?"desc":requestBody.getString("order"));
+                projects, requestBody.getString("channelType"), requestBody.getString("md5"), requestBody.getString("target") == null ? "cost" : requestBody.getString("target")
+                , requestBody.getString("order") == null ? "desc" : requestBody.getString("order"));
         if (null != excelData && excelData.isEmpty()) {
             return;
         }
@@ -463,14 +463,208 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
     @Override
     public List<JSONObject> getMaterialDetailChat(int mediaId, String md5) {
         List<JSONObject> result = new ArrayList<>();
-        if (mediaId == CtopAdConstant.PLATFORM_TYPE_BYTEDANCE_INT) {
-            result = materialReportOverViewMapper.queryBytedanceVideoChat(md5);
-        } else if (mediaId == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
-            result = materialReportOverViewMapper.queryKuaishouVideoChat(md5);
+        List<JSONObject> data = new ArrayList<>();
+        List<String> monthBetween = new ArrayList<>();
+        Map<String, JSONObject> map = new HashMap<>();
+        try {
+            if (mediaId == CtopAdConstant.PLATFORM_TYPE_BYTEDANCE_INT) {
+                result = materialReportOverViewMapper.queryBytedanceVideoChat(md5);
+            } else if (mediaId == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
+                result = materialReportOverViewMapper.queryKuaishouVideoChat(md5);
+            }
+            //获取最小日期和最大日期 计算中间无数据日期 填充0
+            if (result != null && result.size() > 0) {
+                JSONObject first = result.get(0);
+                JSONObject last = result.get(result.size() - 1);
+                String startDate = first.get("statDate") == null ? null : (String) first.get("statDate");
+                String endDate = last.get("statDate") == null ? null : (String) last.get("statDate");
+                if (startDate != null && endDate != null) {
+                    monthBetween = getMonthBetween(startDate, endDate);
+                    log.info(":{}", monthBetween.size());
+                }
+                for (JSONObject jsonObject : result) {
+                    String date = jsonObject.get("statDate") == null ? null : (String) jsonObject.get("statDate");
+                    if (date != null) {
+                        map.put(date, jsonObject);
+                    }
+                }
+                for (String date : monthBetween) {
+                    if (map.get(date) != null) {
+                        data.add(map.get(date));
+                    } else {
+                        JSONObject dataMap = new JSONObject();
+                        dataMap.put("statDate", date);
+                        dataMap.put("cost", 0);
+                        dataMap.put("aclick", 0);
+                        dataMap.put("activation", 0);
+                        data.add(dataMap);
+                    }
+                }
+            }
+
+
+        } catch (Exception e) {
+            log.info("查询数据错误:{}", e.toString());
+        }
+        return data;
+    }
+
+    private static List<String> getMonthBetween(String minDate, String maxDate) throws ParseException {
+        ArrayList<String> result = new ArrayList<String>();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//格式化为年月
+
+        Calendar min = Calendar.getInstance();
+        Calendar max = Calendar.getInstance();
+
+        min.setTime(sdf.parse(minDate));
+        min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1);
+
+        max.setTime(sdf.parse(maxDate));
+        max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2);
+
+        Calendar curr = min;
+        while (curr.before(max)) {
+            result.add(sdf.format(curr.getTime()));
+            curr.add(Calendar.MONTH, 1);
+        }
+
+        return result;
+    }
+
+    /**
+     * 查询人群分析数据列表
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public Result populationAnalysisList(String signature) {
+        Result result = new Result<>();
+        Map resultMap = new HashMap();
+        try {
+            List<Map> list = materialReportOverViewMapper.populationAnalysisList(signature);
+            //查询点击率
+            String actionRatio = materialReportOverViewMapper.getActualProb(signature, "action_ratio");
+            //查询转化率
+            String convertRatio = materialReportOverViewMapper.getActualProb(signature, "convert_ratio");
+            resultMap.put("dataList", list);
+            resultMap.put("actionRatio", actionRatio);
+            resultMap.put("convertRatio", convertRatio);
+            result.setSuccess(true);
+            result.setResult(resultMap);
+        } catch (Exception e) {
+            log.info("查询错误:{}", e.toString());
+            result.error500("查询错误");
+        }
+        return result;
+    }
+
+    /**
+     * 查询人群分析数据图
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public Result populationAnalysisChart(String signature) {
+        Result result = new Result<>();
+        try {
+            List<Map> list = materialReportOverViewMapper.populationAnalysisChart(signature);
+            result.setResult(list);
+        } catch (Exception e) {
+            log.info("查询错误:{}", e.toString());
+            result.error500("查询错误");
+        }
+        return result;
+    }
+
+    /**
+     * 最优定向组合
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public Result optimalCombination(String signature) {
+        Result result = new Result<>();
+        Map<String, String> map = new HashMap();
+        try {
+            //最优转化率组合
+            Map<String, String> convertRatio = materialReportOverViewMapper.optimalCombination(signature, "convert_ratio");
+            //最优点击率组合
+            Map<String, String> actionRatio = materialReportOverViewMapper.optimalCombination(signature, "action_ratio");
+            if (convertRatio != null) {
+                map.put("convertRatio", convertRatio.get("gender") + "/" + convertRatio.get("age"));
+            } else {
+                map.put("convertRatio", null);
+            }
+            if (actionRatio != null) {
+                map.put("actionRatio", actionRatio.get("gender") + "/" + actionRatio.get("age"));
+            } else {
+                map.put("actionRatio", null);
+            }
+
+            result.setResult(map);
+        } catch (Exception e) {
+            log.info("查询错误:{}", e.toString());
+            result.error500("查询错误");
         }
         return result;
     }
 
+    /**
+     * 相似素材
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public Result similarMaterial(String signature) {
+        Result result = new Result<>();
+        List<Map> resultMap = new ArrayList<>();
+        Map<String, String> map = materialReportOverViewMapper.getSimilarMaterialList(signature);
+        if (map != null) {
+            String signature1 = map.get("s1");
+            String signature2 = map.get("s2");
+            String signature3 = map.get("s3");
+            String signature4 = map.get("s4");
+            String signature5 = map.get("s5");
+            if (signature1 != null && !signature1.equals("")) {
+                Map info = materialReportOverViewMapper.similarMaterialInfo(signature1);
+                if (info.get("signature") != null && !info.get("signature").equals("")) {
+                    resultMap.add(info);
+                }
+            }
+            if (signature2 != null && !signature2.equals("")) {
+                Map info = materialReportOverViewMapper.similarMaterialInfo(signature2);
+                if (info.get("signature") != null && !info.get("signature").equals("")) {
+                    resultMap.add(info);
+                }
+            }
+            if (signature3 != null && !signature3.equals("")) {
+                Map info = materialReportOverViewMapper.similarMaterialInfo(signature3);
+                if (info.get("signature") != null && !info.get("signature").equals("")) {
+                    resultMap.add(info);
+                }
+            }
+            if (signature4 != null && !signature4.equals("")) {
+                Map info = materialReportOverViewMapper.similarMaterialInfo(signature4);
+                if (info.get("signature") != null && !info.get("signature").equals("")) {
+                    resultMap.add(info);
+                }
+            }
+            if (signature5 != null && !signature5.equals("")) {
+                Map info = materialReportOverViewMapper.similarMaterialInfo(signature5);
+                if (info.get("signature") != null && !info.get("signature").equals("")) {
+                    resultMap.add(info);
+                }
+            }
+        }
+        result.setResult(resultMap);
+        return result;
+    }
+
+
     //递归查询
     private Set<String> querySubordinate(Set<String> leaderIds, Set<String> result) {
         if (leaderIds.isEmpty()) {
@@ -484,8 +678,8 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
 
     //当项目为空的时候,根据当前登录人查询可查看的所有项目集合
     private JSONArray getProjectsByCurrentUser(int mediaId) {
-        String currentUser = ((LoginUser) SecurityUtils.getSubject().getPrincipal()).getId();
-        //String currentUser = "e9ca23d68d884d4ebb19d07889727dae";
+        //String currentUser = ((LoginUser) SecurityUtils.getSubject().getPrincipal()).getId();
+        String currentUser = "e9ca23d68d884d4ebb19d07889727dae";
         //TODO 为了解决管理员等角色初始化查全部项目查询效率慢的问题判断角色,待优化
         String roleCode = roleService.getRoleCodeByUserId(currentUser);
         if ("admin".equals(roleCode)) {
@@ -493,6 +687,7 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
         }
         return Check.isNull(queryProjectIdBy(recursiveQuerySubordinate(currentUser), mediaId)) ? null : queryProjectIdBy(recursiveQuerySubordinate(currentUser), mediaId);
     }
+
     private List<String> getfileIds(Map<String, Map<String, Object>> kuaishouVideoReportMap, JSONArray columns) {
         List<String> titles = new ArrayList<>();
         for (int i = 0; i < columns.size(); i++) {
@@ -510,12 +705,12 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
     }
 
     //环比计算
-    private  BigDecimal countLink(BigDecimal numA, BigDecimal numB) {
+    private BigDecimal countLink(BigDecimal numA, BigDecimal numB) {
         BigDecimal link = new BigDecimal("0");
-        if (Check.isNull(numA) || Check.isNull(numB)){
+        if (Check.isNull(numA) || Check.isNull(numB)) {
             return link;
         }
-        if (numB.compareTo(BigDecimal.ZERO)!=0) {
+        if (numB.compareTo(BigDecimal.ZERO) != 0) {
             link = (numA.subtract(numB)).divide(numB, 4, RoundingMode.HALF_UP);
         }
         return link;
@@ -524,15 +719,16 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
 
     /**
      * 同比 (当前 - 上阶段 ) / 上阶段
+     *
      * @param current 当前阶段数值
-     * @param last 上阶段数值
+     * @param last    上阶段数值
      * @return
      */
-    private BigDecimal yearOnYearCompare(BigDecimal current,BigDecimal last){
+    private BigDecimal yearOnYearCompare(BigDecimal current, BigDecimal last) {
         BigDecimal yearOnYear = new BigDecimal("0");
-        if (last.compareTo(BigDecimal.ZERO)!=0) {
+        if (last.compareTo(BigDecimal.ZERO) != 0) {
             // (当前 - 上阶段 ) / 上阶段
-            yearOnYear = (current.subtract(last)).divide(last,20,BigDecimal.ROUND_HALF_UP);
+            yearOnYear = (current.subtract(last)).divide(last, 20, BigDecimal.ROUND_HALF_UP);
         }
         return yearOnYear;
     }

+ 3 - 3
jeecg-cloud-module/jeecg-cloud-system-start/src/main/resources/application-dev.yml

@@ -76,9 +76,9 @@ spring:
   autoconfigure:
     exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
   datasource:
-    url: jdbc:mysql://139.186.27.96:3390/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=GMT%2B8
-    username: data
-    password: hcst@2021
+    url: jdbc:mysql://139.186.165.84:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=GMT%2B8
+    username: hcst
+    password: hcst@2020
     driver-class-name: com.mysql.jdbc.Driver
     druid:
       stat-view-servlet: