From 2fcd97552d16718cc7997629fd637a73a5a4483f Mon Sep 17 00:00:00 2001
From: 郑永安 <zyazyz250@sina.com>
Date: 星期一, 19 六月 2023 14:44:19 +0800
Subject: [PATCH] 删除

---
 src/main/java/com/gk/firework/Scheduls/DL/DeviceIdRobot.java |   68 ++++++++++++++++++++++++++++++++++
 1 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/gk/firework/Scheduls/DL/DeviceIdRobot.java b/src/main/java/com/gk/firework/Scheduls/DL/DeviceIdRobot.java
new file mode 100644
index 0000000..107f704
--- /dev/null
+++ b/src/main/java/com/gk/firework/Scheduls/DL/DeviceIdRobot.java
@@ -0,0 +1,68 @@
+package com.gk.firework.Scheduls.DL;
+
+
+import com.gk.firework.Domain.Enterprise;
+import com.gk.firework.Service.EnterpriseService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Component
+@EnableScheduling
+public class DeviceIdRobot {
+
+    private static  final int deviceSize = 32;
+    @Value("${com.gk.firework.schedules.single.switch}")
+    private Boolean switchBtn;
+    @Autowired
+    private EnterpriseService enterpriseService;
+
+
+
+    @Scheduled(cron = "0/3 * * * * ?") //每隔3秒执行一次
+    public void deviceIdRobot(){
+        if (!switchBtn) return;
+        List<Enterprise> result =  enterpriseService.selectAllDlCompanyCodeIsNotNull();
+        List<Enterprise> updates = null;
+        if (result.size() > 0) {
+            updates = new ArrayList<>();
+            for (Enterprise e : result) {
+                String enterprisenumber = e.getEnterprisenumber();
+                String dlcompanycode = e.getDlcompanycode();
+                String strs = dlcompanycode + enterprisenumber;
+                int length = strs.length();
+                if ( length < deviceSize) {
+                    String deviceId = addZeroForNum(strs);
+                    e.setDeviceid(deviceId);
+                }else{
+                    String deviceId = strs.substring(0, deviceSize);
+                    e.setDeviceid(deviceId);
+                }
+                updates.add(e);
+            }
+        }
+
+        if (updates != null && updates.size() > 0) {
+            enterpriseService.updateBatchById(updates);
+        }
+    }
+
+
+    private static String addZeroForNum(String str) {
+        int strLen = str.length();
+        if (strLen < DeviceIdRobot.deviceSize) {
+            StringBuilder sb = new StringBuilder();
+            sb.append(str);
+            while (sb.toString().length() < DeviceIdRobot.deviceSize) {
+                sb.append("0");
+                str = sb.toString();
+            }
+        }
+        return str;
+    }
+}

--
Gitblit v1.9.2