Browse Source

Merge remote-tracking branch 'origin/test' into test

yumeng 5 years ago
parent
commit
0188df57ca
14 changed files with 505 additions and 98 deletions
  1. 5 5
      jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java
  2. 6 4
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/EffiVideoJob.java
  3. 4 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/LoginController.java
  4. 107 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/PerformanceController2.java
  5. 1 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/entity/EffiRateComparator.java
  6. 1 12
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/entity/UserDto.java
  7. 2 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/SysRoleMapper.java
  8. 15 4
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/xml/SysRoleMapper.xml
  9. 0 15
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/IPerformanceService.java
  10. 31 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/IPerformanceService2.java
  11. 215 36
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/PerformanceServiceImpl.java
  12. 32 0
      performance-appraisal/src/main/java/cn/com/ctop/userefficientvideomap/entity/DesignMaterialInfo.java
  13. 18 14
      performance-appraisal/src/main/java/cn/com/ctop/userefficientvideomap/mapper/UserEfficientVideoMapMapper.java
  14. 68 7
      performance-appraisal/src/main/java/cn/com/ctop/userefficientvideomap/mapper/xml/UserEfficientVideoMapMapper.xml

+ 5 - 5
jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java

@@ -76,11 +76,11 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/appium/crawler/startJob", "anon");
 
 		//优化师相关
-		filterChainDefinitionMap.put("/ctop/performanceOptimizer/detail", "anon");
-		filterChainDefinitionMap.put("/ctop/performanceOptimizer/ranking/list", "anon");
-		filterChainDefinitionMap.put("/ctop/performance/project/list", "anon");
-		filterChainDefinitionMap.put("/ctop/performance/account/list", "anon");
-		filterChainDefinitionMap.put("/ctop/optimizerRoleInfo/manager/detail", "anon");
+		//filterChainDefinitionMap.put("/ctop/performanceOptimizer/detail", "anon");
+		//filterChainDefinitionMap.put("/ctop/performanceOptimizer/ranking/list", "anon");
+		//filterChainDefinitionMap.put("/ctop/performance/project/list", "anon");
+		//filterChainDefinitionMap.put("/ctop/performance/account/list", "anon");
+		//filterChainDefinitionMap.put("/ctop/optimizerRoleInfo/manager/detail", "anon");
 
 
         filterChainDefinitionMap.put("/generic/**", "anon");

+ 6 - 4
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/EffiVideoJob.java

@@ -1,13 +1,15 @@
 package org.jeecg.modules.ctop.job;
 
 
+import org.jeecg.modules.system.service.IPerformanceService2;
 import org.quartz.Job;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
 
 public class EffiVideoJob implements Job {
-  /*  @Autowired
-    private IPerformanceService performanceService;*/
+    @Autowired
+    private IPerformanceService2 performanceService;
 
     /**
      * 获取有效视频以及对应人的定时任务
@@ -17,7 +19,7 @@ public class EffiVideoJob implements Job {
      */
     @Override
     public void execute(JobExecutionContext jobExecutionContext) {
-      /*  performanceService.efficientVideoTask(2);
-        performanceService.efficientVideoTask(1);*/
+        performanceService.efficientVideoTask(2);
+        performanceService.efficientVideoTask(1);
     }
 }

+ 4 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/LoginController.java

@@ -91,6 +91,10 @@ public class LoginController {
                     result.error500("该用户未注册系统账户,请联系管理员");
                     return result;
                 }
+                if(sysUser.getStatus() != 1){
+                    result.error500("该用户已冻结,请联系管理员");
+                    return result;
+                }
                 String departId = sysDepartService.selectIdByOrdCode(sysUser.getOrgCode());
                 sysUser.setDepartId(departId);
                 result = sysUserService.checkUserIsEffective(sysUser);

+ 107 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/PerformanceController2.java

@@ -0,0 +1,107 @@
+package org.jeecg.modules.system.controller;
+
+import cn.com.ctop.crawler.modules.account.entity.KuaishouAppAccount;
+import cn.com.ctop.userefficientvideomap.entity.DesignMaterialInfo;
+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.modules.system.service.IPerformanceService2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 设计师季度绩效表2
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2019-12-10
+ */
+@Slf4j
+@Api(tags = "设计师季度绩效表2")
+@RestController
+@RequestMapping("/ctop/performance2")
+public class PerformanceController2 {
+    @Autowired
+    private IPerformanceService2 performanceService;
+
+    //平台的总有效数量、素材总数、素材有效率、总跑量、当前可获得绩效
+    @AutoLog(value = "平台的总有效数量、素材总数、素材有效率、总跑量、当前可获得绩效")
+    @ApiOperation(value = "平台的总有效数量、素材总数、素材有效率、总跑量、当前可获得绩效", notes = "平台的总有效数量、素材总数、素材有效率、总跑量、当前可获得绩效")
+    @PostMapping(value = "/getPerformanceInfo")
+    public Result<Map<String,Object>> getPerformanceInfo() {
+        Result<Map<String,Object>> result = new Result<Map<String,Object>>();
+        Map<String,Object> resultMap = new HashMap<>();
+        try {
+            resultMap = performanceService.getPerformanceInfo();
+            result.setSuccess(true);
+            result.setResult(resultMap);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("/getPerformanceInfo出错啦");
+        }
+        return result;
+    }
+
+    //有效率排行榜
+    @AutoLog(value = "有效率排行榜")
+    @ApiOperation(value = "有效率排行榜", notes = "有效率排行榜")
+    @PostMapping(value = "/effiRateRank")
+    public Result<Map<String,Object>> effiRateRank(@RequestParam(name = "pageSize")Integer pageSize) {
+        Result<Map<String,Object>> result = new Result<Map<String,Object>>();
+        Map<String,Object> resultMap = new HashMap<>();
+        try {
+            resultMap = performanceService.effiRateRank(pageSize);
+            result.setSuccess(true);
+            result.setResult(resultMap);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("/ctop/performance2/effiRateRank出错啦");
+        }
+        return result;
+    }
+
+    //素材、素材跑量、封面点击数、封面曝光数、行为数
+    @AutoLog(value = "素材、素材跑量、封面点击数、封面曝光数、行为数")
+    @ApiOperation(value = "素材、素材跑量、封面点击数、封面曝光数、行为数", notes = "素材、素材跑量、封面点击数、封面曝光数、行为数")
+    @PostMapping(value = "/materialInfoList")
+    public Result<Map<String,Object>> materialInfoList() {
+        Result<Map<String,Object>> result = new Result<Map<String,Object>>();
+        Map<String,Object> resultMap = new HashMap<>();
+        try {
+            List<DesignMaterialInfo> designMaterialInfoList= performanceService.materialInfoList();
+            resultMap.put("designMaterialInfoList",designMaterialInfoList);
+            result.setSuccess(true);
+            result.setResult(resultMap);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("/ctop/performance2/materialInfoList出错啦");
+        }
+        return result;
+    }
+
+    //点击+符号 投放账户、投放账户、跑量
+    @AutoLog(value = "点击账户增加_投放账户、投放账户、跑量")
+    @ApiOperation(value = "点击账户增加_投放账户、投放账户、跑量", notes = "点击账户增加_投放账户、投放账户、跑量")
+    @PostMapping(value = "/materialAccountInfo")
+    public Result<Map<String,Object>> materialAccountInfo(@RequestParam(name = "materialId")String materialId) {
+        Result<Map<String,Object>> result = new Result<Map<String,Object>>();
+        Map<String,Object> resultMap = new HashMap<>();
+        try {
+            List<DesignMaterialInfo> designMaterialInfoList= performanceService.materialAccountInfo(materialId);
+            resultMap.put("designMaterialInfoList",designMaterialInfoList);
+            result.setSuccess(true);
+            result.setResult(resultMap);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("/ctop/performance2/materialAccountInfo出错啦");
+        }
+        return result;
+    }
+
+}

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/entity/EffiRateComparator.java

@@ -20,6 +20,6 @@ public class EffiRateComparator implements Comparator<Object> {
     public int compare(Object o1, Object o2) {
         UserDto p1 = (UserDto) o1; // 强制转换
         UserDto p2 = (UserDto) o2;
-        return (p1.getEffiRate()).compareTo(p2.getEffiRate());
+        return (p2.getEffiRate()).compareTo(p1.getEffiRate());
     }
 }

+ 1 - 12
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/entity/UserDto.java

@@ -14,7 +14,7 @@ public class UserDto implements Serializable {
 
     private String userId;
 
-    private String username;
+    private String realname;
 
     private String roleId;
 
@@ -22,15 +22,4 @@ public class UserDto implements Serializable {
 
     private BigDecimal effiRate;
 
-    //public int compareTo(Object obj) {// Comparable接口中的方法
-    //    UserDto b = (UserDto) obj;
-    //   return this.effiRate.compareTo(b.getEffiRate()); //比较大小,用于默认排序
-    //}
-
-    //@Override
-    //public int compare(Object o1, Object o2) {
-    //    UserDto p1 = (UserDto) o1; // 强制转换
-    //    UserDto p2 = (UserDto) o2;
-    //    return (p1.getEffiRate()).compareTo(p2.getEffiRate());
-    //}
 }

+ 2 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/SysRoleMapper.java

@@ -23,4 +23,6 @@ public interface SysRoleMapper extends BaseMapper<SysRole> {
 
     String getRoleIdByRoleCode(@Param("roleCode")String roleCode);
 
+    String getRoleCodeByUserId(@Param("userId")String userId);
+
 }

+ 15 - 4
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/xml/SysRoleMapper.xml

@@ -6,13 +6,13 @@
 	<select id="getUserByRoleCode" resultType="org.jeecg.modules.system.entity.UserDto">
 			select
 			a.id as userId,
-			b.realname,
-			c.id as roleIdd,
+			a.realname,
+			c.id as roleId,
 			c.role_name
 		from
 		sys_user a
-		left join on sys_user_role b on a.id = b.user_id
-		left join sys_role c int not null on b.role_id = c.id
+		left join sys_user_role b on a.id = b.user_id
+		left join sys_role c on b.role_id = c.id
         where
         c.role_code = #{roleCode}
 	</select>
@@ -25,5 +25,16 @@
 		where role_code = #{roleCode}
 	</select>
 
+	<!-- 根据userId获取角色code -->
+	<select id="getRoleCodeByUserId" resultType="java.lang.String">
+		select
+		c.role_code
+		from
+		sys_user a
+		left join sys_user_role b on a.id = b.user_id
+		left join sys_role c on b.role_id = c.id
+        where
+        a.id = #{userId}
+	</select>
 
 </mapper>

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

@@ -1,15 +0,0 @@
-package org.jeecg.modules.system.service;
-
-import cn.com.ctop.performanceappraisal.entity.Performance;
-import com.baomidou.mybatisplus.extension.service.IService;
-
-/**
- * 设计师季度绩效表
- *
- * @author jeecg-boot
- * @version V1.0
- * @date 2019-12-10
- */
-public interface IPerformanceService extends IService<Performance> {
-   //  void efficientVideoTask(int days);
-}

+ 31 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/IPerformanceService2.java

@@ -0,0 +1,31 @@
+package org.jeecg.modules.system.service;
+
+import cn.com.ctop.performanceappraisal.entity.Performance;
+import cn.com.ctop.userefficientvideomap.entity.DesignMaterialInfo;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 设计师季度绩效表
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2019-12-10
+ */
+public interface IPerformanceService2 extends IService<Performance> {
+    void efficientVideoTask(int days);
+
+    //平台的总有效数量、素材总数、素材有效率、总跑量、当前可获得绩效
+    public Map<String,Object> getPerformanceInfo();
+
+    //有效率排行榜
+    public Map<String,Object> effiRateRank(Integer size);
+
+    //素材、素材跑量、封面点击数、封面曝光数、行为数
+    public List<DesignMaterialInfo> materialInfoList();
+
+    //点击+符号 投放账户、投放账户、跑量
+    public List<DesignMaterialInfo> materialAccountInfo(String materialInfoId);
+}

+ 215 - 36
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/PerformanceServiceImpl.java

@@ -1,4 +1,3 @@
-/*
 package org.jeecg.modules.system.service.impl;
 
 import cn.com.ctop.performanceappraisal.entity.OptimizerConfig;
@@ -6,37 +5,37 @@ import cn.com.ctop.performanceappraisal.entity.Performance;
 import cn.com.ctop.performanceappraisal.mapper.PerformanceMapper;
 import cn.com.ctop.performanceappraisal.service.IOptimizerConfigService;
 import cn.com.ctop.performanceappraisal.vo.OptimizerCostDetailVO;
+import cn.com.ctop.userefficientvideomap.entity.DesignMaterialInfo;
 import cn.com.ctop.userefficientvideomap.entity.EffiVideoDTO;
 import cn.com.ctop.userefficientvideomap.entity.ProjectDTO;
 import cn.com.ctop.userefficientvideomap.entity.UserEfficientVideoMap;
 import cn.com.ctop.userefficientvideomap.mapper.UserEfficientVideoMapMapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import org.apache.commons.io.filefilter.FalseFileFilter;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.modules.system.entity.EffiRateComparator;
 import org.jeecg.modules.system.entity.UserDto;
 import org.jeecg.modules.system.mapper.SysRoleMapper;
-import org.jeecg.modules.system.service.IPerformanceService;
+import org.jeecg.modules.system.service.IPerformanceService2;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.text.ParseException;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
-*/
 /**
  * 设计师季度绩效表
  *
  * @author jeecg-boot
  * @version V1.0
  * @date 2019-12-10
- *//*
-
+ */
+@Slf4j
 @Service
-public class PerformanceServiceImpl extends ServiceImpl<PerformanceMapper, Performance> implements IPerformanceService {
+public class PerformanceServiceImpl2 extends ServiceImpl<PerformanceMapper, Performance> implements IPerformanceService2 {
 
     @Autowired
     private PerformanceMapper performanceMapper;
@@ -130,8 +129,7 @@ public class PerformanceServiceImpl extends ServiceImpl<PerformanceMapper, Perfo
         }
     }
 
-    */
-/**
+    /**
      * 分平台:快手、抖音
      *
      * 编导、剪辑、拍摄:
@@ -151,8 +149,7 @@ public class PerformanceServiceImpl extends ServiceImpl<PerformanceMapper, Perfo
      * 2.查询出所有设计部门的代码,并找出每部门的leader,和部门下所有人员
      * 3.根据编导(或剪辑、拍摄)算出素材的总消耗
      * 4.根据部门当中是否有平面设计师来判断提成绩效。有平面,按照15%计算;没有按照20%计算
-     *//*
-
+     */
     //季度定时任务(在有效视频绑定人定时任务之后跑):设计师绩效计算-----包括快手和头条的计算逻辑
     public void designerPerformanceTask(){
         kuaishouDesigner();//快手
@@ -200,7 +197,7 @@ public class PerformanceServiceImpl extends ServiceImpl<PerformanceMapper, Perfo
             //有效视频数量
             int effiVideoCount = userEfficientVideoMapMapper.getEffiVideoCountByUserId(Integer.parseInt(thisYear),thisQuarter,userDto.getUserId());
             //总视频数量
-            int videoCount = userEfficientVideoMapMapper.getQuarterMaterialCountByUserId(startTime, endTime, userDto.getUserId());
+            int videoCount = userEfficientVideoMapMapper.getQuarterMaterialCountByUserId("plan",startTime, endTime, userDto.getUserId());
             //视频有效率
             BigDecimal effiRate = new BigDecimal( String.valueOf(effiVideoCount) ).divide( new BigDecimal(String.valueOf(videoCount)) );
             userDto.setEffiRate(effiRate);
@@ -266,7 +263,7 @@ public class PerformanceServiceImpl extends ServiceImpl<PerformanceMapper, Perfo
             //有效视频数量
             int effiVideoCount = userEfficientVideoMapMapper.getEffiVideoCountByUserId(Integer.parseInt(thisYear),thisQuarter,userDto.getUserId());
             //总视频数量
-            int videoCount = userEfficientVideoMapMapper.getQuarterMaterialCountByUserId(startTime, endTime, userDto.getUserId());
+            int videoCount = userEfficientVideoMapMapper.getQuarterMaterialCountByUserId("shot",startTime, endTime, userDto.getUserId());
             //视频有效率
             BigDecimal effiRate = new BigDecimal( String.valueOf(effiVideoCount) ).divide( new BigDecimal(String.valueOf(videoCount)) );
             userDto.setEffiRate(effiRate);
@@ -332,7 +329,7 @@ public class PerformanceServiceImpl extends ServiceImpl<PerformanceMapper, Perfo
             //有效视频数量
             int effiVideoCount = userEfficientVideoMapMapper.getEffiVideoCountByUserId(Integer.parseInt(thisYear),thisQuarter,userDto.getUserId());
             //总视频数量
-            int videoCount = userEfficientVideoMapMapper.getQuarterMaterialCountByUserId(startTime, endTime, userDto.getUserId());
+            int videoCount = userEfficientVideoMapMapper.getQuarterMaterialCountByUserId("clip",startTime, endTime, userDto.getUserId());
             //视频有效率
             BigDecimal effiRate = new BigDecimal( String.valueOf(effiVideoCount) ).divide( new BigDecimal(String.valueOf(videoCount)) );
             userDto.setEffiRate(effiRate);
@@ -431,7 +428,7 @@ public class PerformanceServiceImpl extends ServiceImpl<PerformanceMapper, Perfo
         }
         ///////////////////////////////////////////////////////////////////平面end
 
-        //设计师leader start
+        //TODO 设计师leader start
         //* 1.如果媒体总任务未达成,则没有绩效;如果已达成,则按照千分之5给予提点绩效
         //* 2.查询出所有设计部门的代码,并找出每部门的leader,和部门下所有人员
         //* 3.根据编导(或剪辑、拍摄)算出素材的总消耗
@@ -439,18 +436,6 @@ public class PerformanceServiceImpl extends ServiceImpl<PerformanceMapper, Perfo
 
         //判断媒体任务是否达成,如果未达成,则没有绩效
         if(mediaMission()){
-
-
-
-
-
-
-
-
-
-
-
-
         }else{
             return;
         }
@@ -507,36 +492,230 @@ public class PerformanceServiceImpl extends ServiceImpl<PerformanceMapper, Perfo
         Date getDate = DateUtils.addDay(date, -1);
         String startDate = DateUtils.getQuarterStartDate(getDate);
         String endDate = DateUtils.getQuarterEndDate(getDate);
+        String endNowDate = DateUtils.formatDate(getDate);
         String year = DateUtils.getYear(getDate) + "";
         String quarter = DateUtils.getQuarter(getDate) + "";
-        return performanceMapper.getOptimizerTotalCost(startDate, endDate, year, quarter);
+        return performanceMapper.getOptimizerTotalCost(startDate, endNowDate, year, quarter);
     }
 
+    //1
+    //季度到前一天为止个人的有效数量、素材总数、素材有效率、总跑量
+    //{"effiVideoCount有效数":70,"videoCount素材总数":200,"effiRate":40,"cost":2019;performance绩效":20000}
+    public Map<String,Object> getPerformanceInfo(){
+        Map<String,Object> performanceInfoMap = new HashMap<>();
+        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        //LoginUser sysUser = new LoginUser();
+        //sysUser.setId("9712328fddd1443faf566ddb87693658");
 
+        //获取前一天的时间
+        Date date = new Date();
+        Date getDate = DateUtils.addDay(date, -1);
+        String startDate = DateUtils.getQuarterStartDate(getDate);
+        String endDate = DateUtils.getQuarterEndDate(getDate);
+        String endNowDate = DateUtils.formatDate(getDate);
 
-    //TODO 平台的总有效数量、素材总数、素材有效率、总跑量、当前可获得绩效
-    public void getPerformanceInfo(){
-        //获取平台的总有效数量
-    }
+        String roleCode = sysRoleMapper.getRoleCodeByUserId(sysUser.getId());
 
+        log.info(roleCode + ":" + sysUser.getRealname() + "getPerformanceInfo接口开始");
 
+        Map<String,String> lastDateMap = getLastDateInfo();
+        //获取本人的视频总有效数量
+        int effiVideoCount = userEfficientVideoMapMapper.getEffiVideoCountByUserId(Integer.parseInt(lastDateMap.get("year")), Integer.parseInt(lastDateMap.get("quarter")),sysUser.getId());
+        //获取本人的视频总数
+        int videoCount = userEfficientVideoMapMapper.getQuarterMaterialCountByUserId(roleCode, startDate,endNowDate,sysUser.getId());
+        //获取本人目前的视频有效率
+        BigDecimal videoEffiRate = BigDecimal.ZERO;
+        if(effiVideoCount != 0 && videoCount != 0){
+            videoEffiRate = new BigDecimal(String.valueOf(effiVideoCount)).divide(new BigDecimal(String.valueOf(videoCount))).multiply(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP);
+        }
+        //获取本人的总跑量
+        BigDecimal cost = BigDecimal.ZERO;
+
+        if(roleCode.equals("plan") ){
+            cost = userEfficientVideoMapMapper.getTotalCostByPlanId(sysUser.getId(), startDate, endDate);
+        }else if(roleCode.equals("shot") ){
+            cost = userEfficientVideoMapMapper.getTotalCostByShotId(sysUser.getId(), startDate, endDate);
+        }else if(roleCode.equals("clip") ){
+            cost = userEfficientVideoMapMapper.getTotalCostByClipId(sysUser.getId(), startDate, endDate);
+        }
 
+        performanceInfoMap.put("effiVideoCount",effiVideoCount);
+        performanceInfoMap.put("videoCount",videoCount);
+        performanceInfoMap.put("effiRate",videoEffiRate);
+        performanceInfoMap.put("cost",cost);
 
+        log.info(roleCode + ":" + sysUser.getRealname() + "getPerformanceInfo接口开始");
+        return performanceInfoMap;
+    }
+
+    //2
+    //有效率排行榜
+    //{"list":[{"name":"pipi","effiRate":50},{"name":"pipixia","effiRate":40},{"name":"pipiqiu","effiRate":30}],"performance":performance}
+    public Map<String,Object> effiRateRank(Integer size){
+        Map<String,Object> resultMap = new HashMap<>();
+        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        //LoginUser sysUser = new LoginUser();
+        //sysUser.setId("9712328fddd1443faf566ddb87693658");
+
+        //获取前一天的时间
+        Date date = new Date();
+        Date getDate = DateUtils.addDay(date, -1);
+        String startDate = DateUtils.getQuarterStartDate(getDate);
+        String endDate = DateUtils.getQuarterEndDate(getDate);
+        String endNowDate = DateUtils.formatDate(getDate);
+        Map<String,String> lastDateMap = getLastDateInfo();
+        String roleCode = sysRoleMapper.getRoleCodeByUserId(sysUser.getId());
+
+        log.info(roleCode + ":" + sysUser.getRealname() + "有效率排行榜接口开始");
+
+        List<UserDto> userRoleList = new ArrayList<>();
+        BigDecimal rate = BigDecimal.ZERO; //提成比例
+        if(roleCode.equals("plan")){
+            userRoleList = sysRoleMapper.getUserByRoleCode("plan"); //编导
+            rate = new BigDecimal("0.4");
+        }else if(roleCode.equals("shot")){
+            userRoleList = sysRoleMapper.getUserByRoleCode("shot"); //拍摄
+            rate = new BigDecimal("0.1");
+        }else if(roleCode.equals("clip")){
+            userRoleList = sysRoleMapper.getUserByRoleCode("clip"); //剪辑
+            rate = new BigDecimal("0.3");
+        }
 
+        if (userRoleList != null) {
+            for (UserDto userDto : userRoleList) {
+                //有效视频数量
+                int effiVideoCount = userEfficientVideoMapMapper.getEffiVideoCountByUserId(Integer.parseInt(lastDateMap.get("year")), Integer.parseInt(lastDateMap.get("quarter")), userDto.getUserId());
+                //总视频数量
+                int videoCount = userEfficientVideoMapMapper.getQuarterMaterialCountByUserId(roleCode, startDate, endNowDate, userDto.getUserId());
+                //视频有效率
+                BigDecimal effiRate = BigDecimal.ZERO;
+                if(effiVideoCount!=0 && videoCount!=0){
+                    effiRate = new BigDecimal(String.valueOf(effiVideoCount)).divide(new BigDecimal(String.valueOf(videoCount))).multiply(new BigDecimal("100")).setScale(2,BigDecimal.ROUND_HALF_UP);
+                }
+                userDto.setEffiRate(effiRate);
+            }
+            Collections.sort(userRoleList, new EffiRateComparator());
+
+            //获取剪辑人数并按照提点比例计算每个梯度的人数
+            int userRoleLength = userRoleList.size();
+            //获取前30%和中间50%的人数(视频有效率四舍五入)
+            int userTopSize = new BigDecimal(String.valueOf(userRoleLength)).multiply(new BigDecimal("0.3")).setScale(0,BigDecimal.ROUND_HALF_UP).intValue();
+            int userMiddleSize = new BigDecimal(String.valueOf(userRoleLength)).multiply(new BigDecimal("0.5")).setScale(0,BigDecimal.ROUND_HALF_UP).intValue();
+            log.info(roleCode + "的总人数为:" + userRoleLength + ";前30%人数为:"+ userTopSize + ";中间50%的人数为:" + userMiddleSize);
+
+            int index = 0;
+            for(int i=0; i<= userRoleLength; i++){
+                index = index+1;
+                if(userRoleList.get(i).getUserId() .equals( sysUser.getId() )){
+                    log.info("当前登陆人userId:" + sysUser.getId() + ";姓名:" +sysUser.getRealname() + ";排名:" + index);
+                    break;
+                }
+            }
 
+            //总消耗--获取这个人素材总消耗
+            //总绩效=总消耗*提点比例(5‰)*提成比例(剪辑30%)
+            BigDecimal performance = BigDecimal.ZERO; //绩效
+            BigDecimal totalCost = BigDecimal.ZERO;  //总消耗
+            if(roleCode.equals("plan")){
+                totalCost = userEfficientVideoMapMapper.getTotalCostByPlanId(sysUser.getId(), startDate, endNowDate);
+                if(index <= userTopSize){
+                    performance = totalCost.multiply(new BigDecimal("0.005")).multiply(new BigDecimal("0.4"));
+                }else if( index >userTopSize && index <= (userTopSize + userMiddleSize) ){
+                    performance = totalCost.multiply(new BigDecimal("0.003")).multiply(new BigDecimal("0.4"));
+                }else{
+                    performance = BigDecimal.ZERO;
+                }
+            }else if(roleCode.equals("shot")){
+                totalCost = userEfficientVideoMapMapper.getTotalCostByShotId(sysUser.getId(), startDate, endNowDate);
+                if(index <= userTopSize){
+                    performance = totalCost.multiply(new BigDecimal("0.005")).multiply(new BigDecimal("0.1"));
+                }else if( index >userTopSize && index <= (userTopSize + userMiddleSize) ){
+                    performance = totalCost.multiply(new BigDecimal("0.003")).multiply(new BigDecimal("0.1"));
+                }else{
+                    performance = BigDecimal.ZERO;
+                }
+            }else{
+                totalCost = userEfficientVideoMapMapper.getTotalCostByClipId(sysUser.getId(), startDate, endNowDate);
+                if(index <= userTopSize){
+                    performance = totalCost.multiply(new BigDecimal("0.005")).multiply(new BigDecimal("0.3"));
+                }else if( index >userTopSize && index <= (userTopSize + userMiddleSize) ){
+                    performance = totalCost.multiply(new BigDecimal("0.003")).multiply(new BigDecimal("0.3"));
+                }else{
+                    performance = BigDecimal.ZERO;
+                }
+            }
 
+            //去掉list中前30的数据
+            if(size != null){
+                userRoleList.subList(size,userRoleList.size()).clear();
+            }
 
+            resultMap.put("userRoleList",userRoleList);
+            resultMap.put("performance",performance);
+        }else{
+            resultMap.put("userRoleList",null);
+            resultMap.put("performance",0);
+        }
 
+        log.info(roleCode + ":" + sysUser.getRealname() + "有效率排行榜接口结束");
+        return resultMap;
+    }
 
+    //3
+    //素材、素材跑量、封面点击数、封面曝光数、行为数
+    //{"videoUrl":"http://dadfadfadf.mp4","videoCost":34.56,"pageClickCount":1200,"pageExposureCount":3939,"behaviorCount":5000}
+    public List<DesignMaterialInfo> materialInfoList(){
+        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        //LoginUser sysUser = new LoginUser();
+        //sysUser.setId("9712328fddd1443faf566ddb87693658");
+        String roleCode = sysRoleMapper.getRoleCodeByUserId(sysUser.getId());
 
+        log.info(roleCode + ":" + sysUser.getRealname() + "materialInfoList接口开始");
 
+        Date date = new Date();
+        Date getDate = DateUtils.addDay(date, -1);
+        String startDate = DateUtils.getQuarterStartDate(getDate);
+        String endDate = DateUtils.getQuarterEndDate(getDate);
+        String endNowDate = DateUtils.formatDate(getDate);
 
+        List<DesignMaterialInfo> materialInfoList = userEfficientVideoMapMapper.designMaterialInfoList(roleCode, sysUser.getId(), startDate, endNowDate);
 
+        log.info(roleCode + ":" + sysUser.getRealname() + "materialInfoList接口结束");
+        return materialInfoList;
+    }
 
+    //4
+    //点击+符号 投放账户、投放账户、跑量
+    //{"videoAccount":"aabbcc","servingAccount":"ttyyhh","cost":34234.43}
+    public List<DesignMaterialInfo> materialAccountInfo(String materialInfoId){
+        log.info("materialAccountInfo接口开始");
+        Date date = new Date();
+        Date getDate = DateUtils.addDay(date, -1);
+        String startDate = DateUtils.getQuarterStartDate(getDate);
+        String endDate = DateUtils.getQuarterEndDate(getDate);
+        String endNowDate = DateUtils.formatDate(getDate);
 
+        List<DesignMaterialInfo> materialInfoList = userEfficientVideoMapMapper.getMaterialAccountInfoByMaterialId(materialInfoId, startDate, endNowDate);
+        log.info("materialAccountInfo接口结束");
+        return materialInfoList;
+    }
 
+    //获取前一天的年、季度信息
+    private Map<String,String> getLastDateInfo() {
+        Map<String, String> timeMap = new HashMap<String,String>();
+        Date date = new Date();
+        Date getDate = DateUtils.addDay(date, -1);
+        String startDate = DateUtils.getQuarterStartDate(getDate);
+        String endDate = DateUtils.getQuarterEndDate(getDate);
+        String year = DateUtils.getYear(getDate) + "";
+        String quarter = DateUtils.getQuarter(getDate) + "";
 
+        timeMap.put("startDate",startDate);
+        timeMap.put("endDate",endDate);
+        timeMap.put("year",year);
+        timeMap.put("quarter",quarter);
+        return timeMap;
+    }
 
 
 }
-*/

+ 32 - 0
performance-appraisal/src/main/java/cn/com/ctop/userefficientvideomap/entity/DesignMaterialInfo.java

@@ -0,0 +1,32 @@
+package cn.com.ctop.userefficientvideomap.entity;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+@Data
+public class DesignMaterialInfo implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+	private String id;
+
+	private String videoUrl;
+
+	private Integer pageExposureCount;
+
+	private Integer pageClickCount;
+
+	private Integer materialExposureCount;
+
+	private Integer behaviorCount;
+
+	private BigDecimal totalCost;
+
+	private String accountId;
+
+	private String accountName;
+
+	private String platform;
+
+}

+ 18 - 14
performance-appraisal/src/main/java/cn/com/ctop/userefficientvideomap/mapper/UserEfficientVideoMapMapper.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.userefficientvideomap.mapper;
 
+import cn.com.ctop.userefficientvideomap.entity.DesignMaterialInfo;
 import cn.com.ctop.userefficientvideomap.entity.EffiVideoDTO;
 import cn.com.ctop.userefficientvideomap.entity.ProjectDTO;
 import cn.com.ctop.userefficientvideomap.entity.UserEfficientVideoMap;
@@ -12,37 +13,40 @@ import java.util.List;
 
 /**
  * 有效视频与角色对应表
- *
  * @author: jeecg-boot
- * @date: 2019-12-16
+ * @date:   2019-12-16
  * @cersion: V1.0
  */
 @Component
 public interface UserEfficientVideoMapMapper extends BaseMapper<UserEfficientVideoMap> {
 
-    List<EffiVideoDTO> getUserVideoMap(@Param("startDate") String startDate, @Param("endDate") String endDate);
+    List<EffiVideoDTO> getUserVideoMap(@Param("startDate")String startDate, @Param("endDate")String endDate);
 
-    int getEffiVideoCountBySignature(@Param("signature") String signature);
+    int getEffiVideoCountBySignature(@Param("signature")String signature);
 
-    int getEffiVideoCountByUserId(@Param("year") int year, @Param("quarter") int quarter, @Param("userId") String userId);
+    int getEffiVideoCountByUserId(@Param("year")int year, @Param("quarter")int quarter, @Param("userId")String userId);
 
-    int getQuarterMaterialCountByUserId(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("userId") String userId);
+    int getQuarterMaterialCountByUserId(@Param("roleCode")String roleCode, @Param("startTime")String startTime, @Param("endTime")String endTime, @Param("userId")String userId);
 
-    BigDecimal getTotalCostByClipId(@Param("userId") String userId, @Param("startDate") String startDate, @Param("endDate") String endDate);
+    BigDecimal getTotalCostByClipId(@Param("userId")String userId, @Param("startDate")String startDate, @Param("endDate")String endDate);
 
-    BigDecimal getTotalCostByShotId(@Param("userId") String userId, @Param("startDate") String startDate, @Param("endDate") String endDate);
+    BigDecimal getTotalCostByShotId(@Param("userId")String userId, @Param("startDate")String startDate, @Param("endDate")String endDate);
 
-    BigDecimal getTotalCostByPlanId(@Param("userId") String userId, @Param("startDate") String startDate, @Param("endDate") String endDate);
+    BigDecimal getTotalCostByPlanId(@Param("userId")String userId, @Param("startDate")String startDate, @Param("endDate")String endDate);
 
-    BigDecimal getTotalCostByPlaneId(@Param("userId") String userId, @Param("startDate") String startDate, @Param("endDate") String endDate);
+    BigDecimal getTotalCostByPlaneId(@Param("userId")String userId, @Param("startDate")String startDate, @Param("endDate")String endDate);
 
-    BigDecimal getProjectTotalCostByUserId(@Param("userId") String userId, @Param("startDate") String startDate, @Param("endDate") String endDate);
+    BigDecimal getProjectTotalCostByUserId(@Param("userId")String userId, @Param("startDate")String startDate, @Param("endDate")String endDate);
 
-    List<ProjectDTO> getProjectsByUserId(@Param("userId") String userId);
+    List<ProjectDTO> getProjectsByUserId(@Param("userId")String userId);
 
-    int getPlaneCountByProjectId(@Param("projectId") Long projectId);
+    int getPlaneCountByProjectId(@Param("projectId")Long projectId);
 
-    int getPlaneCountByUserId(@Param("userId") String userId);
+    int getPlaneCountByUserId(@Param("userId")String userId);
+
+    List<DesignMaterialInfo> designMaterialInfoList(@Param("roleCode")String roleCode, @Param("userId")String userId, @Param("startDate")String startDate, @Param("endDate")String endDate);
+
+    List<DesignMaterialInfo> getMaterialAccountInfoByMaterialId(@Param("materialId")String materialId, @Param("startDate")String startDate, @Param("endDate")String endDate);
 
 
 }

+ 68 - 7
performance-appraisal/src/main/java/cn/com/ctop/userefficientvideomap/mapper/xml/UserEfficientVideoMapMapper.xml

@@ -52,10 +52,23 @@
     <select id="getQuarterMaterialCountByUserId" resultType="java.lang.Integer">
             select
             count(1)
-        from ctop_material_info
-        where user_id = #{userId}
-        and create_time &gt;= #{startTime}
-        and create_time &lt;= #{endTime}
+        from ctop_material_info a
+        left join ctop_material_ascription b on a.id = b.material_id
+        where date_format(a.create_time,'%Y-%m-%d') &gt;= #{startTime}
+        and date_format(a.create_time,'%Y-%m-%d') &lt;= #{endTime}
+        and
+        <choose>
+            <when test=" roleCode == 'plan' ">
+                b.plan_id = #{userId}
+            </when>
+            <when test=" roleCode == 'clip' ">
+                b.clip_id = #{userId}
+            </when>
+            <otherwise>
+                b.shot_id = #{userId}
+            </otherwise>
+        </choose>
+
     </select>
 
     <!-- 根据clip_id获取视频总消耗 -->
@@ -72,7 +85,7 @@
         where a.signature is not null and b.id is not null
         and DATE_FORMAT(b.create_time,'%Y-%m-%d') &gt;= #{startDate}
         and DATE_FORMAT(b.create_time,'%Y-%m-%d') &lt;= #{endDate}
-        where c.clip_id = #{userId}
+        and c.clip_id = #{userId}
     </select>
 
     <!-- 根据clip_id获取视频总消耗 -->
@@ -89,7 +102,7 @@
         where a.signature is not null and b.id is not null
         and DATE_FORMAT(b.create_time,'%Y-%m-%d') &gt;= #{startDate}
         and DATE_FORMAT(b.create_time,'%Y-%m-%d') &lt;= #{endDate}
-        where c.shot_id = #{userId}
+        and c.shot_id = #{userId}
     </select>
 
     <!-- 根据clip_id获取视频总消耗 -->
@@ -106,7 +119,7 @@
         where a.signature is not null and b.id is not null
         and DATE_FORMAT(b.create_time,'%Y-%m-%d') &gt;= #{startDate}
         and DATE_FORMAT(b.create_time,'%Y-%m-%d') &lt;= #{endDate}
-        where c.plan_id = #{userId}
+        and c.plan_id = #{userId}
     </select>
 
     <!-- 根据plane_id获取视频总消耗 -->
@@ -175,4 +188,52 @@
         and role_code = 'plane'
     </select>
 
+    <select id="designMaterialInfoList" resultType="cn.com.ctop.userefficientvideomap.entity.DesignMaterialInfo">    <!-- 素材、素材跑量、封面点击数、封面曝光数、行为数 -->
+        select
+        b.id as id,
+        b.url as videoUrl, <!-- 素材url -->
+        sum(a.photo_show) as pageExposureCount, <!-- 封面曝光数 -->
+        sum(a.photo_click) as pageClickCount, <!-- 封面点击数 -->
+        sum(a.aclick) as materialExposureCount, <!-- 素材曝光数 -->
+        sum(a.bclick) as behaviorCount,<!-- 行为数 -->
+        sum(a.charge) as totalCost <!-- 素材跑量 -->
+        from
+        ctop_material_info b
+        left join ctop_material_ascription c on b.id = c.material_id
+        left join ctop_kuaishou_report_daily_creative_statistic a on b.code = a.signature
+        where
+        <choose>
+            <when test=" roleCode == 'plan' ">
+                c.plan_id = #{userId}
+            </when>
+            <when test=" roleCode == 'clip' ">
+                c.clip_id = #{userId}
+            </when>
+            <otherwise>
+                c.shot_id = #{userId}
+            </otherwise>
+        </choose>
+         and DATE_FORMAT(b.create_time,'%Y-%m-%d') &gt;= #{startDate}
+         and DATE_FORMAT(b.create_time,'%Y-%m-%d') &lt;= #{endDate}
+        group by b.id
+    </select>
+
+    <!-- 根据material_info的id查询出素材账户、投放账户、跑量 -->
+    <select id="getMaterialAccountInfoByMaterialId" resultType="cn.com.ctop.userefficientvideomap.entity.DesignMaterialInfo">
+        select
+        a.account_id as accountId,
+        a.account_name as accountName,
+        '快手' as platform,
+        sum(charge) as totalCost
+        from
+        ctop_material_info b
+        left join ctop_material_ascription c on b.id = c.material_id
+        left join ctop_kuaishou_report_daily_creative_statistic a on b.code = a.signature
+        where
+        b.id = #{materialId}
+        and DATE_FORMAT(b.create_time,'%Y-%m-%d') &gt;= #{startDate}
+         and DATE_FORMAT(b.create_time,'%Y-%m-%d') &lt;= #{endDate}
+    </select>
+
+
 </mapper>