浏览代码

大屏看板后端接口

oyq28 7 月之前
父节点
当前提交
663b63eaba

+ 3 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/operationManagementCenter/dao/TTaskMapper.java

@@ -86,4 +86,7 @@ public interface TTaskMapper extends SuperMapper<TTask> {
     Integer getMonthProductCount();
 
     ToolCostomAddressHistory getMinTool(@Param("startTime") String startTime, @Param("ip") String ip);
+
+    ToolCostomAddressHistory getMinToolDay(@Param("startTime") String startTime, @Param("ip") String ip);
+    ToolCostomAddressHistory getMaxToolDay(@Param("startTime") String startTime, @Param("ip") String ip);
 }

+ 115 - 8
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/operationManagementCenter/service/impl/TaskServiceImpl.java

@@ -87,7 +87,10 @@ import javax.annotation.Resource;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.sql.Timestamp;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
@@ -1799,6 +1802,89 @@ public class TaskServiceImpl extends SuperServiceImpl<TTaskMapper, TTask> implem
         //获取机床当天最晚采集数据
         List<ToolCostomAddressHistory> maxProduct = baseMapper.getMax();
 
+        Map<String,Double> useTimeMap=new HashMap<>();
+
+        //计算机床隔天 加工时长
+        product.stream().forEach(vo->{
+            String startTime = vo.getStartTime(); // 假设 startTime 的格式是 "yyyy-MM-dd HH:mm"
+
+            // 定义日期格式
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
+
+            DateTimeFormatter formatterDay = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+
+            // 将字符串解析为 LocalDateTime
+            LocalDate startDate = LocalDate.parse(startTime.substring(0, 10), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+
+            // 获取今天的日期
+            LocalDate today = LocalDate.now();
+
+            // 计算相差的天数
+            long daysBetween = ChronoUnit.DAYS.between(startDate, today);
+
+            String ip;
+            if(StringUtils.equals("GMU800AVI-1",vo.getName())){
+                ip="10.161.30.245";
+            }else if(StringUtils.equals("GMU800AVI-2",vo.getName())){
+                ip="10.161.30.246";
+            }else if(StringUtils.equals("GMU800AVI-3",vo.getName())){
+                ip="10.161.30.247";
+            } else {
+                ip = null;
+            }
+            double difference = 0;
+            if(daysBetween==1){
+                //获取机床启动程序时间的数据采集
+                ToolCostomAddressHistory minTool = baseMapper.getMinTool(startTime,ip);
+                ToolCostomAddressHistory maxTool = baseMapper.getMaxToolDay(startTime,ip);
+                if(minTool==null || maxTool==null){
+                    return;
+                }
+
+                String min=getToolUseTime(minTool);
+                String max=getToolUseTime(maxTool);
+
+                // 转换为 double
+                double value1 = Double.parseDouble(max);
+                double value2 = Double.parseDouble(min);
+
+                // 计算差值
+                 difference = value1 - value2;
+            }else if(daysBetween>1){
+                // 初始化日期集合
+                List<String> dateStrings = new ArrayList<>();
+                for (long i = 0; i < daysBetween; i++) { // 不包括 startDate 和 today 本身
+                    LocalDate date = startDate.plusDays(i);
+                    dateStrings.add(date.format(formatterDay)); // 转换为字符串并加入列表
+                }
+                
+                for(int i=0;i<dateStrings.size();i++){
+                    ToolCostomAddressHistory minTool;
+                    if(i==0){
+                         minTool = baseMapper.getMinTool(startTime,ip);
+                    }else{
+                         minTool = baseMapper.getMinToolDay(dateStrings.get(i),ip);
+                    }
+                    
+                    ToolCostomAddressHistory maxTool = baseMapper.getMaxToolDay(dateStrings.get(i),ip);
+                    if(minTool==null || maxTool==null){
+                        continue;
+                    }
+                    String min=getToolUseTime(minTool);
+                    String max=getToolUseTime(maxTool);
+                    // 转换为 double
+                    double value1 = Double.parseDouble(max);
+                    double value2 = Double.parseDouble(min);
+
+                    // 计算差值
+                    double dif = value1 - value2;
+                    difference+=dif;
+                }
+            }
+            useTimeMap.put(ip,difference);
+
+        });
+
 
 
         Map<String,Integer> useMap=new HashMap<>();
@@ -1856,18 +1942,22 @@ public class TaskServiceImpl extends SuperServiceImpl<TTaskMapper, TTask> implem
                     } else {
                         ip = null;
                     }
+                    double beforeUseTime = 0;
+                    if(useTimeMap.containsKey(ip)){
+                        beforeUseTime=useTimeMap.get(ip);
+                    }
+
                     //获取机床启动程序时间的数据采集
                     ToolCostomAddressHistory minTool = baseMapper.getMinTool(item.getStartTime(),ip);
-                    if(minTool!=null){
+
+                    Optional<ToolCostomAddressHistory> first = maxProduct.stream().filter(it -> it.getIp().equals(ip)).findFirst();
+
+                    if(minTool!=null && first.isPresent()){
                         cn.hutool.json.JSONObject jsonObject=new cn.hutool.json.JSONObject(minTool.getValue());
                         JSONArray minJsonArray = JSONArray.parseArray(jsonObject.get("values").toString());
                         String min = minJsonArray.get(101).toString();
 
-                        Optional<ToolCostomAddressHistory> first = maxProduct.stream().filter(it -> it.getIp().equals(ip)).findFirst();
-                        if(!first.isPresent()){
-                            item.setRemainTime();
-                            return;
-                        }
+
                         String value = first.get().getValue();
                         cn.hutool.json.JSONObject maxJsonObject=new cn.hutool.json.JSONObject(value);
                         JSONArray maxJsonArray = JSONArray.parseArray(maxJsonObject.get("values").toString());
@@ -1879,9 +1969,9 @@ public class TaskServiceImpl extends SuperServiceImpl<TTaskMapper, TTask> implem
 
                         // 计算差值
                         double difference = value1 - value2;
+                        
 
-
-                        double result = (difference / (60));
+                        double result = ((difference+beforeUseTime) / (60));
 
                         double point=result/item.getSumTime()*100;
                         int finalPoint = (int) Math.round(point);
@@ -1889,6 +1979,16 @@ public class TaskServiceImpl extends SuperServiceImpl<TTaskMapper, TTask> implem
                         int finalResult = (int) Math.round(result);
                         item.setProcessedTime(finalResult);
                         item.setPoint(finalPoint);
+                        item.setRemainTime();
+                    }else{
+                        double result = ((beforeUseTime) / (60));
+                        double point=result/item.getSumTime()*100;
+                        int finalPoint = (int) Math.round(point);
+                        // 已加工时长
+                        int finalResult = (int) Math.round(result);
+                        item.setProcessedTime(finalResult);
+                        item.setPoint(finalPoint);
+                        item.setRemainTime();
                     }
 
                 });
@@ -1926,6 +2026,13 @@ public class TaskServiceImpl extends SuperServiceImpl<TTaskMapper, TTask> implem
 
         return map;
     }
+    
+    public  String getToolUseTime(ToolCostomAddressHistory toolHistory){
+        cn.hutool.json.JSONObject jsonObject=new cn.hutool.json.JSONObject(toolHistory.getValue());
+        JSONArray minJsonArray = JSONArray.parseArray(jsonObject.get("values").toString());
+        String min = minJsonArray.get(101).toString();
+        return min;
+    }
 
     @Override
     public Map<String, Integer> chfTwoDatasProductAndMes() {

+ 24 - 0
imcs-admin-boot/imcs-business-biz/src/main/resources/mapper_business/base/operationManagementCenter/TTaskMapper.xml

@@ -591,4 +591,28 @@
 
     </select>
 
+    <select id="getMinToolDay" resultType="com.github.zuihou.business.centralToolMagazine.entity.ToolCostomAddressHistory">
+        SELECT t.*
+        FROM tool_costom_address_history t
+                 JOIN (
+            SELECT ip, MIN(create_time) AS earliest_time
+            FROM tool_costom_address_history
+            WHERE DATE(create_time) = DATE(#{startTime}) and result='true' and ip=#{ip}
+        GROUP BY ip
+            ) sub
+        ON t.ip = sub.ip AND t.create_time = sub.earliest_time;
+    </select>
+
+    <select id="getMaxToolDay" resultType="com.github.zuihou.business.centralToolMagazine.entity.ToolCostomAddressHistory">
+        SELECT t.*
+        FROM tool_costom_address_history t
+                 JOIN (
+            SELECT ip, MAX(create_time) AS earliest_time
+            FROM tool_costom_address_history
+            WHERE DATE(create_time) = DATE(#{startTime}) and result='true' and ip=#{ip}
+        GROUP BY ip
+            ) sub
+        ON t.ip = sub.ip AND t.create_time = sub.earliest_time;
+    </select>
+
 </mapper>