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.
165 lines
5.1 KiB
165 lines
5.1 KiB
|
1 year ago
|
package taskmanagement
|
||
|
|
|
||
|
|
import (
|
||
|
|
"appPlatform/api/version1/customerform"
|
||
|
|
"appPlatform/models/customerForm"
|
||
|
|
"appPlatform/models/modelAppPlatform"
|
||
|
|
"appPlatform/models/modelshr"
|
||
|
|
"appPlatform/overall"
|
||
|
|
"appPlatform/overall/publicmethod"
|
||
|
|
"encoding/json"
|
||
|
|
"fmt"
|
||
|
|
"strconv"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2024-06-06 13:57:55
|
||
|
|
@ 功能: 自定义App表单新增记录
|
||
|
|
@ 参数
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 返回值
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 方法原型
|
||
|
|
|
||
|
|
#
|
||
|
|
*/
|
||
|
|
func (a *ApiMethod) CreateAppTask(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["versionId"]; !ok {
|
||
|
|
publicmethod.Result(1, err, c, "非法表单!不能提交数据!")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
status := 1
|
||
|
|
if _, ok := mapData["status"]; ok {
|
||
|
|
fmt.Printf("mapData[status]:%v------------->%T\n", mapData["status"], mapData["status"])
|
||
|
|
if vFloat64, isOk := mapData["status"].(float64); isOk {
|
||
|
|
vStr := strconv.FormatFloat(vFloat64, 'f', -1, 64)
|
||
|
|
status, _ = strconv.Atoi(vStr)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
var formCont modelAppPlatform.CustomerFormView //获取指定版本的表单
|
||
|
|
err = formCont.GetCont(map[string]interface{}{"`id`": mapData["versionId"]})
|
||
|
|
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)
|
||
|
|
masrWriteMap["flowIsOpen"] = formCont.FlowIsOpen
|
||
|
|
//任务列表
|
||
|
|
var taskCont customerForm.TaskRecord
|
||
|
|
taskCont.MastersKey = uuid
|
||
|
|
taskCont.Title = fmt.Sprintf("%v-%v(%v)-%v", formCont.Name, userCont.Name, userCont.Number, publicmethod.UnixTimeToDay(cureeTime, 14)) //标题"`
|
||
|
|
taskCont.AppKey = formCont.Groupid
|
||
|
|
taskCont.TableKey = formCont.SignCode
|
||
|
|
taskCont.Creater = userCont.Key //创建人"`
|
||
|
|
taskCont.CreaterTime = cureeTime //创建时间"`
|
||
|
|
taskCont.EditTime = cureeTime //编辑时间"`
|
||
|
|
taskCont.Types = formCont.FlowIsOpen //类型(1:流程表单;2:普通表单)"`
|
||
|
|
taskCont.VersionId = formCont.Id //来源于哪个表单"`
|
||
|
|
taskCont.Status = status
|
||
|
|
if formCont.FlowIsOpen == 1 {
|
||
|
|
taskCont.Status = status
|
||
|
|
taskCont.FlowKey = formCont.Flowkey
|
||
|
|
var flowInfo modelAppPlatform.FlowVersion
|
||
|
|
flowInfo.GetCont(map[string]interface{}{"`key`": formCont.Flowkey, "`state`": 1}, "`id`")
|
||
|
|
taskCont.FlowRunSing = flowInfo.Id
|
||
|
|
}
|
||
|
|
//判断是否
|
||
|
|
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(masrWriteMap).Error
|
||
|
|
publicmethod.WriteLog("write", "写入自定义表单", formCont.TableKey, err)
|
||
|
|
}
|
||
|
|
if err != nil {
|
||
|
|
publicmethod.Result(104, err, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
taskCont.MastesForm = formCont.MastesForm
|
||
|
|
taskCont.MastesFormJson = formCont.MastesFormJson
|
||
|
|
err = overall.CONSTANT_DB_CustomerForm.Create(&taskCont).Error
|
||
|
|
// for k, v := range masrWriteMap {
|
||
|
|
// fmt.Printf("%v----> %T\n", k, v)
|
||
|
|
// }
|
||
|
|
publicmethod.WriteLog("write", "写入任务", err, taskCont)
|
||
|
|
|
||
|
|
sendData := publicmethod.MapOut[string]()
|
||
|
|
sendData["uuid"] = strconv.FormatInt(uuid, 10)
|
||
|
|
sendData["cureeTime"] = cureeTime
|
||
|
|
sendData["formUnitCont"] = formUnitCont
|
||
|
|
sendData["masterField"] = masterField
|
||
|
|
sendData["sunFieldAry"] = sunFieldAry
|
||
|
|
sendData["sunFieldAry_len"] = len(sunFieldAry)
|
||
|
|
sendData["masrWriteMap"] = masrWriteMap
|
||
|
|
sendData["sunFormName"] = sunFormName
|
||
|
|
sendData["mapData"] = mapData
|
||
|
|
|
||
|
|
publicmethod.Result(0, sendData, c)
|
||
|
|
}
|