|
|
@@ -6,6 +6,9 @@ import (
|
|
|
"encoding/json"
|
|
|
"encoding/xml"
|
|
|
"fmt"
|
|
|
+ "git.qianqiusoft.com/qianqiusoft/light-apiengine/env"
|
|
|
+ "git.qianqiusoft.com/qianqiusoft/light-apiengine/utils"
|
|
|
+ "git.qianqiusoft.com/qianqiusoft/light-apiengine-client/code_gen"
|
|
|
"io"
|
|
|
"io/ioutil"
|
|
|
"mime/multipart"
|
|
|
@@ -13,13 +16,11 @@ import (
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
"strings"
|
|
|
- "git.qianqiusoft.com/qianqiusoft/light-apiengine/env"
|
|
|
- "git.qianqiusoft.com/qianqiusoft/light-apiengine/utils"
|
|
|
)
|
|
|
|
|
|
type EngineClient struct {
|
|
|
ProjectName string
|
|
|
- ServerUrl string
|
|
|
+ ServerUrl string
|
|
|
}
|
|
|
|
|
|
type ResponeResult struct {
|
|
|
@@ -82,6 +83,10 @@ func (c *EngineClient) InitDefalutFile(project_name string) {
|
|
|
}
|
|
|
|
|
|
func (c *EngineClient) GenerateCurrentProject() {
|
|
|
+ c.GenerateCurrentProjectToPath("")
|
|
|
+}
|
|
|
+
|
|
|
+func (c *EngineClient) GenerateCurrentProjectToPath(destPath string) {
|
|
|
c.InitDefalutFile(c.ProjectName)
|
|
|
|
|
|
// 0---0
|
|
|
@@ -89,36 +94,55 @@ func (c *EngineClient) GenerateCurrentProject() {
|
|
|
//c.Generate(path + c.ProjectName + ".xml")
|
|
|
|
|
|
projMainXmlFileTemp := c.MergeXmlToSingle()
|
|
|
- if projMainXmlFileTemp == ""{
|
|
|
+ if projMainXmlFileTemp == "" {
|
|
|
fmt.Println("projMainXmlFileTemp is empty")
|
|
|
return
|
|
|
}
|
|
|
- c.Generate(projMainXmlFileTemp)
|
|
|
+
|
|
|
+ c.GenerateToPath(projMainXmlFileTemp, destPath)
|
|
|
+ c.GenSwagger(projMainXmlFileTemp)
|
|
|
|
|
|
path, _ := utils.GetCurrentPath()
|
|
|
- CopyDir(env.Get("GOPATH", "") + "/src/git.qianqiusoft.com/qianqiusoft/light-apiengine/sqlconfig",
|
|
|
+ CopyDir(env.Get("GOPATH", "")+"/src/git.qianqiusoft.com/qianqiusoft/light-apiengine/sqlconfig",
|
|
|
path+"sqlconfig")
|
|
|
}
|
|
|
|
|
|
-func (c *EngineClient) GenerateToPath(xmlfile string,dest_path string) {
|
|
|
+func (c *EngineClient) GenerateToPath(xmlfile string, dest_path string) {
|
|
|
var result ResponeResult
|
|
|
- server := "http://qianqiusoft.com:6166"
|
|
|
- if c.ServerUrl != "" {
|
|
|
- server = c.ServerUrl
|
|
|
+
|
|
|
+ isCompress := true
|
|
|
+
|
|
|
+ var bJson []byte
|
|
|
+
|
|
|
+ if c.ServerUrl == "local" {
|
|
|
+
|
|
|
+ isCompress = false
|
|
|
+ //dest_path+="../i2-erp-compare/"
|
|
|
+ bs := code_gen.DoGenerate(xmlfile, isCompress)
|
|
|
+ bJson = bs
|
|
|
+ } else {
|
|
|
+ server := "http://qianqiusoft.com:6166"
|
|
|
+ if c.ServerUrl != "" {
|
|
|
+ server = c.ServerUrl
|
|
|
+ }
|
|
|
+ server += "/api/v1/develop/generate"
|
|
|
+
|
|
|
+ bs := DoRequest(xmlfile, server)
|
|
|
+ bJson = bs.Bytes()
|
|
|
}
|
|
|
- server += "/api/v1/develop/generate"
|
|
|
|
|
|
- bs := DoRequest(xmlfile, server)
|
|
|
- if bs != nil {
|
|
|
- err := json.Unmarshal(bs.Bytes(), &result)
|
|
|
+ if bJson != nil {
|
|
|
+ err := json.Unmarshal(bJson, &result)
|
|
|
if err != nil {
|
|
|
fmt.Println(err.Error())
|
|
|
}
|
|
|
- for i := 0; i < len(result.Data); i++ {
|
|
|
- var b bytes.Buffer
|
|
|
- b.Write(result.Data[i].Content)
|
|
|
- unzip := unzipbytes(&b)
|
|
|
- result.Data[i].Content = unzip.Bytes()
|
|
|
+ if isCompress {
|
|
|
+ for i := 0; i < len(result.Data); i++ {
|
|
|
+ var b bytes.Buffer
|
|
|
+ b.Write(result.Data[i].Content)
|
|
|
+ unzip := unzipbytes(&b)
|
|
|
+ result.Data[i].Content = unzip.Bytes()
|
|
|
+ }
|
|
|
}
|
|
|
for i := 0; i < len(result.Data); i++ {
|
|
|
path := result.Data[i].Name
|
|
|
@@ -128,11 +152,13 @@ func (c *EngineClient) GenerateToPath(xmlfile string,dest_path string) {
|
|
|
fmt.Println(path)
|
|
|
|
|
|
ft := result.Data[i].Type
|
|
|
- if result.Data[i].Type == "main" {
|
|
|
+ if ft == "main" {
|
|
|
+ //fmt.Println(string(result.Data[i].Content))
|
|
|
} else if ft == "config" || ft == "ci" {
|
|
|
_, err := os.Stat(path)
|
|
|
if err == nil {
|
|
|
fmt.Println(path + "已经存在,忽略...")
|
|
|
+ // fmt.Println(result.Data[i].Content)
|
|
|
} else {
|
|
|
ioutil.WriteFile(path, result.Data[i].Content, os.ModePerm)
|
|
|
}
|
|
|
@@ -151,7 +177,7 @@ func (c *EngineClient) GenerateToPath(xmlfile string,dest_path string) {
|
|
|
} else if ft == "routers" {
|
|
|
os.MkdirAll(filepath.Dir(path), os.ModePerm)
|
|
|
ioutil.WriteFile(path, result.Data[i].Content, os.ModePerm)
|
|
|
- } else if ft =="sql"{
|
|
|
+ } else if ft == "sql" {
|
|
|
if strings.Index(path, "_gen.xml") > 0 {
|
|
|
os.MkdirAll(filepath.Dir(path), os.ModePerm)
|
|
|
ioutil.WriteFile(path, result.Data[i].Content, os.ModePerm)
|
|
|
@@ -164,7 +190,7 @@ func (c *EngineClient) GenerateToPath(xmlfile string,dest_path string) {
|
|
|
ioutil.WriteFile(path, result.Data[i].Content, os.ModePerm)
|
|
|
}
|
|
|
}
|
|
|
- } else{
|
|
|
+ } else {
|
|
|
os.MkdirAll(filepath.Dir(path), os.ModePerm)
|
|
|
err := ioutil.WriteFile(path, result.Data[i].Content, os.ModePerm)
|
|
|
if err != nil {
|
|
|
@@ -175,12 +201,14 @@ func (c *EngineClient) GenerateToPath(xmlfile string,dest_path string) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/*
|
|
|
func (c *EngineClient) Generate(xmlfile string) {
|
|
|
c.GenerateToPath(xmlfile, "")
|
|
|
c.GenSwagger(xmlfile)
|
|
|
}
|
|
|
+*/
|
|
|
|
|
|
-func (c *EngineClient) GenSwagger(xmlfile string){
|
|
|
+func (c *EngineClient) GenSwagger(xmlfile string) {
|
|
|
server := "http://swagger.pusher.i2erp.cn"
|
|
|
server += "/api/v1/upload"
|
|
|
|
|
|
@@ -192,14 +220,14 @@ func (c *EngineClient) GenSwagger(xmlfile string){
|
|
|
}
|
|
|
client := &http.Client{}
|
|
|
resp, err := client.Do(request)
|
|
|
- if err != nil{
|
|
|
+ if err != nil {
|
|
|
fmt.Println("===========================================================================>", err.Error())
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
defer resp.Body.Close()
|
|
|
bytess, err := ioutil.ReadAll(resp.Body)
|
|
|
- if err != nil{
|
|
|
+ if err != nil {
|
|
|
fmt.Println("=======================================>ioutil.ReadAll error", err.Error())
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
fmt.Println("=======================================>", string(bytess))
|
|
|
}
|
|
|
}
|
|
|
@@ -210,16 +238,17 @@ func (c *EngineClient) GenSwagger(xmlfile string){
|
|
|
* @param: none
|
|
|
* @return: the path of final xml
|
|
|
*/
|
|
|
-func (c *EngineClient)MergeXmlToSingle()string{
|
|
|
+func (c *EngineClient) MergeXmlToSingle() string {
|
|
|
path, _ := utils.GetCurrentPath()
|
|
|
// e.g.: c:/gopath/src/hanghua_background_proj
|
|
|
+ path = "D:\\dev\\Go\\go_path\\src\\i2-erp-backend\\"
|
|
|
projDir := fmt.Sprintf("%s%s.proj", path, c.ProjectName)
|
|
|
projMainXmlFile := projDir + "/" + c.ProjectName + ".xml"
|
|
|
projMainXmlFileTemp := projDir + "/" + c.ProjectName + "_temp.xml"
|
|
|
_, err := os.Stat(projMainXmlFileTemp)
|
|
|
if os.IsNotExist(err) {
|
|
|
fmt.Println("-------------------------->remove project main file temp")
|
|
|
- os.Remove(projMainXmlFileTemp) // remove
|
|
|
+ os.Remove(projMainXmlFileTemp) // remove
|
|
|
}
|
|
|
|
|
|
_, err = os.Stat(projMainXmlFile)
|
|
|
@@ -231,57 +260,57 @@ func (c *EngineClient)MergeXmlToSingle()string{
|
|
|
app := XmlApplication{}
|
|
|
bytess, _ := ioutil.ReadFile(projMainXmlFile)
|
|
|
err = xml.Unmarshal(bytess, &app)
|
|
|
- if err != nil{
|
|
|
+ if err != nil {
|
|
|
fmt.Println("xml.Unmarshal(bytess, &app) error " + err.Error())
|
|
|
return ""
|
|
|
}
|
|
|
|
|
|
controllers, err := scanControllers(projDir + "/controllers")
|
|
|
- if err != nil{
|
|
|
+ if err != nil {
|
|
|
fmt.Println("scanControllers error " + err.Error())
|
|
|
return ""
|
|
|
}
|
|
|
|
|
|
beans, err := scanBeans(projDir + "/beans")
|
|
|
- if err != nil{
|
|
|
+ if err != nil {
|
|
|
fmt.Println("scanBeans error " + err.Error())
|
|
|
return ""
|
|
|
}
|
|
|
|
|
|
tables, err := scanTables(projDir + "/tables")
|
|
|
- if err != nil{
|
|
|
+ if err != nil {
|
|
|
fmt.Println("scanTables error " + err.Error())
|
|
|
return ""
|
|
|
}
|
|
|
|
|
|
- if app.Controllers.ControllerList == nil{
|
|
|
+ if app.Controllers.ControllerList == nil {
|
|
|
app.Controllers.ControllerList = []XmlController{}
|
|
|
}
|
|
|
- for i := range controllers{
|
|
|
+ for i := range controllers {
|
|
|
app.Controllers.ControllerList = append(app.Controllers.ControllerList, controllers[i])
|
|
|
}
|
|
|
createVueApisFolder(app.Controllers.ControllerList)
|
|
|
|
|
|
- if app.Beans.BeanList == nil{
|
|
|
+ if app.Beans.BeanList == nil {
|
|
|
app.Beans.BeanList = []XmlBean{}
|
|
|
}
|
|
|
- for i := range beans{
|
|
|
+ for i := range beans {
|
|
|
app.Beans.BeanList = append(app.Beans.BeanList, beans[i])
|
|
|
}
|
|
|
- if app.Tables.TableList == nil{
|
|
|
+ if app.Tables.TableList == nil {
|
|
|
app.Tables.TableList = []XmlTable{}
|
|
|
}
|
|
|
- for i := range tables{
|
|
|
+ for i := range tables {
|
|
|
app.Tables.TableList = append(app.Tables.TableList, tables[i])
|
|
|
}
|
|
|
|
|
|
bytess, err = xml.Marshal(app)
|
|
|
- if err != nil{
|
|
|
+ if err != nil {
|
|
|
fmt.Println("xml.Marshal(app) error " + err.Error())
|
|
|
return ""
|
|
|
}
|
|
|
- err = ioutil.WriteFile(projMainXmlFileTemp, bytess,os.ModePerm)
|
|
|
- if err != nil{
|
|
|
+ err = ioutil.WriteFile(projMainXmlFileTemp, bytess, os.ModePerm)
|
|
|
+ if err != nil {
|
|
|
fmt.Println("ioutil.WriteFile(projMainXmlFileTemp, bytess,os.ModePerm) error " + err.Error())
|
|
|
return ""
|
|
|
}
|
|
|
@@ -289,14 +318,14 @@ func (c *EngineClient)MergeXmlToSingle()string{
|
|
|
if os.IsNotExist(err) {
|
|
|
fmt.Println("main xml file temp of " + c.ProjectName + " does not exist")
|
|
|
return ""
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
fmt.Println("main xml file temp of " + c.ProjectName + " exist")
|
|
|
}
|
|
|
|
|
|
return projMainXmlFileTemp
|
|
|
}
|
|
|
|
|
|
-func scanControllers(ctrldir string) ([]XmlController, error){
|
|
|
+func scanControllers(ctrldir string) ([]XmlController, error) {
|
|
|
_, err := os.Stat(ctrldir)
|
|
|
if os.IsNotExist(err) {
|
|
|
fmt.Println("controller dir does not exist", err.Error())
|
|
|
@@ -306,7 +335,7 @@ func scanControllers(ctrldir string) ([]XmlController, error){
|
|
|
controllers := []XmlController{}
|
|
|
filePaths := []string{}
|
|
|
filePaths, err = getAllFile(strings.TrimSuffix(ctrldir, "/"), filePaths)
|
|
|
- if err != nil{
|
|
|
+ if err != nil {
|
|
|
fmt.Println("controller getAllFile error", err.Error())
|
|
|
return nil, err
|
|
|
}
|
|
|
@@ -330,9 +359,9 @@ func scanControllers(ctrldir string) ([]XmlController, error){
|
|
|
}
|
|
|
|
|
|
// get sub dir name
|
|
|
- if arr[len(arr) - 2] != "controllers"{
|
|
|
+ if arr[len(arr)-2] != "controllers" {
|
|
|
// if sub dir is not controllers, set the dir attr
|
|
|
- ctrl.Dir = arr[len(arr) - 2]
|
|
|
+ ctrl.Dir = arr[len(arr)-2]
|
|
|
}
|
|
|
controllers = append(controllers, ctrl)
|
|
|
}
|
|
|
@@ -368,7 +397,7 @@ func scanControllers(ctrldir string) ([]XmlController, error){
|
|
|
//return controllers, err
|
|
|
}
|
|
|
|
|
|
-func scanBeans(ctrldir string) ([]XmlBean, error){
|
|
|
+func scanBeans(ctrldir string) ([]XmlBean, error) {
|
|
|
_, err := os.Stat(ctrldir)
|
|
|
if os.IsNotExist(err) {
|
|
|
fmt.Println("controller dir does not exist")
|
|
|
@@ -378,7 +407,7 @@ func scanBeans(ctrldir string) ([]XmlBean, error){
|
|
|
beans := []XmlBean{}
|
|
|
filePaths := []string{}
|
|
|
filePaths, err = getAllFile(strings.TrimSuffix(ctrldir, "/"), filePaths)
|
|
|
- if err != nil{
|
|
|
+ if err != nil {
|
|
|
fmt.Println("controller getAllFile error", err.Error())
|
|
|
return nil, err
|
|
|
}
|
|
|
@@ -430,7 +459,7 @@ func scanBeans(ctrldir string) ([]XmlBean, error){
|
|
|
//return beans, err
|
|
|
}
|
|
|
|
|
|
-func scanTables(ctrldir string) ([]XmlTable, error){
|
|
|
+func scanTables(ctrldir string) ([]XmlTable, error) {
|
|
|
_, err := os.Stat(ctrldir)
|
|
|
if os.IsNotExist(err) {
|
|
|
fmt.Println("controller dir does not exist")
|
|
|
@@ -440,7 +469,7 @@ func scanTables(ctrldir string) ([]XmlTable, error){
|
|
|
tables := []XmlTable{}
|
|
|
filePaths := []string{}
|
|
|
filePaths, err = getAllFile(strings.TrimSuffix(ctrldir, "/"), filePaths)
|
|
|
- if err != nil{
|
|
|
+ if err != nil {
|
|
|
fmt.Println("controller getAllFile error", err.Error())
|
|
|
return nil, err
|
|
|
}
|
|
|
@@ -492,10 +521,10 @@ func scanTables(ctrldir string) ([]XmlTable, error){
|
|
|
//return tables, err
|
|
|
}
|
|
|
|
|
|
-func createVueApisFolder(controllers []XmlController){
|
|
|
- for i := range controllers{
|
|
|
+func createVueApisFolder(controllers []XmlController) {
|
|
|
+ for i := range controllers {
|
|
|
fmt.Println("------------------------------>" + controllers[i].Name)
|
|
|
- os.MkdirAll("vue/api/modules/" + controllers[i].Name, os.ModePerm)
|
|
|
+ os.MkdirAll("vue/api/modules/"+controllers[i].Name, os.ModePerm)
|
|
|
}
|
|
|
}
|
|
|
|