|
|
@@ -2,19 +2,48 @@ package com.happy.action;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.happy.Model.HousePrice;
|
|
|
-import com.happy.Until.GetHttpParam;
|
|
|
-import com.happy.Until.ResUtil;
|
|
|
+import com.happy.Until.*;
|
|
|
import com.happy.common.controller.BaseController;
|
|
|
import com.happy.dto.HousePriceDto;
|
|
|
import com.happy.service.HousePriceService;
|
|
|
+import com.happy.service.HouseService;
|
|
|
+import com.happy.vo.DailyPriceVo;
|
|
|
+import com.happy.vo.HousePriceDataVo;
|
|
|
+import com.happy.vo.HousePriceOneDataVo;
|
|
|
+import com.happy.vo.HousePriceResultVo;
|
|
|
import com.opensymphony.xwork2.ModelDriven;
|
|
|
import lombok.SneakyThrows;
|
|
|
import org.apache.struts2.ServletActionContext;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.List;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
public class HousePriceAction extends BaseController implements ModelDriven<HousePriceDto> {
|
|
|
+
|
|
|
+ private HttpServletRequest request;
|
|
|
+ public HttpServletResponse response;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 房型ID
|
|
|
+ */
|
|
|
+ public Integer sadad;
|
|
|
+ /**
|
|
|
+ * 民宿商家ID
|
|
|
+ */
|
|
|
+ public Integer homestayId;
|
|
|
+ /**
|
|
|
+ * 入住时间
|
|
|
+ */
|
|
|
+ public String startTime;
|
|
|
+ /**
|
|
|
+ * 离店时间
|
|
|
+ */
|
|
|
+ public String endTime;
|
|
|
+
|
|
|
private final HousePriceDto housePriceDto = new HousePriceDto();
|
|
|
|
|
|
@Override
|
|
|
@@ -25,6 +54,9 @@ public class HousePriceAction extends BaseController implements ModelDriven<Hous
|
|
|
@Resource(name = "housePriceService")
|
|
|
private HousePriceService housePriceService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private HouseService houseService;
|
|
|
+
|
|
|
/**
|
|
|
* 批量改价 房态管理-房价管理
|
|
|
* 约定body数据格式:{"dateList":["2023-08-11,2023-08-20"],"priceList":[{"managerId":"1586005529","houseId":"1379573861","price":"180"}]}
|
|
|
@@ -89,4 +121,222 @@ public class HousePriceAction extends BaseController implements ModelDriven<Hous
|
|
|
public void exportHistory() {
|
|
|
housePriceService.exportHistory(housePriceDto);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取价格日历
|
|
|
+ * managerId:民宿商家ID
|
|
|
+ * startTime:入住时间
|
|
|
+ * endTime:离店时间
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String priceCalendar() throws ParseException {
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
+ if (homestayId == null) {
|
|
|
+ resultJson.put("message", "商家不能为空");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (startTime == null) {
|
|
|
+ resultJson.put("message", "入住时间不能为空");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<HousePriceResultVo> result = new ArrayList<>();
|
|
|
+ List<String> dateStrs = new ArrayList<>();
|
|
|
+ String DateNow = TimeExchange.DateToString(new Date(), "yyyy-MM-dd");
|
|
|
+ //离店时间为空的话 则拿入店时间的前三天和后七天数据
|
|
|
+ boolean IsDurStart = TimeExchange.CompareDate(DateNow, startTime, "yyyy-MM-dd");
|
|
|
+ if (IsDurStart) {
|
|
|
+ for (int i = 1; i <= 3; i++) {
|
|
|
+ String date = TimeExchange.TimeDesD(startTime, -i);
|
|
|
+ if (date.equals(DateNow)) {
|
|
|
+ dateStrs.add(date);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ dateStrs.add(date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ dateStrs.add(startTime);
|
|
|
+
|
|
|
+ int dateNum = 7;
|
|
|
+ if (endTime != null) {
|
|
|
+ //后七天
|
|
|
+ dateNum = TimeExchange.daysBetween(startTime, endTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 1; i <= dateNum; i++) {
|
|
|
+ String date = TimeExchange.TimeDesD(startTime, i);
|
|
|
+ dateStrs.add(date);
|
|
|
+ }
|
|
|
+
|
|
|
+ Collections.sort(dateStrs);
|
|
|
+
|
|
|
+ List<HousePriceDataVo> hprd = housePriceService.queryHousePriceDatas(homestayId, dateStrs.get(0), dateStrs.get(dateStrs.size() - 1));
|
|
|
+ List<HousePriceOneDataVo> oneDatas = new ArrayList<>();
|
|
|
+ //将数据处理成单天的
|
|
|
+ for (HousePriceDataVo hp : hprd) {
|
|
|
+ if (hp.getStartTime().equals(hp.getEndTime())) {
|
|
|
+ HousePriceOneDataVo oneData = new HousePriceOneDataVo();
|
|
|
+ oneData.setSetDate(hp.getStartTime());
|
|
|
+ oneData.setCreateDate(hp.getCreateDate());
|
|
|
+ oneData.setPrice(hp.getPrice());
|
|
|
+ oneData.setHouseId(hp.getHouseId());
|
|
|
+ oneDatas.add(oneData);
|
|
|
+ } else {
|
|
|
+ int beDateNum = TimeExchange.daysBetween(hp.getStartTime(), hp.getEndTime());
|
|
|
+ for (int i = 0; i <= beDateNum; i++) {
|
|
|
+ HousePriceOneDataVo oneData = new HousePriceOneDataVo();
|
|
|
+ oneData.setSetDate(TimeExchange.TimeDesD(hp.getStartTime(), i));
|
|
|
+ oneData.setCreateDate(hp.getCreateDate());
|
|
|
+ oneData.setPrice(hp.getPrice());
|
|
|
+ oneData.setHouseId(hp.getHouseId());
|
|
|
+ oneDatas.add(oneData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据房型ID处理重复的数据
|
|
|
+ */
|
|
|
+ List<HousePriceOneDataVo> newOneDatas = new ArrayList<>();
|
|
|
+ List<Integer> houseIds = oneDatas.stream().map(HousePriceOneDataVo::getHouseId).distinct().collect(Collectors.toList());
|
|
|
+ for (Integer houseId : houseIds) {
|
|
|
+ for (String str : dateStrs) {
|
|
|
+ Optional<HousePriceOneDataVo> one = oneDatas.stream().filter(e -> e.getSetDate().equals(str) && e.getHouseId().equals(houseId)).sorted(Comparator.comparing(HousePriceOneDataVo::getCreateDate, Comparator.reverseOrder())).findFirst();
|
|
|
+ if (one != null && one.isPresent()) {
|
|
|
+ HousePriceOneDataVo oneData = new HousePriceOneDataVo();
|
|
|
+ oneData.setSetDate(one.get().getSetDate());
|
|
|
+ oneData.setCreateDate(one.get().getCreateDate());
|
|
|
+ oneData.setPrice(one.get().getPrice());
|
|
|
+ oneData.setHouseId(one.get().getHouseId());
|
|
|
+ newOneDatas.add(oneData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取该民宿下最低房型价格
|
|
|
+ */
|
|
|
+ Double minPrice = houseService.getHouseMinPrice(homestayId);
|
|
|
+
|
|
|
+ for (String str : dateStrs) {
|
|
|
+ HousePriceResultVo data = new HousePriceResultVo();
|
|
|
+ data.setDate(str);
|
|
|
+ List<HousePriceOneDataVo> priceDatas = oneDatas.stream().filter(e -> e.getSetDate().equals(str)).sorted(Comparator.comparing(HousePriceOneDataVo::getPrice)).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (priceDatas.size() > 0) {
|
|
|
+ data.setTopinfo("¥" + priceDatas.get(0).getPrice());
|
|
|
+ } else {
|
|
|
+ data.setTopinfo("¥" + minPrice);
|
|
|
+ }
|
|
|
+ result.add(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ resultJson.put("message", "查询成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ resultJson.put("data", result);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据房型ID获取每日价格
|
|
|
+ * houseId:房型ID
|
|
|
+ * startTime:入住时间
|
|
|
+ * endTime:离店时间
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String dailyPrice() throws ParseException {
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
+
|
|
|
+ if (sadad == null) {
|
|
|
+ resultJson.put("message", "房型不能为空");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (startTime == null) {
|
|
|
+ resultJson.put("message", "入住时间不能为空");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (endTime == null) {
|
|
|
+ resultJson.put("message", "离店时间不能为空");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<HousePriceDataVo> priceDatas = housePriceService.queryPriceByHouseId(sadad, startTime, TimeExchange.TimeDesD(endTime, -1));
|
|
|
+
|
|
|
+ List<HousePriceOneDataVo> oneDatas = new ArrayList<>();
|
|
|
+ //将数据处理成单天的
|
|
|
+ for (HousePriceDataVo hp : priceDatas) {
|
|
|
+ if (hp.getStartTime().equals(hp.getEndTime())) {
|
|
|
+ HousePriceOneDataVo oneData = new HousePriceOneDataVo();
|
|
|
+ oneData.setSetDate(hp.getStartTime());
|
|
|
+ oneData.setCreateDate(hp.getCreateDate());
|
|
|
+ oneData.setPrice(hp.getPrice());
|
|
|
+ oneData.setHouseId(hp.getHouseId());
|
|
|
+ oneDatas.add(oneData);
|
|
|
+ } else {
|
|
|
+ int beDateNum = TimeExchange.daysBetween(hp.getStartTime(), hp.getEndTime());
|
|
|
+ for (int i = 0; i <= beDateNum; i++) {
|
|
|
+ HousePriceOneDataVo oneData = new HousePriceOneDataVo();
|
|
|
+ oneData.setSetDate(TimeExchange.TimeDesD(hp.getStartTime(), i));
|
|
|
+ oneData.setCreateDate(hp.getCreateDate());
|
|
|
+ oneData.setPrice(hp.getPrice());
|
|
|
+ oneData.setHouseId(hp.getHouseId());
|
|
|
+ oneDatas.add(oneData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> dateStrs = new ArrayList<>();
|
|
|
+ int dateNum = TimeExchange.daysBetween(startTime, endTime);
|
|
|
+ for (int i = 1; i <= dateNum; i++) {
|
|
|
+ String date = TimeExchange.TimeDesD(startTime, i);
|
|
|
+ dateStrs.add(date);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取该房型默认价格
|
|
|
+ */
|
|
|
+ Double housePrice = houseService.queryPriceByHouseId(sadad);
|
|
|
+
|
|
|
+ DailyPriceVo dpv = new DailyPriceVo();
|
|
|
+ dpv.setList(new ArrayList<>());
|
|
|
+ for (String dateStr : dateStrs) {
|
|
|
+ HousePriceResultVo data = new HousePriceResultVo();
|
|
|
+ data.setDate(dateStr);
|
|
|
+ List<HousePriceOneDataVo> datas = oneDatas.stream().filter(e -> e.getSetDate().equals(dateStr)).sorted(Comparator.comparing(HousePriceOneDataVo::getPrice)).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if(dateStr.equals(endTime)){
|
|
|
+ data.setTopinfo("离店时间");
|
|
|
+ }else{
|
|
|
+ if (datas.size() > 0) {
|
|
|
+ data.setTopinfo("11晚 共" + datas.get(0).getPrice());
|
|
|
+ dpv.setTotalPrice((dpv.getTotalPrice() == null ? 0 : dpv.getTotalPrice()) + datas.get(0).getPrice());
|
|
|
+ } else {
|
|
|
+ data.setTopinfo("1晚 共" + housePrice);
|
|
|
+ dpv.setTotalPrice((dpv.getTotalPrice() == null ? 0 : dpv.getTotalPrice()) + housePrice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ dpv.getList().add(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ resultJson.put("message", "查询成功");
|
|
|
+ resultJson.put("code", 200);
|
|
|
+ resultJson.put("data", dpv);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
}
|