ts人员报表统计

@PostMapping("/specialPersonTrackStatement")
@ResponseBody
public Object getSpecialPersonTrackStatement(@RequestBody SpecialPersonTrackStatementSearchVO statementSearchVO) {
    return specialPersonSupportSituationService.getSpecialPersonTrackStatement(statementSearchVO);
}


@Override
public List<SpecialPersonTrackStatementBranchVO> getSpecialPersonTrackStatement(SpecialPersonTrackStatementSearchVO statementSearchVO) {
    QueryWrapper<HardUnion> wrapper = new QueryWrapper<>();
    wrapper.eq("is_deleted", false);
    //获取所有的工会信息
    List<HardUnion> hardUnionList = hardUnionMapper.selectList(wrapper);
    List<Integer> branchIdList = hardUnionList.stream().map(HardUnion::getId).collect(Collectors.toList());

    String startTime = startTime(statementSearchVO);
    String endTime = endTime(statementSearchVO);

    //入库和出库统计
    List<SpecialPersonTrackStatementBranchVO> trackStatementCountList =
            specialPersonSupportSituationMapper.trackStatementInOrOutCount(branchIdList, startTime, endTime, statementSearchVO.getUnionId());
    Map<Integer, SpecialPersonTrackStatementBranchVO> trackStatementInOrOutCountMap =
            trackStatementCountList.stream()
                    .collect(Collectors.toMap(SpecialPersonTrackStatementBranchVO::getUnionId, Function.identity(), (key1, key2) -> key2));

    //已走访统计
    List<SpecialPersonTrackStatementBranchVO> alreadyInterviewCountList =
            specialPersonSupportSituationMapper.alreadyInterviewCount(branchIdList, startTime, endTime, statementSearchVO.getUnionId());
    Map<Integer, SpecialPersonTrackStatementBranchVO> alreadyInterviewCountMap =
            alreadyInterviewCountList.stream()
                    .collect(Collectors.toMap(SpecialPersonTrackStatementBranchVO::getUnionId, Function.identity(), (key1, key2) -> key2));

    //拼接超期时间
    String outTime = getOutTime(statementSearchVO);

    //按期走访统计
    List<SpecialPersonTrackStatementBranchVO> punctualInterviewCountList =
            specialPersonSupportSituationMapper.punctualInterviewCount(branchIdList, startTime, endTime, statementSearchVO.getUnionId(), outTime);
    Map<Integer, SpecialPersonTrackStatementBranchVO> punctualInterviewCountMap =
            punctualInterviewCountList.stream()
                    .collect(Collectors.toMap(SpecialPersonTrackStatementBranchVO::getUnionId, Function.identity(), (key1, key2) -> key2));


    trackStatementCountList.stream().forEach(e -> {

        int alreadyInterviewCount = 0;
        int existCount = 0;
        int punctualInterviewCount = 0;
        if (ObjectUtils.isNotEmpty(alreadyInterviewCountMap.get(e.getUnionId()))) {
            //设置已走访数
            alreadyInterviewCount = alreadyInterviewCountMap.get(e.getUnionId()).getAlreadyInterviewCount();
            e.setAlreadyInterviewCount(alreadyInterviewCount);
        }
        if (ObjectUtils.isNotEmpty(trackStatementInOrOutCountMap.get(e.getUnionId()))){
            //设置未走访数
            existCount = trackStatementInOrOutCountMap.get(e.getUnionId()).getExistCount();
            e.setNotInterviewCount(existCount-alreadyInterviewCount);
        }
        if (ObjectUtils.isNotEmpty(punctualInterviewCountMap.get(e.getUnionId()))) {
            //设置按期走访
            e.setPunctualInterviewCount(punctualInterviewCountMap.get(e.getUnionId()).getPunctualInterviewCount());
            punctualInterviewCount = punctualInterviewCountMap.get(e.getUnionId()).getPunctualInterviewCount();
        }
        //设置超期走访
        e.setOvertimeInterviewCount(alreadyInterviewCount-punctualInterviewCount);
        //总数
        e.setCount(e.getExistCount() + e.getNotExistCount());
    });

    //所有的数据
    List<SpecialPersonTrackStatementBranchVO> statementBranchList = setUnionDefaultValue(trackStatementCountList, hardUnionList);
    if (ObjectUtils.isEmpty(statementSearchVO.getUnionId())){
        return statementBranchList;
    }
    ArrayList<SpecialPersonTrackStatementBranchVO> specialPersonTrackStatementBranchVOS = new ArrayList<>();
    Map<Integer, SpecialPersonTrackStatementBranchVO> statementBranchMap =
            statementBranchList.stream()
                    .collect(Collectors.toMap(SpecialPersonTrackStatementBranchVO::getUnionId, Function.identity(), (key1, key2) -> key2));
    specialPersonTrackStatementBranchVOS.add(statementBranchMap.get(statementSearchVO.getUnionId()));
    return specialPersonTrackStatementBranchVOS;
    
}


//补充信息
private List<SpecialPersonTrackStatementBranchVO> setUnionDefaultValue(
        List<SpecialPersonTrackStatementBranchVO> trackStatementList, List<HardUnion> hardUnionList) {

    List<SpecialPersonTrackStatementBranchVO> trackStatementAllList = Lists.newArrayList();
    Map<Integer, SpecialPersonTrackStatementBranchVO> trackStatementMap =
            trackStatementList.stream()
                    .collect(Collectors.toMap(SpecialPersonTrackStatementBranchVO::getUnionId, Function.identity(), (key1, key2) -> key1));
    hardUnionList.stream().forEach(e -> {
        SpecialPersonTrackStatementBranchVO trackStatementVO = trackStatementMap.get(e.getId());
        if (ObjectUtils.isEmpty(trackStatementVO)) {
            trackStatementVO = new SpecialPersonTrackStatementBranchVO();
        }
        trackStatementVO.setUnionName(e.getName());
        trackStatementVO.setUnionId(e.getId());
        trackStatementVO.setShowName(e.getShowName());
        trackStatementAllList.add(trackStatementVO);
    });
    return trackStatementAllList;
}

public String startTime(SpecialPersonTrackStatementSearchVO statementSearchVO){
    if (ObjectUtils.isEmpty(statementSearchVO.getYear())){
        return null;
    }
    String result = null;
    try {
        //定义时间区间
        StringBuilder stringBuilder;
        if (StringUtils.isEmpty(statementSearchVO.getSeason())){
            stringBuilder = new StringBuilder();
            String startTime = stringBuilder.append(statementSearchVO.getYear()).append("-").append(SpecialPersonEnum.getMonth.GET_MONTH_0).toString();
            result =  DateUtils.format(DateUtils.parse(startTime, 1), 2);
        }else {
            stringBuilder = new StringBuilder();
            String startTime = stringBuilder.append(statementSearchVO.getYear()).append("-").append(SpecialPersonEnum.getMonth.GET_MONTH_ARR[Integer.parseInt(statementSearchVO.getSeason())]).toString();;
            result = DateUtils.format(DateUtils.parse(startTime, 1), 2);
        }
    } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
        LogUtils.error("特殊人员根据季度获取开始时间startTime异常,season={}", statementSearchVO.getSeason(), e);
    }
    return result;
}

public String endTime(SpecialPersonTrackStatementSearchVO statementSearchVO){
    if (ObjectUtils.isEmpty(statementSearchVO.getYear())){
        return null;
    }

    String result = null;
    try {
        //定义时间区间
        StringBuilder stringBuilder;
        if (StringUtils.isEmpty(statementSearchVO.getSeason())){
            String year = statementSearchVO.getYear();
            Integer newYear = Integer.parseInt(year)+1;
            stringBuilder = new StringBuilder();
            String endTime = stringBuilder.append(newYear.toString()).append("-").append(SpecialPersonEnum.getMonth.GET_MONTH_0).toString();
            result =  DateUtils.format(DateUtils.parse(endTime, 1), 2);
        }else {
            stringBuilder = new StringBuilder();
            String startTime = stringBuilder.append(statementSearchVO.getYear()).append("-").append(SpecialPersonEnum.getMonth.GET_MONTH_ARR[Integer.parseInt(statementSearchVO.getSeason())]).toString();
            Calendar calendar = Calendar.getInstance();
            Date parse = DateUtils.parse(startTime, 1);
            calendar.setTime(parse);
            calendar.add(Calendar.MONTH, +3);
            result =  DateUtils.format(calendar.getTime(), 2);
        }
    } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
        LogUtils.error("特殊人员根据季度获取结束时间endTime异常,season={}", statementSearchVO.getSeason(), e);
    }
    return result;
}

//拼接超时时间
public String getOutTime(SpecialPersonTrackStatementSearchVO statementSearchVO){
    String result = "";
    try {
        String year = statementSearchVO.getYear();
        StringBuilder sb = new StringBuilder();
        //根据季度获取季度最后一个月份
        //查询超时的具体某日
        SpecialConfig specialConfig = specialConfigMapper.selectOne(new QueryWrapper<SpecialConfig>().eq("content_type", "out_time"));

        sb.append(year).append("-")
                .append(SpecialPersonEnum.outTime.OUT_TIME_ARR[Integer.parseInt(statementSearchVO.getSeason())])
                .append("-").append(specialConfig.getCustomDate());
        result = DateUtils.format(DateUtils.parse(sb.toString(), 1), 2);

    } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
        LogUtils.error("根据季度获取超时时间异常,outTime={}", statementSearchVO.getSeason(), e);
    }
    return result;

}


<update id="deleteSpecialPersonSupportSituation">
    update  special_person_support_situation set deleted =1,modify_time=now()
    where
    <if test="ids!=null and ids.size>0">
        id not in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
        and
    </if>
    special_person_id=#{specialPersonId}
</update>


<update id="deleteSpecialPersonSupportSituationByIds">
    update  special_person_support_situation set deleted =1,modify_time=now()
    where
    <if test="ids!=null and ids.size>0">
        id =
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
        and deleted =0
    </if>
</update>


<update id="updateSupportSituationById" parameterType="com.yutong.hard.web.entity.SpecialPersonSupportSituation">
    update special_person_support_situation
    <set>
        modify_time = now(),
        <if test="data.interviewDate!=null">
            interview_date = #{data.interviewDate} ,
        </if>
        <if test="data.interviewType!=null and data.interviewType!=''">
            interview_type = #{data.interviewType} ,
        </if>
        <if test="data.situationExplain!=null and data.situationExplain!=''">
            situation_explain = #{data.situationExplain} ,
        </if>
        <if test="data.modifyCode!=null and data.modifyCode!=''">
            modify_code = #{data.modifyCode} ,
        </if>
        <if test="data.modifyName!=null and data.modifyName!=''">
            modify_name = #{data.modifyName} ,
        </if>
    </set>
    where id = #{data.id}
</update>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值