| package com.doumee.service.business.impl; | 
|   | 
| import com.doumee.service.business.third.model.PageData; | 
| import com.doumee.service.business.third.model.PageWrap; | 
| import com.doumee.core.utils.Constants; | 
| import com.doumee.core.utils.Utils; | 
| import com.doumee.dao.business.PlatformWarnEventMapper; | 
| import com.doumee.dao.business.join.PlatformWarnEventJoinMapper; | 
| import com.doumee.dao.business.model.Platform; | 
| import com.doumee.dao.business.model.PlatformWarnEvent; | 
| import com.doumee.dao.openapi.response.PlatformWarnEventListResponse; | 
| import com.doumee.dao.web.reqeust.SavePlatformWarnEventDTO; | 
| import com.doumee.service.business.PlatformWarnEventService; | 
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
| import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
| import com.baomidou.mybatisplus.core.metadata.IPage; | 
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
| import com.github.yulichang.wrapper.MPJLambdaWrapper; | 
| import org.apache.commons.lang3.StringUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.util.CollectionUtils; | 
|   | 
| import java.util.ArrayList; | 
| import java.util.Date; | 
| import java.util.List; | 
| import java.util.Objects; | 
|   | 
| /** | 
|  * 月台预警信息Service实现 | 
|  * @author 江蹄蹄 | 
|  * @date 2024/09/25 09:41 | 
|  */ | 
| @Service | 
| public class PlatformWarnEventServiceImpl implements PlatformWarnEventService { | 
|   | 
|     @Autowired | 
|     private PlatformWarnEventMapper platformWarnEventMapper; | 
|   | 
|     @Autowired | 
|     private PlatformWarnEventJoinMapper platformWarnEventJoinMapper; | 
|   | 
|   | 
|   | 
|     @Override | 
|     public Integer create(PlatformWarnEvent platformWarnEvent) { | 
|         platformWarnEventMapper.insert(platformWarnEvent); | 
|         return platformWarnEvent.getId(); | 
|     } | 
|   | 
|     @Override | 
|     public void deleteById(Integer id) { | 
|         platformWarnEventMapper.deleteById(id); | 
|     } | 
|   | 
|     @Override | 
|     public void delete(PlatformWarnEvent platformWarnEvent) { | 
|         UpdateWrapper<PlatformWarnEvent> deleteWrapper = new UpdateWrapper<>(platformWarnEvent); | 
|         platformWarnEventMapper.delete(deleteWrapper); | 
|     } | 
|   | 
|     @Override | 
|     public void deleteByIdInBatch(List<Integer> ids) { | 
|         if (CollectionUtils.isEmpty(ids)) { | 
|             return; | 
|         } | 
|         platformWarnEventMapper.deleteBatchIds(ids); | 
|     } | 
|   | 
|     @Override | 
|     public void updateById(PlatformWarnEvent platformWarnEvent) { | 
|         platformWarnEventMapper.updateById(platformWarnEvent); | 
|     } | 
|   | 
|     @Override | 
|     public void updateByIdInBatch(List<PlatformWarnEvent> platformWarnEvents) { | 
|         if (CollectionUtils.isEmpty(platformWarnEvents)) { | 
|             return; | 
|         } | 
|         for (PlatformWarnEvent platformWarnEvent: platformWarnEvents) { | 
|             this.updateById(platformWarnEvent); | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     public PlatformWarnEvent findById(Integer id) { | 
|         return platformWarnEventMapper.selectById(id); | 
|     } | 
|   | 
|     @Override | 
|     public PlatformWarnEvent findOne(PlatformWarnEvent platformWarnEvent) { | 
|         QueryWrapper<PlatformWarnEvent> wrapper = new QueryWrapper<>(platformWarnEvent); | 
|         return platformWarnEventMapper.selectOne(wrapper); | 
|     } | 
|   | 
|     @Override | 
|     public List<PlatformWarnEvent> findList(PlatformWarnEvent platformWarnEvent) { | 
|         QueryWrapper<PlatformWarnEvent> wrapper = new QueryWrapper<>(platformWarnEvent); | 
|         return platformWarnEventMapper.selectList(wrapper); | 
|     } | 
|   | 
|     @Override | 
|     public List<PlatformWarnEventListResponse> findListToHk() { | 
|         List<PlatformWarnEvent>  platformWarnEvents = platformWarnEventJoinMapper.selectJoinList(PlatformWarnEvent.class, | 
|                 new MPJLambdaWrapper<PlatformWarnEvent>() | 
|                         .selectAll(PlatformWarnEvent.class) | 
|                         .selectAs(Platform::getName,PlatformWarnEvent::getPlatformName) | 
|                         .selectAs(Platform::getHkId,PlatformWarnEvent::getPlatfromHkId) | 
|                         .leftJoin(Platform.class,Platform::getId,PlatformWarnEvent::getPlatformId) | 
|                         .orderByDesc(PlatformWarnEvent::getCreateDate) | 
|                         .last(" limit 20 ") | 
|         ); | 
|         List<PlatformWarnEventListResponse> list = new ArrayList<PlatformWarnEventListResponse>(); | 
|         if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platformWarnEvents)){ | 
|             for (PlatformWarnEvent event:platformWarnEvents) { | 
|                 PlatformWarnEventListResponse platformWarnEventListResponse = new PlatformWarnEventListResponse(); | 
|                 platformWarnEventListResponse.setPlatformName(event.getPlatformName()); | 
|                 platformWarnEventListResponse.setCreateDate(event.getCreateDate()); | 
|                 platformWarnEventListResponse.setContent(event.getEventContent()); | 
|                 platformWarnEventListResponse.setTitle(event.getTitle()); | 
|                 platformWarnEventListResponse.setPlatfromHkId(event.getPlatfromHkId()); | 
|                 platformWarnEventListResponse.setCarCode(event.getCarCode()); | 
|                 list.add(platformWarnEventListResponse); | 
|             } | 
|         } | 
|         return list; | 
|     } | 
|    | 
|     @Override | 
|     public PageData<PlatformWarnEvent> findPage(PageWrap<PlatformWarnEvent> pageWrap) { | 
|         IPage<PlatformWarnEvent> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|         QueryWrapper<PlatformWarnEvent> queryWrapper = new QueryWrapper<>(); | 
|         Utils.MP.blankToNull(pageWrap.getModel()); | 
|         if (pageWrap.getModel().getId() != null) { | 
|             queryWrapper.lambda().eq(PlatformWarnEvent::getId, pageWrap.getModel().getId()); | 
|         } | 
|         if (pageWrap.getModel().getCreator() != null) { | 
|             queryWrapper.lambda().eq(PlatformWarnEvent::getCreator, pageWrap.getModel().getCreator()); | 
|         } | 
|         if (pageWrap.getModel().getCreateDate() != null) { | 
|             queryWrapper.lambda().ge(PlatformWarnEvent::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); | 
|             queryWrapper.lambda().le(PlatformWarnEvent::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); | 
|         } | 
|         if (pageWrap.getModel().getEditor() != null) { | 
|             queryWrapper.lambda().eq(PlatformWarnEvent::getEditor, pageWrap.getModel().getEditor()); | 
|         } | 
|         if (pageWrap.getModel().getEditDate() != null) { | 
|             queryWrapper.lambda().ge(PlatformWarnEvent::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); | 
|             queryWrapper.lambda().le(PlatformWarnEvent::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); | 
|         } | 
|         if (pageWrap.getModel().getIsdeleted() != null) { | 
|             queryWrapper.lambda().eq(PlatformWarnEvent::getIsdeleted, pageWrap.getModel().getIsdeleted()); | 
|         } | 
|         if (pageWrap.getModel().getRemark() != null) { | 
|             queryWrapper.lambda().eq(PlatformWarnEvent::getRemark, pageWrap.getModel().getRemark()); | 
|         } | 
|         if (pageWrap.getModel().getPlatformId() != null) { | 
|             queryWrapper.lambda().eq(PlatformWarnEvent::getPlatformId, pageWrap.getModel().getPlatformId()); | 
|         } | 
|         if (pageWrap.getModel().getTitle() != null) { | 
|             queryWrapper.lambda().eq(PlatformWarnEvent::getTitle, pageWrap.getModel().getTitle()); | 
|         } | 
|         if (pageWrap.getModel().getCarCode() != null) { | 
|             queryWrapper.lambda().eq(PlatformWarnEvent::getCarCode, pageWrap.getModel().getCarCode()); | 
|         } | 
|         if (pageWrap.getModel().getEventContent() != null) { | 
|             queryWrapper.lambda().eq(PlatformWarnEvent::getEventContent, pageWrap.getModel().getEventContent()); | 
|         } | 
|         if (pageWrap.getModel().getPlatformJobId() != null) { | 
|             queryWrapper.lambda().eq(PlatformWarnEvent::getPlatformJobId, pageWrap.getModel().getPlatformJobId()); | 
|         } | 
|         if (pageWrap.getModel().getEventType() != null) { | 
|             queryWrapper.lambda().eq(PlatformWarnEvent::getEventType, pageWrap.getModel().getEventType()); | 
|         } | 
|         for(PageWrap.SortData sortData: pageWrap.getSorts()) { | 
|             if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { | 
|                 queryWrapper.orderByDesc(sortData.getProperty()); | 
|             } else { | 
|                 queryWrapper.orderByAsc(sortData.getProperty()); | 
|             } | 
|         } | 
|         return PageData.from(platformWarnEventMapper.selectPage(page, queryWrapper)); | 
|     } | 
|   | 
|     @Override | 
|     public long count(PlatformWarnEvent platformWarnEvent) { | 
|         QueryWrapper<PlatformWarnEvent> wrapper = new QueryWrapper<>(platformWarnEvent); | 
|         return platformWarnEventMapper.selectCount(wrapper); | 
|     } | 
|   | 
|   | 
|     @Override | 
|     public void savePlatformWarnEvent(SavePlatformWarnEventDTO savePlatformWarnEventDTO){ | 
|         if(Objects.isNull(savePlatformWarnEventDTO) | 
|              || Objects.isNull(savePlatformWarnEventDTO.getEventType()) | 
|              || StringUtils.isBlank(savePlatformWarnEventDTO.getCarCode()) | 
|         ){ | 
|             return; | 
|         } | 
|         PlatformWarnEvent platformWarnEvent = new PlatformWarnEvent(); | 
|         platformWarnEvent.setCreateDate(new Date()); | 
|         platformWarnEvent.setIsdeleted(Constants.ZERO); | 
|         platformWarnEvent.setPlatformId(savePlatformWarnEventDTO.getPlatformId()); | 
|         platformWarnEvent.setCarCode(savePlatformWarnEventDTO.getCarCode()); | 
|         platformWarnEvent.setPlatformId(savePlatformWarnEventDTO.getPlatformJobId()); | 
|         Constants.PlatformWarnEvent cPl = Constants.PlatformWarnEvent.STOP_TIMEOUT; | 
|         if(Constants.equalsInteger(savePlatformWarnEventDTO.getEventType(),Constants.ZERO)){ | 
|             if(Objects.isNull(savePlatformWarnEventDTO.getPlatformJobId())){ | 
|                 return; | 
|             } | 
|             platformWarnEvent.setPlatformJobId(savePlatformWarnEventDTO.getPlatformJobId()); | 
|         }else  if(Constants.equalsInteger(savePlatformWarnEventDTO.getEventType(),Constants.ONE)){ | 
|             cPl = Constants.PlatformWarnEvent.STOP_ERROR; | 
|         } | 
|         platformWarnEvent.setTitle(cPl.getName()); | 
|         platformWarnEvent.setEventContent(cPl.getInfo().replace("${carCode}",savePlatformWarnEventDTO.getCarCode())); | 
|         platformWarnEventMapper.insert(platformWarnEvent); | 
|     } | 
|   | 
|   | 
| } |