Commit e8a16e03 authored by hanbing's avatar hanbing

静态信息接口-时间表数据

parent 494315b1
......@@ -7,6 +7,7 @@ import net.wanji.utc.vo.CrossInfoInVO;
import net.wanji.utc.common.genericentity.OutVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.wanji.utc.vo.CrossSchedulesInVO;
import net.wanji.utc.vo.PlanSectionInVO;
import net.wanji.utc.vo.SchemePhaseLightsInVO;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -57,4 +58,12 @@ public class StaticInfoController {
staticInfoService.planSection(planSectionInVO);
return ResponseEntity.ok("success");
}
@PostMapping("/crossSchedules")
@ApiOperation(value = "时间表数据", notes = "时间表数据")
public ResponseEntity crossSchedules(HttpServletRequest request,
@RequestBody CrossSchedulesInVO crossSchedulesInVO) throws Exception {
staticInfoService.crossSchedules(crossSchedulesInVO);
return ResponseEntity.ok("success");
}
}
......@@ -13,4 +13,8 @@ public interface CrossInfoMapper {
CrossInfoPO selectByPrimaryKey(@Param("key") String key);
void insertBatch(@Param("entities") List<CrossInfoPO> crossInfoPOList);
List<String> selectCrossCodesByIds(@Param("entities") List<String> crossIdList);
String selectIdByCode(@Param("crossCode")String crossCode);
}
......@@ -11,4 +11,6 @@ public interface CrossPlanMapper {
void deleteOne(@Param("crossId") String crossId, @Param("planNo") Integer planNo);
void insertOne(CrossPlanPO crossPlanPO);
Integer selectIdByNo(@Param("crossId")String crossId, @Param("planNo")Integer planNo);
}
package net.wanji.utc.mapper;
import net.wanji.utc.po.CrossSchedulesPO;
import org.apache.ibatis.annotations.Param;
import java.util.ArrayList;
/**
* @author Kent HAN
* @date 2022/11/18 18:58
*/
public interface CrossSchedulesMapper {
void deleteByCrossId(@Param("crossId") String crossId);
void insertBatch(@Param("entities") ArrayList<CrossSchedulesPO> crossSchedulesPOList);
}
package net.wanji.utc.po;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author Kent HAN
* @date 2022/11/18 18:37
*/
@Data
public class CrossSchedulesPO {
/** 日期ID */
@ApiModelProperty(name = "日期ID",notes = "")
private Integer id ;
/** 日期名称 */
@ApiModelProperty(name = "日期名称",notes = "")
private String name ;
/** 路口ID */
@ApiModelProperty(name = "路口ID",notes = "")
private String crossId ;
/** 计划ID */
@ApiModelProperty(name = "计划ID",notes = "")
private Integer planId ;
/** 星期:1周一;2周二,3周三,4周四,5周五,6周六,7周日,0特殊日期 */
@ApiModelProperty(name = "星期:1周一",notes = "2周二,3周三,4周四,5周五,6周六,7周日,0特殊日期")
private Integer week ;
/** 特殊日期 */
@ApiModelProperty(name = "特殊日期",notes = "")
private Date specialDate ;
/** 创建时间 */
@ApiModelProperty(name = "创建时间",notes = "")
private Date gmtCreate ;
/** 修改时间 */
@ApiModelProperty(name = "修改时间",notes = "")
private Date gmtModified ;
}
package net.wanji.utc.service;
import java.util.List;
/**
* @author Kent HAN
* @date 2022/11/18 17:19
*/
public interface HkCrossSchedulesService {
void crossSchedules(List<String> crossIdList) throws Exception;
}
......@@ -3,6 +3,7 @@ package net.wanji.utc.service;
import net.wanji.utc.common.baseentity.BaseCrossInfo;
import net.wanji.utc.common.genericentity.ManufacturerRes;
import net.wanji.utc.common.genericentity.OutVO;
import net.wanji.utc.vo.CrossSchedulesInVO;
import net.wanji.utc.vo.DetailCrossInfoVO;
import net.wanji.utc.vo.PlanSectionInVO;
import net.wanji.utc.vo.SchemePhaseLightsInVO;
......@@ -14,4 +15,6 @@ public interface StaticInfoService {
void schemePhaseLights(SchemePhaseLightsInVO schemePhaseLightsInVO) throws Exception;
void planSection(PlanSectionInVO planSectionInVO) throws Exception;
void crossSchedules(CrossSchedulesInVO crossSchedulesInVO) throws Exception;
}
package net.wanji.utc.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import net.wanji.utc.common.commonentity.HttpRequest;
import net.wanji.utc.common.constant.Constants;
import net.wanji.utc.common.typeenum.BasicEnum;
import net.wanji.utc.mapper.CrossInfoMapper;
import net.wanji.utc.mapper.CrossPlanMapper;
import net.wanji.utc.mapper.CrossSchedulesMapper;
import net.wanji.utc.po.CrossSchedulesPO;
import net.wanji.utc.service.HkCrossSchedulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* @author Kent HAN
* @date 2022/11/18 17:20
*/
@Service
public class HkCrossSchedulesServiceImpl implements HkCrossSchedulesService {
@Value("${signal.manufacturer.hk.artemisPath}")
private String artemisPath;
@Autowired
private ArtemisConfig artemisConfig;
@Autowired
CrossInfoMapper crossInfoMapper;
@Autowired
CrossPlanMapper crossPlanMapper;
@Autowired
CrossSchedulesMapper crossSchedulesMapper;
@Override
public void crossSchedules(List<String> crossIdList) throws Exception {
// 请求3.1.9接口,获取时间表
Map<String, String> path = getPathMapByApiCode("uploadDate");
List<String> crossCodeList = crossInfoMapper.selectCrossCodesByIds(crossIdList);
String body = JSONArray.toJSONString(crossCodeList);
String responseStr = ArtemisHttpUtil.doPostStringArtemis(artemisConfig, path, body, null,
null, "application/json", null);
JSONObject responseObj = JSON.parseObject(responseStr);
if(Constants.HK_SUCCESS_CODE.equals(responseObj.getInteger(Constants.HK_CODE_KEY))) {
JSONArray data = responseObj.getJSONArray("data");
for (int i = 0; i < data.size(); i++) {
ArrayList<CrossSchedulesPO> crossSchedulesPOList = new ArrayList<>();
JSONObject dataEle = data.getJSONObject(i);
JSONArray schedules = dataEle.getJSONArray("schedules");
String crossCode = dataEle.getString("crossCode");
String crossId = crossInfoMapper.selectIdByCode(crossCode);
for (int j = 0; j < schedules.size(); j++) {
JSONObject schedule = schedules.getJSONObject(j);
JSONArray weeks = schedule.getJSONArray("weeks");
String desc = schedule.getString("desc");
Integer planNo = schedule.getInteger("planNo");
Integer planId = crossPlanMapper.selectIdByNo(crossId, planNo);
for (int k = 0; k < weeks.size(); k++) {
Integer week = weeks.getInteger(k);
CrossSchedulesPO crossSchedulesPO = new CrossSchedulesPO();
crossSchedulesPO.setName(desc);
crossSchedulesPO.setCrossId(crossId);
crossSchedulesPO.setPlanId(planId);
crossSchedulesPO.setWeek(week);
if (week != 0) {
crossSchedulesPOList.add(crossSchedulesPO);
} else {
// 特殊日期
JSONArray dates = schedule.getJSONArray("dates");
for (int m = 0; m < dates.size(); m++) {
JSONObject date = dates.getJSONObject(m);
JSONArray days = date.getJSONArray("days");
for (int n = 0; n < days.size(); n++) {
Integer day = days.getInteger(n);
Date specialDate = toDate(date, day);
crossSchedulesPO.setSpecialDate(specialDate);
crossSchedulesPOList.add(crossSchedulesPO);
}
}
}
}
}
// 插入数据库
crossSchedulesMapper.deleteByCrossId(crossId);
crossSchedulesMapper.insertBatch(crossSchedulesPOList);
}
}
}
private Date toDate(JSONObject date, Integer dayInt) {
String year = date.getString("year");
String month = date.getString("month");
String day = dayInt.toString();
if (month.length() == 1) {
month = "0" + month;
}
if (day.length() == 1) {
day = "0" + day;
}
String dateStr = year + "-" + month + "-" + day;
Date parse = DateUtil.parse(dateStr);
return parse;
}
private Map<String, String> getPathMapByApiCode(String apiCode) {
Map<String, String> res = new HashMap<>();
HttpRequest httpRequest = new HttpRequest(BasicEnum.ManufacturerEnum.HK.getAbbr(), apiCode);
res.put("http://", artemisPath + httpRequest.getUrl());
return res;
}
}
......@@ -10,6 +10,7 @@ import net.wanji.utc.service.*;
import net.wanji.utc.common.baseentity.BaseCrossInfo;
import net.wanji.utc.common.genericentity.OutVO;
import net.wanji.utc.util.ListUtil;
import net.wanji.utc.vo.CrossSchedulesInVO;
import net.wanji.utc.vo.DetailCrossInfoVO;
import net.wanji.utc.vo.PlanSectionInVO;
import net.wanji.utc.vo.SchemePhaseLightsInVO;
......@@ -38,6 +39,8 @@ public class StaticInfoServiceImpl implements StaticInfoService {
HkSchemePhaseLightsService hkSchemePhaseLightsService;
@Autowired
HkPlanSectionService hkPlanSectionService;
@Autowired
HkCrossSchedulesService hkCrossSchedulesService;
@Override
public ManufacturerRes<DetailCrossInfoVO> crossBasicInfo(OutVO<BaseCrossInfo> outVO) {
......@@ -127,4 +130,17 @@ public class StaticInfoServiceImpl implements StaticInfoService {
// todo 其他厂商
}
}
@Override
public void crossSchedules(CrossSchedulesInVO crossSchedulesInVO) throws Exception {
String manufacturerAbbr = crossSchedulesInVO.getManufacturerAbbr();
List<String> crossIdList = crossSchedulesInVO.getCrossIdList();
if (Objects.equals(BasicEnum.ManufacturerEnum.HK.getAbbr(), manufacturerAbbr)) {
// 海康
hkCrossSchedulesService.crossSchedules(crossIdList);
} else {
// todo 其他厂商
}
}
}
package net.wanji.utc.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author Kent HAN
* @date 2022/11/18 17:15
*/
@Data
@ApiModel(value = "CrossSchedulesInVO", description = "查询时间表数据输入参数")
public class CrossSchedulesInVO {
@ApiModelProperty(value = "厂商缩写 HK-海康")
String manufacturerAbbr;
@ApiModelProperty(value = "路口列表")
List<String> crossIdList;
}
......@@ -31,4 +31,19 @@
from t_cross_info
where id = #{key}
</select>
<select id="selectCrossCodesByIds" resultType="java.lang.String">
select code
from t_cross_info
where id in
<foreach collection="entities" item="entity" separator="," open="(" close=")">
#{entity}
</foreach>
</select>
<select id="selectIdByCode" resultType="java.lang.String">
select id
from t_cross_info
where code = #{crossCode}
</select>
</mapper>
......@@ -21,5 +21,11 @@
where cross_id = #{crossId} and plan_no = #{planNo}
</delete>
<select id="selectIdByNo" resultType="java.lang.Integer">
select id
from t_cross_plan
where cross_id = #{crossId} and plan_no = #{planNo}
</select>
</mapper>
<?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.utc.mapper.CrossSchedulesMapper">
<resultMap type="net.wanji.utc.po.CrossSchedulesPO" id="BaseResultMap">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="crossId" column="cross_id"/>
<result property="planId" column="plan_id"/>
<result property="week" column="week"/>
<result property="specialDate" column="special_date"/>
<result property="gmtCreate" column="gmt_create"/>
<result property="gmtModified" column="gmt_modified"/>
</resultMap>
<!-- 批量新增数据 -->
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into t_cross_schedules(name,cross_id,plan_id,week,special_date)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.name},#{entity.crossId},#{entity.planId},#{entity.week},#{entity.specialDate})
</foreach>
</insert>
<delete id="deleteByCrossId">
delete from t_cross_schedules
where cross_id = #{crossId}
</delete>
</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