|
@@ -1,13 +1,22 @@
|
|
package com.example.controller;
|
|
package com.example.controller;
|
|
|
|
|
|
-import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.example.common.Result;
|
|
import com.example.common.Result;
|
|
import com.example.common.enums.OrderStatus;
|
|
import com.example.common.enums.OrderStatus;
|
|
import com.example.entity.Orders;
|
|
import com.example.entity.Orders;
|
|
|
|
+import com.example.entity.Product;
|
|
|
|
+import com.example.entity.SaleStatement;
|
|
import com.example.service.OrdersService;
|
|
import com.example.service.OrdersService;
|
|
|
|
+import com.example.service.SaleStatementService;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
+
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -19,7 +28,8 @@ public class OrdersController {
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private OrdersService ordersService;
|
|
private OrdersService ordersService;
|
|
-
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private SaleStatementService saleStatementService;
|
|
/**
|
|
/**
|
|
* 获取店铺未完成的订单个数
|
|
* 获取店铺未完成的订单个数
|
|
* @param shopId
|
|
* @param shopId
|
|
@@ -50,6 +60,53 @@ public class OrdersController {
|
|
public Result setOrdersArrived(@RequestBody Orders orders){
|
|
public Result setOrdersArrived(@RequestBody Orders orders){
|
|
orders.setOrderState(String.valueOf(OrderStatus.ARRIVED));
|
|
orders.setOrderState(String.valueOf(OrderStatus.ARRIVED));
|
|
ordersService.updateById(orders);
|
|
ordersService.updateById(orders);
|
|
|
|
+ Orders dbOrders = ordersService.selectById(orders.getId());
|
|
|
|
+ // 添加到报表信息中去
|
|
|
|
+
|
|
|
|
+ // 构建报表信息
|
|
|
|
+// List<Product> orderProductsLists = dbOrders.getOrderProductsLists(); // 新加入的产品
|
|
|
|
+// String jsonString1 = JSON.toJSONString(orderProductsLists); // 将对象转换成json格式数据
|
|
|
|
+// JSONArray jsonObject = JSON.parseArray(jsonString1); // 在转回去
|
|
|
|
+// List<Product> orderProductsListsTrue = JSON.parseObject(jsonObject.getString("list"), Product.class); // 这样就可以了
|
|
|
|
+ List<Product> orderProductsLists = dbOrders.getOrderProductsLists(); // 获取产品列表
|
|
|
|
+// 将产品列表转换为 JSON 字符串
|
|
|
|
+ String jsonString = JSON.toJSONString(orderProductsLists);
|
|
|
|
+// 将 JSON 字符串解析为 JSONArray
|
|
|
|
+ JSONArray jsonArray = JSON.parseArray(jsonString);
|
|
|
|
+// 创建一个用于存储 Product 对象的列表
|
|
|
|
+ List<Product> orderProductsListsTrue = new ArrayList<>();
|
|
|
|
+// 遍历 JSONArray,将每个元素转换为 Product 对象并添加到新的列表中
|
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
|
+ JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
|
+ Product product = jsonObject.toJavaObject(Product.class);
|
|
|
|
+ orderProductsListsTrue.add(product);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// 现在 orderProductsListsTrue 就是包含正确类型的 Product 对象的列表
|
|
|
|
+
|
|
|
|
+ orderProductsListsTrue.forEach(productMap -> {
|
|
|
|
+ Product product = (Product) productMap; // 进行类型转换
|
|
|
|
+ LinkedHashMap<String ,Object> t = new LinkedHashMap<>();
|
|
|
|
+ SaleStatement saleStatement = new SaleStatement();
|
|
|
|
+ saleStatement.setProductId(product.getId());
|
|
|
|
+ saleStatement.setShopId(dbOrders.getStoreId());
|
|
|
|
+ saleStatement.setAmount(product.getAmount());
|
|
|
|
+ saleStatement.setCount(product.getCount());
|
|
|
|
+ saleStatement.setTimeOver(DateUtil.now());
|
|
|
|
+ saleStatementService.add(saleStatement);
|
|
|
|
+ });
|
|
|
|
+ // 一种产品一个报表
|
|
|
|
+// orderProductsLists.forEach(productMap -> {
|
|
|
|
+// Product product = (Product) productMap; // 进行类型转换
|
|
|
|
+// SaleStatement saleStatement = new SaleStatement();
|
|
|
|
+// saleStatement.setProductId(product.getId());
|
|
|
|
+// saleStatement.setShopId(orders.getStoreId());
|
|
|
|
+// saleStatement.setAmount(product.getAmount());
|
|
|
|
+// saleStatement.setCount(product.getCount());
|
|
|
|
+// saleStatement.setTimeOver(DateUtil.now());
|
|
|
|
+// saleStatementService.add(saleStatement);
|
|
|
|
+// });
|
|
|
|
+
|
|
return Result.success(ordersService.selectById(orders.getId()));
|
|
return Result.success(ordersService.selectById(orders.getId()));
|
|
}
|
|
}
|
|
|
|
|