package cn.hnthyy.thmz.service.impl.his.zy;

import cn.hnthyy.thmz.entity.his.zy.PatientMiSfz;
import cn.hnthyy.thmz.mapper.his.zy.PatientMiSfzMapper;
import cn.hnthyy.thmz.service.his.zy.PatientMiSfzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class PatientMiSfzServiceImpl implements PatientMiSfzService {
    @SuppressWarnings("all")
    @Autowired
    private PatientMiSfzMapper patientMiSfzMapper;

    @Override
    public PatientMiSfz queryPatientMiSfzByPatientId(String patientId) {
        //return patientMiSfzMapper.selectPatientMiSfzByPatientId(patientId);
        List<PatientMiSfz> patientMiSfzs= patientMiSfzMapper.selectPatientMiSfzsByPatientId(patientId);
        if(patientMiSfzs==null || patientMiSfzs.size()==0){
            return null;
        }
        return patientMiSfzs.get(patientMiSfzs.size()-1);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
    public int savePatientMiSfz(PatientMiSfz patientMiSfz) {
        patientMiSfzMapper.deletePatientMiSfzByPatientId(patientMiSfz.getPatientId());
        return  patientMiSfzMapper.insertPatientMiSfz(patientMiSfz);
    }
}
