接口类提交,退货补货逻辑修改
This commit is contained in:
parent
11289b0d11
commit
cb11222a65
|
|
@ -0,0 +1,261 @@
|
|||
|
||||
package tqq9.lc123.cloud.app.plugin.form.pm;
|
||||
|
||||
import kd.bos.algo.DataSet;
|
||||
import kd.bos.bill.BillShowParameter;
|
||||
import kd.bos.coderule.api.CodeRuleInfo;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.dataentity.utils.StringUtils;
|
||||
import kd.bos.db.DB;
|
||||
import kd.bos.db.DBRoute;
|
||||
import kd.bos.entity.datamodel.IDataModel;
|
||||
import kd.bos.form.CloseCallBack;
|
||||
import kd.bos.form.ShowFormHelper;
|
||||
import kd.bos.form.ShowType;
|
||||
import kd.bos.form.control.EntryGrid;
|
||||
import kd.bos.form.control.events.ItemClickEvent;
|
||||
import kd.bos.form.plugin.AbstractFormPlugin;
|
||||
import kd.bos.list.ListFilterParameter;
|
||||
import kd.bos.list.ListShowParameter;
|
||||
import kd.bos.logging.Log;
|
||||
import kd.bos.logging.LogFactory;
|
||||
import kd.bos.orm.ORM;
|
||||
import kd.bos.orm.query.QCP;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.QueryServiceHelper;
|
||||
import kd.bos.servicehelper.coderule.CodeRuleServiceHelper;
|
||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
import kd.bos.servicehelper.user.UserServiceHelper;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
import oadd.org.apache.hadoop.io.compress.zlib.BuiltInZlibInflater;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 动态表单插件
|
||||
*/
|
||||
public class PurSuggestRptFromPlugin extends AbstractFormPlugin implements Plugin {
|
||||
private final static Log logger = LogFactory.getLog(PurSuggestRptFromPlugin.class);
|
||||
private static DynamicObject BILLTYPE;
|
||||
private static DynamicObject BIZTYPE;
|
||||
private static DynamicObject LINETYPE;
|
||||
static {
|
||||
DynamicObject billtype = BusinessDataServiceHelper.loadSingle("bos_billtype", new QFilter[]{new QFilter("number", QCP.equals, "pm_PurApplyBill_STD_BT_S")});
|
||||
BILLTYPE = billtype;
|
||||
DynamicObject biztype = BusinessDataServiceHelper.loadSingle("bd_biztype", new QFilter[]{new QFilter("number", QCP.equals, "110")});
|
||||
BIZTYPE = biztype;
|
||||
DynamicObject linetype = BusinessDataServiceHelper.loadSingle("bd_linetype", new QFilter[]{new QFilter("number", QCP.equals, "010")});
|
||||
LINETYPE = linetype;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registerListener(EventObject e) {
|
||||
super.registerListener(e);
|
||||
this.addItemClickListeners("tbmain");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void itemClick(ItemClickEvent evt) {
|
||||
super.itemClick(evt);
|
||||
String itemKey = evt.getItemKey();
|
||||
IDataModel model = this.getModel();
|
||||
DynamicObject dataEntity = model.getDataEntity(true);
|
||||
if ("tqq9_query".equals(itemKey)) {
|
||||
DynamicObjectCollection entryentity = dataEntity.getDynamicObjectCollection("tqq9_pursuggestrptentry");
|
||||
if (entryentity.size() != 0) {
|
||||
entryentity.clear();
|
||||
}
|
||||
DynamicObjectCollection tqq9_queryorg = dataEntity.getDynamicObjectCollection("tqq9_queryorg");
|
||||
DynamicObjectCollection tqq9_querysku = dataEntity.getDynamicObjectCollection("tqq9_querysku");
|
||||
List<String> org = new ArrayList<>();
|
||||
List<String> sku = new ArrayList<>();
|
||||
StringBuilder orgBuilder = new StringBuilder();
|
||||
StringBuilder skuBuilder = new StringBuilder();
|
||||
for (DynamicObject dynamicObject : tqq9_queryorg) {
|
||||
String id = dynamicObject.getString("fbasedataid.id");
|
||||
org.add(id);
|
||||
orgBuilder.append(",").append(id);
|
||||
}
|
||||
for (DynamicObject dynamicObject : tqq9_querysku) {
|
||||
String id = dynamicObject.getString("fbasedataid.id");
|
||||
sku.add(id);
|
||||
skuBuilder.append(",").append(id);
|
||||
}
|
||||
//物料Map
|
||||
DynamicObject[] materials = BusinessDataServiceHelper.load("bd_material", "id,number,name,tqq9_brand,baseunit", null);
|
||||
HashMap<Long, DynamicObject> materialMap = new HashMap<Long, DynamicObject>();
|
||||
for (DynamicObject dynamicObject : materials) {
|
||||
materialMap.put(dynamicObject.getLong("id"), dynamicObject);
|
||||
}
|
||||
//组织Map
|
||||
DynamicObject[] adminorgs = BusinessDataServiceHelper.load("bos_adminorg", "id,number", null);
|
||||
HashMap<Long, DynamicObject> adminorgMap = new HashMap<Long, DynamicObject>();
|
||||
for (DynamicObject dynamicObject : adminorgs) {
|
||||
adminorgMap.put(dynamicObject.getLong("id"), dynamicObject);
|
||||
}
|
||||
|
||||
QFilter warehouseF = new QFilter("number", QCP.in, new String[]{"001", "006"});
|
||||
DynamicObject[] warehouses = BusinessDataServiceHelper.load("bd_warehouse", "id,number", warehouseF.toArray());
|
||||
StringBuilder warehouseSb = new StringBuilder();
|
||||
for (DynamicObject warehouse : warehouses) {
|
||||
String id = warehouse.getString("id");
|
||||
warehouseSb.append(",'").append(id).append("'");
|
||||
}
|
||||
|
||||
DataSet materialinventoryinfoDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(),
|
||||
"bd_materialinventoryinfo",
|
||||
"id as materialinventoryid,masterid as tqq9_sku ",
|
||||
new QFilter[]{},
|
||||
null);
|
||||
//即时库存表
|
||||
String realbalancesql = "/*dialect*/select t1.fmaterialid tqq9_sku,t1.forgid tqq9_org,sum(t1.fqty) tqq9_totalinventory " +
|
||||
"from t_im_inv_realbalance t1 group by fmaterialid,forgid";
|
||||
//销售订单
|
||||
String saloutbillsql = "/*dialect*/ SELECT sum(CASE WHEN fbiztime >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '3' MONTH) AND fbiztime < DATE_TRUNC('month', CURRENT_DATE)THEN t2.fqty ELSE 0 END) / 3 AS permonthsales,\n" +
|
||||
" sum(CASE WHEN fbiztime >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '2' MONTH) AND fbiztime < DATE_TRUNC('month', CURRENT_DATE)THEN t2.fqty ELSE 0 END) AS last_2month_sum,\n" +
|
||||
" sum(case when t1.fbiztime>= CURRENT_DATE - INTERVAL '90 days' then t2.fqty else 0 end) tqq9_totalqty,\n" +
|
||||
" sum(CASE WHEN t1.fbillstatus in('A','B','C') and t2.fwarehouseid in (" + warehouseSb.substring(1) + ") then t2.fqty ELSE 0 END)tqq9_onorderinventory,t2.fmaterialid materialinventoryid, t1.forgid tqq9_org\n" +
|
||||
" FROM t_im_saloutbill t1,t_im_saloutbillentry t2 WHERE t1.fid = t2.fid AND t1.fbillstatus = 'C'GROUP BY t2.fmaterialid, t1.forgid";
|
||||
|
||||
//采购订单
|
||||
String purorderbillsql = "/*dialect*/select t2.fmaterialid tqq9_sku,t1.forgid tqq9_org, sum(CASE WHEN t1.fclosestatus='A' then t1.fk_tqq9_purqty ELSE 0 END) tqq9_oninventory\n" +
|
||||
"from t_pm_purorderbill t1,t_pm_purorderbillentry t2 where t1.fid=t2.fid and t1.fbillstatus='C' GROUP BY t2.fmaterialid,t1.forgid";
|
||||
|
||||
DataSet realbalanceDataSet = DB.queryDataSet(this.getClass().getName(), DBRoute.of("scm"), realbalancesql);
|
||||
DataSet saloutbillDataSet = DB.queryDataSet(this.getClass().getName(), DBRoute.of("scm"), saloutbillsql);
|
||||
DataSet purorderbillDataSet = DB.queryDataSet(this.getClass().getName(), DBRoute.of("scm"), purorderbillsql);
|
||||
saloutbillDataSet = saloutbillDataSet.leftJoin(materialinventoryinfoDataSet).on("materialinventoryid", "materialinventoryid").select("tqq9_sku", "tqq9_org", "permonthsales", "last_2month_sum", "tqq9_totalqty", "tqq9_onorderinventory").finish();
|
||||
realbalanceDataSet = realbalanceDataSet.leftJoin(saloutbillDataSet).on("tqq9_sku", "tqq9_sku").select("tqq9_sku", "tqq9_org", "tqq9_totalinventory", "permonthsales", "last_2month_sum", "tqq9_totalqty", "tqq9_onorderinventory", "case when permonthsales<>0 then tqq9_totalinventory/permonthsales else -1 end tqq9_saledates").finish();
|
||||
realbalanceDataSet = realbalanceDataSet.leftJoin(purorderbillDataSet).on("tqq9_sku", "tqq9_sku").select("").select("tqq9_sku", "tqq9_org", "tqq9_totalqty", "tqq9_totalinventory", "tqq9_saledates", "permonthsales*0.5 tqq9_safeinventory", "tqq9_oninventory", "" +
|
||||
"case when tqq9_saledates>=0 and tqq9_saledates<0.5 then '急需备货' when tqq9_saledates>0.5 and tqq9_saledates<=2 then '需备货' when tqq9_saledates>2 and tqq9_saledates<=4.5 then '不需备货' when tqq9_saledates>4.5 then '滞销' else '无' end tqq9_remark", "case when tqq9_saledates<=0.5 then last_2month_sum-tqq9_oninventory-tqq9_totalinventory else 0 end tqq9_suppleinventory", "" +
|
||||
"tqq9_onorderinventory", "case when tqq9_totalinventory<>0 and tqq9_onorderinventory/tqq9_totalinventory>0.8 then '需注意' else '无' end tqq9_onorderemark").finish();
|
||||
|
||||
realbalanceDataSet = realbalanceDataSet.where("1=1" + ((!tqq9_queryorg.isEmpty()) ? " and tqq9_org in(" + orgBuilder.substring(1) + ")" : "") + ((!tqq9_querysku.isEmpty()) ? " and tqq9_sku in(" + skuBuilder.substring(1) + ")" : ""));
|
||||
|
||||
DataSet copy1 = realbalanceDataSet.copy();
|
||||
DynamicObjectCollection dynamicObjects = ORM.create().toPlainDynamicObjectCollection(copy1);
|
||||
Iterator<DynamicObject> iterator = dynamicObjects.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
DynamicObject next = iterator.next();
|
||||
DynamicObject entry = new DynamicObject(entryentity.getDynamicObjectType());
|
||||
DynamicObject tqq9_sku = materialMap.get(next.getLong("tqq9_sku"));
|
||||
entry.set("tqq9_sku", tqq9_sku);//sku(物料)
|
||||
entry.set("tqq9_skuname", tqq9_sku.getString("name"));//名称
|
||||
entry.set("tqq9_skubrand", tqq9_sku.getDynamicObject("tqq9_brand"));//品牌
|
||||
entry.set("tqq9_unit", tqq9_sku.getDynamicObject("baseunit"));//基本单位
|
||||
entry.set("tqq9_org", adminorgMap.get(next.getLong("tqq9_org")));//业务归属(组织)
|
||||
entry.set("tqq9_totalqty", next.get("tqq9_totalqty"));//合计销量
|
||||
entry.set("tqq9_totalinventory", next.get("tqq9_totalinventory"));//总仓库存
|
||||
entry.set("tqq9_saledates", next.get("tqq9_saledates"));//预计销售时间
|
||||
entry.set("tqq9_safeinventory", next.get("tqq9_safeinventory"));//安全库存
|
||||
entry.set("tqq9_oninventory", next.get("tqq9_oninventory"));//在途库存
|
||||
entry.set("tqq9_remark", next.get("tqq9_remark"));//备注
|
||||
entry.set("tqq9_suppleinventory", next.get("tqq9_suppleinventory"));//待补库存
|
||||
entry.set("tqq9_onorderinventory", next.get("tqq9_onorderinventory"));//占单库存
|
||||
entry.set("tqq9_onorderemark", next.get("tqq9_onorderemark"));//占单库存备注
|
||||
entryentity.add(entry);
|
||||
}
|
||||
dataEntity.set("tqq9_pursuggestrptentry", entryentity);
|
||||
this.getView().updateView();
|
||||
} else if (StringUtils.equals("tqq9_purapply", itemKey)) {
|
||||
EntryGrid entry = this.getControl("tqq9_pursuggestrptentry");
|
||||
int[] selectRows = entry.getSelectRows();
|
||||
DynamicObjectCollection tqq9_pursuggestrptentry = dataEntity.getDynamicObjectCollection("tqq9_pursuggestrptentry");
|
||||
DynamicObject purapplybill = BusinessDataServiceHelper.newDynamicObject("pm_purapplybill");
|
||||
DynamicObjectCollection dynamicObjectCollection = purapplybill.getDynamicObjectCollection("billentry");
|
||||
|
||||
long currentUserId = UserServiceHelper.getCurrentUserId();
|
||||
DynamicObject user = BusinessDataServiceHelper.loadSingle("bos_user", new QFilter[]{new QFilter("id", QCP.equals, currentUserId)});
|
||||
DynamicObjectCollection entryentity = user.getDynamicObjectCollection("entryentity");
|
||||
DynamicObject dept=null;
|
||||
for (DynamicObject dynamicObject : entryentity) {
|
||||
boolean ispartjob = dynamicObject.getBoolean("ispartjob");
|
||||
if (!ispartjob){
|
||||
dept=dynamicObject.getDynamicObject("dpt");
|
||||
}
|
||||
} DynamicObject org = BusinessDataServiceHelper.loadSingle("bos_org",new QFilter[]{new QFilter("name", QCP.equals,"励齿集团")});
|
||||
CodeRuleInfo vouCodeRule = CodeRuleServiceHelper.getCodeRule("pm_purapplybill",
|
||||
purapplybill, org.getString("id"));
|
||||
String billno = CodeRuleServiceHelper.getNumber(vouCodeRule, purapplybill);//采购申请单编号
|
||||
DynamicObject currency = BusinessDataServiceHelper.loadSingle("bd_currency",
|
||||
new QFilter[]{new QFilter("number", QCP.equals, "CNY")});//币别
|
||||
DynamicObject taxrate = BusinessDataServiceHelper.loadSingle("bd_taxrate",
|
||||
new QFilter[]{new QFilter("number", QCP.equals, "V13")});//税率
|
||||
Date date = new Date();
|
||||
for (int i = 0; i < selectRows.length; i++) {
|
||||
DynamicObject dynamicObject = tqq9_pursuggestrptentry.get(selectRows[i]);
|
||||
DynamicObject tqq9_org = dynamicObject.getDynamicObject("tqq9_org");
|
||||
DynamicObject tqq9_sku = dynamicObject.getDynamicObject("tqq9_sku");
|
||||
DynamicObject materialpurchaseinfo = BusinessDataServiceHelper.loadSingle("bd_materialpurchaseinfo",
|
||||
new QFilter[]{new QFilter("masterid", QCP.equals, tqq9_sku.getLong("id"))});//物料采购信息
|
||||
BigDecimal tqq9_saledates = dynamicObject.getBigDecimal("tqq9_saledates");
|
||||
if (i==0){
|
||||
purapplybill.set("org",org);//申请组织
|
||||
purapplybill.set("dept",dept);//申请部门
|
||||
purapplybill.set("bizuser",user);//申请人
|
||||
purapplybill.set("currency",currency);//币别
|
||||
purapplybill.set("creator",user);//创建人
|
||||
purapplybill.set("lastupdateuser",user);//修改人
|
||||
purapplybill.set("lastupdatetime",date);//修改时间
|
||||
purapplybill.set("billno",billno);//采购申请单编号
|
||||
purapplybill.set("billtype",BILLTYPE);//单据类型
|
||||
purapplybill.set("biztype",BIZTYPE);//业务类型
|
||||
purapplybill.set("biztime",date);//申请日期
|
||||
purapplybill.set("billstatus","A");//单据状态
|
||||
purapplybill.set("closestatus","A");//关闭状态
|
||||
purapplybill.set("cancelstatus","A");//作废状态
|
||||
purapplybill.set("changestatus","A");//作废状态
|
||||
purapplybill.set("subversion","1");//子版本号
|
||||
purapplybill.set("version","1");//版本号
|
||||
purapplybill.set("tqq9_sfsyhf","false");//是否使用货返
|
||||
purapplybill.set("tqq9_hshfsysl",taxrate);//含税货返使用税率
|
||||
purapplybill.set("tqq9_sfsyxf","false");//是否使用现返
|
||||
purapplybill.set("tqq9_hsxfsysl",taxrate);//含税现返使用税率
|
||||
|
||||
}
|
||||
DynamicObject dynamicObject1 = dynamicObjectCollection.addNew();
|
||||
dynamicObject1.set("seq",i+1);//分录号
|
||||
dynamicObject1.set("material",materialpurchaseinfo);//物料
|
||||
dynamicObject1.set("materialname",tqq9_sku.getString("name"));//物料名称
|
||||
dynamicObject1.set("baseunit",tqq9_sku.getDynamicObject("baseunit"));//基本单位
|
||||
dynamicObject1.set("rowclosestatus","A");//行关闭状态
|
||||
dynamicObject1.set("rowterminatestatus","A");//行终止状态
|
||||
dynamicObject1.set("entryrecorg",tqq9_org);//收货组织
|
||||
dynamicObject1.set("entryreqorg",tqq9_org);//需求组织
|
||||
dynamicObject1.set("entryreqdept",dept);//需求部门
|
||||
dynamicObject1.set("reqdate",date);//需求日期
|
||||
dynamicObject1.set("purdate",date);//建议采购日期
|
||||
dynamicObject1.set("deliverdate",date);//交货日期
|
||||
dynamicObject1.set("bomtime",date);//展BOM时间
|
||||
dynamicObject1.set("entrychangetype","B");//变更方式
|
||||
dynamicObject1.set("linetype",LINETYPE);//行类型
|
||||
dynamicObject1.set("linetype",LINETYPE);//行类型
|
||||
dynamicObject1.set("entrycreator",user);//创建人
|
||||
dynamicObject1.set("entryrecdept",tqq9_org);//收货部门
|
||||
dynamicObject1.set("entrypurdept",tqq9_org);//采购部门
|
||||
dynamicObject1.set("entryoperatorgroup",tqq9_org);//采购组
|
||||
dynamicObject1.set("tqq9_expectsaletime",tqq9_saledates);//预计销售时间(月)
|
||||
dynamicObjectCollection.set(i,dynamicObject1);
|
||||
}
|
||||
purapplybill.set("billentry",dynamicObjectCollection);
|
||||
SaveServiceHelper.save(new DynamicObject[]{purapplybill});
|
||||
BillShowParameter billShowParameter = new BillShowParameter();
|
||||
billShowParameter.getOpenStyle().setShowType(ShowType.Modal);
|
||||
billShowParameter.setFormId("pm_purapplybill");
|
||||
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(purapplybill.getLong("id"), "pm_purapplybill");
|
||||
billShowParameter.setPkId(dynamicObject.get("id"));
|
||||
this.getView().showForm(billShowParameter);
|
||||
|
||||
|
||||
// this.getView().showMessage("采购申请单:"+purapplybill.getString("billno")+",下推成功");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package tqq9.lc123.cloud.app.plugin.operate.im;
|
||||
|
||||
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.entity.botp.plugin.args.AfterCreateTargetEventArgs;
|
||||
import kd.bos.entity.botp.plugin.args.AfterFieldMappingEventArgs;
|
||||
import kd.bos.entity.botp.plugin.args.BeforeCreateTargetEventArgs;
|
||||
import kd.bos.logging.Log;
|
||||
import kd.bos.logging.LogFactory;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 采购订单转换插件
|
||||
* 退货补货数量修改
|
||||
*/
|
||||
public class PurOrderPushReceiptNoticePlugin extends AbstractConvertPlugIn implements Plugin {
|
||||
private final static Log logger = LogFactory.getLog(PurOrderPushReceiptNoticePlugin.class);
|
||||
private static String RECEIPTNOTICE = "pm_receiptnotice";
|
||||
|
||||
@Override
|
||||
public void afterConvert(AfterConvertEventArgs e) {
|
||||
super.afterConvert(e);
|
||||
ExtendedDataEntitySet targetExtDataEntitySet = e.getTargetExtDataEntitySet();
|
||||
ExtendedDataEntity[] extendedDataEntities = targetExtDataEntitySet.FindByEntityKey(RECEIPTNOTICE);
|
||||
Map<String, String> variables = this.getOption().getVariables();
|
||||
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
|
||||
//收货通知单
|
||||
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
|
||||
DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("billentry");
|
||||
for (DynamicObject dynamicObject : dynamicObjectCollection) {
|
||||
String mainbillentryid = dynamicObject.getString("mainbillentryid");
|
||||
//核心单据号一致,修改补货数量
|
||||
if (variables.containsKey(mainbillentryid)) {
|
||||
String qty = variables.get(mainbillentryid);
|
||||
BigDecimal entry_qty = new BigDecimal(qty).negate();
|
||||
dynamicObject.set("qty", entry_qty);//数量
|
||||
dynamicObject.set("baseqty", entry_qty);//基本数量
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +1,50 @@
|
|||
package tqq9.lc123.cloud.app.plugin.operate.im;
|
||||
|
||||
import kd.bos.dataentity.OperateOption;
|
||||
import kd.bos.data.BusinessDataReader;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.entity.operate.result.IOperateInfo;
|
||||
import kd.bos.dataentity.metadata.IDataEntityType;
|
||||
import kd.bos.dataentity.resource.ResManager;
|
||||
import kd.bos.dataentity.utils.StringUtils;
|
||||
import kd.bos.entity.EntityMetadataCache;
|
||||
import kd.bos.entity.MainEntityType;
|
||||
import kd.bos.entity.botp.plugin.args.AfterCreateTargetEventArgs;
|
||||
import kd.bos.entity.botp.runtime.ConvertOperationResult;
|
||||
import kd.bos.entity.botp.runtime.PushArgs;
|
||||
import kd.bos.entity.botp.runtime.SourceBillReport;
|
||||
import kd.bos.entity.datamodel.IRefrencedataProvider;
|
||||
import kd.bos.entity.datamodel.ListSelectedRow;
|
||||
import kd.bos.entity.operate.result.OperationResult;
|
||||
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||||
import kd.bos.entity.plugin.args.AfterOperationArgs;
|
||||
import kd.bos.exception.KDBizException;
|
||||
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.bos.servicehelper.botp.ConvertServiceHelper;
|
||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
import tqq9.lc123.cloud.app.plugin.operate.cas.PurOrderUnReversePayBillPlugin;
|
||||
import org.hsqldb.Server;
|
||||
import tqq9.lc123.cloud.app.plugin.utils.BotpParamUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 采购退货申请单(采购退补货)下推红字采购入库单审核后,根据来源的采购订单生成收货通知单
|
||||
*/
|
||||
public class ReturnStockSyncNotifierPlugin extends AbstractOperationServicePlugIn implements Plugin {
|
||||
private final static Log logger = LogFactory.getLog(ReturnStockSyncNotifierPlugin.class);
|
||||
|
||||
private static String PURORDER="pm_purorderbill";
|
||||
private static String RECEIPTNOTICE="pm_receiptnotice";
|
||||
private static String PURORDER_ENTRY="billentry";
|
||||
private static String RULE="2279256940385159168";
|
||||
@Override
|
||||
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
||||
super.afterExecuteOperationTransaction(e);
|
||||
|
|
@ -32,32 +53,43 @@ public class ReturnStockSyncNotifierPlugin extends AbstractOperationServicePlugI
|
|||
DynamicObject biztype = dataEntity.getDynamicObject("biztype");//业务类型
|
||||
String number = biztype.getString("number");
|
||||
//业务类型为物料类采购退补货
|
||||
if ("1102".equals(number)) {
|
||||
if("1102".equals(number)){
|
||||
String billno = dataEntity.getString("billno");//采购入库单单据编号
|
||||
//采购入库单
|
||||
DynamicObject im_purinbill = BusinessDataServiceHelper.loadSingle("im_purinbill", new QFilter[]{new QFilter("billno", QCP.equals, billno)});
|
||||
DynamicObjectCollection billentry = im_purinbill.getDynamicObjectCollection("billentry");
|
||||
List<String> selectedNos = new ArrayList(billentry.size());
|
||||
DynamicObject[] pm_purorderbills = new DynamicObject[billentry.size()];
|
||||
for (int i = 0; i < billentry.size(); i++) {
|
||||
//核心单据编号
|
||||
String mainbillnumber = billentry.get(i).getString("mainbillnumber");
|
||||
//查询采购订单
|
||||
DynamicObject pm_purorderbill = BusinessDataServiceHelper.loadSingle("pm_purorderbill", new QFilter[]{new QFilter("billno", QCP.equals, mainbillnumber).and(new QFilter("billno", QCP.not_in, selectedNos))});
|
||||
selectedNos.add(mainbillnumber);
|
||||
pm_purorderbills[i] = pm_purorderbill;
|
||||
}
|
||||
|
||||
OperateOption option = OperateOption.create();
|
||||
OperationResult result = OperationServiceHelper.executeOperate("pushandsave1", "pm_purorderbill", pm_purorderbills, option);
|
||||
Map<String, String> param=new HashMap<>();
|
||||
HashMap<Long, Long> entitypkMap=new HashMap<>();
|
||||
OperationResult operationResult1 = this.getOperationResult();
|
||||
if (result.isSuccess()) {
|
||||
operationResult1.setMessage("系统已自动进行退货补货,相关收货通知单已自动生成,请手动调整补货数量,再提交审核");
|
||||
for (DynamicObject entry : billentry) {
|
||||
String mainbillnumber = entry.getString("mainbillnumber");//核心单据编号
|
||||
String mainbillentryid = entry.getString("mainbillentryid");//核心单据行id
|
||||
String qty = entry.getString("qty");//数量
|
||||
//查询采购订单
|
||||
DynamicObject pm_purorderbill = BusinessDataServiceHelper.loadSingle("pm_purorderbill", new QFilter[]{new QFilter("billno", QCP.equals, mainbillnumber)});
|
||||
DynamicObjectCollection billentry1 = pm_purorderbill.getDynamicObjectCollection("billentry");
|
||||
for (DynamicObject entry1 : billentry1) {
|
||||
String id = entry1.getString("id");
|
||||
if(StringUtils.equals(id,mainbillentryid)){
|
||||
entitypkMap.put(pm_purorderbill.getLong("id"),entry1.getLong("id"));
|
||||
param.put(id,qty);
|
||||
}
|
||||
}
|
||||
PushArgs pushArgs = BotpParamUtils.getPushArgs(PURORDER,RECEIPTNOTICE,PURORDER_ENTRY,param,entitypkMap,RULE);
|
||||
ConvertOperationResult pushResult = ConvertServiceHelper.pushAndSave(pushArgs);
|
||||
if (!pushResult.isSuccess()) {
|
||||
// 错误摘要
|
||||
String errMessage = pushResult.getMessage();
|
||||
throw new KDBizException("下推失败,请从订单手动下推补货");
|
||||
}else{
|
||||
operationResult1.setMessage("补货失败,请手动操作");
|
||||
operationResult1.setMessage("补货成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue