RoomThirdSettingController.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package com.chuanghai.ihotel.controller;
  2. import com.chuanghai.ihotel.anno.AdminLoginCheck;
  3. import com.chuanghai.ihotel.anno.ParamCheck;
  4. import com.chuanghai.ihotel.common.exception.BizCodeEnume;
  5. import com.chuanghai.ihotel.common.exception.RRException;
  6. import com.chuanghai.ihotel.common.utils.CommonResult;
  7. import com.chuanghai.ihotel.entity.RoomThirdSettingEntity;
  8. import com.chuanghai.ihotel.service.RoomThirdSettingService;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.GetMapping;
  11. import org.springframework.web.bind.annotation.PathVariable;
  12. import org.springframework.web.bind.annotation.PostMapping;
  13. import org.springframework.web.bind.annotation.RequestBody;
  14. import org.springframework.web.bind.annotation.RequestHeader;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RestController;
  17. /**
  18. * 房间第三方平台设置
  19. *
  20. * @author codingliang
  21. * @email codingliang@gmail.com
  22. * @date 2022-07-27 10:02:04
  23. */
  24. @RestController
  25. @RequestMapping("roomThirdSetting")
  26. public class RoomThirdSettingController {
  27. @Autowired
  28. private RoomThirdSettingService thirdSettingService;
  29. /**
  30. * 新增房间第三方平台设置
  31. * @param adminToken 管理员token
  32. * @param entity 请求参数
  33. * @return
  34. */
  35. @AdminLoginCheck
  36. @ParamCheck(index = 2)
  37. @PostMapping("add")
  38. public CommonResult<String> add(@RequestHeader("admin_token") String adminToken, @RequestBody RoomThirdSettingEntity entity) {
  39. thirdSettingService.mySave(entity);
  40. return CommonResult.ok();
  41. }
  42. /**
  43. * 修改房间第三方平台设置
  44. * @param adminToken 管理员token
  45. * @param entity 请求参数
  46. * @return
  47. */
  48. @AdminLoginCheck
  49. @ParamCheck(index = 2)
  50. @PostMapping("update")
  51. public CommonResult<String> update(@RequestHeader("admin_token") String adminToken, @RequestBody RoomThirdSettingEntity entity) {
  52. if (entity.getId() == null) {
  53. throw new RRException(BizCodeEnume.PARAMETER_ERROR, "id不能为空");
  54. }
  55. thirdSettingService.myUpdate(entity);
  56. return CommonResult.ok();
  57. }
  58. /**
  59. * 根据房间id查询
  60. * @param adminToken 管理员token
  61. * @param roomId 房间id
  62. * @return
  63. */
  64. @AdminLoginCheck
  65. @GetMapping("setting/{roomId}")
  66. public CommonResult<RoomThirdSettingEntity> getByRoomId(@RequestHeader("admin_token") String adminToken, @PathVariable("roomId") Long roomId) {
  67. RoomThirdSettingEntity entity = thirdSettingService.findByRoomId(roomId);
  68. if (entity == null) {
  69. entity = new RoomThirdSettingEntity();
  70. }
  71. return CommonResult.ok().setResult(entity);
  72. }
  73. /**
  74. * 电控制
  75. * @param adminToken 管理员token
  76. * @param roomId 房间id
  77. * @param operType 操作类型 1开、2关
  78. * @return
  79. */
  80. @AdminLoginCheck
  81. @GetMapping("changeElectric/{roomId}/{operType}")
  82. public CommonResult<String> changeElectric(@RequestHeader("admin_token") String adminToken,
  83. @PathVariable("roomId") Long roomId,
  84. @PathVariable("operType") String operType) {
  85. if (!("1".equals(operType) || "2".equals(operType))) {
  86. throw new RRException(BizCodeEnume.PARAMETER_ERROR, "operType只能为1或2");
  87. }
  88. thirdSettingService.changeElectric(roomId, operType);
  89. return CommonResult.ok();
  90. }
  91. }