|
@ -0,0 +1,130 @@
|
|
|
|
|
|
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.repository.consult.EvaluateDao;
|
|
|
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.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
@Component
|
|
|
@Transactional
|
|
|
public class EvaluateService extends BaseService {
|
|
|
@Autowired
|
|
|
EvaluateDao evaluateDao;
|
|
|
@Autowired
|
|
|
ConsultTeamService consultTeamService;
|
|
|
@Autowired
|
|
|
EvaluateLabelService evaluateLabelService;
|
|
|
|
|
|
public void save(List<Evaluate> evaluates){
|
|
|
evaluateDao.save(evaluates);
|
|
|
}
|
|
|
|
|
|
public void saveByJson(String jsonData,String patient){
|
|
|
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<EvaluateLabel> evaluateLabelList = new ArrayList<>();
|
|
|
for(Object evaluateObj: evaluateArray){
|
|
|
Evaluate evaluate = new Evaluate();
|
|
|
JSONObject obj =(JSONObject) evaluateObj;
|
|
|
ClazzReflect clazzReflect = new ClazzReflect();
|
|
|
evaluate = (Evaluate)clazzReflect.formatToClazz(evaluate,obj);
|
|
|
evaluate.setConsult(consult);
|
|
|
evaluate.setPatient(patient);
|
|
|
evaluateList.add(evaluate);
|
|
|
}
|
|
|
for(Object labelObj: labelArray){
|
|
|
EvaluateLabel evaluateLabel = new EvaluateLabel();
|
|
|
JSONObject obj =(JSONObject) labelObj;
|
|
|
ClazzReflect clazzReflect = new ClazzReflect();
|
|
|
evaluateLabel = (EvaluateLabel)clazzReflect.formatToClazz(evaluateLabel,obj);
|
|
|
evaluateLabel.setConsult(consult);
|
|
|
evaluateLabel.setPatient(patient);
|
|
|
evaluateLabelList.add(evaluateLabel);
|
|
|
}
|
|
|
this.save(evaluateList);
|
|
|
evaluateLabelService.save(evaluateLabelList);
|
|
|
consultTeam.setEvaluate(1);
|
|
|
consultTeam.setEvaluateTime(new Date());
|
|
|
JSONObject topicObject = new JSONObject();
|
|
|
topicObject.put("evaluate",1);
|
|
|
topicObject.put("evaluate_time",new Date());
|
|
|
ImUtill.updateTopics(consult,topicObject.toString());
|
|
|
this.consultTeamService.save(consultTeam);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询某个咨询某种类型的评价
|
|
|
* @param consult
|
|
|
* @param type
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Evaluate> getEvaluateByConsultAndType(String consult,int type){
|
|
|
List<Evaluate> evaluates = evaluateDao.findByConsultAndType(consult,type);
|
|
|
return evaluates;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询某个咨询的评价
|
|
|
* @param consult
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Evaluate> getEvaluateByConsult(String consult){
|
|
|
List<Evaluate> evaluates = evaluateDao.findByConsult(consult);
|
|
|
return evaluates;
|
|
|
}
|
|
|
/**
|
|
|
* 获取某个医生的某种类型的评价
|
|
|
* @param doctor
|
|
|
* @param type
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Evaluate> getEvaluateByDoctorAndType(String doctor,int type){
|
|
|
List<Evaluate> evaluates = evaluateDao.findByDoctorAndType(doctor,type);
|
|
|
return evaluates;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//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());
|
|
|
//}
|
|
|
}
|