115 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			Java
		
	
	
	
			
		
		
	
	
			115 lines
		
	
	
		
			6.1 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.PreparePropertysEventArgs;
 | 
						|
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.util.ArrayList;
 | 
						|
import java.util.HashMap;
 | 
						|
import java.util.Iterator;
 | 
						|
import java.util.List;
 | 
						|
 | 
						|
/**
 | 
						|
 * 采购入库反写批号主档
 | 
						|
 */
 | 
						|
public class PurInlotReceiptPlugin extends AbstractOperationServicePlugIn implements Plugin {
 | 
						|
    private final static Log logger = LogFactory.getLog(PurInlotReceiptPlugin.class);
 | 
						|
 | 
						|
 | 
						|
    @Override
 | 
						|
    public void afterExecuteOperationTransaction(AfterOperationArgs e) {
 | 
						|
        super.afterExecuteOperationTransaction(e);
 | 
						|
        String operationKey = e.getOperationKey();
 | 
						|
        if (StringUtils.equals("audit", operationKey)) {
 | 
						|
            for (DynamicObject dataEntity : e.getDataEntities()) {
 | 
						|
                ArrayList<String> billnos = new ArrayList<>();
 | 
						|
                HashMap<Long, DynamicObject> entryMap = new HashMap<>();
 | 
						|
                String billno1 = dataEntity.getString("billno");
 | 
						|
                DynamicObject im_purinbill = BusinessDataServiceHelper.loadSingle("im_purinbill", new QFilter[]{new QFilter("billno", QCP.equals, billno1)});
 | 
						|
                DynamicObjectCollection billentry = im_purinbill.getDynamicObjectCollection("billentry");
 | 
						|
 | 
						|
                //处理采购入库逻辑
 | 
						|
                for (DynamicObject dynamicObject : billentry) {
 | 
						|
                    String billno = dynamicObject.getString("mainbillnumber");//采购订单编号
 | 
						|
                    Long entryid = dynamicObject.getLong("mainbillentryid");//核心单据行id
 | 
						|
                    DynamicObject lot = dynamicObject.getDynamicObject("lot");//批号主档
 | 
						|
                    billnos.add(billno);
 | 
						|
                    entryMap.put(entryid, lot);
 | 
						|
                }
 | 
						|
                //查询采购订单
 | 
						|
                QFilter qFilter = new QFilter("billno", QCP.in, billnos);
 | 
						|
                DynamicObject[] pm_purorderbills = BusinessDataServiceHelper.load("pm_purorderbill", "id,billno,billentry.id,billentry.tqq9_bd_lot", qFilter.toArray());
 | 
						|
                if (pm_purorderbills != null && pm_purorderbills.length > 0) {
 | 
						|
                    for (DynamicObject pm_purorderbill : pm_purorderbills) {
 | 
						|
 | 
						|
                        DynamicObjectCollection billentry1 = pm_purorderbill.getDynamicObjectCollection("billentry");
 | 
						|
 | 
						|
                        for (DynamicObject dynamicObject : billentry1) {
 | 
						|
                            long id = dynamicObject.getLong("id");
 | 
						|
                            if (entryMap.containsKey(id)) {
 | 
						|
                                DynamicObject lot = entryMap.get(id);
 | 
						|
                                DynamicObjectCollection tqq9_bd_lot = dynamicObject.getDynamicObjectCollection("tqq9_bd_lot");
 | 
						|
                                DynamicObject newlot = new DynamicObject(tqq9_bd_lot.getDynamicObjectType());
 | 
						|
                                newlot.set("fbasedataId", lot);
 | 
						|
                                if (!tqq9_bd_lot.contains(newlot)) {
 | 
						|
                                    tqq9_bd_lot.add(newlot);
 | 
						|
                                }
 | 
						|
                            }
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                    SaveServiceHelper.save(pm_purorderbills);
 | 
						|
                }
 | 
						|
            }
 | 
						|
        } else if (StringUtils.equals("unaudit", operationKey)) {
 | 
						|
            logger.info("进入反审核方法");
 | 
						|
            for (DynamicObject dataEntity : e.getDataEntities()) {
 | 
						|
                ArrayList<String> billnos = new ArrayList<>();
 | 
						|
                String billno1 = dataEntity.getString("billno");
 | 
						|
 | 
						|
                DynamicObject im_purinbill = BusinessDataServiceHelper.loadSingle("im_purinbill", new QFilter[]{new QFilter("billno", QCP.equals, billno1)});
 | 
						|
                DynamicObjectCollection billentry = im_purinbill.getDynamicObjectCollection("billentry");
 | 
						|
 | 
						|
                //处理采购入库逻辑
 | 
						|
                for (DynamicObject dynamicObject : billentry) {
 | 
						|
                    String billno = dynamicObject.getString("mainbillnumber");//采购订单编号
 | 
						|
                    billnos.add(billno);
 | 
						|
                }
 | 
						|
                //查询采购订单
 | 
						|
                QFilter qFilter = new QFilter("billno", QCP.in, billnos);
 | 
						|
                DynamicObject[] pm_purorderbills = BusinessDataServiceHelper.load("pm_purorderbill", "id,billno,billentry.id,billentry.tqq9_bd_lot", qFilter.toArray());
 | 
						|
                //删除禁用批号
 | 
						|
                for (DynamicObject pm_purorderbill : pm_purorderbills) {
 | 
						|
                    DynamicObjectCollection billentry1 = pm_purorderbill.getDynamicObjectCollection("billentry");
 | 
						|
                    for (DynamicObject dynamicObject : billentry1) {
 | 
						|
                        DynamicObjectCollection tqq9_bd_lot = dynamicObject.getDynamicObjectCollection("tqq9_bd_lot");
 | 
						|
                        Iterator<DynamicObject> iterator = tqq9_bd_lot.iterator();
 | 
						|
                        while (iterator.hasNext()){
 | 
						|
                            DynamicObject lot = iterator.next();
 | 
						|
                            DynamicObject bd_lot = lot.getDynamicObject("fbasedataId");
 | 
						|
                            if(bd_lot!=null){
 | 
						|
                                bd_lot = BusinessDataServiceHelper.loadSingle("bd_lot", new QFilter[]{new QFilter("id", QCP.equals, bd_lot.getLong("id"))});
 | 
						|
                                String lotstatus = bd_lot.getString("lotstatus");
 | 
						|
                                if (lotstatus.equals("B")) {
 | 
						|
                                    logger.info("删除成功");
 | 
						|
                                    iterator.remove();
 | 
						|
                                }
 | 
						|
                            }
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                SaveServiceHelper.save(pm_purorderbills);
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
    }
 | 
						|
} |