Kaynağa Gözat

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

trick9191 8 yıl önce
ebeveyn
işleme
02138c745f

+ 46 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/consult/EvaluateScore.java

@ -0,0 +1,46 @@
package com.yihu.wlyy.entity.consult;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Created by 卓 on 2017/5/10.
 */
@Entity
@Table(name = "wlyy_evaluate_score")
public class EvaluateScore extends IdEntity {
    private static final long serialVersionUID = -16123422342334189L;
    private String doctor;//被评价的医生
    private String consult;//咨询
    private Double score;//分数
    public String getDoctor() {
        return doctor;
    }
    public void setDoctor(String doctor) {
        this.doctor = doctor;
    }
    public String getConsult() {
        return consult;
    }
    public void setConsult(String consult) {
        this.consult = consult;
    }
    public Double getScore() {
        return score;
    }
    public void setScore(Double score) {
        this.score = score;
    }
}

+ 13 - 46
patient-co-wlyy/src/main/java/com/yihu/wlyy/job/consult/EvaluateScoreJob.java

@ -42,59 +42,26 @@ public class EvaluateScoreJob implements Job{
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        try {
            System.out.println("calculate evaluate job start");
            SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
            //获取有被评价过的医生列表
            String doctorsSql = "select w.doctor from wlyy_evaluate w group by w.doctor";
            String sql = "select w.evaluate_type,sum(w.score) as score from wlyy_evaluate w where w.doctor =? GROUP BY w.evaluate_type,w.doctor";
            String evaluateTimesSql = "select count(1) as count from wlyy_evaluate w where w.doctor =? GROUP BY w.consult,w.doctor";
            String sql = "select sum(w.score) as score from wlyy_evaluate_socre w where w.doctor =? ";
            String evaluateTimesSql = "select count(1) as count from wlyy_evaluate_socre w where w.doctor =? GROUP BY w.doctor";
            List<Map<String, Object>> doctorList = jdbcTemplate.queryForList(doctorsSql);
            for (Map<String, Object> doctorMap : doctorList) {
                //获取医生的所有评价信息
                String doctor =  doctorMap.get("doctor").toString();
                //统计总的分数
                List<Map<String, Object>> evaluateList = jdbcTemplate.queryForList(sql, new Object[]{doctor});
                BigDecimal score = BigDecimal.ZERO;//总分
                BigDecimal anonymousScore = BigDecimal.ZERO;//匿名评价分
                BigDecimal realScore = BigDecimal.ZERO;//实名评价分
                BigDecimal jiaquan = BigDecimal.ZERO;//加权平均分
                for (Map<String, Object> evaluate : evaluateList) {
                    BigDecimal scoreTemp = new BigDecimal(evaluate.get("score").toString());
                    switch (evaluate.get("evaluate_type").toString()) {
                        case "0":
                            realScore = realScore.add(scoreTemp.multiply(new BigDecimal("0.3")));
                            break;
                        case "1":
                            anonymousScore=  anonymousScore.add(scoreTemp.multiply(new BigDecimal("0.2")));
                            break;
                        case "2":
                            anonymousScore=  anonymousScore.add(scoreTemp.multiply(new BigDecimal("0.25")));
                            break;
                        case "3":
                            anonymousScore=  anonymousScore.add(scoreTemp.multiply(new BigDecimal("0.25")));
                            break;
                    }
                //统计评价次数
                List<Map<String, Object>> evaluateTimes = jdbcTemplate.queryForList(evaluateTimesSql, new Object[]{doctor});
                if(evaluateTimes!=null&&evaluateTimes.size()>0&&evaluateList!=null&&evaluateList.size()>0){
                    //计算完毕
                    BigDecimal amount = new BigDecimal(evaluateList.get(0).get("score").toString());
                    BigDecimal count = new BigDecimal(evaluateList.get(0).get("count").toString());
                    BigDecimal score = amount.divide(count,1,BigDecimal.ROUND_HALF_UP);
                    Doctor d  =  doctorDao.findByCode(doctor);
                    d.setEvaluateScore(score.doubleValue());
                    doctorDao.save(d);
                }
                //获取有效评价次数
                List<Map<String, Object>> evaluateTimesList = jdbcTemplate.queryForList(evaluateTimesSql, new Object[]{doctor});
                int evaTimes = Integer.parseInt(evaluateTimesList.get(0).get("count").toString());
                if(evaTimes>0){
                    evaTimes = evaluateTimesList.size();
                }
                int consultTimes = consultTeamDoctorDao.countByDoctorAndType(2, doctor);
                jiaquan = (anonymousScore.add(realScore)).divide(BigDecimal.valueOf(evaTimes),2,BigDecimal.ROUND_HALF_UP);
                if (consultTimes <= 100) {  //咨询系数 咨询次数≤100次,对应系数为3;
                    //100次<咨询次数≤1000次,对应系数为2;
                    //咨询次数>1000次,对应系数为1。
                    jiaquan = (jiaquan.subtract(BigDecimal.valueOf(80L))).divide(BigDecimal.valueOf(3L),2,BigDecimal.ROUND_HALF_UP);
                } else if (consultTimes > 100 && consultTimes <= 1000) {
                    jiaquan = (jiaquan.subtract(BigDecimal.valueOf(80L))).divide(BigDecimal.valueOf(2L),2,BigDecimal.ROUND_HALF_UP);
                } else {
                    jiaquan = (jiaquan.subtract(BigDecimal.valueOf(80L))).divide(BigDecimal.valueOf(1L),2,BigDecimal.ROUND_HALF_UP);
                }
                score = jiaquan.add(BigDecimal.valueOf(80L)).setScale(1, BigDecimal.ROUND_HALF_UP);
                //计算完毕
                Doctor d  =  doctorDao.findByCode(doctor);
                d.setEvaluateScore(score.doubleValue());
                doctorDao.save(d);
            }
            System.out.println("calculate evaluate job end");
        } catch (Exception e) {

+ 18 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/consult/EvaluateScoreDao.java

@ -0,0 +1,18 @@
package com.yihu.wlyy.repository.consult;
import com.yihu.wlyy.entity.consult.Evaluate;
import com.yihu.wlyy.entity.consult.EvaluateScore;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by 卓 on 2017/5/10.
 */
public interface EvaluateScoreDao extends PagingAndSortingRepository<EvaluateScore, Long>, JpaSpecificationExecutor<EvaluateScore> {
    int countEvaluateScoreByDoctor(String doctor);
}

+ 87 - 27
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/EvaluateService.java

@ -5,19 +5,22 @@ package com.yihu.wlyy.service.app.consult;
import com.yihu.wlyy.entity.consult.ConsultTeam;
import com.yihu.wlyy.entity.consult.Evaluate;
import com.yihu.wlyy.entity.consult.EvaluateLabel;
import com.yihu.wlyy.entity.consult.EvaluateScore;
import com.yihu.wlyy.repository.consult.ConsultTeamDoctorDao;
import com.yihu.wlyy.repository.consult.EvaluateDao;
import com.yihu.wlyy.repository.consult.EvaluateScoreDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.ClazzReflect;
import com.yihu.wlyy.util.ImUtill;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.math.BigDecimal;
import java.util.*;
@Component
@ -29,6 +32,12 @@ public class EvaluateService extends BaseService {
	ConsultTeamService consultTeamService;
	@Autowired
	EvaluateLabelService evaluateLabelService;
	@Autowired
	JdbcTemplate jdbcTemplate;
	@Autowired
	ConsultTeamDoctorDao consultTeamDoctorDao;
	@Autowired
	EvaluateScoreDao evaluateScoreDao;
	public void save(List<Evaluate> evaluates){
		evaluateDao.save(evaluates);
@ -38,13 +47,11 @@ public class EvaluateService extends BaseService {
		JSONObject jsonObject = new JSONObject(jsonData);
		String consult = jsonObject.getString("consult");
		ConsultTeam consultTeam  = consultTeamService.findByCode(consult);
		if(consultTeam.getEvaluate()==1){
			throw new RuntimeException("已经评价不允许重复评价!");
		}
		JSONArray evaluateArray = jsonObject.getJSONArray("evaluate");
		JSONArray labelArray = jsonObject.getJSONArray("label");
		List<Evaluate> evaluateList = new ArrayList<>();
		List<Evaluate> evaluateList =null;
		List<EvaluateLabel> evaluateLabelList = new ArrayList<>();
		Map<String,List<Evaluate>> docEvaMap = new HashMap<>();
		for(Object evaluateObj: evaluateArray){
			Evaluate evaluate = new Evaluate();
			JSONObject obj =(JSONObject) evaluateObj;
@ -52,7 +59,13 @@ public class EvaluateService extends BaseService {
			evaluate = (Evaluate)clazzReflect.formatToClazz(evaluate,obj);
			evaluate.setConsult(consult);
			evaluate.setPatient(patient);
			evaluateList.add(evaluate);
			if(docEvaMap.get(evaluate.getDoctor())==null){
				evaluateList = new ArrayList<>();
				evaluateList.add(evaluate);
				docEvaMap.put(evaluate.getDoctor(),evaluateList);
			}else{
				docEvaMap.get(evaluate.getDoctor()).add(evaluate);
			}
		}
		for(Object labelObj: labelArray){
			EvaluateLabel evaluateLabel = new EvaluateLabel();
@ -63,6 +76,8 @@ public class EvaluateService extends BaseService {
			evaluateLabel.setPatient(patient);
			evaluateLabelList.add(evaluateLabel);
		}
		//计算单条得分
		evaluateScoreCal(docEvaMap,consult);
		this.save(evaluateList);
		evaluateLabelService.save(evaluateLabelList);
		consultTeam.setEvaluate(1);
@ -106,25 +121,70 @@ public class EvaluateService extends BaseService {
	}
	private void evaluateScoreCal(Map<String,List<Evaluate>> docEvaMap,String consult){
		for(String doctor:docEvaMap.keySet()){
			BigDecimal realScore = new BigDecimal(REAL_SCORE_DEFAULT);//实名评价
			BigDecimal anonymousScore1 = new BigDecimal(ANONYMOUS_SCORE_DEFAULT_ONE);//专业能力
			BigDecimal anonymousScore2 = new BigDecimal(ANONYMOUS_SCORE_DEFAULT_TWO);//服务态度
			BigDecimal anonymousScore3 = new BigDecimal(ANONYMOUS_SCORE_DEFAULT_THREE);//回复速度
			//计算此次评价的分数来源
			for(Evaluate evaluate:docEvaMap.get(doctor)){
				if(evaluate.getEvaluateType()==0){
					realScore = BigDecimal.valueOf(evaluate.getScore());
				}else if(evaluate.getEvaluateType()==1){
					anonymousScore1 = BigDecimal.valueOf(evaluate.getScore());
				}else if(evaluate.getEvaluateType()==2){
					anonymousScore2 = BigDecimal.valueOf(evaluate.getScore());
				}else if(evaluate.getEvaluateType()==3){
					anonymousScore3 = BigDecimal.valueOf(evaluate.getScore());
				}
			}
			String evaluateTimesSql = "select count(1) as count from wlyy_evaluate w where w.doctor =? GROUP BY w.consult,w.doctor";
			//有效评价次数
			List<Map<String, Object>> evaluateTimesList = jdbcTemplate.queryForList(evaluateTimesSql, new Object[]{doctor});
			//有效咨询次数
			int consultTimes = consultTeamDoctorDao.countByDoctorAndType(2, doctor);
			BigDecimal score = BigDecimal.ZERO;//总分
			BigDecimal anonymousScore = BigDecimal.ZERO;//加权平均分笔直综合
			BigDecimal jiaquan = BigDecimal.ZERO;//加权平均分
			//加权平均分=(实名评分×30%+专业能力×20%+服务态度×25%+回复速度×25%)/有效评价次数
			anonymousScore = anonymousScore.add(realScore.multiply(new BigDecimal("0.3")));
			anonymousScore =anonymousScore.add(anonymousScore1.multiply(new BigDecimal("0.2")));
			anonymousScore =anonymousScore.add(anonymousScore2.multiply(new BigDecimal("0.25")));
			anonymousScore =anonymousScore.add(anonymousScore2.multiply(new BigDecimal("0.25")));
			int evaTimes = Integer.parseInt(evaluateTimesList.get(0).get("count").toString());
			if(evaTimes>0){
				evaTimes = evaluateTimesList.size();
			}else{
				evaTimes = 1;
			}
			jiaquan  = anonymousScore.divide(BigDecimal.valueOf(evaTimes),2,BigDecimal.ROUND_HALF_UP);//算的加权平均分
			//满意度=80+(加权平均分-80)/系数
			//咨询系数 咨询次数≤100次,对应系数为3;
			//100次<咨询次数≤1000次,对应系数为2;
			//咨询次数>1000次,对应系数为1。
			if (consultTimes <= 100) {  //咨询系数 咨询次数≤100次,对应系数为3;
				//100次<咨询次数≤1000次,对应系数为2;
				//咨询次数>1000次,对应系数为1。
				jiaquan = (jiaquan.subtract(BigDecimal.valueOf(80L))).divide(BigDecimal.valueOf(3L),2,BigDecimal.ROUND_HALF_UP);
			} else if (consultTimes > 100 && consultTimes <= 1000) {
				jiaquan = (jiaquan.subtract(BigDecimal.valueOf(80L))).divide(BigDecimal.valueOf(2L),2,BigDecimal.ROUND_HALF_UP);
			} else {
				jiaquan = (jiaquan.subtract(BigDecimal.valueOf(80L))).divide(BigDecimal.valueOf(1L),2,BigDecimal.ROUND_HALF_UP);
			}
			score = jiaquan.add(BigDecimal.valueOf(80L)).setScale(1, BigDecimal.ROUND_HALF_UP);
			EvaluateScore evaluateScore = new EvaluateScore();
			evaluateScore.setConsult(consult);
			evaluateScore.setDoctor(doctor);
			evaluateScore.setScore(score.doubleValue());
			evaluateScoreDao.save(evaluateScore);
		}
	};
	//public static void main(String args[]){
	//	JSONObject object = new JSONObject();
	//	JSONArray evaluateArray = new JSONArray();
	//	JSONArray labelArray = new JSONArray();
	//	JSONObject evaluateObject = new JSONObject();
	//	evaluateObject.put("doctor","要评价的医生code");
	//	evaluateObject.put("evaluateType","评价种类0、实名评价, 1、专业能力,2、服务态度,3、回复速度");
	//	evaluateObject.put("type","1、实名,2、匿名");
	//	evaluateObject.put("score","得分多少");
	//	evaluateArray.put(evaluateObject);
	//	JSONObject labelObject = new JSONObject();
	//	labelObject.put("doctor","要贴标签的医生code");
	//	labelObject.put("content","标签内容");
	//	labelArray.put(labelObject);
	//	object.put("consult","咨询的code");
	//	object.put("evaluate",evaluateArray);
	//	object.put("label",labelArray);
	//	System.out.print(object.toString());
	//}
	public static Long REAL_SCORE_DEFAULT =100L;
	public static Long ANONYMOUS_SCORE_DEFAULT_ONE =100L;
	public static Long ANONYMOUS_SCORE_DEFAULT_TWO =100L;
	public static Long ANONYMOUS_SCORE_DEFAULT_THREE =100L;
}