package cn.superdesk.uniorder.dubbo.consumer.sys.role;

import cn.hutool.core.date.DateUtil;
import cn.superdesk.uniorder.common.enums.common.CommonSourceFromEnum;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.common.security.JwtUtil;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.sys.role.SysRoleExtDataSample;
import cn.superdesk.uniorder.dto.dubbo.sys.role.SysRoleExtDataSampleParam;
import cn.superdesk.uniorder.dubbo.facade.sys.role.DubboSysRoleExtDataSampleService;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description: 角色定义-扩展-数据权限主体描述-只能是单个项目或是项目下的企业
 * @Author: linjinyu
 * @Email linjinyu@avic-s.com
 * @CreateDate: 2020-08-26 14:15:28
 * @UpdateUser: linjinyu
 * @UpdateDate: 2020-08-26 14:15:28
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Component
public class SysRoleExtDataSampleDubboConsumerService {

	@Reference(version = "1.0.0", timeout = 10000, retries = -1)
	private DubboSysRoleExtDataSampleService dubboSysRoleExtDataSampleService;


	/****************************************** extends BaseService 部分 start ******************************************/

	public void addObj(SysRoleExtDataSampleParam param) {

		dubboSysRoleExtDataSampleService.addObj(param);

	}

	public void updateObj(SysRoleExtDataSampleParam param) {

		dubboSysRoleExtDataSampleService.updateObj(param);
	}

	public void deleteObj(Long id) {

		dubboSysRoleExtDataSampleService.deleteObj(id);
	}

	public SysRoleExtDataSample findById(Long id) {

		return dubboSysRoleExtDataSampleService.findById(id);
	}

	public PageInfo<SysRoleExtDataSample> findByPaging(Map<String, Object> conditions, Integer pageNun, Integer pageSize) {

		return dubboSysRoleExtDataSampleService.findByPaging(conditions, pageNun, pageSize);
	}

	public List<SysRoleExtDataSample> findAll(Map<String, Object> queryMap) {

		return dubboSysRoleExtDataSampleService.findAll(queryMap);
	}

	/****************************************** extends BaseService 部分   end ******************************************/


	public void addSysRoleExtDataSample(String token, SysRoleExtDataSampleParam param) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		param.setCreateTime(DateUtil.date());
		param.setCreateUserId(loginSysUser.getSysUserId());

		param.setUpdateTime(DateUtil.date());
		param.setUpdateUserId(loginSysUser.getSysUserId());

		param.setSourceFrom(CommonSourceFromEnum.结算中心.getSourceFromCode());

		dubboSysRoleExtDataSampleService.addSysRoleExtDataSample(param);
	}


	public void updateSysRoleExtDataSample(String token, SysRoleExtDataSampleParam param) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		param.setCreateTime(DateUtil.date());
		param.setCreateUserId(loginSysUser.getSysUserId());

		param.setUpdateTime(DateUtil.date());
		param.setUpdateUserId(loginSysUser.getSysUserId());

		param.setSourceFrom(CommonSourceFromEnum.结算中心.getSourceFromCode());

		dubboSysRoleExtDataSampleService.updateSysRoleExtDataSample(param);
	}


	public void deleteSysRoleExtDataSample(Long id) {
		dubboSysRoleExtDataSampleService.deleteSysRoleExtDataSample(id);
	}


	public SysRoleExtDataSample findSysRoleExtDataSampleById(Long id) {

		return dubboSysRoleExtDataSampleService.findSysRoleExtDataSampleById(id);
	}


	public R<List<SysRoleExtDataSample>> pageQuery(Map<String, Object> conditions, int pageNun, int pageSize) {

		return dubboSysRoleExtDataSampleService.pageQuery(conditions, pageNun, pageSize);
	}
}
