package com.fastbee.iot.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fastbee.common.extend.utils.SecurityUtils;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.common.utils.uuid.IdUtils;
import com.fastbee.iot.domain.GoviewProject;
import com.fastbee.iot.mapper.GoviewProjectMapper;
import com.fastbee.iot.service.IGoviewProjectService;
import org.springframework.stereotype.Service;

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

/**
 * 项目Service业务层处理
 *
 * @author kami
 * @date 2022-10-27
 */
@Service
public class GoviewProjectServiceImpl extends ServiceImpl<GoviewProjectMapper,GoviewProject> implements IGoviewProjectService
{
    @Resource
    private GoviewProjectMapper goviewProjectMapper;

    /**
     * 查询项目
     *
     * @param id 项目主键
     * @return 项目
     */
    @Override
    public GoviewProject selectGoviewProjectById(String id)
    {
        return goviewProjectMapper.selectById(id);
    }

    /**
     * 查询项目列表
     *
     * @param goviewProject 项目
     * @return 项目
     */
    @Override
    public Page<GoviewProject> selectGoviewProjectList(GoviewProject goviewProject)
    {
        return goviewProjectMapper.selectGoviewProjectList(new Page<>(goviewProject.getPageNum(), goviewProject.getPageSize()), goviewProject);
    }

    /**
     * 新增项目
     *
     * @param goviewProject 项目
     * @return 结果
     */
    @Override
    public String insertGoviewProject(GoviewProject goviewProject)
    {
        goviewProject.setId(IdUtils.simpleUUID());
        goviewProject.setCreateTime(DateUtils.getNowDate());
        goviewProject.setCreateBy(SecurityUtils.getUserId().toString());
        goviewProject.setUpdateTime(DateUtils.getNowDate());
        int i = goviewProjectMapper.insert(goviewProject);
        if(i > 0){
            return goviewProject.getId();
        }
        return null;
    }

    /**
     * 修改项目
     *
     * @param goviewProject 项目
     * @return 结果
     */
    @Override
    public int updateGoviewProject(GoviewProject goviewProject)
    {
        goviewProject.setUpdateTime(DateUtils.getNowDate());
        return goviewProjectMapper.updateById(goviewProject);
    }

    /**
     * 批量删除项目
     *
     * @param ids 需要删除的项目主键
     * @return 结果
     */
    @Override
    public int deleteGoviewProjectByIds(String[] ids)
    {
        return goviewProjectMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除项目信息
     *
     * @param id 项目主键
     * @return 结果
     */
    @Override
    public int deleteGoviewProjectById(String id)
    {
        return goviewProjectMapper.deleteById(id);
    }
}
