| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- package com.coffee.bus.service;
- import cn.hutool.core.collection.CollectionUtil;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.coffee.bus.controller.vo.ManualUndoConfig;
- import com.coffee.bus.entity.BusClinicEntity;
- import com.coffee.bus.entity.BusDeviceRunningEntity;
- import com.coffee.bus.entity.BusDeviceHistoryEntity;
- import com.coffee.bus.mapper.BusDeviceRunningMapper;
- import com.coffee.common.crud.BaseService;
- import lombok.AllArgsConstructor;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import java.util.stream.Collectors;
- /**
- * @author lifang
- * @version 1.0.0
- * @ClassName LocalBusHospitalService.java
- * @Description TODO
- * @createTime 2022年03月19日 09:27:00
- */
- @Service
- @AllArgsConstructor
- public class LocalBusDeviceRunningService extends BaseService<BusDeviceRunningMapper, BusDeviceRunningEntity,String> {
- private final LocalBusClinicService clinicService;
- private final LocalBusDeviceHistoryService historyService;
- @Override
- public void validateBeforeSave(BusDeviceRunningEntity entity) {
- }
- @Override
- public void validateBeforeUpdate(BusDeviceRunningEntity entity) {
- }
- @Override
- public void validateBeforeDelete(String id) {
- }
- public boolean firstRegister(String deviceId){
- return this.getOne(new QueryWrapper<BusDeviceRunningEntity>().lambda().eq(BusDeviceRunningEntity::getDeviceId,deviceId))!=null;
- }
- public BusDeviceRunningEntity getByDeviceId(String deviceId){
- return this.getOne(new QueryWrapper<BusDeviceRunningEntity>().lambda().eq(BusDeviceRunningEntity::getDeviceId,deviceId));
- }
- /**
- * 撤泵操作
- * @param manualUndoConfig
- */
- @Transactional(rollbackFor = Exception.class)
- public void undo(ManualUndoConfig manualUndoConfig) {
- List<String> ids = manualUndoConfig.getIds();
- if(CollectionUtil.isEmpty(ids)){
- return;
- }
- /****************将撤泵记录存入到泵的使用历史记录中***************/
- List<BusDeviceRunningEntity> pumps = this.listByIds(ids);
- //获取有泵监护的临床信息
- Set<String> clinicIds = pumps.stream().map(BusDeviceRunningEntity::getClinicId).collect(Collectors.toSet());
- List<BusClinicEntity> clinics = clinicService.listByIds(clinicIds);
- Map<String, List<BusClinicEntity>> clinicMap = clinics.stream().collect(Collectors.groupingBy(BusClinicEntity::getId));
- //泵的撤泵数据插入到历史数据中
- List<BusDeviceHistoryEntity> pumpHistories = pumps.stream().map(pump -> {
- BusDeviceHistoryEntity history = BusDeviceHistoryEntity.of(pump, clinicMap.get(pump.getClinicId()).get(0));
- history.setUndoBy(manualUndoConfig.getUndoBy());
- history.setUndoTime(manualUndoConfig.getUndoTime());
- history.setDestroyer(manualUndoConfig.getDestroyer());
- history.setWitnesses(manualUndoConfig.getWitnesses());
- history.setIsUndo(1);
- return history;
- }).collect(Collectors.toList());
- historyService.saveBatch(pumpHistories);
- /****************将撤泵记录存入到泵的使用历史记录中***************/
- /****************将泵改为撤泵状态***************/
- this.updateBatchById(ids.stream().map(id->{
- BusDeviceRunningEntity pump = new BusDeviceRunningEntity();
- pump.setId(id);
- pump.setIsUndo(true);
- return pump;
- }).collect(Collectors.toList()));
- /****************将泵改为撤泵状态***************/
- /****************对临床时间进行记录***************/
- clinics.forEach(clinic->{
- clinic.setEndTime(new Date());
- clinic.setFinished(1);
- });
- clinicService.updateBatchById(clinics);
- /****************对临床时间进行记录***************/
- }
- }
|