package com.younike.system.service.impl;

import com.younike.system.domain.SysCode;
import com.younike.system.mapper.SysCodeMapper;
import com.younike.system.service.ISysCodeService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 店铺端常量Service业务层处理
 *
 * @author elev
 * @date 2022-01-10
 */
@Service
public class SysCodeServiceImpl implements ISysCodeService {
    @Autowired
    private SysCodeMapper sysCodeMapper;

    /**
     * 查询店铺端常量
     *
     * @param codeId 店铺端常量主键
     * @return 店铺端常量
     */
    @Override
    public List<SysCode> selectSysCodeByCodeId(String codeId) {
        return sysCodeMapper.selectSysCodeByCodeId(codeId);
    }

    /**
     * 查询店铺端常量列表
     *
     * @param sysCode 店铺端常量
     * @return 店铺端常量
     */
    @Override
    public List<SysCode> selectSysCodeList(SysCode sysCode) {
        return sysCodeMapper.selectSysCodeList(sysCode);
    }

    /**
     * 新增店铺端常量
     *
     * @param sysCode 店铺端常量
     * @return 结果
     */
    @Override
    public int insertSysCode(SysCode sysCode) {
        return sysCodeMapper.insertSysCode(sysCode);
    }

    /**
     * 修改店铺端常量
     *
     * @param sysCode 店铺端常量
     * @return 结果
     */
    @Override
    public int updateSysCode(SysCode sysCode) {
        return sysCodeMapper.updateSysCode(sysCode);
    }

    /**
     * 批量删除店铺端常量
     *
     * @param codeIds 需要删除的店铺端常量主键
     * @return 结果
     */
    @Override
    public int deleteSysCodeByCodeIds(String[] codeIds) {
        return sysCodeMapper.deleteSysCodeByCodeIds(codeIds);
    }

    /**
     * 删除店铺端常量信息
     *
     * @param codeId 店铺端常量主键
     * @return 结果
     */
    @Override
    public int deleteSysCodeByCodeId(String codeId)
    {
        return sysCodeMapper.deleteSysCodeByCodeId(codeId);
    }

    /**
     * 查询 Decode_Value
     * @param codeId
     * @param decodeId
     * @return
     */
    @Override
    public String getDecodeValue(String codeId, String decodeId) {
        SysCode sysCode =  sysCodeMapper.getByCodeIdAndDecodeId(codeId, decodeId);
        if(ObjectUtils.isEmpty(sysCode)){
            return null;
        }
        return sysCode.getDecodeValue();
    }
}
