zhaoyuyan_server

branch_zhaoyuyan
YOUR_USERNAME 7 months ago committed by wdt
parent 46a6a42652
commit cb6babc47d

@ -0,0 +1,132 @@
package com.sky.config;
import com.sky.interceptor.JwtTokenAdminInterceptor;
import com.sky.interceptor.JwtTokenUserInterceptor;
import com.sky.json.JacksonObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import java.util.List;
/**
* WebMvcConfigurationweb
* WebMvcConfigurationSupportSpringSpring MVC
* WebWebHTTP
*/
@Configuration
@Slf4j
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
/**
* JwtTokenAdminInterceptor
*
*/
@Autowired
private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;
/**
* JwtTokenUserInterceptor
* 访访
*/
@Autowired
private JwtTokenUserInterceptor jwtTokenUserInterceptor;
/**
* InterceptorRegistry
*
*
* @param registry
*/
protected void addInterceptors(InterceptorRegistry registry) {
log.info("开始注册自定义拦截器...");
// 为管理员拦截器添加拦截路径规则,对以"/admin/"开头的所有路径进行拦截,意味着这些路径下的请求在到达具体的处理方法之前,会先经过这个拦截器进行相关处理。
// 同时排除"/admin/employee/login"路径,即该登录接口不进行拦截,方便管理员进行登录操作,避免登录请求也被拦截导致无法正常登录的情况。
registry.addInterceptor(jwtTokenAdminInterceptor)
.addPathPatterns("/admin/**")
.excludePathPatterns("/admin/employee/login");
// 为用户拦截器添加拦截路径规则,对以"/user/"开头的所有路径进行拦截,使得普通用户相关请求先经过此拦截器验证等操作。
// 排除"/user/user/login"路径,保障普通用户的登录接口能正常访问不受拦截;同时排除"/user/shop/status"路径,该路径对应的功能可能不需要拦截验证等情况,具体根据业务需求而定。
registry.addInterceptor(jwtTokenUserInterceptor)
.addPathPatterns("/user/**")
.excludePathPatterns("/user/user/login")
.excludePathPatterns("/user/shop/status");
}
/**
* knife4jSwagger 2
* Docket
*
* @return Docketknife4j
*/
@Bean
public Docket docket() {
// 创建ApiInfo对象用于设置接口文档的标题、版本以及描述等基本信息这些信息会展示在接口文档页面的头部等位置方便使用者了解接口文档的整体情况。
ApiInfo apiInfo = new ApiInfoBuilder()
.title("接口文档")
.version("2.0")
.description("接口文档")
.build();
// 创建Docket对象指定文档类型为DocumentationType.SWAGGER_2即基于Swagger 2规范来生成文档并设置之前构建好的ApiInfo对象包含了文档的基本描述信息。
// 通过.select()方法开始配置选择哪些接口要生成文档,先指定要扫描的接口所在的基础包路径(这里是"com.sky.controller",意味着该包及其子包下的符合条件的接口会被扫描到),
// 然后通过.paths(PathSelectors.any())表示只要是符合前面包路径下的任何路径对应的接口都会被包含进文档中最后构建出完整的Docket对象。
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo)
.select()
.apis(RequestHandlerSelectors.basePackage("com.sky.controller"))
.paths(PathSelectors.any())
.build();
return docket;
}
/**
* addResourceHandlers
* 使Web访HTMLJavaScriptCSS
*
* @param registry
*/
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
// 将请求路径"/doc.html"映射到类路径下的"/META-INF/resources/"目录通常用于将接口文档相关的HTML页面等资源正确映射以便在访问该路径时能展示对应的接口文档页面。
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
// 将以"/webjars/**"开头的请求路径映射到类路径下的"/META-INF/resources/webjars/"目录,"webjars"一般用于管理Web项目中的前端依赖库等静态资源通过这样的映射确保这些资源能被正确访问和使用。
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
super.addResourceHandlers(registry);
}
/**
* spring MVCSpring MVC
* 使JSONJava
*
* @param converters Spring MVC
*/
protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
log.info("扩展消息转换器....");
// 创建一个MappingJackson2HttpMessageConverter类型的消息转换器对象它是Spring框架中用于处理JSON数据与Java对象转换的常用消息转换器基于Jackson库实现。
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
// 需要为这个消息转化器设置一个对象转换器这里使用自定义的JacksonObjectMapper它继承自ObjectMapper并且配置了一些特定的序列化和反序列化规则
// 比如对日期时间类型等的处理方式通过设置它可以让消息转换器按照项目的特定需求将Java对象准确地序列化为JSON数据以及将接收到的JSON数据反序列化为Java对象。
converter.setObjectMapper(new JacksonObjectMapper());
// 将自己创建并配置好的消息转换器添加到容器中即原有的消息转换器列表里添加到索引为0的位置确保它在处理消息转换时能优先被使用按照自定义的规则进行数据转换操作。
converters.add(0, converter);
}
}

@ -0,0 +1,186 @@
package com.sky.controller.admin;
import com.github.pagehelper.Page;
import com.sky.dto.CategoryDTO;
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;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
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.cache.annotation.CachePut;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;
/**
* DishControllerSpring MVCHTTP
* DishService使RedisTemplate
* 便便
*/
@RestController()
@RequestMapping("/admin/dish")
@Slf4j
@Api("菜品相关接口")
public class DishController {
/**
* DishService
* DishService
*/
@Autowired
DishService dishService;
/**
* RedisTemplateRedis
* RedisTemplate
*/
@Autowired
RedisTemplate redisTemplate;
/**
* DishPageQueryDTO
* DishServicepageQueryPageResult便
*
* @param dishPageQueryDTO
* @return ResultPageResultResultPageResult
*/
@GetMapping("/page")
@ApiOperation("菜品分页查询")
public Result<PageResult> pageQuery(DishPageQueryDTO dishPageQueryDTO) {
log.info("菜品分页查询:{}", dishPageQueryDTO);
PageResult pageResult = dishService.pageQuery(dishPageQueryDTO);
return Result.success(pageResult);
}
/**
* DishDTOJSON@RequestBody
* DishServicesaveWithFlavercleanCache
* Result
*
* @param dishDTO
* @return ResultResult
*/
@PostMapping
@ApiOperation("新增菜品")
public Result save(@RequestBody DishDTO dishDTO) {
log.info("新增菜品:{}", dishDTO);
dishService.saveWithFlaver(dishDTO);
cleanCache("dish_"+dishDTO.getCategoryId());
return Result.success();
}
/**
* idArrayList<Long>@RequestParam使
* idDishServicedeleteBatchcleanCache使"dish_*"
* Result
*
* @param ids id
* @return ResultResult
*/
@DeleteMapping
@ApiOperation("批量删除菜品")
public Result deleteBatch(@RequestParam ArrayList<Long> ids) {
log.info("批量删除菜品:{}", ids);
dishService.deleteBatch(ids);
cleanCache("dish_*");
return Result.success();
}
/**
* idid@PathVariable
* idDishServicegetByIdDishVOResult便
*
* @param id id
* @return ResultDishVOResultDishVO
*/
@GetMapping("/{id}")
public Result<DishVO> getByDishId(@PathVariable Long id) {
log.info("根据id获取菜品:{}", id);
DishVO dish = dishService.getById(id);
return Result.success(dish);
}
/**
* DishDTOJSON@RequestBody
* DishServiceupdateDishcleanCache使"dish_*"
* Result
*
* @param dishDTO
* @return ResultResult
*/
@PutMapping()
@ApiOperation("修改菜品")
public Result updateDish(@RequestBody DishDTO dishDTO) {
log.info("修改菜品:{}", dishDTO);
dishService.updateDish(dishDTO);
cleanCache("dish_*");
return Result.success();
}
/**
* idid
* idDishServicegetByCategoryIdArrayList<Dish>Result
* 便
*
* @param categoryId id
* @return ResultArrayListResultArrayList
*/
@GetMapping("/list")
@ApiOperation("根据分类id查询菜品")
public Result<ArrayList> getByCategoryId(Long categoryId) {
log.info("根据分类id查询菜品");
ArrayList<Dish> dishes = dishService.getByCategoryId(categoryId);
return Result.success(dishes);
}
/**
* id@PathVariableid
* DishServicestartOrStopcleanCache使"dish_*"
* 使@CachePut
* Result
*
* @param id id
* @param status 10
* @return ResultResult
*/
@CachePut
@PostMapping("/status/{status}")
public Result startOrStop(Long id, @PathVariable Integer status) {
log.info("起售停售菜品id:{},status:{}", id, status);
dishService.startOrStop(id, status);
cleanCache("dish_*");
return Result.success();
}
/**
* RedisRedisTemplatekeys使"dish_*""dish_"
* 使RedisTemplatedelete
*
* @param pattern 使
*/
private void cleanCache(String pattern) {
Set keys = redisTemplate.keys(pattern);
redisTemplate.delete(keys);
}
}

@ -0,0 +1,149 @@
package com.sky.controller.admin;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
/**
* SetmealControllerSpring MVCHTTP
* SetmealServiceid
* Spring@CacheEvict便
*/
@RestController
@Api("套餐相关接口")
@Slf4j
@RequestMapping("/admin/setmeal")
public class SetmealController {
/**
* SetmealServiceSetmealService
*
*/
@Autowired
SetmealService setmealService;
/**
* SetmealPageQueryDTO
* SetmealServicepageQuery
* PageResultResult便
*
* @param setmealPageQueryDTO 便
* @return ResultPageResultResultPageResult
*/
@GetMapping("/page")
@ApiOperation("分页查询套餐")
public Result<PageResult> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
log.info("分页查询套餐:{}", setmealPageQueryDTO);
PageResult result = setmealService.pageQuery(setmealPageQueryDTO);
return Result.success(result);
}
/**
* @PathVariable10
* idSetmealServicestartOrStop
* 使@CacheEvict"setmealCache"allEntriestrue
* Result
*
* @param status 便
* @param id id
* @return ResultResult
*/
@PostMapping("/status/{status}")
@ApiOperation("起售停售套餐")
@CacheEvict(cacheNames = "setmealCache", allEntries = true)
public Result startOrStop(@PathVariable Integer status, Long id) {
log.info("{}套餐id={}", status == 1? "起售" : "停售", id);
setmealService.startOrStop(status, id);
return Result.success();
}
/**
* SetmealDTOJSON@RequestBody
* SetmealServiceupdateSetmeal使@CacheEvict"setmealCache"allEntriestrue
* Result
*
* @param setmealDTO
* @return ResultResult
*/
@PutMapping
@ApiOperation("修改套餐信息")
@CacheEvict(cacheNames = "setmealCache", allEntries = true)
public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO) {
log.info("修改套餐信息:{}", setmealDTO);
setmealService.updateSetmeal(setmealDTO);
return Result.success();
}
/**
* idid@PathVariable
* idSetmealServicegetDishByIdSetmealVO
* Result便
*
* @param id id
* @return ResultSetmealVOResultSetmealVO
*/
@GetMapping("/{id}")
@ApiOperation("根据id查询套餐")
public Result<SetmealVO> getDishById(@PathVariable Long id) {
log.info("根据套餐id查询套餐");
SetmealVO setmealVO = setmealService.getDishById(id);
return Result.success(setmealVO);
}
/**
* ididArrayList<Long>@RequestParam使
* idSetmealServicebatchDeleteById使@CacheEvict"setmealCache"allEntriestrue
* Result
*
* @param ids id
* @return ResultResult
*/
@DeleteMapping
@ApiOperation("根据id批量删除套餐")
@CacheEvict(cacheNames = "setmealCache", allEntries = true)
public Result batchDeleteById(@RequestParam ArrayList<Long> ids) {
log.info("根据id批量删除套餐:{}", ids);
setmealService.batchDeleteById(ids);
return Result.success();
}
/**
* SetmealDTOJSON@RequestBody
* SetmealServiceinsert使@CacheEvictSetmealDTOcategoryId
* Result
*
* @param setmealDTO categoryId
* @return ResultResult
*/
@CacheEvict(cacheNames = "setmealCache", key = "#setmealDTO.categoryId")
@PostMapping
@ApiOperation("新增套餐")
public Result insert(@RequestBody SetmealDTO setmealDTO) {
log.info("新增套餐:{}", setmealDTO);
setmealService.insert(setmealDTO);
return Result.success();
}
}

@ -0,0 +1,149 @@
package com.sky.controller.user;
import com.sky.context.BaseContext;
import com.sky.entity.AddressBook;
import com.sky.result.Result;
import com.sky.service.AddressBookService;
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.*;
import java.util.List;
/**
* AddressBookControllerSpring MVCC簿HTTP
* AddressBookServiceid//
* 便簿便使
*/
@RestController
@RequestMapping("/user/addressBook")
@Api(tags = "C端地址簿接口")
@Slf4j
public class AddressBookController {
/**
* AddressBookServiceAddressBookService簿
* 簿
*/
@Autowired
private AddressBookService addressBookService;
/**
* AddressBook
* BaseContext.getCurrentId()BaseContextididAddressBook
* AddressBookServicelistList<AddressBook>Result
* 便
*
* @return ResultList<AddressBook>ResultList<AddressBook>
*/
@GetMapping("/list")
@ApiOperation("查询当前登录用户的所有地址信息")
public Result<List<AddressBook>> list() {
log.info("查询当前登录用户的所有地址信息");
AddressBook addressBook = new AddressBook();
addressBook.setUserId(BaseContext.getCurrentId());
List<AddressBook> list = addressBookService.list(addressBook);
return Result.success(list);
}
/**
* AddressBookJSON@RequestBody
* AddressBookServicesaveResult便
*
* @param addressBook
* @return ResultResult
*/
@PostMapping
@ApiOperation("新增地址")
public Result save(@RequestBody AddressBook addressBook) {
log.info("新增地址:{}", addressBook);
addressBookService.save(addressBook);
return Result.success();
}
/**
* idid@PathVariable
* idAddressBookServicegetByIdAddressBook
* Result便使
*
* @param id id
* @return ResultAddressBookResultAddressBook
*/
@GetMapping("/{id}")
@ApiOperation("根据id查询地址")
public Result<AddressBook> getById(@PathVariable Long id) {
log.info("根据id查询地址,id:{}", id);
AddressBook addressBook = addressBookService.getById(id);
return Result.success(addressBook);
}
/**
* idAddressBookJSON@RequestBody
* AddressBookServiceupdateResult便
*
* @param addressBook
* @return ResultResult
*/
@PutMapping
@ApiOperation("根据id修改地址")
public Result update(@RequestBody AddressBook addressBook) {
log.info("根据id修改地址:{}", addressBook);
addressBookService.update(addressBook);
return Result.success();
}
/**
* AddressBookJSON@RequestBody
* AddressBookServicesetDefaultAddressBookService
* Result便便使
*
* @param addressBook id
* @return ResultResult
*/
@PutMapping("/default")
@ApiOperation("设置默认地址")
public Result setDefault(@RequestBody AddressBook addressBook) {
log.info("设置默认地址:{}", addressBook);
addressBookService.setDefault(addressBook);
return Result.success();
}
/**
* idid
* idAddressBookServicedeleteByIdResult便
*
* @param id id
* @return ResultidResult
*/
@DeleteMapping
@ApiOperation("根据id删除地址")
public Result deleteById(Long id) {
log.info("根据id删除地址,id:{}", id);
addressBookService.deleteById(id);
return Result.success();
}
/**
* AddressBookisDefault1BaseContext.getCurrentId()idAddressBook
* AddressBookServicelistResult
* Result便使
*/
@GetMapping("default")
@ApiOperation("查询默认地址")
public Result<AddressBook> getDefault() {
log.info("查询默认地址");
// SQL:select * from address_book where user_id =? and is_default = 1
AddressBook addressBook = new AddressBook();
addressBook.setIsDefault(1);
addressBook.setUserId(BaseContext.getCurrentId());
List<AddressBook> list = addressBookService.list(addressBook);
if (list!= null && list.size() == 1) {
return Result.success(list.get(0));
}
return Result.error("没有查询到默认地址");
}
}

@ -0,0 +1,81 @@
package com.sky.controller.user;
import com.sky.constant.StatusConstant;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
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.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* SetmealControllerSpring MVCCHTTP
* SetmealServiceidid
* Spring@Cacheable便便
*/
@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Api(tags = "C端-套餐浏览接口")
@Slf4j
public class SetmealController {
/**
* SetmealServiceSetmealService
*
*/
@Autowired
private SetmealService setmealService;
/**
* idid
* SetmealidStatusConstant.ENABLE
* SetmealSetmealServicelistList<Setmeal>Result
* 便
* 使@Cacheable"setmealCache"idid
*
* @param categoryId id便
* @return ResultList<Setmeal>ResultList<Setmeal>
*/
@GetMapping("/list")
@ApiOperation("根据分类id查询起售套餐")
@Cacheable(cacheNames = "setmealCache", key = "#categoryId")
public Result<List<Setmeal>> list(Long categoryId) {
log.info("根据分类id查询起售套餐:{}", categoryId);
Setmeal setmeal = new Setmeal();
setmeal.setCategoryId(categoryId);
setmeal.setStatus(StatusConstant.ENABLE);
List<Setmeal> list = setmealService.list(setmeal);
return Result.success(list);
}
/**
* idid@PathVariable"id"
* idSetmealServicegetDishItemByIdList<DishItemVO>
* Result便使
*
* @param id id
* @return ResultList<DishItemVO>ResultList<DishItemVO>
*/
@GetMapping("/dish/{id}")
@ApiOperation("根据套餐id查询包含的菜品列表")
public Result<List<DishItemVO>> dishList(@PathVariable("id") Long id) {
log.info("根据套餐id查询包含的菜品列表{}", id);
List<DishItemVO> list = setmealService.getDishItemById(id);
return Result.success(list);
}
}

@ -0,0 +1,61 @@
package com.sky.handler;
import com.sky.constant.MessageConstant;
import com.sky.exception.BaseException;
import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.sql.SQLIntegrityConstraintViolationException;
/**
* GlobalExceptionHandler
* 使Spring@RestControllerAdvice使@RestController
*
*/
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
/**
* 使@ExceptionHandlerBaseException
* BaseException
* ResultResult.errorResult
* 使
*
* @param ex BaseException
* @return Result便
*/
@ExceptionHandler(BaseException.class)
public Result exceptionHandler(BaseException ex) {
log.error("异常信息:{}", ex.getMessage());
return Result.error(ex.getMessage());
}
/**
* SQL使@ExceptionHandlerSQLIntegrityConstraintViolationException
* SQLIntegrityConstraintViolationException
*
* "Duplicate entry"
* MessageConstant.ALREADY_EXISTS
* MessageConstant.UNKNOWN_ERRORResultMessageConstant.ALREADY_EXISTS
*
*
* @param exception SQLIntegrityConstraintViolationException
* @return ResultSQL便
*/
@ExceptionHandler
public Result SQLExceptionHandler(SQLIntegrityConstraintViolationException exception) {
System.out.println(exception);
String msg = exception.getMessage();
String[] split = msg.split(" ");
if (msg.contains("Duplicate entry")) {
String name = split[2];
log.error("异常信息:{}", name + MessageConstant.ALREADY_EXISTS);
} else {
log.error("异常信息:{}", MessageConstant.UNKNOWN_ERROR);
}
return Result.error(MessageConstant.ALREADY_EXISTS);
}
}

@ -0,0 +1,78 @@
package com.sky.mapper;
import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import com.sky.result.PageResult;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.aspectj.weaver.ast.Or;
import java.util.List;
/**
* CategoryMapperMyBatisCategory
* MyBatis
* MyBatisSQL便
*/
@Mapper
public interface CategoryMapper {
/**
* CategoryPageQueryDTO
* MyBatisSQLMyBatisSQLPage<Category>
* Page<Category>便
*
* @param categoryPageQueryDTO 便
* @return Page<Category>Category
*/
Page<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
/**
* CategoryDTOCategoryDTO
* MyBatisSQLList<Category>
* List<Category>便
*
* @param categoryDTO 便
* @return List<Category>Category
*/
List<Category> query(CategoryDTO categoryDTO);
/**
* idLongMyBatis@DeleteSQL
* "delete from category where id=#{id}"SQLcategoryid
*
*
* @param id idcategory
*/
@Delete("delete from category where id=#{id}")
void delete(Long id);
/**
* Category
* 使@AutoFillOperationType.UPDATE
* MyBatisSQL
*
*
* @param category
*/
@AutoFill(OperationType.UPDATE)
void updateCategory(Category category);
/**
* Category
* 使@AutoFillOperationType.INSERT@Insert
* @InsertSQLSQLCategorycategory
*
*
* @param category SQLcategory
*/
@AutoFill(OperationType.INSERT)
@Insert("insert into category(type,name,sort,status,create_time,create_user,update_time,update_user)" +
"values (#{type},#{name},#{sort},#{status},#{createTime},#{createUser},#{updateTime},#{updateUser})")
void save(Category category);
}

@ -0,0 +1,125 @@
package com.sky.mapper;
import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
/**
* OrderMapperMyBatisOrders
* MyBatisSQL
*
*/
@Mapper
public interface OrderMapper {
/**
* 使@SelectSQLordersstatus
* Integerstatus"select count(id) from orders where status = #{status}"SQL
* Integer便
*
* @param status 01
* @return Integer便
*/
@Select("select count(id) from orders where status = #{status}")
Integer countStatus(Integer status) ;
/**
* OrdersPageQueryDTO
* MyBatisSQLOrdersPageQueryDTOSQLPage<Orders>
* Page<Orders>便便
*
* @param ordersPageQueryDTO 便
* @return Page<Orders>Orders
*/
Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);
/**
* Orders
* MyBatisSQLOrders@InsertSQLMyBatis
* Ordersorders
*
* @param orders MyBatisorders
*/
void insert(Orders orders);
/**
* 使@SelectSQLordersorderNumber
* StringorderNumber"select * from orders where number = #{orderNumber}"SQL
* Orders
*
* @param orderNumber orders
* @return Orders
*/
@Select("select * from orders where number = #{orderNumber}")
Orders getByNumber(String orderNumber);
/**
* Orders
* MyBatisSQL
*
*
* @param orders
*/
void update(Orders orders);
/**
* IntegerpendingPayment
* LocalDateTimetimeMyBatis@Param使SQL
* SQLList<Orders>
* 便
*
* @param pendingPayment
* @param time
* @return List<Orders>Orders便
*/
List<Orders> getByStatusAndOrderTimeLT(@Param("pendingPayment") Integer pendingPayment, @Param("time") LocalDateTime time);
/**
* List<Orders>ordersListOrdersid
* IntegerstatusMyBatis@Param使SQL
* SQL
*
* @param ordersList
* @param status ordersList使10
*/
void updateBatchStatus(@Param("ordersList") List<Orders> ordersList, @Param("status") Integer status);
/**
* orderId使@SelectSQLordersidid
* Longid"select * from orders where id=#{id}"SQL
* Ordersidid
*
* @param id orders
* @return Ordersid
*/
@Select("select * from orders where id=#{id}")
Orders getById(Long id);
/**
* MapmapMap
* MyBatis@Param"map"使SQLSQLMapSQL
* Integer便
*
* @param map Map
* @return Integer便
*/
Integer countByMap(@Param("map") Map map);
/**
* MapmapMap
* MyBatis@Param"map"使SQLSQLMapSQL
* Double便
*
* @param map Map
* @return Double便
*/
Double sumByMap(@Param("map") Map map);
}

@ -0,0 +1,59 @@
package com.sky.mapper;
import com.sky.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Map;
/**
* UserMapperMyBatisUser
* openididMyBatisSQL
*
*/
@Mapper
public interface UserMapper {
/**
* openid使@SelectSQLuseropenidopenid
* Stringopenidopenidopenid使
* "select * from user where openid=#{openid}"SQLUseropenid
* openid
*
* @param openid user
* @return Useropenid
*/
@Select("select * from user where openid=#{openid}")
User getByOpenId(String openid);
/**
* User
* MyBatisSQL@InsertSQLMyBatis
* Useruser
*
* @param user MyBatisuser
*/
void insertUser(User user);
/**
* id使@SelectSQLuseriduserId
* LonguserId"select * from user where id=#{userId}"SQL
* Useridid
*
* @param userId user
* @return Userid
*/
@Select("select * from user where id=#{userId}")
User getById(Long userId);
/**
* MapmapMap
* MyBatis@Param"map"使SQLSQLMapSQL
* Integer便
*
* @param map Map
* @return Integer便
*/
Integer countByMap(@Param("map") Map map);
}

@ -0,0 +1,63 @@
package com.sky.service;
import com.sky.entity.AddressBook;
import java.util.List;
/**
* AddressBookService簿AddressBook
* 簿使
* 簿便
*/
public interface AddressBookService {
/**
* AddressBookid簿
* List<AddressBook>AddressBook
* 便使
*
* @param addressBook 簿id
* @return List<AddressBook>簿AddressBook簿
*/
List<AddressBook> list(AddressBook addressBook);
/**
* AddressBook
* 簿
*
* @param addressBook 簿
*/
void save(AddressBook addressBook);
/**
* idLongidAddressBook
* 便使
*
* @param id id簿
* @return AddressBookid
*/
AddressBook getById(Long id);
/**
* AddressBook
* id
*
* @param addressBook
*/
void update(AddressBook addressBook);
/**
* AddressBookid
* 簿便便使
*
* @param addressBook id
*/
void setDefault(AddressBook addressBook);
/**
* idLongid簿id
*
*
* @param id id簿
*/
void deleteById(Long id);
}

@ -0,0 +1,70 @@
package com.sky.service;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeeLoginDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Employee;
import com.sky.result.PageResult;
/**
* EmployeeServiceEmployee
* 使
* 便id
*/
public interface EmployeeService {
/**
* EmployeeLoginDTO
* Employee
*
*
* @param employeeLoginDTO
* @return Employeenull
*/
Employee login(EmployeeLoginDTO employeeLoginDTO);
/**
* EmployeeDTO
*
*
* @param employeeDTO
*/
void save(EmployeeDTO employeeDTO);
/**
* EmployeePageQueryDTO
* PageResultPageResult
* 便
*
* @param employeePageQueryDTO 便
* @return PageResulttotalrecords便
*/
PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO);
/**
* Integerstatus10
* Longididid
* 使使
*
* @param status
* @param id id
*/
void startOrStop(Integer status, Long id);
/**
* idLongid
* idEmployee
* 便使
*
* @param id id
*/
Employee getById(Long id);
/**
* EmployeeDTO
* id
*
* @param employeeDTO
*/
void update(EmployeeDTO employeeDTO);
}

@ -0,0 +1,43 @@
package com.sky.service;
import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import java.util.List;
/**
* ShoppingCartServiceShoppingCart
* 使
* 便
*/
public interface ShoppingCartService {
/**
* ShoppingCartDTOidid
*
*
* @param shoppingCartDTO idid
*/
void add(ShoppingCartDTO shoppingCartDTO);
/**
* id
* List<ShoppingCart>ShoppingCartid便使
*
* @return List<ShoppingCart>ShoppingCart
*/
List<ShoppingCart> list();
/**
* ShoppingCartDTOidid
*
*
* @param shoppingCartDTO idid
*/
void delete(ShoppingCartDTO shoppingCartDTO);
/**
* id
* 便
*/
void clean();
}

@ -0,0 +1,221 @@
package com.sky.service.impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.constant.MessageConstant;
import com.sky.constant.StatusConstant;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.exception.DeletionNotAllowedException;
import com.sky.mapper.DishMapper;
import com.sky.result.PageResult;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* DishServiceImplDishServiceDish
* DishMapper访DishMapper
*
*/
@Service
public class DishServiceImpl implements DishService {
/**
* DishMapperDishMapper
*
*/
@Autowired
DishMapper dishMapper;
/**
* DishServicepageQueryDishPageQueryDTO
* DishPageQueryDTOpagepageSizePageHelperMyBatis便
* DishMapperpageQueryPage<Dish>
* Page<Dish>totaldishesPageResultPageResult
* 便
*
* @param dishPageQueryDTO
* @return PageResulttotalrecords便
*/
@Override
public PageResult pageQuery(DishPageQueryDTO dishPageQueryDTO) {
int page = dishPageQueryDTO.getPage();
int pageSize = dishPageQueryDTO.getPageSize();
// 开始分页查询通过PageHelper设置当前页码和每页显示数量后续执行的数据库查询会自动按照此分页设置进行操作
PageHelper.startPage(page, pageSize);
Page<Dish> pageResult = dishMapper.pageQuery(dishPageQueryDTO);
// 取出查询总数即满足查询条件的所有记录数量通过Page对象的getTotal方法获取
long total = pageResult.getTotal();
// 取出查询结果即当前页的菜品数据列表通过Page对象的getResult方法获取
List<Dish> dishes = pageResult.getResult();
// 构建查询结果对象,用于将分页相关的数据按照统一的格式返回给上层调用者
PageResult pageResult1 = new PageResult();
pageResult1.setTotal(total);
pageResult1.setRecords(dishes);
return pageResult1;
}
/**
* 使@Transactional
*
* DishDTODishBeanUtils.copyPropertiesStatusConstant.ENABLE
* DishMappersaveidDishDTOflavors
* idDishMapperinsertBatchFlavors
*
*
* @param dishDTO
*/
@Transactional
public void saveWithFlaver(DishDTO dishDTO) {
// 向菜品表添加一条数据创建一个新的Dish实体对象用于接收从DishDTO拷贝过来的属性值
Dish dish = new Dish();
BeanUtils.copyProperties(dishDTO, dish);
dish.setStatus(StatusConstant.ENABLE);
dishMapper.save(dish);
// 向口味表添加n条数据获取刚插入菜品的id后续用于关联口味与菜品
Long dishId = dish.getId();
List<DishFlavor> flavors = dishDTO.getFlavors();
if (flavors!= null && flavors.size() > 0) {
flavors.forEach(dishFlavor -> {
dishFlavor.setDishId(dishId);
});
dishMapper.insertBatchFlavors(flavors);
}
}
/**
*
* DishMappergetByIdBatchidids
* StatusConstant.ENABLEDeletionNotAllowedExceptionMessageConstant.DISH_ON_SALE
* DishMappercountMealDishid0DeletionNotAllowedExceptionMessageConstant.DISH_BE_RELATED_BY_SETMEAL
* DishMapperdeleteBatchid使
*
* @param ids id
*/
public void deleteBatch(ArrayList<Long> ids) {
// 判断菜品是否在起售,起售期间不能被删除,通过查询数据库获取对应菜品列表,遍历检查状态
ArrayList<Dish> dishs = dishMapper.getByIdBatch(ids);
for (Dish dish : dishs) {
if (dish.getStatus() == StatusConstant.ENABLE) {
throw new DeletionNotAllowedException(MessageConstant.DISH_ON_SALE);
}
}
// 判断菜品是否被套餐绑定,绑定期间不能被删除,通过查询统计与菜品关联的套餐菜品数量来判断
Integer count = dishMapper.countMealDish(ids);
if (count > 0) {
throw new DeletionNotAllowedException(MessageConstant.DISH_BE_RELATED_BY_SETMEAL);
}
dishMapper.deleteBatch(ids);
}
/**
* 使@Transactional
* DishDTODishBeanUtils.copyPropertiesDishDTOflavorsidid
* DishMapperupdateDishDishMapperdeleteBatchFlavorsinsertBatchFlavors
*
*
* @param dishDTO
*/
@Transactional
public void updateDish(DishDTO dishDTO) {
Dish dish = new Dish();
BeanUtils.copyProperties(dishDTO, dish);
List<DishFlavor> flavors = dishDTO.getFlavors();
flavors.forEach(dishFlavor -> {
dishFlavor.setDishId(dish.getId());
});
// 更新菜品,调用数据访问层方法更新菜品基本信息
dishMapper.updateDish(dish);
// 更新菜品对应的口味,先删除原有的口味数据,再插入更新后的口味数据
dishMapper.deleteBatchFlavors(flavors);
dishMapper.insertBatchFlavors(flavors);
}
/**
* idid
* idArrayList<Long>便DishMappergetByIdBatchidid
* DishMappergetFlavorByIdidDishVO
* BeanUtils.copyPropertiesDishVODishVODishVO
* 便
*
* @param id id
* @return DishVO便
*/
public DishVO getById(Long id) {
ArrayList<Long> ids = new ArrayList<>();
ids.add(id);
// 根据id获取菜品调用数据访问层方法获取对应菜品对象
Dish dish = dishMapper.getByIdBatch(ids).get(0);
// 根据菜品id获取该菜品的口味调用数据访问层方法获取菜品对应的口味列表
ArrayList<DishFlavor> dishFlavors = dishMapper.getFlavorById(id);
DishVO dishVO = new DishVO();
BeanUtils.copyProperties(dish, dishVO);
dishVO.setFlavors(dishFlavors);
return dishVO;
}
/**
* idDishMappergetByCategoryIdidnull
* ArrayList<Dish>便
*
*
* @param categoryId id
* @return ArrayList<Dish>idDish
*/
public ArrayList<Dish> getByCategoryId(Long categoryId) {
return dishMapper.getByCategoryId(categoryId, null);
}
/**
* Dishididstatus
* DishMapperupdateDishidDish
* 便
*
* @param id id
* @param status 10
*/
public void startOrStop(Long id, Integer status) {
Dish dish = new Dish();
dish.setStatus(status);
dish.setId(id);
dishMapper.updateDish(dish);
}
/**
* Dishiddish.getCategoryId()dish.getStatus()DishMappergetByCategoryIdArrayList<Dish>
* DishVOBeanUtils.copyPropertiesDishVOidDishMappergetFlavorByIdDishVO
* DishVOArrayList<DishVO>DishVO
* 便
*
* @param dish id

@ -0,0 +1,205 @@
package com.sky.service.impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.constant.MessageConstant;
import com.sky.constant.StatusConstant;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.exception.DeletionNotAllowedException;
import com.sky.mapper.DishMapper;
import com.sky.mapper.SetmealMapper;
import com.sky.result.PageResult;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
/**
* SetmealServiceImplSetmealServiceSetmeal
* SetmealMapperDishMapper
* Mapperid
*/
@Service
@Slf4j
public class SetmealServiceImpl implements SetmealService {
/**
* SetmealMapperSetmealMapper
* id
*/
@Autowired
private SetmealMapper setmealMapper;
/**
* DishMapper
* DishMapper
*/
@Autowired
private DishMapper dishMapper;
/**
* SetmealServicelistSetmealid
* SetmealMapperlistSetmealList<Setmeal>
* 便使
*
* @param setmeal id便
* @return List<Setmeal>Setmeal
*/
public List<Setmeal> list(Setmeal setmeal) {
List<Setmeal> list = setmealMapper.list(setmeal);
return list;
}
/**
* idSetmealServicegetDishItemByIdid
* SetmealMappergetDishItemBySetmealIdidList<DishItemVO>DishItemVO
* 便使
*
* @param id id
* @return List<DishItemVO>DishItemVO
*/
public List<DishItemVO> getDishItemById(Long id) {
return setmealMapper.getDishItemBySetmealId(id);
}
/**
* SetmealPageQueryDTO
* PageHelperMyBatis便PageHelper.startPageSetmealPageQueryDTOpagepageSize
* SetmealMapperpageQueryPage<Setmeal>
* PageResultPage<Setmeal>getTotalgetResultPageResultPageResult
* 便
*
* @param setmealPageQueryDTO
* @return PageResulttotalrecords便
*/
public PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
// 开始分页查询通过PageHelper设置当前页码和每页显示数量后续执行的数据库查询会自动按照此分页设置进行操作
PageHelper.startPage(setmealPageQueryDTO.getPage(), setmealPageQueryDTO.getPageSize());
Page<Setmeal> list = setmealMapper.pageQuery(setmealPageQueryDTO);
// 处理查询结果构建PageResult对象来封装分页相关数据以便统一返回给上层调用者
PageResult pageResult = new PageResult();
pageResult.setTotal(list.getTotal());
pageResult.setRecords(list.getResult());
return pageResult;
}
/**
* Setmealididstatus
* SetmealMapperupdateSetmealidSetmeal
* 便
*
* @param status 10
* @param id id
*/
public void startOrStop(Integer status, Long id) {
Setmeal setmeal = new Setmeal();
setmeal.setStatus(status);
setmeal.setId(id);
// 更改套餐的起售或停售状态,调用数据访问层方法更新套餐在数据库中的状态记录
setmealMapper.updateSetmeal(setmeal);
}
/**
* 使@Transactional
*
* SetmealDTOSetmealBeanUtils.copyPropertiesSetmealMapperupdateSetmeal
* SetmealMapperdeleteSetmealDishidSetmealDTO
* SetmealDTOSetmealDishidSetmealMapperinsertBatchSetmealDish
*
*
* @param setmealDTO
*/
@Transactional
public void updateSetmeal(SetmealDTO setmealDTO) {
Setmeal setmeal = new Setmeal();
BeanUtils.copyProperties(setmealDTO, setmeal);
// 修改套餐信息,调用数据访问层方法更新套餐基本信息
setmealMapper.updateSetmeal(setmeal);
// 修改套餐的菜品信息,先删除原有的套餐菜品关联记录
// 通过套餐id删除绑定在套餐上的菜品
setmealMapper.deleteSetmealDish(setmealDTO.getId());
// 批量插入套餐绑定的菜品获取修改后的套餐菜品关联信息列表设置套餐id后插入到关联表中
List<SetmealDish> dishes = setmealDTO.getSetmealDishes();
dishes.forEach(setmealDish -> setmealDish.setSetmealId(setmealDTO.getId()));
setmealMapper.insertBatchSetmealDish(dishes);
}
/**
* idid
* SetmealMappergetBySetmealIdidSetmealMappergetSetmealDishByIdidList<SetmealDish>SetmealDishid
* SetmealVOBeanUtils.copyPropertiesSetmealVOSetmealVO
* SetmealVO便
*
* @param id id
* @return SetmealVOid便
*/
public SetmealVO getDishById(Long id) {
// 获取套餐信息,调用数据访问层方法获取对应套餐对象
Setmeal setmeal = setmealMapper.getBySetmealId(id);
// 获取套餐绑定的菜品,调用数据访问层方法获取套餐对应的菜品关联列表
List<SetmealDish> setmealDishes = setmealMapper.getSetmealDishById(id);
// 构建返回对象创建SetmealVO对象并将套餐及菜品关联信息复制和设置进去
SetmealVO setmealVO = new SetmealVO();
BeanUtils.copyProperties(setmeal, setmealVO);
setmealVO.setSetmealDishes(setmealDishes);
return setmealVO;
}
/**
* idid
* ididsidSetmealMappergetBySetmealId
* StatusConstant.ENABLEDeletionNotAllowedExceptionMessageConstant.SETMEAL_ON_SALE
* idididArrayList<Long>便SetmealMapperbatchDeleteSetmealSetmealMapperdeleteSetmealDish
*
*
* @param ids id
*/
public void batchDeleteById(ArrayList<Long> ids) {
ids.forEach(id -> {
Setmeal setmeal = setmealMapper.getBySetmealId(id);
if (StatusConstant.ENABLE == setmeal.getStatus()) {
// 起售中的套餐不能删除,若处于起售状态则抛出异常提示
throw new DeletionNotAllowedException(MessageConstant.SETMEAL_ON_SALE);
}
});
ids.forEach(setmealId -> {
// 删除套餐表中的数据先构建包含套餐id的集合再调用对应的删除方法
ArrayList<Long> setmealIds = new ArrayList<>();
setmealIds.add(setmealId);
setmealMapper.batchDeleteSetmeal(setmealIds);
// 删除套餐菜品关系表中的数据,直接调用对应的删除方法
setmealMapper.deleteSetmealDish(setmealId);
});
}
/**
*
* SetmealDTOSetmealBeanUtils.copyPropertiesSetmealMapperinsertBatchSetmealDishSetmealDTOList<SetmealDish>
* SetmealMapperinsertSetmeal
*
* @param setmealDTO
*/
public void insert(SetmealDTO setmealDTO) {
Setmeal setmeal = new Setmeal();
BeanUtils.copyProperties(setmealDTO, setmeal);
// 新增套餐绑定的菜品,调用数据访问层方法批量插入套餐

@ -0,0 +1,93 @@
package com.sky.webSocket;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/**
* WebSocketServerJava WebSocketWebSocketWebSocket
* 使WebSocket@ServerEndpoint@OnOpen@OnMessage@OnCloseWebSocket
* 线
*/
@Component
@ServerEndpoint("/ws/{sid}")
@Slf4j
public class WebSocketServer {
/**
* 使MapWebSocket{sid}ididWebSocketSession
* Map便便
*/
private static Map<String, Session> sessionMap = new HashMap<>();
/**
* 使@OnOpenWebSocket
* @PathParam("sid")sidWebSocketSession
* sid便sidSessionsessionMap便
*
* @param sid
* @param session WebSocket
*/
@OnOpen
public void open(@PathParam("sid") String sid, Session session) {
log.info("建立连接:{}", sid);
sessionMap.put(sid, session);
}
/**
* 使@OnMessageWebSocket
* message@PathParam("sid")sid
* sid便
*
* @param message WebSocket
* @param sid 便
*/
@OnMessage
public void onMessage(String message, @PathParam("sid") String sid) {
log.info("收到客户端:{}的信息:{}", sid, message);
}
/**
* 使@OnCloseWebSocket
* @PathParam("sid")sid
* sid便sessionMapsessionMap
*
* @param sid 便Map
*/
@OnClose
public void close(@PathParam("sid") String sid) {
log.info("断开连接:{}", sid);
sessionMap.remove(sid);
}
/**
* WebSocket
* sessionMapsessionMap.values()getBasicRemote().sendText(message)message
* IOExceptionRuntimeException
* 广线
*
* @param message
*/
public void sendToAllClient(String message) {
Collection<Session> sessionCollection = sessionMap.values();
for (Session session : sessionCollection) {
try {
session.getBasicRemote().sendText(message);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
Loading…
Cancel
Save