Browse Source

添加销售绩效计算逻辑

syh 5 years ago
parent
commit
59d259830b
14 changed files with 478 additions and 124 deletions
  1. 73 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/AdvertiserController.java
  2. 27 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/entity/SalePerformanceDetail.java
  3. 6 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/AdvertiserMapper.java
  4. 43 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/AdvertiserMapper.xml
  5. 4 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IAdvertiserService.java
  6. 1 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/PerformanceAreaService.java
  7. 9 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/AdvertiserServiceImpl.java
  8. 131 109
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/PerformanceAreaServiceImpl.java
  9. 27 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/vo/SheetInfoVo.java
  10. 110 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/excelutil/entity/KuaishouXxlEntity.java
  11. 4 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java
  12. 8 0
      jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java
  13. 3 3
      performance-appraisal/src/main/java/cn/com/ctop/performanceappraisal/mapper/xml/PerformanceMapper.xml
  14. 32 6
      performance-appraisal/src/main/java/cn/com/ctop/performanceappraisal/service/impl/PerformanceServiceImpl.java

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

@@ -4,6 +4,7 @@ import cn.com.ctop.bytedance.mapper.MaterialReportMapper;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.StringUtils;
 import cn.com.ctop.common.module.utils.StringUtils;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -379,4 +380,76 @@ public class AdvertiserController {
         }
         }
         return Result.ok("文件导入失败!");
         return Result.ok("文件导入失败!");
     }
     }
+
+    /**
+     * 导出报表
+     *
+     * @return
+     */
+    @RequestMapping(value = "/exportXxlDailyReport")
+    @ResponseBody
+    public void exportXxl(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson) throws Exception {
+
+//        List<SheetInfoVo> sheets = new ArrayList<SheetInfoVo>();
+//        List<KuaishouXxlEntity> entities = advertiserService.getXxlStatisticInfo();
+//
+//        List<List<Object>> group = new ArrayList<>();
+//        List<DailyGroupReportVO> dailyGroupReport = dailyReport.getDailyGroupReport();
+//        if (!Check.isNull(dailyGroupReport)) {
+//            for (DailyGroupReportVO groupReportVO : dailyGroupReport) {
+//                List<Object> dailyGroup = new ArrayList();
+//                dailyGroup.add(groupReportVO.getAccountId());
+//                dailyGroup.add(groupReportVO.getAuthName());
+//                dailyGroup.add(groupReportVO.getStatDate());
+//                dailyGroup.add(groupReportVO.getCampaignName());
+//                dailyGroup.add(groupReportVO.getUnitName());
+//                dailyGroup.add(groupReportVO.getCost()); // 花费
+//                dailyGroup.add(groupReportVO.getDisCountCost()); // 折后花费
+//                dailyGroup.add(groupReportVO.getPhotoShow()); // 展示数
+//                dailyGroup.add(groupReportVO.getPhotoClick()); // 点击数
+//                dailyGroup.add(groupReportVO.getBclick());   // 行为数
+//                dailyGroup.add(RateUtil.getRate(groupReportVO.getPhotoClickRatio())); // 点击率
+//                dailyGroup.add(RateUtil.getRate(groupReportVO.getActionRatio())); // 行为率
+//
+//                dailyGroup.add(groupReportVO.getImpression1kCost()); // 平均千次展现花费
+//                dailyGroup.add(groupReportVO.getPhotoClickCost()); // 平均点击花费
+//                dailyGroup.add(groupReportVO.getConversions()); // 转化数
+//                //  dailyGroup.add(groupReportVO.getConversionPrice()); // 转化单价
+//                dailyGroup.add(groupReportVO.getDiscountConversionPrice()); // 折后转化成本
+//                dailyGroup.add(RateUtil.getRate(groupReportVO.getClickConversionRate())); // 点击转化率
+//
+//                group.add(dailyGroup);
+//            }
+//
+//        }
+//
+//        String[] accountHeaders = {"时间", "消耗(元)", "激励花费(元)", "实际消耗(元)", "展示数", "素材曝光数", "点击数", "点击率", "平均点击花费(元)", "行为数", "行为率", "平均千次展现花费(元)", "转化数(元)", "转化单价", "转化率", "折后转化成本(元)"};
+//        String[] groupHeaders = {"账号", "账号名称", "日期", "计划名称", "广告组名称", "消耗(元)", "折后消耗(元)", "展现", "点击数", "行为数", "点击率", "行为率", "平均千次展现费用(元)", "平均点击费用(元)", "转化数", "折后转化成本(元)", "点击转化率"};
+//        OutputStream os = response.getOutputStream();
+//        ExportExcelUtils eeu = new ExportExcelUtils();
+//        XSSFWorkbook workbook = new XSSFWorkbook();
+//        eeu.exportExcel(workbook, 0, "分日数据", accountHeaders, accountData);
+//        eeu.exportExcel(workbook, 1, "分组数据", groupHeaders, group);
+//        this.setResponseHeader(response, "日报.xls");
+//        workbook.write(os);
+//        os.flush();
+//        os.close();
+    }
+
+    //发送响应流方法
+    public void setResponseHeader(HttpServletResponse response, String fileName) {
+        try {
+            try {
+                fileName = new String(fileName.getBytes(), "ISO8859-1");
+            } catch (UnsupportedEncodingException e) {
+                e.printStackTrace();
+            }
+            response.setContentType("application/octet-stream;charset=ISO8859-1");
+            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+            response.addHeader("Pargam", "no-cache");
+            response.addHeader("Cache-Control", "no-cache");
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+    }
 }
 }

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

@@ -127,7 +127,7 @@ public class SalePerformanceDetail {
      */
      */
     @Excel(name = "提成百分比", width = 15)
     @Excel(name = "提成百分比", width = 15)
     @ApiModelProperty(value = "提成百分比")
     @ApiModelProperty(value = "提成百分比")
-    private java.math.BigDecimal percentagePercent;
+    private java.math.BigDecimal percent;
     /**
     /**
      * 提成金额
      * 提成金额
      */
      */
@@ -144,4 +144,30 @@ public class SalePerformanceDetail {
      */
      */
     @ApiModelProperty(value = "updateTime")
     @ApiModelProperty(value = "updateTime")
     private Date updateTime;
     private Date updateTime;
+
+    @Override
+    public String toString() {
+        return "SalePerformanceDetail{" +
+                "id=" + id +
+                ", saleId='" + saleId + '\'' +
+                ", roleId='" + roleId + '\'' +
+                ", mediaType='" + mediaType + '\'' +
+                ", advertiserId='" + advertiserId + '\'' +
+                ", year=" + year +
+                ", quarter=" + quarter +
+                ", startDate='" + startDate + '\'' +
+                ", endDate='" + endDate + '\'' +
+                ", totalCost=" + totalCost +
+                ", mediaTask=" + mediaTask +
+                ", doMediaTask=" + doMediaTask +
+                ", personnalTask=" + personnalTask +
+                ", doPersonalTask=" + doPersonalTask +
+                ", extensionSelf=" + extensionSelf +
+                ", brandNew=" + brandNew +
+                ", percent=" + percent +
+                ", percentage=" + percentage +
+                ", createTime=" + createTime +
+                ", updateTime=" + updateTime +
+                '}';
+    }
 }
 }

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

@@ -1,7 +1,11 @@
 package org.jeecg.modules.ctop.mapper;
 package org.jeecg.modules.ctop.mapper;
 
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 import org.jeecg.modules.ctop.entity.Advertiser;
 import org.jeecg.modules.ctop.entity.Advertiser;
+import org.jeecg.modules.excelutil.entity.KuaishouXxlEntity;
+
+import java.util.List;
 
 
 /**
 /**
  * @Description: 广告主信息表
  * @Description: 广告主信息表
@@ -11,4 +15,6 @@ import org.jeecg.modules.ctop.entity.Advertiser;
  */
  */
 public interface AdvertiserMapper extends BaseMapper<Advertiser> {
 public interface AdvertiserMapper extends BaseMapper<Advertiser> {
 
 
+    List<KuaishouXxlEntity> getXXlStatisticInfo(@Param(value = "accountId") String accountId, @Param(value = "groupBy") String groupBy);
+
 }
 }

+ 43 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/AdvertiserMapper.xml

@@ -2,4 +2,46 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <!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.AdvertiserMapper">
 <mapper namespace="org.jeecg.modules.ctop.mapper.AdvertiserMapper">
 
 
-</mapper>
+    <select id="getXXlStatisticInfo" resultType="org.jeecg.modules.excelutil.entity.KuaishouXxlEntity">
+        select report.stat_date as date,
+        sum(report.charge) as cost,
+        sum(case
+        when g.deep_conversion_bid != 0
+        then report.charge
+        else 0
+        end) as doubleBid,
+        sum(case
+        when g.deep_conversion_bid = 0
+        then report.charge
+        else 0
+        end) as singleBid,
+        sum(activation) as active,
+        round(sum(report.charge) / sum(activation), 2) as activeCost,
+        (
+        select
+        count(1)
+        from
+        ctop_kuaishou_group g2
+        left join ctop_user_allocation allocation2 on g2.account_id = allocation2.account_id
+        where
+        allocation2.project_id = 285
+        <if test="accountId != null">
+            and allocation2.account_id = #{accountId}
+        </if>
+        and
+        date_format(g2.group_create_time, '%Y-%m-%d') = report.stat_date)
+        as planNum,
+        '' as mat
+        from ctop_kuaishou_report_daily_group report
+        left join ctop_kuaishou_group g on g.unit_id = report.unit_id
+        left join ctop_user_allocation allocation on allocation.account_id = report.account_id
+        where allocation.project_id = 285
+        <if test="accountId != null">
+            and allocation2.account_id = #{accountId}
+        </if>
+        <if test="groupBy != null">
+            group by report.stat_date;
+        </if>
+
+    </select>
+</mapper>

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

@@ -2,6 +2,7 @@ package org.jeecg.modules.ctop.service;
 
 
 import org.jeecg.modules.ctop.entity.Advertiser;
 import org.jeecg.modules.ctop.entity.Advertiser;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.excelutil.entity.KuaishouXxlEntity;
 
 
 import java.util.List;
 import java.util.List;
 
 
@@ -14,4 +15,7 @@ import java.util.List;
 public interface IAdvertiserService extends IService<Advertiser> {
 public interface IAdvertiserService extends IService<Advertiser> {
 
 
     List<Advertiser> getBySaleId(String saleId);
     List<Advertiser> getBySaleId(String saleId);
+
+    List<KuaishouXxlEntity> getXxlStatisticInfo();
+
 }
 }

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/PerformanceAreaService.java

@@ -1,5 +1,5 @@
 package org.jeecg.modules.ctop.service;
 package org.jeecg.modules.ctop.service;
 
 
-public interface PerformanceAreaService {
+public interface IPerformanceAreaService {
     void loadSalsePerformance();
     void loadSalsePerformance();
 }
 }

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

@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import org.jeecg.modules.ctop.entity.Advertiser;
 import org.jeecg.modules.ctop.entity.Advertiser;
 import org.jeecg.modules.ctop.mapper.AdvertiserMapper;
 import org.jeecg.modules.ctop.mapper.AdvertiserMapper;
 import org.jeecg.modules.ctop.service.IAdvertiserService;
 import org.jeecg.modules.ctop.service.IAdvertiserService;
+import org.jeecg.modules.excelutil.entity.KuaishouXxlEntity;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -19,10 +21,17 @@ import java.util.List;
 @Service
 @Service
 public class AdvertiserServiceImpl extends ServiceImpl<AdvertiserMapper, Advertiser> implements IAdvertiserService {
 public class AdvertiserServiceImpl extends ServiceImpl<AdvertiserMapper, Advertiser> implements IAdvertiserService {
 
 
+    @Autowired
+    private AdvertiserMapper advertiserMapper;
     @Override
     @Override
     public List<Advertiser> getBySaleId(String saleId) {
     public List<Advertiser> getBySaleId(String saleId) {
         QueryWrapper<Advertiser> queryWrapper = new QueryWrapper<>();
         QueryWrapper<Advertiser> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("sale_id", saleId);
         queryWrapper.eq("sale_id", saleId);
         return this.list(queryWrapper);
         return this.list(queryWrapper);
     }
     }
+
+    @Override
+    public List<KuaishouXxlEntity> getXxlStatisticInfo() {
+        return advertiserMapper.getXXlStatisticInfo(null, null);
+    }
 }
 }

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

@@ -6,21 +6,24 @@ import org.jeecg.common.util.DateUtils;
 import org.jeecg.modules.ctop.entity.Advertiser;
 import org.jeecg.modules.ctop.entity.Advertiser;
 import org.jeecg.modules.ctop.entity.SalePerformanceDetail;
 import org.jeecg.modules.ctop.entity.SalePerformanceDetail;
 import org.jeecg.modules.ctop.service.IAdvertiserService;
 import org.jeecg.modules.ctop.service.IAdvertiserService;
+import org.jeecg.modules.ctop.service.IPerformanceAreaService;
 import org.jeecg.modules.ctop.service.ISalePerformanceDetailService;
 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.SysUser;
 import org.jeecg.modules.system.entity.SysUserRole;
 import org.jeecg.modules.system.entity.SysUserRole;
 import org.jeecg.modules.system.service.ISysUserRoleService;
 import org.jeecg.modules.system.service.ISysUserRoleService;
 import org.jeecg.modules.system.service.ISysUserService;
 import org.jeecg.modules.system.service.ISysUserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.ParseException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Date;
 import java.util.List;
 import java.util.List;
 
 
-public class PerformanceAreaServiceImpl implements PerformanceAreaService {
+@Service
+public class PerformanceAreaServiceImpl implements IPerformanceAreaService {
 
 
     @Autowired
     @Autowired
     private ISysUserService sysUserService;
     private ISysUserService sysUserService;
@@ -31,8 +34,18 @@ public class PerformanceAreaServiceImpl implements PerformanceAreaService {
     public void loadSalsePerformance() {
     public void loadSalsePerformance() {
         //1:获取销售列表
         //1:获取销售列表
         List<SysUser> sales = sysUserService.getUserListByRoleId("75ee837e6f3de29c0e3ed75d4629438e");
         List<SysUser> sales = sysUserService.getUserListByRoleId("75ee837e6f3de29c0e3ed75d4629438e");
+        if (null != sales && sales.size() > 0) {
+            sales.forEach(sale -> {
+                countPerformance(sale);
+            });
+        }
         //2:获取销售AM列表
         //2:获取销售AM列表
         List<SysUser> saleAms = sysUserService.getUserListByRoleId("f5a68aa2acf86e842100f0fa4b050d28");
         List<SysUser> saleAms = sysUserService.getUserListByRoleId("f5a68aa2acf86e842100f0fa4b050d28");
+        if (null != saleAms && saleAms.size() > 0) {
+            saleAms.forEach(saleAm -> {
+                countPerformance(saleAm);
+            });
+        }
     }
     }
 
 
     @Autowired
     @Autowired
@@ -41,142 +54,151 @@ public class PerformanceAreaServiceImpl implements PerformanceAreaService {
     private ISalePerformanceDetailService salePerformanceDetailService;
     private ISalePerformanceDetailService salePerformanceDetailService;
 
 
     public void countPerformance(SysUser user) {
     public void countPerformance(SysUser user) {
-        Date getDate = DateUtils.addDay(new Date(), -1);
+//        Date getDate = DateUtils.addDay(new Date(), -1)
+        Date getDate = DateUtils.addDay(new Date(), -5);
         String startDateStr = DateUtils.getQuarterStartDate(getDate);
         String startDateStr = DateUtils.getQuarterStartDate(getDate);
         String endDateStr = DateUtils.getQuarterEndDate(getDate);
         String endDateStr = DateUtils.getQuarterEndDate(getDate);
         //获取用户角色信息
         //获取用户角色信息
         SysUserRole userRole = userRoleService.getUserRoleByUserId(user.getId());
         SysUserRole userRole = userRoleService.getUserRoleByUserId(user.getId());
         //1:获取快手季度总消耗
         //1:获取快手季度总消耗
-        BigDecimal kuaishouDoSeasonTask = performanceService.getKuaishouSeasonTotalCost(startDateStr, endDateStr);
+        BigDecimal kuaishouFinishMediaTask = performanceService.getKuaishouSeasonTotalCost(startDateStr, endDateStr);
         //2:获取快手个人季度总消耗
         //2:获取快手个人季度总消耗
-        BigDecimal kuaishouDoPersonnalTask = performanceService.getKuaishouSalesSeasonTotalCostByParams(startDateStr, endDateStr, user.getId(), null);
+        BigDecimal kuaishouFinishPersonnalTask = performanceService.getKuaishouSalesSeasonTotalCostByParams(startDateStr, endDateStr, user.getId(), null);
         //1:获取头条季度总消耗
         //1:获取头条季度总消耗
-        BigDecimal bytedanceDoSeasonTask = performanceService.getBytedanceSeasonTotalCost(startDateStr, endDateStr);
+        BigDecimal bytedanceFinishMediaTask = performanceService.getBytedanceSeasonTotalCost(startDateStr, endDateStr);
         //2:获取头条个人季度总消耗
         //2:获取头条个人季度总消耗
-        BigDecimal bytedanceDoPersonnalTask = performanceService.getBytedanceSalesSeasonTotalCostByParams(startDateStr, endDateStr, user.getId(), null);
+        BigDecimal bytedanceFinishPersonnalTask = performanceService.getBytedanceSalesSeasonTotalCostByParams(startDateStr, endDateStr, user.getId(), null);
         //获取销售所属的广告主信息
         //获取销售所属的广告主信息
         List<Advertiser> advertiserList = advertiserService.getBySaleId(user.getId());
         List<Advertiser> advertiserList = advertiserService.getBySaleId(user.getId());
 
 
         if (null != advertiserList && advertiserList.size() > 0) {
         if (null != advertiserList && advertiserList.size() > 0) {
             SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
             SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
-            Date startDate = null;
-            Date endDate = null;
+            Date startSeasonDate = null;
+            Date endSeasonDate = null;
             try {
             try {
-                startDate = dateFormat.parse(startDateStr);
-                endDate = dateFormat.parse(endDateStr);
+                startSeasonDate = dateFormat.parse(startDateStr);
+                endSeasonDate = dateFormat.parse(endDateStr);
             } catch (ParseException e) {
             } catch (ParseException e) {
                 e.printStackTrace();
                 e.printStackTrace();
             }
             }
 
 
             for (Advertiser advertiser : advertiserList) {
             for (Advertiser advertiser : advertiserList) {
-                Date endODate = DateUtils.addDay(advertiser.getCreateTime(), 90);
-                BigDecimal totalCost = BigDecimal.ZERO;
-                if (startDate.after(endODate)) {
+                Date endOldDate = DateUtils.addDay(advertiser.getCreateTime(), 90);
+                if (startSeasonDate.after(endOldDate)) {
                     //季度开始时间大于新户结束时间(全部按照老户逻辑计算)
                     //季度开始时间大于新户结束时间(全部按照老户逻辑计算)
-                    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;
-                    }
+                    saveSalePerformanceDetail(advertiser, user, userRole, DateUtils.getYear(getDate), DateUtils.getQuarter(getDate),
+                            startDateStr, endDateStr, bytedanceFinishMediaTask, bytedanceFinishPersonnalTask, kuaishouFinishMediaTask,
+                            kuaishouFinishPersonnalTask, 0);
+                } else if (endOldDate.after(endSeasonDate)) {
+                    saveSalePerformanceDetail(advertiser, user, userRole, DateUtils.getYear(getDate), DateUtils.getQuarter(getDate),
+                            startDateStr, endDateStr, bytedanceFinishMediaTask, bytedanceFinishPersonnalTask, kuaishouFinishMediaTask,
+                            kuaishouFinishPersonnalTask, 1);
                 } else {
                 } else {
                     //新户结束时间处于本季度中间
                     //新户结束时间处于本季度中间
+                    String endduring1Date = DateUtils.formatDate(endOldDate);
+                    saveSalePerformanceDetail(advertiser, user, userRole, DateUtils.getYear(getDate), DateUtils.getQuarter(getDate),
+                            startDateStr, endduring1Date, bytedanceFinishMediaTask, bytedanceFinishPersonnalTask, kuaishouFinishMediaTask,
+                            kuaishouFinishPersonnalTask, 1);
+                    saveSalePerformanceDetail(advertiser, user, userRole, DateUtils.getYear(getDate), DateUtils.getQuarter(getDate),
+                            endduring1Date, endDateStr, bytedanceFinishMediaTask, bytedanceFinishPersonnalTask, kuaishouFinishMediaTask,
+                            kuaishouFinishPersonnalTask, 0);
+                }
+            }
+        }
+    }
 
 
+    public static final BigDecimal BYTEDANCE_MEDIA_TASK_COST = new BigDecimal("200000000");
+    public static final BigDecimal KUAISHOU_MEDIA_TASK_COST = new BigDecimal("200000000");
+    public static final BigDecimal BYTEDANCE_PERSONAL_TASK_COST = new BigDecimal("2400000");
+    public static final BigDecimal KUAISHOU_PERSONAL_TASK_COST = new BigDecimal("2400000");
 
 
-                }
+    private void saveSalePerformanceDetail(Advertiser advertiser, SysUser user, SysUserRole userRole, int year, int quarter, String startDate, String endDate, BigDecimal bytedanceFinishMediaTask, BigDecimal bytedanceFinishPersonnalTask, BigDecimal kuaishouFinishMediaTask, BigDecimal kuaishouFinishPersonnalTask, Integer brandNew) {
+        SalePerformanceDetail detail = new SalePerformanceDetail();
+        detail.setAdvertiserId(advertiser.getId());
+        detail.setSaleId(user.getId());
+        detail.setRoleId(userRole.getRoleId());
+        detail.setYear(year);
+        detail.setQuarter(quarter);
+        detail.setStartDate(startDate);
+        detail.setEndDate(endDate);
+        detail.setExtensionSelf(advertiser.getAdvertiserType());
+        detail.setBrandNew(brandNew);
+        if (user.getOrgCode().startsWith("A01A11A02")) {
+            detail.setMediaType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
+            BigDecimal totalCost = performanceService.getSalesSeasonTotalCostByParams(startDate, endDate, null, advertiser.getId(), CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
+            if (null == totalCost) {
+                totalCost = BigDecimal.ZERO;
+            }
+            detail.setTotalCost(totalCost);
+            detail.setMediaTask(BYTEDANCE_MEDIA_TASK_COST);
+            detail.setDoMediaTask(bytedanceFinishMediaTask);
+            detail.setPersonnalTask(BYTEDANCE_PERSONAL_TASK_COST);
+            detail.setDoPersonalTask(bytedanceFinishPersonnalTask);
+            detail.setPercent(getPercentagePercent(detail));
+            detail.setPercentage(detail.getTotalCost().multiply(detail.getPercent()).setScale(2, RoundingMode.HALF_UP));
+            salePerformanceDetailService.save(detail);
+        } else if (user.getOrgCode().startsWith("A01A11A01")) {
+            detail.setMediaType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
+            BigDecimal totalCost = performanceService.getSalesSeasonTotalCostByParams(startDate, endDate, null, advertiser.getId(), CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
+            if (null == totalCost) {
+                totalCost = BigDecimal.ZERO;
             }
             }
+            detail.setTotalCost(totalCost);
+            detail.setMediaTask(KUAISHOU_MEDIA_TASK_COST);
+            detail.setDoMediaTask(kuaishouFinishMediaTask);
+            detail.setPersonnalTask(KUAISHOU_PERSONAL_TASK_COST);
+            detail.setDoPersonalTask(kuaishouFinishPersonnalTask);
+            //提成比例
+            detail.setPercent(getPercentagePercent(detail));
+            detail.setPercentage(detail.getTotalCost().multiply(detail.getPercent()).setScale(2, RoundingMode.HALF_UP));
+            salePerformanceDetailService.save(detail);
+        } else {
+            return;
         }
         }
     }
     }
 
 
-    private void saveSalePerformanceDetail() {
+    //TODO 提成比例
+    private BigDecimal getPercentagePercent(SalePerformanceDetail detail) {
+        BigDecimal percent = detail.getDoMediaTask().divide(detail.getMediaTask()).multiply(new BigDecimal("100"));
+        //AM非自拓客户
+        if (detail.getRoleId().equals("f5a68aa2acf86e842100f0fa4b050d28") && detail.getExtensionSelf() != 1) {
+            return new BigDecimal("0.0005");
+        }
+        if (detail.getMediaType().equals(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE)) {
+            //头条
+            if (detail.getBrandNew() == 0) {
+                return new BigDecimal("0.001");
+            }
+            if (percent.compareTo(new BigDecimal("100")) >= 0) {
+                return new BigDecimal("0.003");
+            } else if (percent.compareTo(new BigDecimal("80")) >= 0) {
+                return new BigDecimal("0.0025");
+            } else if (percent.compareTo(new BigDecimal("60")) >= 0) {
+                return new BigDecimal("0.002");
+            } else {
+                return BigDecimal.ZERO;
+            }
+        } else {
+            //快手
+            if (detail.getBrandNew() == 1) {
+                if (percent.compareTo(new BigDecimal("100")) >= 0) {
+                    return new BigDecimal("0.005");
+                } else if (percent.compareTo(new BigDecimal("80")) >= 0) {
+                    return new BigDecimal("0.004");
+                } else if (percent.compareTo(new BigDecimal("60")) >= 0) {
+                    return new BigDecimal("0.003");
+                } else {
+                    return BigDecimal.ZERO;
+                }
+            }
+            //自拓
+            if (detail.getExtensionSelf() == 1) {
+                return new BigDecimal("0.0015");
+            } else {
+                return new BigDecimal("0.001");
+            }
 
 
+        }
     }
     }
 
 
     @Autowired
     @Autowired

+ 27 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/vo/SheetInfoVo.java

@@ -0,0 +1,27 @@
+package org.jeecg.modules.ctop.vo;
+
+import java.util.List;
+
+/**
+ * @author 宋英豪
+ */
+public class SheetInfoVo {
+    private String sheetName;
+    List<Object> details;
+
+    public List<Object> getDetails() {
+        return details;
+    }
+
+    public void setDetails(List<Object> details) {
+        this.details = details;
+    }
+
+    public String getSheetName() {
+        return sheetName;
+    }
+
+    public void setSheetName(String sheetName) {
+        this.sheetName = sheetName;
+    }
+}

+ 110 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/excelutil/entity/KuaishouXxlEntity.java

@@ -0,0 +1,110 @@
+package org.jeecg.modules.excelutil.entity;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.metadata.BaseRowModel;
+
+import java.math.BigDecimal;
+
+/**
+ * @author 宋英豪
+ */
+public class KuaishouXxlEntity extends BaseRowModel {
+    /**
+     * 日期
+     */
+    @ExcelProperty(index = 1, value = "日期")
+    private String date;
+    /**
+     * 总花费
+     */
+    @ExcelProperty(index = 2, value = "总花费(元)")
+    private BigDecimal cost;
+    /**
+     * 双出价
+     */
+    @ExcelProperty(index = 3, value = "双出价(元)")
+    private BigDecimal doubleBid;
+    /**
+     * 非双出价
+     */
+    @ExcelProperty(index = 4, value = "非双出价(元)")
+    private BigDecimal singleBid;
+    /**
+     * 激活数
+     */
+    @ExcelProperty(index = 5, value = "激活数")
+    private int active;
+    /**
+     * 激活成本
+     */
+    @ExcelProperty(index = 6, value = "激活成本")
+    private int activeCost;
+    @ExcelProperty(index = 7, value = "每日计划(组)")
+    private int planNum;
+    @ExcelProperty(index = 8, value = "每日素材安排")
+    private String mat;
+
+    public String getDate() {
+        return date;
+    }
+
+    public void setDate(String date) {
+        this.date = date;
+    }
+
+    public BigDecimal getCost() {
+        return cost;
+    }
+
+    public void setCost(BigDecimal cost) {
+        this.cost = cost;
+    }
+
+    public BigDecimal getDoubleBid() {
+        return doubleBid;
+    }
+
+    public void setDoubleBid(BigDecimal doubleBid) {
+        this.doubleBid = doubleBid;
+    }
+
+    public BigDecimal getSingleBid() {
+        return singleBid;
+    }
+
+    public void setSingleBid(BigDecimal singleBid) {
+        this.singleBid = singleBid;
+    }
+
+    public int getActive() {
+        return active;
+    }
+
+    public void setActive(int active) {
+        this.active = active;
+    }
+
+    public int getActiveCost() {
+        return activeCost;
+    }
+
+    public void setActiveCost(int activeCost) {
+        this.activeCost = activeCost;
+    }
+
+    public int getPlanNum() {
+        return planNum;
+    }
+
+    public void setPlanNum(int planNum) {
+        this.planNum = planNum;
+    }
+
+    public String getMat() {
+        return mat;
+    }
+
+    public void setMat(String mat) {
+        this.mat = mat;
+    }
+}

+ 4 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java

@@ -277,9 +277,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
 
 
     @Override
     @Override
     public List<SysUser> getUserListByRoleId(String roleId) {
     public List<SysUser> getUserListByRoleId(String roleId) {
-        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("role_id", roleId);
-        return this.list(queryWrapper);
+        Page<SysUser> page = new Page<>();
+        page.setSize(10000);
+        IPage<SysUser> userPage = this.getUserByRoleId(page, roleId, null);
+        return userPage.getRecords();
     }
     }
 
 
 
 

+ 8 - 0
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -15,6 +15,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.modules.ctop.service.IPerformanceAreaService;
 import org.junit.Test;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -235,6 +236,13 @@ public class SampleTest {
     @Autowired
     @Autowired
     private IKuaiShouCreativeService creativeService;
     private IKuaiShouCreativeService creativeService;
 
 
+    @Test
+    public void testSalePerformance() {
+        performanceAreaService.loadSalsePerformance();
+    }
+
+    @Autowired
+    private IPerformanceAreaService performanceAreaService;
 
 
 
 
     @Test
     @Test

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

@@ -274,9 +274,9 @@
         FROM
         FROM
             ctop_bytedance_report_advertiser_daily
             ctop_bytedance_report_advertiser_daily
         WHERE
         WHERE
-            stat_date &gt;= #{startDate}
+            stat_datetime &gt;= #{startDate}
         AND
         AND
-            stat_date &lt; #{endDate}
+            stat_datetime &lt; #{endDate}
     </select>
     </select>
     <select id="getKuaishouSeasonTotalCost" resultType="java.math.BigDecimal">
     <select id="getKuaishouSeasonTotalCost" resultType="java.math.BigDecimal">
         SELECT
         SELECT
@@ -332,7 +332,7 @@
     </select>
     </select>
     <select id="getBytedanceSalesSeasonTotalCostByParams" resultType="java.math.BigDecimal">
     <select id="getBytedanceSalesSeasonTotalCostByParams" resultType="java.math.BigDecimal">
         SELECT
         SELECT
-        SUM(charge)
+        SUM(daily.cost)
         FROM
         FROM
         ctop_bytedance_report_advertiser_daily daily
         ctop_bytedance_report_advertiser_daily daily
         LEFT JOIN
         LEFT JOIN

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

@@ -165,30 +165,56 @@ public class PerformanceServiceImpl extends ServiceImpl<PerformanceMapper, Perfo
 
 
     @Override
     @Override
     public BigDecimal getBytedanceSeasonTotalCost(String startDate, String endDate) {
     public BigDecimal getBytedanceSeasonTotalCost(String startDate, String endDate) {
-        return performanceMapper.getBytedanceSeasonTotalCost(startDate, endDate);
+        BigDecimal cost = performanceMapper.getBytedanceSeasonTotalCost(startDate, endDate);
+        if (null == cost) {
+            return BigDecimal.ZERO;
+        } else {
+            return cost;
+        }
     }
     }
 
 
     @Override
     @Override
     public BigDecimal getKuaishouSeasonTotalCost(String startDate, String endDate) {
     public BigDecimal getKuaishouSeasonTotalCost(String startDate, String endDate) {
-        return performanceMapper.getKuaishouSeasonTotalCost(startDate, endDate);
+        BigDecimal cost = performanceMapper.getKuaishouSeasonTotalCost(startDate, endDate);
+        if (null == cost) {
+            return BigDecimal.ZERO;
+        } else {
+            return cost;
+        }
     }
     }
 
 
     @Override
     @Override
     public BigDecimal getKuaishouSalesSeasonTotalCostByParams(String startDate, String endDate, String salesId, String advertiserId) {
     public BigDecimal getKuaishouSalesSeasonTotalCostByParams(String startDate, String endDate, String salesId, String advertiserId) {
-        return performanceMapper.getKuaishouSalesSeasonTotalCostByParams(startDate, endDate, salesId, advertiserId);
+        BigDecimal cost = performanceMapper.getKuaishouSalesSeasonTotalCostByParams(startDate, endDate, salesId, advertiserId);
+        if (null == cost) {
+            return BigDecimal.ZERO;
+        } else {
+            return cost;
+        }
     }
     }
 
 
     @Override
     @Override
     public BigDecimal getBytedanceSalesSeasonTotalCostByParams(String startDate, String endDate, String salesId, String advertiserId) {
     public BigDecimal getBytedanceSalesSeasonTotalCostByParams(String startDate, String endDate, String salesId, String advertiserId) {
-        return performanceMapper.getBytedanceSalesSeasonTotalCostByParams(startDate, endDate, salesId, advertiserId);
+        BigDecimal cost = performanceMapper.getBytedanceSalesSeasonTotalCostByParams(startDate, endDate, salesId, advertiserId);
+        if (null == cost) {
+            return BigDecimal.ZERO;
+        } else {
+            return cost;
+        }
     }
     }
 
 
     @Override
     @Override
     public BigDecimal getSalesSeasonTotalCostByParams(String startDate, String endDate, String saledId, String advertiserId, String mediaType) {
     public BigDecimal getSalesSeasonTotalCostByParams(String startDate, String endDate, String saledId, String advertiserId, String mediaType) {
+        BigDecimal cost;
         if (null != mediaType && mediaType.equals(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE)) {
         if (null != mediaType && mediaType.equals(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE)) {
-            return performanceMapper.getKuaishouSalesSeasonTotalCostByParams(startDate, endDate, saledId, advertiserId);
+            cost = performanceMapper.getKuaishouSalesSeasonTotalCostByParams(startDate, endDate, saledId, advertiserId);
+        } else {
+            cost = performanceMapper.getBytedanceSalesSeasonTotalCostByParams(startDate, endDate, saledId, advertiserId);
+        }
+        if (null == cost) {
+            return BigDecimal.ZERO;
         } else {
         } else {
-            return performanceMapper.getBytedanceSalesSeasonTotalCostByParams(startDate, endDate, saledId, advertiserId);
+            return cost;
         }
         }
     }
     }