list列表按照实体类中某个属性排序

    技术2022-07-13  78

    接将数据库中同一用户的各类分数相加一文,获得最终评价分列表后,会发现还有一个问题,就是获取到列表后,由于每期评价表的人员得分并不同,所以即使每期数据是按照总评价分升序排序的,但是分数相加后排序会乱,所以现在需将得到的列表按照总评价分升序,分数相同的按照人员职务排序,如下:

    service:

    /**      * 获取自评价子表列表      * @param weekScoreZpj      * @return      */     public List<WeekScoreZpjDet> findWeekScoreZpjDetList(WeekScoreZpj weekScoreZpj){         String zpjDate = dao.findZpjDate(weekScoreZpj.getCountTime());         if(StringUtils.isBlank(zpjDate)){             return null;         }         String preMonth = DateUtils.formatDate(DateUtils.addMonth(weekScoreZpj.getCountTime(), -1), "yyyy-MM-dd");         String[] sendDate = zpjDate.split(",");         List<WeekScoreZpjDet> detList = dao.findWeekScoreZpjDetList(preMonth, sendDate[0]);         for (int i = 1; i < sendDate.length; i++) {             addAllList(detList, dao.findWeekScoreZpjDetList(preMonth, sendDate[i]));         }         Collections.sort(detList, (o1, o2) -> {             return o1.getAllScore() == o2.getAllScore() ? compareTo(o1.getWork(), o2.getWork()) : o1.getAllScore() - o2.getAllScore();         });         return detList;     }

    添加按照职务排序的方法:

    private int compareTo(String work1, String work2) {         Map<String, Integer> map = new HashMap<>(16);         map.put("项目助理", 9);         map.put("部门副经理", 8);         map.put("部门经理", 7);         map.put("技术总监(兼)部门经理", 6);         map.put("技术总监", 5);         map.put("高级总监", 4);         map.put("质量总监", 3);         map.put("副总经理", 2);         map.put("常务副总经理", 1);         return map.get(work1) - map.get(work2);     }

     

    Processed: 0.013, SQL: 9