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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
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.constant.SystemFieldConstants;
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) {
        // 查询修改记录
        QueryWrapper<AcApprovalLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("APPROVAL_TYPE", eApprovalBusiness.getValue());
        queryWrapper.eq("BUSINESS_CODE", businessCode);
        queryWrapper.eq(SystemFieldConstants.PK_COUNTRY, pkCountry);
        return this.getOne(queryWrapper);
    }

    @Override
    public List<AcApprovalLog> queryApprovalLogList(EApprovalBusiness eApprovalBusiness, String businessCode, Integer pkCountry) {
        // 查询修改记录
        QueryWrapper<AcApprovalLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("BUSINESS_CODE", businessCode);
        queryWrapper.eq("APPROVAL_TYPE", eApprovalBusiness.getValue());
        queryWrapper.eq(SystemFieldConstants.PK_COUNTRY, pkCountry);
        return this.list(queryWrapper);
    }

    @Override
    public boolean updateApprovalLog(EApprovalBusiness eApprovalBusiness, String businessCode, Integer pkCountry, Long userId,
                                     EApproveRechargeStatus approveStatus, String remark) {
        // 处理修改记录
        UpdateWrapper<AcApprovalLog> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("APPROVAL_TYPE", eApprovalBusiness.getValue());
        updateWrapper.eq("BUSINESS_CODE", businessCode);
        updateWrapper.eq(SystemFieldConstants.PK_COUNTRY, pkCountry);
        updateWrapper.eq("APPROVAL_STATUS", EApproveRechargeStatus.WAIT.getValue());
        updateWrapper.set("APPROVAL_STATUS", approveStatus.getValue());
        updateWrapper.set("APPROVAL_REMARK", remark);
        updateWrapper.set(SystemFieldConstants.PK_MODIFIED, userId);
        updateWrapper.set(SystemFieldConstants.MODIFIED_TIME, new Date());
        return this.update(updateWrapper);
    }

}
