排除指标(本归属本班组和不归属,立即生效和下周期生效)

 系统内有普通的 1.通用指标(不分专业,默认每个班组必填),

                           2.专业指标(每个指标默认归属于对应专业的班组)

所以每个班组默认归属的指标:默认归属的通用指标+本班组对应专业的指标

                     默认不归属的指标:专业指标中和本班组专业不同的指标

指标管理员可以设置默认不归属的归属,默认归属的不归属

并且可以设置本周期生效和下周期生效

还可以设置每个周期起始月份

排除指标时,按默认归属/不归属立马/下周期生效可以大致分为四种情况测试:

如果是归属本班组的指标要排除

1、如果是立马生效=========

2、如果是将来生效=========

如果是本不归属本班组的指标,现在又需要排除不再受指标a考核

3、如果是立马生效=========

4、如果是将来生效=========

数据库c_team_index表:

需求:

1、将当前归属于本班组的指标排除(本篇)

指标管理员可以将本归属于本班组的指标排除掉,不用继续考核,并分为:

立马生效:从当前周期就开始不用考核,不归属于本班组,排除立马生效

下周期生效:当前周期不变,依然归属,需要等到下周期才不归属,排除掉

这里内部代码需要注意的点:

如果是本归属本班组的指标排除

      则需要判断在连表:肯定没有生效的排除记录,不然就是已经排除的指标(fail)

如果是本不归属本班组的指标排除

     则需要判断判断连表:肯定有生效的包含记录,不然就还没归属本班组,不需要排除

2、将当前不归属于本班组的指标添加(本篇)

指标管理员可以将本不归属于本班组的指标添加进来,不用继续考核,并分为:

立马生效:从当前周期就开始考核,归属于本班组,添加立马生效

下周期生效:当前周期不变,依然不归属,需要等到下周期才归属,添加

这里内部代码需要注意的点:

如果是本不归属本班组的指标添加

     则需要判断判断连表:肯定没有生效的包含记录,不然就已经归属本班组了,不需要再添加

如果是本归属本班组的指标添加

      则需要判断在连表:肯定有生效的排除记录,不然就是还处于归属的指标,不需要添加(fail)

注意点:填报周期不一定非是每年的年初开始,例如本项目是从上年的十二月份就开始了,所以我在全局变量表中配置了一个评分周期月偏移量参数

 -1代表默认的一月往前偏移一个月,即前一年十二月开始本周期填报,以此类推

同时,全局参数表中还有评分周期年份,自增1后成为下周期,得到月偏移量后,根据正负来判定是否推到前一年下半年:

int mon = 1;
if (offserMon < 0) {
    nextscoreCycle--;
    mon = 13 + offserMon;
}

再得到下周期详细时间:

String nextTimes = nextscoreCycle + "-" + mon + "-01 00:00:00";
DateTimeFormatter de = DateTimeFormatter.ofPattern(FORMAT, Locale.CHINA);
//下一周期生效具体时间
LocalDateTime nextTime = LocalDateTime.parse(nextTimes, de);
(FORMAT是上面的常量FORMAT = "yyyy-MM-dd HH:mm:ss"
LocalDateTime nowTime = LocalDateTime.parse(timeStr1, da);
//班组创建时间
LocalDateTime beginTeamTime = oldTeam.getData().getCreateTime();
//最大失效时间
LocalDateTime maxFaulureTime = LocalDateTime.parse(FAILURE_TIME, da);

功能代码结构:

一、排除指标 接口:(把本 属于本专业的指标排除)

如果指标默认归属本班组,判断指标在c_team_index表中必须没有生效的排除记录

1、如果是立马生效,c_team_index表新增,生效时间为now 失效时间设置为2036

include_or_exclude值为1(排除) status为1

2、如果是将来生效,c_team_index表新增,生效时间为下一周期起始月

失效时间设置2036 include_or_exclude值为1(排除) status为1

如果指标默认不归属本班组,现在又需要排除不再考核,那肯定表里肯定有之前的包含记录

3、如果是立马生效,失效时间为失效时间设置为now

status为0(状态改不可用即可)

4、如果是将来生效,失效时间设置(下一周期起始月份1号0时0分0秒)

的前一秒 status为0

二、添加指标 接口(把本 不属于本专业的指标添加给本班组)

如果指标默认不归属班组,指标在c_team_index表中肯定没有生效的包含记录,

1、如果是立马生效,c_team_index新增,include_or_exclude值为0(包含),status为1, begin_time为now(), end_time 为 2036...

2、如果是将来生效,c_team_index新增,include_or_exclude值为0(包含),status为1, begin_time为下一周期起始月份1号0时0分0秒, end_time 为 2036...

如果指标默认归属班组,指标在c_team_index表中肯定有生效的排除记录,现在要重新又要考核

3、如果是立马生效,status为0, 失效end时间为now (下周期一开始排除记录就没作用了,下周期不排除,即从下周期一开始就不排除,要考核)

4、如果是将来生效,status为0, 失效(下一周期起始月份1号0时0分0秒)的前一秒

常量声明

//指标排除  /不归属
public static final int INCLUDER_OR_EXCLUDE = 1;
//包含指标  /归属
public static final int CONTION_OR_EXCLUDE = 0;
public static final String FORMAT = "yyyy-MM-dd HH:mm:ss";
public static final String FAILURE_TIME = "2036-12-31 23:59:59";
//指标立马生效
public static final Integer IS_NOW_EFFECT = 1;
//归属当前班组
public static final Integer INCLUDER_OR_EXCLUDER = 0;
//通用指标类型
public static final Long COMMON_INDEX_TYPE = 0L;

校验:

 
msg = "userId和teamId不能为空";
msg = "通过班组标识获取可用的班组列表失败,请输入有效的teamId";(班组表查不到)
msg = "通过指标标识获取指标失败,请输入有效的indexId";(指标表查不到)
msg = "通过指标标识获取的指标不可用,请输入有效的indexId";(指标状态)

11

排除指标接口  四种情况测试情况解析:

1、归属本班组的指标要排除,并且立马生效=========

2、归属本班组的指标要排除,并且将来生效=========

3、不归属本班组的指标要排除,并且立马生效=========

 4、不归属本班组的指标要排除,并且将来生效=========

 

 //排除指标填报评分任务
    @Override
    public R<String> cancelindexFillTasks(IndexTeamVO indexTeamVO) {
        String msg;
        Long teamId = indexTeamVO.getTeamId();
        Long indexId = indexTeamVO.getIndexId();
        int isNowEffect = indexTeamVO.getIsNowEffect();

        //当前时间                                    //班组创建时间//LocalDateTime beginTime=teamListR.getData().get(0).getCreateTime();
        String timeStr1 = LocalDateTime.now().format(DateTimeFormatter.ofPattern(FORMAT, Locale.CHINA));
        DateTimeFormatter df = DateTimeFormatter.ofPattern(FORMAT, Locale.CHINA);
        LocalDateTime nowTime = LocalDateTime.parse(timeStr1, df);

        //下一周期起始时间

        ParameterDTO p = new ParameterDTO();
        p.setKey(INDEX_SCORE_CYCLE);
        R<List<ParameterGradeValueDTO>> cycle = authorityApi.getValueByKey(p);
        if (null == cycle.getData() || cycle.getData().isEmpty()) {
            msg = "系统测试获取失败:评分周期";
            log.error(msg);
            return R.fail(msg);
        }
        //先获取当前评分周期
        int scoreCycle = Integer.parseInt(cycle.getData().get(0).getLeftValue());
        //默认下一周期
        int nextscoreCycle = ++scoreCycle;

        ParameterDTO p1 = new ParameterDTO();
        p1.setKey(SCORE_OFFSET_MON);
        R<List<ParameterGradeValueDTO>> offser = authorityApi.getValueByKey(p1);
        if (null == offser.getData() || offser.getData().isEmpty()) {
            msg = "系统测试获取失败:评分周期月份偏移量";
            log.error(msg);
            return R.fail(msg);
        }
        //和月偏移量
        int offserMon = Integer.parseInt(offser.getData().get(0).getLeftValue());

        int mon = 1;
        if (offserMon < 0) {
            nextscoreCycle--;
            mon = 13 + offserMon;
        }
        String nextTimes = nextscoreCycle + "-" + mon + "-01 00:00:00";
        DateTimeFormatter de = DateTimeFormatter.ofPattern(FORMAT, Locale.CHINA);
        //下一周期生效具体时间
        LocalDateTime nextTime = LocalDateTime.parse(nextTimes, de);

        /最大失效时间
        LocalDateTime maxFaulureTime = LocalDateTime.parse(FAILURE_TIME, de);

        if (null == teamId || null == indexId) {
            msg = "userId和teamId不能为空";
            log.error(msg);
            return R.fail(msg);
        }

        List<Long> teamIds = new ArrayList<>();
        teamIds.add(teamId);

        TeamNameDTO dto = new TeamNameDTO(teamIds, null, null, null, null, null, false);
        R<List<Team>> teamListR = authorityApi.getAllTeam(dto);

        if (teamListR.getData() == null || teamListR.getData().isEmpty()) {
            msg = "通过班组标识获取可用的班组列表失败,请输入有效的teamId";
            log.error(msg);
            return R.fail(msg);
        }

        //所有通用指标集合
        List<CommonIndex> commonIndexList = commonIndexService.lambdaQuery()
                .eq(CommonIndex::getStatus, ON_STATUS)
                .eq(CommonIndex::getIndexType, COMMON_INDEX_TYPE)
                .list();

        //所有当前班组 相同专业的指标集合
        List<CommonIndex> careerIndexList = commonIndexService.lambdaQuery()
                .eq(CommonIndex::getStatus, ON_STATUS)
                .eq(CommonIndex::getIndexType, teamListR.getData().get(0).getSpecialityId())
                .list();

        //该班组 所有默认 指标
        List<CommonIndex> allIndex = new ArrayList<>();
        List<Long> allIndexId = new ArrayList<>();

        allIndex.addAll(commonIndexList);
        allIndex.addAll(careerIndexList);

        //该班组 所有默认 指标 id
        for (CommonIndex indexs : allIndex) {
            allIndexId.add(indexs.getId());
        }

        //根据指标id,班组id查 排除记录
        TeamIndex oldTeamIndexP = teamIndexService.lambdaQuery()
                .eq(TeamIndex::getIndexId, indexId)
                .eq(TeamIndex::getTeamId, teamId)
                .eq(TeamIndex::getIncludeOrExclude, INCLUDER_OR_EXCLUDE)
                .one();

        //根据指标id,班组id查 包含记录
        TeamIndex oldTeamIndexB = teamIndexService.lambdaQuery()
                .eq(TeamIndex::getIndexId, indexId)
                .eq(TeamIndex::getTeamId, teamId)
                .eq(TeamIndex::getIncludeOrExclude, CONTION_OR_EXCLUDE)
                .one();

        //指标默认归属本班---------------------------------------------------------------------
        if (allIndexId.contains(indexId)) {


            if (oldTeamIndexP != null) {
                msg = "此默认归属本班的指标已经排除,请输入有效的indexId!!";
                log.error(msg);
                return R.fail(msg);
            }

            //立马生效/
            if (IS_NOW_EFFECT == isNowEffect) {

                TeamIndex t = new TeamIndex();
                t.setTeamId(teamId);
                t.setIndexId(indexId);
                t.setStatus(ON_STATUS);
                t.setIncludeOrExclude(INCLUDER_OR_EXCLUDE);

                t.setBeginTime(nowTime);
                t.setEndTime(maxFaulureTime);//2036

                if (!teamIndexService.save(t)) {
                    msg = "新增排除的指标失败,请联系管理员或稍后重试!";
                    log.error(msg);
                    return R.fail(msg);
                }
                return R.success("新增排除的指标成功!");

            } else {

                //下一周期生效//
                TeamIndex t = new TeamIndex();
                t.setTeamId(teamId);
                t.setIndexId(indexId);
                t.setStatus(ON_STATUS);
                t.setIncludeOrExclude(INCLUDER_OR_EXCLUDE);

                t.setBeginTime(nextTime);
                t.setEndTime(maxFaulureTime);//2036

                if (!teamIndexService.save(t)) {
                    msg = "新增下一周期排除的指标失败,请联系管理员或稍后重试!";
                    log.error(msg);
                    return R.fail(msg);
                }
                return R.success("新增下一周期排除的指标成功!");
            }


        } else {
            //指标不归属本班---------------------------------------------------------------

            //肯定已有包含记录
            if (oldTeamIndexB == null) {
                msg = "此指标本不归属于当前班组,还没有添加包含记录,不需要排除!";
                log.error(msg);
                return R.fail(msg);
            }


            //立马生效
            if (IS_NOW_EFFECT == isNowEffect) {
                oldTeamIndexB.setEndTime(nowTime);//失效时间改为当前立马失效
                oldTeamIndexB.setStatus(NOT_ON_STATUS);//包含记录暂生效状态不考虑

                if (!teamIndexService.updateById(oldTeamIndexB)) {
                    msg = "本不归属本班的指标排除失败,请联系管理员或稍后重试!";
                    log.error(msg);
                    return R.fail(msg);
                }
                return R.success("本不归属本班的指标排除成功!");

            } else {//默认 本不属于本班组的 指标(已验证有包含记录)========================================

                //下一周期生效
                oldTeamIndexB.setStatus(NOT_ON_STATUS);//包含记录暂生效状态不考虑

                oldTeamIndexB.setEndTime(nextTime);
                //包含记录失效时间设置为下个周期开头失效,即下个周期就不包含此默认就不属于本班组的指标了,
                // 但当前依然生效,依然包含需要考核,这条包含记录到下个周期才失效,才不包含了不用填了


                if (!teamIndexService.updateById(oldTeamIndexB)) {
                    msg = "本不归属本班的指标设置下个周期排除失败,请联系管理员或稍后重试!";
                    log.error(msg);
                    return R.fail(msg);
                }
                return R.success("本不归属本班的指标设置下个周期排除成功!");

            }
            
        }

    }
//排除指标填报评分任务
@Override
public R<String> cancelindexFillTasks(IndexTeamVO indexTeamVO) {
    String msg;
    Long teamId = indexTeamVO.getTeamId();
    Long indexId = indexTeamVO.getIndexId();
    int isNowEffect = indexTeamVO.getIsNowEffect();

    //当前时间                                    //班组创建时间//LocalDateTime beginTime=teamListR.getData().get(0).getCreateTime();
    String timeStr1 = LocalDateTime.now().format(DateTimeFormatter.ofPattern(FORMAT, Locale.CHINA));
    DateTimeFormatter df = DateTimeFormatter.ofPattern(FORMAT, Locale.CHINA);
    LocalDateTime nowTime = LocalDateTime.parse(timeStr1, df);

    //下一周期起始时间

    ParameterDTO p = new ParameterDTO();
    p.setKey(INDEX_SCORE_CYCLE);
    R<List<ParameterGradeValueDTO>> cycle = authorityApi.getValueByKey(p);
    if (null == cycle.getData() || cycle.getData().isEmpty()) {
        msg = "系统测试获取失败:评分周期";
        log.error(msg);
        return R.fail(msg);
    }
    //先获取当前评分周期
    int scoreCycle = Integer.parseInt(cycle.getData().get(0).getLeftValue());
    //默认下一周期
    int nextscoreCycle = ++scoreCycle;

    ParameterDTO p1 = new ParameterDTO();
    p1.setKey(SCORE_OFFSET_MON);
    R<List<ParameterGradeValueDTO>> offser = authorityApi.getValueByKey(p1);
    if (null == offser.getData() || offser.getData().isEmpty()) {
        msg = "系统测试获取失败:评分周期月份偏移量";
        log.error(msg);
        return R.fail(msg);
    }
    //和月偏移量
    int offserMon = Integer.parseInt(offser.getData().get(0).getLeftValue());

    int mon = 1;
    if (offserMon < 0) {
        nextscoreCycle--;
        mon = 13 + offserMon;
    }
    String nextTimes = nextscoreCycle + "-" + mon + "-01 00:00:00";
    DateTimeFormatter de = DateTimeFormatter.ofPattern(FORMAT, Locale.CHINA);
    //下一周期生效具体时间
    LocalDateTime nextTime = LocalDateTime.parse(nextTimes, de);

    /最大失效时间
    LocalDateTime maxFaulureTime = LocalDateTime.parse(FAILURE_TIME, de);

    if (null == teamId || null == indexId) {
        msg = "userId和teamId不能为空";
        log.error(msg);
        return R.fail(msg);
    }

    List<Long> teamIds = new ArrayList<>();
    teamIds.add(teamId);

    TeamNameDTO dto = new TeamNameDTO(teamIds, null, null, null, null, null, false);
    R<List<Team>> teamListR = authorityApi.getAllTeam(dto);

    if (teamListR.getData() == null || teamListR.getData().isEmpty()) {
        msg = "通过班组标识获取可用的班组列表失败,请输入有效的teamId";
        log.error(msg);
        return R.fail(msg);
    }

    //所有通用指标集合
    List<CommonIndex> commonIndexList = commonIndexService.lambdaQuery()
            .eq(CommonIndex::getStatus, ON_STATUS)
            .eq(CommonIndex::getIndexType, COMMON_INDEX_TYPE)
            .list();

    //所有当前班组 相同专业的指标集合
    List<CommonIndex> careerIndexList = commonIndexService.lambdaQuery()
            .eq(CommonIndex::getStatus, ON_STATUS)
            .eq(CommonIndex::getIndexType, teamListR.getData().get(0).getSpecialityId())
            .list();

    //该班组 所有默认 指标
    List<CommonIndex> allIndex = new ArrayList<>();
    List<Long> allIndexId = new ArrayList<>();

    allIndex.addAll(commonIndexList);
    allIndex.addAll(careerIndexList);

    //该班组 所有默认 指标 id
    for (CommonIndex indexs : allIndex) {
        allIndexId.add(indexs.getId());
    }

    //根据指标id,班组id查 排除记录
    TeamIndex oldTeamIndexP = teamIndexService.lambdaQuery()
            .eq(TeamIndex::getIndexId, indexId)
            .eq(TeamIndex::getTeamId, teamId)
            .eq(TeamIndex::getIncludeOrExclude, INCLUDER_OR_EXCLUDE)
            .one();

    //根据指标id,班组id查 包含记录
    TeamIndex oldTeamIndexB = teamIndexService.lambdaQuery()
            .eq(TeamIndex::getIndexId, indexId)
            .eq(TeamIndex::getTeamId, teamId)
            .eq(TeamIndex::getIncludeOrExclude, CONTION_OR_EXCLUDE)
            .one();

    //指标默认归属本班---------------------------------------------------------------------
    if (allIndexId.contains(indexId)) {


        if (oldTeamIndexP != null) {
            msg = "此默认归属本班的指标已经排除,请输入有效的indexId!!";
            log.error(msg);
            return R.fail(msg);
        }

        //立马生效/
        if (IS_NOW_EFFECT == isNowEffect) {

            TeamIndex t = new TeamIndex();
            t.setTeamId(teamId);
            t.setIndexId(indexId);
            t.setStatus(ON_STATUS);
            t.setIncludeOrExclude(INCLUDER_OR_EXCLUDE);

            t.setBeginTime(nowTime);
            t.setEndTime(maxFaulureTime);//2036

            if (!teamIndexService.save(t)) {
                msg = "新增排除的指标失败,请联系管理员或稍后重试!";
                log.error(msg);
                return R.fail(msg);
            }
            return R.success("新增排除的指标成功!");

        } else {

            //下一周期生效//
            TeamIndex t = new TeamIndex();
            t.setTeamId(teamId);
            t.setIndexId(indexId);
            t.setStatus(ON_STATUS);
            t.setIncludeOrExclude(INCLUDER_OR_EXCLUDE);

            t.setBeginTime(nextTime);
            t.setEndTime(maxFaulureTime);//2036

            if (!teamIndexService.save(t)) {
                msg = "新增下一周期排除的指标失败,请联系管理员或稍后重试!";
                log.error(msg);
                return R.fail(msg);
            }
            return R.success("新增下一周期排除的指标成功!");
        }


    } else {
        //指标不归属本班---------------------------------------------------------------

        //肯定已有包含记录
        if (oldTeamIndexB == null) {
            msg = "此指标本不归属于当前班组,还没有添加包含记录,不需要排除!";
            log.error(msg);
            return R.fail(msg);
        }


        //立马生效
        if (IS_NOW_EFFECT == isNowEffect) {
            oldTeamIndexB.setEndTime(nowTime);//失效时间改为当前立马失效
            oldTeamIndexB.setStatus(NOT_ON_STATUS);//包含记录暂生效状态不考虑

            if (!teamIndexService.updateById(oldTeamIndexB)) {
                msg = "本不归属本班的指标排除失败,请联系管理员或稍后重试!";
                log.error(msg);
                return R.fail(msg);
            }
            return R.success("本不归属本班的指标排除成功!");

        } else {//默认 本不属于本班组的 指标(已验证有包含记录)========================================

            //下一周期生效
            oldTeamIndexB.setStatus(NOT_ON_STATUS);//包含记录暂生效状态不考虑

            oldTeamIndexB.setEndTime(nextTime);
            //包含记录失效时间设置为下个周期开头失效,即下个周期就不包含此默认就不属于本班组的指标了,
            // 但当前依然生效,依然包含需要考核,这条包含记录到下个周期才失效,才不包含了不用填了


            if (!teamIndexService.updateById(oldTeamIndexB)) {
                msg = "本不归属本班的指标设置下个周期排除失败,请联系管理员或稍后重试!";
                log.error(msg);
                return R.fail(msg);
            }
            return R.success("本不归属本班的指标设置下个周期排除成功!");

        }
        
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值