package com.dxhy.sign.service.qsgz.impl;

import com.dxhy.common.vo.Tax;
import com.dxhy.common.vo.UserInfo;
import com.dxhy.sign.entity.TDxRecordInvoice;
import com.dxhy.sign.service.qsgz.RulesService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

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

@Service("1010")
public class Rules1010ServiceImpl implements RulesService {


    /**
     * 艺龙公司编码
     */
    @Value("${oldOrgName}")
    private String oldOrgName;

    @Override
    public String validationRules(UserInfo userInfo, String qsType, Map<String, String> pramsMap, TDxRecordInvoice recordInvoice, String invoiceType) {
        // 1010 购方名称强制校验（与1003规则冲突）
        List<Tax> taxList = userInfo.getOrg();
        Map<String, String> map = new HashMap<>();

        for (Tax tax : taxList) {
            tax.setTaxname(tax.getTaxname().trim());
            map.put(tax.getTaxno(), tax.getTaxname());

        }
        String taxname = map.get(recordInvoice.getGfTaxNo());
        if (!taxname.equals(recordInvoice.getGfName().trim())) {
            if (StringUtils.isBlank(oldOrgName) || !oldOrgName.contains(recordInvoice.getGfName().trim())) {
                // 发票上的购方名称不在登录账号能操作的购方税号范围内
                return "登录人公司名称与发票的购方名称不一致";
            }
        }
        return "";
    }

    @Override
    public String getEdiType() {
        return "1010";
    }
}
