package com.emr.service.ipml;


import com.emr.dao.FinishedDateTimeMapper;
import com.emr.entity.FinishedDateTime;
import com.emr.entity.OracleDateVo;
import com.emr.service.FinishedDateTimeService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.Reader;

/**
 * oracle数据获取
 */
@Service
public class FinishedDateTimeServiceImpl implements FinishedDateTimeService {
    /**
     * 实际查询方法
     *2021/9/28
     * @param INP_NO   编号
     * @param VISIT_ID 住院次数
     * @return 最后完成时间及护士完成时间
     * @throws IOException 注意传入两个参数都是Long，项目需求变更，重新修改获取数据及返回数据，
     * 返回为oracleDateVo对象，使用时请@Autowired注入，然后调用方法获取即可
     *
     */
    @Override
    public OracleDateVo findByID(String INP_NO, String VISIT_ID) throws IOException {
        //加载资源
        String resource = "config/mybatis-config.xml";
        Reader reader = Resources.getResourceAsReader(resource);
        //创建session
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader);
        SqlSession session = factory.openSession();
        //获取映射对象
        FinishedDateTimeMapper mapper = session.getMapper(FinishedDateTimeMapper.class);
        FinishedDateTime result = mapper.findByID(INP_NO, VISIT_ID);
        if (result != null) {
            OracleDateVo oracleDateVo = new OracleDateVo();
            oracleDateVo.setFinishedDateTime(result.getFINISHED_DATE_TIME());
            oracleDateVo.setMrCommitNurseDateTime(result.getMR_COMMIT_NURSE_DATE_TIME());
            return oracleDateVo;
        }
        return null;
    }
}