package com.fs.his.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fs.common.utils.DateUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fs.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.his.mapper.FsHfpayConfigMapper;
import com.fs.his.domain.FsHfpayConfig;
import com.fs.his.service.IFsHfpayConfigService;

/**
 * 汇付多支付配置Service业务层处理
 * 
 * @author fs
 * @date 2025-09-10
 */
@Service
public class FsHfpayConfigServiceImpl extends ServiceImpl<FsHfpayConfigMapper, FsHfpayConfig> implements IFsHfpayConfigService {

    /**
     * 查询汇付多支付配置
     * 
     * @param id 汇付多支付配置主键
     * @return 汇付多支付配置
     */
    @Override
    public FsHfpayConfig selectFsHfpayConfigById(Long id)
    {
        return baseMapper.selectFsHfpayConfigById(id);
    }

    /**
     * 查询汇付多支付配置列表
     * 
     * @param fsHfpayConfig 汇付多支付配置
     * @return 汇付多支付配置
     */
    @Override
    public List<FsHfpayConfig> selectFsHfpayConfigList(FsHfpayConfig fsHfpayConfig)
    {
        return baseMapper.selectFsHfpayConfigList(fsHfpayConfig);
    }

    /**
     * 新增汇付多支付配置
     * 
     * @param fsHfpayConfig 汇付多支付配置
     * @return 结果
     */
    @Override
    public int insertFsHfpayConfig(FsHfpayConfig fsHfpayConfig)
    {
        if(StringUtils.isNotEmpty(fsHfpayConfig.getAppId())) {
            FsHfpayConfig config = baseMapper.selectOne(Wrappers.<FsHfpayConfig>lambdaQuery()
                    .eq(FsHfpayConfig::getAppId, fsHfpayConfig.getAppId()));
            if(config != null)
                throw new RuntimeException("appId已存在");
        }
        fsHfpayConfig.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insertFsHfpayConfig(fsHfpayConfig);
    }

    /**
     * 修改汇付多支付配置
     * 
     * @param fsHfpayConfig 汇付多支付配置
     * @return 结果
     */
    @Override
    public int updateFsHfpayConfig(FsHfpayConfig fsHfpayConfig)
    {
        if(StringUtils.isNotEmpty(fsHfpayConfig.getAppId())) {
            FsHfpayConfig config = baseMapper.selectOne(Wrappers.<FsHfpayConfig>lambdaQuery()
                    .eq(FsHfpayConfig::getAppId, fsHfpayConfig.getAppId())
                    .ne(FsHfpayConfig::getId, fsHfpayConfig.getId()));
            if(config != null)
                throw new RuntimeException("appId已存在");
        }
        fsHfpayConfig.setUpdateTime(DateUtils.getNowDate());
        return baseMapper.updateFsHfpayConfig(fsHfpayConfig);
    }

    /**
     * 批量删除汇付多支付配置
     * 
     * @param ids 需要删除的汇付多支付配置主键
     * @return 结果
     */
    @Override
    public int deleteFsHfpayConfigByIds(Long[] ids)
    {
        return baseMapper.deleteFsHfpayConfigByIds(ids);
    }

    /**
     * 删除汇付多支付配置信息
     * 
     * @param id 汇付多支付配置主键
     * @return 结果
     */
    @Override
    public int deleteFsHfpayConfigById(Long id)
    {
        return baseMapper.deleteFsHfpayConfigById(id);
    }
}
