Commit fa0b832b by xxlv

Add auto gen dto

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