13 changed files with 1061 additions and 19 deletions
@ -0,0 +1,593 @@ |
|||
package taskflow |
|||
|
|||
import ( |
|||
"appPlatform/api/version1/customerform" |
|||
"appPlatform/api/version1/taskplatform/taskmanagement" |
|||
"appPlatform/models/modelAppPlatform" |
|||
"appPlatform/models/modelshr" |
|||
"appPlatform/models/reviseform" |
|||
"appPlatform/overall" |
|||
"appPlatform/overall/publicmethod" |
|||
"encoding/json" |
|||
"fmt" |
|||
"strconv" |
|||
"strings" |
|||
"time" |
|||
|
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-12-01 11:40:12 |
|||
@ 功能: 获取要修改的数据 |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func (a *ApiMethod) GainEditFormFlowInfo(c *gin.Context) { |
|||
var requestData publicmethod.PublicId |
|||
err := c.ShouldBindJSON(&requestData) |
|||
if err != nil { |
|||
publicmethod.Result(100, err, c) |
|||
return |
|||
} |
|||
if requestData.Id == "" { |
|||
publicmethod.Result(1, err, c, "未知表单参数!请核对1后重新提交!") |
|||
return |
|||
} |
|||
//第一步判断流程是否已经归档
|
|||
var flowInfo modelAppPlatform.RunFlow |
|||
err = flowInfo.GetCont(map[string]interface{}{"`flow_key`": requestData.Id}, "`flow_key`", "`status`", "`runKey`") |
|||
if err != nil { |
|||
publicmethod.Result(1, err, c, "流程未归档不可执行修改审批") |
|||
return |
|||
} |
|||
//获取当前流程记录使用得哪个表单及表单组件列表
|
|||
var taskInfo modelAppPlatform.Task |
|||
err = taskInfo.GetCont(map[string]interface{}{"`masters_key`": flowInfo.FlowKey}, "`version_id`", "`mastesformjson`") |
|||
if err != nil { |
|||
publicmethod.Result(107, err, c) |
|||
return |
|||
} |
|||
//展开表单
|
|||
var formJsonCont customerform.CustomerFormMaster |
|||
json.Unmarshal([]byte(taskInfo.MastesFormJson), &formJsonCont) |
|||
//获取流程使用得表单数据表
|
|||
var customerFormInfo modelAppPlatform.CustomerFormVersion |
|||
err = customerFormInfo.GetCont(map[string]interface{}{"`id`": taskInfo.VersionId}, "`tablekey`", "`table_structure`", "`dict`") |
|||
if err != nil { |
|||
publicmethod.Result(107, err, c) |
|||
return |
|||
} |
|||
var formUnitCont customerform.FormUnitInfo |
|||
formUnitCont.GainMasterAndSunFormUnit(customerFormInfo.TableKey, formJsonCont.List, true) |
|||
masterUnitList := make(map[string]customerform.MasterStruct) |
|||
for _, v := range formUnitCont.MasterInfo { |
|||
|
|||
masterUnitList[v.Name] = v |
|||
} |
|||
mastKeyName, sunKeyName := formUnitCont.GainMasterAndSunFormUnitNameKey() |
|||
// fmt.Printf("formUnitCont.MasterInfo---->%v---->%v\n", mastKeyName, sunKeyName)
|
|||
masterDataInfo := GainCurrendLogData(flowInfo.FlowKey, customerFormInfo, formUnitCont, masterUnitList) |
|||
|
|||
var logDataInfo FormDataLog |
|||
logDataInfo.FlowKey = flowInfo.FlowKey |
|||
logDataInfo.GainFlowFoemLog() |
|||
// fmt.Printf("logDataInfo.NewData---->%v\n", logDataInfo.NewData)
|
|||
if len(logDataInfo.NewData) > 0 { |
|||
|
|||
logTime := logDataInfo.NewData["logTime"] |
|||
newDataInfo := publicmethod.MapOut[string]() |
|||
for i, _ := range masterDataInfo { |
|||
// fmt.Printf("logDataInfo.masterDataInfo---->%v:%v\n", i, v)
|
|||
for j, jv := range logDataInfo.NewData { |
|||
if i == j { |
|||
newDataInfo[i] = jv |
|||
} |
|||
if j == "explicate" { |
|||
newDataInfo["explicate"] = jv |
|||
} |
|||
} |
|||
} |
|||
// newDataInfo["logTime"] = logDataInfo.NewData["logTime"]
|
|||
logDataInfo.NewData = masterDataInfo |
|||
logDataInfo.NewData["logTime"] = logTime |
|||
masterDataInfo = newDataInfo |
|||
fmt.Printf("新表数据---> %v\n", newDataInfo) |
|||
} else { |
|||
isWrite := true |
|||
for i, _ := range masterDataInfo { |
|||
if i == "explicate" { |
|||
isWrite = false |
|||
} |
|||
} |
|||
if isWrite { |
|||
masterDataInfo["explicate"] = "" |
|||
} |
|||
} |
|||
masterDataInfo["flowKey"] = strconv.FormatInt(flowInfo.FlowKey, 10) |
|||
sendData := publicmethod.MapOut[string]() |
|||
sendData["masterDataInfo"] = masterDataInfo |
|||
|
|||
sendNewData := publicmethod.MapOut[string]() |
|||
sendSunNewData := publicmethod.MapOut[string]() |
|||
for i, v := range logDataInfo.NewData { |
|||
if val, isOk := v.([]map[string]interface{}); !isOk { |
|||
for mi, mv := range mastKeyName { |
|||
if mi == i { |
|||
sendNewData[mv] = v |
|||
} |
|||
} |
|||
} else { |
|||
// fmt.Printf("获取数据类型:---4-->%v----->%v\n", val, sunKeyName[i])
|
|||
var newSunData []map[string]interface{} |
|||
for _, sv := range val { |
|||
sunOld := publicmethod.MapOut[string]() |
|||
for smi, smv := range sv { |
|||
for sui, suv := range sunKeyName[i] { |
|||
if sui == smi { |
|||
sunOld[suv] = smv |
|||
} |
|||
if smi == "id" { |
|||
sunOld[suv] = smv |
|||
} |
|||
} |
|||
} |
|||
newSunData = append(newSunData, sunOld) |
|||
fmt.Printf("获取数据类型:---4-->%v----->%v\n", sv, newSunData) |
|||
} |
|||
sendSunNewData[i] = newSunData |
|||
} |
|||
|
|||
} |
|||
for i, v := range sendSunNewData { |
|||
sendNewData[i] = v |
|||
} |
|||
if len(sendNewData) > 0 { |
|||
sendNewData["logTime"] = logDataInfo.NewData["logTime"] |
|||
} |
|||
|
|||
// fmt.Printf("获取数据类型:----->%v\n", sendNewData)
|
|||
sendData["newData"] = sendNewData |
|||
sendData["oldData"] = EditLogCont(logDataInfo.OldData, mastKeyName, sunKeyName) |
|||
sendData["newDataLen"] = len(sendNewData) |
|||
sendData["logistrue"] = false |
|||
if len(sendNewData) > 0 || len(logDataInfo.OldData) > 0 { |
|||
sendData["logistrue"] = true |
|||
} |
|||
publicmethod.Result(0, sendData, c) |
|||
} |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-12-02 14:42:15 |
|||
@ 功能: 修改历史记录处理 |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func EditLogCont(oldData []map[string]interface{}, mastKeyName map[string]string, sunKeyName map[string]map[string]string) []map[string]interface{} { |
|||
var oldAry []map[string]interface{} |
|||
|
|||
for _, v := range oldData { |
|||
sendNewData := publicmethod.MapOut[string]() |
|||
for fi, fv := range v { |
|||
// fmt.Printf("方法原型===>%v:%T>>>%v\n", fi, fv, fv)
|
|||
if val, isOk := fv.([]interface{}); !isOk { //主表字段
|
|||
for mi, mv := range mastKeyName { |
|||
if mi == fi { |
|||
sendNewData[mv] = fv |
|||
} |
|||
} |
|||
if fi == "explicate" { |
|||
sendNewData["修改说明"] = fv |
|||
// oldDataCont["logTime"] = publicmethod.UnixTimeToDay(v.AddTime, 12)
|
|||
// fmt.Printf("修改说明:---4-->%v----->%v\n", fi, fv)
|
|||
|
|||
} |
|||
if fi == "logTime" { |
|||
sendNewData["logTime"] = fv |
|||
} |
|||
} else { //子表字段
|
|||
var newSunData []map[string]interface{} |
|||
for _, sv := range val { |
|||
if ktv, ok := sv.(map[string]interface{}); ok { |
|||
sunOld := publicmethod.MapOut[string]() |
|||
for smi, smv := range ktv { |
|||
for sui, suv := range sunKeyName[fi] { |
|||
if sui == smi { |
|||
sunOld[suv] = smv |
|||
} |
|||
} |
|||
} |
|||
newSunData = append(newSunData, sunOld) |
|||
} |
|||
|
|||
// fmt.Printf("获取数据类型:---4-->%T----->%v\n", sv, sv)
|
|||
} |
|||
sendNewData[fi] = newSunData |
|||
} |
|||
|
|||
} |
|||
|
|||
// sendNewData["修改说明"] = v["explicate"]
|
|||
oldAry = append(oldAry, sendNewData) |
|||
|
|||
} |
|||
return oldAry |
|||
} |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-12-01 13:37:39 |
|||
@ 功能: 获取数据表单数据 |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func GainCurrendLogData(flowKey int64, customerFormInfo modelAppPlatform.CustomerFormVersion, formUnitCont customerform.FormUnitInfo, masterUnitList map[string]customerform.MasterStruct) map[string]interface{} { |
|||
//获取自定义创建表单数据
|
|||
masterFormCont := publicmethod.MapOut[string]() |
|||
err := overall.CONSTANT_DB_CustomerForm.Table(customerFormInfo.TableKey).Where("`masters_key` = ?", flowKey).Take(&masterFormCont).Error |
|||
if err != nil { |
|||
return masterFormCont |
|||
} |
|||
masterFormCont = taskmanagement.CustomerFormCallBackVal(masterFormCont, masterUnitList) |
|||
if customerFormInfo.TableStructure != "" { |
|||
sunFormTable := publicmethod.MapOut[string]() |
|||
err = json.Unmarshal([]byte(customerFormInfo.TableStructure), &sunFormTable) |
|||
sunTypeAry := make(map[string]map[string]customerform.MasterStruct) |
|||
for _, v := range formUnitCont.SunFormInfo { |
|||
sunTypeAry[v.TableName] = v.UbitInfo |
|||
} |
|||
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` = ?", flowKey).Find(&sunContList) |
|||
var sunContListZhuanBian []map[string]interface{} |
|||
if len(sunContList) > 0 { |
|||
for _, sclv := range sunContList { |
|||
if sunTableType, sunIsOk := sunTypeAry[tableName]; sunIsOk { |
|||
masterFormCont := taskmanagement.CustomerFormCallBackVal(sclv, sunTableType) |
|||
sunContListZhuanBian = append(sunContListZhuanBian, masterFormCont) |
|||
} else { |
|||
sunContListZhuanBian = append(sunContListZhuanBian, sclv) |
|||
} |
|||
} |
|||
} |
|||
fmt.Printf("自定义表单结果值!tableName:%v---->%T---->%v\n", tableName, sunContListZhuanBian, sunContListZhuanBian) |
|||
masterFormCont[tableName] = sunContListZhuanBian |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return masterFormCont |
|||
} |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-12-01 13:19:43 |
|||
@ 功能: 获取自定义表单历史记录 |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func (f *FormDataLog) GainFlowFoemLog() { |
|||
var logDataList []reviseform.EditFormDataLog |
|||
err := overall.CONSTANT_DB_ReviseFormData.Where("`flow_key` = ?", f.FlowKey).Order("`addTime` desc").Find(&logDataList).Error |
|||
if err != nil { |
|||
return |
|||
} |
|||
if len(logDataList) > 0 { |
|||
for _, v := range logDataList { |
|||
if v.State == 1 { |
|||
if v.DataCont != "" { |
|||
json.Unmarshal([]byte(v.DataCont), &f.NewData) |
|||
f.NewData["explicate"] = v.Explicate |
|||
f.NewData["logTime"] = publicmethod.UnixTimeToDay(v.AddTime, 12) |
|||
} |
|||
if v.SunDataCont != "" { |
|||
sunDataList := publicmethod.MapOut[string]() |
|||
json.Unmarshal([]byte(v.SunDataCont), &sunDataList) |
|||
|
|||
for si, sv := range sunDataList { |
|||
f.NewData[si] = sv |
|||
} |
|||
} |
|||
} else { |
|||
var oldDataCont map[string]interface{} |
|||
if v.DataCont != "" { |
|||
json.Unmarshal([]byte(v.DataCont), &oldDataCont) |
|||
|
|||
if v.SunDataCont != "" { |
|||
sunDataList := publicmethod.MapOut[string]() |
|||
json.Unmarshal([]byte(v.SunDataCont), &sunDataList) |
|||
// fmt.Printf("v.SunDataCont====>%v====>%v\n", v.DataCont, sunDataList)
|
|||
for si, sv := range sunDataList { |
|||
// fmt.Printf("v.SunDataCont====>%v====>%v\n", si, sv)
|
|||
oldDataCont[si] = sv |
|||
} |
|||
} |
|||
oldDataCont["explicate"] = v.Explicate |
|||
oldDataCont["logTime"] = publicmethod.UnixTimeToDay(v.AddTime, 12) |
|||
f.OldData = append(f.OldData, oldDataCont) |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-12-01 11:07:06 |
|||
@ 功能: 申请修改数据 |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func (a *ApiMethod) EditFormLogData(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 |
|||
} |
|||
fmt.Printf("接收表单提交得数据-->%v\n", mapData) |
|||
if _, ok := mapData["flowKey"]; !ok { |
|||
publicmethod.Result(1, err, c, "非法表单!1不能提交数据!") |
|||
return |
|||
} |
|||
//第一步判断流程是否已经归档
|
|||
var flowInfo modelAppPlatform.RunFlow |
|||
err = flowInfo.GetCont(map[string]interface{}{"`flow_key`": mapData["flowKey"]}, "`flow_key`", "`status`", "`runKey`", "`id`", "`flow_cont`", "`current_step`", `next_step`, `participants`) |
|||
if err != nil || flowInfo.Status != 4 { |
|||
publicmethod.Result(1, err, c, "流程未归档不可执行修改审批") |
|||
return |
|||
} |
|||
//获取当前流程记录使用得哪个表单及表单组件列表
|
|||
var taskInfo modelAppPlatform.Task |
|||
err = taskInfo.GetCont(map[string]interface{}{"`masters_key`": flowInfo.FlowKey}, "`version_id`", "`mastesformjson`") |
|||
if err != nil { |
|||
publicmethod.Result(107, err, c) |
|||
return |
|||
} |
|||
//获取指定版本表单内容
|
|||
var formCont modelAppPlatform.CustomerFormView //获取指定版本的表单
|
|||
err = formCont.GetCont(map[string]interface{}{"`id`": taskInfo.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"}) { |
|||
masterField[k] = v |
|||
} |
|||
} else { |
|||
sunFieldAry[k] = v |
|||
} |
|||
} |
|||
context, _ := c.Get(overall.MyContJwt) |
|||
var userCont modelshr.ManCont |
|||
userCont.GetLoginCont(context) //当前操作人
|
|||
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 |
|||
} |
|||
uuid := publicmethod.GetUUid(6) |
|||
//自定义表单修改数据历史记录
|
|||
startUs := strconv.FormatInt(userCont.Key, 10) //当前操作人
|
|||
var editFormDataLogInfo reviseform.EditFormDataLog |
|||
editFormDataLogInfo.SourceForm = taskInfo.VersionId //int64 来源表单"`
|
|||
editFormDataLogInfo.FlowKey = flowInfo.FlowKey //int64 流程标识符"`
|
|||
editFormDataLogInfo.RunKey = uuid //int64 当前执行识别符"`
|
|||
editFormDataLogInfo.AddTime = cureeTime //int64 创建时间"`
|
|||
editFormDataLogInfo.State = 1 //int 状态(1、新数据;2:已批准的老数据)"`
|
|||
// editFormDataLogInfo.DataCont = //string 数据值"`
|
|||
if expval, isOk := mapData["explicate"].(string); isOk { |
|||
editFormDataLogInfo.Explicate = expval //string 说明"`
|
|||
} |
|||
|
|||
// editFormDataLogInfo.SunDataCont = //string 子表数值"`
|
|||
|
|||
saveData := publicmethod.MapOut[string]() |
|||
|
|||
//组装数据表新增数据
|
|||
masrWriteMap := taskmanagement.MakeFormMapData(flowInfo.FlowKey, userCont.Key, cureeTime, masterField, masterUnitList, 2) |
|||
masterTableJson, _ := json.Marshal(masrWriteMap) |
|||
editFormDataLogInfo.DataCont = string(masterTableJson) |
|||
//判断是否有子表
|
|||
if len(sunFieldAry) > 0 { |
|||
//有子表
|
|||
sunTypeAry := make(map[string]map[string]customerform.MasterStruct) |
|||
for _, v := range formUnitCont.SunFormInfo { |
|||
sunTypeAry[v.TableName] = v.UbitInfo |
|||
} |
|||
sunTableData := EditSunDatabase(flowInfo.FlowKey, userCont.Key, cureeTime, formCont.TableKey, masrWriteMap, sunFieldAry, sunTypeAry) |
|||
fmt.Printf("判断是否有子表得数据-->%v\n", sunTableData) |
|||
saveData["sunTypeAry"] = sunTableData |
|||
sunTableJson, _ := json.Marshal(sunTableData) |
|||
editFormDataLogInfo.SunDataCont = string(sunTableJson) |
|||
} |
|||
saveData["masrWriteMap"] = masrWriteMap |
|||
editFormDataLogInfo.EiteCont(map[string]interface{}{"`flow_key`": flowInfo.FlowKey, "`state`": 1}, map[string]interface{}{"`state`": 2}) |
|||
fmt.Printf("写入数据-->%v\n", editFormDataLogInfo) |
|||
err = overall.CONSTANT_DB_ReviseFormData.Model(&reviseform.EditFormDataLog{}).Create(&editFormDataLogInfo).Error |
|||
if err != nil { |
|||
publicmethod.Result(106, err, c) |
|||
return |
|||
} |
|||
var flowList []RunFlow |
|||
err = json.Unmarshal([]byte(flowInfo.FlowCont), &flowList) |
|||
//执行流程
|
|||
var runFlow RunWorkFlow |
|||
runFlow.Step = 0 //执行第几部
|
|||
runFlow.FlowList = flowList |
|||
runFlow.Participant = append(runFlow.Participant, startUs) |
|||
runFlow.TotalSteps = len(flowList) //流程总长度
|
|||
runFlow.Uuid = flowInfo.Id |
|||
runFlow.RunUid = uuid |
|||
runFlow.GainRunNode(startUs, 2, "申请修改数据") |
|||
|
|||
flowJsonCont, _ := json.Marshal(runFlow.FlowList) //将步进流转化成json流
|
|||
SaveFlowCont := publicmethod.MapOut[string]() |
|||
SaveFlowCont["`flow_cont`"] = string(flowJsonCont) |
|||
SaveFlowCont["`current_step`"] = runFlow.Step |
|||
SaveFlowCont["`next_step`"] = runFlow.NextStep |
|||
SaveFlowCont["`runKey`"] = uuid |
|||
//参与人去重
|
|||
var parUser []string |
|||
for _, v := range runFlow.Participant { |
|||
if !publicmethod.IsInTrue[string](v, parUser) { |
|||
parUser = append(parUser, v) |
|||
} |
|||
} |
|||
SaveFlowCont["`participants`"] = strings.Join(parUser, ",") |
|||
nextRunUser := runFlow.NextRunNodeUser(1) |
|||
SaveFlowCont["`next_executor`"] = strings.Join(nextRunUser, ",") |
|||
SaveFlowCont["`status`"] = 3 |
|||
if runFlow.NextStep <= 0 { |
|||
SaveFlowCont["`status`"] = 4 |
|||
} |
|||
SaveFlowCont["`update_time`"] = time.Now().Unix() |
|||
|
|||
flowInfo.EiteCont(map[string]interface{}{"`flow_key`": flowInfo.FlowKey}, SaveFlowCont) |
|||
taskInfo.EiteCont(map[string]interface{}{"`masters_key`": flowInfo.FlowKey}, map[string]interface{}{"`status`": 3}) |
|||
publicmethod.Result(0, saveData, c) |
|||
} |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-12-02 09:24:33 |
|||
@ 功能: 处理指标字段值 |
|||
@ 参数 |
|||
|
|||
#uuid 唯一标识 |
|||
#creater 创建人 |
|||
#createrTime 创建时间 |
|||
#masterTableName 主表标识 |
|||
#masterDataCont 主表数据 |
|||
#sunDataList 字表数据列表 |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func EditSunDatabase(uuid, creater, createrTime int64, masterTableName string, masterDataCont, sunDataList map[string]interface{}, sunTable map[string]map[string]customerform.MasterStruct) (sunTableData map[string]interface{}) { |
|||
if len(masterDataCont) > 0 { |
|||
if len(sunDataList) > 0 { |
|||
sunMasterMap := publicmethod.MapOut[string]() |
|||
//子表存在时,执行主表和子表数据写入
|
|||
for k, v := range sunDataList { |
|||
// fmt.Printf("处理指标字段值--->%v--->%v\n", k, v)
|
|||
// 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 := taskmanagement.MakeFormMapData(uuid, creater, createrTime, sdf, sunTableType, 2) //转换数据表值
|
|||
// fmt.Printf("处理指标字段值-1-->%v--->%v\n", sunTableType, masterWriteVal)
|
|||
if len(masterWriteVal) > 0 { |
|||
sunCont = append(sunCont, masterWriteVal) |
|||
} |
|||
} |
|||
} |
|||
} |
|||
if len(sunCont) > 0 { |
|||
sunMasterMap[k] = sunCont |
|||
} |
|||
} |
|||
} |
|||
} |
|||
sunTableData = sunMasterMap |
|||
} |
|||
} |
|||
return |
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
package reviseform |
|||
|
|||
import ( |
|||
"appPlatform/overall" |
|||
"strings" |
|||
) |
|||
|
|||
// 字典类型
|
|||
type EditFormDataLog struct { |
|||
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` |
|||
SourceForm int64 `json:"source_form" gorm:"column:source_form;type:bigint(20) unsigned;default:0;not null;comment:来源表单"` |
|||
FlowKey int64 `json:"flow_key" gorm:"column:flow_key;type:bigint(20) unsigned;default:0;not null;comment:流程标识符"` |
|||
RunKey int64 `json:"runKey" gorm:"column:runKey;type:bigint(20) unsigned;default:0;not null;comment:当前执行识别符"` |
|||
AddTime int64 `json:"addTime" gorm:"column:addTime;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
|||
State int `json:"state" gorm:"column:state;type:int(1) unsigned;default:1;not null;comment:状态(1、新数据;2:已批准的老数据)"` |
|||
DataCont string `json:"dataCont" gorm:"column:dataCont;type:longtext;default:'';comment:数据值"` |
|||
Explicate string `json:"explicate" gorm:"column:explicate;type:longtext;default:'';comment:说明"` |
|||
SunDataCont string `json:"sunDataCont" gorm:"column:sunDataCont;type:longtext;default:'';comment:子表数值"` |
|||
EditTime int64 `json:"editTime" gorm:"column:editTime;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
|||
} |
|||
|
|||
func (EditFormDataLog *EditFormDataLog) TableName() string { |
|||
return "edit_form_data_log" |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *EditFormDataLog) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_ReviseFormData.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *EditFormDataLog) GetCont(whereMap interface{}, field ...string) (err error) { |
|||
gormDb := overall.CONSTANT_DB_ReviseFormData.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 *EditFormDataLog) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_ReviseFormData.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *EditFormDataLog) ContMap(whereMap interface{}, field ...string) (countAry []EditFormDataLog, err error) { |
|||
gormDb := overall.CONSTANT_DB_ReviseFormData.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
err = gormDb.Where(whereMap).Find(&countAry).Error |
|||
return |
|||
} |
|||
|
|||
// 删除内容
|
|||
func (cont *EditFormDataLog) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_ReviseFormData.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
Loading…
Reference in new issue