Commit fbfc162a authored by duanruiming's avatar duanruiming

[add] 策略管理页面接口

parent 8668906d
package net.wanji.opt.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.opt.synthesis.pojo.StrategyDailyPlanInfoEntity;
/**
* @author duanruiming
* @date 2024/11/08 10:15
*/
public interface StrategyDailyPlanInfoMapper extends BaseMapper<StrategyDailyPlanInfoEntity> {
}
package net.wanji.opt.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.opt.synthesis.pojo.StrategyPlanInfoEntity;
/**
* @author duanruiming
* @date 2024/11/08 10:14
*/
public interface StrategyPlanInfoMapper extends BaseMapper<StrategyPlanInfoEntity> {
}
......@@ -7,12 +7,11 @@ import io.swagger.annotations.ApiResponses;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.opt.dao.mapper.SynthesisOptimizeLogInfoMapper;
import net.wanji.opt.po.StrategyControlDataEntity;
import net.wanji.opt.synthesis.pojo.StrategyControlDetailList;
import net.wanji.opt.synthesis.pojo.StrategyControlVO;
import net.wanji.opt.synthesis.service.StrategyControlService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.ws.rs.core.MediaType;
......@@ -56,4 +55,27 @@ public class StrategyControlController {
return strategyControlService.strategyInfoPageList(entity);
}
@ApiOperation(value = "策略管理计划列表查询", notes = "策略管理计划列表查询",
response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/strategyPlanList",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = StrategyControlDataEntity.class),
})
public JsonViewObject strategyPlanList(@RequestParam String crossId) throws Exception {
return strategyControlService.strategyPlanList(crossId);
}
@ApiOperation(value = "策略管理计划保存", notes = "策略管理计划列表查询",
response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/strategyPlanSave",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = StrategyControlDetailList.class),
})
public JsonViewObject strategyPlanSave(@RequestBody @Validated StrategyControlDetailList list) throws Exception {
return strategyControlService.strategyPlanSave(list);
}
}
......@@ -35,6 +35,8 @@ public class StrategyControlDataVO {
private Integer status;
@ApiModelProperty(value = "操作(insert=新增,update=更新,delete=删除)")
private String action;
@ApiModelProperty(value = "模式1定时任务 2自适应")
private Integer model;
@Data
@NoArgsConstructor
......
package net.wanji.opt.synthesis.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.util.Date;
import java.util.List;
/**
* @author duanruiming
* @date 2024/11/08 0:24
*/
@Data
public class StrategyControlDetailList {
@NotEmpty
private List<ExecutePlan> plans;
@NotEmpty
private List<DailyPlan> dailyPlans;
@Data
public static class ExecutePlan {
private String crossId;
private Integer type;
private Integer planId;
private String company;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date startTime;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date endTime;
private List<PlanDetail> planDetails;
@Data
public static class PlanDetail {
private Integer dailyPlanId;
private List<Integer> weeks;
}
}
@Data
public static class DailyPlan {
private String crossId;
private Integer dailyPlanId;
private List<DailyPlanDetail> dailyPlanDetails;
@Data
public static class DailyPlanDetail {
private Integer strategy;
private List<String> times;
}
}
}
package net.wanji.opt.synthesis.pojo;
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 io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author duanruiming
* @date 2024/11/08 10:10
*/
@TableName("t_strategy_daily_plan_info")
@ApiModel(value = "StrategyDailyPlanInfoEntity", description = "策略管理日计划管理实体")
@Data
public class StrategyDailyPlanInfoEntity {
@ApiModelProperty("id")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@ApiModelProperty("dailyPlanId")
@TableField("daily_plan_id")
private Integer dailyPlanId;
@ApiModelProperty("crossId")
@TableField("cross_id")
private String crossId;
@ApiModelProperty("dailyPlanDetails")
@TableField("daily_plan_details")
private String dailyPlanDetails;
}
package net.wanji.opt.synthesis.pojo;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* @author duanruiming
* @date 2024/11/08 13:12
*/
@Data
public class StrategyPlanDTO {
private String crossId;
private Integer planId;
private Integer dailyPlanId;
private Integer strategy;
private List<String> times;
private List<Integer> weeks;
private Date startTime;
private Date endTime;
}
package net.wanji.opt.synthesis.pojo;
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 io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author duanruiming
* @date 2024/11/08 10:02
* @description 策略管理运行计划管理实体
*/
@TableName("t_strategy_plan_info")
@ApiModel(value = "StrategyPlanInfoEntity", description = "策略管理运行计划管理实体")
@Data
public class StrategyPlanInfoEntity {
@ApiModelProperty("id")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@ApiModelProperty("planId")
@TableField("plan_id")
private Integer planId;
@ApiModelProperty("crossId")
@TableField("cross_id")
private String crossId;
@ApiModelProperty("type")
@TableField("type")
private Integer type;
@ApiModelProperty("startTime")
@TableField("start_time")
private Date startTime;
@ApiModelProperty("endTime")
@TableField("end_time")
private Date endTime;
private String company;
@ApiModelProperty("planDetails")
@TableField("plan_details")
private String planDetails;
}
......@@ -2,6 +2,7 @@ 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.StrategyControlDetailList;
import net.wanji.opt.synthesis.pojo.StrategyControlVO;
/**
......@@ -12,4 +13,13 @@ public interface StrategyControlService {
JsonViewObject strategyInfoOperation(StrategyControlVO strategyControlVO) throws Exception;
JsonViewObject strategyInfoPageList(StrategyControlDataEntity entity) throws Exception;
/**
* 策略管理查询
* @param crossId
* @return
* @throws Exception
*/
JsonViewObject strategyPlanList(String crossId) throws Exception;
JsonViewObject strategyPlanSave(StrategyControlDetailList list) throws Exception;
}
......@@ -4,12 +4,16 @@ import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.enums.DateStyle;
import net.wanji.common.framework.Constants;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.opt.dao.mapper.StrategyControlInfoMapper;
import net.wanji.opt.dao.mapper.StrategyDailyPlanInfoMapper;
import net.wanji.opt.dao.mapper.StrategyPlanInfoMapper;
import net.wanji.opt.po.StrategyControlDataEntity;
import net.wanji.opt.synthesis.pojo.*;
import net.wanji.opt.synthesis.service.PushStrategyControlService;
......@@ -22,6 +26,7 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
......@@ -37,6 +42,10 @@ public class StrategyControlServiceImpl implements StrategyControlService {
private PushStrategyControlService pushStrategyControlService;
@Resource
private StrategyControlInfoMapper strategyControlInfoMapper;
@Resource
private StrategyPlanInfoMapper strategyPlanInfoMapper;
@Resource
private StrategyDailyPlanInfoMapper strategyDailyPlanInfoMapper;
@Override
public JsonViewObject strategyInfoOperation(StrategyControlVO strategyControlVO) throws Exception {
......@@ -135,4 +144,137 @@ public class StrategyControlServiceImpl implements StrategyControlService {
Page<StrategyControlDataEntity> pageInfo = strategyControlInfoMapper.selectPage(page, queryWrapper);
return JsonViewObject.newInstance().success(pageInfo.getRecords());
}
@Override
public JsonViewObject strategyPlanList(String crossId) throws Exception {
try {
ObjectMapper instance = JacksonUtils.getInstance();
StrategyControlDetailList result = new StrategyControlDetailList();
LambdaQueryWrapper<StrategyPlanInfoEntity> planQueryWrapper = new LambdaQueryWrapper<>();
planQueryWrapper.eq(StrategyPlanInfoEntity::getCrossId, crossId);
List<StrategyPlanInfoEntity> planInfoEntities = strategyPlanInfoMapper.selectList(planQueryWrapper);
List<StrategyControlDetailList.ExecutePlan> executePlans = new ArrayList<>();
for (StrategyPlanInfoEntity planInfoEntity : planInfoEntities) {
StrategyControlDetailList.ExecutePlan executePlan = new StrategyControlDetailList.ExecutePlan();
executePlan.setCompany(planInfoEntity.getCompany());
executePlan.setCrossId(planInfoEntity.getCrossId());
executePlan.setType(planInfoEntity.getType());
executePlan.setPlanId(planInfoEntity.getPlanId());
executePlan.setStartTime(planInfoEntity.getStartTime());
executePlan.setEndTime(planInfoEntity.getEndTime());
String planDetailsStr = planInfoEntity.getPlanDetails();
List<StrategyControlDetailList.ExecutePlan.PlanDetail> planDetails = instance.readValue(planDetailsStr, new TypeReference<List<StrategyControlDetailList.ExecutePlan.PlanDetail>>() {});
executePlan.setPlanDetails(planDetails);
executePlans.add(executePlan);
}
result.setPlans(executePlans);
LambdaQueryWrapper<StrategyDailyPlanInfoEntity> dailyPlanQueryWrapper = new LambdaQueryWrapper<>();
dailyPlanQueryWrapper.eq(StrategyDailyPlanInfoEntity::getCrossId, crossId);
List<StrategyDailyPlanInfoEntity> dailyPlanInfoEntities = strategyDailyPlanInfoMapper.selectList(dailyPlanQueryWrapper);
List<StrategyControlDetailList.DailyPlan> dailyPlans = new ArrayList<>();
for (StrategyDailyPlanInfoEntity dailyPlanInfoEntity : dailyPlanInfoEntities) {
StrategyControlDetailList.DailyPlan dailyPlan = new StrategyControlDetailList.DailyPlan();
dailyPlan.setCrossId(dailyPlanInfoEntity.getCrossId());
dailyPlan.setDailyPlanId(dailyPlanInfoEntity.getDailyPlanId());
String dailyPlanDetailsStr = dailyPlanInfoEntity.getDailyPlanDetails();
List<StrategyControlDetailList.DailyPlan.DailyPlanDetail> dailyPlanDetails = instance.readValue(dailyPlanDetailsStr, new TypeReference<List<StrategyControlDetailList.DailyPlan.DailyPlanDetail>>() {});
dailyPlan.setDailyPlanDetails(dailyPlanDetails);
dailyPlans.add(dailyPlan);
}
result.setDailyPlans(dailyPlans);
return JsonViewObject.newInstance().success(result);
} catch (Exception e) {
log.error("策略管理查询失败:{}", e);
throw new Exception(e);
}
}
@Override
public JsonViewObject strategyPlanSave(StrategyControlDetailList list) throws Exception {
try {
if (Objects.nonNull(list)) {
ObjectMapper mapper = JacksonUtils.getInstance();
List<StrategyControlDetailList.ExecutePlan> plans = list.getPlans();
if (!CollectionUtils.isEmpty(plans)) {
for (StrategyControlDetailList.ExecutePlan plan : plans) {
StrategyPlanInfoEntity planInfoEntity = new StrategyPlanInfoEntity();
planInfoEntity.setPlanId(plan.getPlanId());
planInfoEntity.setCrossId(plan.getCrossId());
planInfoEntity.setType(plan.getType());
planInfoEntity.setStartTime(plan.getStartTime());
planInfoEntity.setEndTime(plan.getEndTime());
planInfoEntity.setCompany(plan.getCompany());
planInfoEntity.setPlanDetails(mapper.writeValueAsString(plan.getPlanDetails()));
strategyPlanInfoMapper.insert(planInfoEntity);
}
}
List<StrategyControlDetailList.DailyPlan> dailyPlans = list.getDailyPlans();
for (StrategyControlDetailList.DailyPlan dailyPlan : dailyPlans) {
Integer dailyPlanId = dailyPlan.getDailyPlanId();
String crossId = dailyPlan.getCrossId();
List<StrategyControlDetailList.DailyPlan.DailyPlanDetail> dailyPlanDetails = dailyPlan.getDailyPlanDetails();
StrategyDailyPlanInfoEntity dailyPlanInfoEntity = new StrategyDailyPlanInfoEntity();
dailyPlanInfoEntity.setCrossId(crossId);
dailyPlanInfoEntity.setDailyPlanId(dailyPlanId);
dailyPlanInfoEntity.setDailyPlanDetails(mapper.writeValueAsString(dailyPlanDetails));
strategyDailyPlanInfoMapper.insert(dailyPlanInfoEntity);
}
}
return JsonViewObject.newInstance().success();
} catch (Exception e) {
log.error("策略管理数据保存失败,:{}", e);
throw new Exception(e);
}
}
/**
* 页面管理数据转化神思数据
*
* @param list
*/
public void convertDataList(StrategyControlDetailList list) {
if (Objects.nonNull(list)) {
List<StrategyControlDetailList.DailyPlan> dailyPlans = list.getDailyPlans();
List<StrategyPlanDTO> strategyPlanDTOS = new ArrayList<>();
if (!CollectionUtils.isEmpty(dailyPlans)) {
for (StrategyControlDetailList.DailyPlan dailyPlan : dailyPlans) {
Integer dailyPlanId = dailyPlan.getDailyPlanId();
List<StrategyControlDetailList.DailyPlan.DailyPlanDetail> dailyPlanDetails = dailyPlan.getDailyPlanDetails();
for (StrategyControlDetailList.DailyPlan.DailyPlanDetail dailyPlanDetail : dailyPlanDetails) {
StrategyPlanDTO strategyPlanDTO = new StrategyPlanDTO();
strategyPlanDTO.setStrategy(dailyPlanDetail.getStrategy());
strategyPlanDTO.setTimes(dailyPlanDetail.getTimes());
strategyPlanDTO.setDailyPlanId(dailyPlanId);
dailyPlans.add(dailyPlan);
}
}
}
List<StrategyControlDetailList.ExecutePlan> plans = list.getPlans();
if (!CollectionUtils.isEmpty(plans) && !CollectionUtils.isEmpty(dailyPlans)) {
for (StrategyControlDetailList.ExecutePlan plan : plans) {
Integer planId = plan.getPlanId();
Date startTime = plan.getStartTime();
Date endTime = plan.getEndTime();
List<StrategyControlDetailList.ExecutePlan.PlanDetail> planDetails = plan.getPlanDetails();
if (!CollectionUtils.isEmpty(planDetails)) {
for (StrategyControlDetailList.ExecutePlan.PlanDetail planDetail : planDetails) {
Integer dailyPlanId = planDetail.getDailyPlanId();
List<Integer> weeks = planDetail.getWeeks();
for (StrategyPlanDTO strategyPlanDTO : strategyPlanDTOS) {
if (dailyPlanId == strategyPlanDTO.getDailyPlanId()) {
strategyPlanDTO.setPlanId(planId);
strategyPlanDTO.setStartTime(startTime);
strategyPlanDTO.setEndTime(endTime);
}
}
}
}
}
}
}
}
}
<?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.StrategyDailyPlanInfoMapper">
</mapper>
\ No newline at end of file
<?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.StrategyPlanInfoMapper">
</mapper>
\ No newline at end of file
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