package com.jiayue.ipp.idp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiayue.ipp.common.data.entity.SysParameter;
import com.jiayue.ipp.idp.mapper.SysParameterMapper;
import com.jiayue.ipp.idp.service.SysParameterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * idp_sys_parameter
 *
 * @author whc
 * @date 2022-03-18 15:49:37
 */
@Service
public class SysParameterServiceImpl extends ServiceImpl<SysParameterMapper, SysParameter> implements SysParameterService {

    @Autowired
    SysParameterMapper sysParameterMapper;

    @Override
    public String getSysParameterAndStationCode(String sysKey, String defaultValue, String stationCode) {
        QueryWrapper<SysParameter> wrapper = new QueryWrapper<>();

        if (stationCode != null && !stationCode.equals("")) {
            wrapper.eq("station_code", stationCode);
        }
        if (sysKey != null && !sysKey.equals("")) {
            wrapper.eq("sys_key", sysKey);
        }
        List<SysParameter> sysParameterList = baseMapper.selectList(wrapper);
        if (sysParameterList.isEmpty()) {
            return defaultValue;
        } else {
            return sysParameterList.get(0).getSysValue();
        }

    }

    /**
     * 查询参数值
     *
     * @param sysKey 参数标识
     * @return 参数
     */
    public SysParameter getParameterBySysKey(final String sysKey) {
        SysParameter sysParameter = sysParameterMapper.findBySysKeyEquals(sysKey);
        return sysParameter;
    }
}
