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.stereotype.Service;

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 {

    @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();
        }

    }

}
