Bladeren bron

欠货库存接口更新

hu 1 jaar geleden
bovenliggende
commit
8e0e650a09
1 gewijzigde bestanden met toevoegingen van 86 en 86 verwijderingen
  1. 86 86
      src/custom/restcontroller/webmanage/sale/invbal/invbal.java

+ 86 - 86
src/custom/restcontroller/webmanage/sale/invbal/invbal.java

@@ -116,69 +116,61 @@ public class invbal extends Controller {
 	@API(title = "查询Erp库存列表", apiversion = R.ID20230408091703.v1.class)
 	public String queryErpInvbalList() throws YosException, IOException {
 		boolean isExport = content.getBooleanValue("isExport");
-		String iteminfo = content.getStringValue("iteminfo");
-		String agentinfo = content.getStringValue("agentinfo");
-		boolean all = content.getBooleanValue("all");
-		JSONArray itemclassids = content.getJSONArray("itemclassids");
-		String where ="1=2";
+		//String iteminfo = content.getStringValue("iteminfo");
+		//String agentinfo = content.getStringValue("agentinfo");
+		//boolean all = content.getBooleanValue("all");
+		//JSONArray itemclassids = content.getJSONArray("itemclassids");
+		String where =" 1=1 ";
 		SQLFactory sqlFactory =new SQLFactory(this,"商品列表", pageSize, pageNumber, pageSorting);
 		if (isExport) {
 			sqlFactory = new SQLFactory(this,"商品列表");
 		}
-		if(!StringUtils.isBlank(iteminfo)){
-			sqlFactory=new SQLFactory(this,"商品列表", pageSize, pageNumber, pageSorting);
-			if (isExport) {
-				sqlFactory = new SQLFactory(this,"商品列表");
+		if (content.containsKey("where")) {
+			JSONObject whereObject = content.getJSONObject("where");
+			if(whereObject.containsKey("iteminfo")){
+				if(!StringUtils.isBlank(whereObject.getStringValue("iteminfo"))){
+					where=where+" and (t2.itemno like '%"+whereObject.getStringValue("iteminfo")+"%' or t2.itemname like '%"+whereObject.getStringValue("iteminfo")+"%') ";
+				}
 			}
-			where=where+" or t2.itemno like '%"+iteminfo+"%' or t2.itemname like '%"+iteminfo+"%' ";
-		}
-//		if(!StringUtils.isBlank(itemname)){
-//			sqlFactory=new SQLFactory(this,"商品列表", pageSize, pageNumber, pageSorting);
-//			if (isExport) {
-//				sqlFactory = new SQLFactory(this,"商品列表");
-//			}
-//			where=where+" or t2.itemname like '%"+itemname+"%' ";
-//		}
-		if (itemclassids.size() > 0) {
-			sqlFactory=new SQLFactory(this,"商品列表", pageSize, pageNumber, pageSorting);
-			if (isExport) {
-				sqlFactory = new SQLFactory(this,"商品列表");
+			if(whereObject.containsKey("itemclassids")){
+				if (whereObject.getJSONArray("itemclassids").size() > 0) {
+					ArrayList<Long> itemclassList = new ArrayList<Long>();
+					for (Object object : whereObject.getJSONArray("itemclassids")) {
+						//System.out.println(row.getLong("itemclassid"));
+
+						long itemclassid = Long.valueOf(String.valueOf(object));
+						itemclassList.add(itemclassid);
+						itemclassList.addAll(ItemClass.getSubItemClassIds(this,itemclassid));
+					}
+					String sql = " and t2.itemid in ( SELECT itemid from sa_itemsaleclass WHERE itemclassid IN " + itemclassList + "  and siteid='" + siteid + "')";
+					sql = sql.replace("[", "(").replace("]", ")");
+					where=where+sql;
+				}
 			}
-			ArrayList<Long> itemclassList = new ArrayList<Long>();
-			for (Object object : itemclassids) {
-				//System.out.println(row.getLong("itemclassid"));
 
-				long itemclassid = Long.valueOf(String.valueOf(object));
-				itemclassList.add(itemclassid);
-				itemclassList.addAll(ItemClass.getSubItemClassIds(this,itemclassid));
+			if (whereObject.containsKey("all") && !"".equals(whereObject.getString("all"))) {
+				if(!whereObject.getBooleanValue("all")){
+					where = where+" and 1=2 ";
+				}
 			}
-			String sql = " or t2.itemid in ( SELECT itemid from sa_itemsaleclass WHERE itemclassid IN " + itemclassList + "  and siteid='" + siteid + "')";
-			sql = sql.replace("[", "(").replace("]", ")");
-			where=where+sql;
-		}
-		if(all){
-			where=where+" or 1=1 ";
-		}
-		if (content.containsKey("where")) {
-			JSONObject whereObject = content.getJSONObject("where");
 			if (whereObject.containsKey("isonsale") && !"".equals(whereObject.getString("isonsale"))) {
-				where = where+" or t2.isonsale ='"+whereObject.getString("isonsale") + "' ";
-			}
-		}
-
-		if(!StringUtils.isBlank(agentinfo)){
-			sqlFactory =new SQLFactory(this,"订单明细未发商品列表", pageSize, pageNumber, pageSorting);
-			if (isExport) {
-				sqlFactory = new SQLFactory(this,"订单明细未发商品列表");
+				where = where+" and t2.isonsale ='"+whereObject.getString("isonsale") + "' ";
 			}
-			//System.out.println(StringUtils.isBlank(itemname) && StringUtils.isBlank(itemno) && itemclassids.size()==0);
-			if(StringUtils.isBlank(iteminfo) && StringUtils.isBlank(iteminfo) && itemclassids.size()==0){
-				where=where+" or 1=1 and (t6.agentnum like '%"+agentinfo+"%' or t5.enterprisename like '%"+agentinfo+"%') ";
-			}else {
-				where=where+" and (t6.agentnum like '%"+agentinfo+"%' or t5.enterprisename like '%"+agentinfo+"%') ";
+			if(whereObject.containsKey("agentinfo")){
+				if(!StringUtils.isBlank(whereObject.getStringValue("agentinfo"))){
+					sqlFactory =new SQLFactory(this,"订单明细未发商品列表", pageSize, pageNumber, pageSorting);
+					if (isExport) {
+						sqlFactory = new SQLFactory(this,"订单明细未发商品列表");
+					}
+					//System.out.println(StringUtils.isBlank(itemname) && StringUtils.isBlank(itemno) && itemclassids.size()==0);
+					if(!StringUtils.isBlank(whereObject.getStringValue("agentinfo"))){
+						where=where+" and (t6.agentnum like '%"+whereObject.getStringValue("agentinfo")+"%' or t5.enterprisename like '%"+whereObject.getStringValue("agentinfo")+"%') ";
+					}
+				}
 			}
 
 		}
+
 		sqlFactory.addParameter("siteid", siteid);
 		sqlFactory.addParameter_SQL("where", where);
 		//System.out.println(sqlFactory.getSQL());
@@ -195,25 +187,33 @@ public class invbal extends Controller {
 		sqlFactory1.addParameter_SQL("where", where);
 		Rows sumQtyRows = dbConnect.runSqlQuery(sqlFactory1);
 		RowsMap sumAllQtyRowsMap= sumQtyRows.toRowsMap("itemno");
-		if(!StringUtils.isBlank(agentinfo)){
-			where=where+" and (t6.agentnum like '%"+agentinfo+"%' or t5.enterprisename like '%"+agentinfo+"%') ";
+		if (content.containsKey("where")) {
+			JSONObject whereObject = content.getJSONObject("where");
+			if(!StringUtils.isBlank(whereObject.getStringValue("agentinfo"))){
+				where=where+" and (t6.agentnum like '%"+whereObject.getStringValue("agentinfo")+"%' or t5.enterprisename like '%"+whereObject.getStringValue("agentinfo")+"%') ";
+			}
 		}
+
 		sqlFactory1.addParameter_SQL("where", where);
 		sumQtyRows = dbConnect.runSqlQuery(sqlFactory1);
 		RowsMap sumQtyRowsMap= sumQtyRows.toRowsMap("itemno");
 
-        SQLFactory sqlFactory2 =new SQLFactory(this,"商品未发货数量汇总");
-        sqlFactory2.addParameter("siteid", siteid);
+		SQLFactory sqlFactory2 =new SQLFactory(this,"商品未发货数量汇总");
+		sqlFactory2.addParameter("siteid", siteid);
 		where=" 1=1 ";
-        sqlFactory2.addParameter_SQL("where", where);
-        Rows sumUnQtyRows = dbConnect.runSqlQuery(sqlFactory2);
-        RowsMap sumUnAllQtyRowsMap= sumUnQtyRows.toRowsMap("itemno");
-		if(!StringUtils.isBlank(agentinfo)){
-			where=where+" and (t6.agentnum like '%"+agentinfo+"%' or t5.enterprisename like '%"+agentinfo+"%') ";
+		sqlFactory2.addParameter_SQL("where", where);
+		Rows sumUnQtyRows = dbConnect.runSqlQuery(sqlFactory2);
+		RowsMap sumUnAllQtyRowsMap= sumUnQtyRows.toRowsMap("itemno");
+		if (content.containsKey("where")) {
+			JSONObject whereObject = content.getJSONObject("where");
+			if(!StringUtils.isBlank(whereObject.getStringValue("agentinfo"))){
+				where=where+" and (t6.agentnum like '%"+whereObject.getStringValue("agentinfo")+"%' or t5.enterprisename like '%"+whereObject.getStringValue("agentinfo")+"%') ";
+			}
 		}
+
 		sqlFactory2.addParameter_SQL("where", where);
 		sumUnQtyRows = dbConnect.runSqlQuery(sqlFactory2);
-        RowsMap sumUnQtyRowsMap= sumUnQtyRows.toRowsMap("itemno");
+		RowsMap sumUnQtyRowsMap= sumUnQtyRows.toRowsMap("itemno");
 
 
 		ERPDocking erpDocking =new ERPDocking();
@@ -236,7 +236,7 @@ public class invbal extends Controller {
 				if(rowsMap.containsKey(jsonObject.getString("fitemno"))){
 					if(rowsMap.get(jsonObject.getString("fitemno")).isNotEmpty()){
 						rowsMap.get(jsonObject.getString("fitemno")).get(0).put("invbalqty", jsonObject.getBigDecimalValue("fqty"));
-				}
+					}
 				}
 			}
 		}
@@ -255,18 +255,18 @@ public class invbal extends Controller {
 				row.put("undelqty", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
 				row.put("qty", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
 			}
-            if(sumUnAllQtyRowsMap.get(row.getString("itemno")).isNotEmpty()){
-                row.put("undelqtysum", sumUnAllQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("undeliqty").stripTrailingZeros().toPlainString());
-            }else {
-                row.put("undelqtysum", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
-            }
+			if(sumUnAllQtyRowsMap.get(row.getString("itemno")).isNotEmpty()){
+				row.put("undelqtysum", sumUnAllQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("undeliqty").stripTrailingZeros().toPlainString());
+			}else {
+				row.put("undelqtysum", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
+			}
 			if(sumAllQtyRowsMap.get(row.getString("itemno")).isNotEmpty()){
 				row.put("unsoldqtysum", sumAllQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("qty").stripTrailingZeros().toPlainString());
 			}else {
 				row.put("unsoldqtysum", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
 			}
 
-            if(!row.containsKey("invbalqty")){
+			if(!row.containsKey("invbalqty")){
 				row.put("invbalqty",BigDecimal.ZERO.stripTrailingZeros().toPlainString());
 			}
 
@@ -276,27 +276,27 @@ public class invbal extends Controller {
 			row.put("canbesent", (row.getBigDecimal("invbalqty").subtract(row.getBigDecimal("unsoldqty"))).stripTrailingZeros().toPlainString());
 			row.put("canbesale", ((row.getBigDecimal("invbalqty").subtract(row.getBigDecimal("unsoldqty"))).subtract(row.getBigDecimal("undelqtysum"))).stripTrailingZeros().toPlainString());
 			if(row.getString("itemno").equals("10901371")){
-				//System.out.println(row.getString("canbesent"));
-				//System.out.println(row.getString("canbesale"));
-				//System.out.println(row.toJsonObject().toJSONString());
+				System.out.println(row.getString("canbesent"));
+				System.out.println(row.getString("canbesale"));
+				System.out.println(row.toJsonObject().toJSONString());
+			}
+		}
+		if(isExport){
+			//去除不需要导出项
+			rows.getFieldList().remove("itemid");
+			rows.getFieldList().remove("packageqty");
+			rows.getFieldList().remove("qty");
+			for (Row row:rows) {
+				if(row.getString("itemno").equals("10901371")){
+					System.out.println(row.getString("canbesent"));
+					System.out.println(row.getString("canbesale"));
+					System.out.println(row.toJsonObject().toJSONString());
+				}
+
 			}
+			Rows uploadRows = uploadExcelToObs("invbal", "库存列表", rows, getTitleMap());
+			return getSucReturnObject().setData(uploadRows).toString();
 		}
-//		if(isExport){
-//			//去除不需要导出项
-//			rows.getFieldList().remove("itemid");
-//			rows.getFieldList().remove("packageqty");
-//			rows.getFieldList().remove("qty");
-//			for (Row row:rows) {
-//				if(row.getString("itemno").equals("10901371")){
-//					System.out.println(row.getString("canbesent"));
-//					System.out.println(row.getString("canbesale"));
-//					 System.out.println(row.toJsonObject().toJSONString());
-//				}
-//
-//			}
-//			Rows uploadRows = uploadExcelToObs("invbal", "库存列表", rows, getTitleMap());
-//			return getSucReturnObject().setData(uploadRows).toString();
-//		}
 		return getSucReturnObject().setData(rows).toString();
 	}