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.
265 lines
6.5 KiB
265 lines
6.5 KiB
package overallhandle
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"hr_server/models"
|
|
"hr_server/overall"
|
|
"math"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/mozillazg/go-pinyin"
|
|
)
|
|
|
|
//全局函数处理
|
|
|
|
//初始化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"
|
|
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
|
|
}
|
|
|
|
//
|
|
// 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
|
|
}
|
|
|
|
// //获取行政组织的部门
|
|
// func GetOrgDepartment()
|
|
|