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;
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;
......@@ -9,16 +14,23 @@ import java.util.Date;
* @date 2024/11/04 10:53
*/
@Data
public class StrategyControlDataEntity {
/** value = 路口干线Id */
@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-干线 */
/** value = 类型 0-路口 1-干线 */
@TableField("biz_type")
private Integer bizType;
/** value = 策略类型 0-绿波带 1-失衡 2-溢出 3-空放 */
private Integer strategy;
/** value = 开始时间日期 */
/** value = 开始时间日期 */
@TableField("schedule_start")
private Date scheduleStart;
/** value = 结束时间日期 */
/** value = 结束时间日期 */
@TableField("schedule_end")
private Date scheduleEnd;
/** value = 日计划表 */
private String time;
......
......@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
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.service.StrategyControlService;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -39,4 +40,17 @@ public class StrategyControlController {
public JsonViewObject strategyInfoOperation(@RequestBody StrategyControlVO strategyControlVO) throws Exception {
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;
* @date 2024/11/03 14:06
*/
public interface PushStrategyControlService {
void insert();
void update();
void delete();
Result push(StrategyControlReq req) throws Exception;
}
package net.wanji.opt.synthesis.service;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.opt.po.StrategyControlDataEntity;
import net.wanji.opt.synthesis.pojo.StrategyControlVO;
/**
......@@ -9,4 +10,6 @@ import net.wanji.opt.synthesis.pojo.StrategyControlVO;
*/
public interface StrategyControlService {
JsonViewObject strategyInfoOperation(StrategyControlVO strategyControlVO) throws Exception;
JsonViewObject strategyInfoPageList(StrategyControlDataEntity entity) throws Exception;
}
......@@ -7,10 +7,8 @@ import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.opt.synthesis.pojo.Result;
import net.wanji.opt.synthesis.pojo.StrategyControlReq;
import net.wanji.opt.synthesis.service.PushStrategyControlService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.Objects;
/**
* @author duanruiming
......@@ -20,32 +18,14 @@ import java.util.Objects;
@Slf4j
public class PushStrategyControlServiceImpl implements PushStrategyControlService {
@Override
public void insert() {
}
@Override
public void update() {
}
@Override
public void delete() {
}
@Override
public Result push(StrategyControlReq req) throws Exception {
String url = "";
try {
ObjectMapper mapper = JacksonUtils.getInstance();
String resultStr = RestTemplateTool.post(url, mapper.writeValueAsString(req));
Result result = mapper.readValue(resultStr, Result.class);
if (Objects.nonNull(result)) {
if (StringUtils.endsWithIgnoreCase("200", result.getCode())) {
return result;
}
if (StringUtils.isNotBlank(resultStr)) {
Result result = mapper.readValue(resultStr, Result.class);
return result;
} else {
log.error("策略推送url:{}失败:返回数据异常", url);
......
package net.wanji.opt.synthesis.service.impl;
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 net.wanji.common.enums.DateStyle;
import net.wanji.common.framework.Constants;
......@@ -13,11 +14,14 @@ import net.wanji.opt.synthesis.pojo.*;
import net.wanji.opt.synthesis.service.PushStrategyControlService;
import net.wanji.opt.synthesis.service.StrategyControlService;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* @author duanruiming
......@@ -43,12 +47,11 @@ public class StrategyControlServiceImpl implements StrategyControlService {
StrategyControlDataEntity entity = new StrategyControlDataEntity();
BeanUtils.copyProperties(entity, dataVO);
entity.setTime(JacksonUtils.getInstance().writeValueAsString(dataVO.getTime()));
entities.add(entity);
}
strategyControlInfoMapper.insertBatch(entities);
StrategyControlReq req = convertReq(strategyControlVO);
// todo 测试数据
//req.setData(Arrays.asList(detailData));
Result result = pushStrategyControlService.push(req);
if (Objects.nonNull(result)) {
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
......@@ -102,33 +105,23 @@ public class StrategyControlServiceImpl implements StrategyControlService {
}
}
public static void main(String[] args) throws Exception {
StrategyControlDataReq detailData = new StrategyControlDataReq();
detailData.setBiz_id("241940");
detailData.setBiz_type(0);
detailData.setStrategy(3);
Date date = new Date();
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()));
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(2);
timeTable1.setTime_list(new String[]{"02:00-03:00", "03:00-04:00"});
detailData.setTime(Arrays.asList(timeTable1, timeTable));
detailData.setFreq(1000 * 60);
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());
@Override
public JsonViewObject strategyInfoPageList(StrategyControlDataEntity entity) throws Exception {
LambdaQueryWrapper<StrategyControlDataEntity> queryWrapper = new LambdaQueryWrapper<>();
if (StringUtils.isNotBlank(entity.getBizId())) {
queryWrapper.eq(StrategyControlDataEntity::getBizId, entity.getBizId());
}
if (Objects.nonNull(entity.getBizType())) {
queryWrapper.eq(StrategyControlDataEntity::getBizType, entity.getBizType());
}
if (Objects.nonNull(entity.getStrategy())) {
queryWrapper.eq(StrategyControlDataEntity::getStrategy, entity.getStrategy());
}
if (Objects.nonNull(entity.getStatus())) {
queryWrapper.eq(StrategyControlDataEntity::getStatus, entity.getStatus());
}
Page<StrategyControlDataEntity> page = new Page<>(entity.getPageNum(), entity.getPageSize());
Page<StrategyControlDataEntity> pageInfo = strategyControlInfoMapper.selectPage(page, queryWrapper);
return JsonViewObject.newInstance().success(pageInfo.getRecords());
}
}
......@@ -7,28 +7,24 @@
<insert id="insertBatch" parameterType="net.wanji.opt.po.StrategyControlDataEntity">
INSERT INTO t_strategy_control_info (
bizId,
bizType,
biz_id,
biz_type,
strategy,
schedule_start,
schedule_end,
`time`,
frequency,
status,
create_time,
gmt_modified
status
) VALUES
<foreach collection="list" item="entity" separator=",">
#{entity.bizId},
(#{entity.bizId},
#{entity.bizType},
#{entity.strategy},
#{entity.scheduleStart},
#{entity.scheduleEnd},
#{entity.time},
#{entity.frequency},
#{entity.status},
#{createTime, jdbcType=TIMESTAMP, default=CURRENT_TIMESTAMP},
#{gmtModified, jdbcType=TIMESTAMP, default=CURRENT_TIMESTAMP, update="CURRENT_TIMESTAMP"}
#{entity.status})
</foreach>
</insert>
</mapper>
\ No newline at end of file
package net.wanji.databus.vo;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -12,7 +13,9 @@ import lombok.Data;
@ApiModel(value = "分页实体")
public class PageVO {
@ApiModelProperty(required = true, value = "页号")
@TableField(exist = false)
Integer pageNum;
@ApiModelProperty(required = true, value = "每页记录数")
@TableField(exist = false)
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