package com.liang.service.impl;

import com.liang.entity.ViewApproveRecord;
import com.liang.dao.ViewApproveRecordDao;
import com.liang.service.ViewApproveRecordService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

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

/**
 * (ViewApproveRecord)表服务实现类
 *
 * @author makejava
 * @since 2023-05-03 12:25:57
 */
@Service("viewApproveRecordService")
public class ViewApproveRecordServiceImpl implements ViewApproveRecordService {
    @Resource
    private ViewApproveRecordDao viewApproveRecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param 主键
     * @return 实例对象
     */
    @Override
    public ViewApproveRecord queryById(Integer id) {
        return this.viewApproveRecordDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param viewApproveRecord 筛选条件
     * @param pageRequest       分页对象
     * @return 查询结果
     */
    @Override
    public Page<ViewApproveRecord> queryByPage(ViewApproveRecord viewApproveRecord, PageRequest pageRequest) {
        long total = this.viewApproveRecordDao.count(viewApproveRecord);
        return new PageImpl<>(this.viewApproveRecordDao.queryAllByLimit(viewApproveRecord, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param viewApproveRecord 实例对象
     * @return 实例对象
     */
    @Override
    public ViewApproveRecord insert(ViewApproveRecord viewApproveRecord) {
        this.viewApproveRecordDao.insert(viewApproveRecord);
        return viewApproveRecord;
    }

    /**
     * 修改数据
     *
     * @param viewApproveRecord 实例对象
     * @return 实例对象
     */
    @Override
    public ViewApproveRecord update(ViewApproveRecord viewApproveRecord) {
        this.viewApproveRecordDao.update(viewApproveRecord);
        return this.queryById(viewApproveRecord.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.viewApproveRecordDao.deleteById(id) > 0;
    }

    @Override
    public List<ViewApproveRecord> getApproveRecordList(Map<String, String> paraMap) {
        return this.viewApproveRecordDao.getApproveRecordList(paraMap);
    }
}
