package com.xingxi.master.merchant.service.impl;

import com.xingxi.common.core.text.Convert;
import com.xingxi.common.enums.EDelFlag;
import com.xingxi.common.utils.DateUtils;
import com.xingxi.common.utils.ShiroUtils;
import com.xingxi.master.merchant.domain.Merchant;
import com.xingxi.master.merchant.mapper.MerchantMapper;
import com.xingxi.master.merchant.service.IMerchantService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商户Service业务层处理
 *
 * @author xingxi
 * @date 2025-03-06
 */
@Service
public class MerchantServiceImpl implements IMerchantService {
    @Resource
    private MerchantMapper merchantMapper;

    /**
     * 查询商户
     *
     * @param mercId 商户主键
     * @return 商户
     */
    @Override
    public Merchant selectMerchantByMercId(Long mercId) {
        return merchantMapper.selectMerchantByMercId(mercId);
    }

    /**
     * 查询商户列表
     *
     * @param merchant 商户
     * @return 商户
     */
    @Override
    public List<Merchant> selectMerchantList(Merchant merchant) {
        return merchantMapper.selectMerchantList(merchant);
    }

    /**
     * 新增商户
     *
     * @param merchant 商户
     * @return 结果
     */
    @Override
    public int insertMerchant(Merchant merchant) {
        merchant.setDelFlag(EDelFlag.NO.getVal());
        merchant.setCreateUser(ShiroUtils.getLoginName());
        merchant.setCreateTime(DateUtils.getNowDate());
        return merchantMapper.insertMerchant(merchant);
    }

    /**
     * 新增商户
     *
     * @param merchantList 商户
     * @return 结果
     */
    @Override
    public int batchInsertMerchant(List<Merchant> merchantList) {
        return merchantMapper.batchInsertMerchant(merchantList);
    }

    /**
     * 修改商户
     *
     * @param merchant 商户
     * @return 结果
     */
    @Override
    public int updateMerchant(Merchant merchant) {
        merchant.setUpdateUser(ShiroUtils.getLoginName());
        merchant.setUpdateTime(DateUtils.getNowDate());
        return merchantMapper.updateMerchant(merchant);
    }

    /**
     * 批量删除商户
     *
     * @param mercIds 需要删除的商户主键
     * @return 结果
     */
    @Override
    public int deleteMerchantByMercIds(String mercIds) {
        return merchantMapper.deleteMerchantByMercIds(Convert.toStrArray(mercIds));
    }

    /**
     * 删除商户信息
     *
     * @param mercId 商户主键
     * @return 结果
     */
    @Override
    public int deleteMerchantByMercId(Long mercId) {
        return merchantMapper.deleteMerchantByMercId(mercId);
    }

    /**
     * 逻辑删除商户
     *
     * @param mercId 商户主键
     * @return 结果
     */
    @Override
    public int logicDeleteMerchantByMercId(Long mercId) {
        return merchantMapper.logicDeleteMerchantByMercId(mercId);
    }

    /**
     * 逻辑批量删除商户
     *
     * @param mercIds 需要删除的数据主键集合
     * @return 结果
     */
    @Override
    public int logicDeleteMerchantByMercIds(String[] mercIds) {
        return merchantMapper.logicDeleteMerchantByMercIds(mercIds);
    }

    /**
     * 逻辑批量删除商户
     *
     * @param merchant 商户
     * @return 结果
     */
    @Override
    public int logicDeleteMerchantByCondition(Merchant merchant) {
        return merchantMapper.logicDeleteMerchantByCondition(merchant);
    }
}
