package com.sqx.modules.bl.collect.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.DateUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.bl.collect.dao.CollectMassageDao;
import com.sqx.modules.bl.collect.entity.CollectMassage;
import com.sqx.modules.bl.collect.service.CollectMassageService;
import org.springframework.stereotype.Service;
import java.util.Date;

@Service
public class CollectMassageServiceImpl extends ServiceImpl<CollectMassageDao, CollectMassage> implements CollectMassageService {

    @Override
    public Result findPage(CollectMassage collectMassage){
        Page<CollectMassage> pages=new Page<>(collectMassage.getPage(),collectMassage.getLimit());
        return Result.success().put("data",baseMapper.findPage(pages,collectMassage));
    }

    @Override
    public void insertCollect(CollectMassage collectMassage){
        CollectMassage cm = selectCollectMassageByUserId(collectMassage);
        if(cm!=null){
            cm.setCreateTime(DateUtils.format(new Date()));
            baseMapper.updateById(cm);
        }else{
            collectMassage.setCreateTime(DateUtils.format(new Date()));
            baseMapper.insert(collectMassage);
        }
    }

    @Override
    public CollectMassage selectCollectMassageByUserId(CollectMassage collectMassage){
        return baseMapper.selectCollectMassageByUserId(collectMassage);
    }

}