Bläddra i källkod

添加销售绩效计算逻辑

syh 5 år sedan
förälder
incheckning
1a9f0bb37b
18 ändrade filer med 723 tillägg och 53 borttagningar
  1. 11 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/CallbackController.java
  2. 248 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/SalePerformanceDetailController.java
  3. 21 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java
  4. 147 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/entity/SalePerformanceDetail.java
  5. 15 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/SalePerformanceDetailMapper.java
  6. 5 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/SalePerformanceDetailMapper.xml
  7. 15 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/ISalePerformanceDetailService.java
  8. 131 7
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/PerformanceAreaServiceImpl.java
  9. 19 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/SalePerformanceDetailServiceImpl.java
  10. 5 4
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/ISysUserRoleService.java
  11. 14 7
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysUserRoleServiceImpl.java
  12. 35 12
      jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java
  13. 2 0
      module-report/src/main/java/cn/com/ctop/bytedance/service/IReportService.java
  14. 10 0
      module-report/src/main/java/cn/com/ctop/bytedance/service/impl/ReportServiceImpl.java
  15. 2 2
      performance-appraisal/src/main/java/cn/com/ctop/performanceappraisal/mapper/PerformanceMapper.java
  16. 26 14
      performance-appraisal/src/main/java/cn/com/ctop/performanceappraisal/mapper/xml/PerformanceMapper.xml
  17. 4 2
      performance-appraisal/src/main/java/cn/com/ctop/performanceappraisal/service/IPerformanceService.java
  18. 13 4
      performance-appraisal/src/main/java/cn/com/ctop/performanceappraisal/service/impl/PerformanceServiceImpl.java

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

@@ -1,5 +1,6 @@
 package org.jeecg.modules.ctop.controller;
 
+import cn.com.ctop.bytedance.service.IReportService;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.UserAllocationMapper;
@@ -350,6 +351,13 @@ public class CallbackController {
             }
             //账号绑定
             bindAccountAuthService.addBindAccount(token.getAccountId(), KuaishouInterfaceConstant.LOGIN_TYPE_BYTEDANCE, advertiserId);
+            Thread thread = new Thread() {
+                @Override
+                public void run() {
+                    reportService.loadBytedanceHistoryData(token);
+                }
+            };
+            thread.start();
             returnMap.put("code", 0);
             returnMap.put("desc", "success");
         } catch (Exception e) {
@@ -360,4 +368,7 @@ public class CallbackController {
         return returnMap;
     }
 
+    @Autowired
+    private IReportService reportService;
+
 }

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

@@ -0,0 +1,248 @@
+package org.jeecg.modules.ctop.controller;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.aspect.annotation.AutoLog;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.ctop.entity.SalePerformanceDetail;
+import org.jeecg.modules.ctop.service.ISalePerformanceDetailService;
+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 javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 销售绩效详细信息
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-04-01
+ */
+@Slf4j
+@Api(tags = "销售绩效详细信息")
+@RestController
+@RequestMapping("/ctop/salePerformanceDetail")
+public class SalePerformanceDetailController {
+    @Autowired
+    private ISalePerformanceDetailService salePerformanceDetailService;
+
+    /**
+     * 分页列表查询
+     *
+     * @param salePerformanceDetail
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    @AutoLog(value = "销售绩效详细信息-分页列表查询")
+    @ApiOperation(value = "销售绩效详细信息-分页列表查询", notes = "销售绩效详细信息-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<IPage<SalePerformanceDetail>> queryPageList(SalePerformanceDetail salePerformanceDetail,
+                                                              @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                              @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                              HttpServletRequest req) {
+        Result<IPage<SalePerformanceDetail>> result = new Result<IPage<SalePerformanceDetail>>();
+        QueryWrapper<SalePerformanceDetail> queryWrapper = QueryGenerator.initQueryWrapper(salePerformanceDetail, req.getParameterMap());
+        Page<SalePerformanceDetail> page = new Page<SalePerformanceDetail>(pageNo, pageSize);
+        IPage<SalePerformanceDetail> pageList = salePerformanceDetailService.page(page, queryWrapper);
+        result.setSuccess(true);
+        result.setResult(pageList);
+        return result;
+    }
+
+    /**
+     * 添加
+     *
+     * @param salePerformanceDetail
+     * @return
+     */
+    @AutoLog(value = "销售绩效详细信息-添加")
+    @ApiOperation(value = "销售绩效详细信息-添加", notes = "销售绩效详细信息-添加")
+    @PostMapping(value = "/add")
+    public Result<SalePerformanceDetail> add(@RequestBody SalePerformanceDetail salePerformanceDetail) {
+        Result<SalePerformanceDetail> result = new Result<SalePerformanceDetail>();
+        try {
+            salePerformanceDetailService.save(salePerformanceDetail);
+            result.success("添加成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        return result;
+    }
+
+    /**
+     * 编辑
+     *
+     * @param salePerformanceDetail
+     * @return
+     */
+    @AutoLog(value = "销售绩效详细信息-编辑")
+    @ApiOperation(value = "销售绩效详细信息-编辑", notes = "销售绩效详细信息-编辑")
+    @PutMapping(value = "/edit")
+    public Result<SalePerformanceDetail> edit(@RequestBody SalePerformanceDetail salePerformanceDetail) {
+        Result<SalePerformanceDetail> result = new Result<SalePerformanceDetail>();
+        SalePerformanceDetail salePerformanceDetailEntity = salePerformanceDetailService.getById(salePerformanceDetail.getId());
+        if (salePerformanceDetailEntity == null) {
+            result.error500("未找到对应实体");
+        } else {
+            boolean ok = salePerformanceDetailService.updateById(salePerformanceDetail);
+            if (ok) {
+                result.success("修改成功!");
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * 通过id删除
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "销售绩效详细信息-通过id删除")
+    @ApiOperation(value = "销售绩效详细信息-通过id删除", notes = "销售绩效详细信息-通过id删除")
+    @DeleteMapping(value = "/delete")
+    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
+        try {
+            salePerformanceDetailService.removeById(id);
+        } catch (Exception e) {
+            log.error("删除失败", e.getMessage());
+            return Result.error("删除失败!");
+        }
+        return Result.ok("删除成功!");
+    }
+
+    /**
+     * 批量删除
+     *
+     * @param ids
+     * @return
+     */
+    @AutoLog(value = "销售绩效详细信息-批量删除")
+    @ApiOperation(value = "销售绩效详细信息-批量删除", notes = "销售绩效详细信息-批量删除")
+    @DeleteMapping(value = "/deleteBatch")
+    public Result<SalePerformanceDetail> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        Result<SalePerformanceDetail> result = new Result<SalePerformanceDetail>();
+        if (ids == null || "".equals(ids.trim())) {
+            result.error500("参数不识别!");
+        } else {
+            this.salePerformanceDetailService.removeByIds(Arrays.asList(ids.split(",")));
+            result.success("删除成功!");
+        }
+        return result;
+    }
+
+    /**
+     * 通过id查询
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "销售绩效详细信息-通过id查询")
+    @ApiOperation(value = "销售绩效详细信息-通过id查询", notes = "销售绩效详细信息-通过id查询")
+    @GetMapping(value = "/queryById")
+    public Result<SalePerformanceDetail> queryById(@RequestParam(name = "id", required = true) String id) {
+        Result<SalePerformanceDetail> result = new Result<SalePerformanceDetail>();
+        SalePerformanceDetail salePerformanceDetail = salePerformanceDetailService.getById(id);
+        if (salePerformanceDetail == null) {
+            result.error500("未找到对应实体");
+        } else {
+            result.setResult(salePerformanceDetail);
+            result.setSuccess(true);
+        }
+        return result;
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param request
+     * @param response
+     */
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
+        // Step.1 组装查询条件
+        QueryWrapper<SalePerformanceDetail> queryWrapper = null;
+        try {
+            String paramsStr = request.getParameter("paramsStr");
+            if (oConvertUtils.isNotEmpty(paramsStr)) {
+                String deString = URLDecoder.decode(paramsStr, "UTF-8");
+                SalePerformanceDetail salePerformanceDetail = JSON.parseObject(deString, SalePerformanceDetail.class);
+                queryWrapper = QueryGenerator.initQueryWrapper(salePerformanceDetail, request.getParameterMap());
+            }
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        //Step.2 AutoPoi 导出Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        List<SalePerformanceDetail> pageList = salePerformanceDetailService.list(queryWrapper);
+        //导出文件名称
+        mv.addObject(NormalExcelConstants.FILE_NAME, "销售绩效详细信息列表");
+        mv.addObject(NormalExcelConstants.CLASS, SalePerformanceDetail.class);
+        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("销售绩效详细信息列表数据", "导出人:Jeecg", "导出信息"));
+        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
+        return mv;
+    }
+
+    /**
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
+        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
+            MultipartFile file = entity.getValue();
+            ImportParams params = new ImportParams();
+            params.setTitleRows(2);
+            params.setHeadRows(1);
+            params.setNeedSave(true);
+            try {
+                List<SalePerformanceDetail> listSalePerformanceDetails = ExcelImportUtil.importExcel(file.getInputStream(), SalePerformanceDetail.class, params);
+                salePerformanceDetailService.saveBatch(listSalePerformanceDetails);
+                return Result.ok("文件导入成功!数据行数:" + listSalePerformanceDetails.size());
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                return Result.error("文件导入失败:" + e.getMessage());
+            } finally {
+                try {
+                    file.getInputStream().close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return Result.ok("文件导入失败!");
+    }
+
+}

+ 21 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -163,7 +163,7 @@ public class TestController {
         return "Success";
     }
 
-    static ExecutorService executorService = Executors.newFixedThreadPool(5);
+    static ExecutorService executorService = Executors.newFixedThreadPool(10);
 
     @GetMapping(value = "/getVideoAndImage")
     public String getVideoAndImage() {
@@ -267,6 +267,26 @@ public class TestController {
         thread.start();
     }
 
+    @GetMapping("loadBytedanceHistoryData")
+    public Map<String, Object> loadBytedanceHistoryData() {
+        Map<String, Object> result = new HashMap<>();
+        //1:查询所有头条的token数据
+        List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
+        if (null != tokens && tokens.size() > 0) {
+            tokens.forEach(token -> {
+                //拉取往期数据
+                executorService.submit(new Runnable() {
+                    @Override
+                    public void run() {
+                        reportService.loadBytedanceHistoryData(token);
+                    }
+                });
+            });
+        }
+        ResultMapUtils.setResultMap(result, StatusCode.COMMON_SUCCESS);
+        return result;
+    }
+
 
     @Autowired
     private IUserAllocationService userAllocationService;

+ 147 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/entity/SalePerformanceDetail.java

@@ -0,0 +1,147 @@
+package org.jeecg.modules.ctop.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+import java.util.Date;
+
+/**
+ * 销售绩效详细信息
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-04-01
+ */
+@Data
+@TableName("ctop_sale_performance_detail")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_sale_performance_detail对象", description = "销售绩效详细信息")
+public class SalePerformanceDetail {
+
+    /**
+     * id
+     */
+    @TableId(type = IdType.AUTO)
+    @ApiModelProperty(value = "id")
+    private Long id;
+    /**
+     * 销售人员id
+     */
+    @Excel(name = "销售人员id", width = 15)
+    @ApiModelProperty(value = "销售人员id")
+    private String saleId;
+    /**
+     * 角色id
+     */
+    @Excel(name = "角色id", width = 15)
+    @ApiModelProperty(value = "角色id")
+    private String roleId;
+    /**
+     * 媒体类型
+     */
+    @Excel(name = "媒体类型", width = 15)
+    @ApiModelProperty(value = "媒体类型")
+    private String mediaType;
+    /**
+     * 广告主id
+     */
+    @Excel(name = "广告主id", width = 15)
+    @ApiModelProperty(value = "广告主id")
+    private String advertiserId;
+    /**
+     * 年
+     */
+    @Excel(name = "年", width = 15)
+    @ApiModelProperty(value = "年")
+    private Integer year;
+    /**
+     * 季度
+     */
+    @Excel(name = "季度", width = 15)
+    @ApiModelProperty(value = "季度")
+    private Integer quarter;
+    /**
+     * 开始时间
+     */
+    @Excel(name = "开始时间", width = 15)
+    @ApiModelProperty(value = "开始时间")
+    private String startDate;
+    /**
+     * 结束时间
+     */
+    @Excel(name = "结束时间", width = 15)
+    @ApiModelProperty(value = "结束时间")
+    private String endDate;
+    /**
+     * 总消耗
+     */
+    @Excel(name = "总消耗", width = 15)
+    @ApiModelProperty(value = "总消耗")
+    private java.math.BigDecimal totalCost;
+    /**
+     * 媒体任务
+     */
+    @Excel(name = "媒体任务", width = 15)
+    @ApiModelProperty(value = "媒体任务")
+    private java.math.BigDecimal mediaTask;
+    /**
+     * 媒体任务完成情况
+     */
+    @Excel(name = "媒体任务完成情况", width = 15)
+    @ApiModelProperty(value = "媒体任务完成情况")
+    private java.math.BigDecimal doMediaTask;
+    /**
+     * 个人任务
+     */
+    @Excel(name = "个人任务", width = 15)
+    @ApiModelProperty(value = "个人任务")
+    private java.math.BigDecimal personnalTask;
+    /**
+     * 个人任务完成情况
+     */
+    @Excel(name = "个人任务完成情况", width = 15)
+    @ApiModelProperty(value = "个人任务完成情况")
+    private java.math.BigDecimal doPersonalTask;
+    /**
+     * 是否自拓客户
+     */
+    @Excel(name = "是否自拓客户", width = 15)
+    @ApiModelProperty(value = "是否自拓客户")
+    private Integer extensionSelf;
+    /**
+     * 是否新客
+     */
+    @Excel(name = "是否新客", width = 15)
+    @ApiModelProperty(value = "是否新客")
+    private Integer brandNew;
+    /**
+     * 提成百分比
+     */
+    @Excel(name = "提成百分比", width = 15)
+    @ApiModelProperty(value = "提成百分比")
+    private java.math.BigDecimal percentagePercent;
+    /**
+     * 提成金额
+     */
+    @Excel(name = "提成金额", width = 15)
+    @ApiModelProperty(value = "提成金额")
+    private java.math.BigDecimal percentage;
+    /**
+     * createTime
+     */
+    @ApiModelProperty(value = "createTime")
+    private Date createTime;
+    /**
+     * updateTime
+     */
+    @ApiModelProperty(value = "updateTime")
+    private Date updateTime;
+}

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

@@ -0,0 +1,15 @@
+package org.jeecg.modules.ctop.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.jeecg.modules.ctop.entity.SalePerformanceDetail;
+
+/**
+ * 销售绩效详细信息
+ *
+ * @author: jeecg-boot
+ * @date: 2020-04-01
+ * @cersion: V1.0
+ */
+public interface SalePerformanceDetailMapper extends BaseMapper<SalePerformanceDetail> {
+
+}

+ 5 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/SalePerformanceDetailMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.jeecg.modules.ctop.mapper.SalePerformanceDetailMapper">
+
+</mapper>

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

@@ -0,0 +1,15 @@
+package org.jeecg.modules.ctop.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.ctop.entity.SalePerformanceDetail;
+
+/**
+ * 销售绩效详细信息
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-04-01
+ */
+public interface ISalePerformanceDetailService extends IService<SalePerformanceDetail> {
+
+}

+ 131 - 7
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/PerformanceAreaServiceImpl.java

@@ -1,15 +1,22 @@
 package org.jeecg.modules.ctop.service.impl;
 
+import cn.com.ctop.common.module.utils.CtopAdConstant;
 import cn.com.ctop.performanceappraisal.service.IPerformanceService;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.modules.ctop.entity.Advertiser;
+import org.jeecg.modules.ctop.entity.SalePerformanceDetail;
 import org.jeecg.modules.ctop.service.IAdvertiserService;
+import org.jeecg.modules.ctop.service.ISalePerformanceDetailService;
 import org.jeecg.modules.ctop.service.PerformanceAreaService;
 import org.jeecg.modules.system.entity.SysUser;
+import org.jeecg.modules.system.entity.SysUserRole;
+import org.jeecg.modules.system.service.ISysUserRoleService;
 import org.jeecg.modules.system.service.ISysUserService;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.math.BigDecimal;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
 
@@ -28,33 +35,150 @@ public class PerformanceAreaServiceImpl implements PerformanceAreaService {
         List<SysUser> saleAms = sysUserService.getUserListByRoleId("f5a68aa2acf86e842100f0fa4b050d28");
     }
 
+    @Autowired
+    private ISysUserRoleService userRoleService;
+    @Autowired
+    private ISalePerformanceDetailService salePerformanceDetailService;
+
     public void countPerformance(SysUser user) {
         Date getDate = DateUtils.addDay(new Date(), -1);
-        String startDate = DateUtils.getQuarterStartDate(getDate);
-        String endDate = DateUtils.getQuarterEndDate(getDate);
+        String startDateStr = DateUtils.getQuarterStartDate(getDate);
+        String endDateStr = DateUtils.getQuarterEndDate(getDate);
+        //获取用户角色信息
+        SysUserRole userRole = userRoleService.getUserRoleByUserId(user.getId());
         //1:获取快手季度总消耗
-        BigDecimal kuaishouDoSeasonTask = performanceService.getKuaishouSeasonTotalCost(startDate, endDate);
+        BigDecimal kuaishouDoSeasonTask = performanceService.getKuaishouSeasonTotalCost(startDateStr, endDateStr);
         //2:获取快手个人季度总消耗
-        BigDecimal kuaishouDoPersonnalTask = performanceService.getKuaishouSalesSeasonTotalCost(startDate, endDate, user.getId());
+        BigDecimal kuaishouDoPersonnalTask = performanceService.getKuaishouSalesSeasonTotalCostByParams(startDateStr, endDateStr, user.getId(), null);
         //1:获取头条季度总消耗
-        BigDecimal bytedanceDoSeasonTask = performanceService.getBytedanceSeasonTotalCost(startDate, endDate);
+        BigDecimal bytedanceDoSeasonTask = performanceService.getBytedanceSeasonTotalCost(startDateStr, endDateStr);
         //2:获取头条个人季度总消耗
-        BigDecimal bytedanceDoPersonnalTask = performanceService.getBytedanceSalesSeasonTotalCost(startDate, endDate, user.getId());
+        BigDecimal bytedanceDoPersonnalTask = performanceService.getBytedanceSalesSeasonTotalCostByParams(startDateStr, endDateStr, user.getId(), null);
         //获取销售所属的广告主信息
         List<Advertiser> advertiserList = advertiserService.getBySaleId(user.getId());
 
         if (null != advertiserList && advertiserList.size() > 0) {
+            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+            Date startDate = null;
+            Date endDate = null;
+            try {
+                startDate = dateFormat.parse(startDateStr);
+                endDate = dateFormat.parse(endDateStr);
+            } catch (ParseException e) {
+                e.printStackTrace();
+            }
+
             for (Advertiser advertiser : advertiserList) {
                 Date endODate = DateUtils.addDay(advertiser.getCreateTime(), 90);
-                if (1 == 1) {
+                BigDecimal totalCost = BigDecimal.ZERO;
+                if (startDate.after(endODate)) {
+                    //季度开始时间大于新户结束时间(全部按照老户逻辑计算)
+                    SalePerformanceDetail detail = new SalePerformanceDetail();
+                    detail.setAdvertiserId(advertiser.getId());
+                    detail.setSaleId(user.getId());
+                    detail.setRoleId(userRole.getRoleId());
+                    detail.setYear(DateUtils.getYear(getDate));
+                    detail.setQuarter(DateUtils.getQuarter(getDate));
+                    if (user.getOrgCode().startsWith("A01A08")) {
+                        detail.setMediaType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
+                        detail.setStartDate(startDateStr);
+                        detail.setEndDate(endDateStr);
+                        totalCost = performanceService.getSalesSeasonTotalCostByParams(startDateStr, endDateStr, null, advertiser.getId(), CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
+                        detail.setTotalCost(totalCost);
+                        //TODO ---需要设定头条媒体季度任务
+                        detail.setMediaTask(new BigDecimal("200000000"));
+                        detail.setDoMediaTask(bytedanceDoSeasonTask);
+                        detail.setPersonnalTask(new BigDecimal("2400000"));
+                        detail.setDoPersonalTask(bytedanceDoPersonnalTask);
+                        detail.setExtensionSelf(advertiser.getAdvertiserType());
+                        detail.setBrandNew(0);
+                        //提成比例
+                        detail.setPercentagePercent(new BigDecimal("1.5"));
+                        //
+                        detail.setPercentage(new BigDecimal(""));
+                        salePerformanceDetailService.save(detail);
+                    } else if (user.getOrgCode().startsWith("A01A07")) {
+                        detail.setMediaType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
+                        detail.setStartDate(startDateStr);
+                        detail.setEndDate(endDateStr);
+                        totalCost = performanceService.getSalesSeasonTotalCostByParams(startDateStr, endDateStr, null, advertiser.getId(), CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
+                        detail.setTotalCost(totalCost);
+                        //TODO ---需要设定头条媒体季度任务
+                        detail.setMediaTask(new BigDecimal("200000000"));
+                        detail.setDoMediaTask(bytedanceDoSeasonTask);
+                        detail.setPersonnalTask(new BigDecimal("2400000"));
+                        detail.setDoPersonalTask(bytedanceDoPersonnalTask);
+                        detail.setExtensionSelf(advertiser.getAdvertiserType());
+                        detail.setBrandNew(0);
+                        //提成比例
+                        detail.setPercentagePercent(new BigDecimal("1.5"));
+                        //
+                        detail.setPercentage(new BigDecimal(""));
+                        salePerformanceDetailService.save(detail);
+                    } else {
+                        continue;
+                    }
 
+                } else if (endODate.after(endDate)) {
+                    //新湖结束时间大于季度结束时间(全部按照新户计算)
+                    SalePerformanceDetail detail = new SalePerformanceDetail();
+                    detail.setAdvertiserId(advertiser.getId());
+                    detail.setSaleId(user.getId());
+                    detail.setRoleId(userRole.getRoleId());
+                    detail.setYear(DateUtils.getYear(getDate));
+                    detail.setQuarter(DateUtils.getQuarter(getDate));
+                    if (user.getOrgCode().startsWith("A01A08")) {
+                        detail.setMediaType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
+                        detail.setStartDate(startDateStr);
+                        detail.setEndDate(endDateStr);
+                        totalCost = performanceService.getSalesSeasonTotalCostByParams(startDateStr, endDateStr, null, advertiser.getId(), CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
+                        detail.setTotalCost(totalCost);
+                        //TODO ---需要设定头条媒体季度任务
+                        detail.setMediaTask(new BigDecimal("200000000"));
+                        detail.setDoMediaTask(bytedanceDoSeasonTask);
+                        detail.setPersonnalTask(new BigDecimal("2400000"));
+                        detail.setDoPersonalTask(bytedanceDoPersonnalTask);
+                        detail.setExtensionSelf(advertiser.getAdvertiserType());
+                        detail.setBrandNew(1);
+                        //提成比例
+                        detail.setPercentagePercent(new BigDecimal("1.5"));
+                        //
+                        detail.setPercentage(new BigDecimal(""));
+                        salePerformanceDetailService.save(detail);
+                    } else if (user.getOrgCode().startsWith("A01A07")) {
+                        detail.setMediaType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
+                        detail.setStartDate(startDateStr);
+                        detail.setEndDate(endDateStr);
+                        totalCost = performanceService.getSalesSeasonTotalCostByParams(startDateStr, endDateStr, null, advertiser.getId(), CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
+                        detail.setTotalCost(totalCost);
+                        //TODO ---需要设定头条媒体季度任务
+                        detail.setMediaTask(new BigDecimal("200000000"));
+                        detail.setDoMediaTask(bytedanceDoSeasonTask);
+                        detail.setPersonnalTask(new BigDecimal("2400000"));
+                        detail.setDoPersonalTask(bytedanceDoPersonnalTask);
+                        detail.setExtensionSelf(advertiser.getAdvertiserType());
+                        detail.setBrandNew(1);
+                        //提成比例
+                        detail.setPercentagePercent(new BigDecimal("1.5"));
+                        //
+                        detail.setPercentage(new BigDecimal(""));
+                        salePerformanceDetailService.save(detail);
+                    } else {
+                        continue;
+                    }
                 } else {
+                    //新户结束时间处于本季度中间
+
 
                 }
             }
         }
     }
 
+    private void saveSalePerformanceDetail() {
+
+    }
+
     @Autowired
     private IAdvertiserService advertiserService;
 }

+ 19 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/SalePerformanceDetailServiceImpl.java

@@ -0,0 +1,19 @@
+package org.jeecg.modules.ctop.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.jeecg.modules.ctop.entity.SalePerformanceDetail;
+import org.jeecg.modules.ctop.mapper.SalePerformanceDetailMapper;
+import org.jeecg.modules.ctop.service.ISalePerformanceDetailService;
+import org.springframework.stereotype.Service;
+
+/**
+ * 销售绩效详细信息
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-04-01
+ */
+@Service
+public class SalePerformanceDetailServiceImpl extends ServiceImpl<SalePerformanceDetailMapper, SalePerformanceDetail> implements ISalePerformanceDetailService {
+
+}

+ 5 - 4
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/ISysUserRoleService.java

@@ -1,10 +1,9 @@
 package org.jeecg.modules.system.service;
 
-import java.util.Map;
-
+import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.modules.system.entity.SysUserRole;
 
-import com.baomidou.mybatisplus.extension.service.IService;
+import java.util.Map;
 
 /**
  * <p>
@@ -15,10 +14,12 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * @since 2018-12-21
  */
 public interface ISysUserRoleService extends IService<SysUserRole> {
-	
+
 	/**
 	 * 查询所有的用户角色信息
 	 * @return
 	 */
 	Map<String,String> queryUserRole();
+
+	SysUserRole getUserRoleByUserId(String userId);
 }

+ 14 - 7
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysUserRoleServiceImpl.java

@@ -1,9 +1,7 @@
 package org.jeecg.modules.system.service.impl;
 
-import java.util.IdentityHashMap;
-import java.util.List;
-import java.util.Map;
-
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.jeecg.modules.system.entity.SysRole;
 import org.jeecg.modules.system.entity.SysUser;
 import org.jeecg.modules.system.entity.SysUserRole;
@@ -14,7 +12,9 @@ import org.jeecg.modules.system.service.ISysUserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import java.util.IdentityHashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -31,7 +31,7 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
 	private ISysUserService userService;
 	@Autowired
 	private ISysRoleService roleService;
-	
+
 	/**
 	 * 查询所有用户对应的角色信息
 	 */
@@ -59,7 +59,14 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
 		}
 		return map;
 	}
-	
+
+	@Override
+	public SysUserRole getUserRoleByUserId(String userId) {
+		QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<>();
+		queryWrapper.eq("user_id", userId);
+		return getOne(queryWrapper);
+	}
+
 	/**
 	 * queryUserRole调用的方法
 	 * @param roleList

+ 35 - 12
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -2,7 +2,6 @@ package org.jeecg;
 
 import cn.com.ctop.bytedance.service.IReportService;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
-import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.service.IUserAllocationService;
@@ -11,11 +10,11 @@ import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
-import org.jeecg.common.util.DateUtils;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -130,20 +129,44 @@ public class SampleTest {
 
     @Autowired
     private ICtopOauthTokenService tokenService;
-    private static ExecutorService executorService = Executors.newFixedThreadPool(3);
+    private static ExecutorService executorService = Executors.newFixedThreadPool(10);
     private static CountDownLatch countDownLatch = null;
 
+    @Autowired
+    private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
     @Test
     public void testLoadJob() {
-        Date getDate = DateUtils.addDay(new Date(), -1);
-        //1:查询当日数据
-        QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("project_id", 222);
-        List<UserAllocation> allocations = userAllocationService.list(queryWrapper);
-        allocations.forEach(allocation -> {
-            CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
-            reportService.getAdvertiserPlanReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
-        });
+//        try {
+//            kuaishouWebInterfaceService.adkuaishouWebLogin("18606113995", "SsjX666!@");
+//            kuaishouWebInterfaceService.deleteAllComment(new HashMap<>());
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+
+        List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
+        if (null != tokens && tokens.size() > 0) {
+            countDownLatch = new CountDownLatch(tokens.size());
+            tokens.forEach(token -> {
+                //拉取往期数据
+                executorService.submit(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            reportService.loadBytedanceHistoryData(token);
+                            countDownLatch.countDown();
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                });
+            });
+            try {
+                countDownLatch.await();
+                System.out.println("数据获取完成");
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
     }
 
     @Autowired

+ 2 - 0
module-report/src/main/java/cn/com/ctop/bytedance/service/IReportService.java

@@ -31,4 +31,6 @@ public interface IReportService {
     void getAdvertiserPlanReport(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePL);
 
     void getAdvertiserCreativeReport(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePL);
+
+    void loadBytedanceHistoryData(CtopOauthToken token);
 }

+ 10 - 0
module-report/src/main/java/cn/com/ctop/bytedance/service/impl/ReportServiceImpl.java

@@ -307,6 +307,16 @@ public class ReportServiceImpl implements IReportService {
         getCreativeReportByPage(token, conditions, 1);
     }
 
+    @Override
+    public void loadBytedanceHistoryData(CtopOauthToken token) {
+        for (int i = 1; i < 180; i++) {
+            Date getDate = DateUtils.addDay(new Date(), -i);
+            this.getAdvertiserCreativeReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+            this.getAdvertiserPlanReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+            this.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+        }
+    }
+
     private ByteDanceAdvertiserReportDTO getReportDTO(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePl) {
         var conditions = new ByteDanceAdvertiserReportDTO();
         conditions.setAdvertiserId(token.getAccountId());

+ 2 - 2
performance-appraisal/src/main/java/cn/com/ctop/performanceappraisal/mapper/PerformanceMapper.java

@@ -42,7 +42,7 @@ public interface PerformanceMapper extends BaseMapper<Performance> {
 
     BigDecimal getKuaishouSeasonTotalCost(@Param(value = "startDate") String startDate, @Param(value = "endDate") String endDate);
 
-    BigDecimal getKuaishouSalesSeasonTotalCost(@Param(value = "startDate") String startDate, @Param(value = "endDate") String endDate, @Param(value = "saleId") String saleId);
+    BigDecimal getKuaishouSalesSeasonTotalCostByParams(@Param(value = "startDate") String startDate, @Param(value = "endDate") String endDate, @Param(value = "saleId") String saleId, @Param(value = "advertiserId") String advertiserId);
 
-    BigDecimal getBytedanceSalesSeasonTotalCost(@Param(value = "startDate") String startDate, @Param(value = "endDate") String endDate, @Param(value = "saleId") String saleId);
+    BigDecimal getBytedanceSalesSeasonTotalCostByParams(@Param(value = "startDate") String startDate, @Param(value = "endDate") String endDate, @Param(value = "saleId") String saleId, @Param(value = "advertiserId") String advertiserId);
 }

+ 26 - 14
performance-appraisal/src/main/java/cn/com/ctop/performanceappraisal/mapper/xml/PerformanceMapper.xml

@@ -330,36 +330,48 @@
         ORDER BY
             SUM(dailyAccount.cost) DESC
     </select>
-    <select id="getKuaishouSalesSeasonTotalCost" resultType="java.math.BigDecimal">
+    <select id="getBytedanceSalesSeasonTotalCostByParams" resultType="java.math.BigDecimal">
         SELECT
-            SUM(charge)
+        SUM(charge)
         FROM
-            ctop_kuaishou_report_daily_account daily
+        ctop_bytedance_report_advertiser_daily daily
         LEFT JOIN
-            ctop_user_allocation allocation ON daily.account_id = allocation.account_id
+        ctop_user_allocation allocation ON daily.advertiser_id = allocation.account_id
         LEFT JOIN
-            ctop_advertiser advertiser ON advertiser.id = allocation.advertiser_id
+        ctop_advertiser advertiser ON advertiser.id = allocation.advertiser_id
         WHERE
-            advertiser.sale_id = #{saleId}
+        1=1
+        <if test="saleId != null">
+            and advertiser.sale_id = #{saleId}
+        </if>
+        <if test="advertiserId != null">
+            and advertiser.id = #{advertiserId}
+        </if>
         AND
-            daily.stat_date &gt;= #{startDate}
+        daily.stat_datetime &gt;= #{startDate}
         AND
-            daily.stat_date &lt; #{endDate}
+        daily.stat_datetime &lt; #{endDate}
     </select>
-    <select id="getBytedanceSalesSeasonTotalCost" resultType="java.math.BigDecimal">
+    <select id="getKuaishouSalesSeasonTotalCostByParams" resultType="java.math.BigDecimal">
         SELECT
             SUM(charge)
         FROM
-            ctop_bytedance_report_advertiser_daily daily
+        ctop_kuaishou_report_daily_account daily
         LEFT JOIN
-            ctop_user_allocation allocation ON daily.advertiser_id = allocation.account_id
+        ctop_user_allocation allocation ON daily.account_id = allocation.account_id
         LEFT JOIN
             ctop_advertiser advertiser ON advertiser.id = allocation.advertiser_id
         WHERE
-            advertiser.sale_id = #{saleId}
+        1=1
+        <if test="saleId != null">
+            and advertiser.sale_id = #{saleId}
+        </if>
+        <if test="advertiserId != null">
+            and advertiser.id = #{advertiserId}
+        </if>
         AND
-            daily.stat_datetime &gt;= #{startDate}
+        daily.stat_date &gt;= #{startDate}
         AND
-            daily.stat_datetime &lt; #{endDate}
+        daily.stat_date &lt; #{endDate}
     </select>
 </mapper>

+ 4 - 2
performance-appraisal/src/main/java/cn/com/ctop/performanceappraisal/service/IPerformanceService.java

@@ -40,7 +40,9 @@ public interface IPerformanceService extends IService<Performance> {
 
     BigDecimal getKuaishouSeasonTotalCost(String startDate, String endDate);
 
-    BigDecimal getKuaishouSalesSeasonTotalCost(String startDate, String endDate, String id);
+    BigDecimal getKuaishouSalesSeasonTotalCostByParams(String startDate, String endDate, String salesId, String advertiserId);
 
-    BigDecimal getBytedanceSalesSeasonTotalCost(String startDate, String endDate, String id);
+    BigDecimal getBytedanceSalesSeasonTotalCostByParams(String startDate, String endDate, String saledId, String advertiserId);
+
+    BigDecimal getSalesSeasonTotalCostByParams(String startDate, String endDate, String saledId, String advertiserId, String mediaType);
 }

+ 13 - 4
performance-appraisal/src/main/java/cn/com/ctop/performanceappraisal/service/impl/PerformanceServiceImpl.java

@@ -174,13 +174,22 @@ public class PerformanceServiceImpl extends ServiceImpl<PerformanceMapper, Perfo
     }
 
     @Override
-    public BigDecimal getKuaishouSalesSeasonTotalCost(String startDate, String endDate, String salesId) {
-        return performanceMapper.getKuaishouSalesSeasonTotalCost(startDate, endDate, salesId);
+    public BigDecimal getKuaishouSalesSeasonTotalCostByParams(String startDate, String endDate, String salesId, String advertiserId) {
+        return performanceMapper.getKuaishouSalesSeasonTotalCostByParams(startDate, endDate, salesId, advertiserId);
     }
 
     @Override
-    public BigDecimal getBytedanceSalesSeasonTotalCost(String startDate, String endDate, String salesId) {
-        return performanceMapper.getBytedanceSalesSeasonTotalCost(startDate, endDate, salesId);
+    public BigDecimal getBytedanceSalesSeasonTotalCostByParams(String startDate, String endDate, String salesId, String advertiserId) {
+        return performanceMapper.getBytedanceSalesSeasonTotalCostByParams(startDate, endDate, salesId, advertiserId);
+    }
+
+    @Override
+    public BigDecimal getSalesSeasonTotalCostByParams(String startDate, String endDate, String saledId, String advertiserId, String mediaType) {
+        if (null != mediaType && mediaType.equals(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE)) {
+            return performanceMapper.getKuaishouSalesSeasonTotalCostByParams(startDate, endDate, saledId, advertiserId);
+        } else {
+            return performanceMapper.getBytedanceSalesSeasonTotalCostByParams(startDate, endDate, saledId, advertiserId);
+        }
     }
 
     private BigDecimal getTotalRoyalty(OptimizerConfig config, OptimizerCostDetailVO vo, OptimizerCostDetailVO quarterCost) {