package com.yonge.cooleshow.bbs.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonge.cooleshow.bbs.dao.BbsReplyAuthRecordDao;
import com.yonge.cooleshow.bbs.dto.ReplyAuditDto;
import com.yonge.cooleshow.bbs.entity.BbsReplyAuthRecord;
import com.yonge.cooleshow.bbs.enums.ArticleEnum;
import com.yonge.cooleshow.bbs.service.BbsReplyAuthRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Date;


@Service
public class BbsReplyAuthRecordServiceImpl extends ServiceImpl<BbsReplyAuthRecordDao, BbsReplyAuthRecord> implements
        BbsReplyAuthRecordService {
    private final static Logger log = LoggerFactory.getLogger(BbsReplyAuthRecordServiceImpl.class);


    @Override
    public void audit(ReplyAuditDto auditDto) {
        this.lambdaUpdate()
                .eq(BbsReplyAuthRecord::getReplyId, auditDto.getReplyId())
                .eq(BbsReplyAuthRecord::getAuditState, ArticleEnum.DOING.getCode())
                .remove();
        BbsReplyAuthRecord bbsReplyAuthRecord = new BbsReplyAuthRecord();

        bbsReplyAuthRecord.setReplyId(auditDto.getReplyId());
        bbsReplyAuthRecord.setAuditState(auditDto.getStatus());
        bbsReplyAuthRecord.setReason(auditDto.getReason());
        bbsReplyAuthRecord.setCreateTime(new Date());
        bbsReplyAuthRecord.setVerifyUserId(auditDto.getVerityUserId());
        bbsReplyAuthRecord.setUpdateTime(new Date());
        this.save(bbsReplyAuthRecord);
    }
}