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

import com.yem.wm.im.inquirylist.vaildator.InquirylistVaildator;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.AddValidatorsEventArgs;
import kd.bos.entity.plugin.PreparePropertysEventArgs;
import kd.bos.entity.plugin.args.BeforeOperationArgs;

public class InquirylistSubmitOp extends AbstractOperationServicePlugIn {
    @Override
    public void onPreparePropertys(PreparePropertysEventArgs e) {
        e.getFieldKeys().add("yem_customer");
        e.getFieldKeys().add("yem_im_detailedinfor");
        e.getFieldKeys().add("yem_im_detailedinfor.yem_material");
        e.getFieldKeys().add("yem_im_detailedinfor.seq");
        e.getFieldKeys().add("billstatus");
        e.getFieldKeys().add("yem_enquirymessage");
        e.getFieldKeys().add("yem_remark");
        e.getFieldKeys().add("yem_titleoftheinquiry");

    }

    @Override
    public void onAddValidators(AddValidatorsEventArgs e) {
//        e.addValidator(new InquirylistVaildator());
        // disable 2024-04-26 zzs
    }

    @Override
    public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
        super.beforeExecuteOperationTransaction(e);
        for (DynamicObject dataEntity : e.getDataEntities()) {
            DynamicObject billtype = dataEntity.getDynamicObject("yem_billtype");
            if (billtype == null) continue;
            String number = billtype.getString("number");
            if (!"yem_im_inquirylist_ZJ".equals(number)) {
                String yemEnquirymessage = dataEntity.getString("yem_enquirymessage");
                String string = "";
                if ("A".equals(yemEnquirymessage)){
                    string = "自制件询价-大装";
                }else if ("B".equals(yemEnquirymessage)){
                    string = "自制件询价-小装";
                }else if ("C".equals(yemEnquirymessage)){
                    string = "自制件询价-农装";
                }else if ("D".equals(yemEnquirymessage)){
                    string = "自制件询价-叉车";
                }else if ("E".equals(yemEnquirymessage)){
                    string = "外购件询价-大装";
                }else if ("F".equals(yemEnquirymessage)){
                    string = "外购件询价-小装";
                }else if ("G".equals(yemEnquirymessage)){
                    string = "外购件询价-农装";
                }else if ("H".equals(yemEnquirymessage)){
                    string = "外购件询价-叉车";
                }
                String yemRemark = dataEntity.getString("yem_remark");
                if (!"".equals(yemRemark)&&!"".equals(string)){
                    dataEntity.set("yem_titleoftheinquiry",string+" "+yemRemark);
                }else if (!"".equals(yemRemark)){
                    dataEntity.set("yem_titleoftheinquiry",yemRemark);
                }else if (!"".equals(string)){
                    dataEntity.set("yem_titleoftheinquiry",string);
                }
            }
        }
    }
}
