|
|
@@ -1,22 +1,22 @@
|
|
|
package com.chuanghai.ihotel.controller;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-
|
|
|
+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.controller.request.RoomRealtimeStatuRequest;
|
|
|
+import com.chuanghai.ihotel.service.RoomRealtimeStatuService;
|
|
|
+import com.chuanghai.ihotel.vo.RoomRealDataStatuVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.PutMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestHeader;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import com.chuanghai.ihotel.entity.RoomRealtimeStatuEntity;
|
|
|
-import com.chuanghai.ihotel.service.RoomRealtimeStatuService;
|
|
|
-import com.chuanghai.ihotel.common.utils.PageUtils;
|
|
|
-import com.chuanghai.ihotel.common.utils.CommonResult;
|
|
|
-import com.chuanghai.ihotel.common.utils.PageParam;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -34,62 +34,32 @@ public class RoomRealtimeStatuController {
|
|
|
private RoomRealtimeStatuService roomRealtimeStatuService;
|
|
|
|
|
|
/**
|
|
|
- * 列表
|
|
|
+ * 房态信息
|
|
|
+ * @param request 请求参数
|
|
|
+ * @param adminToken 管理员token
|
|
|
+ * @return
|
|
|
*/
|
|
|
- @GetMapping("/list")
|
|
|
- public CommonResult<PageUtils<RoomRealtimeStatuEntity>> list(PageParam pageParam){
|
|
|
- PageUtils page = roomRealtimeStatuService.queryPage(pageParam);
|
|
|
-
|
|
|
- return CommonResult.ok().setResult(page);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 信息
|
|
|
- */
|
|
|
- @GetMapping("/info/{id}")
|
|
|
- public CommonResult<RoomRealtimeStatuEntity> info(@PathVariable("id") Long id){
|
|
|
- RoomRealtimeStatuEntity roomRealtimeStatu = roomRealtimeStatuService.getById(id);
|
|
|
-
|
|
|
- return CommonResult.ok().setResult(roomRealtimeStatu);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 保存
|
|
|
- */
|
|
|
- @PostMapping("/save")
|
|
|
- public CommonResult<String> save(@RequestBody RoomRealtimeStatuEntity roomRealtimeStatu){
|
|
|
- roomRealtimeStatuService.save(roomRealtimeStatu);
|
|
|
-
|
|
|
- return CommonResult.ok();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 修改
|
|
|
- */
|
|
|
- @PutMapping("/update")
|
|
|
- public CommonResult<String> update(@RequestBody RoomRealtimeStatuEntity roomRealtimeStatu){
|
|
|
- boolean flag = roomRealtimeStatuService.updateById(roomRealtimeStatu);
|
|
|
-
|
|
|
- if (flag) {
|
|
|
- return CommonResult.ok();
|
|
|
- } else {
|
|
|
- return CommonResult.fail();
|
|
|
+ @ParamCheck
|
|
|
+ @AdminLoginCheck
|
|
|
+ @GetMapping("/realData")
|
|
|
+ public CommonResult<List<RoomRealDataStatuVO>> realData(RoomRealtimeStatuRequest request,
|
|
|
+ @RequestHeader("admin_token") String adminToken) {
|
|
|
+ LocalDate startDay = request.getStartDay();
|
|
|
+ LocalDate endDay = request.getEndDay();
|
|
|
+ if (startDay.isEqual(endDay)) {
|
|
|
+ throw new RRException(BizCodeEnume.PARAMETER_ERROR, "查询开始时间和结束时间不能为同一天");
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 删除
|
|
|
- */
|
|
|
- @DeleteMapping("/delete")
|
|
|
- public CommonResult<String> delete(@RequestBody Long[] ids){
|
|
|
- boolean flag = roomRealtimeStatuService.removeByIds(Arrays.asList(ids));
|
|
|
+ if (endDay.isBefore(startDay)) {
|
|
|
+ throw new RRException(BizCodeEnume.PARAMETER_ERROR, "查询日期错误");
|
|
|
+ }
|
|
|
|
|
|
- if (flag) {
|
|
|
- return CommonResult.ok();
|
|
|
- } else {
|
|
|
- return CommonResult.fail();
|
|
|
+ if (ChronoUnit.DAYS.between(startDay, endDay) > 1) {
|
|
|
+ throw new RRException(BizCodeEnume.PARAMETER_ERROR, "查询日期最多间隔一天");
|
|
|
}
|
|
|
+
|
|
|
+ List<RoomRealDataStatuVO> realData = roomRealtimeStatuService.realData(request);
|
|
|
+ return CommonResult.ok().setResult(realData);
|
|
|
}
|
|
|
|
|
|
}
|