| | |
| | | package com.ycl.platform.service.impl; |
| | | |
| | | import com.alibaba.excel.annotation.format.DateTimeFormat; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | 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.ycl.config.ServerConfig; |
| | | import com.ycl.exception.ServiceException; |
| | | import com.ycl.platform.domain.entity.*; |
| | | import com.ycl.platform.domain.excel.PointExport; |
| | | import com.ycl.platform.domain.form.*; |
| | | import com.ycl.platform.domain.query.*; |
| | | import com.ycl.platform.domain.vo.*; |
| | |
| | | import com.ycl.platform.wvp.WVPResult; |
| | | import com.ycl.system.Result; |
| | | import com.ycl.system.domain.SysConfig; |
| | | import com.ycl.system.entity.SysDictData; |
| | | import com.ycl.system.mapper.SysConfigMapper; |
| | | import com.ycl.system.mapper.SysDictDataMapper; |
| | | import com.ycl.system.model.LoginUser; |
| | |
| | | import com.ycl.utils.http.HttpUtils; |
| | | import com.ycl.utils.redis.RedisCache; |
| | | import com.ycl.utils.uuid.IdUtils; |
| | | import constant.ApiConstants; |
| | | import constant.CheckConstants; |
| | | import constant.Constants; |
| | | import enumeration.general.NotifyTypeEnum; |
| | | import enumeration.general.UrgentLevelEnum; |
| | | import enumeration.general.WorkOrderDistributeWayEnum; |
| | | import enumeration.general.WorkOrderStatusEnum; |
| | | import constant.RedisConstant; |
| | | import enumeration.general.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.net.URLDecoder; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.util.*; |
| | |
| | | @RequiredArgsConstructor |
| | | public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder> implements WorkOrderService { |
| | | |
| | | private final WorkOrderMapper workOrderMapper; |
| | | private final YwPointService ywPointService; |
| | | private final WorkOrderAuditingRecordMapper workOrderAuditingRecordMapper; |
| | | private final WorkOrderAuditingRecordService workOrderAuditingRecordService; |
| | |
| | | private final WorkOrderDistributeRecordMapper workOrderDistributeRecordMapper; |
| | | private final WorkOrderErrorTypeServiceImpl workOrderErrorTypeService; |
| | | private final SysConfigMapper configMapper; |
| | | private final ServerConfig serverConfig; |
| | | private final ReportMapper reportMapper; |
| | | private final SysDictDataMapper dictDataMapper; |
| | | |
| | | private final WorkOrderCheckImgMapper workOrderCheckImgMapper; |
| | | private final WorkOrderWhiteMapper workOrderWhiteMapper; |
| | | private final DeviceInfoMapper deviceInfoMapper; |
| | | private final ApplicationContext applicationContext; |
| | | @Value("${rtsp.server:http://127.0.0.1:7788}") |
| | | private String rtspServer; |
| | | |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean innerAddWorkOrder(List<WorkOrder> workOrderList) { |
| | | public synchronized Boolean innerAddWorkOrder(List<WorkOrder> workOrderList) { |
| | | int total = workOrderList.size(); |
| | | workOrderList.stream().filter(item -> { |
| | | // 查询出白名单列表 |
| | | List<String> serialNumbers = workOrderWhiteMapper.selectList().stream().map(WorkOrderWhite::getSerialNumber).collect(Collectors.toList()); |
| | | // 遍历工单列表,判断是否在白名单中 |
| | | workOrderList = workOrderList.stream().filter(item -> !serialNumbers.contains(item.getSerialNumber())) |
| | | .collect(Collectors.toList()); |
| | | workOrderList = workOrderList.stream().filter(item -> { |
| | | return StringUtils.hasText(item.getSerialNumber()) && Objects.nonNull(item.getStatus()) && !CollectionUtils.isEmpty(item.getErrorTypeList()); |
| | | }); |
| | | }).collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(workOrderList)) { |
| | | return Boolean.TRUE; |
| | | } |
| | |
| | | continue; |
| | | } else { |
| | | for (String errorType : errorTypes) { |
| | | if (! errorNameList.contains(errorType)) { |
| | | if (!errorNameList.contains(errorType)) { |
| | | // 错误类型不一样,就新增一个错误类型,并且重置工单状态为待处理 |
| | | WorkOrderErrorType workOrderErrorType = new WorkOrderErrorType(); |
| | | workOrderErrorType.setWorkOrderNo(databaseWorkOrder.getWorkOrderNo()); |
| | |
| | | willAddErrorType.add(workOrderErrorType); |
| | | } |
| | | } |
| | | databaseWorkOrder.setStatus(WorkOrderStatusEnum.DISTRIBUTED); |
| | | //避免代下发的工单直接变成下发 |
| | | if(!databaseWorkOrder.getStatus().equals(WorkOrderStatusEnum.WAIT_DISTRIBUTE)) { |
| | | databaseWorkOrder.setStatus(WorkOrderStatusEnum.DISTRIBUTED); |
| | | } |
| | | databaseWorkOrder.setUpdateTime(now); |
| | | willUpdateStatusWorkOrderList.add(databaseWorkOrder); |
| | | updateNum++; |
| | |
| | | return Boolean.TRUE; |
| | | } |
| | | List<String> willAddSerialNumber = waitAddList.stream().map(WorkOrder::getSerialNumber).collect(Collectors.toList()); |
| | | //只生成考核设备、且有运维单位的工单 |
| | | List<YwPoint> pointList = new LambdaQueryChainWrapper<>(ywPointService.getBaseMapper()) |
| | | .select(YwPoint::getUnitId, YwPoint::getSerialNumber, YwPoint::getImportantTag, YwPoint::getImportantTag, YwPoint::getProvinceTag, YwPoint::getImportantCommandImageTag) |
| | | .in(YwPoint::getSerialNumber, willAddSerialNumber) |
| | | .eq(YwPoint::getExamineStatus, Boolean.TRUE) |
| | | .isNotNull(YwPoint::getUnitId) |
| | | .list(); |
| | | Map<String, YwPoint> pointMapping = pointList.stream().collect(Collectors.toMap(YwPoint::getSerialNumber, point -> point)); |
| | | // 查出重点点位、普通点位的处理时间 |
| | |
| | | SysConfig normal = configMapper.checkConfigKeyUnique("normal.wordkorder.alarm.time"); |
| | | // 如果即将生成工单,但是设备国标码查不到点位,则不添加? |
| | | List<WorkOrder> notAddList = new ArrayList<>(); |
| | | //查redis今日工单数量 |
| | | int workOrderNum = 0; |
| | | for (WorkOrder workOrder : waitAddList) { |
| | | YwPoint point = pointMapping.get(workOrder.getSerialNumber()); |
| | | if (Objects.isNull(point)) { |
| | | notAddList.add(workOrder); |
| | | continue; |
| | | } |
| | | workOrder.setWorkOrderNo(IdUtils.randomNO(now)); |
| | | if (Objects.nonNull(point.getUnitId())) { |
| | | workOrder.setUnitId(Math.toIntExact(point.getUnitId())); |
| | | } |
| | |
| | | } else { |
| | | workOrder.setProcessingPeriod(Integer.valueOf(normal.getConfigValue())); |
| | | } |
| | | } |
| | | waitAddList.removeAll(notAddList); |
| | | if (CollectionUtils.isEmpty(waitAddList)) { |
| | | return Boolean.TRUE; |
| | | } |
| | | //UUID作为value,保证上锁的线程自己解锁 |
| | | String requestId = IdUtils.fastSimpleUUID(); |
| | | try { |
| | | for (int i = 0; i < 3; i++) { |
| | | boolean result = redisCache.acquireLock(RedisConstant.WORKORDER_NUM_LOCK, requestId, 10000); |
| | | if (result) { |
| | | //查今日工单量 |
| | | Object redisNum = redisCache.getCacheObject(RedisConstant.WORKORDER_NUM); |
| | | workOrderNum = redisNum == null ? 0 : (Integer) redisNum; |
| | | break; |
| | | } else { |
| | | if (i == 2) { |
| | | log.error("锁被占用"); |
| | | return Boolean.FALSE; |
| | | } |
| | | //等待一段时间后继续 |
| | | Thread.sleep(5000); |
| | | } |
| | | } |
| | | } catch (InterruptedException e) { |
| | | log.error("获取锁异常"); |
| | | return Boolean.FALSE; |
| | | } |
| | | //记录工单数,补充工单号 |
| | | for (WorkOrder workOrder : waitAddList) { |
| | | //数字前面补0 |
| | | workOrderNum++; |
| | | workOrder.setWorkOrderNo(IdUtils.workOrderNO(now, String.format("%05d", workOrderNum))); |
| | | // 保存错误类型 |
| | | for (String errorType : workOrder.getErrorTypeList()) { |
| | | WorkOrderErrorType workOrderErrorType = new WorkOrderErrorType(); |
| | |
| | | workOrderErrorType.setErrorName(errorType); |
| | | waitAddErrorTypeList.add(workOrderErrorType); |
| | | } |
| | | log.info("即将生成的工单:{}",workOrder); |
| | | } |
| | | waitAddList.removeAll(notAddList); |
| | | if (CollectionUtils.isEmpty(waitAddList)) { |
| | | return Boolean.TRUE; |
| | | } |
| | | redisCache.setCacheObject(RedisConstant.WORKORDER_NUM, workOrderNum); |
| | | redisCache.releaseLock(RedisConstant.WORKORDER_NUM_LOCK, requestId); |
| | | // 保存工单和故障类型 |
| | | baseMapper.addMany(waitAddList); |
| | | if (! CollectionUtils.isEmpty(waitAddErrorTypeList)) { |
| | | if (!CollectionUtils.isEmpty(waitAddErrorTypeList)) { |
| | | workOrderErrorTypeService.getBaseMapper().addMany(waitAddErrorTypeList); |
| | | } |
| | | // 如果是直接下发,添加下发记录 |
| | |
| | | |
| | | /** |
| | | * 添加 |
| | | * |
| | | * @param form |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result add(WorkOrderForm form) { |
| | | WorkOrder entity = WorkOrderForm.getEntityByForm(form, null); |
| | | entity.setCreateTime(DateUtils.getNowDate()); |
| | | entity.setStatus(WorkOrderStatusEnum.WAIT_DISTRIBUTE); |
| | | Date now = new Date(); |
| | | entity.setCreateTime(now); |
| | | entity.setUpdateTime(now); |
| | | entity.setWorkOrderNo(IdUtils.randomNO(now)); |
| | | entity.setErrorType(String.join(",", form.getErrorType())); |
| | | List<WorkOrderErrorType> workOrderErrorTypes = form.getErrorType().stream().map(errorType -> new WorkOrderErrorType(entity.getWorkOrderNo(), errorType)).toList(); |
| | | workOrderErrorTypeService.getBaseMapper().insertWorkOrderErrorTypeList(workOrderErrorTypes); |
| | | if(baseMapper.insert(entity) > 0) { |
| | | return Result.ok("添加成功"); |
| | | //查redis今日工单数量 |
| | | int workOrderNum = 0; |
| | | //UUID作为value,保证上锁的线程自己解锁 |
| | | String requestId = IdUtils.fastSimpleUUID(); |
| | | boolean result = redisCache.acquireLock(RedisConstant.WORKORDER_NUM_LOCK, requestId, 10000); |
| | | if (result) { |
| | | //查今日工单量 |
| | | Object redisNum = redisCache.getCacheObject(RedisConstant.WORKORDER_NUM); |
| | | workOrderNum = redisNum == null ? 0 : (Integer) redisNum; |
| | | workOrderNum++; |
| | | redisCache.setCacheObject(RedisConstant.WORKORDER_NUM, workOrderNum); |
| | | redisCache.releaseLock(RedisConstant.WORKORDER_NUM_LOCK, requestId); |
| | | } else { |
| | | return Result.error("工单正在添加,请稍后再试"); |
| | | } |
| | | return Result.error("添加失败"); |
| | | WorkOrder entity = WorkOrderForm.getEntityByForm(form, null); |
| | | // 查询出白名单列表 |
| | | List<String> serialNumbers = workOrderWhiteMapper.selectList().stream().map(WorkOrderWhite::getSerialNumber).collect(Collectors.toList()); |
| | | // 遍历工单列表,判断是否在白名单中 |
| | | if (serialNumbers.contains(entity.getSerialNumber())){ |
| | | return Result.error("该设备在白名单中,不能添加工单"); |
| | | }else { |
| | | entity.setCreateTime(DateUtils.getNowDate()); |
| | | entity.setStatus(WorkOrderStatusEnum.WAIT_DISTRIBUTE); |
| | | Date now = new Date(); |
| | | entity.setCreateTime(now); |
| | | entity.setUpdateTime(now); |
| | | entity.setWorkOrderNo(IdUtils.workOrderNO(now, String.format("%05d", workOrderNum))); |
| | | entity.setErrorType(String.join(",", form.getErrorType())); |
| | | List<WorkOrderErrorType> workOrderErrorTypes = form.getErrorType().stream().map(errorType -> new WorkOrderErrorType(entity.getWorkOrderNo(), errorType)).toList(); |
| | | workOrderErrorTypeService.getBaseMapper().insertWorkOrderErrorTypeList(workOrderErrorTypes); |
| | | if (baseMapper.insert(entity) > 0) { |
| | | return Result.ok("添加成功"); |
| | | } |
| | | return Result.error("添加失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 修改 |
| | | * |
| | | * @param form |
| | | * @return |
| | | */ |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result ywCondition(WorkOrderYWConditionForm form) { |
| | | |
| | | WorkOrder workOrder = baseMapper.selectById(form.getId()); |
| | | if (Objects.isNull(workOrder)) { |
| | | throw new ServiceException("工单不存在"); |
| | |
| | | workOrderYwConditionRecord.setYwProofMaterials(form.getYwProofMaterials()); |
| | | workOrderYwConditionRecord.setSysMsg(Boolean.FALSE); |
| | | workOrderYwConditionRecordMapper.insert(workOrderYwConditionRecord); |
| | | //异步获取图片 |
| | | WorkOrderServiceImpl self = applicationContext.getBean(WorkOrderServiceImpl.class); |
| | | self.getImage(workOrder); |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | | @Async("threadPoolTaskExecutor") |
| | | public void getImage(WorkOrder workOrder) { |
| | | List<DeviceInfo> gbDevices = new LambdaQueryChainWrapper<>(deviceInfoMapper) |
| | | .orderByDesc(DeviceInfo::getUpdateTime) |
| | | .last("limit 1") |
| | | .list(); |
| | | if (CollectionUtils.isEmpty(gbDevices)) { |
| | | return; |
| | | } |
| | | // 国标设备的编码就是取视频流的设备编码,国标设备就一个。国标设备的每一个通道代表一个摄像头,也就是设备id是取流的通道id |
| | | String frameImg = null; |
| | | try { |
| | | log.info("国标平台:{},设备编码:{},工单号:{}",gbDevices.get(0).getDeviceId(), workOrder.getSerialNumber(), workOrder.getWorkOrderNo()); |
| | | frameImg = this.getFrameImgByDevice(gbDevices.get(0).getDeviceId(), workOrder.getSerialNumber(), workOrder.getWorkOrderNo()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if (StringUtils.hasText(frameImg)) { |
| | | WorkOrderCheckImg img = new WorkOrderCheckImg(); |
| | | img.setWorkOrderNo(workOrder.getWorkOrderNo()); |
| | | img.setImgUrl(frameImg); |
| | | img.setCreateTime(new Date()); |
| | | workOrderCheckImgMapper.insert(img); |
| | | } |
| | | } |
| | | @Override |
| | | public List<WorkOrderYwConditionRecordVO> selectYwConditionByYwId(String workOrderNo) { |
| | | List<WorkOrderYwConditionRecordVO> ywConditionList = workOrderYwConditionRecordMapper.selectYwConditionByYwId(workOrderNo); |
| | | ywConditionList.stream().forEach(item -> { |
| | | if (Objects.nonNull(item.getSysMsg()) && item.getSysMsg()) { |
| | | item.setCommitUserName("系统消息"); |
| | | item.setUnitName("系统消息"); |
| | | } |
| | | }); |
| | | return ywConditionList; |
| | |
| | | @Override |
| | | public List<WorkOrderAuditingRecord> selectYwAuditingListByYwId(String workOrderNo) { |
| | | return new LambdaQueryChainWrapper<>(workOrderAuditingRecordMapper) |
| | | .eq(WorkOrderAuditingRecord::getWorkOrderNo, workOrderNo) |
| | | .orderByAsc(WorkOrderAuditingRecord::getCreateTime) |
| | | .list(); |
| | | .eq(WorkOrderAuditingRecord::getWorkOrderNo, workOrderNo) |
| | | .orderByAsc(WorkOrderAuditingRecord::getCreateTime) |
| | | .list(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | /** |
| | | * 批量删除 |
| | | * |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result remove(List<String> ids) { |
| | | if(baseMapper.deleteBatchIds(ids) > 0) { |
| | | if (baseMapper.deleteBatchIds(ids) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | | return Result.error("删除失败"); |
| | |
| | | |
| | | /** |
| | | * id删除 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result removeById(String id) { |
| | | if(baseMapper.deleteById(id) > 0) { |
| | | if (baseMapper.deleteById(id) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | | return Result.error("删除失败"); |
| | |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result page(WorkOrderQuery query) { |
| | | IPage<WorkOrderVO> page = PageUtil.getPage(query, WorkOrderVO.class); |
| | | if(query.getUnitId()==null) { |
| | | query.setUnitId(SecurityUtils.getUnitId()); |
| | | } |
| | | query.setStart(DateUtils.getDayStart(query.getStart())); |
| | | query.setEnd(DateUtils.getDayEnd(query.getEnd())); |
| | | baseMapper.page(page, query); |
| | | if (! CollectionUtils.isEmpty(page.getRecords())) { |
| | | if (!CollectionUtils.isEmpty(page.getRecords())) { |
| | | page.getRecords().stream().forEach(item -> { |
| | | if (StringUtils.hasText(item.getErrorType())) { |
| | | item.setErrorTypeList(List.of(item.getErrorType().split(","))); |
| | |
| | | data.setStart(now.minusHours(1)); |
| | | break; |
| | | case LAST_TWO_HOUR: |
| | | data.setStart(now.minusHours(2)); |
| | | break; |
| | | data.setStart(now.minusHours(2)); |
| | | break; |
| | | case LAST_DAY: |
| | | data.setStart(now.minusDays(1)); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | if (Objects.isNull(data.getStart())) { |
| | | throw new RuntimeException("无法生成快速下发的时间范围,请选择正确的快速下发方式"); |
| | | } |
| | |
| | | .select(WorkOrder::getSerialNumber, WorkOrder::getWorkOrderNo) |
| | | .eq(WorkOrder::getStatus, WorkOrderStatusEnum.WAIT_DISTRIBUTE) |
| | | .eq(Objects.nonNull(data.getUnitId()), WorkOrder::getUnitId, data.getUnitId()) |
| | | .eq(WorkOrder::getErrorType, data.getErrorType()) |
| | | .in(WorkOrder::getErrorType, data.getErrorType()) |
| | | .between(WorkOrder::getCreateTime, data.getStart(), data.getEnd()) |
| | | .orderByDesc(WorkOrder::getCreateTime) |
| | | .last("limit " + data.getFastNumLimit()) |
| | |
| | | List<String> workOrderNoList = list.stream().map(WorkOrder::getWorkOrderNo).toList(); |
| | | List<String> serialNumberList = list.stream().map(WorkOrder::getSerialNumber).toList(); |
| | | |
| | | if (workOrderNoList.isEmpty()) { return Result.error("没有符合条件的工单"); } |
| | | if (!getDistributeLock()) { return Result.error("此刻有人下发中,为避免冲突,请稍后重试"); } |
| | | if (workOrderNoList.isEmpty()) { |
| | | return Result.error("没有符合条件的工单"); |
| | | } |
| | | if (!getDistributeLock()) { |
| | | return Result.error("此刻有人下发中,为避免冲突,请稍后重试"); |
| | | } |
| | | try { |
| | | new LambdaUpdateChainWrapper<>(baseMapper) |
| | | .set(WorkOrder::getStatus, WorkOrderStatusEnum.DISTRIBUTED) |
| | |
| | | @Transactional |
| | | public Result selectedIdsDistribute(DistributeWorkOrderQuery query) { |
| | | WorkOrderDistributeWayEnum distributeWayEnum = WorkOrderDistributeWayEnum.SELECTED_DISTRIBUTE; |
| | | if (!getDistributeLock()) { return Result.error("此刻有人下发中,为避免冲突,请稍后重试"); } |
| | | if (!getDistributeLock()) { |
| | | return Result.error("此刻有人下发中,为避免冲突,请稍后重试"); |
| | | } |
| | | try { |
| | | if (query.getWorkOrderNOList().isEmpty()) { |
| | | query.setWorkOrderNOList(new LambdaQueryChainWrapper<>(baseMapper) |
| | |
| | | .collect(Collectors.toList())); |
| | | distributeWayEnum = WorkOrderDistributeWayEnum.ALL_DISTRIBUTE; |
| | | } |
| | | if (query.getWorkOrderNOList().isEmpty()) { return Result.error("没有工单待下发"); } |
| | | if (query.getWorkOrderNOList().isEmpty()) { |
| | | return Result.error("没有工单待下发"); |
| | | } |
| | | new LambdaUpdateChainWrapper<>(baseMapper) |
| | | .set(WorkOrder::getStatus, WorkOrderStatusEnum.DISTRIBUTED) |
| | | .in(WorkOrder::getWorkOrderNo, query.getWorkOrderNOList()) |
| | |
| | | ywPointService.updateRecovery(serialNumberList, 1); |
| | | return Result.ok("成功下发" + query.getWorkOrderNOList().size() + "条工单"); |
| | | } catch (Exception e) { |
| | | System.out.println(e.getMessage()); |
| | | return Result.error("操作失败"); |
| | | } finally { |
| | | distributeUnLock(); |
| | |
| | | |
| | | /** |
| | | * 申请工单下发锁 |
| | | * |
| | | * @return 工单下发锁申请结果 |
| | | */ |
| | | public synchronized Boolean getDistributeLock() { |
| | |
| | | |
| | | /** |
| | | * 添加工单下发记录 |
| | | * |
| | | * @param workOrderNoList 工单id |
| | | */ |
| | | private void addDistributeRecord(List<String> workOrderNoList, WorkOrderDistributeWayEnum distributeWay) { |
| | |
| | | |
| | | /** |
| | | * 根据id查找 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 列表 |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public List<WorkOrderRegionVO> workOrderRegion(DashboardQuery dashboardQuery) { |
| | | return baseMapper.workOrderRegion(dashboardQuery); |
| | | //初始化所有区域数据 |
| | | List<WorkOrderRegionVO> vos = new ArrayList<>(); |
| | | for (AreaDeptEnum value : AreaDeptEnum.values()) { |
| | | WorkOrderRegionVO vo = new WorkOrderRegionVO(); |
| | | vo.setArea(value.getName()); |
| | | vo.setDoneNum(0); |
| | | vo.setTodoNum(0); |
| | | vos.add(vo); |
| | | } |
| | | List<WorkOrderRegionVO> workOrderRegionVOS = baseMapper.workOrderRegion(dashboardQuery); |
| | | for (WorkOrderRegionVO vo : vos) { |
| | | for (WorkOrderRegionVO workOrder : workOrderRegionVOS) { |
| | | //赋值 |
| | | if (vo.getArea().equals(workOrder.getArea())) { |
| | | BeanUtils.copyProperties(workOrder, vo); |
| | | } |
| | | } |
| | | } |
| | | return vos; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String getFrameImgByDevice(String deviceId, String channelId, String workOrderNo) { |
| | | public synchronized String getFrameImgByDevice(String deviceId, String channelId, String workOrderNo) throws Exception { |
| | | String url = String.format(this.rtspServer + "/api/play/start/img/%s/%s", deviceId, channelId); |
| | | log.info("访问路径{}",url); |
| | | String result = HttpUtils.sendGet(url); |
| | | log.info("拿到取流图片响应结果:" + result); |
| | | WVPResult wvpResult = JSON.parseObject(result, WVPResult.class); |
| | | if(wvpResult.getCode() == 0) { |
| | | Object imgUrl = (Object) wvpResult.getData(); |
| | | imgUrl = Objects.isNull(imgUrl) ? "" : imgUrl; |
| | | log.info("拿到取流图片:" + imgUrl); |
| | | return (String) imgUrl; |
| | | } |
| | | return null; |
| | | // WVPResult wvpResult = JSON.parseObject(result, WVPResult.class); |
| | | // String imgUrl = null; |
| | | // if (wvpResult.getCode() == 0) { |
| | | // JSONObject data = (JSONObject) wvpResult.getData(); |
| | | // String rtspUrl = data.getString("fmp4"); // 取mp4地址 |
| | | // if (StringUtils.hasText(rtspUrl)) { |
| | | // System.out.println("目标地址:" + rtspUrl); |
| | | // FFmpegFrameGrabber grabber = null; |
| | | // try { |
| | | // grabber = new FFmpegFrameGrabber(rtspUrl); |
| | | //// grabber.setOption("rtsp_transport", "tcp"); // 使用tcp的方式,不然会丢包很严重 |
| | | //// grabber.setVideoOption("probesize", "10000"); // 设置捕获分析的最大字节 |
| | | // grabber.start(); |
| | | // Frame frame = grabber.grabImage(); // 直接捕获一帧 |
| | | // if (frame != null) { |
| | | // System.out.println("成功捕获一帧"); |
| | | // // 将Frame转换为Mat |
| | | // OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat(); |
| | | // Mat mat = converter.convertToMat(frame); |
| | | // |
| | | // imgUrl = workOrderNo + "_" + IdUtils.fastSimpleUUID() + ".png"; |
| | | // // 生成图片路径 |
| | | // String imgPath = PlatformConfig.getProfile() + "/" + imgUrl; |
| | | // System.out.println("图片保存地址:" + imgPath); |
| | | // imgUrl = Constants.RESOURCE_PREFIX + "/" + imgUrl; |
| | | // // 保存图片 |
| | | // opencv_imgcodecs.imwrite(imgPath, mat); |
| | | // } else { |
| | | // System.out.println("未捕获到帧"); |
| | | // } |
| | | // } catch (FrameGrabber.Exception e) { |
| | | // e.printStackTrace(); |
| | | // } finally { |
| | | // if (grabber != null) { |
| | | // try { |
| | | // grabber.stop(); // 停止捕获 |
| | | // } catch (FrameGrabber.Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // } else { |
| | | // System.out.println("请求失败,错误码:" + wvpResult.getCode() + "--" + wvpResult.getMsg()); |
| | | // } |
| | | // System.out.println("图片URL:" + imgUrl); |
| | | // return imgUrl; |
| | | } |
| | | |
| | | @Override |
| | | public void saveFrameImgByDevice (String deviceId, String channelId, String workOrderNo){ |
| | | String url = String.format(this.rtspServer + "/api/play/start/%s/%s", deviceId, channelId); |
| | | String result = HttpUtils.sendGet(url); |
| | | WVPResult wvpResult = JSON.parseObject(result, WVPResult.class); |
| | | String imgUrl = null; |
| | | if (wvpResult.getCode() == 0) { |
| | | JSONObject data = (JSONObject) wvpResult.getData(); |
| | | String rtspUrl = data.getString("fmp4"); // 取mp4地址 |
| | | String rtspUrl = data.getString("rtsp"); // 取mp4地址 |
| | | if (StringUtils.hasText(rtspUrl)) { |
| | | System.out.println("目标地址:" + rtspUrl); |
| | | FFmpegFrameGrabber grabber = null; |
| | | try { |
| | | grabber = FFmpegFrameGrabber.createDefault(rtspUrl); |
| | | //设置10s超时 |
| | | grabber.setTimeout(10000); |
| | | grabber.start(); |
| | | Frame frame = grabber.grabImage(); // 直接捕获一帧 |
| | | if (frame != null) { |
| | |
| | | System.out.println("请求失败,错误码:" + wvpResult.getCode()); |
| | | } |
| | | System.out.println("图片URL:" + imgUrl); |
| | | return imgUrl; |
| | | if (StringUtils.hasText(imgUrl)) { |
| | | WorkOrderCheckImg img = new WorkOrderCheckImg(); |
| | | img.setWorkOrderNo(workOrderNo); |
| | | img.setImgUrl(imgUrl); |
| | | img.setCreateTime(new Date()); |
| | | workOrderCheckImgMapper.insert(img); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<DeviceInfoVO> hasErrorWorkOrderList(Date start, Date end) { |
| | | public List<DeviceInfoVO> hasErrorWorkOrderList (Date start, Date end){ |
| | | List<DeviceInfoVO> list = baseMapper.hasErrorWorkOrderList(start, end); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public void updateImgById(Integer workOrderId, String imgPath) { |
| | | public void updateImgById (Integer workOrderId, String imgPath){ |
| | | new LambdaUpdateChainWrapper<>(baseMapper) |
| | | .eq(WorkOrder::getId, workOrderId) |
| | | .set(WorkOrder::getYwCheckResult, imgPath) |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result processImg(String workOrderNo) { |
| | | public Result processImg (String workOrderNo){ |
| | | WorkOrder workOrder = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .eq(WorkOrder::getWorkOrderNo, workOrderNo) |
| | | .one(); |
| | | if (Objects.isNull(workOrder)) { |
| | | throw new RuntimeException("此工单不存在"); |
| | | } |
| | | // 运维记录 |
| | | List<WorkOrderYwConditionRecordVO> workOrderYwConditionRecordVOS = this.selectYwConditionByYwId(workOrderNo); |
| | | // 审核记录 |
| | |
| | | WorkOrderProcessVO process = new WorkOrderProcessVO(); |
| | | process.setYwList(workOrderYwConditionRecordVOS); |
| | | process.setAuditingList(workOrderAuditingRecords); |
| | | // 查询点位事前事后最新的一条数据是否审核通过 |
| | | ReportAuditingRecordVO beforeRecord = ywPointService.getReportResult(workOrder.getSerialNumber(), "事前报备"); |
| | | ReportAuditingRecordVO afterRecord = ywPointService.getReportResult(workOrder.getSerialNumber(), "事后报备"); |
| | | |
| | | Date now = new Date(); |
| | | if (Objects.nonNull(beforeRecord)) { |
| | | if (now.before(beforeRecord.getBeginCreateTime())) { |
| | | process.setBeforeReportMsg("事前报备已失效"); |
| | | } else if (now.after(beforeRecord.getEndCreateTime())) { |
| | | process.setBeforeReportMsg("事前报备未生效"); |
| | | } else { |
| | | process.setBeforeReportMsg("已事前报备"); |
| | | } |
| | | } |
| | | if (Objects.nonNull(afterRecord)) { |
| | | if (now.before(afterRecord.getBeginCreateTime())) { |
| | | process.setAfterReportMsg("事后报备已失效"); |
| | | } else if (now.after(afterRecord.getEndCreateTime())) { |
| | | process.setAfterReportMsg("事后报备未生效"); |
| | | } else { |
| | | process.setAfterReportMsg("已事后报备"); |
| | | } |
| | | } |
| | | return Result.ok().data(process); |
| | | } |
| | | |
| | | @Override |
| | | public Result detailByNo (String workOrderNo){ |
| | | WorkOrderDetailVO workOrder = baseMapper.detailByNo(workOrderNo); |
| | | // 是否报备 |
| | | boolean hasReport = new LambdaQueryChainWrapper<>(reportMapper) |
| | | .eq(Report::getSerialNumber, workOrder.getSerialNumber()) |
| | | .exists(); |
| | | workOrder.setHasReport(hasReport); |
| | | // 故障类型 |
| | | List<SysDictData> errorList = workOrderErrorTypeService.getBaseMapper().getErrorList(workOrder.getWorkOrderNo()); |
| | | List<String> errList = errorList.stream().map(SysDictData::getDictLabel).collect(Collectors.toList()); |
| | | workOrder.setErrorTypeList(errList); |
| | | // 检测图片 |
| | | List<WorkOrderCheckImg> imgList = new LambdaQueryChainWrapper<>(workOrderCheckImgMapper) |
| | | .eq(WorkOrderCheckImg::getWorkOrderNo, workOrderNo) |
| | | .orderByDesc(WorkOrderCheckImg::getCreateTime) |
| | | .last("limit 20") |
| | | .list(); |
| | | workOrder.setImgList(imgList); |
| | | return Result.ok().data(workOrder); |
| | | } |
| | | |
| | | @Override |
| | | public List<WorkOrderVO> export (WorkOrderExportQuery query){ |
| | | query.setUnitId(SecurityUtils.getUnitId()); |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | if (query.getStart() == null) { |
| | | query.setStart(format.format(DateUtils.getDayStart(new Date()))); |
| | | } else { |
| | | query.setStart(query.getStart() + " 00:00:00"); |
| | | } |
| | | if (query.getEnd() == null) { |
| | | query.setEnd(format.format(DateUtils.getDayEnd(new Date()))); |
| | | } else { |
| | | query.setEnd(query.getEnd() + " 23:59:59"); |
| | | } |
| | | |
| | | List<WorkOrderVO> export = baseMapper.export(query); |
| | | |
| | | System.out.println(export); |
| | | return export; |
| | | } |
| | | |
| | | /** |
| | | * 工单白名单列表 |
| | | * |
| | | * @param query 查询 |
| | | * @return {@link List }<{@link WorkOrderWhite }> |
| | | * @author |
| | | */ |
| | | @Override |
| | | public Result selectWorkOrderWhiteList(WorkOrderWhiteQuery query) { |
| | | IPage<WorkOrderWhite> page = PageUtil.getPage(query, WorkOrderWhite.class); |
| | | workOrderWhiteMapper.page(page, query); |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | | /** |
| | | * 添加工单白名单 |
| | | * |
| | | * @param workOrderWhite 白色工单 |
| | | * @return {@link Result } |
| | | * @author |
| | | */ |
| | | @Override |
| | | public Result addWorkOrderWhite(WorkOrderWhite workOrderWhite) { |
| | | // 通过设备编码查询设备信息 |
| | | YwPoint ywPoint = ywPointService.selectBySerialNumber(workOrderWhite.getSerialNumber()); |
| | | // 新增白名单设备记录 |
| | | if (ywPoint == null){ |
| | | return Result.error("设备不存在"); |
| | | } |
| | | // 检查是否已经存在该白名单 |
| | | WorkOrderWhite flag = workOrderWhiteMapper.selectBySerialNumber(workOrderWhite.getSerialNumber()); |
| | | if (flag != null) { |
| | | return Result.error("该设备已存在白名单"); |
| | | } else { |
| | | workOrderWhite.setPointName(ywPoint.getPointName()); |
| | | workOrderWhite.setCreateBy(SecurityUtils.getUsername()); |
| | | workOrderWhiteMapper.insert(workOrderWhite); |
| | | return Result.ok(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 批量删除工单白名单 |
| | | * |
| | | * @param ids ids |
| | | * @author |
| | | */ |
| | | @Override |
| | | public Result batchDeleteWorkOrderWhite(List<String> ids) { |
| | | workOrderWhiteMapper.batchDelete(ids); |
| | | return Result.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 批量导入白名单 |
| | | * |
| | | * @param dataList 数据列表 |
| | | * @author |
| | | */ |
| | | @Override |
| | | public void batchImportWhite(List<PointExport> dataList) { |
| | | // 获得所有需要新增的白名单对象 |
| | | List<WorkOrderWhite> whitelist = dataList.stream().map(pointExport -> |
| | | new WorkOrderWhite(pointExport.getSerialNumber(), pointExport.getPointName(), SecurityUtils.getUsername())) |
| | | .collect(Collectors.toList()); |
| | | // 获得所有已存在的白名单设备编码 |
| | | List<String> serialNumbers = workOrderWhiteMapper.selectList().stream().map(WorkOrderWhite::getSerialNumber).collect(Collectors.toList()); |
| | | // 筛选出新增、修改的白名单对象 |
| | | List<WorkOrderWhite> updateWhiteList = whitelist.stream().filter(white -> serialNumbers.contains(white.getSerialNumber())).collect(Collectors.toList()); |
| | | List<WorkOrderWhite> insertWhiteList = whitelist.stream().filter(white ->!serialNumbers.contains(white.getSerialNumber())).collect(Collectors.toList()); |
| | | // 新增/修改白名单设备记录 |
| | | updateWhiteList.stream().forEach(white -> workOrderWhiteMapper.updateBySerialNumber(white)); |
| | | insertWhiteList.stream().forEach(white -> workOrderWhiteMapper.insert(white)); |
| | | } |
| | | |
| | | |
| | | } |