package com.lightinit.hsdataportal.impl;

import com.lightinit.hsdataportal.entity.ResourceAuth;
import com.lightinit.hsdataportal.mapper.ResourceAuthMapper;
import com.lightinit.hsdataportal.model.ResultState;
import com.lightinit.hsdataportal.model.ResultStateCode;
import com.lightinit.hsdataportal.service.IResourceAuthService;
import com.lightinit.hsdataportal.spring.DynamicDataContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: sunxiang
 * @Date: 2018/6/14 16:40
 * @Description:
 **/
@Service
public class ResourceAuthServiceImpl implements IResourceAuthService {

    @Autowired
    private ResourceAuthMapper resourceAuthMapper;
    @Transactional
    @Override
    public ResultState<Long> addResourceAuth(ResourceAuth resourceAuth) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState<Long> resultState = new ResultState<>();
       try{
           resourceAuthMapper.insert(resourceAuth);
           resultState.setMsg("提交申请成功");
           return resultState;
       }catch (Exception e){
           e.printStackTrace();
       }
        resultState.setStateCode(ResultStateCode.INVALID_DATA);
        resultState.setMsg("提交申请失败");
        return resultState;
    }
}
