package cn.superdesk.uniorder.dubbo.consumer.invoice.common;

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.invoice.common.InvoiceBankInfo;
import cn.superdesk.uniorder.dto.param.invoice.common.InvoiceBankInfoParam;
import cn.superdesk.uniorder.dto.param.invoice.common.InvoiceBankInfoQueryCriteria;
import cn.superdesk.uniorder.dubbo.facade.invoice.common.DubboInvoiceBankInfoService;
import com.alibaba.dubbo.config.annotation.Reference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

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

@Slf4j
@Component
public class InvoiceBankInfoDubboConsumerService {

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

	public int addInvoiceBankInfo(InvoiceBankInfo param, String token) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		return dubboInvoiceBankInfoService.addInvoiceBankInfo(param, loginSysUser);
	}

	public int updateInvoiceBankInfo(InvoiceBankInfo param, String token) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		return dubboInvoiceBankInfoService.updateInvoiceBankInfo(param, loginSysUser);
	}


	public int opPhysicsDelete(Long id, String token) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		return dubboInvoiceBankInfoService.opPhysicsDelete(id, loginSysUser);
	}

	public int opLogicalDelete(Long id, String token) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		return dubboInvoiceBankInfoService.opPhysicsDelete(id, loginSysUser);
	}


	public int opSetDefault(Long id, String token) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		return dubboInvoiceBankInfoService.setDefault(id, loginSysUser);
	}

	public int opSetNormal(Long id, String token) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		return dubboInvoiceBankInfoService.setNormal(id, loginSysUser);
	}

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

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
		return dubboInvoiceBankInfoService.pageQuery(conditions, pageNun, pageSize);
	}

	public List<InvoiceBankInfo> query(InvoiceBankInfoQueryCriteria queryCriteria, String token) {

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		return dubboInvoiceBankInfoService.query(queryCriteria, loginSysUser);
	}

	public R<List<InvoiceBankInfoParam>> pageQuery(InvoiceBankInfoQueryCriteria queryCriteria, String token) {

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

	/****************************************** 缓存 start ******************************************/

	/**
	 * 初始化
	 */
	public void cacheInit() {
		dubboInvoiceBankInfoService.cacheInit();
	}

	/**
	 * 刷新
	 */
	public void cacheRefresh() {
		dubboInvoiceBankInfoService.cacheRefresh();
	}

	/**
	 * 清除
	 */
	public void cacheRemove() {
		dubboInvoiceBankInfoService.cacheRemove();
	}

	public String cacheGet(String hashTable, String keyField) {
		return dubboInvoiceBankInfoService.cacheGet(hashTable, keyField);
	}
}
