完成AllModels序列化
This commit is contained in:
		
							parent
							
								
									389f12b8c5
								
							
						
					
					
						commit
						7fe53f749e
					
				| @ -2,3 +2,5 @@ | |||||||
| name=${1%\/} | name=${1%\/} | ||||||
| echo $name | echo $name | ||||||
| goctl api go -api server_api/$name.api -dir server/$name --home ./goctl_template/ | goctl api go -api server_api/$name.api -dir server/$name --home ./goctl_template/ | ||||||
|  | # ctxName=server/$name/internal/svc/servicecontext.go | ||||||
|  | # gofmt -w $ctxName | ||||||
| @ -1,16 +1,24 @@ | |||||||
| package main | package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"log" | ||||||
|  | 	"regexp" | ||||||
| 	"testing" | 	"testing" | ||||||
| 
 | 
 | ||||||
| 	_ "github.com/go-sql-driver/mysql" | 	_ "github.com/go-sql-driver/mysql" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func TestXMain(t *testing.T) { | func TestXMain(t *testing.T) { | ||||||
| 	testGenDir = "../" + testGenDir | 	a := "	FsAddress                 *FsAddressModel                 // fs_address 用户地址表" | ||||||
| 	GenAllModels(testGenDir, TableNameComment{ | 	re := regexp.MustCompile(`([A-Za-z0-9_]+) [^/]+ // ([^ ]+) (.+)$`) | ||||||
| 		Name:    "FsFont", | 	for _, line := range re.FindStringSubmatch(a) { | ||||||
| 		Comment: "测试", | 		log.Println(line) | ||||||
| 	}) | 	} | ||||||
|  | 	log.Println(re.FindStringSubmatch(a)) | ||||||
|  | 	// testGenDir = "../" + testGenDir | ||||||
|  | 	// GenAllModels(testGenDir, TableNameComment{ | ||||||
|  | 	// 	Name:    "FsFont", | ||||||
|  | 	// 	Comment: "测试", | ||||||
|  | 	// }) | ||||||
| 	// Now you can use the generated GORM model to interact with the database | 	// Now you can use the generated GORM model to interact with the database | ||||||
| } | } | ||||||
|  | |||||||
| @ -8,6 +8,7 @@ import ( | |||||||
| 	"os" | 	"os" | ||||||
| 	"os/exec" | 	"os/exec" | ||||||
| 	"regexp" | 	"regexp" | ||||||
|  | 	"sort" | ||||||
| 	"strconv" | 	"strconv" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
| @ -70,6 +71,7 @@ package gmodel | |||||||
| 
 | 
 | ||||||
| import "gorm.io/gorm" | import "gorm.io/gorm" | ||||||
| 
 | 
 | ||||||
|  | // AllModelsGen 所有Model集合,修改单行,只要不改字段名,不会根据新的内容修改,需要修改的话手动删除 | ||||||
| type AllModelsGen struct { | type AllModelsGen struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -85,6 +87,7 @@ package gmodel | |||||||
| 
 | 
 | ||||||
| import "gorm.io/gorm" | import "gorm.io/gorm" | ||||||
| 
 | 
 | ||||||
|  | // AllModelsGen 所有Model集合,修改单行,只要不改字段名,不会根据新的内容修改,需要修改的话手动删除 | ||||||
| type AllModelsGen struct { | type AllModelsGen struct { | ||||||
| 	 %s | 	 %s | ||||||
| } | } | ||||||
| @ -103,34 +106,71 @@ type TableNameComment struct { | |||||||
| 	Comment string | 	Comment string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | type TMCS []TableNameComment | ||||||
|  | 
 | ||||||
|  | func (u TMCS) Len() int { | ||||||
|  | 	return len(u) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (u TMCS) Less(i, j int) bool { | ||||||
|  | 	return u[i].Name < u[j].Name | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (u TMCS) Swap(i, j int) { | ||||||
|  | 	u[i], u[j] = u[j], u[i] | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func GenAllModels(filedir string, tmcs ...TableNameComment) { | func GenAllModels(filedir string, tmcs ...TableNameComment) { | ||||||
| 	fileName := filedir + "/var_gen.go" | 	fileName := filedir + "/var_gen.go" | ||||||
|  | 	var dupMap map[string]TableNameComment = make(map[string]TableNameComment) | ||||||
|  | 	for _, tmc := range tmcs { | ||||||
|  | 		dupMap[tmc.Name] = tmc | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	if _, err := os.Stat(fileName); err == nil { | 	if _, err := os.Stat(fileName); err == nil { | ||||||
|  | 		log.Printf("%s exists!", fileName) | ||||||
| 		data, err := os.ReadFile(fileName) | 		data, err := os.ReadFile(fileName) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			panic(err) | 			panic(err) | ||||||
| 		} | 		} | ||||||
| 		filestr := string(data) | 		filestr := string(data) | ||||||
| 		filelines := strings.Split(filestr, "\n") | 		filelines := strings.Split(filestr, "\n") | ||||||
| 		re := regexp.MustCompile(` +([^:]+)[^/]+ // ([^ ]+) (.?)$`) | 		re := regexp.MustCompile(`([A-Za-z0-9_]+) [^/]+ // ([^ ]+) (.+)$`) | ||||||
| 		for _, line := range filelines { | 		for _, line := range filelines { | ||||||
| 			result := re.FindStringSubmatch(line) | 			result := re.FindStringSubmatch(line) | ||||||
| 			if len(result) > 0 { | 			if len(result) > 0 { | ||||||
| 				// key := result[0] | 				// key := result[0] | ||||||
|  | 				if len(result) != 4 { | ||||||
|  | 					log.Println(result) | ||||||
|  | 				} | ||||||
| 				log.Println(result) | 				log.Println(result) | ||||||
| 				tmcs = append(tmcs, TableNameComment{ |  | ||||||
| 					Name:    result[1], |  | ||||||
| 					GoName:  result[0], |  | ||||||
| 					Comment: result[2], |  | ||||||
| 				}) |  | ||||||
| 
 | 
 | ||||||
|  | 				tmc := TableNameComment{ | ||||||
|  | 					Name:    result[2], | ||||||
|  | 					GoName:  result[1], | ||||||
|  | 					Comment: result[3], | ||||||
|  | 				} | ||||||
|  | 
 | ||||||
|  | 				if newTmc, ok := dupMap[tmc.Name]; ok { | ||||||
|  | 					log.Printf("not change: (old)%v -> (new)%v", tmc, newTmc) | ||||||
|  | 				} | ||||||
|  | 
 | ||||||
|  | 				dupMap[tmc.Name] = tmc | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		tmcs = nil | ||||||
|  | 
 | ||||||
|  | 		for _, tmc := range dupMap { | ||||||
|  | 			tmcs = append(tmcs, tmc) | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		sort.Sort(TMCS(tmcs)) | ||||||
|  | 
 | ||||||
| 		structStr := "" | 		structStr := "" | ||||||
| 		newModelsStr := "" | 		newModelsStr := "" | ||||||
| 		for _, tmc := range tmcs { | 		for _, tmc := range tmcs { | ||||||
| 			fsline := fmt.Sprintf("%s %sModel // %s %s\n", tmc.GoName, tmc.GoName, tmc.Name, tmc.Comment) | 			fsline := fmt.Sprintf("%s *%sModel // %s %s\n", tmc.GoName, tmc.GoName, tmc.Name, tmc.Comment) | ||||||
| 			structStr += fsline | 			structStr += fsline | ||||||
| 			nmline := fmt.Sprintf("%s: New%sModel(gdb),\n", tmc.GoName, tmc.GoName) | 			nmline := fmt.Sprintf("%s: New%sModel(gdb),\n", tmc.GoName, tmc.GoName) | ||||||
| 			newModelsStr += nmline | 			newModelsStr += nmline | ||||||
|  | |||||||
| @ -1,6 +1,7 @@ | |||||||
| package main | package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"os" | ||||||
| 	"testing" | 	"testing" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| @ -8,6 +9,6 @@ func TestMain(t *testing.T) { | |||||||
| 	// args := []string{"-name", "fs_guest"} | 	// args := []string{"-name", "fs_guest"} | ||||||
| 
 | 
 | ||||||
| 	testGenDir = "../" + testGenDir | 	testGenDir = "../" + testGenDir | ||||||
| 	// os.Args = []string{"cmd", "-name=fs_guest"} | 	os.Args = []string{"cmd", "-name=-"} | ||||||
| 	main() | 	main() | ||||||
| } | } | ||||||
|  | |||||||
| @ -2,17 +2,22 @@ package svc | |||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	{{.configImport}} | 	{{.configImport}} | ||||||
|  | 	"errors" | ||||||
|  | 	"fmt" | ||||||
|  | 	"net/http" | ||||||
|  | 	 | ||||||
| 	"fusenapi/initalize" | 	"fusenapi/initalize" | ||||||
|  | 	"fusenapi/model/gmodel" | ||||||
|  | 	 | ||||||
| 	"gorm.io/gorm" | 	"gorm.io/gorm" | ||||||
| 	"github.com/golang-jwt/jwt" | 	"github.com/golang-jwt/jwt" | ||||||
| 	"net/http" |  | ||||||
| 	"errors" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type ServiceContext struct { | type ServiceContext struct { | ||||||
| 	Config {{.config}} | 	Config {{.config}} | ||||||
| 	{{.middleware}} | 	{{.middleware}} | ||||||
| 	MysqlConn *gorm.DB | 	MysqlConn *gorm.DB | ||||||
|  | 	AllModels *gmodel.AllModelsGen | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewServiceContext(c {{.config}}) *ServiceContext { | func NewServiceContext(c {{.config}}) *ServiceContext { | ||||||
| @ -20,6 +25,7 @@ func NewServiceContext(c {{.config}}) *ServiceContext { | |||||||
| 	return &ServiceContext{ | 	return &ServiceContext{ | ||||||
| 		Config: c, | 		Config: c, | ||||||
| 		MysqlConn: initalize.InitMysql(c.SourceMysql), | 		MysqlConn: initalize.InitMysql(c.SourceMysql), | ||||||
|  | 		AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)), | ||||||
| 		{{.middlewareAssignment}} | 		{{.middlewareAssignment}} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ import ( | |||||||
| // fs_product_model3d 产品模型表 | // fs_product_model3d 产品模型表 | ||||||
| type FsProductModel3d struct { | type FsProductModel3d struct { | ||||||
| 	Id             int64   `gorm:"primary_key;default:0;auto_increment;" json:"id"` // | 	Id             int64   `gorm:"primary_key;default:0;auto_increment;" json:"id"` // | ||||||
| 	ProductId      *int64  `gorm:"index;default:0;" json:"product_id"`              // | 	ProductId      *int64  `gorm:"index;default:0;" json:"product_id"`              // 产品ID | ||||||
| 	Tag            *int64  `gorm:"default:1;" json:"tag"`                           // 类别(1:模型,2:配件,3:场景) | 	Tag            *int64  `gorm:"default:1;" json:"tag"`                           // 类别(1:模型,2:配件,3:场景) | ||||||
| 	Title          *string `gorm:"default:'';" json:"title"`                        // 标题 | 	Title          *string `gorm:"default:'';" json:"title"`                        // 标题 | ||||||
| 	Name           *string `gorm:"default:'';" json:"name"`                         // 详情页展示名称 | 	Name           *string `gorm:"default:'';" json:"name"`                         // 详情页展示名称 | ||||||
| @ -15,13 +15,13 @@ type FsProductModel3d struct { | |||||||
| 	MaterialId     *int64  `gorm:"default:0;" json:"material_id"`                   // 材质ID | 	MaterialId     *int64  `gorm:"default:0;" json:"material_id"`                   // 材质ID | ||||||
| 	SizeId         *int64  `gorm:"default:0;" json:"size_id"`                       // 尺寸ID | 	SizeId         *int64  `gorm:"default:0;" json:"size_id"`                       // 尺寸ID | ||||||
| 	Sort           *int64  `gorm:"default:0;" json:"sort"`                          // 排序 | 	Sort           *int64  `gorm:"default:0;" json:"sort"`                          // 排序 | ||||||
| 	Light          *int64  `gorm:"default:0;" json:"light"`                         // | 	Light          *int64  `gorm:"default:0;" json:"light"`                         // 灯光组 | ||||||
| 	LightList      *string `gorm:"default:'';" json:"light_list"`                   // | 	LightList      *string `gorm:"default:'';" json:"light_list"`                   // 灯光备选项 | ||||||
| 	PartId         *int64  `gorm:"default:0;" json:"part_id"`                       // | 	PartId         *int64  `gorm:"default:0;" json:"part_id"`                       // 配件选项id(配件就是模型的id) | ||||||
| 	PartList       *string `gorm:"default:'';" json:"part_list"`                    // | 	PartList       *string `gorm:"default:'';" json:"part_list"`                    // 配件备选项 | ||||||
| 	Status         *int64  `gorm:"default:0;" json:"status"`                        // 状态位 显示 删除 | 	Status         *int64  `gorm:"default:0;" json:"status"`                        // 状态位 显示 删除 | ||||||
| 	Ctime          *int64  `gorm:"default:0;" json:"ctime"`                         // 添加时间 | 	Ctime          *int64  `gorm:"default:0;" json:"ctime"`                         // 添加时间 | ||||||
| 	OptionTemplate *int64  `gorm:"default:0;" json:"option_template"`               // | 	OptionTemplate *int64  `gorm:"default:0;" json:"option_template"`               // 配件绑定的公共模板 | ||||||
| 	Price          *int64  `gorm:"default:0;" json:"price"`                         // 仅配件用,配件的价格, 单位:美分 | 	Price          *int64  `gorm:"default:0;" json:"price"`                         // 仅配件用,配件的价格, 单位:美分 | ||||||
| 	Sku            *string `gorm:"default:'';" json:"sku"`                          // sku | 	Sku            *string `gorm:"default:'';" json:"sku"`                          // sku | ||||||
| } | } | ||||||
|  | |||||||
| @ -11,9 +11,9 @@ type FsProductTemplateV2 struct { | |||||||
| 	ModelId      *int64  `gorm:"default:0;" json:"model_id"`                      // 模型ID | 	ModelId      *int64  `gorm:"default:0;" json:"model_id"`                      // 模型ID | ||||||
| 	Title        *string `gorm:"default:'';" json:"title"`                        // 模板(sku),预留字段 | 	Title        *string `gorm:"default:'';" json:"title"`                        // 模板(sku),预留字段 | ||||||
| 	Name         *string `gorm:"default:'';" json:"name"`                         // 名称 | 	Name         *string `gorm:"default:'';" json:"name"`                         // 名称 | ||||||
| 	CoverImg     *string `gorm:"default:'';" json:"cover_img"`                    // | 	CoverImg     *string `gorm:"default:'';" json:"cover_img"`                    // 模板背景图 | ||||||
| 	TemplateInfo *string `gorm:"default:'';" json:"template_info"`                // 模板详情 | 	TemplateInfo *string `gorm:"default:'';" json:"template_info"`                // 模板详情 | ||||||
| 	MaterialImg  *string `gorm:"default:'';" json:"material_img"`                 // | 	MaterialImg  *string `gorm:"default:'';" json:"material_img"`                 // 合成好的贴图 | ||||||
| 	Sort         *int64  `gorm:"default:0;" json:"sort"`                          // 排序 | 	Sort         *int64  `gorm:"default:0;" json:"sort"`                          // 排序 | ||||||
| 	LogoWidth    *int64  `gorm:"default:0;" json:"logo_width"`                    // logo图最大宽度 | 	LogoWidth    *int64  `gorm:"default:0;" json:"logo_width"`                    // logo图最大宽度 | ||||||
| 	LogoHeight   *int64  `gorm:"default:0;" json:"logo_height"`                   // logo图最大高度 | 	LogoHeight   *int64  `gorm:"default:0;" json:"logo_height"`                   // logo图最大高度 | ||||||
|  | |||||||
| @ -1,14 +1,180 @@ | |||||||
| 
 |  | ||||||
| package gmodel | package gmodel | ||||||
| 
 | 
 | ||||||
| import "gorm.io/gorm" | import "gorm.io/gorm" | ||||||
| 
 | 
 | ||||||
|  | // AllModelsGen 所有Model集合,修改单行,只要不改字段名,不会根据新的内容修改,需要修改的话手动删除 | ||||||
| type AllModelsGen struct { | type AllModelsGen struct { | ||||||
|  | 	FsAddress                 *FsAddressModel                 // fs_address 用户地址表 | ||||||
|  | 	FsAuthAssignment          *FsAuthAssignmentModel          // fs_auth_assignment 用户角色和权限信息 | ||||||
|  | 	FsAuthItem                *FsAuthItemModel                // fs_auth_item 用户角色和权限信息 | ||||||
|  | 	FsAuthItemChild           *FsAuthItemChildModel           // fs_auth_item_child 角色和权限关系表 | ||||||
|  | 	FsAuthRule                *FsAuthRuleModel                // fs_auth_rule 规则表 | ||||||
|  | 	FsCanteenProduct          *FsCanteenProductModel          // fs_canteen_product 餐厅类别产品对应表 | ||||||
|  | 	FsCanteenType             *FsCanteenTypeModel             // fs_canteen_type 餐厅类型表 | ||||||
|  | 	FsCard                    *FsCardModel                    // fs_card 卡号表 | ||||||
|  | 	FsCardGroup               *FsCardGroupModel               // fs_card_group 卡号分组表 | ||||||
|  | 	FsCart                    *FsCartModel                    // fs_cart 购物车 | ||||||
|  | 	FsChangeCode              *FsChangeCodeModel              // fs_change_code 忘记密码code表 | ||||||
|  | 	FsCloud                   *FsCloudModel                   // fs_cloud 云仓表 | ||||||
|  | 	FsCloudDeliverEveryTmp    *FsCloudDeliverEveryTmpModel    // fs_cloud_deliver_every_tmp | ||||||
|  | 	FsCloudDeliverTmp         *FsCloudDeliverTmpModel         // fs_cloud_deliver_tmp | ||||||
|  | 	FsCloudPickUp             *FsCloudPickUpModel             // fs_cloud_pick_up 云仓提货单 | ||||||
|  | 	FsCloudPickUpDetail       *FsCloudPickUpDetailModel       // fs_cloud_pick_up_detail 云仓提货单-详情 | ||||||
|  | 	FsCloudReceive            *FsCloudReceiveModel            // fs_cloud_receive 云仓接收工厂总单 | ||||||
|  | 	FsCloudReceiveEvery       *FsCloudReceiveEveryModel       // fs_cloud_receive_every | ||||||
|  | 	FsCloudRenderLog          *FsCloudRenderLogModel          // fs_cloud_render_log 云渲染日志表 | ||||||
|  | 	FsCloudUserApplyBack      *FsCloudUserApplyBackModel      // fs_cloud_user_apply_back 该表废弃 | ||||||
|  | 	FsContact                 *FsContactModel                 // fs_contact 该表暂未使用 | ||||||
|  | 	FsContactService          *FsContactServiceModel          // fs_contact_service | ||||||
|  | 	FsCoupon                  *FsCouponModel                  // fs_coupon 代金券(暂未使用) | ||||||
|  | 	FsDeliver                 *FsDeliverModel                 // fs_deliver 发货表  云仓 直发 通用(已废弃) | ||||||
|  | 	FsDeliverEvery            *FsDeliverEveryModel            // fs_deliver_every 发货详细表(已废弃) | ||||||
|  | 	FsDepartment              *FsDepartmentModel              // fs_department 部门表 | ||||||
|  | 	FsEmailLogs               *FsEmailLogsModel               // fs_email_logs 邮件日志表 | ||||||
|  | 	FsEmailTemplate           *FsEmailTemplateModel           // fs_email_template 邮件模板表(暂未使用) | ||||||
|  | 	FsFactory                 *FsFactoryModel                 // fs_factory 该表废弃 | ||||||
|  | 	FsFactoryDeliver          *FsFactoryDeliverModel          // fs_factory_deliver 工厂发货主表(废弃) | ||||||
|  | 	FsFactoryDeliverEvery     *FsFactoryDeliverEveryModel     // fs_factory_deliver_every 该表废弃 | ||||||
|  | 	FsFactoryProduct          *FsFactoryProductModel          // fs_factory_product 工厂生产表(废弃) | ||||||
|  | 	FsFactoryShipTmp          *FsFactoryShipTmpModel          // fs_factory_ship_tmp | ||||||
|  | 	FsFaq                     *FsFaqModel                     // fs_faq 常见问题 | ||||||
|  | 	FsFont                    *FsFontModel                    // fs_font 字体配置 | ||||||
|  | 	FsGerent                  *FsGerentModel                  // fs_gerent 管理员表 | ||||||
|  | 	FsGuest                   *FsGuestModel                   // fs_guest 游客表 | ||||||
|  | 	FsLog                     *FsLogModel                     // fs_log 日志表 | ||||||
|  | 	FsMapLibrary              *FsMapLibraryModel              // fs_map_library 贴图库 | ||||||
|  | 	FsMenu                    *FsMenuModel                    // fs_menu 后台菜单 | ||||||
|  | 	FsMigration               *FsMigrationModel               // fs_migration 版本库 | ||||||
|  | 	FsOrder                   *FsOrderModel                   // fs_order | ||||||
|  | 	FsOrderAffiliate          *FsOrderAffiliateModel          // fs_order_affiliate 订单附属表-流程控制时间等 | ||||||
|  | 	FsOrderDetail             *FsOrderDetailModel             // fs_order_detail 订单详细表 | ||||||
|  | 	FsOrderDetailTemplate     *FsOrderDetailTemplateModel     // fs_order_detail_template 订单模板详细表 | ||||||
|  | 	FsOrderRemark             *FsOrderRemarkModel             // fs_order_remark 订单备注表 | ||||||
|  | 	FsPay                     *FsPayModel                     // fs_pay 支付记录 | ||||||
|  | 	FsProduct                 *FsProductModel                 // fs_product 产品表 | ||||||
|  | 	FsProductCopy1            *FsProductCopy1Model            // fs_product_copy1 产品表 | ||||||
|  | 	FsProductDesign           *FsProductDesignModel           // fs_product_design 产品设计表 | ||||||
|  | 	FsProductDesignGather     *FsProductDesignGatherModel     // fs_product_design_gather | ||||||
|  | 	FsProductModel3d          *FsProductModel3dModel          // fs_product_model3d 产品模型表 | ||||||
|  | 	FsProductModel3dLight     *FsProductModel3dLightModel     // fs_product_model3d_light 模型-灯光组表 | ||||||
|  | 	FsProductOption           *FsProductOptionModel           // fs_product_option 产品选项表(已废弃) | ||||||
|  | 	FsProductPrice            *FsProductPriceModel            // fs_product_price 阶梯价格表 | ||||||
|  | 	FsProductRenderDesign     *FsProductRenderDesignModel     // fs_product_render_design | ||||||
|  | 	FsProductScene            *FsProductSceneModel            // fs_product_scene 产品场景表 | ||||||
|  | 	FsProductSize             *FsProductSizeModel             // fs_product_size 产品尺寸表 | ||||||
|  | 	FsProductTemplate         *FsProductTemplateModel         // fs_product_template 产品模板表(已废弃) | ||||||
|  | 	FsProductTemplateBasemap  *FsProductTemplateBasemapModel  // fs_product_template_basemap 模板底图表 | ||||||
|  | 	FsProductTemplateElement  *FsProductTemplateElementModel  // fs_product_template_element 云渲染配置表 | ||||||
|  | 	FsProductTemplateTags     *FsProductTemplateTagsModel     // fs_product_template_tags  模板标签表 | ||||||
|  | 	FsProductTemplateV2       *FsProductTemplateV2Model       // fs_product_template_v2 产品-模型-模板表 | ||||||
|  | 	FsProductV2Tmp            *FsProductV2TmpModel            // fs_product_v2_tmp 产品表 | ||||||
|  | 	FsQrcode                  *FsQrcodeModel                  // fs_qrcode | ||||||
|  | 	FsQrcodeLog               *FsQrcodeLogModel               // fs_qrcode_log 二维码扫描日志 | ||||||
|  | 	FsQrcodeSet               *FsQrcodeSetModel               // fs_qrcode_set 二维码边框配置表 | ||||||
|  | 	FsQrcodeUser              *FsQrcodeUserModel              // fs_qrcode_user 二维码-用户名表 | ||||||
|  | 	FsQuotation               *FsQuotationModel               // fs_quotation 报价单信息表 | ||||||
|  | 	FsQuotationProduct        *FsQuotationProductModel        // fs_quotation_product 报价单产品表 | ||||||
|  | 	FsQuotationRemarkTemplate *FsQuotationRemarkTemplateModel // fs_quotation_remark_template 报价单备注模板 | ||||||
|  | 	FsQuotationSaler          *FsQuotationSalerModel          // fs_quotation_saler 报价单业务员表 | ||||||
|  | 	FsRefundReason            *FsRefundReasonModel            // fs_refund_reason | ||||||
|  | 	FsStandardLogo            *FsStandardLogoModel            // fs_standard_logo 标准logo | ||||||
|  | 	FsTags                    *FsTagsModel                    // fs_tags 产品分类表 | ||||||
|  | 	FsToolLogs                *FsToolLogsModel                // fs_tool_logs 3d设计工具日志表 | ||||||
|  | 	FsToolTemplate            *FsToolTemplateModel            // fs_tool_template 设计工具模板(废弃) | ||||||
|  | 	FsToolUser                *FsToolUserModel                // fs_tool_user 3d设计工具用户表 | ||||||
|  | 	FsTrade                   *FsTradeModel                   // fs_trade | ||||||
|  | 	FsUser                    *FsUserModel                    // fs_user 用户表 | ||||||
|  | 	FsUserDesign              *FsUserDesignModel              // fs_user_design 废弃表 | ||||||
|  | 	FsUserStock               *FsUserStockModel               // fs_user_stock 用户云仓库存 | ||||||
|  | 	FsWebSet                  *FsWebSetModel                  // fs_web_set 网站配置表 | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewAllModels(gdb *gorm.DB) *AllModelsGen { | func NewAllModels(gdb *gorm.DB) *AllModelsGen { | ||||||
| 	models := &AllModelsGen{ | 	models := &AllModelsGen{ | ||||||
|  | 		FsAddress:                 NewFsAddressModel(gdb), | ||||||
|  | 		FsAuthAssignment:          NewFsAuthAssignmentModel(gdb), | ||||||
|  | 		FsAuthItem:                NewFsAuthItemModel(gdb), | ||||||
|  | 		FsAuthItemChild:           NewFsAuthItemChildModel(gdb), | ||||||
|  | 		FsAuthRule:                NewFsAuthRuleModel(gdb), | ||||||
|  | 		FsCanteenProduct:          NewFsCanteenProductModel(gdb), | ||||||
|  | 		FsCanteenType:             NewFsCanteenTypeModel(gdb), | ||||||
|  | 		FsCard:                    NewFsCardModel(gdb), | ||||||
|  | 		FsCardGroup:               NewFsCardGroupModel(gdb), | ||||||
|  | 		FsCart:                    NewFsCartModel(gdb), | ||||||
|  | 		FsChangeCode:              NewFsChangeCodeModel(gdb), | ||||||
|  | 		FsCloud:                   NewFsCloudModel(gdb), | ||||||
|  | 		FsCloudDeliverEveryTmp:    NewFsCloudDeliverEveryTmpModel(gdb), | ||||||
|  | 		FsCloudDeliverTmp:         NewFsCloudDeliverTmpModel(gdb), | ||||||
|  | 		FsCloudPickUp:             NewFsCloudPickUpModel(gdb), | ||||||
|  | 		FsCloudPickUpDetail:       NewFsCloudPickUpDetailModel(gdb), | ||||||
|  | 		FsCloudReceive:            NewFsCloudReceiveModel(gdb), | ||||||
|  | 		FsCloudReceiveEvery:       NewFsCloudReceiveEveryModel(gdb), | ||||||
|  | 		FsCloudRenderLog:          NewFsCloudRenderLogModel(gdb), | ||||||
|  | 		FsCloudUserApplyBack:      NewFsCloudUserApplyBackModel(gdb), | ||||||
|  | 		FsContact:                 NewFsContactModel(gdb), | ||||||
|  | 		FsContactService:          NewFsContactServiceModel(gdb), | ||||||
|  | 		FsCoupon:                  NewFsCouponModel(gdb), | ||||||
|  | 		FsDeliver:                 NewFsDeliverModel(gdb), | ||||||
|  | 		FsDeliverEvery:            NewFsDeliverEveryModel(gdb), | ||||||
|  | 		FsDepartment:              NewFsDepartmentModel(gdb), | ||||||
|  | 		FsEmailLogs:               NewFsEmailLogsModel(gdb), | ||||||
|  | 		FsEmailTemplate:           NewFsEmailTemplateModel(gdb), | ||||||
|  | 		FsFactory:                 NewFsFactoryModel(gdb), | ||||||
|  | 		FsFactoryDeliver:          NewFsFactoryDeliverModel(gdb), | ||||||
|  | 		FsFactoryDeliverEvery:     NewFsFactoryDeliverEveryModel(gdb), | ||||||
|  | 		FsFactoryProduct:          NewFsFactoryProductModel(gdb), | ||||||
|  | 		FsFactoryShipTmp:          NewFsFactoryShipTmpModel(gdb), | ||||||
|  | 		FsFaq:                     NewFsFaqModel(gdb), | ||||||
|  | 		FsFont:                    NewFsFontModel(gdb), | ||||||
|  | 		FsGerent:                  NewFsGerentModel(gdb), | ||||||
|  | 		FsGuest:                   NewFsGuestModel(gdb), | ||||||
|  | 		FsLog:                     NewFsLogModel(gdb), | ||||||
|  | 		FsMapLibrary:              NewFsMapLibraryModel(gdb), | ||||||
|  | 		FsMenu:                    NewFsMenuModel(gdb), | ||||||
|  | 		FsMigration:               NewFsMigrationModel(gdb), | ||||||
|  | 		FsOrder:                   NewFsOrderModel(gdb), | ||||||
|  | 		FsOrderAffiliate:          NewFsOrderAffiliateModel(gdb), | ||||||
|  | 		FsOrderDetail:             NewFsOrderDetailModel(gdb), | ||||||
|  | 		FsOrderDetailTemplate:     NewFsOrderDetailTemplateModel(gdb), | ||||||
|  | 		FsOrderRemark:             NewFsOrderRemarkModel(gdb), | ||||||
|  | 		FsPay:                     NewFsPayModel(gdb), | ||||||
|  | 		FsProduct:                 NewFsProductModel(gdb), | ||||||
|  | 		FsProductCopy1:            NewFsProductCopy1Model(gdb), | ||||||
|  | 		FsProductDesign:           NewFsProductDesignModel(gdb), | ||||||
|  | 		FsProductDesignGather:     NewFsProductDesignGatherModel(gdb), | ||||||
|  | 		FsProductModel3d:          NewFsProductModel3dModel(gdb), | ||||||
|  | 		FsProductModel3dLight:     NewFsProductModel3dLightModel(gdb), | ||||||
|  | 		FsProductOption:           NewFsProductOptionModel(gdb), | ||||||
|  | 		FsProductPrice:            NewFsProductPriceModel(gdb), | ||||||
|  | 		FsProductRenderDesign:     NewFsProductRenderDesignModel(gdb), | ||||||
|  | 		FsProductScene:            NewFsProductSceneModel(gdb), | ||||||
|  | 		FsProductSize:             NewFsProductSizeModel(gdb), | ||||||
|  | 		FsProductTemplate:         NewFsProductTemplateModel(gdb), | ||||||
|  | 		FsProductTemplateBasemap:  NewFsProductTemplateBasemapModel(gdb), | ||||||
|  | 		FsProductTemplateElement:  NewFsProductTemplateElementModel(gdb), | ||||||
|  | 		FsProductTemplateTags:     NewFsProductTemplateTagsModel(gdb), | ||||||
|  | 		FsProductTemplateV2:       NewFsProductTemplateV2Model(gdb), | ||||||
|  | 		FsProductV2Tmp:            NewFsProductV2TmpModel(gdb), | ||||||
|  | 		FsQrcode:                  NewFsQrcodeModel(gdb), | ||||||
|  | 		FsQrcodeLog:               NewFsQrcodeLogModel(gdb), | ||||||
|  | 		FsQrcodeSet:               NewFsQrcodeSetModel(gdb), | ||||||
|  | 		FsQrcodeUser:              NewFsQrcodeUserModel(gdb), | ||||||
|  | 		FsQuotation:               NewFsQuotationModel(gdb), | ||||||
|  | 		FsQuotationProduct:        NewFsQuotationProductModel(gdb), | ||||||
|  | 		FsQuotationRemarkTemplate: NewFsQuotationRemarkTemplateModel(gdb), | ||||||
|  | 		FsQuotationSaler:          NewFsQuotationSalerModel(gdb), | ||||||
|  | 		FsRefundReason:            NewFsRefundReasonModel(gdb), | ||||||
|  | 		FsStandardLogo:            NewFsStandardLogoModel(gdb), | ||||||
|  | 		FsTags:                    NewFsTagsModel(gdb), | ||||||
|  | 		FsToolLogs:                NewFsToolLogsModel(gdb), | ||||||
|  | 		FsToolTemplate:            NewFsToolTemplateModel(gdb), | ||||||
|  | 		FsToolUser:                NewFsToolUserModel(gdb), | ||||||
|  | 		FsTrade:                   NewFsTradeModel(gdb), | ||||||
|  | 		FsUser:                    NewFsUserModel(gdb), | ||||||
|  | 		FsUserDesign:              NewFsUserDesignModel(gdb), | ||||||
|  | 		FsUserStock:               NewFsUserStockModel(gdb), | ||||||
|  | 		FsWebSet:                  NewFsWebSetModel(gdb), | ||||||
| 	} | 	} | ||||||
| 	return models | 	return models | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,24 +1,27 @@ | |||||||
| package svc | package svc | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"errors" |  | ||||||
| 	"fmt" |  | ||||||
| 	"fusenapi/initalize" | 	"fusenapi/initalize" | ||||||
| 	"fusenapi/model/gmodel" | 	"fusenapi/model/gmodel" | ||||||
| 	"fusenapi/server/home-user-auth/internal/config" |  | ||||||
| 	"net/http" |  | ||||||
| 
 | 
 | ||||||
| 	"github.com/golang-jwt/jwt" | 	"github.com/golang-jwt/jwt" | ||||||
| 	"gorm.io/gorm" | 	"gorm.io/gorm" | ||||||
|  | 
 | ||||||
|  | 	"errors" | ||||||
|  | 	"fmt" | ||||||
|  | 	"fusenapi/server/home-user-auth/internal/config" | ||||||
|  | 	"net/http" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type ServiceContext struct { | type ServiceContext struct { | ||||||
| 	Config    config.Config | 	Config config.Config | ||||||
|  | 
 | ||||||
| 	MysqlConn *gorm.DB | 	MysqlConn *gorm.DB | ||||||
| 	AllModels *gmodel.AllModelsGen | 	AllModels *gmodel.AllModelsGen | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewServiceContext(c config.Config) *ServiceContext { | func NewServiceContext(c config.Config) *ServiceContext { | ||||||
|  | 
 | ||||||
| 	return &ServiceContext{ | 	return &ServiceContext{ | ||||||
| 		Config:    c, | 		Config:    c, | ||||||
| 		MysqlConn: initalize.InitMysql(c.SourceMysql), | 		MysqlConn: initalize.InitMysql(c.SourceMysql), | ||||||
| @ -28,8 +31,8 @@ func NewServiceContext(c config.Config) *ServiceContext { | |||||||
| 
 | 
 | ||||||
| func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { | ||||||
| 	AuthKey := r.Header.Get("Authorization") | 	AuthKey := r.Header.Get("Authorization") | ||||||
| 	if AuthKey == "" { | 	if len(AuthKey) <= 50 { | ||||||
| 		return nil, nil | 		return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	token, err := jwt.Parse(AuthKey, func(token *jwt.Token) (interface{}, error) { | 	token, err := jwt.Parse(AuthKey, func(token *jwt.Token) (interface{}, error) { | ||||||
| @ -38,7 +41,7 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err | |||||||
| 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | 			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) | ||||||
| 		} | 		} | ||||||
| 		// 返回用于验证签名的密钥 | 		// 返回用于验证签名的密钥 | ||||||
| 		return []byte(svcCtx.Config.Auth.AccessSecret), nil | 		return svcCtx.Config.Auth.AccessSecret, nil | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | 		return nil, errors.New(fmt.Sprint("Error parsing token:", err)) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user