From cfb0fa7ba6ec895960cee1e7f8a1eba7521c3ee4 Mon Sep 17 00:00:00 2001 From: herenshan112 Date: Wed, 27 Sep 2023 13:24:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AB=AF=E5=A2=9E=E5=8A=A0=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/shiyan/maptostruct/shiyan.go | 165 +++ api/version1/customerform/analysis_table.go | 483 +++++++ api/version1/customerform/datatable.go | 614 +++++++++ api/version1/customerform/form.go | 1165 +++++++++++++++++ api/version1/customerform/type.go | 228 +++- api/version1/entry.go | 4 + api/version1/menus/menus.go | 12 +- api/version1/publicapi/api.go | 53 + api/version1/publicapi/type.go | 7 + api/version1/publicapi/组件结构.ts | 813 ++++++++++++ api/version1/taskplatform/taskflow/types.go | 36 + .../taskplatform/taskmanagement/appform.go | 479 +++++++ .../taskplatform/taskmanagement/types.go | 73 ++ apirouter/apishiyan/maptostruct.go | 9 + apirouter/entry.go | 2 + apirouter/v1/customerformrouter/router.go | 22 +- apirouter/v1/public/router.go | 1 + apirouter/v1/taskrouter/taskrouter.go | 31 + apirouter/v1/taskrouter/type.go | 4 + config/configDatabase/database.go | 1 + initialization/databaseinit/mysql.go | 6 + initialization/route/initRoute.go | 3 + models/modelAppPlatform/customer_form.go | 70 + .../modelAppPlatform/customer_form_version.go | 66 + models/modelAppPlatform/customer_form_view.go | 71 + models/modelAppPlatform/task.go | 64 + models/modelshr/man_cont.go | 11 + models/modelsschool/test_paper.go | 1 + overall/appConfig.go | 2 + overall/publicmethod/technique.go | 128 ++ scheduledtask/time_task_cron.go | 3 +- 31 files changed, 4603 insertions(+), 24 deletions(-) create mode 100644 api/version1/customerform/analysis_table.go create mode 100644 api/version1/customerform/datatable.go create mode 100644 api/version1/customerform/form.go create mode 100644 api/version1/publicapi/组件结构.ts create mode 100644 api/version1/taskplatform/taskflow/types.go create mode 100644 api/version1/taskplatform/taskmanagement/appform.go create mode 100644 api/version1/taskplatform/taskmanagement/types.go create mode 100644 apirouter/v1/taskrouter/taskrouter.go create mode 100644 apirouter/v1/taskrouter/type.go create mode 100644 models/modelAppPlatform/customer_form.go create mode 100644 models/modelAppPlatform/customer_form_version.go create mode 100644 models/modelAppPlatform/customer_form_view.go create mode 100644 models/modelAppPlatform/task.go diff --git a/api/shiyan/maptostruct/shiyan.go b/api/shiyan/maptostruct/shiyan.go index 047e571..120e17c 100644 --- a/api/shiyan/maptostruct/shiyan.go +++ b/api/shiyan/maptostruct/shiyan.go @@ -1,6 +1,8 @@ package maptostruct import ( + "appPlatform/api/version1/customerform" + "appPlatform/models/modelAppPlatform" "appPlatform/models/modelsschool" "appPlatform/overall" "appPlatform/overall/publicmethod" @@ -12,6 +14,7 @@ import ( "time" "github.com/gin-gonic/gin" + "github.com/mozillazg/go-pinyin" "gorm.io/gorm/clause" ) @@ -212,3 +215,165 @@ func TestPageTimeTask() { // var countPages int64 // overall.CONSTANT_DB_Tidb.Model(&modelsschool.TestPaper{}).Select("tp_id").Count(&countPages) } + +type canshuzhi interface{} + +// 接收参数 +func (A *ApiMethod) Canshu(c *gin.Context) { + // var zhi canshuzhi + zhi, _ := c.GetRawData() + + fmt.Printf("%T------------->%v\n", zhi, string(zhi)) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-05 08:38:58 +@ 功能: 模拟创建表单 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) CreateTable(c *gin.Context) { + var requestData publicmethod.CommonId[int64] + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + var customerFormCont modelAppPlatform.CustomerFormView + err = customerFormCont.GetCont(map[string]interface{}{"cfid": requestData.Id, "`status`": 1}) + if err != nil { + publicmethod.Result(107, err, c) + return + } + var formJsonCont customerform.CustomerFormMaster + json.Unmarshal([]byte(customerFormCont.MastesFormJson), &formJsonCont) + mastSql, _ := formJsonCont.DisassembleForm() + var formVersionCont modelAppPlatform.CustomerFormVersion + formVersionCont.EiteCont(map[string]interface{}{"id": customerFormCont.Id}, map[string]interface{}{"table_structure": mastSql, "edit_time": time.Now().Unix()}) + publicmethod.Result(0, mastSql, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-08 09:24:00 +@ 功能: 改革自定义表单列表 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) QianyiVersion(c *gin.Context) { + var list []modelAppPlatform.CustomerForm + err := overall.CONSTANT_DB_AppPlatform.Find(&list).Error + if err != nil { + return + } + for _, v := range list { + var versionCont modelAppPlatform.CustomerFormVersion + versionCont.TableKey = v.TableNames //default:'';not null;comment:表单标识符"` + versionCont.Version = 1 //1;not null;comment:版本号"` + versionCont.Status = 1 //not null;comment:显示状态(1:启用;2:禁用,3:删除)"` + // versionCont.MastesForm = v.MastesForm //';comment:表单结构"` + // versionCont.MastesFormJson = v.MastesFormJson //efault:'';comment:表单结构json"` + // versionCont.Creater = v.Creater //ult:0;not null;comment:创建人"` + versionCont.CreaterTime = v.CreaterTime //not null;comment:创建时间"` + versionCont.EditTime = v.EditTime //efault:0;not null;comment:编辑时间"` + // versionCont.TableStructure = v.TableStructure //;default:'';comment:字表结构"` + // versionCont.Dict = v.Dict //字表结构"` + overall.CONSTANT_DB_AppPlatform.Create(&versionCont) + } +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-13 13:13:13 +@ 功能: 查询表结构 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) LookTableStruct(c *gin.Context) { + var requestData publicmethod.CommonId[int64] + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Id == 0 { + publicmethod.Result(107, err, c) + return + } + var versionCont modelAppPlatform.CustomerFormVersion + err = versionCont.GetCont(map[string]interface{}{"`id`": requestData.Id}) + if err != nil { + publicmethod.Result(107, err, c) + return + } + + formStruct, err := customerform.ReadDatabaseForm(versionCont.TableKey) + publicmethod.Result(107, formStruct, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-26 11:34:53 +@ 功能: 汉字转拼音 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) HanZiZhuanPinYin(c *gin.Context) { + var requestData publicmethod.PublicName + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Name == "" { + publicmethod.Result(107, err, c) + return + } + pyObject := pinyin.NewArgs() + // pyObject.Heteronym =true + pyObject.Style = pinyin.Tone3 + pyObject.Separator = "" + str := pinyin.Slug(requestData.Name, pyObject) + publicmethod.Result(0, str, c) +} diff --git a/api/version1/customerform/analysis_table.go b/api/version1/customerform/analysis_table.go new file mode 100644 index 0000000..9e3febc --- /dev/null +++ b/api/version1/customerform/analysis_table.go @@ -0,0 +1,483 @@ +package customerform + +import ( + "appPlatform/overall/publicmethod" + "fmt" + "strconv" +) + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-26 15:34:07 +@ 功能: +@ 参数 + + #分析表格 + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func AnalysisTable(subUnit MasterStruct) (fieldCont TableFormStruct) { + //TableFormStruct + fieldCont.TableName = subUnit.Name + switch subUnit.Type { + case "datePicker": + switch subUnit.Control.Type { + case "year", "month", "date", "datetime": + + fieldCont.Types = "bigint" + fieldCont.ControlType = subUnit.Control.Type + fieldCont.DefaultValue = 0 + fieldCont.FieldLenght = 20 + + case "week": + + fieldCont.Types = "varchar" + fieldCont.ControlType = subUnit.Control.Type + fieldCont.DefaultValue = "" + fieldCont.ControlType = "string" + fieldCont.FieldLenght = 255 + + case "datetimerange", "daterange", "monthrange": + + fieldCont.Types = "bigint" + fieldCont.ControlType = "array" + fieldCont.DefaultValue = 0 + fieldCont.FieldLenght = 20 + + default: + + fieldCont.Types = "mediumtext" + fieldCont.ControlType = subUnit.Control.Type + fieldCont.DefaultValue = "" + fieldCont.ControlType = "string" + + } + case "input", "password": + if len(subUnit.CustomRules) > 0 { + zdType, signed := CustomRulesInput(subUnit.CustomRules) + fieldCont.Types = zdType + fieldCont.Signed = signed + switch zdType { + case "float": + fieldCont.DefaultValue = 0 + fieldCont.FieldLenght = 20 + fieldCont.ControlType = "float" + case "decimal": + fieldCont.DefaultValue = 0 + fieldCont.FieldLenght = 20 + fieldCont.ControlType = "decimal" + case "bigint": + fieldCont.DefaultValue = 0 + fieldCont.FieldLenght = 20 + fieldCont.ControlType = "bigint" + case "int": + fieldCont.DefaultValue = 0 + fieldCont.FieldLenght = 6 + fieldCont.ControlType = "int" + default: + fieldCont.DefaultValue = "" + fieldCont.FieldLenght = 255 + fieldCont.ControlType = "string" + } + } else { + fieldCont.Types = "varchar" + fieldCont.DefaultValue = "" + fieldCont.FieldLenght = 255 + fieldCont.ControlType = "string" + } + + case "textarea", "cascader": + + fieldCont.Types = "mediumtext" + fieldCont.DefaultValue = "" + fieldCont.ControlType = "string" + + case "radio", "select": + var fieldVal string + if len(subUnit.Options) > 0 { + for _, ov := range subUnit.Options { + if len(fieldVal) < len(ov.Value) { + fieldVal = ov.Value + } + } + } + if subUnit.Config.TransformData == "number" { + size, fieldType := CalculateCharacterLength("int", fieldVal) + + fieldCont.Types = fieldType + fieldCont.DefaultValue = 0 + fieldCont.FieldLenght = size + fieldCont.ControlType = fieldType + + } else { + size, fieldType := CalculateCharacterLength("string", fieldVal) + + fieldCont.Types = fieldType + fieldCont.DefaultValue = "" + fieldCont.FieldLenght = size + fieldCont.ControlType = "string" + + } + case "checkbox": + + fieldCont.Types = "mediumtext" + fieldCont.DefaultValue = "" + fieldCont.ControlType = "array" + + case "colorPicker", "timePicker": + + fieldCont.Types = "varchar" + fieldCont.DefaultValue = "" + fieldCont.FieldLenght = 50 + fieldCont.ControlType = "string" + + case "switch": + var fieldVal string + if len(subUnit.Control.ActiveValue) < len(subUnit.Control.InactiveValue) { + fieldVal = subUnit.Control.InactiveValue + } else { + fieldVal = subUnit.Control.ActiveValue + } + size, fieldType := CalculateCharacterLength("int", fieldVal) + + fieldCont.Types = fieldType + fieldCont.ControlType = "booble" + fieldCont.DefaultValue, _ = strconv.Atoi(subUnit.Control.ActiveValue) + fieldCont.FieldLenght = size + + case "inputNumber": + + fieldCont.Types = "bigint" + fieldCont.DefaultValue = 0 + fieldCont.FieldLenght = 20 + fieldCont.ControlType = "bigint" + + case "rate", "slider": + fieldVal := strconv.Itoa(subUnit.Control.Max) + size, fieldType := CalculateCharacterLength("int", fieldVal) + + fieldCont.Types = fieldType + fieldCont.ControlType = fieldType + if scm, scmIsok := subUnit.Control.ModelValue.(int); scmIsok { + fieldCont.DefaultValue = scm + } + fieldCont.FieldLenght = size + + case "treeSelect": + case "upload": + + fieldCont.Types = "longtext" + fieldCont.DefaultValue = "" + fieldCont.ControlType = "array" //返回值为数组 + + case "tinymce", "expand-user": + + fieldCont.Types = "longtext" + fieldCont.DefaultValue = "" + fieldCont.ControlType = "string" + case "grid", "tabs", "card", "div", "table", "flex", "divider": + default: + + fieldCont.Types = "varchar" + fieldCont.DefaultValue = "" + fieldCont.FieldLenght = 255 + fieldCont.ControlType = "string" + + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-27 09:28:33 +@ 功能: 文本框校验规则 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func CustomRulesInput(list []CustomRulesStruct) (types string, signed bool) { + if len(list) == 0 { + types = "varchar" + return + } + var typeAry []string + for _, v := range list { + if !publicmethod.IsInTrue[string](v.Type, typeAry) { + typeAry = append(typeAry, v.Type) + } + } + if len(typeAry) == 0 { + types = "varchar" + return + } + stringType := []string{"mobile", "tel", "phone", "email", "card", "cn", "numberLetter", "网址"} + moneyType := []string{"money"} + floatType := []string{"longitude", "latitude"} + zhengZs := []string{"int"} + numberType := []string{"number"} + for _, tv := range typeAry { + if publicmethod.IsInTrue[string](tv, floatType) { + types = "float" + return + } + if publicmethod.IsInTrue[string](tv, moneyType) { + types = "decimal" + return + } + if publicmethod.IsInTrue[string](tv, numberType) { + types = "bigint" + signed = true + return + } + if publicmethod.IsInTrue[string](tv, zhengZs) { + types = "int" + return + } + if publicmethod.IsInTrue[string](tv, stringType) { + types = "varchar" + return + } + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-26 16:28:16 +@ 功能: 计算字符长度 +@ 参数 + + #class 类型 + #str 值 + +@ 返回值 + + #size 字段长度 + #fieldType 字段类型 + +@ 方法原型 + + #func CalculateCharacterLength(class, str string) (size int, fieldType string) +*/ +func CalculateCharacterLength(class, str string) (size int, fieldType string) { + size = len(str) + 1 + switch class { + case "int": + if size <= 9 { + fieldType = "int" + } else { + fieldType = "bigint" + } + case "string": + if size <= 255 { + fieldType = "varchar" + } else { + fieldType = "mediumtext" + } + default: + fieldType = "varchar" + size = 255 + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-27 08:52:56 +@ 功能: 创建自定义表单数据表 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (c *CustomerFormMaster) CreateFormDatabaseTable() (relevance string, err error) { + err = CreateForm(c.Form.Name, c.Form.FormName, true) //创建主表 + if err != nil { + return + } + var masterSql []string //主数据库添加字段语句集合 + var sunFormName []string //子表名称集合 + sunFormNameAry := publicmethod.MapOut[string]() //子表对应关系 + sunForm := publicmethod.MapOut[string]() + for _, v := range c.List { + + switch v.Type { + case "grid", "tabs": + if len(v.Columns) > 0 { + for _, cv := range v.Columns { + // fmt.Printf("type:%v <===========>label:%v <===========> Name:%v<===========> ModelValue:%v\n", v.Type, cv.Attr.Span, cv.Type, v.Control.ModelValue) + sqlStr := VesselSubUnitConvertSql(c.Form.Name, cv.List) + if len(sqlStr) > 0 { + masterSql = append(masterSql, sqlStr...) + } + + } + } + case "card", "div": + if len(v.List) > 0 { + sqlStr := VesselSubUnitConvertSql(c.Form.Name, v.List) + if len(sqlStr) > 0 { + masterSql = append(masterSql, sqlStr...) + } + } + case "table", "flex": + if len(v.List) > 0 { + if !publicmethod.IsInTrue[string](v.Name, sunFormName) { + sunFormName = append(sunFormName, v.Name) + sunFormNameAry[v.Name] = v.Name + sqlStr := VesselSubUnitConvertSql(v.Name, v.List) + sunForm[v.Name] = sqlStr + CreateForm(v.Name, fmt.Sprintf("%v(%v)子表", c.Form.FormName, c.Form.Name), false) + } else { + sunTableName := fmt.Sprintf("%v%v", v.Name, publicmethod.GetUUid(1)) + sunFormName = append(sunFormName, sunTableName) + sunFormNameAry[v.Name] = sunTableName + sqlStr := VesselSubUnitConvertSql(sunTableName, v.List) + sunForm[sunTableName] = sqlStr + CreateForm(sunTableName, fmt.Sprintf("%v(%v)子表", c.Form.FormName, c.Form.Name), false) + } + } + default: + sqlMasterStr := SubUnitConvertSql(c.Form.Name, v) + if sqlMasterStr != "not" { + masterSql = append(masterSql, sqlMasterStr) + } + // masterSql = append(masterSql, SubUnitConvertSql(c.Form.Name, v)) + // fielfInfoClass := AnalysisTable(v) + // unsigned := "" + // if !fielfInfoClass.Signed { + // unsigned = "unsigned" + // } + // switch fielfInfoClass.Types { + // case "int", "bigint": + // masterSql = append(masterSql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v(%v) %v NOT NULL DEFAULT %v COMMENT '%v'", c.Form.Name, v.Name, fielfInfoClass.Types, fielfInfoClass.FieldLenght, unsigned, fielfInfoClass.DefaultValue, v.Item.Label)) + // case "booble": + // masterSql = append(masterSql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v(1) %v NOT NULL DEFAULT %v COMMENT '%v'", c.Form.Name, v.Name, fielfInfoClass.Types, unsigned, fielfInfoClass.DefaultValue, v.Item.Label)) + // case "float": + // masterSql = append(masterSql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v(%v,%v) %v NOT NULL DEFAULT %v COMMENT '%v'", c.Form.Name, v.Name, fielfInfoClass.Types, fielfInfoClass.FieldLenght, fielfInfoClass.FieldLenght, unsigned, fielfInfoClass.DefaultValue, v.Item.Label)) + // case "decimal": + // masterSql = append(masterSql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v(%v,2) %v NOT NULL DEFAULT %v COMMENT '%v'", c.Form.Name, v.Name, fielfInfoClass.Types, fielfInfoClass.FieldLenght, unsigned, fielfInfoClass.DefaultValue, v.Item.Label)) + // case "mediumtext", "longtext": + // masterSql = append(masterSql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v COMMENT '%v'", c.Form.Name, v.Name, fielfInfoClass.Types, v.Item.Label)) + // default: + // masterSql = append(masterSql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v(%v) COLLATE utf8mb4_general_ci NOT NULL DEFAULT %v COMMENT '%v'", c.Form.Name, v.Name, fielfInfoClass.Types, fielfInfoClass.FieldLenght, fielfInfoClass.DefaultValue, v.Item.Label)) + // } + } + } + // if len(masterSql) > 0 { + // CreateFormFiled(c.Form.Name, c.Form.FormName, true, masterSql) //添加主表字段 + // } + // if len(sunForm) > 0 { //子表操作 + // relevanceByte, _ := json.Marshal(sunFormNameAry) + // relevance = string(relevanceByte) + // for i, v := range sunForm { + // // fmt.Printf("表单结构----拆解----》%v========>%v\n", i, v) + // CreateFormFiled(i, fmt.Sprintf("%v(%v)子表", c.Form.FormName, c.Form.Name), false, v) + // } + // } + fmt.Printf("主表数据:%v\n", masterSql) + fmt.Printf("子表表数据:%v\n", sunForm) + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-27 11:04:39 +@ 功能: 容器组件生成数据库字段语句 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func VesselSubUnitConvertSql(tableName string, list []MasterStruct) (mastSql []string) { + if len(list) > 0 { + for _, v := range list { + sqlStr := SubUnitConvertSql(tableName, v) + if sqlStr != "not" { + mastSql = append(mastSql, sqlStr) + } + + } + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-27 10:30:25 +@ 功能: 单一组件转换Sql语句 +@ 参数 + + #tablename 表单名称 + #subUnit 第一组件结构体 + +@ 返回值 + + #sql 数据库字段添加语句 + +@ 方法原型 + + #func SubUnitConvertSql(tablename string, subUnit MasterStruct) (sql string) +*/ +func SubUnitConvertSql(tablename string, subUnit MasterStruct) (sql string) { + if tablename == "" { + sql = "not" + return + } + fielfInfoClass := AnalysisTable(subUnit) + unsigned := "" + if !fielfInfoClass.Signed { + unsigned = "unsigned" + } + switch fielfInfoClass.Types { + case "int", "bigint": + sql = fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v(%v) %v NOT NULL DEFAULT %v COMMENT '%v'", tablename, subUnit.Name, fielfInfoClass.Types, fielfInfoClass.FieldLenght, unsigned, fielfInfoClass.DefaultValue, subUnit.Item.Label) + case "booble": + sql = fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v(1) %v NOT NULL DEFAULT %v COMMENT '%v'", tablename, subUnit.Name, fielfInfoClass.Types, unsigned, fielfInfoClass.DefaultValue, subUnit.Item.Label) + case "float": + sql = fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v(%v,%v) %v NOT NULL DEFAULT %v COMMENT '%v'", tablename, subUnit.Name, fielfInfoClass.Types, fielfInfoClass.FieldLenght, fielfInfoClass.FieldLenght, unsigned, fielfInfoClass.DefaultValue, subUnit.Item.Label) + case "decimal": + sql = fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v(%v,2) %v NOT NULL DEFAULT %v COMMENT '%v'", tablename, subUnit.Name, fielfInfoClass.Types, fielfInfoClass.FieldLenght, unsigned, fielfInfoClass.DefaultValue, subUnit.Item.Label) + case "mediumtext", "longtext": + sql = fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v COMMENT '%v'", tablename, subUnit.Name, fielfInfoClass.Types, subUnit.Item.Label) + default: + if fielfInfoClass.Types != "" { + sql = fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v(%v) COLLATE utf8mb4_general_ci NOT NULL DEFAULT %v COMMENT '%v'", tablename, subUnit.Name, fielfInfoClass.Types, fielfInfoClass.FieldLenght, fielfInfoClass.DefaultValue, subUnit.Item.Label) + } + } + return +} diff --git a/api/version1/customerform/datatable.go b/api/version1/customerform/datatable.go new file mode 100644 index 0000000..f575fe7 --- /dev/null +++ b/api/version1/customerform/datatable.go @@ -0,0 +1,614 @@ +package customerform + +import ( + "appPlatform/models/modelAppPlatform" + "appPlatform/overall" + "appPlatform/overall/publicmethod" + "encoding/json" + "fmt" + "strconv" + "strings" + + "github.com/gin-gonic/gin" +) + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-13 13:02:23 +@ 功能: 数据库表结构 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) HaveDataBaseTableStruct(c *gin.Context) { + var requestData publicmethod.CommonId[string] + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Id == "" { + publicmethod.Result(101, err, c) + return + } + //获取自定义表单设置主表信息 + var customerFormCont modelAppPlatform.CustomerForm + err = customerFormCont.GetCont(map[string]interface{}{"`id`": requestData.Id}, "`id`", "`tablename`") + if err != nil { + publicmethod.Result(107, err, c) + return + } + var versionInfo []modelAppPlatform.CustomerFormVersion + err = overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.CustomerFormVersion{}).Select("`id`,`tablekey`,`status`,`version`,`table_structure`").Where("`tablekey` = ? AND `status` BETWEEN ? AND ?", customerFormCont.TableNames, 1, 2).Order("status asc").Order("version asc").Order("id desc").Find(&versionInfo).Error + if err != nil { + publicmethod.Result(107, err, c) + return + } + + var sunFormStr string + var versionIdStr string + var sendCont CustomerFormDatabaseVesion + if len(versionInfo) > 0 { + for _, v := range versionInfo { + var versionCont PublicFormDatabaseVesion + versionCont.Id = requestData.Id + versionCont.VersionId = strconv.FormatInt(v.Id, 10) + versionCont.Name = fmt.Sprintf("V%v", v.Version) + if v.Status == 1 { + versionCont.IsMain = true + sunFormStr = v.TableStructure + versionIdStr = strconv.FormatInt(v.Id, 10) + //主表单数据 + var masterFormTable PublicFormDatabaseVesion + masterFormTable.Id = requestData.Id + masterFormTable.VersionId = versionIdStr + masterFormTable.Name = v.TableKey + masterFormTable.IsMain = true + if num := HaveTableLog(v.TableKey); num > 0 { + masterFormTable.IsEdit = false + } else { + masterFormTable.IsEdit = true + } + sendCont.TableList = append(sendCont.TableList, masterFormTable) + } else { + versionCont.IsMain = false + } + + sendCont.Version = append(sendCont.Version, versionCont) + } + } + if sunFormStr != "" { + sunSqlMap := make(map[string]string) + json.Unmarshal([]byte(sunFormStr), &sunSqlMap) + if len(sunSqlMap) > 0 { + for _, s := range sunSqlMap { + var sunFromTableCont PublicFormDatabaseVesion + sunFromTableCont.Id = requestData.Id + sunFromTableCont.VersionId = versionIdStr + sunFromTableCont.Name = s + sunFromTableCont.IsMain = false + if num := HaveTableLog(s); num > 0 { + sunFromTableCont.IsEdit = false + } else { + sunFromTableCont.IsEdit = true + } + sendCont.TableList = append(sendCont.TableList, sunFromTableCont) + } + } + } + publicmethod.Result(0, sendCont, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-13 14:34:04 +@ 功能: 获取表格是否有记录 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func HaveTableLog(tableName string) (logCount int64) { + err := overall.CONSTANT_DB_CustomerForm.Table(tableName).Select("`id`").First(&logCount).Error + if err != nil { + logCount = 0 + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-13 13:03:11 +@ 功能: 读取数据表结构 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func ReadDatabaseForm(tableName string, tableType ...string) (list []Result, err error) { + tableTypes := "" + if len(tableType) > 0 { + tableTypes = tableType[0] + } + gormDb := overall.CONSTANT_DB_CustomerForm + switch tableTypes { + default: + gormDb = overall.CONSTANT_DB_CustomerForm + } + // sqlStr := fmt.Sprintf("DESC %v", tableName) + sqlStr := fmt.Sprintf("SHOW FULL COLUMNS FROM `%v`", tableName) + err = gormDb.Raw(sqlStr).Scan(&list).Error + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-13 15:25:03 +@ 功能: 获取表单结构{"table1693810889577":"table1693810889577","table1693811003658":"table1693811003658","table1693811044212":"table1693811044212"} +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) HaveFormTabelCont(c *gin.Context) { + var requestData HaveVersionForm + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Id == "" { + publicmethod.Result(101, err, c) + return + } + if requestData.Name == "" { + publicmethod.Result(101, err, c) + return + } + //获取自定义表单设置主表信息 + var versionCont modelAppPlatform.CustomerFormVersion + err = versionCont.GetCont(map[string]interface{}{"`id`": requestData.Id}, "`tablekey`", "`mastesformjson`", "`table_structure`") + if err != nil { + publicmethod.Result(107, err, c) + return + } + var formJsonCont CustomerFormMaster + err = json.Unmarshal([]byte(versionCont.MastesFormJson), &formJsonCont) + + masterForm, sunForm := AnalyseFormTableJson(formJsonCont) + formStruct, err := ReadDatabaseForm(requestData.Name) + if err != nil { + publicmethod.Result(107, err, c) + return + } + fmt.Printf("%s\n", masterForm) + sendMap := make(map[string]interface{}) + // sendMap["masterForm"] = masterForm + // sendMap["sunForm"] = sunForm + // sendMap["formStruct"] = formStruct + + // sendMap["err"] = err + // sendMap["formJsonCont"] = formJsonCont + + var filedList []Result + if requestData.Name == versionCont.TableKey { + for _, v := range formStruct { + if publicmethod.IsInTrue[string](v.Field, masterForm) { + attFiled := strings.Split(v.Type, " ") + if len(attFiled) >= 2 { + v.Attribute = attFiled[1] + v.Type = attFiled[0] + } + // fmt.Printf("attFiled--->%v--->%v\n", attFiled, len(attFiled)) + filedList = append(filedList, v) + } + // attFiled := strings.Split(v.Type, " ") + // if len(attFiled) >= 2 { + // v.Attribute = attFiled[1] + // v.Type = attFiled[0] + // } + // // fmt.Printf("attFiled--->%v--->%v\n", attFiled, len(attFiled)) + // filedList = append(filedList, v) + } + } else { + if fieldAry, isOk := sunForm[requestData.Name]; isOk { + for _, v := range formStruct { + if publicmethod.IsInTrue[string](v.Field, fieldAry.([]string)) { + attFiled := strings.Split(v.Type, " ") + if len(attFiled) >= 2 { + v.Attribute = attFiled[1] + v.Type = attFiled[0] + } + filedList = append(filedList, v) + } + } + } + } + sendMap["filedlist"] = filedList + if num := HaveTableLog(requestData.Name); num > 0 { + sendMap["isedit"] = false + } else { + sendMap["isedit"] = true + } + publicmethod.Result(0, sendMap, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-13 15:38:42 +@ 功能: 根据版本获取数据库表集合 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) HaveFormTableList(c *gin.Context) { + var requestData publicmethod.CommonId[string] + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Id == "" { + publicmethod.Result(101, err, c) + return + } + //获取自定义表单设置主表信息 + var versionCont modelAppPlatform.CustomerFormVersion + err = versionCont.GetCont(map[string]interface{}{"`id`": requestData.Id}, "`id`", "`tablekey`", "`status`", "`version`", "`table_structure`") + if err != nil { + publicmethod.Result(107, err, c) + return + } + var customerFormCont modelAppPlatform.CustomerForm + err = customerFormCont.GetCont(map[string]interface{}{"`tablename`": versionCont.TableKey}, "`id`") + if err != nil { + publicmethod.Result(107, err, c) + return + } + formId := strconv.FormatInt(customerFormCont.Id, 10) + var sendAry []PublicFormDatabaseVesion + var masterFormTable PublicFormDatabaseVesion + masterFormTable.Id = formId + masterFormTable.VersionId = requestData.Id + masterFormTable.Name = versionCont.TableKey + masterFormTable.IsMain = true + if num := HaveTableLog(versionCont.TableKey); num > 0 { + masterFormTable.IsEdit = false + } else { + masterFormTable.IsEdit = true + } + sendAry = append(sendAry, masterFormTable) + if versionCont.TableStructure != "" { + sunSqlMap := make(map[string]string) + json.Unmarshal([]byte(versionCont.TableStructure), &sunSqlMap) + if len(sunSqlMap) > 0 { + for _, s := range sunSqlMap { + var sunFromTableCont PublicFormDatabaseVesion + sunFromTableCont.Id = formId + sunFromTableCont.VersionId = requestData.Id + sunFromTableCont.Name = s + sunFromTableCont.IsMain = false + if num := HaveTableLog(s); num > 0 { + sunFromTableCont.IsEdit = false + } else { + sunFromTableCont.IsEdit = true + } + sendAry = append(sendAry, sunFromTableCont) + } + } + } + publicmethod.Result(0, sendAry, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-13 15:57:13 +@ 功能: 拆析版本表单 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func AnalyseFormTableJson(formJsonCont CustomerFormMaster) (masterForm []string, sunForm map[string]interface{}) { + dataMap := make(map[string]interface{}) + fieldType := []string{"input", "password", "colorPicker", "component", "datePicker", "checkbox", "cascader", "treeSelect", "textarea", "upload", "expand-user", "select", "radio", "inputSlot", "rate", "inputNumber", "slider", "switch", "tinymce"} + cardFieldType := []string{"card"} + customLayout := []string{"grid", "tabs"} + sunFieldType := []string{"table", "flex"} + for _, v := range formJsonCont.List { + + if publicmethod.IsInTrue[string](v.Type, fieldType) { + masterForm = append(masterForm, v.Name) + } + //卡片数据 + if publicmethod.IsInTrue[string](v.Type, cardFieldType) { + if len(v.List) > 0 { + sqlStr := ComponentMappingDataTableField(v.List) + masterForm = append(masterForm, sqlStr...) + } + } + //自定义布局 + if publicmethod.IsInTrue[string](v.Type, customLayout) { + if len(v.Columns) > 0 { + for _, cv := range v.Columns { + sqlStr := ComponentMappingDataTableField(cv.List) + masterForm = append(masterForm, sqlStr...) + } + } + } + //子表 + if publicmethod.IsInTrue[string](v.Type, sunFieldType) { + if len(v.List) > 0 { + sqlStr := ComponentMappingDataTableField(v.List) + dataMap[v.Name] = sqlStr + } + } + } + sunForm = dataMap + return +} + +/** +@ 作者: 秦东 +@ 时间: 2023-09-13 16:14:07 +@ 功能: 组件印射字段 +@ 参数 + # +@ 返回值 + # +@ 方法原型 + # +*/ + +func ComponentMappingDataTableField(list []MasterStruct) (mastSql []string) { + if len(list) > 0 { + for _, lv := range list { + fieldType := []string{"input", "password", "colorPicker", "component", "datePicker", "checkbox", "cascader", "treeSelect", "textarea", "upload", "expand-user", "select", "radio", "inputSlot", "rate", "inputNumber", "slider", "switch", "tinymce"} + if publicmethod.IsInTrue[string](lv.Type, fieldType) { + mastSql = append(mastSql, lv.Name) + } + } + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-14 09:01:40 +@ 功能: 优化/修复数据表 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) OptimizeOrRepairFormTable(c *gin.Context) { + var requestData OptimizeOrRepairTable + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Name == "" { + publicmethod.Result(101, err, c) + return + } + + if requestData.OptimizeOrRepair == 1 { //优化表 + sqlStr := fmt.Sprintf("OPTIMIZE TABLE %v", requestData.Name) + overall.CONSTANT_DB_CustomerForm.Exec(sqlStr) + } else { //修复表 + sqlStr1 := fmt.Sprintf("CHECK TABLE %v", requestData.Name) + overall.CONSTANT_DB_CustomerForm.Exec(sqlStr1) + sqlStr2 := fmt.Sprintf("REPAIR TABLE %v", requestData.Name) + overall.CONSTANT_DB_CustomerForm.Exec(sqlStr2) + } + publicmethod.Result(0, err, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-14 11:50:30 +@ 功能: 表单结构数据处理 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) FormFieldHandle(c *gin.Context) { + var requestData Result + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + var sendForm SendFieldCont + sendForm.Field = requestData.Field + sendForm.Type = requestData.Type + sendForm.Attribute = requestData.Attribute + sendForm.Collation = requestData.Collation + sendForm.Null = requestData.Null + sendForm.Key = requestData.Key + sendForm.Default = requestData.Default + sendForm.Extra = requestData.Extra + sendForm.Privileges = requestData.Privileges + sendForm.Comment = requestData.Comment + if requestData.Type == "" { + sendForm.Type = "varchar" + } else { + attFiled := strings.Split(requestData.Type, "(") + sendForm.Type = attFiled[0] + if len(attFiled) > 1 { + fieldLenght := publicmethod.MatchBracket(requestData.Type, "(", ")") + switch sendForm.Type { + case "decimal", "float", "double": + maxAndMin := strings.Split(fieldLenght, ",") + switch len(maxAndMin) { + case 1: + sendForm.Integer = maxAndMin[0] + case 2: + sendForm.Integer = maxAndMin[0] + sendForm.Decimal = maxAndMin[1] + default: + } + + default: + sendForm.Integer = fieldLenght + } + } + } + publicmethod.Result(0, sendForm, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-14 15:43:03 +@ 功能: 编辑数据库表字段信息 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) EditFormField(c *gin.Context) { + var requestData EditDatabaseFormField + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.FormName == "" || requestData.Field == "" { + publicmethod.Result(101, err, c) + return + } + sqlStr := fmt.Sprintf("ALTER TABLE `%v` MODIFY COLUMN `%v` ", requestData.FormName, requestData.Field) + switch requestData.Type { + case "decimal", "float", "double": + var integerIntVal int64 + if requestData.Integer == "" { + integerIntVal = 3 + } else { + integerInt, err := strconv.ParseInt(requestData.Integer, 10, 64) + if err == nil { + integerIntVal = integerInt + } + } + decimalVal := integerIntVal - 1 + if requestData.Decimal != "" { + decimalVales, err := strconv.ParseInt(requestData.Decimal, 10, 64) + if err == nil { + decimalVal = decimalVales + } + + } + if decimalVal == 0 { + decimalVal = integerIntVal + } + sqlStr = fmt.Sprintf(" %v %v(%v,%v) ", sqlStr, requestData.Type, integerIntVal, decimalVal) + case "tinyint", "smallint", "mediumint", "int", "integer", "bigint": + var integerIntVal int64 + if requestData.Integer == "" { + integerIntVal = 3 + } else { + integerInt, err := strconv.ParseInt(requestData.Integer, 10, 64) + if err == nil { + integerIntVal = integerInt + } + } + sqlStr = fmt.Sprintf(" %v %v(%v) %v ", sqlStr, requestData.Type, integerIntVal, requestData.Attribute) + case "enum", "set", "text", "tinytext", "mediumtext", "longtext", "blob", "year", "date", "time", "datetime", "timestamp": + sqlStr = fmt.Sprintf(" %v %v ", sqlStr, requestData.Type) + default: + if requestData.Integer != "" { + sqlStr = fmt.Sprintf(" %v %v(%v) ", sqlStr, requestData.Type, requestData.Integer) + } else { + sqlStr = fmt.Sprintf(" %v %v ", sqlStr, requestData.Type) + } + + } + if requestData.Null == "NO" { + sqlStr = fmt.Sprintf(" %v NOT NULL ", sqlStr) + } + if !publicmethod.IsInTrue[string](requestData.Type, []string{"enum", "set", "text", "tinytext", "mediumtext", "longtext", "blob", "year", "date", "time", "datetime", "timestamp"}) { + sqlStr = fmt.Sprintf(" %v DEFAULT '%v'", sqlStr, requestData.Default) + } + sqlStr = fmt.Sprintf(" %v COMMENT '%v'", sqlStr, requestData.Comment) + err = publicmethod.ExecSql("CustomerForm", sqlStr) + if err != nil { + publicmethod.Result(106, err, c) + return + } + publicmethod.Result(0, err, c) +} diff --git a/api/version1/customerform/form.go b/api/version1/customerform/form.go new file mode 100644 index 0000000..275e4f8 --- /dev/null +++ b/api/version1/customerform/form.go @@ -0,0 +1,1165 @@ +package customerform + +import ( + "appPlatform/models/modelAppPlatform" + "appPlatform/models/modelshr" + "appPlatform/overall" + "appPlatform/overall/publicmethod" + "encoding/json" + "fmt" + "strconv" + "strings" + "time" + + "github.com/gin-gonic/gin" +) + +/* +* +@ 作者: 秦东 +@ 时间: 2023-08-28 16:19:38 +@ 功能: 自定义表单列表 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) CustomerFormList(c *gin.Context) { + var requestData SearchForm + ersr := c.ShouldBindJSON(&requestData) + if requestData.Page == 0 { + requestData.Page = 1 + } + if requestData.PageSize == 0 { + requestData.PageSize = 15 + } + fmt.Printf("requestData---->%v---->%v\n", requestData, ersr) + var formList []modelAppPlatform.CustomerForm + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.CustomerForm{}).Select("`id`,`name`,`tablename`,`classify`,`permit`,`states`,`creater_time`").Where("`states` BETWEEN ? AND ?", 1, 2) + if requestData.KeyWords != "" { + gormDb = gormDb.Where("`name` LIKE ? OR `tablename` LIKE ?", "%"+requestData.KeyWords+"%", "%"+requestData.KeyWords+"%") + } + if requestData.Classify != 0 { + gormDb = gormDb.Where("`classify` = ?", requestData.Classify) + } + var total int64 + totalErr := gormDb.Count(&total).Error + if totalErr != nil { + total = 0 + } + gormDb = publicmethod.PageTurningSettings(gormDb, requestData.Page, requestData.PageSize) + err := gormDb.Order("`id` DESC").Find(&formList).Error + if err != nil && len(formList) < 1 { + publicmethod.Result(0, err, c) + return + } + var sendList []SendCustomerForm + for _, v := range formList { + var sendCont SendCustomerForm + sendCont.Id = strconv.FormatInt(v.Id, 10) + sendCont.Name = v.Name + sendCont.TableNames = v.TableNames + sendCont.States = v.States + sendCont.Classify = v.Classify + userCont := HaveCustomerFormCreaterUs(v.TableNames) + sendCont.CreaterName = userCont.Name + sendCont.CreaterTime = publicmethod.UnixTimeToDay(v.CreaterTime, 1) + sendList = append(sendList, sendCont) + } + publicmethod.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(sendList)), sendList, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-08 11:03:19 +@ 功能: 获取启用自定义表单创建人 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func HaveCustomerFormCreaterUs(tableKey string) (userCont modelshr.PersonArchives) { + var formVersion modelAppPlatform.CustomerFormVersion + err := formVersion.GetCont(map[string]interface{}{"`tablekey`": tableKey}, "`creater`") + if err != nil { + return + } + userCont.GetCont(map[string]interface{}{"`key`": formVersion.Creater}, "`name`", "`number`") + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-08-29 13:16:12 +@ 功能: 生成表单基本信息 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) ProductionMarkOfCustomerForm(c *gin.Context) { + uuid := publicmethod.GetUUid(1) + tableName := fmt.Sprintf("customer_form_%v", uuid) + for { + isTrue := overall.CONSTANT_DB_CustomerForm.Migrator().HasTable(tableName) + if !isTrue { + break + } else { + uuid = publicmethod.GetUUid(1) + tableName = fmt.Sprintf("customer_form_%v", uuid) + } + } + var sendCont SendCustomerFormConfig + sendCont.FormName = fmt.Sprintf("未命名表单_%v", uuid) + sendCont.FormLogo = tableName + publicmethod.Result(0, sendCont, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-08-29 15:21:58 +@ 功能: 保存自定义表单 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) SaveCustomerForm(c *gin.Context) { + context, _ := c.Get(overall.MyContJwt) + var requestData HaveCustomerFormConfig + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Data == "" { + publicmethod.Result(1, err, c, "自定义表单错误!") + return + } + if requestData.Name == "" { + publicmethod.Result(1, err, c, "未知表单名称!") + return + } + if requestData.Classify == 0 { + requestData.Classify = 1 + } + var formJsonCont CustomerFormMaster + json.Unmarshal([]byte(requestData.JsonData), &formJsonCont) + + if formJsonCont.Form.FormName == "" { + publicmethod.Result(1, err, c, "未知表单名称!") + return + } + if formJsonCont.Form.Name == "" { + publicmethod.Result(1, err, c, "未知表单标识!") + return + } + var userCont modelshr.ManCont + userCont.GetLoginCont(context) + cureeTime := time.Now().Unix() + var customerFormCont modelAppPlatform.CustomerForm + err = customerFormCont.GetCont(map[string]interface{}{"`tablename`": formJsonCont.Form.Name}, "`id`") + if err == nil || customerFormCont.Id != 0 { + publicmethod.Result(1, err, c, "已有相同表单标识!请更换后再提交!") + return + } + customerFormCont.Name = formJsonCont.Form.FormName //表单名称"` + customerFormCont.TableNames = formJsonCont.Form.Name //创建表单名称"` + customerFormCont.Classify = requestData.Classify //分类1:表单;2:流程表单"` + customerFormCont.Permit = "" //授权范围"` + customerFormCont.States = 1 //显示状态(1:启用;2:禁用,3:删除)"` + // customerFormCont.MastesForm = requestData.Data //表单结构"` + // customerFormCont.MastesFormJson = requestData.JsonData //表单结构json"` + // customerFormCont.Creater = userCont.Key //创建人"` + customerFormCont.CreaterTime = cureeTime //创建时间"` + customerFormCont.EditTime = cureeTime //编辑时间"` + // customerFormCont.TableStructure = "" //字表结构"` + // customerFormCont.Dict = requestData.Dict + + var formVersion modelAppPlatform.CustomerFormVersion + formVersion.TableKey = formJsonCont.Form.Name //default:'';not null;comment:表单标识符"` + varsionNum := HageFormVersionNum(formJsonCont.Form.Name) + formVersion.Version = varsionNum //1;not null;comment:版本号"` + if varsionNum > 1 { + formVersion.Status = 2 + } else { + formVersion.Status = 1 //not null;comment:显示状态(1:启用;2:禁用,3:删除)"` + } + formVersion.MastesForm = requestData.Data //';comment:表单结构"` + formVersion.MastesFormJson = requestData.JsonData //efault:'';comment:表单结构json"` + formVersion.Creater = userCont.Key //ult:0;not null;comment:创建人"` + formVersion.CreaterTime = cureeTime //not null;comment:创建时间"` + formVersion.EditTime = cureeTime //efault:0;not null;comment:编辑时间"` + mastSql, _ := formJsonCont.CreateFormDatabaseTable() + // mastSql, _ := formJsonCont.DisassembleForm() + formVersion.TableStructure = mastSql //;default:'';comment:字表结构"` + formVersion.Dict = requestData.Dict //字表结构"` + + createDb := overall.CONSTANT_DB_AppPlatform.Begin() + errMain := createDb.Create(&customerFormCont).Error + errVer := createDb.Create(&formVersion).Error + + if errMain != nil || errVer != nil { + createDb.Rollback() + publicmethod.Result(104, customerFormCont, c) + return + } + createDb.Commit() + err = createDb.Create(&customerFormCont).Error + if err != nil { + publicmethod.Result(104, customerFormCont, c) + return + } + publicmethod.Result(0, err, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-08 11:23:48 +@ 功能: 获取自定义表单版本号 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func HageFormVersionNum(tableKey string) (num int64) { + overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.CustomerFormVersion{}).Where("`tablekey` = ?", tableKey).Count(&num) + num = num + 1 + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-08-30 14:58:19 +@ 功能: 查看自定义表单 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) LookCustomerForm(c *gin.Context) { + var requestData publicmethod.CommonId[string] + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Id == "" { + publicmethod.Result(1, requestData.Id, c, "未知表单!") + return + } + var customerFormCont modelAppPlatform.CustomerForm + err = customerFormCont.GetCont(map[string]interface{}{"id": requestData.Id}) + if err != nil { + publicmethod.Result(107, err, c) + return + } + var sendCont LookCustomerFormInfo + sendCont.CfId = customerFormCont.Id + sendCont.Name = customerFormCont.Name //表单名称"` + sendCont.Classify = customerFormCont.Classify //分类1:表单;2:流程表单"` + sendCont.Permit = customerFormCont.Permit //授权范围"` + // sendCont.OpenClose = false + // if customerFormCont.States == 1 { + // sendCont.OpenClose = true + // } + sendCont.States = customerFormCont.States //显示状态(1:启用;2:禁用,3:删除)"` + // sendCont.MastesForm = customerFormCont.MastesForm //表单结构"` + // sendCont.MastesFormJson = customerFormCont.MastesFormJson //表单结构json"` + // sendCont.Creater = customerFormCont.Creater //创建人"` + sendCont.CreaterTime = customerFormCont.CreaterTime //创建时间"` + sendCont.EditTime = customerFormCont.EditTime //编辑时间"` + // sendCont.TableStructure = customerFormCont.TableStructure //字表结构"` + // sendCont.Dict = customerFormCont.Dict //字表结构"` + + var formVersion modelAppPlatform.CustomerFormVersion + formVersion.GetCont(map[string]interface{}{"tablekey": customerFormCont.TableNames, "`status`": 1}) + sendCont.Id = formVersion.Id + sendCont.TableKey = customerFormCont.TableNames //创建表单名称"` + sendCont.MastesForm = formVersion.MastesForm //表单结构"` + sendCont.MastesFormJson = formVersion.MastesFormJson //表单结构json"` + sendCont.Creater = formVersion.Creater //创建人"` + sendCont.TableStructure = formVersion.TableStructure //字表结构"` + sendCont.Dict = formVersion.Dict //字表结构"` + sendCont.Status = formVersion.Status //显示状态(1:启用;2:禁用,3:删除)"` + + json.Unmarshal([]byte(customerFormCont.Permit), &sendCont.PermitList) + publicmethod.Result(0, sendCont, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-01 08:26:14 +@ 功能: 编辑自定义表单状态 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) EditCustomerFormStatus(c *gin.Context) { + var requestData EditCustomerFormStatus + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if len(requestData.Id) < 1 { + publicmethod.Result(1, err, c, "没有要删除得内容!") + return + } + if requestData.Status == 0 { + requestData.Status = 2 + } + editCustomerForm := publicmethod.MapOut[string]() + editCustomerForm["`states`"] = requestData.Status + if requestData.Status != 3 { + err = overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.CustomerForm{}).Where("`id` IN ?", requestData.Id).Updates(editCustomerForm).Error + if err != nil { + publicmethod.Result(108, err, c) + return + } + } else { + if requestData.IsDelete { + err = overall.CONSTANT_DB_AppPlatform.Where("`id` IN ?", requestData.Id).Delete(&modelAppPlatform.CustomerForm{}).Error + } else { + err = overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.CustomerForm{}).Where("`id` IN ?", requestData.Id).Updates(editCustomerForm).Error + if err != nil { + publicmethod.Result(108, err, c) + return + } + } + } + publicmethod.Result(0, err, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-08 14:08:34 +@ 功能: 获取版本列表 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) HaveCustomerFormVersion(c *gin.Context) { + var requestData publicmethod.CommonId[string] + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Id == "" { + publicmethod.Result(1, err, c, "未知设置数据!请检查!") + return + } + var list []modelAppPlatform.CustomerFormVersion + overall.CONSTANT_DB_AppPlatform.Where("`tablekey` = ? AND `status` BETWEEN ? AND ?", requestData.Id, 1, 2).Find(&list) + publicmethod.Result(0, list, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-01 15:14:38 +@ 功能: 编辑自定义表单设置 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) SaveSetupCont(c *gin.Context) { + var requestData HaveCustomerFormInfo + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Id == 0 { + publicmethod.Result(1, err, c, "未知设置数据!请检查!") + return + } + if requestData.Name == "" { + publicmethod.Result(1, err, c, "请输入表格名称!") + return + } + if requestData.States == 0 { + requestData.States = 1 + } + var saveCont modelAppPlatform.CustomerForm + err = saveCont.GetCont(map[string]interface{}{"id": requestData.Id}) + if err != nil { + publicmethod.Result(107, err, c) + return + } + var orgAry [][]int64 + json.Unmarshal([]byte(requestData.Permit), &orgAry) + var orgList []string + if len(orgAry) > 0 { + for i := 0; i < len(orgAry); i++ { + if len(orgAry[i]) > 0 { + for j := 0; j < len(orgAry[i]); j++ { + orgId := strconv.FormatInt(orgAry[i][j], 10) + if !publicmethod.IsInTrue[string](orgId, orgList) { + orgList = append(orgList, orgId) + } + } + } + } + } + orgLists := strings.Join(orgList, ",") + editCont := publicmethod.MapOut[string]() + editCont["`name`"] = requestData.Name + editCont["`permit`"] = requestData.Permit + editCont["`permitstr`"] = orgLists + editCont["`states`"] = requestData.States + editCont["`edit_time`"] = time.Now().Unix() + err = saveCont.EiteCont(map[string]interface{}{"id": requestData.Id}, editCont) + if err != nil { + publicmethod.Result(106, err, c) + return + } + publicmethod.Result(0, orgLists, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-05 08:03:04 +@ 功能: 拆解表单结构,设计创建数据库表 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (c *CustomerFormMaster) DisassembleForm() (relevance string, err error) { + err = CreateForm(c.Form.Name, c.Form.FormName, true) + if err != nil { + return + } + var masterSql []string + var sunFormName []string + sunFormNameAry := publicmethod.MapOut[string]() + sunForm := publicmethod.MapOut[string]() + for _, v := range c.List { + switch v.Type { + // case "title": + // fmt.Printf("type:%v <===========>label:%v <===========> Name:%v <===========> ModelValue:%v\n", v.Type, v.Control, v.Name, v.Control.ModelValue) + case "grid", "tabs": + if len(v.Columns) > 0 { + for _, cv := range v.Columns { + // fmt.Printf("type:%v <===========>label:%v <===========> Name:%v<===========> ModelValue:%v\n", v.Type, cv.Attr.Span, cv.Type, v.Control.ModelValue) + sqlStr := ComponentMappingDataTable(c.Form.Name, cv.List) + masterSql = append(masterSql, sqlStr...) + } + } + case "card", "div": + if len(v.List) > 0 { + sqlStr := ComponentMappingDataTable(c.Form.Name, v.List) + masterSql = append(masterSql, sqlStr...) + } + case "table", "flex": + if len(v.List) > 0 { + if !publicmethod.IsInTrue[string](v.Name, sunFormName) { + sunFormName = append(sunFormName, v.Name) + sunFormNameAry[v.Name] = v.Name + sqlStr := ComponentMappingDataTable(v.Name, v.List) + sunForm[v.Name] = sqlStr + CreateForm(v.Name, fmt.Sprintf("%v(%v)子表", c.Form.FormName, c.Form.Name), false) + } else { + sunTableName := fmt.Sprintf("%v%v", v.Name, publicmethod.GetUUid(1)) + sunFormName = append(sunFormName, sunTableName) + sunFormNameAry[v.Name] = sunTableName + sqlStr := ComponentMappingDataTable(sunTableName, v.List) + sunForm[sunTableName] = sqlStr + CreateForm(sunTableName, fmt.Sprintf("%v(%v)子表", c.Form.FormName, c.Form.Name), false) + } + + } + case "input": + masterSql = append(masterSql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v COMMENT '%v'", c.Form.Name, v.Name, CustomRules(v.CustomRules), v.Item.Label)) + case "password", "colorPicker", "component": + // sqlStr = fmt.Sprintf("%v varchar(255) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '%v'", sqlStr, lv.Item.Label) + masterSql = append(masterSql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` varchar(255) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '%v'", c.Form.Name, v.Name, v.Item.Label)) + case "datePicker", "checkbox", "cascader", "treeSelect", "textarea", "upload", "expand-user": + // sqlStr = fmt.Sprintf("%v mediumtext COMMENT '%v'", sqlStr, lv.Item.Label) + masterSql = append(masterSql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` mediumtext COMMENT '%v'", c.Form.Name, v.Name, v.Item.Label)) + case "select", "radio", "inputSlot": + // sqlStr = fmt.Sprintf("%v %v COMMENT '%v'", sqlStr, SelectUnit(lv.Config), lv.Item.Label) + masterSql = append(masterSql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v COMMENT '%v'", c.Form.Name, v.Name, SelectUnit(v.Config), v.Item.Label)) + case "rate", "inputNumber", "slider", "switch": + // sqlStr = fmt.Sprintf("%v %v COMMENT '%v'", sqlStr, ControlJudge(lv.Type, lv.Control), lv.Item.Label) + masterSql = append(masterSql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v COMMENT '%v'", c.Form.Name, v.Name, ControlJudge(v.Type, v.Control), v.Item.Label)) + case "tinymce": + // sqlStr = fmt.Sprintf("%v longtext COMMENT '%v'", sqlStr, lv.Item.Label) + masterSql = append(masterSql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` longtext COMMENT '%v'", c.Form.Name, v.Name, v.Item.Label)) + default: + // fmt.Printf("type:%v <===========>label:%v <===========> Name:%v<===========> ModelValue:%v\n", v.Type, v.Item.Label, v.Name, v.Control.ModelValue) + } + + } + // fmt.Printf("主表单结构---》%v\n", masterSql) + CreateFormFiled(c.Form.Name, c.Form.FormName, true, masterSql) + if len(sunForm) > 0 { + relevanceByte, _ := json.Marshal(sunFormNameAry) + relevance = string(relevanceByte) + for i, v := range sunForm { + // fmt.Printf("表单结构----拆解----》%v========>%v\n", i, v) + CreateFormFiled(i, fmt.Sprintf("%v(%v)子表", c.Form.FormName, c.Form.Name), false, v) + } + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-13 09:28:58 +@ 功能: 创建数据表字段 +@ 参数 + + #formName 表单名称 + #formNotes 表单备注 + #isMasters true 主表;false:子表 + #sqlList 语句列表 + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func CreateFormFiled(formName, formNotes string, isMasters bool, sqlList interface{}) { + // fmt.Printf("函数类型----%v---%T\n", reflect.TypeOf(sqlList), sqlList) + if sql, isOk := sqlList.([]string); isOk { + for _, v := range sql { + // fmt.Printf("%v\n", v) + overall.CONSTANT_DB_CustomerForm.Exec(v) + // err := overall.CONSTANT_DB_CustomerForm.Exec(v).Error + // fmt.Printf("字段创建----%v---%v\n", err, v) + } + } +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-13 08:12:23 +@ 功能: 创建表单 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func CreateForm(formName, notes string, isMasters bool) (err error) { + //判断表单是否存在 + isTrue := overall.CONSTANT_DB_CustomerForm.Migrator().HasTable(formName) + if !isTrue { //当数据表不存在时进行创建 + if isMasters { + //创建主表 + sqlCreateTable := fmt.Sprintf("CREATE TABLE `%v` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,`masters_key` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '主表标识',`creater` bigint(20) unsigned DEFAULT '0' COMMENT '创建人',`creater_time` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',`edit_time` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '编辑时间',`flow_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '流程识别标识',PRIMARY KEY (`id`) USING BTREE,UNIQUE KEY `id` (`id`) USING HASH,UNIQUE KEY `masters_key` (`masters_key`) USING HASH) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COMMENT='%v'", formName, notes) + err = overall.CONSTANT_DB_CustomerForm.Exec(sqlCreateTable).Error + + } else { + //创建子表 + sqlCreateTable := fmt.Sprintf("CREATE TABLE `%v` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,`masters_key` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '主表标识',`creater` bigint(20) unsigned DEFAULT '0' COMMENT '创建人',`creater_time` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',`edit_time` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '编辑时间',PRIMARY KEY (`id`) USING BTREE,UNIQUE KEY `id` (`id`) USING HASH,KEY `masters_key` (`masters_key`) USING HASH) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COMMENT='%v'", formName, notes) + err = overall.CONSTANT_DB_CustomerForm.Exec(sqlCreateTable).Error + } + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-12 16:15:59 +@ 功能: 组件映射数据表 +@ 参数 + + #tableName 表明 + #list 组件列表 + +@ 返回值 + + #mastSql 数据库语句 + +@ 方法原型 + + #func ComponentMappingDataTable(tableName string, list []MasterStruct) (mastSql []string) +*/ +func ComponentMappingDataTable(tableName string, list []MasterStruct) (mastSql []string) { + if len(list) > 0 { + for _, lv := range list { + sqlStr := fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v`", tableName, lv.Name) + switch lv.Type { + case "input": + sqlStr = fmt.Sprintf("%v %v COMMENT '%v'", sqlStr, CustomRules(lv.CustomRules), lv.Item.Label) + case "password", "colorPicker", "component": + sqlStr = fmt.Sprintf("%v varchar(255) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '%v'", sqlStr, lv.Item.Label) + case "datePicker", "checkbox", "cascader", "treeSelect", "textarea", "upload", "expand-user": + sqlStr = fmt.Sprintf("%v mediumtext COMMENT '%v'", sqlStr, lv.Item.Label) + case "select", "radio", "inputSlot": + sqlStr = fmt.Sprintf("%v %v COMMENT '%v'", sqlStr, SelectUnit(lv.Config), lv.Item.Label) + case "rate", "inputNumber", "slider", "switch": + sqlStr = fmt.Sprintf("%v %v COMMENT '%v'", sqlStr, ControlJudge(lv.Type, lv.Control), lv.Item.Label) + case "tinymce": + sqlStr = fmt.Sprintf("%v longtext COMMENT '%v'", sqlStr, lv.Item.Label) + default: + } + mastSql = append(mastSql, sqlStr) + } + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-12 14:59:51 +@ 功能: 组件配置判断 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func ControlJudge(class string, control ControlStruct) (sqlStr string) { + switch class { + case "rate": + if control.Max < 10 { + sqlStr = " tinyint(1) unsigned NOT NULL DEFAULT '0' " + } else if control.Max <= 255 { + sqlStr = " tinyint(3) unsigned NOT NULL DEFAULT '0' " + } else if control.Max <= 4294967295 { + sqlStr = " int(10) unsigned NOT NULL DEFAULT '0' " + } else { + sqlStr = " bigint(20) unsigned NOT NULL DEFAULT '0' " + } + case "switch": + switch control.ModelValue.(type) { + case bool: + if control.ModelValue == true { + sqlStr = " tinyint(1) unsigned NOT NULL DEFAULT '1' " + } else { + sqlStr = " tinyint(1) unsigned NOT NULL DEFAULT '0' " + } + case int, int8, int16: + sqlStr = " int(10) unsigned NOT NULL DEFAULT '0' " + case int32, int64: + sqlStr = " bigint(20) unsigned NOT NULL DEFAULT '0' " + case float32, float64: + sqlStr = " float(20,10) unsigned DEFAULT '0' " + default: + sqlStr = " varchar(255) COLLATE utf8mb4_general_ci DEFAULT '' " + } + case "slider": + if control.Max == 0 { + sqlStr = " tinyint(3) unsigned NOT NULL DEFAULT '0' " + } else if control.Max < 10 && control.Max > 0 { + sqlStr = " tinyint(1) unsigned NOT NULL DEFAULT '0' " + } else if control.Max <= 255 { + sqlStr = " tinyint(3) unsigned NOT NULL DEFAULT '0' " + } else if control.Max <= 4294967295 { + sqlStr = " int(10) unsigned NOT NULL DEFAULT '0' " + } else { + sqlStr = " bigint(20) unsigned NOT NULL DEFAULT '0' " + } + default: + sqlStr = " varchar(255) COLLATE utf8mb4_general_ci DEFAULT '' " + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-12 10:17:58 +@ 功能: 下拉字段处理 +@ 参数 + + #tableName 表名 + #field 字段名 + #rubric 备注 + #control 控制器 + +@ 返回值 + + #sqlStr 补充SQL语句 + +@ 方法原型 + + # +*/ +func SelectUnit(config UnitConfigStruct) (sqlStr string) { + switch config.TransformData { + case "number": + sqlStr = " bigint(20) unsigned NOT NULL DEFAULT '0' " + default: + sqlStr = " varchar(255) COLLATE utf8mb4_general_ci DEFAULT '' " + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-12 09:29:23 +@ 功能: 校验规则 +@ 参数 + + #list 自定义规则 + +@ 返回值 + + #sqlStr 补充SQL语句 + +@ 方法原型 + + #func CustomRules(list []CustomRulesStruct) (sqlStr string) +*/ +func CustomRules(list []CustomRulesStruct) (sqlStr string) { + sqlStr = fmt.Sprintf("NOT NULL") + if len(list) <= 0 { + sqlStr = fmt.Sprintf(" varchar(255) COLLATE utf8mb4_general_ci %v DEFAULT '' ", sqlStr) + return + } + + var typeAry []string + for _, v := range list { + if !publicmethod.IsInTrue[string](v.Type, typeAry) { + switch v.Type { + case "int": + sqlStr = fmt.Sprintf(" int(6) unsigned %v DEFAULT '1' ", sqlStr) + case "number": + sqlStr = fmt.Sprintf(" bigint(20) unsigned %v DEFAULT '0' ", sqlStr) + case "money": + sqlStr = fmt.Sprintf(" decimal(20,4) unsigned %v DEFAULT '0' ", sqlStr) + case "mobile", "tel", "phone": + sqlStr = fmt.Sprintf(" varchar(100) COLLATE utf8mb4_general_ci %v DEFAULT '' ", sqlStr) + default: + sqlStr = fmt.Sprintf(" varchar(255) COLLATE utf8mb4_general_ci %v DEFAULT '' ", sqlStr) + } + } + + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-09 09:31:55 +@ 功能: 编辑自定义表单内容 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) EditCustomerFormInfo(c *gin.Context) { + context, _ := c.Get(overall.MyContJwt) + var requestData EditCustomerFormCont + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Id == "" { + publicmethod.Result(1, err, c, "自定义表单错误!") + return + } + if requestData.Version == "" { + publicmethod.Result(1, err, c, "自定义表单错误!") + return + } + if requestData.Data == "" { + publicmethod.Result(1, err, c, "自定义表单错误!") + return + } + if requestData.Name == "" { + publicmethod.Result(1, err, c, "未知表单名称!") + return + } + if requestData.Classify == 0 { + requestData.Classify = 1 + } + var formJsonCont CustomerFormMaster + json.Unmarshal([]byte(requestData.JsonData), &formJsonCont) + + if formJsonCont.Form.FormName == "" { + publicmethod.Result(1, err, c, "未知表单名称!") + return + } + if formJsonCont.Form.Name == "" { + publicmethod.Result(1, err, c, "未知表单标识!") + return + } + var customerFormCont modelAppPlatform.CustomerForm + err = customerFormCont.GetCont(map[string]interface{}{"`id`": requestData.Id}, "`tablename`") + if err != nil { + publicmethod.Result(107, err, c) + return + } + var userCont modelshr.ManCont + userCont.GetLoginCont(context) + + cureeTime := time.Now().Unix() + mainData := publicmethod.MapOut[string]() + mainData["`name`"] = formJsonCont.Form.FormName + mainData["`classify`"] = requestData.Classify + mainData["`edit_time`"] = cureeTime + customerFormCont.EiteCont(map[string]interface{}{"`id`": requestData.Id}, mainData) + versionData := publicmethod.MapOut[string]() + versionData["`mastesform`"] = requestData.Data + versionData["`mastesformjson`"] = requestData.JsonData + versionData["`creater`"] = userCont.Key + // mastSql, _ := formJsonCont.DisassembleForm() + mastSql, _ := formJsonCont.CreateFormDatabaseTable() + versionData["`table_structure`"] = mastSql + versionData["`dict`"] = requestData.Dict + var formVersion modelAppPlatform.CustomerFormVersion + formVersion.EiteCont(map[string]interface{}{"`id`": requestData.Version}, versionData) + publicmethod.Result(0, err, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-09 09:45:42 +@ 功能: 另存为新版 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) SaveAsNewVersion(c *gin.Context) { + context, _ := c.Get(overall.MyContJwt) + var requestData HaveCustomerFormConfig + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Data == "" { + publicmethod.Result(1, err, c, "自定义表单错误!") + return + } + if requestData.Name == "" { + publicmethod.Result(1, err, c, "未知表单名称!") + return + } + if requestData.Classify == 0 { + requestData.Classify = 1 + } + var formJsonCont CustomerFormMaster + json.Unmarshal([]byte(requestData.JsonData), &formJsonCont) + + if formJsonCont.Form.FormName == "" { + publicmethod.Result(1, err, c, "未知表单名称!") + return + } + if formJsonCont.Form.Name == "" { + publicmethod.Result(1, err, c, "未知表单标识!") + return + } + var userCont modelshr.ManCont + userCont.GetLoginCont(context) + cureeTime := time.Now().Unix() + var customerFormCont modelAppPlatform.CustomerForm + err = customerFormCont.GetCont(map[string]interface{}{"`tablename`": formJsonCont.Form.Name}, "`id`", "`tablename`") + if err != nil { + publicmethod.Result(107, err, c) + return + } + var formVersion modelAppPlatform.CustomerFormVersion + formVersion.TableKey = customerFormCont.TableNames //default:'';not null;comment:表单标识符"` + varsionNum := HageFormVersionNum(customerFormCont.TableNames) + formVersion.Version = varsionNum //1;not null;comment:版本号"` + if varsionNum > 1 { + formVersion.Status = 2 + } else { + formVersion.Status = 1 //not null;comment:显示状态(1:启用;2:禁用,3:删除)"` + } + formVersion.MastesForm = requestData.Data //';comment:表单结构"` + formVersion.MastesFormJson = requestData.JsonData //efault:'';comment:表单结构json"` + formVersion.Creater = userCont.Key //ult:0;not null;comment:创建人"` + formVersion.CreaterTime = cureeTime //not null;comment:创建时间"` + formVersion.EditTime = cureeTime //efault:0;not null;comment:编辑时间"` + // mastSql, _ := formJsonCont.DisassembleForm() + mastSql, _ := formJsonCont.CreateFormDatabaseTable() + formVersion.TableStructure = mastSql //;default:'';comment:字表结构"` + formVersion.Dict = requestData.Dict //字表结构"` + errVer := overall.CONSTANT_DB_AppPlatform.Create(&formVersion).Error + if errVer != nil { + publicmethod.Result(104, customerFormCont, c) + return + } + publicmethod.Result(0, err, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-09 10:44:55 +@ 功能: 启用版本 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) EnableVersion(c *gin.Context) { + var requestData publicmethod.CommonId[string] + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Id == "" { + publicmethod.Result(1, err, c, "未知启用版本!") + return + } + var formVersion modelAppPlatform.CustomerFormVersion + err = formVersion.GetCont(map[string]interface{}{"`id`": requestData.Id}) + if err != nil { + publicmethod.Result(107, err, c) + return + } + overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.CustomerFormVersion{}).Where("`tablekey` = ? AND `status` = 1", formVersion.TableKey).Updates(map[string]interface{}{"`status`": 2}) + err = formVersion.EiteCont(map[string]interface{}{"`id`": requestData.Id}, map[string]interface{}{"`status`": 1}) + publicmethod.Result(0, err, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-15 10:29:39 +@ 功能: 检测是否存在提交和返回按钮 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) JudgeSubmitCancel(c *gin.Context) { + var requestData publicmethod.PublicName + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Name == "" { + publicmethod.Result(1, err, c, "未知表单数据!") + return + } + isSubmit := false + isCancel := false + + var formJsonCont CustomerFormMaster + json.Unmarshal([]byte(requestData.Name), &formJsonCont) + if len(formJsonCont.List) > 0 { + for _, v := range formJsonCont.List { + switch v.Type { + case "grid", "tabs": + if len(v.Columns) > 0 { + for _, cv := range v.Columns { + isSubmits, isCancels := PublicUnitJieXi(cv.List) + if isSubmits { + isSubmit = true + } + if isCancels { + isCancel = true + } + } + } + case "card", "div": + if len(v.List) > 0 { + isSubmits, isCancels := PublicUnitJieXi(v.List) + if isSubmits { + isSubmit = true + } + if isCancels { + isCancel = true + } + } + case "button": + if v.Control.Key == "submit" { + isSubmit = true + } + if v.Control.Key == "cancel" { + isCancel = true + } + default: + // fmt.Printf("type:%v <===========>label:%v <===========> Name:%v<===========> ModelValue:%v\n", v.Type, v.Item.Label, v.Name, v.Control.ModelValue) + } + + } + } + buttonIsTrue := 0 + if isSubmit && isCancel { + buttonIsTrue = 1 + } else if isSubmit && !isCancel { + buttonIsTrue = 2 + } else if !isSubmit && isCancel { + buttonIsTrue = 3 + } else { + buttonIsTrue = 4 + } + snedAry := publicmethod.MapOut[string]() + snedAry["buttonIsTrue"] = buttonIsTrue + snedAry["formJsonCont"] = formJsonCont + publicmethod.Result(0, buttonIsTrue, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-15 10:44:20 +@ 功能: 通用组件解析 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func PublicUnitJieXi(list []MasterStruct) (isSubmit, isCancel bool) { + + if len(list) > 0 { + for _, v := range list { + switch v.Type { + case "button": + if v.Control.Key == "submit" { + isSubmit = true + } + if v.Control.Key == "cancel" { + isCancel = true + } + default: + } + } + } + return + +} diff --git a/api/version1/customerform/type.go b/api/version1/customerform/type.go index 794d874..091a4e0 100644 --- a/api/version1/customerform/type.go +++ b/api/version1/customerform/type.go @@ -1,6 +1,7 @@ package customerform import ( + "appPlatform/models/modelAppPlatform" "appPlatform/overall/publicmethod" "sync" @@ -44,12 +45,35 @@ type CustomerFormMaster struct { // 组件主体 type MasterStruct struct { - Type string `json:"type"` //组件类型 - Control ControlStruct `json:"control"` - Config UnitConfigStruct `json:"config"` - Options []OptionsStruct `json:"options"` - Name string `json:"name"` - Item ItemStruct `json:"item"` + Type string `json:"type"` //组件类型 + Columns []columnsStruct `json:"columns"` // + Control ControlStruct `json:"control"` + Config UnitConfigStruct `json:"config"` //组件配置 + Options []OptionsStruct `json:"options"` + Name string `json:"name"` + Item ItemStruct `json:"item"` + CustomRules []CustomRulesStruct `json:"customRules"` //校验规则 + List []MasterStruct `json:"list"` + TableData interface{} `json:"tableData"` +} + +// 校验规则 +type CustomRulesStruct struct { + Type string `json:"type"` + Message string `json:"message"` + Trigger string `json:"trigger"` +} + +// 标签 +type columnsStruct struct { + Label string `json:"label"` + Attr AttrStruct `json:"attr"` + List []MasterStruct `json:"list"` //组件列表 + Type string `json:"type"` +} + +type AttrStruct struct { + Span int `json:"span"` //占行范围 } // 选择内容 @@ -59,37 +83,86 @@ type OptionsStruct struct { } type ItemStruct struct { - Label string `json:"label"` + Label string `json:"label"` + ShowLabel bool `json:"showLabel"` + Rules []rulesStruct `json:"rules"` +} + +type rulesStruct struct { + Name bool `json:"name"` + Required bool `json:"required"` + Message string `json:"message"` + Trigger string `json:"trigger"` } // 组件控制器 type ControlStruct struct { - Label string `json:"label"` - Type string `json:"type"` - Key string `json:"key"` - ModelValue []interface{} `json:"model"` + Label string `json:"label"` + Type string `json:"type"` + Key string `json:"key"` + ModelValue interface{} `json:"modelValue"` + Placeholder string `json:"placeholder"` //占位内容 + Disabled bool `json:"disabled"` //是否禁用 + Rows int `json:"rows"` //行数(多行文本使用) + Direction string `json:"direction"` // + ContentPosition string `json:"contentPosition"` // + BorderStyle string `json:"borderStyle"` // + Height string `json:"height"` // + Width string `json:"width"` // + ImgUrl string `json:"imgUrl"` // + BlobUrl string `json:"blobUrl"` // + ActiveValue string `json:"activeValue"` // + InactiveValue string `json:"inactiveValue"` // + Max int `json:"max"` // + ColorFormat string `json:"colorFormat"` // + FormAt string `json:"format"` // + Data []string `json:"data"` // + RenderAfterExpand bool `json:"renderAfterExpand"` // + Multiple bool `json:"multiple"` // + Action string `json:"action"` // + ListType string `json:"listType"` // + Name string `json:"name"` // + AppendToBody bool `json:"appendToBody"` // + Clearable bool `json:"clearable"` // } // 组件配置 type UnitConfigStruct struct { ClassName string `json:"className"` //自定义样式 + Help string `json:"help"` //帮助信息 Span int `json:"span"` //占行范围 + Prepend string `json:"prepend"` //对齐方式 + Append string `json:"append"` //对齐方式 TextAlign string `json:"textAlign"` //对齐方式 + EditDisabled bool `json:"editDisabled"` // 页隐藏 DisabledAdd bool `json:"disabledAdd"` //添加页隐藏 + DisabledEdit bool `json:"disabledEdit"` //编辑页隐藏 DisabledDetail bool `json:"disabledDetail"` //编辑页隐藏 LinkKey bool `json:"linkKey"` //开启联动条件 LinkValue string `json:"linkValue"` //联动条件内容 + LinkResult string `json:"linkResult"` //联动条件内容 OptionsType int `json:"optionsType"` //选择数据源 0:固定选项;1:数据源;3:1接口字典 OptionsFun string `json:"optionsFun"` - Help string `json:"help"` //帮助信息 + TransformData string `json:"transformData"` //值转换类型 + AddBtnText string `json:"addBtnText"` //添加一行按钮(自定义布局中使用) + DelBtnText string `json:"delBtnText"` //删除一行按钮(自定义布局中使用) + BtnText string `json:"btnText"` //按钮文字 + + Label string `json:"label"` //指定label属性值 + Value string `json:"value"` //指定value属性值 + Method string `json:"method"` // + AddAll string `json:"addAll"` // + BeforeRequest interface{} `json:"beforeRequest"` + AfterResponse interface{} `json:"afterResponse"` } // 表单信息 type FormStruct struct { Size string `json:"size"` - Name string `json:"name"` - LabelWidth string `json:"labelWidth"` - Class string `json:"class"` + FormName string `json:"formName"` //表单名称 + Name string `json:"name"` //表单标识 + LabelWidth string `json:"labelWidth"` //表单宽度 + Class string `json:"class"` //表单样式 ShowColon bool `json:"showColon"` } @@ -97,3 +170,128 @@ type FormStruct struct { type ConfigStruct struct { AddLoad bool `json:"addLoad"` } + +// 搜索自定义表单 +type SearchForm struct { + publicmethod.PagesTurn + KeyWords string `json:"keywords"` + Classify int `json:"classify"` +} + +// 输出表单列表 +type SendCustomerForm struct { + Id string `json:"id"` + Name string `json:"name"` + TableNames string `json:"tablename"` + States int `json:"states"` + Classify int `json:"classify"` + CreaterName string `json:"creatername"` + CreaterTime string `json:"creatertime"` +} + +// 输出自定义表格基础信息 +type SendCustomerFormConfig struct { + FormName string `json:"formname"` + FormLogo string `json:"formlogo"` +} + +// 提交自定义表单数据 +type HaveCustomerFormConfig struct { + Types int `json:"type"` + Name string `json:"name"` + Source string `json:"source"` // 数据源允许在表单属性设置里修改的 + Dict string `json:"dict"` + Data string `json:"data"` + JsonData string `json:"jsondata"` + Classify int `json:"classify"` //分类1:表单;2:流程表单" +} + +// 改变自定义报道状态 +type EditCustomerFormStatus struct { + Id []string `json:"id"` + Status int `json:"status"` + IsDelete bool `json:"is_delete"` +} + +// 输出查看详情信息 +type LookCustomerFormInfo struct { + modelAppPlatform.CustomerFormView + States int `json:"states"` + PermitList [][]int64 `json:"permit_list"` +} + +// 接收自定义表单设置数据 +type HaveCustomerFormInfo struct { + publicmethod.CommonId[int64] + publicmethod.PublicName + States int `json:"states"` + Permit string `json:"permit"` +} + +// 编辑自定义表单内容 +type EditCustomerFormCont struct { + publicmethod.CommonId[string] + Version string `json:"version"` + HaveCustomerFormConfig +} + +// 数据库表结构 +type Result struct { + Field string `json:"field"` + Type string `json:"type"` + Attribute string `json:"attribute"` + Collation string `json:"collation"` + Null string `json:"null"` + Key string `json:"key"` + Default string `json:"default"` + Extra string `json:"extra"` + Privileges string `json:"privileges"` + Comment string `json:"comment"` +} + +// 自定义表单数据结构版本及表单输出 +type CustomerFormDatabaseVesion struct { + Version []PublicFormDatabaseVesion `json:"version"` + TableList []PublicFormDatabaseVesion `json:"tablelist"` +} + +// 通用自定义表单数据结构 +type PublicFormDatabaseVesion struct { + HaveVersionForm + IsMain bool `json:"ismain"` + IsEdit bool `json:"isedit"` + VersionId string `json:"versionid"` +} + +// 获取版本表单 +type HaveVersionForm struct { + publicmethod.CommonId[string] + publicmethod.PublicName +} +type OptimizeOrRepairTable struct { + publicmethod.PublicName + OptimizeOrRepair int `json:"optimizerender"` //1:优化;2:修复 +} + +// 输出字段拆析 +type SendFieldCont struct { + Result + Integer string `json:"integer"` //整数部门 + Decimal string `json:"decimal"` //小数部分 +} + +// 编辑数据库表单字段 +type EditDatabaseFormField struct { + FormName string `json:"formname"` // + SendFieldCont +} + +// 分析表单结构 +type TableFormStruct struct { + TableName string `json:"tablename"` //字段名称 + Types string `json:"types"` //组件类型 + FieldLenght int `json:"fieldlenght"` //字段长度 + ControlType string `json:"controlType"` // + DefaultValue interface{} `json:"defaultValue"` // + Signed bool `json:"signed"` // +} diff --git a/api/version1/entry.go b/api/version1/entry.go index db0f141..2d4ec2f 100644 --- a/api/version1/entry.go +++ b/api/version1/entry.go @@ -7,6 +7,8 @@ import ( matrixapi "appPlatform/api/version1/matrixApi" "appPlatform/api/version1/menus" "appPlatform/api/version1/publicapi" + "appPlatform/api/version1/taskplatform/taskflow" + "appPlatform/api/version1/taskplatform/taskmanagement" "appPlatform/api/version1/user" ) @@ -18,6 +20,8 @@ type ApiEntry struct { MatrixApi matrixapi.ApiMethod //权限矩阵 PublicApi publicapi.ApiMethod //公共方法 CustomerFormApi customerform.ApiMethod //自定表单 + TaskManagementApi taskmanagement.ApiMethod + TaskFlowApi taskflow.ApiMethod } var AppApiEntry = new(ApiEntry) diff --git a/api/version1/menus/menus.go b/api/version1/menus/menus.go index dc68bf7..f91c3d3 100644 --- a/api/version1/menus/menus.go +++ b/api/version1/menus/menus.go @@ -160,11 +160,13 @@ func (a *ApiMethod) AddNewMenu(c *gin.Context) { menuCont.Component = requestData.Component //组件路径(vue页面完整路径,省略.vue后缀)"` } - menuCont.Perm = publicmethod.GetUUid(3) //权限标识"` - menuCont.Visible = requestData.Visible //显示状态(1:显示;2:隐藏,3:删除)"` - menuCont.Sort = requestData.Sort //排序(数字越小排名越靠前))"` - menuCont.Icon = requestData.Icon //菜单图标"` - menuCont.Redirect = requestData.Redirect //跳转路径"` + menuCont.Perm = publicmethod.GetUUid(3) //权限标识"` + menuCont.Visible = requestData.Visible //显示状态(1:显示;2:隐藏,3:删除)"` + menuCont.Sort = requestData.Sort //排序(数字越小排名越靠前))"` + menuCont.Icon = requestData.Icon //菜单图标"` + if types != 1 { + menuCont.Redirect = requestData.Redirect //跳转路径"` + } menuCont.ParentId = requestData.ParentId //父菜单ID"` menuCont.Time = time.Now().Unix() //创建时间"` menuCont.Outside = requestData.Outside //1:内部使用;2:外部使用;3:内外使用"` diff --git a/api/version1/publicapi/api.go b/api/version1/publicapi/api.go index 1d6da94..ede725a 100644 --- a/api/version1/publicapi/api.go +++ b/api/version1/publicapi/api.go @@ -10,6 +10,7 @@ import ( "unicode" "github.com/gin-gonic/gin" + "github.com/mozillazg/go-pinyin" ) /* @@ -147,3 +148,55 @@ func (a *ApiMethod) GenerateSignCode(c *gin.Context) { sendCode["code"] = signCode publicmethod.Result(0, sendCode, c) } + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-26 11:51:43 +@ 功能: 中文转拼音 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) ChineseToPinyin(c *gin.Context) { + var requestData HanziToPinyin + c.ShouldBindJSON(&requestData) + if requestData.Title == "" { + publicmethod.Result(1, requestData, c, "未知中文语句!") + return + } + pyObject := pinyin.NewArgs() + switch requestData.Types { + case 1: + pyObject.Style = pinyin.Tone + case 2: + pyObject.Style = pinyin.Tone2 + case 3: + pyObject.Style = pinyin.Initials + case 4: + pyObject.Style = pinyin.FirstLetter + case 5: + pyObject.Style = pinyin.Finals + case 6: + pyObject.Style = pinyin.FinalsTone + case 7: + pyObject.Style = pinyin.FinalsTone2 + case 8: + pyObject.Style = pinyin.Tone3 + case 9: + pyObject.Style = pinyin.FinalsTone3 + default: + pyObject.Style = pinyin.Normal + } + pyObject.Separator = requestData.Connector + str := pinyin.Slug(requestData.Title, pyObject) + publicmethod.Result(0, str, c) +} diff --git a/api/version1/publicapi/type.go b/api/version1/publicapi/type.go index 9628a98..62f6716 100644 --- a/api/version1/publicapi/type.go +++ b/api/version1/publicapi/type.go @@ -20,3 +20,10 @@ type SendUUID struct { UuId int64 `json:"uuid"` UuIdString string `json:"uuidstring"` } + +// 汉字转拼音 +type HanziToPinyin struct { + Title string `json:"title"` //中文语句 + Types int `json:"types"` //转换风格 0:普通风格,不带声调(默认风格)。如: zhong guo;1:声调风格1,拼音声调在韵母第一个字母上。如: zhōng guó;2:声调风格2,即拼音声调在各个韵母之后,用数字 [1-4] 进行表示。如: zho1ng guo2;3:声母风格,只返回各个拼音的声母部分。如: zh g 。注意:不是所有的拼音都有声母;4:首字母风格,只返回拼音的首字母部分。如: z g;5: 韵母风格,只返回各个拼音的韵母部分,不带声调。如: ong uo;6:韵母风格1,带声调,声调在韵母第一个字母上。如: ōng uó;7:韵母风格2,带声调,声调在各个韵母之后,用数字 [1-4] 进行表示。如: o1ng uo2;8:声调风格3,即拼音声调在各个拼音之后,用数字 [1-4] 进行表示。如: zhong1 guo2;9:韵母风格3,带声调,声调在各个拼音之后,用数字 [1-4] 进行表示。如: ong1 uo2; + Connector string `json:"connector"` // Join 所用的分隔符 +} diff --git a/api/version1/publicapi/组件结构.ts b/api/version1/publicapi/组件结构.ts new file mode 100644 index 0000000..2d87032 --- /dev/null +++ b/api/version1/publicapi/组件结构.ts @@ -0,0 +1,813 @@ +opt = { + list: [ + { + type: "datePicker", + control: + { + modelValue: "", + type: "year", + format: "YYYY" + }, + config: + {}, + name: "nian2", + item: + { + label: "年" + } + }, + { + type: "datePicker", + control: + { + modelValue: "", + type: "month" + }, + config: + {}, + name: "yue4", + item: + { + label: "月" + } + }, + { + type: "datePicker", + control: + { + modelValue: "", + type: "date" + }, + config: + {}, + name: "ri4qi1", + item: + { + label: "日期" + } + }, + { + type: "datePicker", + control: + { + modelValue: "", + type: "datetime" + }, + config: + {}, + name: "shi2jian1", + item: + { + label: "时间" + } + }, + { + type: "datePicker", + control: + { + modelValue: "", + type: "week" + }, + config: + {}, + name: "zhou1", + item: + { + label: "周" + } + }, + { + type: "datePicker", + control: + { + modelValue: "", + type: "datetimerange" + }, + config: + {}, + name: "shi2jian1zhou1qi1", + item: + { + label: "时间周期" + } + }, + { + type: "datePicker", + control: + { + modelValue: "", + type: "daterange" + }, + config: + {}, + name: "ri4qi1zhou1qi1", + item: + { + label: "日期周期" + } + }, + { + type: "datePicker", + control: + { + modelValue: "", + type: "monthrange" + }, + config: + {}, + name: "yue4zhou1qi1", + item: + { + label: "月周期" + } + }, + { + type: "input", + control: + { + modelValue: "" + }, + config: + {}, + name: "wen2ben317478324", + item: + { + label: "文本" + } + }, + { + type: "password", + control: + { + modelValue: "" + }, + config: + { + prepend: "1", + append: "2" + }, + name: "mi4ma3", + item: + { + label: "密码" + } + }, + { + type: "textarea", + control: + { + modelValue: "" + }, + config: + {}, + name: "textarea1695711791732", + item: + { + label: "多行文本" + } + }, + { + type: "radio", + control: + { + modelValue: "" + }, + options: [ + { + label: "男", + value: "1" + }, + { + label: "女", + value: "2" + }], + config: + { + optionsType: 0, + transformData: "number" + }, + name: "dan1xuan3kuang1zu3gu4ding4xuan3xiang4", + item: + { + label: "单选框组(固定选项)" + } + }, + { + type: "radio", + control: + { + modelValue: "" + }, + options: [], + config: + { + optionsType: 1, + optionsFun: "http://www.api.com/api", + method: "post", + label: "name", + value: "id" + }, + name: "dxansjymoren", + item: + { + label: "单选框组数据源(默认)" + } + }, + { + type: "radio", + control: + { + modelValue: "" + }, + options: [], + config: + { + optionsType: 2, + optionsFun: "kjh", + transformData: "string" + }, + name: "radio1695711963706", + item: + { + label: "单选框组" + } + }, + { + type: "checkbox", + control: + { + modelValue: [] + }, + options: [ + { + label: "书", + value: "1" + }, + { + label: "笔", + value: "2" + }, + { + label: "墨", + value: "3" + }], + config: + { + optionsType: 0, + transformData: "number" + }, + name: "checkbox1695712007255", + item: + { + label: "多选框组" + } + }, + { + type: "select", + control: + { + modelValue: "", + appendToBody: true + }, + options: [ + { + label: "笔", + value: "1" + }, + { + label: "墨", + value: "2" + }, + { + label: "纸", + value: "3" + }, + { + label: "砚", + value: "4" + }], + config: + { + optionsType: 0, + addAll: "全部", + transformData: "number" + }, + name: "select1695712048045", + item: + { + label: "下拉选择框" + } + }, + { + type: "timePicker", + control: + { + modelValue: "", + format: "" + }, + config: + {}, + name: "timePicker1695712127740", + item: + { + label: "时间选择器" + } + }, + { + type: "colorPicker", + control: + { + modelValue: "", + colorFormat: "rgb" + }, + config: + {}, + name: "colorPicker1695712229351", + item: + { + label: "取色器" + } + }, + { + type: "switch", + control: + { + modelValue: false, + activeValue: 1, + inactiveValue: 2 + }, + config: + {}, + name: "switch1695712256687", + item: + { + label: "开关" + } + }, + { + type: "inputNumber", + control: + { + modelValue: 0 + }, + config: + {}, + name: "inputNumber1695712298560", + item: + { + label: "计数器" + } + }, + { + type: "cascader", + control: + { + modelValue: [] + }, + options: [ + { + value: "guide", + label: "Guide", + children: [ + { + value: "disciplines", + label: "Disciplines", + children: [ + { + value: "consistency", + label: "Consistency" + }, + { + value: "feedback", + label: "Feedback" + }, + { + value: "efficiency", + label: "Efficiency" + }, + { + value: "controllability", + label: "Controllability" + }] + }, + { + value: "navigation", + label: "Navigation", + children: [ + { + value: "side nav", + label: "Side Navigation" + }, + { + value: "top nav", + label: "Top Navigation" + }] + }] + }, + { + value: "component", + label: "Component", + children: [ + { + value: "basic", + label: "Basic", + children: [ + { + value: "layout", + label: "Layout" + }, + { + value: "color", + label: "Color" + }, + { + value: "typography", + label: "Typography" + }, + { + value: "icon", + label: "Icon" + }, + { + value: "button", + label: "Button" + }] + }, + { + value: "form", + label: "Form", + children: [ + { + value: "radio", + label: "Radio" + }, + { + value: "checkbox", + label: "Checkbox" + }, + { + value: "input", + label: "Input" + }, + { + value: "input-number", + label: "InputNumber" + }, + { + value: "select", + label: "Select" + }, + { + value: "cascader", + label: "Cascader" + }, + { + value: "switch", + label: "Switch" + }, + { + value: "slider", + label: "Slider" + }, + { + value: "time-picker", + label: "TimePicker" + }, + { + value: "date-picker", + label: "DatePicker" + }, + { + value: "datetime-picker", + label: "DateTimePicker" + }, + { + value: "upload", + label: "Upload" + }, + { + value: "rate", + label: "Rate" + }, + { + value: "form", + label: "Form" + }] + }, + { + value: "data", + label: "Data", + children: [ + { + value: "table", + label: "Table" + }, + { + value: "tag", + label: "Tag" + }, + { + value: "progress", + label: "Progress" + }, + { + value: "tree", + label: "Tree" + }, + { + value: "pagination", + label: "Pagination" + }, + { + value: "badge", + label: "Badge" + }] + }, + { + value: "notice", + label: "Notice", + children: [ + { + value: "alert", + label: "Alert" + }, + { + value: "loading", + label: "Loading" + }, + { + value: "message", + label: "Message" + }, + { + value: "message-box", + label: "MessageBox" + }, + { + value: "notification", + label: "Notification" + }] + }, + { + value: "navigation", + label: "Navigation", + children: [ + { + value: "menu", + label: "Menu" + }, + { + value: "tabs", + label: "Tabs" + }, + { + value: "breadcrumb", + label: "Breadcrumb" + }, + { + value: "dropdown", + label: "Dropdown" + }, + { + value: "steps", + label: "Steps" + }] + }, + { + value: "others", + label: "Others", + children: [ + { + value: "dialog", + label: "Dialog" + }, + { + value: "tooltip", + label: "Tooltip" + }, + { + value: "popover", + label: "Popover" + }, + { + value: "card", + label: "Card" + }, + { + value: "carousel", + label: "Carousel" + }, + { + value: "collapse", + label: "Collapse" + }] + }] + }, + { + value: "resource", + label: "Resource", + children: [ + { + value: "axure", + label: "Axure Components" + }, + { + value: "sketch", + label: "Sketch Templates" + }, + { + value: "docs", + label: "Design Documentation" + }] + }], + config: + { + optionsType: 0, + transformData: "number" + }, + name: "cascader1695712324832", + item: + { + label: "级联选择器" + } + }, + { + type: "rate", + control: + { + modelValue: 0, + max: 10 + }, + config: + {}, + name: "rate1695712405129", + item: + { + label: "评分" + } + }, + { + type: "slider", + control: + { + modelValue: 0, + min: 0, + max: 10, + step: 1 + }, + config: + {}, + name: "slider1695712423938", + item: + { + label: "滑块" + } + }, + { + type: "treeSelect", + control: + { + modelValue: "", + data: [ + { + label: "Level one 1", + children: [ + { + label: "Level two 1-1", + children: [ + { + label: "Level three 1-1-1" + }] + }] + }, + { + label: "Level one 2", + children: [ + { + label: "Level two 2-1", + children: [ + { + label: "Level three 2-1-1" + }] + }, + { + label: "Level two 2-2", + children: [ + { + label: "Level three 2-2-1" + }] + }] + }, + { + label: "Level one 3", + children: [ + { + label: "Level two 3-1", + children: [ + { + label: "Level three 3-1-1" + }] + }, + { + label: "Level two 3-2", + children: [ + { + label: "Level three 3-2-1" + }] + }] + }], + renderAfterExpand: false + }, + config: + { + optionsType: 0, + transformData: "number" + }, + name: "treeSelect1695712442351", + item: + { + label: "树形控件" + } + }, + { + type: "txt", + control: + { + modelValue: "文字描述" + }, + config: + {} + }, + { + type: "title", + control: + { + modelValue: "标题空间" + }, + config: + {} + }, + { + type: "upload", + control: + { + modelValue: "", + action: "/api/upordown" + }, + config: + {}, + name: "upload1695712574412", + item: + { + label: "图片/文件" + } + }, + { + type: "tinymce", + control: + { + modelValue: "" + }, + config: + {}, + name: "tinymce1695712627245", + item: + { + label: "富文本" + } + }, + { + type: "expand-user", + control: + { + modelValue: "" + }, + config: + {}, + name: "expand-user1695712647280", + item: + { + label: "选择用户" + } + }, + { + type: "button", + control: + { + label: "按钮", + key: "submit" + }, + config: + { + textAlign: "center" + } + }], + form: + { + size: "default", + name: "customer_form_167271084951867392", + formName: "所有空间验证" + }, + config: + {} + } \ No newline at end of file diff --git a/api/version1/taskplatform/taskflow/types.go b/api/version1/taskplatform/taskflow/types.go new file mode 100644 index 0000000..8cb1c08 --- /dev/null +++ b/api/version1/taskplatform/taskflow/types.go @@ -0,0 +1,36 @@ +package taskflow + +import ( + "appPlatform/overall/publicmethod" + "sync" + + "github.com/gin-gonic/gin" +) + +// 协程设置 +var syncSeting = sync.WaitGroup{} + +type ApiMethod struct{} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-05-25 10:20:11 +@ 功能:自定义表单流程表单列表 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) Index(c *gin.Context) { + outputCont := publicmethod.MapOut[string]() + outputCont["index"] = "流程表单内容列表入口" + publicmethod.Result(0, outputCont, c) +} diff --git a/api/version1/taskplatform/taskmanagement/appform.go b/api/version1/taskplatform/taskmanagement/appform.go new file mode 100644 index 0000000..83b1547 --- /dev/null +++ b/api/version1/taskplatform/taskmanagement/appform.go @@ -0,0 +1,479 @@ +package taskmanagement + +import ( + "appPlatform/models/modelAppPlatform" + "appPlatform/models/modelshr" + "appPlatform/overall" + "appPlatform/overall/publicmethod" + "encoding/json" + "errors" + "fmt" + "strconv" + "time" + + "github.com/gin-gonic/gin" +) + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-21 15:19:03 +@ 功能: 非流程表单提交数据记录 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) AppFormDataLog(c *gin.Context) { + var requestData AppFormDataLogStruct + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Page == 0 { + requestData.Page = 1 + } + if requestData.PageSize == 0 { + requestData.Page = 15 + } + context, _ := c.Get(overall.MyContJwt) + var userCont modelshr.ManCont + userCont.GetLoginCont(context) + var list []modelAppPlatform.Task + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.Task{}).Where("`status` BETWEEN ? AND ? AND `creater` = ?", 1, 4, userCont.Key) + if requestData.KeyWords != "" { + gormDb = gormDb.Where("`title` LIKE ?", "%"+requestData.KeyWords+"%") + } + var total int64 + totalErr := gormDb.Count(&total).Error + if totalErr != nil { + total = 0 + } + gormDb = publicmethod.PageTurningSettings(gormDb, requestData.Page, requestData.PageSize) + err = gormDb.Order("`id` DESC").Find(&list).Error + if err != nil && len(list) < 1 { + publicmethod.Result(0, err, c) + return + } + var sendList []SendAppFormDataLog + for _, v := range list { + var sendCont SendAppFormDataLog + sendCont.Id = v.Id //dex"` + sendCont.Title = v.Title //标题"` + sendCont.Creater = v.Creater //创建人"` + sendCont.CreaterTime = v.CreaterTime //创建时间"` + sendCont.EditTime = v.EditTime //编辑时间"` + sendCont.Types = v.Types //类型(1:普通表单;2:流程表单)"` + sendCont.VersionId = v.VersionId //来源于哪个表单"` + sendCont.Status = v.Status // + var myConst modelshr.PersonArchives + myConst.GetCont(map[string]interface{}{"`key`": v.Creater}, "`number`", "`name`") + sendCont.CreaterName = myConst.Name + sendCont.CreaterNumber = myConst.Number + sendCont.CreaterTimeStr = publicmethod.UnixTimeToDay(v.CreaterTime, 1) + sendCont.MastersKey = v.MastersKey + sendCont.MastersKeyStr = strconv.FormatInt(v.MastersKey, 10) + sendList = append(sendList, sendCont) + } + // publicmethod.Result(0, sendList, c) + publicmethod.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(sendList)), sendList, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-22 11:04:56 +@ 功能: 获取可执行得任务列表 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) GainTaskList(c *gin.Context) { + var requestData GainTaskListStruct + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Page == 0 { + requestData.Page = 1 + } + if requestData.PageSize == 0 { + requestData.Page = 15 + } + if requestData.Status == 0 { + requestData.Status = 1 + } + context, _ := c.Get(overall.MyContJwt) + var userCont modelshr.ManCont + userCont.GetLoginCont(context) + var list []modelAppPlatform.CustomerFormView + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.CustomerFormView{}).Where("`status` = 1") + //获取当前登录人得行政组织关系 + var sunOrg publicmethod.GetOrgAllParent + sunOrg.GetOrgSun(userCont.AdminOrg) + sunOrg.GetOrgParentAllId(userCont.AdminOrg) + sunOrg.Id = append(sunOrg.Id, userCont.AdminOrg) + if len(sunOrg.Id) > 0 { + gormDb = gormDb.Where("ISNULL(permitstr) OR permitstr = ''") + var sqlStr string + for i, v := range sunOrg.Id { + if i < len(sunOrg.Id)-1 { + sqlStr = fmt.Sprintf("%v FIND_IN_SET(%v,`permitstr`) OR ", sqlStr, v) + } else { + sqlStr = fmt.Sprintf("%v FIND_IN_SET(%v,`permitstr`) ", sqlStr, v) + } + + // gormDb = gormDb.Or("FIND_IN_SET(?,`permitstr`)", v) + } + gormDb = gormDb.Or(sqlStr) + } else { + gormDb = gormDb.Where("ISNULL(permitstr) OR permitstr = ''", sunOrg.Id) + } + + var total int64 + totalErr := gormDb.Count(&total).Error + if totalErr != nil { + total = 0 + } + gormDb = publicmethod.PageTurningSettings(gormDb, requestData.Page, requestData.PageSize) + err = gormDb.Order("`time` DESC").Order("`id` DESC").Find(&list).Error + if err != nil && len(list) < 1 { + publicmethod.Result(0, err, c) + return + } + var sendList []SendTaskList + for _, v := range list { + var sendCont SendTaskList + sendCont.Id = strconv.FormatInt(v.Id, 10) + sendCont.Name = v.Name + var myInfo modelshr.PersonArchives + myInfo.GetCont(map[string]interface{}{"`key`": v.Creater}, "`number`", "`name`") + sendCont.CreaterName = myInfo.Name + sendCont.CreaterNumber = myInfo.Number + sendCont.CreaterTimeStr = publicmethod.UnixTimeToDay(v.CreaterTime, 1) + sendList = append(sendList, sendCont) + } + // publicmethod.Result(0, sendList, c) + publicmethod.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(sendList)), sendList, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-23 13:51:58 +@ 功能: 根据版本获取表单内容 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) GianTaskVersionCont(c *gin.Context) { + var requestData publicmethod.CommonId[string] + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Id == "" { + publicmethod.Result(107, err, c) + return + } + var versionCont modelAppPlatform.CustomerFormView + err = versionCont.GetCont(map[string]interface{}{"`id`": requestData.Id}) + if err != nil { + publicmethod.Result(107, err, c) + return + } + publicmethod.Result(0, versionCont, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-25 11:42:35 +@ 功能: 自定义表单新增记录数据 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) CustomerFormAddData(c *gin.Context) { + data, err := c.GetRawData() //接收表单提交得数据 + if err != nil { + publicmethod.Result(100, err, c) + return + } + mapData := publicmethod.MapOut[string]() //初始化MAP + err = json.Unmarshal(data, &mapData) //将json字符串转换成Map + sendData := publicmethod.MapOut[string]() + if _, ok := mapData["formId"]; !ok { + publicmethod.Result(1, err, c, "非法表单!不能提交数据!") + return + } + var formCont modelAppPlatform.CustomerFormView + err = formCont.GetCont(map[string]interface{}{"`id`": mapData["formId"]}) + var sunFormName []string + if formCont.TableStructure != "" { + var sunFormStruct map[string]string + err = json.Unmarshal([]byte(formCont.TableStructure), &sunFormStruct) + if err == nil { + for _, v := range sunFormStruct { + if !publicmethod.IsInTrue[string](v, sunFormName) { + sunFormName = append(sunFormName, v) + } + } + } + } + context, _ := c.Get(overall.MyContJwt) + var userCont modelshr.ManCont + userCont.GetLoginCont(context) + uuid := publicmethod.GetUUid(1) + cureeTime := time.Now().Unix() + masterFrom := publicmethod.MapOut[string]() + masterFrom["masters_key"] = uuid + masterFrom["creater"] = userCont.Key + masterFrom["creater_time"] = cureeTime + masterFrom["edit_time"] = cureeTime + sunFormList := publicmethod.MapOut[string]() + for k, v := range mapData { + // fmt.Printf("key: %v, value: %v\n", k, v) + if !publicmethod.IsInTrue[string](k, sunFormName) { + if !publicmethod.IsInTrue[string](k, []string{"formId", "id"}) { + masterFrom[k] = v + } + } else { + sunFormList[k] = v + } + } + var taskCont modelAppPlatform.Task + taskCont.MastersKey = uuid + taskCont.Title = fmt.Sprintf("%v-%v(%v)-%v", formCont.Name, userCont.Name, userCont.Number, publicmethod.UnixTimeToDay(cureeTime, 14)) //标题"` + taskCont.Creater = userCont.Key //创建人"` + taskCont.CreaterTime = cureeTime //创建时间"` + taskCont.EditTime = cureeTime //编辑时间"` + taskCont.Types = 1 //类型(1:普通表单;2:流程表单)"` + taskCont.VersionId = formCont.Id //来源于哪个表单"` + taskCont.Status = 2 //状态(1:草稿,2:发表;3:审批中;4:归档;5:删除)"` + if len(sunFormList) > 0 { + WriteDatabase(uuid, userCont.Key, cureeTime, taskCont, formCont.TableKey, masterFrom, sunFormList) + } else { + + err = overall.CONSTANT_DB_CustomerForm.Table(formCont.TableKey).Create(masterFrom).Error + overall.CONSTANT_DB_AppPlatform.Create(&taskCont) + + } + sendData["err"] = err + sendData["data"] = data + sendData["mapData"] = mapData + sendData["formCont"] = formCont + sendData["masterFrom"] = masterFrom + sendData["sunFormList"] = sunFormList + publicmethod.Result(0, sendData, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-25 14:33:51 +@ 功能: 写入数据库 +@ 参数 + + #uuid 唯一标识 + #creater 创建人 + #createrTime 创建时间 + #taskCont 主记录表 + #masterTableName 主表标识 + #masterDataCont 主表数据 + #sunDataList 字表数据列表 + +@ 返回值 + + #err 返回信息 + +@ 方法原型 + + #func WriteDatabase(uuid, creater, createrTime int64, masterTableName string, masterDataCont, sunDataList map[string]interface{}) (err error) +*/ +func WriteDatabase(uuid, creater, createrTime int64, taskCont modelAppPlatform.Task, masterTableName string, masterDataCont, sunDataList map[string]interface{}) (err error) { + + if len(sunDataList) > 0 && len(masterDataCont) > 0 { + sunMasterMap := publicmethod.MapOut[string]() + for k, v := range sunDataList { + s, ok := v.([]interface{}) + if !ok { + err = errors.New("表单数据错误!请验证后重新提交!") + return + } else { + if len(s) > 0 { + var sunCont []map[string]interface{} + for _, sv := range s { + if sdf, isOk := sv.(map[string]interface{}); isOk { + for sdk, sdv := range sdf { + if fieldVal, filedIsok := sdv.(bool); filedIsok { + if fieldVal { + sdf[sdk] = 1 + } else { + sdf[sdk] = 2 + } + } + } + sdf["masters_key"] = uuid + sdf["creater"] = creater + sdf["creater_time"] = createrTime + sdf["edit_time"] = createrTime + + sunCont = append(sunCont, sdf) + } + + } + sunMasterMap[k] = sunCont + } + + } + } + if len(sunMasterMap) < 1 { + err = overall.CONSTANT_DB_CustomerForm.Table(masterTableName).Create(masterDataCont).Error + overall.CONSTANT_DB_AppPlatform.Create(&taskCont) + } else { + + gormDb := overall.CONSTANT_DB_CustomerForm.Begin() + masterErr := gormDb.Table(masterTableName).Create(masterDataCont).Error + taskErr := overall.CONSTANT_DB_AppPlatform.Create(&taskCont).Error + sunCreateIsOk := true + for k, v := range sunMasterMap { + sunErr := gormDb.Table(k).Create(v).Error + if sunErr != nil { + sunCreateIsOk = false + break + } + // fmt.Printf("234----->%v----->%v\n", k, v) + } + if masterErr == nil && taskErr == nil && sunCreateIsOk { + err = gormDb.Commit().Error + } else { + gormDb.Rollback() + err = errors.New("表单数据提交失败!请重新提交") + } + } + } else { + err = errors.New("表单数据错误!请验证后重新提交!") + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-25 11:45:08 +@ 功能: 自定义表单编辑记录数据 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) CustomerFormEditData(c *gin.Context) { + requestData := publicmethod.MapOut[string]() + err := c.ShouldBindQuery(&requestData) + sendData := publicmethod.MapOut[string]() + sendData["err"] = err + sendData["requestData"] = sendData + publicmethod.Result(0, sendData, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-25 11:45:08 +@ 功能: 查看自定义表单记录数据 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) LookCustomerFormData(c *gin.Context) { + var requestData GainCustomerFormLogInfo + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Id == "" { + publicmethod.Result(1, err, c, "未知表单参数!请核对1后重新提交!") + return + } + if requestData.MastersKey == "" { + publicmethod.Result(1, err, c, "未知表单参数!请核对2后重新提交!") + return + } + var customerFormCont modelAppPlatform.CustomerFormView + err = customerFormCont.GetCont(map[string]interface{}{"`id`": requestData.MastersKey}, "`tablekey`", "`table_structure`", "`name`", "`classify`") + if err != nil { + publicmethod.Result(107, err, c) + return + } + masterFormCont := publicmethod.MapOut[string]() + err = overall.CONSTANT_DB_CustomerForm.Table(customerFormCont.TableKey).Where("`masters_key` = ?", requestData.Id).Find(&masterFormCont).Error + if customerFormCont.TableStructure != "" { + sunFormTable := publicmethod.MapOut[string]() + err = json.Unmarshal([]byte(customerFormCont.TableStructure), &sunFormTable) + if err == nil { + for _, v := range sunFormTable { + var sunContList []map[string]interface{} + if tableName, isOk := v.(string); isOk { + overall.CONSTANT_DB_CustomerForm.Table(tableName).Where("`masters_key` = ?", requestData.Id).Find(&sunContList) + masterFormCont[tableName] = sunContList + } + } + } + } + sendData := publicmethod.MapOut[string]() + sendData["err"] = err + sendData["customerFormCont"] = customerFormCont + sendData["masterFormCont"] = masterFormCont + publicmethod.Result(0, masterFormCont, c) +} diff --git a/api/version1/taskplatform/taskmanagement/types.go b/api/version1/taskplatform/taskmanagement/types.go new file mode 100644 index 0000000..c29de0e --- /dev/null +++ b/api/version1/taskplatform/taskmanagement/types.go @@ -0,0 +1,73 @@ +package taskmanagement + +import ( + "appPlatform/models/modelAppPlatform" + "appPlatform/overall/publicmethod" + "sync" + + "github.com/gin-gonic/gin" +) + +// 协程设置 +var syncSeting = sync.WaitGroup{} + +type ApiMethod struct{} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-05-25 10:20:11 +@ 功能:自定义表单非流程表单列表 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) Index(c *gin.Context) { + outputCont := publicmethod.MapOut[string]() + outputCont["index"] = "非流程表单内容列表入口" + publicmethod.Result(0, outputCont, c) +} + +// 非流程表单提交数据记录参数 +type AppFormDataLogStruct struct { + publicmethod.PagesTurn + KeyWords string `json:"keywords"` +} + +// 返回非流程表单记录数据 +type SendAppFormDataLog struct { + modelAppPlatform.Task + CreaterName string `json:"createrName"` + CreaterNumber string `json:"createrNumber"` + CreaterTimeStr string `json:"createrTame"` + MastersKeyStr string `json:"mastersKeyStr"` +} + +// 获取可执行得任务列表 +type GainTaskListStruct struct { + publicmethod.PagesTurn + publicmethod.PublicStatus +} + +// 输出可执行得任务列表内容 +type SendTaskList struct { + publicmethod.CommonId[string] + publicmethod.PublicName + CreaterName string `json:"createrName"` + CreaterNumber string `json:"createrNumber"` + CreaterTimeStr string `json:"createrTame"` +} + +// 获取表单详细内容 +type GainCustomerFormLogInfo struct { + publicmethod.CommonId[string] + MastersKey string `json:"formId"` +} diff --git a/apirouter/apishiyan/maptostruct.go b/apirouter/apishiyan/maptostruct.go index d7b8bb6..4c6a558 100644 --- a/apirouter/apishiyan/maptostruct.go +++ b/apirouter/apishiyan/maptostruct.go @@ -18,5 +18,14 @@ func (a *ApiRouter) RouterGroup(router *gin.RouterGroup) { apiRouter.POST("charparking", methodBinding.CharParking) //获取车场车位信息 apiRouter.POST("testpage", methodBinding.TestPage) //获取车场车位信息 + + apiRouter.POST("canshu", methodBinding.Canshu) //获取车场车位信息 + + apiRouter.POST("create_table", methodBinding.CreateTable) //模拟创建表单 + + apiRouter.POST("qianyi_version", methodBinding.QianyiVersion) //改革自定义表单列表 + apiRouter.POST("LookTableStruct", methodBinding.LookTableStruct) //查询表结构 + + apiRouter.POST("hzzpy", methodBinding.HanZiZhuanPinYin) //汉字转拼音 } } diff --git a/apirouter/entry.go b/apirouter/entry.go index d965212..7a40389 100644 --- a/apirouter/entry.go +++ b/apirouter/entry.go @@ -9,6 +9,7 @@ import ( matrixrouters "appPlatform/apirouter/v1/matrixRouters" menusrouters "appPlatform/apirouter/v1/menusRouters" "appPlatform/apirouter/v1/public" + "appPlatform/apirouter/v1/taskrouter" userrouters "appPlatform/apirouter/v1/userRouters" ) @@ -23,6 +24,7 @@ type RouterGroup struct { PublicRouters public.ApiRouter SignCodeRouter authenticationroute.ApiRouter CustomerFormRouter customerformrouter.ApiRouter + TaskRouter taskrouter.ApiRouter } var RouterGroupEntry = new(RouterGroup) diff --git a/apirouter/v1/customerformrouter/router.go b/apirouter/v1/customerformrouter/router.go index 633be85..26c2a9d 100644 --- a/apirouter/v1/customerformrouter/router.go +++ b/apirouter/v1/customerformrouter/router.go @@ -12,7 +12,25 @@ func (a *ApiRouter) RouterGroupPc(router *gin.RouterGroup) { var methodBinding = version1.AppApiEntry.CustomerFormApi { - apiRouter.GET("", methodBinding.Index) //入口 - apiRouter.POST("", methodBinding.Index) //入口 + apiRouter.GET("", methodBinding.Index) //入口 + apiRouter.POST("", methodBinding.Index) //入口 + apiRouter.POST("customer_form_list", methodBinding.CustomerFormList) //自定义表单列表 + apiRouter.POST("production_mark_form", methodBinding.ProductionMarkOfCustomerForm) //生成表单基本信息 + apiRouter.POST("save_customer_form", methodBinding.SaveCustomerForm) //保存自定义表单 + apiRouter.POST("look_customer_form", methodBinding.LookCustomerForm) //查看自定义表单 + apiRouter.POST("edit_customer_form_status", methodBinding.EditCustomerFormStatus) //编辑自定义表单状态 + apiRouter.POST("save_setup_cont", methodBinding.SaveSetupCont) //编辑自定义表单设置 + apiRouter.POST("have_customer_form_version", methodBinding.HaveCustomerFormVersion) //获取版本列表 + apiRouter.POST("edit_customer_form_info", methodBinding.EditCustomerFormInfo) //编辑自定义表单内容 + apiRouter.POST("save_as_new_version", methodBinding.SaveAsNewVersion) //另存为新版 + apiRouter.POST("enable_version", methodBinding.EnableVersion) //启用版本 + apiRouter.POST("judge_submit_cancel", methodBinding.JudgeSubmitCancel) //检测是否存在提交和返回按钮 + + apiRouter.POST("have_database_table_struct", methodBinding.HaveDataBaseTableStruct) //数据库表结构(版本及数据表) + apiRouter.POST("have_form_tabelcont", methodBinding.HaveFormTabelCont) //获取表单结构 + apiRouter.POST("have_form_tablelist", methodBinding.HaveFormTableList) //根据版本获取数据库表集合 + apiRouter.POST("optimize_repair_form", methodBinding.OptimizeOrRepairFormTable) //优化/修复数据表 + apiRouter.POST("form_field_handle", methodBinding.FormFieldHandle) //表单结构数据处理 + apiRouter.POST("edit_form_field", methodBinding.EditFormField) //编辑数据库表字段信息 } } diff --git a/apirouter/v1/public/router.go b/apirouter/v1/public/router.go index aecdde5..ff41fee 100644 --- a/apirouter/v1/public/router.go +++ b/apirouter/v1/public/router.go @@ -17,5 +17,6 @@ func (a *ApiRouter) RouterGroupPc(router *gin.RouterGroup) { apiRouter.POST("chinese_initial", methodBinding.ChineseInitial) //获取汉字首字母 apiRouter.POST("send_number", methodBinding.SendNumber) //输出编号 apiRouter.POST("generate_sign_code", methodBinding.GenerateSignCode) //生成身份验证唯一识别符 + apiRouter.POST("chinese_to_pinyin", methodBinding.ChineseToPinyin) //中文转拼音 } } diff --git a/apirouter/v1/taskrouter/taskrouter.go b/apirouter/v1/taskrouter/taskrouter.go new file mode 100644 index 0000000..7dc78a1 --- /dev/null +++ b/apirouter/v1/taskrouter/taskrouter.go @@ -0,0 +1,31 @@ +package taskrouter + +import ( + "appPlatform/api/version1" + + "github.com/gin-gonic/gin" +) + +// 工作台 +func (a *ApiRouter) RouterGroupPc(router *gin.RouterGroup) { + apiRouter := router.Group("task_management") + var taskManagementRouter = version1.AppApiEntry.TaskManagementApi + { + apiRouter.GET("", taskManagementRouter.Index) //入口 + apiRouter.POST("", taskManagementRouter.Index) //入口 + apiRouter.POST("app_formdata_log", taskManagementRouter.AppFormDataLog) //非流程表单提交数据记录 + apiRouter.POST("gain_task_list", taskManagementRouter.GainTaskList) //获取可执行得任务列表 + apiRouter.POST("gain_task_versioncont", taskManagementRouter.GianTaskVersionCont) //根据版本获取表单内容 + apiRouter.POST("customer_form_adddata", taskManagementRouter.CustomerFormAddData) //自定义表单新增记录数据 + apiRouter.POST("customer_form_editdata", taskManagementRouter.CustomerFormEditData) //自定义表单编辑记录数据 + apiRouter.POST("look_customer_formdata", taskManagementRouter.LookCustomerFormData) //查看自定义表单记录数据列表 + } + + taskFlowApi := router.Group("task_flow") + var taskFlowRouter = version1.AppApiEntry.TaskFlowApi + { + taskFlowApi.GET("", taskFlowRouter.Index) //入口 + taskFlowApi.POST("", taskFlowRouter.Index) //入口 + + } +} diff --git a/apirouter/v1/taskrouter/type.go b/apirouter/v1/taskrouter/type.go new file mode 100644 index 0000000..1ce2477 --- /dev/null +++ b/apirouter/v1/taskrouter/type.go @@ -0,0 +1,4 @@ +package taskrouter + +//公共路由 +type ApiRouter struct{} diff --git a/config/configDatabase/database.go b/config/configDatabase/database.go index 55d7054..025bd4f 100644 --- a/config/configDatabase/database.go +++ b/config/configDatabase/database.go @@ -30,6 +30,7 @@ type MysqlSetUp struct { Storage MasterMysqlSetUp `mapstructure:"storage" json:"storage" yaml:"storage"` //仓储系统数据库 ServerMaster MasterMysqlSetUp `mapstructure:"servermaster" json:"servermaster" yaml:"servermaster"` //仓储系统数据库 TidbrMaster MasterMysqlSetUp `mapstructure:"tidbrmaster" json:"tidbrmaster" yaml:"tidbrmaster"` //仓储系统数据库 + CustomerForm MasterMysqlSetUp `mapstructure:"customerFormDatabase" json:"customerFormDatabase" yaml:"customerFormDatabase"` //自定义表单数据库 } type MasterMysqlSetUp struct { diff --git a/initialization/databaseinit/mysql.go b/initialization/databaseinit/mysql.go index cef5177..e43b4fe 100644 --- a/initialization/databaseinit/mysql.go +++ b/initialization/databaseinit/mysql.go @@ -142,4 +142,10 @@ func LoadDatabase() { } else { fmt.Printf("%v数据库开启成功!私有云服务器\n", sqlConfig.TidbrMaster.Name) } + overall.CONSTANT_DB_CustomerForm = sqlConfig.CustomerForm.OpenSql() + if overall.CONSTANT_DB_Tidb == nil { + fmt.Printf("%v数据库开启失败!服务器\n", sqlConfig.CustomerForm.Name) + } else { + fmt.Printf("%v数据库开启成功!服务器\n", sqlConfig.CustomerForm.Name) + } } diff --git a/initialization/route/initRoute.go b/initialization/route/initRoute.go index db1b001..b8591af 100644 --- a/initialization/route/initRoute.go +++ b/initialization/route/initRoute.go @@ -64,6 +64,9 @@ func InitialRouter() *gin.Engine { //自定义表单 customerFormRouterApi := apirouter.RouterGroupEntry.CustomerFormRouter customerFormRouterApi.RouterGroupPc(VerifyIdentity) + //工作台 + taskRouterApi := apirouter.RouterGroupEntry.TaskRouter + taskRouterApi.RouterGroupPc(VerifyIdentity) } //验证身份接口 无需鉴权Url(主要web端使用) VerifyIdentityWeb := router.Group("") diff --git a/models/modelAppPlatform/customer_form.go b/models/modelAppPlatform/customer_form.go new file mode 100644 index 0000000..16f7348 --- /dev/null +++ b/models/modelAppPlatform/customer_form.go @@ -0,0 +1,70 @@ +package modelAppPlatform + +import ( + "appPlatform/overall" + "strings" +) + +// 字典类型 +type CustomerForm struct { + Id int64 `json:"id" gorm:"primaryKey;column:id;type:int(5) unsigned;not null;comment:Id;index"` + Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:表单名称"` + TableNames string `json:"tablename" gorm:"column:tablename;type:varchar(255) unsigned;default:'';not null;comment:创建表单名称"` + Classify int `json:"classify" gorm:"column:classify;type:int(1) unsigned;default:1;not null;comment:分类1:表单;2:流程表单"` + Permit string `json:"permit" gorm:"column:permit;type:mediumtext;default:'';comment:授权范围"` + PermitStr string `json:"permitstr" gorm:"column:permitstr;type:mediumtext;default:'';comment:授权范围"` + States int `json:"states" gorm:"column:states;type:int(1) unsigned;default:1;not null;comment:显示状态(1:启用;2:禁用,3:删除)"` + CreaterTime int64 `json:"createrTime" gorm:"column:creater_time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` + EditTime int64 `json:"editTime" gorm:"column:edit_time;type:bigint(20) unsigned;default:0;not null;comment:编辑时间"` + + // MastesForm string `json:"mastesform" gorm:"column:mastesform;type:longtext;default:'';comment:表单结构"` + // MastesFormJson string `json:"mastesformjson" gorm:"column:mastesformjson;type:longtext;default:'';comment:表单结构json"` + // Creater int64 `json:"creater" gorm:"column:creater;type:bigint(20) unsigned;default:0;not null;comment:创建人"` + // TableStructure string `json:"table_structure" gorm:"column:table_structure;type:longtext;default:'';comment:字表结构"` + // Dict string `json:"dict" gorm:"column:dict;type:mediumtext;default:'';comment:字表结构"` +} + +func (CustomerForm *CustomerForm) TableName() string { + return "customer_form" +} + +// 编辑内容 +func (cont *CustomerForm) EiteCont(whereMap interface{}, saveData interface{}) (err error) { + err = overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Updates(saveData).Error + return +} + +// 获取内容 +func (cont *CustomerForm) GetCont(whereMap interface{}, field ...string) (err error) { + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + gormDb = gormDb.Where(whereMap) + err = gormDb.First(&cont).Error + return +} + +// 根据条件获取总数 +func (cont *CustomerForm) CountCont(whereMap interface{}) (countId int64) { + overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Count(&countId) + return +} + +// 读取全部信息 +func (cont *CustomerForm) ContMap(whereMap interface{}, field ...string) (countAry []CustomerForm, err error) { + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + err = gormDb.Where(whereMap).Find(&countAry).Error + return +} + +// 删除内容 +func (cont *CustomerForm) DelCont(whereMap interface{}) (err error) { + err = overall.CONSTANT_DB_AppPlatform.Where(whereMap).Delete(&cont).Error + return +} diff --git a/models/modelAppPlatform/customer_form_version.go b/models/modelAppPlatform/customer_form_version.go new file mode 100644 index 0000000..e41ed6d --- /dev/null +++ b/models/modelAppPlatform/customer_form_version.go @@ -0,0 +1,66 @@ +package modelAppPlatform + +import ( + "appPlatform/overall" + "strings" +) + +// 自定义表单版本列表 +type CustomerFormVersion struct { + Id int64 `json:"id" gorm:"primaryKey;column:id;type:int(5) unsigned;not null;comment:Id;index"` + TableKey string `json:"tablekey" gorm:"column:tablekey;type:varchar(255) unsigned;default:'';not null;comment:表单标识符"` + Version int64 `json:"version" gorm:"column:version;type:int(5) unsigned;default:1;not null;comment:版本号"` + Status int `json:"status" gorm:"column:status;type:int(1) unsigned;default:1;not null;comment:显示状态(1:启用;2:禁用,3:删除)"` + MastesForm string `json:"mastesform" gorm:"column:mastesform;type:longtext;default:'';comment:表单结构"` + MastesFormJson string `json:"mastesformjson" gorm:"column:mastesformjson;type:longtext;default:'';comment:表单结构json"` + Creater int64 `json:"creater" gorm:"column:creater;type:bigint(20) unsigned;default:0;not null;comment:创建人"` + CreaterTime int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` + EditTime int64 `json:"editTime" gorm:"column:edit_time;type:bigint(20) unsigned;default:0;not null;comment:编辑时间"` + TableStructure string `json:"table_structure" gorm:"column:table_structure;type:longtext;default:'';comment:字表结构"` + Dict string `json:"dict" gorm:"column:dict;type:mediumtext;default:'';comment:字表结构"` +} + +func (CustomerFormVersion *CustomerFormVersion) TableName() string { + return "customer_form_version" +} + +// 编辑内容 +func (cont *CustomerFormVersion) EiteCont(whereMap interface{}, saveData interface{}) (err error) { + err = overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Updates(saveData).Error + return +} + +// 获取内容 +func (cont *CustomerFormVersion) GetCont(whereMap interface{}, field ...string) (err error) { + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + gormDb = gormDb.Where(whereMap) + err = gormDb.First(&cont).Error + return +} + +// 根据条件获取总数 +func (cont *CustomerFormVersion) CountCont(whereMap interface{}) (countId int64) { + overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Count(&countId) + return +} + +// 读取全部信息 +func (cont *CustomerFormVersion) ContMap(whereMap interface{}, field ...string) (countAry []CustomerFormVersion, err error) { + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + err = gormDb.Where(whereMap).Find(&countAry).Error + return +} + +// 删除内容 +func (cont *CustomerFormVersion) DelCont(whereMap interface{}) (err error) { + err = overall.CONSTANT_DB_AppPlatform.Where(whereMap).Delete(&cont).Error + return +} diff --git a/models/modelAppPlatform/customer_form_view.go b/models/modelAppPlatform/customer_form_view.go new file mode 100644 index 0000000..7a7d814 --- /dev/null +++ b/models/modelAppPlatform/customer_form_view.go @@ -0,0 +1,71 @@ +package modelAppPlatform + +import ( + "appPlatform/overall" + "strings" +) + +// 自定义表单版本列表 +type CustomerFormView struct { + Id int64 `json:"id" gorm:"primaryKey;column:id;type:int(5) unsigned;not null;comment:Id;index"` + TableKey string `json:"tablekey" gorm:"column:tablekey;type:varchar(255) unsigned;default:'';not null;comment:表单标识符"` + Version int `json:"version" gorm:"column:version;type:int(5) unsigned;default:1;not null;comment:版本号"` + Status int `json:"status" gorm:"column:status;type:int(1) unsigned;default:1;not null;comment:显示状态(1:启用;2:禁用,3:删除)"` + MastesForm string `json:"mastesform" gorm:"column:mastesform;type:longtext;default:'';comment:表单结构"` + MastesFormJson string `json:"mastesformjson" gorm:"column:mastesformjson;type:longtext;default:'';comment:表单结构json"` + Creater int64 `json:"creater" gorm:"column:creater;type:bigint(20) unsigned;default:0;not null;comment:创建人"` + CreaterTime int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` + EditTime int64 `json:"editTime" gorm:"column:edit_time;type:bigint(20) unsigned;default:0;not null;comment:编辑时间"` + TableStructure string `json:"table_structure" gorm:"column:table_structure;type:longtext;default:'';comment:字表结构"` + Dict string `json:"dict" gorm:"column:dict;type:mediumtext;default:'';comment:字表结构"` + CfId int64 `json:"cfid" gorm:"column:cfid;type:int(5) unsigned;not null;comment:Id"` + Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:表单名称"` + Classify int `json:"classify" gorm:"column:classify;type:int(1) unsigned;default:1;not null;comment:分类1:表单;2:流程表单"` + Permit string `json:"permit" gorm:"column:permit;type:mediumtext;default:'';comment:授权范围"` + PermitStr string `json:"permitstr" gorm:"column:permitstr;type:mediumtext;default:'';comment:授权范围"` +} + +func (CustomerFormView *CustomerFormView) TableName() string { + return "customer_form_view" +} + +// 编辑内容 +func (cont *CustomerFormView) EiteCont(whereMap interface{}, saveData interface{}) (err error) { + err = overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Updates(saveData).Error + return +} + +// 获取内容 +func (cont *CustomerFormView) GetCont(whereMap interface{}, field ...string) (err error) { + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + gormDb = gormDb.Where(whereMap) + err = gormDb.First(&cont).Error + return +} + +// 根据条件获取总数 +func (cont *CustomerFormView) CountCont(whereMap interface{}) (countId int64) { + overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Count(&countId) + return +} + +// 读取全部信息 +func (cont *CustomerFormView) ContMap(whereMap interface{}, field ...string) (countAry []CustomerFormView, err error) { + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + err = gormDb.Where(whereMap).Find(&countAry).Error + return +} + +// 删除内容 +func (cont *CustomerFormView) DelCont(whereMap interface{}) (err error) { + err = overall.CONSTANT_DB_AppPlatform.Where(whereMap).Delete(&cont).Error + return +} diff --git a/models/modelAppPlatform/task.go b/models/modelAppPlatform/task.go new file mode 100644 index 0000000..3b47372 --- /dev/null +++ b/models/modelAppPlatform/task.go @@ -0,0 +1,64 @@ +package modelAppPlatform + +import ( + "appPlatform/overall" + "strings" +) + +// 行政组织类型 +type Task struct { + Id int `json:"id" gorm:"primaryKey;column:id;type:int(5) unsigned;not null;comment:Id;index"` + Title string `json:"title" gorm:"column:title;type:varchar(255) unsigned;default:'';not null;comment:标题"` + Creater int64 `json:"creater" gorm:"column:creater;type:bigint(20) unsigned;default:0;not null;comment:创建人"` + CreaterTime int64 `json:"creater_time" gorm:"column:creater_time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` + EditTime int64 `json:"editTime" gorm:"column:edit_time;type:bigint(20) unsigned;default:0;not null;comment:编辑时间"` + Types int `json:"types" gorm:"column:types;type:int(1) unsigned;default:1;not null;comment:类型(1:普通表单;2:流程表单)"` + VersionId int64 `json:"version_id" gorm:"column:version_id;type:bigint(20) unsigned;default:0;not null;comment:来源于哪个表单"` + Status int `json:"status" gorm:"column:status;type:int(1) unsigned;default:1;not null;comment:状态(1:草稿,2:发表;3:审批中;4:归档;5:删除)"` + MastersKey int64 `json:"masters_key" gorm:"column:masters_key;type:bigint(20) unsigned;default:0;not null;comment:主表标识"` +} + +func (Task *Task) TableName() string { + return "task" +} + +// 编辑内容 +func (cont *Task) EiteCont(whereMap interface{}, saveData interface{}) (err error) { + err = overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Updates(saveData).Error + return +} + +// 获取内容 +func (cont *Task) GetCont(whereMap interface{}, field ...string) (err error) { + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + gormDb = gormDb.Where(whereMap) + err = gormDb.First(&cont).Error + return +} + +// 根据条件获取总数 +func (cont *Task) CountCont(whereMap interface{}) (countId int64) { + overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Count(&countId) + return +} + +// 读取全部信息 +func (cont *Task) ContMap(whereMap interface{}, field ...string) (countAry []Task, err error) { + gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + err = gormDb.Where(whereMap).Find(&countAry).Error + return +} + +// 删除内容 +func (cont *Task) DelCont(whereMap interface{}) (err error) { + err = overall.CONSTANT_DB_AppPlatform.Where(whereMap).Delete(&cont).Error + return +} diff --git a/models/modelshr/man_cont.go b/models/modelshr/man_cont.go index 649a4d7..8acc27e 100644 --- a/models/modelshr/man_cont.go +++ b/models/modelshr/man_cont.go @@ -2,6 +2,7 @@ package modelshr import ( "appPlatform/overall" + "encoding/json" "strings" ) @@ -74,3 +75,13 @@ func (cont *ManCont) GetCont(whereMap interface{}, field ...string) (err error) err = gormDb.First(&cont).Error return } + +// 获取当前登录信息 +func (c *ManCont) GetLoginCont(context any) (err error) { + jsonCont, err := json.Marshal(context) + if err != nil { + return + } + err = json.Unmarshal(jsonCont, c) + return +} diff --git a/models/modelsschool/test_paper.go b/models/modelsschool/test_paper.go index 98ee505..b7359ab 100644 --- a/models/modelsschool/test_paper.go +++ b/models/modelsschool/test_paper.go @@ -11,6 +11,7 @@ type TestPaper struct { UserKey int64 `json:"tp_u_key" gorm:"column:tp_u_key;type:bigint(20) unsigned;default:0;not null;comment:员工唯一识别符"` ExamKey int64 `json:"tp_exa_key" gorm:"column:tp_exa_key;type:bigint(20) unsigned;default:0;not null;comment:考试项目唯一识别符"` RightKey string `json:"tp_right_key" gorm:"column:tp_right_key;type:mediumtext;default:'';comment:正确答案"` + TpExaQue string `json:"tp_exa_que" gorm:"column:tp_exa_que;type:mediumtext;default:'';comment:试卷Json格式"` UserReply string `json:"tp_reply" gorm:"column:tp_reply;type:mediumtext;default:'';comment:员工提交答案"` Fraction int `json:"tp_fraction" gorm:"column:tp_fraction;type:int(5);default:1;not null;comment:分数"` SumFraction int `json:"tp_sum_fraction" gorm:"column:tp_sum_fraction;type:int(5);default:1;not null;comment:总分"` diff --git a/overall/appConfig.go b/overall/appConfig.go index 8cbc043..7c97967 100644 --- a/overall/appConfig.go +++ b/overall/appConfig.go @@ -42,6 +42,8 @@ var ( CONSTANT_DB_System_Permission *gorm.DB //系统权限配置数据库 CONSTANT_DB_Storage *gorm.DB //仓储系统数据库 + CONSTANT_DB_CustomerForm *gorm.DB //自定义表单数据库 + CONSTANT_DB_Server *gorm.DB //线上数据库 CONSTANT_DB_Tidb *gorm.DB //私有云数据库 //Redis diff --git a/overall/publicmethod/technique.go b/overall/publicmethod/technique.go index 6f11477..f3771a3 100644 --- a/overall/publicmethod/technique.go +++ b/overall/publicmethod/technique.go @@ -2245,3 +2245,131 @@ func MenuTypeToInt(class string) int { } return 2 } + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-14 13:33:12 +@ 功能: 获取指定括号中的数据 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func MatchBracket(s, starBracket, endBracket string) string { + i := strings.Index(s, starBracket) + if i >= 0 { + // fmt.Printf("match-i-->%v\n", i) + j := strings.Index(s[i:], endBracket) + if j >= 0 { + // fmt.Printf("match-j-->%v-->%v\n", j, s[i+1:i+j]) + return s[i+1 : i+j] + } + } + return "" +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-14 16:01:13 +@ 功能: 通用执行SQL原生语句 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func ExecSql(database, sqlStr string) (err error) { + + switch database { + case "Master": + err = overall.CONSTANT_DB_Master.Exec(sqlStr).Error + case "AppPlatform": + err = overall.CONSTANT_DB_AppPlatform.Exec(sqlStr).Error + case "Wechat": + err = overall.CONSTANT_DB_Wechat.Exec(sqlStr).Error + case "HR": + err = overall.CONSTANT_DB_HR.Exec(sqlStr).Error + case "FILE_BOOK": + err = overall.CONSTANT_DB_FILE_BOOK.Exec(sqlStr).Error + case "ERROR_SUBJECT": + err = overall.CONSTANT_DB_ERROR_SUBJECT.Exec(sqlStr).Error + case "MY_TEST": + err = overall.CONSTANT_DB_MY_TEST.Exec(sqlStr).Error + case "SCORING": + err = overall.CONSTANT_DB_SCORING.Exec(sqlStr).Error + case "QA": + err = overall.CONSTANT_DB_QA.Exec(sqlStr).Error + case "BILLBOARD": + err = overall.CONSTANT_DB_BILLBOARD.Exec(sqlStr).Error + case "HEALTH": + err = overall.CONSTANT_DB_HEALTH.Exec(sqlStr).Error + case "KPI": + err = overall.CONSTANT_DB_KPI.Exec(sqlStr).Error + case "WECHAT_LOG": + err = overall.CONSTANT_DB_WECHAT_LOG.Exec(sqlStr).Error + case "MANAGE_ARCHIVES": + err = overall.CONSTANT_DB_MANAGE_ARCHIVES.Exec(sqlStr).Error + case "System_Permission": + err = overall.CONSTANT_DB_System_Permission.Exec(sqlStr).Error + case "DB_Storage": + err = overall.CONSTANT_DB_Storage.Exec(sqlStr).Error + case "DB_Server": + err = overall.CONSTANT_DB_Server.Exec(sqlStr).Error + case "Tidb": + err = overall.CONSTANT_DB_Tidb.Exec(sqlStr).Error + case "CustomerForm": + err = overall.CONSTANT_DB_CustomerForm.Exec(sqlStr).Error + default: + + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-09-22 11:28:12 +@ 功能: 获取指定行政组织id,所有子类 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (g *GetOrgAllParent) GetOrgSun(superior int64) { + var id []int64 + if superior == 0 { + return + } + err := overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Select("`id`").Where("`state` = 1 AND `superior` = ?", superior).Find(&id).Error + if err != nil || len(id) < 1 { + return + } + for _, v := range id { + if !IsInTrue[int64](v, g.Id) { + g.Id = append(g.Id, v) + } + g.GetOrgSun(v) + } +} diff --git a/scheduledtask/time_task_cron.go b/scheduledtask/time_task_cron.go index 873e1a1..61c2fe0 100644 --- a/scheduledtask/time_task_cron.go +++ b/scheduledtask/time_task_cron.go @@ -1,7 +1,6 @@ package scheduledtask import ( - "appPlatform/api/shiyan/maptostruct" "fmt" "time" @@ -35,7 +34,7 @@ func TimeTask() { */ c.AddFunc("0 0 2 * * *", func() { fmt.Printf("执行定时任务--同步试卷数据---->%v\n", time.Now().UTC()) - maptostruct.TestPageTimeTask() + // maptostruct.TestPageTimeTask() }) //每3秒执行一个任务 c.Start() //启动 defer c.Stop() //设定全部执行后,最后关闭定时任务