153 lines
7.8 KiB
Java
153 lines
7.8 KiB
Java
package tqq9.lc123.cloud.app.plugin.form.sys;
|
|
|
|
import kd.bos.dataentity.OperateOption;
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
import kd.bos.dataentity.utils.StringUtils;
|
|
import kd.bos.entity.datamodel.ListSelectedRowCollection;
|
|
import kd.bos.entity.operate.result.IOperateInfo;
|
|
import kd.bos.entity.operate.result.OperationResult;
|
|
import kd.bos.form.CloseCallBack;
|
|
import kd.bos.form.FormShowParameter;
|
|
import kd.bos.form.ShowType;
|
|
import kd.bos.form.control.events.BeforeItemClickEvent;
|
|
import kd.bos.form.events.ClosedCallBackEvent;
|
|
import kd.bos.list.BillList;
|
|
import kd.bos.list.plugin.AbstractListPlugin;
|
|
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.bos.servicehelper.operation.OperationServiceHelper;
|
|
import kd.sdk.plugin.Plugin;
|
|
import tqq9.lc123.cloud.app.api.utils.Constants;
|
|
|
|
import java.util.*;
|
|
|
|
/**
|
|
* 供应商列表插件
|
|
*/
|
|
public class SupplierFormPlugin extends AbstractListPlugin implements Plugin {
|
|
private final static Log logger = LogFactory.getLog(SupplierFormPlugin.class);
|
|
|
|
@Override
|
|
public void beforeItemClick(BeforeItemClickEvent evt) {
|
|
super.beforeItemClick(evt);
|
|
String itemKey = evt.getItemKey();
|
|
if ("tqq9_qyzzbg".equals(itemKey)) {
|
|
BillList billList = this.getControl(AbstractListPlugin.BILLLISTID);
|
|
ListSelectedRowCollection selectedRows = billList.getSelectedRows();
|
|
if (selectedRows.size() > 0) {
|
|
HashSet<Object> ids = new HashSet<>();
|
|
StringBuilder errorMsg = new StringBuilder();
|
|
Object[] primaryKeyValues = selectedRows.getPrimaryKeyValues();
|
|
for (Object primaryKeyValue : primaryKeyValues) {
|
|
ids.add(primaryKeyValue);
|
|
}
|
|
DynamicObject[] bd_suppliers = BusinessDataServiceHelper.load("bd_supplier", "id,number,status,enable,tqq9_mulcombofield1,createorg", new QFilter[]{new QFilter("id", QCP.in, ids)});
|
|
for (DynamicObject bd_supplier : bd_suppliers) {
|
|
String number = bd_supplier.getString("number");
|
|
String status = bd_supplier.getString("status");
|
|
if (!StringUtils.equals("C", status)) {
|
|
errorMsg.append(",").append("供应商编码 " + number + "未审核");
|
|
}
|
|
String enable = bd_supplier.getString("enable");
|
|
if (!StringUtils.equals("1", enable)) {
|
|
errorMsg.append(",").append("供应商编码 " + number + "未启用");
|
|
}
|
|
}
|
|
if (errorMsg.length() > 0) {
|
|
this.getView().showErrorNotification(errorMsg.substring(1));
|
|
return;
|
|
}
|
|
FormShowParameter param = new FormShowParameter();
|
|
param.setFormId("tqq9_gysqyzz");
|
|
param.setCloseCallBack(new CloseCallBack(this, "updateFilter"));
|
|
param.setCustomParam("ids", ids.toString());
|
|
param.getOpenStyle().setShowType(ShowType.Modal);
|
|
this.getView().showForm(param);
|
|
} else {
|
|
this.getView().showErrorNotification("请先选中供应商数据");
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
|
|
super.closedCallBack(closedCallBackEvent);
|
|
if (closedCallBackEvent.getActionId().equals("updateFilter")) {
|
|
Object returnData = closedCallBackEvent.getReturnData();
|
|
if (returnData != null) {
|
|
Map data = (Map) returnData;
|
|
Boolean isContinue = (Boolean) data.get("isContinue");
|
|
if (isContinue == null || !isContinue) {
|
|
return;
|
|
}
|
|
String tqq9_qyzz = data.get("tqq9_qyzz").toString();
|
|
String tqq9_ids = data.get("tqq9_ids").toString();
|
|
String[] stringArray = tqq9_ids.substring(1, tqq9_ids.length() - 1).split(", ");
|
|
List<Long> longList = new ArrayList<>();
|
|
for (String str : stringArray) {
|
|
longList.add(Long.parseLong(str));
|
|
}
|
|
HashMap<Object, String> supplierMap = new HashMap<>();
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
DynamicObject[] bd_suppliers =new DynamicObject[longList.size()];
|
|
for (int i = 0; i < longList.size(); i++) {
|
|
bd_suppliers[i]= BusinessDataServiceHelper.loadSingle("bd_supplier", new QFilter[]{new QFilter("id", QCP.in, longList.get(i))});
|
|
}
|
|
for (DynamicObject bd_supplier : bd_suppliers) {
|
|
supplierMap.put(bd_supplier.get("id"),bd_supplier.getString("number"));
|
|
}
|
|
OperateOption operateOption = OperateOption.create();
|
|
OperationResult unauditResult = OperationServiceHelper.executeOperate(Constants.TYPE_UNAUDIT, "bd_supplier", bd_suppliers, operateOption);
|
|
if(!unauditResult.isSuccess()){
|
|
List<IOperateInfo> allErrorOrValidateInfo = unauditResult.getAllErrorOrValidateInfo();
|
|
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
|
|
String supNumber = supplierMap.get(iOperateInfo.getPkValue());
|
|
String message = iOperateInfo.getMessage();
|
|
stringBuilder.append(",").append("编码为 ").append(supNumber).append(" 的供应商反审核失败,"+message);
|
|
}
|
|
String message = unauditResult.getMessage();
|
|
String simpleMessage = unauditResult.getInteractionContext().getSimpleMessage();
|
|
if (message!=null){
|
|
stringBuilder.append(",").append(message);
|
|
}
|
|
if (message!=null){
|
|
stringBuilder.append(",").append(simpleMessage);
|
|
}
|
|
}
|
|
List<Object> successPkIds = unauditResult.getSuccessPkIds();
|
|
DynamicObject[] bd_suppliers1 =new DynamicObject[successPkIds.size()];
|
|
for (int i = 0; i < successPkIds.size(); i++) {
|
|
bd_suppliers1[i]= BusinessDataServiceHelper.loadSingle("bd_supplier", new QFilter[]{new QFilter("id", QCP.in, successPkIds.get(i))});
|
|
bd_suppliers1[i].set("tqq9_mulcombofield1",tqq9_qyzz);
|
|
}
|
|
OperationResult sumbitResult = OperationServiceHelper.executeOperate(Constants.TYPE_SUBMIT, "bd_supplier", bd_suppliers1, operateOption);
|
|
if (!sumbitResult.isSuccess()) {
|
|
List<IOperateInfo> allErrorOrValidateInfo = unauditResult.getAllErrorOrValidateInfo();
|
|
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
|
|
String supNumber = supplierMap.get(iOperateInfo.getPkValue());
|
|
String message = iOperateInfo.getMessage();
|
|
stringBuilder.append(",").append("编码为 ").append(supNumber).append(" 的供应商提交失败,"+message);
|
|
}
|
|
String message = sumbitResult.getMessage();
|
|
String simpleMessage = sumbitResult.getInteractionContext().getSimpleMessage();
|
|
if (message!=null){
|
|
stringBuilder.append(",").append(message);
|
|
}
|
|
if (message!=null){
|
|
stringBuilder.append(",").append(simpleMessage);
|
|
}
|
|
}
|
|
if(stringBuilder.length()>0){
|
|
this.getView().showErrorNotification(stringBuilder.substring(1));
|
|
return;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} |