package com.ruoyi.interfaces.service.impl;

import com.ruoyi.interfaces.mapper.PtConsultDao;
import com.ruoyi.interfaces.domain.PtConsult;
import com.ruoyi.interfaces.core.page.PageParam;
import com.ruoyi.interfaces.core.service.AbstractCrudService;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.interfaces.service.PtConsultService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
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-20
 */
@Service
@Transactional
public class PtConsultServiceImpl extends AbstractCrudService<PtConsult, PageParam<PtConsult>> implements PtConsultService {

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

    @Autowired
    private PtConsultDao ptConsultDao;

    public PtConsultServiceImpl(PtConsultDao ptConsultDao) {
        super(ptConsultDao);
        this.ptConsultDao = ptConsultDao;
    }

    @Override
    public int insert(PtConsult ptConsult) {
        String uuid = IdUtils.simpleUUID();  // 生成uuid
        ptConsult.setId(uuid);
        ptConsult.setIntm(new Date());
        ptConsult.setUptm(new Date());
        return this.ptConsultDao.insert(ptConsult);
    }

    @Override
    public int update(PtConsult ptConsult) {
        ptConsult.setUptm(new Date());
        return this.ptConsultDao.update(ptConsult);
    }

    @Override
    public PtConsult save(PtConsult ptConsult) {
        int ret = 0;
        if (StringUtils.isBlank(ptConsult.getId())) {
            ret = insert(ptConsult);
        } else {
            ret = update(ptConsult);
        }
        return ptConsult;
    }

    @Override
    public PtConsult get(String id) {
        return ptConsultDao.get(id);
    }

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

    @Override
    public PageInfo<PtConsult> findPageInfo(PageParam<PtConsult> param) {
        PageHelper.startPage(param);
        PageHelper.orderBy("INTM DESC");
        List<PtConsult> list = ptConsultDao.list(param.getData());
        return new PageInfo<>(list);
    }
}
