|
|
|
|
package jurisdictionpc
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"key_performance_indicators/models/modelsschool"
|
|
|
|
|
"key_performance_indicators/models/modelsstorage"
|
|
|
|
|
"key_performance_indicators/models/modelssystempermission"
|
|
|
|
|
"key_performance_indicators/overall"
|
|
|
|
|
"key_performance_indicators/overall/publicmethod"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 编辑权限
|
|
|
|
|
func (a *ApiMethod) EditPower(c *gin.Context) {
|
|
|
|
|
var receivedValue appPowerStruct
|
|
|
|
|
err := c.ShouldBindJSON(&receivedValue)
|
|
|
|
|
if err != nil {
|
|
|
|
|
publicmethod.Result(100, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if receivedValue.OrdId == "" {
|
|
|
|
|
publicmethod.Result(1, receivedValue, c, "请指定要配置的行政组织!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if receivedValue.PostId == "" {
|
|
|
|
|
publicmethod.Result(1, receivedValue, c, "请指定要配置的岗位!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if receivedValue.SystemName == "" {
|
|
|
|
|
publicmethod.Result(1, err, c, "请提交系统识别符!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if len(receivedValue.PointId) < 1 {
|
|
|
|
|
publicmethod.Result(1, err, c, "请至少指定一项权限!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
switch receivedValue.Level {
|
|
|
|
|
case 2: //本分部
|
|
|
|
|
if len(receivedValue.Organization) < 1 {
|
|
|
|
|
receivedValue.Organization = append(receivedValue.Organization, receivedValue.OrdId)
|
|
|
|
|
ordIdInt, _ := strconv.ParseInt(receivedValue.OrdId, 10, 64)
|
|
|
|
|
_, companyId, _, _, _ := publicmethod.GetOrgStructure(ordIdInt)
|
|
|
|
|
var sonOrgId []int64
|
|
|
|
|
sonOrgId = publicmethod.GetDepartmentSun(companyId, sonOrgId)
|
|
|
|
|
if len(sonOrgId) > 0 {
|
|
|
|
|
for oi := 0; oi < len(sonOrgId); oi++ {
|
|
|
|
|
sonOrgIdStr := strconv.FormatInt(sonOrgId[oi], 10)
|
|
|
|
|
if publicmethod.IsInTrue[string](sonOrgIdStr, receivedValue.Organization) == false {
|
|
|
|
|
receivedValue.Organization = append(receivedValue.Organization, sonOrgIdStr)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case 3:
|
|
|
|
|
var orgAry []string
|
|
|
|
|
receivedValue.Organization = orgAry
|
|
|
|
|
default:
|
|
|
|
|
receivedValue.Level = 1
|
|
|
|
|
if len(receivedValue.Organization) < 1 {
|
|
|
|
|
var orgAry []string
|
|
|
|
|
orgAry = append(orgAry, receivedValue.OrdId)
|
|
|
|
|
receivedValue.Organization = orgAry
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var empowerCont modelssystempermission.Empower
|
|
|
|
|
err = empowerCont.GetCont(map[string]interface{}{"`ordid`": receivedValue.OrdId, "`post_id`": receivedValue.PostId, "`system`": receivedValue.SystemName}, "`id`")
|
|
|
|
|
postIdStr := strings.Join(receivedValue.PointId, ",")
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
|
|
err = empowerCont.EiteCont(map[string]interface{}{"`id`": empowerCont.Id}, map[string]interface{}{"`state`": 1, "`point_id`": postIdStr, "`time`": time.Now().Unix(), "`level`": receivedValue.Level, "`organization`": strings.Join(receivedValue.Organization, ",")})
|
|
|
|
|
} else {
|
|
|
|
|
ordIdInt64, _ := strconv.ParseInt(receivedValue.OrdId, 10, 64)
|
|
|
|
|
empowerCont.OrdId = ordIdInt64 //行政组织"`
|
|
|
|
|
postIdInt64, _ := strconv.ParseInt(receivedValue.PostId, 10, 64)
|
|
|
|
|
empowerCont.PostId = postIdInt64 //岗位ID"`
|
|
|
|
|
empowerCont.System = receivedValue.SystemName //系统"`
|
|
|
|
|
empowerCont.PointId = postIdStr //权限点位"`
|
|
|
|
|
empowerCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
|
|
|
|
|
empowerCont.Time = time.Now().Unix() //创建时间"`
|
|
|
|
|
empowerCont.Level = receivedValue.Level
|
|
|
|
|
empowerCont.Organization = strings.Join(receivedValue.Organization, ",")
|
|
|
|
|
err = overall.CONSTANT_DB_System_Permission.Create(&empowerCont).Error
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
publicmethod.Result(104, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
publicmethod.Result(0, err, c)
|
|
|
|
|
// for i := 0; i < len(receivedValue.PointId); i++ {
|
|
|
|
|
// var empowerCont modelssystempermission.Empower
|
|
|
|
|
// err = empowerCont.GetCont(map[string]interface{}{"`post_id`": receivedValue.PostId, "`system`": receivedValue.SystemName, "`point_id`": receivedValue.PointId[i]})
|
|
|
|
|
// if err == nil {
|
|
|
|
|
// if empowerCont.State != 1 {
|
|
|
|
|
// empowerCont.EiteCont(map[string]interface{}{"`id`": empowerCont.Id}, map[string]interface{}{"`state`": 1, "`time`": time.Now().Unix()})
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// postIdInt64, _ := strconv.ParseInt(receivedValue.PostId, 10, 64)
|
|
|
|
|
// empowerCont.PostId = postIdInt64 //岗位ID"`
|
|
|
|
|
// empowerCont.System = receivedValue.SystemName //系统"`
|
|
|
|
|
// poinIdInt64, _ := strconv.ParseInt(receivedValue.PointId[i], 10, 64)
|
|
|
|
|
// empowerCont.PointId = poinIdInt64 //权限点位"`
|
|
|
|
|
// empowerCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
|
|
|
|
|
// empowerCont.Time = time.Now().Unix() //创建时间"`
|
|
|
|
|
// saveData = append(saveData, empowerCont)
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// if len(saveData) > 0 {
|
|
|
|
|
// err = overall.CONSTANT_DB_System_Permission.Create(&saveData).Error
|
|
|
|
|
// }
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// publicmethod.Result(104, err, c)
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
// //清除其他权限
|
|
|
|
|
// otherSaveData := publicmethod.MapOut[string]()
|
|
|
|
|
// otherSaveData["`state`"] = 2
|
|
|
|
|
// otherSaveData["`time`"] = time.Now().Unix()
|
|
|
|
|
// overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.Empower{}).Where("`state` = 1 AND `post_id` = ? AND `system` = ?", receivedValue.PostId, receivedValue.SystemName).Not(map[string]interface{}{"point_id": receivedValue.PointId}).Updates(&otherSaveData)
|
|
|
|
|
// publicmethod.Result(0, saveData, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 相关系统菜单
|
|
|
|
|
func (a *ApiMethod) SystemAboutMenu(c *gin.Context) {
|
|
|
|
|
var receivedValue publicmethod.PublicName
|
|
|
|
|
err := c.ShouldBindJSON(&receivedValue)
|
|
|
|
|
if err != nil {
|
|
|
|
|
publicmethod.Result(100, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if receivedValue.Name == "" {
|
|
|
|
|
publicmethod.Result(101, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var systemPower modelssystempermission.Appsystem
|
|
|
|
|
err = systemPower.GetCont(map[string]interface{}{"`coder`": receivedValue.Name})
|
|
|
|
|
if err != nil {
|
|
|
|
|
publicmethod.Result(105, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if systemPower.State == 2 {
|
|
|
|
|
publicmethod.Result(1, err, c, "该系统授权已经禁用!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if systemPower.State == 3 {
|
|
|
|
|
publicmethod.Result(1, err, c, "该系统授权已经取消合作!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var menuThree []publicmethod.PowerThree
|
|
|
|
|
// fmt.Printf("ApiUrl------>%v\n", systemPower)
|
|
|
|
|
if systemPower.ApiUrl != "" {
|
|
|
|
|
//api入口不为空的情况下采用get访问方式接收数据
|
|
|
|
|
htmlByte := publicmethod.CurlGet(systemPower.ApiUrl)
|
|
|
|
|
fmt.Printf("%v\n", string(htmlByte))
|
|
|
|
|
var jsonAry callBackUrlMenu
|
|
|
|
|
jsonErr := json.Unmarshal(htmlByte, &jsonAry)
|
|
|
|
|
if jsonErr != nil {
|
|
|
|
|
publicmethod.Result(1, jsonErr, c, "数据获取错误!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if jsonAry.Code != 0 {
|
|
|
|
|
publicmethod.Result(1, jsonErr, c, jsonAry.Msg)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
menuThree = jsonAry.Data
|
|
|
|
|
} else {
|
|
|
|
|
//api入口为空,采用系统内置获取授权菜单
|
|
|
|
|
switch systemPower.Coder {
|
|
|
|
|
case "cangchu":
|
|
|
|
|
menuThree = wmsMenuThree()
|
|
|
|
|
// fmt.Printf("ApiUrl----2-->%v\n", systemPower.ApiUrl)
|
|
|
|
|
default:
|
|
|
|
|
//获取绩效考核菜单树
|
|
|
|
|
menuThree = kpiMenuThree()
|
|
|
|
|
// fmt.Printf("ApiUrl---1--->%v\n", systemPower.ApiUrl)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
publicmethod.Result(0, menuThree, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// kpi菜单树
|
|
|
|
|
func kpiMenuThree() (menuThree []publicmethod.PowerThree) {
|
|
|
|
|
|
|
|
|
|
var menuList []modelsschool.SystemMenuSchool
|
|
|
|
|
err := overall.CONSTANT_DB_Master.Where("`m_steat` = 1").Order("`m_sort` ASC").Order("`m_id` DESC").Find(&menuList).Error
|
|
|
|
|
lenSum := len(menuList)
|
|
|
|
|
// fmt.Printf("ApiUrl---3--->%v--->%v\n", err, lenSum)
|
|
|
|
|
if err != nil || lenSum < 1 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var menuSmaillList []publicmethod.MenuContList
|
|
|
|
|
for i := 0; i < lenSum; i++ {
|
|
|
|
|
var menSmaiCont publicmethod.MenuContList
|
|
|
|
|
menSmaiCont.Id = strconv.FormatInt(menuList[i].Id, 10)
|
|
|
|
|
menSmaiCont.Name = menuList[i].Title
|
|
|
|
|
menSmaiCont.ParentId = strconv.FormatInt(menuList[i].ParentId, 10)
|
|
|
|
|
menSmaiCont.PathUrl = menuList[i].ApiUrl
|
|
|
|
|
menuSmaillList = append(menuSmaillList, menSmaiCont)
|
|
|
|
|
}
|
|
|
|
|
menuThree = publicmethod.GetMenuThree(1, "0", menuSmaillList)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 仓储菜单树
|
|
|
|
|
func wmsMenuThree() (menuThree []publicmethod.PowerThree) {
|
|
|
|
|
var menuList []modelsstorage.AccesstoAddress
|
|
|
|
|
err := overall.CONSTANT_DB_Storage.Where("`state` = 1").Find(&menuList).Error
|
|
|
|
|
lenSum := len(menuList)
|
|
|
|
|
if err != nil || lenSum < 1 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var menuSmaillList []publicmethod.MenuContList
|
|
|
|
|
for i := 0; i < lenSum; i++ {
|
|
|
|
|
var menSmaiCont publicmethod.MenuContList
|
|
|
|
|
menSmaiCont.Id = strconv.FormatInt(menuList[i].Id, 10)
|
|
|
|
|
menSmaiCont.Name = menuList[i].Name
|
|
|
|
|
menSmaiCont.ParentId = strconv.FormatInt(int64(menuList[i].Menuparent), 10)
|
|
|
|
|
menSmaiCont.PathUrl = menuList[i].Url
|
|
|
|
|
menuSmaillList = append(menuSmaillList, menSmaiCont)
|
|
|
|
|
}
|
|
|
|
|
menuThree = publicmethod.GetMenuThrees(1, "0", menuSmaillList)
|
|
|
|
|
return
|
|
|
|
|
}
|