12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package service
- import (
- "errors"
- "gin-vue-admin/global"
- "gin-vue-admin/model"
- "gin-vue-admin/utils"
- "strings"
- "go.uber.org/zap"
- )
- func CreateAutoCodeHistory(autoCodeMeta string, injectionMeta string, tableName string) error {
- return global.GVA_DB.Create(&model.SysAutoCodeHistory{
- AutoCodeMeta: autoCodeMeta,
- InjectionMeta: injectionMeta,
- TableName: tableName,
- }).Error
- }
- func RollBack(id uint) error {
- md := model.SysAutoCodeHistory{}
- if err := global.GVA_DB.First(&md, id).Error; err != nil {
- return err
- }
-
- err, dbNames := GetTables(global.GVA_CONFIG.Mysql.Dbname)
- if err != nil {
- return err
- }
-
- for _, name := range dbNames {
- if strings.Contains(strings.ToUpper(strings.Replace(name.TableName, "_", "", -1)), strings.ToUpper(md.TableName)) {
-
- if err = DropTable(name.TableName); err != nil {
- global.GVA_LOG.Error("ClearTag DropTable:", zap.Error(err))
- }
- }
- }
-
- for _, path := range strings.Split(md.AutoCodeMeta, ";") {
- _ = utils.DeLFile(path)
- }
-
- for _, v := range strings.Split(md.InjectionMeta, ";") {
-
- meta := strings.Split(v, "@")
- if len(meta) != 3 {
- return errors.New("split InjectionMeta Err")
- }
- _ = utils.AutoClearCode(meta[0], meta[2])
- }
- md.Flag = 1
- return global.GVA_DB.Save(&md).Error
- }
|