diff --git a/cmd_dao.bat b/cmd_dao.bat new file mode 100644 index 0000000..bb51c63 --- /dev/null +++ b/cmd_dao.bat @@ -0,0 +1,23 @@ +@echo off +setlocal + +set "BasePath=./" + +REM 假设已经提供了文件名作为参数 +set "FileName=%~1" + +REM 将参数设置最终文件名 +set "FinalFile=%BasePath%src\dao\%FileName%_dao.go" + +REM 将文件名转换成大驼峰格式并设置成最终接口名 +for /f "delims=" %%i in ('powershell -File "%BasePath%etc\ps\ConvertToUpperCase.ps1" -inputString "%FileName%"') do set "InterfaceName=%%i" + +REM 使用 PowerShell 替换接口名称,并指定 UTF-8 编码 +powershell -Command "(Get-Content '%BasePath%etc\template\template_interface.tpl') -replace 'DemoInterface', '%InterfaceName%' | Out-File -FilePath '%BasePath%temp_interface.go' -Encoding UTF8" + +REM 如果需要,将临时文件重命名为最终文件(取决于move Y?N) +move /Y "%BasePath%temp_interface.go" "%FinalFile%" + +echo Interface file %FileName%_dao.go generated successfully. + +endlocal diff --git a/cmd_db.bat b/cmd_db.bat new file mode 100644 index 0000000..f17da43 --- /dev/null +++ b/cmd_db.bat @@ -0,0 +1,25 @@ +@echo off + +set Table=* +set TName="" +set one=%1 + +if "%one%" NEQ "" ( + set Table=%one% + set TName="^%one%$" +) + +set BasePath="./" +set DBUSER="root" +set DBPSW="Fnuo123com@" +set DBNAME="fnuoos_test1" +set DBHOST="119.23.182.117" +set DBPORT="3306" + +del "src\models\%Table%.go" + +echo start reverse table %Table% + +xorm reverse mysql "%DBUSER%:%DBPSW%@tcp(%DBHOST%:%DBPORT%)/%DBNAME%?charset=utf8" %BasePath%/etc/db_tpl %BasePath%/src/models/ %TName% + +echo end \ No newline at end of file diff --git a/cmd_db.sh b/cmd_db.sh new file mode 100644 index 0000000..f7d5f84 --- /dev/null +++ b/cmd_db.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# 使用方法, 直接执行该脚本更新所有表, cmd_db.sh 表名, 如 ./cmd_db.sh tableName + +Table=* +TName="" +if [ "$1" ] ;then + Table=$1 + TName="^$1$" +fi + +BasePath="./" +DBUSER="root" +DBPSW="Fnuo123com@" +DBNAME="super_advertisement" +DBHOST="119.23.182.117" +DBPORT="3306" + +rm -rf $BasePath/app/db/model/$Table.go && \ + +xorm reverse mysql "$DBUSER:$DBPSW@tcp($DBHOST:$DBPORT)/$DBNAME?charset=utf8" $BasePath/etc/db_tpl $BasePath/src/models/ $TName \ No newline at end of file diff --git a/cmd_implement.bat b/cmd_implement.bat new file mode 100644 index 0000000..74a7ac4 --- /dev/null +++ b/cmd_implement.bat @@ -0,0 +1,23 @@ +@echo off +setlocal + +set "BasePath=./" + +REM 假设已经提供了文件名作为参数 +set "FileName=%~1" + +REM 将参数设置最终文件名 +set "FinalFile=%BasePath%src\implement\%FileName%_db.go" + +REM 将文件名转换成大驼峰格式并设置成最终实现类名 +for /f "delims=" %%i in ('powershell -File "%BasePath%etc\ps\ConvertToUpperCase.ps1" -inputString "%FileName%"') do set "ImplementName=%%i" + +REM 使用 PowerShell 替换接口名称,并指定 UTF-8 编码 +powershell -Command "(Get-Content '%BasePath%etc\template\template_implement.tpl') -replace 'DemoImplement', '%ImplementName%' | Out-File -FilePath '%BasePath%temp_implement.go' -Encoding UTF8" + +REM 如果需要,将临时文件重命名为最终文件(取决于move Y?N) +move /Y "%BasePath%temp_implement.go" "%FinalFile%" + +echo Implement file %FileName%_dao.go generated successfully. + +endlocal diff --git a/etc/ps/ConvertToUpperCase.ps1 b/etc/ps/ConvertToUpperCase.ps1 new file mode 100644 index 0000000..9a61727 --- /dev/null +++ b/etc/ps/ConvertToUpperCase.ps1 @@ -0,0 +1,9 @@ +param($inputString) +$words = $inputString.Split('_') +$outputString = "" +foreach ($word in $words) { + $outputString += $word.Substring(0,1).ToUpper() + $word.Substring(1).ToLower() + "" +} +$outputString = $outputString.TrimEnd() +$outputString -replace ' ', '' # 如果想要没有空格的字符串,取消注释这行代码 +$outputString \ No newline at end of file diff --git a/etc/template/template_implement.tpl b/etc/template/template_implement.tpl new file mode 100644 index 0000000..ecc280f --- /dev/null +++ b/etc/template/template_implement.tpl @@ -0,0 +1,14 @@ +package implement + +import ( + "applet/app/db/dao" + "xorm.io/xorm" +) + +func NewDemoImplementDb(engine *xorm.Engine) dao.DemoImplementDao { + return &DemoImplementDb{Db: engine} +} + +type DemoImplementDb struct { + Db *xorm.Engine +} \ No newline at end of file diff --git a/etc/template/template_interface.tpl b/etc/template/template_interface.tpl new file mode 100644 index 0000000..2a05d90 --- /dev/null +++ b/etc/template/template_interface.tpl @@ -0,0 +1,5 @@ +package dao + +type DemoInterfaceDao interface { + //TODO:: You can add specific method definitions here +} diff --git a/src/dao/db_mapping_agent_dao.go b/src/dao/db_mapping_agent_dao.go new file mode 100644 index 0000000..641e1ac --- /dev/null +++ b/src/dao/db_mapping_agent_dao.go @@ -0,0 +1,5 @@ +package dao + +type DbMappingAgentDao interface { + //TODO:: You can add specific method definitions here +} diff --git a/src/dao/agent_domain_dao.go b/src/dao/db_mapping_dao.go similarity index 69% rename from src/dao/agent_domain_dao.go rename to src/dao/db_mapping_dao.go index 5e7a804..374fe3e 100644 --- a/src/dao/agent_domain_dao.go +++ b/src/dao/db_mapping_dao.go @@ -1,5 +1,5 @@ package dao -type AgentDomainDao interface { +type DbMappingDao interface { //TODO:: You can add specific method definitions here } diff --git a/src/dao/db_mapping_medium_dao.go b/src/dao/db_mapping_medium_dao.go new file mode 100644 index 0000000..4048f53 --- /dev/null +++ b/src/dao/db_mapping_medium_dao.go @@ -0,0 +1,5 @@ +package dao + +type DbMappingMediumDao interface { + //TODO:: You can add specific method definitions here +} diff --git a/src/dao/medium_domain_dao.go b/src/dao/medium_domain_dao.go deleted file mode 100644 index f755ddb..0000000 --- a/src/dao/medium_domain_dao.go +++ /dev/null @@ -1,10 +0,0 @@ -package dao - -import ( - "code.fnuoos.com/zhimeng/model.git/src/model" -) - -type MediumDomainDao interface { - GetMediumDomain(mediumId int) (medium *model.MediumDomain, err error) - MediumDomainInsert(m *model.MediumDomain) (int64, error) -} diff --git a/src/implement/agent_domain_implement.go b/src/implement/agent_domain_implement.go deleted file mode 100644 index 8d3a05a..0000000 --- a/src/implement/agent_domain_implement.go +++ /dev/null @@ -1,14 +0,0 @@ -package implement - -import ( - "code.fnuoos.com/zhimeng/model.git/src/dao" - "xorm.io/xorm" -) - -func NewAgentDomainDb(engine *xorm.Engine) dao.AgentDomainDao { - return &AgentDomainDb{Db: engine} -} - -type AgentDomainDb struct { - Db *xorm.Engine -} diff --git a/src/implement/medium_domain_implement.go b/src/implement/medium_domain_implement.go deleted file mode 100644 index e3d71ae..0000000 --- a/src/implement/medium_domain_implement.go +++ /dev/null @@ -1,36 +0,0 @@ -package implement - -import ( - "code.fnuoos.com/zhimeng/model.git/src/dao" - "code.fnuoos.com/zhimeng/model.git/src/model" - zhios_order_relate_logx "code.fnuoos.com/zhimeng/model.git/utils/logx" - "xorm.io/xorm" -) - -func NewMediumDomainDb(engine *xorm.Engine) dao.MediumDomainDao { - return &MediumDomainDb{Db: engine} -} - -type MediumDomainDb struct { - Db *xorm.Engine -} - -func (m MediumDomainDb) GetMediumDomain(mediumId int) (medium *model.MediumDomain, err error) { - medium = new(model.MediumDomain) - has, err := m.Db.Where("medium_id =?", mediumId).Get(medium) - if err != nil { - return nil, zhios_order_relate_logx.Error(err) - } - if has == false { - return nil, nil - } - return medium, nil -} - -func (m MediumDomainDb) MediumDomainInsert(medium *model.MediumDomain) (int64, error) { - insertAffected, err := m.Db.InsertOne(medium) - if err != nil { - return 0, err - } - return insertAffected, nil -} diff --git a/src/model/agent_domain.go b/src/model/agent_domain.go deleted file mode 100644 index 79f4953..0000000 --- a/src/model/agent_domain.go +++ /dev/null @@ -1,8 +0,0 @@ -package model - -type AgentDomain struct { - Domain string `json:"domain" xorm:"not null pk comment('绑定域名') VARCHAR(100)"` - MediumId int `json:"medium_id" xorm:"not null comment('媒体id') index unique INT(11)"` - IsOfficial int `json:"is_official" xorm:"not null default 1 comment('是否官方指定域名(1:是 2:否)') TINYINT(1)"` - IsSsl int `json:"is_ssl" xorm:"not null default 0 comment('是否开启ssl:0否;1是') TINYINT(255)"` -} diff --git a/src/model/medium_domain.go b/src/model/medium_domain.go deleted file mode 100644 index 337e167..0000000 --- a/src/model/medium_domain.go +++ /dev/null @@ -1,8 +0,0 @@ -package model - -type MediumDomain struct { - Domain string `json:"domain" xorm:"not null pk comment('绑定域名') VARCHAR(100)"` - MediumId int `json:"medium_id" xorm:"not null comment('媒体id') index unique INT(11)"` - IsOfficial int `json:"is_official" xorm:"not null default 1 comment('是否官方指定域名(1:是 2:否)') TINYINT(1)"` - IsSsl int `json:"is_ssl" xorm:"not null default 0 comment('是否开启ssl:0否;1是') TINYINT(255)"` -} diff --git a/src/super/dao/agent_app_domain_dao.go b/src/super/dao/agent_app_domain_dao.go new file mode 100644 index 0000000..06835ff --- /dev/null +++ b/src/super/dao/agent_app_domain_dao.go @@ -0,0 +1,9 @@ +package dao + +import "code.fnuoos.com/zhimeng/model.git/src/super/model" + +type AgentAppDomainDao interface { + GetAgentAppDomain(agentId int) (m *model.AgentAppDomain, err error) + GetAgentAppDomainByHost(host string) (m *model.AgentAppDomain, err error) + AgentAppDomainInsert(m *model.AgentAppDomain) (int64, error) +} diff --git a/src/super/dao/medium_app_domain_dao.go b/src/super/dao/medium_app_domain_dao.go new file mode 100644 index 0000000..e3c1a71 --- /dev/null +++ b/src/super/dao/medium_app_domain_dao.go @@ -0,0 +1,9 @@ +package dao + +import "code.fnuoos.com/zhimeng/model.git/src/super/model" + +type MediumAppDomainDao interface { + GetMediumAppDomain(mediumId int) (m *model.MediumAppDomain, err error) + GetMediumAppDomainByHost(host string) (m *model.MediumAppDomain, err error) + MediumAppDomainInsert(m *model.MediumAppDomain) (int64, error) +} diff --git a/src/super/dao/user_app_domain_dao.go b/src/super/dao/user_app_domain_dao.go new file mode 100644 index 0000000..e120f8a --- /dev/null +++ b/src/super/dao/user_app_domain_dao.go @@ -0,0 +1,9 @@ +package dao + +import "code.fnuoos.com/zhimeng/model.git/src/super/model" + +type UserAppDomainDao interface { + GetUserAppDomain(masterId int) (m *model.UserAppDomain, err error) + GetMediumAppDomainByHost(host string) (m *model.UserAppDomain, err error) + UserAppDomainInsert(m *model.UserAppDomain) (int64, error) +} diff --git a/src/super/implement/agent_app_domain_implement.go b/src/super/implement/agent_app_domain_implement.go new file mode 100644 index 0000000..e34008d --- /dev/null +++ b/src/super/implement/agent_app_domain_implement.go @@ -0,0 +1,48 @@ +package implement + +import ( + "code.fnuoos.com/zhimeng/model.git/src/super/dao" + "code.fnuoos.com/zhimeng/model.git/src/super/model" + zhios_order_relate_logx "code.fnuoos.com/zhimeng/model.git/utils/logx" + "xorm.io/xorm" +) + +func NewAgentAppDomainDb(engine *xorm.Engine) dao.AgentAppDomainDao { + return &AgentAppDomainDb{Db: engine} +} + +type AgentAppDomainDb struct { + Db *xorm.Engine +} + +func (a AgentAppDomainDb) GetAgentAppDomainByHost(host string) (m *model.AgentAppDomain, err error) { + m = new(model.AgentAppDomain) + has, err := a.Db.Where("domain =?", host).Get(m) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, nil + } + return m, nil +} + +func (a AgentAppDomainDb) GetAgentAppDomain(agent int) (m *model.AgentAppDomain, err error) { + m = new(model.AgentAppDomain) + has, err := a.Db.Where("agent_id =?", agent).Get(m) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, nil + } + return m, nil +} + +func (a AgentAppDomainDb) AgentAppDomainInsert(m *model.AgentAppDomain) (int64, error) { + insertAffected, err := a.Db.InsertOne(m) + if err != nil { + return 0, err + } + return insertAffected, nil +} diff --git a/src/super/implement/medium_app_domain_implement.go b/src/super/implement/medium_app_domain_implement.go new file mode 100644 index 0000000..189fb15 --- /dev/null +++ b/src/super/implement/medium_app_domain_implement.go @@ -0,0 +1,48 @@ +package implement + +import ( + "code.fnuoos.com/zhimeng/model.git/src/super/dao" + "code.fnuoos.com/zhimeng/model.git/src/super/model" + zhios_order_relate_logx "code.fnuoos.com/zhimeng/model.git/utils/logx" + "xorm.io/xorm" +) + +func NewMediumAppDomainDb(engine *xorm.Engine) dao.MediumAppDomainDao { + return &MediumAppDomainDb{Db: engine} +} + +type MediumAppDomainDb struct { + Db *xorm.Engine +} + +func (m2 MediumAppDomainDb) GetMediumAppDomainByHost(host string) (m *model.MediumAppDomain, err error) { + m = new(model.MediumAppDomain) + has, err := m2.Db.Where("domain =?", host).Get(m) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, nil + } + return m, nil +} + +func (m2 MediumAppDomainDb) GetMediumAppDomain(mediumId int) (m *model.MediumAppDomain, err error) { + m = new(model.MediumAppDomain) + has, err := m2.Db.Where("medium_id =?", mediumId).Get(m) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, nil + } + return m, nil +} + +func (m2 MediumAppDomainDb) MediumAppDomainInsert(m *model.MediumAppDomain) (int64, error) { + insertAffected, err := m2.Db.InsertOne(m) + if err != nil { + return 0, err + } + return insertAffected, nil +} diff --git a/src/super/implement/user_app_domain_implement.go b/src/super/implement/user_app_domain_implement.go new file mode 100644 index 0000000..adc82b5 --- /dev/null +++ b/src/super/implement/user_app_domain_implement.go @@ -0,0 +1,48 @@ +package implement + +import ( + "code.fnuoos.com/zhimeng/model.git/src/super/dao" + "code.fnuoos.com/zhimeng/model.git/src/super/model" + zhios_order_relate_logx "code.fnuoos.com/zhimeng/model.git/utils/logx" + "xorm.io/xorm" +) + +func NewUserAppDomainDb(engine *xorm.Engine) dao.UserAppDomainDao { + return &UserAppDomainDb{Db: engine} +} + +type UserAppDomainDb struct { + Db *xorm.Engine +} + +func (u UserAppDomainDb) GetMediumAppDomainByHost(host string) (m *model.UserAppDomain, err error) { + m = new(model.UserAppDomain) + has, err := u.Db.Where("domain =?", host).Get(m) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, nil + } + return m, nil +} + +func (u UserAppDomainDb) GetUserAppDomain(masterId int) (m *model.UserAppDomain, err error) { + m = new(model.UserAppDomain) + has, err := u.Db.Where("uuid =?", masterId).Get(m) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, nil + } + return m, nil +} + +func (u UserAppDomainDb) UserAppDomainInsert(m *model.UserAppDomain) (int64, error) { + insertAffected, err := u.Db.InsertOne(m) + if err != nil { + return 0, err + } + return insertAffected, nil +} diff --git a/src/super/model/agent_app_domain.go b/src/super/model/agent_app_domain.go new file mode 100644 index 0000000..baaa5df --- /dev/null +++ b/src/super/model/agent_app_domain.go @@ -0,0 +1,9 @@ +package model + +type AgentAppDomain struct { + Domain string `json:"domain" xorm:"not null pk comment('绑定域名') VARCHAR(100)"` + AgentId int `json:"agent_id" xorm:"not null comment('代理id') index unique(IDX_UUID_TYPE) INT(10)"` + Uuid int `json:"uuid" xorm:"not null comment('对应APP ID编号') index unique(IDX_UUID_TYPE) INT(10)"` + Type string `json:"type" xorm:"not null comment('api接口域名,wap.h5域名,admin管理后台') unique(IDX_UUID_TYPE) ENUM('admin','api','wap')"` + IsSsl int `json:"is_ssl" xorm:"not null default 0 comment('是否开启ssl:0否;1是') TINYINT(255)"` +} diff --git a/src/super/model/medium_app_domain.go b/src/super/model/medium_app_domain.go new file mode 100644 index 0000000..5d1f607 --- /dev/null +++ b/src/super/model/medium_app_domain.go @@ -0,0 +1,9 @@ +package model + +type MediumAppDomain struct { + Domain string `json:"domain" xorm:"not null pk comment('绑定域名') VARCHAR(100)"` + MediumId int `json:"medium_id" xorm:"not null comment('媒体id') index unique(IDX_UUID_TYPE) INT(10)"` + Uuid int `json:"uuid" xorm:"not null comment('对应APP ID编号') index unique(IDX_UUID_TYPE) INT(10)"` + Type string `json:"type" xorm:"not null comment('api接口域名,wap.h5域名,admin管理后台') unique(IDX_UUID_TYPE) ENUM('admin','api','wap')"` + IsSsl int `json:"is_ssl" xorm:"not null default 0 comment('是否开启ssl:0否;1是') TINYINT(255)"` +} diff --git a/src/super/model/user_app_domain.go b/src/super/model/user_app_domain.go new file mode 100644 index 0000000..4522cef --- /dev/null +++ b/src/super/model/user_app_domain.go @@ -0,0 +1,8 @@ +package model + +type UserAppDomain struct { + Domain string `json:"domain" xorm:"not null pk comment('绑定域名') VARCHAR(100)"` + Uuid int `json:"uuid" xorm:"not null comment('对应APP ID编号') index unique(IDX_UUID_TYPE) INT(10)"` + Type string `json:"type" xorm:"not null comment('api接口域名,wap.h5域名,admin管理后台') unique(IDX_UUID_TYPE) ENUM('admin','api','wap')"` + IsSsl int `json:"is_ssl" xorm:"not null default 0 comment('是否开启ssl:0否;1是') TINYINT(255)"` +}