Commit 8ca0bcc3df4709073ed4100670eb4a88ef670b32
1 parent
e12f6a7c
优化导入数据
Showing
5 changed files
with
86 additions
and
49 deletions
Bsth-admin/src/main/java/com/ruoyi/domain/key/location/LinggangKeyWorkLocation.java
| @@ -122,6 +122,15 @@ public class LinggangKeyWorkLocation { | @@ -122,6 +122,15 @@ public class LinggangKeyWorkLocation { | ||
| 122 | @TableField(exist = false) | 122 | @TableField(exist = false) |
| 123 | private Collection<Integer> keyInfoIds; | 123 | private Collection<Integer> keyInfoIds; |
| 124 | 124 | ||
| 125 | + public boolean importEquals(LinggangKeyWorkLocation location) { | ||
| 126 | + if (Objects.isNull(location)) { | ||
| 127 | + return false; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + return Objects.equals(this.yardId, location.getYardId()) && Objects.equals(this.device, location.getDevice()) && Objects.equals(this.keyInfoId, location.getKeyInfoId()) | ||
| 131 | + && Objects.equals(this.scheduleDate, location.getScheduleDate()) && Objects.equals(this.schedulingId, location.getSchedulingId()) && Objects.equals(this.type, location.getType()); | ||
| 132 | + } | ||
| 133 | + | ||
| 125 | 134 | ||
| 126 | public enum LinggangKeyWorkLocationEventTypeEnum { | 135 | public enum LinggangKeyWorkLocationEventTypeEnum { |
| 127 | TAKE_OUT(0, "取出"), | 136 | TAKE_OUT(0, "取出"), |
| @@ -167,7 +176,7 @@ public class LinggangKeyWorkLocation { | @@ -167,7 +176,7 @@ public class LinggangKeyWorkLocation { | ||
| 167 | TAKE_OUT(0, "取出"), | 176 | TAKE_OUT(0, "取出"), |
| 168 | 177 | ||
| 169 | REPAY(1, "归还"), | 178 | REPAY(1, "归还"), |
| 170 | - | 179 | + |
| 171 | ; | 180 | ; |
| 172 | 181 | ||
| 173 | private String label; | 182 | private String label; |
Bsth-admin/src/main/java/com/ruoyi/domain/scheduling/LinggangScheduling.java
| @@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j; | @@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j; | ||
| 12 | import org.apache.commons.lang3.StringUtils; | 12 | import org.apache.commons.lang3.StringUtils; |
| 13 | 13 | ||
| 14 | import java.util.Date; | 14 | import java.util.Date; |
| 15 | +import java.util.Objects; | ||
| 15 | 16 | ||
| 16 | 17 | ||
| 17 | @Data | 18 | @Data |
| @@ -163,7 +164,16 @@ public class LinggangScheduling { | @@ -163,7 +164,16 @@ public class LinggangScheduling { | ||
| 163 | } | 164 | } |
| 164 | 165 | ||
| 165 | 166 | ||
| 166 | - | 167 | + public boolean importEqus(LinggangScheduling linggangScheduling){ |
| 168 | + if(Objects.isNull(linggangScheduling)){ | ||
| 169 | + return false; | ||
| 170 | + } | ||
| 171 | + return Objects.equals(this.getScheduleDate(),linggangScheduling.getScheduleDate()) && Objects.equals(this.lineName,linggangScheduling.getLineName()) | ||
| 172 | + && Objects.equals(this.jobCode,linggangScheduling.getJobCode()) && Objects.equals(this.name,linggangScheduling.getName()) && Objects.equals(this.posts,linggangScheduling.getPosts()) | ||
| 173 | + && Objects.equals(this.lpName,linggangScheduling.getLpName()) && Objects.equals(this.nbbm,linggangScheduling.getNbbm()) && Objects.equals(this.getBcType(),linggangScheduling.getBcType()) | ||
| 174 | + && Objects.equals(this.fcsjT,linggangScheduling.getFcsjT()) && Objects.equals(this.zdsjT,linggangScheduling.getZdsjT()) && Objects.equals(this.qdzcode,linggangScheduling.getQdzcode()) | ||
| 175 | + && Objects.equals(this.zdzcode,linggangScheduling.getZdzcode()); | ||
| 176 | + } | ||
| 167 | 177 | ||
| 168 | @Override | 178 | @Override |
| 169 | public String toString() { | 179 | public String toString() { |
Bsth-admin/src/main/java/com/ruoyi/job/DriverJob.java
| @@ -8,7 +8,6 @@ import com.ruoyi.common.cache.NowSchedulingCache; | @@ -8,7 +8,6 @@ import com.ruoyi.common.cache.NowSchedulingCache; | ||
| 8 | import com.ruoyi.common.cache.SchedulingCache; | 8 | import com.ruoyi.common.cache.SchedulingCache; |
| 9 | import com.ruoyi.common.core.redis.RedisCache; | 9 | import com.ruoyi.common.core.redis.RedisCache; |
| 10 | import com.ruoyi.common.utils.StringUtils; | 10 | import com.ruoyi.common.utils.StringUtils; |
| 11 | -import com.ruoyi.common.utils.spring.SpringUtils; | ||
| 12 | import com.ruoyi.domain.scheduling.LinggangScheduling; | 11 | import com.ruoyi.domain.scheduling.LinggangScheduling; |
| 13 | import com.ruoyi.driver.domain.Driver; | 12 | import com.ruoyi.driver.domain.Driver; |
| 14 | import com.ruoyi.driver.service.IDriverService; | 13 | import com.ruoyi.driver.service.IDriverService; |
| @@ -282,15 +281,7 @@ public class DriverJob implements InitializingBean { | @@ -282,15 +281,7 @@ public class DriverJob implements InitializingBean { | ||
| 282 | idSets = linggangSchedulings.stream().map(LinggangScheduling::getId).collect(Collectors.toSet()); | 281 | idSets = linggangSchedulings.stream().map(LinggangScheduling::getId).collect(Collectors.toSet()); |
| 283 | } | 282 | } |
| 284 | 283 | ||
| 285 | - scheduling.setType(type); | ||
| 286 | - if(Objects.isNull(schedulingService)){ | ||
| 287 | - schedulingService = SpringUtils.getBean(LinggangSchedulingService.class); | ||
| 288 | - } | ||
| 289 | - Integer count = schedulingService.countId(scheduling); | ||
| 290 | - if (Objects.nonNull(count) && count > 0) { | ||
| 291 | - log.info("[{}]排班数据已经存在:[{}]", date,count); | ||
| 292 | - return; | ||
| 293 | - } | 284 | + |
| 294 | 285 | ||
| 295 | 286 | ||
| 296 | 287 |
Bsth-admin/src/main/java/com/ruoyi/service/ThreadJobService.java
| @@ -42,7 +42,6 @@ import com.ruoyi.utils.ConstDateUtil; | @@ -42,7 +42,6 @@ import com.ruoyi.utils.ConstDateUtil; | ||
| 42 | import com.ruoyi.utils.DateUtil; | 42 | import com.ruoyi.utils.DateUtil; |
| 43 | import lombok.extern.slf4j.Slf4j; | 43 | import lombok.extern.slf4j.Slf4j; |
| 44 | import org.apache.commons.collections4.CollectionUtils; | 44 | import org.apache.commons.collections4.CollectionUtils; |
| 45 | -import org.apache.commons.collections4.MapUtils; | ||
| 46 | import org.springframework.beans.BeanUtils; | 45 | import org.springframework.beans.BeanUtils; |
| 47 | import org.springframework.beans.factory.annotation.Autowired; | 46 | import org.springframework.beans.factory.annotation.Autowired; |
| 48 | import org.springframework.beans.factory.annotation.Value; | 47 | import org.springframework.beans.factory.annotation.Value; |
| @@ -417,24 +416,24 @@ public class ThreadJobService { | @@ -417,24 +416,24 @@ public class ThreadJobService { | ||
| 417 | */ | 416 | */ |
| 418 | @Async | 417 | @Async |
| 419 | @Transactional(rollbackFor = {Exception.class}) | 418 | @Transactional(rollbackFor = {Exception.class}) |
| 420 | - public synchronized void asyncComputedScheduling(Map<String, List<ResponseSchedulingDto>> originSchedulingMap, String timeOut, Date date, int type,Set<Long> idSets,String requestId) { | ||
| 421 | - JwtAuthenticationTokenFilter.putMDC("job",requestId); | ||
| 422 | - //查询当天是否保存过考情表 如果不存在则保存 | 419 | + public synchronized void asyncComputedScheduling(Map<String, List<ResponseSchedulingDto>> originSchedulingMap, String timeOut, Date date, int type, Set<Long> idSets, String requestId) { |
| 420 | + JwtAuthenticationTokenFilter.putMDC("job", requestId); | ||
| 421 | +// //查询当天是否保存过考情表 如果不存在则保存 | ||
| 423 | List<DriverScheduling> bcList = schedulingMapper.queryToDay(DateUtil.YYYY_MM_DD_LINK.format(date), DateUtil.YYYY_MM_DD_LINK.format(org.apache.commons.lang3.time.DateUtils.addDays(date, 1)), null, null, null); | 422 | List<DriverScheduling> bcList = schedulingMapper.queryToDay(DateUtil.YYYY_MM_DD_LINK.format(date), DateUtil.YYYY_MM_DD_LINK.format(org.apache.commons.lang3.time.DateUtils.addDays(date, 1)), null, null, null); |
| 424 | - Map<String, List<DriverScheduling>> dto = nowSchedulingCache.getCacheScheduling(ConstDateUtil.formatDate(date)); | ||
| 425 | - if (CollectionUtils.isNotEmpty(bcList) && MapUtils.isEmpty(dto) && Objects.equals(1, type)) { | ||
| 426 | - String dateStr = DateUtil.YYYY_MM_DD.format(date); | ||
| 427 | - Map<String, List<DriverScheduling>> resultMap = new HashMap<>(800); | ||
| 428 | - NowSchedulingCache.handlerResultMap(resultMap, bcList); | ||
| 429 | - // 更新缓存 | ||
| 430 | - nowSchedulingCache.setCacheScheduling(dateStr, resultMap); | ||
| 431 | - } | 423 | +// Map<String, List<DriverScheduling>> dto = nowSchedulingCache.getCacheScheduling(ConstDateUtil.formatDate(date)); |
| 424 | +// if (CollectionUtils.isNotEmpty(bcList) && MapUtils.isEmpty(dto) && Objects.equals(1, type)) { | ||
| 425 | +// String dateStr = DateUtil.YYYY_MM_DD.format(date); | ||
| 426 | +// Map<String, List<DriverScheduling>> resultMap = new HashMap<>(800); | ||
| 427 | +// NowSchedulingCache.handlerResultMap(resultMap, bcList); | ||
| 428 | +// // 更新缓存 | ||
| 429 | +// nowSchedulingCache.setCacheScheduling(dateStr, resultMap); | ||
| 430 | +// } | ||
| 432 | 431 | ||
| 433 | - // 当天已有记录则不在保存 或者 调度记录为空则不在保存 | ||
| 434 | - if ((CollectionUtil.isNotEmpty(dto) && CollectionUtil.isNotEmpty(bcList)) || originSchedulingMap.size() == 0) { | ||
| 435 | - log.info("调度最新数据:{},当天获取数据:{},时间:[{}]", originSchedulingMap.size(), bcList.size(), date); | ||
| 436 | - return; | ||
| 437 | - } | 432 | +// // 当天已有记录则不在保存 或者 调度记录为空则不在保存 |
| 433 | +// if ((CollectionUtil.isNotEmpty(dto) && CollectionUtil.isNotEmpty(bcList)) || originSchedulingMap.size() == 0) { | ||
| 434 | +// log.info("调度最新数据:{},当天获取数据:{},时间:[{}]", originSchedulingMap.size(), bcList.size(), date); | ||
| 435 | +// return; | ||
| 436 | +// } | ||
| 438 | 437 | ||
| 439 | if (Objects.equals(1, type)) { | 438 | if (Objects.equals(1, type)) { |
| 440 | TempCache.resetMapStatus(); | 439 | TempCache.resetMapStatus(); |
| @@ -504,7 +503,23 @@ public class ThreadJobService { | @@ -504,7 +503,23 @@ public class ThreadJobService { | ||
| 504 | } | 503 | } |
| 505 | } | 504 | } |
| 506 | 505 | ||
| 507 | - schedulingService.saveBatch(schedulings); | 506 | + LinggangScheduling scheduling = new LinggangScheduling(); |
| 507 | + scheduling.setStartScheduleDate(DateUtil.shortDate(date)); | ||
| 508 | + scheduling.setEndScheduleDate(org.apache.commons.lang3.time.DateUtils.addDays(scheduling.getStartScheduleDate(), 1)); | ||
| 509 | + | ||
| 510 | + scheduling.setType(type); | ||
| 511 | + | ||
| 512 | + List<LinggangScheduling> sourceList = schedulingService.list(scheduling); | ||
| 513 | + if (CollectionUtils.isNotEmpty(sourceList)) { | ||
| 514 | + schedulings = schedulings.stream().filter(s -> { | ||
| 515 | + Optional<LinggangScheduling> opt = sourceList.stream().filter(s1 -> s1.importEqus(s)).findFirst(); | ||
| 516 | + return !opt.isPresent(); | ||
| 517 | + }).filter(s -> Objects.nonNull(s)).collect(Collectors.toList()); | ||
| 518 | + } | ||
| 519 | + | ||
| 520 | + if(CollectionUtils.isNotEmpty(schedulings)) { | ||
| 521 | + schedulingService.saveBatch(schedulings); | ||
| 522 | + } | ||
| 508 | } | 523 | } |
| 509 | String dateStr1 = DateUtil.YYYY_MM_DD_LINK.format(date); | 524 | String dateStr1 = DateUtil.YYYY_MM_DD_LINK.format(date); |
| 510 | // 异常数据过多,不通过自增获取id再次查询获取 | 525 | // 异常数据过多,不通过自增获取id再次查询获取 |
| @@ -521,11 +536,14 @@ public class ThreadJobService { | @@ -521,11 +536,14 @@ public class ThreadJobService { | ||
| 521 | // 插入错误排班 | 536 | // 插入错误排班 |
| 522 | errorJobcodeService.insertBatchErrorJobcode(errorScheduling); | 537 | errorJobcodeService.insertBatchErrorJobcode(errorScheduling); |
| 523 | } | 538 | } |
| 524 | - if(CollectionUtils.isNotEmpty(idSets)) { | 539 | + if (CollectionUtils.isNotEmpty(idSets)) { |
| 525 | keyWorkLocationService.removeBySchedulingId(idSets); | 540 | keyWorkLocationService.removeBySchedulingId(idSets); |
| 526 | schedulingService.removeByIds(idSets); | 541 | schedulingService.removeByIds(idSets); |
| 527 | } | 542 | } |
| 528 | - keyWorkLocationService.insertJob(dateStr1,schedulings,null); | 543 | + |
| 544 | + if(CollectionUtils.isNotEmpty(schedulings)) { | ||
| 545 | + keyWorkLocationService.insertJob(dateStr1, schedulings, null); | ||
| 546 | + } | ||
| 529 | log.info("当天排班数据获取完毕,共:{}条", bcList.size()); | 547 | log.info("当天排班数据获取完毕,共:{}条", bcList.size()); |
| 530 | } | 548 | } |
| 531 | 549 |
Bsth-admin/src/main/java/com/ruoyi/service/impl/key/location/LinggangKeyWorkLocationServiceImpl.java
| @@ -292,24 +292,33 @@ public class LinggangKeyWorkLocationServiceImpl extends ServiceImpl<LinggangKeyW | @@ -292,24 +292,33 @@ public class LinggangKeyWorkLocationServiceImpl extends ServiceImpl<LinggangKeyW | ||
| 292 | 292 | ||
| 293 | @Override | 293 | @Override |
| 294 | @Transactional(rollbackFor = Exception.class) | 294 | @Transactional(rollbackFor = Exception.class) |
| 295 | - public synchronized boolean insertJob(String timeStr,List<LinggangScheduling> schedulings, Set<Long> schedulingIds) { | 295 | + public synchronized boolean insertJob(String timeStr, List<LinggangScheduling> schedulings, Set<Long> schedulingIds) { |
| 296 | try { | 296 | try { |
| 297 | removeBySchedulingId(schedulingIds); | 297 | removeBySchedulingId(schedulingIds); |
| 298 | 298 | ||
| 299 | log.info("分配钥匙所存放的柜子:[{}]", timeStr); | 299 | log.info("分配钥匙所存放的柜子:[{}]", timeStr); |
| 300 | 300 | ||
| 301 | Date date = DateUtil.YYYY_MM_DD_LINK.parse(timeStr); | 301 | Date date = DateUtil.YYYY_MM_DD_LINK.parse(timeStr); |
| 302 | - LinggangKeyWorkLocation workLocation = new LinggangKeyWorkLocation(); | ||
| 303 | - workLocation.setStartScheduleDate(date); | ||
| 304 | - workLocation.setEndScheduleDate(DateUtils.addDays(date, 1)); | ||
| 305 | - Integer count = countId(workLocation); | ||
| 306 | - if (Objects.nonNull(count) && count > 0) { | ||
| 307 | - log.error("当天的数据已经存在:[{}];[{}]", timeStr, count); | ||
| 308 | - return false; | ||
| 309 | - } | ||
| 310 | 302 | ||
| 311 | - List<LinggangKeyWorkLocation> locations = computeKeyLocal(date,schedulings); | 303 | +// Integer count = countId(workLocation); |
| 304 | +// if (Objects.nonNull(count) && count > 0) { | ||
| 305 | +// log.error("当天的数据已经存在:[{}];[{}]", timeStr, count); | ||
| 306 | +// return false; | ||
| 307 | +// } | ||
| 308 | + | ||
| 309 | + List<LinggangKeyWorkLocation> locations = computeKeyLocal(date, schedulings); | ||
| 312 | if (CollectionUtils.isNotEmpty(locations)) { | 310 | if (CollectionUtils.isNotEmpty(locations)) { |
| 311 | + LinggangKeyWorkLocation workLocation = new LinggangKeyWorkLocation(); | ||
| 312 | + workLocation.setStartScheduleDate(date); | ||
| 313 | + workLocation.setEndScheduleDate(DateUtils.addDays(date, 1)); | ||
| 314 | + List<LinggangKeyWorkLocation> source = list(workLocation); | ||
| 315 | + if (CollectionUtils.isNotEmpty(source)) { | ||
| 316 | + locations = locations.stream().filter(l -> { | ||
| 317 | + Optional<LinggangKeyWorkLocation> opt = source.stream().filter(s -> s.importEquals(l)).findFirst(); | ||
| 318 | + return !opt.isPresent(); | ||
| 319 | + }).collect(Collectors.toList()); | ||
| 320 | + } | ||
| 321 | + | ||
| 313 | return saveBatch(locations); | 322 | return saveBatch(locations); |
| 314 | } | 323 | } |
| 315 | return true; | 324 | return true; |
| @@ -397,7 +406,7 @@ public class LinggangKeyWorkLocationServiceImpl extends ServiceImpl<LinggangKeyW | @@ -397,7 +406,7 @@ public class LinggangKeyWorkLocationServiceImpl extends ServiceImpl<LinggangKeyW | ||
| 397 | if (CollectionUtils.isNotEmpty(workLocations)) { | 406 | if (CollectionUtils.isNotEmpty(workLocations)) { |
| 398 | Set<Long> ids = workLocations.stream().map(LinggangKeyWorkLocation::getId).collect(Collectors.toSet()); | 407 | Set<Long> ids = workLocations.stream().map(LinggangKeyWorkLocation::getId).collect(Collectors.toSet()); |
| 399 | if (CollectionUtils.isNotEmpty(ids)) { | 408 | if (CollectionUtils.isNotEmpty(ids)) { |
| 400 | - return removeByIds(ids); | 409 | + return removeByIds(ids); |
| 401 | } | 410 | } |
| 402 | } | 411 | } |
| 403 | } | 412 | } |
| @@ -722,10 +731,10 @@ public class LinggangKeyWorkLocationServiceImpl extends ServiceImpl<LinggangKeyW | @@ -722,10 +731,10 @@ public class LinggangKeyWorkLocationServiceImpl extends ServiceImpl<LinggangKeyW | ||
| 722 | return source; | 731 | return source; |
| 723 | } | 732 | } |
| 724 | 733 | ||
| 725 | - private List<LinggangKeyWorkLocation> computeKeyLocal(Date date,List<LinggangScheduling> sourceSchedulings) { | 734 | + private List<LinggangKeyWorkLocation> computeKeyLocal(Date date, List<LinggangScheduling> sourceSchedulings) { |
| 726 | 735 | ||
| 727 | 736 | ||
| 728 | - List<LinggangScheduling> schedulings = querySchedulingByTiime(date,sourceSchedulings); | 737 | + List<LinggangScheduling> schedulings = querySchedulingByTiime(date, sourceSchedulings); |
| 729 | if (schedulings == null) return null; | 738 | if (schedulings == null) return null; |
| 730 | 739 | ||
| 731 | List<LinggangVenueInfo> venueInfos = queryVenueInfo(schedulings); | 740 | List<LinggangVenueInfo> venueInfos = queryVenueInfo(schedulings); |
| @@ -817,10 +826,10 @@ public class LinggangKeyWorkLocationServiceImpl extends ServiceImpl<LinggangKeyW | @@ -817,10 +826,10 @@ public class LinggangKeyWorkLocationServiceImpl extends ServiceImpl<LinggangKeyW | ||
| 817 | }).filter(obj -> Objects.nonNull(obj)).collect(Collectors.toList()); | 826 | }).filter(obj -> Objects.nonNull(obj)).collect(Collectors.toList()); |
| 818 | } | 827 | } |
| 819 | 828 | ||
| 820 | - private List<LinggangScheduling> querySchedulingByTiime(Date date,List<LinggangScheduling> schedulings) { | ||
| 821 | - if(CollectionUtils.isNotEmpty(schedulings)){ | ||
| 822 | - schedulings = schedulings.stream().filter(s->Objects.nonNull(s.getId())).collect(Collectors.toList()); | ||
| 823 | - if(CollectionUtils.isNotEmpty(schedulings)) { | 829 | + private List<LinggangScheduling> querySchedulingByTiime(Date date, List<LinggangScheduling> schedulings) { |
| 830 | + if (CollectionUtils.isNotEmpty(schedulings)) { | ||
| 831 | + schedulings = schedulings.stream().filter(s -> Objects.nonNull(s.getId())).collect(Collectors.toList()); | ||
| 832 | + if (CollectionUtils.isNotEmpty(schedulings)) { | ||
| 824 | return schedulings; | 833 | return schedulings; |
| 825 | } | 834 | } |
| 826 | } | 835 | } |