LocalBusDeviceRunningService.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package com.coffee.bus.service;
  2. import cn.hutool.core.collection.CollectionUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.coffee.bus.controller.vo.ManualUndoConfig;
  5. import com.coffee.bus.entity.BusClinicEntity;
  6. import com.coffee.bus.entity.BusDeviceRunningEntity;
  7. import com.coffee.bus.entity.BusDeviceHistoryEntity;
  8. import com.coffee.bus.mapper.BusDeviceRunningMapper;
  9. import com.coffee.common.crud.BaseService;
  10. import lombok.AllArgsConstructor;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import java.util.Date;
  14. import java.util.List;
  15. import java.util.Map;
  16. import java.util.Set;
  17. import java.util.stream.Collectors;
  18. /**
  19. * @author lifang
  20. * @version 1.0.0
  21. * @ClassName LocalBusHospitalService.java
  22. * @Description TODO
  23. * @createTime 2022年03月19日 09:27:00
  24. */
  25. @Service
  26. @AllArgsConstructor
  27. public class LocalBusDeviceRunningService extends BaseService<BusDeviceRunningMapper, BusDeviceRunningEntity,String> {
  28. private final LocalBusClinicService clinicService;
  29. private final LocalBusDeviceHistoryService historyService;
  30. @Override
  31. public void validateBeforeSave(BusDeviceRunningEntity entity) {
  32. }
  33. @Override
  34. public void validateBeforeUpdate(BusDeviceRunningEntity entity) {
  35. }
  36. @Override
  37. public void validateBeforeDelete(String id) {
  38. }
  39. public boolean firstRegister(String deviceId){
  40. return this.getOne(new QueryWrapper<BusDeviceRunningEntity>().lambda().eq(BusDeviceRunningEntity::getDeviceId,deviceId))!=null;
  41. }
  42. public BusDeviceRunningEntity getByDeviceId(String deviceId){
  43. return this.getOne(new QueryWrapper<BusDeviceRunningEntity>().lambda().eq(BusDeviceRunningEntity::getDeviceId,deviceId));
  44. }
  45. /**
  46. * 撤泵操作
  47. * @param manualUndoConfig
  48. */
  49. @Transactional(rollbackFor = Exception.class)
  50. public void undo(ManualUndoConfig manualUndoConfig) {
  51. List<String> ids = manualUndoConfig.getIds();
  52. if(CollectionUtil.isEmpty(ids)){
  53. return;
  54. }
  55. /****************将撤泵记录存入到泵的使用历史记录中***************/
  56. List<BusDeviceRunningEntity> pumps = this.listByIds(ids);
  57. //获取有泵监护的临床信息
  58. Set<String> clinicIds = pumps.stream().map(BusDeviceRunningEntity::getClinicId).collect(Collectors.toSet());
  59. List<BusClinicEntity> clinics = clinicService.listByIds(clinicIds);
  60. Map<String, List<BusClinicEntity>> clinicMap = clinics.stream().collect(Collectors.groupingBy(BusClinicEntity::getId));
  61. //泵的撤泵数据插入到历史数据中
  62. List<BusDeviceHistoryEntity> pumpHistories = pumps.stream().map(pump -> {
  63. BusDeviceHistoryEntity history = BusDeviceHistoryEntity.of(pump, clinicMap.get(pump.getClinicId()).get(0));
  64. history.setUndoBy(manualUndoConfig.getUndoBy());
  65. history.setUndoTime(manualUndoConfig.getUndoTime());
  66. history.setDestroyer(manualUndoConfig.getDestroyer());
  67. history.setWitnesses(manualUndoConfig.getWitnesses());
  68. history.setIsUndo(1);
  69. return history;
  70. }).collect(Collectors.toList());
  71. historyService.saveBatch(pumpHistories);
  72. /****************将撤泵记录存入到泵的使用历史记录中***************/
  73. /****************将泵改为撤泵状态***************/
  74. this.updateBatchById(ids.stream().map(id->{
  75. BusDeviceRunningEntity pump = new BusDeviceRunningEntity();
  76. pump.setId(id);
  77. pump.setIsUndo(true);
  78. return pump;
  79. }).collect(Collectors.toList()));
  80. /****************将泵改为撤泵状态***************/
  81. /****************对临床时间进行记录***************/
  82. clinics.forEach(clinic->{
  83. clinic.setEndTime(new Date());
  84. clinic.setFinished(1);
  85. });
  86. clinicService.updateBatchById(clinics);
  87. /****************对临床时间进行记录***************/
  88. }
  89. }