From 982937e0f439f6422a9912da604def3f10b41bb9 Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期一, 02 九月 2024 10:36:40 +0800
Subject: [PATCH] 2024-09-02 朱宝民 字典及字典项放到配置文件中,自动导入数据库
---
pipIrr-platform/pipIrr-global/src/main/resources/application-database-pj.yml | 4
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/util/InitListener.java | 103 +++++++++++++++++++++++++++++++--
pipIrr-platform/pipIrr-global/src/main/resources/init-config.xml | 48 ++++++++++-----
3 files changed, 129 insertions(+), 26 deletions(-)
diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/application-database-pj.yml b/pipIrr-platform/pipIrr-global/src/main/resources/application-database-pj.yml
index 6b1b3b1..4b385ce 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/application-database-pj.yml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/application-database-pj.yml
@@ -5,8 +5,8 @@
#name: pj
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
- #url: jdbc:mysql://192.168.40.166:3306/pipIrr_pj?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
- #url: jdbc:mysql://8.130.130.233:3306/pipIrr_pj?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
+# url: jdbc:mysql://192.168.40.166:3306/pipIrr_pj?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
+# url: jdbc:mysql://8.130.130.233:3306/pipIrr_pj?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
#url: jdbc:mysql://8.140.179.55:3306/pipIrr_pj?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
url: jdbc:mysql://127.0.0.1:3306/pipIrr_pj?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
username: root
diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/init-config.xml b/pipIrr-platform/pipIrr-global/src/main/resources/init-config.xml
index 130b67f..b28eb79 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/init-config.xml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/init-config.xml
@@ -10,6 +10,14 @@
</city>
</province>
</districts>
+ <dictionaries>
+ <dict code="protocol" title="鍗忚" valueType="2">
+ <dictItem>
+ <item1 dictCode="protocol" value="p206V1_0_1" name="鑰佸崗璁�" status="1" sort="0" />
+ <item2 dictCode="protocol" value="p206V202404" name="鏂板崗璁�" status="0" sort="1" />
+ </dictItem>
+ </dict>
+ </dictionaries>
<user name="瓒呯骇绠$悊鍛�" phone="admin" password="admin" supperAdmin="1" />
<payments>
<item1 name="鐜伴噾"/>
@@ -30,14 +38,14 @@
</waterTypes>
<waterPrice price="0.90" />
<irrigateProfile>
- <item1 default_value = "10" unit = "2" sort = "1" type = "1"/>
- <item2 default_value = "20" unit = "2" sort = "2" type = "1" />
- <item3 default_value = "1" unit = "1" sort = "3" type = "1"/>
- <item4 default_value = "2" unit = "1" sort = "4" type = "1"/>
- <item5 default_value = "20" unit = "3" sort = "1" type = "2"/>
- <item6 default_value = "30" unit = "3" sort = "2" type = "2"/>
- <item7 default_value = "50" unit = "3" sort = "3" type = "2"/>
- <item8 default_value = "80" unit = "3" sort = "4" type = "2"/>
+ <item1 defaultValue = "10" unit = "2" sort = "1" type = "1"/>
+ <item2 defaultValue = "20" unit = "2" sort = "2" type = "1" />
+ <item3 defaultValue = "1" unit = "1" sort = "3" type = "1"/>
+ <item4 defaultValue = "2" unit = "1" sort = "4" type = "1"/>
+ <item5 defaultValue = "20" unit = "3" sort = "1" type = "2"/>
+ <item6 defaultValue = "30" unit = "3" sort = "2" type = "2"/>
+ <item7 defaultValue = "50" unit = "3" sort = "3" type = "2"/>
+ <item8 defaultValue = "80" unit = "3" sort = "4" type = "2"/>
</irrigateProfile>
</org1>
<org2 tag="pj" name="鐗囪" enable="false">
@@ -48,6 +56,14 @@
</city>
</province>
</districts>
+ <dictionaries>
+ <dict code="protocol" title="鍗忚" valueType="2">
+ <dictItem>
+ <item1 dictCode="protocol" value="p206V1_0_1" name="鑰佸崗璁�" status="1" sort="0" />
+ <item2 dictCode="protocol" value="p206V202404" name="鏂板崗璁�" status="0" sort="1" />
+ </dictItem>
+ </dict>
+ </dictionaries>
<user name="瓒呯骇绠$悊鍛�" phone="admin" password="admin" supperAdmin="1" />
<payments>
<item1 name="鐜伴噾"/>
@@ -68,14 +84,14 @@
</waterTypes>
<waterPrice price="0.90" />
<irrigateProfile>
- <item1 default_value = "10" unit = "2" sort = "1" type = "1"/>
- <item2 default_value = "20" unit = "2" sort = "2" type = "1" />
- <item3 default_value = "1" unit = "1" sort = "3" type = "1"/>
- <item4 default_value = "2" unit = "1" sort = "4" type = "1"/>
- <item5 default_value = "20" unit = "3" sort = "1" type = "2"/>
- <item6 default_value = "30" unit = "3" sort = "2" type = "2"/>
- <item7 default_value = "50" unit = "3" sort = "3" type = "2"/>
- <item8 default_value = "80" unit = "3" sort = "4" type = "2"/>
+ <item1 defaultValue = "10" unit = "2" sort = "1" type = "1"/>
+ <item2 defaultValue = "20" unit = "2" sort = "2" type = "1" />
+ <item3 defaultValue = "1" unit = "1" sort = "3" type = "1"/>
+ <item4 defaultValue = "2" unit = "1" sort = "4" type = "1"/>
+ <item5 defaultValue = "20" unit = "3" sort = "1" type = "2"/>
+ <item6 defaultValue = "30" unit = "3" sort = "2" type = "2"/>
+ <item7 defaultValue = "50" unit = "3" sort = "3" type = "2"/>
+ <item8 defaultValue = "80" unit = "3" sort = "4" type = "2"/>
</irrigateProfile>
</org2>
</orgs>
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/util/InitListener.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/util/InitListener.java
index 4e54a8f..eaf3213 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/util/InitListener.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/util/InitListener.java
@@ -5,16 +5,12 @@
import com.dy.common.mybatis.envm.Disabled;
import com.dy.common.util.ConfigXml4Springboot;
import com.dy.common.util.MD5;
-import com.dy.pipIrrGlobal.daoBa.BaDistrictMapper;
-import com.dy.pipIrrGlobal.daoBa.BaSettingsMapper;
-import com.dy.pipIrrGlobal.daoBa.BaUserMapper;
+import com.dy.pipIrrGlobal.daoBa.*;
import com.dy.pipIrrGlobal.daoPr.PrWaterPriceMapper;
import com.dy.pipIrrGlobal.daoRm.RmIrrigateProfileMapper;
import com.dy.pipIrrGlobal.daoSe.SePaymentMethodMapper;
import com.dy.pipIrrGlobal.daoSe.SeWaterTypeMapper;
-import com.dy.pipIrrGlobal.pojoBa.BaDistrict;
-import com.dy.pipIrrGlobal.pojoBa.BaSettings;
-import com.dy.pipIrrGlobal.pojoBa.BaUser;
+import com.dy.pipIrrGlobal.pojoBa.*;
import com.dy.pipIrrGlobal.pojoPr.PrWaterPrice;
import com.dy.pipIrrGlobal.pojoRm.RmIrrigateProfile;
import com.dy.pipIrrGlobal.pojoSe.SePaymentMethod;
@@ -46,6 +42,8 @@
private SeWaterTypeMapper waterTypeDao ;
private RmIrrigateProfileMapper rmIrrigateProfileDao;
private PrWaterPriceMapper prWaterPriceDao;
+ private BaDictMapper baDictDao;
+ private BaDictItemMapper baDictItemDao;
@Autowired
public void setResourceLoader(ResourceLoader resourceLoader){
@@ -85,6 +83,16 @@
@Autowired
public void setWaterPriceDao(PrWaterPriceMapper prWaterPriceDao) {
this.prWaterPriceDao = prWaterPriceDao;
+ }
+
+ @Autowired
+ public void setBaDictDao(BaDictMapper baDictDao) {
+ this.baDictDao = baDictDao;
+ }
+
+ @Autowired
+ public void setBaDictItemDao(BaDictItemMapper baDictItemDao) {
+ this.baDictItemDao = baDictItemDao;
}
/**
@@ -186,11 +194,11 @@
if(configXml.existElement(doc, "config.orgs.org" + num + ".irrigateProfile")){
for(int i = 1 ; i < 10000; i++){
if(configXml.existElement(doc, "config.orgs.org" + num + ".irrigateProfile.item" + i)){
- String default_value = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".irrigateProfile.item" + i,"default_value", null, false, null) ;
+ String defaultValue = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".irrigateProfile.item" + i,"defaultValue", null, false, null) ;
String unit = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".irrigateProfile.item" + i,"unit", null, false, null) ;
String sort = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".irrigateProfile.item" + i,"sort", null, false, null) ;
String type = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".irrigateProfile.item" + i,"type", null, false, null) ;
- this.saveIrrigateProfile(orgTag, default_value, unit,sort,type);
+ this.saveIrrigateProfile(orgTag, defaultValue, unit,sort,type);
}else{
break ;
}
@@ -213,6 +221,28 @@
if(configXml.existElement(doc, "config.orgs.org" + num + ".waterPrice")){
String price = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".waterPrice","price", null, false, null) ;
this.saveWaterPrice(orgTag, price);
+ }
+ }
+ if(!this.existDict()){
+ if(configXml.existElement(doc, "config.orgs.org" + num + ".dictionaries.dict")){
+ String code = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".dictionaries.dict","code", null, false, null) ;
+ String title = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".dictionaries.dict","title", null, false, null) ;
+ String valueType = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".dictionaries.dict","valueType", null, false, null) ;
+ this.saveDicts(orgTag, code,title,valueType);
+ if(configXml.existElement(doc, "config.orgs.org" + num + ".dictionaries.dict.dictItem")){
+ for(int i = 1 ; i < 10000; i++){
+ if(configXml.existElement(doc, "config.orgs.org" + num + ".dictionaries.dict.dictItem.item" + i)){
+ String dictCode = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".dictionaries.dict.dictItem.item" + i,"dictCode", null, false, null) ;
+ String value = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".dictionaries.dict.dictItem.item" + i,"value", null, false, null) ;
+ String name = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".dictionaries.dict.dictItem.item" + i,"name", null, false, null) ;
+ String status = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".dictionaries.dict.dictItem.item" + i,"status", null, false, null) ;
+ String sort = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".dictionaries.dict.dictItem.item" + i,"sort", null, false, null) ;
+ this.saveDictItems(orgTag,dictCode,value,name,status,sort);
+ }else{
+ break ;
+ }
+ }
+ }
}
}
}
@@ -283,6 +313,15 @@
*/
private boolean existWaterPrice() {
Long total = this.prWaterPriceDao.selectCount(null);
+ return (total != null && total > 0) ;
+ }
+
+ /**
+ * 鏁版嵁搴撲腑鏄惁瀛樺湪瀛楀吀
+ * @return
+ */
+ private boolean existDict() {
+ Long total = this.baDictDao.selectCount(null);
return (total != null && total > 0) ;
}
@@ -401,6 +440,7 @@
po.setUnit(Byte.valueOf(unit));
po.setSort(Integer.parseInt(sort));
po.setType(Byte.valueOf(type));
+ po.setDeleted(0L);
this.rmIrrigateProfileDao.insert(po);
}
}
@@ -415,7 +455,54 @@
po.setPrice(Double.parseDouble(price));
po.setDeleted((byte)0);
this.prWaterPriceDao.insert(po);
+ }
+ }
+ /**
+ * 淇濆瓨瀛楀吀
+ * @param orgTag
+ * @param code
+ * @param title
+ * @param valueType
+ * @return
+ */
+ private void saveDicts(String orgTag, String code, String title, String valueType) {
+ if((code != null && !code.trim().equals("")) &&
+ (title != null && !title.trim().equals("")) &&
+ (valueType != null && !valueType.trim().equals(""))) {
+ BaDict po = new BaDict();
+ po.setCode(code);
+ po.setTitle(title);
+ po.setValueType(Byte.valueOf(valueType));
+ po.setHashCode("c4ca4238a0b923820dcc509a6f75849b");
+ po.setDeleted(0L);
+ this.baDictDao.insert(po);
+ }
+ }
+
+ /**
+ * 淇濆瓨瀛楀吀椤�
+ * @param orgTag
+ * @param dictCode
+ * @param value
+ * @param name
+ * @param status
+ * @param sort
+ */
+ private void saveDictItems(String orgTag, String dictCode, String value, String name, String status, String sort) {
+ if((dictCode != null && !dictCode.trim().equals("")) &&
+ (value != null && !value.trim().equals("")) &&
+ (name != null && !name.trim().equals("")) &&
+ (status != null && !status.trim().equals("")) &&
+ (sort != null && !sort.trim().equals(""))) {
+ BaDictItem po = new BaDictItem();
+ po.setDictCode(dictCode);
+ po.setValue(value);
+ po.setName(name);
+ po.setStatus(Byte.valueOf(status));
+ po.setSort(Integer.parseInt(sort));
+ po.setDeleted(0L);
+ this.baDictItemDao.insert(po);
}
}
--
Gitblit v1.8.0