瀏覽代碼

update

master
dengbiao 7 月之前
父節點
當前提交
4b5112646d
共有 15 個文件被更改,包括 123 次插入45 次删除
  1. +3
    -2
      README.md
  2. +9
    -6
      cmd_dao.bat
  3. +23
    -0
      cmd_implement.bat
  4. +6
    -14
      etc/db_tpl/struct.go.tpl
  5. +9
    -0
      etc/ps/ConvertToUpperCase.ps1
  6. +14
    -0
      etc/template/template_implement.tpl
  7. +1
    -3
      src/dao/happy_orchard_seed_dao.go
  8. +5
    -0
      src/dao/hello_world_dao.go
  9. +14
    -0
      src/implement/demo_db.go
  10. +3
    -3
      src/implement/happy_orchard_reward_db.go
  11. +5
    -5
      src/implement/happy_orchard_reward_exchange_records_db.go
  12. +3
    -3
      src/implement/happy_orchard_seed_db.go
  13. +14
    -0
      src/implement/hello_world_db.go
  14. +0
    -1
      src/models/happy_orchard_basic_setting.go
  15. +14
    -8
      src/models/happy_orchard_seed.go

+ 3
- 2
README.md 查看文件

@@ -40,5 +40,6 @@
确保安装了所需的依赖,然后运行以下命令:

```bash
.\cmd_db.bat HelloWorld
.\cmd_dao.bat HelloWorld
.\cmd_db.bat hello_world ---> 自动生成模型类
.\cmd_dao.bat hello_world ---> 自动生成接口类
cmd_implement.bat hello_world ---> 自动生成实现类

+ 9
- 6
cmd_dao.bat 查看文件

@@ -3,12 +3,14 @@ setlocal

set "BasePath=./"

REM 假设已经提供了接口名作为参数
set "InterfaceName=%~1"
REM 假设已经提供了文件名作为参数
set "FileName=%~1"

REM 将接口名转换为小写并设置最终文件名
for /f "delims=" %%i in ('powershell -Command "('%InterfaceName%').ToLower()"') do set "LowerInterfaceName=%%i"
set "FinalFile=%BasePath%src\dao\%LowerInterfaceName%_dao.go"
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"
@@ -16,5 +18,6 @@ powershell -Command "(Get-Content '%BasePath%etc\template\template_interface.tpl
REM 如果需要,将临时文件重命名为最终文件(取决于move Y?N)
move /Y "%BasePath%temp_interface.go" "%FinalFile%"

echo Interface file %FileName%_dao.go generated successfully.

endlocal
echo Interface file %LowerInterfaceName%_dao.go generated successfully.

+ 23
- 0
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

+ 6
- 14
etc/db_tpl/struct.go.tpl 查看文件

@@ -1,17 +1,9 @@
package {{.Models}}
@echo off
setlocal

{{$ilen := len .Imports}}
{{if gt $ilen 0}}
import (
{{range .Imports}}"{{.}}"{{end}}
)
{{end}}
set "inputString=hello_world"
for /f "delims=" %%i in ('powershell -File "ConvertToUpperCase.ps1" -inputString "%inputString%"') do set "outputVar=%%i"

{{range .Tables}}
type {{Mapper .Name}} struct {
{{$table := .}}
{{range .ColumnsSeq}}{{$col := $table.GetColumn .}} {{Mapper $col.Name}} {{Type $col}} {{Tag $table $col}}
{{end}}
}
{{end}}
echo %outputVar%

endlocal

+ 9
- 0
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

+ 14
- 0
etc/template/template_implement.tpl 查看文件

@@ -0,0 +1,14 @@
package implement

import (
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/dao"
"xorm.io/xorm"
)

type DemoImplementDb struct {
Db *xorm.Engine
}

func NewDemoImplementDb(engine *xorm.Engine) dao.DemoImplementDao {
return &DemoImplementDb{Db: engine}
}

src/dao/happy_happy_orchard_seed_dao.go → src/dao/happy_orchard_seed_dao.go 查看文件

@@ -1,8 +1,6 @@
package dao

import (
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/models"
)
import "code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/models"

type HappyOrchardSeedDao interface {
GetHappyOrchardSeed(id int) (m *models.HappyOrchardSeed, err error)

+ 5
- 0
src/dao/hello_world_dao.go 查看文件

@@ -0,0 +1,5 @@
package dao

type HelloWorldDao interface {
//TODO:: You can add specific method definitions here
}

+ 14
- 0
src/implement/demo_db.go 查看文件

@@ -0,0 +1,14 @@
package implement

import (
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/dao"
"xorm.io/xorm"
)

type DemoDb struct {
Db *xorm.Engine
}

func NewDemoDb(engine *xorm.Engine) dao.DemoDao {
return &DemoDb{Db: engine}
}

+ 3
- 3
src/implement/happy_orchard_reward_db.go 查看文件

@@ -7,15 +7,15 @@ import (
"xorm.io/xorm"
)

type happyOrchardRewardDb struct {
type HappyOrchardRewardDb struct {
Db *xorm.Engine
}

func NewHappyOrchardRewardDb(engine *xorm.Engine) dao.HappyOrchardRewardDao {
return &happyOrchardRewardDb{Db: engine}
return &HappyOrchardRewardDb{Db: engine}
}

func (h happyOrchardRewardDb) GetHappyOrchardReward(id int) (m *models.HappyOrchardReward, err error) {
func (h HappyOrchardRewardDb) GetHappyOrchardReward(id int) (m *models.HappyOrchardReward, err error) {
m = new(models.HappyOrchardReward)
has, err := h.Db.Where("id =?", id).Get(m)
if err != nil {


+ 5
- 5
src/implement/happy_orchard_reward_exchange_records_db.go 查看文件

@@ -7,15 +7,15 @@ import (
"xorm.io/xorm"
)

type happyOrchardRewardExchangeRecordsDb struct {
type HappyOrchardRewardExchangeRecordsDb struct {
Db *xorm.Engine
}

func NewHappyOrchardRewardExchangeRecordsDb123456(engine *xorm.Engine) dao.HappyOrchardRewardExchangeRecordsDao {
return &happyOrchardRewardExchangeRecordsDb{Db: engine}
func NewHappyOrchardRewardExchangeRecordsDb(engine *xorm.Engine) dao.HappyOrchardRewardExchangeRecordsDao {
return &HappyOrchardRewardExchangeRecordsDb{Db: engine}
}

func (h happyOrchardRewardExchangeRecordsDb) GetHappyOrchardRewardExchangeRecords(id int) (m *models.HappyOrchardRewardExchangeRecords, err error) {
func (h HappyOrchardRewardExchangeRecordsDb) GetHappyOrchardRewardExchangeRecords(id int) (m *models.HappyOrchardRewardExchangeRecords, err error) {
//TODO implement me
m = new(models.HappyOrchardRewardExchangeRecords)
has, err := h.Db.Where("id =?", id).Get(m)
@@ -28,7 +28,7 @@ func (h happyOrchardRewardExchangeRecordsDb) GetHappyOrchardRewardExchangeRecord
return m, nil
}

func (h happyOrchardRewardExchangeRecordsDb) FindHappyOrchardRewardExchangeRecordsByUid(uid int) (mm *[]models.HappyOrchardRewardExchangeRecords, err error) {
func (h HappyOrchardRewardExchangeRecordsDb) FindHappyOrchardRewardExchangeRecordsByUid(uid int) (mm *[]models.HappyOrchardRewardExchangeRecords, err error) {
//TODO implement me
var m []models.HappyOrchardRewardExchangeRecords
if err := h.Db.Where("uid =?", uid).Desc("id").Find(&m); err != nil {


+ 3
- 3
src/implement/happy_orchard_seed_db.go 查看文件

@@ -7,15 +7,15 @@ import (
"xorm.io/xorm"
)

type happyOrchardSeedDb struct {
type HappyOrchardSeedDb struct {
Db *xorm.Engine
}

func NewHappyOrchardSeedDb(engine *xorm.Engine) dao.HappyOrchardSeedDao {
return &happyOrchardSeedDb{Db: engine}
return &HappyOrchardSeedDb{Db: engine}
}

func (h happyOrchardSeedDb) GetHappyOrchardSeed(id int) (m *models.HappyOrchardSeed, err error) {
func (h HappyOrchardSeedDb) GetHappyOrchardSeed(id int) (m *models.HappyOrchardSeed, err error) {
m = new(models.HappyOrchardSeed)
has, err := h.Db.Where("id =?", id).Get(m)
if err != nil {


+ 14
- 0
src/implement/hello_world_db.go 查看文件

@@ -0,0 +1,14 @@
package implement

import (
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/dao"
"xorm.io/xorm"
)

type HelloWorldDb struct {
Db *xorm.Engine
}

func NewHelloWorldDb(engine *xorm.Engine) dao.HelloWorldDao {
return &HelloWorldDb{Db: engine}
}

+ 0
- 1
src/models/happy_orchard_basic_setting.go 查看文件

@@ -29,7 +29,6 @@ type HappyOrchardBasicSetting struct {
UpgradeRewardWaterDroplet int `json:"upgrade_reward_water_droplet" xorm:"not null default 0 comment('升级奖励水滴') INT(11)"`
ReplaceSeedNums int `json:"replace_seed_nums" xorm:"not null default 0 comment('更换种子次数') INT(11)"`
StageNameCustom string `json:"stage_name_custom" xorm:"not null comment('阶段自定义') TEXT"`
LevelRules string `json:"level_rules" xorm:"not null comment('等级规则') TEXT"`
VirtualRewardIsAutoSend int `json:"virtual_reward_is_auto_send" xorm:"not null default 0 comment('虚拟奖品是否自动发放(1:是 2:否)') TINYINT(1)"`
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`


+ 14
- 8
src/models/happy_orchard_seed.go 查看文件

@@ -1,12 +1,18 @@
package models

type HappyOrchardSeed struct {
Id int `json:"id" xorm:"not null pk autoincr comment('自增id') INT(11)"`
Name string `json:"name" xorm:"not null default '' comment('名称') VARCHAR(255)"`
WaterNums int `json:"water_nums" xorm:"not null default 0 comment('所需水滴数') INT(11)"`
SeedImgUrl string `json:"seed_img_url" xorm:"not null default '' comment('种子图片地址') VARCHAR(255)"`
SeedMatureImgUrl string `json:"seed_mature_img_url" xorm:"not null default '' comment('种子成熟后图片地址') VARCHAR(255)"`
Sort int `json:"sort" xorm:"not null default 0 comment('排序') INT(11)"`
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
Id int `json:"id" xorm:"not null pk autoincr comment('自增id') INT(11)"`
Name string `json:"name" xorm:"not null default '' comment('名称') VARCHAR(255)"`
WaterNums int `json:"water_nums" xorm:"not null default 0 comment('所需水滴数') INT(11)"`
SeedImgUrl string `json:"seed_img_url" xorm:"not null default '' comment('种子图片地址') VARCHAR(255)"`
SeedMatureImgUrl string `json:"seed_mature_img_url" xorm:"not null default '' comment('种子成熟后图片地址') VARCHAR(255)"`
Sort int `json:"sort" xorm:"not null default 0 comment('排序') INT(11)"`
NeedWatersNumForStage0 int `json:"need_waters_num_for_stage_0" xorm:"not null default 0 comment('阶段1所需水滴数') INT(11)"`
NeedWatersNumForStage1 int `json:"need_waters_num_for_stage_1" xorm:"not null default 0 comment('阶段2所需水滴数') INT(11)"`
NeedWatersNumForStage2 int `json:"need_waters_num_for_stage_2" xorm:"not null default 0 comment('阶段3所需水滴数') INT(11)"`
NeedWatersNumForStage3 int `json:"need_waters_num_for_stage_3" xorm:"not null default 0 comment('阶段4所需水滴数') INT(11)"`
NeedWatersNumForStage4 int `json:"need_waters_num_for_stage_4" xorm:"not null default 0 comment('阶段5所需水滴数') INT(11)"`
NeedWatersNumForStage5 int `json:"need_waters_num_for_stage_5" xorm:"not null default 0 comment('阶段6所需水滴数') INT(11)"`
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

Loading…
取消
儲存