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

import cn.superdesk.uniorder.common.json.AnJsonUtils;
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.SysEnterpriseExtInvoice;
import cn.superdesk.uniorder.dto.param.invoice.txt.TaxationAisinoTxtRow;
import cn.superdesk.uniorder.dto.param.organisation.SysCliqueXInvoiceCriteria;
import cn.superdesk.uniorder.dto.param.organisation.SysEnterpriseExtInvoiceParam;
import cn.superdesk.uniorder.dto.param.organisation.SysEnterpriseExtInvoiceQueryCriteria;
import cn.superdesk.uniorder.dto.param.organisation.SysEnterpriseExtInvoiceXCliqueParam;
import cn.superdesk.uniorder.dto.vo.organisation.SysEnterpriseExtInvoiceExtPathVo;
import cn.superdesk.uniorder.dubbo.facade.organisation.DubboSysEnterpriseExtInvoiceService;
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 java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 企业信息-扩展-发票相关
 * @Author: linjinyu
 * @Email linjinyu@avic-s.com
 * @CreateDate: 2020-08-20 19:16:09
 * @UpdateUser: linjinyu
 * @UpdateDate: 2020-08-20 19:16:09
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Component
public class SysEnterpriseExtInvoiceDubboConsumerService {

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


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

    public void addObj(SysEnterpriseExtInvoiceParam param) {

        dubboSysEnterpriseExtInvoiceService.addObj(param);

    }

    public void updateObj(SysEnterpriseExtInvoiceParam param) {

        dubboSysEnterpriseExtInvoiceService.updateObj(param);
    }

    public void deleteObj(Long id) {

        dubboSysEnterpriseExtInvoiceService.deleteObj(id);
    }

    public SysEnterpriseExtInvoice findById(Long id) {

        return dubboSysEnterpriseExtInvoiceService.findById(id);
    }

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

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

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

        return dubboSysEnterpriseExtInvoiceService.findAll(queryMap);
    }

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


    public void addSysEnterpriseExtInvoiceXCliqueParam(SysEnterpriseExtInvoiceXCliqueParam param, String token) {

        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

        dubboSysEnterpriseExtInvoiceService.addSysEnterpriseExtInvoiceXCliqueParam(param, loginSysUser);
    }


    public void updateSysEnterpriseExtInvoiceXCliqueParam(SysEnterpriseExtInvoiceXCliqueParam param, String token) {

        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

        dubboSysEnterpriseExtInvoiceService.updateSysEnterpriseExtInvoiceXCliqueParam(param, loginSysUser);
    }


    public int addSysEnterpriseExtInvoice(SysEnterpriseExtInvoiceParam param, String token) {

        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

        return dubboSysEnterpriseExtInvoiceService.addSysEnterpriseExtInvoice(param, loginSysUser);
    }


    public int updateSysEnterpriseExtInvoice(SysEnterpriseExtInvoiceParam param, String token) {

        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

        return dubboSysEnterpriseExtInvoiceService.updateSysEnterpriseExtInvoice(param, loginSysUser);
    }

    public int opSetDefault(SysEnterpriseExtInvoice entity, String token) {

        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
        return dubboSysEnterpriseExtInvoiceService.opSetDefault(entity, loginSysUser);
    }

    public int opSetNormal(SysEnterpriseExtInvoice entity, String token) {

        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

        return dubboSysEnterpriseExtInvoiceService.opSetNormal(entity, loginSysUser);
    }

    public void deleteSysEnterpriseExtInvoice(Long id, String token) {

        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
        dubboSysEnterpriseExtInvoiceService.deleteSysEnterpriseExtInvoice(id, loginSysUser);
    }


    public SysEnterpriseExtInvoice findBySysVirtId(Long id) {

        return dubboSysEnterpriseExtInvoiceService.findBySysVirtId(id);
    }

    public SysEnterpriseExtInvoice getByCompanyName(String companyName) {
        return dubboSysEnterpriseExtInvoiceService.getByCompanyName(companyName);
    }

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

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

    }

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

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

        if (AnCollectionUtils.isNotEmpty(outVirtIds)) {

            return dubboSysEnterpriseExtInvoiceService.findByOutVirtIdsConvertKV(outVirtIds);
        }

        return result;

    }

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

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

    public R<List<SysEnterpriseExtInvoiceExtPathVo>> pageQuery(SysEnterpriseExtInvoiceQueryCriteria queryCriteria, String token) {

        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

        return dubboSysEnterpriseExtInvoiceService.pageQuery(queryCriteria, loginSysUser);
    }


    public R<List<SysEnterpriseExtInvoiceExtPathVo>> pageQuerySysCliqueXInvoice(SysCliqueXInvoiceCriteria conditions, int pageNun, int pageSize) {

        log.info("\nSysEnterpriseExtInvoiceDubboConsumerService.pageQuerySysCliqueXInvoice\n -> \n{}\n", AnJsonUtils.toJson(conditions));

        return dubboSysEnterpriseExtInvoiceService.pageQuerySysCliqueXInvoice(conditions, pageNun, pageSize);
    }


    /******************************************  start ******************************************/

    public void saveOrUpdate4TaxationAisinoTxtRowParamListByPurchaserTaxpayersIDCode(List<TaxationAisinoTxtRow> taxationAisinoTxtRowParamList, String token) {

        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

        dubboSysEnterpriseExtInvoiceService.saveOrUpdate4TaxationAisinoTxtRowParamListByPurchaserTaxpayersIDCode(taxationAisinoTxtRowParamList, loginSysUser);
    }


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

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

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

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

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