1. QuestionnairesService类中:
/** * 获取岗位id-问卷id的映射, 一个岗位可能会对应两份试卷(业绩卷、能力态度卷) * * @return */ public Multimap<Long, Long> getPostQuestMap() { // 当前考评周期 AppraisalPeriod period = testingService.getLast().getAppraisalPeriod(); Multimap<Long, Long> postQuestMap = ArrayListMultimap.create(); List<Questionnaires> questList = questionnairesDao .findAll(new Questionnaires().enable()); for (Questionnaires quest : questList) { if (quest.getPost() != null && quest.getAppraisalCycle().getAppraisalPeriod() .equals(period)) { postQuestMap.put(quest.getPost().getId(), quest.getId()); } } return postQuestMap; }
2. JXUserService中
/** * 获得用户id-岗位id的映射(userId, postId) * * @return */ public Map<Long, Long> getUserPostMap(List<JXUser> userList) { Map<Long, Long> userPostMap = new HashMap<Long, Long>(); for (JXUser user : userList) userPostMap.put(user.getId(), user.getPost().getId()); return userPostMap; }
3. JXUserService中
/** * 获得岗位id-用户id的多Key映射(postId, userId) * * @return */ public Multimap<Long, Long> getPostUsersMap(List<JXUser> userList) { Multimap<Long, Long> postUsersMap = ArrayListMultimap.create(); for (JXUser user : userList) postUsersMap.put(user.getPost().getId(), user.getId()); return postUsersMap; }
4. JXUserService中
/** * 被评用户id-评分用户id,岗位评分关系PostScoreRelation映射表 * @return */ public MultiKeyMap<Long, PostScoreRelation> findTestingParam() { //输出对象 MultiKeyMap<Long, PostScoreRelation> multiMap = new MultiKeyMap<Long, PostScoreRelation>(); List<JXUser> userList = userDao.findAll(new JXUser().enable()); //岗位-用户(postId,userIds) Multimap<Long, Long> postUsersMap = getPostUsersMap(userList); Map<Long, Collection<Long>> postUsers = postUsersMap.asMap(); //用户-岗位(userId,postId) Map<Long, Long> userPostMap = getUserPostMap(userList); //用户-问卷(postId,questionnaireIds) Multimap<Long, Long> postQuestMap = questService.getPostQuestMap(); Map<Long, Collection<Long>> postQuests = postQuestMap.asMap(); // 获得评分关系 List<PostScoreRelation> psrList = postService.findPSRs(); for (PostScoreRelation psr : psrList) { //根据岗位评分关系遍历 Collection<Long> userIds = postUsers.get(psr.getPost().getId()); // 被评岗位id->被评用户userIds; Collection<Long> questIds = postQuests.get(psr.getPost().getId()); // 被评岗位id->问卷questIds; for (Long questid : questIds) { // 被评用户岗位试卷遍历 for (Long userid : userIds) { // 被评用户遍历 Collection<Long> eavlUserIds = postUsers.get(psr .getPostMap().getId()); // 评分岗位id for (Long eavluserid : eavlUserIds) { multiMap.put(userid,eavluserid,questid, psr); //被评用户id-评分用户id-问卷, 岗位评分关系 } } } } return multiMap; }
时间: 2024-10-28 13:21:39