lc/lc123/cloud/app/plugin/form/conm/RebateRulesBillPlugin.java

122 lines
5.6 KiB
Java

package tqq9.lc123.cloud.app.plugin.form.conm;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.param.CustomParam;
import kd.bos.form.FormShowParameter;
import kd.bos.form.control.events.ItemClickEvent;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
import java.math.BigDecimal;
import java.util.Date;
import java.util.EventObject;
import java.util.HashMap;
import java.util.Map;
/**
* 返利规则表单插件
* 同步采购合同信息
*/
public class RebateRulesBillPlugin extends AbstractBillPlugIn implements Plugin {
private final static Log logger = LogFactory.getLog(RebateRulesBillPlugin.class);
@Override
public void registerListener(EventObject e) {
super.registerListener(e);
this.addItemClickListeners("tbmain");
}
@Override
public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
super.afterDoOperation(afterDoOperationEventArgs);
String itemKey = afterDoOperationEventArgs.getOperateKey();
if (StringUtils.equals("donothing", itemKey)) {
Object name = this.getModel().getValue("name");
Object tqq9_supplier = this.getModel().getValue("tqq9_supplier");
Object tqq9_startdate = this.getModel().getValue("tqq9_startdate");
Object tqq9_enddate = this.getModel().getValue("tqq9_enddate");
Object tqq9_estimatepro = this.getModel().getValue("tqq9_estimatepro");
Object tqq9_rebatebrand = this.getModel().getValue("tqq9_rebatebrand");
Object tqq9_rebategoods = this.getModel().getValue("tqq9_rebategoods");
if(name==null||tqq9_supplier==null||tqq9_startdate==null||tqq9_enddate==null||tqq9_estimatepro==null||tqq9_rebatebrand==null||tqq9_rebategoods==null){
this.getView().showErrorNotification("请确认必录项是否为空");
}else{
DynamicObject dataEntity = this.getModel().getDataEntity(true);
HashMap<String, DynamicObject> map = new HashMap<>();
map.put("tqq9_pur_rebate", dataEntity);
this.getView().returnDataToParent(map);
this.getView().close();
}
}
}
@Override
public void afterCreateNewData(EventObject e) {
// 获取当前页面的FormShowParameter对象
FormShowParameter formShowParameter = this.getView().getFormShowParameter();
// 获取自定义参数
String billno =formShowParameter.getCustomParam("purcontract_billno");
JSONObject purcontract_supplier = formShowParameter.getCustomParam("purcontract_supplier");
JSONArray purcontract_tqq9_dxpp = formShowParameter.getCustomParam("purcontract_tqq9_dxpp");
DynamicObject supplier = null;
// DynamicObject tqq9_dxpp = null;
DynamicObject purcontract = BusinessDataServiceHelper.loadSingle("conm_purcontract", new QFilter[]{new QFilter("billno", QCP.equals, billno)});
DynamicObjectCollection tqq9_supplier = this.getModel().getDataEntity().getDynamicObjectCollection("tqq9_supplier");
DynamicObjectCollection tqq9_rebatebrand = this.getModel().getDataEntity().getDynamicObjectCollection("tqq9_rebatebrand");
DynamicObject newsupplier = new DynamicObject(tqq9_supplier.getDynamicObjectType());
if (purcontract_supplier != null) {
String number = purcontract_supplier.get("number").toString();
supplier = BusinessDataServiceHelper.loadSingle("bd_supplier", new QFilter[]{new QFilter("number", QCP.equals, number)});
}
if (purcontract_tqq9_dxpp != null) {
for (int i = 0; i < purcontract_tqq9_dxpp.size(); i++) {
JSONObject jsonObject = (JSONObject)purcontract_tqq9_dxpp.get(i);
JSONObject fbasedataid = jsonObject.getJSONObject("fbasedataid");
String number = fbasedataid.getString("number");
DynamicObject tqq9_dxpp = BusinessDataServiceHelper.loadSingle("tqq9_brand", new QFilter[]{new QFilter("number", QCP.equals, number)});
if (tqq9_dxpp != null) {
DynamicObject newbrand = new DynamicObject(tqq9_rebatebrand.getDynamicObjectType());
newbrand.set("fbasedataId", tqq9_dxpp);
tqq9_rebatebrand.add(newbrand);
}
}
}
// 把参数值赋值到页面文本字段上
if (supplier != null) {
newsupplier.set("fbasedataId", supplier);
tqq9_supplier.add(newsupplier);
this.getModel().setValue("tqq9_supplier", tqq9_supplier);
}
this.getModel().setValue("tqq9_conm_purcontract", purcontract);
this.getModel().setValue("tqq9_rebatebrand", tqq9_rebatebrand);
}
// @Override
// public void itemClick(ItemClickEvent evt) {
// super.itemClick(evt);
// String itemKey = evt.getItemKey();
// if (StringUtils.equals("tqq9_confirm", itemKey)) {
// DynamicObject dataEntity = this.getModel().getDataEntity(true);
// HashMap<String, DynamicObject> map = new HashMap<>();
// map.put("tqq9_pur_rebate", dataEntity);
// this.getView().returnDataToParent(map);
// this.getView().close();
// }
// }
}