Commit a0c88fe0 authored by fengyasheng's avatar fengyasheng

查询一个路口的方案周期

parent d98b7b9d
package net.wanji.opt.controllerv2.judgeanalysis; package net.wanji.opt.controllerv2.judgeanalysis;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
...@@ -13,6 +14,7 @@ import net.wanji.databus.po.BaseAreaInfoPO; ...@@ -13,6 +14,7 @@ import net.wanji.databus.po.BaseAreaInfoPO;
import net.wanji.opt.controllerv2.judgeanalysis.design.response.crosssignal.CrossSignalPlanReasonResult; import net.wanji.opt.controllerv2.judgeanalysis.design.response.crosssignal.CrossSignalPlanReasonResult;
import net.wanji.opt.controllerv2.judgeanalysis.design.response.greenproblem.GreenCrossProblemTrendAnalysisResult; import net.wanji.opt.controllerv2.judgeanalysis.design.response.greenproblem.GreenCrossProblemTrendAnalysisResult;
import net.wanji.opt.servicev2.judgeanalysis.BaseAreaInfoService; import net.wanji.opt.servicev2.judgeanalysis.BaseAreaInfoService;
import net.wanji.opt.servicev2.judgeanalysis.CrossSignalPlanService;
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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -21,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -21,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* <p> * <p>
...@@ -33,6 +36,8 @@ import java.util.List; ...@@ -33,6 +36,8 @@ import java.util.List;
@Api(value="CrossSignalPlanController", description="路口信号方案查询", tags = "路口信号方案查询") @Api(value="CrossSignalPlanController", description="路口信号方案查询", tags = "路口信号方案查询")
public class CrossSignalPlanController { public class CrossSignalPlanController {
@Autowired
private CrossSignalPlanService crossSignalPlanService;
@ApiOperation(value = "路口信号方案查询", @ApiOperation(value = "路口信号方案查询",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON) produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
...@@ -48,7 +53,8 @@ public class CrossSignalPlanController { ...@@ -48,7 +53,8 @@ public class CrossSignalPlanController {
public JsonViewObject getByDateScope(String crossId,String startTime,String endTime) { public JsonViewObject getByDateScope(String crossId,String startTime,String endTime) {
JsonViewObject jsonViewObject = JsonViewObject.newInstance(); JsonViewObject jsonViewObject = JsonViewObject.newInstance();
try { try {
return jsonViewObject.success(); JSONObject jsonObject = crossSignalPlanService.getByDateScope(crossId,startTime,endTime);
return jsonViewObject.success(jsonObject);
} catch (Exception e) { } catch (Exception e) {
jsonViewObject.fail(I18nResourceBundle.getConstants("GET_FAILED_MSG")); jsonViewObject.fail(I18nResourceBundle.getConstants("GET_FAILED_MSG"));
log.error("{} getAll error", this.getClass().getSimpleName(), e); log.error("{} getAll error", this.getClass().getSimpleName(), e);
......
package net.wanji.opt.dao.mapper.judgeanalysis;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface CrossSignalPlanMapper {
List<Map<String, String>> getSpecialDate(@Param("crossId") String crossId);
List<Map<String, String>> getByDateScope(@Param("crossId") String crossId,@Param("weekNumber") Integer weekNumber);
List<Map<String, String>> getSpecialByDateScope(@Param("crossId") String crossId,@Param("planId") Integer planId);
}
package net.wanji.opt.servicev2.judgeanalysis;
import com.alibaba.fastjson.JSONObject;
public interface CrossSignalPlanService {
JSONObject getByDateScope(String crossId, String startTime, String endTime);
}
package net.wanji.opt.servicev2.judgeanalysis.impl;
import com.alibaba.fastjson.JSONObject;
import net.wanji.opt.dao.mapper.judgeanalysis.CrossSignalPlanMapper;
import net.wanji.opt.servicev2.judgeanalysis.CrossSignalPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service
public class CrossSignalPlanServiceImpl implements CrossSignalPlanService {
@Autowired
private CrossSignalPlanMapper crossSignalPlanMapper;
@Override
public JSONObject getByDateScope(String crossId, String startTime, String endTime) {
List<String> dateRange = generateDateRange(startTime, endTime);
//查询路口特殊日期
List<Map<String,String>> specialDates = crossSignalPlanMapper.getSpecialDate(crossId);
List<Map<String,String>> result = new ArrayList<>();
dateRange.forEach(x->{
//非特殊日期周期查询
if(ObjectUtils.isEmpty(specialDates)){
int weekNumber = getDayOfWeekNumber(x);
List<Map<String,String>> scopeList = crossSignalPlanMapper.getByDateScope(crossId,weekNumber);
scopeList.forEach(t->{
t.put("startTime",x+" "+t.get("startTime")+":00");
t.put("endTime",x+" "+t.get("endTime")+":00");
});
result.addAll(scopeList);
}else {
boolean specialBool = false;
for (Map<String, String> specialDate : specialDates) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String special_date = specialDate.get("special_date");
LocalDateTime specialTime = LocalDateTime.parse(special_date,formatter);
//特殊日期周期查询
if(x.equals(specialTime.format(formatter1))){
String planId = String.valueOf(specialDate.get("plan_id"));
List<Map<String,String>> scopeList = crossSignalPlanMapper.getSpecialByDateScope(crossId,Integer.valueOf(planId));
scopeList.forEach(t->{
t.put("startTime",x+" "+t.get("startTime")+":00");
t.put("endTime",x+" "+t.get("endTime")+":00");
});
result.addAll(scopeList);
specialBool = true;
break;
}
}
//非特殊日期周期查询
if(!specialBool){
int weekNumber = getDayOfWeekNumber(x);
List<Map<String,String>> scopeList = crossSignalPlanMapper.getByDateScope(crossId,weekNumber);
scopeList.forEach(t->{
t.put("startTime",x+" "+t.get("startTime")+":00");
t.put("endTime",x+" "+t.get("endTime")+":00");
});
result.addAll(scopeList);
}
}
});
JSONObject jsonObject = new JSONObject();
jsonObject.put("list",result);
return jsonObject;
}
/**
* 获取开始时间和结束时间之间的所有日期,格式为 yyyy-MM-dd HH:mm:ss
*
* @param startDate 开始时间(格式:yyyy-MM-dd HH:mm:ss)
* @param endDate 结束时间(格式:yyyy-MM-dd HH:mm:ss)
* @return 包含所有日期的 List<String>
*/
public static List<String> generateDateRange(String startDate, String endDate) {
List<String> dateList = new ArrayList<>();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// 将字符串解析为 LocalDate
LocalDateTime start = LocalDateTime.parse(startDate,formatter);
LocalDateTime end = LocalDateTime.parse(endDate,formatter);
// 遍历日期范围
while (!start.isAfter(end)) {
dateList.add(start.format(formatter1));
start = start.plusDays(1); // 增加一天
}
return dateList;
}
/**
* 获取指定日期是周几的数字表示(周一为 1,周日为 7)
*
* @param date 输入日期,格式为 yyyy-MM-dd
* @return 周几的数字(1 表示周一,7 表示周日)
*/
public static int getDayOfWeekNumber(String date) {
// 定义日期格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// 将字符串解析为 LocalDate
LocalDate localDate = LocalDate.parse(date, formatter);
// 获取周几
DayOfWeek dayOfWeek = localDate.getDayOfWeek();
// 返回数字表示(周一为 1,周日为 7)
return dayOfWeek.getValue(); // getValue() 返回 1(周一)到 7(周日)
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.wanji.opt.dao.mapper.judgeanalysis.CrossSignalPlanMapper">
<select id="getByDateScope" resultType="java.util.Map">
SELECT b.start_time as startTime,b.end_time as endTime,cycle from t_base_cross_schedules_plan as a LEFT JOIN t_base_cross_section as b on a.plan_id = b.plan_id LEFT JOIN t_base_cross_scheme as c on b.scheme_id = c.id where a.cross_id = #{crossId} and a.week = #{weekNumber} ORDER BY start_time
</select>
<select id="getSpecialDate" resultType="java.util.Map">
SELECT special_date,plan_id FROM t_base_cross_schedules_plan where cross_id = #{crossId} and week = 0
</select>
<select id="getSpecialByDateScope" resultType="java.util.Map">
SELECT b.start_time as startTime,b.end_time as endTime,cycle from t_base_cross_section as b LEFT JOIN t_base_cross_scheme as c on b.scheme_id = c.id where b.cross_id = #{crossId} and b.plan_id = #{planId} ORDER BY start_time
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment