package com.ruoyi.interfaces.service.impl;

import com.alibaba.fastjson2.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.interfaces.core.page.PageParam;
import com.ruoyi.interfaces.core.service.AbstractCrudService;
import com.ruoyi.interfaces.domain.PtFile;
import com.ruoyi.interfaces.mapper.PtFileDao;
import com.ruoyi.interfaces.service.PtFileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * @author
 * @date 2022-1-25
 */
@Service
@Transactional
public class PtFileServiceImpl extends AbstractCrudService<PtFile, PageParam<PtFile>> implements PtFileService {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private PtFileDao ptFileDao;

    public PtFileServiceImpl(PtFileDao ptFileDao) {
        super(ptFileDao);
        this.ptFileDao = ptFileDao;
    }

    @Override
    public int insert(PtFile ptFile) {
        ptFile.setViewNum(0L);
        ptFile.setStatus("0");
        ptFile.setIntm(new Date());
        logger.info("ptFile insert:{}", JSON.toJSONString(ptFile));
        return this.ptFileDao.insert(ptFile);
    }

    @Override
    public int update(PtFile ptFile) {
        return this.ptFileDao.update(ptFile);
    }

    @Override
    public PtFile get(String id) {
        return ptFileDao.get(id);
    }

    @Override
    public int delete(String id) {
        return this.ptFileDao.delete(id);
    }

    @Override
    public List<PtFile> listByRelId(String relId) {
        return ptFileDao.listByRelId(relId);
    }

    @Override
    public PageInfo<PtFile> findPageInfo(PageParam<PtFile> param) {
        PageHelper.startPage(param);
        List<PtFile> list = this.ptFileDao.list(param.getData());
        return new PageInfo<>(list);
    }

}
