|  | @@ -1,15 +1,464 @@
 | 
	
		
			
				|  |  |  package nckd.wnq01.wnq.scm.plugin.form;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import kd.bos.algo.DataSet;
 | 
	
		
			
				|  |  | +import kd.bos.algo.Row;
 | 
	
		
			
				|  |  |  import kd.bos.bill.AbstractBillPlugIn;
 | 
	
		
			
				|  |  | +import kd.bos.dataentity.entity.DynamicObject;
 | 
	
		
			
				|  |  | +import kd.bos.dataentity.entity.DynamicObjectCollection;
 | 
	
		
			
				|  |  | +import kd.bos.db.DB;
 | 
	
		
			
				|  |  | +import kd.bos.db.DBRoute;
 | 
	
		
			
				|  |  | +import kd.bos.form.events.AfterDoOperationEventArgs;
 | 
	
		
			
				|  |  | +import kd.bos.form.events.BeforeDoOperationEventArgs;
 | 
	
		
			
				|  |  | +import kd.bos.form.field.BasedataEdit;
 | 
	
		
			
				|  |  | +import kd.bos.form.field.events.BeforeF7SelectEvent;
 | 
	
		
			
				|  |  | +import kd.bos.form.field.events.BeforeF7SelectListener;
 | 
	
		
			
				|  |  | +import kd.bos.form.operate.FormOperate;
 | 
	
		
			
				|  |  | +import kd.bos.list.ListShowParameter;
 | 
	
		
			
				|  |  | +import kd.bos.orm.query.QCP;
 | 
	
		
			
				|  |  | +import kd.bos.orm.query.QFilter;
 | 
	
		
			
				|  |  | +import kd.bos.servicehelper.BusinessDataServiceHelper;
 | 
	
		
			
				|  |  |  import kd.sdk.plugin.Plugin;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import java.math.BigDecimal;
 | 
	
		
			
				|  |  | +import java.util.*;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   *  价格批量调整单
 | 
	
		
			
				|  |  |   *  元数据: nckd_pricetiaozheng
 | 
	
		
			
				|  |  |   *  需求描述:生产取价结果自动获取生成对应的页签
 | 
	
		
			
				|  |  | - * author: chengchaohua
 | 
	
		
			
				|  |  | - * date: 2025-03-02
 | 
	
		
			
				|  |  | + * author: wangjun
 | 
	
		
			
				|  |  | + * date: 2025-03-11
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  | -public class PriceTiaoZhengPlugin extends AbstractBillPlugIn implements Plugin {
 | 
	
		
			
				|  |  | +public class PriceTiaoZhengPlugin extends AbstractBillPlugIn implements Plugin, BeforeF7SelectListener {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void beforeDoOperation(BeforeDoOperationEventArgs args) {
 | 
	
		
			
				|  |  | +        FormOperate operate = (FormOperate) args.getSource();
 | 
	
		
			
				|  |  | +        String operateKey = operate.getOperateKey();
 | 
	
		
			
				|  |  | +        if("getpriceresult".equals(operateKey)) {
 | 
	
		
			
				|  |  | +            String message = "";
 | 
	
		
			
				|  |  | +            if (this.getModel().getValue("nckd_tzsxsj") == null) {
 | 
	
		
			
				|  |  | +                message = "调整生效时间不能为空!";
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (this.getModel().getValue("nckd_radiogroupfield") == null) {
 | 
	
		
			
				|  |  | +                message = message + "上涨价格或者下调价格必须选择一项!";
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (this.getModel().getValue("nckd_bumen") == null) {
 | 
	
		
			
				|  |  | +                message = message + "申请部门不能为空!";
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (((DynamicObjectCollection) this.getModel().getValue("nckd_quyus")).size() == 0) {
 | 
	
		
			
				|  |  | +                message = message + "请重新选择区域!";
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (((DynamicObjectCollection) this.getModel().getValue("nckd_xqys")).size() == 0) {
 | 
	
		
			
				|  |  | +                message = message + "请重新选择小区域!";
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (((DynamicObjectCollection) this.getModel().getValue("nckd_saletypes")).size() == 0) {
 | 
	
		
			
				|  |  | +                message = message + "请重新选择销售类别!";
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (((DynamicObjectCollection) this.getModel().getValue("nckd_mulmaterials")).size() == 0) {
 | 
	
		
			
				|  |  | +                message = message + "请重新选择物料!";
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (((DynamicObjectCollection) this.getModel().getValue("nckd_tjjd")).size() == 0) {
 | 
	
		
			
				|  |  | +                message = message + "调价基地不能为空!";
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (this.getModel().getValue("nckd_adjustproduct") == null) {
 | 
	
		
			
				|  |  | +                message = message + "调价产品品种不能为空,品种需要手工填写!";
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (this.getModel().getValue("nckd_customers") != null) {
 | 
	
		
			
				|  |  | +                DynamicObjectCollection customers = (DynamicObjectCollection) this.getModel().getValue("nckd_customers");
 | 
	
		
			
				|  |  | +                if (customers.size() > 10) {
 | 
	
		
			
				|  |  | +                    message = message + "客户最多只能选择10个!";
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (!"".equals(message)) {
 | 
	
		
			
				|  |  | +                this.getView().showMessage(message);
 | 
	
		
			
				|  |  | +                args.setCancel(true);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        super.beforeDoOperation(args);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
 | 
	
		
			
				|  |  | +        super.afterDoOperation(afterDoOperationEventArgs);
 | 
	
		
			
				|  |  | +        String operateKey = afterDoOperationEventArgs.getOperateKey();
 | 
	
		
			
				|  |  | +        if("getpriceresult".equals(operateKey)){
 | 
	
		
			
				|  |  | +            //调价基地
 | 
	
		
			
				|  |  | +            DynamicObjectCollection tjjds = (DynamicObjectCollection) this.getModel().getValue("nckd_tjjd");
 | 
	
		
			
				|  |  | +            String tjjds_ids_str = "";//sql用
 | 
	
		
			
				|  |  | +            String tjjd_names = "";
 | 
	
		
			
				|  |  | +            List<Long> tjjds_ids = new ArrayList();//qfilter用
 | 
	
		
			
				|  |  | +            for(DynamicObject tjjd : tjjds){
 | 
	
		
			
				|  |  | +                DynamicObject real_tjjd = tjjd.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +                tjjds_ids.add(real_tjjd.getLong("id"));
 | 
	
		
			
				|  |  | +                tjjds_ids_str = tjjds_ids_str + "," + real_tjjd.getPkValue().toString();
 | 
	
		
			
				|  |  | +                tjjd_names = tjjd_names+","+real_tjjd.getString("name");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //客户
 | 
	
		
			
				|  |  | +            DynamicObjectCollection customers = null;
 | 
	
		
			
				|  |  | +            DynamicObject[] allcustomers = null;
 | 
	
		
			
				|  |  | +            //区域
 | 
	
		
			
				|  |  | +            DynamicObjectCollection quyus = (DynamicObjectCollection) this.getModel().getValue("nckd_quyus");
 | 
	
		
			
				|  |  | +            List<Long> quyus_ids = new ArrayList();
 | 
	
		
			
				|  |  | +            for(DynamicObject quyu : quyus){
 | 
	
		
			
				|  |  | +                DynamicObject real_quyu = quyu.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +                quyus_ids.add(real_quyu.getLong("id"));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //小区域
 | 
	
		
			
				|  |  | +            DynamicObjectCollection xqys = (DynamicObjectCollection) this.getModel().getValue("nckd_xqys");
 | 
	
		
			
				|  |  | +            List<Long> xqys_ids = new ArrayList();
 | 
	
		
			
				|  |  | +            for(DynamicObject xqy : xqys){
 | 
	
		
			
				|  |  | +                DynamicObject real_xqy = xqy.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +                xqys_ids.add(real_xqy.getLong("id"));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //销售类别
 | 
	
		
			
				|  |  | +            DynamicObjectCollection saletypes = (DynamicObjectCollection) this.getModel().getValue("nckd_saletypes");
 | 
	
		
			
				|  |  | +            List<Long> saletypes_ids = new ArrayList();
 | 
	
		
			
				|  |  | +            List<Long> salebigtype_ids = new ArrayList();
 | 
	
		
			
				|  |  | +            for(DynamicObject saletype : saletypes){
 | 
	
		
			
				|  |  | +                DynamicObject real_saletype = saletype.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +                saletypes_ids.add(real_saletype.getLong("id"));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if(real_saletype.getDynamicObject("nckd_salebigtype")!=null){
 | 
	
		
			
				|  |  | +                    DynamicObject salebigtype = real_saletype.getDynamicObject("nckd_salebigtype");
 | 
	
		
			
				|  |  | +                    salebigtype_ids.add(salebigtype.getLong("id"));
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //物料
 | 
	
		
			
				|  |  | +            DynamicObjectCollection materials = (DynamicObjectCollection) this.getModel().getValue("nckd_mulmaterials");
 | 
	
		
			
				|  |  | +            List<Long> material_ids = new ArrayList();
 | 
	
		
			
				|  |  | +            for(DynamicObject material : materials){
 | 
	
		
			
				|  |  | +                DynamicObject real_material = material.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +                material_ids.add(real_material.getLong("id"));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //调整价格
 | 
	
		
			
				|  |  | +            BigDecimal tiaozjiage = new BigDecimal(this.getModel().getValue("nckd_tiaozjiage").toString());
 | 
	
		
			
				|  |  | +            String radiogroup = this.getModel().getValue("nckd_radiogroupfield").toString();
 | 
	
		
			
				|  |  | +            BigDecimal real_tiaozjiage = new BigDecimal(0);
 | 
	
		
			
				|  |  | +            if("s".equals(radiogroup)){//上调
 | 
	
		
			
				|  |  | +                real_tiaozjiage = tiaozjiage;
 | 
	
		
			
				|  |  | +            }else if("x".equals(radiogroup)){//下调
 | 
	
		
			
				|  |  | +                real_tiaozjiage = tiaozjiage.negate();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if(this.getModel().getValue("nckd_customers")!=null &&
 | 
	
		
			
				|  |  | +                    ((DynamicObjectCollection)this.getModel().getValue("nckd_customers")).size()>0){
 | 
	
		
			
				|  |  | +                customers = (DynamicObjectCollection) this.getModel().getValue("nckd_customers");
 | 
	
		
			
				|  |  | +            }else{
 | 
	
		
			
				|  |  | +                QFilter qFilter_tjjd = new QFilter("createorg.id", QCP.in,tjjds_ids);
 | 
	
		
			
				|  |  | +                QFilter qFilter_quyu = new QFilter("nckd_qy.id", QCP.in,quyus_ids);
 | 
	
		
			
				|  |  | +                QFilter qFilter_xqys = new QFilter("nckd_xqy.id", QCP.in,xqys_ids);
 | 
	
		
			
				|  |  | +                QFilter qFilter_saletypes = new QFilter("nckd_xslb.id", QCP.in,saletypes_ids);
 | 
	
		
			
				|  |  | +                allcustomers = BusinessDataServiceHelper.load("nckd_thht","id",
 | 
	
		
			
				|  |  | +                        new QFilter[]{qFilter_tjjd,qFilter_quyu,qFilter_xqys,qFilter_saletypes});
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            //设置调整结果分录
 | 
	
		
			
				|  |  | +            setTiaozhengresultEntrys(real_tiaozjiage,tjjds_ids_str,tjjds,customers,allcustomers,material_ids,materials);
 | 
	
		
			
				|  |  | +            //设置价格基本信息分录
 | 
	
		
			
				|  |  | +            setEntryentityEntrys(real_tiaozjiage,tjjds_ids_str,tjjds,quyus_ids,xqys_ids,xqys,salebigtype_ids,material_ids,materials);
 | 
	
		
			
				|  |  | +            //设置调价简介
 | 
	
		
			
				|  |  | +            setTiaojiajianjieEntrys();
 | 
	
		
			
				|  |  | +            //设置审批界面
 | 
	
		
			
				|  |  | +            setAuditjiemianEntrys(real_tiaozjiage,customers,allcustomers,saletypes);
 | 
	
		
			
				|  |  | +            //设置调价基地
 | 
	
		
			
				|  |  | +            setTiaozhengdescEntrys(tjjd_names);
 | 
	
		
			
				|  |  | +            this.getView().showMessage("获取成功");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void setAuditjiemianEntrys(BigDecimal real_tiaozjiage, DynamicObjectCollection customers, DynamicObject[] allcustomers, DynamicObjectCollection saletypes) {
 | 
	
		
			
				|  |  | +        //先循环分录缓存
 | 
	
		
			
				|  |  | +        Map entryentity2Map = new HashMap();
 | 
	
		
			
				|  |  | +        DynamicObjectCollection entryentityresultCol = (DynamicObjectCollection) this.getModel().getValue("nckd_entryentity2");
 | 
	
		
			
				|  |  | +        for(int row=0;row<entryentityresultCol.size();row++){
 | 
	
		
			
				|  |  | +            DynamicObject entryentityresultObj = entryentityresultCol.get(row);
 | 
	
		
			
				|  |  | +            DynamicObject nckd_etqyhmbsc = entryentityresultObj.getDynamicObject("nckd_etqyhmbsc");
 | 
	
		
			
				|  |  | +            String nckd_eadjustproduct = entryentityresultObj.getString("nckd_eadjustproduct");
 | 
	
		
			
				|  |  | +            DynamicObject nckd_saletypeb = entryentityresultObj.getDynamicObject("nckd_saletypeb");
 | 
	
		
			
				|  |  | +            String key = nckd_etqyhmbsc.getPkValue().toString()+";"+nckd_eadjustproduct+";"+
 | 
	
		
			
				|  |  | +                    nckd_saletypeb.getPkValue().toString();
 | 
	
		
			
				|  |  | +            entryentity2Map.put(key,row);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //开始插入分录
 | 
	
		
			
				|  |  | +        String adjustproduct = this.getModel().getValue("nckd_adjustproduct").toString();
 | 
	
		
			
				|  |  | +        if(customers!=null && customers.size()>0){
 | 
	
		
			
				|  |  | +            for(DynamicObject customer: customers){
 | 
	
		
			
				|  |  | +                DynamicObject real_customer = customer.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +                for(DynamicObject saletype : saletypes){
 | 
	
		
			
				|  |  | +                    doSetAuditjiemianEntrys(real_tiaozjiage,adjustproduct,real_customer,saletype,entryentity2Map);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }else{
 | 
	
		
			
				|  |  | +            if(allcustomers!=null){
 | 
	
		
			
				|  |  | +                for(DynamicObject customer: allcustomers){
 | 
	
		
			
				|  |  | +                    for(DynamicObject saletype : saletypes){
 | 
	
		
			
				|  |  | +                        doSetAuditjiemianEntrys(real_tiaozjiage,adjustproduct,customer,saletype,entryentity2Map);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void doSetAuditjiemianEntrys(BigDecimal realTiaozjiage, String adjustproduct, DynamicObject customer, DynamicObject saletype,
 | 
	
		
			
				|  |  | +                                         Map entryentity2Map) {
 | 
	
		
			
				|  |  | +        DynamicObject real_saletype = saletype.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +        String row_key = customer.getPkValue().toString()+";"+adjustproduct+";"+
 | 
	
		
			
				|  |  | +                real_saletype.getPkValue().toString();
 | 
	
		
			
				|  |  | +        int row = 0;
 | 
	
		
			
				|  |  | +        if(entryentity2Map.get(row_key)!=null){
 | 
	
		
			
				|  |  | +            row = Integer.valueOf(entryentity2Map.get(row_key).toString());
 | 
	
		
			
				|  |  | +        }else{
 | 
	
		
			
				|  |  | +            row = this.getModel().createNewEntryRow("nckd_entryentity2");
 | 
	
		
			
				|  |  | +            this.getModel().setValue("nckd_etqyhmbsc",customer,row);
 | 
	
		
			
				|  |  | +            this.getModel().setValue("nckd_eadjustproduct",adjustproduct,row);
 | 
	
		
			
				|  |  | +            this.getModel().setValue("nckd_saletypeb",real_saletype,row);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        this.getModel().setValue("nckd_tiaozfudu",realTiaozjiage,row);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void setTiaozhengdescEntrys(String tjjd_names) {
 | 
	
		
			
				|  |  | +        tjjd_names = !"".equals(tjjd_names)?tjjd_names.substring(1):"";
 | 
	
		
			
				|  |  | +        this.getModel().setValue("nckd_tiaojiajidi",tjjd_names);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void setEntryentityEntrys(BigDecimal real_tiaozjiage,String tjjdsIdsStr, DynamicObjectCollection tjjds,
 | 
	
		
			
				|  |  | +                                      List<Long> quyusIds, List<Long> xqysIds, DynamicObjectCollection xqys,
 | 
	
		
			
				|  |  | +                                      List<Long> salebigtype_ids,List<Long> material_ids, DynamicObjectCollection materials) {
 | 
	
		
			
				|  |  | +        tjjdsIdsStr = tjjdsIdsStr.substring(1);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Map entryDatas = new HashMap();
 | 
	
		
			
				|  |  | +        String sql = "SELECT SPL.fk_nckd_saleorg saleorg," +
 | 
	
		
			
				|  |  | +                            "SPL.fk_nckd_qy qy," +
 | 
	
		
			
				|  |  | +                            "SPL.fk_nckd_material material," +
 | 
	
		
			
				|  |  | +                            "SPL.fk_nckd_salebigtyp salebigtyp," +
 | 
	
		
			
				|  |  | +                            "SPL.fk_nckd_price price " +
 | 
	
		
			
				|  |  | +                "FROM tk_nckd_salepricelevel SPL \n" +
 | 
	
		
			
				|  |  | +                "WHERE SPL.fk_nckd_saleorg IN ("+tjjdsIdsStr+") AND " +
 | 
	
		
			
				|  |  | +                    "SPL.fk_nckd_qy IN ("+quyusIds+") AND " +
 | 
	
		
			
				|  |  | +                    "SPL.fk_nckd_material IN ("+material_ids+") AND " +
 | 
	
		
			
				|  |  | +                    "SPL.fk_nckd_salebigtyp IN ("+salebigtype_ids+")";
 | 
	
		
			
				|  |  | +        DataSet ds = DB.queryDataSet("PriceTiaoZhengPlugin", DBRoute.of("scm"), sql);
 | 
	
		
			
				|  |  | +        while (ds.hasNext()) {
 | 
	
		
			
				|  |  | +            Row row = ds.next();
 | 
	
		
			
				|  |  | +            String key = row.getString("saleorg") + ";"+row.get("qy")+";"+row.get("material");
 | 
	
		
			
				|  |  | +            String value = row.getString("price");
 | 
	
		
			
				|  |  | +            if(entryDatas.get(key)!=null){
 | 
	
		
			
				|  |  | +                value = value +";"+entryDatas.get(key);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            entryDatas.put(key,value);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //先循环分录缓存
 | 
	
		
			
				|  |  | +        Map entryentityMap = new HashMap();
 | 
	
		
			
				|  |  | +        DynamicObjectCollection entryentityresultCol = (DynamicObjectCollection) this.getModel().getValue("nckd_entryentity");
 | 
	
		
			
				|  |  | +        for(int row=0;row<entryentityresultCol.size();row++){
 | 
	
		
			
				|  |  | +            DynamicObject entryentityresultObj = entryentityresultCol.get(row);
 | 
	
		
			
				|  |  | +            DynamicObject nckd_base = entryentityresultObj.getDynamicObject("nckd_base");
 | 
	
		
			
				|  |  | +            DynamicObject nckd_xiaoquyu1 = entryentityresultObj.getDynamicObject("nckd_xiaoquyu1");
 | 
	
		
			
				|  |  | +            DynamicObject nckd_shuini = entryentityresultObj.getDynamicObject("nckd_shuini");
 | 
	
		
			
				|  |  | +            String nckd_tiaozhqianprice = entryentityresultObj.getString("nckd_tiaozhqianprice");
 | 
	
		
			
				|  |  | +            String key = nckd_base.getPkValue().toString()+";"+nckd_xiaoquyu1.getPkValue().toString()+";"+
 | 
	
		
			
				|  |  | +                    nckd_shuini.getPkValue().toString()+";"+nckd_tiaozhqianprice;
 | 
	
		
			
				|  |  | +            entryentityMap.put(key,row);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //开始插入分录
 | 
	
		
			
				|  |  | +        for(DynamicObject tjjd : tjjds){
 | 
	
		
			
				|  |  | +            for(DynamicObject xqy : xqys){
 | 
	
		
			
				|  |  | +                for(DynamicObject material : materials){
 | 
	
		
			
				|  |  | +                    doSetEntryentityEntrys(real_tiaozjiage,tjjd,xqy,material,entryDatas,entryentityMap);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void doSetEntryentityEntrys(BigDecimal real_tiaozjiage, DynamicObject tjjd, DynamicObject xqy, DynamicObject material,
 | 
	
		
			
				|  |  | +                                        Map entryDatas, Map entryentityMap) {
 | 
	
		
			
				|  |  | +        //设置销售基地
 | 
	
		
			
				|  |  | +        DynamicObject real_xiaojd = tjjd.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +        DynamicObject real_xqy = xqy.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +        DynamicObject real_qu = real_xqy.getDynamicObject("nckd_qy");
 | 
	
		
			
				|  |  | +        DynamicObject real_material = material.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +        String price_key = real_xiaojd.getPkValue().toString()+";"+real_qu.getPkValue().toString()+";"+real_material.getPkValue().toString();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        int row = 0;
 | 
	
		
			
				|  |  | +        if(entryDatas.get(price_key)!=null){
 | 
	
		
			
				|  |  | +            String[] values = entryDatas.get(price_key).toString().split(";");
 | 
	
		
			
				|  |  | +            for(String value : values){
 | 
	
		
			
				|  |  | +                String row_key = real_xiaojd.getPkValue().toString()+";"+real_xqy.getPkValue().toString()+";"+
 | 
	
		
			
				|  |  | +                        real_material.getPkValue().toString()+";"+value;
 | 
	
		
			
				|  |  | +                if(entryentityMap.get(row_key)!=null){
 | 
	
		
			
				|  |  | +                    row = Integer.valueOf(entryentityMap.get(row_key).toString());
 | 
	
		
			
				|  |  | +                }else{
 | 
	
		
			
				|  |  | +                    row = this.getModel().createNewEntryRow("nckd_entryentity");
 | 
	
		
			
				|  |  | +                    this.getModel().setValue("nckd_base",real_xiaojd,row);
 | 
	
		
			
				|  |  | +                    this.getModel().setValue("nckd_xiaoquyu1",real_xqy,row);
 | 
	
		
			
				|  |  | +                    this.getModel().setValue("nckd_shuini",real_material,row);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                //设置调整前价格
 | 
	
		
			
				|  |  | +                BigDecimal tiaozhqianprice = new BigDecimal(value);
 | 
	
		
			
				|  |  | +                this.getModel().setValue("nckd_tiaozhqianprice",tiaozhqianprice,row);
 | 
	
		
			
				|  |  | +                //设置调整后价格
 | 
	
		
			
				|  |  | +                BigDecimal tiaozhhouprice = tiaozhqianprice.add(real_tiaozjiage);
 | 
	
		
			
				|  |  | +                this.getModel().setValue("nckd_tiaozhhouprice",tiaozhhouprice,row);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }else{
 | 
	
		
			
				|  |  | +            String row_key = real_xiaojd.getPkValue().toString()+";"+real_xqy.getPkValue().toString()+";"+
 | 
	
		
			
				|  |  | +                    real_material.getPkValue().toString()+";0.00";
 | 
	
		
			
				|  |  | +            if(entryentityMap.get(row_key)!=null){
 | 
	
		
			
				|  |  | +                row = Integer.valueOf(entryentityMap.get(row_key).toString());
 | 
	
		
			
				|  |  | +            }else{
 | 
	
		
			
				|  |  | +                row = this.getModel().createNewEntryRow("nckd_entryentity");
 | 
	
		
			
				|  |  | +                this.getModel().setValue("nckd_base",real_xiaojd,row);
 | 
	
		
			
				|  |  | +                this.getModel().setValue("nckd_xiaoquyu1",real_xqy,row);
 | 
	
		
			
				|  |  | +                this.getModel().setValue("nckd_shuini",real_material,row);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //设置调整后价格
 | 
	
		
			
				|  |  | +            this.getModel().setValue("nckd_tiaozhhouprice",real_tiaozjiage,row);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void setTiaojiajianjieEntrys() {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void setTiaozhengresultEntrys(BigDecimal real_tiaozjiage, String tjjds_ids_str, DynamicObjectCollection tjjds,
 | 
	
		
			
				|  |  | +                                          DynamicObjectCollection customers, DynamicObject[] allcustomers,
 | 
	
		
			
				|  |  | +                                          List<Long> materials_ids, DynamicObjectCollection materials) {
 | 
	
		
			
				|  |  | +        tjjds_ids_str = tjjds_ids_str.substring(1);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String customers_ids = "";
 | 
	
		
			
				|  |  | +        if(customers!=null && customers.size()>0){
 | 
	
		
			
				|  |  | +            for(DynamicObject customer: customers){
 | 
	
		
			
				|  |  | +                DynamicObject real_customer = customer.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +                customers_ids = customers_ids + "," + real_customer.getPkValue().toString();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }else{
 | 
	
		
			
				|  |  | +            if(allcustomers!=null){
 | 
	
		
			
				|  |  | +                for(DynamicObject customer: allcustomers){
 | 
	
		
			
				|  |  | +                    customers_ids = customers_ids + "," + customer.getPkValue().toString();
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        customers_ids = !"".equals(customers_ids)?customers_ids.substring(1):"9999999";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //查询分录数据并缓存
 | 
	
		
			
				|  |  | +        Map entryDatas = new HashMap();
 | 
	
		
			
				|  |  | +        String sql = "SELECT sps.fk_nckd_org tjjd,\n" +
 | 
	
		
			
				|  |  | +                    "spsce.fk_nckd_thht thht,\n" +
 | 
	
		
			
				|  |  | +                    "spspe.fk_nckd_material wl,\n" +
 | 
	
		
			
				|  |  | +                    "spspe.fk_nckd_price price \n" +
 | 
	
		
			
				|  |  | +                "FROM tk_nckd_salepricesubc sps \n" +
 | 
	
		
			
				|  |  | +                "LEFT JOIN tk_nckd_customerentry spsce on sps.fid = spsce.fid \n" +
 | 
	
		
			
				|  |  | +                "LEFT JOIN tk_nckd_priceentry spspe on sps.fid = spspe.fid \n" +
 | 
	
		
			
				|  |  | +//                "LEFT JOIN tk_nckd_thht thht  on spsce.fk_nckd_thht = thht.fid \n" +
 | 
	
		
			
				|  |  | +                "WHERE sps.fk_nckd_org in ("+tjjds_ids_str+") and " +
 | 
	
		
			
				|  |  | +                    "spsce.fk_nckd_thht in ("+customers_ids+") and " +
 | 
	
		
			
				|  |  | +                    "spspe.fk_nckd_material in ("+materials_ids+")";
 | 
	
		
			
				|  |  | +        DataSet ds = DB.queryDataSet("PriceTiaoZhengPlugin", DBRoute.of("scm"), sql);
 | 
	
		
			
				|  |  | +        while (ds.hasNext()) {
 | 
	
		
			
				|  |  | +            Row row = ds.next();
 | 
	
		
			
				|  |  | +            String key = row.getString("tjjd") + ";"+row.get("thht")+";"+row.get("wl");
 | 
	
		
			
				|  |  | +            String value = row.getString("price");
 | 
	
		
			
				|  |  | +            entryDatas.put(key,value);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //先循环分录缓存
 | 
	
		
			
				|  |  | +        Map entryentityresultMap = new HashMap();
 | 
	
		
			
				|  |  | +        DynamicObjectCollection entryentityresultCol = (DynamicObjectCollection) this.getModel().getValue("nckd_entryentityresult");
 | 
	
		
			
				|  |  | +        for(int row=0;row<entryentityresultCol.size();row++){
 | 
	
		
			
				|  |  | +            DynamicObject entryentityresultObj = entryentityresultCol.get(row);
 | 
	
		
			
				|  |  | +            DynamicObject nckd_xiaojd = entryentityresultObj.getDynamicObject("nckd_xiaojd");
 | 
	
		
			
				|  |  | +            DynamicObject nckd_customerhang = entryentityresultObj.getDynamicObject("nckd_customerhang");
 | 
	
		
			
				|  |  | +            DynamicObject nckd_materialhang = entryentityresultObj.getDynamicObject("nckd_materialhang");
 | 
	
		
			
				|  |  | +            String key = nckd_xiaojd.getPkValue().toString()+";"+nckd_customerhang.getPkValue().toString()+";"+nckd_materialhang.getPkValue().toString();
 | 
	
		
			
				|  |  | +            entryentityresultMap.put(key,row);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //开始插入分录
 | 
	
		
			
				|  |  | +        for(DynamicObject tjjd : tjjds){
 | 
	
		
			
				|  |  | +            if(customers!=null && customers.size()>0){//使用选择提货客户
 | 
	
		
			
				|  |  | +                for(DynamicObject customer: customers){
 | 
	
		
			
				|  |  | +                    DynamicObject real_customerhang = customer.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +                    for(DynamicObject material:materials){
 | 
	
		
			
				|  |  | +                        doSetTiaozhengresultEntrys(real_tiaozjiage,tjjd,real_customerhang,material,entryDatas,entryentityresultMap);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }else{//使用全部条件提货客户
 | 
	
		
			
				|  |  | +                if(allcustomers!=null){
 | 
	
		
			
				|  |  | +                    for(DynamicObject customer: allcustomers){
 | 
	
		
			
				|  |  | +                        for(DynamicObject material:materials){
 | 
	
		
			
				|  |  | +                            doSetTiaozhengresultEntrys(real_tiaozjiage,tjjd,customer,material,entryDatas,entryentityresultMap);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void doSetTiaozhengresultEntrys(BigDecimal real_tiaozjiage,DynamicObject tjjd, DynamicObject customer,
 | 
	
		
			
				|  |  | +                                            DynamicObject material, Map entryDatas, Map entryentityresultMap) {
 | 
	
		
			
				|  |  | +        DynamicObject real_xiaojd = tjjd.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +        DynamicObject real_material = material.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +        String row_key = real_xiaojd.getPkValue()+";"+customer.getPkValue()+";"+real_material.getPkValue();
 | 
	
		
			
				|  |  | +        int row = 0;
 | 
	
		
			
				|  |  | +        if(entryentityresultMap.get(row_key)!=null){
 | 
	
		
			
				|  |  | +            row = Integer.valueOf(entryentityresultMap.get(row_key).toString());
 | 
	
		
			
				|  |  | +        }else{
 | 
	
		
			
				|  |  | +            row = this.getModel().createNewEntryRow("nckd_entryentityresult");
 | 
	
		
			
				|  |  | +            //设置销售基地
 | 
	
		
			
				|  |  | +            this.getModel().setValue("nckd_xiaojd",real_xiaojd,row);
 | 
	
		
			
				|  |  | +            //设置提货户头
 | 
	
		
			
				|  |  | +            this.getModel().setValue("nckd_customerhang",customer,row);
 | 
	
		
			
				|  |  | +            //设置物料
 | 
	
		
			
				|  |  | +            this.getModel().setValue("nckd_materialhang",real_material,row);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //设置原单价
 | 
	
		
			
				|  |  | +        String price_key = real_xiaojd.getPkValue().toString()+";"+customer.getPkValue().toString()+";"+real_material.getPkValue().toString();
 | 
	
		
			
				|  |  | +        BigDecimal yuanprice = new BigDecimal(0);
 | 
	
		
			
				|  |  | +        if(entryDatas.get(price_key)!=null){
 | 
	
		
			
				|  |  | +            yuanprice = new BigDecimal(entryDatas.get(price_key).toString());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        this.getModel().setValue("nckd_yuanprice",yuanprice,row);
 | 
	
		
			
				|  |  | +        //设置调价幅度
 | 
	
		
			
				|  |  | +        this.getModel().setValue("nckd_tiaojiafudu",real_tiaozjiage,row);
 | 
	
		
			
				|  |  | +        //设置新单价==原单价+调价幅度
 | 
	
		
			
				|  |  | +        BigDecimal newPrice = yuanprice.add(real_tiaozjiage);
 | 
	
		
			
				|  |  | +        this.getModel().setValue("nckd_newprice",newPrice,row);
 | 
	
		
			
				|  |  | +        //设置执行时间
 | 
	
		
			
				|  |  | +        this.getModel().setValue("nckd_zhixingdate",this.getModel().getValue("nckd_tzsxsj"),row);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void registerListener(EventObject e) {
 | 
	
		
			
				|  |  | +        BasedataEdit bEdit = this.getView().getControl("nckd_xqys");
 | 
	
		
			
				|  |  | +        bEdit.addBeforeF7SelectListener(this);
 | 
	
		
			
				|  |  | +        super.registerListener(e);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void beforeF7Select(BeforeF7SelectEvent beforeF7SelectEvent) {
 | 
	
		
			
				|  |  | +        String propertyName = beforeF7SelectEvent.getProperty().getName();
 | 
	
		
			
				|  |  | +        if("nckd_xqys".equals(propertyName)) {
 | 
	
		
			
				|  |  | +            ListShowParameter formShowParameter = (ListShowParameter) beforeF7SelectEvent.getFormShowParameter();
 | 
	
		
			
				|  |  | +            List<QFilter> qFilters = new ArrayList<>();
 | 
	
		
			
				|  |  | +            DynamicObjectCollection quyus = (DynamicObjectCollection) this.getModel().getValue("nckd_quyus");
 | 
	
		
			
				|  |  | +            List<Long> quyus_ids = new ArrayList();
 | 
	
		
			
				|  |  | +            for(DynamicObject quyu : quyus){
 | 
	
		
			
				|  |  | +                DynamicObject real_quyu = quyu.getDynamicObject("fbasedataid");
 | 
	
		
			
				|  |  | +                quyus_ids.add(real_quyu.getLong("id"));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            qFilters.add(new QFilter("nckd_qy.id", QCP.in, quyus_ids));
 | 
	
		
			
				|  |  | +            formShowParameter.getListFilterParameter().setQFilters(qFilters);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |