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.
758 lines
19 KiB
758 lines
19 KiB
package overallhandle
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/md5"
|
|
"crypto/rand"
|
|
"crypto/sha1"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"hr_server/models"
|
|
"hr_server/overall"
|
|
"math"
|
|
"math/big"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/mozillazg/go-pinyin"
|
|
)
|
|
|
|
// 全局函数处理
|
|
// 编号,纯数字
|
|
func TableNumber(class ...string) (number int64) {
|
|
result, _ := rand.Int(rand.Reader, big.NewInt(8999))
|
|
numberTeam := result.Int64() + 1000
|
|
numberStr := fmt.Sprintf("%v%v", time.Now().Unix(), numberTeam)
|
|
if len(class) > 0 {
|
|
resultLong, _ := rand.Int(rand.Reader, big.NewInt(8999999))
|
|
numberTeamLong := resultLong.Int64() + 1000000
|
|
numberStr = fmt.Sprintf("%v%v", time.Now().Unix(), numberTeamLong)
|
|
}
|
|
number, _ = strconv.ParseInt(numberStr, 10, 64)
|
|
return
|
|
}
|
|
|
|
// 初始化map
|
|
func MapOut() (data map[string]interface{}) {
|
|
data = make(map[string]interface{}) //必可不少,分配内存
|
|
return data
|
|
}
|
|
|
|
func MapOutint() (data map[int]interface{}) {
|
|
data = make(map[int]interface{}) //必可不少,分配内存
|
|
return data
|
|
}
|
|
func MapOutint64() (data map[int64]interface{}) {
|
|
data = make(map[int64]interface{}) //必可不少,分配内存
|
|
return data
|
|
}
|
|
func MapOutFloat64() (data map[float64]interface{}) {
|
|
data = make(map[float64]interface{}) //必可不少,分配内存
|
|
return data
|
|
}
|
|
func MapOutString() (data map[string]string) {
|
|
data = make(map[string]string) //必可不少,分配内存
|
|
return data
|
|
}
|
|
|
|
//时间搓转换成日期
|
|
/*
|
|
@timestamp 待转换的时间戳
|
|
@timeType 转换类型
|
|
*/
|
|
func UnixTimeToDay(timeStamp int64, timeType int) (dateStr string) {
|
|
timeTemplate := "2006-01-02 15:04:05" //常规类型
|
|
switch timeType {
|
|
case 1:
|
|
timeTemplate = "2006/01/02 15:04:05"
|
|
case 2:
|
|
timeTemplate = "2006/01/02 15:04"
|
|
case 3:
|
|
timeTemplate = "2006/01/02 15"
|
|
case 4:
|
|
timeTemplate = "2006/01/02"
|
|
case 5:
|
|
timeTemplate = "15:04:05"
|
|
case 6:
|
|
timeTemplate = "15:04"
|
|
case 7:
|
|
timeTemplate = "15"
|
|
case 8:
|
|
timeTemplate = "04:05"
|
|
case 9:
|
|
timeTemplate = "04"
|
|
case 10:
|
|
timeTemplate = "05"
|
|
case 11:
|
|
timeTemplate = "2006-01-02 15:04:05"
|
|
case 12:
|
|
timeTemplate = "2006-01-02 15:04"
|
|
case 13:
|
|
timeTemplate = "2006-01-02 15"
|
|
case 14:
|
|
timeTemplate = "2006-01-02"
|
|
case 15:
|
|
timeTemplate = "2006-01" //年月
|
|
case 16:
|
|
timeTemplate = "2006" //年
|
|
case 17:
|
|
timeTemplate = "01" //月
|
|
case 18:
|
|
timeTemplate = "02" //日
|
|
case 19: //季度
|
|
dayMonth := time.Unix(timeStamp, 0).Format("01")
|
|
datMonthFloat, datMonthFloatErr := strconv.ParseFloat(dayMonth, 10)
|
|
if datMonthFloatErr == nil {
|
|
dateStr = strconv.FormatFloat(math.Ceil(datMonthFloat/3), 'f', -1, 64)
|
|
}
|
|
dateStr = "1"
|
|
case 20:
|
|
timeTemplate = "20060102"
|
|
case 21:
|
|
timeTemplate = "200601"
|
|
default:
|
|
timeTemplate = "2006-01-02 15:04:05" //常规类型
|
|
}
|
|
dateStr = time.Unix(timeStamp, 0).Format(timeTemplate)
|
|
return
|
|
}
|
|
|
|
/*
|
|
日期转时间戳
|
|
*/
|
|
func DateToTimeStamp(dataStr string) (timeStamp int64, isTrue bool) {
|
|
isTrue = false
|
|
tmp := "2006-01-02 15:04:05"
|
|
res, err := time.ParseInLocation(tmp, dataStr, time.Local)
|
|
timeStamp = res.Unix()
|
|
if err == nil {
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
// 数据库查询翻页
|
|
func LimitPage(page, pageSize int) (offSet int) {
|
|
if page < 1 {
|
|
page = 1
|
|
}
|
|
offSet = pageSize * (page - 1)
|
|
if offSet < 0 {
|
|
offSet = 0
|
|
}
|
|
return
|
|
}
|
|
|
|
// 中文首字母大写
|
|
func ChineseFirstWordCapitalize(wordStr string) (firstWord string) {
|
|
pinYinSub := pinyin.NewArgs()
|
|
rows := pinyin.Pinyin(wordStr, pinYinSub)
|
|
for i := 0; i < len(rows); i++ {
|
|
if len(rows[i]) != 0 {
|
|
str := rows[i][0]
|
|
pi := str[0:1]
|
|
firstWord += string(bytes.ToUpper([]byte(pi)))
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取行政组织首字母
|
|
/*
|
|
@govName 全称
|
|
@abbreviation 简称
|
|
@govClass 部门类型
|
|
@parentId 上级
|
|
*/
|
|
func GetGovFirstWords(govName, abbreviation, govClass, parentId string) (firstWord string) {
|
|
var lev int = 0
|
|
overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganizationType{}).Select("`level`").Where("`id` = ?", govClass).First(&lev)
|
|
if lev <= 2 {
|
|
if abbreviation != "" {
|
|
firstWord = ChineseFirstWordCapitalize(abbreviation)
|
|
} else {
|
|
firstWord = ChineseFirstWordCapitalize(govName)
|
|
}
|
|
} else {
|
|
var idAry []int64
|
|
firstWord = GetCompany(GetGroupFramework(parentId, idAry))
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取行政级别公司
|
|
func GetCompany(id []int64) (firstWord string) {
|
|
var govClass []outGovToClass
|
|
err := overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Select("administrative_organization.name,administrative_organization.abbreviation,aot.level").Joins("left join administrative_organization_type as aot on aot.id = administrative_organization.organization_type").Where("administrative_organization.state IN ? AND administrative_organization.id IN ?", []int{1, 2}, id).Find(&govClass).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
levelOne := ""
|
|
levelTwo := ""
|
|
for _, v := range govClass {
|
|
if v.Level == 2 {
|
|
if v.Abbreviation != "" {
|
|
levelTwo = ChineseFirstWordCapitalize(v.Abbreviation)
|
|
} else {
|
|
levelTwo = ChineseFirstWordCapitalize(v.Name)
|
|
}
|
|
firstWord = levelTwo
|
|
return
|
|
}
|
|
if v.Level == 1 {
|
|
if v.Abbreviation != "" {
|
|
levelOne = ChineseFirstWordCapitalize(v.Abbreviation)
|
|
} else {
|
|
levelOne = ChineseFirstWordCapitalize(v.Name)
|
|
}
|
|
}
|
|
}
|
|
if levelTwo != "" {
|
|
firstWord = levelTwo
|
|
} else {
|
|
firstWord = levelOne
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取架构
|
|
func GetGroupFramework(parentId string, father []int64) []int64 {
|
|
var id int64
|
|
err := overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Select("`id`").Where("`superior` = ?", parentId).First(&id)
|
|
if err != nil {
|
|
return father
|
|
}
|
|
father = append(father, id)
|
|
GetGroupFramework(strconv.FormatInt(id, 10), father)
|
|
return father
|
|
}
|
|
|
|
// 获取集团或第一实权部门
|
|
func GetGroupOrDepartPower(parentId int64, departId ...int64) int64 {
|
|
var orgCont models.AdministrativeOrganization
|
|
err := orgCont.GetCont(map[string]interface{}{"id": parentId}, "id", "organization_type", "superior", "ispower")
|
|
if err != nil {
|
|
return parentId
|
|
}
|
|
// jsonCCC, _ := json.Marshal(orgCont)
|
|
// fmt.Printf("orgCont------->%v\n", string(jsonCCC))
|
|
if len(departId) > 0 {
|
|
if orgCont.IsPower == 1 {
|
|
// fmt.Printf("orgCont---1---->%v---->%v\n", string(jsonCCC), orgCont.Id)
|
|
return orgCont.Id
|
|
}
|
|
return GetGroupOrDepartPower(orgCont.Superior, 1)
|
|
} else {
|
|
if orgCont.OrganizationType <= 2 {
|
|
// fmt.Printf("orgCont---2---->%v\n", string(jsonCCC))
|
|
return orgCont.Id
|
|
}
|
|
return GetGroupOrDepartPower(orgCont.Superior)
|
|
}
|
|
// if len(departId) > 0 {
|
|
// fmt.Printf("orgCont----4--->%v\n", orgCont.Superior)
|
|
// GetGroupOrDepartPower(orgCont.Superior, 1)
|
|
// } else {
|
|
// fmt.Printf("orgCont----5--->%v\n", orgCont.Superior)
|
|
// GetGroupOrDepartPower(orgCont.Superior)
|
|
// }
|
|
// fmt.Printf("orgCont----3--->%v\n", string(jsonCCC))
|
|
return orgCont.Id
|
|
}
|
|
|
|
// ZeroFillByStr
|
|
// @Description: 字符串补零
|
|
// @param str :需要操作的字符串
|
|
// @param resultLen 结果字符串的长度
|
|
// @param reverse true 为前置补零,false 为后置补零
|
|
// @return string
|
|
func ZeroFillByStr(str string, resultLen int, reverse bool) string {
|
|
if len(str) > resultLen || resultLen <= 0 {
|
|
return str
|
|
}
|
|
if reverse {
|
|
return fmt.Sprintf("%0*s", resultLen, str) //不足前置补零
|
|
}
|
|
result := str
|
|
for i := 0; i < resultLen-len(str); i++ {
|
|
result += "0"
|
|
}
|
|
return result
|
|
}
|
|
|
|
// 生成编号
|
|
func CreateNumber(firstWords, govClass string) (numberStr string) {
|
|
var orgCont models.AdministrativeOrganization
|
|
var orgClass models.AdministrativeOrganizationType
|
|
|
|
whereAry := MapOut()
|
|
whereAry["superior"] = govClass
|
|
countId := orgCont.CountCont(whereAry)
|
|
|
|
whereOrgAry := MapOut()
|
|
whereOrgAry["id"] = govClass
|
|
orgCont.GetCont(whereOrgAry)
|
|
|
|
orgWhere := MapOut()
|
|
orgWhere["id"] = orgCont.OrganizationType
|
|
orgClass.GetCont(orgWhere)
|
|
|
|
// fmt.Printf("---11---------->%v------>%v\n", orgWhere, orgClass)
|
|
|
|
if orgClass.Level < 2 {
|
|
numberVal := ZeroFillByStr(strconv.FormatInt(countId, 10), 2, true)
|
|
numberStr = fmt.Sprintf("%v%v", firstWords, numberVal)
|
|
} else {
|
|
countId++
|
|
numberVal := ZeroFillByStr(strconv.FormatInt(countId, 10), 2, true)
|
|
|
|
// fmt.Printf("------------->%v------>%v\n", whereOrgAry, orgCont)
|
|
numberStr = fmt.Sprintf("%v%v", orgCont.Number, numberVal)
|
|
}
|
|
return
|
|
}
|
|
|
|
type MenuList []OutGovCont
|
|
|
|
// 行政组织递归
|
|
func (g *MenuList) GovRecursion(parentId, level int64) []govThree {
|
|
var govMap []govThree
|
|
|
|
list := g.findChildren(parentId)
|
|
if len(list) == 0 {
|
|
return govMap
|
|
}
|
|
for _, v := range list {
|
|
// child := g.GovRecursion(v.Superior, level+1)
|
|
g.GovRecursion(v.Superior, level+1)
|
|
// govMap = append(govMap, govThree{v, child})
|
|
}
|
|
return govMap
|
|
}
|
|
|
|
// 获取子集
|
|
func (g *MenuList) findChildren(parentId int64) []OutGovCont {
|
|
child := []OutGovCont{}
|
|
|
|
for _, v := range *g {
|
|
if v.Superior == parentId {
|
|
child = append(child, v)
|
|
}
|
|
}
|
|
return child
|
|
}
|
|
|
|
func GovThreeList(parentId int64, govAry []OutGovCont) []govThree {
|
|
var govMap []govThree
|
|
// fmt.Printf("govAry---------------->%v\n", govAry)
|
|
for _, v := range govAry {
|
|
// var zhucont govThree
|
|
|
|
if v.Superior == parentId {
|
|
|
|
child := GovThreeList(v.Id, govAry)
|
|
govMap = append(govMap, govThree{v, child})
|
|
}
|
|
|
|
}
|
|
return govMap
|
|
}
|
|
|
|
// 菜单权限递归
|
|
func MenuThreePermit(parentId int64, menuAry []models.SystemMenuOperation) []MenuPermitThree {
|
|
var menuThree []MenuPermitThree
|
|
for _, v := range menuAry {
|
|
if v.ParentId == parentId {
|
|
child := MenuThreePermit(v.Id, menuAry)
|
|
menuThree = append(menuThree, MenuPermitThree{v, child})
|
|
}
|
|
}
|
|
return menuThree
|
|
}
|
|
|
|
/*
|
|
*加密算法
|
|
*/
|
|
type Md5Encryption struct {
|
|
Code string `json:"code"`
|
|
AppKey string `json:"appKey"`
|
|
}
|
|
|
|
func (m *Md5Encryption) Md5EncryptionAlgorithm() (md5Val string) {
|
|
if m.AppKey == "" {
|
|
m.Md5EncryptionInit(m.Code)
|
|
}
|
|
// fmt.Printf("Code ====> %v\n", m.Code)
|
|
// fmt.Printf("AppKey ====> %v\n", m.AppKey)
|
|
|
|
mdNew := md5.New()
|
|
mdNew.Write([]byte(m.AppKey))
|
|
keyMd5 := fmt.Sprintf("%x", mdNew.Sum(nil))
|
|
|
|
// fmt.Printf("Step1:--AppKey-加密->%v\n", keyMd5)
|
|
|
|
codeNewMd1 := md5.New()
|
|
codeNewMd1.Write([]byte(m.Code))
|
|
codeMd1 := fmt.Sprintf("%x", codeNewMd1.Sum(nil))
|
|
|
|
// fmt.Printf("Step2:--CodeString-加密->%v\n", codeMd1)
|
|
|
|
yiCeng := codeMd1 + keyMd5
|
|
|
|
// fmt.Printf("Step3:--CodeString+AppKey-->%v\n", yiCeng)
|
|
|
|
yiCengNew := md5.New()
|
|
yiCengNew.Write([]byte(yiCeng))
|
|
yiCengMd5 := fmt.Sprintf("%x", yiCengNew.Sum(nil))
|
|
|
|
// fmt.Printf("Step4:--one-加密->%v\n", yiCengMd5)
|
|
|
|
erCeng := yiCengMd5 + m.AppKey
|
|
|
|
// fmt.Printf("Step5:--one + AppKey->%v\n", erCeng)
|
|
|
|
// fmt.Printf("AppKey ===2=> %v\n", m.AppKey)
|
|
|
|
erCengNew := md5.New()
|
|
erCengNew.Write([]byte(erCeng))
|
|
md5Val = fmt.Sprintf("%x", erCengNew.Sum(nil))
|
|
|
|
// fmt.Printf("Step6:--therr--加密-->%v\n", md5Val)
|
|
|
|
// md5Val = codeMd1
|
|
return
|
|
}
|
|
|
|
func (m *Md5Encryption) Md5EncryptionAlgorithmFj() (md5Val string, outlog []string) {
|
|
if m.AppKey == "" {
|
|
m.Md5EncryptionInit(m.Code)
|
|
}
|
|
// fmt.Printf("Code ====> %v\n", m.Code)
|
|
// fmt.Printf("AppKey ====> %v\n", m.AppKey)
|
|
|
|
outlog = append(outlog, fmt.Sprintf("Code ====> %v", m.Code))
|
|
outlog = append(outlog, fmt.Sprintf("AppKey ====> %v", m.AppKey))
|
|
|
|
mdNew := md5.New()
|
|
mdNew.Write([]byte(m.AppKey))
|
|
keyMd5 := fmt.Sprintf("%x", mdNew.Sum(nil))
|
|
|
|
// fmt.Printf("Step1:--AppKey-加密->%v\n", keyMd5)
|
|
outlog = append(outlog, fmt.Sprintf("Step1:--AppKey-加密->%v", keyMd5))
|
|
|
|
codeNewMd1 := md5.New()
|
|
codeNewMd1.Write([]byte(m.Code))
|
|
codeMd1 := fmt.Sprintf("%x", codeNewMd1.Sum(nil))
|
|
|
|
// fmt.Printf("Step2:--CodeString-加密->%v\n", codeMd1)
|
|
outlog = append(outlog, fmt.Sprintf("Step2:--CodeString-加密->%v", codeMd1))
|
|
|
|
yiCeng := codeMd1 + keyMd5
|
|
|
|
// fmt.Printf("Step3:--CodeString+AppKey-->%v\n", yiCeng)
|
|
outlog = append(outlog, fmt.Sprintf("Step3:--CodeString+AppKey-->%v", yiCeng))
|
|
|
|
yiCengNew := md5.New()
|
|
yiCengNew.Write([]byte(yiCeng))
|
|
yiCengMd5 := fmt.Sprintf("%x", yiCengNew.Sum(nil))
|
|
|
|
// fmt.Printf("Step4:--one-加密->%v\n", yiCengMd5)
|
|
outlog = append(outlog, fmt.Sprintf("Step4:--one-加密->%v", yiCengMd5))
|
|
|
|
erCeng := yiCengMd5 + m.AppKey
|
|
|
|
// fmt.Printf("Step5:--one + AppKey->%v\n", erCeng)
|
|
outlog = append(outlog, fmt.Sprintf("Step5:--one + AppKey->%v", erCeng))
|
|
|
|
// fmt.Printf("AppKey ===2=> %v\n", m.AppKey)
|
|
|
|
erCengNew := md5.New()
|
|
erCengNew.Write([]byte(erCeng))
|
|
md5Val = fmt.Sprintf("%x", erCengNew.Sum(nil))
|
|
|
|
fmt.Printf("Step6:--therr--加密-->%v\n", md5Val)
|
|
outlog = append(outlog, fmt.Sprintf("Step6:--therr--加密-->%v", md5Val))
|
|
|
|
// md5Val = codeMd1
|
|
return
|
|
}
|
|
|
|
// 初始化程序
|
|
func (m *Md5Encryption) Md5EncryptionInit(code string) {
|
|
m.AppKey = overall.CONSTANT_CONFIG.Appsetup.AppKey
|
|
m.Code = code
|
|
}
|
|
|
|
// sha1算法
|
|
func Sha1Encryption(str string) string {
|
|
sha1 := sha1.New()
|
|
sha1.Write([]byte(str))
|
|
return hex.EncodeToString(sha1.Sum(nil))
|
|
}
|
|
|
|
//计算当前时间N个月后的时间
|
|
/*
|
|
@timeStamp 当前时间戳
|
|
@futureTime 正数多少时间后,负数多少时间前
|
|
*/
|
|
func GetFutureMonthTime(timeStamp int64, futureTime, class int) (dateStr int64) {
|
|
timeUnix := time.Unix(timeStamp, 0)
|
|
addDate := timeUnix.AddDate(0, 0, futureTime)
|
|
switch class {
|
|
case 2:
|
|
addDate = timeUnix.AddDate(0, futureTime, 0)
|
|
case 3:
|
|
addDate = timeUnix.AddDate(futureTime, 0, 0)
|
|
default:
|
|
addDate = timeUnix.AddDate(0, 0, futureTime)
|
|
}
|
|
|
|
dateStr = addDate.Unix()
|
|
return
|
|
}
|
|
|
|
// 判断字符串是否在切片中
|
|
func StringIsInMap(str string, strAry []string) bool {
|
|
if len(strAry) > 0 {
|
|
for _, v := range strAry {
|
|
// fmt.Printf("id------>%v----->%v\n", str, strAry)
|
|
if v == str {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// 判断值是否在数组中
|
|
func JudeInArray(id int64, ary []string) (isTrue bool) {
|
|
// isTrue = false
|
|
// for _, val := range ary {
|
|
// valint64, err := strconv.ParseInt(val, 10, 64)
|
|
// if err == nil {
|
|
// if id == valint64 {
|
|
// isTrue = true
|
|
// }
|
|
// }
|
|
// }
|
|
idStr := strconv.FormatInt(id, 10)
|
|
isTrue = StringIsInMap(idStr, ary)
|
|
return
|
|
}
|
|
|
|
func JudgeInMap(id int64, ary []int64) bool {
|
|
if len(ary) > 0 {
|
|
for _, v := range ary {
|
|
if v == id {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// 判断元素是否在切片中
|
|
func IsInTrue[T GenericityVariable](key T, keyAry []T) (isTrue bool) {
|
|
isTrue = false
|
|
for _, v := range keyAry {
|
|
if v == key {
|
|
return true
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取两个切片得差集
|
|
func DifferenceSet[T GenericityVariable](one, two []T) []T {
|
|
var three []T
|
|
temp := map[T]struct{}{}
|
|
for _, val := range two {
|
|
if _, ok := temp[val]; !ok {
|
|
temp[val] = struct{}{}
|
|
}
|
|
}
|
|
for _, val := range one {
|
|
if _, ok := temp[val]; !ok {
|
|
three = append(three, val)
|
|
}
|
|
}
|
|
return three
|
|
}
|
|
|
|
// 合并两个数组
|
|
func HeBingArray[T GenericityVariable](one, two []T) (three []T) {
|
|
three = one
|
|
for _, val := range two {
|
|
if IsInTrue[T](val, three) == false {
|
|
three = append(three, val)
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//判断类型转换成
|
|
/*
|
|
字符转int
|
|
*/
|
|
func StringToInt(val interface{}) (int, error) {
|
|
switch val.(type) {
|
|
case string:
|
|
return strconv.Atoi(val.(string))
|
|
case int:
|
|
return val.(int), nil
|
|
default:
|
|
return 0, nil
|
|
}
|
|
return 0, nil
|
|
}
|
|
|
|
/*
|
|
字符转int64
|
|
*/
|
|
func StringToInt64(val interface{}) (int64, error) {
|
|
switch val.(type) {
|
|
case string:
|
|
return strconv.ParseInt(val.(string), 10, 64)
|
|
case int:
|
|
return int64(val.(int)), nil
|
|
case int64:
|
|
return val.(int64), nil
|
|
default:
|
|
return 0, nil
|
|
}
|
|
return 0, nil
|
|
}
|
|
|
|
/*
|
|
政治面貌
|
|
(1:群众; 2:无党派;3:台盟会员;4:九三社员;5:致公党员;6:农工党员;7:民进会员;8:民建会员;9:民盟盟员;10:民革会员,11:共青团员;12:预备党员;13:中共党员)
|
|
*/
|
|
func PolitiToString(emp int) string {
|
|
switch emp {
|
|
case 1:
|
|
return "群众"
|
|
case 2:
|
|
return "无党派"
|
|
case 3:
|
|
return "台盟会员"
|
|
case 4:
|
|
return "九三社员"
|
|
case 5:
|
|
return "致公党员"
|
|
case 6:
|
|
return "农工党员"
|
|
case 7:
|
|
return "民进会员"
|
|
case 8:
|
|
return "民建会员"
|
|
case 9:
|
|
return "民盟盟员"
|
|
case 10:
|
|
return "民革会员"
|
|
case 11:
|
|
return "共青团员"
|
|
case 12:
|
|
return "预备党员"
|
|
case 13:
|
|
return "中共党员"
|
|
default:
|
|
return "群众"
|
|
}
|
|
}
|
|
|
|
// 递归查找
|
|
func RecursionOrgLeve(superior int64, leve int64) (groupId int64) {
|
|
if leve == 0 {
|
|
leve = 1
|
|
}
|
|
var orgMap models.OrgContType
|
|
err := orgMap.GetCont(map[string]interface{}{"`id`": superior, "`state`": 1}, "`id`", "`superior`", "`level`")
|
|
if err != nil {
|
|
return
|
|
}
|
|
if orgMap.Level <= leve {
|
|
groupId = orgMap.Id
|
|
return
|
|
} else {
|
|
groupId = RecursionOrgLeve(orgMap.Superior, leve)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取集团、公司、部门、二级部门、工段
|
|
func GetOrgStructure(orgId int64) (groupId, companyId, departmentId, sunDepartId, workShopId int64) {
|
|
var orgContTypeInfo models.OrgContType
|
|
err := orgContTypeInfo.GetCont(map[string]interface{}{"`id`": orgId})
|
|
if err != nil {
|
|
return
|
|
}
|
|
switch orgContTypeInfo.Level {
|
|
case 1:
|
|
groupId = orgContTypeInfo.Id
|
|
case 2:
|
|
groupId = RecursionOrgLeve(orgContTypeInfo.Superior, 1)
|
|
workShopId = orgContTypeInfo.Id
|
|
case 3:
|
|
groupId = RecursionOrgLeve(orgContTypeInfo.Superior, 2)
|
|
companyId = orgContTypeInfo.Id
|
|
case 4:
|
|
groupId = RecursionOrgLeve(orgContTypeInfo.Superior, 2)
|
|
companyId = RecursionOrgLeve(orgContTypeInfo.Superior, 3)
|
|
departmentId = orgContTypeInfo.Id
|
|
case 5:
|
|
groupId = RecursionOrgLeve(orgContTypeInfo.Superior, 2)
|
|
companyId = RecursionOrgLeve(orgContTypeInfo.Superior, 3)
|
|
departmentId = RecursionOrgLeve(orgContTypeInfo.Superior, 4)
|
|
sunDepartId = orgContTypeInfo.Id
|
|
case 6:
|
|
groupId = RecursionOrgLeve(orgContTypeInfo.Superior, 2)
|
|
companyId = RecursionOrgLeve(orgContTypeInfo.Superior, 3)
|
|
departmentId = RecursionOrgLeve(orgContTypeInfo.Superior, 4)
|
|
sunDepartId = RecursionOrgLeve(orgContTypeInfo.Superior, 5)
|
|
workShopId = orgContTypeInfo.Id
|
|
default:
|
|
groupId = orgContTypeInfo.Id
|
|
companyId = orgContTypeInfo.Id
|
|
workShopId = orgContTypeInfo.Id
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取指定行政组织id,所有子类
|
|
func GetDepartmentSun(superior int64, idary []int64) (orgIdAry []int64) {
|
|
// if superior != 0 && IsInTrue[int64](superior, orgIdAry) == false {
|
|
// orgIdAry = append(orgIdAry, superior)
|
|
// }
|
|
var orgAry []models.AdministrativeOrganization
|
|
err := overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Select("`id`").Where("`state` = 1 AND `superior` = ?", superior).Find(&orgAry).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, v := range orgAry {
|
|
if superior != 0 && IsInTrue[int64](v.Id, orgIdAry) == false {
|
|
orgIdAry = append(orgIdAry, v.Id)
|
|
GetDepartmentSun(v.Id, orgIdAry)
|
|
} else {
|
|
GetDepartmentSun(v.Id, orgIdAry)
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取所有子集
|
|
func (a *AllSunList[int64]) GetAllSunOrg(superior int64) (err error) {
|
|
var orgAry []models.AdministrativeOrganization
|
|
err = overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Select("`id`").Where("`state` = 1 AND `superior` = ?", superior).Find(&orgAry).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, v := range orgAry {
|
|
// var idInt int64
|
|
idInt := int64(v.Id)
|
|
if IsInTrue[int64](idInt, a.SunList) == false {
|
|
a.SunList = append(a.SunList, idInt)
|
|
}
|
|
a.GetAllSunOrg(idInt)
|
|
}
|
|
return
|
|
}
|
|
|