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.
232 lines
9.4 KiB
232 lines
9.4 KiB
package publicmethod
|
|
|
|
import (
|
|
"appPlatform/models/modelshr"
|
|
"appPlatform/models/modelssystempermission"
|
|
"appPlatform/overall"
|
|
"bytes"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// 格式化输出
|
|
func Result(code int, data interface{}, c *gin.Context, msgAry ...string) {
|
|
var msg string
|
|
if _, isTrue := ErrorCodeMsg[code]; isTrue {
|
|
msg = ErrorCodeMsg[code]
|
|
}
|
|
if len(msgAry) > 0 {
|
|
for _, v := range msgAry {
|
|
if msg == "" {
|
|
msg = fmt.Sprintf("%v", v)
|
|
} else {
|
|
msg = fmt.Sprintf("%v。%v", msg, v)
|
|
}
|
|
|
|
}
|
|
}
|
|
c.JSON(http.StatusOK, Reply{code, msg, data}) //输出json格式数据
|
|
}
|
|
|
|
//列表输出标准格式
|
|
/*
|
|
@total 总数
|
|
@count 当前页总数
|
|
@page 页数
|
|
@pageSize 每页显示数量
|
|
@data 返回数据
|
|
*/
|
|
func ResultList(code, page, pageSize int, total, count int64, data interface{}, c *gin.Context) (printMap map[string]interface{}) {
|
|
outMap := MapOut[string]()
|
|
outMap["count"] = count
|
|
outMap["total"] = total
|
|
outMap["page"] = page
|
|
outMap["pagesize"] = pageSize
|
|
outMap["list"] = data
|
|
printMap = outMap
|
|
Result(code, outMap, c)
|
|
return
|
|
}
|
|
|
|
// 登录信息转换
|
|
func LoginMyCont(c *gin.Context) (myCont AuthenticationPower, err error) {
|
|
var myContInfo modelshr.ManCont
|
|
context, exi := c.Get(overall.MyContJwt)
|
|
contextPower, exiPower := c.Get(overall.MyContJwtPower)
|
|
if exi != true {
|
|
err = errors.New("对不起!你没有该功能的操作权限!1")
|
|
return
|
|
}
|
|
jsonCont, jsonErr := json.Marshal(context)
|
|
// fmt.Printf("LoginMyCont--------->%v--------->%v\n", contextPower, exiPower)
|
|
if jsonErr != nil {
|
|
err = jsonErr
|
|
return
|
|
}
|
|
jsonUnErr := json.Unmarshal(jsonCont, &myContInfo)
|
|
if jsonUnErr != nil {
|
|
err = jsonUnErr
|
|
return
|
|
}
|
|
// var powerInfo SystemPowerInfo
|
|
var powerInfo EmpowerCont
|
|
if exiPower == true {
|
|
jsonPowerCont, _ := json.Marshal(contextPower)
|
|
json.Unmarshal(jsonPowerCont, &powerInfo)
|
|
// fmt.Printf("LoginMyCont--------->%v--------->%v\n", powerInfo, string(jsonPowerCont))
|
|
}
|
|
PointIdList := strings.Split(powerInfo.PointId, ",")
|
|
OrganizationList := strings.Split(powerInfo.Operation, ",")
|
|
myCont.Id = myContInfo.Id
|
|
myCont.Number = myContInfo.Number //员工工号"`
|
|
myCont.Name = myContInfo.Name //姓名"`
|
|
myCont.Icon = myContInfo.Icon //头像"`
|
|
myCont.HireClass = myContInfo.HireClass //雇佣类型(1:雇佣入职;2:再入职;)"`
|
|
myCont.EmpType = myContInfo.EmpType //用工关系(1:临时工 , 2:编外人员 ;3:实习&实习生;4:试用员工;5:待分配;6:待岗;7:临时调入;8:正式员工;9:长期病假;10:停薪留职;11:退休;12:辞职;13:辞退;14:离职)"`
|
|
myCont.Company = myContInfo.Company //入职公司"`
|
|
myCont.MainDeparment = myContInfo.MainDeparment //主部门"`
|
|
myCont.SunMainDeparment = myContInfo.SunMainDeparment //二级主部门"`
|
|
myCont.Deparment = myContInfo.Deparment //部门
|
|
myCont.AdminOrg = myContInfo.AdminOrg // 所属行政组织"`
|
|
myCont.TeamId = myContInfo.TeamId //班组"`
|
|
myCont.Position = myContInfo.Position //职位"`
|
|
myCont.JobClass = myContInfo.JobClass // 职务分类"`
|
|
myCont.JobId = myContInfo.JobId //职务"`
|
|
myCont.JobLeve = myContInfo.JobLeve //职务等级"`
|
|
myCont.Time = myContInfo.Time //写入时间"`
|
|
myCont.EiteTime = myContInfo.EiteTime // 编辑时间"`
|
|
myCont.Wechat = myContInfo.Wechat //微信UserId"`
|
|
myCont.WorkWechat = myContInfo.WorkWechat //企业微信UserId"`
|
|
myCont.State = myContInfo.State //状态(1:启用;2:禁用;3:删除)`
|
|
myCont.Key = myContInfo.Key //nkey"`
|
|
myCont.IsAdmin = myContInfo.IsAdmin //是否为管理员(1:不是;2:分公司;3:集团管理员;4:超级管`
|
|
myCont.Password = myContInfo.Password // 密码"`
|
|
myCont.Role = myContInfo.Role // 角色
|
|
myCont.Idcardno = myContInfo.Idcardno //t 身份证号"`
|
|
myCont.Passportno = myContInfo.Passportno // 护照号码"`
|
|
myCont.Globalroaming = myContInfo.Globalroaming // 国际区号"`
|
|
myCont.Mobilephone = myContInfo.Mobilephone //手机号码"`
|
|
myCont.Email = myContInfo.Email //电子邮件"`
|
|
myCont.Gender = myContInfo.Gender //性别(1:男性;2:女性;3:中性)"`
|
|
myCont.Birthday = myContInfo.Birthday //birthday"`
|
|
myCont.Myfolk = myContInfo.Myfolk //民族"`
|
|
myCont.Nativeplace = myContInfo.Nativeplace //籍贯"`
|
|
myCont.Idcardstartdate = myContInfo.Idcardstartdate // 身份证有效期开始"`
|
|
myCont.Idcardenddate = myContInfo.Idcardenddate //身份证有效期结束"`
|
|
myCont.Idcardaddress = myContInfo.Idcardaddress // 身份证地址"`
|
|
myCont.IdcardIssued = myContInfo.IdcardIssued // 身份证签发机关"`
|
|
myCont.Health = myContInfo.Health //健康状况(1:良好;2:一般;3:较弱,4:有生理缺陷;5:残废)"`
|
|
myCont.Maritalstatus = myContInfo.Maritalstatus //婚姻状况(1:未婚;2:已婚;3:丧偶;4:离异)"`
|
|
myCont.Internaltelephone = myContInfo.Internaltelephone //i内线电话"`
|
|
myCont.Currentresidence = myContInfo.Currentresidence //现居住地址"`
|
|
myCont.Constellation = myContInfo.Constellation //星座(1:白羊座;2:金牛座;3:双子座;4:巨蟹座;5:狮子座;6:处女座;7:天枰座;8:天蝎座;9:射手座;10:摩羯座;11:水瓶座;12:双鱼座)"`
|
|
myCont.Isdoubleworker = myContInfo.Isdoubleworker //是否双职工(1:是;2:否)"`
|
|
myCont.Isveterans = myContInfo.Isveterans //是否为退役军人(1:是;2:否)"`
|
|
myCont.Veteransnumber = myContInfo.Veteransnumber //退役证编号"`
|
|
myCont.Jobstartdate = myContInfo.Jobstartdate //参加工作日期"`
|
|
myCont.Entrydate = myContInfo.Entrydate //入职日期"`
|
|
myCont.Probationperiod = myContInfo.Probationperiod //试用期"`
|
|
myCont.Planformaldate = myContInfo.Planformaldate //预计转正日期"`
|
|
myCont.PoliticalOutlook = myContInfo.PoliticalOutlook //政治面貌(1:群众;2:无党派;3:台盟会员;4:九三社员;5:致公党员;6:农工党员;7:民进会员;8:民建会员;9:民盟盟员;10:民革会员,11:共青团员;12:预备党员;13:中共党员)"`
|
|
myCont.Level = powerInfo.Level
|
|
myCont.PointIdList = PointIdList
|
|
myCont.OrganizationList = OrganizationList
|
|
return
|
|
}
|
|
|
|
// Get请求
|
|
func CurlGet(getUrl string) []byte {
|
|
client := &http.Client{}
|
|
reqest, err := http.NewRequest("GET", getUrl, nil)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
response, _ := client.Do(reqest)
|
|
defer response.Body.Close()
|
|
body, err := ioutil.ReadAll(response.Body)
|
|
return body
|
|
}
|
|
|
|
// Post请求 json
|
|
func CurlPostJosn(postUrl string, jsonData []byte) []byte {
|
|
req, err := http.NewRequest("POST", postUrl, bytes.NewBuffer(jsonData))
|
|
req.Header.Set("Content-Type", "application/json;charset=utf-8")
|
|
client := &http.Client{}
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer resp.Body.Close()
|
|
body, _ := ioutil.ReadAll(resp.Body)
|
|
return body
|
|
}
|
|
|
|
// 判断用户身份
|
|
func DetermineUserIdentity(userKey int64) (identity outShenFen) {
|
|
var userCont modelshr.PersonArchives
|
|
err := userCont.GetCont(map[string]interface{}{"`key`": userKey})
|
|
if err != nil {
|
|
identity.Level = 1
|
|
return
|
|
}
|
|
//角色权限范围判定
|
|
roleList := strings.Split(userCont.Role, ",")
|
|
var roleVerify modelssystempermission.RoleEmpower
|
|
overall.CONSTANT_DB_System_Permission.Where("`state` = 1 AND `system` = ? AND `id` IN ? ", "kpi", roleList).Find(&roleVerify)
|
|
|
|
//岗位权限范围判定
|
|
var postVerify modelssystempermission.Empower
|
|
postVerify.GetCont(map[string]interface{}{"`post_id`": userCont.Position, "`state`": 1, "`system`": "kpi"})
|
|
if roleVerify.Level >= postVerify.Level {
|
|
identity.Level = roleVerify.Level
|
|
} else {
|
|
identity.Level = postVerify.Level
|
|
}
|
|
|
|
switch identity.Level {
|
|
case 2:
|
|
identity.Level = 2
|
|
|
|
var sunOrg GetOrgAllParent
|
|
sunOrg.GetOrgSonAllId(userCont.MainDeparment)
|
|
identity.OrgList = sunOrg.Id
|
|
identity.OrgList = append(identity.OrgList, userCont.MainDeparment)
|
|
case 3:
|
|
identity.Level = 3
|
|
identity.Group = userCont.Company
|
|
case 4:
|
|
identity.Level = 4
|
|
if roleVerify.Organization != "" {
|
|
orgList := strings.Split(roleVerify.Organization, ",")
|
|
for _, v := range orgList {
|
|
orgIdInt, _ := strconv.ParseInt(v, 10, 64)
|
|
if !IsInTrue[int64](orgIdInt, identity.OrgList) {
|
|
identity.OrgList = append(identity.OrgList, orgIdInt)
|
|
}
|
|
}
|
|
}
|
|
if postVerify.Organization != "" {
|
|
orgListPost := strings.Split(postVerify.Organization, ",")
|
|
for _, pv := range orgListPost {
|
|
orgIdPostInt, _ := strconv.ParseInt(pv, 10, 64)
|
|
if !IsInTrue[int64](orgIdPostInt, identity.OrgList) {
|
|
identity.OrgList = append(identity.OrgList, orgIdPostInt)
|
|
}
|
|
}
|
|
}
|
|
case 5:
|
|
identity.Level = 5
|
|
identity.Group = 0
|
|
identity.OrgList = []int64{}
|
|
default:
|
|
identity.Level = 1
|
|
}
|
|
return
|
|
}
|
|
|