@@ -133,50 +133,7 @@ var AutoCodeServiceApp = new(AutoCodeService)
133133// @return: map[string]string, error
134134
135135func (autoCodeService * AutoCodeService ) PreviewTemp (autoCode system.AutoCodeStruct ) (map [string ]string , error ) {
136- makeDictTypes (& autoCode )
137- for i := range autoCode .Fields {
138- if autoCode .Fields [i ].FieldType == "time.Time" {
139- autoCode .HasTimer = true
140- if autoCode .Fields [i ].FieldSearchType != "" {
141- autoCode .HasSearchTimer = true
142- }
143- }
144- if autoCode .Fields [i ].Sort {
145- autoCode .NeedSort = true
146- }
147- if autoCode .Fields [i ].FieldType == "picture" {
148- autoCode .HasPic = true
149- }
150- if autoCode .Fields [i ].FieldType == "video" {
151- autoCode .HasPic = true
152- }
153- if autoCode .Fields [i ].FieldType == "richtext" {
154- autoCode .HasRichText = true
155- }
156- if autoCode .Fields [i ].FieldType == "pictures" {
157- autoCode .HasPic = true
158- autoCode .NeedJSON = true
159- }
160- if autoCode .Fields [i ].FieldType == "file" {
161- autoCode .HasFile = true
162- autoCode .NeedJSON = true
163- }
164-
165- if autoCode .GvaModel {
166- autoCode .PrimaryField = & system.Field {
167- FieldName : "ID" ,
168- FieldType : "uint" ,
169- FieldDesc : "ID" ,
170- FieldJson : "ID" ,
171- DataTypeLong : "20" ,
172- Comment : "主键ID" ,
173- ColumnName : "id" ,
174- }
175- }
176- if ! autoCode .GvaModel && autoCode .PrimaryField == nil && autoCode .Fields [i ].PrimaryKey {
177- autoCode .PrimaryField = autoCode .Fields [i ]
178- }
179- }
136+ fmtField (& autoCode )
180137 dataList , _ , needMkdir , err := autoCodeService .getNeedList (& autoCode )
181138 if err != nil {
182139 return nil , err
@@ -255,49 +212,7 @@ func makeDictTypes(autoCode *system.AutoCodeStruct) {
255212// @return: err error
256213
257214func (autoCodeService * AutoCodeService ) CreateTemp (autoCode system.AutoCodeStruct , menuID uint , ids ... uint ) (err error ) {
258- makeDictTypes (& autoCode )
259- for i := range autoCode .Fields {
260- if autoCode .Fields [i ].FieldType == "time.Time" {
261- autoCode .HasTimer = true
262- if autoCode .Fields [i ].FieldSearchType != "" {
263- autoCode .HasSearchTimer = true
264- }
265- }
266- if autoCode .Fields [i ].Sort {
267- autoCode .NeedSort = true
268- }
269- if autoCode .Fields [i ].FieldType == "picture" {
270- autoCode .HasPic = true
271- }
272- if autoCode .Fields [i ].FieldType == "video" {
273- autoCode .HasPic = true
274- }
275- if autoCode .Fields [i ].FieldType == "richtext" {
276- autoCode .HasRichText = true
277- }
278- if autoCode .Fields [i ].FieldType == "pictures" {
279- autoCode .NeedJSON = true
280- autoCode .HasPic = true
281- }
282- if autoCode .Fields [i ].FieldType == "file" {
283- autoCode .NeedJSON = true
284- autoCode .HasFile = true
285- }
286- if autoCode .GvaModel {
287- autoCode .PrimaryField = & system.Field {
288- FieldName : "ID" ,
289- FieldType : "uint" ,
290- FieldDesc : "ID" ,
291- FieldJson : "ID" ,
292- DataTypeLong : "20" ,
293- Comment : "主键ID" ,
294- ColumnName : "id" ,
295- }
296- }
297- if ! autoCode .GvaModel && autoCode .PrimaryField == nil && autoCode .Fields [i ].PrimaryKey {
298- autoCode .PrimaryField = autoCode .Fields [i ]
299- }
300- }
215+ fmtField (& autoCode )
301216 // 增加判断: 重复创建struct
302217 if autoCode .AutoMoveFile && AutoCodeHistoryServiceApp .Repeat (autoCode .BusinessDB , autoCode .StructName , autoCode .Package ) {
303218 return RepeatErr
@@ -1030,3 +945,55 @@ func (autoCodeService *AutoCodeService) doZip(zipWriter *zip.Writer, serverPath,
1030945 })
1031946 return err
1032947}
948+
949+ func fmtField (autoCode * system.AutoCodeStruct ) {
950+ makeDictTypes (autoCode )
951+ for i := range autoCode .Fields {
952+
953+ if autoCode .Fields [i ].Front {
954+ autoCode .FrontFields = append (autoCode .FrontFields , autoCode .Fields [i ])
955+ }
956+
957+ if autoCode .Fields [i ].FieldType == "time.Time" {
958+ autoCode .HasTimer = true
959+ if autoCode .Fields [i ].FieldSearchType != "" {
960+ autoCode .HasSearchTimer = true
961+ }
962+ }
963+ if autoCode .Fields [i ].Sort {
964+ autoCode .NeedSort = true
965+ }
966+ if autoCode .Fields [i ].FieldType == "picture" {
967+ autoCode .HasPic = true
968+ }
969+ if autoCode .Fields [i ].FieldType == "video" {
970+ autoCode .HasPic = true
971+ }
972+ if autoCode .Fields [i ].FieldType == "richtext" {
973+ autoCode .HasRichText = true
974+ }
975+ if autoCode .Fields [i ].FieldType == "pictures" {
976+ autoCode .HasPic = true
977+ autoCode .NeedJSON = true
978+ }
979+ if autoCode .Fields [i ].FieldType == "file" {
980+ autoCode .HasFile = true
981+ autoCode .NeedJSON = true
982+ }
983+
984+ if autoCode .GvaModel {
985+ autoCode .PrimaryField = & system.Field {
986+ FieldName : "ID" ,
987+ FieldType : "uint" ,
988+ FieldDesc : "ID" ,
989+ FieldJson : "ID" ,
990+ DataTypeLong : "20" ,
991+ Comment : "主键ID" ,
992+ ColumnName : "id" ,
993+ }
994+ }
995+ if ! autoCode .GvaModel && autoCode .PrimaryField == nil && autoCode .Fields [i ].PrimaryKey {
996+ autoCode .PrimaryField = autoCode .Fields [i ]
997+ }
998+ }
999+ }
0 commit comments