优秀代码的使用

优秀代码的使用

功能:获取一个职位中的招聘订单中的:新投递人数,待面试人数,已录用人数。
在这里插入图片描述

1实现层serviceimpl代码:
   //带面试 待入职 已入职人数count
                        List<Long> projectId = new ArrayList<>();
                        projectId.add(PositionId);
                        List<ApplyStatusEnum> status = new ArrayList<>();
                        status.add(ApplyStatusEnum.AlreadyEmployed);
                        status.add(ApplyStatusEnum.To_Be_Interviewed);
                        status.add(ApplyStatusEnum.Waiting_For_Entry);
                        status.add(ApplyStatusEnum.New_Delivery);
                        List<Map<String, Integer>> applyCountByDemandIdsAndApplyStatus = getApplyCountByDemandIdsAndApplyStatus(projectId, status);
                        for (Map<String , Integer> count: applyCountByDemandIdsAndApplyStatus) {
                            Integer getpositionId = count.get("demandId");
                            if( getpositionId !=null ){
                                if(PositionId == getpositionId.longValue()){
                                    Integer interViewCount = count.get(ApplyStatusEnum.To_Be_Interviewed.getDesc());
                                    Integer entryCount = count.get(ApplyStatusEnum.Waiting_For_Entry.getDesc());
                                    Integer entrySsucessCount = count.get(ApplyStatusEnum.AlreadyEmployed.getDesc());
                                    Integer applyCount = count.get(ApplyStatusEnum.New_Delivery.getDesc());
                                    demand.setEntrySuccessCount(entrySsucessCount);
                                    demand.setEntryCount(entryCount);
                                    demand.setInterViewCount(interViewCount);
                                    demand.setApplyCount(applyCount);
                                    break;
                                }
                            }
                        }
2.一层层的级联查询代码:
 /**
     * 获取多个职位,多个状态的订单统计数据
     */
    @Override
    @CheckParam("demandIds,status")
    public List<Map<String,Integer>> getApplyCountByDemandIdsAndApplyStatus(List<Long> demandIds,List<ApplyStatusEnum> status){
        final LinkedList<Map<String,Integer>> result = new LinkedList<Map<String,Integer>>();
        demandIds.forEach(demandId -> result.addLast(getApplyCountByDemandIdAndApplyStatus(demandId,status)));
        return result;
    }

    /**
     * 获取一个职位的,多个状态的订单统计数据
     * @param demandId
     * @param status
     * @return
     */
    @CheckParam("demandId,status")
    private Map<String,Integer> getApplyCountByDemandIdAndApplyStatus(Long demandId, List<ApplyStatusEnum> status) {
        final Map<String,Integer> result = new HashMap<>();
        result.put("demandId",demandId.intValue());
        status.forEach(applyEnum -> result.put(applyEnum.getDesc(),getApplyCountByDemandIdAndApplyState(demandId,applyEnum)));
        return  result;
    }

    /**
     * 获取一个职位的,一个状态的订单统计数据
     * @param result
     * @param demandId
     * @param applyEnum
     */
    private Integer getApplyCountByDemandIdAndApplyState( Long demandId, ApplyStatusEnum applyEnum) {
        Map<String,Object> params = new HashMap<>();
        params.put("demandId",demandId);
        params.put("stateArr",applyEnum.getValue());
        Long count = demandDao.getApplyCountByDemandIdAndApplyState(params);
        return count == null ? 0 : count.intValue();
    }
3.具体的sql内容:
 <select id="getApplyCountByDemandIdAndApplyState" resultType="long">
        SELECT COUNT(id)
        FROM apply_base
        WHERE
        project_id = #{demandId}
        AND flow_node in
        <foreach collection="stateArr" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
4.其中使用到的枚举enum 具体的数据代表着订单节点数值
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ylkz.enums;

public enum ApplyStatusEnum {
    New_Delivery("新投递", new int[]{11, 12, 17}),
    To_Be_Interviewed("待面试", new int[]{21, 24, 25, 26}),
    Waiting_For_Entry("待入职", new int[]{27, 31, 33}),
    AlreadyEmployed("已入职", new int[]{35, 36, 41, 45});

    private String desc;
    private int[] value;

    private ApplyStatusEnum(String desc, int[] value) {
        this.desc = desc;
        this.value = value;
    }

    public String getDesc() {
        return this.desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public int[] getValue() {
        return this.value;
    }

    public void setValue(int[] value) {
        this.value = value;
    }
}

5.总结:其中比较好的是代码级联查询的使用以及LinkedList的使用使得我们的代码显示更加的简洁优雅。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值