优秀代码的使用
功能:获取一个职位中的招聘订单中的:新投递人数,待面试人数,已录用人数。
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;
}
}