Blame view

src/main/java/com/xkl/service/ScoreServiceImpl.java 3.43 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
package com.xkl.service;

import com.xkl.config.Constants;
import com.xkl.domain.XklAmpReportDetailEntity;
import com.xkl.domain.XklAmpReportEntity;
import com.xkl.domain.XklAmpReportHealthScoreEntity;
import com.xkl.domain.XklAmpReportMetaScoreStandardEntity;
import com.xkl.repository.XklAmpReportDetailRespository;
import com.xkl.repository.XklAmpReportHealthScoreRespository;
import com.xkl.repository.XklAmpReportRespository;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Created by win7 on 2016/11/21.
 */
@Service
@CommonsLog
public class ScoreServiceImpl implements IScoreService,Constants{
    @Autowired
    private XklAmpReportRespository xklAmpReportRespository;
    @Autowired
    private XklAmpReportDetailRespository xklAmpReportDetailRespository;
    @Autowired
    private XklAmpReportHealthScoreRespository xklAmpReportHealthScoreRespository;

    @Override
fangyeqing authored
31
    public double getScore(long report_id) {
32 33
        Map<Integer,Double> typeScoreMap=new HashMap<>();//记录各大项打分的Map
34 35 36
        /**
         * report_detail表中获取每项体检的值,按大类存入typeScoreMap
         */
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
        List<XklAmpReportDetailEntity> reportDetailList=xklAmpReportDetailRespository.findAllByReportId(report_id);

        for(XklAmpReportDetailEntity detail:reportDetailList){

            int item_id=detail.getItemId();
            XklAmpReportMetaScoreStandardEntity scoreStandard= scoreMap.get(item_id);//从定时加载的打分map中取出该体检小项

            if(scoreStandard!=null) {
                double score = scoreStandard.getScore(detail.getItemValue());
                int item_type = scoreStandard.getItemType();

                if(typeScoreMap.containsKey(item_type)){//将分类中的每个大项中分数相加
                    double type_score=typeScoreMap.get(item_type)+score;
                    typeScoreMap.put(item_type,type_score);
                }else{
                    typeScoreMap.put(item_type,score);
                }
            }

        }
        /**
         *  循环每类得分的typeScoreMap,计算总得分
         */
        double finalScore=0;
        List<XklAmpReportHealthScoreEntity> saveScoreList=new ArrayList<>();

        Iterator<Map.Entry<Integer,Double>> it=typeScoreMap.entrySet().iterator();
        while(it.hasNext()){
            Map.Entry<Integer, Double> entry = it.next();
            int item_type = entry.getKey();
            double score = entry.getValue();

            XklAmpReportHealthScoreEntity scoreEntity=new XklAmpReportHealthScoreEntity();
            scoreEntity.setReportId(report_id);
            scoreEntity.setType(item_type);
            scoreEntity.setTypeHealthScore(score);
            saveScoreList.add(scoreEntity);
fangyeqing authored
75 76
            double weightedScore=weightedScoreMap.get(item_type).getScoreWeight();
            finalScore += weightedScore*score;
77 78 79 80 81 82 83 84 85 86 87 88 89
        }
        /**
         * 每类得分存入xkl_amp_report_health_scroe
         * 总得分存入xkl_amp_report
         */
        if(saveScoreList!=null&&saveScoreList.size()>0)
            xklAmpReportHealthScoreRespository.save(saveScoreList);

        XklAmpReportEntity report=xklAmpReportRespository.findOne(report_id);
        if(report!=null){
            report.setScore(finalScore);
            xklAmpReportRespository.save(report);
        }
fangyeqing authored
90
        return finalScore;
91 92
    }
}