CustomOptionController.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package cn.cslg.pas.controller;
  2. import cn.cslg.pas.common.core.base.Constants;
  3. import cn.cslg.pas.common.dto.business.*;
  4. import cn.cslg.pas.common.model.cronModel.Records;
  5. import cn.cslg.pas.common.utils.Response;
  6. import cn.cslg.pas.exception.ConditionException;
  7. import cn.cslg.pas.exception.UnLoginException;
  8. import cn.cslg.pas.exception.XiaoShiException;
  9. import cn.cslg.pas.service.business.CustomOptionService;
  10. import io.swagger.v3.oas.annotations.Operation;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.web.bind.annotation.PostMapping;
  14. import org.springframework.web.bind.annotation.RequestBody;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import java.util.List;
  18. /**
  19. * 自定义选项Controller层
  20. * @Author xiexiang
  21. * @Date 2023/11/13
  22. */
  23. @Slf4j
  24. @RequestMapping(Constants.API_XiaoSHI + "/customOption")
  25. @RestController
  26. public class CustomOptionController {
  27. @Autowired
  28. private CustomOptionService customOptionService;
  29. @Operation(summary = "查询自定义选项")
  30. @PostMapping("/queryCustomOption")
  31. public Response queryCustomOption(@RequestBody GetCustomOptionDTO getCustomOptionDTO) throws Exception {
  32. Records records = customOptionService.getCustomOption(getCustomOptionDTO);
  33. return Response.success(records);
  34. }
  35. @Operation(summary = "新增自定义选项")
  36. @PostMapping("/addCustomOption")
  37. public Response addCustomOption(@RequestBody CustomOptionDTO customOptionDTO) throws Exception {
  38. if(customOptionDTO != null){
  39. Integer id = null;
  40. try {
  41. id = customOptionService.addCustomOption(customOptionDTO);
  42. } catch (Exception e){
  43. if(e instanceof XiaoShiException) {
  44. return Response.error(e.getMessage());
  45. } else if (e instanceof UnLoginException) {
  46. return Response.unLogin(e.getMessage());
  47. }
  48. }
  49. return Response.success(id);
  50. } else {
  51. return Response.error("网络异常");
  52. }
  53. }
  54. @Operation(summary = "更新自定义选项")
  55. @PostMapping("/updateCustomOption")
  56. public Response updateCustomOption(@RequestBody UpdateCustomOptionDTO updateCustomOptionDTO) throws Exception {
  57. if (updateCustomOptionDTO != null) {
  58. Integer id = customOptionService.updateCustomOption(updateCustomOptionDTO);
  59. return Response.success(id);
  60. } else {
  61. return Response.error("网络异常");
  62. }
  63. }
  64. @Operation(summary = "删除自定义选项")
  65. @PostMapping("/deleteCustomOption")
  66. public Response deleteCustomOption(@RequestBody List<CustomOptionDeleteDTO> customOptionDeleteDTOS) throws Exception {
  67. customOptionService.deleteCustomOption(customOptionDeleteDTOS);
  68. return Response.success("删除成功");
  69. }
  70. }