package com.hzs.activity.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.activity.base.mapper.AcApprovalLogMapper;
import com.hzs.activity.base.service.IAcApprovalLogService;
import com.hzs.common.core.enums.EApprovalBusiness;
import com.hzs.common.core.enums.EApproveRechargeStatus;
import com.hzs.common.domain.activity.base.AcApprovalLog;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 活动审批日志 服务实现类
 *
 * @author hzs
 * @since 2023-04-22
 */
@Service
public class AcApprovalLogServiceImpl extends ServiceImpl<AcApprovalLogMapper, AcApprovalLog> implements IAcApprovalLogService {

    @Override
    public AcApprovalLog queryApprovalLog(EApprovalBusiness eApprovalBusiness, String businessCode, Integer pkCountry) {
        // 查询修改记录
        LambdaQueryWrapper<AcApprovalLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AcApprovalLog::getApprovalType, eApprovalBusiness.getValue());
        queryWrapper.eq(AcApprovalLog::getBusinessCode, businessCode);
        queryWrapper.eq(AcApprovalLog::getPkCountry, pkCountry);
        return this.getOne(queryWrapper);
    }

    @Override
    public List<AcApprovalLog> queryApprovalLogList(EApprovalBusiness eApprovalBusiness, String businessCode, Integer pkCountry) {
        // 查询修改记录
        LambdaQueryWrapper<AcApprovalLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AcApprovalLog::getBusinessCode, businessCode);
        queryWrapper.eq(AcApprovalLog::getApprovalType, eApprovalBusiness.getValue());
        queryWrapper.eq(AcApprovalLog::getPkCountry, pkCountry);
        return this.list(queryWrapper);
    }

    @Override
    public boolean updateApprovalLog(EApprovalBusiness eApprovalBusiness, String businessCode, Integer pkCountry, Long userId,
                                     EApproveRechargeStatus approveStatus, String remark) {
        // 处理修改记录
        LambdaUpdateWrapper<AcApprovalLog> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(AcApprovalLog::getApprovalType, eApprovalBusiness.getValue());
        updateWrapper.eq(AcApprovalLog::getBusinessCode, businessCode);
        updateWrapper.eq(AcApprovalLog::getPkCountry, pkCountry);
        updateWrapper.eq(AcApprovalLog::getApprovalStatus, EApproveRechargeStatus.WAIT.getValue());
        updateWrapper.set(AcApprovalLog::getApprovalStatus, approveStatus.getValue());
        updateWrapper.set(AcApprovalLog::getApprovalRemark, remark);
        updateWrapper.set(AcApprovalLog::getPkModified, userId);
        updateWrapper.set(AcApprovalLog::getModifiedTime, new Date());
        return this.update(updateWrapper);
    }

}
