|
@@ -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);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|