Commit e57171a946e8a0a685e42cff7910981c36ed3680

Authored by liujun001
1 parent 1b83bb7c

数据字典添加分别字符key

Bsth-admin/src/main/java/com/ruoyi/controller/RefreshController.java
... ... @@ -60,7 +60,7 @@ public class RefreshController {
60 60  
61 61 List<LinggangScheduling> linggangSchedulings = linggangSchedulingService.list(scheduling);
62 62 Set<Long> idSets = linggangSchedulings.stream().map(LinggangScheduling::getId).collect(Collectors.toSet());
63   - keyWorkLocationService.insertJob(dateStr, idSets);
  63 + keyWorkLocationService.insertJob(dateStr,null, idSets);
64 64 return ResponseResult.success();
65 65 }
66 66  
... ...
Bsth-admin/src/main/java/com/ruoyi/controller/dss/KeyBoxController.java
... ... @@ -440,6 +440,9 @@ public class KeyBoxController extends BaseController {
440 440 keyInfos = keyInfoService.listLikePlate(keyInfo);
441 441 if (CollectionUtils.isNotEmpty(keyInfos)) {
442 442 keyInfoIds = keyInfos.stream().map(KeyInfo::getId).collect(Collectors.toSet());
  443 + }else{
  444 + keyInfoIds = new HashSet<>();
  445 + keyInfoIds.add(-10000);
443 446 }
444 447 }
445 448  
... ...
Bsth-admin/src/main/java/com/ruoyi/job/DriverJob.java
... ... @@ -26,6 +26,7 @@ import com.ruoyi.service.DriverSchedulingExpandSmartService;
26 26 import com.ruoyi.service.RuleAttendanceMainService;
27 27 import com.ruoyi.service.RuleNumSettingService;
28 28 import com.ruoyi.service.ThreadJobService;
  29 +import com.ruoyi.service.key.location.LinggangKeyWorkLocationService;
29 30 import com.ruoyi.service.scheduling.LinggangSchedulingService;
30 31 import com.ruoyi.utils.ConstDateUtil;
31 32 import com.ruoyi.utils.DateUtil;
... ... @@ -103,6 +104,8 @@ public class DriverJob implements InitializingBean {
103 104 private RuleAttendanceMainService attendanceMainService;
104 105 @Autowired
105 106 private LinggangSchedulingService schedulingService;
  107 + @Autowired
  108 + private LinggangKeyWorkLocationService keyWorkLocationService;
106 109  
107 110 @Value("${api.url.getDriverInfo}")
108 111 private String getDriverInfoUrl;
... ... @@ -253,7 +256,6 @@ public class DriverJob implements InitializingBean {
253 256  
254 257 }
255 258  
256   - @Transactional(rollbackFor = Exception.class)
257 259 public void runScheduling(long timeLong) {
258 260 long timestamp = System.currentTimeMillis();
259 261 Date date = new Date(timeLong);
... ... @@ -278,9 +280,6 @@ public class DriverJob implements InitializingBean {
278 280 scheduling.setType(100);
279 281 List<LinggangScheduling> linggangSchedulings = schedulingService.list(scheduling);
280 282 idSets = linggangSchedulings.stream().map(LinggangScheduling::getId).collect(Collectors.toSet());
281   - if (CollectionUtils.isNotEmpty(idSets)) {
282   - schedulingService.removeByIds(idSets);
283   - }
284 283 }
285 284  
286 285 scheduling.setType(type);
... ... @@ -453,6 +452,7 @@ public class DriverJob implements InitializingBean {
453 452 THREAD_JOB_SERVICE.asyncComputedScheduling(driverSchedulingMap, timeOut, date, type,idSets,requestId);
454 453 // 实时排班直接存入缓存
455 454 SCHEDULING_CACHE.setCacheScheduling(DRIVER_SCHEDULING_PRE + dateKey, driverSchedulingMap);
  455 +
456 456 log.info("拉取排班完毕:{}", dateKey);
457 457 return driverSchedulingMap;
458 458 }
... ...
Bsth-admin/src/main/java/com/ruoyi/mapper/driver/NewDriverMapper.java
... ... @@ -11,4 +11,6 @@ public interface NewDriverMapper extends BaseMapper&lt;NewDriver&gt; {
11 11 * 插入有值的列
12 12 */
13 13 int insertSelective(NewDriver name);
  14 +
  15 + int updateSelective(NewDriver driver);
14 16 }
15 17 \ No newline at end of file
... ...
Bsth-admin/src/main/java/com/ruoyi/service/ThreadJobService.java
... ... @@ -417,7 +417,7 @@ public class ThreadJobService {
417 417 */
418 418 @Async
419 419 @Transactional(rollbackFor = {Exception.class})
420   - public void asyncComputedScheduling(Map<String, List<ResponseSchedulingDto>> originSchedulingMap, String timeOut, Date date, int type,Set<Long> IdSets,String requestId) {
  420 + public synchronized void asyncComputedScheduling(Map<String, List<ResponseSchedulingDto>> originSchedulingMap, String timeOut, Date date, int type,Set<Long> idSets,String requestId) {
421 421 JwtAuthenticationTokenFilter.putMDC("job",requestId);
422 422 //查询当天是否保存过考情表 如果不存在则保存
423 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);
... ... @@ -521,7 +521,11 @@ public class ThreadJobService {
521 521 // 插入错误排班
522 522 errorJobcodeService.insertBatchErrorJobcode(errorScheduling);
523 523 }
524   - keyWorkLocationService.insertJob(dateStr1,IdSets);
  524 + if(CollectionUtils.isNotEmpty(idSets)) {
  525 + keyWorkLocationService.removeBySchedulingId(idSets);
  526 + schedulingService.removeByIds(idSets);
  527 + }
  528 + keyWorkLocationService.insertJob(dateStr1,schedulings,null);
525 529 log.info("当天排班数据获取完毕,共:{}条", bcList.size());
526 530 }
527 531  
... ...
Bsth-admin/src/main/java/com/ruoyi/service/impl/driver/NewDriverServiceImpl.java
... ... @@ -221,6 +221,42 @@ public class NewDriverServiceImpl extends ServiceImpl&lt;NewDriverMapper, NewDriver
221 221 return false;
222 222 }
223 223  
  224 + Set<String> reqJobs = drivers.stream().map(NewDriver::getJobCode).collect(Collectors.toSet());
  225 + List<NewDriver> sourceDriver = list(reqJobs);
  226 + if (CollectionUtils.isEmpty(sourceDriver)) {
  227 + return saveBatch(drivers);
  228 + }
  229 +
  230 + drivers = drivers.stream().map(d -> {
  231 + Optional<NewDriver> opt = sourceDriver.stream().filter(s -> Objects.equals(s.getJobCode(), d.getJobCode())).findFirst();
  232 + if (opt.isPresent()) {
  233 + d.setId(opt.get().getId());
  234 + d.setImage(null);
  235 + }
  236 + return d;
  237 + }).collect(Collectors.toList());
  238 +
  239 + List<NewDriver> updateDriver = drivers.stream().filter(d -> Objects.nonNull(d.getId())).collect(Collectors.toList());
  240 + List<NewDriver> addDriver = drivers.stream().filter(d -> Objects.isNull(d.getId())).collect(Collectors.toList());
  241 +
  242 + return updateByPrimaryKeys(updateDriver) && insertBach(addDriver);
  243 + }
  244 +
  245 + public boolean updateByPrimaryKeys(List<NewDriver> drivers) {
  246 + if (CollectionUtils.isEmpty(drivers)) {
  247 + return true;
  248 + }
  249 + Set<Boolean> flags = new HashSet<>();
  250 + for (NewDriver driver : drivers) {
  251 + flags.add(updateByPrimaryKey(driver));
  252 + }
  253 + return flags.contains(Boolean.FALSE) ? Boolean.FALSE : Boolean.TRUE;
  254 + }
  255 +
  256 + public boolean insertBach(List<NewDriver> drivers) {
  257 + if (CollectionUtils.isEmpty(drivers)) {
  258 + return true;
  259 + }
224 260 return saveBatch(drivers);
225 261 }
226 262  
... ... @@ -261,11 +297,6 @@ public class NewDriverServiceImpl extends ServiceImpl&lt;NewDriverMapper, NewDriver
261 297  
262 298 driver.setJobCode(Convert.toStr(obj.get("personNumber")));
263 299  
264   - if (CollectionUtils.isNotEmpty(jobs) && jobs.contains(driver.getJobCode())) {
265   - log.info("[{}]的数据已经存在", obj);
266   - return null;
267   - }
268   -
269 300 driver.setCompanyCode(Convert.toStr(obj.get("companyNumner")));
270 301 driver.setBrancheCompanyCode(Convert.toStr(obj.get("companyNumner")));
271 302 driver.setPersonnelName(Convert.toStr(obj.get("personName")));
... ...
Bsth-admin/src/main/java/com/ruoyi/service/impl/key/location/LinggangKeyWorkLocationServiceImpl.java
... ... @@ -78,7 +78,7 @@ public class LinggangKeyWorkLocationServiceImpl extends ServiceImpl&lt;LinggangKeyW
78 78 countWrapper.select(LinggangKeyWorkLocation::getId);
79 79 switchTime(entity, countWrapper);
80 80 switchTypes(entity, countWrapper);
81   - switchKeyInfoIds(entity,countWrapper);
  81 + switchKeyInfoIds(entity, countWrapper);
82 82 int count = count(countWrapper);
83 83  
84 84 List<LinggangKeyWorkLocation> lists = Collections.emptyList();
... ... @@ -87,7 +87,7 @@ public class LinggangKeyWorkLocationServiceImpl extends ServiceImpl&lt;LinggangKeyW
87 87 LambdaQueryWrapper<LinggangKeyWorkLocation> selectWrapper = new LambdaQueryWrapper<>(entity);
88 88 switchTime(entity, selectWrapper);
89 89 switchTypes(entity, selectWrapper);
90   - switchKeyInfoIds(entity,selectWrapper);
  90 + switchKeyInfoIds(entity, selectWrapper);
91 91 orderColumn(selectWrapper, orderEntity);
92 92 lists = list(selectWrapper);
93 93 }
... ... @@ -292,17 +292,9 @@ public class LinggangKeyWorkLocationServiceImpl extends ServiceImpl&lt;LinggangKeyW
292 292  
293 293 @Override
294 294 @Transactional(rollbackFor = Exception.class)
295   - public boolean insertJob(String timeStr, Set<Long> schedulingIds) {
  295 + public synchronized boolean insertJob(String timeStr,List<LinggangScheduling> schedulings, Set<Long> schedulingIds) {
296 296 try {
297   - if (CollectionUtils.isNotEmpty(schedulingIds)) {
298   - List<LinggangKeyWorkLocation> workLocations = listRecent(null, schedulingIds);
299   - if (CollectionUtils.isNotEmpty(workLocations)) {
300   - Set<Long> ids = workLocations.stream().map(LinggangKeyWorkLocation::getId).collect(Collectors.toSet());
301   - if (CollectionUtils.isNotEmpty(ids)) {
302   - removeByIds(ids);
303   - }
304   - }
305   - }
  297 + removeBySchedulingId(schedulingIds);
306 298  
307 299 log.info("分配钥匙所存放的柜子:[{}]", timeStr);
308 300  
... ... @@ -316,7 +308,7 @@ public class LinggangKeyWorkLocationServiceImpl extends ServiceImpl&lt;LinggangKeyW
316 308 return false;
317 309 }
318 310  
319   - List<LinggangKeyWorkLocation> locations = computeKeyLocal(date);
  311 + List<LinggangKeyWorkLocation> locations = computeKeyLocal(date,schedulings);
320 312 if (CollectionUtils.isNotEmpty(locations)) {
321 313 return saveBatch(locations);
322 314 }
... ... @@ -398,6 +390,20 @@ public class LinggangKeyWorkLocationServiceImpl extends ServiceImpl&lt;LinggangKeyW
398 390 return removeById(id);
399 391 }
400 392  
  393 + @Override
  394 + public boolean removeBySchedulingId(Set<Long> schedulingIds) {
  395 + if (CollectionUtils.isNotEmpty(schedulingIds)) {
  396 + List<LinggangKeyWorkLocation> workLocations = listRecent(null, schedulingIds);
  397 + if (CollectionUtils.isNotEmpty(workLocations)) {
  398 + Set<Long> ids = workLocations.stream().map(LinggangKeyWorkLocation::getId).collect(Collectors.toSet());
  399 + if (CollectionUtils.isNotEmpty(ids)) {
  400 + return removeByIds(ids);
  401 + }
  402 + }
  403 + }
  404 + return true;
  405 + }
  406 +
401 407  
402 408 public static void orderColumn(LambdaQueryWrapper<LinggangKeyWorkLocation> wrapper, OrderEntity orderEntity) {
403 409 if (org.apache.commons.lang3.StringUtils.equals("ascending", orderEntity.getOrder())) {
... ... @@ -716,10 +722,10 @@ public class LinggangKeyWorkLocationServiceImpl extends ServiceImpl&lt;LinggangKeyW
716 722 return source;
717 723 }
718 724  
719   - private List<LinggangKeyWorkLocation> computeKeyLocal(Date date) {
  725 + private List<LinggangKeyWorkLocation> computeKeyLocal(Date date,List<LinggangScheduling> sourceSchedulings) {
720 726  
721 727  
722   - List<LinggangScheduling> schedulings = querySchedulingByTiime(date);
  728 + List<LinggangScheduling> schedulings = querySchedulingByTiime(date,sourceSchedulings);
723 729 if (schedulings == null) return null;
724 730  
725 731 List<LinggangVenueInfo> venueInfos = queryVenueInfo(schedulings);
... ... @@ -811,12 +817,18 @@ public class LinggangKeyWorkLocationServiceImpl extends ServiceImpl&lt;LinggangKeyW
811 817 }).filter(obj -> Objects.nonNull(obj)).collect(Collectors.toList());
812 818 }
813 819  
814   - private List<LinggangScheduling> querySchedulingByTiime(Date date) {
  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)) {
  824 + return schedulings;
  825 + }
  826 + }
815 827 LinggangScheduling scheduling = new LinggangScheduling();
816 828 scheduling.setStartScheduleDate(DateUtil.shortDate(date));
817 829 scheduling.setEndScheduleDate(DateUtils.addDays(scheduling.getStartScheduleDate(), 1));
818 830 scheduling.setBcType(BC_TYPE_OUT);
819   - List<LinggangScheduling> schedulings = schedulingService.list(scheduling);
  831 + schedulings = schedulingService.list(scheduling);
820 832 if (CollectionUtils.isEmpty(schedulings)) {
821 833 log.info("没有查到排班信息:[{}]", date);
822 834 return null;
... ...
Bsth-admin/src/main/java/com/ruoyi/service/key/location/LinggangKeyWorkLocationService.java
... ... @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
5 5 import com.ruoyi.common.core.domain.ResponseResult;
6 6 import com.ruoyi.domain.OrderEntity;
7 7 import com.ruoyi.domain.key.location.LinggangKeyWorkLocation;
  8 +import com.ruoyi.domain.scheduling.LinggangScheduling;
8 9  
9 10 import java.util.Collection;
10 11 import java.util.Date;
... ... @@ -60,7 +61,7 @@ public interface LinggangKeyWorkLocationService extends IService&lt;LinggangKeyWork
60 61 /***插入数据*/
61 62 boolean insert(LinggangKeyWorkLocation entity);
62 63  
63   - boolean insertJob(String timeStr, Set<Long> IdSets);
  64 + boolean insertJob(String timeStr, List<LinggangScheduling> schedulings, Set<Long> IdSets);
64 65  
65 66 /**
66 67 * 根据主键修改数据
... ... @@ -78,4 +79,6 @@ public interface LinggangKeyWorkLocationService extends IService&lt;LinggangKeyWork
78 79  
79 80 boolean deleteById(Long id);
80 81  
  82 + boolean removeBySchedulingId(Set<Long> schedulingId );
  83 +
81 84 }
82 85 \ No newline at end of file
... ...
Bsth-admin/src/main/resources/mapper/driver/NewDriverMapper.xml
... ... @@ -32,13 +32,18 @@
32 32 <result column="image_version" jdbcType="VARCHAR" property="imageVersion"/>
33 33 </resultMap>
34 34  
35   - <insert id="insertSelective" keyColumn="job_code" keyProperty="jobCode" useGeneratedKeys="true"
  35 + <insert id="insertSelective" keyColumn="id" keyProperty="id" useGeneratedKeys="true"
36 36 parameterType="com.ruoyi.domain.driver.NewDriver">
37 37 INSERT INTO driver
38 38 <include refid="insertSelectiveColumn"></include>
39 39 <include refid="insertSelectiveValue"></include>
40 40 </insert>
41 41  
  42 + <update id="updateSelective" parameterType="com.ruoyi.domain.driver.NewDriver">
  43 + update driver set <include refid="updateByPrimaryKeySelectiveSql"></include>
  44 + where id=#{id}
  45 + </update>
  46 +
42 47 <sql id="columns">
43 48 id
44 49 , job_code , company_code , branche_company_code , personnel_name , papers_code , ic_card_code , personnel_type , posts , card , telphone , ic_rfid , id_rfid , tag_rfid , remark , line_name , line_code , face_sign_in , image , update_time , sign_in_equipment , fleet_name , face_Feature , blue_Tooth , driver_integer , synContent , csn , image_version
... ...