package com.wms.service.serviceImplements;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wms.entity.table.Config;
import com.wms.mapper.ConfigMapper;
import com.wms.service.ConfigService;
import com.wms.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ConfigServiceImplement extends ServiceImpl<ConfigMapper, Config> implements ConfigService {
    private final ConfigMapper configMapper;

    @Override
    public List<Config> selectConfigs(String configKey) {
        // 查询条件
        LambdaQueryWrapper<Config> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(configKey)) {// 判断configKey是否为空
            queryWrapper.eq(Config::getConfigKey, configKey);
        }
        return configMapper.selectList(queryWrapper);
    }

    @Override
    public int updateConfig(Config config) {
        if (StringUtils.isEmpty(config.getConfigKey())) {
            return 0;
        } else {
            LambdaQueryWrapper<Config> queryWrapperForUpdate =  new LambdaQueryWrapper<Config>()
                    .eq(Config::getConfigKey, config.getConfigKey());
            return configMapper.update(config, queryWrapperForUpdate);
        }
    }
}
