package thyyxxk.webserver.service.zhuyuanyisheng.emr;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;
import thyyxxk.webserver.config.exception.ExceptionEnum;
import thyyxxk.webserver.dao.his.zhuyuanyisheng.emr.EmrSuggestionDao;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.dictionary.CodeName;
import thyyxxk.webserver.entity.zhuyuanyisheng.emr.LinkQualityControl;
import thyyxxk.webserver.utils.ListUtil;
import thyyxxk.webserver.utils.ResultVoUtil;

import java.util.List;

/**
 * 电子病历的建议维护
 *
 * @author xiaochan
 */
@Service
@Slf4j
public class EmrSuggestionService {

    private final EmrSuggestionDao dao;

    public EmrSuggestionService(EmrSuggestionDao dao) {
        this.dao = dao;
    }

    public ResultVo<List<LinkQualityControl>> getLinkQuality(String code) {
        List<LinkQualityControl> list = dao.selectedLink(code);
        return ResultVoUtil.success(list);
    }

    public ResultVo<List<CodeName>> getLinkSelect() {
        return ResultVoUtil.success(dao.getLinkSelect());
    }

    public ResultVo<String> revise(LinkQualityControl param) {
        dao.updateById(param);
        return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_EL_MESSAGE);
    }

    public ResultVo<String> addTo(LinkQualityControl param) {
        dao.insert(param);
        return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_EL_MESSAGE);
    }

    public ResultVo<String> deleteById(LinkQualityControl param) {
        dao.deleteById(param);
        return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_EL_MESSAGE);
    }

    public ResultVo<String> updateSort(List<LinkQualityControl> list) {
        ListUtil.batchList(list, EmrSuggestionDao.class, BaseMapper::updateById);
        return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_EL_MESSAGE);
    }

}
