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

104 lines
5.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package tqq9.lc123.cloud.app.plugin.form.conm;
import com.alibaba.fastjson.JSONObject;
import com.bes.gson.Gson;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.datamodel.ListSelectedRow;
import kd.bos.entity.datamodel.ListSelectedRowCollection;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.operate.FormOperate;
import kd.bos.list.BillList;
import kd.bos.list.plugin.AbstractListPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
import tqq9.lc123.cloud.app.eip.iscb.LCLogService;
import tqq9.lc123.cloud.app.eip.iscb.impl.LCLogServiceImpl;
import tqq9.lc123.cloud.app.plugin.utils.HttpRequestUtils;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* 标准单据列表插件
* 采购合同变更调用返利规则状态查询
*/
public class ConmChangePlugin extends AbstractListPlugin implements Plugin {
final static String KEY_OPKEY = "bizchange";
private static String Change_URL;
private static String FLXT_TOKEN;
static {
DynamicObject url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
new QFilter[]{new QFilter("number", QCP.equals, "FLXT_Change_Url")});
Change_URL = url != null ? url.getString("name") : null;
DynamicObject token = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
new QFilter[]{new QFilter("number", QCP.equals, "FLXT_TOKEN")});
FLXT_TOKEN = token != null ? token.getString("name") : null;
}
@Override
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
super.beforeDoOperation(args);
FormOperate formOperate = (FormOperate) args.getSource();
if (StringUtils.equals(KEY_OPKEY, formOperate.getOperateKey())) {
LCLogService lcLogService = new LCLogServiceImpl();
BillList billlistap = this.getControl("billlistap");
HashMap<String, Object> params = new HashMap<>();
HashMap<String, String> headers = new HashMap<>();
headers.put("Authorization", FLXT_TOKEN);
ListSelectedRowCollection selectedRows = billlistap.getSelectedRows();
if (selectedRows != null && selectedRows.size() > 0) {
for (ListSelectedRow listSelectedRow : selectedRows) {
Object primaryKeyValue = listSelectedRow.getPrimaryKeyValue(); //获取单据pkid
DynamicObject dataEntity = BusinessDataServiceHelper.loadSingle("conm_purcontract",
new QFilter[]{new QFilter("id", QCP.equals, primaryKeyValue)});
DynamicObjectCollection tqq9Entryentity = dataEntity.getDynamicObjectCollection("tqq9_entryentity");
for (DynamicObject dynamicObject : tqq9Entryentity) {//
DynamicObject tqq9_pur_rebate = dynamicObject.getDynamicObject("tqq9_pur_rebate");
DynamicObject tqq9_pur_rebate1 = BusinessDataServiceHelper.loadSingle("tqq9_pur_rebate", new QFilter[]{new QFilter("id", QCP.equals, tqq9_pur_rebate.getLong("id"))});
String id = tqq9_pur_rebate1.getString("id");//获取返利单据id
String tqq9_rebateruleid = tqq9_pur_rebate1.getString("tqq9_rebateruleid");//获取返利规则id
if (tqq9_rebateruleid != null && id != null) {
params.put("id", tqq9_rebateruleid);
}
Gson gson = new Gson();
try {
String bodyString = HttpRequestUtils.doGet(Change_URL, params, headers);
JSONObject map = gson.fromJson(bodyString, JSONObject.class);
Integer code = map.getInteger("code");
if (code == 0) {
lcLogService.savelog("FL-查看规则状态", Change_URL, false, true, params.toString(), bodyString);
Map<String, Object> data = (Map<String, Object>) map.get("data");
if (data != null) {
Number statusNum = (Number) data.get("status");
if (statusNum != null) {
int status = statusNum.intValue();
if (status == -1 || status == 1 || status == 4) {
//终止流程
this.getView().showErrorNotification("该状态下不允许变更!");
args.setCancel(true);
return;
}
}
}
} else {
lcLogService.savelog("FL-查看规则状态", Change_URL, false, true, params.toString(), bodyString);
args.setCancel(true);
return;
}
} catch (IOException e) {
lcLogService.savelog("FL-查看规则状态", Change_URL, false, false, params.toString(), "接口调用报错errormessage:" + e.getMessage());
throw new RuntimeException(e + ",请求返利规则状态查询失败");
}
}
}
}
}
}
}