Commit 494315b1 authored by hanbing's avatar hanbing

静态信息接口-计划数据-计划信息、时段信息

parent 1fc2f3c0
package net.wanji.utc.common.typeenum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Objects;
/**
* @author Kent HAN
* @date 2022/11/18 16:24
*/
@Getter
@AllArgsConstructor
public enum HkPlanSectionControlTypeEnum {
ZERO(1, 0),
ONE(5, 1),
TWO(3, 2),
THREE(4, 3),
FOUR(1, 4),
FIVE(2, 5),
SEVEN(7, 7),
EIGHT(8, 8),
TWELVE(-1, 12),
THIRTEEN(6, 13),
FOURTEEN(-1, 14),
FIFTEEN(-1, 15);
private Integer code;
private Integer hkCode;
public static Integer getCodeByHkCode(Integer hkCode) {
for (HkPlanSectionControlTypeEnum value : values()) {
if (Objects.equals(hkCode, value.getHkCode())) {
return value.getCode();
}
}
return null;
}
}
......@@ -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.PlanSectionInVO;
import net.wanji.utc.vo.SchemePhaseLightsInVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
......@@ -48,4 +49,12 @@ public class StaticInfoController {
staticInfoService.schemePhaseLights(schemePhaseLightsInVO);
return ResponseEntity.ok("success");
}
@PostMapping("/planSection")
@ApiOperation(value = "计划数据-计划信息、时段信息", notes = "计划数据-计划信息、时段信息")
public ResponseEntity planSection(HttpServletRequest request,
@RequestBody PlanSectionInVO planSectionInVO) throws Exception {
staticInfoService.planSection(planSectionInVO);
return ResponseEntity.ok("success");
}
}
package net.wanji.utc.mapper;
import net.wanji.utc.po.CrossPlanPO;
import org.apache.ibatis.annotations.Param;
/**
* @author Kent HAN
* @date 2022/11/18 15:57
*/
public interface CrossPlanMapper {
void deleteOne(@Param("crossId") String crossId, @Param("planNo") Integer planNo);
void insertOne(CrossPlanPO crossPlanPO);
}
......@@ -15,4 +15,7 @@ public interface CrossSchemeMapper {
void insertOne(CrossSchemePO crossSchemePO);
void deleteOne(@Param("crossId") String crossId, @Param("patternNo") String patternNo);
CrossSchemePO selectByCrossIdAndSchemeNo(@Param("crossId")String crossId,
@Param("schemeNo")Integer schemeNo);
}
package net.wanji.utc.mapper;
import net.wanji.utc.po.CrossSectionPO;
import org.apache.ibatis.annotations.Param;
/**
* @author Kent HAN
* @date 2022/11/18 16:46
*/
public interface CrossSectionMapper {
void deleteOne(@Param("crossId") String crossId,
@Param("timeSecNo") Integer timeSecNo);
void insertOne(CrossSectionPO crossSectionPO);
}
package net.wanji.utc.po;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author Kent HAN
* @date 2022/11/18 15:52
*/
@Data
public class CrossPlanPO {
/** 计划ID */
@ApiModelProperty(name = "计划ID",notes = "")
private Integer id ;
/** 计划号 */
@ApiModelProperty(name = "计划号",notes = "")
private String planNo ;
/** 计划名称 */
@ApiModelProperty(name = "计划名称",notes = "")
private String name ;
/** 路口ID */
@ApiModelProperty(name = "路口ID",notes = "")
private String crossId ;
/** 创建时间 */
@ApiModelProperty(name = "创建时间",notes = "")
private Date gmtCreate ;
/** 修改时间 */
@ApiModelProperty(name = "修改时间",notes = "")
private Date gmtModified ;
}
package net.wanji.utc.po;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author Kent HAN
* @date 2022/11/18 16:14
*/
@Data
public class CrossSectionPO {
/** 时段ID */
@ApiModelProperty(name = "时段ID",notes = "")
private Integer id ;
/** 时段号 */
@ApiModelProperty(name = "时段号",notes = "")
private String sectionNo ;
/** 开始时间 */
@ApiModelProperty(name = "开始时间",notes = "")
private String startTime ;
/** 结束时间 */
@ApiModelProperty(name = "结束时间",notes = "")
private String endTime ;
/** 路口ID */
@ApiModelProperty(name = "路口ID",notes = "")
private String crossId ;
/** 计划ID */
@ApiModelProperty(name = "计划ID",notes = "")
private Integer planId ;
/** 控制模式:1定周期;2绿波协调;3黄闪;4全红;5关灯;6单点自适应;7全感应;8半感应;9 */
@ApiModelProperty(name = "控制模式:1定周期;2绿波协调;3黄闪;4全红;5关灯;6单点自适应;7全感应;8半感应;9",notes = "")
private Integer controlMode ;
/** 方案ID */
@ApiModelProperty(name = "方案ID",notes = "")
private Integer scemeId ;
/** 创建时间 */
@ApiModelProperty(name = "创建时间",notes = "")
private Date gmtCreate ;
/** 修改时间 */
@ApiModelProperty(name = "修改时间",notes = "")
private Date gmtModified ;
}
package net.wanji.utc.service;
/**
* @author Kent HAN
* @date 2022/11/18 16:34
*/
public interface HkPlanSectionService {
void planSection(String crossCode, Integer planNo, String crossId) throws Exception;
}
......@@ -4,6 +4,7 @@ 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.DetailCrossInfoVO;
import net.wanji.utc.vo.PlanSectionInVO;
import net.wanji.utc.vo.SchemePhaseLightsInVO;
public interface StaticInfoService {
......@@ -11,4 +12,6 @@ public interface StaticInfoService {
ManufacturerRes<DetailCrossInfoVO> crossBasicInfo(OutVO<BaseCrossInfo> outVO);
void schemePhaseLights(SchemePhaseLightsInVO schemePhaseLightsInVO) throws Exception;
void planSection(PlanSectionInVO planSectionInVO) throws Exception;
}
package net.wanji.utc.service.impl;
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.common.typeenum.HkPlanSectionControlTypeEnum;
import net.wanji.utc.mapper.CrossPlanMapper;
import net.wanji.utc.mapper.CrossSchemeMapper;
import net.wanji.utc.mapper.CrossSectionMapper;
import net.wanji.utc.po.CrossPlanPO;
import net.wanji.utc.po.CrossSchemePO;
import net.wanji.utc.po.CrossSectionPO;
import net.wanji.utc.service.HkPlanSectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* @author Kent HAN
* @date 2022/11/18 16:34
*/
@Service
public class HkPlanSectionServiceImpl implements HkPlanSectionService {
@Value("${signal.manufacturer.hk.artemisPath}")
private String artemisPath;
@Autowired
private ArtemisConfig artemisConfig;
@Autowired
CrossPlanMapper crossPlanMapper;
@Autowired
CrossSchemeMapper crossSchemeMapper;
@Autowired
CrossSectionMapper crossSectionMapper;
@Override
public void planSection(String crossCode, Integer planNo, String crossId) throws Exception {
// 请求3.1.6接口,获取信号机计划
Map<String, String> path = getPathMapByApiCode("uploadPlan");
JSONObject dataEle = new JSONObject();
dataEle.put("crossCode", crossCode);
dataEle.put("planNo", planNo);
ArrayList<JSONObject> data = new ArrayList<>();
data.add(dataEle);
JSONObject requestContent = new JSONObject();
requestContent.put("data", data);
String body = requestContent.toJSONString();
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 responsedata = responseObj.getJSONArray("data");
for (int n = 0; n < responsedata.size(); n++) {
JSONObject responseDataEle = responsedata.getJSONObject(n);
JSONArray planList = responseDataEle.getJSONArray("planList");
for (int i = 0; i < planList.size(); i++) {
CrossPlanPO crossPlanPO = new CrossPlanPO();
JSONObject plan = planList.getJSONObject(i);
String responsePlanNo = plan.getString("planNo");
crossPlanPO.setPlanNo(responsePlanNo);
String name = plan.getString("planName");
crossPlanPO.setName(name);
crossPlanPO.setCrossId(crossId);
// 写入数据库
crossPlanMapper.deleteOne(crossId, Integer.parseInt(responsePlanNo));
crossPlanMapper.insertOne(crossPlanPO);
Integer crossPlanPOId = crossPlanPO.getId();
// 构造时段数据
JSONArray sectionList = plan.getJSONArray("sectionList");
for (int j = 0; j < sectionList.size(); j++) {
JSONObject section = sectionList.getJSONObject(j);
CrossSectionPO crossSectionPO = new CrossSectionPO();
String timeSecNo = section.getString("timeSecNo");
crossSectionPO.setSectionNo(timeSecNo);
String beginTime = section.getString("beginTime");
crossSectionPO.setStartTime(beginTime);
// 计算结束时间
if (j < sectionList.size() - 1) {
JSONObject nextSection = sectionList.getJSONObject(j + 1);
String endTime = nextSection.getString("beginTime");
crossSectionPO.setEndTime(endTime);
} else {
crossSectionPO.setEndTime("24:00");
}
crossSectionPO.setCrossId(crossId);
crossSectionPO.setPlanId(crossPlanPOId);
Integer controlType = section.getInteger("controlType");
controlType = HkPlanSectionControlTypeEnum.getCodeByHkCode(controlType);
crossSectionPO.setControlMode(controlType);
// 获取方案ID
Integer schemeNo = section.getInteger("patternNo");
CrossSchemePO crossSchemePO = crossSchemeMapper.selectByCrossIdAndSchemeNo(crossId, schemeNo);
Integer schemePOId = crossSchemePO.getId();
crossSectionPO.setScemeId(schemePOId);
// 写入数据库
crossSectionMapper.deleteOne(crossId, Integer.parseInt(timeSecNo));
crossSectionMapper.insertOne(crossSectionPO);
}
}
}
}
}
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;
}
}
......@@ -7,19 +7,10 @@ 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.common.typeenum.HkLightsDirEnum;
import net.wanji.utc.common.typeenum.HkLightsTurnEnum;
import net.wanji.utc.common.typeenum.HkLightsTypeEnum;
import net.wanji.utc.common.typeenum.*;
import net.wanji.utc.entity.cache.PhaseCache;
import net.wanji.utc.mapper.CrossLightsMapper;
import net.wanji.utc.mapper.CrossPhaseLightsMapper;
import net.wanji.utc.mapper.CrossPhaseMapper;
import net.wanji.utc.mapper.CrossSchemeMapper;
import net.wanji.utc.po.CrossLightsPO;
import net.wanji.utc.po.CrossPhaseLightsPO;
import net.wanji.utc.po.CrossPhasePO;
import net.wanji.utc.po.CrossSchemePO;
import net.wanji.utc.mapper.*;
import net.wanji.utc.po.*;
import net.wanji.utc.service.HkSchemePhaseLightsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......
......@@ -6,14 +6,12 @@ import net.wanji.utc.mapper.CrossInfoMapper;
import net.wanji.utc.mapper.ManufacturerInfoMapper;
import net.wanji.utc.po.CrossInfoPO;
import net.wanji.utc.po.ManufacturerInfoPO;
import net.wanji.utc.service.HkStaticInfoService;
import net.wanji.utc.service.OthersStaticInfoService;
import net.wanji.utc.service.HkSchemePhaseLightsService;
import net.wanji.utc.service.StaticInfoService;
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.DetailCrossInfoVO;
import net.wanji.utc.vo.PlanSectionInVO;
import net.wanji.utc.vo.SchemePhaseLightsInVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -38,6 +36,8 @@ public class StaticInfoServiceImpl implements StaticInfoService {
ManufacturerInfoMapper manufacturerInfoMapper;
@Autowired
HkSchemePhaseLightsService hkSchemePhaseLightsService;
@Autowired
HkPlanSectionService hkPlanSectionService;
@Override
public ManufacturerRes<DetailCrossInfoVO> crossBasicInfo(OutVO<BaseCrossInfo> outVO) {
......@@ -106,7 +106,25 @@ public class StaticInfoServiceImpl implements StaticInfoService {
hkSchemePhaseLightsService.hkSchemePhaseLights(crossId, crossCode);
} else {
// todo 其他厂商
}
}
@Override
public void planSection(PlanSectionInVO planSectionInVO) throws Exception {
String crossId = planSectionInVO.getCrossId();
// 获取厂商ID和信号机ID
CrossInfoPO crossInfoPO = crossInfoMapper.selectByPrimaryKey(crossId);
String crossCode = crossInfoPO.getCode();
Integer manufacturerId = crossInfoPO.getManufacturerId();
// 获取厂商缩写
ManufacturerInfoPO manufacturerInfoPO = manufacturerInfoMapper.selectById(manufacturerId);
String manufacturerAbbr = manufacturerInfoPO.getNickName();
Integer planNo = planSectionInVO.getPlanNo();
if (Objects.equals(BasicEnum.ManufacturerEnum.HK.getAbbr(), manufacturerAbbr)) {
// 海康
hkPlanSectionService.planSection(crossCode, planNo, crossId);
} else {
// todo 其他厂商
}
}
}
package net.wanji.utc.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author Kent HAN
* @date 2022/11/15 9:57
*/
@Data
@ApiModel(value = "PlanSectionInVO", description = "查询计划数据-计划信息、时段信息输入参数")
public class PlanSectionInVO {
@ApiModelProperty(value = "路口ID")
private String crossId;
@ApiModelProperty(value = "计划号,-1代表所有")
private Integer planNo;
}
<?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.CrossPlanMapper">
<resultMap type="net.wanji.utc.po.CrossPlanPO" id="BaseResultMap">
<result property="id" column="id"/>
<result property="planNo" column="plan_no"/>
<result property="name" column="name"/>
<result property="crossId" column="cross_id"/>
<result property="gmtCreate" column="gmt_create"/>
<result property="gmtModified" column="gmt_modified"/>
</resultMap>
<!--新增数据-->
<insert id="insertOne" keyProperty="id" useGeneratedKeys="true">
insert into t_cross_plan(plan_no,name,cross_id)
values (#{planNo},#{name},#{crossId})
</insert>
<delete id="deleteOne">
delete from t_cross_plan
where cross_id = #{crossId} and plan_no = #{planNo}
</delete>
</mapper>
......@@ -34,4 +34,11 @@
where cross_id = #{crossId} and scheme_no = #{patternNo}
</delete>
<select id="selectByCrossIdAndSchemeNo" resultMap="BaseResultMap">
select
id,scheme_no,name,cross_id,cycle,coord_phase,offset,source,is_deleted,gmt_create,gmt_modified
from t_cross_scheme
where cross_id = #{crossId} and scheme_no = #{schemeNo}
</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.CrossSectionMapper">
<resultMap type="net.wanji.utc.po.CrossSectionPO" id="BaseResultMap">
<result property="id" column="id"/>
<result property="sectionNo" column="section_no"/>
<result property="startTime" column="start_time"/>
<result property="endTime" column="end_time"/>
<result property="crossId" column="cross_id"/>
<result property="planId" column="plan_id"/>
<result property="controlMode" column="control_mode"/>
<result property="scemeId" column="sceme_id"/>
<result property="gmtCreate" column="gmt_create"/>
<result property="gmtModified" column="gmt_modified"/>
</resultMap>
<insert id="insertOne" keyProperty="id" useGeneratedKeys="true">
insert into t_cross_section(section_no,start_time,end_time,cross_id,plan_id,control_mode,sceme_id)
values (#{sectionNo},#{startTime},#{endTime},#{crossId},#{planId},#{controlMode},#{scemeId})
</insert>
<delete id="deleteOne">
delete from t_cross_section
where cross_id = #{crossId} and section_no = #{timeSecNo}
</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