|
@@ -1,27 +1,179 @@
|
|
|
package com.ch.jiaoxuelou_houtai.controller;
|
|
package com.ch.jiaoxuelou_houtai.controller;
|
|
|
|
|
|
|
|
-import com.alibaba.fastjson2.JSON;
|
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.ch.jiaoxuelou_houtai.core.ResponseResult;
|
|
import com.ch.jiaoxuelou_houtai.core.ResponseResult;
|
|
|
-import com.ch.jiaoxuelou_houtai.service.ApiService;
|
|
|
|
|
|
|
+import com.ch.jiaoxuelou_houtai.entity.Course;
|
|
|
|
|
+import com.ch.jiaoxuelou_houtai.entity.User;
|
|
|
|
|
+import com.ch.jiaoxuelou_houtai.service.CourseService;
|
|
|
|
|
+import com.ch.jiaoxuelou_houtai.service.UserService;
|
|
|
|
|
+import com.ch.jiaoxuelou_houtai.util.DateTimeUtil;
|
|
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+import javax.swing.*;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
|
-@RequestMapping("/thapi")
|
|
|
|
|
|
|
+@RequestMapping("/api")
|
|
|
public class ApiController {
|
|
public class ApiController {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private ApiService apiService;
|
|
|
|
|
|
|
+ private CourseService courseService;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 教室使用情况
|
|
|
|
|
+ * @param jsonObject
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "/theClassrooms", method = RequestMethod.GET)
|
|
|
|
|
+ public ResponseResult getNumOfUsingClassRoom(@RequestBody JSONObject jsonObject) {
|
|
|
|
|
+ // 如:博学楼
|
|
|
|
|
+ String building = jsonObject.getString("building");
|
|
|
|
|
+ // 获取必要的参数
|
|
|
|
|
+ Map<String, String> params = getParams();
|
|
|
|
|
+ String schoolYear = params.get("schoolYear");
|
|
|
|
|
+ String semester = params.get("semester");
|
|
|
|
|
+ String weeks = params.get("weeks");
|
|
|
|
|
+ String week = params.get("week");
|
|
|
|
|
+
|
|
|
|
|
+ DateTimeUtil dateTimeUtil = new DateTimeUtil();
|
|
|
|
|
+ // 获取第几节课
|
|
|
|
|
+ String section;
|
|
|
|
|
+ if (dateTimeUtil.campareTime("8:50", "9:30"))
|
|
|
|
|
+ section = "1-";
|
|
|
|
|
+ else if (dateTimeUtil.campareTime("9:35", "10:15"))
|
|
|
|
|
+ section = "-2";
|
|
|
|
|
+ else if (dateTimeUtil.campareTime("10:30", "11:20"))
|
|
|
|
|
+ section = "3-";
|
|
|
|
|
+ else if (dateTimeUtil.campareTime("11:20", "12:05"))
|
|
|
|
|
+ section = "-4";
|
|
|
|
|
+ else if (dateTimeUtil.campareTime("14:00", "14:40"))
|
|
|
|
|
+ section = "5-";
|
|
|
|
|
+ else if (dateTimeUtil.campareTime("14:45", "15:25"))
|
|
|
|
|
+ section = "-6";
|
|
|
|
|
+ else if (dateTimeUtil.campareTime("15:40", "16:20"))
|
|
|
|
|
+ section = "7-";
|
|
|
|
|
+ else if (dateTimeUtil.campareTime("16:25", "17:05"))
|
|
|
|
|
+ section = "-8";
|
|
|
|
|
+ else if (dateTimeUtil.campareTime("18:30", "20:40"))
|
|
|
|
|
+ section = "9-";
|
|
|
|
|
+ else
|
|
|
|
|
+ section = "未使用";
|
|
|
|
|
+ // 获取正在使用的教室总数量
|
|
|
|
|
+ int numOfUsingClassRoom = courseService.getNumOfUsingClassRoom(building, schoolYear, semester, weeks, week, section);
|
|
|
|
|
+ // 获取教室总数量
|
|
|
|
|
+ int totalOfClassRoom = courseService.getTotalOfClassRoom(building);
|
|
|
|
|
+ // 使用中的教室百分比
|
|
|
|
|
+ double totalUsingPercent = (numOfUsingClassRoom / (double) totalOfClassRoom) * 100;
|
|
|
|
|
+ totalUsingPercent = (double) Math.round(totalUsingPercent * 100) / 100;
|
|
|
|
|
+ // 未使用的百分比
|
|
|
|
|
+ double totalUnusingPercent = ((totalOfClassRoom - numOfUsingClassRoom) / (double) totalOfClassRoom) * 100;
|
|
|
|
|
+ totalUnusingPercent = (double) Math.round(totalUnusingPercent * 100) / 100;
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Double> returnMap = new HashMap<>();
|
|
|
|
|
+ returnMap.put("total", (double) totalOfClassRoom);
|
|
|
|
|
+ returnMap.put("totalUsing", (double) numOfUsingClassRoom);
|
|
|
|
|
+ returnMap.put("totalUsingPercent", totalUsingPercent);
|
|
|
|
|
+ returnMap.put("totalUnusing", (double) (totalOfClassRoom - numOfUsingClassRoom));
|
|
|
|
|
+ returnMap.put("totalUnusingPercent", totalUnusingPercent);
|
|
|
|
|
+
|
|
|
|
|
+ return ResponseResult.success(returnMap);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 教室排课表
|
|
|
|
|
+ * @param jsonObject
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "/listCourse", method = RequestMethod.GET)
|
|
|
|
|
+ public ResponseResult listCourse(@RequestBody JSONObject jsonObject) {
|
|
|
|
|
+ int pageNum = jsonObject.getInteger("pageNum");
|
|
|
|
|
+ int pageSize = jsonObject.getInteger("pageSize");
|
|
|
|
|
+ // 如:博学楼
|
|
|
|
|
+ String building = jsonObject.getString("building");
|
|
|
|
|
+ // 获取必要的参数
|
|
|
|
|
+ Map<String, String> params = getParams();
|
|
|
|
|
+ String schoolYear = params.get("schoolYear");
|
|
|
|
|
+ String semester = params.get("semester");
|
|
|
|
|
+ String weeks = params.get("weeks");
|
|
|
|
|
+ String week = params.get("week");
|
|
|
|
|
+
|
|
|
|
|
+ DateTimeUtil dateTimeUtil = new DateTimeUtil();
|
|
|
|
|
+ // 获取第几节课
|
|
|
|
|
+ String section;
|
|
|
|
|
+ if (dateTimeUtil.campareTime("0:00", "9:30"))
|
|
|
|
|
+ section = "1-";
|
|
|
|
|
+ else if (dateTimeUtil.campareTime("9:30", "10:15"))
|
|
|
|
|
+ section = "-2";
|
|
|
|
|
+ else if (dateTimeUtil.campareTime("10:15", "11:15"))
|
|
|
|
|
+ section = "3-";
|
|
|
|
|
+ else if (dateTimeUtil.campareTime("11:15", "12:05"))
|
|
|
|
|
+ section = "-4";
|
|
|
|
|
+ else if (dateTimeUtil.campareTime("12:05", "14:40"))
|
|
|
|
|
+ section = "5-";
|
|
|
|
|
+ else if (dateTimeUtil.campareTime("14:40", "15:25"))
|
|
|
|
|
+ section = "-6";
|
|
|
|
|
+ else if (dateTimeUtil.campareTime("15:25", "16:20"))
|
|
|
|
|
+ section = "7-";
|
|
|
|
|
+ else if (dateTimeUtil.campareTime("16:20", "17:05"))
|
|
|
|
|
+ section = "-8";
|
|
|
|
|
+ else
|
|
|
|
|
+ section = "9-";
|
|
|
|
|
|
|
|
- @GetMapping("/api")
|
|
|
|
|
- public ResponseResult callApi(@RequestParam(value = "page", defaultValue = "1") int page,
|
|
|
|
|
- @RequestParam(value = "rows", defaultValue = "10") int rows) throws IOException {
|
|
|
|
|
- String url = "https://chtech.ncjti.edu.cn/air-conditioner-control/airManage/buildqueryEnergyRank.action";
|
|
|
|
|
- return ResponseResult.success(JSON.parse(apiService.callApi(url, page, rows)));
|
|
|
|
|
|
|
+ // 执行查询获取结果
|
|
|
|
|
+ PageInfo<Course> courses = courseService.listCourse(pageNum, pageSize, building, schoolYear, semester, weeks, week, section);
|
|
|
|
|
+
|
|
|
|
|
+ return ResponseResult.success(courses);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private Map<String, String> getParams() {
|
|
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
|
|
+ // 获取开学时间
|
|
|
|
|
+ String termBeginsTime = courseService.getTermBeginsTime();
|
|
|
|
|
+
|
|
|
|
|
+ // 获取年月日周
|
|
|
|
|
+ DateTimeUtil dateTimeUtil = new DateTimeUtil();
|
|
|
|
|
+ Map<String, Integer> dateTime = dateTimeUtil.getDateTime(termBeginsTime);
|
|
|
|
|
+ int year = dateTime.get("year");
|
|
|
|
|
+ int month = dateTime.get("month");
|
|
|
|
|
+ int weeks = dateTime.get("weeks");
|
|
|
|
|
+ int week = dateTime.get("week");
|
|
|
|
|
+
|
|
|
|
|
+ // 获取学年、学期
|
|
|
|
|
+ String schoolYear, semester;
|
|
|
|
|
+ if (month >= 2 && month <= 7) {
|
|
|
|
|
+ schoolYear = (year - 1) + "-" + year;
|
|
|
|
|
+ semester = "2";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ schoolYear = year + "-" + (year + 1);
|
|
|
|
|
+ semester = "1";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ map.put("schoolYear", schoolYear);
|
|
|
|
|
+ map.put("semester", semester);
|
|
|
|
|
+ map.put("weeks", String.valueOf(weeks));
|
|
|
|
|
+ map.put("week", String.valueOf(week));
|
|
|
|
|
+
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 调整开学日期,用于获取当前是第几周
|
|
|
|
|
+ * @param jsonObject
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "/updateTermBeginsDate", method = RequestMethod.GET)
|
|
|
|
|
+ public ResponseResult updateTermBeginsDate(@RequestBody JSONObject jsonObject) {
|
|
|
|
|
+ String date = jsonObject.getString("termBeginsDate");
|
|
|
|
|
+ int row = courseService.updateTermBeginsDate(date);
|
|
|
|
|
+ if (row > 0)
|
|
|
|
|
+ return ResponseResult.success("开学日期更新成功!");
|
|
|
|
|
+
|
|
|
|
|
+ return ResponseResult.failed("开学日期更新失败!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|