Commit fa0b832b by xxlv

Add auto gen dto

parent 3cb36c43
......@@ -2,13 +2,9 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="1abc04e8-e167-42cd-98ea-074bbb2150ed" name="Default" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gen.py" beforeDir="false" afterPath="$PROJECT_DIR$/gen.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/template/${PLACE}.java" beforeDir="false" afterPath="$PROJECT_DIR$/template/${PLACE}.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/template/${PLACE}BizImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/template/${PLACE}BizImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/template/${PLACE}Facade.java" beforeDir="false" afterPath="$PROJECT_DIR$/template/${PLACE}Facade.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/template/${PLACE}FacadeImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/template/${PLACE}FacadeImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/template/${PLACE}Mapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/template/${PLACE}Mapper.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/template/${PLACE}ReqDto.java" beforeDir="false" afterPath="$PROJECT_DIR$/template/${PLACE}ReqDto.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/template/${PLACE}RespDto.java" beforeDir="false" afterPath="$PROJECT_DIR$/template/${PLACE}RespDto.java" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
......@@ -22,11 +18,11 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="gen.py" pinned="false" current-in-tab="false">
<file leaf-file-name="gen.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/gen.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-367">
<caret line="265" column="45" lean-forward="true" selection-start-line="265" selection-start-column="45" selection-end-line="265" selection-end-column="45" />
<state relative-caret-position="521">
<caret line="426" selection-start-line="426" selection-end-line="426" />
<folding>
<element signature="e#42#51#0" expanded="true" />
</folding>
......@@ -34,20 +30,29 @@
</provider>
</entry>
</file>
<file leaf-file-name="${PLACE}FacadeImpl.java" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/template/${PLACE}FacadeImpl.java">
<file leaf-file-name="AbnormalOrder.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tmp/AbnormalOrder.java">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret column="28" selection-start-column="28" selection-end-column="28" />
<state relative-caret-position="-1479">
<caret line="4" column="28" selection-start-line="4" selection-start-column="28" selection-end-line="4" selection-end-column="28" />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="${PLACE}Mapper.xml" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/template/${PLACE}Mapper.xml">
<file leaf-file-name="${PLACE}ReqDto.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/template/${PLACE}ReqDto.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="30">
<caret line="2" column="57" selection-start-line="2" selection-start-column="43" selection-end-line="2" selection-end-column="57" />
<state relative-caret-position="60">
<caret line="4" selection-start-line="4" selection-end-line="4" />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="${PLACE}RespDto.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/template/${PLACE}RespDto.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="60">
<caret line="4" column="30" selection-start-line="4" selection-start-column="30" selection-end-line="4" selection-end-column="30" />
</state>
</provider>
</entry>
......@@ -58,15 +63,15 @@
<findStrings>
<find>systemlogZt</find>
<find>{}/dat</find>
<find>clean_tmp</find>
<find>compile_table</find>
<find>config_mybatis</find>
<find>PLACE</find>
<find>po</find>
<find>gen_po</find>
<find>is_po</find>
<find>table</find>
<find>get_rs</find>
<find>clean_tmp</find>
<find>is_po</find>
</findStrings>
<replaceStrings>
<replace>${PLACE}</replace>
......@@ -84,15 +89,16 @@
<option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/template/${PLACE}Biz.java" />
<option value="$PROJECT_DIR$/template/${PLACE}Mapper.java" />
<option value="$PROJECT_DIR$/template/${PLACE}ReqDto.java" />
<option value="$PROJECT_DIR$/template/${PLACE}RespDto.java" />
<option value="$PROJECT_DIR$/template/${PLACE}Facade.java" />
<option value="$PROJECT_DIR$/template/${PLACE}.java" />
<option value="$PROJECT_DIR$/template/${PLACE}BizImpl.java" />
<option value="$PROJECT_DIR$/template/${PLACE}Mapper.xml" />
<option value="$PROJECT_DIR$/tmp/generatorConfig.xml" />
<option value="$PROJECT_DIR$/gen.py" />
<option value="$PROJECT_DIR$/template/${PLACE}FacadeImpl.java" />
<option value="$PROJECT_DIR$/tmp/AbnormalOrderReqDto.java" />
<option value="$PROJECT_DIR$/template/${PLACE}ReqDto.java" />
<option value="$PROJECT_DIR$/template/${PLACE}RespDto.java" />
<option value="$PROJECT_DIR$/gen.py" />
</list>
</option>
</component>
......@@ -131,6 +137,11 @@
<item name="quick_generator" type="462c0819:PsiDirectoryNode" />
<item name="template" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="quick_generator" type="b2602c69:ProjectViewProjectNode" />
<item name="quick_generator" type="462c0819:PsiDirectoryNode" />
<item name="tmp" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
......@@ -251,8 +262,8 @@
<window_info anchor="bottom" id="Version Control" order="7" />
<window_info anchor="bottom" id="Python Console" order="9" />
<window_info anchor="bottom" id="Run" order="2" />
<window_info anchor="bottom" id="Terminal" order="7" visible="true" weight="0.329718" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.25235197" />
<window_info active="true" anchor="bottom" id="Terminal" order="7" visible="true" weight="0.329718" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25235197" />
<window_info anchor="bottom" id="Docker" order="9" show_stripe_button="false" />
<window_info anchor="right" id="Database" order="3" />
<window_info anchor="right" id="SciView" order="5" />
......@@ -282,23 +293,24 @@
<window_info id="Designer" order="2" />
<window_info anchor="right" id="Palette" order="3" />
<window_info anchor="bottom" id="Python Console" order="12" />
<window_info id="Image Layers" order="3" />
<window_info anchor="bottom" id="Run" order="2" />
<window_info id="Image Layers" order="3" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info id="Capture Tool" order="4" />
<window_info id="UI Designer" order="5" />
<window_info id="Favorites" order="6" side_tool="true" />
<window_info anchor="bottom" id="Terminal" order="8" visible="true" weight="0.329718" />
<window_info active="true" anchor="bottom" id="Terminal" order="8" visible="true" weight="0.329718" />
<window_info anchor="bottom" id="Docker" order="13" show_stripe_button="false" />
<window_info anchor="right" id="Capture Analysis" order="4" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="bottom" id="Event Log" order="9" side_tool="true" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
<window_info anchor="bottom" id="Database Changes" order="10" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="11" />
<window_info anchor="right" id="Maven Projects" order="5" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.25235197" />
<window_info anchor="bottom" id="Find" order="1" weight="0.329718" />
<window_info content_ui="combo" id="Project" order="0" weight="0.25235197" />
<window_info anchor="right" id="SciView" order="9" />
<window_info anchor="right" id="Database" order="6" />
<window_info anchor="bottom" id="Message" order="0" />
......@@ -307,7 +319,6 @@
<window_info anchor="right" id="Theme Preview" order="8" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="Find" order="1" weight="0.329718" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
</layout-to-restore>
</component>
......@@ -318,20 +329,6 @@
<option name="myLimit" value="2678400000" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/template/${PLACE}Facade.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="15">
<caret line="1" selection-start-line="1" selection-end-line="1" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/template/${PLACE}FacadeImpl.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="285">
<caret line="19" column="86" selection-start-line="19" selection-start-column="86" selection-end-line="19" selection-end-column="86" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/gen.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="150">
......@@ -481,23 +478,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/template/${PLACE}ReqDto.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="105">
<caret line="7" lean-forward="true" selection-start-line="7" selection-end-line="7" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/template/${PLACE}RespDto.java">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret column="46" selection-start-column="46" selection-end-column="46" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/template/${PLACE}.java">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/template/${PLACE}BizImpl.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="270">
......@@ -505,13 +485,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/template/${PLACE}Facade.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="60">
<caret line="4" column="45" selection-start-line="4" selection-start-column="31" selection-end-line="4" selection-end-column="45" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/template/${PLACE}Mapper.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="105">
......@@ -519,9 +492,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tmp/AbnormalOrder.java">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/tmp/AbnormalOrderFacadeImpl.java">
<provider selected="true" editor-type-id="text-editor" />
</entry>
......@@ -546,16 +516,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/gen.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-367">
<caret line="265" column="45" lean-forward="true" selection-start-line="265" selection-start-column="45" selection-end-line="265" selection-end-column="45" />
<folding>
<element signature="e#42#51#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/template/${PLACE}Mapper.xml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="30">
......@@ -565,8 +525,61 @@
</entry>
<entry file="file://$PROJECT_DIR$/template/${PLACE}FacadeImpl.java">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret column="28" selection-start-column="28" selection-end-column="28" />
<state relative-caret-position="60">
<caret line="4" column="44" lean-forward="true" selection-start-line="4" selection-start-column="44" selection-end-line="4" selection-end-column="44" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/template/${PLACE}Facade.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="150">
<caret line="10" column="1" lean-forward="true" selection-start-line="10" selection-start-column="1" selection-end-line="10" selection-end-column="1" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/template/${PLACE}.java">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/tmp/java/com/ydl/user/intf/po/DoctorModify.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-45" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tmp/AbnormalOrderReqDto.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="120">
<caret line="8" column="4" selection-start-line="8" selection-start-column="4" selection-end-line="8" selection-end-column="9" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/template/${PLACE}ReqDto.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="60">
<caret line="4" selection-start-line="4" selection-end-line="4" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/template/${PLACE}RespDto.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="60">
<caret line="4" column="30" selection-start-line="4" selection-start-column="30" selection-end-line="4" selection-end-column="30" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tmp/AbnormalOrder.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1479">
<caret line="4" column="28" selection-start-line="4" selection-start-column="28" selection-end-line="4" selection-end-column="28" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/gen.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="521">
<caret line="426" selection-start-line="426" selection-end-line="426" />
<folding>
<element signature="e#42#51#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
......
......@@ -11,7 +11,7 @@ DIR = "./template"
TMP = "./tmp"
JAR_PATH = "./jar"
MYBATIS_GEN_JAVA_PATH = "{}/java".format(TMP)
PO=""
def parse_ydl_project(path):
"""
......@@ -122,6 +122,10 @@ def safe_cpfile(f, target_path_map, res_name):
print("move 当前的文件{} 到 {}".format(f, target_path))
def is_dto(path):
return path[-8:]=="Dto.java"
def is_po(res_name, identity):
"""
检测是否是po
......@@ -130,7 +134,7 @@ def is_po(res_name, identity):
:param identity:
:return:
"""
res_name=res_name[0].upper()+res_name[1:]
res_name = res_name[0].upper() + res_name[1:]
print("检测po {} {}".format(res_name, identity.split("/")[-1]))
......@@ -163,15 +167,13 @@ def config_mybatis(res_name, table_name, mybatis_config_path):
classPathEntry = ET.Element("classPathEntry", location="{}/mysql-connector-java-5.1.25.jar".format(JAR_PATH))
context = root.find("context")
root.getroot().insert(0,classPathEntry)
root.getroot().insert(0, classPathEntry)
context.append(e)
po_path = context.find("javaModelGenerator").get("targetPackage")
java_model_generator = context.find("javaModelGenerator")
java_model_generator.set("targetProject", "{}/java/".format(TMP))
tmp_mybatis_path = os.path.join(TMP, "generatorConfig.xml")
root.write(tmp_mybatis_path, encoding="utf-8")
......@@ -217,15 +219,17 @@ def gen_po(res_name, project_target_path):
print("----------------------------------------")
os.system(gen_po_cmd)
mybatis_gen_po_path="{}/{}.java".format(po_path, res_name)
mybatis_gen_po_path = "{}/{}.java".format(po_path, res_name)
if(not os.path.exists(mybatis_gen_po_path)):
if (not os.path.exists(mybatis_gen_po_path)):
print("无法获取到Mybatis 生成的po文件")
exit(-1)
with open(mybatis_gen_po_path, "r+") as f:
po = f.read()
return po
......@@ -240,8 +244,10 @@ def compile_content(res_name, compile_table, origin, tmp, project_target_path):
:param project_target_path:
:return:
"""
global PO
res_name=get_res_name(res_name)
res_name = get_res_name(res_name)
if not os.path.isdir(tmp):
os.mkdir(tmp)
......@@ -259,7 +265,9 @@ def compile_content(res_name, compile_table, origin, tmp, project_target_path):
print("发现po {}".format(identity))
with open(identity, "w+") as f:
f.write(gen_po(res_name, project_target_path))
po_body = gen_po(res_name, project_target_path)
PO=po_body
f.write(po_body)
print("--------------------------------")
print("成功编译文件 {} [{}]".format(identity, len(body)))
......@@ -298,10 +306,10 @@ def clean_tmp():
def get_res_name(res_name):
name = underline2hump(res_name)
name= underline2hump(res_name)
return name[0].upper() + name[1:]
return name[0].upper()+name[1:]
def hump2underline(hunp_str):
'''
......@@ -315,6 +323,7 @@ def hump2underline(hunp_str):
sub = re.sub(p, r'\1_\2', hunp_str).lower()
return sub
def underline2hump(underline_str):
'''
下划线形式字符串转成驼峰形式
......@@ -322,26 +331,17 @@ def underline2hump(underline_str):
:return: 驼峰形式字符串
'''
# 这里re.sub()函数第二个替换参数用到了一个匿名回调函数,回调函数的参数x为一个匹配对象,返回值为一个处理后的字符串
sub = re.sub(r'(_\w)',lambda x:x.group(1)[1].upper(),underline_str)
sub = re.sub(r'(_\w)', lambda x: x.group(1)[1].upper(), underline_str)
return sub
def get_table_name(res_name):
def get_table_name(res_name):
return hump2underline(res_name)
#
# table_name = ""
# res_name = res_name[0:1].lower() + res_name[1:]
#
# for i in range(0, len(res_name)):
# t = res_name[i]
# if (t.isupper()):
# t = "".join(["_", t.lower()])
# table_name = "".join([table_name, t])
#
# return table_name
def gen(res_name, look_path):
global PO
"""
核心逻辑
......@@ -398,20 +398,52 @@ def gen(res_name, look_path):
print("编译常量表")
print("--------------------------------------")
# 编译文件
compiled_file_list = []
for root, dirs, files in os.walk(DIR, False):
for file in files:
if (file[0] == "$"):
compiled_file = compile_content(res_name, compile_table, os.path.join(root, file), TMP,
PROJECT_TARGET_PATH)
safe_cpfile(compiled_file, PROJECT_TARGET_PATH, res_name)
compiled_file_list.append(compiled_file)
# safe_cpfile(compiled_file, PROJECT_TARGET_PATH, res_name)
# 考虑生成dto
# PO="""
# Cats are {smarter} than dogs
#
# """
matchObj = re.match("[\s\S]+class (\w+) {([\s\S]+)}(.*?)[\s\S]+", PO)
if(matchObj is not None):
PO=matchObj.group(2)
print(PO)
if PO[-1]!="}":
PO+="\n }"
po_body=PO
for compiled_file in compiled_file_list:
if is_dto(compiled_file):
with open(compiled_file,"r+") as f:
dto_body=f.read()
dto_body=dto_body.replace("${PO}",po_body)
with open(compiled_file,"w+") as f:
f.write(dto_body)
safe_cpfile(compiled_file, PROJECT_TARGET_PATH, res_name)
# clean_tmp()
print("---------------------------------------------")
print("你已经成功的生成了代码")
print("---------------------------------------------")
if __name__ == "__main__":
print("-------------------------")
print("Start Building your Resource")
print("Draw by ghost ")
......
package com.${PACKAGE_LEVEL1}.${PACKAGE_LEVEL2}.intf.dto.request;
import java.io.Serializable;
import java.util.Date;
public class ${PLACE}ReqDto implements Serializable {
//...
${PO}
}
package com.${PACKAGE_LEVEL1}.${PACKAGE_LEVEL2}.intf.dto.response;
public class ${PLACE}RespDto {
import java.util.Date;
public class ${PLACE}RespDto {
${PO}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment