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

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
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.constant.SystemFieldConstants;
import com.hzs.common.core.enums.EDelFlag;
import com.hzs.common.core.enums.EYesNo;
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;

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

    @Override
    public Boolean cancelOrder(Long orderId, Long pkModified) {
        UpdateWrapper<AcRecomUpgradeRecord> updateWrapper = new UpdateWrapper();
        updateWrapper.set(SystemFieldConstants.DEL_FLAG, EDelFlag.DELETE.getValue());
        updateWrapper.set(SystemFieldConstants.PK_MODIFIED, pkModified);
        updateWrapper.set(SystemFieldConstants.MODIFIED_TIME, new Date());
        updateWrapper.eq("PK_ORDER_ID", 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) {
        UpdateWrapper<AcRecomUpgradeRecord> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("UPGRADE_STATUS", EYesNo.NO.getIntValue())
                .set("PK_MODIFIED", pkModified)
                .in("PK_ID", pkIds);
        return this.update(updateWrapper);
    }


}
