146 lines
8.4 KiB
Java
146 lines
8.4 KiB
Java
package tqq9.lc123.cloud.app.plugin.operate.im;
|
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
import kd.bos.dataentity.utils.StringUtils;
|
|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
|
import kd.bos.entity.plugin.args.AfterOperationArgs;
|
|
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.SaveServiceHelper;
|
|
import kd.sdk.plugin.Plugin;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
|
|
/**
|
|
* 采购入库反写批次注册证管理
|
|
*/
|
|
public class PurInIotManagePlugin extends AbstractOperationServicePlugIn implements Plugin {
|
|
private final static Log logger = LogFactory.getLog(PurInIotManagePlugin.class);
|
|
|
|
@Override
|
|
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
|
super.afterExecuteOperationTransaction(e);
|
|
//物料Map
|
|
DynamicObject[] materials = BusinessDataServiceHelper.load("bd_material", "id,number,name,tqq9_brand,baseunit,tqq9_brand", null);
|
|
HashMap<Long, DynamicObject> materialMap = new HashMap<Long, DynamicObject>();
|
|
for (DynamicObject dynamicObject : materials) {
|
|
materialMap.put(dynamicObject.getLong("id"), dynamicObject);
|
|
}
|
|
for (DynamicObject dataEntity : e.getDataEntities()) {
|
|
String billno = dataEntity.getString("billno");
|
|
QFilter qFilter = new QFilter("billno", QCP.equals, billno);
|
|
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("im_purinbill",
|
|
"billentry.producedate,billentry.expirydate,billentry.lotnumber,billentry.tqq9_registration,billentry.material,billentry.warehouse,billentry.lot,billentry.qty,billentry.tqq9_goods",
|
|
qFilter.toArray());
|
|
DynamicObjectCollection billentry = dynamicObject.getDynamicObjectCollection("billentry");
|
|
// DynamicObject[] tqq9_goodlotmanages=new DynamicObject[billentry.size()];
|
|
DynamicObjectCollection tqq9_goodlotmanages = new DynamicObjectCollection();
|
|
boolean falg = false;
|
|
for (int i = 0; i < billentry.size(); i++) {
|
|
DynamicObject entry = billentry.get(i);
|
|
DynamicObject tqq9_goodlotmanage = BusinessDataServiceHelper.newDynamicObject("tqq9_goodlotmanage");
|
|
Date producedate = entry.getDate("producedate");//生产日期
|
|
Date expirydate = entry.getDate("expirydate");//到期日期
|
|
String lotnumber = entry.getString("lotnumber");//批号
|
|
DynamicObject tqq9_registration = entry.getDynamicObject("tqq9_registration");//商品注册证
|
|
DynamicObject materialpurch = entry.getDynamicObject("material");//物料采购信息
|
|
DynamicObject masterid = materialpurch.getDynamicObject("masterid");//物料id
|
|
DynamicObject material = materialMap.get(masterid.getLong("id"));//物料
|
|
DynamicObject tqq9_brand = material.getDynamicObject("tqq9_brand");//商品品牌
|
|
String number = material.getString("number");//商品编码
|
|
String name = null;
|
|
if (tqq9_registration != null) {
|
|
name = tqq9_registration.getString("name");
|
|
}
|
|
tqq9_goodlotmanage.set("number", number);//商品编码
|
|
tqq9_goodlotmanage.set("tqq9_lot", lotnumber);//批号
|
|
tqq9_goodlotmanage.set("name", name);//商品注册证名称
|
|
tqq9_goodlotmanage.set("tqq9_brand", tqq9_brand);//商品品牌
|
|
tqq9_goodlotmanage.set("tqq9_crreatdate", producedate);//生产日期
|
|
tqq9_goodlotmanage.set("tqq9_invaliddate", expirydate);//到期日期
|
|
tqq9_goodlotmanage.set("status", "C");//数据状态
|
|
tqq9_goodlotmanage.set("enable", "1");//使用状态
|
|
QFilter f1 = new QFilter("number", QCP.equals, number);
|
|
QFilter f2 = new QFilter("tqq9_lot", QCP.equals, lotnumber);
|
|
QFilter f3 = new QFilter("tqq9_crreatdate", QCP.equals, producedate);
|
|
QFilter f4 = new QFilter("tqq9_invaliddate", QCP.equals, expirydate);
|
|
DynamicObject tqq9_goodlotmanage1 = BusinessDataServiceHelper.loadSingle("tqq9_goodlotmanage", new QFilter[]{f1,f2,f3,f4});
|
|
if (tqq9_goodlotmanage1 == null && StringUtils.isNotBlank(lotnumber)) {
|
|
falg = true;
|
|
tqq9_goodlotmanages.add(tqq9_goodlotmanage);
|
|
}
|
|
|
|
String warehouseNumber = null;
|
|
DynamicObject warehouse = entry.getDynamicObject("warehouse");
|
|
if(warehouse != null){
|
|
warehouseNumber = warehouse.getString("number");
|
|
}
|
|
|
|
// 将入库物料的批次信息写到商品明细中
|
|
DynamicObject tqq9_goods = entry.getDynamicObject("tqq9_goods");
|
|
if(tqq9_goods != null){
|
|
tqq9_goods = BusinessDataServiceHelper.loadSingle(tqq9_goods.getPkValue(), tqq9_goods.getDynamicObjectType().getName());
|
|
|
|
// 物料已经被封装成了商品
|
|
boolean isExistEntry = false;//在明细中是否能找到对应的商品信息
|
|
DynamicObjectCollection entryies = tqq9_goods.getDynamicObjectCollection("tqq9_entry");
|
|
for (DynamicObject entry1 : entryies) {
|
|
String lotNumber = null;
|
|
DynamicObject tqq9_lot = entry1.getDynamicObject("tqq9_lot");
|
|
if(tqq9_lot != null){
|
|
lotNumber = tqq9_lot.getString("number");
|
|
}
|
|
String whNumber = "";
|
|
DynamicObject wh = entry1.getDynamicObject("tqq9_basedatafield");
|
|
if(wh != null){
|
|
whNumber = wh.getString("number");
|
|
}
|
|
Date tqq9_productdate = entry1.getDate("tqq9_productdate");
|
|
Date tqq9_todate = entry1.getDate("tqq9_todate");
|
|
if(((StringUtils.isBlank(lotNumber) && StringUtils.isBlank(lotnumber)) || lotNumber.equals(lotnumber))
|
|
&& ((StringUtils.isBlank(whNumber) && StringUtils.isBlank(warehouseNumber)) || whNumber.equals(warehouseNumber))
|
|
&& ((tqq9_productdate == null && producedate == null) || (tqq9_productdate.equals(producedate)))
|
|
&& ((tqq9_todate == null && expirydate == null) || (tqq9_todate.equals(expirydate)))){
|
|
// 如果现有的商品数据存在
|
|
BigDecimal tqq9_availablestock = entry1.getBigDecimal("tqq9_availablestock");
|
|
entry1.set("tqq9_availablestock", tqq9_availablestock.add(entry.getBigDecimal("qty")));
|
|
BigDecimal tqq9_upstock = entry1.getBigDecimal("tqq9_upstock");
|
|
entry1.set("tqq9_upstock", tqq9_upstock.add(entry.getBigDecimal("qty")));
|
|
isExistEntry = true;
|
|
}
|
|
if(isExistEntry){
|
|
break;
|
|
}
|
|
}
|
|
if(!isExistEntry){
|
|
DynamicObject entry1 = entryies.addNew();
|
|
entry1.set("tqq9_lot", entry.getDynamicObject("lot"));//批号
|
|
entry1.set("tqq9_basedatafield", warehouse);//仓库
|
|
entry1.set("tqq9_productdate", producedate);//生产日期
|
|
entry1.set("tqq9_todate", expirydate);//到期日期
|
|
entry1.set("tqq9_availablestock", entry.getBigDecimal("qty"));//到期日期
|
|
entry1.set("tqq9_upstock", entry.getBigDecimal("qty"));//到期日期
|
|
}
|
|
SaveServiceHelper.save(new DynamicObject[]{tqq9_goods});
|
|
}
|
|
|
|
|
|
}
|
|
if (falg) {
|
|
DynamicObject[] objects = new DynamicObject[tqq9_goodlotmanages.size()];
|
|
for (int i = 0; i < tqq9_goodlotmanages.size(); i++) {
|
|
objects[i] = tqq9_goodlotmanages.get(i);
|
|
}
|
|
|
|
SaveServiceHelper.save(objects);
|
|
}
|
|
}
|
|
|
|
}
|
|
} |