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.module.system.controller.admin.assets.vo.AssetsTypePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.assets.vo.AssetsTypeSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.assets.AssetsTypeDO;
import cn.iocoder.yudao.module.system.dal.mysql.assets.AssetsTypeMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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 AssetsTypeServiceImpl implements AssetsTypeService {

    @Resource
    private AssetsTypeMapper assetsTypeMapper;

    @Override
    public Long createAssetsType(AssetsTypeSaveReqVO createReqVO) {
        // 插入
        AssetsTypeDO assetsType = BeanUtils.toBean(createReqVO, AssetsTypeDO.class);
        assetsTypeMapper.insert(assetsType);
        // 返回
        return assetsType.getId();
    }

    @Override
    public void updateAssetsType(AssetsTypeSaveReqVO updateReqVO) {
        // 更新
        AssetsTypeDO updateObj = BeanUtils.toBean(updateReqVO, AssetsTypeDO.class);
        assetsTypeMapper.updateById(updateObj);
    }

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

    @Override
    public AssetsTypeDO getAssetsType(Long id) {
        return assetsTypeMapper.selectById(id);
    }

    @Override
    public PageResult<AssetsTypeDO> getAssetsTypePage(AssetsTypePageReqVO pageReqVO) {
        return assetsTypeMapper.selectPage(pageReqVO);
    }

    @Override
    public List<AssetsTypeDO> getByPid(Long pid) {
        return assetsTypeMapper.selectList(new LambdaQueryWrapper<AssetsTypeDO>().eq(AssetsTypeDO::getPid, pid));
    }

    @Override
    public List<AssetsTypeDO> getAllList() {
        return assetsTypeMapper.selectList();
    }

}