|
@@ -340,14 +340,28 @@ public class invbal extends Controller {
|
|
|
@API(title = "商品补货分析", apiversion = R.ID20231228102402.v1.class)
|
|
|
public String queryItemSalesList() throws YosException, IOException {
|
|
|
// boolean isExport = content.getBooleanValue("isExport");
|
|
|
- int year = content.getIntValue("year");
|
|
|
- if (year <= 0) {
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- year = calendar.get(Calendar.YEAR);
|
|
|
+ String year_month = content.getStringValue("year_month");
|
|
|
+ if (StringUtils.isBlank(year_month)) {
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
+ String formattedDate = currentDate.format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
|
|
+ year_month = formattedDate;
|
|
|
}
|
|
|
|
|
|
// String begindate = year+"-01-01";
|
|
|
// String enddate = (year+1)+"-01-01";
|
|
|
+ year_month=year_month+"-01";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 定义日期格式
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+
|
|
|
+ // 解析指定日期字符串为 LocalDate 对象
|
|
|
+ LocalDate specifiedDate = LocalDate.parse(year_month, formatter);
|
|
|
+
|
|
|
+ // 计算下个月的同一天,然后使用 withDayOfMonth(1) 方法获取下个月的第一天
|
|
|
+ LocalDate nextMonthFirstDay = specifiedDate.plusMonths(1).withDayOfMonth(1);
|
|
|
+
|
|
|
|
|
|
String where = " 1=1 ";
|
|
|
SQLFactory sqlFactory = new SQLFactory(this, "商品列表", pageSize, pageNumber, pageSorting);
|
|
@@ -503,12 +517,17 @@ public class invbal extends Controller {
|
|
|
//查询统计商品月销量销
|
|
|
SQLFactory sqlFactory3 = new SQLFactory(this, "查询统计商品月销量销");
|
|
|
sqlFactory3.addParameter("siteid", siteid);
|
|
|
+ sqlFactory3.addParameter("begindate", year_month);
|
|
|
+ sqlFactory3.addParameter("enddate", nextMonthFirstDay);
|
|
|
+
|
|
|
sqlFactory3.addParameter_in("itemid", rows.toArray("itemid"));
|
|
|
Rows rows3 = dbConnect.runSqlQuery(sqlFactory3);
|
|
|
RowsMap monthRowsMap = rows3.toRowsMap("itemid");
|
|
|
|
|
|
SQLFactory sqlFactory4 = new SQLFactory(this, "查询退货统计");
|
|
|
sqlFactory4.addParameter("siteid", siteid);
|
|
|
+ sqlFactory4.addParameter("begindate", year_month);
|
|
|
+ sqlFactory4.addParameter("enddate", nextMonthFirstDay);
|
|
|
sqlFactory4.addParameter_in("itemid", rows.toArray("itemid"));
|
|
|
Rows rows4 = dbConnect.runSqlQuery(sqlFactory4);
|
|
|
RowsMap returnRowsMap = rows4.toRowsMap("itemid");
|
|
@@ -516,6 +535,8 @@ public class invbal extends Controller {
|
|
|
|
|
|
SQLFactory sqlFactory5 = new SQLFactory(this, "查询手工关闭统计");
|
|
|
sqlFactory5.addParameter("siteid", siteid);
|
|
|
+ sqlFactory5.addParameter("begindate", year_month);
|
|
|
+ sqlFactory5.addParameter("enddate", nextMonthFirstDay);
|
|
|
sqlFactory5.addParameter_in("itemid", rows.toArray("itemid"));
|
|
|
Rows rows5 = dbConnect.runSqlQuery(sqlFactory4);
|
|
|
RowsMap closeRowsMap = rows5.toRowsMap("itemid");
|
|
@@ -530,7 +551,7 @@ public class invbal extends Controller {
|
|
|
row.put(month.getString("month"), month.getBigDecimal("qty"));
|
|
|
}
|
|
|
//补足月份
|
|
|
- row = initMonthRow(row);
|
|
|
+ row = initMonthRow(row,year_month);
|
|
|
//处理退货
|
|
|
Rows returnRows = returnRowsMap.getOrDefault(row.getString("itemid"), new Rows());
|
|
|
for (Row returnRow : returnRows) {
|
|
@@ -547,9 +568,9 @@ public class invbal extends Controller {
|
|
|
for (Row row : rows) {
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
if (i < 9) {
|
|
|
- row.replace("month_0" + (i + 1), row.get(getLast12Months().get(i)));
|
|
|
+ row.replace("month_0" + (i + 1), row.get(getLast12Months(year_month).get(i)));
|
|
|
} else {
|
|
|
- row.replace("month_" + (i + 1), row.get(getLast12Months().get(i)));
|
|
|
+ row.replace("month_" + (i + 1), row.get(getLast12Months(year_month).get(i)));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -564,8 +585,8 @@ public class invbal extends Controller {
|
|
|
return getSucReturnObject().setData(rows).toString();
|
|
|
}
|
|
|
|
|
|
- public Row initMonthRow(Row row) {
|
|
|
- for (String key : getLast12Months()) {
|
|
|
+ public Row initMonthRow(Row row,String date) {
|
|
|
+ for (String key : getLast12Months(date)) {
|
|
|
row.putIfAbsent(key, 0);
|
|
|
}
|
|
|
|
|
@@ -586,9 +607,14 @@ public class invbal extends Controller {
|
|
|
return row;
|
|
|
}
|
|
|
|
|
|
- public List<String> getLast12Months() {
|
|
|
- // 获取当前日期
|
|
|
- LocalDate currentDate = LocalDate.now();
|
|
|
+ public List<String> getLast12Months(String date) {
|
|
|
+
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+
|
|
|
+ // 解析指定日期字符串为 LocalDate 对象
|
|
|
+ LocalDate currentDate = LocalDate.parse(date, formatter);
|
|
|
+// // 获取当前日期
|
|
|
+// LocalDate currentDate = LocalDate.now();
|
|
|
|
|
|
// 创建一个存储日期的列表
|
|
|
List<String> last12Months = new ArrayList<>();
|