From c206acfaedc69c390fb67daa81bc686f58a212ef Mon Sep 17 00:00:00 2001
From: CZT <czt18638530771@163.com>
Date: 星期一, 27 十一月 2023 16:12:11 +0800
Subject: [PATCH] 提交配置信息2

---
 igds-verb/src/main/java/com/ld/igds/verb/service/HMAreationDataService.java |   61 ++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 1 deletions(-)

diff --git a/igds-verb/src/main/java/com/ld/igds/verb/service/HMAreationDataService.java b/igds-verb/src/main/java/com/ld/igds/verb/service/HMAreationDataService.java
index 6a33db5..e5456d7 100644
--- a/igds-verb/src/main/java/com/ld/igds/verb/service/HMAreationDataService.java
+++ b/igds-verb/src/main/java/com/ld/igds/verb/service/HMAreationDataService.java
@@ -2,18 +2,29 @@
 
 import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
 import com.bstek.dorado.data.provider.Page;
+import com.ld.igds.constant.RedisConst;
 import com.ld.igds.models.MAreationData;
 import com.ld.igds.util.ContextUtil;
+import com.ld.igds.util.RedisUtil;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.time.DateFormatUtils;
 import org.hibernate.Session;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.Date;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 @Service
 public class HMAreationDataService extends HibernateDao {
+
+    @Autowired
+    private RedisUtil redisUtil;
+
+    public static final String CACHE_AREATION_ID = "AREATION_ID";
+
     public void pageData(Page<MAreationData> page, Map<String, Object> param)
             throws Exception {
         String hql = " from " + MAreationData.class.getName()
@@ -49,7 +60,8 @@
         data.setUpdateUser(ContextUtil.getLoginUserCName());
         try {
             if (null == data.getId()) {
-                data.setId(ContextUtil.getUUID());
+                String id = createId(data.getCompanyId(), data.getStartTime());
+                data.setId(id);
                 session.save(data);
             } else {
                 session.update(data);
@@ -61,6 +73,7 @@
             session.close();
         }
     }
+
     public String delData(MAreationData data) {
         Session session = this.getSessionFactory().openSession();
         try {
@@ -75,4 +88,50 @@
         }
         return null;
     }
+
+    public List<MAreationData> areationList(Map<String, Object> param) {
+        StringBuffer hql = new StringBuffer();
+        Map<String, Object> args = new HashMap<>();
+        hql.append(" from " + MAreationData.class.getName() + " where companyId=:companyId");
+        args.put("companyId", ContextUtil.getCompanyId());
+        if (null != param) {
+            String str = (String) param.get("id");
+            if (StringUtils.isNotEmpty(str)) {
+                hql.append(" and id like:id");
+                args.put("id", str + "%");
+            }
+        }
+        hql.append(" order by id desc");
+        return this.query(String.valueOf(hql), args);
+    }
+
+    public String createId(String companyId, Date time) {
+
+        String timeKey = DateFormatUtils.format(time, "yyyyMMdd");
+        // 浠庣紦瀛樹腑鑾峰彇宸叉湁鐨勭粍缁囩紪鐮�
+        String cacheKey = RedisConst.buildKey(companyId, HMAreationDataService.CACHE_AREATION_ID);
+
+        String cacheId = (String) redisUtil.get(cacheKey);
+        if (null != cacheId && cacheId.indexOf(timeKey) >= 0) {
+            String temp = cacheId.substring(cacheId.length() - 3);
+            Integer i = Integer.valueOf(temp);
+            cacheId = timeKey + String.format("%03d", ++i);
+        } else {
+            Map<String, Object> param = new HashMap<>();
+            param.put("id", timeKey);
+            List<MAreationData> areationList = this.areationList(param);
+            if (null == areationList || areationList.size() == 0) {
+                cacheId = timeKey + "001";
+            } else {
+                String temp = areationList.get(0).getId();
+                String tempNum = temp.substring(temp.length() - 3);
+                Integer i = Integer.valueOf(tempNum);
+                cacheId = timeKey + String.format("%03d", ++i);
+            }
+        }
+        // 鏇存柊缂撳瓨
+        redisUtil.set(cacheKey, cacheId);
+
+        return cacheId;
+    }
 }

--
Gitblit v1.9.3