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.
365 lines
12 KiB
365 lines
12 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"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2025-05-31 15:32:53
|
|
@ 功能: 根据设定得字段显示数据列表内容
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) TableCusterField(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, "未知表单!无法获取字段!")
|
|
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)
|
|
var total int64
|
|
//判断当前数据源来源于什么地方
|
|
var formList []map[string]interface{}
|
|
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 获取一共有多少条数据
|
|
|
|
totalErr := gormDb.Count(&total).Error
|
|
if totalErr != nil {
|
|
total = 0
|
|
}
|
|
//Step 5 获取每页具体数据
|
|
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
|
|
}
|
|
} else { //采用系统数据源
|
|
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 获取一共有多少条数据
|
|
|
|
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 sendList []KaPianField
|
|
var listFieldsMap ListPageFields
|
|
if formInfo.ListJson != "" {
|
|
err = json.Unmarshal([]byte(formInfo.ListJson), &listFieldsMap)
|
|
if err == nil {
|
|
formList = listFieldsMap.DevelopSpecificationsSend(formList, formJsonCont)
|
|
}
|
|
for _, v := range formList {
|
|
var sendInfo KaPianField
|
|
sendInfo.TableKey = formInfo.TableKey
|
|
sendInfo.IsRetract = false
|
|
if id, ok := v["id"]; ok {
|
|
sendInfo.Id = publicmethod.TypeToClass(id, 10)
|
|
}
|
|
if timeAdd, ok := v["creater_time"]; ok {
|
|
sendInfo.CreaterTime = publicmethod.TypeToInterface(timeAdd)
|
|
}
|
|
|
|
var createrVal int64
|
|
if createrName, ok := v["createrKey"]; ok {
|
|
createrVal, _ = publicmethod.StringToInt64(createrName)
|
|
var myInfo modelshr.PersonArchives
|
|
myInfo.GetCont(map[string]interface{}{"`key`": createrName}, "`name`", "`number`")
|
|
sendInfo.Creater = fmt.Sprintf("%v(NO. %v)", myInfo.Name, myInfo.Number)
|
|
if createrVal == userCont.Key {
|
|
sendInfo.IsMyMsg = true
|
|
}
|
|
}
|
|
|
|
if mastrKeyVal, ok := v["masters_key"]; ok {
|
|
masterKeyVal := publicmethod.TypeToInterface(mastrKeyVal)
|
|
sendInfo.Title = masterKeyVal
|
|
sendInfo.MastersKey = masterKeyVal //唯一标识符
|
|
// if mastrKeyUint64, ok := mastrKeyVal.(uint64); ok {
|
|
// sendInfo.MastersKey = strconv.FormatUint(mastrKeyUint64, 10) //唯一标识符
|
|
// }
|
|
redisKey := fmt.Sprintf("SendMsg:Work_WeChat_%v", masterKeyVal)
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS3)
|
|
|
|
sendInfo.RetractTrue, _ = redisClient.Get(redisKey)
|
|
|
|
if createrVal, ok := v["creater"]; ok {
|
|
createrValInt, _ := publicmethod.StringToInt64(createrVal)
|
|
|
|
if userCont.Key != createrValInt {
|
|
sendInfo.RetractTrue = false
|
|
}
|
|
}
|
|
}
|
|
if flowIsOpen, ok := v["flowIsOpens"]; ok {
|
|
sendInfo.FlowIsOpens = flowIsOpen //是否为流程表单
|
|
}
|
|
if taskStatus, ok := v["taskStatus"]; ok {
|
|
sendInfo.TaskStatus = taskStatus //是否为流程表单
|
|
}
|
|
|
|
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`")
|
|
sendInfo.RunFlowInfo = strconv.FormatInt(runFlowInfo.Id, 10)
|
|
if stateVal, ok := v["taskStatus"]; ok {
|
|
if stauval, ok := stateVal.(string); ok {
|
|
if stauval == "3" && runFlowInfo.NextStep != 0 {
|
|
|
|
if runFlowInfo.CurrentStep == 1 {
|
|
|
|
if createrVal == userCont.Key {
|
|
sendInfo.IsRetract = true
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
sendInfo.Img = HaveImgInfo(v, listFieldsMap.View, formJsonCont.List, 1) //项目图片
|
|
sendInfo.TitleWork = HaveImgInfo(v, listFieldsMap.View, formJsonCont.List, 2) //项目图片标题
|
|
sendInfo.Title = HaveImgInfo(v, listFieldsMap.View, formJsonCont.List, 3) //项目标题
|
|
sendInfo.Describe = strings.Split(HaveImgInfo(v, listFieldsMap.View, formJsonCont.List, 4), "|#|") //项目描述
|
|
|
|
sendList = append(sendList, sendInfo)
|
|
}
|
|
}
|
|
publicmethod.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(sendList)), sendList, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2025-06-03 09:46:52
|
|
@ 功能: 组装返回值
|
|
*/
|
|
func HaveImgInfo(val map[string]interface{}, view map[string]ViewInfo, unitList []MasterStruct, types int) string {
|
|
switch types {
|
|
case 1:
|
|
if viewCard, ok := view["card"]; ok {
|
|
if viewCard.Form.ImgWork != "" {
|
|
if imgSrc, ok := val[viewCard.Form.ImgWork]; ok {
|
|
return publicmethod.TypeToInterface(imgSrc)
|
|
}
|
|
}
|
|
// if imgSrc,ok := val[viewCard.Form]
|
|
}
|
|
case 2:
|
|
if viewCard, ok := view["card"]; ok {
|
|
if viewCard.Form.TitleWork != "" {
|
|
titleAry := strings.Split(viewCard.Form.TitleWork, "|#|")
|
|
if len(titleAry) >= 2 {
|
|
return titleAry[0]
|
|
} else {
|
|
if imgSrcTitle, ok := val[viewCard.Form.TitleWork]; ok {
|
|
return publicmethod.TypeToInterface(imgSrcTitle)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
case 3:
|
|
titleStr := ""
|
|
if viewCard, ok := view["card"]; ok {
|
|
if len(viewCard.Form.Title) > 0 {
|
|
for _, v := range viewCard.Form.Title {
|
|
vAry := strings.Split(v, "|#|")
|
|
if len(vAry) >= 2 {
|
|
if vAry[0] != "" {
|
|
if titleStr != "" {
|
|
titleStr = fmt.Sprintf("%v - %v", titleStr, vAry[0])
|
|
} else {
|
|
titleStr = vAry[0]
|
|
}
|
|
}
|
|
} else {
|
|
if vInfo, ok := val[v]; ok {
|
|
vInfoStr := publicmethod.TypeToInterface(vInfo)
|
|
if vInfoStr != "" {
|
|
if titleStr != "" {
|
|
titleStr = fmt.Sprintf("%v - %v", titleStr, vInfoStr)
|
|
} else {
|
|
titleStr = vInfoStr
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return titleStr
|
|
case 4:
|
|
if viewCard, ok := view["card"]; ok {
|
|
fmt.Printf("\n\n\n\n描述类型----->%T------------1------------->%v\n\n\n\n", viewCard.Form.Describe, viewCard.Form.Describe)
|
|
switch descVal := viewCard.Form.Describe.(type) {
|
|
case []interface{}:
|
|
var descAry []string
|
|
for _, v := range descVal {
|
|
vInfoStr := publicmethod.TypeToInterface(v)
|
|
descInfo := strings.Split(vInfoStr, "|#|")
|
|
if len(descInfo) >= 2 {
|
|
descAry = append(descAry, descInfo[0])
|
|
} else {
|
|
if descTitle, ok := val[vInfoStr]; ok {
|
|
descInfoVal := ""
|
|
for _, uv := range unitList {
|
|
if uv.Name != "" && uv.Name == vInfoStr {
|
|
descInfoVal = fmt.Sprintf("%v:%v ", uv.Item.Label, publicmethod.TypeToInterface(descTitle))
|
|
}
|
|
}
|
|
if descInfoVal == "" {
|
|
descInfoVal = publicmethod.TypeToInterface(descTitle)
|
|
}
|
|
if descInfoVal != "" {
|
|
descAry = append(descAry, descInfoVal)
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
return strings.Join(descAry, "|#|")
|
|
default:
|
|
vInfoStr := publicmethod.TypeToInterface(descVal)
|
|
if vInfoStr != "" {
|
|
descInfo := strings.Split(vInfoStr, "|#|")
|
|
if len(descInfo) >= 2 {
|
|
return descInfo[0]
|
|
} else {
|
|
if descTitle, ok := val[vInfoStr]; ok {
|
|
descInfoVal := ""
|
|
for _, uv := range unitList {
|
|
if uv.Name != "" && uv.Name == vInfoStr {
|
|
descInfoVal = fmt.Sprintf("%v:%v ", uv.Item.Label, publicmethod.TypeToInterface(descTitle))
|
|
}
|
|
}
|
|
if descInfoVal == "" {
|
|
descInfoVal = publicmethod.TypeToInterface(descTitle)
|
|
}
|
|
return descInfoVal
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
default:
|
|
strVal := ""
|
|
for _, v := range val {
|
|
if strVal == "" {
|
|
fmt.Printf("%v", v)
|
|
} else {
|
|
fmt.Printf("%v - %v", strVal, v)
|
|
}
|
|
|
|
}
|
|
return strVal
|
|
}
|
|
return ""
|
|
}
|
|
|