Commit b5a033ef authored by duanruiming's avatar duanruiming

[add] 策略管理页面接口

parent fbfc162a
......@@ -10,7 +10,8 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* @author
*/
@SpringBootApplication(scanBasePackages = {"net.wanji.opt", "net.wanji.databus", "net.wanji.common"})
@SpringBootApplication(scanBasePackages = {"net.wanji.opt", "net.wanji.databus", "net.wanji.common",
"net.wanji.opt.controller","net.wanji.opt.synthesis.controller"})
@MapperScan(basePackages = {"net.wanji.opt.dao.mapper", "net.wanji.databus.dao.mapper"})
@EnableTransactionManagement
@EnableScheduling
......
package net.wanji.opt.config;
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
......@@ -21,7 +22,8 @@ public class Swagger2 {
.apiInfo(apiInfo())
.select()
//为当前包路径
.apis(RequestHandlerSelectors.basePackage("net.wanji.opt.controller"))
.apis(Predicates.or(RequestHandlerSelectors.basePackage("net.wanji.opt.controller"),
RequestHandlerSelectors.basePackage("net.wanji.opt.synthesis.controller")))
.paths(PathSelectors.any())
.build();
}
......
package net.wanji.opt.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.opt.po.StrategyControlDataEntity;
import net.wanji.opt.synthesis.pojo.StrategyControlDataEntity;
import org.apache.ibatis.annotations.Param;
import java.util.List;
......
......@@ -6,7 +6,7 @@ import io.swagger.annotations.ApiResponse;
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.StrategyControlDataEntity;
import net.wanji.opt.synthesis.pojo.StrategyControlDetailList;
import net.wanji.opt.synthesis.pojo.StrategyControlVO;
import net.wanji.opt.synthesis.service.StrategyControlService;
......@@ -55,16 +55,26 @@ public class StrategyControlController {
return strategyControlService.strategyInfoPageList(entity);
}
@ApiOperation(value = "策略管理计划列表查询", notes = "策略管理计划列表查询",
@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)
@GetMapping(value = "/crossStrategyInfoList")
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = StrategyControlDataEntity.class),
})
public JsonViewObject strategyPlanList(@RequestParam String crossId) throws Exception {
return strategyControlService.strategyPlanList(crossId);
public JsonViewObject crossStrategyInfoList(@RequestParam Integer type) throws Exception {
return strategyControlService.crossStrategyInfoList(type);
}
@ApiOperation(value = "策略管理计划详情查询", notes = "策略管理计划详情查询",
response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/strategyPlanDetail")
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = StrategyControlDetailList.class),
})
public JsonViewObject strategyPlanDetail(@RequestParam String crossId) throws Exception {
return strategyControlService.strategyPlanDetail(crossId);
}
@ApiOperation(value = "策略管理计划保存", notes = "策略管理计划列表查询",
......
package net.wanji.opt.po;
package net.wanji.opt.synthesis.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
......
......@@ -13,6 +13,7 @@ import java.util.List;
*/
@Data
public class StrategyControlDetailList {
private String crossId;
@NotEmpty
private List<ExecutePlan> plans;
@NotEmpty
......
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.StrategyControlDataEntity;
import net.wanji.opt.synthesis.pojo.StrategyControlDetailList;
import net.wanji.opt.synthesis.pojo.StrategyControlVO;
......@@ -13,13 +13,8 @@ public interface StrategyControlService {
JsonViewObject strategyInfoOperation(StrategyControlVO strategyControlVO) throws Exception;
JsonViewObject strategyInfoPageList(StrategyControlDataEntity entity) throws Exception;
JsonViewObject crossStrategyInfoList(Integer type) throws Exception;
/**
* 策略管理查询
* @param crossId
* @return
* @throws Exception
*/
JsonViewObject strategyPlanList(String crossId) throws Exception;
JsonViewObject strategyPlanDetail(String crossId) throws Exception;
JsonViewObject strategyPlanSave(StrategyControlDetailList list) throws Exception;
}
package net.wanji.opt.synthesis.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
......@@ -14,7 +15,6 @@ 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;
import net.wanji.opt.synthesis.service.StrategyControlService;
......@@ -146,7 +146,55 @@ public class StrategyControlServiceImpl implements StrategyControlService {
}
@Override
public JsonViewObject strategyPlanList(String crossId) throws Exception {
public JsonViewObject crossStrategyInfoList(Integer type) throws Exception {
ObjectMapper instance = JacksonUtils.getInstance();
LambdaQueryWrapper<StrategyControlDataEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StrategyControlDataEntity::getBizType, type);
List<StrategyControlDataEntity> entities = strategyControlInfoMapper.selectList(queryWrapper);
List<StrategyControlDataEntity> results = new ArrayList<>(entities.size());
Date current = new Date();
for (StrategyControlDataEntity entity : entities) {
StrategyControlDataEntity result = new StrategyControlDataEntity();
BeanUtils.copyProperties(result, entity);
Date start = entity.getScheduleStart();
Date end = entity.getScheduleEnd();
if (current.before(start) || current.after(end)) {
result.setTime("");
} else {
String time = entity.getTime();
List<StrategyControlDataVO.TimeTable> timeTables = instance.readValue(time, new TypeReference<List<StrategyControlDataVO.TimeTable>>() {});
for (StrategyControlDataVO.TimeTable timeTable : timeTables) {
int currentWeek = DateUtil.thisDayOfWeek();
if (currentWeek != timeTable.getWeek()) {
result.setTime("");
} else {
String[] timeList = timeTable.getTimeList();
for (String s : timeList) {
String[] hours = s.split(",");
for (String hour : hours) {
String[] currentHour = hour.split("-");
String startHour = currentHour[0];
String entHour = currentHour[1];
String format = DateUtil.format(current, "HH:mm");
DateTime currentTime = DateUtil.parse(format, "HH:mm");
DateTime startHourDate = DateUtil.parse(startHour, "HH:mm");
DateTime endHourDate = DateUtil.parse(entHour, "HH:mm");
if (currentTime.before(startHourDate) || currentTime.after(endHourDate)) {
result.setTime(hour);
}
}
}
}
results.add(result);
}
}
}
return JsonViewObject.newInstance().success(results);
}
@Override
public JsonViewObject strategyPlanDetail(String crossId) throws Exception {
try {
ObjectMapper instance = JacksonUtils.getInstance();
StrategyControlDetailList result = new StrategyControlDetailList();
......@@ -222,6 +270,7 @@ public class StrategyControlServiceImpl implements StrategyControlService {
strategyDailyPlanInfoMapper.insert(dailyPlanInfoEntity);
}
}
convertDataList(list);
return JsonViewObject.newInstance().success();
} catch (Exception e) {
log.error("策略管理数据保存失败,:{}", e);
......@@ -235,7 +284,8 @@ public class StrategyControlServiceImpl implements StrategyControlService {
*
* @param list
*/
public void convertDataList(StrategyControlDetailList list) {
public void convertDataList(StrategyControlDetailList list) throws Exception {
try {
if (Objects.nonNull(list)) {
List<StrategyControlDetailList.DailyPlan> dailyPlans = list.getDailyPlans();
List<StrategyPlanDTO> strategyPlanDTOS = new ArrayList<>();
......@@ -248,11 +298,12 @@ public class StrategyControlServiceImpl implements StrategyControlService {
strategyPlanDTO.setStrategy(dailyPlanDetail.getStrategy());
strategyPlanDTO.setTimes(dailyPlanDetail.getTimes());
strategyPlanDTO.setDailyPlanId(dailyPlanId);
dailyPlans.add(dailyPlan);
strategyPlanDTOS.add(strategyPlanDTO);
}
}
}
List<StrategyPlanDTO> resultList = new ArrayList<>();
List<StrategyControlDetailList.ExecutePlan> plans = list.getPlans();
if (!CollectionUtils.isEmpty(plans) && !CollectionUtils.isEmpty(dailyPlans)) {
for (StrategyControlDetailList.ExecutePlan plan : plans) {
......@@ -269,12 +320,22 @@ public class StrategyControlServiceImpl implements StrategyControlService {
strategyPlanDTO.setPlanId(planId);
strategyPlanDTO.setStartTime(startTime);
strategyPlanDTO.setEndTime(endTime);
strategyPlanDTO.setWeeks(weeks);
resultList.add(strategyPlanDTO);
}
}
}
}
}
}
for (StrategyPlanDTO strategyPlanDTO : strategyPlanDTOS) {
System.err.println(strategyPlanDTO);
}
log.error("神思数据:{}", JacksonUtils.getInstance().writeValueAsString(strategyPlanDTOS));
}
} catch (Exception e) {
log.error("数据转化神思数据结构异常:{}", e);
throw new Exception(e);
}
}
}
......@@ -5,7 +5,7 @@
<mapper namespace="net.wanji.opt.dao.mapper.StrategyControlInfoMapper">
<insert id="insertBatch" parameterType="net.wanji.opt.po.StrategyControlDataEntity">
<insert id="insertBatch" parameterType="net.wanji.opt.synthesis.pojo.StrategyControlDataEntity">
INSERT INTO t_strategy_control_info (
biz_id,
biz_type,
......
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