package beilv.vipCardAmountLog.service.impl;

import beilv.common.core.domain.entity.SysDictData;
import beilv.common.core.text.Convert;
import beilv.common.utils.CacheUtils;
import beilv.common.utils.DateUtils;
import beilv.common.utils.DictUtils;
import beilv.vipCardAmountLog.domain.VipCardAmountLog;
import beilv.vipCardAmountLog.mapper.VipCardAmountLogMapper;
import beilv.vipCardAmountLog.service.IVipCardAmountLogService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;

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

/**
 * 会员卡金额流水Service业务层处理
 *
 * @author LG
 * @date 2025-11-18
 */
@Service
public class VipCardAmountLogServiceImpl implements IVipCardAmountLogService {

    @Resource
    private VipCardAmountLogMapper vipCardAmountLogMapper;

    /**
     * 查询会员卡金额流水
     *
     * @param id 会员卡金额流水主键
     * @return 会员卡金额流水
     */
    @Override
    public VipCardAmountLog selectVipCardAmountLogById(String id) {
        return vipCardAmountLogMapper.selectVipCardAmountLogById(id);
    }

    /**
     * 查询会员卡金额流水列表
     *
     * @param vipCardAmountLog 会员卡金额流水
     * @return 会员卡金额流水
     */
    @Override
    public List<VipCardAmountLog> selectVipCardAmountLogList(VipCardAmountLog vipCardAmountLog) {
        return vipCardAmountLogMapper.selectVipCardAmountLogList(vipCardAmountLog);
    }

    /**
     * 新增会员卡金额流水
     *
     * @param vipCardAmountLog 会员卡金额流水
     * @return 结果
     */
    @Override
    public int insertVipCardAmountLog(VipCardAmountLog vipCardAmountLog) {
        vipCardAmountLog.setCreateTime(DateUtils.getNowDate());
        return vipCardAmountLogMapper.insertVipCardAmountLog(vipCardAmountLog);
    }

    /**
     * 修改会员卡金额流水
     *
     * @param vipCardAmountLog 会员卡金额流水
     * @return 结果
     */
    @Override
    public int updateVipCardAmountLog(VipCardAmountLog vipCardAmountLog) {
        return vipCardAmountLogMapper.updateVipCardAmountLog(vipCardAmountLog);
    }

    /**
     * 批量删除会员卡金额流水
     *
     * @param ids 需要删除的会员卡金额流水主键
     * @return 结果
     */
    @Override
    public int deleteVipCardAmountLogByIds(String ids) {
        return vipCardAmountLogMapper.deleteVipCardAmountLogByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除会员卡金额流水信息
     *
     * @param id 会员卡金额流水主键
     * @return 结果
     */
    @Override
    public int deleteVipCardAmountLogById(String id) {
        return vipCardAmountLogMapper.deleteVipCardAmountLogById(id);
    }

    @Override
    public List<Map<String, Object>> selectVipCardAmountLogListAndOrderInfo(VipCardAmountLog amountLog) {
        List<Map<String, Object>> maps = vipCardAmountLogMapper.selectVipCardAmountLogListAndOrderInfo(amountLog);
        Map<String, String> orderType = DictUtils.getDictCacheToMap("order_type");
        Map<String, String> paymentType = DictUtils.getDictCacheToMap("payment_type");
        maps.forEach(map->{
            map.put("orderTypeLabel", MapUtils.getString(orderType, MapUtils.getString(map,"orderType")));
            map.put("paymentTypeLabel", MapUtils.getString(paymentType, MapUtils.getString(map,"paymentType")));
        });
        return maps;
    }
}
