package cn.iocoder.yudao.module.smartfactory.service.factorydataoverview;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.smartfactory.controller.admin.factorydataoverview.vo.FactoryDataOverviewPageReqVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.factorydataoverview.vo.FactoryDataOverviewSaveReqVO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.factorydataoverview.FactoryDataOverviewDO;
import cn.iocoder.yudao.module.smartfactory.dal.mysql.factorydataoverview.FactoryDataOverviewMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

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


/**
 * 工厂数据总览 Service 实现类
 *
 * @author 艾楷
 */
@Service
@Validated
public class FactoryDataOverviewServiceImpl implements FactoryDataOverviewService {

    @Resource
    private FactoryDataOverviewMapper dataOverviewMapper;

    @Override
    public Long createDataOverview(FactoryDataOverviewSaveReqVO createReqVO) {
        // 插入
        FactoryDataOverviewDO dataOverview = BeanUtils.toBean(createReqVO, FactoryDataOverviewDO.class);
        dataOverviewMapper.insert(dataOverview);
        // 返回
        return dataOverview.getId();
    }

    @Override
    public void updateDataOverview(FactoryDataOverviewSaveReqVO updateReqVO) {
        // 更新
        FactoryDataOverviewDO updateObj = BeanUtils.toBean(updateReqVO, FactoryDataOverviewDO.class);
        dataOverviewMapper.updateById(updateObj);
    }

    @Override
    public void deleteDataOverview(Long id) {
        // 删除
        dataOverviewMapper.deleteById(id);
    }

    @Override
    public FactoryDataOverviewDO getDataOverview(Long id) {
        return dataOverviewMapper.selectById(id);
    }

    @Override
    public PageResult<FactoryDataOverviewDO> getDataOverviewPage(FactoryDataOverviewPageReqVO pageReqVO) {
        return dataOverviewMapper.selectPage(pageReqVO);
    }

    @Override
    public List<FactoryDataOverviewDO> list() {
        return dataOverviewMapper.selectList();
    }

}