1. 程式人生 > 其它 >監測員工離職傾向的好處

監測員工離職傾向的好處

一、新增一個比較器

點選檢視程式碼
import java.util.Comparator;

/**
 * @Classname ComparatorResultType
 * @Description 排序比較器(金牌師傅推薦-分頁中使用)
 * @Date 2022/3/10 11:19
 * @Created by 小郭
 */
public class ComparatorResultType implements Comparator {
    @Override
    public int compare(Object arg0, Object arg1) {

        //MasterPageVO是查詢資料的實體類,自己根據業務替換掉
        MasterPageVO masterPageVO0=(MasterPageVO)arg0;
        MasterPageVO masterPageVO1=(MasterPageVO)arg1;
        //首先比較主指標,如果主指標相同,則比較次指標
        int flag=masterPageVO0.getScore().compareTo(masterPageVO1.getScore());
        if(flag==0){
            return masterPageVO0.getOrderCount().compareTo(masterPageVO1.getOrderCount());

        }else{
            return flag;
        }
    }
}

二、業務程式碼

點選檢視程式碼
@Override
    public PageData<MasterPageVO> getMasterPage(Map<String, Object> params) {

        List<MasterPageVO> voList=masterWorkerDao.getMasterPage(params);

        if (voList.size()>0 && !voList.isEmpty()) {
            for (MasterPageVO vo : voList) {
                //查詢師傅擁有的服務
                List<MasterWorkerServiceTypeVO> serviceList = masterWorkerServiceTypeDao.getServiceByMasterWorkerId(Long.parseLong(vo.getId()));
                if (serviceList.size() > 0) {
                    vo.setServiceList(serviceList);
                }
                //查詢印象評價標籤列表
                List<ImpressionEvaluationVO> impressionEvaluationVOList = masterWorkerDao.getImpressionEvaluationList(Long.parseLong(vo.getId()));
                if (impressionEvaluationVOList.size() > 0) {
                    vo.setImpressionEvaluationVOList(impressionEvaluationVOList);
                }
                //查詢評分(總評分數/接單量)
                ScoreDetailVO scoreDetailVO = masterWorkerDao.getScoreTotal(Long.parseLong(vo.getId()));
                if (scoreDetailVO.getScoreTotal() != null && scoreDetailVO.getOrderCount() != null) {
                    vo.setScore(Integer.parseInt(scoreDetailVO.getScoreTotal()) / Integer.parseInt(scoreDetailVO.getOrderCount()));
                    vo.setOrderCount(Integer.parseInt(scoreDetailVO.getOrderCount()));
                } else {
                    vo.setScore(0);
                    vo.setOrderCount(0);
                }
            }
            //根據分數降序排序
            ComparatorResultType comparator=new ComparatorResultType();
            //正常排序
            Collections.sort(voList, comparator);
            //進行降序
            Collections.reverse(voList);
        }
        return getPageData(voList, voList.size(), MasterPageVO.class);
    }