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

import cn.hutool.core.date.DateUtil;
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.SysRoleExtData;
import cn.superdesk.uniorder.dto.dubbo.sys.role.SysRoleExtDataParam;
import cn.superdesk.uniorder.dubbo.facade.sys.role.DubboSysRoleExtDataService;
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 SysRoleExtDataDubboConsumerService {

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


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

	public void addObj(SysRoleExtDataParam param) {

		dubboSysRoleExtDataService.addObj(param);

	}

	public void updateObj(SysRoleExtDataParam param) {

		dubboSysRoleExtDataService.updateObj(param);
	}

	public void deleteObj(Long id) {

		dubboSysRoleExtDataService.deleteObj(id);
	}

	public SysRoleExtData findById(Long id) {

		return dubboSysRoleExtDataService.findById(id);
	}

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

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

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

		return dubboSysRoleExtDataService.findAll(queryMap);
	}

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


	public void addSysRoleExtData(String token, SysRoleExtDataParam param) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
		param.setCreateTime(DateUtil.date());
		param.setCreateUserId(loginSysUser.getSysUserId());
		param.setUpdateTime(DateUtil.date());
		param.setUpdateUserId(loginSysUser.getSysUserId());

		dubboSysRoleExtDataService.addSysRoleExtData(param);
	}


	public void updateSysRoleExtData(String token, SysRoleExtDataParam param) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

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

		dubboSysRoleExtDataService.updateSysRoleExtData(param);
	}


	public void deleteSysRoleExtData(Long id) {
		dubboSysRoleExtDataService.deleteSysRoleExtData(id);
	}


	public SysRoleExtData findSysRoleExtDataById(Long id) {

		return dubboSysRoleExtDataService.findSysRoleExtDataById(id);
	}


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

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