Commit a540e135 by 张晓

接口逻辑增加

1 parent ede28e8b
...@@ -100,7 +100,7 @@ ...@@ -100,7 +100,7 @@
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<optional>true</optional> <optional>true</optional>
<version>1.18.16</version> <version>1.18.24</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
......
...@@ -125,6 +125,14 @@ ...@@ -125,6 +125,14 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<!-- <scope>runtime</scope>-->
<!-- <optional>true</optional>-->
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
......
package com.dituhui.pea.pre.controller;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.pre.entity.DispatchBatch;
import com.dituhui.pea.pre.service.BatchService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.sql.SQLException;
import java.time.LocalDateTime;
/**
* @author zhangx
*/
@Slf4j
@RequestMapping("/pea-pre")
@RestController
public class BatchController {
@Autowired
BatchService batchService;
/*
* 检查指定日期的小组是否有在运行的批次任务,有则返回,没有则创建后返回批次码
*/
@GetMapping("/batch/build/{groupId}/{day}")
public Result<?> buildBatch(@PathVariable String groupId, @PathVariable String day) {
log.info("buildBatch, groupId:{}, day:{}", groupId, day);
try {
String batchNo = batchService.buildBatchNo(groupId, day);
DispatchBatch batch = batchService.queryBatch(groupId, batchNo);
DispatchBatchDTO batchDTO = new DispatchBatchDTO();
BeanUtils.copyProperties(batch, batchDTO);
return Result.success(batchDTO);
} catch (SQLException e) {
log.error("buildBatch error", e);
return Result.failed(e.getMessage());
}
}
@GetMapping("/batch/query/{groupId}/{batchNo}")
public Result<?> queryBatch(@PathVariable String groupId, @PathVariable String batchNo) {
log.info("buildBatch, groupId:{}, batchNo:{}", groupId, batchNo);
DispatchBatch batch = batchService.queryBatch(groupId, batchNo);
DispatchBatchDTO batchDTO = new DispatchBatchDTO();
BeanUtils.copyProperties(batch, batchDTO);
return Result.success(batch);
}
@Data
class DispatchBatchDTO {
String groupId;
String batchNo;
int engineerNum;
int orderNum;
LocalDateTime startTime;
LocalDateTime endTime;
String status;
}
}
package com.dituhui.pea.pre.controller;
import cn.hutool.core.map.MapUtil;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.pre.opta.domain.Vehicle;
import com.dituhui.pea.pre.opta.domain.VehicleRoutingSolution;
import com.dituhui.pea.pre.service.BatchService;
import com.dituhui.pea.pre.service.PrepareService;
import lombok.extern.slf4j.Slf4j;
import org.optaplanner.core.api.score.buildin.hardsoftlong.HardSoftLongScore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.sql.SQLException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author zhangx
*/
@Slf4j
@RequestMapping("/pea-pre")
@RestController
public class PrepareController {
@Autowired
PrepareService prepareService;
/*
* 检查指定日期的小组是否有在运行的批次任务,有则返回,没有则创建后返回批次码
*/
@GetMapping("/prepare/solve/{groupId}/{batchNo}")
public Result<?> prepareAndSolve(@PathVariable String groupId, @PathVariable String batchNo) {
log.info("prepareSolve, groupId:{}, day:{}", groupId, batchNo);
VehicleRoutingSolution solution = prepareService.prepareAndSolveSolution(groupId, batchNo);
List<Vehicle> engineerList = solution.getVehicleList();
HardSoftLongScore score = solution.getScore();
log.info("prepareSolve done, groupId:{}, day:{}, score:{}", groupId, batchNo, score.toString());
Map<String, Object> resultMap = MapUtil.builder(new HashMap<String, Object>()).
put("score", score).put("engineers", engineerList).build();
return Result.success(resultMap);
}
}
...@@ -5,17 +5,21 @@ import lombok.extern.slf4j.Slf4j; ...@@ -5,17 +5,21 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* @author zhangx
*/
@Slf4j @Slf4j
@Component @Component
public class Scheduler { public class Scheduler {
@Scheduled(fixedRate = 1000*10) // @Scheduled(fixedRate = 1000*10)
public void RunLog(){ public void RunLog(){
log.info("RunLog"); log.info("RunLog");
} }
@Scheduled(cron = "${pre-dispatch.cron.expr}") // @Scheduled(cron = "${pre-dispatch.cron.expr}")
public void dispatchRun(){ public void dispatchRun(){
log.info("dispatchRun"); log.info("dispatchRun");
} }
......
package com.dituhui.pea.pre.service; package com.dituhui.pea.pre.service;
import com.dituhui.pea.pre.entity.DispatchBatch;
import java.sql.SQLException; import java.sql.SQLException;
/** /**
* @author zhangx * @author zhangx
* * <p>
* 批次排班数据准备 * 批次排班数据准备
*
*/ */
public interface BatchService { public interface BatchService {
// 检查指定日期的小组是否有在运行的批次任务,有则返回,没有则创建后返回批次码 // 检查指定日期的小组是否有在运行的批次任务,有则返回,没有则创建后返回批次码
String buildBatchNo(String groupId, String day) throws SQLException; String buildBatchNo(String groupId, String day) throws SQLException;
DispatchBatch queryBatch(String groupId, String day);
} }
...@@ -16,6 +16,7 @@ import java.sql.SQLException; ...@@ -16,6 +16,7 @@ import java.sql.SQLException;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional; import java.util.Optional;
...@@ -144,4 +145,15 @@ public class BatchServiceImpl implements BatchService { ...@@ -144,4 +145,15 @@ public class BatchServiceImpl implements BatchService {
return batchNo; return batchNo;
} }
public DispatchBatch queryBatch(String groupId, String batchNo) {
List<DispatchBatch> batchList = batchRepository.findLatestGroup(groupId, batchNo);
if (batchList.size() > 0) {
return batchList.get(0);
} else {
return new DispatchBatch();
}
}
} }
server: server:
port: 8012 port: 8012
pre-dispatch: pre-dispatch:
cron: cron:
expr: 0 */5 8-18 * * ? expr: 0 */5 8-18 * * ?
...@@ -13,7 +10,7 @@ spring: ...@@ -13,7 +10,7 @@ spring:
name: project-pre-dispatch name: project-pre-dispatch
jackson: jackson:
default-property-inclusion: NON_NULL default-property-inclusion: NON_NULL
# time-zone: GMT+8 time-zone: GMT+8
date-format: yyyy-MM-dd HH:mm:ss date-format: yyyy-MM-dd HH:mm:ss
cloud: cloud:
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!