package com.yem.wm.im.placeexamine.op;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.entity.plugin.args.BeforeOperationArgs;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;

public class PlaceExamineSaveOp extends AbstractOperationServicePlugIn {

    @Override
    public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
        super.beforeExecuteOperationTransaction(e);
        if ("save".equals(e.getOperationKey())) {
//            if (null != e.getDataEntities()) {
//                DynamicObject[] bills = e.getDataEntities();
//                for (int i = 0; i < bills.length; ++i) {
//                    DynamicObject bill = bills[i];
//                    saveyemtitle(bill);
//                }
//            }
        }
    }

    @Override
    public void afterExecuteOperationTransaction(AfterOperationArgs e) {
        super.afterExecuteOperationTransaction(e);
        DynamicObject[] bills = e.getDataEntities();
//
//        for (int i = 0; i < bills.length; ++i) {
//            DynamicObject bill = bills[i];
//            saveyemtitle(bill);
//        }
    }

    private void saveyemtitle(DynamicObject bill) {
        DynamicObject yemOperator = bill.getDynamicObject("yem_operator");
        String yem_title = "";
        if (yemOperator != null) {
            String name = yemOperator.getString("name");
            yem_title = yem_title + name + " ";
        }
        DynamicObject yemClientcountry = bill.getDynamicObject("yem_clientcountry");
        if (yemClientcountry != null) {
            String name = yemClientcountry.getString("name");
            yem_title = yem_title + name + " ";
        }
        String yemContractnumber = bill.getString("yem_contractnumber");
        if (!yemContractnumber.equals("")) {
            yem_title = yem_title + yemContractnumber + " ";
        }
        DynamicObject yemBdProducts = bill.getDynamicObject("yem_bd_products");
        if (yemBdProducts != null) {
            String name = yemBdProducts.getString("name");
            yem_title = yem_title + name + " ";
        }
        DynamicObject yemBilltype = bill.getDynamicObject("yem_billtype");
        if (yemBilltype != null) {
            String name = yemBilltype.getString("name");
            yem_title = yem_title + name + " ";
        }
        String billno = bill.getString("billno");
        if (!"".equals(billno)) {
            yem_title = yem_title + billno + " ";
        }
        bill.set("yem_titles", yem_title);
        SaveServiceHelper.update(bill);
    }
}
