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.
1468 lines
39 KiB
1468 lines
39 KiB
package overallhandle
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/md5"
|
|
"crypto/rand"
|
|
"crypto/sha1"
|
|
"encoding/hex"
|
|
"errors"
|
|
"fmt"
|
|
"hr_server/grocerystore"
|
|
"hr_server/middleware/snowflake"
|
|
"hr_server/models"
|
|
"hr_server/overall"
|
|
"io/ioutil"
|
|
"math"
|
|
"math/big"
|
|
"net/http"
|
|
"reflect"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/mozillazg/go-pinyin"
|
|
)
|
|
|
|
// 全局函数处理
|
|
var (
|
|
timeLayoutMap = map[string]string{
|
|
"y": "2006",
|
|
"m": "2006-01",
|
|
"d": "2006-01-02",
|
|
"h": "2006-01-02 15",
|
|
"i": "2006-01-02 15:04",
|
|
"s": "2006-01-02 15:04:05",
|
|
}
|
|
|
|
weekDay = map[string]int{
|
|
"Monday": 1,
|
|
"Tuesday": 2,
|
|
"Wednesday": 3,
|
|
"Thursday": 4,
|
|
"Friday": 5,
|
|
"Saturday": 6,
|
|
"Sunday": 7,
|
|
}
|
|
)
|
|
|
|
// 编号,纯数字
|
|
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
|
|
}
|
|
|
|
// 获取唯一编号
|
|
func OnlyOneNumber(id int64) (manKeyNum int64) {
|
|
node, nodeErr := snowflake.NewWorker(id)
|
|
if nodeErr == nil {
|
|
manKeyNum = node.GetId()
|
|
} else {
|
|
idStr := strconv.FormatInt(id, 10)
|
|
manKeyNum = TableNumber(idStr)
|
|
}
|
|
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 GetIntTime(timeStamp int64, timeType int) (timeInt int) {
|
|
dayMonth := time.Unix(timeStamp, 0)
|
|
switch timeType {
|
|
case 1:
|
|
timeInt = dayMonth.Year()
|
|
case 2:
|
|
fmt.Printf("%v\n", dayMonth.Format("01"))
|
|
timeInt, _ = strconv.Atoi(dayMonth.Format("01"))
|
|
default:
|
|
timeInt = dayMonth.Day()
|
|
}
|
|
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
|
|
}
|
|
|
|
// 获取集团或第一实权部门
|
|
func GetGroupOrDepartPoweres(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 GetGroupOrDepartPoweres(orgCont.Superior, 1)
|
|
} else {
|
|
if orgCont.OrganizationType <= 3 {
|
|
// fmt.Printf("orgCont---2---->%v\n", string(jsonCCC))
|
|
return orgCont.Id
|
|
}
|
|
return GetGroupOrDepartPoweres(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 RecursionOrgLevees(oldId, superior int64, leve int64) (groupId int64) {
|
|
if leve == 0 {
|
|
leve = 1
|
|
}
|
|
if superior == 0 {
|
|
return
|
|
}
|
|
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 {
|
|
if orgMap.Level == leve {
|
|
groupId = oldId
|
|
} else {
|
|
groupId = orgMap.Id
|
|
}
|
|
|
|
return
|
|
} else {
|
|
groupId = RecursionOrgLevees(orgMap.Superior, orgMap.Superior, leve)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 递归查找
|
|
func RecursionOrgLeve(superior int64, leve int64) (groupId int64) {
|
|
if leve == 0 {
|
|
leve = 1
|
|
}
|
|
if superior == 0 {
|
|
return
|
|
}
|
|
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 || (orgMap.Level == 5 && leve == 4 && (orgMap.Id == 282 || orgMap.Id == 115)) {
|
|
if orgMap.Level == leve {
|
|
groupId = superior
|
|
} else {
|
|
groupId = orgMap.Id
|
|
}
|
|
|
|
return
|
|
} else {
|
|
groupId = RecursionOrgLeve(orgMap.Superior, leve)
|
|
}
|
|
return
|
|
}
|
|
|
|
func RecursionOrgLeveEs(oldId, superior, leve int64) (groupId int64) {
|
|
if leve == 0 {
|
|
leve = 1
|
|
}
|
|
if superior == 0 {
|
|
return
|
|
}
|
|
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 {
|
|
if orgMap.Level == leve {
|
|
groupId = oldId
|
|
} else {
|
|
groupId = orgMap.Id
|
|
}
|
|
|
|
return
|
|
} else {
|
|
groupId = RecursionOrgLeveEs(orgMap.Id, orgMap.Superior, leve)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取集团、公司、部门、二级部门、工段
|
|
func GetOrgStructure(orgId int64) (groupId, companyId, departmentId, sunDepartId, workShopId int64) {
|
|
if orgId == 0 {
|
|
return
|
|
}
|
|
var orgContTypeInfo models.OrgContType
|
|
err := orgContTypeInfo.GetCont(map[string]interface{}{"`id`": orgId})
|
|
if err != nil {
|
|
return
|
|
}
|
|
fmt.Printf("获取集团属性--->%v\n", orgContTypeInfo.Level)
|
|
switch orgContTypeInfo.Level {
|
|
case 1:
|
|
groupId = orgContTypeInfo.Id
|
|
case 2:
|
|
groupId = RecursionOrgLevees(orgContTypeInfo.Superior, orgContTypeInfo.Superior, 1)
|
|
workShopId = orgContTypeInfo.Id
|
|
case 3:
|
|
groupId = RecursionOrgLevees(orgContTypeInfo.Superior, orgContTypeInfo.Superior, 2)
|
|
companyId = orgContTypeInfo.Id
|
|
case 4:
|
|
groupId = RecursionOrgLevees(orgContTypeInfo.Superior, orgContTypeInfo.Superior, 2)
|
|
companyId = RecursionOrgLevees(orgContTypeInfo.Superior, orgContTypeInfo.Superior, 3)
|
|
departmentId = orgContTypeInfo.Id
|
|
case 5:
|
|
groupId = RecursionOrgLevees(orgContTypeInfo.Superior, orgContTypeInfo.Superior, 2)
|
|
companyId = RecursionOrgLevees(orgContTypeInfo.Superior, orgContTypeInfo.Superior, 3)
|
|
departmentId = RecursionOrgLevees(orgContTypeInfo.Superior, orgContTypeInfo.Superior, 4)
|
|
fmt.Printf("departmentId--->%v\norgId--->%v\n", departmentId, orgId)
|
|
sunDepartId = orgContTypeInfo.Id
|
|
case 6:
|
|
groupId = RecursionOrgLevees(orgContTypeInfo.Superior, orgContTypeInfo.Superior, 2)
|
|
companyId = RecursionOrgLevees(orgContTypeInfo.Superior, orgContTypeInfo.Superior, 3)
|
|
departmentId = RecursionOrgLevees(orgContTypeInfo.Superior, orgContTypeInfo.Superior, 4)
|
|
sunDepartId = RecursionOrgLevees(orgContTypeInfo.Superior, 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
|
|
}
|
|
|
|
// 获取行政组织所有上级
|
|
func (a *AllSunList[int64]) GetAllFatherOrg(superior int64) (err error) {
|
|
var orgAry []models.AdministrativeOrganization
|
|
err = overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Select("`id`,`superior`").Where("`id` = ?", superior).Find(&orgAry).Error
|
|
if err != nil {
|
|
if IsInTrue[int64](superior, a.SunList) == false {
|
|
a.SunList = append(a.SunList, superior)
|
|
}
|
|
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)
|
|
}
|
|
supId := int64(v.Superior)
|
|
a.GetAllSunOrg(supId)
|
|
}
|
|
return
|
|
}
|
|
|
|
//浮点数保留小数
|
|
/*
|
|
@value 浮点数值
|
|
@weishu 要保留的小数位数
|
|
*/
|
|
func DecimalEs(value float64, weishu int) float64 {
|
|
switch weishu {
|
|
case 3:
|
|
value, _ = strconv.ParseFloat(fmt.Sprintf("%.3f", value), 64)
|
|
case 4:
|
|
value, _ = strconv.ParseFloat(fmt.Sprintf("%.4f", value), 64)
|
|
case 5:
|
|
value, _ = strconv.ParseFloat(fmt.Sprintf("%.5f", value), 64)
|
|
case 6:
|
|
value, _ = strconv.ParseFloat(fmt.Sprintf("%.6f", value), 64)
|
|
default:
|
|
value, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", value), 64)
|
|
}
|
|
|
|
return value
|
|
}
|
|
|
|
/*
|
|
*
|
|
获取月份有多少天
|
|
@year 年
|
|
@month 月
|
|
*/
|
|
func GetYearOfMonthHaveDay(year, month int) (day int) {
|
|
//有31天的月份
|
|
day31 := map[int]bool{
|
|
1: true,
|
|
3: true,
|
|
5: true,
|
|
7: true,
|
|
8: true,
|
|
10: true,
|
|
12: true,
|
|
}
|
|
if day31[month] == true {
|
|
return 31
|
|
}
|
|
//有30天的月份
|
|
day30 := map[int]bool{
|
|
4: true,
|
|
6: true,
|
|
9: true,
|
|
11: true,
|
|
}
|
|
if day30[month] == true {
|
|
return 30
|
|
}
|
|
if (year%4 == 0 && year%100 != 0) || (year%400 == 0) {
|
|
return 29
|
|
}
|
|
return 28
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-01-29 11:37:59
|
|
@ 功能: 获取行政组织父级列表
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *AllSunList[int64]) GetAllParentOrg(superior int64, level int) (err error) {
|
|
var orgAry models.OrgContType
|
|
gormDb := overall.CONSTANT_DB_HR.Model(&models.OrgContType{}).Select("`id`,`superior`,`level`").Where("`state` = 1 AND `id` = ?", superior)
|
|
if level != 0 {
|
|
gormDb = gormDb.Where("`level` > ?", level)
|
|
}
|
|
err = gormDb.First(&orgAry).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
idInt := int64(orgAry.Superior)
|
|
var fatherCont models.OrgContType
|
|
fatherCont.GetCont(map[string]interface{}{"`id`": idInt}, "`level`")
|
|
if orgAry.Superior != 0 && int64(fatherCont.Level) > int64(level) {
|
|
if IsInTrue[int64](idInt, a.SunList) == false {
|
|
a.SunList = append(a.SunList, idInt)
|
|
}
|
|
}
|
|
a.GetAllParentOrg(idInt, level)
|
|
return
|
|
}
|
|
|
|
// Post请求 json
|
|
func CurlPostJosn(postUrl string, jsonData []byte) []byte {
|
|
req, err := http.NewRequest("POST", postUrl, bytes.NewBuffer(jsonData))
|
|
if err != nil {
|
|
var kkl []byte
|
|
return kkl
|
|
}
|
|
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 NewGovThreeList(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 DucationToInt(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 "专家、教授"
|
|
default:
|
|
return "初中及以下"
|
|
}
|
|
}
|
|
|
|
// 学位(0:无;1:学士;2:硕士;3:博士;4:工学学士;5:教育学学位)int
|
|
func HestacademicdegreeToInt(hir string) int {
|
|
switch hir {
|
|
case "学士":
|
|
return 1
|
|
case "硕士":
|
|
return 2
|
|
case "博士":
|
|
return 3
|
|
case "学士学位":
|
|
return 1
|
|
case "工学学士":
|
|
return 4
|
|
case "教育学学位":
|
|
return 5
|
|
default:
|
|
return 0
|
|
}
|
|
}
|
|
|
|
// 根据字符串组合时间
|
|
/*
|
|
#dateTime 日期
|
|
*/
|
|
func (d *DateTimeTotimes) BaisStrToTime(dateTime string) {
|
|
timeStrAry := strings.Split(dateTime, "-")
|
|
switch len(timeStrAry) {
|
|
case 1:
|
|
dateTime = fmt.Sprintf("%v-01-01 12:00:00", dateTime)
|
|
case 2:
|
|
if len(timeStrAry[1]) < 2 {
|
|
dateTime = fmt.Sprintf("%v-0%v-01 12:00:00", timeStrAry[0], timeStrAry[1])
|
|
}
|
|
case 3:
|
|
monthStr := timeStrAry[1]
|
|
if len(timeStrAry[1]) < 2 {
|
|
monthStr = fmt.Sprintf("0%v", timeStrAry[1])
|
|
}
|
|
dayAry := strings.Split(timeStrAry[2], " ")
|
|
// fmt.Printf("dayAry:%v------>%v\n", dayAry, len(dayAry))
|
|
dayStr := dayAry[0]
|
|
if len(dayAry[0]) < 2 {
|
|
dayStr = fmt.Sprintf("0%v", dayAry[0])
|
|
}
|
|
if len(dayAry) > 1 {
|
|
// fmt.Printf("dayAry[1]:%v------>%v\n", dayAry[1], len(dayAry[1]))
|
|
if len(dayAry[1]) > 0 {
|
|
Hours := "00"
|
|
minutes := "00"
|
|
seconds := "00"
|
|
hisAry := strings.Split(dayAry[1], ":")
|
|
switch len(hisAry) {
|
|
case 1:
|
|
if len(hisAry[0]) < 2 {
|
|
Hours = fmt.Sprintf("0%v", hisAry[0])
|
|
} else {
|
|
Hours = hisAry[0]
|
|
}
|
|
case 2:
|
|
if len(hisAry[0]) < 2 {
|
|
Hours = fmt.Sprintf("0%v", hisAry[0])
|
|
} else {
|
|
Hours = hisAry[0]
|
|
}
|
|
if len(hisAry[1]) < 2 {
|
|
minutes = fmt.Sprintf("0%v", hisAry[1])
|
|
} else {
|
|
minutes = hisAry[1]
|
|
}
|
|
case 3:
|
|
if len(hisAry[0]) < 2 {
|
|
Hours = fmt.Sprintf("0%v", hisAry[0])
|
|
} else {
|
|
Hours = hisAry[0]
|
|
}
|
|
if len(hisAry[1]) < 2 {
|
|
minutes = fmt.Sprintf("0%v", hisAry[1])
|
|
} else {
|
|
minutes = hisAry[1]
|
|
}
|
|
if len(hisAry[2]) < 2 {
|
|
seconds = fmt.Sprintf("0%v", hisAry[2])
|
|
} else {
|
|
seconds = hisAry[2]
|
|
}
|
|
default:
|
|
}
|
|
dayStr = fmt.Sprintf("%v %v:%v:%v", dayStr, Hours, minutes, seconds)
|
|
}
|
|
}
|
|
// dayStr := timeStrAry[2]
|
|
// if len(timeStrAry[2]) < 2 {
|
|
// dayStr = fmt.Sprintf("0%v", timeStrAry[2])
|
|
// }
|
|
dateTime = fmt.Sprintf("%v-%v-%v", timeStrAry[0], monthStr, dayStr)
|
|
|
|
default:
|
|
}
|
|
// fmt.Printf("dateTime:%v---1--->%v\n", dateTime, len(dateTime))
|
|
orgTime, orgTimeErr := DateToTimeStamp(fmt.Sprintf("%v-01-01 12:00:00", dateTime))
|
|
d.Time = dateTime
|
|
if orgTimeErr {
|
|
d.AllTime = orgTime
|
|
d.Years = strconv.FormatInt(ComputingTime(orgTime, 1), 10)
|
|
d.Quarter = strconv.FormatInt(ComputingTime(orgTime, 2), 10)
|
|
d.Months = strconv.FormatInt(ComputingTime(orgTime, 3), 10)
|
|
d.Week = strconv.FormatInt(ComputingTime(orgTime, 4), 10)
|
|
d.Days = strconv.FormatInt(ComputingTime(orgTime, 5), 10)
|
|
d.Hours = strconv.FormatInt(ComputingTime(orgTime, 7), 10)
|
|
d.Minutes = strconv.FormatInt(ComputingTime(orgTime, 8), 10)
|
|
d.Second = strconv.FormatInt(ComputingTime(orgTime, 9), 10)
|
|
} else {
|
|
|
|
orgTime, orgTimeErr = DateToTimeStamp(fmt.Sprintf("%v-01 12:00:00", dateTime))
|
|
if orgTimeErr {
|
|
d.AllTime = orgTime
|
|
d.Years = strconv.FormatInt(ComputingTime(orgTime, 1), 10)
|
|
d.Quarter = strconv.FormatInt(ComputingTime(orgTime, 2), 10)
|
|
d.Months = strconv.FormatInt(ComputingTime(orgTime, 3), 10)
|
|
d.Week = strconv.FormatInt(ComputingTime(orgTime, 4), 10)
|
|
d.Days = strconv.FormatInt(ComputingTime(orgTime, 5), 10)
|
|
d.Hours = strconv.FormatInt(ComputingTime(orgTime, 7), 10)
|
|
d.Minutes = strconv.FormatInt(ComputingTime(orgTime, 8), 10)
|
|
d.Second = strconv.FormatInt(ComputingTime(orgTime, 9), 10)
|
|
|
|
fmt.Printf("dateTime:%v---2--->%v--->%v\n", orgTime, d.AllTime, d.Quarter)
|
|
} else {
|
|
orgTime, orgTimeErr = DateToTimeStamp(fmt.Sprintf("%v 12:00:00", dateTime))
|
|
if orgTimeErr {
|
|
d.AllTime = orgTime
|
|
d.Years = strconv.FormatInt(ComputingTime(orgTime, 1), 10)
|
|
d.Quarter = strconv.FormatInt(ComputingTime(orgTime, 2), 10)
|
|
d.Months = strconv.FormatInt(ComputingTime(orgTime, 3), 10)
|
|
d.Week = strconv.FormatInt(ComputingTime(orgTime, 4), 10)
|
|
d.Days = strconv.FormatInt(ComputingTime(orgTime, 5), 10)
|
|
d.Hours = strconv.FormatInt(ComputingTime(orgTime, 7), 10)
|
|
d.Minutes = strconv.FormatInt(ComputingTime(orgTime, 8), 10)
|
|
d.Second = strconv.FormatInt(ComputingTime(orgTime, 9), 10)
|
|
} else {
|
|
orgTime, orgTimeErr = DateToTimeStamp(fmt.Sprintf("%v:00:00", dateTime))
|
|
if orgTimeErr {
|
|
d.AllTime = orgTime
|
|
d.Years = strconv.FormatInt(ComputingTime(orgTime, 1), 10)
|
|
d.Quarter = strconv.FormatInt(ComputingTime(orgTime, 2), 10)
|
|
d.Months = strconv.FormatInt(ComputingTime(orgTime, 3), 10)
|
|
d.Week = strconv.FormatInt(ComputingTime(orgTime, 4), 10)
|
|
d.Days = strconv.FormatInt(ComputingTime(orgTime, 5), 10)
|
|
d.Hours = strconv.FormatInt(ComputingTime(orgTime, 7), 10)
|
|
d.Minutes = strconv.FormatInt(ComputingTime(orgTime, 8), 10)
|
|
d.Second = strconv.FormatInt(ComputingTime(orgTime, 9), 10)
|
|
} else {
|
|
orgTime, orgTimeErr = DateToTimeStamp(fmt.Sprintf("%v:00", dateTime))
|
|
if orgTimeErr {
|
|
d.AllTime = orgTime
|
|
d.Years = strconv.FormatInt(ComputingTime(orgTime, 1), 10)
|
|
d.Quarter = strconv.FormatInt(ComputingTime(orgTime, 2), 10)
|
|
d.Months = strconv.FormatInt(ComputingTime(orgTime, 3), 10)
|
|
d.Week = strconv.FormatInt(ComputingTime(orgTime, 4), 10)
|
|
d.Days = strconv.FormatInt(ComputingTime(orgTime, 5), 10)
|
|
d.Hours = strconv.FormatInt(ComputingTime(orgTime, 7), 10)
|
|
d.Minutes = strconv.FormatInt(ComputingTime(orgTime, 8), 10)
|
|
d.Second = strconv.FormatInt(ComputingTime(orgTime, 9), 10)
|
|
} else {
|
|
orgTime, orgTimeErr = DateToTimeStamp(dateTime)
|
|
if orgTimeErr {
|
|
d.AllTime = orgTime
|
|
d.Years = strconv.FormatInt(ComputingTime(orgTime, 1), 10)
|
|
d.Quarter = strconv.FormatInt(ComputingTime(orgTime, 2), 10)
|
|
d.Months = strconv.FormatInt(ComputingTime(orgTime, 3), 10)
|
|
d.Week = strconv.FormatInt(ComputingTime(orgTime, 4), 10)
|
|
d.Days = strconv.FormatInt(ComputingTime(orgTime, 5), 10)
|
|
d.Hours = strconv.FormatInt(ComputingTime(orgTime, 7), 10)
|
|
d.Minutes = strconv.FormatInt(ComputingTime(orgTime, 8), 10)
|
|
d.Second = strconv.FormatInt(ComputingTime(orgTime, 9), 10)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
func DateToTimeStampOld(dataStr string) (timeStamp int64) {
|
|
tmp := "2006-01-02 15:04:05"
|
|
res, _ := time.ParseInLocation(tmp, dataStr, time.Local)
|
|
timeStamp = res.Unix()
|
|
return
|
|
}
|
|
|
|
// 时间计算(年、季、月、周、日、时、分、秒)
|
|
func ComputingTime(timeStamp int64, timeType int) (timeDataInt int64) {
|
|
var timeData string = "1"
|
|
switch timeType {
|
|
case 1:
|
|
timeData = time.Unix(timeStamp, 0).Format("2006") //年
|
|
case 2:
|
|
dayMonth := time.Unix(timeStamp, 0).Format("01") //季度
|
|
datMonthFloat, datMonthFloatErr := strconv.ParseFloat(dayMonth, 10)
|
|
if datMonthFloatErr == nil {
|
|
timeData = strconv.FormatFloat(math.Ceil(datMonthFloat/3), 'f', -1, 64)
|
|
} else {
|
|
timeData = "1"
|
|
}
|
|
case 3:
|
|
timeData = time.Unix(timeStamp, 0).Format("01") //月份
|
|
case 4: //当前日期为本月第几周
|
|
monthFirstDayStr := DateToTimeStampOld(UnixTimeToDay(timeStamp, 15) + "-01 00:00:00") //获取指定月第一天时间戳
|
|
dayTime := time.Unix(monthFirstDayStr, 0)
|
|
dayOfWeek := int(dayTime.Weekday()) //获取本月第一天是周几
|
|
if dayOfWeek == 0 {
|
|
dayOfWeek = 7
|
|
}
|
|
|
|
dayNumber, dayNumberErr := strconv.ParseInt(UnixTimeToDay(timeStamp, 18), 10, 64) //获取今天是几号
|
|
if dayNumberErr != nil {
|
|
dayNumber = 1
|
|
}
|
|
daysAndWeeksDiff := dayNumber - (8 - int64(dayOfWeek))
|
|
if daysAndWeeksDiff <= 0 {
|
|
timeData = "1"
|
|
} else {
|
|
daysAndWeeksDiffFlot, daysAndWeeksDiffFloatErr := strconv.ParseFloat(strconv.FormatInt(daysAndWeeksDiff, 10), 10)
|
|
if daysAndWeeksDiffFloatErr == nil {
|
|
daysWeeksDiffVal := math.Ceil(daysAndWeeksDiffFlot/7) + 1
|
|
timeData = strconv.FormatFloat(daysWeeksDiffVal, 'f', -1, 64)
|
|
} else {
|
|
timeData = "1"
|
|
}
|
|
}
|
|
case 5:
|
|
timeData = time.Unix(timeStamp, 0).Format("02") //天
|
|
case 7:
|
|
timeData = time.Unix(timeStamp, 0).Format("15") //时
|
|
case 8:
|
|
timeData = time.Unix(timeStamp, 0).Format("04") //分
|
|
case 9:
|
|
timeData = time.Unix(timeStamp, 0).Format("05") //秒
|
|
default:
|
|
timeData = "0"
|
|
}
|
|
timeDataInt, timeDataIntErr := strconv.ParseInt(timeData, 10, 64)
|
|
if timeDataIntErr != nil {
|
|
timeDataInt = 0
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取指定月的起止时间副本
|
|
func GetAppointMonthStarAndEndTimeEs(dayTime string) (startTime, endTime int64) {
|
|
dataTypeAll := "2006-01-02"
|
|
firstToTime := StringToTimeIng("d", dayTime)
|
|
startTimeStr := fmt.Sprintf("%v 00:00:00", firstToTime.AddDate(0, 0, 0).Format(dataTypeAll))
|
|
endTimeStr := fmt.Sprintf("%v 23:59:59", firstToTime.AddDate(0, 1, -1).Format(dataTypeAll))
|
|
// startTime = dayTime
|
|
// fmt.Printf("获取指定月的起止时间副本--->%v--->%v\n", startTimeStr, endTimeStr)
|
|
startTime, _ = DateToTimeStamp(startTimeStr)
|
|
endTime, _ = DateToTimeStamp(endTimeStr)
|
|
return
|
|
}
|
|
|
|
// 日期字符串转换成time格式
|
|
func StringToTimeIng(unit, str string) (res time.Time) {
|
|
loc, _ := time.LoadLocation("Local")
|
|
// str := t.ToString()
|
|
layout, ok := timeLayoutMap[unit]
|
|
if !ok {
|
|
layout = timeLayoutMap["s"]
|
|
}
|
|
res, _ = time.ParseInLocation(layout, str, loc)
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-07-01 13:04:00
|
|
@ 功能: 获取当前登陆人信息
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func GetCreetUserCont(userKey string) (manCont models.ManCont, err error) {
|
|
redisFileKey := fmt.Sprintf("ScanCode:Authentication:LoginApi_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, userKey)
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS5)
|
|
userRedisToken, isTrue := redisClient.HashGetAll(redisFileKey)
|
|
if !isTrue {
|
|
return
|
|
}
|
|
manCont, err = GetUserRedisCont(userRedisToken["usernumber"])
|
|
return
|
|
}
|
|
|
|
// 获取人员Redis信息
|
|
func GetUserRedisCont(number string) (manCont models.ManCont, err error) {
|
|
redisMyContKey := fmt.Sprintf("ScanCode:Authentication:UserCont_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, number)
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS5)
|
|
useMap, isTrue := redisClient.HashGetAll(redisMyContKey)
|
|
if !isTrue {
|
|
errors.New("没有相关信息")
|
|
return
|
|
}
|
|
err = MapToStruct(useMap, &manCont, "json")
|
|
return
|
|
}
|
|
|
|
/*
|
|
map[string]string 转 struct
|
|
*/
|
|
func MapToStruct(mapString map[string]string, structInterface interface{}, tag string) (err error) {
|
|
strType := reflect.TypeOf(structInterface)
|
|
strValue := reflect.ValueOf(structInterface)
|
|
switch strType.Kind() {
|
|
case reflect.Ptr:
|
|
if strType.Elem().Kind() != reflect.Struct {
|
|
// fmt.Printf("1-->%v\n", strType.Elem().Kind().String())
|
|
return errors.New("需要*struct类型,却传入*" + strType.Elem().Kind().String() + "类型")
|
|
}
|
|
default:
|
|
// fmt.Printf("2-->%v\n", strType.Kind().String())
|
|
return errors.New("需要*struct类型,却传入" + strType.Kind().String() + "类型")
|
|
}
|
|
// fmt.Printf("strType--->%v---strValue---->%v\n", strType, strValue)
|
|
strTypeElem := strType.Elem()
|
|
strValueElem := strValue.Elem()
|
|
strTypeNum := strTypeElem.NumField()
|
|
// fmt.Printf("strTypeElem--->%v---strValueElem---->%v---------strTypeNum--------->%v\n", strTypeElem, strValueElem, strTypeNum)
|
|
for i := 0; i < strTypeNum; i++ {
|
|
fieldName := strTypeElem.Field(i).Name
|
|
if tag != "" {
|
|
fieldName = strTypeElem.Field(i).Tag.Get(tag)
|
|
}
|
|
value, ok := mapString[fieldName]
|
|
if !ok {
|
|
continue
|
|
}
|
|
// fmt.Printf("name--->%v---tag---->%v----value---->%v----ok---->%v\n", fieldName, tag, value, ok)
|
|
if strValueElem.Field(i).CanSet() {
|
|
// fmt.Printf("Type--->%v---value---->%v\n", strValueElem.Field(i).Type(), reflect.TypeOf(value))
|
|
valType := fmt.Sprintf("%v", strValueElem.Field(i).Type())
|
|
switch valType {
|
|
case "int":
|
|
valueInt, _ := strconv.Atoi(value)
|
|
strValueElem.Field(i).Set(reflect.ValueOf(valueInt))
|
|
case "int32":
|
|
valueInt32, _ := strconv.ParseInt(value, 10, 32)
|
|
strValueElem.Field(i).Set(reflect.ValueOf(int32(valueInt32)))
|
|
case "int64":
|
|
valueInt64, _ := strconv.ParseInt(value, 10, 64)
|
|
strValueElem.Field(i).Set(reflect.ValueOf(valueInt64))
|
|
case "float32":
|
|
valuefloat32, _ := strconv.ParseFloat(value, 32)
|
|
strValueElem.Field(i).Set(reflect.ValueOf(float32(valuefloat32)))
|
|
case "float64":
|
|
valuefloat64, _ := strconv.ParseFloat(value, 64)
|
|
strValueElem.Field(i).Set(reflect.ValueOf(valuefloat64))
|
|
case "string":
|
|
strValueElem.Field(i).Set(reflect.ValueOf(value))
|
|
default:
|
|
|
|
}
|
|
} else {
|
|
continue
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|