package com.chuanghai.ihotel.controller; import com.chuanghai.ihotel.anno.AdminLoginCheck; import com.chuanghai.ihotel.anno.ParamCheck; import com.chuanghai.ihotel.common.exception.BizCodeEnume; import com.chuanghai.ihotel.common.exception.RRException; import com.chuanghai.ihotel.common.utils.CommonResult; import com.chuanghai.ihotel.entity.RoomThirdSettingEntity; import com.chuanghai.ihotel.service.RoomThirdSettingService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * 房间第三方平台设置 * * @author codingliang * @email codingliang@gmail.com * @date 2022-07-27 10:02:04 */ @RestController @RequestMapping("roomThirdSetting") public class RoomThirdSettingController { @Autowired private RoomThirdSettingService thirdSettingService; /** * 新增房间第三方平台设置 * @param adminToken 管理员token * @param entity 请求参数 * @return */ @AdminLoginCheck @ParamCheck(index = 2) @PostMapping("add") public CommonResult add(@RequestHeader("admin_token") String adminToken, @RequestBody RoomThirdSettingEntity entity) { thirdSettingService.mySave(entity); return CommonResult.ok(); } /** * 修改房间第三方平台设置 * @param adminToken 管理员token * @param entity 请求参数 * @return */ @AdminLoginCheck @ParamCheck(index = 2) @PostMapping("update") public CommonResult update(@RequestHeader("admin_token") String adminToken, @RequestBody RoomThirdSettingEntity entity) { if (entity.getId() == null) { throw new RRException(BizCodeEnume.PARAMETER_ERROR, "id不能为空"); } thirdSettingService.myUpdate(entity); return CommonResult.ok(); } /** * 根据房间id查询 * @param adminToken 管理员token * @param roomId 房间id * @return */ @AdminLoginCheck @GetMapping("setting/{roomId}") public CommonResult getByRoomId(@RequestHeader("admin_token") String adminToken, @PathVariable("roomId") Long roomId) { RoomThirdSettingEntity entity = thirdSettingService.findByRoomId(roomId); if (entity == null) { entity = new RoomThirdSettingEntity(); } return CommonResult.ok().setResult(entity); } /** * 电控制 * @param adminToken 管理员token * @param roomId 房间id * @param operType 操作类型 1开、2关 * @return */ @AdminLoginCheck @GetMapping("changeElectric/{roomId}/{operType}") public CommonResult changeElectric(@RequestHeader("admin_token") String adminToken, @PathVariable("roomId") Long roomId, @PathVariable("operType") String operType) { if (!("1".equals(operType) || "2".equals(operType))) { throw new RRException(BizCodeEnume.PARAMETER_ERROR, "operType只能为1或2"); } thirdSettingService.changeElectric(roomId, operType); return CommonResult.ok(); } }