package com.inkasso.factoring.system.role.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.inkasso.adapter.util.BeanUtilsProxy;
import com.inkasso.factoring.system.role.dao.RoleResourceDAO;
import com.inkasso.factoring.system.role.entity.RoleResourceDO;
import com.inkasso.factoring.system.role.model.dto.RoleResourceDTO;
import com.inkasso.factoring.system.role.model.request.AddRoleResourceRequest;
import com.inkasso.factoring.system.role.model.request.EditRoleResourceRequest;
import com.inkasso.factoring.system.role.service.RoleResourceService;
import com.inkasso.adapter.exception.ServiceException;
import com.inkasso.adapter.exception.enums.ExceptionEnum;
import org.springframework.stereotype.Service;

/**
* @author 张超
* @date  2023-08-19
*/
@Service
public class RoleResourceServiceImpl extends ServiceImpl<RoleResourceDAO, RoleResourceDO> implements RoleResourceService {


    @Override
    public void addRoleResource(AddRoleResourceRequest addRoleResourceRequest) {
    RoleResourceDO roleResource = BeanUtilsProxy.copyPropertiesIgnoreNull(addRoleResourceRequest, RoleResourceDO.class);
    this.baseMapper.insert(roleResource);
    }

    @Override
    public void editRoleResource(EditRoleResourceRequest editRoleResourceRequest) {

    RoleResourceDO roleResource = super.getById(editRoleResourceRequest.getId());
    if (roleResource == null) {
    throw new ServiceException(400, ExceptionEnum.SYSTEM_DATE_ERROR);
    }
    BeanUtilsProxy.copyPropertiesNotIgnoreNull(editRoleResourceRequest,roleResource);
    this.updateById(roleResource);
    }

    @Override
    public RoleResourceDTO getById(Long id) {
    RoleResourceDO roleResource = super.getById(id);
    RoleResourceDTO roleResourceDto = BeanUtilsProxy.copyProperties(roleResource,RoleResourceDTO.class);
    return roleResourceDto;
    }

    @Override
    public void deleteRoleResource(Long id) {

    this.removeById(id);
    }
}

