package cn.iocoder.yudao.module.system.service.assets;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
import cn.iocoder.yudao.module.system.controller.admin.assets.vo.DeptAssetsLittleVO;
import cn.iocoder.yudao.module.system.controller.admin.assets.vo.DeptAssetsPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.assets.vo.DeptAssetsRespVO;
import cn.iocoder.yudao.module.system.controller.admin.assets.vo.DeptAssetsSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.assets.DeptAssetsDO;
import cn.iocoder.yudao.module.system.dal.mysql.assets.DeptAssetsMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * 部门资产 Service 实现类
 *
 * @author 艾楷
 */
@Service
@Validated
public class DeptAssetsServiceImpl implements DeptAssetsService {

    @Resource
    private DeptAssetsMapper deptAssetsMapper;

    @Override
    public Long createDeptAssets(DeptAssetsSaveReqVO createReqVO) {
        // 插入
        DeptAssetsDO deptAssets = BeanUtils.toBean(createReqVO, DeptAssetsDO.class);
        deptAssetsMapper.insert(deptAssets);
        // 返回
        return deptAssets.getId();
    }

    @Override
    public void updateDeptAssets(DeptAssetsSaveReqVO updateReqVO) {
        // 更新
        DeptAssetsDO updateObj = BeanUtils.toBean(updateReqVO, DeptAssetsDO.class);
        deptAssetsMapper.updateById(updateObj);
    }

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

    @Override
    public DeptAssetsDO getDeptAssets(Long id) {
        return deptAssetsMapper.selectById(id);
    }

    @Override
    public PageResult<DeptAssetsRespVO> getDeptAssetsPage(DeptAssetsPageReqVO pageReqVO) {
        IPage<DeptAssetsRespVO> assetsDOIPage = deptAssetsMapper.getDeptAssetsPage(pageReqVO, MyBatisUtils.buildPage(pageReqVO));
        return new PageResult<>(assetsDOIPage.getRecords(), assetsDOIPage.getTotal());
    }

    @Override
    public PageResult<DeptAssetsLittleVO> deptAssetsLittlePage(DeptAssetsPageReqVO pageReqVO) {
        IPage<DeptAssetsLittleVO> assetsDOIPage = deptAssetsMapper.deptAssetsLittlePage(pageReqVO, MyBatisUtils.buildPage(pageReqVO));
        return new PageResult<>(assetsDOIPage.getRecords(), assetsDOIPage.getTotal());
    }

}