|
@@ -2,9 +2,12 @@ package restcontroller.webmanage.sale.invbal;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
|
|
|
import beans.itemclass.ItemClass;
|
|
|
import beans.parameter.Parameter;
|
|
@@ -214,15 +217,15 @@ public class invbal extends Controller {
|
|
|
RowsMap sumUnQtyRowsMap = sumUnQtyRows.toRowsMap("itemno");
|
|
|
|
|
|
|
|
|
- ERPDocking erpDocking =new ERPDocking(siteid);
|
|
|
- JSONArray jsonArray =new JSONArray();
|
|
|
- if(rows.toJsonArray("itemno").size()!=0){
|
|
|
- if (Parameter.get("system.ccerp_dockswitch").equalsIgnoreCase("true") ) {
|
|
|
- if(rows.toJsonArray("itemno").size()<=2000){
|
|
|
- jsonArray=erpDocking.getErpIcinvbalRows(200000, 1,rows.toJsonArray("itemno"));
|
|
|
- }else {
|
|
|
- jsonArray=erpDocking.getErpIcinvbalRows(200000, 1,new JSONArray());
|
|
|
- }
|
|
|
+ ERPDocking erpDocking = new ERPDocking(siteid);
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ if (rows.toJsonArray("itemno").size() != 0) {
|
|
|
+ if (Parameter.get("system.ccerp_dockswitch").equalsIgnoreCase("true")) {
|
|
|
+ if (rows.toJsonArray("itemno").size() <= 2000) {
|
|
|
+ jsonArray = erpDocking.getErpIcinvbalRows(200000, 1, rows.toJsonArray("itemno"));
|
|
|
+ } else {
|
|
|
+ jsonArray = erpDocking.getErpIcinvbalRows(200000, 1, new JSONArray());
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -343,8 +346,8 @@ public class invbal extends Controller {
|
|
|
year = calendar.get(Calendar.YEAR);
|
|
|
}
|
|
|
|
|
|
- String begindate = year+"-01-01";
|
|
|
- String enddate = (year+1)+"-01-01";
|
|
|
+// String begindate = year+"-01-01";
|
|
|
+// String enddate = (year+1)+"-01-01";
|
|
|
|
|
|
String where = " 1=1 ";
|
|
|
SQLFactory sqlFactory = new SQLFactory(this, "商品列表", pageSize, pageNumber, pageSorting);
|
|
@@ -412,7 +415,7 @@ public class invbal extends Controller {
|
|
|
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") + "%') ";
|
|
|
+// where = where + " and (t6.agentnum like '%" + whereObject.getStringValue("agentinfo") + "%' or t5.enterprisename like '%" + whereObject.getStringValue("agentinfo") + "%') ";
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -498,25 +501,22 @@ public class invbal extends Controller {
|
|
|
//查询统计商品月销量销
|
|
|
SQLFactory sqlFactory3 = new SQLFactory(this, "查询统计商品月销量销");
|
|
|
sqlFactory3.addParameter("siteid", siteid);
|
|
|
- sqlFactory3.addParameter("begindate", begindate);
|
|
|
- sqlFactory3.addParameter("enddate", enddate);
|
|
|
sqlFactory3.addParameter_in("itemid", rows.toArray("itemid"));
|
|
|
- RowsMap monthRowsMap = dbConnect.runSqlQuery(sqlFactory3).toRowsMap("itemid");
|
|
|
+ Rows rows3 = dbConnect.runSqlQuery(sqlFactory3);
|
|
|
+ RowsMap monthRowsMap = rows3.toRowsMap("itemid");
|
|
|
|
|
|
SQLFactory sqlFactory4 = new SQLFactory(this, "查询退货统计");
|
|
|
sqlFactory4.addParameter("siteid", siteid);
|
|
|
- sqlFactory4.addParameter("begindate", begindate);
|
|
|
- sqlFactory4.addParameter("enddate", enddate);
|
|
|
sqlFactory4.addParameter_in("itemid", rows.toArray("itemid"));
|
|
|
- RowsMap returnRowsMap = dbConnect.runSqlQuery(sqlFactory4).toRowsMap("itemid");
|
|
|
+ Rows rows4 = dbConnect.runSqlQuery(sqlFactory4);
|
|
|
+ RowsMap returnRowsMap = rows4.toRowsMap("itemid");
|
|
|
|
|
|
|
|
|
SQLFactory sqlFactory5 = new SQLFactory(this, "查询手工关闭统计");
|
|
|
sqlFactory5.addParameter("siteid", siteid);
|
|
|
- sqlFactory5.addParameter("begindate", begindate);
|
|
|
- sqlFactory5.addParameter("enddate", enddate);
|
|
|
sqlFactory5.addParameter_in("itemid", rows.toArray("itemid"));
|
|
|
- RowsMap closeRowsMap = dbConnect.runSqlQuery(sqlFactory5).toRowsMap("itemid");
|
|
|
+ Rows rows5 = dbConnect.runSqlQuery(sqlFactory4);
|
|
|
+ RowsMap closeRowsMap = rows5.toRowsMap("itemid");
|
|
|
|
|
|
|
|
|
for (Row row : rows) {
|
|
@@ -525,23 +525,28 @@ public class invbal extends Controller {
|
|
|
row.put("canbesale", ((row.getBigDecimal("invbalqty").subtract(row.getBigDecimal("unsoldqty"))).subtract(row.getBigDecimal("undelqtysum"))).stripTrailingZeros().toPlainString());
|
|
|
Rows monthRows = monthRowsMap.getOrDefault(row.getString("itemid"), new Rows());
|
|
|
for (Row month : monthRows) {
|
|
|
- row.put("month_" + month.getString("month"), month.getBigDecimal("qty"));
|
|
|
+ row.put(month.getString("month"), month.getBigDecimal("qty"));
|
|
|
}
|
|
|
//补足月份
|
|
|
row = initMonthRow(row);
|
|
|
//处理退货
|
|
|
Rows returnRows = returnRowsMap.getOrDefault(row.getString("itemid"), new Rows());
|
|
|
for (Row returnRow : returnRows) {
|
|
|
- String key = "month_" + returnRow.getString("month");
|
|
|
+ String key = returnRow.getString("month");
|
|
|
row.replace(key, row.getBigDecimal(key).subtract(returnRow.getBigDecimal("qty")));
|
|
|
}
|
|
|
//
|
|
|
Rows closeRows = closeRowsMap.getOrDefault(row.getString("itemid"), new Rows());
|
|
|
for (Row closeRow : closeRows) {
|
|
|
- String key = "month_" + closeRow.getString("month");
|
|
|
+ String key = closeRow.getString("month");
|
|
|
row.replace(key, row.getBigDecimal(key).subtract(closeRow.getBigDecimal("qty")));
|
|
|
}
|
|
|
}
|
|
|
+ for (Row row : rows) {
|
|
|
+ for (int i=0;i<12;i++) {
|
|
|
+ row.replace("month_0"+(i+1), row.get(getLast12Months().get(i)));
|
|
|
+ }
|
|
|
+ }
|
|
|
// if (isExport) {
|
|
|
// //去除不需要导出项
|
|
|
// rows.getFieldList().remove("itemid");
|
|
@@ -554,6 +559,11 @@ public class invbal extends Controller {
|
|
|
}
|
|
|
|
|
|
public Row initMonthRow(Row row) {
|
|
|
+ for (String key : getLast12Months()) {
|
|
|
+ row.putIfAbsent(key, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ //初始化
|
|
|
row.putIfAbsent("month_01", 0);
|
|
|
row.putIfAbsent("month_02", 0);
|
|
|
row.putIfAbsent("month_03", 0);
|
|
@@ -566,7 +576,27 @@ public class invbal extends Controller {
|
|
|
row.putIfAbsent("month_10", 0);
|
|
|
row.putIfAbsent("month_11", 0);
|
|
|
row.putIfAbsent("month_12", 0);
|
|
|
+
|
|
|
return row;
|
|
|
}
|
|
|
|
|
|
+ public List<String> getLast12Months() {
|
|
|
+ // 获取当前日期
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
+
|
|
|
+ // 创建一个存储日期的列表
|
|
|
+ List<String> last12Months = new ArrayList<>();
|
|
|
+
|
|
|
+ // 获取最近12个月的日期
|
|
|
+ for (int i = 0; i < 12; i++) {
|
|
|
+ // 使用DateTimeFormatter将日期格式化为字符串
|
|
|
+ String formattedDate = currentDate.format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
|
|
+ last12Months.add(formattedDate);
|
|
|
+
|
|
|
+ // 将当前日期减去一个月
|
|
|
+ currentDate = currentDate.minusMonths(1);
|
|
|
+ }
|
|
|
+ return last12Months;
|
|
|
+ }
|
|
|
+
|
|
|
}
|