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.
247 lines
9.1 KiB
247 lines
9.1 KiB
package customerform
|
|
|
|
import (
|
|
datacenter "appPlatform/api/version1/dataCenter"
|
|
"appPlatform/middleware/grocerystore"
|
|
"appPlatform/models/customerForm"
|
|
"appPlatform/models/modelAppPlatform"
|
|
"appPlatform/models/modelshr"
|
|
"appPlatform/overall"
|
|
"appPlatform/overall/publicmethod"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2025-05-22 10:44:33
|
|
@ 功能: 获取App表单翻页列表数据
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) GainFormPageListContNew(c *gin.Context) {
|
|
var requestData FormPageListAttr
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
if requestData.FormId == "" {
|
|
publicmethod.Result(1, err, c, "未知表单!无法获取字段!2")
|
|
return
|
|
}
|
|
if requestData.Page == 0 {
|
|
requestData.Page = 1
|
|
}
|
|
if requestData.PageSize == 0 {
|
|
requestData.Page = 20
|
|
}
|
|
context, _ := c.Get(overall.MyContJwt)
|
|
var userCont modelshr.ManCont
|
|
userCont.GetLoginCont(context) //当前操作人
|
|
|
|
//获取表单数据
|
|
var formInfo modelAppPlatform.CustomerFormView
|
|
err = formInfo.GetCont(map[string]interface{}{"`cfid`": requestData.FormId, "`status`": 1}, "`tablekey`", "`table_structure`", "`mastesform`", "`mastesformjson`", "`listjson`", "`flowIsOpen`", "`flowkey`", "`groupid`", "`cfid`")
|
|
if err != nil {
|
|
publicmethod.Result(1, err, c, "未知表单!无法获取字段!")
|
|
return
|
|
}
|
|
//解析表单列表数据结构
|
|
var formJsonCont CustomerFormMaster
|
|
json.Unmarshal([]byte(formInfo.MastesFormJson), &formJsonCont)
|
|
//解析表格组件数据
|
|
var sunMap map[string]string
|
|
json.Unmarshal([]byte(formInfo.TableStructure), &sunMap)
|
|
|
|
//判断当前数据源来源于什么地方
|
|
if formJsonCont.Form.DataSource == "yes" { //采用外部数据源
|
|
//Step 1 打开数据源
|
|
var sqlDb datacenter.DataBastType
|
|
sqlDb.Type = formJsonCont.Form.DataSourceConfig.DSN.SqlType
|
|
sqlDb.Ip = formJsonCont.Form.DataSourceConfig.DSN.Ip
|
|
sqlDb.DataBaseName = formJsonCont.Form.DataSourceConfig.DSN.DataBaseName
|
|
sqlDb.Port = formJsonCont.Form.DataSourceConfig.DSN.Port
|
|
sqlDb.UserName = formJsonCont.Form.DataSourceConfig.DSN.UserName
|
|
sqlDb.Pwd = formJsonCont.Form.DataSourceConfig.DSN.Password
|
|
sqlDborm, err := sqlDb.StartDataBast()
|
|
if err != nil {
|
|
sqlDborm, err = datacenter.GainDataStorce(formJsonCont.Form.DataSourceConfig.Id)
|
|
if err != nil {
|
|
publicmethod.Result(0, sqlDb, c)
|
|
return
|
|
}
|
|
}
|
|
//Step 2 使用数据源处理数据
|
|
gormDb := sqlDborm.Table(formJsonCont.Form.DataSourceConfig.TableKey) //确定使用哪个库
|
|
gormDb = gormDb.Where("`states` BETWEEN ? AND ?", 1, 2) //基础查询条件
|
|
gormDb = AnalysisSerachTermSql(requestData.SearchData, gormDb) //处理查询条件
|
|
//Step 3 权限处理
|
|
var powerSearch publicmethod.GainUserPower
|
|
powerSearch.SystemName = "appsystem" //系统名称
|
|
powerSearch.RoleId = userCont.Role //角色列表
|
|
powerSearch.OrgId = userCont.AdminOrg //行政组织
|
|
powerSearch.PostId = userCont.Position //岗位
|
|
powerSearch.AppKey = formInfo.Groupid //归属哪个App
|
|
powerSearch.TableId = formInfo.CfId //归属哪个表格
|
|
gormDb = powerSearch.MakeSearchSql(gormDb, userCont, formJsonCont.Form.DataSource)
|
|
//Step 4 获取一共有多少条数据
|
|
var total int64
|
|
totalErr := gormDb.Count(&total).Error
|
|
if totalErr != nil {
|
|
total = 0
|
|
}
|
|
//Step 5 获取每页具体数据
|
|
var formList []map[string]interface{}
|
|
gormDb = publicmethod.PageTurningSettings(gormDb, requestData.Page, requestData.PageSize)
|
|
err = gormDb.Order("`id` DESC").Find(&formList).Error
|
|
if err != nil && len(formList) < 1 {
|
|
publicmethod.Result(0, err, c)
|
|
return
|
|
}
|
|
//Setp 6 列表字段与数据绑定
|
|
var listFieldsMap ListPageFields
|
|
if formInfo.ListJson != "" {
|
|
err = json.Unmarshal([]byte(formInfo.ListJson), &listFieldsMap)
|
|
if err == nil {
|
|
formList = listFieldsMap.DevelopSpecificationsSend(formList, formJsonCont)
|
|
}
|
|
}
|
|
//Setp 7 处理信息任务状态
|
|
for i, v := range formList {
|
|
formList[i]["isRetract"] = false //是否可撤回
|
|
var masterKey int64
|
|
if mastrKeyVal, isOk := v["masters_key"]; isOk {
|
|
masterKeyVal := publicmethod.TypeToInterface(mastrKeyVal)
|
|
masterKey, _ = publicmethod.StringToInt64(mastrKeyVal) //表单数据唯一识别码
|
|
formList[i]["masters_key"] = masterKeyVal
|
|
//获取Redsi
|
|
redisKey := fmt.Sprintf("SendMsg:Work_WeChat_%v", masterKeyVal)
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS3)
|
|
formList[i]["retract_true"], _ = redisClient.Get(redisKey)
|
|
//获取任务详情
|
|
var taskInfo customerForm.TaskRecord
|
|
overall.CONSTANT_DB_CustomerForm.Where("`masters_key` = ?", mastrKeyVal).First(&taskInfo)
|
|
formList[i]["runFlowId"] = strconv.FormatInt(taskInfo.RunFlowId, 10)
|
|
if mastrKey, ok := formList[i]["runFlowId"]; ok { //流程执行编号
|
|
mastrKeyInt, _ := publicmethod.StringToInt64(mastrKey)
|
|
if mastrKeyInt != 0 { //存在流程
|
|
//获取流程信息
|
|
var runFlowInfo customerForm.RunWorkflow
|
|
runFlowInfo.GetCont(map[string]interface{}{"`id`": mastrKey}, "`id`", "`current_step`", "`next_step`")
|
|
formList[i]["runFlowInfo"] = strconv.FormatInt(runFlowInfo.Id, 10)
|
|
if taskInfo.Status == 3 && runFlowInfo.NextStep != 0 { //判断流程是否还在审批中
|
|
if runFlowInfo.CurrentStep == 1 {
|
|
if createrName, ok := formList[i]["creater"].(string); ok {
|
|
if createrName == userCont.Name {
|
|
formList[i]["isRetract"] = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for _, sv := range sunMap {
|
|
formList[i][sv] = gainMasterSunList(sv, masterKey, formJsonCont, sqlDborm)
|
|
}
|
|
}
|
|
//Setp 8 输出分页数据
|
|
publicmethod.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(formList)), formList, c)
|
|
} else { //采用系统数据源
|
|
//Step 1 使用数据源打开数据库表
|
|
var formList []map[string]interface{}
|
|
tableName := fmt.Sprintf("`%v` as f", formInfo.TableKey)
|
|
gormDb := overall.CONSTANT_DB_CustomerForm.Table(tableName).Select("f.*,t.status as taskStatus,t.runFlowId")
|
|
gormDb = gormDb.Joins("LEFT JOIN `taskrecord` as t ON f.masters_key = t.masters_key")
|
|
gormDb = gormDb.Where("f.`states` BETWEEN ? AND ?", 1, 2) //基础查询条件
|
|
gormDb = AnalysisSerachTermSql(requestData.SearchData, gormDb) //处理查询条件
|
|
//Step 2 权限处理
|
|
var powerSearch publicmethod.GainUserPower
|
|
powerSearch.SystemName = "appsystem" //系统名称
|
|
powerSearch.RoleId = userCont.Role //角色列表
|
|
powerSearch.OrgId = userCont.AdminOrg //行政组织
|
|
powerSearch.PostId = userCont.Position //岗位
|
|
powerSearch.AppKey = formInfo.Groupid //归属哪个App
|
|
powerSearch.TableId = formInfo.CfId //归属哪个表格
|
|
gormDb = powerSearch.MakeSearchSql(gormDb, userCont, formJsonCont.Form.DataSource)
|
|
//Step 3 获取一共有多少条数据
|
|
var total int64
|
|
totalErr := gormDb.Count(&total).Error
|
|
if totalErr != nil {
|
|
total = 0
|
|
}
|
|
//Step 4 翻页配置
|
|
gormDb = publicmethod.PageTurningSettings(gormDb, requestData.Page, requestData.PageSize)
|
|
err = gormDb.Order("f.`id` DESC").Find(&formList).Error
|
|
fmt.Printf("err----%v------->%v\n\n\n", formJsonCont.Form.DataSource, err)
|
|
if err != nil && len(formList) < 1 {
|
|
publicmethod.Result(0, err, c)
|
|
return
|
|
}
|
|
var listFieldsMap ListPageFields
|
|
if formInfo.ListJson != "" {
|
|
err = json.Unmarshal([]byte(formInfo.ListJson), &listFieldsMap)
|
|
if err == nil {
|
|
formList = listFieldsMap.DevelopSpecificationsSend(formList, formJsonCont)
|
|
}
|
|
}
|
|
//获取任务状态
|
|
for i, v := range formList {
|
|
formList[i]["isRetract"] = false
|
|
if mastrKey, ok := v["runFlowId"]; ok {
|
|
mastrKeyInt, _ := publicmethod.StringToInt64(mastrKey)
|
|
if mastrKeyInt != 0 {
|
|
var runFlowInfo customerForm.RunWorkflow
|
|
runFlowInfo.GetCont(map[string]interface{}{"`id`": mastrKey}, "`id`", "`current_step`", "`next_step`")
|
|
formList[i]["runFlowInfo"] = runFlowInfo.Id
|
|
if stateVal, ok := v["taskStatus"]; ok {
|
|
if stauval, ok := stateVal.(string); ok {
|
|
if stauval == "3" && runFlowInfo.NextStep != 0 {
|
|
|
|
if runFlowInfo.CurrentStep == 1 {
|
|
if createrName, ok := formList[i]["creater"].(string); ok {
|
|
if createrName == userCont.Name {
|
|
formList[i]["isRetract"] = true
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
var masterKey int64
|
|
if mastrKeyVal, ok := v["masters_key"]; ok {
|
|
masterKey, _ = publicmethod.StringToInt64(mastrKeyVal)
|
|
masterKeyVal := publicmethod.TypeToInterface(mastrKeyVal)
|
|
if mastrKeyUint64, ok := mastrKeyVal.(uint64); ok {
|
|
formList[i]["masters_key"] = strconv.FormatUint(mastrKeyUint64, 10)
|
|
}
|
|
redisKey := fmt.Sprintf("SendMsg:Work_WeChat_%v", masterKeyVal)
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS3)
|
|
formList[i]["retract_true"], _ = redisClient.Get(redisKey)
|
|
}
|
|
for _, sv := range sunMap {
|
|
formList[i][sv] = gainMasterSunList(sv, masterKey, formJsonCont, overall.CONSTANT_DB_CustomerForm)
|
|
}
|
|
}
|
|
publicmethod.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(formList)), formList, c)
|
|
}
|
|
|
|
}
|
|
|