fixbug— 预定展示

This commit is contained in:
limqhz
2021-05-07 23:55:13 +08:00
parent 4461ba2564
commit d1c89577fe
6 changed files with 261 additions and 74 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,11 +1,12 @@
package com.sv.netty.controller;
import com.dw.ccm.wechat.base.utils.JsonUtils;
import com.sv.dto.app.VenueItem;
import com.sv.dto.app.VenueLessonStatus;
import com.sv.entity.Venue;
import com.sv.netty.config.OrderTools;
import com.sv.service.api.VenueLessonService;
import com.sv.service.oms.VenueService;
import org.apache.http.client.fluent.Request;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -13,13 +14,10 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@RestController
public class AppVenueLessonController {
@@ -51,80 +49,129 @@ public class AppVenueLessonController {
LocalDate now = LocalDate.now();
date = now.toString();
}
List<String> th = fetchDays(LocalDate.parse(date));
Venue venue = venueService.getVenue(id);
List<String> lessonTypes = venueLessonService.getLessonTypes(id);
List<VenueLessonStatus> lessonOrder = venueLessonService.getLessonOrder(id);
String returnHtml = concatResult(lessonOrder);
String returnHtml = concatResult(lessonOrder,th,lessonTypes,venue);
return returnHtml;
}
private String concatResult(List<VenueLessonStatus> lessonOrder) {
private List<String> fetchDays(LocalDate date) {
List<String> list = new ArrayList<>();
for (int i = 0; i < 4; i++) {
list.add(date.toString());
date = date.plusDays(1);
}
list.add(date.toString());
return list;
}
private String concatResult(List<VenueLessonStatus> lessonOrder, List<String> th, List<String> lessonTypes, Venue venue) {
StringBuffer sb = new StringBuffer();
sb.append("<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" +
"<meta http-equiv=\"refresh\" content=\"10\"/><head>");
sb.append("<style type=\"text/css\">");
sb.append("table {" +
" border-collapse: collapse;" +
" margin: 0 auto;" +
" text-align: center;" +
"}" +
"" +
"table td," +
"table th {" +
" border: 1px solid #cad9ea;" +
" color: #666;" +
" height: 30px;" +
"}" +
"" +
"table tr th {" +
" background-color: #CCE8EB;" +
" width: 100px;" +
"}" +
"" +
"table tr:nth-child(odd) {" +
" background: #fff;" +
"}" +
"" +
".nl {" +
" text-align: left;" +
"}" +
"" +
"table tr:nth-child(even) {" +
" background: #F5FAFA;" +
"}");
sb.append("</style>");
sb.append("<script>" + OrderTools.JS + "</script>");
sb.append("<style>" + OrderTools.STYLE + "</style>");
sb.append("</head>");
sb.append("<body>");
sb.append("<h1 align=\"center\">【" + lessonOrder.get(0).getVenueName() + "】预订信息" + "<h1>");
sb.append("<table cellspacing=\"0\" cellpadding=\"0\" width = 100% align=\"center\">");
sb.append("<tr align=\"center\">" +
// "<td width = 10%>场馆</td>" +
"<th width = 10%>课程</th>" +
"<th width = 10%>日期</th>" +
"<th width = 10%>时间</th>" +
"<th width = 6%>总量</th>" +
"<th width = 6%>预订</th>" +
"<th width = 6%>剩余</th>" +
"<th width = 22%>预约用户</th>" +
"<th width = 30%>说明</th>" +
"</tr>");
// boolean firstLine = true;
for (VenueLessonStatus s : lessonOrder){
sb.append("<tr>");
// if (firstLine){
// sb.append( "<td width = 10% rowspan=" + lessonOrder.size() + ">"+ s.getVenueName() + "</td>");
// firstLine = false;
// }
sb.append( "<td width = 10%>"+ s.getLessonName() + "</td>");
sb.append( "<td width = 10%>"+ s.getSearchDate() + "</td>");
sb.append( "<td width = 10%>"+ s.getStartTime() + "-" + s.getEndTime() + "</td>");
sb.append( "<td width = 6%>"+ s.getNum() + "</td>");
sb.append( "<td width = 6%>"+ s.getSaleNum() + "</td>");
sb.append( "<td width = 6%>"+ s.getLimitNum() + "</td>");
sb.append( "<td class=\"nl\" width = 22%>"+ s.getOrderUsers() + "</td>");
String note = s.getNote().replaceAll("<br data-mce-bogus=\"1\">","").replaceAll("<br>","").replaceAll("<p>", "").replaceAll("</p>", "<br/>");
sb.append( "<td class=\"nl\" width = 30%>"+ note + "</td>");
sb.append("</tr>");
sb.append("<body background = \"" + OrderTools.BG + "\" >");
// 显示LOGO && 场馆名 && 二维码
sb.append("<div id=\"qrcode\">"
+ "<img width=\"50\" height=\"50\" src=\"" + venue.getCodeUrl() + "\" />"
+ "</div>"
+ "<div id=\"venue\">" +
"<img width=\"200\" height=\"50\" src=\"" + OrderTools.LOGO
+ "\" /><span>"
+ venue.getName()
+ "预定信息</span></div>");
sb.append("<div id=\"coursesTable\"></div>");
sb.append("<script>");
sb.append("var week = " + JsonUtils.toJson(th)
.replaceAll("\"","'") + ";");
String courseType = OrderTools.COMMON_TYPE;
if (lessonTypes != null && lessonTypes.size() >= 0){
StringBuffer type = new StringBuffer();
type.append("[");
int temp = 1;
for (String t : lessonTypes){
if (temp != 1){
type.append(",");
}
type.append("[{index:" + temp + ",name:'" + t.substring(0,5) + "'},1]");
temp ++;
}
type.append("]");
courseType = type.toString();
}
sb.append("</table></body></html>");
sb.append("var courseType = " + courseType + ";");
String courseList = "[]";
if (lessonOrder != null && lessonOrder.size() >= 0){
int col = lessonTypes.size();
StringBuffer course = new StringBuffer();
course.append("[");
int temp1 = 1;
for (String d : th){
if (temp1 != 1){
course.append(",");
}
course.append("[");
temp1 ++;
List<VenueLessonStatus> theDay = lessonOrder.stream().filter(x -> d.equals(x.getSearchDate()))
.collect(Collectors.toList());
if (theDay != null && theDay.size() > 0){
int temp2 = 1;
for (String t : lessonTypes){
if (temp2 != 1){
course.append(",");
}
temp2 ++;
List<VenueLessonStatus> collect = theDay.stream().filter(y -> t.equals(y.getStartTime()))
.collect(Collectors.toList());
if (collect != null && collect.size()>0){
course.append(ForEachCourse(collect));
}else {
course.append("''");
}
}
}else {
course.append(getEmptyStr(col));
}
course.append("]");
}
course.append("]");
courseList = course.toString();
}
sb.append("var courseList = " + courseList + ";");
sb.append("// 实例化(初始化课表)\n" +
" var Timetable = new Timetables({\n" +
" el: '#coursesTable',\n" +
" timetables: courseList,\n" +
" week: week,\n" +
" timetableType: courseType,\n" +
" styles: {\n" +
" Gheight: 100\n" +
" }\n" +
" });");
sb.append("</script></body></html>");
return sb.toString();
}
private String ForEachCourse(List<VenueLessonStatus> collect) {
StringBuffer sb = new StringBuffer();
for (VenueLessonStatus v : collect){
sb.append("'" + v.getLessonName() + "(" + v.getStartTime().substring(0,5) + "-" + v.getEndTime().substring(0,5) + ")");
sb.append("【总计:" + v.getNum() + "" + (v.getLimitNum() == 0 ? "已约满】" : "剩余:" + v.getLimitNum()) + "");
sb.append("@预订用户:(" + v.getOrderUsers() + ")'");
}
return sb.toString();
}
private String getEmptyStr(int i) {
StringBuffer sb = new StringBuffer();
for (int j = 1 ; j < i; j ++){
sb.append("'',");
}
sb.append("''");
return sb.toString();
}