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

import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.system.controller.admin.assets.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.assets.AssetsSecondmentRecordDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.system.dal.mysql.assets.AssetsSecondmentRecordMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;

/**
 * 资产借调记录 Service 实现类
 *
 * @author 艾楷
 */
@Service
@Validated
public class AssetsSecondmentRecordServiceImpl implements AssetsSecondmentRecordService {

    @Resource
    private AssetsSecondmentRecordMapper assetsSecondmentRecordMapper;

    @Override
    public Long createAssetsSecondmentRecord(AssetsSecondmentRecordSaveReqVO createReqVO) {
        // 插入
        AssetsSecondmentRecordDO assetsSecondmentRecord = BeanUtils.toBean(createReqVO, AssetsSecondmentRecordDO.class);
        assetsSecondmentRecordMapper.insert(assetsSecondmentRecord);
        // 返回
        return assetsSecondmentRecord.getId();
    }

    @Override
    public void updateAssetsSecondmentRecord(AssetsSecondmentRecordSaveReqVO updateReqVO) {
        // 更新
        AssetsSecondmentRecordDO updateObj = BeanUtils.toBean(updateReqVO, AssetsSecondmentRecordDO.class);
        assetsSecondmentRecordMapper.updateById(updateObj);
    }

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


    @Override
    public AssetsSecondmentRecordDO getAssetsSecondmentRecord(Long id) {
        return assetsSecondmentRecordMapper.selectById(id);
    }

    @Override
    public PageResult<AssetsSecondmentRecordRespVO> getAssetsSecondmentRecordPage(AssetsSecondmentRecordPageReqVO pageReqVO) {
        IPage<AssetsSecondmentRecordRespVO> vos = assetsSecondmentRecordMapper.getAssetsSecondmentRecordPage(pageReqVO, MyBatisUtils.buildPage(pageReqVO));
        return new PageResult<>(vos.getRecords(), vos.getTotal());
    }

}