Commit 63837ff2 authored by zhouleilei's avatar zhouleilei

Merge remote-tracking branch 'origin/master'

parents 25b55bf1 b5de02c9
package net.wanji.opt.config;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author duanruiming
* @date 2024/11/04 18:44
*/
@Configuration
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return interceptor;
}
}
package net.wanji.opt.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.opt.po.StrategyControlDataEntity;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author duanruiming
* @date 2024/11/04 10:57
*/
public interface StrategyControlInfoMapper extends BaseMapper<StrategyControlDataEntity> {
int insertBatch(@Param("list") List<StrategyControlDataEntity> list);
}
package net.wanji.opt.po;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import net.wanji.databus.vo.PageVO;
import java.util.Date;
/**
* @author duanruiming
* @date 2024/11/04 10:53
*/
@Data
@TableName("t_strategy_control_info")
public class StrategyControlDataEntity extends PageVO {
/** value = 路口干线Id */
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@TableField("biz_id")
private String bizId;
/** value = 类型 0-路口 1-干线 */
@TableField("biz_type")
private Integer bizType;
/** value = 策略类型 0-绿波带 1-失衡 2-溢出 3-空放 */
private Integer strategy;
/** value = 开始时间日期 */
@TableField("schedule_start")
private Date scheduleStart;
/** value = 结束时间日期 */
@TableField("schedule_end")
private Date scheduleEnd;
/** value = 日计划表 */
private String time;
/** value = 调控频率(秒),策略下发的频率(只针对失衡和绿波带有效) */
private Integer frequency;
/** value = 状态(1=开启,0=停止) */
private Integer status;
}
...@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiOperation; ...@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses; import io.swagger.annotations.ApiResponses;
import net.wanji.common.framework.rest.JsonViewObject; import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.opt.po.StrategyControlDataEntity;
import net.wanji.opt.synthesis.pojo.StrategyControlVO; import net.wanji.opt.synthesis.pojo.StrategyControlVO;
import net.wanji.opt.synthesis.service.StrategyControlService; import net.wanji.opt.synthesis.service.StrategyControlService;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
...@@ -39,4 +40,17 @@ public class StrategyControlController { ...@@ -39,4 +40,17 @@ public class StrategyControlController {
public JsonViewObject strategyInfoOperation(@RequestBody StrategyControlVO strategyControlVO) throws Exception { public JsonViewObject strategyInfoOperation(@RequestBody StrategyControlVO strategyControlVO) throws Exception {
return strategyControlService.strategyInfoOperation(strategyControlVO); return strategyControlService.strategyInfoOperation(strategyControlVO);
} }
@ApiOperation(value = "策略控制信息分页查询", notes = "策略控制信息分页查询",
response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/strategyInfoPageList",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = StrategyControlDataEntity.class),
})
public JsonViewObject strategyInfoPageList(@RequestBody StrategyControlDataEntity entity) throws Exception {
return strategyControlService.strategyInfoPageList(entity);
}
} }
...@@ -15,6 +15,8 @@ import java.util.List; ...@@ -15,6 +15,8 @@ import java.util.List;
@Data @Data
@ApiModel(value = "StrategyControlDataVO", description = "策略控制操作数据实体") @ApiModel(value = "StrategyControlDataVO", description = "策略控制操作数据实体")
public class StrategyControlDataVO { public class StrategyControlDataVO {
@ApiModelProperty(value = "id")
private Integer id;
@ApiModelProperty(value = "路口干线Id") @ApiModelProperty(value = "路口干线Id")
private String bizId; private String bizId;
@ApiModelProperty(value = "类型 0-路口 1-干线") @ApiModelProperty(value = "类型 0-路口 1-干线")
...@@ -28,7 +30,7 @@ public class StrategyControlDataVO { ...@@ -28,7 +30,7 @@ public class StrategyControlDataVO {
@ApiModelProperty(value = "日计划表") @ApiModelProperty(value = "日计划表")
private List<StrategyControlDataVO.TimeTable> time; private List<StrategyControlDataVO.TimeTable> time;
@ApiModelProperty(value = "调控频率(秒),策略下发的频率(只针对失衡和绿波带有效)") @ApiModelProperty(value = "调控频率(秒),策略下发的频率(只针对失衡和绿波带有效)")
private Integer freq; private Integer frequency;
@ApiModelProperty(value = "状态(1=开启,0=停止)") @ApiModelProperty(value = "状态(1=开启,0=停止)")
private Integer status; private Integer status;
@ApiModelProperty(value = "操作(insert=新增,update=更新,delete=删除)") @ApiModelProperty(value = "操作(insert=新增,update=更新,delete=删除)")
......
...@@ -8,8 +8,5 @@ import net.wanji.opt.synthesis.pojo.StrategyControlReq; ...@@ -8,8 +8,5 @@ import net.wanji.opt.synthesis.pojo.StrategyControlReq;
* @date 2024/11/03 14:06 * @date 2024/11/03 14:06
*/ */
public interface PushStrategyControlService { public interface PushStrategyControlService {
void insert();
void update();
void delete();
Result push(StrategyControlReq req) throws Exception; Result push(StrategyControlReq req) throws Exception;
} }
package net.wanji.opt.synthesis.service; package net.wanji.opt.synthesis.service;
import net.wanji.common.framework.rest.JsonViewObject; import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.opt.po.StrategyControlDataEntity;
import net.wanji.opt.synthesis.pojo.StrategyControlVO; import net.wanji.opt.synthesis.pojo.StrategyControlVO;
/** /**
...@@ -9,4 +10,6 @@ import net.wanji.opt.synthesis.pojo.StrategyControlVO; ...@@ -9,4 +10,6 @@ import net.wanji.opt.synthesis.pojo.StrategyControlVO;
*/ */
public interface StrategyControlService { public interface StrategyControlService {
JsonViewObject strategyInfoOperation(StrategyControlVO strategyControlVO) throws Exception; JsonViewObject strategyInfoOperation(StrategyControlVO strategyControlVO) throws Exception;
JsonViewObject strategyInfoPageList(StrategyControlDataEntity entity) throws Exception;
} }
...@@ -7,10 +7,8 @@ import net.wanji.common.utils.tool.JacksonUtils; ...@@ -7,10 +7,8 @@ import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.opt.synthesis.pojo.Result; import net.wanji.opt.synthesis.pojo.Result;
import net.wanji.opt.synthesis.pojo.StrategyControlReq; import net.wanji.opt.synthesis.pojo.StrategyControlReq;
import net.wanji.opt.synthesis.service.PushStrategyControlService; import net.wanji.opt.synthesis.service.PushStrategyControlService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.Objects;
/** /**
* @author duanruiming * @author duanruiming
...@@ -20,32 +18,14 @@ import java.util.Objects; ...@@ -20,32 +18,14 @@ import java.util.Objects;
@Slf4j @Slf4j
public class PushStrategyControlServiceImpl implements PushStrategyControlService { public class PushStrategyControlServiceImpl implements PushStrategyControlService {
@Override
public void insert() {
}
@Override
public void update() {
}
@Override
public void delete() {
}
@Override @Override
public Result push(StrategyControlReq req) throws Exception { public Result push(StrategyControlReq req) throws Exception {
String url = ""; String url = "";
try { try {
ObjectMapper mapper = JacksonUtils.getInstance(); ObjectMapper mapper = JacksonUtils.getInstance();
String resultStr = RestTemplateTool.post(url, mapper.writeValueAsString(req)); String resultStr = RestTemplateTool.post(url, mapper.writeValueAsString(req));
Result result = mapper.readValue(resultStr, Result.class); if (StringUtils.isNotBlank(resultStr)) {
if (Objects.nonNull(result)) { Result result = mapper.readValue(resultStr, Result.class);
if (StringUtils.endsWithIgnoreCase("200", result.getCode())) {
return result;
}
return result; return result;
} else { } else {
log.error("策略推送url:{}失败:返回数据异常", url); log.error("策略推送url:{}失败:返回数据异常", url);
......
package net.wanji.opt.synthesis.service.impl; package net.wanji.opt.synthesis.service.impl;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.alibaba.druid.util.StringUtils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.wanji.common.enums.DateStyle; import net.wanji.common.enums.DateStyle;
import net.wanji.common.framework.Constants; import net.wanji.common.framework.Constants;
import net.wanji.common.framework.rest.JsonViewObject; import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.common.utils.tool.JacksonUtils; import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.opt.dao.mapper.StrategyControlInfoMapper;
import net.wanji.opt.po.StrategyControlDataEntity;
import net.wanji.opt.synthesis.pojo.*; import net.wanji.opt.synthesis.pojo.*;
import net.wanji.opt.synthesis.service.PushStrategyControlService; import net.wanji.opt.synthesis.service.PushStrategyControlService;
import net.wanji.opt.synthesis.service.StrategyControlService; import net.wanji.opt.synthesis.service.StrategyControlService;
import org.springframework.beans.factory.annotation.Autowired; import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.*; import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/** /**
* @author duanruiming * @author duanruiming
...@@ -24,36 +33,19 @@ import java.util.*; ...@@ -24,36 +33,19 @@ import java.util.*;
@Service @Service
public class StrategyControlServiceImpl implements StrategyControlService { public class StrategyControlServiceImpl implements StrategyControlService {
@Autowired @Resource
private PushStrategyControlService pushStrategyControlService; private PushStrategyControlService pushStrategyControlService;
@Resource
private StrategyControlInfoMapper strategyControlInfoMapper;
@Override @Override
public JsonViewObject strategyInfoOperation(StrategyControlVO strategyControlVO) throws Exception { public JsonViewObject strategyInfoOperation(StrategyControlVO strategyControlVO) throws Exception {
try { try {
StrategyControlReq req = convertReq(strategyControlVO);
// 存库 // 存库
// 调用推送 insertAndUpdate(strategyControlVO);
//StrategyControlDataReq detailData = new StrategyControlDataReq();
//detailData.setBiz_id("241940");
//detailData.setBiz_type(0);
//detailData.setStrategy(3);
//Date date = new Date();
//detailData.setSchedule_end(DateUtil.format(date, DateStyle.YYYY_MM_DD_HH_MM_SS.getValue()));
//detailData.setSchedule_end(DateUtil.format(date, DateStyle.YYYY_MM_DD_HH_MM_SS.getValue()));
//StrategyControlDataReq.Time_table timeTable = new StrategyControlDataReq.Time_table();
//timeTable.setWeek(1);
//timeTable.setTime_list(new String[]{"00:00-01:00", "01:00-02:00"});
//StrategyControlDataReq.Time_table timeTable1 = new StrategyControlDataReq.Time_table();
//timeTable1.setWeek(1);
//timeTable1.setTime_list(new String[]{"02:00-03:00", "03:00-04:00"});
//detailData.setTime(Arrays.asList(timeTable1, timeTable));
//detailData.setFreq(1000 * 60);
//detailData.setStrategy(1);
//detailData.setAction("insert");
// todo 测试数据 StrategyControlReq req = convertReq(strategyControlVO);
//req.setData(Arrays.asList(detailData));
Result result = pushStrategyControlService.push(req); Result result = pushStrategyControlService.push(req);
if (Objects.nonNull(result)) { if (Objects.nonNull(result)) {
JsonViewObject jsonViewObject = JsonViewObject.newInstance(); JsonViewObject jsonViewObject = JsonViewObject.newInstance();
...@@ -71,6 +63,22 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -71,6 +63,22 @@ public class StrategyControlServiceImpl implements StrategyControlService {
} }
} }
private void insertAndUpdate(StrategyControlVO strategyControlVO) throws IllegalAccessException, InvocationTargetException, JsonProcessingException {
List<StrategyControlDataVO> dataList = strategyControlVO.getDataList();
for (StrategyControlDataVO dataVO : dataList) {
StrategyControlDataEntity entity = new StrategyControlDataEntity();
BeanUtils.copyProperties(entity, dataVO);
entity.setTime(JacksonUtils.getInstance().writeValueAsString(dataVO.getTime()));
if (StringUtils.equals("insert", dataVO.getAction())) {
strategyControlInfoMapper.insert(entity);
} else if (StringUtils.equals("update", dataVO.getAction())) {
strategyControlInfoMapper.updateById(entity);
} else if (StringUtils.equals("delete", dataVO.getAction())) {
strategyControlInfoMapper.deleteById(entity);
}
}
}
private StrategyControlReq convertReq(StrategyControlVO vo) throws Exception { private StrategyControlReq convertReq(StrategyControlVO vo) throws Exception {
try { try {
List<StrategyControlDataVO> dataList = vo.getDataList(); List<StrategyControlDataVO> dataList = vo.getDataList();
...@@ -93,7 +101,7 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -93,7 +101,7 @@ public class StrategyControlServiceImpl implements StrategyControlService {
timeTables.add(timeTable); timeTables.add(timeTable);
}); });
detailData.setTime(timeTables); detailData.setTime(timeTables);
detailData.setFreq(dataVO.getFreq()); detailData.setFreq(dataVO.getFrequency());
detailData.setStatus(dataVO.getStatus()); detailData.setStatus(dataVO.getStatus());
detailData.setAction(dataVO.getAction()); detailData.setAction(dataVO.getAction());
dataReqList.add(detailData); dataReqList.add(detailData);
...@@ -107,33 +115,23 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -107,33 +115,23 @@ public class StrategyControlServiceImpl implements StrategyControlService {
} }
} }
@Override
public static void main(String[] args) throws Exception { public JsonViewObject strategyInfoPageList(StrategyControlDataEntity entity) throws Exception {
LambdaQueryWrapper<StrategyControlDataEntity> queryWrapper = new LambdaQueryWrapper<>();
StrategyControlDataReq detailData = new StrategyControlDataReq(); if (StringUtils.isNotBlank(entity.getBizId())) {
detailData.setBiz_id("241940"); queryWrapper.eq(StrategyControlDataEntity::getBizId, entity.getBizId());
detailData.setBiz_type(0); }
detailData.setStrategy(3); if (Objects.nonNull(entity.getBizType())) {
Date date = new Date(); queryWrapper.eq(StrategyControlDataEntity::getBizType, entity.getBizType());
detailData.setSchedule_start(DateUtil.format(date, DateStyle.YYYY_MM_DD_HH_MM_SS.getValue())); }
detailData.setSchedule_end(DateUtil.format(date, DateStyle.YYYY_MM_DD_HH_MM_SS.getValue())); if (Objects.nonNull(entity.getStrategy())) {
StrategyControlDataReq.Time_table timeTable = new StrategyControlDataReq.Time_table(); queryWrapper.eq(StrategyControlDataEntity::getStrategy, entity.getStrategy());
timeTable.setWeek(1); }
timeTable.setTime_list(new String[]{"00:00-01:00", "01:00-02:00"}); if (Objects.nonNull(entity.getStatus())) {
StrategyControlDataReq.Time_table timeTable1 = new StrategyControlDataReq.Time_table(); queryWrapper.eq(StrategyControlDataEntity::getStatus, entity.getStatus());
timeTable1.setWeek(2); }
timeTable1.setTime_list(new String[]{"02:00-03:00", "03:00-04:00"}); Page<StrategyControlDataEntity> page = new Page<>(entity.getPageNum(), entity.getPageSize());
detailData.setTime(Arrays.asList(timeTable1, timeTable)); Page<StrategyControlDataEntity> pageInfo = strategyControlInfoMapper.selectPage(page, queryWrapper);
detailData.setFreq(1000 * 60); return JsonViewObject.newInstance().success(pageInfo.getRecords());
detailData.setStatus(1);
detailData.setAction("insert");
// todo 测试数据
StrategyControlReq req = new StrategyControlReq();
req.setData(Arrays.asList(detailData));
System.err.println(JacksonUtils.getInstance().writeValueAsString(req));
System.err.println(new Date());
} }
} }
<?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.StrategyControlInfoMapper">
<insert id="insertBatch" parameterType="net.wanji.opt.po.StrategyControlDataEntity">
INSERT INTO t_strategy_control_info (
biz_id,
biz_type,
strategy,
schedule_start,
schedule_end,
`time`,
frequency,
status
) VALUES
<foreach collection="list" item="entity" separator=",">
(#{entity.bizId},
#{entity.bizType},
#{entity.strategy},
#{entity.scheduleStart},
#{entity.scheduleEnd},
#{entity.time},
#{entity.frequency},
#{entity.status})
</foreach>
</insert>
</mapper>
\ No newline at end of file
package net.wanji.utc.hisense; package net.wanji.utc.hisense;
import net.wanji.utc.hisense.netty.TcpClient;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
......
...@@ -5,7 +5,6 @@ import net.wanji.utc.hisense.netty.pojo.CommandPojo; ...@@ -5,7 +5,6 @@ import net.wanji.utc.hisense.netty.pojo.CommandPojo;
import net.wanji.utc.hisense.netty.request.CommandRequestFactory; import net.wanji.utc.hisense.netty.request.CommandRequestFactory;
import net.wanji.utc.hisense.netty.response.CommandResponseFactory; import net.wanji.utc.hisense.netty.response.CommandResponseFactory;
import net.wanji.utc.hisense.pojo.xml.pojo.messagecontent.get.GetSchemeNoRequest; import net.wanji.utc.hisense.pojo.xml.pojo.messagecontent.get.GetSchemeNoRequest;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
...@@ -31,9 +30,4 @@ public class GetSchemeNoService implements CommandResponseFactory, CommandReques ...@@ -31,9 +30,4 @@ public class GetSchemeNoService implements CommandResponseFactory, CommandReques
return commandPojo.getMsg(); return commandPojo.getMsg();
} }
@Scheduled(initialDelay = 30 * 1000, fixedRate = 4000)
public void test(){
sendCommandRequest(1);
System.err.println("==============发送消息成功");
}
} }
\ No newline at end of file
package net.wanji.databus.vo; package net.wanji.databus.vo;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -12,7 +13,9 @@ import lombok.Data; ...@@ -12,7 +13,9 @@ import lombok.Data;
@ApiModel(value = "分页实体") @ApiModel(value = "分页实体")
public class PageVO { public class PageVO {
@ApiModelProperty(required = true, value = "页号") @ApiModelProperty(required = true, value = "页号")
@TableField(exist = false)
Integer pageNum; Integer pageNum;
@ApiModelProperty(required = true, value = "每页记录数") @ApiModelProperty(required = true, value = "每页记录数")
@TableField(exist = false)
Integer pageSize; Integer pageSize;
} }
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