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.
466 lines
11 KiB
466 lines
11 KiB
package customerform
|
|
|
|
import (
|
|
"appPlatform/models/modelAppPlatform"
|
|
"appPlatform/overall"
|
|
"appPlatform/overall/publicmethod"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-03-06 13:28:08
|
|
@ 功能: 自定义表单分组列表树
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) CustomerFormGroupTree(c *gin.Context) {
|
|
var requestData FormGroupArg
|
|
c.ShouldBindJSON(&requestData)
|
|
// err := c.ShouldBindJSON(&requestData)
|
|
// if err != nil {
|
|
// publicmethod.Result(100, err, c)
|
|
// return
|
|
// }
|
|
// var groupList []*publicmethod.CustomerFormGroupTree
|
|
var groupList []modelAppPlatform.CustomerFormGroup
|
|
gormDb := overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.CustomerFormGroup{})
|
|
if requestData.Name != "" {
|
|
gormDb = gormDb.Where("`title` LIKE ?", "%"+requestData.Name+"%")
|
|
}
|
|
if requestData.State != 0 {
|
|
gormDb = gormDb.Where("`state` = ?", requestData.State)
|
|
} else {
|
|
gormDb = gormDb.Where("`state` IN ?", []int{1, 2})
|
|
}
|
|
if requestData.OrgId != "" && requestData.OrgId != "0" {
|
|
gormDb = gormDb.Where("`ordid` = ?", requestData.OrgId)
|
|
}
|
|
if requestData.Superior != "" && requestData.Superior != "0" {
|
|
var sunGroupId publicmethod.GetOrgAllParent
|
|
superiorId, _ := strconv.ParseInt(requestData.Superior, 10, 64)
|
|
sunGroupId.GetFormGroupSun(superiorId)
|
|
if len(sunGroupId.Id) < 1 {
|
|
gormDb = gormDb.Where("`superior` = ?", -1)
|
|
} else {
|
|
gormDb = gormDb.Where("`superior` IN ?", sunGroupId.Id)
|
|
}
|
|
|
|
}
|
|
err := gormDb.Order("`sort` DESC").Find(&groupList).Error
|
|
if err != nil {
|
|
publicmethod.Result(106, err, c)
|
|
return
|
|
}
|
|
groupTree := publicmethod.CustFormGroupTree(0, groupList)
|
|
publicmethod.Result(0, groupTree, c)
|
|
}
|
|
|
|
/**
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-03-19 08:23:44
|
|
@ 功能: 自定义分组列表
|
|
@ 参数
|
|
#
|
|
@ 返回值
|
|
#
|
|
@ 方法原型
|
|
#
|
|
*/
|
|
// func (){}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-03-07 08:55:42
|
|
@ 功能: 自定义表单分组列表
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) CustomerFormGroupList(c *gin.Context) {
|
|
var requestData FormGroupArgList
|
|
c.ShouldBindJSON(&requestData)
|
|
if requestData.Page == 0 {
|
|
requestData.Page = 1
|
|
}
|
|
if requestData.PageSize == 0 {
|
|
requestData.PageSize = 15
|
|
}
|
|
var groupList []SendFormGroupInfo
|
|
gormDb := overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.CustomerFormGroup{})
|
|
if requestData.Name != "" {
|
|
gormDb = gormDb.Where("`title` LIKE ?", "%"+requestData.Name+"%")
|
|
}
|
|
if requestData.State != 0 {
|
|
gormDb = gormDb.Where("`state` = ?", requestData.State)
|
|
} else {
|
|
gormDb = gormDb.Where("`state` IN ?", []int{1, 2})
|
|
}
|
|
if requestData.OrgId != "" && requestData.OrgId != "0" {
|
|
gormDb = gormDb.Where("`ordid` = ?", requestData.OrgId)
|
|
}
|
|
if requestData.Superior != "" && requestData.Superior != "0" {
|
|
var sunGroupId publicmethod.GetOrgAllParent
|
|
superiorId, _ := strconv.ParseInt(requestData.Superior, 10, 64)
|
|
sunGroupId.GetFormGroupSun(superiorId)
|
|
if len(sunGroupId.Id) < 1 {
|
|
gormDb = gormDb.Where("`superior` = ?", -1)
|
|
} else {
|
|
gormDb = gormDb.Where("`superior` IN ?", sunGroupId.Id)
|
|
}
|
|
|
|
}
|
|
var total int64
|
|
totalErr := gormDb.Count(&total).Error
|
|
if totalErr != nil {
|
|
total = 0
|
|
}
|
|
gormDb = publicmethod.PageTurningSettings(gormDb, requestData.Page, requestData.PageSize)
|
|
err := gormDb.Order("`sort` ASC").Order("`id` DESC").Find(&groupList).Error
|
|
if err != nil {
|
|
publicmethod.Result(106, err, c)
|
|
return
|
|
}
|
|
for i, v := range groupList {
|
|
groupList[i].IdStr = strconv.FormatInt(v.Id, 10)
|
|
}
|
|
// publicmethod.Result(0, groupList, c)
|
|
publicmethod.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(groupList)), groupList, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-03-06 15:10:52
|
|
@ 功能:添加自定义表单分组
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) AddCustomerFormGroup(c *gin.Context) {
|
|
var requestData AddFormGroup
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
if requestData.Title == "" {
|
|
publicmethod.Result(101, err, c)
|
|
return
|
|
}
|
|
if requestData.Sort == 0 {
|
|
requestData.Sort = 50
|
|
}
|
|
var groupInfo modelAppPlatform.CustomerFormGroup
|
|
err = groupInfo.GetCont(map[string]interface{}{"`title`": requestData.Title}, "`id`")
|
|
if err == nil || groupInfo.Id != 0 {
|
|
publicmethod.Result(103, err, c)
|
|
return
|
|
}
|
|
groupInfo.Id = onlyoenUUID(publicmethod.GetUUid(1))
|
|
groupInfo.Title = requestData.Title
|
|
groupInfo.Superior = 0
|
|
groupInfo.Sort = requestData.Sort
|
|
groupInfo.Ordid = 0
|
|
groupInfo.State = 1
|
|
groupInfo.Icon = requestData.Icon
|
|
groupInfo.Time = time.Now().Unix()
|
|
err = overall.CONSTANT_DB_AppPlatform.Create(&groupInfo).Error
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
publicmethod.Result(0, err, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-03-08 08:16:33
|
|
@ 功能: 确保添加时uuid唯一
|
|
*/
|
|
func onlyoenUUID(uuId int64) int64 {
|
|
var groupInfo modelAppPlatform.CustomerFormGroup
|
|
err := groupInfo.GetCont(map[string]interface{}{"`id`": uuId}, "`id`")
|
|
if err == nil {
|
|
uId := publicmethod.GetUUid(1)
|
|
return onlyoenUUID(uId)
|
|
}
|
|
return uuId
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-03-07 08:59:59
|
|
@ 功能: 改变自定义表单分组内容
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) EditCustomerFormGroup(c *gin.Context) {
|
|
var requestData EditFormGroup
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
if requestData.Id == "" {
|
|
publicmethod.Result(102, err, c)
|
|
return
|
|
}
|
|
if requestData.Title == "" {
|
|
publicmethod.Result(101, err, c)
|
|
return
|
|
}
|
|
var groupInfo modelAppPlatform.CustomerFormGroup
|
|
err = groupInfo.GetCont(map[string]interface{}{"`id`": requestData.Id})
|
|
if err != nil {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
saveInfo := publicmethod.MapOut[string]()
|
|
if groupInfo.Title != requestData.Title {
|
|
var groupInfoJuadge modelAppPlatform.CustomerFormGroup
|
|
err = groupInfoJuadge.GetCont(map[string]interface{}{"`title`": requestData.Title}, "`id`")
|
|
if err == nil || groupInfoJuadge.Id != 0 {
|
|
publicmethod.Result(103, err, c)
|
|
return
|
|
}
|
|
saveInfo["`title`"] = requestData.Title
|
|
}
|
|
if requestData.Sort != 0 && requestData.Sort != groupInfo.Sort {
|
|
saveInfo["`sort`"] = requestData.Sort
|
|
}
|
|
if requestData.Icon != "" && requestData.Icon != groupInfo.Icon {
|
|
saveInfo["`icon`"] = requestData.Icon
|
|
}
|
|
if len(saveInfo) > 0 {
|
|
saveInfo["`time`"] = time.Now().Unix()
|
|
var groupEditInfo modelAppPlatform.CustomerFormGroup
|
|
err = groupEditInfo.EiteCont(map[string]interface{}{"`id`": requestData.Id}, saveInfo)
|
|
if err != nil {
|
|
publicmethod.Result(106, err, c)
|
|
return
|
|
}
|
|
}
|
|
publicmethod.Result(0, err, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-03-08 08:09:17
|
|
@ 功能: 改变自定义表单分组状态
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) EditFormGroupState(c *gin.Context) {
|
|
var requestData publicmethod.PublicStates
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
if requestData.Id == "" {
|
|
publicmethod.Result(102, err, c)
|
|
return
|
|
}
|
|
if requestData.Status == 0 {
|
|
requestData.Status = 2
|
|
}
|
|
var groupInfo modelAppPlatform.CustomerFormGroup
|
|
err = groupInfo.GetCont(map[string]interface{}{"`id`": requestData.Id}, "`state`")
|
|
if err != nil {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
saveInfo := publicmethod.MapOut[string]()
|
|
if requestData.Status != groupInfo.State {
|
|
saveInfo["`state`"] = requestData.Status
|
|
saveInfo["`time`"] = time.Now().Unix()
|
|
var groupEditInfo modelAppPlatform.CustomerFormGroup
|
|
err = groupEditInfo.EiteCont(map[string]interface{}{"`id`": requestData.Id}, saveInfo)
|
|
if err != nil {
|
|
publicmethod.Result(106, err, c)
|
|
return
|
|
}
|
|
}
|
|
publicmethod.Result(0, err, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-03-08 08:21:14
|
|
@ 功能: 强制删除(慎重操作!一旦执行不可恢复!)
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) DelFormGroup(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(102, err, c)
|
|
return
|
|
}
|
|
var groupInfo modelAppPlatform.CustomerFormGroup
|
|
err = groupInfo.GetCont(map[string]interface{}{"`id`": requestData.Id}, "`state`")
|
|
if err != nil {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
var custFormIdAry []modelAppPlatform.CustomerForm
|
|
err = overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.CustomerForm{}).Where("`groupid` = ?", requestData.Id).Find(&custFormIdAry).Error
|
|
var oldCustForm []modelAppPlatform.CustomerForm
|
|
var oldCustFormVersion []modelAppPlatform.CustomerFormVersion
|
|
var workForm []modelAppPlatform.WorkFlow
|
|
var workFormVersion []modelAppPlatform.WorkFlowVersion
|
|
var formId []int64
|
|
var formVersionKey []string
|
|
var flowKey []int64
|
|
if err == nil {
|
|
for _, v := range custFormIdAry {
|
|
if v.Id != 0 && !publicmethod.IsInTrue[int64](v.Id, formId) {
|
|
formId = append(formId, v.Id)
|
|
}
|
|
if v.TableNames != "" && !publicmethod.IsInTrue[string](v.TableNames, formVersionKey) {
|
|
formVersionKey = append(formVersionKey, v.TableNames)
|
|
}
|
|
if v.FlowKey != 0 && !publicmethod.IsInTrue[int64](v.FlowKey, flowKey) {
|
|
flowKey = append(flowKey, v.FlowKey)
|
|
}
|
|
if len(formId) > 0 {
|
|
overall.CONSTANT_DB_AppPlatform.Where("`id IN ?", formId).Find(&oldCustForm)
|
|
overall.CONSTANT_DB_AppPlatform.Where("`id IN ?", formId).Delete(&modelAppPlatform.CustomerForm{})
|
|
}
|
|
if len(formVersionKey) > 0 {
|
|
overall.CONSTANT_DB_AppPlatform.Where("`tablekey` IN ?", formVersionKey).Find(&oldCustFormVersion)
|
|
overall.CONSTANT_DB_AppPlatform.Where("`tablekey` IN ?", formVersionKey).Delete(&modelAppPlatform.CustomerFormVersion{})
|
|
}
|
|
if len(flowKey) > 0 {
|
|
overall.CONSTANT_DB_AppPlatform.Where("`id IN ?", flowKey).Find(&workForm)
|
|
overall.CONSTANT_DB_AppPlatform.Where("`key IN ?", flowKey).Find(&workFormVersion)
|
|
overall.CONSTANT_DB_AppPlatform.Where("`id IN ?", flowKey).Delete(&modelAppPlatform.WorkFlow{})
|
|
overall.CONSTANT_DB_AppPlatform.Where("`key IN ?", flowKey).Delete(&modelAppPlatform.WorkFlowVersion{})
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
var delGroupInfo modelAppPlatform.CustomerFormGroup
|
|
err = delGroupInfo.DelCont(map[string]interface{}{"`id`": requestData.Id})
|
|
if err != nil {
|
|
if len(formId) > 0 {
|
|
overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.CustomerForm{}).Save(&oldCustForm)
|
|
}
|
|
if len(formVersionKey) > 0 {
|
|
overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.CustomerFormVersion{}).Save(&oldCustFormVersion)
|
|
}
|
|
if len(flowKey) > 0 {
|
|
overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.WorkFlow{}).Save(&workForm)
|
|
overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.WorkFlowVersion{}).Save(&workFormVersion)
|
|
}
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
publicmethod.Result(0, err, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-03-09 10:12:00
|
|
@ 功能: 查看分组详情
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) GainFormGroupInfo(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(102, err, c)
|
|
return
|
|
}
|
|
var groupInfo SendFormGroupInfo
|
|
err = groupInfo.GetCont(map[string]interface{}{"`id`": requestData.Id})
|
|
if err != nil {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
groupInfo.IdStr = strconv.FormatInt(groupInfo.Id, 10)
|
|
publicmethod.Result(0, groupInfo, c)
|
|
}
|
|
|