網(wǎng)站運營與管理的目的是合肥網(wǎng)絡推廣公司
需求分析和設計
1.1.1 產(chǎn)品原型
進到蒼穹外賣后臺,顯示餐廳的營業(yè)狀態(tài),營業(yè)狀態(tài)分為營業(yè)中和打烊中,若當前餐廳處于營業(yè)狀態(tài),自動接收任何訂單,客戶可在小程序進行下單操作;若當前餐廳處于打烊狀態(tài),不接受任何訂單,客戶便無法在小程序進行下單操作。
點擊營業(yè)狀態(tài)按鈕時,彈出更改營業(yè)狀態(tài)
選擇營業(yè),設置餐廳為營業(yè)中狀態(tài)
選擇打烊,設置餐廳為打烊中狀態(tài)
1.1.2 接口設計
根據(jù)上述原型圖設計接口,共包含3個接口。
接口設計:
- 設置營業(yè)狀態(tài)
- 管理端查詢營業(yè)狀態(tài)
- 用戶端查詢營業(yè)狀態(tài)
**注:**從技術(shù)層面分析,其實管理端和用戶端查詢營業(yè)狀態(tài)時,可通過一個接口去實現(xiàn)即可。因為營業(yè)狀態(tài)是一致的。但是,本項目約定:
- 管理端發(fā)出的請求,統(tǒng)一使用/admin作為前綴。
- 用戶端發(fā)出的請求,統(tǒng)一使用/user作為前綴。
因為訪問路徑不一致,故分為兩個接口實現(xiàn)。
1.1.3 營業(yè)狀態(tài)存儲方式
雖然,可以通過一張表來存儲營業(yè)狀態(tài)數(shù)據(jù),但整個表中只有一個字段,所以意義不大。
營業(yè)狀態(tài)數(shù)據(jù)存儲方式:基于Redis的字符串來進行存儲
**約定:**1表示營業(yè) 0表示打烊
1.2 代碼開發(fā)
1.2.1 設置營業(yè)狀態(tài)
在sky-server模塊中,創(chuàng)建ShopController.java
根據(jù)接口定義創(chuàng)建ShopController的setStatus設置營業(yè)狀態(tài)方法:
package com.sky.controller.admin;import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "店鋪相關(guān)接口")
@Slf4j
public class ShopController {public static final String KEY = "SHOP_STATUS";@Autowiredprivate RedisTemplate redisTemplate;/*** 設置店鋪的營業(yè)狀態(tài)* @param status* @return*/@PutMapping("/{status}")@ApiOperation("設置店鋪的營業(yè)狀態(tài)")public Result setStatus(@PathVariable Integer status){log.info("設置店鋪的營業(yè)狀態(tài)為:{}",status == 1 ? "營業(yè)中" : "打烊中");redisTemplate.opsForValue().set(KEY,status);return Result.success();}
}
1.2.2 管理端查詢營業(yè)狀態(tài)
根據(jù)接口定義創(chuàng)建ShopController的getStatus查詢營業(yè)狀態(tài)方法:
/*** 獲取店鋪的營業(yè)狀態(tài)* @return*/@GetMapping("/status")@ApiOperation("獲取店鋪的營業(yè)狀態(tài)")public Result<Integer> getStatus(){Integer status = (Integer) redisTemplate.opsForValue().get(KEY);log.info("獲取到店鋪的營業(yè)狀態(tài)為:{}",status == 1 ? "營業(yè)中" : "打烊中");return Result.success(status);}
1.2.3 用戶端查詢營業(yè)狀態(tài)
創(chuàng)建com.sky.controller.user包,在該包下創(chuàng)建ShopController.java
根據(jù)接口定義創(chuàng)建ShopController的getStatus查詢營業(yè)狀態(tài)方法:
package com.sky.controller.user;import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;@RestController("userShopController")
@RequestMapping("/user/shop")
@Api(tags = "店鋪相關(guān)接口")
@Slf4j
public class ShopController {public static final String KEY = "SHOP_STATUS";@Autowiredprivate RedisTemplate redisTemplate;/*** 獲取店鋪的營業(yè)狀態(tài)* @return*/@GetMapping("/status")@ApiOperation("獲取店鋪的營業(yè)狀態(tài)")public Result<Integer> getStatus(){Integer status = (Integer) redisTemplate.opsForValue().get(KEY);log.info("獲取到店鋪的營業(yè)狀態(tài)為:{}",status == 1 ? "營業(yè)中" : "打烊中");return Result.success(status);}
}
``