OpenApiController.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package me.zhengjie.modules.thirdparty.v1;
  2. import io.swagger.annotations.Api;
  3. import io.swagger.annotations.ApiOperation;
  4. import lombok.RequiredArgsConstructor;
  5. import me.zhengjie.annotation.AnonymousAccess;
  6. import me.zhengjie.annotation.Log;
  7. import me.zhengjie.annotation.rest.AnonymousPostMapping;
  8. import me.zhengjie.base.BaseResponse;
  9. import me.zhengjie.base.QueryPageParams;
  10. import me.zhengjie.domain.LocalStorage;
  11. import me.zhengjie.exception.BadRequestException;
  12. import me.zhengjie.modules.dm.daypc.domain.DmDayPc;
  13. import me.zhengjie.modules.dm.daypc.service.DmDayPcService;
  14. import me.zhengjie.modules.dm.daypc.service.dto.DmDayPcQueryCriteria;
  15. import me.zhengjie.modules.dm.foodPj.domain.DmFoodPj;
  16. import me.zhengjie.modules.dm.foodPj.service.DmFoodPjService;
  17. import me.zhengjie.modules.dm.order.domain.DmOrderItem;
  18. import me.zhengjie.modules.dm.order.domain.DmOrderRecord;
  19. import me.zhengjie.modules.dm.order.repository.DmOrderItemRepository;
  20. import me.zhengjie.modules.dm.order.repository.DmOrderRecordRepository;
  21. import me.zhengjie.modules.dm.service.domain.DmServicePj;
  22. import me.zhengjie.modules.dm.service.service.DmServicePjService;
  23. import me.zhengjie.modules.dmApp.domain.AppFoodPj;
  24. import me.zhengjie.modules.dmApp.service.AppFoodPjService;
  25. import me.zhengjie.service.LocalStorageService;
  26. import me.zhengjie.utils.FileUtil;
  27. import me.zhengjie.utils.SecurityUtils;
  28. import org.springframework.data.domain.Pageable;
  29. import org.springframework.http.HttpStatus;
  30. import org.springframework.http.ResponseEntity;
  31. import org.springframework.validation.annotation.Validated;
  32. import org.springframework.web.bind.annotation.*;
  33. import org.springframework.web.multipart.MultipartFile;
  34. import java.util.List;
  35. import java.util.Map;
  36. @RestController
  37. @RequiredArgsConstructor
  38. @Api(tags = "用户接口")
  39. @RequestMapping("/api/thirdparty/v1/open")
  40. public class OpenApiController {
  41. private final DmDayPcService dmDayPcService;
  42. private final DmServicePjService dmServicePjService;
  43. private final AppFoodPjService appFoodPjService;
  44. private final DmFoodPjService dmFoodPjService;
  45. private final LocalStorageService localStorageService;
  46. private final DmOrderRecordRepository dmOrderRecordRepository;
  47. private final DmOrderItemRepository orderItemRepository;
  48. @Log("获取今日菜品-App")
  49. @ApiOperation("获取今日菜品-App")
  50. @AnonymousPostMapping(value = "/foodRepository")
  51. public BaseResponse<Object> foodRepository(@RequestBody QueryPageParams<DmDayPcQueryCriteria> criteria, Pageable pageable){
  52. SecurityUtils.CheckApiAuth(criteria);
  53. return new BaseResponse<>(dmDayPcService.foodRepository());
  54. }
  55. @AnonymousPostMapping(value = "/createApp")
  56. @Log("新增服务评价")
  57. @ApiOperation("新增服务评价")
  58. public BaseResponse<Object> createApp(@RequestBody QueryPageParams<DmServicePj> resources){
  59. SecurityUtils.CheckApiAuth(resources);
  60. return new BaseResponse<>(dmServicePjService.createApp(resources.getQuery()));
  61. }
  62. @AnonymousPostMapping(value = "/appFoodPj")
  63. @Log("App菜品评价")
  64. @ApiOperation("App菜品评价")
  65. public BaseResponse<Object> appFoodPj(@RequestBody QueryPageParams<String> userCode) {
  66. SecurityUtils.CheckApiAuth(userCode);
  67. List<AppFoodPj> list = appFoodPjService.selectAppFoodPj(userCode.getQuery());
  68. return new BaseResponse<>(list);
  69. }
  70. @AnonymousPostMapping(value = "/createFoodPj")
  71. @Log("新增菜品评价")
  72. @ApiOperation("新增菜品评价")
  73. public BaseResponse<Object> createFoodPj(@RequestBody QueryPageParams<DmFoodPj> resources){
  74. SecurityUtils.CheckApiAuth(resources);
  75. return new BaseResponse<>(dmFoodPjService.createApp(resources.getQuery()));
  76. }
  77. @AnonymousPostMapping(value = "/pictures")
  78. @Log("上传图片")
  79. @ApiOperation("上传图片")
  80. public BaseResponse<Object> upload(@RequestParam String timestamp, @RequestParam String nonce, @RequestParam String name, @RequestParam("file") MultipartFile file){
  81. QueryPageParams params = new QueryPageParams();
  82. params.setNonce(nonce);
  83. params.setTimestamp(timestamp);
  84. SecurityUtils.CheckApiAuth(params);
  85. // 判断文件是否为图片
  86. String suffix = FileUtil.getExtensionName(file.getOriginalFilename());
  87. if(!FileUtil.IMAGE.equals(FileUtil.getFileType(suffix))){
  88. throw new BadRequestException("只能上传图片");
  89. }
  90. LocalStorage localStorage = localStorageService.create(name, file);
  91. return new BaseResponse<>(localStorage);
  92. }
  93. @AnonymousAccess
  94. @GetMapping(value = "/countOrderAmt")
  95. @Log("pc端运营食堂营业额")
  96. @ApiOperation("pc端运营食堂营业额")
  97. public ResponseEntity<Object> countOrderAmt(){
  98. return new ResponseEntity<>(dmOrderRecordRepository.countOrderAmt(),HttpStatus.OK);
  99. }
  100. @AnonymousAccess
  101. @GetMapping(value = "/hyFood")
  102. @Log("pc端运营最受欢迎菜品")
  103. @ApiOperation("pc端运营最受欢迎菜品")
  104. public ResponseEntity<Object> hyFood(){
  105. return new ResponseEntity<>(orderItemRepository.hyFood(),HttpStatus.OK);
  106. }
  107. @AnonymousPostMapping(value = "/countOrderAmtApp")
  108. @Log("App端运营食堂营业额")
  109. @ApiOperation("App端运营食堂营业额")
  110. public BaseResponse<Object> countOrderAmtApp(@RequestBody QueryPageParams<DmOrderRecord> criteria){
  111. SecurityUtils.CheckApiAuth(criteria);
  112. return new BaseResponse<>(dmOrderRecordRepository.countOrderAmt());
  113. }
  114. @AnonymousPostMapping(value = "/hyFoodApp")
  115. @Log("App端运营最受欢迎菜品")
  116. @ApiOperation("App端运营最受欢迎菜品")
  117. public BaseResponse<Object> hyFoodApp(@RequestBody QueryPageParams<DmOrderItem> criteria){
  118. SecurityUtils.CheckApiAuth(criteria);
  119. return new BaseResponse<>(orderItemRepository.hyFood());
  120. }
  121. }