Skip to content

Commit

Permalink
营业状态设置以及客户端Swagger接口测试配置
Browse files Browse the repository at this point in the history
  • Loading branch information
Q-1515 committed Jul 23, 2022
1 parent f101312 commit afb96f9
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ https://www.aliyundrive.com/s/AnRReoe66dQ
![img.png](img/Swagger.png)

##### **项目效果展示**

###### 管理员展示
![img.png](img/reggie.png)
###### 小程序展示
![img.png](img/小程序.png)
Binary file added img/小程序.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.reggie.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
@Slf4j
public class ReidsConfiguration {

@Bean
public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) {

RedisTemplate redisTemplate = new RedisTemplate();
//设置redis的key序列化器
redisTemplate.setKeySerializer(new StringRedisSerializer());
//设置redis的连接工程
redisTemplate.setConnectionFactory(connectionFactory);
return redisTemplate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,53 @@ protected void addInterceptors(InterceptorRegistry registry) {
}

/**
* @return 配置swagger接口文档对象
* @return 配置swagger管理端接口文档对象
*/
@Bean
public Docket docket() {
log.info("准备生成接口文档");
public Docket docket1() {
log.info("准备生成接口文档...");

ApiInfo apiInfo = new ApiInfoBuilder()
.title("瑞吉外卖项目接口文档")
.version("2.0")
.description("瑞吉外卖项目接口文档")
.build();

Docket docket = new Docket(DocumentationType.SWAGGER_2)
return new Docket(DocumentationType.SWAGGER_2)
.groupName("管理端接口")
.apiInfo(apiInfo)
.select()
//指定生成接口需要扫描的包
.apis(RequestHandlerSelectors.basePackage("com.reggie.controller"))
.apis(RequestHandlerSelectors.basePackage("com.reggie.controller.admin"))
.paths(PathSelectors.any())
.build();
}


/**
* @return 配置swagger用户端接口文档对象
*/
@Bean
public Docket docket2() {
log.info("准备生成接口文档...");

ApiInfo apiInfo = new ApiInfoBuilder()
.title("瑞吉外卖项目接口文档")
.version("2.0")
.description("瑞吉外卖项目接口文档")
.build();

return docket;
return new Docket(DocumentationType.SWAGGER_2)
.groupName("用户端接口")
.apiInfo(apiInfo)
.select()
//指定生成接口需要扫描的包
.apis(RequestHandlerSelectors.basePackage("com.reggie.controller.user"))
.paths(PathSelectors.any())
.build();
}


@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
log.info("开始设置静态资源映射...");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.reggie.controller.admin;

import com.reggie.result.R;
import com.reggie.service.ShopService;
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.web.bind.annotation.*;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Slf4j
@Api(tags = "店铺操作接口")
public class ShopController {

@Autowired
private ShopService shopService;

/**
* 设置营业状态
*
* @return success
*/
@PutMapping("/{status}")
@ApiOperation("设置营业状态")
public R<String> setShopOrStatus(@PathVariable Integer status) {
log.info("设置店铺状态为:{}", status);
shopService.setShopStatus(status);
return R.success("店铺状态更新成功");
}


/**
* 获取营业状态
*
* @return 营业状态
*/
@GetMapping("/status")
@ApiOperation("获取营业状态")
public R<Integer> getShopOrStatus() {
Integer shopStatus = null;
try {
shopStatus = shopService.getShopStatus();
} catch (Exception e) {
e.printStackTrace();
shopStatus = 1;
}
log.info("当前营业状态为{}",shopStatus);
return R.success(shopStatus);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.reggie.controller.user;

import com.reggie.result.R;
import com.reggie.service.ShopService;
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.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("userShopController")
@RequestMapping("/user/shop")
@Slf4j
@Api(tags = "C端-店铺操作接口")
public class ShopController {

@Autowired
private ShopService shopService;

/**
* 获取营业状态
*
* @return 营业状态
*/
@GetMapping("/status")
@ApiOperation("获取营业状态")
public R<Integer> getShopOrStatus() {
Integer shopStatus = null;

try {
shopStatus = shopService.getShopStatus();
} catch (Exception e) {
e.printStackTrace();
shopStatus = 1;
}
log.info("当前营业状态为{}", shopStatus);
return R.success(shopStatus);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import java.util.List;

/**
* 分类操作
*/
public interface CategoryService {
//新增分类
void save(CategoryDTO categoryDTO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import java.util.List;

/**
* 菜品操作
*/
public interface DishService {

//添加菜品
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import com.reggie.entity.Employee;
import com.reggie.result.PageResult;

/**
* 员工操作
*/
public interface EmployeeService {
//员工登录
Employee login(EmployeeLoginDTO employeeLoginDTO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import java.util.List;

/**
* 套餐操作
*/
public interface SetmealService {

//新增套餐
Expand Down
14 changes: 14 additions & 0 deletions reggie_server/src/main/java/com/reggie/service/ShopService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.reggie.service;

/**
* 店铺操作
*/
public interface ShopService {

//设置店铺的营业状态 1为营业 0为打样
public void setShopStatus(Integer status);

//获取店铺的营业状态
public Integer getShopStatus();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.reggie.service.impl;

import com.reggie.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class ShopServiceImpl implements ShopService {

public static final String KEY = "SHOP:STATUS";

@Autowired
private RedisTemplate redisTemplate;


/**
* 设置店铺的营业状态 1为营业 0为打烊
*
* @param status 营业状态
*/
public void setShopStatus(Integer status) {
redisTemplate.opsForValue().set(KEY, status);
log.info("设置店铺营业状态为:{}", status == 1 ? "营业" : "打烊");
}

/**
* 获取店铺的营业状态
*
* @return 店铺的营业状态
*/
public Integer getShopStatus() {
return (Integer) redisTemplate.opsForValue().get(KEY);
}
}
6 changes: 6 additions & 0 deletions reggie_server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ spring:
username: ${reggie.datasource.username}
password: ${reggie.datasource.password}

redis:
host: ${reggie.redis.host}
port: ${reggie.redis.port}
database: ${reggie.redis.database}
password: ${reggie.redis.password}

mybatis:
#mapper配置文件
mapper-locations: classpath:mapper/*.xml
Expand Down

0 comments on commit afb96f9

Please sign in to comment.