package com.yihu.wlyy.service.app.feedback;

import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.feedback.Feedback;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.repository.feedback.FeedbackDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.service.common.account.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by Reece on 2017/5/6.
 */
@Service
@Transactional
public class FeedbackService extends BaseService {
    @Autowired
    private FeedbackDao feedbackDao;

    @Autowired
    private PatientService patientService;

    @Autowired
    private DoctorService doctorService;

    public void saveFeedback(String creater,int identity,String description,int type,String images,String contact) throws Exception{
        Feedback feedback = new Feedback();
        feedback.setCode(getCode());
        feedback.setCreater(creater);
        feedback.setIdentity(identity);
        feedback.setDescription(description);
        feedback.setType(type);
        feedback.setImages(images);
        feedback.setContact(contact);
        feedback.setStatus(0);
        feedback.setDel(1);
        //通过creater获取创建人名字
        String name ="";
        if(identity==1){//说明是患者
            Patient patient = patientService.findByCode(creater);
            name = patient.getName();
        }else{//说明是医生
            Doctor doctor = doctorService.findDoctorByCode(creater);
            name = doctor.getName();
        }
        feedback.setCreaterName(name);
        feedbackDao.save(feedback);
    }

}
