From 689440364e45d515966f908506ec66dc5ccb8d62 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期三, 15 十一月 2023 14:42:30 +0800 Subject: [PATCH] 1、*Mapper.java继承泛型错误修改 2、行政区实体中增加编号属性 3、行政区级别枚举去掉组 4、实现系统启动后初始化数据库数据监听器 --- pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/config/WebListenerConfiguration.java | 18 ++ pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaBlockMapper.java | 2 pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaDistrictMapper.xml | 22 +++ pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaDistrict.java | 9 + pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaBlockMapper.xml | 22 ++- pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaDistrictMapper.java | 3 pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVoMapper.java | 1 pipIrr-platform/pipIrr-global/src/main/resources/application-database.yml | 1 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ConfigXml.java | 48 +++++-- pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/TypeConversionEnum.java | 2 pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVo.java | 5 pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java | 2 pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/resources/init-config.xml | 14 ++ pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/util/InitListener.java | 183 ++++++++++++++++++++++++++++++ pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaRolePrivilegeMapper.java | 2 pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/DistrictLevel.java | 16 ++ pipIrr-platform/文档/增加一个应用机构.docx | 0 17 files changed, 314 insertions(+), 36 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ConfigXml.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ConfigXml.java index 329b6e3..1b7f619 100644 --- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ConfigXml.java +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ConfigXml.java @@ -104,7 +104,27 @@ } } } - + + /** + * 妫�鏌ュ厓绱犳槸鍚﹀瓨鍦� + * @param doc doc瀵硅薄 + * @param elementName 鍏冪礌鍚嶇О + * @return 杩斿洖缁撴灉 杩斿洖缁撴灉 + */ + public Element getElement(Document doc, String elementName){ + if(doc == null){ + return null ; + } + if(elementName == null){ + return null ; + } + elementName = elementName.trim() ; + if(elementName.equals("")){ + return null ; + } + return this.get_element(doc, elementName) ; + } + /** * 妫�鏌ュ厓绱犳槸鍚﹀瓨鍦� * @param doc doc瀵硅薄 @@ -121,8 +141,8 @@ elementName = elementName.trim() ; if(elementName.equals("")){ return false ; - } - Element e = this.getElement(doc, elementName) ; + } + Element e = this.get_element(doc, elementName) ; return e != null; } @@ -168,7 +188,7 @@ * @throws Exception 鎶涘嚭寮傚父 */ public String getSetAttrTxt(Document doc, String elementName, String attrName, String attPropertyNameFix, Boolean canBlank, String setValue) throws Exception{ - Element e = this.checkAndGetElement(doc, elementName); + Element e = this.check_and_get_element(doc, elementName); return this.getSetAttrTxt(e, attrName, attPropertyNameFix, canBlank, setValue) ; } @@ -204,7 +224,7 @@ * @throws Exception 鎶涘嚭寮傚父 */ public Integer getSetAttrPlusInt(Document doc, String elementName, String attrName, String attPropertyNameFix, Integer min, Integer max, String setValue) throws Exception{ - Element e = this.checkAndGetElement(doc, elementName); + Element e = this.check_and_get_element(doc, elementName); return this.getSetAttrPlusInt(e, attrName, attPropertyNameFix, min, max, setValue) ; } @@ -248,7 +268,7 @@ * @throws Exception 鎶涘嚭寮傚父 */ public Integer getSetAttrInt(Document doc, String elementName, String attrName, String attPropertyNameFix, Integer min, Integer max, String setValue) throws Exception{ - Element e = this.checkAndGetElement(doc, elementName); + Element e = this.check_and_get_element(doc, elementName); return this.getSetAttrInt(e, attrName, attPropertyNameFix, min, max, setValue) ; } @@ -291,7 +311,7 @@ * @throws Exception 鎶涘嚭寮傚父 */ public Double getSetAttrPlusDouble(Document doc, String elementName, String attrName, String attPropertyNameFix, Double min, Double max, String setValue) throws Exception{ - Element e = this.checkAndGetElement(doc, elementName); + Element e = this.check_and_get_element(doc, elementName); return this.getSetAttrPlusDouble(e, attrName, attPropertyNameFix, min, max, setValue) ; } @@ -335,7 +355,7 @@ * @throws Exception 鎶涘嚭寮傚父 */ public Double getSetAttrDouble(Document doc, String elementName, String attrName, String attPropertyNameFix, Double min, Double max, String setValue) throws Exception{ - Element e = this.checkAndGetElement(doc, elementName); + Element e = this.check_and_get_element(doc, elementName); return this.getSetAttrDouble(e, attrName, attPropertyNameFix, min, max, setValue) ; } @@ -371,7 +391,7 @@ * @param elementName 鍏冪礌鍚嶇О 鍏冪礌鍚嶏紝褰㈠"config.base.test" * @return 杩斿洖缁撴灉 */ - private Element getElement(Document doc, String elementName){ + private Element get_element(Document doc, String elementName){ Element e = null ; Element root ; String nm ; @@ -383,7 +403,7 @@ if(eNames.length == 1){ e = root ; }else{ - e = this.getNextElement(root, eNames, 1) ; + e = this.get_next_element(root, eNames, 1) ; } } } @@ -397,7 +417,7 @@ * @param index 鏁扮粍涓嬫爣 * @return 杩斿洖缁撴灉 */ - private Element getNextElement(Element base, String[] eNames, int index){ + private Element get_next_element(Element base, String[] eNames, int index){ Element e = null ; String nm ; List<Element> list = base.getChildren() ; @@ -408,7 +428,7 @@ if(eNames.length == index + 1){ e = el ; }else{ - e = this.getNextElement(el, eNames, index + 1) ; + e = this.get_next_element(el, eNames, index + 1) ; } break ; } @@ -423,7 +443,7 @@ * @return 杩斿洖缁撴灉 * @throws Exception 鎶涘嚭寮傚父 */ - private Element checkAndGetElement(Document doc, String elementName)throws Exception{ + private Element check_and_get_element(Document doc, String elementName)throws Exception{ if(doc == null){ throw new Exception("閰嶇疆鏂囦欢鐨凞OM瀵硅薄涓虹┖!"); } @@ -434,7 +454,7 @@ if(elementName.equals("")){ throw new Exception("鍏冪礌鍚嶄负绌�!"); } - Element e = this.getElement(doc, elementName) ; + Element e = this.get_element(doc, elementName) ; if(e == null){ throw new Exception("鏈緱鍒板悕绉颁负" + elementName + "鐨勫厓绱�!"); } diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaBlockMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaBlockMapper.java index e5933fe..40a5e42 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaBlockMapper.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaBlockMapper.java @@ -10,7 +10,7 @@ import java.util.Map; @Mapper -public interface BaBlockMapper extends BaseMapper<BaPrivilege> { +public interface BaBlockMapper extends BaseMapper<BaBlock> { /** * delete by primary key * @param id primaryKey diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaDistrictMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaDistrictMapper.java index 45af66a..e789212 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaDistrictMapper.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaDistrictMapper.java @@ -8,7 +8,8 @@ import java.util.List; @Mapper -public interface BaDistrictMapper extends BaseMapper<BaPrivilege> { +public interface BaDistrictMapper extends BaseMapper<BaDistrict> { + /** * select by primary key * @param id primary key diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaRolePrivilegeMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaRolePrivilegeMapper.java index 4474cbf..bc9cd3b 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaRolePrivilegeMapper.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaRolePrivilegeMapper.java @@ -6,7 +6,7 @@ import org.apache.ibatis.annotations.Param; @Mapper -public interface BaRolePrivilegeMapper extends BaseMapper<BaRolePrivilegeMapper> { +public interface BaRolePrivilegeMapper extends BaseMapper<BaRolePrivilege> { /** * insert record to table diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaDistrict.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaDistrict.java index 5183651..e9930da 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaDistrict.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaDistrict.java @@ -53,6 +53,15 @@ public String name; /** + * 琛屾斂鍖虹紪鍙� + */ + @Schema(description = "琛屾斂鍖虹紪鍙�", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "琛屾斂鍖虹紪鍙蜂笉鑳戒负绌�") //涓嶈兘涓虹┖涔熶笉鑳戒负null + @Max(message = "琛屾斂鍖虹紪鍙蜂笉澶т簬99", value = 99) + @Min(message = "琛屾斂鍖虹紪鍙蜂笉灏忎簬0",value = 0) + public String num; + + /** * 琛屾斂鍖虹骇鍒� */ @Schema(description = "琛屾斂鍖虹骇鍒�", requiredMode = Schema.RequiredMode.REQUIRED) diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/DistrictLevel.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/DistrictLevel.java index f841907..edc4a10 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/DistrictLevel.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/DistrictLevel.java @@ -12,8 +12,7 @@ City((byte)1, "甯�"), County((byte)2, "鍘�"), Town((byte)3, "闀�"), - Village((byte)4, "鏉�"), - Group((byte)5, "缁�"); + Village((byte)4, "鏉�") ; @EnumValue public Byte code ; @@ -33,4 +32,17 @@ public String getName() { return this.name ; } + + public static DistrictLevel get(Byte code){ + if(code.byteValue() == City.code.byteValue()){ + return City ; + }else if(code.byteValue() == County.code.byteValue()){ + return County ; + }else if(code.byteValue() == Town.code.byteValue()){ + return Town ; + }else if(code.byteValue() == Village.code.byteValue()){ + return Village ; + } + return null ; + } } diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/TypeConversionEnum.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/TypeConversionEnum.java index 578e348..e12c531 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/TypeConversionEnum.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/TypeConversionEnum.java @@ -30,8 +30,6 @@ rObj = DistrictLevel.Town ; }else if(sourceObj == DistrictLevel.Village.code){ rObj = DistrictLevel.Village ; - }else if(sourceObj == DistrictLevel.Group.code){ - rObj = DistrictLevel.Group ; } return rObj ; } diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/application-database.yml b/pipIrr-platform/pipIrr-global/src/main/resources/application-database.yml index ba485ec..a215953 100644 --- a/pipIrr-platform/pipIrr-global/src/main/resources/application-database.yml +++ b/pipIrr-platform/pipIrr-global/src/main/resources/application-database.yml @@ -106,6 +106,7 @@ maxPoolPreparedStatementPerConnectionSize: 20 #灞炴�х被鍨嬫槸瀛楃涓诧紝閫氳繃鍒悕鐨勬柟寮忛厤缃墿灞曟彃浠讹紝甯哥敤鐨勬彃浠舵湁锛� #鐩戞帶缁熻鐢ㄧ殑filter:stat锛屾棩蹇楃敤鐨刦ilter:log4j锛岄槻寰ql娉ㄥ叆鐨刦ilter:wall + #寮冪敤filter:stat锛岃https://blog.csdn.net/K_520_W/article/details/132382812 filters: stat,wall,config webStatFilter: # 娣诲姞杩囨护瑙勫垯 diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaBlockMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaBlockMapper.xml index 89576a3..46df3bd 100644 --- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaBlockMapper.xml +++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaBlockMapper.xml @@ -69,16 +69,6 @@ </trim> </select> - <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> - <!--@mbg.generated--> - delete from ba_block - where id = #{id,jdbcType=BIGINT} - </delete> - <delete id="deleteLogicById" parameterType="java.lang.Long"> - <!--@mbg.generated--> - update ba_block set deleted = 1 - where id = #{id,jdbcType=BIGINT} - </delete> <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoBa.BaBlock"> <!--@mbg.generated--> insert into ba_block (id, `name`, `header`, phone, area, color, deleted) @@ -176,4 +166,16 @@ deleted = #{deleted,typeHandler=com.dy.common.mybatis.envm.EnumCodeTypeHandler, jdbcType=TINYINT} where id = #{id,jdbcType=BIGINT} </update> + + <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> + <!--@mbg.generated--> + delete from ba_block + where id = #{id,jdbcType=BIGINT} + </delete> + <delete id="deleteLogicById" parameterType="java.lang.Long"> + <!--@mbg.generated--> + update ba_block set deleted = 1 + where id = #{id,jdbcType=BIGINT} + </delete> + </mapper> \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaDistrictMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaDistrictMapper.xml index 2455532..db51681 100644 --- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaDistrictMapper.xml +++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaDistrictMapper.xml @@ -7,13 +7,16 @@ <id column="id" jdbcType="BIGINT" property="id" /> <id column="supperId" jdbcType="BIGINT" property="supperId" /> <result column="name" jdbcType="VARCHAR" property="name" /> + <result column="num" jdbcType="TINYINT" property="num" /> <result property="level" column="level" typeHandler="com.dy.common.mybatis.envm.EnumCodeTypeHandler" javaType="com.dy.pipIrrGlobal.util.DistrictLevel"/> <result property="deleted" column="deleted" typeHandler="com.dy.common.mybatis.envm.EnumCodeTypeHandler" javaType="com.dy.common.mybatis.envm.Deleted"/> </resultMap> + <sql id="Base_Column_List"> <!--@mbg.generated--> - id, supperId, `name`, `level`, deleted + id, supperId, `name`, num, `level`, deleted </sql> + <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap"> <!--@mbg.generated--> select @@ -21,6 +24,7 @@ from ba_district where id = #{id,jdbcType=BIGINT} </select> + <select id="selectByLevel" parameterType="java.lang.Byte" resultMap="BaseResultMap"> <!--@mbg.generated--> select @@ -28,6 +32,7 @@ from ba_district where level = #{level,jdbcType=TINYINT} </select> + <select id="selectBySupperId" parameterType="java.lang.Long" resultMap="BaseResultMap"> <!--@mbg.generated--> select @@ -35,16 +40,19 @@ from ba_district where supperId = #{supperId,jdbcType=BIGINT} </select> + <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoBa.BaDistrict"> <!--@mbg.generated--> - insert into ba_district (id, supperId, `name`, `level`, deleted) + insert into ba_district (id, supperId, `name`, num, `level`, deleted) values (#{id,jdbcType=BIGINT}, #{supperId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, + #{num,jdbcType=TINYINT}, #{level,typeHandler=com.dy.common.mybatis.envm.EnumCodeTypeHandler, jdbcType=TINYINT}, #{deleted,typeHandler=com.dy.common.mybatis.envm.EnumCodeTypeHandler, jdbcType=TINYINT} ) </insert> + <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoBa.BaDistrict"> <!--@mbg.generated--> insert into ba_district @@ -57,6 +65,9 @@ </if> <if test="name != null"> `name`, + </if> + <if test="num != null"> + num, </if> <if test="level != null"> `level`, @@ -75,6 +86,9 @@ <if test="name != null"> #{name,jdbcType=VARCHAR}, </if> + <if test="num != null"> + #{num,jdbcType=TINYINT}, + </if> <if test="level != null"> #{level,typeHandler=com.dy.common.mybatis.envm.EnumCodeTypeHandler, jdbcType=TINYINT}, </if> @@ -89,6 +103,9 @@ <set> <if test="name != null"> `name` = #{name,jdbcType=VARCHAR}, + </if> + <if test="num != null"> + num = #{num,jdbcType=TINYINT}, </if> <if test="supperId != null"> supperId = #{supperId,jdbcType=BIGINT}, @@ -107,6 +124,7 @@ update ba_district set supperId = #{supperId,jdbcType=BIGINT}, `name` = #{name,jdbcType=VARCHAR}, + num = #{num,jdbcType=TINYINT}, `level` = #{level,typeHandler=com.dy.common.mybatis.envm.EnumCodeTypeHandler, jdbcType=TINYINT}, deleted = #{deleted,typeHandler=com.dy.common.mybatis.envm.EnumCodeTypeHandler, jdbcType=TINYINT} where id = #{id,jdbcType=BIGINT} diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/config/WebListenerConfiguration.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/config/WebListenerConfiguration.java index cb50fca..d34e937 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/config/WebListenerConfiguration.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/config/WebListenerConfiguration.java @@ -1,6 +1,7 @@ package com.dy.pipIrrBase.config; import com.dy.common.webListener.GenerateIdSetSuffixListener; +import com.dy.pipIrrBase.util.InitListener; import jakarta.servlet.ServletContextListener; import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; import org.springframework.context.annotation.Bean; @@ -14,6 +15,7 @@ */ //private static final int order_config = 0 ; private static final int order_idSetSuffix = 1 ; + //private static final int order_init = 2 ; /* * 瑙f瀽鍚勭***.config閰嶇疆鐨凜onfigListener锛屾殏鏃朵笉閲囩敤姝ょ閰嶇疆鏂瑰紡 @@ -36,14 +38,26 @@ */ /** - * 鍐呴儴鎻愪緵listener锛岃listener鍦ㄧ郴缁熷惎鍔ㄦ椂锛屾牴鎹厤缃缃甀D浜х敓鍣ㄧ殑鍚庣紑 + * 鍐呴儴鎻愪緵listener锛岃listener鍦ㄧ郴缁熷惎鍔ㄦ椂锛屾牴鎹厤缃� 璁剧疆ID浜х敓鍣ㄧ殑鍚庣紑 * @return 娉ㄥ唽Bean */ @Bean - public ServletListenerRegistrationBean<? extends ServletContextListener> reqSsoListener() { + public ServletListenerRegistrationBean<? extends ServletContextListener> regSsoListener() { ServletListenerRegistrationBean<GenerateIdSetSuffixListener> listenerRegistrationBean = new ServletListenerRegistrationBean<>(); listenerRegistrationBean.setListener(new GenerateIdSetSuffixListener()); listenerRegistrationBean.setOrder(order_idSetSuffix); return listenerRegistrationBean; } + +// /** +// * 鍐呴儴鎻愪緵listener锛岃listener鍦ㄧ郴缁熷惎鍔ㄦ椂锛屽垵濮嬪寲鏁版嵁搴撴暟鎹� +// * @return 娉ㄥ唽Bean +// */ +// @Bean +// public ServletListenerRegistrationBean<? extends ServletContextListener> regInitListener() { +// ServletListenerRegistrationBean<InitListener> listenerRegistrationBean = new ServletListenerRegistrationBean<>(); +// listenerRegistrationBean.setListener(new InitListener()); +// listenerRegistrationBean.setOrder(order_init); +// return listenerRegistrationBean; +// } } diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java index 507f034..5d7ae5f 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java @@ -56,7 +56,7 @@ }) @GetMapping(path = "allLevel") public BaseResponse<List<DistrictLevel>> allDistrictLevels(){ - List<DistrictLevel> list = Arrays.asList(DistrictLevel.City, DistrictLevel.County, DistrictLevel.Town, DistrictLevel.Village, DistrictLevel.Group) ; + List<DistrictLevel> list = Arrays.asList(DistrictLevel.City, DistrictLevel.County, DistrictLevel.Town, DistrictLevel.Village) ; return BaseResponseUtils.buildSuccess(list); } diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVo.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVo.java index 6c0af30..a542141 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVo.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVo.java @@ -26,6 +26,11 @@ @Length(message = "琛屾斂鍖哄悕绉板皬浜巤max}瀛�", min = 1, max = 25) public String name ; + @Schema(description = "琛屾斂鍖虹紪鍙�", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "琛屾斂鍖虹紪鍙蜂笉鑳戒负绌�") //涓嶈兘涓虹┖涔熶笉鑳戒负null + @Length(message = "琛屾斂鍖虹紪鍙锋槸涓�浣嶆垨涓や綅鏁�", min = 1, max = 2) + public String num ; + @Schema(description = "琛屾斂鍖虹骇鍒�", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "琛屾斂鍖虹骇鍒笉鑳戒负绌�") //涓嶈兘涓虹┖涔熶笉鑳戒负null @Max(message = "琛屾斂鍖虹骇鍒笉姝g‘", value = 10) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVoMapper.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVoMapper.java index ffc818d..dced96f 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVoMapper.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictVoMapper.java @@ -17,6 +17,7 @@ @Mapping(target = "id", source = "supperId") @Mapping(target = "supperId", source = "supperId") @Mapping(target = "name", source = "name") + @Mapping(target = "num", source = "num") @Mapping(target = "level", source = "level", qualifiedByName = "districtLevelByteToObj") @Mapping(target = "deleted", source = "deleted", qualifiedByName = "deletedByteToObj") @Mapping(target = "subDistricts", ignore = true) 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 new file mode 100644 index 0000000..aa77c42 --- /dev/null +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/util/InitListener.java @@ -0,0 +1,183 @@ +package com.dy.pipIrrBase.util; + +import com.dy.common.multiDataSource.DataSourceContext; +import com.dy.common.mybatis.envm.Deleted; +import com.dy.common.mybatis.envm.Disabled; +import com.dy.common.util.ConfigXml; +import com.dy.common.util.MD5; +import com.dy.common.webListener.ConfigListener; +import com.dy.pipIrrGlobal.daoBa.BaDistrictMapper; +import com.dy.pipIrrGlobal.daoBa.BaUserMapper; +import com.dy.pipIrrGlobal.pojoBa.BaDistrict; +import com.dy.pipIrrGlobal.pojoBa.BaUser; +import com.dy.pipIrrGlobal.util.DistrictLevel; +import org.jdom2.Document; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Component; + +import java.net.URL; + +/** + * 鐩戝惉鍣紝瀹炵幇鍔熻兘锛氬湪绯荤粺鍚姩鏃跺垵濮嬪寲锛屽悜鏁版嵁搴撲腑鎻掑叆鏁版嵁 + * 鏈洃鍚櫒涓嶈兘閲囩敤ServletContextListener鏂瑰紡锛屽洜涓篠ervlet涓婁笅鏂嘋ontext鍒涘缓鍚� + * Spring瀹瑰櫒骞舵病鏈夊垱寤哄畬锛岃�屾湰绫讳腑鐢ㄧ彁浜哠pring瀹瑰櫒涓殑Bean锛屽嵆distriDao, userDao銆� + * 鎵�浠ラ噰鐢ㄤ簡Spring浜嬩欢鐩戝惉鍣ㄦ潵瀹炵幇 + */ +@Component +public class InitListener implements ApplicationListener<ApplicationReadyEvent> { + + private BaDistrictMapper distriDao ; + private BaUserMapper userDao ; + + @Autowired + public void setDistriDao(BaDistrictMapper distriDao){ + this.distriDao = distriDao ; + } + + @Autowired + public void setUserDao(BaUserMapper userDao){ + this.userDao = userDao ; + } + + + /** + * SpringBoot瀹瑰櫒宸茬粡鍑嗗濂戒簡 + * @param event 浜嬩欢 + */ + @Override + public void onApplicationEvent(@NonNull ApplicationReadyEvent event) { + try { + //绛�1绉掞紝绛夊緟com.alibaba.druid.pool.DruidDataSource瀹炲鍖栧畬鎴� + Thread.sleep(1000L); + } catch (InterruptedException e) { + e.printStackTrace(); + }finally { + this.init(event); + } + } + + /** + * 瀹炲鍖� + */ + @SuppressWarnings("unused ") + private void init(ApplicationReadyEvent event){ + try { + URL configFileURL = ConfigListener.class.getResource("/init-config.xml" ); + ConfigXml configXml = new ConfigXml() ; + Document doc = configXml.createDom(configFileURL) ; + this.doInit(configXml, doc); + } catch (Exception e) { + System.out.println("绯荤粺鍚姩鏃讹紝鍒濆鍖栭厤缃嚭閿� !"); + System.out.println(e.getMessage()); + e.printStackTrace(); + } + } + private void doInit(ConfigXml configXml, Document doc) throws Exception{ + if(configXml != null && doc != null){ + for(int num = 1; num <= 10000; num++){ + if(configXml.existElement(doc, "config.orgs.org" + num)){ + String orgTag = configXml.getSetAttrTxt(doc, "config.orgs.org" + num,"name", null, false, null) ; + //璁剧疆鏁版嵁婧� + DataSourceContext.set(orgTag); + if(!this.existDistricts()){ + if(configXml.existElement(doc, "config.orgs.org" + num + ".districts.city")){ + String distriName = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".districts.city","name", null, false, null) ; + String distriNum = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".districts.city","num", null, false, null) ; + Integer distriLevel = configXml.getSetAttrPlusInt(doc, "config.orgs.org" + num + ".districts.city","level", null, 1, 99,null) ; + Long supperId = this.saveDistrict(null, distriName, distriNum, distriLevel); + if(supperId != null && configXml.existElement(doc, "config.orgs.org" + num + ".districts.city.country")){ + distriName = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".districts.city.country","name", null, false, null) ; + distriNum = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".districts.city.country","num", null, false, null) ; + distriLevel = configXml.getSetAttrPlusInt(doc, "config.orgs.org" + num + ".districts.city.country","level", null, 1, 99,null) ; + this.saveDistrict(supperId, distriName, distriNum, distriLevel); + } + } + } + if(!this.existUsers()){ + if(configXml.existElement(doc, "config.orgs.org" + num + ".user")){ + String name = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".user","name", null, false, null) ; + String phone = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".user","phone", null, false, null) ; + String password = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".user","password", null, false, null) ; + Integer supperAdmin = configXml.getSetAttrPlusInt(doc, "config.orgs.org" + num + ".user","supperAdmin", null, 0, 1,null) ; + this.saveUser(orgTag, name, phone, password, supperAdmin); + } + } + }else{ + break ; + } + } + } + } + + /** + * 鏁版嵁搴撲腑鏄惁瀛樺湪琛屾斂鍖哄垝鏁版嵁 + * @return 瀛樺湪鍚� + */ + private boolean existDistricts(){ + Long total = this.distriDao.selectCount(null) ; + return (total != null && total > 0) ; + } + + /** + * 鏁版嵁搴撲腑鏄惁瀛樺湪琛屾斂鍖哄垝鏁版嵁 + * @return 瀛樺湪鍚� + */ + private boolean existUsers(){ + Long total = this.userDao.selectCount(null) ; + return (total != null && total > 0) ; + } + + /** + * 鏁版嵁搴撲腑淇濆瓨琛屾斂鍖哄垝瀹炰綋 + * @param supperId 涓婄骇ID + * @param name 鍚嶇О + * @param num 缂栧彿 + * @param level 绾у埆 + * @return id + */ + private Long saveDistrict(Long supperId, String name, String num, Integer level){ + if((name != null && !name.trim().equals("")) && + (num != null && !num.trim().equals("")) && + level != null){ + BaDistrict po = new BaDistrict() ; + po.supperId = supperId ; + po.name = name ; + po.num = num ; + po.level = DistrictLevel.get(level.byteValue()) ; + po.deleted = Deleted.NO ; + this.distriDao.insert(po) ; + return po.getId() ; + }else{ + return null ; + } + } + + /** + * 淇濆瓨鐢ㄦ埛 + * @param orgTag 鏈烘瀯鏍囩 + * @param name 鍚嶇О + * @param phone 鎵嬫満鍙� + * @param password 瀵嗙爜 + * @param supperAdmin 鏄惁涓鸿秴绾х鐞嗗憳锛�1鏄紝0鍚︼級 + */ + private void saveUser(String orgTag, String name, String phone, String password, Integer supperAdmin) throws Exception{ + if((name != null && !name.trim().equals("")) && + (phone != null && !phone.trim().equals("")) && + (password != null && !password.trim().equals("")) && + supperAdmin != null){ + BaUser po = new BaUser() ; + po.name = name ; + po.phone = phone ; + po.password = MD5.encrypt(password) ;//杩涜鍔犲瘑鐮� ; + po.orgTag = orgTag ; + po.supperAdmin = supperAdmin.byteValue() ; + po.disabled = Disabled.NO ; + po.deleted = Deleted.NO ; + this.userDao.insert(po) ; + } + } + +} diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/resources/init-config.xml b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/resources/init-config.xml new file mode 100644 index 0000000..6259b52 --- /dev/null +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/resources/init-config.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<config> + <orgs> + <!-- 澶氫釜缁勭粐锛岀敤缂栧彿鍖哄垎锛岀紪鍙蜂粠1寮�濮� --> + <org1 name="ym"> + <districts> + <city name="妤氶泟褰濇棌鑷不宸�" num="23" level="1"> + <country name="鍏冭皨鍘�" num="28" level="2" /> + </city> + </districts> + <user name="瓒呯骇绠$悊鍛�" phone="admin" password="admin" supperAdmin="1" /> + </org1> + </orgs> +</config> \ No newline at end of file diff --git "a/pipIrr-platform/\346\226\207\346\241\243/\345\242\236\345\212\240\344\270\200\344\270\252\345\272\224\347\224\250\346\234\272\346\236\204.docx" "b/pipIrr-platform/\346\226\207\346\241\243/\345\242\236\345\212\240\344\270\200\344\270\252\345\272\224\347\224\250\346\234\272\346\236\204.docx" new file mode 100644 index 0000000..f8dbac1 --- /dev/null +++ "b/pipIrr-platform/\346\226\207\346\241\243/\345\242\236\345\212\240\344\270\200\344\270\252\345\272\224\347\224\250\346\234\272\346\236\204.docx" Binary files differ -- Gitblit v1.8.0