package com.fs.course.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import com.fs.common.core.domain.R;
import com.fs.common.utils.DateUtils;
import com.fs.course.param.FsCourseRedPacketLogParam;
import com.fs.course.vo.FsCourseRedPacketLogListPVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.course.mapper.FsCourseRedPacketLogMapper;
import com.fs.course.domain.FsCourseRedPacketLog;
import com.fs.course.service.IFsCourseRedPacketLogService;

/**
 * 短链课程看课记录Service业务层处理
 *
 * @author fs
 * @date 2024-10-24
 */
@Service
public class FsCourseRedPacketLogServiceImpl implements IFsCourseRedPacketLogService
{
    @Autowired
    private FsCourseRedPacketLogMapper fsCourseRedPacketLogMapper;

    /**
     * 查询短链课程看课记录
     *
     * @param logId 短链课程看课记录主键
     * @return 短链课程看课记录
     */
    @Override
    public FsCourseRedPacketLog selectFsCourseRedPacketLogByLogId(Long logId)
    {
        return fsCourseRedPacketLogMapper.selectFsCourseRedPacketLogByLogId(logId);
    }

    /**
     * 查询短链课程看课记录列表
     *
     * @param fsCourseRedPacketLog 短链课程看课记录
     * @return 短链课程看课记录
     */
    @Override
    public List<FsCourseRedPacketLog> selectFsCourseRedPacketLogList(FsCourseRedPacketLog fsCourseRedPacketLog)
    {
        return fsCourseRedPacketLogMapper.selectFsCourseRedPacketLogList(fsCourseRedPacketLog);
    }

    /**
     * 新增短链课程看课记录
     *
     * @param fsCourseRedPacketLog 短链课程看课记录
     * @return 结果
     */
    @Override
    public int insertFsCourseRedPacketLog(FsCourseRedPacketLog fsCourseRedPacketLog)
    {
        fsCourseRedPacketLog.setCreateTime(DateUtils.getNowDate());
        return fsCourseRedPacketLogMapper.insertFsCourseRedPacketLog(fsCourseRedPacketLog);
    }

    /**
     * 修改短链课程看课记录
     *
     * @param fsCourseRedPacketLog 短链课程看课记录
     * @return 结果
     */
    @Override
    public int updateFsCourseRedPacketLog(FsCourseRedPacketLog fsCourseRedPacketLog)
    {
        return fsCourseRedPacketLogMapper.updateFsCourseRedPacketLog(fsCourseRedPacketLog);
    }

    /**
     * 批量删除短链课程看课记录
     *
     * @param logIds 需要删除的短链课程看课记录主键
     * @return 结果
     */
    @Override
    public int deleteFsCourseRedPacketLogByLogIds(Long[] logIds)
    {
        return fsCourseRedPacketLogMapper.deleteFsCourseRedPacketLogByLogIds(logIds);
    }

    /**
     * 删除短链课程看课记录信息
     *
     * @param logId 短链课程看课记录主键
     * @return 结果
     */
    @Override
    public int deleteFsCourseRedPacketLogByLogId(Long logId)
    {
        return fsCourseRedPacketLogMapper.deleteFsCourseRedPacketLogByLogId(logId);
    }

    @Override
    public R syncRedPacket(String outBatchNo) {
        FsCourseRedPacketLog log = fsCourseRedPacketLogMapper.selectFsCourseRedPacketLogByBatchNo(outBatchNo);
        if (log!=null){
            log.setStatus(1);
            log.setUpdateTime(new Date());
            fsCourseRedPacketLogMapper.updateFsCourseRedPacketLog(log);
            return R.ok();
        }
        return R.error("批次不存在");
    }

    @Override
    public List<FsCourseRedPacketLogListPVO> selectFsCourseRedPacketLogListVO(FsCourseRedPacketLogParam fsCourseRedPacketLog) {
        return fsCourseRedPacketLogMapper.selectFsCourseRedPacketLogListVO(fsCourseRedPacketLog);
    }

    @Override
    public List<FsCourseRedPacketLogListPVO> selectFsCourseRedPacketLogListVONew(FsCourseRedPacketLogParam fsCourseRedPacketLog) {
        return fsCourseRedPacketLogMapper.selectFsCourseRedPacketLogListVONew(fsCourseRedPacketLog);
    }

    /**
     * 查询红包数量
     * @param companyUserId 销售ID
     * @return count
     */
    @Override
    public int getCountByCompanyUserIdId(Long companyUserId) {
        return fsCourseRedPacketLogMapper.getCountByCompanyUserIdId(companyUserId);
    }

    /**
     * 查询新用户红包金额总和
     * @param companyUserId 销售ID
     * @return amount
     */
    @Override
    public BigDecimal getNewVipRedPackAmountByCompanyUserIdId(Long companyUserId) {
        return fsCourseRedPacketLogMapper.getNewVipRedPackAmountByCompanyUserIdId(companyUserId);
    }

    /**
     * 查询红包金额数
     * @param companyUserId 销售ID
     * @return amount
     */
    @Override
    public BigDecimal getSumByCompanyUserIdId(Long companyUserId) {
        return fsCourseRedPacketLogMapper.getSumByCompanyUserIdId(companyUserId);
    }
}
