| | |
| | | package com.ycl.platform.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.config.PlatformConfig; |
| | | import com.ycl.config.ServerConfig; |
| | | import com.ycl.exception.ServiceException; |
| | | import com.ycl.platform.domain.entity.*; |
| | | import com.ycl.platform.domain.form.*; |
| | | import com.ycl.platform.domain.query.*; |
| | | import com.ycl.platform.domain.vo.DeviceInfoVO; |
| | | import com.ycl.platform.domain.vo.DistributeWorkOrderVO; |
| | | import com.ycl.platform.domain.vo.WorkOrderVO; |
| | | import com.ycl.platform.domain.vo.WorkOrderYwConditionRecordVO; |
| | |
| | | import com.ycl.platform.service.WorkOrderAuditingRecordService; |
| | | import com.ycl.platform.service.WorkOrderService; |
| | | import com.ycl.platform.service.YwPointService; |
| | | import com.ycl.platform.wvp.StreamContent; |
| | | import com.ycl.platform.wvp.WVPResult; |
| | | import com.ycl.system.Result; |
| | | import com.ycl.system.domain.SysConfig; |
| | | import com.ycl.system.mapper.SysConfigMapper; |
| | |
| | | import com.ycl.system.page.PageUtil; |
| | | import com.ycl.utils.DateUtils; |
| | | import com.ycl.utils.SecurityUtils; |
| | | import com.ycl.utils.http.HttpUtils; |
| | | import com.ycl.utils.redis.RedisCache; |
| | | import com.ycl.utils.uuid.IdUtils; |
| | | import enumeration.general.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.bytedeco.javacv.FFmpegFrameGrabber; |
| | | import org.bytedeco.javacv.Frame; |
| | | import org.bytedeco.javacv.Java2DFrameConverter; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.imageio.ImageIO; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private final WorkOrderYwConditionRecordMapper workOrderYwConditionRecordMapper; |
| | | private final NotifyService notifyService; |
| | | private final WorkOrderDistributeRecordMapper workOrderDistributeRecordMapper; |
| | | private final TMonitorMapper monitorMapper; |
| | | private final WorkOrderErrorTypeMapper workOrderErrorTypeMapper; |
| | | private final SysConfigMapper configMapper; |
| | | private final ServerConfig serverConfig; |
| | | private final ReportMapper reportMapper; |
| | | |
| | | @Value("${rtsp.server:http://127.0.0.1:7788}") |
| | | private String rtspServer; |
| | | |
| | | private final String DISTRIBUTE_LOCK_KEY = "distributeLock"; |
| | | private final static String IMPORTANT = "important"; |
| | |
| | | workOrderList.stream().filter(item -> { |
| | | return StringUtils.hasText(item.getSerialNumber()) && Objects.nonNull(item.getStatus()) && StringUtils.hasText(item.getErrorType()); |
| | | }); |
| | | if (CollectionUtils.isEmpty(workOrderList)) { |
| | | return Boolean.TRUE; |
| | | } |
| | | List<String> serialNumberList = workOrderList.stream().map(WorkOrder::getSerialNumber).collect(Collectors.toList()); |
| | | // 查出数据库中国标码对应的未完成的工单 |
| | | List<WorkOrder> inDatabaseWorkOrderList = new LambdaQueryChainWrapper<>(baseMapper) |
| | |
| | | Map<String, WorkOrder> mapping = inDatabaseWorkOrderList.stream().collect((Collectors.toMap(WorkOrder::getSerialNumber, workOrder -> workOrder))); |
| | | List<WorkOrder> waitAddList = new ArrayList<>(48); |
| | | Integer updateNum = 0; |
| | | |
| | | for (WorkOrder workOrder : workOrderList) { |
| | | WorkOrder databaseWorkOrder = mapping.get(workOrder.getSerialNumber()); |
| | | if (Objects.nonNull(databaseWorkOrder)) { |
| | |
| | | errorType = errorType + "," + workOrder.getErrorType(); |
| | | databaseWorkOrder.setErrorType(errorType); |
| | | databaseWorkOrder.setStatus(WorkOrderStatusEnum.DISTRIBUTED); |
| | | Date now = new Date(); |
| | | databaseWorkOrder.setUpdateTime(now); |
| | | baseMapper.updateById(databaseWorkOrder); |
| | | updateNum++; |
| | | // 同时新增一个运维处理信息,表明此工单被调整 TODO |
| | | // 同时新增一个运维处理信息,表明此工单被调整 |
| | | WorkOrderYwConditionRecord ywRecord = new WorkOrderYwConditionRecord(); |
| | | ywRecord.setWorkOrderId(databaseWorkOrder.getId()); |
| | | ywRecord.setCommitUser(1); |
| | | ywRecord.setYwCondition("故障类型更新,工单状态调整为待处理"); |
| | | ywRecord.setCreateTime(new Date()); |
| | | workOrderYwConditionRecordMapper.insert(ywRecord); |
| | | } |
| | | } else { |
| | | workOrder.setCreateTime(new Date()); |
| | | workOrder.setUpdateTime(new Date()); |
| | | // 如果报备过,使用最新报备的错误类型 |
| | | Report report = reportMapper.checkPointReported(workOrder.getSerialNumber()); |
| | | if (Objects.nonNull(report)) { |
| | | workOrder.setErrorType(report.getErrorType()); |
| | | } |
| | | waitAddList.add(workOrder); |
| | | } |
| | | } |
| | |
| | | // 查出重点点位、普通点位的处理时间 |
| | | SysConfig important = configMapper.checkConfigKeyUnique("important.wordkorder.time"); |
| | | SysConfig normal = configMapper.checkConfigKeyUnique("normal.wordkorder.alarm.time"); |
| | | // 如果即将生成工单,但是设备国标码查不到点位,则不添加? |
| | | List<WorkOrder> notAddList = new ArrayList<>(); |
| | | for (WorkOrder workOrder : waitAddList) { |
| | | YwPoint point = pointMapping.get(workOrder.getSerialNumber()); |
| | | if (Objects.isNull(point)) { |
| | | notAddList.add(workOrder); |
| | | continue; |
| | | } |
| | | workOrder.setWorkOrderNo(IdUtils.timeAddRandomNO(5)); |
| | | workOrder.setUnitId(Math.toIntExact(point.getUnitId())); |
| | | if (point.getImportantTag() || point.getImportantCommandImageTag()) { |
| | |
| | | } else { |
| | | workOrder.setProcessingPeriod(Integer.valueOf(normal.getConfigValue())); |
| | | } |
| | | } |
| | | waitAddList.removeAll(notAddList); |
| | | if (CollectionUtils.isEmpty(waitAddList)) { |
| | | return Boolean.TRUE; |
| | | } |
| | | this.saveBatch(waitAddList); |
| | | // 如果是直接下发,添加下发记录 |
| | |
| | | workOrderDistributeRecord.setWorkOrderId(item.getId()); |
| | | workOrderDistributeRecord.setDistributeWay(WorkOrderDistributeWayEnum.DIRECT_DISTRIBUTE); |
| | | workOrderDistributeRecord.setUserId(1L); |
| | | Date now = new Date(); |
| | | workOrderDistributeRecord.setCreateTime(now); |
| | | workOrderDistributeRecord.setUpdateTime(now); |
| | | return workOrderDistributeRecord; |
| | | }).collect(Collectors.toList()); |
| | | workOrderDistributeRecordMapper.insertBatch(distributedRecordList); |
| | |
| | | entity.setWorkOrderNo(IdUtils.timeAddRandomNO(5)); |
| | | entity.setCreateTime(DateUtils.getNowDate()); |
| | | entity.setStatus(WorkOrderStatusEnum.WAIT_DISTRIBUTE); |
| | | Date now = new Date(); |
| | | entity.setCreateTime(now); |
| | | entity.setUpdateTime(now); |
| | | entity.setErrorType(form.getErrorType().stream().map(ErrorTypeEnum::getValue).collect(Collectors.joining(","))); |
| | | List<WorkOrderErrorType> workOrderErrorTypes = form.getErrorType().stream().map(errorType -> new WorkOrderErrorType(entity.getWorkOrderNo(), errorType.getValue())).toList(); |
| | | workOrderErrorTypeMapper.insertWorkOrderErrorTypeList(workOrderErrorTypes); |
| | | if(baseMapper.insert(entity) > 0) { |
| | | return Result.ok("添加成功"); |
| | | } |
| | |
| | | public Result update(WorkOrderForm form) { |
| | | |
| | | WorkOrder entity = baseMapper.selectById(form.getId()); |
| | | |
| | | // 为空抛IllegalArgumentException,做全局异常处理 |
| | | Assert.notNull(entity, "记录不存在"); |
| | | BeanUtils.copyProperties(form, entity); |
| | | Date now = new Date(); |
| | | entity.setUpdateTime(now); |
| | | if (baseMapper.updateById(entity) > 0) { |
| | | return Result.ok("修改成功"); |
| | | } |
| | |
| | | workOrderYwConditionRecord.setCommitUser(SecurityUtils.getLoginUser().getUserId().intValue()); |
| | | workOrderYwConditionRecord.setYwCondition(form.getYwCondition()); |
| | | workOrderYwConditionRecord.setYwProofMaterials(form.getYwProofMaterials()); |
| | | workOrderYwConditionRecord.setSysMsg(Boolean.FALSE); |
| | | workOrderYwConditionRecordMapper.insert(workOrderYwConditionRecord); |
| | | return Result.ok("操作成功"); |
| | | } |
| | |
| | | @Override |
| | | public Result selectYwConditionByYwId(Integer id) { |
| | | List<WorkOrderYwConditionRecordVO> ywConditionList = workOrderYwConditionRecordMapper.selectYwConditionByYwId(id); |
| | | ywConditionList.stream().forEach(item -> { |
| | | if (Objects.nonNull(item.getSysMsg()) && item.getSysMsg()) { |
| | | item.setCommitUserName("系统消息"); |
| | | } |
| | | }); |
| | | return Result.ok().data(ywConditionList); |
| | | } |
| | | |
| | |
| | | */ |
| | | public synchronized Boolean getDistributeLock() { |
| | | if (Objects.isNull(redisCache.getCacheObject(DISTRIBUTE_LOCK_KEY))) { |
| | | redisCache.setCacheObject(DISTRIBUTE_LOCK_KEY, "1"); |
| | | redisCache.setCacheObject(DISTRIBUTE_LOCK_KEY, "1", 30, TimeUnit.SECONDS); |
| | | return true; |
| | | } else { |
| | | return false; |
| | |
| | | public List<WorkOrderRegionVO> workOrderRegion(DashboardQuery dashboardQuery) { |
| | | return baseMapper.workOrderRegion(dashboardQuery); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String getFrameImgByDevice(String deviceId, String channelId) { |
| | | String url = String.format(this.rtspServer + "/start/%s/%s", deviceId, channelId); |
| | | String result = HttpUtils.sendGet(url); |
| | | WVPResult wvpResult = JSON.parseObject(result, WVPResult.class); |
| | | if (0 == wvpResult.getCode()) { |
| | | StreamContent data = (StreamContent) wvpResult.getData(); |
| | | String rtspUrl = data.getRtsp(); |
| | | if (StringUtils.hasText(rtspUrl)) { |
| | | try { |
| | | // 创建FFmpegFrameGrabber对象 |
| | | FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(rtspUrl); |
| | | grabber.start(); // 开始捕获 |
| | | |
| | | Frame frame; |
| | | if ((frame = grabber.grabFrame()) != null) { |
| | | // 将帧转换为图片 |
| | | Java2DFrameConverter converter = new Java2DFrameConverter(); |
| | | BufferedImage image = converter.convert(frame); |
| | | File outputfile = new File(serverConfig.getUrl() + PlatformConfig.getUploadPath() + deviceId + IdUtils.fastSimpleUUID() + ".png"); |
| | | ImageIO.write(image, "png", outputfile); |
| | | String imgPath = outputfile.getAbsolutePath(); |
| | | System.out.println("Saved " + imgPath); |
| | | return imgPath; |
| | | } |
| | | grabber.stop(); // 停止捕获 |
| | | grabber.release(); // 释放资源 |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public List<DeviceInfoVO> hasErrorWorkOrderList() { |
| | | List<DeviceInfoVO> list = baseMapper.hasErrorWorkOrderList(); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public void updateImgById(Integer workOrderId, String imgPath) { |
| | | new LambdaUpdateChainWrapper<>(baseMapper) |
| | | .eq(WorkOrder::getId, workOrderId) |
| | | .set(WorkOrder::getYwCheckCondition, imgPath); |
| | | } |
| | | } |