|
|
@@ -1,5 +1,10 @@
|
|
|
package org.dromara.system.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateField;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
@@ -8,6 +13,13 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.dromara.common.redis.utils.CacheUtils;
|
|
|
+import org.dromara.common.redis.utils.RedisUtils;
|
|
|
+import org.dromara.system.domain.TblDzbcPath;
|
|
|
+import org.dromara.system.domain.vo.TblDzbcCarVo;
|
|
|
+import org.dromara.system.domain.vo.TblDzbcPathVo;
|
|
|
+import org.dromara.system.mapper.TblDzbcCarMapper;
|
|
|
+import org.dromara.system.mapper.TblDzbcPathMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.dromara.system.domain.bo.TblDzbcPathSchedulingBo;
|
|
|
import org.dromara.system.domain.vo.TblDzbcPathSchedulingVo;
|
|
|
@@ -15,9 +27,8 @@ import org.dromara.system.domain.TblDzbcPathScheduling;
|
|
|
import org.dromara.system.mapper.TblDzbcPathSchedulingMapper;
|
|
|
import org.dromara.system.service.ITblDzbcPathSchedulingService;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Collection;
|
|
|
+import java.time.Duration;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 定制班车-路线排班Service业务层处理
|
|
|
@@ -31,6 +42,9 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
|
|
|
private final TblDzbcPathSchedulingMapper baseMapper;
|
|
|
|
|
|
+ private final TblDzbcCarMapper carMapper;
|
|
|
+ private final TblDzbcPathMapper pathMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询定制班车-路线排班
|
|
|
*/
|
|
|
@@ -69,6 +83,11 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
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.getExt2()), TblDzbcPathScheduling::getExt2, bo.getExt2());
|
|
|
+ if(params!=null){
|
|
|
+ if(params.containsKey("mdate")){
|
|
|
+ lqw.ge(params.get("mdate")!=null, TblDzbcPathScheduling::getMdate, (params.get("mdate").toString()));
|
|
|
+ }
|
|
|
+ }
|
|
|
return lqw;
|
|
|
}
|
|
|
|
|
|
@@ -78,10 +97,28 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
@Override
|
|
|
public Boolean insertByBo(TblDzbcPathSchedulingBo bo) {
|
|
|
TblDzbcPathScheduling add = MapstructUtils.convert(bo, TblDzbcPathScheduling.class);
|
|
|
+ //添加车辆信息
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ if(add.getCarId()!=null){
|
|
|
+ TblDzbcCarVo carVo = carMapper.selectVoById(bo.getCarId());
|
|
|
+ if(carVo == null){
|
|
|
+ throw new RuntimeException("车辆不存在");
|
|
|
+ }
|
|
|
+ params.put("carInfo",carVo);
|
|
|
+ }
|
|
|
+ if(add.getPathId()!=null){
|
|
|
+ TblDzbcPathVo pathVo = pathMapper.selectVoById(bo.getPathId());
|
|
|
+ if(pathVo == null){
|
|
|
+ throw new RuntimeException("路线不存在");
|
|
|
+ }
|
|
|
+ params.put("pathInfo",pathVo);
|
|
|
+ }
|
|
|
+ add.setExt1(JSONUtil.toJsonStr(params));
|
|
|
validEntityBeforeSave(add);
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (flag) {
|
|
|
bo.setId(add.getId());
|
|
|
+ SysCache(add.getId(),null);
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
@@ -93,9 +130,56 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
public Boolean updateByBo(TblDzbcPathSchedulingBo bo) {
|
|
|
TblDzbcPathScheduling update = MapstructUtils.convert(bo, TblDzbcPathScheduling.class);
|
|
|
validEntityBeforeSave(update);
|
|
|
- return baseMapper.updateById(update) > 0;
|
|
|
+ int c = baseMapper.updateById(update) ;
|
|
|
+ if(c>0){
|
|
|
+ SysCache(bo.getId(),null);
|
|
|
+ }
|
|
|
+ return c> 0;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private void SysCache(Long id, Collection<Long> ids) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ if(ids!=null){
|
|
|
+ List<String> keys = RedisUtils.keys("dzbc_path_scheduling").stream().toList();
|
|
|
+ for (String key : keys) {
|
|
|
+ Map<String,TblDzbcPathSchedulingVo> boMap = RedisUtils.getCacheMap(key.toString());
|
|
|
+ if(boMap == null){
|
|
|
+ boMap = new HashMap<>();
|
|
|
+ }
|
|
|
+ for (Long id1 : ids) {
|
|
|
+ boMap.remove(id1.toString());
|
|
|
+ }
|
|
|
+ RedisUtils.setCacheMap(key.toString(),boMap);
|
|
|
+ String date = key.split("\\|")[1];
|
|
|
+ long datetime = DateUtil.parseDate(date).getTime();
|
|
|
+ long currentdatetime = DateUtil.parseDate(DateUtil.today()).getTime();
|
|
|
+ if(datetime<currentdatetime){
|
|
|
+ RedisUtils.deleteObject(key.toString());
|
|
|
+ }
|
|
|
+ RedisUtils.expire(key.toString(),DateUtil.parseDate(date).offset(DateField.HOUR_OF_DAY,24).getTime()-DateUtil.current() );
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ TblDzbcPathSchedulingVo bo = baseMapper.selectVoById(id);
|
|
|
+ if(bo == null||bo.getMdate()==null) return;
|
|
|
+ {
|
|
|
+ Map<String, TblDzbcPathSchedulingVo> boMap = RedisUtils.getCacheMap(StrUtil.format("dzbc_path_scheduling|{}", DateUtil.formatDate(bo.getMdate())));
|
|
|
+ if (boMap == null||boMap.size() <1) {
|
|
|
+ boMap = new HashMap<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ boMap.put(id.toString(), bo);
|
|
|
+ RedisUtils.setCacheMap(StrUtil.format("dzbc_path_scheduling|{}", DateUtil.formatDate(bo.getMdate())), boMap);
|
|
|
+ RedisUtils.expire(StrUtil.format("dzbc_path_scheduling|{}", DateUtil.formatDate(bo.getMdate())), DateUtil.offset(bo.getMdate(), DateField.HOUR_OF_DAY, 24).getTime() - DateUtil.current());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){}
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 保存前的数据校验
|
|
|
*/
|
|
|
@@ -111,6 +195,10 @@ public class TblDzbcPathSchedulingServiceImpl implements ITblDzbcPathSchedulingS
|
|
|
if(isValid){
|
|
|
//TODO 做一些业务上的校验,判断是否需要校验
|
|
|
}
|
|
|
- return baseMapper.deleteBatchIds(ids) > 0;
|
|
|
+ int c = baseMapper.deleteBatchIds(ids) ;
|
|
|
+ if(c>0){
|
|
|
+ SysCache(null,ids);
|
|
|
+ }
|
|
|
+ return c>0;
|
|
|
}
|
|
|
}
|