From 15b48df58447a18c42485d23355832e77aafd773 Mon Sep 17 00:00:00 2001 From: pjhmizn49 Date: Fri, 13 Dec 2024 14:35:38 +0800 Subject: [PATCH] ADD file via upload --- .../flower/controller/OrderController.java | 694 ++++++++++++++++++ 1 file changed, 694 insertions(+) create mode 100644 flower_back/src/main/java/com/example/flower/controller/OrderController.java diff --git a/flower_back/src/main/java/com/example/flower/controller/OrderController.java b/flower_back/src/main/java/com/example/flower/controller/OrderController.java new file mode 100644 index 0000000..842e2f4 --- /dev/null +++ b/flower_back/src/main/java/com/example/flower/controller/OrderController.java @@ -0,0 +1,694 @@ +package com.example.flower.controller; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.example.flower.entity.*; +import com.example.flower.service.*; +import io.jsonwebtoken.Claims; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.example.flower.unit.JWTUtil; +import org.springframework.web.bind.annotation.*; +import jakarta.annotation.Resource; + +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.util.*; + +@RestController +@RequestMapping("/order") +public class OrderController { + @Resource + private OrderService orderService; + @Resource + private DiscountService discountService; + @Resource + private FlowerService flowerService; + @Resource + private PackService packService; + @Resource + private GiftService giftService; + @Resource + private UserService userService; + + @PostMapping("/list") //orderList获取所有花卉信息列表 + public JSONObject orderList(@RequestHeader String Authorization, @RequestBody JSONObject param){ + JSONObject jsonObject = new JSONObject(); + + if(!JWTUtil.checkToken(Authorization)){ //token认证失败 + JWTUtil.checkTokenFailed(jsonObject); + return jsonObject; + } + + JSONObject jsonObject1 = new JSONObject(); + int page=param.getIntValue("page"); + int page_size=param.getIntValue("page_size"); + + List orderList = orderService.orderList(page,page_size).getList(); + + jsonObject1.put("page_number", orderService.orderList(page,page_size).getPages()); + jsonObject1.put("total", orderService.orderList(page,page_size).getTotal()); + + int size=orderList.size(); + + JSONObject[] objects = new JSONObject[size]; + for(int i = 0;i orderList = orderService.orderListByQuery(page,page_size,order_id).getList(); + + jsonObject1.put("page_number", orderService.orderListByQuery(page,page_size,order_id).getPages()); + jsonObject1.put("total", orderService.orderListByQuery(page,page_size,order_id).getTotal()); + + int size=orderList.size(); + + JSONObject[] objects = new JSONObject[size]; + for(int i = 0;i order_details = orderService.orderDetailFlower(order_id); + int size=order_details.size(); + JSONObject[] jsonObject_flower = new JSONObject[size]; + for(int i=0;i order_details = orderService.orderDetailGift(order_id); + int size=order_details.size(); + JSONObject[] jsonObject_gift = new JSONObject[size]; + for(int i=0;i rankList1 = orderService.order_flower_top3(); + JSONObject[] jsonObject_bottom1 = new JSONObject[rankList1.size()]; + for(int i=0;i rankList2 = orderService.order_class_rank(); + JSONObject[] jsonObject_bottom2 = new JSONObject[rankList2.size()]; + for(int i=0;i orderUserListAll = orderService.orderUserListFlower(page,page_size,user_id).getList(); + + jsonObject1.put("page_number", orderService.orderUserListFlower(page,page_size,user_id).getPages()); + jsonObject1.put("total", orderService.orderUserListFlower(page,page_size,user_id).getTotal()); + + int size=orderUserListAll.size(); + JSONObject[] objects = new JSONObject[size]; + for(int i = 0;i order_details = orderService.orderDetailFlower(order_id); + Flower flower = flowerService.flowerInfo(order_details.get(0).getFlower_id()); + objects[i].put("flower_id",flower.getFlower_id()); + objects[i].put("flower_name",flower.getFlower_name()); + objects[i].put("flower_price",flower.getFlower_price()); + objects[i].put("flower_pic",flower.getFlower_pic()); + objects[i].put("number",order_details.get(0).getNumber()); + + //包装信息 + if(order_details.get(0).getPack_ids() ==null || Objects.equals(order_details.get(0).getPack_ids(), "")){ + objects[i].put("packs",null); + } + else{ + //数组拆分 + String[] pack_ids_string = order_details.get(0).getPack_ids().split(","); + int [] pack_ids_int = new int[pack_ids_string.length]; + for(int k=0;k orderUserListAll = orderService.orderUserListGift(page,page_size,user_id).getList(); + + jsonObject1.put("page_number", orderService.orderUserListGift(page,page_size,user_id).getPages()); + jsonObject1.put("total", orderService.orderUserListGift(page,page_size,user_id).getTotal()); + + int size=orderUserListAll.size(); + JSONObject[] objects = new JSONObject[size]; + for(int i = 0;i order_details = orderService.orderDetailGift(order_id); + Gift gift = giftService.giftInfo(order_details.get(0).getGift_id()); + objects[i].put("gift_id",gift.getGift_id()); + objects[i].put("gift_name",gift.getGift_name()); + objects[i].put("gift_point",gift.getGift_point()); + objects[i].put("gift_pic",gift.getGift_pic()); + objects[i].put("number",order_details.get(0).getNumber()); + } + jsonObject1.put("orders",objects); + + jsonObject.put("code",200 ); + jsonObject.put("msg","成功!" ); + jsonObject.put("data",jsonObject1); + return jsonObject; + } + + @PostMapping("/userDelete") //orderUserDelete用户删除订单(仅不可见) + public JSONObject orderUserDelete(@RequestHeader String Authorization, @RequestBody JSONObject param){ + JSONObject jsonObject = new JSONObject(); + + if(!JWTUtil.checkToken(Authorization)){ //token认证失败 + JWTUtil.checkTokenFailed(jsonObject); + return jsonObject; + } + int flag = orderService.orderUserDelete(param.getIntValue("order_id")); + if(flag==1){ + jsonObject.put("code",200 ); + jsonObject.put("msg","成功!" ); + } + else { + jsonObject.put("code",403 ); + jsonObject.put("msg","删除失败!" ); + } + return jsonObject; + } + + @PostMapping("/userOrderCount") //用户订单统计相关 + public JSONObject userOrderCount(@RequestHeader String Authorization){ + JSONObject jsonObject = new JSONObject(); + + if(!JWTUtil.checkToken(Authorization)){ //token认证失败 + JWTUtil.checkTokenFailed(jsonObject); + return jsonObject; + } + Claims claims = JWTUtil.getBodyByToken(Authorization); + int user_id = (int) claims.get("id"); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("order_send",orderService.orderUserSend(user_id)); + jsonObject1.put("order_receive",orderService.orderUserReceive(user_id)); + jsonObject1.put("order_pay",orderService.orderUserPay(user_id)); + + jsonObject.put("code",200); + jsonObject.put("msg","统计信息成功"); + jsonObject.put("data",jsonObject1); + return jsonObject; + } +} \ No newline at end of file