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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.inkasso.adapter.util.BeanUtilsProxy;
import com.inkasso.factoring.system.user.dao.UserRoleDAO;
import com.inkasso.factoring.system.user.entity.UserRoleDO;
import com.inkasso.factoring.system.user.model.request.AddUserRoleRequest;
import com.inkasso.factoring.system.user.model.request.EditUserRoleRequest;
import com.inkasso.factoring.system.user.service.UserRoleService;
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 UserRoleServiceImpl extends ServiceImpl<UserRoleDAO, UserRoleDO> implements UserRoleService {


    @Override
    public void addUserRole(AddUserRoleRequest addUserRoleRequest) {
    UserRoleDO userRole = BeanUtilsProxy.copyPropertiesIgnoreNull(addUserRoleRequest, UserRoleDO.class);
    this.baseMapper.insert(userRole);
    }

    @Override
    public void editUserRole(EditUserRoleRequest editUserRoleRequest) {

    UserRoleDO userRole = super.getById(editUserRoleRequest.getId());
    if (userRole == null) {
    throw new ServiceException(400, ExceptionEnum.SYSTEM_DATE_ERROR);
    }
    BeanUtilsProxy.copyPropertiesNotIgnoreNull(editUserRoleRequest,userRole);
    this.updateById(userRole);
    }

    @Override
    public void deleteUserRole(Long id) {

    this.removeById(id);
    }
}

