package cn.superdesk.uniorder.dubbo.consumer.organisation;

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.organisation.SysEnterprise;
import cn.superdesk.uniorder.dto.param.operationCenter.base.OperationCenterParam;
import cn.superdesk.uniorder.dto.param.organisation.SysEnterpriseParam;
import cn.superdesk.uniorder.dto.param.organisation.SysEnterpriseQueryCriteria;
import cn.superdesk.uniorder.dto.param.organisation.SysVirtQueryParam;
import cn.superdesk.uniorder.dto.vo._function.select.SelectOptionVirt;
import cn.superdesk.uniorder.dto.vo.sys.SysOrganizationXEnterpriseVo;
import cn.superdesk.uniorder.dto.vo.sys.SysSelectVo;
import cn.superdesk.uniorder.dto.vo.sys.SysVirtVo;
import cn.superdesk.uniorder.dubbo.consumer._permission.PermissionDubboCustomerService;
import cn.superdesk.uniorder.dubbo.facade.organisation.DubboSysEnterpriseService;
import cn.superdesk.uniorder.common.numerical.AnCollectionUtils;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Slf4j
@Component
public class SysEnterpriseDubboConsumerService {

	@Reference(version = "1.0.0", timeout = 30000, retries = -1)
	private DubboSysEnterpriseService dubboSysEnterpriseService;

	@Resource
	private PermissionDubboCustomerService permissionDubboCustomerService;


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

	public void addObj(SysEnterpriseParam param) {

		dubboSysEnterpriseService.addObj(param);

	}

	public void updateObj(SysEnterpriseParam param) {

		dubboSysEnterpriseService.updateObj(param);
	}

	public void deleteObj(Long id) {

		dubboSysEnterpriseService.deleteObj(id);
	}
//	public void delObj(Long id) {
//
//		dubboSysEnterpriseService.delObj(id);
//	}

	public SysEnterprise findById(Long id) {

		return dubboSysEnterpriseService.findById(id);
	}


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

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

	public List<SysOrganizationXEnterpriseVo> findSysOrganizationXEnterprise(Map<String, Object> queryMap) {

		return dubboSysEnterpriseService.findSysOrganizationXEnterprise(queryMap);
	}

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


	public void addSysEnterprise(SysEnterpriseParam param) {

		dubboSysEnterpriseService.addSysEnterprise(param);
	}


	public void updateSysEnterprise(SysEnterpriseParam param) {

		dubboSysEnterpriseService.updateSysEnterprise(param);
	}


	public void deleteSysEnterprise(Long id) {
		dubboSysEnterpriseService.deleteSysEnterprise(id);
	}


	/**
	 * @param id
	 * @return
	 */
	public SysEnterprise findSysEnterpriseById(/*统一订单的企业id*/Long id) {

		return dubboSysEnterpriseService.findSysEnterpriseById(id);
	}


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

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

	public R<List<SysOrganizationXEnterpriseVo>> pageQuery(SysEnterpriseQueryCriteria queryCriteria,String token) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
		return dubboSysEnterpriseService.pageQuery(queryCriteria, loginSysUser);
	}


	/****************************************** 之前的 要合并 start ******************************************/


	public SysEnterprise findByVirtId(Long id) {

		return dubboSysEnterpriseService.findByVirtId(id);
	}

	public List<SysEnterprise> findByOutVirtIds(List<Long> outVirtIds) {

		if (AnCollectionUtils.isNotEmpty(outVirtIds)) {
			return dubboSysEnterpriseService.findByOutVirtIds(outVirtIds);
		} else {
			return new ArrayList<>();
		}
	}

	public Map<Long, SysEnterprise> findByOutVirtIdsConvertKV(List<Long> outVirtIds) {

		Map<Long, SysEnterprise> result = new HashMap<>();

		result = dubboSysEnterpriseService.findByOutVirtIdsConvertKV(outVirtIds);

		return result;

	}

	public List<String> convertOutVirtIds2VirtNames(List<Long> outVirtIds) {

		if (AnCollectionUtils.isNotEmpty(outVirtIds)) {
			return dubboSysEnterpriseService.convertOutVirtIds2VirtNames(outVirtIds);
		} else {
			return new ArrayList<>();
		}

	}

//	public SysEnterprise findByVirId(Long orgId) {
//		return dubboSysEnterpriseService.findByVirId(orgId);
//	}

	public void add(SysEnterprise entity) {

		dubboSysEnterpriseService.add(entity);
	}

	public void update(SysEnterprise entity) {

		dubboSysEnterpriseService.update(entity);
	}

//	public void add(SysEnterprise t) {
//		dubboSysEnterpriseService.addObj(t);
//	}

//	public void update(SysEnterprise t) {
//		dubboSysEnterpriseService.updateObj(t);
//	}

	public List<SysEnterprise> findByName(Long orgId, String enterpriseName) {
		return dubboSysEnterpriseService.findByName(orgId, enterpriseName);
	}

	public R<List<SelectOptionVirt>> getVirtSelect(Map<String, Object> params, int pageNum, int pageSize, String token) {

		// 20191205 add 数据权限
		Boolean isPass = permissionDubboCustomerService.addOnPerm(token, params);
		if (isPass.equals(false)) {
			R<List<SelectOptionVirt>> responseResult = new R<>();
			responseResult.setSuccess(false);
			responseResult.setMessage("您没有企业数据权限！");
			return responseResult;
		}
		return dubboSysEnterpriseService.getVirtSelect(params, pageNum, pageSize);
	}

	public void addSpecDaiDeLiangHang(Long id) {

		dubboSysEnterpriseService.addSpecDaiDeLiangHang(id);
	}

	public void deleteDaiDeLiangHang(Long id) {

		dubboSysEnterpriseService.deleteDaiDeLiangHang(id);
	}


	public void mergeReceiveVirtualarchitecture4SuperdeskMall(String message) {
		dubboSysEnterpriseService.mergeReceiveVirtualarchitecture4SuperdeskMall(message);
	}

	/**
	 * 20200707 林志鹏说是没删除
	 *
	 * @param message
	 */
	@Deprecated
	public void deleteReceiveVirtualarchitecture4SuperdeskMall(String message) {
		dubboSysEnterpriseService.deleteReceiveVirtualarchitecture4SuperdeskMall(message);
	}


	/****************************************** 之前的 要合并   end ******************************************/


	public void mergeReceiveVirtualarchitecture4SuperdeskTransfer(String message) {
		dubboSysEnterpriseService.mergeReceiveVirtualarchitecture4SuperdeskTransfer(message);
	}

	public void deleteReceiveVirtualarchitecture4SuperdeskTransfer(String message) {
		dubboSysEnterpriseService.deleteReceiveVirtualarchitecture4SuperdeskTransfer(message);
	}

	public R<List<SysVirtVo>> getVirtList(SysVirtQueryParam param){
		return dubboSysEnterpriseService.getVirtList(param);
	}

	public List<SysSelectVo> selectList(OperationCenterParam params){
		return dubboSysEnterpriseService.selectList(params);
	}

}
