You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
734 lines
21 KiB
734 lines
21 KiB
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
|
|
}
|
|
|