網(wǎng)站運(yùn)營(yíng)與管理的目的是合肥網(wǎng)絡(luò)推廣公司
需求分析和設(shè)計(jì)
1.1.1 產(chǎn)品原型
進(jìn)到蒼穹外賣(mài)后臺(tái),顯示餐廳的營(yíng)業(yè)狀態(tài),營(yíng)業(yè)狀態(tài)分為營(yíng)業(yè)中和打烊中,若當(dāng)前餐廳處于營(yíng)業(yè)狀態(tài),自動(dòng)接收任何訂單,客戶(hù)可在小程序進(jìn)行下單操作;若當(dāng)前餐廳處于打烊狀態(tài),不接受任何訂單,客戶(hù)便無(wú)法在小程序進(jìn)行下單操作。
點(diǎn)擊營(yíng)業(yè)狀態(tài)按鈕時(shí),彈出更改營(yíng)業(yè)狀態(tài)
選擇營(yíng)業(yè),設(shè)置餐廳為營(yíng)業(yè)中狀態(tài)
選擇打烊,設(shè)置餐廳為打烊中狀態(tài)
1.1.2 接口設(shè)計(jì)
根據(jù)上述原型圖設(shè)計(jì)接口,共包含3個(gè)接口。
接口設(shè)計(jì):
- 設(shè)置營(yíng)業(yè)狀態(tài)
- 管理端查詢(xún)營(yíng)業(yè)狀態(tài)
- 用戶(hù)端查詢(xún)營(yíng)業(yè)狀態(tài)
**注:**從技術(shù)層面分析,其實(shí)管理端和用戶(hù)端查詢(xún)營(yíng)業(yè)狀態(tài)時(shí),可通過(guò)一個(gè)接口去實(shí)現(xiàn)即可。因?yàn)闋I(yíng)業(yè)狀態(tài)是一致的。但是,本項(xiàng)目約定:
- 管理端發(fā)出的請(qǐng)求,統(tǒng)一使用/admin作為前綴。
- 用戶(hù)端發(fā)出的請(qǐng)求,統(tǒng)一使用/user作為前綴。
因?yàn)樵L(fǎng)問(wèn)路徑不一致,故分為兩個(gè)接口實(shí)現(xiàn)。
1.1.3 營(yíng)業(yè)狀態(tài)存儲(chǔ)方式
雖然,可以通過(guò)一張表來(lái)存儲(chǔ)營(yíng)業(yè)狀態(tài)數(shù)據(jù),但整個(gè)表中只有一個(gè)字段,所以意義不大。
營(yíng)業(yè)狀態(tài)數(shù)據(jù)存儲(chǔ)方式:基于Redis的字符串來(lái)進(jìn)行存儲(chǔ)
**約定:**1表示營(yíng)業(yè) 0表示打烊
1.2 代碼開(kāi)發(fā)
1.2.1 設(shè)置營(yíng)業(yè)狀態(tài)
在sky-server模塊中,創(chuàng)建ShopController.java
根據(jù)接口定義創(chuàng)建ShopController的setStatus設(shè)置營(yíng)業(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;/*** 設(shè)置店鋪的營(yíng)業(yè)狀態(tài)* @param status* @return*/@PutMapping("/{status}")@ApiOperation("設(shè)置店鋪的營(yíng)業(yè)狀態(tài)")public Result setStatus(@PathVariable Integer status){log.info("設(shè)置店鋪的營(yíng)業(yè)狀態(tài)為:{}",status == 1 ? "營(yíng)業(yè)中" : "打烊中");redisTemplate.opsForValue().set(KEY,status);return Result.success();}
}
1.2.2 管理端查詢(xún)營(yíng)業(yè)狀態(tài)
根據(jù)接口定義創(chuàng)建ShopController的getStatus查詢(xún)營(yíng)業(yè)狀態(tài)方法:
/*** 獲取店鋪的營(yíng)業(yè)狀態(tài)* @return*/@GetMapping("/status")@ApiOperation("獲取店鋪的營(yíng)業(yè)狀態(tài)")public Result<Integer> getStatus(){Integer status = (Integer) redisTemplate.opsForValue().get(KEY);log.info("獲取到店鋪的營(yíng)業(yè)狀態(tài)為:{}",status == 1 ? "營(yíng)業(yè)中" : "打烊中");return Result.success(status);}
1.2.3 用戶(hù)端查詢(xún)營(yíng)業(yè)狀態(tài)
創(chuàng)建com.sky.controller.user包,在該包下創(chuàng)建ShopController.java
根據(jù)接口定義創(chuàng)建ShopController的getStatus查詢(xún)營(yíng)業(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íng)業(yè)狀態(tài)* @return*/@GetMapping("/status")@ApiOperation("獲取店鋪的營(yíng)業(yè)狀態(tài)")public Result<Integer> getStatus(){Integer status = (Integer) redisTemplate.opsForValue().get(KEY);log.info("獲取到店鋪的營(yíng)業(yè)狀態(tài)為:{}",status == 1 ? "營(yíng)業(yè)中" : "打烊中");return Result.success(status);}
}
``