137 lines
7.6 KiB
Java
137 lines
7.6 KiB
Java
package tqq9.lc123.cloud.app.plugin.operate.im;
|
|
|
|
import com.google.gson.Gson;
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
import kd.bos.entity.ExtendedDataEntity;
|
|
import kd.bos.entity.ExtendedDataEntitySet;
|
|
import kd.bos.entity.botp.plugin.AbstractConvertPlugIn;
|
|
import kd.bos.entity.botp.plugin.args.AfterConvertEventArgs;
|
|
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.math.BigDecimal;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 单据转换插件
|
|
*/
|
|
public class PurApplyPushPurOrderConverPlugin extends AbstractConvertPlugIn implements Plugin {
|
|
|
|
private static String URL;
|
|
|
|
private static String FLXT_TOKEN;
|
|
|
|
|
|
static {
|
|
DynamicObject url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
|
|
new QFilter[]{new QFilter("number", QCP.equals, "FLXT_Balance_Url")});
|
|
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 afterConvert(AfterConvertEventArgs e) {
|
|
super.afterConvert(e);
|
|
ExtendedDataEntitySet targetExtDataEntitySet = e.getTargetExtDataEntitySet();
|
|
ExtendedDataEntity[] extendedDataEntities = targetExtDataEntitySet.FindByEntityKey("pm_purorderbill");
|
|
Map<String, String> variables = this.getOption().getVariables();
|
|
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
|
|
//采购订单
|
|
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
|
|
DynamicObject supplier = dataEntity.getDynamicObject("supplier");
|
|
BigDecimal totalAmount = BigDecimal.ZERO;
|
|
BigDecimal totalCount = BigDecimal.ZERO;
|
|
if (null != supplier) {
|
|
//查询已审核未关闭非克隆(上游单据编号为空)数量-到货数量、有优惠有返利含税单价*(数量-到货数量)
|
|
|
|
// 查询正常的采购订单 总额,总数量
|
|
QFilter f1 = new QFilter("supplier.id", "=", supplier.getPkValue());
|
|
QFilter f2 = new QFilter("billstatus", "=", "C");//已审核
|
|
QFilter f3 = new QFilter("closestatus", "=", "A");//关闭状态正常
|
|
QFilter f4 = new QFilter("tqq9_sourcebillno", "=", "");//上游单据编号为空
|
|
DynamicObject[] pmBillArr = BusinessDataServiceHelper.load("pm_receiptnotice",
|
|
"id,billno,supplier,billentry.qty,billentry.tqq9_dhsl,billentry.tqq9_yyhyflje,tqq9_sourcebillno",
|
|
new QFilter[]{f1, f2, f3, f4});
|
|
for (DynamicObject bill : pmBillArr) {
|
|
//String billno = bill.getString("billno");
|
|
//String tqq9_sourcebillno = bill.getString("tqq9_sourcebillno");
|
|
DynamicObjectCollection entries = bill.getDynamicObjectCollection("billentry");
|
|
for (DynamicObject entry : entries) {
|
|
BigDecimal qty = entry.getBigDecimal("qty") == null ? BigDecimal.ZERO : entry.getBigDecimal("qty");//数量
|
|
BigDecimal tqq9_dhsl = entry.getBigDecimal("tqq9_dhsl") == null ? BigDecimal.ZERO : entry.getBigDecimal("tqq9_dhsl");//到货数量
|
|
BigDecimal wrkqty = qty.subtract(tqq9_dhsl);//未入库数量
|
|
totalCount = totalCount.add(wrkqty);
|
|
BigDecimal tqq9_disandrefoundprice = entry.getBigDecimal("tqq9_yyhyflje") == null ?
|
|
BigDecimal.ZERO : entry.getBigDecimal("tqq9_yyhyflje");//有优惠有返利含税单价
|
|
BigDecimal wrkAmount = tqq9_disandrefoundprice.multiply(wrkqty);
|
|
totalAmount = totalAmount.add(wrkAmount);
|
|
}
|
|
}
|
|
dataEntity.set("tqq9_lswdhje", totalAmount);
|
|
dataEntity.set("tqq9_lswdhsl", totalCount);
|
|
|
|
LCLogService lcLogService = new LCLogServiceImpl();
|
|
HashMap<String, String> tokenMap = new HashMap<String, String>();
|
|
tokenMap.put("Authorization", FLXT_TOKEN);
|
|
DynamicObject org = dataEntity.getDynamicObject("org");//组织
|
|
if (supplier != null && org != null) {
|
|
String number = org.getString("number");
|
|
DynamicObject org_fl = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
|
|
new QFilter[]{new QFilter("number", QCP.equals, number)});
|
|
String orgid_fl = org_fl != null ? org_fl.getString("name") : null;
|
|
HashMap<String, Object> queryMap = new HashMap<>();
|
|
String tqq9_ztsupplierid = supplier.getString("tqq9_ztsupplierid");
|
|
if (kd.bos.dataentity.utils.StringUtils.isBlank(tqq9_ztsupplierid)) {
|
|
tqq9_ztsupplierid = "0";
|
|
}
|
|
queryMap.put("supplierId", tqq9_ztsupplierid);
|
|
queryMap.put("companyId", orgid_fl);
|
|
Gson gson = new Gson();
|
|
try {
|
|
String bodyString = HttpRequestUtils.doGet(URL, queryMap, tokenMap);
|
|
HashMap map = gson.fromJson(bodyString, HashMap.class);
|
|
ArrayList<Map<String, Object>> data = (ArrayList) map.get("data");
|
|
if (data != null) {
|
|
for (Map datum : data) {
|
|
Map<String, Object> dataMap = datum;
|
|
String type = dataMap.get("type").toString();//类型
|
|
BigDecimal totalMoney = new BigDecimal((Double) dataMap.get("totalMoney"));//剩余总金额
|
|
BigDecimal totalMoneyAvailable = new BigDecimal((Double) dataMap.get("totalMoneyAvailable"));//可使用金额
|
|
if (kd.bos.dataentity.utils.StringUtils.equals(type, "0.0")) {
|
|
//货返
|
|
dataEntity.set("tqq9_hshfzje", totalMoney);//含税货返总金额
|
|
dataEntity.set("tqq9_hshfkyje", totalMoneyAvailable);//含税货返可用金额
|
|
} else if (kd.bos.dataentity.utils.StringUtils.equals(type, "1.0")) {
|
|
//现返
|
|
dataEntity.set("tqq9_hsxfzje", totalMoney);//含税现返总金额
|
|
dataEntity.set("tqq9_hsxfkyje", totalMoneyAvailable);//含税现返可用金额
|
|
}
|
|
}
|
|
lcLogService.savelog("查询返利金额", URL, false, true, queryMap.toString(), bodyString);
|
|
}
|
|
} catch (IOException ex) {
|
|
lcLogService.savelog("查询返利金额", URL, false, false, queryMap.toString(), "接口调用报错,无返回值");
|
|
throw new RuntimeException(ex + ",请求返利系统失败");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|