package com.huiju.estateagents.redpack.service.impl;

import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.redpack.entity.TaRedPacketClient;
import com.huiju.estateagents.redpack.entity.TaRedPacketMoney;
import com.huiju.estateagents.redpack.mapper.TaRedPacketMoneyMapper;
import com.huiju.estateagents.redpack.service.ITaRedPacketClientService;
import com.huiju.estateagents.redpack.service.ITaRedPacketMoneyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 红包金额设置  服务实现类
 * </p>
 *
 * @author fxf
 * @since 2020-06-03
 */
@Service
public class TaRedPacketMoneyServiceImpl extends ServiceImpl<TaRedPacketMoneyMapper, TaRedPacketMoney> implements ITaRedPacketMoneyService {

    @Autowired
    private ITaRedPacketClientService iTaRedPacketClientService;

    @Override
    public ResponseBean getRedPacketMoneyById(String activityId) {
        ResponseBean responseBean = new ResponseBean();

        // 获取红包金额设置
        TaRedPacketMoney taRedPacketMoney = getById(activityId);
        if (taRedPacketMoney == null) {
            responseBean.addError("fail");
            return responseBean;
        }

        // 获取红包客户端消息配置
        TaRedPacketClient taRedPacketClient = iTaRedPacketClientService.getById(activityId);
        taRedPacketMoney.setTaRedPacketClient(taRedPacketClient);
        responseBean.addSuccess(taRedPacketMoney);
        return responseBean;
    }

    @Override
    public ResponseBean updateRedPacketMoney(TaRedPacketMoney taRedPacketMoney) {
        ResponseBean responseBean = new ResponseBean();

        // 更新红包金额设置
        updateById(taRedPacketMoney);
        // 更新红包客户端消息配置
        iTaRedPacketClientService.updateById(taRedPacketMoney.getTaRedPacketClient());
        responseBean.addSuccess("success");
        return responseBean;
    }
}
