浏览代码

设计绩效

yangzian 2 年之前
父节点
当前提交
bde82d3e79

+ 155 - 10
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -1,5 +1,9 @@
 package org.jeecg.common.util;
 package org.jeecg.common.util;
 
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import net.sf.saxon.type.StringConverter;
+import org.hibernate.annotations.Check;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.StringUtils;
 import org.springframework.util.StringUtils;
@@ -9,15 +13,7 @@ import java.sql.Timestamp;
 import java.text.DateFormat;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.TimeZone;
+import java.util.*;
 
 
 /**
 /**
  * 类描述:时间操作定义类
  * 类描述:时间操作定义类
@@ -2156,9 +2152,158 @@ public class DateUtils extends PropertyEditorSupport {
         list.add("2022-09-04");
         list.add("2022-09-04");
 
 
 
 
-        System.out.println(getHoursListDifference(list));
+        //System.out.println(getHoursListDifference(list));
+        //System.out.println(getCurrentQuarterMonths());
+        System.out.println(isThisQuarter("2022-08-02 12:23:23"));
+
+
+        //离职时间不为空
+        String frozenTime = "";
+        String createTime = "2022-11-02 12:23:23";
+
+//        //绩效 = 在职月份 * 80w 额度
+//        int cost = 80;
+//        int i = 3;
+//        if (!frozenTime.isEmpty()){
+//            //离职时间 是否在当前季度
+//            if (DateUtils.isThisQuarter(frozenTime)){
+//                Map<String,Object> map = getCurrentQuarterMonths(frozenTime);
+//                //月份
+//                String monthTime = map.get("monthTime")+"" ;
+//                //季度
+//                String[]  quarter =(String[]) map.get("quarter");
+//                //判断当前离职所在的月份 与当前季度中的月份集合 并获取下标  下标+1 则是 在职月份i
+//                int j = Collections.indexOfSubList(Arrays.asList(quarter),Arrays.asList(monthTime));
+//                i = j + 1;
+//                log.info("职-----离职时间是:{}在本季度范围内!系数为{}个月的绩效数据--->{}",frozenTime,i,i*cost);
+//                //return i*cost;
+//            };
+//            log.info("离职-----离职时间是:{}不在本季度范围内!绩效按照240计算。当前时间是:{},",frozenTime,new Date());
+//        }
+//
+//        if (!createTime.isEmpty()){
+//            //在职时间 是否在当前季度
+//            if (DateUtils.isThisQuarter(createTime)){
+//                Map<String,Object> map = getCurrentQuarterMonths(createTime);
+//                //月份
+//                String monthTime = map.get("monthTime")+"" ;
+//                //季度
+//                String[]  quarter =(String[]) map.get("quarter");
+//                //判断当前离职所在的月份 与当前季度中的月份集合 并获取下标  下标+1 则是 在职月份i
+//                int j = Collections.indexOfSubList(Arrays.asList(quarter),Arrays.asList(monthTime));
+//                i = 3 - j;
+//                log.info("在职-----入职时间是:{}在本季度范围内!系数为{}个月的绩效数据--->{}",createTime,i,i*cost);
+//                //return i*cost;
+//            };
+//            log.info("在职-----入职时间是:{}不在本季度范围内!绩效按照240计算。当前时间是:{},",createTime,new Date());
+//        }
+//
+
+        System.out.println(getQuarterEndDay("2022-01-01"));
+        System.out.println(getMonth("yyyy-MM-dd","2022-01-01"));
+
+    }
+
+    /**
+     * 获取当前时间的季度的月份
+     * @return
+     */
+    public static Map<String,Object> getCurrentQuarterMonths(String dateStr){
+
+        Date date = parseDate(dateStr,"yyyy-MM-dd HH:mm:ss");
+
+        Map<String,Object> map = new HashMap<>();
+        String quarter[] = new String[]{};
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        int yearTime = calendar.get(Calendar.YEAR);
+        int monthTime = calendar.get(Calendar.MONTH)+1;
+        int quarterTime = monthTime % 3 == 0 ? monthTime / 3 : monthTime / 3 + 1;
+        if (quarterTime == 1){
+             quarter = new String[]{"1","2","3"};
+        }
+        if (quarterTime == 2){
+             quarter = new String[]{"4","5","6"};
+        }
+        if (quarterTime == 3){
+             quarter = new String[]{"7","8","9"};
+        }
+        if (quarterTime == 4){
+             quarter = new String[]{"10","11","12"};
+        }
+        map.put("yearTime",yearTime);
+        map.put("monthTime",monthTime);
+        map.put("quarterTime",quarterTime);
+        map.put("quarter",quarter);
+        return map;
+    }
+
 
 
+    /**
+     * 获得季度开始时间
+     * @return
+     */
+    public static Date getCurrentQuarterStartTime() {
+        Calendar c = Calendar.getInstance();
+        int currentMonth = c.get(Calendar.MONTH) + 1;
+        SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
+        Date now = null;
+        try {
+            if (currentMonth >= 1 && currentMonth <= 3)
+                c.set(Calendar.MONTH, 0);
+            else if (currentMonth >= 4 && currentMonth <= 6)
+                c.set(Calendar.MONTH, 3);
+            else if (currentMonth >= 7 && currentMonth <= 9)
+                c.set(Calendar.MONTH, 4);
+            else if (currentMonth >= 10 && currentMonth <= 12)
+                c.set(Calendar.MONTH, 9);
+            c.set(Calendar.DATE, 1);
+            now = longSdf.parse(shortSdf.format(c.getTime()) + " 00:00:00");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return now;
     }
     }
 
 
+    /**
+     * 当前季度的结束时间
+     * @return
+     */
+    public static Date getCurrentQuarterEndTime() {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(getCurrentQuarterStartTime());
+        cal.add(Calendar.MONTH, 3);
+        return cal.getTime();
+    }
+
+    //判断选择的日期是否是本季度
+    public static boolean isThisQuarter(String time) {
+        Date date = parseDate(time, "yyyy-MM-dd");
+        Date QuarterStart = getCurrentQuarterStartTime();
+        Date QuarterEnd = getCurrentQuarterEndTime();
+        return date.after(QuarterStart) && date.before(QuarterEnd);
+    }
+
+
+    /**
+     * 离职时间所在季度的最后一天
+     * @param time
+     * @return
+     */
+    public static String getQuarterEndDay(String time) {
+        Date date = parseDate(time, "yyyy-MM-dd");
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        cal.add(Calendar.MONTH, 3);
+        cal.add(Calendar.DATE, -1);
+        return dateToStringTime(cal.getTime());
+    }
+
+
+
+
+
+
 
 
 }
 }

+ 61 - 6
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/achievements/controller/DesignerAchievementsController.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.common.module.achievements.controller;
 package cn.com.ctop.common.module.achievements.controller;
 
 
 import cn.com.ctop.common.module.achievements.service.IDesignerService;
 import cn.com.ctop.common.module.achievements.service.IDesignerService;
+import com.alibaba.fastjson.JSONObject;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.api.vo.Result;
@@ -22,17 +23,71 @@ public class DesignerAchievementsController {
     private IDesignerService designerService;
     private IDesignerService designerService;
 
 
     /**
     /**
-     * 分页列表查询
+     * 查询设计人员基础信息
      *
      *
-     * @param pageNo
-     * @param pageSize
+     * @param userId
+     * @return
+     */
+    @GetMapping(value = "/getDesignBasicsInfoList")
+    public Result getDesignBasicsInfoList(@RequestParam(name = "userId") String userId,
+                                          @RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum,
+                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+
+        return designerService.getDesignBasicsInfoList(userId,pageNum,pageSize);
+
+    }
+
+    /**
+     * 爆款视频数据
+     *
+     * @param userId
+     * @param
      * @return
      * @return
      */
      */
     @GetMapping(value = "/getHotVideoData")
     @GetMapping(value = "/getHotVideoData")
-    public Result getHotVideoData(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
-                                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+    public Result getHotVideoData(@RequestParam(name = "userId") String userId) {
+
+        return designerService.getHotVideoData(userId);
+
+    }
+
+    /**
+     * 设计绩效
+     *
+     * @param userId
+     * @param
+     * @return
+     */
+    @GetMapping(value = "/getDesignerAchievements")
+    public Result getDesignerAchievements(@RequestParam(name = "userId") String userId) {
+        return designerService.getDesignerAchievements(userId);
+
+    }
+
+    /**
+     * 设计提成
+     *
+     * @param userId
+     * @param
+     * @return
+     */
+    @GetMapping(value = "/getDesignerCommission")
+    public Result getDesignerCommission(@RequestParam(name = "userId") String userId) {
+        return designerService.getDesignerCommission(userId);
+
+    }
+
+    /**
+     * 修改绩效中的用户部分信息
+     *
+     * @param jsonObject
+     * @param
+     * @return
+     */
+    @PostMapping(value = "/updateUserHappyProbability")
+    public Result updateUserHappyProbability(@RequestBody JSONObject jsonObject) {
 
 
-        return designerService.getHotVideoData();
+        return designerService.updateUserHappyProbability(jsonObject);
 
 
     }
     }
 
 

+ 66 - 2
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/achievements/mapper/DesignerMapper.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Param;
 
 
 import java.util.List;
 import java.util.List;
+import java.util.Set;
 
 
 /**
 /**
  * 设计人员绩效
  * 设计人员绩效
@@ -16,8 +17,71 @@ public interface DesignerMapper{
 
 
     /**
     /**
      * 查询设计人员基础信息
      * 查询设计人员基础信息
-     * @param userId 用户id
+     * @param userIdList 用户id
+     * @param departName 部门名称
      * @return
      * @return
      */
      */
-    List<JSONObject> getDesignerUserInfo(@Param("userId") String userId);
+    List<JSONObject> getDesignerUserInfo(@Param("departName")String departName,@Param("userIdList") Set<String> userIdList);
+
+
+    /**
+     * 获取爆款视频数量
+     * @param userId
+     * @param roleName  角色名称
+     * @param mediaType 1-头条 2-快手
+     * @param yearTime 当前年份
+     * @param monthTime 当前月份
+     * @return
+     */
+    JSONObject  getHotVideoData(@Param("userId")String userId,
+                                     @Param("roleName") String roleName,
+                                     @Param("mediaType") String mediaType,
+                                     @Param("yearTime") String yearTime,
+                                     @Param("monthTime") String monthTime);
+
+
+    /**
+     *  设计人员绩效-头条
+     * @param userId
+     * @param yearTime
+     * @param monthTime
+     * @return
+     */
+    List<JSONObject>  getDesignerAchievementsBytedance(@Param("userId")String userId,
+                                     @Param("yearTime") String yearTime,
+                                     @Param("monthTime") String monthTime);
+
+    /**
+     * 查询设计 本季度 头条和快手季度消耗汇总
+     * @param userId
+     * @return
+     */
+    List<JSONObject>  getDesignerBytedanceAndKuaishouQuaterCost(@Param("userId")String userId);
+
+    /**
+     * 查询人员离职时间
+     * @param userId
+     * @return
+     */
+    JSONObject  getUserFrozenInfo(@Param("userId")String userId);
+
+    /**
+     * 查询人员 当前季度爆款素材数量
+     * @param userId
+     * @return
+     */
+    JSONObject  getUserHotMaterialQuarter(@Param("userId")String userId);
+
+    /**
+     * 绩效- 用户信息修改
+     * @return
+     */
+    void  updateUserHappyProbability(@Param("userId")String userId,
+                                           @Param("openScreenNum")String openScreenNum,
+                                           @Param("paySalary")String paySalary,
+                                           @Param("remarks")String remarks);
+
+
+
+
 }
 }

+ 233 - 4
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/achievements/mapper/xml/DesignerMapper.xml

@@ -11,21 +11,250 @@
             u.sex AS userSex,
             u.sex AS userSex,
             u.frozen_time AS frozenTime,
             u.frozen_time AS frozenTime,
             d.depart_name AS departName,
             d.depart_name AS departName,
-            r.role_name AS roleName
+            r.role_name AS roleName,
+            u.`status`
         FROM
         FROM
             `jeecg-boot`.sys_user u
             `jeecg-boot`.sys_user u
                 LEFT JOIN `jeecg-boot`.sys_depart d ON u.org_code = d.org_code
                 LEFT JOIN `jeecg-boot`.sys_depart d ON u.org_code = d.org_code
                 LEFT JOIN `jeecg-boot`.sys_user_role ur ON ur.user_id = u.id
                 LEFT JOIN `jeecg-boot`.sys_user_role ur ON ur.user_id = u.id
                 LEFT JOIN `jeecg-boot`.sys_role r ON r.id = ur.role_id
                 LEFT JOIN `jeecg-boot`.sys_role r ON r.id = ur.role_id
         <where>
         <where>
-            and d.depart_name LIKE '%设计%'
-            <if test="userId != null and userId != ''">
-                and u.id = #{userId}
+            <if test="departName != null and departName != ''">
+                and d.depart_name LIKE concat('%',#{departName},'%')
+            </if>
+            <if test="userIdList != null and userIdList.size() > 0">
+                and u.id in
+                    <foreach collection="userIdList" item="userId" separator="," open="(" close=")">
+                        #{userId}
+                    </foreach>
             </if>
             </if>
         </where>
         </where>
     </select>
     </select>
 
 
 
 
 
 
+    <!-- 查询设计人员基础信息 -->
+    <select id="getHotVideoData" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        QUARTER	( h.hot_date ) quaterTime,
+        DATE_FORMAT( h.hot_date, '%Y' ) yearTime,
+        DATE_FORMAT( h.hot_date, '%m' ) monthTime,
+        IFNULL( COUNT( h.signature ), 0 ) AS hotNum
+        FROM
+        application.hot_material h
+        LEFT JOIN `jeecg-boot`.ctop_material_ascription v ON v.material_id = h.signature
+        where
+        v.clip_id != v.shot_id
+        AND v.shot_id != v.plan_id
+        AND h.media_id = #{mediaType}
+        AND DATE_FORMAT( h.hot_date, '%Y' ) = #{yearTime}
+        AND DATE_FORMAT( h.hot_date, '%m' ) = #{monthTime}
+        <if test="roleName == 'clip'.toString()">
+            AND clip_id = #{userId}
+        </if>
+
+        <if test="roleName == 'shot'.toString()">
+            AND shot_id = #{userId}
+        </if>
+
+        <if test="roleName == 'plan'.toString()">
+            AND plan_id = #{userId}
+        </if>
+
+    </select>
+
+
+
+
+    <!-- 查询设计人员 头条绩效-->
+    <select id="getDesignerAchievementsBytedance" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            QUARTER	( d.first_cost_day ) quaterTime,
+            DATE_FORMAT( d.first_cost_day, '%Y' ) yearTime,
+            DATE_FORMAT( d.first_cost_day, '%m' ) monthTime,
+            IFNULL( sum( d.cost ), 0 ) AS cost,
+            '0.3' AS coefficient,
+            IFNULL( round(( sum( d.cost ) * 0.002 * 0.3 ), 3 ), 0 ) AS commission,
+            'clip' AS type
+        FROM
+            application.bytedance_material_cost_daily d
+        WHERE
+            clip_id = #{userId}
+          AND DATE_FORMAT( d.first_cost_day, '%Y' ) = #{yearTime}
+          AND DATE_FORMAT( d.first_cost_day, '%m' ) = #{monthTime}
+        UNION ALL
+        SELECT
+            QUARTER	( d.first_cost_day ) quaterTime,
+            DATE_FORMAT( d.first_cost_day, '%Y' ) yearTime,
+            DATE_FORMAT( d.first_cost_day, '%m' ) monthTime,
+            IFNULL( sum( d.cost ), 0 ) AS cost,
+            '0.1' AS coefficient,
+            IFNULL( round(( sum( d.cost ) * 0.002 * 0.1 ), 3 ), 0 ) AS commission,
+            'shot' AS type
+        FROM
+            application.bytedance_material_cost_daily d
+        WHERE
+            shot_id = #{userId}
+          AND DATE_FORMAT( d.first_cost_day, '%Y' ) = #{yearTime}
+          AND DATE_FORMAT( d.first_cost_day, '%m' ) = #{monthTime}
+        UNION ALL
+        SELECT
+            QUARTER	( d.first_cost_day ) quaterTime,
+            DATE_FORMAT( d.first_cost_day, '%Y' ) yearTime,
+            DATE_FORMAT( d.first_cost_day, '%m' ) monthTime,
+            IFNULL( sum( d.cost ), 0 ) AS cost,
+            '0.4' AS coefficient,
+            IFNULL( round(( sum( d.cost ) * 0.002 * 0.4 ), 3 ), 0 ) AS commission,
+            'plan' AS type
+        FROM
+            application.bytedance_material_cost_daily d
+        WHERE
+            plan_id = #{userId}
+          AND DATE_FORMAT( d.first_cost_day, '%Y' ) = #{yearTime}
+          AND DATE_FORMAT( d.first_cost_day, '%m' ) = #{monthTime}
+    </select>
+
+
+    <!-- 查询设计人员 快手绩效-->
+    <select id="getDesignerAchievementsKuaishou" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            QUARTER	( d.first_cost_day ) quaterTime,
+            DATE_FORMAT( d.first_cost_day, '%Y' ) yearTime,
+            DATE_FORMAT( d.first_cost_day, '%m' ) monthTime,
+            IFNULL( sum( d.charge ), 0 ) AS cost,
+            '0.3' AS coefficient,
+            IFNULL( round(( sum( d.charge ) * 0.003 * 0.3 ), 3 ), 0 ) AS commission,
+            'clip' AS type
+        FROM
+            application.kuaishou_material_cost_daily d
+        WHERE
+            clip_id = #{userId}
+          AND DATE_FORMAT( d.first_cost_day, '%Y' ) = #{yearTime}
+          AND DATE_FORMAT( d.first_cost_day, '%m' ) = #{monthTime}
+        UNION ALL
+        SELECT
+            QUARTER	( d.first_cost_day ) quaterTime,
+            DATE_FORMAT( d.first_cost_day, '%Y' ) yearTime,
+            DATE_FORMAT( d.first_cost_day, '%m' ) monthTime,
+            IFNULL( sum( d.charge ), 0 ) AS cost,
+            '0.1' AS coefficient,
+            IFNULL( round(( sum( d.charge ) * 0.003 * 0.1 ), 3 ), 0 ) AS commission,
+            'shot' AS type
+        FROM
+            application.kuaishou_material_cost_daily d
+        WHERE
+            shot_id = #{userId}
+          AND DATE_FORMAT( d.first_cost_day, '%Y' ) = #{yearTime}
+          AND DATE_FORMAT( d.first_cost_day, '%m' ) = #{monthTime}
+        UNION ALL
+        SELECT
+            QUARTER( d.first_cost_day ) quaterTime,
+            DATE_FORMAT( d.first_cost_day, '%Y' ) yearTime,
+            DATE_FORMAT( d.first_cost_day, '%m' ) monthTime,
+            IFNULL( sum( d.charge ), 0 ) AS cost,
+            '0.4' AS coefficient,
+            IFNULL( round(( sum( d.charge ) * 0.003 * 0.4 ), 3 ), 0 ) AS commission,
+            'plan' AS type
+        FROM
+            application.kuaishou_material_cost_daily d
+        WHERE
+            plan_id = #{userId}
+          AND DATE_FORMAT( d.first_cost_day, '%Y' ) = #{yearTime}
+          AND DATE_FORMAT( d.first_cost_day, '%m' ) = #{monthTime}
+    </select>
+
+    <!-- 查询设计 本季度 头条和快手季度消耗汇总-->
+    <select id="getDesignerBytedanceAndKuaishouQuaterCost" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            QUARTER( d.first_cost_day ) quaterTime,
+            YEAR ( d.first_cost_day ) yearTime,
+            IFNULL( sum( d.cost ), 0 ) AS cost,
+            'byteDance' AS type
+        FROM
+            application.bytedance_material_cost_daily d
+        WHERE
+            (
+            d.clip_id = #{userId} OR d.shot_id = #{userId} OR d.plan_id = #{userId}
+            )
+          AND
+            QUARTER ( d.first_cost_day ) = QUARTER (NOW())
+          AND YEAR ( d.first_cost_day ) = YEAR (NOW())
+        UNION ALL
+        SELECT
+            QUARTER( d.first_cost_day ) quaterTime,
+            YEAR ( d.first_cost_day ) yearTime,
+            IFNULL( sum( d.charge ), 0 ) AS cost,
+            'kuaiShou' AS type
+        FROM
+            application.kuaishou_material_cost_daily d
+
+        WHERE
+            (
+            d.clip_id = #{userId} OR d.shot_id = #{userId} OR d.plan_id = #{userId}
+            )
+          and
+            QUARTER ( d.first_cost_day ) = QUARTER (NOW())
+          AND YEAR ( d.first_cost_day ) = YEAR (NOW())
+    </select>
+
+
+    <!-- 查询人员离职时间-->
+    <select id="getUserFrozenInfo" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            u.id userId,
+            u.username userName,
+            u.realname realName,
+            u.create_time createTime,
+            u.frozen_time frozenTime,
+            IFNULL(u.open_screen_num,0) openHotVideoNum,
+            IFNULL(u.pay_salary,0) paySalary,
+            u.remarks
+        FROM
+            `jeecg-boot`.sys_user u
+        WHERE u.id = #{userId}
+            limit 1
+    </select>
+
+
+    <!-- 查询人员 当前季度爆款素材数量 -->
+    <select id="getUserHotMaterialQuarter" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            COUNT(h.signature) hotVideoNum
+        FROM
+            application.hot_material h
+                LEFT JOIN `jeecg-boot`.ctop_material_ascription v ON v.material_id = h.signature
+        WHERE
+
+                (v.plan_id = #{userId}
+                    OR v.clip_id = #{userId}
+                    or v.shot_id =#{userId}
+                    )
+                and
+                QUARTER ( h.hot_date ) = QUARTER (NOW())
+                AND YEAR ( h.hot_date ) = YEAR (NOW())
+
+    </select>
+
+
+    <update id="updateUserHappyProbability">
+        UPDATE `jeecg-boot`.sys_user
+        <set>
+            <if test="openScreenNum != null">
+                open_screen_num = #{openScreenNum},
+            </if>
+            <if test="paySalary != null">
+                pay_salary = #{paySalary},
+            </if>
+            <if test="remarks != null and remarks !=''">
+                remarks = #{remarks},
+            </if>
+        </set>
+        WHERE
+        id = #{userId}
+    </update>
+
+
+
+
 
 
 </mapper>
 </mapper>

+ 10 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/achievements/service/IDesignerService.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.common.module.achievements.service;
 package cn.com.ctop.common.module.achievements.service;
 
 
+import com.alibaba.fastjson.JSONObject;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.api.vo.Result;
 
 
 /**
 /**
@@ -12,6 +13,14 @@ import org.jeecg.common.api.vo.Result;
 public interface IDesignerService{
 public interface IDesignerService{
 
 
 
 
-    Result getHotVideoData();
+    Result getDesignBasicsInfoList(String userId,int pageNum,int pageSize);
+
+    Result getHotVideoData(String userId);
+
+    Result getDesignerAchievements(String userId);
+
+    Result getDesignerCommission(String userId);
+
+    Result updateUserHappyProbability(JSONObject jsonObject);
 
 
 }
 }

+ 346 - 4
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/achievements/service/impl/DesignerServiceImpl.java

@@ -2,12 +2,23 @@ package cn.com.ctop.common.module.achievements.service.impl;
 
 
 import cn.com.ctop.common.module.achievements.mapper.DesignerMapper;
 import cn.com.ctop.common.module.achievements.mapper.DesignerMapper;
 import cn.com.ctop.common.module.achievements.service.IDesignerService;
 import cn.com.ctop.common.module.achievements.service.IDesignerService;
+import cn.com.ctop.common.module.utils.Check;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.itextpdf.text.pdf.parser.clipper.ClipperOffset;
+import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.modules.ctop.service.IMaterialReportOverViewService;
+import org.jeecg.modules.system.service.ISysRoleService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
-import java.util.List;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.function.ToDoubleFunction;
 
 
 /**
 /**
  * 设计人员绩效
  * 设计人员绩效
@@ -16,18 +27,349 @@ import java.util.List;
  * @date: 2022-09-28
  * @date: 2022-09-28
  * @cersion: V1.0
  * @cersion: V1.0
  */
  */
+
+@Slf4j
 @Service
 @Service
 public class DesignerServiceImpl implements IDesignerService {
 public class DesignerServiceImpl implements IDesignerService {
     @Resource
     @Resource
     private DesignerMapper designerMapper;
     private DesignerMapper designerMapper;
 
 
+    @Autowired
+    private ISysRoleService roleService;
+
+    @Autowired
+    private IMaterialReportOverViewService materialReportOverViewService;
+    private ToDoubleFunction<JSONObject> getJSONObject;
 
 
     @Override
     @Override
-    public Result getHotVideoData() {
+    public Result getDesignBasicsInfoList(String userId,int pageNum,int pageSize) {
+        String departName = null;
+        Set<String> userIdList = new HashSet<>();
+        //查询用户角色
+        String roleCode = roleService.getRoleCodeByUserId(userId);
+        if (roleCode.contains("admin")){
+            //查询设计部门所有人
+            departName = "设计";
+        }else if (roleCode.contains("Leader")){
+            //查询所有包含自己的下级
+            userIdList = materialReportOverViewService.recursiveQuerySubordinate(userId);
+        }else {
+            userIdList.add(userId);
+        }
+        PageHelper.startPage(pageNum,pageSize);
+        List<JSONObject> list = designerMapper.getDesignerUserInfo(departName,userIdList);
+        PageInfo<JSONObject> pageInfo = new PageInfo<>(list);
+        return Result.successMsg("设计基础信息查询成功",pageInfo);
+    }
+
+
+    /**
+     *
+     * @description:爆款视频数据
+     *
+     * @param userId
+     * @return: org.jeecg.common.api.vo.Result
+     * @author: zianY
+     */
+    @Override
+    public Result getHotVideoData(String userId) {
+        String roleName = null;
+        //查询用户角色
+        String roleCode = roleService.getRoleCodeByUserId(userId);
+        if (roleCode.contains("clip")){
+            roleName = "clip";
+        }else if (roleCode.contains("shot")){
+            roleName = "shot";
+        }else if (roleCode.contains("plan")){
+            roleName = "plan";
+        }else {
+            return Result.successMsg("请核实人员["+userId+"]角色信息。",userId);
+        }
+        //取当前时间的季度的月份
+        Map<String,Object> timeMap = DateUtils.getCurrentQuarterMonths(DateUtils.dateToStringTime(new Date()));
+        String[] quarterStr = (String[])timeMap.get("quarter");
+        List<Map<String,Object>> resultList = new ArrayList<>();
+        List<Map<String,Object>> byteDanceList = new ArrayList<>();
+        Map<String,Object> bytedanceMap = new HashMap<>();
+        List<Map<String,Object>> kuaishouList = new ArrayList<>();
+        Map<String,Object> kuaishouMap = new HashMap<>();
+        for (String month : quarterStr ){
+            //头条
+            JSONObject bytedanceJson = designerMapper.getHotVideoData(userId,roleName,"1",timeMap.get("yearTime")+"",month);
+            bytedanceJson.put("monthTime",month);
+            byteDanceList.add(bytedanceJson);
+            bytedanceMap.put("byteDance",byteDanceList);
+            //快手
+            JSONObject kuaishouJson = designerMapper.getHotVideoData(userId,roleName,"2",timeMap.get("yearTime")+"",month);
+            kuaishouJson.put("monthTime",month);
+            kuaishouList.add(kuaishouJson);
+            kuaishouMap.put("kuaishou",kuaishouList);
+        }
+        resultList.add(bytedanceMap);
+        resultList.add(kuaishouMap);
+        return Result.successMsg("设计基础信息查询成功",resultList);
+    }
+
+
+   @Override
+    public Result getDesignerAchievements(String userId) {
+        //取当前时间的季度的月份
+        Map<String,Object> timeMap = DateUtils.getCurrentQuarterMonths(DateUtils.dateToStringTime(new Date()));
+        String[] quarterStr = (String[])timeMap.get("quarter");
+       Map<String,Object> resultMap = new HashMap<>();
+       List<Map<String,Object>> byteDanceList = new ArrayList<>();
+       List<Map<String,Object>> kuaishouList = new ArrayList<>();
+
+        for (String month : quarterStr ){
+            Map<String,Object> bytedanceMap = new HashMap<>();
+            Map<String,Object> kuaishouMap = new HashMap<>();
+            //头条
+            List<JSONObject> bytedanceJson = designerMapper.getDesignerAchievementsBytedance(userId,timeMap.get("yearTime")+"",month);
+            bytedanceMap.put("monthTime",month );
+            bytedanceMap.put("yearTime",timeMap.get("yearTime")+"" );
+            bytedanceMap.put("byteDance",bytedanceJson);
+            byteDanceList.add(bytedanceMap);
+            //快手
+            List<JSONObject> kuaishouJson = designerMapper.getDesignerAchievementsBytedance(userId,timeMap.get("yearTime")+"",month);
+            kuaishouMap.put("monthTime",month );
+            bytedanceMap.put("yearTime",timeMap.get("yearTime")+"" );
+            kuaishouMap.put("kuaiShou",kuaishouJson);
+            kuaishouList.add(kuaishouMap);
+        }
+       resultMap.put("byteDanceData",byteDanceList);
+       resultMap.put("kuaiShouData",kuaishouList);
+        return Result.successMsg("设计绩效信息查询成功",resultMap);
+    }
+
+
+    /**
+     * 判断 人员 季度消耗 是否达标
+     * 一季度3个月 平均每个月80w消耗
+     * 此季度素材总消耗大于240w,则为达标,否则为不达标;
+     * 此外需要考虑人员的入离职日期,如果5月入职,则只计算5、6月是否达标即可,则为每个月80w的消耗目标;
+     * frozenTime 离职时间
+     * createTime 员工入职时间
+     * @return
+     */
+    public Double getMaterialCost(String frozenTime, String createTime){
+
+        //String frozenTime = "";
+        //String createTime = "2022-11-02 12:23:23";
+
+        //绩效 = 在职月份 * 80w 额度
+        Double cost = new Double("800000");
+        int i = 3;
+
+        /**
+         * 人员离职
+         */
+        if (!Check.isNull(frozenTime)){
+            //离职时间 是否在当前季度
+            if (DateUtils.isThisQuarter(frozenTime)){
+                Map<String,Object> map = DateUtils.getCurrentQuarterMonths(frozenTime);
+                //月份
+                String monthTime = map.get("monthTime")+"" ;
+                //季度
+                String[]  quarter =(String[]) map.get("quarter");
+                //判断当前离职所在的月份 与当前季度中的月份集合 并获取下标  下标+1 则是 在职月份i
+                int j = Collections.indexOfSubList(Arrays.asList(quarter),Arrays.asList(monthTime));
+                i = j + 1;
+                log.info("离职-----离职时间是:{}在本季度范围内!系数为{}个月的绩效数据--->{}",frozenTime,i,i*cost);
+                return i * cost;
+            };
+            log.info("离职-----离职时间是:{}不在本季度范围内!绩效按照240计算。当前时间是:{},",frozenTime,new Date());
+        }else {
+            //入职时间 是否在当前季度
+            if (DateUtils.isThisQuarter(createTime)){
+                Map<String,Object> map = DateUtils.getCurrentQuarterMonths(createTime);
+                //月份
+                String monthTime = map.get("monthTime")+"" ;
+                //季度
+                String[]  quarter =(String[]) map.get("quarter");
+                //判断当前离职所在的月份 与当前季度中的月份集合 并获取下标  下标+1 则是 在职月份i
+                int j = Collections.indexOfSubList(Arrays.asList(quarter),Arrays.asList(monthTime));
+                i = 3 - j;
+                log.info("在职-----入职时间是:{}在本季度范围内!系数为{}个月的绩效数据--->{}",createTime,i,i*cost);
+                return i * cost;
+            };
+            log.info("在职-----入职时间是:{}不在本季度范围内!绩效按照240计算。当前时间是:{},",createTime,new Date());
+        }
+        return i * cost;
+    }
+
 
 
-        List<JSONObject> list = designerMapper.getDesignerUserInfo(null);
+    /**
+     * 离职发放比例
+     * frozenTime 离职时间
+     * @return
+     */
+    public Double userHappyProbability(String frozenTime){
 
 
+        //离职发放比例
+        Double userHappyProbability = new Double("1");
+        if (!Check.isNull(frozenTime)){
+            //离职时间所在季度的最后一天
+            String endDay = DateUtils.getQuarterEndDay(frozenTime);
+            //离职月份
+            String month = DateUtils.getMonth("yyyy-MM-dd",frozenTime);
+            // 离职时间 > = 最后一天 发放比例为1
+            if (DateUtils.str2Date(frozenTime,new SimpleDateFormat("yyyy-MM-dd")).getTime() >=
+                    DateUtils.str2Date(endDay,new SimpleDateFormat("yyyy-MM-dd")).getTime()){
+                userHappyProbability = new Double("1");
+            }
+            //15日之前离职 不发
+            // 15号之后离职,发50%
+            if (Integer.valueOf(month) >= 15){
+                userHappyProbability = new Double("0.5");
+            }
 
 
-        return Result.successMsg("查询成功",list);
+        }
+
+        return userHappyProbability;
     }
     }
+
+
+
+
+
+
+
+   @Override
+    public Result getDesignerCommission(String userId) {
+        //取当前时间的季度的月份
+        Map<String,Object> timeMap = DateUtils.getCurrentQuarterMonths(DateUtils.dateToStringTime(new Date()));
+        String[] quarterStr = (String[])timeMap.get("quarter");
+
+       //人员离职信息
+       JSONObject userFrozen = designerMapper.getUserFrozenInfo(userId);
+
+
+       //季度 分媒体 素材消耗
+       List<JSONObject> quarterCost = designerMapper.getDesignerBytedanceAndKuaishouQuaterCost(userId);
+       userFrozen.put("quarterCostList",quarterCost);
+
+       //季度素材 总消耗
+       Double tatolCost = quarterCost.stream().mapToDouble(json -> json.getDouble("cost")).reduce(Double::sum).orElse(new Double("0"));
+       userFrozen.put("tatolQuarterCost",tatolCost);
+
+       //消耗是否达标
+
+       //离职时间
+       String frozenTime = userFrozen.getString("frozenTime");
+       //入职时间
+       String createTime = userFrozen.getString("createTime");
+
+       //判断素材消耗是否达标
+       Double i = getMaterialCost(frozenTime,createTime);
+       String materialCostQualifiedFlag = tatolCost >= i ? "是" : "否";
+       userFrozen.put("materialCostQualifiedFlag",materialCostQualifiedFlag);
+
+       //爆款素材数量
+       JSONObject hotVideoNum = designerMapper.getUserHotMaterialQuarter(userId);
+       int hotVideoN = Check.isNull(hotVideoNum) ? 0 : hotVideoNum.getInteger("hotVideoNum");
+       userFrozen.put("hotVideoNum",hotVideoN);
+
+
+
+       //爆款总量 开屏爆款数量 + 爆款数量
+       int hotVideoTotalNum = userFrozen.getInteger("openHotVideoNum") + hotVideoN;
+       userFrozen.put("hotVideoTotalNum",hotVideoTotalNum);
+
+       /**
+        * 爆款达标 提成发放系数
+        * 在季度中
+        * 爆款 >= 10个 消耗>=240w 绩效 100%
+        * 爆款 < 10 消耗 >= 240w 绩效50%
+        * 爆款<=0 绩效 >= 240w 不发
+        * 爆款>=10 绩效<=240w 不发
+        * 其中的绩效240 根据入职或离职时间按月计算 使用字段materialCostQualifiedFlag
+        *
+        */
+       Double coefficient = new Double("0");
+       if (materialCostQualifiedFlag.equals("是")){
+           if (hotVideoTotalNum >= 10){
+               coefficient = new Double("1");
+           }
+           if (hotVideoTotalNum > 0 && hotVideoTotalNum < 10){
+               coefficient = new Double("0.5");
+           }
+       }
+       userFrozen.put("coefficient",coefficient);
+
+
+       //提成 分月份
+       List<JSONObject> commissionList = new ArrayList<>();
+       for (String month : quarterStr ) {
+           JSONObject commissionJson = new JSONObject();
+           //头条提成
+           List<JSONObject> bytedanceJson = designerMapper.getDesignerAchievementsBytedance(userId, timeMap.get("yearTime") + "", month);
+           Double bytedanceCommission = bytedanceJson.stream().mapToDouble(json -> json.getDouble("commission")).reduce(Double::sum).orElse(new Double("0"));
+
+           //快手提成
+           List<JSONObject> kuaishouJson = designerMapper.getDesignerAchievementsBytedance(userId, timeMap.get("yearTime") + "", month);
+           Double kuaishouCommission = kuaishouJson.stream().mapToDouble(json -> json.getDouble("commission")).reduce(Double::sum).orElse(new Double("0"));
+
+           commissionJson.put("monthTime", month);
+           commissionJson.put("yearTime", timeMap.get("yearTime") + "");
+           commissionJson.put("commission", bytedanceCommission+kuaishouCommission);
+           commissionList.add(commissionJson);
+       }
+       userFrozen.put("commissionList",commissionList);
+
+
+       //季度提成汇总
+       Double totalCommission = commissionList.stream().mapToDouble(json -> json.getDouble("commission")).reduce(Double::sum).orElse(new Double("0"));
+
+       //如果是负责人 (设计组长) 负责人提成千三的20%
+       Double designerLeaderCommission = new Double("0");
+       String roleCode = roleService.getRoleCodeByUserId(userId);
+       if (roleCode.equalsIgnoreCase("designTeamLeader")){
+           designerLeaderCommission = totalCommission * 0.003 * 0.2;
+       }
+       userFrozen.put("designerLeaderCommission",designerLeaderCommission);
+
+
+       //提成汇总 = 季度汇总 + 负责人提成
+       totalCommission+=designerLeaderCommission;
+       userFrozen.put("totalCommission",totalCommission);
+
+
+
+       //离职发放比例
+       Double userHappyProbability = userHappyProbability(frozenTime);
+
+       //提成发放金额 = 总提成* 发放系数 * 离职发放比例
+       Double userHappyGetMoney = totalCommission * coefficient * userHappyProbability;
+       userFrozen.put("userHappyGetMoney",userHappyGetMoney);
+
+       return Result.successMsg("查询成功",userFrozen);
+
+
+   }
+
+
+
+
+
+
+   @Override
+    public Result updateUserHappyProbability(JSONObject jsonObject) {
+        designerMapper.updateUserHappyProbability(jsonObject.getString("userId"),
+                jsonObject.getString("openScreenNum"),
+                jsonObject.getString("paySalary"),
+                jsonObject.getString("remarks"));
+       return Result.successMsg("修改成功",null);
+
+
+   }
+
+
+
+
+
+
+
+
+
+
 }
 }