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

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.activity.recommend.mapper.AcRecomUpgradeRecordMapper;
import com.hzs.activity.recommend.service.IAcRecomUpgradeRecordService;
import com.hzs.common.core.enums.EDelFlag;
import com.hzs.common.domain.activity.recommend.AcRecomUpgradeRecord;
import com.hzs.common.domain.activity.recommend.AcRecomUpgradeRecordExt;
import org.springframework.stereotype.Service;

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

/**
 * 推荐升级业务表 服务实现类
 *
 * @author hzs
 * @since 2023-04-27
 */
@Service
public class AcRecomUpgradeRecordServiceImpl extends ServiceImpl<AcRecomUpgradeRecordMapper, AcRecomUpgradeRecord> implements IAcRecomUpgradeRecordService {

    @Override
    public Boolean cancelOrder(Long orderId, Long pkModified) {
        LambdaUpdateWrapper<AcRecomUpgradeRecord> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(AcRecomUpgradeRecord::getDelFlag, EDelFlag.DELETE.getValue());
        updateWrapper.set(AcRecomUpgradeRecord::getPkModified, pkModified);
        updateWrapper.set(AcRecomUpgradeRecord::getModifiedTime, new Date());
        updateWrapper.eq(AcRecomUpgradeRecord::getPkOrderId, orderId);
        return update(updateWrapper);
    }

    @Override
    public AcRecomUpgradeRecord selectUpgradeRecordByOrderId(AcRecomUpgradeRecordExt upgradeRecord) {
        return baseMapper.selectUpgradeRecordByOrderId(upgradeRecord);
    }

    @Override
    public List<Long> selectRecommendNumber(AcRecomUpgradeRecordExt upgradeRecord) {
        return baseMapper.selectRecommendNumber(upgradeRecord);
    }

    @Override
    public Boolean updateUpgradeStatusById(List<Long> pkIds, Long pkModified, Integer upGradeStatus) {
        LambdaUpdateWrapper<AcRecomUpgradeRecord> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(AcRecomUpgradeRecord::getUpGradeStatus, upGradeStatus)
                .set(AcRecomUpgradeRecord::getPkModified, pkModified)
                .in(AcRecomUpgradeRecord::getPkId, pkIds);
        return this.update(updateWrapper);
    }

}
