package com.zfire.mall.manager.logic.k3.bill;

import cn.hutool.core.collection.CollectionUtil;
import com.zfire.mall.manager.bean.k3.RequestExcuteOperationBean;
import com.zfire.mall.manager.bean.k3.bill.PurchaseInStockBean;
import com.zfire.mall.manager.bean.k3.bill.PurchaseOutStockBean;
import com.zfire.mall.manager.bean.k3.bill.SalesOrderBean;
import com.zfire.mall.manager.bean.k3.bill.TransferOrderBean;
import com.zfire.mall.manager.bean.k3.bill.result.BillItem;
import com.zfire.mall.manager.bean.k3.bill.result.ResultBean;
import com.zfire.mall.manager.bean.k3.bill.result.ResultEntity;
import com.zfire.mall.manager.bean.k3.bill.result.SuccessEntitys;
import com.zfire.mall.manager.constant.KingDeeCons;
import com.zfire.mall.manager.exception.RemoteServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class GeJiangInStockLogic extends CommonGeJiangOrderLogic {

    private static final String salesFieldKeys = "FInStockEntry_FSeq,FInStockEntry_FEntryID,FMaterialId,F_kls_Text";

    /**
     * 同步格匠采购入库单
     *
     * @param purchaseInStockBean
     * @return
     */
    public ResultEntity syncBillData(PurchaseInStockBean purchaseInStockBean) {
        try {
            ResultBean resultBean = super.syncBillData(purchaseInStockBean, KingDeeCons.PURCHASE_IN_STOCK, true);
            if (CollectionUtil.isEmpty(resultBean.getResponseStatus().getSuccessEntitys())) {
                throw new RemoteServiceException("未返回下游标识");
            }

            /*SuccessEntitys successEntitys = resultBean.getResponseStatus().getSuccessEntitys().get(0);
            List<BillItem> billItems = super.queryBillItemRowInfo(getQueryId(), successEntitys.getId(), salesFieldKeys, KingDeeCons.PURCHASE_IN_STOCK);
*/
            return null;
        } catch (Exception e) {
            log.error("格匠采购入库单同步失败！原因:", e);
            throw new RemoteServiceException("格匠采购入库单同步失败！原因:" + e.getMessage());
        }
    }

    /**
     * 反审核格匠采购入库单根据单据编号
     *
     * @param billNo
     * @return
     */
    public boolean unAuditByBillNo(String billNo) {
        try {
            return super.unAudit(getQueryBillNo(), billNo, KingDeeCons.PURCHASE_IN_STOCK);
        } catch (Exception e) {
            log.error("格匠采购入库单反审失败！原因:", e);
            throw new RemoteServiceException("格匠采购入库单反审失败！原因:" + e.getMessage());
        }
    }


    /**
     * 同步格匠采购退料单
     *
     * @param purchaseOutStockBean
     * @return
     */
    public ResultEntity syncBillTuiLiaoData(PurchaseOutStockBean purchaseOutStockBean) {
        try {
            ResultBean resultBean = super.syncBillData(purchaseOutStockBean, KingDeeCons.PURCHASE_RET_BILL, true);
            if (CollectionUtil.isEmpty(resultBean.getResponseStatus().getSuccessEntitys())) {
                throw new RemoteServiceException("未返回下游标识");
            }

            /*SuccessEntitys successEntitys = resultBean.getResponseStatus().getSuccessEntitys().get(0);
            List<BillItem> billItems = super.queryBillItemRowInfo(getQueryId(), successEntitys.getId(), salesFieldKeys, KingDeeCons.PURCHASE_IN_STOCK);
*/
            return null;
        } catch (Exception e) {
            log.error("格匠采购退料单同步失败！原因:", e);
            throw new RemoteServiceException("格匠采购退料单同步失败！原因:" + e.getMessage());
        }
    }

    /**
     * 反审核格匠采购入库单根据单据编号
     *
     * @param billNo
     * @return
     */
    public boolean unAuditByTuiLiaoBillNo(String billNo) {
        try {
            return super.unAudit(getQueryBillNo(), billNo, KingDeeCons.PURCHASE_RET_BILL);
        } catch (Exception e) {
            log.error("格匠采购退料单同步失败！原因:", e);
            throw new RemoteServiceException("格匠采购退料单同步失败！原因:" + e.getMessage());
        }
    }


}
