Procházet zdrojové kódy

菜品相关业务和店铺相关设置开发

潘海瑞 před 10 měsíci
rodič
revize
936982897b

+ 23 - 0
sky-server/src/main/java/com/sky/config/RedisConfiguration.java

@@ -0,0 +1,23 @@
+package com.sky.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 RedisConfiguration {
+    @Bean
+    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){
+        log.info("开始创建redis模板对象...");
+        RedisTemplate redisTemplate = new RedisTemplate();
+        //设置redis的连接工厂对象
+        redisTemplate.setConnectionFactory(redisConnectionFactory);
+        //设置redis key 的序列化器
+        redisTemplate.setKeySerializer(new StringRedisSerializer());
+        return redisTemplate;
+    }
+}

+ 20 - 2
sky-server/src/main/java/com/sky/config/WebMvcConfiguration.java

@@ -47,16 +47,34 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
      * @return
      */
     @Bean
-    public Docket docket() {
+    public Docket docket1() {
         ApiInfo apiInfo = new ApiInfoBuilder()
                 .title("苍穹外卖项目接口文档")
                 .version("2.0")
                 .description("苍穹外卖项目接口文档")
                 .build();
         Docket docket = new Docket(DocumentationType.SWAGGER_2)
+                .groupName("管理端接口")
                 .apiInfo(apiInfo)
                 .select()
-                .apis(RequestHandlerSelectors.basePackage("com.sky.controller"))
+                .apis(RequestHandlerSelectors.basePackage("com.sky.controller.admin"))
+                .paths(PathSelectors.any())
+                .build();
+        return docket;
+    }
+
+    @Bean
+    public Docket docket2() {
+        ApiInfo apiInfo = new ApiInfoBuilder()
+                .title("苍穹外卖项目接口文档")
+                .version("2.0")
+                .description("苍穹外卖项目接口文档")
+                .build();
+        Docket docket = new Docket(DocumentationType.SWAGGER_2)
+                .groupName("用户端接口") // 分组
+                .apiInfo(apiInfo)
+                .select()
+                .apis(RequestHandlerSelectors.basePackage("com.sky.controller.user"))
                 .paths(PathSelectors.any())
                 .build();
         return docket;

+ 0 - 4
sky-server/src/main/java/com/sky/controller/SetmealController.java

@@ -1,4 +0,0 @@
-package com.sky.controller;
-
-public class SetmealController {
-}

+ 1 - 1
sky-server/src/main/java/com/sky/controller/CategoryController.java → sky-server/src/main/java/com/sky/controller/admin/CategoryController.java

@@ -1,4 +1,4 @@
-package com.sky.controller;
+package com.sky.controller.admin;
 
 
 import com.sky.dto.CategoryDTO;

+ 1 - 1
sky-server/src/main/java/com/sky/controller/CommonController.java → sky-server/src/main/java/com/sky/controller/admin/CommonController.java

@@ -1,4 +1,4 @@
-package com.sky.controller;
+package com.sky.controller.admin;
 
 import com.sky.result.Result;
 import com.sky.utils.AliOssUtil;

+ 13 - 1
sky-server/src/main/java/com/sky/controller/DishController.java → sky-server/src/main/java/com/sky/controller/admin/DishController.java

@@ -1,7 +1,8 @@
-package com.sky.controller;
+package com.sky.controller.admin;
 
 import com.sky.dto.DishDTO;
 import com.sky.dto.DishPageQueryDTO;
+import com.sky.entity.Dish;
 import com.sky.result.PageResult;
 import com.sky.result.Result;
 import com.sky.service.DishService;
@@ -93,4 +94,15 @@ public class DishController {
         dishService.isSole(status,id);
         return Result.success();
     }
+
+
+    /**
+     * 根据分类id查询菜品
+     * @param categoryId
+     * @return
+     */
+    @GetMapping("/list")
+    public Result<List<Dish>> list(Long categoryId){
+        return Result.success();
+    }
 }

+ 37 - 0
sky-server/src/main/java/com/sky/controller/admin/SetmealController.java

@@ -0,0 +1,37 @@
+package com.sky.controller.admin;
+
+import com.sky.dto.SetmealDTO;
+import com.sky.dto.SetmealPageQueryDTO;
+import com.sky.result.PageResult;
+import com.sky.result.Result;
+import com.sky.service.SetmealService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.annotations.Mapper;
+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
+@RequestMapping("/admin/setmeal")
+@Slf4j
+public class SetmealController {
+    @Autowired
+    private SetmealService setmealService;
+
+    
+    /**
+     * 分页查询
+     * @param setmealPageQueryDTO
+     * @return
+     */
+    @GetMapping("/page")
+    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO){
+        log.info("分页查询:{}",setmealPageQueryDTO);
+        PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);
+        return Result.success(pageResult);
+    }
+}

+ 45 - 0
sky-server/src/main/java/com/sky/controller/admin/ShopController.java

@@ -0,0 +1,45 @@
+package com.sky.controller.admin;
+
+import com.sky.result.Result;
+import io.swagger.annotations.Api;
+import io.swagger.models.auth.In;
+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("adminShopController")
+@RequestMapping("/admin/shop")
+@Api(tags = "店铺相关接口")
+@Slf4j
+public class ShopController {
+
+    public static final String KEY = "SHOP_STATUS";
+
+    @Autowired
+    private RedisTemplate redisTemplate;
+
+    /**
+     * 设置店铺的营业状态
+     * @param status
+     * @return
+     */
+    @PutMapping("/{status}")
+    public Result setStatus(@PathVariable Integer status){
+        log.info("设置店铺的营业状态为:{}",status == 1 ? "营业中" : "打烊中");
+        redisTemplate.opsForValue().set(KEY,status);
+        return Result.success();
+    }
+
+
+    /**
+     * 获取店铺的营业状态
+     * @return
+     */
+    @GetMapping("/status")
+    public Result getStatus(){
+        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
+        log.info("获取店铺的营业状态:{}",status == 1 ? "营业中" : "打烊中");
+        return Result.success(status);
+    }
+}

+ 34 - 0
sky-server/src/main/java/com/sky/controller/user/ShopController.java

@@ -0,0 +1,34 @@
+package com.sky.controller.user;
+
+import com.sky.result.Result;
+import io.swagger.annotations.Api;
+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")//区分bean
+@RequestMapping("/user/shop")
+@Api(tags = "店铺相关接口")
+@Slf4j
+public class ShopController {
+
+    public static final String KEY = "SHOP_STATUS";
+
+    @Autowired
+    private RedisTemplate redisTemplate;
+
+
+
+
+    /**
+     * 获取店铺的营业状态
+     * @return
+     */
+    @GetMapping("/status")
+    public Result getStatus(){
+        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
+        log.info("获取店铺的营业状态:{}",status == 1 ? "营业中" : "打烊中");
+        return Result.success(status);
+    }
+}

+ 9 - 0
sky-server/src/main/java/com/sky/mapper/SetmealMapper.java

@@ -1,5 +1,8 @@
 package com.sky.mapper;
 
+import com.github.pagehelper.Page;
+import com.sky.dto.SetmealPageQueryDTO;
+import com.sky.vo.SetmealVO;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Select;
 
@@ -14,4 +17,10 @@ public interface SetmealMapper {
     @Select("select count(id) from setmeal where category_id = #{categoryId}")
     Integer countByCategoryId(Long id);
 
+    /**
+     * 分页查询
+     * @param setmealPageQueryDTO
+     * @return
+     */
+    Page<SetmealVO> pagequery(SetmealPageQueryDTO setmealPageQueryDTO);
 }

+ 16 - 0
sky-server/src/main/java/com/sky/service/SetmealService.java

@@ -0,0 +1,16 @@
+package com.sky.service;
+
+import com.sky.dto.SetmealPageQueryDTO;
+import com.sky.result.PageResult;
+
+public interface SetmealService {
+    /**
+     * 分页查询
+     * @param setmealPageQueryDTO
+     */
+    PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
+
+
+
+
+}

+ 32 - 0
sky-server/src/main/java/com/sky/service/impl/SetmealServiceImpl.java

@@ -0,0 +1,32 @@
+package com.sky.service.impl;
+
+import com.github.pagehelper.Page;
+import com.github.pagehelper.PageHelper;
+import com.sky.dto.SetmealPageQueryDTO;
+import com.sky.mapper.SetmealMapper;
+import com.sky.result.PageResult;
+import com.sky.service.SetmealService;
+import com.sky.vo.SetmealVO;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+@Slf4j
+public class SetmealServiceImpl implements SetmealService {
+    @Autowired
+    private SetmealMapper setmealMapper;
+
+    /**
+     * 分页查询
+     * @param setmealPageQueryDTO
+     */
+    @Override
+    public PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
+        PageHelper.startPage(setmealPageQueryDTO.getPage(), setmealPageQueryDTO.getPageSize());
+
+        Page<SetmealVO> page = setmealMapper.pagequery(setmealPageQueryDTO);
+
+        return new PageResult(page.getTotal(), page.getResult());
+    }
+}

+ 5 - 0
sky-server/src/main/resources/application-dev.yml

@@ -11,3 +11,8 @@ sky:
     access-key-id: LTAI5tCWqFgcLgYfxoCzNo1J
     access-key-secret: 0tVFd0llLCyj6r3ubO6WZhpIDrmePS
     bucket-name: sky-itcast-p
+  redis:
+    host: localhost
+    port: 6379
+    password: 1234
+    database: 10

+ 5 - 0
sky-server/src/main/resources/application.yml

@@ -12,6 +12,11 @@ spring:
       url: jdbc:mysql://${sky.datasource.host}:${sky.datasource.port}/${sky.datasource.database}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
       username: ${sky.datasource.username}
       password: ${sky.datasource.password}
+  redis:
+    host: ${sky.redis.host}
+    port: ${sky.redis.port}
+    password: ${sky.redis.password}
+    database: ${sky.redis.database}
 
 mybatis:
   #mapper配置文件

+ 9 - 0
sky-server/src/main/resources/mapper/SetmealMapper.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.sky.mapper.SetmealMapper">
+
+    <select id="pagequery" resultType="com.sky.vo.SetmealVO">
+
+    </select>
+</mapper>