package com.diagbot.facade;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diagbot.entity.SysHospitalSet;
import com.diagbot.enums.IsDeleteEnum;
import com.diagbot.service.impl.SysHospitalSetServiceImpl;
import com.diagbot.util.StringUtil;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description:
 * @author: gaodm
 * @time: 2020/7/6 9:29
 */
@Component
public class SysHospitalSetFacade extends SysHospitalSetServiceImpl {

    public String getScoreType(Long hospitalId) {
        String res = "0";
        SysHospitalSet sysHospitalSet
                = this.getOne(new QueryWrapper<SysHospitalSet>()
                        .eq("is_deleted", IsDeleteEnum.N.getKey())
                        .eq("hospital_id", hospitalId)
                        .eq("code", "score_type")
                , false);
        if (null != sysHospitalSet
                && sysHospitalSet.getValue().equals("1")) {
            res = "1";
        }
        return res;
    }

    public String getValue(Long hospitalId, String code) {
        String res = "";
        SysHospitalSet sysHospitalSet
                = this.getOne(new QueryWrapper<SysHospitalSet>()
                        .eq("is_deleted", IsDeleteEnum.N.getKey())
                        .eq("hospital_id", hospitalId)
                        .eq("code", code)
                , false);
        if (null != sysHospitalSet
                && StringUtil.isNotBlank(sysHospitalSet.getValue())) {
            res = sysHospitalSet.getValue();
        }
        return res;
    }

    /**
     *获取remark相同的一些列配置
     *
     * @param hospitalId
     * @param remark
     * @Return java.util.List<com.diagbot.entity.SysHospitalSet>
     */
    @Cacheable(value = "cache", key = "'operationLog:hospId_'+#hospitalId")
    public List<SysHospitalSet> getHospitalSetByRemark(Long hospitalId, String remark) {
        return this.list(new QueryWrapper<SysHospitalSet>()
                .eq("is_deleted", IsDeleteEnum.N.getKey())
                .eq("hospital_id", hospitalId)
                .eq("remark", remark));
    }
}
