15 changed files with 5231 additions and 103 deletions
@ -0,0 +1,415 @@ |
|||||
|
const optAll = { |
||||
|
list: [ |
||||
|
{ |
||||
|
type: "input", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: "" |
||||
|
}, |
||||
|
config: |
||||
|
{}, |
||||
|
name: "input1696058746993", |
||||
|
item: |
||||
|
{ |
||||
|
label: "单行文本" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "password", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: "" |
||||
|
}, |
||||
|
config: |
||||
|
{}, |
||||
|
name: "input1696058918134", |
||||
|
item: |
||||
|
{ |
||||
|
label: "单行文本" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "textarea", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: "" |
||||
|
}, |
||||
|
config: |
||||
|
{}, |
||||
|
name: "textarea1696058748248", |
||||
|
item: |
||||
|
{ |
||||
|
label: "多行文本" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "radio", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: "" |
||||
|
}, |
||||
|
options: [], |
||||
|
config: |
||||
|
{ |
||||
|
optionsType: 0 |
||||
|
}, |
||||
|
name: "radio1696058749689", |
||||
|
item: |
||||
|
{ |
||||
|
label: "单选框组" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "checkbox", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: [] |
||||
|
}, |
||||
|
options: [], |
||||
|
config: |
||||
|
{ |
||||
|
optionsType: 0 |
||||
|
}, |
||||
|
name: "checkbox1696058751136", |
||||
|
item: |
||||
|
{ |
||||
|
label: "多选框组" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "select", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: "", |
||||
|
appendToBody: true |
||||
|
}, |
||||
|
options: [], |
||||
|
config: |
||||
|
{ |
||||
|
optionsType: 0 |
||||
|
}, |
||||
|
name: "select1696058753224", |
||||
|
item: |
||||
|
{ |
||||
|
label: "下拉选择框" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "datePicker", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: "", |
||||
|
type: "date", |
||||
|
valueFormat: "x" |
||||
|
}, |
||||
|
config: |
||||
|
{}, |
||||
|
name: "datePicker1696058754895", |
||||
|
item: |
||||
|
{ |
||||
|
label: "日期选择器" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "timePicker", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: "" |
||||
|
}, |
||||
|
config: |
||||
|
{}, |
||||
|
name: "timePicker1696058756240", |
||||
|
item: |
||||
|
{ |
||||
|
label: "时间选择器" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "colorPicker", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: "" |
||||
|
}, |
||||
|
config: |
||||
|
{}, |
||||
|
name: "colorPicker1696058757846", |
||||
|
item: |
||||
|
{ |
||||
|
label: "取色器" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "switch", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: false |
||||
|
}, |
||||
|
config: |
||||
|
{}, |
||||
|
name: "switch1696058780439", |
||||
|
item: |
||||
|
{ |
||||
|
label: "开关" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "inputNumber", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: 0 |
||||
|
}, |
||||
|
config: |
||||
|
{}, |
||||
|
name: "inputNumber1696058782096", |
||||
|
item: |
||||
|
{ |
||||
|
label: "计数器" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "cascader", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: [] |
||||
|
}, |
||||
|
options: [], |
||||
|
config: |
||||
|
{ |
||||
|
optionsType: 0 |
||||
|
}, |
||||
|
name: "cascader1696058783721", |
||||
|
item: |
||||
|
{ |
||||
|
label: "级联选择器" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "rate", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: 0 |
||||
|
}, |
||||
|
config: |
||||
|
{}, |
||||
|
name: "rate1696058785728", |
||||
|
item: |
||||
|
{ |
||||
|
label: "评分" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "slider", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: 0 |
||||
|
}, |
||||
|
config: |
||||
|
{}, |
||||
|
name: "slider1696058788101", |
||||
|
item: |
||||
|
{ |
||||
|
label: "滑块" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "treeSelect", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: "", |
||||
|
data: [], |
||||
|
renderAfterExpand: false |
||||
|
}, |
||||
|
config: |
||||
|
{ |
||||
|
optionsType: 0 |
||||
|
}, |
||||
|
name: "treeSelect1696058790114", |
||||
|
item: |
||||
|
{ |
||||
|
label: "树形控件" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "txt", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: "" |
||||
|
}, |
||||
|
config: |
||||
|
{} |
||||
|
}, |
||||
|
{ |
||||
|
type: "title", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: "标题" |
||||
|
}, |
||||
|
config: |
||||
|
{} |
||||
|
}, |
||||
|
{ |
||||
|
type: "button", |
||||
|
control: |
||||
|
{ |
||||
|
label: "保存" |
||||
|
}, |
||||
|
config: |
||||
|
{} |
||||
|
}, |
||||
|
{ |
||||
|
type: "table", |
||||
|
list: [], |
||||
|
tableData: [], |
||||
|
control: |
||||
|
{ |
||||
|
border: true |
||||
|
}, |
||||
|
config: |
||||
|
{ |
||||
|
addBtnText: "添加一行" |
||||
|
}, |
||||
|
name: "table1696058799887" |
||||
|
}, |
||||
|
{ |
||||
|
type: "component", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: "" |
||||
|
}, |
||||
|
config: |
||||
|
{}, |
||||
|
name: "component1696058802415", |
||||
|
item: |
||||
|
{ |
||||
|
label: "自定义组件" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "upload", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: "", |
||||
|
action: "/dev-api/api/upordown" |
||||
|
}, |
||||
|
config: |
||||
|
{}, |
||||
|
name: "upload1696058806299", |
||||
|
item: |
||||
|
{ |
||||
|
label: "图片/文件" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "tinymce", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: "" |
||||
|
}, |
||||
|
config: |
||||
|
{}, |
||||
|
name: "tinymce1696058809231", |
||||
|
item: |
||||
|
{ |
||||
|
label: "富文本" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "grid", |
||||
|
columns: [ |
||||
|
{ |
||||
|
attr: |
||||
|
{ |
||||
|
span: 12 |
||||
|
}, |
||||
|
list: [] |
||||
|
}, |
||||
|
{ |
||||
|
attr: |
||||
|
{ |
||||
|
span: 12 |
||||
|
}, |
||||
|
list: [] |
||||
|
}], |
||||
|
control: |
||||
|
{}, |
||||
|
config: |
||||
|
{} |
||||
|
}, |
||||
|
{ |
||||
|
type: "tabs", |
||||
|
columns: [ |
||||
|
{ |
||||
|
label: "Tab1", |
||||
|
list: [] |
||||
|
}], |
||||
|
control: |
||||
|
{}, |
||||
|
config: |
||||
|
{} |
||||
|
}, |
||||
|
{ |
||||
|
type: "card", |
||||
|
list: [], |
||||
|
control: |
||||
|
{}, |
||||
|
config: |
||||
|
{}, |
||||
|
item: |
||||
|
{ |
||||
|
label: "卡片布局" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "flex", |
||||
|
list: [], |
||||
|
tableData: [], |
||||
|
control: |
||||
|
{}, |
||||
|
config: |
||||
|
{ |
||||
|
addBtnText: "添加一行" |
||||
|
}, |
||||
|
name: "flex1696058823576" |
||||
|
}, |
||||
|
{ |
||||
|
type: "divider", |
||||
|
control: |
||||
|
{}, |
||||
|
config: |
||||
|
{}, |
||||
|
item: |
||||
|
{ |
||||
|
label: "分割线" |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
type: "div", |
||||
|
control: |
||||
|
{}, |
||||
|
config: |
||||
|
{}, |
||||
|
list: [] |
||||
|
}, |
||||
|
{ |
||||
|
type: "expand-user", |
||||
|
control: |
||||
|
{ |
||||
|
modelValue: "" |
||||
|
}, |
||||
|
config: |
||||
|
{}, |
||||
|
name: "expand-user1696058834253", |
||||
|
item: |
||||
|
{ |
||||
|
label: "选择用户" |
||||
|
} |
||||
|
}], |
||||
|
form: |
||||
|
{ |
||||
|
size: "default", |
||||
|
name: "customer_form_168743329826082816", |
||||
|
formName: "未命名表单_168743329826082816" |
||||
|
}, |
||||
|
config: |
||||
|
{} |
||||
|
} |
||||
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,520 @@ |
|||||
|
package customerform |
||||
|
|
||||
|
import ( |
||||
|
"appPlatform/overall/publicmethod" |
||||
|
"encoding/json" |
||||
|
"errors" |
||||
|
"fmt" |
||||
|
"strconv" |
||||
|
) |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-09-30 14:37:11 |
||||
|
@ 功能: 分析表格组件转换值类型 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func AnalysisFormUnitClass(subUnit MasterStruct) (fieldCont AnalysisFormSubUnitClass) { |
||||
|
fieldCont.UnitName = subUnit.Type |
||||
|
fieldCont.WordName = subUnit.Name |
||||
|
fieldCont.Describe = subUnit.Item.Label |
||||
|
fieldCont.MinVal = 0 |
||||
|
switch subUnit.Type { |
||||
|
case "input", "password": //单行文本
|
||||
|
if len(subUnit.CustomRules) > 0 { |
||||
|
var fieldType []string |
||||
|
var valType []fieldStruct |
||||
|
for _, v := range subUnit.CustomRules { |
||||
|
switch v.Trigger { |
||||
|
case "mobile", "tel", "phone", "card": |
||||
|
if !publicmethod.IsInTrue[string]("varchar", fieldType) { |
||||
|
fieldType = append(fieldType, "varchar") |
||||
|
valType = append(valType, fieldStruct{Types: "varchar", MaxVal: 50}) |
||||
|
} else { |
||||
|
for i := 0; i < len(valType); i++ { |
||||
|
if valType[i].Types == "varchar" { |
||||
|
valType[i].MaxVal = 50 |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
case "email", "url", "numberLetter": |
||||
|
if !publicmethod.IsInTrue[string]("varchar", fieldType) { |
||||
|
fieldType = append(fieldType, "varchar") |
||||
|
valType = append(valType, fieldStruct{Types: "varchar", MaxVal: 255}) |
||||
|
} else { |
||||
|
for i := 0; i < len(valType); i++ { |
||||
|
if valType[i].Types == "varchar" { |
||||
|
valType[i].MaxVal = 255 |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
case "cn": |
||||
|
if !publicmethod.IsInTrue[string]("mediumtext", fieldType) { |
||||
|
fieldType = append(fieldType, "mediumtext") |
||||
|
valType = append(valType, fieldStruct{Types: "mediumtext", MaxVal: 0}) |
||||
|
} |
||||
|
case "longitude", "latitude": |
||||
|
if !publicmethod.IsInTrue[string]("float", fieldType) { |
||||
|
fieldType = append(fieldType, "float") |
||||
|
valType = append(valType, fieldStruct{Types: "float", MaxVal: 20, MinVal: 20}) |
||||
|
} else { |
||||
|
for i := 0; i < len(valType); i++ { |
||||
|
if valType[i].Types == "float" { |
||||
|
valType[i].MaxVal = 20 |
||||
|
valType[i].MinVal = 20 |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
case "money": |
||||
|
if !publicmethod.IsInTrue[string]("decimal", fieldType) { |
||||
|
fieldType = append(fieldType, "decimal") |
||||
|
valType = append(valType, fieldStruct{Types: "decimal", MaxVal: 20, MinVal: 4}) |
||||
|
} else { |
||||
|
for i := 0; i < len(valType); i++ { |
||||
|
if valType[i].Types == "decimal" { |
||||
|
valType[i].MaxVal = 20 |
||||
|
valType[i].MinVal = 4 |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
case "int": |
||||
|
if !publicmethod.IsInTrue[string]("bigint", fieldType) { |
||||
|
fieldType = append(fieldType, "bigint") |
||||
|
valType = append(valType, fieldStruct{Types: "bigint", MaxVal: 20, Signed: true}) |
||||
|
} else { |
||||
|
for i := 0; i < len(valType); i++ { |
||||
|
if valType[i].Types == "bigint" { |
||||
|
valType[i].MaxVal = 20 |
||||
|
valType[i].Signed = true |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
case "number": |
||||
|
if !publicmethod.IsInTrue[string]("bigint", fieldType) { |
||||
|
fieldType = append(fieldType, "bigint") |
||||
|
valType = append(valType, fieldStruct{Types: "bigint", MaxVal: 20}) |
||||
|
} else { |
||||
|
for i := 0; i < len(valType); i++ { |
||||
|
if valType[i].Types == "bigint" { |
||||
|
valType[i].MaxVal = 20 |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
default: |
||||
|
} |
||||
|
if len(valType) > 0 { |
||||
|
for _, v := range valType { |
||||
|
if v.Types == "mediumtext" { |
||||
|
fieldCont.FieldType = "mediumtext" |
||||
|
} else if v.Types == "varchar" { |
||||
|
fieldCont.FieldType = "varchar" |
||||
|
fieldCont.MaxVal = v.MaxVal |
||||
|
} else if v.Types == "float" { |
||||
|
fieldCont.FieldType = "float" |
||||
|
fieldCont.MaxVal = v.MaxVal |
||||
|
fieldCont.MinVal = v.MinVal |
||||
|
} else if v.Types == "decimal" { |
||||
|
fieldCont.FieldType = "decimal" |
||||
|
fieldCont.MaxVal = v.MaxVal |
||||
|
fieldCont.MinVal = v.MinVal |
||||
|
} else if v.Types == "bigint" { |
||||
|
fieldCont.FieldType = "bigint" |
||||
|
fieldCont.MaxVal = v.MaxVal |
||||
|
fieldCont.Signed = v.Signed |
||||
|
} else { |
||||
|
fieldCont.FieldType = "varchar" |
||||
|
fieldCont.MaxVal = 255 |
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
fieldCont.FieldType = "varchar" |
||||
|
fieldCont.MaxVal = 255 |
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
fieldCont.FieldType = "varchar" |
||||
|
fieldCont.MaxVal = 255 |
||||
|
} |
||||
|
|
||||
|
case "textarea", "tinymce": //多行文本,富文本
|
||||
|
fieldCont.FieldType = "mediumtext" |
||||
|
case "radio": //单选框组
|
||||
|
if subUnit.Config.TransformData == "number" || subUnit.Config.TransformData == "" { |
||||
|
var fieldVal string |
||||
|
if len(subUnit.Options) > 0 { |
||||
|
for _, ov := range subUnit.Options { |
||||
|
if len(fieldVal) < len(ov.Value) { |
||||
|
fieldVal = ov.Value |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
size, fieldType := CalculateCharacterLength("int", fieldVal) |
||||
|
fieldCont.FieldType = fieldType |
||||
|
fieldCont.MaxVal = size |
||||
|
fieldCont.Signed = true |
||||
|
} else { |
||||
|
fieldCont.FieldType = "varchar" |
||||
|
fieldCont.MaxVal = 50 |
||||
|
} |
||||
|
case "checkbox", "cascader", "treeSelect", "upload", "expand-user": //checkbox,级联选择器,树形控件,图片/文件: ,选择用户
|
||||
|
fieldCont.FieldType = "mediumtext" |
||||
|
fieldCont.ValIsAry = true |
||||
|
case "select": //下拉选择框
|
||||
|
if subUnit.Control.Multiple { |
||||
|
fieldCont.FieldType = "mediumtext" |
||||
|
fieldCont.ValIsAry = true |
||||
|
} else { |
||||
|
if subUnit.Config.TransformData == "number" { |
||||
|
var fieldVal string |
||||
|
if len(subUnit.Options) > 0 { |
||||
|
for _, ov := range subUnit.Options { |
||||
|
if len(fieldVal) < len(ov.Value) { |
||||
|
fieldVal = ov.Value |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
size, fieldType := CalculateCharacterLength("int", fieldVal) |
||||
|
fieldCont.FieldType = fieldType |
||||
|
fieldCont.MaxVal = size |
||||
|
fieldCont.Signed = true |
||||
|
} else { |
||||
|
fieldCont.FieldType = "varchar" |
||||
|
fieldCont.MaxVal = 50 |
||||
|
} |
||||
|
} |
||||
|
case "datePicker": //日期选择器
|
||||
|
fieldCont.UnitType = subUnit.Control.Type |
||||
|
switch subUnit.Control.Type { |
||||
|
case "year", "month", "date", "datetime", "week": |
||||
|
fieldCont.FieldType = "bigint" |
||||
|
fieldCont.MaxVal = 20 |
||||
|
case "datetimerange", "daterange", "monthrange": |
||||
|
fieldCont.FieldType = "bigint" |
||||
|
fieldCont.MaxVal = 20 |
||||
|
fieldCont.ValIsAry = true |
||||
|
default: |
||||
|
fieldCont.FieldType = "bigint" |
||||
|
fieldCont.MaxVal = 20 |
||||
|
} |
||||
|
case "timePicker", "inputNumber": //时间选择器,计数器
|
||||
|
fieldCont.FieldType = "bigint" |
||||
|
fieldCont.MaxVal = 20 |
||||
|
case "colorPicker": //取色器
|
||||
|
fieldCont.FieldType = "varchar" |
||||
|
fieldCont.MaxVal = 50 |
||||
|
case "switch": //开关
|
||||
|
var fieldVal string |
||||
|
if len(subUnit.Options) > 0 { |
||||
|
for _, ov := range subUnit.Options { |
||||
|
if len(fieldVal) < len(ov.Value) { |
||||
|
fieldVal = ov.Value |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
size, fieldType := CalculateCharacterLength("int", fieldVal) |
||||
|
fieldCont.FieldType = fieldType |
||||
|
fieldCont.MaxVal = size |
||||
|
fieldCont.Signed = true |
||||
|
case "rate", "slider": //评分,滑块
|
||||
|
fieldVal := strconv.Itoa(subUnit.Control.Max) |
||||
|
size, fieldType := CalculateCharacterLength("int", fieldVal) |
||||
|
fieldCont.FieldType = fieldType |
||||
|
fieldCont.MaxVal = size |
||||
|
fieldCont.Signed = true |
||||
|
case "txt", "button", "title", "table", "grid", "tabs", "card", "flex", "divider", "div": //文本,按钮,标题,表格,格栅,标签,卡片布局,弹性布局,分割线,容器
|
||||
|
case "component": //自定义组件 (格式待定)
|
||||
|
default: |
||||
|
fieldCont.FieldType = "varchar" |
||||
|
fieldCont.MaxVal = 255 |
||||
|
} |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-09-30 14:10:21 |
||||
|
@ 功能: 自定义表格生成数据表 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (c *CustomerFormMaster) CreateFormTable() (relevance string, err error) { |
||||
|
// for _, v := range c.List {
|
||||
|
|
||||
|
// }
|
||||
|
var tableFormSqlAry FormTableSql |
||||
|
tableFormSqlAry.TableSubUnitAnalysis(c.Form.Name, c.List, true) |
||||
|
// jsonStr, _ := json.Marshal(tableFormSqlAry)
|
||||
|
// fmt.Printf("数据表-----》%v\n", string(jsonStr))
|
||||
|
isSunForm := false |
||||
|
if len(tableFormSqlAry.MasterSql) <= 0 { |
||||
|
err = errors.New("没有主表!") |
||||
|
return |
||||
|
} |
||||
|
if len(tableFormSqlAry.SunSql) > 0 { |
||||
|
isSunForm = true |
||||
|
err = CreateForm(c.Form.Name, c.Form.FormName, "InnoDB", true) |
||||
|
} else { |
||||
|
err = CreateForm(c.Form.Name, c.Form.FormName, "MyISAM", true) |
||||
|
} |
||||
|
CreateFormFiled(c.Form.Name, c.Form.FormName, true, tableFormSqlAry.MasterSql) //添加主表字段
|
||||
|
sunFormNameAry := make(map[string]string) |
||||
|
var sunTableNameAry []string |
||||
|
if isSunForm { |
||||
|
for _, v := range tableFormSqlAry.SunSql { |
||||
|
if len(v.SqlAry) > 0 { |
||||
|
sunFormTableName := v.TableName |
||||
|
if !publicmethod.IsInTrue[string](sunFormTableName, sunTableNameAry) { |
||||
|
sunTableNameAry = append(sunTableNameAry, sunFormTableName) |
||||
|
sunFormNameAry[v.TableName] = sunFormTableName |
||||
|
} else { |
||||
|
sunFormTableName = fmt.Sprintf("%v%v", v.TableName, publicmethod.GetUUid(1)) |
||||
|
sunTableNameAry = append(sunTableNameAry, sunFormTableName) |
||||
|
sunFormNameAry[v.TableName] = sunFormTableName |
||||
|
} |
||||
|
err = CreateForm(sunFormTableName, fmt.Sprintf("%v(%v)子表", c.Form.FormName, c.Form.Name), "InnoDB", false) |
||||
|
// fmt.Printf("%v------->%v------->%v\n", sunFormTableName, err, v.SqlAry)
|
||||
|
if err == nil { |
||||
|
CreateFormFiled(sunFormTableName, fmt.Sprintf("%v(%v)子表", c.Form.FormName, c.Form.Name), false, v.SqlAry) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
if len(sunFormNameAry) > 0 { |
||||
|
relevanceByte, _ := json.Marshal(sunFormNameAry) |
||||
|
relevance = string(relevanceByte) |
||||
|
} |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-09-30 14:12:51 |
||||
|
@ 功能: 表格组件拆分 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (f *FormTableSql) TableSubUnitAnalysis(tablename string, subUnitAry []MasterStruct, isMaster bool) { |
||||
|
if len(subUnitAry) > 0 { |
||||
|
var sqlAllAry []string |
||||
|
// fmt.Printf("tablename--->%v===>%v\n", tablename, isMaster)
|
||||
|
for _, v := range subUnitAry { |
||||
|
wordClass := AnalysisFormUnitClass(v) |
||||
|
switch wordClass.UnitName { |
||||
|
case "flex", "table": |
||||
|
if len(v.List) > 0 { |
||||
|
f.TableSubUnitAnalysis(v.Name, v.List, false) |
||||
|
} |
||||
|
case "grid", "tabs": |
||||
|
if len(v.Columns) > 0 { |
||||
|
for _, mv := range v.Columns { |
||||
|
f.TableSubUnitAnalysis(tablename, mv.List, isMaster) |
||||
|
} |
||||
|
} |
||||
|
case "card", "div": |
||||
|
if len(v.List) > 0 { |
||||
|
f.TableSubUnitAnalysis(tablename, v.List, isMaster) |
||||
|
} |
||||
|
default: |
||||
|
masterSql := MakeSql(tablename, wordClass) |
||||
|
sqlAllAry = append(sqlAllAry, masterSql...) |
||||
|
|
||||
|
// if len(masterSql) > 0 {
|
||||
|
// if isMaster {
|
||||
|
// f.MasterSql = append(f.MasterSql, masterSql...)
|
||||
|
// } else {
|
||||
|
// sunSqlAry := publicmethod.MapOut[string]()
|
||||
|
// sunSqlAry[tablename] = masterSql
|
||||
|
// f.SunSql = sunSqlAry
|
||||
|
// }
|
||||
|
|
||||
|
// }
|
||||
|
} |
||||
|
} |
||||
|
// fmt.Printf("tablename--->%v===>%v===>%v\n", tablename, isMaster, sqlAllAry)
|
||||
|
if len(sqlAllAry) > 0 { |
||||
|
if isMaster { |
||||
|
f.MasterSql = append(f.MasterSql, sqlAllAry...) |
||||
|
} else { |
||||
|
if len(f.SunSql) > 0 { |
||||
|
isWrite := true |
||||
|
for sk, s := range f.SunSql { |
||||
|
if s.TableName == tablename { |
||||
|
f.SunSql[sk].SqlAry = append(f.SunSql[sk].SqlAry, sqlAllAry...) |
||||
|
isWrite = false |
||||
|
} |
||||
|
} |
||||
|
if isWrite { |
||||
|
var sunSqlInfo SunSqlCont |
||||
|
sunSqlInfo.TableName = tablename |
||||
|
sunSqlInfo.SqlAry = sqlAllAry |
||||
|
f.SunSql = append(f.SunSql, sunSqlInfo) |
||||
|
} |
||||
|
} else { |
||||
|
var sunSqlInfo SunSqlCont |
||||
|
sunSqlInfo.TableName = tablename |
||||
|
sunSqlInfo.SqlAry = sqlAllAry |
||||
|
f.SunSql = append(f.SunSql, sunSqlInfo) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-10-01 08:22:23 |
||||
|
@ 功能: 组装sql语句 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func MakeSql(tablename string, fieldCont AnalysisFormSubUnitClass) (sql []string) { |
||||
|
if tablename == "" || fieldCont.WordName == "" { |
||||
|
return |
||||
|
} |
||||
|
unsigned := "" |
||||
|
if !fieldCont.Signed { |
||||
|
unsigned = "unsigned" |
||||
|
} |
||||
|
// fmt.Printf("%v------->%v------->%v\n", fieldCont.WordName, fieldCont.FieldType, fieldCont.ValIsAry)
|
||||
|
switch fieldCont.FieldType { |
||||
|
case "int": |
||||
|
sql = append(sql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v(%v) %v NOT NULL DEFAULT %v COMMENT '%v'", tablename, fieldCont.WordName, fieldCont.FieldType, fieldCont.MaxVal, unsigned, fieldCont.MinVal, fieldCont.Describe)) |
||||
|
case "bigint": |
||||
|
sql = append(sql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v(%v) %v NOT NULL DEFAULT %v COMMENT '%v'", tablename, fieldCont.WordName, fieldCont.FieldType, fieldCont.MaxVal, unsigned, fieldCont.MinVal, fieldCont.Describe)) |
||||
|
if fieldCont.ValIsAry { |
||||
|
endField := fmt.Sprintf("%v_end", fieldCont.WordName) |
||||
|
sql = append(sql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v(%v) %v NOT NULL DEFAULT %v COMMENT '%v'", tablename, endField, fieldCont.FieldType, fieldCont.MaxVal, unsigned, fieldCont.MinVal, fieldCont.Describe)) |
||||
|
} |
||||
|
case "float": |
||||
|
sql = append(sql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v(%v,%v) %v NOT NULL DEFAULT 0 COMMENT '%v'", tablename, fieldCont.WordName, fieldCont.FieldType, fieldCont.MaxVal, fieldCont.MinVal, unsigned, fieldCont.Describe)) |
||||
|
case "decimal": |
||||
|
sql = append(sql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v(%v,%v) %v NOT NULL DEFAULT 0 COMMENT '%v'", tablename, fieldCont.WordName, fieldCont.FieldType, fieldCont.MaxVal, fieldCont.MinVal, unsigned, fieldCont.Describe)) |
||||
|
case "mediumtext", "longtext": |
||||
|
sql = append(sql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v COMMENT '%v'", tablename, fieldCont.WordName, fieldCont.FieldType, fieldCont.Describe)) |
||||
|
case "varchar": |
||||
|
sql = append(sql, fmt.Sprintf("ALTER TABLE `%v` ADD COLUMN `%v` %v(%v) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '%v'", tablename, fieldCont.WordName, fieldCont.FieldType, fieldCont.MaxVal, fieldCont.Describe)) |
||||
|
default: |
||||
|
} |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-10-07 14:18:23 |
||||
|
@ 功能: 获取主表及子表相关组件 |
||||
|
@ 参数 |
||||
|
|
||||
|
#tablename 当前表明 |
||||
|
#subUnitAry 组件列表 |
||||
|
#isMaster true:主表;false:子表 |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (f *FormUnitInfo) GainMasterAndSunFormUnit(tablename string, subUnitAry []MasterStruct, isMaster bool) { |
||||
|
if len(subUnitAry) > 0 { |
||||
|
unitAry := make(map[string]MasterStruct) |
||||
|
for _, v := range subUnitAry { |
||||
|
wordClass := AnalysisFormUnitClass(v) |
||||
|
switch wordClass.UnitName { |
||||
|
case "flex", "table": |
||||
|
if len(v.List) > 0 { |
||||
|
f.GainMasterAndSunFormUnit(v.Name, v.List, false) |
||||
|
} |
||||
|
case "grid", "tabs": |
||||
|
if len(v.Columns) > 0 { |
||||
|
for _, mv := range v.Columns { |
||||
|
f.GainMasterAndSunFormUnit(tablename, mv.List, isMaster) |
||||
|
} |
||||
|
} |
||||
|
case "card", "div": |
||||
|
if len(v.List) > 0 { |
||||
|
f.GainMasterAndSunFormUnit(tablename, v.List, isMaster) |
||||
|
} |
||||
|
default: |
||||
|
// unitAry = append(unitAry, v)
|
||||
|
if v.Name != "" { |
||||
|
unitAry[v.Name] = v |
||||
|
if isMaster { |
||||
|
f.MasterInfo = append(f.MasterInfo, v) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
if len(unitAry) > 0 { |
||||
|
if isMaster { |
||||
|
|
||||
|
} else { |
||||
|
if len(f.SunFormInfo) > 0 { |
||||
|
isWrite := true |
||||
|
for sk, s := range f.SunFormInfo { |
||||
|
if s.TableName == tablename { |
||||
|
f.SunFormInfo[sk].UbitInfo = unitAry |
||||
|
isWrite = false |
||||
|
} |
||||
|
} |
||||
|
if isWrite { |
||||
|
var sunTableCont SunFormInfoList |
||||
|
sunTableCont.TableName = tablename |
||||
|
sunTableCont.UbitInfo = unitAry |
||||
|
f.SunFormInfo = append(f.SunFormInfo, sunTableCont) |
||||
|
} |
||||
|
} else { |
||||
|
var sunTableCont SunFormInfoList |
||||
|
sunTableCont.TableName = tablename |
||||
|
sunTableCont.UbitInfo = unitAry |
||||
|
f.SunFormInfo = append(f.SunFormInfo, sunTableCont) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,734 @@ |
|||||
|
package taskmanagement |
||||
|
|
||||
|
import ( |
||||
|
"appPlatform/api/version1/customerform" |
||||
|
"appPlatform/models/modelAppPlatform" |
||||
|
"appPlatform/models/modelshr" |
||||
|
"appPlatform/overall" |
||||
|
"appPlatform/overall/publicmethod" |
||||
|
"encoding/json" |
||||
|
"errors" |
||||
|
"fmt" |
||||
|
"strconv" |
||||
|
"strings" |
||||
|
"time" |
||||
|
|
||||
|
"github.com/gin-gonic/gin" |
||||
|
) |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-09-27 14:21:08 |
||||
|
@ 功能: 用户端自定义表单新增记录 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (a *ApiMethod) AddFormAddData(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
|
||||
|
if err != nil { |
||||
|
publicmethod.Result(100, err, c) |
||||
|
return |
||||
|
} |
||||
|
if _, ok := mapData["formId"]; !ok { |
||||
|
publicmethod.Result(1, err, c, "非法表单!不能提交数据!") |
||||
|
return |
||||
|
} |
||||
|
sendData := publicmethod.MapOut[string]() |
||||
|
var formCont modelAppPlatform.CustomerFormView //获取指定版本的表单
|
||||
|
err = formCont.GetCont(map[string]interface{}{"`id`": mapData["formId"]}) |
||||
|
if err != nil { |
||||
|
publicmethod.Result(107, err, c) |
||||
|
return |
||||
|
} |
||||
|
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) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
masterField := publicmethod.MapOut[string]() |
||||
|
sunFieldAry := publicmethod.MapOut[string]() |
||||
|
for k, v := range mapData { |
||||
|
if !publicmethod.IsInTrue[string](k, sunFormName) { |
||||
|
if !publicmethod.IsInTrue[string](k, []string{"formId", "id"}) { |
||||
|
masterField[k] = v |
||||
|
} |
||||
|
} else { |
||||
|
sunFieldAry[k] = v |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
context, _ := c.Get(overall.MyContJwt) |
||||
|
var userCont modelshr.ManCont |
||||
|
userCont.GetLoginCont(context) |
||||
|
uuid := publicmethod.GetUUid(1) |
||||
|
cureeTime := time.Now().Unix() |
||||
|
|
||||
|
master, sunTable, jsonerr := GainFormStruct(formCont.MastesFormJson) |
||||
|
if jsonerr != nil { |
||||
|
publicmethod.Result(104, err, c) |
||||
|
return |
||||
|
} |
||||
|
// master, _, _ := GainFormStruct(formCont.MastesFormJson)
|
||||
|
masterWriteVal := MakeTableVal(uuid, userCont.Key, cureeTime, masterField, master) |
||||
|
|
||||
|
//任务列表
|
||||
|
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 |
||||
|
//判断是否
|
||||
|
if len(sunFieldAry) > 0 { |
||||
|
//有子表
|
||||
|
err = WriteSunDatabase(uuid, userCont.Key, cureeTime, formCont.TableKey, masterWriteVal, sunFieldAry, sunTable) |
||||
|
} else { |
||||
|
//无子表
|
||||
|
err = overall.CONSTANT_DB_CustomerForm.Table(formCont.TableKey).Create(masterWriteVal).Error |
||||
|
} |
||||
|
if err != nil { |
||||
|
publicmethod.Result(104, err, c) |
||||
|
return |
||||
|
} |
||||
|
overall.CONSTANT_DB_AppPlatform.Create(&taskCont) |
||||
|
// sendData["err"] = err
|
||||
|
// sendData["data"] = data
|
||||
|
// sendData["mapData"] = mapData
|
||||
|
// sendData["formCont"] = formCont
|
||||
|
sendData["master"] = master |
||||
|
sendData["sunTable"] = sunTable |
||||
|
// sendData["jsonerr"] = jsonerr
|
||||
|
// sendData["jsondfg"] = jsondfg
|
||||
|
// sendData["formJsonCont"] = formJsonCont
|
||||
|
|
||||
|
sendData["master_len"] = len(master) |
||||
|
sendData["sunTable_len"] = len(sunTable) |
||||
|
// sendData["masterWriteVal"] = masterWriteVal
|
||||
|
// sendData["sunFormName"] = sunFormName
|
||||
|
// sendData["sunFieldAry"] = sunFieldAry
|
||||
|
sendData["masterField"] = masterField |
||||
|
publicmethod.Result(0, sendData, c) |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-09-28 09:37:49 |
||||
|
@ 功能: 主表与子表数据写入 |
||||
|
@ 参数 |
||||
|
|
||||
|
#uuid 唯一标识 |
||||
|
#creater 创建人 |
||||
|
#createrTime 创建时间 |
||||
|
#masterTableName 主表标识 |
||||
|
#masterDataCont 主表数据 |
||||
|
#sunDataList 字表数据列表 |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func WriteSunDatabase(uuid, creater, createrTime int64, masterTableName string, masterDataCont, sunDataList map[string]interface{}, sunTable map[string]map[string]customerform.MasterStruct) (err error) { |
||||
|
if len(masterDataCont) > 0 { |
||||
|
if len(sunDataList) > 0 { |
||||
|
sunMasterMap := publicmethod.MapOut[string]() |
||||
|
//子表存在时,执行主表和子表数据写入
|
||||
|
for k, v := range sunDataList { |
||||
|
// if k == "table1693811044212" {
|
||||
|
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 { |
||||
|
if sunTableType, sunIsOk := sunTable[k]; sunIsOk { |
||||
|
masterWriteVal := MakeFormMapData(uuid, creater, createrTime, sdf, sunTableType, 2) //转换数据表值
|
||||
|
if len(masterWriteVal) > 0 { |
||||
|
sunCont = append(sunCont, masterWriteVal) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
if len(sunCont) > 0 { |
||||
|
sunMasterMap[k] = sunCont |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
if len(sunMasterMap) > 0 { |
||||
|
gormDb := overall.CONSTANT_DB_CustomerForm.Begin() |
||||
|
masterErr := gormDb.Table(masterTableName).Create(masterDataCont).Error |
||||
|
sunCreateIsOk := true |
||||
|
for k, v := range sunMasterMap { |
||||
|
sunErr := gormDb.Table(k).Create(v).Error |
||||
|
if sunErr != nil { |
||||
|
sunCreateIsOk = false |
||||
|
break |
||||
|
} |
||||
|
} |
||||
|
if masterErr == nil && sunCreateIsOk { |
||||
|
err = gormDb.Commit().Error |
||||
|
} else { |
||||
|
gormDb.Rollback() |
||||
|
err = errors.New("表单数据提交失败!请重新提交") |
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
//子表不存在时,写入主表数据
|
||||
|
err = overall.CONSTANT_DB_CustomerForm.Table(masterTableName).Create(masterDataCont).Error |
||||
|
} |
||||
|
} else { |
||||
|
err = errors.New("表单数据提交失败!请重新提交") |
||||
|
} |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-09-27 16:01:48 |
||||
|
@ 功能: 组装数据表值 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func MakeTableVal(uuid, userKey, cureeTime int64, fieldVal map[string]interface{}, subUnit map[string]customerform.MasterStruct) map[string]interface{} { |
||||
|
keyAndVal := make(map[string]interface{}) |
||||
|
keyAndVal["masters_key"] = uuid |
||||
|
keyAndVal["creater"] = userKey |
||||
|
keyAndVal["creater_time"] = cureeTime |
||||
|
keyAndVal["edit_time"] = cureeTime |
||||
|
for k, v := range fieldVal { |
||||
|
if v != "" { |
||||
|
if val, isOk := subUnit[k]; isOk { |
||||
|
fielfInfoClass := customerform.AnalysisTable(val) |
||||
|
// fmt.Printf("k--->%v\nv--->%T\nfielfInfoClass------>%v\n\n\n", k, v, fielfInfoClass)
|
||||
|
switch fielfInfoClass.Types { |
||||
|
case "int", "bigint": |
||||
|
//值类型是数组,并且需要分开存储
|
||||
|
switch fielfInfoClass.ControlType { |
||||
|
case "year", "month", "date", "datetime": |
||||
|
if strVal, ok := v.(string); ok { |
||||
|
localTime, _ := time.ParseInLocation(time.RFC3339, strVal, time.Local) |
||||
|
keyAndVal[k] = localTime.Unix() |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
case "array": |
||||
|
if fielfInfoClass.Signed { |
||||
|
kEnd := fmt.Sprintf("%v_end", k) |
||||
|
if strVal, ok := v.([]interface{}); ok { |
||||
|
if len(strVal) >= 2 { |
||||
|
if starTimeStr, tOk := strVal[0].(string); tOk { |
||||
|
starTime, _ := time.ParseInLocation(time.RFC3339, starTimeStr, time.Local) |
||||
|
keyAndVal[k] = starTime.Unix() |
||||
|
} else { |
||||
|
keyAndVal[k] = strVal[0] |
||||
|
} |
||||
|
if endTimeStr, tOk := strVal[len(strVal)-1].(string); tOk { |
||||
|
endTime, _ := time.ParseInLocation(time.RFC3339, endTimeStr, time.Local) |
||||
|
keyAndVal[kEnd] = endTime.Unix() |
||||
|
} else { |
||||
|
keyAndVal[kEnd] = strVal[len(strVal)-1] |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} else { |
||||
|
if strVal, ok := v.(string); ok { |
||||
|
floatVal, _ := strconv.ParseInt(strVal, 10, 64) |
||||
|
keyAndVal[k] = floatVal |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
} |
||||
|
case "bigint": |
||||
|
if strVal, ok := v.(string); ok { |
||||
|
floatVal, _ := strconv.ParseInt(strVal, 10, 64) |
||||
|
keyAndVal[k] = floatVal |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
case "int": |
||||
|
if strVal, ok := v.(string); ok { |
||||
|
floatVal, _ := strconv.Atoi(strVal) |
||||
|
keyAndVal[k] = floatVal |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
case "booble": |
||||
|
if strVal, ok := v.(string); ok { |
||||
|
floatVal, _ := strconv.Atoi(strVal) |
||||
|
keyAndVal[k] = floatVal |
||||
|
} else if strVal, ok := v.(bool); ok { |
||||
|
if strVal { |
||||
|
keyAndVal[k] = fielfInfoClass.DefaultValue |
||||
|
} else { |
||||
|
keyAndVal[k] = fielfInfoClass.DefaultValuees |
||||
|
} |
||||
|
|
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
default: |
||||
|
} |
||||
|
case "booble": |
||||
|
if strVal, ok := v.(string); ok { |
||||
|
floatVal, _ := strconv.Atoi(strVal) |
||||
|
keyAndVal[k] = floatVal |
||||
|
} else if strVal, ok := v.(bool); ok { |
||||
|
if strVal { |
||||
|
keyAndVal[k] = fielfInfoClass.DefaultValue |
||||
|
} else { |
||||
|
keyAndVal[k] = fielfInfoClass.DefaultValuees |
||||
|
} |
||||
|
|
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
case "float": |
||||
|
if strVal, ok := v.(string); ok { |
||||
|
floatVal, _ := strconv.ParseFloat(strVal, 64) |
||||
|
keyAndVal[k] = floatVal |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
case "decimal": |
||||
|
if strVal, ok := v.(string); ok { |
||||
|
floatVal, _ := strconv.ParseFloat(strVal, 64) |
||||
|
keyAndVal[k] = floatVal |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
case "mediumtext", "longtext": |
||||
|
if valAry, ok := v.([]interface{}); ok { |
||||
|
if len(valAry) > 0 { |
||||
|
valStrJson, _ := json.Marshal(valAry) |
||||
|
keyAndVal[k] = string(valStrJson) |
||||
|
} else { |
||||
|
keyAndVal[k] = "" |
||||
|
} |
||||
|
} else { |
||||
|
if fielfInfoClass.ControlType == "array" { |
||||
|
if valStr, ok := v.(string); ok { |
||||
|
valStrAry := strings.Split(valStr, ",") |
||||
|
if len(valStrAry) > 0 { |
||||
|
valStrJson, _ := json.Marshal(valStrAry) |
||||
|
keyAndVal[k] = string(valStrJson) |
||||
|
} else { |
||||
|
keyAndVal[k] = "" |
||||
|
} |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
} |
||||
|
default: |
||||
|
if fielfInfoClass.Types != "" { |
||||
|
if valAry, ok := v.([]interface{}); ok { |
||||
|
if len(valAry) > 0 { |
||||
|
valStrJson, _ := json.Marshal(valAry) |
||||
|
keyAndVal[k] = string(valStrJson) |
||||
|
} else { |
||||
|
keyAndVal[k] = "" |
||||
|
} |
||||
|
} else { |
||||
|
if fielfInfoClass.ControlType == "array" { |
||||
|
if valStr, ok := v.(string); ok { |
||||
|
valStrAry := strings.Split(valStr, ",") |
||||
|
if len(valStrAry) > 0 { |
||||
|
valStrJson, _ := json.Marshal(valStrAry) |
||||
|
keyAndVal[k] = string(valStrJson) |
||||
|
} else { |
||||
|
keyAndVal[k] = "" |
||||
|
} |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
// } else {
|
||||
|
// keyAndVal[k] = v
|
||||
|
// }
|
||||
|
|
||||
|
} |
||||
|
return keyAndVal |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-09-27 14:30:57 |
||||
|
@ 功能: 获取组件结构体 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func GainFormStruct(formTabelJson string) (master map[string]customerform.MasterStruct, sunTable map[string]map[string]customerform.MasterStruct, err error) { |
||||
|
//将表格组件json数据转化成结构体
|
||||
|
var formJsonCont customerform.CustomerFormMaster |
||||
|
json.Unmarshal([]byte(formTabelJson), &formJsonCont) |
||||
|
// fmt.Printf("将表格组件json数据转化成结构体---->%v---->%v\n", err, formTabelJson)
|
||||
|
// if err != nil {
|
||||
|
// return
|
||||
|
// }
|
||||
|
masterAry := make(map[string]customerform.MasterStruct) |
||||
|
sunTableAry := make(map[string]map[string]customerform.MasterStruct) |
||||
|
for _, v := range formJsonCont.List { |
||||
|
switch v.Type { |
||||
|
case "grid", "tabs": |
||||
|
if len(v.Columns) > 0 { |
||||
|
for _, cv := range v.Columns { |
||||
|
for _, cvl := range cv.List { |
||||
|
masterAry[cvl.Name] = cvl |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
case "card", "div": |
||||
|
if len(v.List) > 0 { |
||||
|
for _, cvl := range v.List { |
||||
|
masterAry[cvl.Name] = cvl |
||||
|
} |
||||
|
} |
||||
|
case "table", "flex": |
||||
|
if len(v.List) > 0 { |
||||
|
sunTableGd := make(map[string]customerform.MasterStruct) |
||||
|
for _, vl := range v.List { |
||||
|
sunTableGd[vl.Name] = vl |
||||
|
} |
||||
|
sunTableAry[v.Name] = sunTableGd |
||||
|
} |
||||
|
default: |
||||
|
// fmt.Printf("获取组件结构体-->%v-->%v\n", v.Name, v)
|
||||
|
if v.Name != "" { |
||||
|
masterAry[v.Name] = v |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
master = masterAry |
||||
|
sunTable = sunTableAry |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-10-07 13:18:35 |
||||
|
@ 功能: 用户端自定义表单新增记录(新版) |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (a *ApiMethod) AddFormAddNewData(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
|
||||
|
if err != nil { |
||||
|
publicmethod.Result(100, err, c) |
||||
|
return |
||||
|
} |
||||
|
if _, ok := mapData["formId"]; !ok { |
||||
|
publicmethod.Result(1, err, c, "非法表单!不能提交数据!") |
||||
|
return |
||||
|
} |
||||
|
var formCont modelAppPlatform.CustomerFormView //获取指定版本的表单
|
||||
|
err = formCont.GetCont(map[string]interface{}{"`id`": mapData["formId"]}) |
||||
|
if err != nil { |
||||
|
publicmethod.Result(107, err, c) |
||||
|
return |
||||
|
} |
||||
|
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) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
masterField := publicmethod.MapOut[string]() //主表数据
|
||||
|
sunFieldAry := publicmethod.MapOut[string]() //子表数据
|
||||
|
for k, v := range mapData { |
||||
|
if !publicmethod.IsInTrue[string](k, sunFormName) { |
||||
|
if !publicmethod.IsInTrue[string](k, []string{"formId", "id"}) { |
||||
|
masterField[k] = v |
||||
|
} |
||||
|
} else { |
||||
|
sunFieldAry[k] = v |
||||
|
} |
||||
|
} |
||||
|
context, _ := c.Get(overall.MyContJwt) |
||||
|
var userCont modelshr.ManCont |
||||
|
userCont.GetLoginCont(context) //当前操作人
|
||||
|
uuid := publicmethod.GetUUid(1) //统一识别符
|
||||
|
cureeTime := time.Now().Unix() //写入时间
|
||||
|
|
||||
|
var formJsonCont customerform.CustomerFormMaster |
||||
|
json.Unmarshal([]byte(formCont.MastesFormJson), &formJsonCont) |
||||
|
|
||||
|
var formUnitCont customerform.FormUnitInfo |
||||
|
formUnitCont.GainMasterAndSunFormUnit(formCont.TableKey, formJsonCont.List, true) |
||||
|
masterUnitList := make(map[string]customerform.MasterStruct) |
||||
|
for _, v := range formUnitCont.MasterInfo { |
||||
|
masterUnitList[v.Name] = v |
||||
|
} |
||||
|
masrWriteMap := MakeFormMapData(uuid, userCont.Key, cureeTime, masterField, masterUnitList, 1) |
||||
|
|
||||
|
//任务列表
|
||||
|
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 |
||||
|
|
||||
|
//判断是否
|
||||
|
if len(sunFieldAry) > 0 { |
||||
|
//有子表
|
||||
|
sunTypeAry := make(map[string]map[string]customerform.MasterStruct) |
||||
|
for _, v := range formUnitCont.SunFormInfo { |
||||
|
sunTypeAry[v.TableName] = v.UbitInfo |
||||
|
} |
||||
|
|
||||
|
err = WriteSunDatabase(uuid, userCont.Key, cureeTime, formCont.TableKey, masrWriteMap, sunFieldAry, sunTypeAry) |
||||
|
} else { |
||||
|
// //无子表
|
||||
|
err = overall.CONSTANT_DB_CustomerForm.Table(formCont.TableKey).Create(masterUnitList).Error |
||||
|
} |
||||
|
if err != nil { |
||||
|
publicmethod.Result(104, err, c) |
||||
|
return |
||||
|
} |
||||
|
err = overall.CONSTANT_DB_AppPlatform.Create(&taskCont).Error |
||||
|
|
||||
|
sendData := publicmethod.MapOut[string]() |
||||
|
sendData["uuid"] = uuid |
||||
|
sendData["cureeTime"] = cureeTime |
||||
|
sendData["formUnitCont"] = formUnitCont |
||||
|
sendData["masterField"] = masterField |
||||
|
sendData["sunFieldAry"] = sunFieldAry |
||||
|
sendData["masrWriteMap"] = masrWriteMap |
||||
|
sendData["sunFormName"] = sunFormName |
||||
|
sendData["mapData"] = mapData |
||||
|
|
||||
|
publicmethod.Result(0, err, c) |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-10-07 15:35:07 |
||||
|
@ 功能: 组装数据表新增数据 |
||||
|
@ 参数 |
||||
|
|
||||
|
#uuid 统一识别符 |
||||
|
#userKey 当前操作人 |
||||
|
#cureeTime 操作时间 |
||||
|
#fieldVal 提交数据得键值对 |
||||
|
#subUnit 组件信息 |
||||
|
#calss 1:新增;2:编辑 |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func MakeFormMapData(uuid, userKey, cureeTime int64, fieldVal map[string]interface{}, subUnit map[string]customerform.MasterStruct, calss int) map[string]interface{} { |
||||
|
keyAndVal := make(map[string]interface{}) |
||||
|
if calss == 1 { |
||||
|
keyAndVal["creater_time"] = cureeTime |
||||
|
} |
||||
|
keyAndVal["masters_key"] = uuid |
||||
|
keyAndVal["creater"] = userKey |
||||
|
keyAndVal["edit_time"] = cureeTime |
||||
|
for k, v := range fieldVal { |
||||
|
// fmt.Printf("写入字段:%v->%v\n", k, v)
|
||||
|
if v != "" { |
||||
|
if val, isOk := subUnit[k]; isOk { |
||||
|
// fmt.Printf("写入字段:%v->%v\n", k, val)
|
||||
|
fielfInfoClass := customerform.AnalysisFormUnitClass(val) |
||||
|
switch fielfInfoClass.FieldType { |
||||
|
case "int": |
||||
|
if strVal, ok := v.(string); ok { |
||||
|
keyAndVal[k], _ = strconv.Atoi(strVal) |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
case "bigint": |
||||
|
if fielfInfoClass.ValIsAry { //判断值是否为数组
|
||||
|
endField := fmt.Sprintf("%v_end", k) |
||||
|
if strVal, ok := v.([]interface{}); ok { |
||||
|
if len(strVal) >= 2 { |
||||
|
if starTimeStr, tOk := strVal[0].(string); tOk { |
||||
|
keyAndVal[k], _ = strconv.ParseInt(starTimeStr, 10, 64) |
||||
|
} else { |
||||
|
keyAndVal[k] = strVal[0] |
||||
|
} |
||||
|
if endTimeStr, tOk := strVal[len(strVal)-1].(string); tOk { |
||||
|
keyAndVal[endField], _ = strconv.ParseInt(endTimeStr, 10, 64) |
||||
|
} else { |
||||
|
keyAndVal[endField] = strVal[len(strVal)-1] |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
if strVal, ok := v.(string); ok { |
||||
|
fieldVal, _ := strconv.ParseInt(strVal, 10, 64) |
||||
|
keyAndVal[k] = fieldVal |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
} |
||||
|
case "float": |
||||
|
if strVal, ok := v.(string); ok { |
||||
|
floatVal, _ := strconv.ParseFloat(strVal, 64) |
||||
|
keyAndVal[k] = floatVal |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
case "decimal": |
||||
|
if strVal, ok := v.(string); ok { |
||||
|
floatVal, _ := strconv.ParseFloat(strVal, 64) |
||||
|
keyAndVal[k] = floatVal |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
case "mediumtext", "longtext": |
||||
|
if valAry, ok := v.([]interface{}); ok { |
||||
|
if len(valAry) > 0 { |
||||
|
valStrJson, _ := json.Marshal(valAry) |
||||
|
keyAndVal[k] = string(valStrJson) |
||||
|
} else { |
||||
|
keyAndVal[k] = "" |
||||
|
} |
||||
|
} else { |
||||
|
if fielfInfoClass.ValIsAry { |
||||
|
if valStr, ok := v.(string); ok { |
||||
|
valStrAry := strings.Split(valStr, ",") |
||||
|
if len(valStrAry) > 0 { |
||||
|
valStrJson, _ := json.Marshal(valStrAry) |
||||
|
keyAndVal[k] = string(valStrJson) |
||||
|
} else { |
||||
|
keyAndVal[k] = "" |
||||
|
} |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
} |
||||
|
case "varchar": |
||||
|
if valAry, ok := v.([]interface{}); ok { |
||||
|
if len(valAry) > 0 { |
||||
|
valStrJson, _ := json.Marshal(valAry) |
||||
|
keyAndVal[k] = string(valStrJson) |
||||
|
} else { |
||||
|
keyAndVal[k] = "" |
||||
|
} |
||||
|
} else { |
||||
|
if fielfInfoClass.ValIsAry { |
||||
|
if valStr, ok := v.(string); ok { |
||||
|
valStrAry := strings.Split(valStr, ",") |
||||
|
if len(valStrAry) > 0 { |
||||
|
valStrJson, _ := json.Marshal(valStrAry) |
||||
|
keyAndVal[k] = string(valStrJson) |
||||
|
} else { |
||||
|
keyAndVal[k] = "" |
||||
|
} |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
} else { |
||||
|
keyAndVal[k] = v |
||||
|
} |
||||
|
} |
||||
|
default: |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return keyAndVal |
||||
|
} |
||||
Loading…
Reference in new issue