Commit bff3bdd5 authored by duanruiming's avatar duanruiming

[update] 策略管理代码提交

parent 763365d3
......@@ -7,8 +7,8 @@ import io.swagger.annotations.ApiResponses;
import net.wanji.common.annotation.aspect.AspectLog;
import net.wanji.common.enums.BaseEnum;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.databus.vo.SchemeOptSendVO;
import net.wanji.opt.service.signalcontrol.FeignProxyService;
import net.wanji.opt.vo.SchemeOptSendVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -37,7 +37,7 @@ public class SignalCommandOptController {
@PostMapping(value = "/schemeOptSend",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = JsonViewObject.class)})
public JsonViewObject schemeOptSend(@RequestBody @Validated SchemeOptSendVO schemeOptSendVO) throws Exception{
public JsonViewObject schemeOptSend(@RequestBody @Validated SchemeOptSendVO schemeOptSendVO) throws Exception {
JsonViewObject jsonViewObject = feignProxyService.schemeOptSend(schemeOptSendVO);
return jsonViewObject;
}
......@@ -48,7 +48,7 @@ public class SignalCommandOptController {
@PostMapping(value = "/schemeOptRestore",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = JsonViewObject.class)})
public JsonViewObject schemeOptRestore(@RequestBody @NotBlank String crossId) throws Exception{
public JsonViewObject schemeOptRestore(@RequestBody @NotBlank String crossId) throws Exception {
JsonViewObject jsonViewObject = feignProxyService.schemeOptRestore(crossId);
return jsonViewObject;
}
......
......@@ -29,7 +29,7 @@ import net.wanji.opt.service.signalcontrol.FeignProxyService;
import net.wanji.opt.service.strategy.SceneService;
import net.wanji.opt.vo.CrossIdAndLocationVO;
import net.wanji.opt.vo.OptEffectVO;
import net.wanji.opt.vo.SchemeOptSendVO;
import net.wanji.databus.vo.SchemeOptSendVO;
import net.wanji.opt.vo.SchemeOptVO;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
......
package net.wanji.opt.service.signalcontrol;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.opt.vo.SchemeOptSendVO;
import net.wanji.databus.vo.SchemeOptSendVO;
/**
* @author duanruiming
......
......@@ -13,7 +13,7 @@ import net.wanji.opt.dto.CrossPhaseDTO;
import net.wanji.opt.po.base.CrossSchemeOptLogPO;
import net.wanji.opt.service.impl.CrossOptimizeServiceImpl;
import net.wanji.opt.service.signalcontrol.FeignProxyService;
import net.wanji.opt.vo.SchemeOptSendVO;
import net.wanji.databus.vo.SchemeOptSendVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
......
......@@ -77,6 +77,18 @@ public class StrategyControlController {
return strategyControlService.strategyPlanDetail(crossId);
}
@ApiOperation(value = "策略管理计划详情下发", notes = "策略管理计划详情下发",
response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/strategyPush",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = StrategyControlDetailList.class),
})
public JsonViewObject strategyPush(@RequestBody @Validated StrategyControlDetailList list) throws Exception {
return strategyControlService.strategyPush(list);
}
@ApiOperation(value = "策略管理计划保存", notes = "策略管理计划列表查询",
response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
......
......@@ -38,4 +38,6 @@ public class StrategyControlDataEntity extends PageVO {
private Integer frequency;
/** value = 状态(1=开启,0=停止) */
private Integer status;
@TableField(exist = false)
private String crossName;
}
......@@ -25,6 +25,7 @@ public class StrategyControlDetailList {
private Integer type;
private Integer planId;
private String company;
private Integer status;
@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")
......
......@@ -19,5 +19,6 @@ public class StrategyPlanDTO {
private List<Integer> weeks;
private Date startTime;
private Date endTime;
private Integer status;
private Integer freq;
}
......@@ -37,6 +37,7 @@ public class StrategyPlanInfoEntity {
@ApiModelProperty("endTime")
@TableField("end_time")
private Date endTime;
private Integer status;
private String company;
@ApiModelProperty("planDetails")
@TableField("plan_details")
......
......@@ -16,5 +16,6 @@ public interface StrategyControlService {
JsonViewObject crossStrategyInfoList(Integer type) throws Exception;
JsonViewObject strategyPlanDetail(String crossId) throws Exception;
JsonViewObject strategyPush(StrategyControlDetailList list) throws Exception;
JsonViewObject strategyPlanSave(StrategyControlDetailList list) throws Exception;
}
......@@ -12,6 +12,9 @@ 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.databus.dao.mapper.BaseCrossInfoMapper;
import net.wanji.databus.po.BaseCrossInfoPO;
import net.wanji.feign.service.UtcFeignClients;
import net.wanji.opt.dao.mapper.StrategyControlInfoMapper;
import net.wanji.opt.dao.mapper.StrategyDailyPlanInfoMapper;
import net.wanji.opt.dao.mapper.StrategyPlanInfoMapper;
......@@ -25,10 +28,8 @@ 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;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author duanruiming
......@@ -46,6 +47,11 @@ public class StrategyControlServiceImpl implements StrategyControlService {
private StrategyPlanInfoMapper strategyPlanInfoMapper;
@Resource
private StrategyDailyPlanInfoMapper strategyDailyPlanInfoMapper;
@Resource
private UtcFeignClients utcFeignClients;
@Resource
private BaseCrossInfoMapper baseCrossInfoMapper;
@Override
public JsonViewObject strategyInfoOperation(StrategyControlVO strategyControlVO) throws Exception {
......@@ -91,14 +97,27 @@ public class StrategyControlServiceImpl implements StrategyControlService {
private StrategyControlReq convertReq(StrategyControlVO vo) throws Exception {
try {
ObjectMapper instance = JacksonUtils.getInstance();
List<StrategyControlDataVO> dataList = vo.getDataList();
StrategyControlReq req = new StrategyControlReq();
if (!CollectionUtils.isEmpty(dataList)) {
List<StrategyControlDataReq> dataReqList = new ArrayList<>(dataList.size());
for (StrategyControlDataVO dataVO : dataList) {
StrategyControlDataReq detailData = new StrategyControlDataReq();
detailData.setBiz_id(dataVO.getBizId());
detailData.setBiz_type(dataVO.getBizType());
//try {
// if (0 == dataVO.getBizType()) {
// CrossIdBO crossIdBO = new CrossIdBO();
// crossIdBO.setCrossId(dataVO.getBizId());
// JsonViewObject jsonViewObject = utcFeignClients.crossInfoById(crossIdBO);
// Object content = jsonViewObject.getContent();
// CrossInfoPO crossInfoPO = instance.readValue(String.valueOf(content), CrossInfoPO.class);
// detailData.setBiz_id(crossInfoPO.getCode());
// }
//} catch (JsonProcessingException e) {
// detailData.setBiz_id(null);
//}
detailData.setBiz_id("311358");
detailData.setStrategy(dataVO.getStrategy());
detailData.setSchedule_start(DateUtil.format(dataVO.getScheduleStart(), DateStyle.YYYY_MM_DD_HH_MM_SS.getValue()));
detailData.setSchedule_end(DateUtil.format(dataVO.getScheduleEnd(), DateStyle.YYYY_MM_DD_HH_MM_SS.getValue()));
......@@ -114,6 +133,7 @@ public class StrategyControlServiceImpl implements StrategyControlService {
detailData.setFreq(dataVO.getFrequency());
detailData.setStatus(dataVO.getStatus());
detailData.setAction(StringUtils.equals("update", dataVO.getAction()) ? "insert" : dataVO.getAction());
dataReqList.add(detailData);
req.setData(dataReqList);
}
......@@ -185,9 +205,11 @@ public class StrategyControlServiceImpl implements StrategyControlService {
}
}
}
results.add(result);
}
}
BaseCrossInfoPO baseCrossInfoPO = baseCrossInfoMapper.selectById(entity.getBizId());
result.setCrossName(baseCrossInfoPO.getName());
results.add(result);
}
return JsonViewObject.newInstance().success(results);
}
......@@ -210,6 +232,8 @@ public class StrategyControlServiceImpl implements StrategyControlService {
executePlan.setPlanId(planInfoEntity.getPlanId());
executePlan.setStartTime(planInfoEntity.getStartTime());
executePlan.setEndTime(planInfoEntity.getEndTime());
executePlan.setStatus(planInfoEntity.getStatus());
executePlan.setType(planInfoEntity.getType());
String planDetailsStr = planInfoEntity.getPlanDetails();
List<StrategyControlDetailList.ExecutePlan.PlanDetail> planDetails = instance.readValue(planDetailsStr, new TypeReference<List<StrategyControlDetailList.ExecutePlan.PlanDetail>>() {});
executePlan.setPlanDetails(planDetails);
......@@ -231,6 +255,7 @@ public class StrategyControlServiceImpl implements StrategyControlService {
dailyPlans.add(dailyPlan);
}
result.setDailyPlans(dailyPlans);
result.setCrossId(crossId);
return JsonViewObject.newInstance().success(result);
} catch (Exception e) {
log.error("策略管理查询失败:{}", e);
......@@ -266,11 +291,14 @@ public class StrategyControlServiceImpl implements StrategyControlService {
StrategyDailyPlanInfoEntity dailyPlanInfoEntity = new StrategyDailyPlanInfoEntity();
dailyPlanInfoEntity.setCrossId(crossId);
dailyPlanInfoEntity.setDailyPlanId(dailyPlanId);
LambdaQueryWrapper<StrategyDailyPlanInfoEntity> delete = new LambdaQueryWrapper<>();
delete.eq(StrategyDailyPlanInfoEntity::getCrossId, crossId);
delete.eq(StrategyDailyPlanInfoEntity::getDailyPlanId, dailyPlanId);
strategyDailyPlanInfoMapper.delete(delete);
dailyPlanInfoEntity.setDailyPlanDetails(mapper.writeValueAsString(dailyPlanDetails));
strategyDailyPlanInfoMapper.insert(dailyPlanInfoEntity);
}
}
convertDataList(list);
return JsonViewObject.newInstance().success();
} catch (Exception e) {
log.error("策略管理数据保存失败,:{}", e);
......@@ -278,13 +306,47 @@ public class StrategyControlServiceImpl implements StrategyControlService {
}
}
@Override
public JsonViewObject strategyPush(StrategyControlDetailList list) throws Exception {
List<StrategyControlDetailList.ExecutePlan> plans = list.getPlans();
StrategyControlDetailList.ExecutePlan executePlan = plans.get(0);
LambdaQueryWrapper<StrategyPlanInfoEntity> query = new LambdaQueryWrapper<>();
query.eq(StrategyPlanInfoEntity::getPlanId, executePlan.getPlanId());
query.eq(StrategyPlanInfoEntity::getCrossId, executePlan.getCrossId());
strategyPlanInfoMapper.delete(query);
StrategyPlanInfoEntity planInfoEntity = new StrategyPlanInfoEntity();
planInfoEntity.setCrossId(executePlan.getCrossId());
planInfoEntity.setPlanId(executePlan.getPlanId());
planInfoEntity.setType(executePlan.getType());
planInfoEntity.setCompany("神思");
planInfoEntity.setStatus(executePlan.getStatus());
planInfoEntity.setStartTime(executePlan.getStartTime());
planInfoEntity.setEndTime(executePlan.getEndTime());
planInfoEntity.setPlanDetails(JacksonUtils.getInstance().writeValueAsString(executePlan.getPlanDetails()));
strategyPlanInfoMapper.insert(planInfoEntity);
StrategyControlVO strategyControlVO = convertDataList(list);
StrategyControlReq req = convertReq(strategyControlVO);
log.error(JacksonUtils.getInstance().writeValueAsString(req));
//Result result = pushStrategyControlService.push(req);
Result result = new Result("200", "成功", null);
if (Objects.nonNull(result)) {
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
jsonViewObject.setCode(Integer.valueOf(result.getCode()));
jsonViewObject.setMessage(result.getMsg());
jsonViewObject.setContent(result.getData());
jsonViewObject.setStatus(StringUtils.equals("200", result.getCode()) ? Constants.JsonView.STATUS_SUCCESS : Constants.JsonView.STATUS_FAIL);
return jsonViewObject;
} else {
return JsonViewObject.newInstance().fail("推送神思策略控制失败!");
}
}
/**
* 页面管理数据转化神思数据
*
* @param list
*/
public void convertDataList(StrategyControlDetailList list) throws Exception {
public StrategyControlVO convertDataList(StrategyControlDetailList list) throws Exception {
try {
if (Objects.nonNull(list)) {
List<StrategyControlDetailList.DailyPlan> dailyPlans = list.getDailyPlans();
......@@ -292,12 +354,33 @@ public class StrategyControlServiceImpl implements StrategyControlService {
if (!CollectionUtils.isEmpty(dailyPlans)) {
for (StrategyControlDetailList.DailyPlan dailyPlan : dailyPlans) {
Integer dailyPlanId = dailyPlan.getDailyPlanId();
String crossId = dailyPlan.getCrossId();
List<StrategyControlDetailList.DailyPlan.DailyPlanDetail> dailyPlanDetails = dailyPlan.getDailyPlanDetails();
for (StrategyControlDetailList.DailyPlan.DailyPlanDetail dailyPlanDetail : dailyPlanDetails) {
List<StrategyControlDetailList.DailyPlan.DailyPlanDetail> dailyPlanGroupList = new ArrayList<>(dailyPlanDetails.size());
Map<Integer, List<StrategyControlDetailList.DailyPlan.DailyPlanDetail>> dailyMap = dailyPlanDetails.stream().collect(Collectors.groupingBy(StrategyControlDetailList.DailyPlan.DailyPlanDetail::getStrategy));
for (Map.Entry<Integer, List<StrategyControlDetailList.DailyPlan.DailyPlanDetail>> entry : dailyMap.entrySet()) {
StrategyControlDetailList.DailyPlan.DailyPlanDetail result = new StrategyControlDetailList.DailyPlan.DailyPlanDetail();
Integer strategy = entry.getKey();
List<StrategyControlDetailList.DailyPlan.DailyPlanDetail> value = entry.getValue();
List<String> times = new ArrayList<>(value.size());
for (StrategyControlDetailList.DailyPlan.DailyPlanDetail dailyPlanDetail : value) {
List<String> timesList = dailyPlanDetail.getTimes();
String timeStr = timesList.get(0) + "-" + timesList.get(1);
times.add(timeStr);
}
result.setStrategy(strategy);
result.setTimes(times);
dailyPlanGroupList.add(result);
}
for (StrategyControlDetailList.DailyPlan.DailyPlanDetail dailyPlanDetail : dailyPlanGroupList) {
StrategyPlanDTO strategyPlanDTO = new StrategyPlanDTO();
strategyPlanDTO.setStrategy(dailyPlanDetail.getStrategy());
Integer strategy = dailyPlanDetail.getStrategy();
strategyPlanDTO.setStrategy(strategy);
strategyPlanDTO.setTimes(dailyPlanDetail.getTimes());
strategyPlanDTO.setDailyPlanId(dailyPlanId);
strategyPlanDTO.setCrossId(crossId);
strategyPlanDTOS.add(strategyPlanDTO);
}
}
......@@ -310,6 +393,7 @@ public class StrategyControlServiceImpl implements StrategyControlService {
Integer planId = plan.getPlanId();
Date startTime = plan.getStartTime();
Date endTime = plan.getEndTime();
Integer status = plan.getStatus();
List<StrategyControlDetailList.ExecutePlan.PlanDetail> planDetails = plan.getPlanDetails();
if (!CollectionUtils.isEmpty(planDetails)) {
for (StrategyControlDetailList.ExecutePlan.PlanDetail planDetail : planDetails) {
......@@ -321,6 +405,7 @@ public class StrategyControlServiceImpl implements StrategyControlService {
strategyPlanDTO.setStartTime(startTime);
strategyPlanDTO.setEndTime(endTime);
strategyPlanDTO.setWeeks(weeks);
strategyPlanDTO.setStatus(status);
resultList.add(strategyPlanDTO);
}
}
......@@ -328,14 +413,37 @@ public class StrategyControlServiceImpl implements StrategyControlService {
}
}
}
List<StrategyControlDataVO> dataList = new ArrayList<>();
for (StrategyPlanDTO strategyPlanDTO : strategyPlanDTOS) {
System.err.println(strategyPlanDTO);
StrategyControlDataVO dataVO = new StrategyControlDataVO();
dataVO.setBizId(strategyPlanDTO.getCrossId());
dataVO.setBizType(0);
dataVO.setStrategy(strategyPlanDTO.getStrategy());
dataVO.setScheduleStart(strategyPlanDTO.getStartTime());
dataVO.setScheduleEnd(strategyPlanDTO.getEndTime());
dataVO.setAction("insert");
dataVO.setStatus(strategyPlanDTO.getStatus());
dataVO.setFrequency(strategyPlanDTO.getFreq());
List<StrategyControlDataVO.TimeTable> timeTables = new ArrayList<>();
List<Integer> weeks = strategyPlanDTO.getWeeks();
for (Integer week : weeks) {
StrategyControlDataVO.TimeTable timeTable = new StrategyControlDataVO.TimeTable();
timeTable.setWeek(week);
List<String> times = strategyPlanDTO.getTimes();
timeTable.setTimeList(times.toArray(new String[times.size()]));
timeTables.add(timeTable);
}
dataVO.setTime(timeTables);
dataList.add(dataVO);
StrategyControlVO req = new StrategyControlVO();
req.setDataList(dataList);
return req;
}
log.error("神思数据:{}", JacksonUtils.getInstance().writeValueAsString(strategyPlanDTOS));
}
} catch (Exception e) {
log.error("数据转化神思数据结构异常:{}", e);
throw new Exception(e);
}
return null;
}
}
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