Kaynağa Gözat

批次号根据接口调用次数动态更新,每天23:50重新计数

wjsheng 3 yıl önce
ebeveyn
işleme
5e7e700c53

+ 47 - 2
test-api/src/main/java/com/sooka/service/impl/Guiji_Housingconstruction_ServiceImpl.java

@@ -10,10 +10,15 @@ import com.sooka.mapper.Guiji_Housingconstruction_Mapper2;
 import com.sooka.model.ResultModel;
 import com.sooka.model.bo.*;
 import com.sooka.service.Guiji_Housingconstruction_Service;
+import com.sooka.utils.HttpUtil;
 import com.sooka.utils.UnicodeUtil;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
 import java.util.UUID;
 
 @Service
@@ -154,6 +159,15 @@ public class Guiji_Housingconstruction_ServiceImpl extends BaseService implement
         return r;
     }
 
+    //批次号计数器,每天0点清零
+    int batch = 0;
+
+    //每天23:50清空批次号计数器batch
+    @Scheduled(cron = "0 50 23 * * ?")
+    public void batchClear() {
+        batch = 0;
+    }
+
     @Override
     public ResultModel add_guiji_housingconstruction_hqrlsj(String str, String type) {
         ResultModel r = new ResultModel();
@@ -162,14 +176,29 @@ public class Guiji_Housingconstruction_ServiceImpl extends BaseService implement
             if (jsonObject.getString("status").equals("1")) {
                 JSONArray data = jsonObject.getJSONArray("data");
                 for (int i = 0; i < data.size(); i++) {
+                    //每次执行接口 批次号计数器 加1
+                    batch++;
+
                     JSONObject obj = data.getJSONObject(i);
                     String id = UUID.randomUUID().toString();
                     String name = obj.getString("name");
                     String time = obj.getString("time");
                     JSONArray params = obj.getJSONArray("params");
                     Guiji_housingconstruction_hqrlsj_Bean bean = new Guiji_housingconstruction_hqrlsj_Bean();
+
                     //2021-10-21 添加
-                    initBaseGuijiBean(str, bean);
+                    SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                    Date date = new Date(System.currentTimeMillis());
+                    Calendar rightNow = Calendar.getInstance();
+                    Integer year = rightNow.get(Calendar.YEAR);
+                    Integer month = rightNow.get(Calendar.MONTH)+1;
+                    Integer day = rightNow.get(rightNow.DAY_OF_MONTH);
+
+                    bean.setCd_time(sdf.format(date));
+                    bean.setCd_batch(year + "" + month+"" + day + this.getBatch(batch));//
+                    bean.setCd_operation("I");
+                    bean.setCd_source("503026");
+
                     bean.setId(id);
                     bean.setName(name);
                     bean.setType(type);
@@ -183,7 +212,12 @@ public class Guiji_Housingconstruction_ServiceImpl extends BaseService implement
                         String hqrlsj_id = id;
                         Guiji_housingconstruction_hqrlsj_Bean bean_detail = new Guiji_housingconstruction_hqrlsj_Bean();
                         //2021-10-21 添加
-                        initBaseGuijiBean(str, bean_detail);
+                        Date date_detail = new Date(System.currentTimeMillis());
+                        bean_detail.setCd_time(sdf.format(date_detail));
+                        bean_detail.setCd_batch(year + "" + month + "" + day + this.getBatch(batch));
+                        bean_detail.setCd_operation("I");
+                        bean_detail.setCd_source("503026");
+
                         bean_detail.setId(param_id);
                         bean_detail.setName(p_name);
                         bean_detail.setValue(p_value);
@@ -202,4 +236,15 @@ public class Guiji_Housingconstruction_ServiceImpl extends BaseService implement
         }
         return r;
     }
+
+    //根据全局变量batch获取批次号后五位,如果batch是一位数,则在前面补全4个0,如果是两位数补全3个0
+    public String getBatch(int batch){
+        String cdBatch = batch + "";
+        String str;
+        if(cdBatch.length() == 1){
+            return "0000"+batch;
+        }else{
+            return "000"+batch;
+        }
+    }
 }