Commit c3c89fa9 authored by duanruiming's avatar duanruiming

[add] 策略查询接口

parent 92556429
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.po; 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 lombok.Data;
import net.wanji.databus.vo.PageVO;
import java.util.Date; import java.util.Date;
...@@ -9,16 +14,23 @@ import java.util.Date; ...@@ -9,16 +14,23 @@ import java.util.Date;
* @date 2024/11/04 10:53 * @date 2024/11/04 10:53
*/ */
@Data @Data
public class StrategyControlDataEntity { @TableName("t_strategy_control_info")
/** value = 路口干线Id */ public class StrategyControlDataEntity extends PageVO {
/** value = 路口干线Id */
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@TableField("biz_id")
private String bizId; private String bizId;
/** value = 类型 0-路口 1-干线 */ /** value = 类型 0-路口 1-干线 */
@TableField("biz_type")
private Integer bizType; private Integer bizType;
/** value = 策略类型 0-绿波带 1-失衡 2-溢出 3-空放 */ /** value = 策略类型 0-绿波带 1-失衡 2-溢出 3-空放 */
private Integer strategy; private Integer strategy;
/** value = 开始时间日期 */ /** value = 开始时间日期 */
@TableField("schedule_start")
private Date scheduleStart; private Date scheduleStart;
/** value = 结束时间日期 */ /** value = 结束时间日期 */
@TableField("schedule_end")
private Date scheduleEnd; private Date scheduleEnd;
/** value = 日计划表 */ /** value = 日计划表 */
private String time; private String time;
......
...@@ -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);
}
} }
...@@ -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 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;
...@@ -13,11 +14,14 @@ import net.wanji.opt.synthesis.pojo.*; ...@@ -13,11 +14,14 @@ 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.apache.commons.beanutils.BeanUtils; 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 javax.annotation.Resource; import javax.annotation.Resource;
import java.util.*; import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/** /**
* @author duanruiming * @author duanruiming
...@@ -43,12 +47,11 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -43,12 +47,11 @@ public class StrategyControlServiceImpl implements StrategyControlService {
StrategyControlDataEntity entity = new StrategyControlDataEntity(); StrategyControlDataEntity entity = new StrategyControlDataEntity();
BeanUtils.copyProperties(entity, dataVO); BeanUtils.copyProperties(entity, dataVO);
entity.setTime(JacksonUtils.getInstance().writeValueAsString(dataVO.getTime())); entity.setTime(JacksonUtils.getInstance().writeValueAsString(dataVO.getTime()));
entities.add(entity);
} }
strategyControlInfoMapper.insertBatch(entities); strategyControlInfoMapper.insertBatch(entities);
StrategyControlReq req = convertReq(strategyControlVO); StrategyControlReq req = convertReq(strategyControlVO);
// todo 测试数据
//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();
...@@ -102,33 +105,23 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -102,33 +105,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());
} }
} }
...@@ -7,28 +7,24 @@ ...@@ -7,28 +7,24 @@
<insert id="insertBatch" parameterType="net.wanji.opt.po.StrategyControlDataEntity"> <insert id="insertBatch" parameterType="net.wanji.opt.po.StrategyControlDataEntity">
INSERT INTO t_strategy_control_info ( INSERT INTO t_strategy_control_info (
bizId, biz_id,
bizType, biz_type,
strategy, strategy,
schedule_start, schedule_start,
schedule_end, schedule_end,
`time`, `time`,
frequency, frequency,
status, status
create_time,
gmt_modified
) VALUES ) VALUES
<foreach collection="list" item="entity" separator=","> <foreach collection="list" item="entity" separator=",">
#{entity.bizId}, (#{entity.bizId},
#{entity.bizType}, #{entity.bizType},
#{entity.strategy}, #{entity.strategy},
#{entity.scheduleStart}, #{entity.scheduleStart},
#{entity.scheduleEnd}, #{entity.scheduleEnd},
#{entity.time}, #{entity.time},
#{entity.frequency}, #{entity.frequency},
#{entity.status}, #{entity.status})
#{createTime, jdbcType=TIMESTAMP, default=CURRENT_TIMESTAMP},
#{gmtModified, jdbcType=TIMESTAMP, default=CURRENT_TIMESTAMP, update="CURRENT_TIMESTAMP"}
</foreach> </foreach>
</insert> </insert>
</mapper> </mapper>
\ 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