Quellcode durchsuchen

设备利用率后台代码处理

oyq28 vor 1 Tag
Ursprung
Commit
4c6c27dafb
11 geänderte Dateien mit 171 neuen und 43 gelöschten Zeilen
  1. 0 28
      imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/mq/TaskWorkNode.java
  2. 2 0
      imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/dao/DeviceStatusLogMapper.java
  3. 2 0
      imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/service/AAutoNodeLogService.java
  4. 2 0
      imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/service/DeviceStatusLogService.java
  5. 36 0
      imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/service/impl/AAutoNodeLogServiceImpl.java
  6. 5 0
      imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/service/impl/DeviceStatusLogServiceImpl.java
  7. 94 0
      imcs-admin-boot/imcs-business-biz/src/main/resources/mapper_business/base/productionReadyCenter/DeviceStatusLogMapper.xml
  8. 14 8
      imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/externalApi/ProductionTasksController.java
  9. 5 5
      imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/externalApi/SynProductionStatus.java
  10. 7 0
      imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/productionReadyCenter/WarnLogController.java
  11. 4 2
      imcs-admin-boot/imcs-business-entity/src/main/java/com/github/zuihou/business/productionReadyCenter/entity/AAutoNodeLog.java

+ 0 - 28
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/mq/TaskWorkNode.java

@@ -278,34 +278,6 @@ public class TaskWorkNode {
                 String handMode = jsonObject.containsKey("handMode")?jsonObject.getString("handMode"):"";
                 //多产品搬运类型
                 String carryType = jsonObject.containsKey("carryType")?jsonObject.getString("carryType"):"";
-
-                //String queueName = "device.queue."+ BizConstant.MQ_GLOBAL_EXCEPTION;
-                /*
-                if (consumerQueue.equals(queueName)) {
-                    StringBuilder buffer = new StringBuilder();
-                    //处理产线存储
-                    String lineName = jsonObject.getString("Line");
-                    ZZone line = zoneService.getOne(new LbqWrapper<ZZone>().like(ZZone::getAbbreviate, lineName.substring(0, lineName.length()-1)));
-                    buffer.append(lineName).append("-设备(").append(jsonObject.getString("Name")+")").append(jsonObject.getString("Status"));
-                    log.setExeResult("0").setManual("1").setFeedback("全局异常:"+ buffer.toString()).setStartTime(new Date()).setExecuteTime(new Date()).setZoneId(line.getId());
-
-                    LbqWrapper<AAutoNodeLog> lbqWrapper = new LbqWrapper<AAutoNodeLog>();
-                    lbqWrapper.eq(AAutoNodeLog::getZoneId, line.getId()).eq(AAutoNodeLog::getExeResult, log.getExeResult()).eq(AAutoNodeLog::getManual, log.getManual()).eq(AAutoNodeLog::getStatus, 0).eq(AAutoNodeLog::getFeedback, log.getFeedback());
-                    //判断全局异常是否已存在
-                    AAutoNodeLog exist = autoNodeLogService.getOne(lbqWrapper);
-                    if(null == exist){
-                        autoNodeLogService.save(log);
-                    }else{
-                        //更新执行时间
-                        exist.setExecuteTime(new Date());
-                        autoNodeLogService.updateAllById(exist);
-                    }
-                    //throw new RuntimeException("全局通知异常");
-                    return;
-                }
-                logger.info("=======================" + taskNodeId);
-                */
-
                 if (tTask == null || tTask.getStatus() == "3") {
                     log.setTaskNodeId(taskNode.getId()).setExeResult("0").setManual("0").setFeedback("当前任务为空");
                     autoNodeLogService.save(log);

+ 2 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/dao/DeviceStatusLogMapper.java

@@ -13,4 +13,6 @@ import java.util.Map;
 public interface DeviceStatusLogMapper extends SuperMapper<DeviceStatusLog> {
 
     Map<String, String> queryMachineEvent(@Param(Constants.WRAPPER) LbqWrapper<DeviceStatusLog> wrapper);
+
+    Map<String, String> calStatusLogTime(@Param(Constants.WRAPPER) Map paramsMap);
 }

+ 2 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/service/AAutoNodeLogService.java

@@ -33,4 +33,6 @@ public interface AAutoNodeLogService extends SuperService<AAutoNodeLog> {
     void executeNextNode(Long id);
 
     List<Map> getErrList(Map params);
+
+    void synLineWarn(String ips);
 }

+ 2 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/service/DeviceStatusLogService.java

@@ -9,4 +9,6 @@ import java.util.Map;
 public interface DeviceStatusLogService extends SuperService<DeviceStatusLog> {
 
     Map<String,String> queryMachineEvent(LbqWrapper<DeviceStatusLog> wrapper);
+
+    Map<String, String> calStatusLogTime(Map paramsMap);
 }

+ 36 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/service/impl/AAutoNodeLogServiceImpl.java

@@ -2,8 +2,11 @@ package com.github.zuihou.business.productionReadyCenter.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollectionUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.beust.jcommander.internal.Lists;
 import com.github.zuihou.authority.service.auth.UserService;
 import com.github.zuihou.authority.strategy.DataScopeContext;
 import com.github.zuihou.base.request.PageParams;
@@ -24,6 +27,7 @@ import com.github.zuihou.business.productionReadyCenter.service.AAutoNodeLogServ
 import com.github.zuihou.business.util.DynamicRabbitMq;
 import com.github.zuihou.business.util.MsgUtil;
 import com.github.zuihou.common.constant.BizConstant;
+import com.github.zuihou.common.constant.ParameterKey;
 import com.github.zuihou.common.util.StringUtil;
 import com.github.zuihou.context.BaseContextHandler;
 import com.github.zuihou.database.mybatis.auth.DataScope;
@@ -31,12 +35,14 @@ import com.github.zuihou.database.mybatis.conditions.Wraps;
 import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
 import com.github.zuihou.database.mybatis.conditions.query.QueryWrap;
 import com.github.zuihou.exception.BizException;
+import com.github.zuihou.utils.DateUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.util.Date;
 import java.util.List;
@@ -81,6 +87,7 @@ public class AAutoNodeLogServiceImpl extends SuperServiceImpl<AAutoNodeLogMapper
     @Resource
     private DynamicRabbitMq dynamicRabbitMq;
 
+
     @Override
     public IPage<AAutoNodeLog> pageList(IPage page, LbqWrapper<AAutoNodeLog> wrapper, String instructionName) {
         return baseMapper.pageList(page,wrapper, new DataScope(), instructionName);
@@ -265,4 +272,33 @@ public class AAutoNodeLogServiceImpl extends SuperServiceImpl<AAutoNodeLogMapper
     public List<Map> getErrList(Map params) {
         return baseMapper.getErrList(params);
     }
+
+    @Override
+    public void synLineWarn(String ips) {
+        //CCS调用产线警报内容
+        String hostSystemUrl = (null == msgUtil.redis_get(ParameterKey.PARAMETERS) ? "" : ((Map<String, String>) msgUtil.redis_get(ParameterKey.PARAMETERS)).get(ParameterKey.HOSTSYSTEMURL).toString());
+        String lineWarnUrl = hostSystemUrl + "/api/GetLineWarn";
+        JSONObject jsonParam = new JSONObject();
+        jsonParam.put("url", ips);
+        String results = msgUtil.httpForPost(lineWarnUrl, jsonParam.toJSONString());
+
+        if(!results.contains("imcsTOccsEnable")){
+            JSONArray jsonArray = JSON.parseArray(results);
+            List<AAutoNodeLog> addLogs = Lists.newArrayList();
+            for(Object obj : jsonArray){
+                JSONObject jsonObject = (JSONObject)obj;
+                int count = aAutoNodeLogService.count(new LbqWrapper<AAutoNodeLog>().eq(AAutoNodeLog::getMethod, "GlobalException").eq(AAutoNodeLog::getStatus, "0").geHeader(AAutoNodeLog::getExecuteTime, LocalDate.now()).leFooter(AAutoNodeLog::getExecuteTime, LocalDate.now()));
+                if(count == 0){
+                    AAutoNodeLog aAutoNodeLog = AAutoNodeLog.builder().status("0").manual("1").exeStatus("2").method("GlobalException").executeTime(new Date())
+                            .exeResult("0").feedback("["+ jsonObject.getString("ip") +"] "+ jsonObject.getString("alertMsg"))
+                            .build();
+                    addLogs.add(aAutoNodeLog);
+                }
+            }
+            if(addLogs.size()>0) {
+                aAutoNodeLogService.saveBatch(addLogs);
+            }
+        }
+        //非空判断是否本地存储
+    }
 }

+ 5 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/service/impl/DeviceStatusLogServiceImpl.java

@@ -17,4 +17,9 @@ public class DeviceStatusLogServiceImpl extends SuperServiceImpl<DeviceStatusLog
     public Map<String, String> queryMachineEvent(LbqWrapper<DeviceStatusLog> wrapper) {
         return baseMapper.queryMachineEvent(wrapper);
     }
+
+    @Override
+    public Map<String, String> calStatusLogTime(Map paramsMap) {
+        return baseMapper.calStatusLogTime(paramsMap);
+    }
 }

+ 94 - 0
imcs-admin-boot/imcs-business-biz/src/main/resources/mapper_business/base/productionReadyCenter/DeviceStatusLogMapper.xml

@@ -37,4 +37,98 @@
          ) s ${ew.customSqlSegment}
     </select>
 
+    <select id="calStatusLogTime" resultType="map">
+        SELECT
+        count(*) AS cnt,
+        sum(n.runMinutes) AS calTime,
+        n.code,
+        n.resource_id,
+        n.curr_date AS currDate
+        FROM (
+        SELECT
+        TIMESTAMPDIFF(
+        MINUTE,
+        MAX(l.start_time),
+        MAX(l.end_time)
+        ) AS runMinutes,
+        l.row_index,
+        l.code,
+        l.resource_id,
+        l.row_group,
+        l.curr_date,
+        MAX(l.start_time) as start_time,
+        MAX(l.end_time)  as end_time
+        FROM
+        (SELECT
+        s.create_time,
+        s.row_index,
+        s.pre_status,
+        s.change_status,
+        s.code,
+        s.resource_id,
+        s.curr_date,
+        FLOOR((s.row_index + 1) / 2) AS row_group,
+        CASE
+        WHEN s.row_index % 2 = 1 THEN
+        s.create_time
+        END AS start_time,
+        CASE
+        WHEN s.row_index % 2 = 0 THEN
+        s.create_time
+        END AS end_time
+        FROM
+        (
+        SELECT
+        t.*, @row_index := @row_index + 1 AS row_index
+        FROM
+        (
+        SELECT
+        code,
+        resource_id,
+        pre_status,
+        change_status,
+        create_time,
+        curr_date,
+        CASE
+        WHEN @row_code = code THEN
+        @row_num := @row_num + 1
+        ELSE
+        @row_num := 1
+        END AS row_num,
+        @row_code := code AS row_code
+        FROM
+        imcs_device_status_log
+        CROSS JOIN (
+        SELECT
+        @row_num := 0,
+        @row_code := ''
+        ) AS init
+        WHERE
+        1=1
+        <if test="ew.currDate != null and ew.currDate != ''">
+            and curr_date = #{ew.currDate}
+        </if>
+        ORDER BY
+        code,
+        create_time
+        ) t
+        CROSS JOIN (SELECT @row_index := 0) AS vars
+        WHERE
+        CASE
+        WHEN t.row_num = 1
+        AND t.pre_status = '2' THEN
+        t.row_num > 1
+        ELSE
+        t.row_num > 0
+        END
+        ) s
+        ) l
+        GROUP BY l.row_group HAVING end_time IS NOT NULL
+        )n
+        where n.start_time <![CDATA[ < ]]> n.end_time
+        <if test="ew.resourceId != null and ew.resourceId != ''">
+            and n.resource_id = #{ew.resourceId}
+        </if>
+        group by n.curr_date, n.code
+    </select>
 </mapper>

+ 14 - 8
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/externalApi/ProductionTasksController.java

@@ -707,19 +707,16 @@ public class ProductionTasksController {
          String strDay = DateUtil.dateToString0(yesterday, "yyyy-MM-dd");
          List<DeviceRateLog> dataList = Lists.newArrayList();
          int count = deviceRateLogService.count(new LbqWrapper<DeviceRateLog>().eq(DeviceRateLog::getDate, strDay));
-         if(count > 0) return;
+         if(count > 0) return R2.fail("数据已存在");
 
          deviceList.stream().forEach(item -> {
              DeviceRateLog deviceRateLog = DeviceRateLog.builder().code(item.getCode()).date(strDay).resourceId(item.getId()).build();
-             if(!item.getOnlineStatus().equals("1") || !item.getStatus().equals("1")){
-                 deviceRateLog.setDeviceRate("0");
-             }else{
-                 String rateVal = this.calDeviceRate(item.getId().toString(), strDay);
-                 deviceRateLog.setDeviceRate(rateVal);
-             }
+             String rateVal = this.calDeviceRate(item.getId().toString(), strDay);
+             deviceRateLog.setDeviceRate(rateVal);
              dataList.add(deviceRateLog);
          });
          deviceRateLogService.saveBatch(dataList);
+         return R2.success(true);
     }
 
      private String calDeviceRate(String deviceId, String date){
@@ -730,7 +727,16 @@ public class ProductionTasksController {
          params.put("endDate",  DateUtil.dateToString0(new Date(), "yyyy-MM-dd"));
          IPage<DeviceResourceSumVo> page = productLinePerformanceService.deviceResourceSum(new Page(1L, 10L), params);
          DeviceResourceSumVo deviceResourceSumVo = page.getRecords().size()>0? page.getRecords().get(0) : null;
-         if(deviceResourceSumVo == null) return "0";
+         if(deviceResourceSumVo == null) {
+             Map paramsMap = Maps.newHashMap();
+             paramsMap.put("currDate", date);
+             paramsMap.put("resourceId", deviceId);
+             Map calStatusLogTime = deviceStatusLogService.calStatusLogTime(paramsMap);
+             if(calStatusLogTime==null || calStatusLogTime.isEmpty() || !calStatusLogTime.containsKey("calTime")) return "0";
+             String calTime = calStatusLogTime.get("calTime").toString();
+             float calRate = 100 * Integer.parseInt(calTime)/1440;
+             return String.valueOf(Math.round(calRate));
+         }
 
          float avgActualTime = Integer.parseInt(deviceResourceSumVo.getAvgRealTime())/ 1230;
          float performanceRate = 100 * Float.parseFloat(deviceResourceSumVo.getTotalExpectTime())/ Integer.parseInt(deviceResourceSumVo.getTotalRealTime());

+ 5 - 5
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/externalApi/SynProductionStatus.java

@@ -109,8 +109,6 @@ public class SynProductionStatus {
     @Autowired
     private CodeRuleService codeRuleService;
 
-    private List<DeviceStatusLog> deviceStatusLogList = new ArrayList<DeviceStatusLog>();
-
     @ApiOperation(value = "设备状态同步", notes = "设备状态同步")
     @PostMapping("/synProductionStatus")
     public R agvCallback(@RequestBody Map<String, String> data) {
@@ -128,7 +126,7 @@ public class SynProductionStatus {
         String groupId = codeRuleService.getBillCode(CodeRuleModule.CODE_RULE_UNIQUE);
 
         List<com.github.zuihou.business.productionResourceCenter.entity.Productionresource> bizProductionResources = JSONArray.parseArray(productionStatus, com.github.zuihou.business.productionResourceCenter.entity.Productionresource.class);
-
+        List<DeviceStatusLog> deviceStatusLogList = Lists.newArrayList();
         for(com.github.zuihou.business.productionResourceCenter.entity.Productionresource bizProductionResource : bizProductionResources){
             com.github.zuihou.business.productionResourceCenter.entity.Productionresource  productionresource =
                     productionresourceBizMapper.selectById(bizProductionResource.getId());
@@ -145,8 +143,8 @@ public class SynProductionStatus {
                     networkChanged = true;
                 }else {
                     //设备状态变化本地更新
-                    if(!bizProductionResource.getOnlineStatus().equals(productionresource.getOnlineStatus())){
-                       if(StringUtils.isNotEmpty(productionresource.getModeSpecification())){
+                    if(StringUtils.isNotEmpty(productionresource.getModeSpecification())){
+                        if(!bizProductionResource.getOnlineStatus().equals(productionresource.getOnlineStatus())){
                            //加工设备状态变化触发线边库调度
                            statusChanged = true;
                            //判断机床设备是否有警报或离线上线处理
@@ -175,7 +173,9 @@ public class SynProductionStatus {
                 }
             }
             if(deviceStatusLogList.size()>0){
+                deviceStatusLogList = deviceStatusLogList.stream().distinct().collect(Collectors.toList());
                 deviceStatusLogService.saveBatch(deviceStatusLogList);
+                deviceStatusLogList.clear();
             }
             productionresourceBizMapper.updateById(productionresource);
         }

+ 7 - 0
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/productionReadyCenter/WarnLogController.java

@@ -80,4 +80,11 @@ public class WarnLogController extends SuperSimpleController<AAutoNodeLogService
     public R<Boolean> updateStatus(@RequestParam(value="ids[]")  List<Long> ids) {
         return R.success(baseService.updateStatus(ids));
     }
+
+    @ApiOperation(value = "获取产线报警", notes = "获取产线报警")
+    @PostMapping("/synLineWarn")
+    public R<Boolean> synLineWarn(@RequestParam(value="ips", required = false) String ips) {
+        baseService.synLineWarn(ips);
+        return R.success();
+    }
 }

+ 4 - 2
imcs-admin-boot/imcs-business-entity/src/main/java/com/github/zuihou/business/productionReadyCenter/entity/AAutoNodeLog.java

@@ -285,9 +285,9 @@ public class AAutoNodeLog extends Entity<Long> {
     private String executeTime_ed;
 
     @Builder
-    public AAutoNodeLog(Long id, LocalDateTime createTime, Long createUser, LocalDateTime updateTime, Long updateUser, Long taskId,
+    public AAutoNodeLog(Long id, LocalDateTime createTime, Long createUser, LocalDateTime updateTime, Long updateUser, Long taskId, Date executeTime,
                     Long autoNodeId, String exeStatus, String exeResult, Date startTime, Date endTime, Long taskNodeId, Long orderId,
-                    String feedback, String feedbackFile, String method, Long zoneId, String manual, String sendStatus) {
+                    String feedback, String feedbackFile, String method, Long zoneId, String manual, String sendStatus, String status) {
         this.id = id;
         this.createTime = createTime;
         this.createUser = createUser;
@@ -307,6 +307,8 @@ public class AAutoNodeLog extends Entity<Long> {
         this.sendStatus = sendStatus;
         this.taskId = taskId;
         this.orderId = orderId;
+        this.status = status;
+        this.executeTime = executeTime;
     }
 
 }