|
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import org.dromara.common.core.service.OssService;
|
|
import org.dromara.common.core.service.OssService;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
@@ -22,18 +23,24 @@ import org.dromara.system.domain.SysUser;
|
|
|
import org.dromara.system.domain.TblDzbcPath;
|
|
import org.dromara.system.domain.TblDzbcPath;
|
|
|
import org.dromara.system.domain.vo.SysUserVo;
|
|
import org.dromara.system.domain.vo.SysUserVo;
|
|
|
import org.dromara.system.domain.vo.TblDzbcCarVo;
|
|
import org.dromara.system.domain.vo.TblDzbcCarVo;
|
|
|
|
|
+import org.dromara.system.domain.vo.TblDzbcMultiSitePathVo;
|
|
|
import org.dromara.system.domain.vo.TblDzbcPathVo;
|
|
import org.dromara.system.domain.vo.TblDzbcPathVo;
|
|
|
import org.dromara.system.mapper.SysUserMapper;
|
|
import org.dromara.system.mapper.SysUserMapper;
|
|
|
import org.dromara.system.mapper.TblDzbcCarMapper;
|
|
import org.dromara.system.mapper.TblDzbcCarMapper;
|
|
|
|
|
+import org.dromara.system.mapper.TblDzbcMultiSitePathMapper;
|
|
|
import org.dromara.system.mapper.TblDzbcPathMapper;
|
|
import org.dromara.system.mapper.TblDzbcPathMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.dromara.system.domain.bo.TblDzbcDriverTripBo;
|
|
|
import org.dromara.system.domain.bo.TblDzbcPathSchedulingBo;
|
|
import org.dromara.system.domain.bo.TblDzbcPathSchedulingBo;
|
|
|
import org.dromara.system.domain.vo.TblDzbcPathSchedulingVo;
|
|
import org.dromara.system.domain.vo.TblDzbcPathSchedulingVo;
|
|
|
import org.dromara.system.domain.TblDzbcPathScheduling;
|
|
import org.dromara.system.domain.TblDzbcPathScheduling;
|
|
|
import org.dromara.system.mapper.TblDzbcPathSchedulingMapper;
|
|
import org.dromara.system.mapper.TblDzbcPathSchedulingMapper;
|
|
|
|
|
+import org.dromara.system.service.ITblDzbcDriverTripService;
|
|
|
import org.dromara.system.service.ITblDzbcPathSchedulingService;
|
|
import org.dromara.system.service.ITblDzbcPathSchedulingService;
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -50,6 +57,8 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
|
|
|
|
|
private final TblDzbcCarMapper carMapper;
|
|
private final TblDzbcCarMapper carMapper;
|
|
|
private final TblDzbcPathMapper pathMapper;
|
|
private final TblDzbcPathMapper pathMapper;
|
|
|
|
|
+ private final TblDzbcMultiSitePathMapper multiSitePathMapper;
|
|
|
|
|
+ private final ITblDzbcDriverTripService driverTripService;
|
|
|
|
|
|
|
|
private final SysUserMapper userMapper;
|
|
private final SysUserMapper userMapper;
|
|
|
private final OssService ossService;
|
|
private final OssService ossService;
|
|
@@ -60,7 +69,16 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
@Override
|
|
@Override
|
|
|
public TblDzbcPathSchedulingVo queryById(Long id){
|
|
public TblDzbcPathSchedulingVo queryById(Long id){
|
|
|
SysCache();
|
|
SysCache();
|
|
|
- return baseMapper.selectVoById(id);
|
|
|
|
|
|
|
+ TblDzbcPathSchedulingVo vo = baseMapper.selectVoById(id);
|
|
|
|
|
+ if (vo != null && vo.getExt2() != null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ JSONObject ext2 = JSONUtil.parseObj(vo.getExt2());
|
|
|
|
|
+ if (ext2.containsKey("type")) {
|
|
|
|
|
+ vo.setType(ext2.getInt("type"));
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {}
|
|
|
|
|
+ }
|
|
|
|
|
+ return vo;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -70,6 +88,16 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
public TableDataInfo<TblDzbcPathSchedulingVo> queryPageList(TblDzbcPathSchedulingBo bo, PageQuery pageQuery) {
|
|
public TableDataInfo<TblDzbcPathSchedulingVo> queryPageList(TblDzbcPathSchedulingBo bo, PageQuery pageQuery) {
|
|
|
LambdaQueryWrapper<TblDzbcPathScheduling> lqw = buildQueryWrapper(bo);
|
|
LambdaQueryWrapper<TblDzbcPathScheduling> lqw = buildQueryWrapper(bo);
|
|
|
Page<TblDzbcPathSchedulingVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
Page<TblDzbcPathSchedulingVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
|
|
+ result.getRecords().forEach(vo -> {
|
|
|
|
|
+ if (vo.getExt2() != null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ JSONObject ext2 = JSONUtil.parseObj(vo.getExt2());
|
|
|
|
|
+ if (ext2.containsKey("type")) {
|
|
|
|
|
+ vo.setType(ext2.getInt("type"));
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {}
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
return TableDataInfo.build(result);
|
|
return TableDataInfo.build(result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -79,7 +107,18 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
@Override
|
|
@Override
|
|
|
public List<TblDzbcPathSchedulingVo> queryList(TblDzbcPathSchedulingBo bo) {
|
|
public List<TblDzbcPathSchedulingVo> queryList(TblDzbcPathSchedulingBo bo) {
|
|
|
LambdaQueryWrapper<TblDzbcPathScheduling> lqw = buildQueryWrapper(bo);
|
|
LambdaQueryWrapper<TblDzbcPathScheduling> lqw = buildQueryWrapper(bo);
|
|
|
- return baseMapper.selectVoList(lqw);
|
|
|
|
|
|
|
+ List<TblDzbcPathSchedulingVo> list = baseMapper.selectVoList(lqw);
|
|
|
|
|
+ list.forEach(vo -> {
|
|
|
|
|
+ if (vo.getExt2() != null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ JSONObject ext2 = JSONUtil.parseObj(vo.getExt2());
|
|
|
|
|
+ if (ext2.containsKey("type")) {
|
|
|
|
|
+ vo.setType(ext2.getInt("type"));
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {}
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ return list;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private LambdaQueryWrapper<TblDzbcPathScheduling> buildQueryWrapper(TblDzbcPathSchedulingBo bo) {
|
|
private LambdaQueryWrapper<TblDzbcPathScheduling> buildQueryWrapper(TblDzbcPathSchedulingBo bo) {
|
|
@@ -94,6 +133,18 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getEndSites()), TblDzbcPathScheduling::getEndSites, bo.getEndSites());
|
|
lqw.eq(StringUtils.isNotBlank(bo.getEndSites()), TblDzbcPathScheduling::getEndSites, bo.getEndSites());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getExt1()), TblDzbcPathScheduling::getExt1, bo.getExt1());
|
|
lqw.eq(StringUtils.isNotBlank(bo.getExt1()), TblDzbcPathScheduling::getExt1, bo.getExt1());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getExt2()), TblDzbcPathScheduling::getExt2, bo.getExt2());
|
|
lqw.eq(StringUtils.isNotBlank(bo.getExt2()), TblDzbcPathScheduling::getExt2, bo.getExt2());
|
|
|
|
|
+
|
|
|
|
|
+ // 根据 type 查询 (映射到 ext2->'$.type')
|
|
|
|
|
+ if (bo.getType() != null) {
|
|
|
|
|
+ if (bo.getType() == 2) {
|
|
|
|
|
+ // 固定路线:明确 type 为 2
|
|
|
|
|
+ lqw.apply("ext2->'$.type' = 2");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 普通路线:type 为 1 或 不存在 type 字段
|
|
|
|
|
+ lqw.apply("(ext2->'$.type' = 1 OR ext2->'$.type' IS NULL)");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if(params!=null){
|
|
if(params!=null){
|
|
|
if(params.containsKey("mdate")){
|
|
if(params.containsKey("mdate")){
|
|
|
lqw.ge(params.get("mdate")!=null, TblDzbcPathScheduling::getMdate, (params.get("mdate").toString()));
|
|
lqw.ge(params.get("mdate")!=null, TblDzbcPathScheduling::getMdate, (params.get("mdate").toString()));
|
|
@@ -144,19 +195,48 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
throw new RuntimeException("车辆不能为空");
|
|
throw new RuntimeException("车辆不能为空");
|
|
|
}
|
|
}
|
|
|
if(add.getPathId()!=null){
|
|
if(add.getPathId()!=null){
|
|
|
- TblDzbcPathVo pathVo = pathMapper.selectVoById(bo.getPathId());
|
|
|
|
|
- if(pathVo == null){
|
|
|
|
|
- throw new RuntimeException("路线不存在");
|
|
|
|
|
|
|
+ if (bo.getType() != null && bo.getType() == 2) {
|
|
|
|
|
+ // 固定路线(多站点)
|
|
|
|
|
+ TblDzbcMultiSitePathVo multiSitePathVo = multiSitePathMapper.selectVoById(bo.getPathId());
|
|
|
|
|
+ if (multiSitePathVo == null) {
|
|
|
|
|
+ throw new RuntimeException("路线不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ params.put("pathInfo", multiSitePathVo);
|
|
|
|
|
+ // 多站点路线不自动设置mtime,需前端传递或后续处理
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 普通路线
|
|
|
|
|
+ TblDzbcPathVo pathVo = pathMapper.selectVoById(bo.getPathId());
|
|
|
|
|
+ if(pathVo == null){
|
|
|
|
|
+ throw new RuntimeException("路线不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ params.put("pathInfo",pathVo);
|
|
|
|
|
+ // 如果未设置时间,则使用路线默认时间
|
|
|
|
|
+ if (StrUtil.isBlank(add.getMtime())) {
|
|
|
|
|
+ add.setMtime(pathVo.getMtime());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- params.put("pathInfo",pathVo);
|
|
|
|
|
- add.setMtime(pathVo.getMtime());
|
|
|
|
|
}else{
|
|
}else{
|
|
|
throw new RuntimeException("路线不能为空");
|
|
throw new RuntimeException("路线不能为空");
|
|
|
}
|
|
}
|
|
|
add.setExt1(JSONUtil.toJsonStr(params));
|
|
add.setExt1(JSONUtil.toJsonStr(params));
|
|
|
|
|
+
|
|
|
|
|
+ // 处理排班类型
|
|
|
|
|
+ if (bo.getType() != null) {
|
|
|
|
|
+ JSONObject ext2 = JSONUtil.parseObj(add.getExt2());
|
|
|
|
|
+ if (ext2 == null) {
|
|
|
|
|
+ ext2 = JSONUtil.createObj();
|
|
|
|
|
+ }
|
|
|
|
|
+ ext2.set("type", bo.getType());
|
|
|
|
|
+ add.setExt2(ext2.toString());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
validEntityBeforeSave(add);
|
|
validEntityBeforeSave(add);
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (flag) {
|
|
if (flag) {
|
|
|
|
|
+ // 如果是车辆排班(type=2),自动创建司机发车任务
|
|
|
|
|
+ if (bo.getType() != null && bo.getType() == 2) {
|
|
|
|
|
+ createDriverTrip(add, params);
|
|
|
|
|
+ }
|
|
|
bo.setId(add.getId());
|
|
bo.setId(add.getId());
|
|
|
SysCache();
|
|
SysCache();
|
|
|
}
|
|
}
|
|
@@ -164,6 +244,53 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 创建司机发车任务
|
|
|
|
|
+ */
|
|
|
|
|
+ private void createDriverTrip(TblDzbcPathScheduling scheduling, Map<String, Object> params) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ SysUserVo driver = (SysUserVo) params.get("driverInfo");
|
|
|
|
|
+ if (driver == null) {
|
|
|
|
|
+ // 如果params中没有,尝试重新查询
|
|
|
|
|
+ TblDzbcCarVo carVo = carMapper.selectVoById(scheduling.getCarId());
|
|
|
|
|
+ if (carVo != null && carVo.getDriverId() != null) {
|
|
|
|
|
+ driver = userMapper.selectUserById(carVo.getDriverId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (driver != null) {
|
|
|
|
|
+ TblDzbcDriverTripBo tripBo = new TblDzbcDriverTripBo();
|
|
|
|
|
+ tripBo.setPathId(scheduling.getPathId());
|
|
|
|
|
+ tripBo.setDriverId(driver.getUserId());
|
|
|
|
|
+ tripBo.setCarId(scheduling.getCarId());
|
|
|
|
|
+
|
|
|
|
|
+ // 设置开始时间 (mdate + mtime)
|
|
|
|
|
+ String dateStr = DateUtil.formatDate(scheduling.getMdate());
|
|
|
|
|
+ String timeStr = scheduling.getMtime();
|
|
|
|
|
+ // 确保时间格式正确,例如 "08:00" -> "08:00:00"
|
|
|
|
|
+ if (StringUtils.countMatches(timeStr, ":") == 1) {
|
|
|
|
|
+ timeStr += ":00";
|
|
|
|
|
+ }
|
|
|
|
|
+ String dateTimeStr = dateStr + " " + timeStr;
|
|
|
|
|
+ LocalDateTime startTime = LocalDateTime.parse(dateTimeStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
+ tripBo.setStartTime(startTime);
|
|
|
|
|
+
|
|
|
|
|
+ // 扩展字段关联排班ID
|
|
|
|
|
+ JSONObject ext2 = JSONUtil.createObj();
|
|
|
|
|
+ ext2.set("schedulingId", scheduling.getId());
|
|
|
|
|
+ tripBo.setExt2(ext2.toString());
|
|
|
|
|
+
|
|
|
|
|
+ // 存储排班的 JSON 快照到 ext1
|
|
|
|
|
+ tripBo.setExt1(JSONUtil.toJsonStr(scheduling));
|
|
|
|
|
+
|
|
|
|
|
+ driverTripService.createTrip(tripBo);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ throw new RuntimeException("自动创建发车任务失败: " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* 修改定制班车-路线排班
|
|
* 修改定制班车-路线排班
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
@@ -195,13 +322,38 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
params.put("carInfo",carVo);
|
|
params.put("carInfo",carVo);
|
|
|
}
|
|
}
|
|
|
if(add.getPathId()!=null){
|
|
if(add.getPathId()!=null){
|
|
|
- TblDzbcPathVo pathVo = pathMapper.selectVoById(bo.getPathId());
|
|
|
|
|
- if(pathVo == null){
|
|
|
|
|
- throw new RuntimeException("路线不存在");
|
|
|
|
|
|
|
+ if (bo.getType() != null && bo.getType() == 2) {
|
|
|
|
|
+ // 固定路线(多站点)
|
|
|
|
|
+ TblDzbcMultiSitePathVo multiSitePathVo = multiSitePathMapper.selectVoById(bo.getPathId());
|
|
|
|
|
+ if (multiSitePathVo == null) {
|
|
|
|
|
+ throw new RuntimeException("路线不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ params.put("pathInfo", multiSitePathVo);
|
|
|
|
|
+ // 多站点路线不自动设置mtime,需前端传递或后续处理
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 普通路线
|
|
|
|
|
+ TblDzbcPathVo pathVo = pathMapper.selectVoById(bo.getPathId());
|
|
|
|
|
+ if(pathVo == null){
|
|
|
|
|
+ throw new RuntimeException("路线不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ params.put("pathInfo",pathVo);
|
|
|
|
|
+ // 如果未设置时间,则使用路线默认时间
|
|
|
|
|
+ if (StrUtil.isBlank(add.getMtime())) {
|
|
|
|
|
+ add.setMtime(pathVo.getMtime());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- params.put("pathInfo",pathVo);
|
|
|
|
|
- add.setMtime(pathVo.getMtime());
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 处理排班类型
|
|
|
|
|
+ if (bo.getType() != null) {
|
|
|
|
|
+ JSONObject ext2 = JSONUtil.parseObj(add.getExt2());
|
|
|
|
|
+ if (ext2 == null) {
|
|
|
|
|
+ ext2 = JSONUtil.createObj();
|
|
|
|
|
+ }
|
|
|
|
|
+ ext2.set("type", bo.getType());
|
|
|
|
|
+ add.setExt2(ext2.toString());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
add.setExt1(JSONUtil.toJsonStr(params));
|
|
add.setExt1(JSONUtil.toJsonStr(params));
|
|
|
baseMapper.updateById(add);
|
|
baseMapper.updateById(add);
|
|
|
|
|
|