suochencheng 6 years ago
parent
commit
4b4e5541a3

+ 1 - 1
Permanent_Data/accesstoken.xml

@@ -1 +1 @@
-{"dingmiwmqwbheqscaqn1":{"access_token":"ff53ed905f853339a8958d776b86599c","begin_time":1571043265860},"dinguq6noxhfizkqnsaf":{"access_token":"e93aa02c6c5e33f99cc68f7901781da1","begin_time":1574833239419}}
+{"dingmiwmqwbheqscaqn1":{"access_token":"ff53ed905f853339a8958d776b86599c","begin_time":1571043265860},"dinguq6noxhfizkqnsaf":{"access_token":"3e1e70a1fcf83826b0def2c49804dd48","begin_time":1576809318050}}

+ 3 - 0
src/main/java/com/izouma/zhumj/dto/BedInfoDTO.java

@@ -84,4 +84,7 @@ public class BedInfoDTO {
     @ApiModelProperty(value = "用户余额", name = "money")
     @ApiModelProperty(value = "用户余额", name = "money")
     private BigDecimal money;
     private BigDecimal money;
 
 
+    @ApiModelProperty(value = "无人入住", name = "nobody")
+    private Boolean nobody;
+
 }
 }

+ 4 - 0
src/main/java/com/izouma/zhumj/dto/CheckinInfoDTO.java

@@ -93,4 +93,8 @@ public class CheckinInfoDTO extends BaseEntity {
         this.monthRate = monthRate;
         this.monthRate = monthRate;
         this.dayRate = dayRate;
         this.dayRate = dayRate;
     }
     }
+
+    public CheckinInfoDTO(String idNo) {
+        this.idNo = idNo;
+    }
 }
 }

+ 15 - 0
src/main/java/com/izouma/zhumj/service/CheckinInfoService.java

@@ -18,6 +18,7 @@ import com.izouma.zhumj.utils.BeanCopierUtils;
 import lombok.AllArgsConstructor;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 
 
@@ -268,8 +269,22 @@ public class CheckinInfoService {
 
 
     }
     }
 
 
+    // 每天凌晨4点执行
+    @Scheduled(cron = "0 1 0 * * ?")
     public void autoGenRoomRate() {
     public void autoGenRoomRate() {
 
 
+        List<CheckinInfo> checkinInfoList = checkinInfoRepo.findAllByRoomIdIsNotNullAndMonthRateIsNull();
+
+        for (CheckinInfo checkinInfo : checkinInfoList) {
+            if (checkinInfo.getRoomInfo() != null) {
+                if (checkinInfo.getRoomInfo().getRoomTypeInfo() != null) {
+                    checkinInfo.setMonthRate(checkinInfo.getRoomInfo().getRoomTypeInfo().getMonthPrice());
+                }
+            }
+        }
+        checkinInfoRepo.saveAll(checkinInfoList);
+
+
         Set<Long> storeSet = checkinInfoRepo.findAllStoreId();
         Set<Long> storeSet = checkinInfoRepo.findAllStoreId();
 
 
         for (Long storeId : storeSet) {
         for (Long storeId : storeSet) {

+ 9 - 4
src/main/java/com/izouma/zhumj/service/RoomInfoService.java

@@ -103,12 +103,12 @@ public class RoomInfoService {
         long checkinCount = checkinInfoRepo.countAllByStoreIdAndCheckout(baseDto.getStoreId(), false);
         long checkinCount = checkinInfoRepo.countAllByStoreIdAndCheckout(baseDto.getStoreId(), false);
 
 
         List<CheckinInfoDTO> checkinInfoList = checkinInfoRepo.findRateAllByStoreId(baseDto.getStoreId());
         List<CheckinInfoDTO> checkinInfoList = checkinInfoRepo.findRateAllByStoreId(baseDto.getStoreId());
-        checkinInfoList = checkinInfoList.stream().filter(checkinInfo -> checkinInfo.getDayRate() != null).collect(Collectors.toList());
-        BigDecimal totalPrice = checkinInfoList.stream().map(CheckinInfoDTO::getDayRate).reduce(BigDecimal.ZERO, BigDecimal::add);
+        checkinInfoList = checkinInfoList.stream().filter(checkinInfo -> checkinInfo.getMonthRate() != null).collect(Collectors.toList());
+        BigDecimal totalPrice = checkinInfoList.stream().map(CheckinInfoDTO::getMonthRate).reduce(BigDecimal.ZERO, BigDecimal::add);
 
 
         BigDecimal averagePrice = checkinCount > 0 ? totalPrice.divide(BigDecimal.valueOf(checkinCount), 2, BigDecimal.ROUND_HALF_EVEN) : BigDecimal.ZERO;
         BigDecimal averagePrice = checkinCount > 0 ? totalPrice.divide(BigDecimal.valueOf(checkinCount), 2, BigDecimal.ROUND_HALF_EVEN) : BigDecimal.ZERO;
 
 
-        BigDecimal checkinRate = totalBedCount > 0 ? BigDecimal.valueOf(100 * checkinCount / totalBedCount) : BigDecimal.ZERO;
+        BigDecimal checkinRate = totalBedCount > 0 ? BigDecimal.valueOf(100.0 * checkinCount / totalBedCount).setScale(2, BigDecimal.ROUND_HALF_EVEN) : BigDecimal.ZERO;
 
 
         return HomeRoomDTO.builder()
         return HomeRoomDTO.builder()
                 .totalRoomCount(totalRoomCount)
                 .totalRoomCount(totalRoomCount)
@@ -339,8 +339,12 @@ public class RoomInfoService {
     }
     }
 
 
     private BedInfoDTO changeToBedInfoDTO(BedInfo bedInfo) {
     private BedInfoDTO changeToBedInfoDTO(BedInfo bedInfo) {
+        CheckinInfo checkinInfo = checkinInfoRepo.findFirstByBedIdAndCheckoutIsFalse(bedInfo.getId());
 
 
-
+        boolean nobody = false;
+        if (checkinInfo != null && StringUtils.isNotBlank(checkinInfo.getIdNo())) {
+            nobody = true;
+        }
         return BedInfoDTO.builder()
         return BedInfoDTO.builder()
                 .id(bedInfo.getId())
                 .id(bedInfo.getId())
                 .roomId(bedInfo.getRoomId())
                 .roomId(bedInfo.getRoomId())
@@ -353,6 +357,7 @@ public class RoomInfoService {
                 .repairStatus(bedInfo.getRepairStatus())
                 .repairStatus(bedInfo.getRepairStatus())
                 .lockStatus(bedInfo.getLockStatus())
                 .lockStatus(bedInfo.getLockStatus())
                 .remark(bedInfo.getRemark())
                 .remark(bedInfo.getRemark())
+                .nobody(nobody)
                 .build();
                 .build();
     }
     }
 
 

+ 0 - 2
src/main/java/com/izouma/zhumj/web/RoomInfoController.java

@@ -1,6 +1,5 @@
 package com.izouma.zhumj.web;
 package com.izouma.zhumj.web;
 
 
-import com.izouma.zhumj.domain.BedInfo;
 import com.izouma.zhumj.domain.RoomInfo;
 import com.izouma.zhumj.domain.RoomInfo;
 import com.izouma.zhumj.dto.*;
 import com.izouma.zhumj.dto.*;
 import com.izouma.zhumj.service.RoomInfoService;
 import com.izouma.zhumj.service.RoomInfoService;
@@ -12,7 +11,6 @@ import com.izouma.zhumj.utils.excel.ExcelUtils;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Page;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;

+ 14 - 2
src/test/java/com/izouma/zhumj/service/CheckinTest.java

@@ -51,13 +51,25 @@ public class CheckinTest {
 
 
     @Test
     @Test
     public void updateCheckinInfoMonthRate() {
     public void updateCheckinInfoMonthRate() {
-        //List<CheckinInfo> checkinInfoList = checkinInfoRepo.findAllByRoomIdIsNotNullAndMonthRateIsNull();
+        List<CheckinInfo> checkinInfoList = checkinInfoRepo.findAllByRoomIdIsNotNullAndMonthRateIsNull();
+
+        for (CheckinInfo checkinInfo : checkinInfoList) {
+            if (checkinInfo.getRoomInfo() != null) {
+                if (checkinInfo.getRoomInfo().getRoomTypeInfo() != null) {
+                    checkinInfo.setMonthRate(checkinInfo.getRoomInfo().getRoomTypeInfo().getMonthPrice());
+                }
+            }
+        }
+        checkinInfoRepo.saveAll(checkinInfoList);
+    }
+
+    @Test
+    public void updateCheckinInfoRoomType() {
         List<CheckinInfo> checkinInfoList = checkinInfoRepo.findAll();
         List<CheckinInfo> checkinInfoList = checkinInfoRepo.findAll();
 
 
         for (CheckinInfo checkinInfo : checkinInfoList) {
         for (CheckinInfo checkinInfo : checkinInfoList) {
             if (checkinInfo.getRoomInfo() != null) {
             if (checkinInfo.getRoomInfo() != null) {
                 if (checkinInfo.getRoomInfo().getRoomTypeInfo() != null) {
                 if (checkinInfo.getRoomInfo().getRoomTypeInfo() != null) {
-                    //checkinInfo.setMonthRate(checkinInfo.getRoomInfo().getRoomTypeInfo().getMonthPrice());
                     checkinInfo.setRoomTypeId(checkinInfo.getRoomInfo().getRoomTypeId());
                     checkinInfo.setRoomTypeId(checkinInfo.getRoomInfo().getRoomTypeId());
                 }
                 }
             }
             }