diff --git a/api/version1/customerApp/appControll.go b/api/version1/customerApp/appControll.go index 1a75b96..2f6a2c7 100644 --- a/api/version1/customerApp/appControll.go +++ b/api/version1/customerApp/appControll.go @@ -1490,6 +1490,18 @@ func (a *ApiMethod) GainAppPageInfo(c *gin.Context) { return } + context, _ := c.Get(overall.MyContJwt) + var userCont modelshr.ManCont + userCont.GetLoginCont(context) //当前操作人 + + var powerSearch publicmethod.GainUserPower + powerSearch.SystemName = "appsystem" //系统名称 + powerSearch.RoleId = userCont.Role //角色列表 + powerSearch.OrgId = userCont.AdminOrg //行政组织 + powerSearch.PostId = userCont.Position //岗位 + powerSearch.AppKey = appFormPage.Groupid //归属哪个App + powerSearch.TableId = appFormPage.Id //归属哪个表格 + // powerInfo := powerSearch.GetUserPower() // publicmethod.Result(105, appFormPage, c) // return sendData := publicmethod.MapOut[string]() @@ -1498,6 +1510,7 @@ func (a *ApiMethod) GainAppPageInfo(c *gin.Context) { sendData["flowkey"] = strconv.FormatInt(appFormPage.Flowkey, 10) sendData["groupid"] = strconv.FormatInt(appFormPage.Groupid, 10) sendData["signCode"] = strconv.FormatInt(appFormPage.SignCode, 10) + sendData["powerInfo"] = powerSearch.GetUserPower() if appFormPage.MastesForm == "" && appFormPage.MastesFormJson == "" { sendData["page"] = false @@ -1558,6 +1571,7 @@ func (a *ApiMethod) GainAppPageInfo(c *gin.Context) { } } sendData["formField"] = fieldList + publicmethod.Result(0, sendData, c) } diff --git a/api/version1/customerform/formTableList.go b/api/version1/customerform/formTableList.go new file mode 100644 index 0000000..49f5d93 --- /dev/null +++ b/api/version1/customerform/formTableList.go @@ -0,0 +1,246 @@ +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`", "`id`") + 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.Id //归属哪个表格 + 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.Id //归属哪个表格 + 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 + 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) + } + +} diff --git a/api/version1/grantpowers/postpower.go b/api/version1/grantpowers/postpower.go index fcf88bb..a457758 100644 --- a/api/version1/grantpowers/postpower.go +++ b/api/version1/grantpowers/postpower.go @@ -10,6 +10,7 @@ import ( "fmt" "strconv" "strings" + "time" "github.com/gin-gonic/gin" ) @@ -221,3 +222,259 @@ func (a *ApiMethod) GetRoleGrantPowers(c *gin.Context) { sendData["level"] = empowerCont.Level publicmethod.Result(0, sendData, c) } + +/* +* +@ 作者: 秦东 +@ 时间: 2025-05-13 13:57:55 +@ 功能: 不分类别的自定义App列表 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) GainAppList(c *gin.Context) { + var custForm modelAppPlatform.CustomerForm + list, _ := custForm.ContMap(map[string]interface{}{"`states`": 1, "`classify`": 3}, "`name`", "`signCode`", "`id`") + var sendList []interface{} + for _, v := range list { + mapInfo := publicmethod.MapOut[string]() + mapInfo["id"] = strconv.FormatInt(v.Id, 10) + mapInfo["signCode"] = strconv.FormatInt(v.SignCode, 10) + mapInfo["name"] = v.Name + sendList = append(sendList, mapInfo) + } + publicmethod.Result(0, sendList, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2025-05-13 15:01:11 +@ 功能: 获取对应App下边的表单 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) GainAppTableList(c *gin.Context) { + var requestData GainAppIdAndRole + err := c.ShouldBindJSON(&requestData) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if requestData.Id == "" { + publicmethod.Result(1, err, c, "未知App!不可获取表单列表!") + return + } + if requestData.RoleId == "" { + publicmethod.Result(1, err, c, "未知角色!不可获取表单列表!") + return + } + roleIdInt, _ := strconv.ParseInt(requestData.RoleId, 10, 64) + // var appInfo modelAppPlatform.CustomerForm + // appInfo.GetCont(map[string]interface{}{"`signCode`":requestData.Id},"``") + var custForm []modelAppPlatform.CustomerForm + overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.CustomerForm{}).Where("`states` = 1 AND `groupid` = ? AND `classify` IN (2,4)", requestData.Id).Find(&custForm) + var sendList []CusterAppTablePower + for _, v := range custForm { + formPower := GainAppTablePower(roleIdInt, v.Groupid, v.Id) + var sendInfo CusterAppTablePower + sendInfo.Id = strconv.FormatInt(v.Id, 10) + sendInfo.Name = v.Name + sendInfo.SignCode = strconv.FormatInt(v.SignCode, 10) + sendInfo.TablePower = formPower.TablePower + sendInfo.ListPower = formPower.ListPower + if v.ListJson != "" { + sendInfo.IstIsTrue = true + } else { + sendInfo.IstIsTrue = false + } + sendInfo.DatePower.Types = formPower.DatePower.Types + sendInfo.DatePower.Attribute = formPower.DatePower.Attribute + sendList = append(sendList, sendInfo) + } + publicmethod.Result(0, sendList, c) + // publicmethod.Result(0, custForm, c) +} + +/* +计算初始权限 +*/ +func GainAppTablePower(roleId, appSignCode, tableId int64) (formPower SendAppTablePower) { + var tablePower modelssystempermission.CustomTableAuthorize + err := tablePower.GetCont(map[string]interface{}{"`role_id`": roleId, "`app_sign_code`": appSignCode, "`table_sign_code`": tableId}) + if err != nil { + formPower.TablePower = []string{} //表单权限 + formPower.ListPower = []string{} //列表权限 + formPower.DatePower.Types = 1 //数据权限 + formPower.DatePower.Attribute = []int64{} + return + } + if tablePower.TablePower != "" { + // fmt.Printf("dskjfhsdjklfhlskdjfhlksdhfl---->%v\n\n\n", tablePower.TablePower) + formPower.TablePower = strings.Split(tablePower.TablePower, ",") //表单权限 + } else { + formPower.TablePower = []string{} + // fmt.Printf("dskjfhsdjklfhlskdjfhlksdhfl---22222->%v\n\n\n", tablePower.TablePower) + } + if tablePower.ListPower != "" { + formPower.ListPower = strings.Split(tablePower.ListPower, ",") //表单权限 + } else { + formPower.ListPower = []string{} + } + formPower.DatePower.Types = int64(tablePower.PowerLerver) + orgStrAry := strings.Split(tablePower.Organization, ",") + if len(orgStrAry) > 0 { + for _, v := range orgStrAry { + vInt, _ := strconv.ParseInt(v, 10, 64) + formPower.DatePower.Attribute = append(formPower.DatePower.Attribute, vInt) + } + } else { + formPower.DatePower.Attribute = []int64{} + } + + return +} + +/* +*‘ +@ 作者: 秦东 +@ 时间: 2025-05-19 16:16:16 +@ 功能: 提交APp单一表单权限 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) SetpAppTableForm(c *gin.Context) { + var requestData GainAppTableInfo + c.ShouldBindJSON(&requestData) + if requestData.Id == "" { + publicmethod.Result(1, requestData, c, "未知App!不可获取表单列表!") + return + } + if requestData.RoleId == "" { + publicmethod.Result(1, requestData, c, "未知角色!不可编辑权限!") + return + } + if len(requestData.AppTablePwoer) < 1 { + publicmethod.Result(200, requestData, c, "没有具体表单!无需配置权限!") + return + } + var appInfo modelAppPlatform.CustomerForm + appInfo.GetCont(map[string]interface{}{"`signCode`": requestData.Id}, "id", "name") + var msgInfo AppTableMsgInfo + msgInfo.Id = strconv.FormatInt(appInfo.Id, 10) + msgInfo.SignCode = requestData.Id + msgInfo.Name = appInfo.Name + for _, v := range requestData.AppTablePwoer { + syncSeting.Add(1) + go msgInfo.AppTablePowerSave(requestData.RoleId, requestData.Id, v) + } + syncSeting.Wait() + publicmethod.Result(0, msgInfo, c) +} + +/* +* +@ 作者: 秦东 +@ 时间: 2025-05-19 16:35:59 +@ 功能: +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *AppTableMsgInfo) AppTablePowerSave(roleId, appSignCode string, list CusterAppTablePower) { + defer syncSeting.Done() + var errInfo ErrorInfo + var tablePower modelssystempermission.CustomTableAuthorize + err := tablePower.GetCont(map[string]interface{}{"`role_id`": roleId, "`app_sign_code`": appSignCode, "`table_sign_code`": list.Id}) + if err != nil { //判断是否存在。不存在的情况下进行新增。 + var newAddInfo modelssystempermission.CustomTableAuthorize + newAddInfo.Roleid, _ = strconv.ParseInt(roleId, 10, 64) // 角色ID + newAddInfo.TableSignCode, _ = strconv.ParseInt(list.Id, 10, 64) // app表格唯一识别符 + newAddInfo.AppCignCode, _ = strconv.ParseInt(appSignCode, 10, 64) // 归谁哪个App + newAddInfo.TablePower = strings.Join(list.TablePower, ",") // 表格权限 + newAddInfo.ListPower = strings.Join(list.ListPower, ",") // 列表权限 + newAddInfo.PowerLerver, _ = strconv.Atoi(strconv.FormatInt(list.DatePower.Types, 10)) // 授权范围等级(1:本岗位;2:本部门;3:本分部;4:指定行政组织;5:所有) + var attAry []string + if len(list.DatePower.Attribute) > 0 { + for _, v := range list.DatePower.Attribute { + vStr := strconv.FormatInt(v, 10) + if !publicmethod.IsInTrue[string](vStr, attAry) { + attAry = append(attAry, vStr) + } + } + } + newAddInfo.Organization = strings.Join(attAry, ",") // 授权范围属性 + newAddInfo.Time = time.Now().Unix() // + err = overall.CONSTANT_DB_System_Permission.Create(&newAddInfo).Error + errInfo.Id = list.Id + errInfo.Name = list.Name + errInfo.Msg = err + if err != nil { + errInfo.Code = 1 + } else { + errInfo.Code = 0 + } + a.TableMsg = append(a.TableMsg, errInfo) + } else { //存在的情况下进行编辑。 + saveData := publicmethod.MapOut[string]() + saveData["table_power"] = strings.Join(list.TablePower, ",") + saveData["list_power"] = strings.Join(list.ListPower, ",") + saveData["power_lerver"], _ = strconv.Atoi(strconv.FormatInt(list.DatePower.Types, 10)) + var attAry []string + if len(list.DatePower.Attribute) > 0 { + for _, v := range list.DatePower.Attribute { + vStr := strconv.FormatInt(v, 10) + if !publicmethod.IsInTrue[string](vStr, attAry) { + attAry = append(attAry, vStr) + } + } + } + saveData["organization"] = strings.Join(attAry, ",") + saveData["time"] = time.Now().Unix() + var saveRun modelssystempermission.CustomTableAuthorize + err = saveRun.EiteCont(map[string]interface{}{"`id`": tablePower.Id}, saveData) + errInfo.Id = list.Id + errInfo.Name = list.Name + errInfo.Msg = err + if err != nil { + errInfo.Code = 1 + } else { + errInfo.Code = 0 + } + a.TableMsg = append(a.TableMsg, errInfo) + } +} diff --git a/api/version1/grantpowers/type.go b/api/version1/grantpowers/type.go index 3050ae3..84b8368 100644 --- a/api/version1/grantpowers/type.go +++ b/api/version1/grantpowers/type.go @@ -2,12 +2,16 @@ package grantpowers import ( "appPlatform/overall/publicmethod" + "sync" "github.com/gin-gonic/gin" ) type ApiMethod struct{} +// 协程设置 +var syncSeting = sync.WaitGroup{} + /* * @ 作者: 秦东 @@ -47,3 +51,75 @@ type GetRolePowerCont struct { RoleId string `json:"roleid"` //角色Id SystemName string `json:"name"` //系统识别符 } + +/* +* +@ 作者: 秦东 +@ 时间: 2025-05-14 11:34:18 +@ 功能: 输出表单权限数据结构 +*/ +type CusterAppTablePower struct { + Id string `json:"id"` //表单ID + Name string `json:"name"` //表单名称 + SignCode string `json:"signCode"` //表单识别符 + IstIsTrue bool `json:"istIsTrue"` + TableIsAll bool `json:"tableIsAll"` + TablePower []string `json:"tablePower"` //表单权限 + ListIsAll bool `json:"listIsAll"` + ListPower []string `json:"listPower"` //列表权限 + DatePower DatePowerInfo `json:"datePower"` //数据权限 +} + +type DatePowerInfo struct { + Types int64 `json:"types"` //权限类型 + Attribute []int64 `json:"attribute"` //全选属性 +} + +/* +* +@ 作者: 秦东 +@ 时间: 2025-05-19 16:22:44 +@ 功能: 接收App表单权限数据 +*/ +type GainAppTableInfo struct { + RoleId string `json:"roleId"` //归属哪个角色 + publicmethod.PublicId + AppTablePwoer []CusterAppTablePower `json:"appTablePwoer"` +} + +/* +* +@ 作者: 秦东 +@ 时间: 2025-05-19 16:29:10 +@ 功能: 执行结构 +*/ +type AppTableMsgInfo struct { + publicmethod.PublicId + SignCode string `json:"signCode"` + publicmethod.PublicName + TableMsg []ErrorInfo `json:"tableMsg"` +} + +type ErrorInfo struct { + publicmethod.PublicId + publicmethod.PublicName + Code int `json:"code"` + Msg error `json:"msg"` +} + +type GainAppIdAndRole struct { + publicmethod.PublicId + RoleId string `json:"roleId"` +} + +/* +* +@ 作者: 秦东 +@ 时间: 2025-05-20 11:16:48 +@ 功能: 输出角色权限 +*/ +type SendAppTablePower struct { + TablePower []string `json:"tablePower"` //表单权限 + ListPower []string `json:"listPower"` //列表权限 + DatePower DatePowerInfo `json:"datePower"` //数据权限 +} diff --git a/api/version1/user/userCont.go b/api/version1/user/userCont.go index 0c067c0..30effbb 100644 --- a/api/version1/user/userCont.go +++ b/api/version1/user/userCont.go @@ -217,9 +217,11 @@ func GetUserPower(appType string, postId int64, roleList []string) (menuPoint, o for _, v := range roleId { var roleEmpower modelssystempermission.RoleEmpower err = roleEmpower.GetCont(map[string]interface{}{"`role_id`": v, "`system`": appType}) + // fmt.Printf("\n\n\n%v----------1-------->%v\n\n\n", v, roleEmpower.PointId) if err == nil { if roleEmpower.PointId != "" { pointIdList := strings.Split(roleEmpower.PointId, ",") + // fmt.Printf("%v------------------>%v\n\n\n", roleEmpower.RoleId, pointIdList) menuPoint = publicmethod.MergeStruct[string](pointIdList, menuPoint) } if roleEmpower.Operation != "" { diff --git a/apirouter/v1/customerformrouter/router.go b/apirouter/v1/customerformrouter/router.go index af803aa..02ec146 100644 --- a/apirouter/v1/customerformrouter/router.go +++ b/apirouter/v1/customerformrouter/router.go @@ -50,7 +50,7 @@ func (a *ApiRouter) RouterGroupPc(router *gin.RouterGroup) { apiRouter.POST("editCustomerFormList", methodBinding.EditCustomerFormList) //编辑自定义表单列表数据 apiRouter.POST("gainFormListCont", methodBinding.GainFormListCont) //获取表单列表数据 - apiRouter.POST("gainFormPageListCont", methodBinding.GainFormPageListCont) //获取表单列表翻页数据 + apiRouter.POST("gainFormPageListCont", methodBinding.GainFormPageListContNew) //获取表单列表翻页数据 apiRouter.POST("gainListTableField", methodBinding.GainListTableField) //列表展示需要字段 diff --git a/apirouter/v1/grantsystempower/pc.go b/apirouter/v1/grantsystempower/pc.go index 3375c54..22932bd 100644 --- a/apirouter/v1/grantsystempower/pc.go +++ b/apirouter/v1/grantsystempower/pc.go @@ -16,5 +16,8 @@ func (a *ApiRouter) RouterGroupPc(router *gin.RouterGroup) { apiRouter.POST("", methodBinding.Index) //入口 apiRouter.POST("get_post_grant_powers", methodBinding.GetPostGrantPowers) //获取岗位已配置的权限 apiRouter.POST("get_role_grant_powers", methodBinding.GetRoleGrantPowers) //获取角色已配置的权限 + apiRouter.POST("gainAppList", methodBinding.GainAppList) //不分类别的自定义App列表 + apiRouter.POST("gainAppTableList", methodBinding.GainAppTableList) //获取对应App下边的表单 + apiRouter.POST("setpAppTableForms", methodBinding.SetpAppTableForm) //提交APp单一表单权限 } } diff --git a/models/modelssystempermission/custom_table_authorize.go b/models/modelssystempermission/custom_table_authorize.go new file mode 100644 index 0000000..88df91e --- /dev/null +++ b/models/modelssystempermission/custom_table_authorize.go @@ -0,0 +1,69 @@ +package modelssystempermission + +import ( + "appPlatform/overall" + "strings" +) + +/* +* +@ 作者: 秦东 +@ 时间: 2025-05-19 14:01:12 +@ 功能: 自定义表单权限设置 +*/ +type CustomTableAuthorize struct { + Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` // 编辑时间 + Roleid int64 `json:"role_id" gorm:"column:role_id;type:bigint(20) unsigned;default:0;not null;comment:角色ID"` // 角色ID + TableSignCode int64 `json:"table_sign_code" gorm:"column:table_sign_code;type:bigint(20) unsigned;default:0;not null;comment:app表格唯一识别符"` // app表格唯一识别符 + AppCignCode int64 `json:"app_sign_code" gorm:"column:app_sign_code;type:bigint(20) unsigned;default:0;not null;comment:归谁哪个App"` // 归谁哪个App + TablePower string `json:"table_power" gorm:column:table_power;type:varchar(255) ;comment:表格权限"` // 表格权限 + ListPower string `json:"list_power" gorm:"column:list_power;type:varchar(255) ;comment:列表权限"` // 列表权限 + PowerLerver int `json:"power_lerver" gorm:"column:power_lerver;type:tinyint(1) unsigned;default:1;not null;comment:授权范围等级(1:本岗位;2:本部门;3:本分部;4:指定行政组织;5:所有)"` // 授权范围等级(1:本岗位;2:本部门;3:本分部;4:指定行政组织;5:所有) + Organization string `json:"organization" gorm:"column:organization;type:text;comment:授权范围属性"` // 授权范围属性 + Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` // 编辑时间 +} + +func (CustomTableAuthorize *CustomTableAuthorize) TableName() string { + return "custom_table_authorize" +} + +// 编辑内容 +func (cont *CustomTableAuthorize) EiteCont(whereMap interface{}, saveData interface{}) (err error) { + err = overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Updates(saveData).Error + return +} + +// 获取内容 +func (cont *CustomTableAuthorize) GetCont(whereMap interface{}, field ...string) (err error) { + gormDb := overall.CONSTANT_DB_System_Permission.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 *CustomTableAuthorize) CountCont(whereMap interface{}) (countId int64) { + overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Count(&countId) + return +} + +// 读取全部信息 +func (cont *CustomTableAuthorize) ContMap(whereMap interface{}, field ...string) (countAry []CustomTableAuthorize, err error) { + gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + err = gormDb.Where(whereMap).Find(&countAry).Error + return +} + +// 删除内容 +func (cont *CustomTableAuthorize) DelCont(whereMap interface{}) (err error) { + err = overall.CONSTANT_DB_System_Permission.Where(whereMap).Delete(&cont).Error + return +} diff --git a/overall/publicmethod/getUserPower.go b/overall/publicmethod/getUserPower.go new file mode 100644 index 0000000..da73c54 --- /dev/null +++ b/overall/publicmethod/getUserPower.go @@ -0,0 +1,251 @@ +package publicmethod + +import ( + "appPlatform/models/modelshr" + "appPlatform/models/modelssystempermission" + "appPlatform/overall" + "fmt" + "strconv" + "strings" + + "gorm.io/gorm" +) + +/* +* +@ 作者: 秦东 +@ 时间: 2025-05-21 08:44:35 +@ 功能: 获取用户权限 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (g *GainUserPower) GetUserPower() (powerInfo SendUserPower) { + //正常系统权限配置 + orgLook := []int64{} + if g.RoleId != "" { + roleAry := strings.Split(g.RoleId, ",") + if len(roleAry) > 0 { + var rolePowerList []modelssystempermission.RoleEmpower + overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.RoleEmpower{}).Where("`state` = 1 AND `system` = ? AND `role_id` IN ?", g.SystemName, roleAry).Updates(&rolePowerList) + for _, v := range rolePowerList { + if v.Level >= powerInfo.System.Level { + powerInfo.System.Level = v.Level + } + if v.PointId != "" { + pointIdAry := strings.Split(v.PointId, ",") + for _, pv := range pointIdAry { + if !IsInTrue[string](pv, powerInfo.System.PointId) { + powerInfo.System.PointId = append(powerInfo.System.PointId, pv) + } + } + } + if v.Operation != "" { + operationAry := strings.Split(v.Operation, ",") + for _, ov := range operationAry { + if !IsInTrue[string](ov, powerInfo.System.Operation) { + powerInfo.System.Operation = append(powerInfo.System.Operation, ov) + } + } + } + if v.Organization != "" { + orgtionAry := strings.Split(v.Organization, ",") + for _, pv := range orgtionAry { + pvInt, _ := strconv.ParseInt(pv, 10, 64) + if !IsInTrue[int64](pvInt, orgLook) { + orgLook = append(orgLook, pvInt) + } + } + } + } + } + } + if g.PostId != 0 && g.OrgId != 0 { + var postPower modelssystempermission.Empower + postPower.GetCont(map[string]interface{}{"`state`": 1, "`ordid`": g.OrgId, "`post_id`": g.PostId, "`system`": g.SystemName}) + if postPower.Level >= powerInfo.System.Level { + powerInfo.System.Level = postPower.Level + } + if postPower.PointId != "" { + pointIdAry := strings.Split(postPower.PointId, ",") + for _, pv := range pointIdAry { + if !IsInTrue[string](pv, powerInfo.System.PointId) { + powerInfo.System.PointId = append(powerInfo.System.PointId, pv) + } + } + } + if postPower.Operation != "" { + operationAry := strings.Split(postPower.Operation, ",") + for _, ov := range operationAry { + if !IsInTrue[string](ov, powerInfo.System.Operation) { + powerInfo.System.Operation = append(powerInfo.System.Operation, ov) + } + } + } + if postPower.Organization != "" { + orgtionAry := strings.Split(postPower.Organization, ",") + for _, pv := range orgtionAry { + pvInt, _ := strconv.ParseInt(pv, 10, 64) + if !IsInTrue[int64](pvInt, orgLook) { + orgLook = append(orgLook, pvInt) + } + } + } + } + _, companyId, departmentId, _, workShopId := GetOrgStructure(g.OrgId) + switch powerInfo.System.Level { + case 1: + powerInfo.System.OrgList = []int64{} + var sunOrg GetOrgAllParent + sunOrg.GetOrgSun(workShopId) + sunOrg.Id = append(sunOrg.Id, workShopId) + powerInfo.System.OrgList = append(powerInfo.System.OrgList, sunOrg.Id...) + case 2: + powerInfo.System.OrgList = []int64{} + var sunOrgDepart GetOrgAllParent + sunOrgDepart.GetOrgSun(departmentId) + sunOrgDepart.Id = append(sunOrgDepart.Id, departmentId) + powerInfo.System.OrgList = append(powerInfo.System.OrgList, sunOrgDepart.Id...) + case 3: + powerInfo.System.OrgList = []int64{} + var sunOrgCompan GetOrgAllParent + sunOrgCompan.GetOrgSun(companyId) + sunOrgCompan.Id = append(sunOrgCompan.Id, companyId) + powerInfo.System.OrgList = append(powerInfo.System.OrgList, sunOrgCompan.Id...) + case 4: + powerInfo.System.OrgList = orgLook + case 5: + powerInfo.System.OrgList = []int64{} + default: + } + //低代码权限系统配置 + if g.RoleId != "" { + orgLookApp := []int64{} + roleAry := strings.Split(g.RoleId, ",") + if len(roleAry) > 0 { + + var tablePower []modelssystempermission.CustomTableAuthorize + + overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.CustomTableAuthorize{}).Where("`app_sign_code` = ? AND `table_sign_code` = ? AND `role_id` IN ?", g.AppKey, g.TableId, roleAry).Find(&tablePower) + + for _, v := range tablePower { + if v.PowerLerver >= powerInfo.System.Level { + powerInfo.AppSystem.Level = v.PowerLerver + } + + if v.TablePower != "" { + tableAry := strings.Split(v.TablePower, ",") + for _, tv := range tableAry { + if !IsInTrue[string](tv, powerInfo.AppSystem.PointId) { + powerInfo.AppSystem.PointId = append(powerInfo.AppSystem.PointId, tv) + } + } + } + if v.ListPower != "" { + listAry := strings.Split(v.ListPower, ",") + for _, lv := range listAry { + if !IsInTrue[string](lv, powerInfo.AppSystem.Operation) { + powerInfo.AppSystem.Operation = append(powerInfo.AppSystem.Operation, lv) + } + } + } + if v.Organization != "" { + orgtionAry := strings.Split(v.Organization, ",") + for _, pv := range orgtionAry { + pvInt, _ := strconv.ParseInt(pv, 10, 64) + if !IsInTrue[int64](pvInt, orgLookApp) { + orgLookApp = append(orgLookApp, pvInt) + } + } + } + } + + switch powerInfo.AppSystem.Level { + case 2: + powerInfo.AppSystem.OrgList = []int64{} + var sunOrg GetOrgAllParent + sunOrg.GetOrgSun(workShopId) + sunOrg.Id = append(sunOrg.Id, workShopId) + powerInfo.AppSystem.OrgList = append(powerInfo.AppSystem.OrgList, sunOrg.Id...) + case 3: + powerInfo.AppSystem.OrgList = []int64{} + var sunOrgDepart GetOrgAllParent + sunOrgDepart.GetOrgSun(departmentId) + sunOrgDepart.Id = append(sunOrgDepart.Id, departmentId) + powerInfo.AppSystem.OrgList = append(powerInfo.AppSystem.OrgList, sunOrgDepart.Id...) + case 4: + powerInfo.AppSystem.OrgList = []int64{} + var sunOrgCompan GetOrgAllParent + sunOrgCompan.GetOrgSun(companyId) + sunOrgCompan.Id = append(sunOrgCompan.Id, companyId) + powerInfo.AppSystem.OrgList = append(powerInfo.AppSystem.OrgList, sunOrgCompan.Id...) + case 5: + powerInfo.AppSystem.OrgList = orgLookApp + case 6: + powerInfo.AppSystem.OrgList = []int64{} + default: + } + } + } + return +} + +/* +* +@ 作者: 秦东 +@ 时间: 2025-05-22 13:53:17 +@ 功能: 权限结构查询语句 +@ 参数 +授权范围等级(1:本人;2:本岗位;3:本部门;4:本分部;5:指定行政组织;6:所有) + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (g *GainUserPower) MakeSearchSql(gormDb *gorm.DB, userCont modelshr.ManCont, isOdeb string) *gorm.DB { + powerInfo := g.GetUserPower() + fmt.Printf("\n\n\n等级-----%v------->%v\n\n\n", powerInfo.AppSystem.Level, g) + if isOdeb == "yes" { + switch powerInfo.AppSystem.Level { + case 2, 3, 4: + if len(powerInfo.AppSystem.OrgList) > 0 { + gormDb = gormDb.Where("`createrOrg` IN ?", powerInfo.AppSystem.OrgList) + } else { + gormDb = gormDb.Where("`creater` = ?", userCont.Key) + } + case 6: + + default: + gormDb = gormDb.Where("`creater` = ?", userCont.Key) + } + } else { + switch powerInfo.AppSystem.Level { + case 2, 3, 4: + if len(powerInfo.AppSystem.OrgList) > 0 { + gormDb = gormDb.Where("f.`createrOrg` IN ?", powerInfo.AppSystem.OrgList) + } else { + gormDb = gormDb.Where("f.`creater` = ?", userCont.Key) + } + case 6: + + default: + gormDb = gormDb.Where("f.`creater` = ?", userCont.Key) + } + } + + return gormDb +} diff --git a/overall/publicmethod/type.go b/overall/publicmethod/type.go index 79aafd3..0937aba 100644 --- a/overall/publicmethod/type.go +++ b/overall/publicmethod/type.go @@ -350,3 +350,26 @@ type CustomerFormGroupTree struct { modelAppPlatform.CustomerFormGroup Child []CustomerFormGroupTree `json:"child"` } + +// 获取权限参数 +type GainUserPower struct { + SystemName string //系统名称 + RoleId string //角色列表 + OrgId int64 //行政组织 + PostId int64 //岗位 + AppKey int64 //归属哪个App + TableId int64 //归属哪个表格 +} + +// 输出用户的权限 +type SendUserPower struct { + System SystemPower + AppSystem SystemPower +} + +type SystemPower struct { + Level int //级别 + PointId []string //菜单级&表格 + Operation []string //按钮级&列表 + OrgList []int64 //可见行政组织&数据可见行政组织 +}