package com.yc.ship.module.resource.service.audit;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.common.util.object.BeanUtils;
import com.yc.ship.module.resource.controller.admin.audit.vo.AuditPageReqVO;
import com.yc.ship.module.resource.controller.admin.audit.vo.AuditSaveReqVO;
import com.yc.ship.module.resource.dal.dataobject.audit.AuditDO;
import com.yc.ship.module.resource.dal.mysql.audit.AuditMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

/**
 * 审核记录 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
public class AuditServiceImpl implements AuditService {

    @Resource
    private AuditMapper auditMapper;

    @Override
    public String createAudit(AuditSaveReqVO createReqVO) {
        // 插入
        AuditDO audit = BeanUtils.toBean(createReqVO, AuditDO.class);
        audit.setId(IdWorker.getIdStr());
        audit.setDeleted(false);
        auditMapper.insert(audit);
        // 返回
        return audit.getId();
    }

    @Override
    public void updateAudit(AuditSaveReqVO updateReqVO) {
        // 更新
        AuditDO updateObj = BeanUtils.toBean(updateReqVO, AuditDO.class);
        auditMapper.updateById(updateObj);
    }

    @Override
    public void deleteAudit(String id) {
        // 删除
        auditMapper.deleteById(id);
    }


    @Override
    public AuditDO getAudit(String id) {
        return auditMapper.selectById(id);
    }

    @Override
    public PageResult<AuditDO> getAuditPage(AuditPageReqVO pageReqVO) {
        return auditMapper.selectPage(pageReqVO);
    }
    @Override
    public AuditDO getAuditNewInfo(AuditPageReqVO pageReqVO) {
        List<AuditDO> auditList=auditMapper.getAuditNewInfo(pageReqVO);
        if(auditList.size()>0) {
            return auditList.get(0);
        }
        return null;
    }

}
