dobe_comic8/main/java/shkd/repc/rebm/formplugin/DecisionJumpToConPlanPlugin...

171 lines
8.2 KiB
Java

package shkd.repc.rebm.formplugin;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.bill.BillShowParameter;
import kd.bos.bill.OperationStatus;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.entity.LocaleString;
import kd.bos.dataentity.metadata.IDataEntityProperty;
import kd.bos.dataentity.resource.ResManager;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.AppInfo;
import kd.bos.entity.AppMenuInfo;
import kd.bos.entity.AppMetadataCache;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.exception.KDException;
import kd.bos.form.*;
import kd.bos.form.container.Tab;
import kd.bos.form.control.Control;
import kd.bos.form.control.Toolbar;
import kd.bos.form.control.events.ItemClickEvent;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.field.AmountEdit;
import kd.bos.form.field.DecimalEdit;
import kd.bos.portal.util.OpenPageUtils;
import kd.sdk.plugin.Plugin;
import kd.svc.control.events.AppNavigationMenuEvent;
import java.math.BigDecimal;
import java.util.*;
/**
* 单据界面插件
*/
public class DecisionJumpToConPlanPlugin extends AbstractBillPlugIn implements Plugin {
/*
* 定标
* 1.点击‘变更合约规划’按钮跳转到成本管理的 目标成本调整
* 2.将采购明细中的规划金额 < 供应商信息的最终价 所对应的采购项目带到目标成本调整中
* */
@Override
public void afterBindData(EventObject e) {
super.afterBindData(e);
IDataModel model = this.getModel();
String conPlanAdjust = (String) model.getValue("qeug_conplan_adjust");// 关联合约规划调整
if (!conPlanAdjust.isEmpty()) {
IFormView view = this.getView();
view.setVisible(true, "qeug_planamount");
view.setVisible(true, "qeug_botcontrolamount");
DecimalEdit planAmount = getControl("planamount");// 规划金额(含税)
AmountEdit controlAmount = getControl("botcontrolamount");// 采购控制金额(含税)
planAmount.setCaption(new LocaleString("规划金额(变更后)"));
controlAmount.setCaption(new LocaleString("采购控制金额(变更后)"));
Map<String, IDataEntityProperty> allFields = this.getModel().getDataEntityType().getAllFields();
IDataEntityProperty field1 = allFields.get("planamount");
IDataEntityProperty field2 = allFields.get("botcontrolamount");
field1.getDisplayName().setLocaleValue("规划金额(变更后)");
field2.getDisplayName().setLocaleValue("采购控制金额(变更后)");
}
}
@Override
public void afterDoOperation(AfterDoOperationEventArgs eventArgs) {
String operateKey = eventArgs.getOperateKey();
if ("changeplan".equals(operateKey)) {
IFormView mainView = this.getView().getMainView();
IPageCache pageCache = mainView.getPageCache();
String tabPageKeys = pageCache.get("_Tab_Items_TabPageKeys");
boolean result = false;
String key = "";
if (!tabPageKeys.isEmpty()) {
String[] splits = tabPageKeys.replaceAll("\\[", "").replaceAll("]", "").split(",");
for (String split : splits) {
if (split.contains("recos")) {
key = split.replaceAll("\"", "");
result = true;
break;
}
}
}
if (!result) {
FormShowParameter formShowParameter = new FormShowParameter();
formShowParameter.setAppId("recos");
formShowParameter.getOpenStyle().setShowType(ShowType.NewTabPage);
formShowParameter.getOpenStyle().setTargetKey("tabap");
formShowParameter.setCustomParam("formId", "recos_conplan");
formShowParameter.setCustomParam("appImageUrl", "icons/pc/application/fdc_cbgl_48_48.png");
formShowParameter.setCustomParam("appid", "recos");
formShowParameter.setFormId("recos_apphome");
formShowParameter.setCaption("成本管理");
formShowParameter.setPageId("recos" + mainView.getPageId());
mainView.showForm(formShowParameter);
getView().sendFormAction(mainView);
} else {
Tab tab = mainView.getControl("tabap");
tab.activeTab(key);
}
IDataModel model = this.getModel();
String purProjectNum = "";
DynamicObjectCollection bidSections = model.getEntryEntity("bidsection");// 标段
DynamicObjectCollection bottomSections = model.getEntryEntity("bottomsection");// 标底标段
DynamicObjectCollection supplierEntries = model.getEntryEntity("supplierentry");// 定标供应商
DynamicObjectCollection bottomEntries = model.getEntryEntity("bottomentry");// 采购明细
if (bidSections != null && supplierEntries != null && bottomSections != null && bottomEntries != null) {
for (DynamicObject bidSection : bidSections) {
BigDecimal finalPriceSum = new BigDecimal(0);
int seq = bidSection.getInt("seq");
long entryId = bidSection.getLong("id");
for (DynamicObject supplierEntry : supplierEntries) {
DynamicObject parent = (DynamicObject) supplierEntry.getParent();
if (entryId == parent.getLong("id")) {// 判断是否该标段对应的供应商
if (supplierEntry.getBoolean("isrecommended")) {// 是否中标单位
BigDecimal finalPrice = supplierEntry.getBigDecimal("finalprice");
finalPriceSum = finalPriceSum.add(finalPrice);
}
}
}
DynamicObject project = null;
BigDecimal controlAmountSum = new BigDecimal(0);
for (DynamicObject bottomSection : bottomSections) {
int bottomSeq = bottomSection.getInt("seq");
if (seq == bottomSeq) {
long bottomEntryId = bottomSection.getLong("id");
if (!bottomEntries.isEmpty()) project = bottomEntries.get(0).getDynamicObject("botpurentryproject");
for (DynamicObject bottomEntry : bottomEntries) {
DynamicObject parent = (DynamicObject) bottomEntry.getParent();
if (bottomEntryId == parent.getLong("id")) {
BigDecimal controlAmount = bottomEntry.getBigDecimal("botcontrolamount");// 采购控制金额(含税)
controlAmountSum = controlAmountSum.add(controlAmount);
}
}
}
}
if (finalPriceSum.compareTo(controlAmountSum) >= 1) {
if (!bottomEntries.isEmpty() && project != null) {
purProjectNum = project.getString("number");
break;
}
}
}
}
String appPageID = "recos" + mainView.getPageId();
IFormView appPageView = mainView.getViewNoPlugin(appPageID);
BillShowParameter billShowParameter = new BillShowParameter();
billShowParameter.setFormId("recos_aimadjust");
billShowParameter.setBillStatusValue(0);
billShowParameter.getOpenStyle().setShowType(ShowType.MainNewTabPage);
billShowParameter.getOpenStyle().setTargetKey("_submaintab_");
billShowParameter.setCustomParam("decision_id", model.getDataEntity().getLong("id"));
billShowParameter.setCustomParam("purproject_number", purProjectNum);
appPageView.showForm(billShowParameter);
getView().sendFormAction(appPageView);
}
}
}