Created
April 30, 2014 07:39
-
-
Save yanhua365/315f1c03aa0651d3240b to your computer and use it in GitHub Desktop.
处理sql文本,用最后一个数字排序生成sql的groovy脚本。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'4','绘画',NULL,'7','4'); | |
'3','音乐',NULL,'7','3'); | |
'9','其他',NULL,'7','9'); | |
'1','唱歌',NULL,'7','1'); | |
'8','书法',NULL,'7','8'); | |
'5','篮球',NULL,'7','5'); | |
'6','排球',NULL,'7','6'); | |
'2','电脑',NULL,'7','2'); | |
'7','摄影',NULL,'7','7'); | |
'1','一般',NULL,'8','1'); | |
'3','精通',NULL,'8','3'); | |
'2','熟练',NULL,'8','2'); | |
'1','未婚',NULL,'1','1'); | |
'2','已婚',NULL,'1','2'); | |
'3','丧偶',NULL,'1','3'); | |
'4','离婚',NULL,'1','4'); | |
'5','其他',NULL,'1','5'); | |
'1','小学',NULL,'2','1'); | |
'2','初中',NULL,'2','2'); | |
'3','高中',NULL,'2','3'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Line{ | |
int seq | |
String line | |
} | |
def fi = new File("./data.sql") | |
def fo = new File("./out.sql") | |
def lines = [] | |
fi.each{ln -> | |
def seq = ln.substring(ln.lastIndexOf(",")+2,ln.lastIndexOf("'")) | |
lines << new Line(seq:Integer.valueOf(seq),line:ln) | |
} | |
lines.sort { a, b-> | |
a.seq.compareTo(b.seq) | |
} | |
def i = 0; | |
lines.each{ | |
fo << "insert into hr_dic_item (`id`, `dicKey`, `dicValue`, `parentId`, `dicId`, `sequence`) values(${++i} ${it.line}\n\n" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment