|
|
@@ -1,21 +1,316 @@
|
|
|
package com.happy.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.happy.Model.House;
|
|
|
+import com.happy.Model.HouseNumber;
|
|
|
import com.happy.Model.HouseNumberStatus;
|
|
|
+import com.happy.Until.DateUtil;
|
|
|
+import com.happy.Until.Func;
|
|
|
import com.happy.dao.HouseNumberDao;
|
|
|
import com.happy.dao.HouseNumberStatusDao;
|
|
|
+import com.happy.dao.HousePriceDao;
|
|
|
+import com.happy.dto.HouseNumberStatusDto;
|
|
|
+import com.happy.dto.HousePriceDto;
|
|
|
import com.happy.service.HouseNumberStatusService;
|
|
|
+import com.happy.service.HousePriceService;
|
|
|
+import lombok.SneakyThrows;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.BeanWrapper;
|
|
|
+import org.springframework.beans.BeanWrapperImpl;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.List;
|
|
|
+import java.beans.PropertyDescriptor;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service("HouseNumberStatusService")
|
|
|
public class HouseNumberStatusImplService implements HouseNumberStatusService {
|
|
|
|
|
|
- @Resource
|
|
|
+ @Resource(name = "HouseNumberStatusDao")
|
|
|
public HouseNumberStatusDao houseNumberStatusDao;
|
|
|
+ @Resource(name = "housePriceService")
|
|
|
+ private HousePriceService housePriceService;
|
|
|
+ @Resource(name = "HouseNumberDao")
|
|
|
+ public HouseNumberDao houseNumberDao;
|
|
|
+ @Resource(name = "housePriceDao")
|
|
|
+ public HousePriceDao housePriceDao;
|
|
|
+
|
|
|
@Override
|
|
|
public int saveBatch(List<HouseNumberStatus> list) {
|
|
|
return houseNumberStatusDao.saveBatch(list);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<?> queryData(HouseNumberStatusDto houseNumberStatusDto) {
|
|
|
+ String managerId = houseNumberStatusDto.getManagerId();
|
|
|
+ Integer showType = houseNumberStatusDto.getShowType();
|
|
|
+ if (StringUtils.isBlank(managerId) || showType == null) return Collections.emptyList();
|
|
|
+ List<House> houseList = housePriceService.queryHouseListByManagerId(houseNumberStatusDto.getManagerId());
|
|
|
+ if (houseList.isEmpty()) return houseList;
|
|
|
+ List<HouseNumber> houseNumberList = houseNumberDao.queryListByHouseIdList(houseList.stream().map(House::getId).collect(Collectors.toList()));
|
|
|
+ if (houseNumberList.isEmpty()) return houseList;
|
|
|
+
|
|
|
+ String setDate = houseNumberStatusDto.getSetDate();
|
|
|
+ Date startDate = DateUtil.parseDateOnly(setDate);
|
|
|
+ Date endDate = DateUtil.addDate(startDate, Calendar.DATE, 27);
|
|
|
+ String setDateWithEndDate = String.format("%s,%s", setDate, DateUtil.parseDateToStr(endDate, DateUtil.Time_Formatter_Day));
|
|
|
+
|
|
|
+ //region 房间状态信息
|
|
|
+ houseNumberStatusDto.setStatuses(Arrays.asList(2, 3, 4, 5, 6));
|
|
|
+ List<String> houseNumberIdList = houseNumberList.stream().map(HouseNumber::getId).collect(Collectors.toList());
|
|
|
+ houseNumberStatusDto.setHouseNumberIds(houseNumberIdList);
|
|
|
+ List<HouseNumberStatusDto> houseNumberStatusDtoList;
|
|
|
+ if (showType == 1) {
|
|
|
+ houseNumberStatusDto.setSetDate(setDateWithEndDate);
|
|
|
+ // 周日内的房间状态信息
|
|
|
+ houseNumberStatusDtoList = houseNumberStatusDao.queryList(houseNumberStatusDto);
|
|
|
+ } else if (showType == 2) {
|
|
|
+ // 当日的房间状态信息
|
|
|
+ houseNumberStatusDtoList = houseNumberStatusDao.queryList(houseNumberStatusDto);
|
|
|
+ } else {
|
|
|
+ houseNumberStatusDtoList = Collections.emptyList();
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ boolean existHouseNumberStatus = !houseNumberStatusDtoList.isEmpty();
|
|
|
+
|
|
|
+ //region 订单信息
|
|
|
+ Map<String, HouseNumberStatusDto> orderInfoMap;
|
|
|
+ if (existHouseNumberStatus) {
|
|
|
+ List<String> bookingId = houseNumberStatusDtoList.stream()
|
|
|
+ .filter(item -> item.getStatus() == 5 || item.getStatus() == 6)
|
|
|
+ .map(HouseNumberStatusDto::getBookingId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (bookingId.isEmpty()) {
|
|
|
+ orderInfoMap = Collections.emptyMap();
|
|
|
+ } else {
|
|
|
+ orderInfoMap = houseNumberStatusDao.queryOrderSomeColumnListByIds(bookingId)
|
|
|
+ .stream().collect(Collectors.toMap(HouseNumberStatusDto::getBookingId, item -> item, (bookingIdOne, bookingIdTow) -> bookingIdOne));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ orderInfoMap = Collections.emptyMap();
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ if (existHouseNumberStatus) {
|
|
|
+ houseNumberList.forEach(houseNumber -> {
|
|
|
+ for (HouseNumberStatusDto numberStatusDto : houseNumberStatusDtoList) {
|
|
|
+ // 填充预定/入住的一些订单信息
|
|
|
+ if (numberStatusDto.getStatus() == 5 || numberStatusDto.getStatus() == 6) {
|
|
|
+ HouseNumberStatusDto score = orderInfoMap.getOrDefault(numberStatusDto.getBookingId(), new HouseNumberStatusDto());
|
|
|
+ BeanUtils.copyProperties(score, numberStatusDto, getNullPropertyNames(score));
|
|
|
+ }
|
|
|
+ // 填充房间状态信息
|
|
|
+ if (Objects.equals(houseNumber.getId(), numberStatusDto.getNumberId())) {
|
|
|
+ houseNumber.setHouseNumberStatus(numberStatusDto);
|
|
|
+ // 已按创建时间倒叙,找到直接退出本次循环
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (houseNumberStatusDto.getShowType() == 1) {
|
|
|
+ List<String> dateListBetween = DateUtil.getDateStrListBetween(startDate, endDate);
|
|
|
+
|
|
|
+ //region 周期内的改价记录
|
|
|
+ HousePriceDto housePriceDto = new HousePriceDto();
|
|
|
+ List<String> houseIdList = houseList.stream().map(House::getId).collect(Collectors.toList());
|
|
|
+ housePriceDto.setHouseIdList(houseIdList);
|
|
|
+ housePriceDto.setSetDate(setDateWithEndDate);
|
|
|
+ List<HousePriceDto> housePriceDtoList = housePriceDao.queryListTwo(housePriceDto);
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ List<JSONObject> result = new ArrayList<>();
|
|
|
+ houseList.forEach(house -> houseNumberList.forEach(houseNumber -> {
|
|
|
+ if (houseNumber.getHouseId().equals(house.getId())) {
|
|
|
+ JSONObject houseJsonObject = new JSONObject();
|
|
|
+ houseJsonObject.put("id", house.getId());
|
|
|
+ houseJsonObject.put("houseName", house.gethName());
|
|
|
+ String numberName = houseNumber.getNumberName();
|
|
|
+ dateListBetween.forEach(date -> {
|
|
|
+ houseJsonObject.put("numberName", numberName);
|
|
|
+ JSONObject dateJsonObject = new JSONObject();
|
|
|
+ dateJsonObject.put("numberId", houseNumber.getId());
|
|
|
+ dateJsonObject.put("houseName", house.gethName());
|
|
|
+ dateJsonObject.put("numberName", numberName);
|
|
|
+ dateJsonObject.put("housePrice", getPrice(DateUtil.parseDateOnly(date), house, housePriceDtoList));
|
|
|
+ Optional.ofNullable(houseNumber.getHouseNumberStatus()).ifPresent(houseNumberStatus -> {
|
|
|
+ if (date.equals(houseNumberStatus.getSetDate())) {
|
|
|
+ dateJsonObject.put("closeType", houseNumberStatus.getCloseType());
|
|
|
+ dateJsonObject.put("remark", houseNumberStatus.getRemark());
|
|
|
+ dateJsonObject.put("setDate", houseNumberStatus.getSetDate());
|
|
|
+ dateJsonObject.put("status", houseNumberStatus.getStatus());
|
|
|
+ if (houseNumberStatus.getStatus() == 5 || houseNumberStatus.getStatus() == 6) {
|
|
|
+ dateJsonObject.put("orderNum", houseNumberStatus.getOrderNum());
|
|
|
+ dateJsonObject.put("orderUserName", houseNumberStatus.getOrderUserName());
|
|
|
+ dateJsonObject.put("orderUserPhone", houseNumberStatus.getOrderUserPhone());
|
|
|
+ dateJsonObject.put("orderPayAccount", houseNumberStatus.getOrderPayAccount());
|
|
|
+ dateJsonObject.put("orderStartTime", houseNumberStatus.getOrderStartTime());
|
|
|
+ dateJsonObject.put("orderEndTime", houseNumberStatus.getOrderEndTime());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ houseJsonObject.put(date, dateJsonObject);
|
|
|
+ });
|
|
|
+ result.add(houseJsonObject);
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ if (houseNumberStatusDto.getShowType() == 2) {
|
|
|
+ return buildResultOne(houseList, houseNumberList);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<?> queryListWithHouse(HouseNumberStatusDto houseNumberStatusDto) {
|
|
|
+ String managerId = houseNumberStatusDto.getManagerId();
|
|
|
+ if (StringUtils.isBlank(managerId)) return Collections.emptyList();
|
|
|
+ List<House> houseList = housePriceService.queryHouseListByManagerId(houseNumberStatusDto.getManagerId());
|
|
|
+ if (houseList.isEmpty()) return houseList;
|
|
|
+ List<HouseNumber> houseNumberList = houseNumberDao.queryListByHouseIdList(houseList.stream().map(House::getId).collect(Collectors.toList()));
|
|
|
+ if (houseNumberList.isEmpty()) return houseList;
|
|
|
+
|
|
|
+ // 需求文档只注明:批量置净时展示的是脏房(status=3)
|
|
|
+ if (houseNumberStatusDto.getStatus() != null && houseNumberStatusDto.getStatus() == 3) {
|
|
|
+ //region 此代码块为移除不是脏房的房间
|
|
|
+ List<String> houseNumberIdList = houseNumberList.stream().map(HouseNumber::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //region 脏房房间id集合
|
|
|
+ HouseNumberStatusDto paramsOne = new HouseNumberStatusDto();
|
|
|
+ paramsOne.setHouseNumberIds(houseNumberIdList);
|
|
|
+ paramsOne.setStatuses(Collections.singletonList(3));
|
|
|
+ List<String> numberIdList = houseNumberStatusDao.queryList(paramsOne).stream()
|
|
|
+ .map(HouseNumberStatusDto::getNumberId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ if (numberIdList.isEmpty()) return houseList;
|
|
|
+ Set<String> numberIdSet = new HashSet<>(numberIdList);
|
|
|
+ houseNumberList = houseNumberList.stream().filter(houseNumber -> numberIdSet.contains(houseNumber.getId())).collect(Collectors.toList());
|
|
|
+ //endregion
|
|
|
+ }
|
|
|
+ return buildResultOne(houseList, houseNumberList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ @Override
|
|
|
+ public void modifyStatusBatch(HouseNumberStatusDto houseNumberStatusDto) {
|
|
|
+ Integer status = houseNumberStatusDto.getStatus();
|
|
|
+ boolean isStatusEqualsThree = status == 3;
|
|
|
+ boolean isStatusEqualsFour = status == 4;
|
|
|
+ List<String> dateStrListBetween;
|
|
|
+ if (isStatusEqualsFour) {
|
|
|
+ String[] setDateStr = houseNumberStatusDto.getSetDate().split(",");
|
|
|
+ dateStrListBetween = DateUtil.getDateStrListBetween(DateUtil.parseDateOnly(setDateStr[0]), DateUtil.parseDateOnly(setDateStr[1]));
|
|
|
+ } else {
|
|
|
+ dateStrListBetween = Collections.emptyList();
|
|
|
+ }
|
|
|
+ String currentDateStr = DateUtil.getFormatDate(DateUtil.Time_Formatter_Day);
|
|
|
+ Date dataTime = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
|
|
|
+ List<String> houseNumberIds = houseNumberStatusDto.getHouseNumberIds();
|
|
|
+ List<HouseNumberStatus> houseNumberStatusList = new ArrayList<>();
|
|
|
+ if (isStatusEqualsThree || isStatusEqualsFour) {
|
|
|
+ houseNumberIds.forEach(houseNumberId -> {
|
|
|
+ HouseNumberStatus houseNumberStatus = new HouseNumberStatus();
|
|
|
+ houseNumberStatus.setNumberId(houseNumberId);
|
|
|
+ houseNumberStatus.setStatus(status);
|
|
|
+ houseNumberStatus.setCreateId("");
|
|
|
+ houseNumberStatus.setCreateDate(dataTime);
|
|
|
+ if (isStatusEqualsThree) {
|
|
|
+ houseNumberStatus.setId(Func.newGuid());
|
|
|
+ houseNumberStatus.setSetDate(currentDateStr);
|
|
|
+ houseNumberStatusList.add(houseNumberStatus);
|
|
|
+ } else {
|
|
|
+ dateStrListBetween.forEach(dateStr -> {
|
|
|
+ HouseNumberStatus houseNumberStatusNew = new HouseNumberStatus();
|
|
|
+ BeanUtils.copyProperties(houseNumberStatus, houseNumberStatusNew);
|
|
|
+ houseNumberStatusNew.setId(Func.newGuid());
|
|
|
+ houseNumberStatusNew.setCloseType(houseNumberStatusDto.getCloseType());
|
|
|
+ houseNumberStatusNew.setSetDate(dateStr);
|
|
|
+ houseNumberStatusNew.setRemark(houseNumberStatusDto.getRemark());
|
|
|
+ houseNumberStatusList.add(houseNumberStatusNew);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ houseNumberStatusDao.saveBatch(houseNumberStatusList);
|
|
|
+ } else {
|
|
|
+ houseNumberStatusDto.setModifyDate(dataTime);
|
|
|
+ houseNumberStatusDao.updateStatus(houseNumberStatusDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ @Override
|
|
|
+ public void modifyStatus(HouseNumberStatusDto houseNumberStatusDto) {
|
|
|
+ Integer status = houseNumberStatusDto.getStatus();
|
|
|
+ boolean isStatusEqualsThree = status == 3;
|
|
|
+ boolean isStatusEqualsFour = status == 4;
|
|
|
+ Date dataTime = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
|
|
|
+ if (isStatusEqualsThree || isStatusEqualsFour) {
|
|
|
+ HouseNumberStatus houseNumberStatus = new HouseNumberStatus();
|
|
|
+ BeanUtils.copyProperties(houseNumberStatusDto, houseNumberStatus);
|
|
|
+ houseNumberStatus.setId(Func.newGuid());
|
|
|
+ houseNumberStatus.setCreateDate(dataTime);
|
|
|
+ houseNumberStatus.setCreateId("");
|
|
|
+ houseNumberStatusDao.saveBatch(Collections.singletonList(houseNumberStatus));
|
|
|
+ } else {
|
|
|
+ houseNumberStatusDto.setModifyDate(dataTime);
|
|
|
+ houseNumberStatusDao.updateStatus(houseNumberStatusDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<JSONObject> buildResultOne(List<House> houseList, List<HouseNumber> houseNumberList) {
|
|
|
+ List<JSONObject> result = new ArrayList<>();
|
|
|
+ Map<String, List<HouseNumber>> houseNumberMap = houseNumberList.stream().collect(Collectors.groupingBy(HouseNumber::getHouseId));
|
|
|
+ houseList.forEach(house -> {
|
|
|
+ JSONObject houseJosoObj = (JSONObject) JSONObject.toJSON(house);
|
|
|
+ houseJosoObj.put("HouseNumberList", houseNumberMap.getOrDefault(house.getId(), Collections.emptyList()));
|
|
|
+ result.add(houseJosoObj);
|
|
|
+ });
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取对象null值属性名称,用于BeanUtils.copyProperties忽略字段
|
|
|
+ */
|
|
|
+ private String[] getNullPropertyNames(Object source) {
|
|
|
+ final BeanWrapper src = new BeanWrapperImpl(source);
|
|
|
+ PropertyDescriptor[] pds = src.getPropertyDescriptors();
|
|
|
+ Set<String> emptyNames = new HashSet<String>();
|
|
|
+ for (PropertyDescriptor pd : pds) {
|
|
|
+ Object srcValue = src.getPropertyValue(pd.getName());
|
|
|
+ if (srcValue == null) {
|
|
|
+ emptyNames.add(pd.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String[] result = new String[emptyNames.size()];
|
|
|
+ return emptyNames.toArray(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取房型指定日期的价格
|
|
|
+ *
|
|
|
+ * @return 原价 or 周日内最新一条改价记录的价格
|
|
|
+ */
|
|
|
+ private Double getPrice(Date dateIn, House house, List<HousePriceDto> housePriceDtoList) {
|
|
|
+ Double price = house.getPrice();
|
|
|
+ if (housePriceDtoList.isEmpty()) return price;
|
|
|
+ for (HousePriceDto priceDto : housePriceDtoList) {
|
|
|
+ String[] date = priceDto.getSetDate().split(",");
|
|
|
+ Date startDate = DateUtil.parseDateOnly(date[0]);
|
|
|
+ Date endDate = DateUtil.parseDateOnly(date[1]);
|
|
|
+ assert startDate != null;
|
|
|
+ boolean flag = DateUtil.isEffectiveDate(dateIn, startDate, endDate) && house.getId().equals(priceDto.getHouseId());
|
|
|
+ if (flag) {
|
|
|
+ price = priceDto.getPrice();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return price;
|
|
|
+ }
|
|
|
}
|