人工智慧為改變我的日常工作並提高效率做出了貢獻
身為開發人員,當您的時間有限時,建立訂單處理服務有時會讓人感到不知所措。然而,借助 ChatGPT 等人工智慧驅動的開發工具的強大功能,您可以透過產生程式碼、設計實體和逐步解決問題來顯著加快流程。在本文中,我將向您介紹如何使用 ChatGPT 在短短 2 天內建立功能齊全的訂單處理服務,從收集需求到完成。
老實說,對於不同的小任務有很多小線程和提示,我無法將它們總結成一個完整的項目,但總的來說......它幫助了我70 - 80 %。另外,這裡是一些原始程式碼,經過我審閱,可能是手工修改的,所以你可能在我分享的github上找不到這個功能。
第一天:了解要求和設置
第 1 步:收集並明確需求
我做的第一件事就是列出該服務所需的核心功能。以下是我需要的主要功能:
- 用戶註冊:允許用戶使用手機號碼和地址註冊。
- 特許經營位置搜尋:使客戶能夠查看和尋找附近的咖啡特許經營店。
- 下訂單:顧客可以從選單中下單包含多個項目。
- 隊列管理:追蹤客戶在隊列中的位置並提供預期等待時間。
- 取消訂單:顧客可以隨時退出隊列並取消訂單。
第 2 步:使用 ChatGPT 產生 API 端點
我請求 ChatGPT 幫我設計符合需求的 API 結構。這是我使用的第一個提示的範例:
提示:
使用 Spring Boot 為使用者註冊系統建立 API 端點,使用者可以在其中使用自己的姓名、手機號碼和地址進行註冊。
結果: ChatGPT 產生了多個端點:
- POST /users/register:註冊新用戶。
- GET /franchises/nearby:根據緯度和經度找出附近的咖啡特許經營店。
- POST /orders: 下單購買多件商品。
- GET /orders/{orderId}/queue-position:檢查使用者在佇列中的位置。
- DELETE /orders/{orderId}: 取消訂單並退出佇列。
第 3 步:實體設計
對於訂單處理服務,我們需要 User、Franchise、Order、Queue 和 OrderItem 實體。我使用 ChatGPT 來定義這些具有必要欄位的實體。
提示:
為系統設計使用者實體。用戶可以擁有手機號碼、地址和角色(例如 CUSTOMER)。
結果: ChatGPT 使用 JPA 提供了一個簡單的使用者實體:
@Entity public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) private UUID id; @Column(nullable = false, unique = true) private String username; @Column(nullable = false) private String password; private String mobileNumber; private String address; private UserRole role; // CUSTOMER, ADMIN }
我對特許經營、訂單和隊列實體重複了這個過程。
第 2 天:實施業務邏輯
第四步:下單邏輯
設定基本 API 和實體後,我開始實作下單業務邏輯。這是該服務的關鍵部分,因為它需要處理選單中的多個項目並管理佇列位置。
提示:
實現多個商品下訂單的邏輯,其中每個商品都連結到特許經營中的特定菜單。
結果: ChatGPT 指導我設計了一個 OrderService 來處理這個問題。這是實現的一部分:
public Order createOrder(UUID customerId, UUID franchiseId, List<orderitemdto> items) { Order order = new Order(); order.setCustomer(userRepository.findById(customerId).orElseThrow()); order.setFranchise(franchiseRepository.findById(franchiseId).orElseThrow()); List<orderitem> orderItems = items.stream() .map(itemDto -> new OrderItem(menuItemRepository.findById(itemDto.getMenuItemId()), itemDto.getQuantity())) .collect(Collectors.toList()); order.setItems(orderItems); order.setQueuePosition(findQueuePositionForFranchise(franchiseId)); return orderRepository.save(order); } </orderitem></orderitemdto>
第5步:隊列管理
接下來,我請 ChatGPT 幫我設計將客戶放入隊列並追蹤其位置的邏輯。
提示:
如何計算咖啡加盟系統中訂單的排隊位置和等待時間?
結果: ChatGPT 建議建立一個 QueueService 來追蹤訂單並根據時間戳為其分配位置。我的實作如下:
public int findQueuePositionForFranchise(UUID franchiseId) { List<customerqueue> queue = customerQueueRepository.findAllByFranchiseId(franchiseId); return queue.size() + 1; } </customerqueue>
它還提供了根據平均訂單處理時間估計等待時間的指導。
第 6 步:取消訂單
最後,我實現了允許客戶取消訂單並退出隊列的邏輯:
public void cancelOrder(UUID orderId) { Order order = orderRepository.findById(orderId).orElseThrow(); queueService.removeFromQueue(order.getQueue().getId(), order.getId()); orderRepository.delete(order); }
Finalizing the Project
By the end of Day 2, I had a fully functional service that allowed customers to:
- Register using their mobile number and address.
- View nearby franchises.
- Place orders with multiple items from the menu.
- Check their queue position and waiting time.
- Cancel their order at any time.
Key Takeaways
- Leverage AI for Routine Tasks: ChatGPT sped up repetitive tasks like designing APIs, generating boilerplate code, and implementing common business logic patterns.
- Divide and Conquer: By breaking the project into small, manageable tasks (such as user registration, queue management, and order placement), I was able to implement each feature sequentially.
- AI-Assisted Learning: While ChatGPT provided a lot of code, I still had to understand the underlying logic and tweak it to fit my project’s needs, which was a great learning experience.
- Real-Time Debugging: ChatGPT helped me solve real-time issues by guiding me through errors and exceptions I encountered during implementation, which kept the project on track.
I have a few more steps to create the documentation, use liquidbase and have chatGPT generate sample data for easier testing.
Conclusion
Building an order processing system for a coffee shop in 2 days may sound daunting, but with AI assistance, it’s achievable. ChatGPT acted like a coding assistant, helping me transform abstract requirements into a working system quickly. While AI can provide a foundation, refining and customizing code is still an essential skill. This project taught me how to maximize the value of AI tools without losing control of the development process.
By following the steps I took, you can speed up your own projects and focus on higher-level problem-solving, leaving the routine code generation and guidance to AI.
Full source Github
以上是使用 ChatGPT 建立訂單處理服務(貢獻努力)並已完成的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本文討論了使用咖啡因和Guava緩存在Java中實施多層緩存以提高應用程序性能。它涵蓋設置,集成和績效優勢,以及配置和驅逐政策管理最佳PRA

Java的類上載涉及使用帶有引導,擴展程序和應用程序類負載器的分層系統加載,鏈接和初始化類。父代授權模型確保首先加載核心類別,從而影響自定義類LOA

本文使用lambda表達式,流API,方法參考和可選探索將功能編程集成到Java中。 它突出顯示了通過簡潔性和不變性改善代碼可讀性和可維護性等好處

本文討論了使用JPA進行對象相關映射,並具有高級功能,例如緩存和懶惰加載。它涵蓋了設置,實體映射和優化性能的最佳實踐,同時突出潛在的陷阱。[159個字符]

本文討論了使用Maven和Gradle進行Java項目管理,構建自動化和依賴性解決方案,以比較其方法和優化策略。

本文使用選擇器和頻道使用單個線程有效地處理多個連接的Java的NIO API,用於非阻滯I/O。 它詳細介紹了過程,好處(可伸縮性,性能)和潛在的陷阱(複雜性,

本文使用Maven和Gradle之類的工具討論了具有適當的版本控制和依賴關係管理的自定義Java庫(JAR文件)的創建和使用。

本文詳細介紹了用於網絡通信的Java的套接字API,涵蓋了客戶服務器設置,數據處理和關鍵考慮因素,例如資源管理,錯誤處理和安全性。 它還探索了性能優化技術,我


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

Dreamweaver Mac版
視覺化網頁開發工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),