[if !supportLists]1、? [endif]為什么要寫(xiě)本文?
A匀谣、在做很多系統(tǒng)開(kāi)發(fā)的時(shí)候停做,區(qū)域管理之前一直是基于js加載json格式文檔來(lái)實(shí)現(xiàn)的三級(jí)聯(lián)動(dòng)。但很多系統(tǒng)設(shè)計(jì)的時(shí)候,有些表需要一個(gè)行政區(qū)域的外鍵勿侯;
B拓瞪、一直以來(lái)想自主實(shí)現(xiàn)一次行政區(qū)域的管理在系統(tǒng)設(shè)計(jì)級(jí)別上
C、希望此文助琐,能給有A祭埂、B想法的朋友給予快速完成idea的參考以及給“拿來(lái)黨”(注:是拿來(lái)主義的狂熱粉絲)提供力所能及的幫助。
D兵钮、近一兩年自己工作是做一些深度學(xué)習(xí)中圖像識(shí)別的工作蛆橡,覺(jué)得博文可以給予別人幫助,因?yàn)楸救丝催^(guò)很多別人的博文掘譬,收益頗豐泰演。從此篇開(kāi)始,以后工作中遇到的問(wèn)題值得分享的葱轩,都會(huì)寫(xiě)文分享睦焕。完成個(gè)人從“拿來(lái)主義”到“造車(chē)輪”轉(zhuǎn)變的起點(diǎn),更希望以此鼓勵(lì)跟我一樣的朋友“開(kāi)始分享”酿箭!
[if !supportLists]2复亏、? [endif]具體實(shí)現(xiàn)
[if !supportLists]A、 [endif]行政區(qū)域劃分一手的資料在哪里缭嫡?
個(gè)人查閱相關(guān)資料缔御,覺(jué)得國(guó)務(wù)院網(wǎng)站應(yīng)該有,但是查詢(xún)后發(fā)現(xiàn)只有枝干性質(zhì)的說(shuō)明妇蛀。再次查閱相關(guān)資料發(fā)現(xiàn)耕突,最全最直接負(fù)責(zé)更新的國(guó)家部門(mén)是民政部,以下是民政部官方網(wǎng)站http://www.mca.gov.cn评架。其中在本文書(shū)寫(xiě)的時(shí)期最新的行政區(qū)域網(wǎng)址如下(該網(wǎng)址極有可能更新)http://www.mca.gov.cn/article/sj/xzqh/2019/眷茁。
[if !supportLists]B、 [endif]打開(kāi)A中最新的劃分鏈接
[if !supportLists]C纵诞、 [endif]找到準(zhǔn)確的最新文檔位置后上祈,我們需要完成數(shù)據(jù)的采集及落地的各自系統(tǒng)的DB中。
具體的分析如下浙芙,行政區(qū)域代碼總共6位登刺,前2位代表省級(jí)行政區(qū)域,中間兩位代表市級(jí)行政區(qū)域嗡呼,最后兩位代表縣區(qū)級(jí)行政區(qū)域劃分纸俭。
[if !supportLists]D、 [endif]因?yàn)椴徽撐覀兪桥廊∵€是直接復(fù)制的數(shù)據(jù)在結(jié)構(gòu)化上不統(tǒng)一所以需要做一定的結(jié)構(gòu)化改變南窗,具體來(lái)說(shuō)主要是直轄市和港澳地區(qū)以及臺(tái)灣省(這是我國(guó)不可分割的一部分揍很,作為愛(ài)國(guó)人士郎楼,炎黃子孫所以中國(guó)的領(lǐng)土所以一定要包括進(jìn)來(lái))。
具體的調(diào)整如下圖窒悔,將直轄市增加一行呜袁,將港澳及臺(tái)灣增加兩級(jí)
對(duì)比
[if !supportLists]E、? [endif]具體的數(shù)據(jù)結(jié)構(gòu)和代碼實(shí)現(xiàn)如下
數(shù)據(jù)庫(kù)設(shè)計(jì)(按個(gè)人系統(tǒng)需要設(shè)計(jì))
Sql語(yǔ)句如下
DROP TABLE IF EXISTS `area`;
CREATE TABLE `area` (
? `id` bigint(16) NOT NULL COMMENT '編號(hào)',
? `parent_id` bigint(16) DEFAULT NULL COMMENT '父級(jí)編號(hào)',
? `description` varchar(128) DEFAULT NULL COMMENT '名稱(chēng)',
? `rank_number` bigint(16) DEFAULT '0' COMMENT '排序',
? `display_status` varchar(16) DEFAULT NULL COMMENT '是否顯示',
? `create_time` datetime DEFAULT NULL,
? `update_time` datetime DEFAULT NULL,
? `remark` varchar(128) DEFAULT NULL COMMENT '備注',
? PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
[if !supportLists]F蛉迹、? [endif]Java語(yǔ)言實(shí)現(xiàn)從文本到結(jié)構(gòu)化數(shù)據(jù)
package com.awaymeet.fly.common.utils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import org.apache.commons.lang3.StringUtils;
public class ReadText {
???? public static void main(String[] args) throws IOException {
???????? Filef=new File("D://a.txt");//將從行政區(qū)域劃分的網(wǎng)站上采集下來(lái)或者手動(dòng)復(fù)制下來(lái)的文本放入這個(gè)文件
???????? FileReaderfileReader=new FileReader(f);
???????? BufferedReaderbufferedReader=new BufferedReader(fileReader);//讀取文件BufferedReader
???????? StringreadLine;//讀取的每一行文本內(nèi)容
???????? StringpreCode=null;//前一行的行政區(qū)域編碼
???????? //當(dāng)前省市縣的編碼
???????? StringcurrentCodePrivince=null;
???????? StringcurrentCodeCity=null;
???????? StringcurrentCodeCounty=null;
???????? //之前省市縣的編碼
???????? StringpreCodePrivince=null;
???????? StringpreCodeCity=null;
???????? StringpreCodeCounty=null;
???????? int countPrivince=0;//統(tǒng)計(jì)省個(gè)數(shù)傅寡,輔助看看而已
???????? int countCity=0;//統(tǒng)計(jì)市個(gè)數(shù),輔助看看而已
???????? int countCounty=0;//統(tǒng)計(jì)縣區(qū)個(gè)數(shù)北救,輔助看看而已
???????? StringsinglePrivinceCode = null,singleCityCode= null;//用于記錄讀取省市變化的時(shí)候記錄某一個(gè)省市
???????? StringprivinceSqlTxt = "",citySqlTxt= "",countySqlTxt= "";//最終的Sql語(yǔ)句
???????? while(null != (readLine=bufferedReader.readLine())){
????????????? readLine=StringUtils.deleteWhitespace(readLine);
????????????? StringcurrentCode=readLine.substring(0,6);
????????????? StringcurrentArea=readLine.substring(6);
????????????? currentCodePrivince=currentCode.substring(0,2);
????????????? currentCodeCity=currentCode.substring(2,4);
????????????? currentCodeCounty=currentCode.substring(4);
????????????? if(null != preCode){
?????????????????? preCodePrivince=preCode.substring(0,2);
?????????????????? preCodeCity=preCode.substring(2,4);
?????????????????? preCodeCounty=preCode.substring(4);???????????????
????????????? }
????????????? if(currentCodePrivince.equals(preCodePrivince)){
?????????????????? //System.out.println(currentCode+currentArea);
?????????????????? if(currentCodeCity.equals(preCodeCity)){
?????????????????????? //System.out.println(currentCode+currentArea);
?????????????????????? if(currentCodeCounty.equals(preCodeCounty)){
??????????????????????????? System.out.println(currentCode+currentArea);
?????????????????????? }else{
??????????????????????????? System.out.println("父級(jí)市"+singleCityCode+"——下一個(gè)縣區(qū)"+currentCode+currentArea);
??????????????????????????? countCounty++;
??????????????????????????? countySqlTxt+="INSERT
? INTO `area` VALUES ('"+currentCode+"',
? '"+singleCityCode+"', '"+currentArea+"', null, 'open', '2019-07-13
? 21:50:02', '2019-07-13 21:50:02', null);";
?????????????????????? }
?????????????????? }else{
?????????????????????? singleCityCode=currentCode;
?????????????????????? System.out.println("父級(jí)省"+singlePrivinceCode+"——下一個(gè)市"+currentCode+currentArea);
?????????????????????? countCity++;
?????????????????????? citySqlTxt+="INSERT
? INTO `area` VALUES ('"+currentCode+"',
? '"+singlePrivinceCode+"', '"+currentArea+"', null, 'open', '2019-07-13
? 21:50:02', '2019-07-13 21:50:02', null);";
?????????????????? }
????????????? }else{
?????????????????? singlePrivinceCode=currentCode;
?????????????????? System.out.println("下一個(gè)省"+currentCode+currentArea);
?????????????????? countPrivince++;
?????????????????? privinceSqlTxt+="INSERT
? INTO `area` VALUES ('"+currentCode+"',
? null, '"+currentArea+"', null, 'open', '2019-07-13
? 21:50:02', '2019-07-13 21:50:02', null);";
????????????? }
????????????? preCode=currentCode;
???????? }
???????? bufferedReader.close();
???????? System.out.println(countPrivince);
???????? System.out.println(countCity);
???????? System.out.println(countCounty);
???????? FilesqlFile=new File("D://sql.sql");//將sql語(yǔ)句保存為文本
???????? FileWriterfileWriter=new FileWriter(sqlFile);
???????? fileWriter.write(privinceSqlTxt+citySqlTxt+countySqlTxt);
???????? fileWriter.close();
???? }
}
[if !supportLists]G荐操、 [endif]附件
[if !supportLists]3、??[endif]2019年5月份實(shí)現(xiàn)結(jié)果(前臺(tái)實(shí)現(xiàn)完全是想怎么做就怎么做的事珍策,我們只要完成數(shù)據(jù)結(jié)構(gòu)化就okay)
[if !supportLists]4托启、??[endif]個(gè)人水平有限,文中如有錯(cuò)誤或不當(dāng)之處,請(qǐng)聯(lián)系本人修改或刪除攘宙,個(gè)人郵箱jaylinn@126.com,另外個(gè)人愛(ài)好技術(shù)屯耸,如有興趣可加QQ群377147577