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

import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.feedback.Appeal;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.repository.feedback.AppealDao;
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 AppealService extends BaseService {
    @Autowired
    private AppealDao appealDao;

    @Autowired
    private PatientService patientService;

    @Autowired
    private DoctorService doctorService;

    public void saveAppeal(String creater,String description,int type,String images,String phone,int identity) throws Exception{
        Appeal appeal = new Appeal();
        appeal.setCode(getCode());
        appeal.setCreater(creater);
        appeal.setDescription(description);
        appeal.setType(type);
        appeal.setImages(images);
        appeal.setPhone(phone);
        appeal.setStatus(0);
        appeal.setIdentity(identity);
        appeal.setDel(1);
        //通过creater获取创建人名字
        String name ="";
        if(creater!=null&&!"".equals(creater)){
            if(identity==1){//说明是患者
                Patient patient = patientService.findByCode(creater);
                name = patient.getName();
            }else{//说明是医生
                Doctor doctor = doctorService.findDoctorByCode(creater);
                name = doctor.getName();
            }
        }
        appeal.setCreaterName(name);
        appealDao.save(appeal);
    }
}
