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.
3081 lines
87 KiB
3081 lines
87 KiB
package publicmethod
|
|
|
|
import (
|
|
"appPlatform/middleware/grocerystore"
|
|
"appPlatform/middleware/snowflake"
|
|
"appPlatform/models/modelAppPlatform"
|
|
"appPlatform/models/modelshr"
|
|
"appPlatform/models/modelsschool"
|
|
"appPlatform/models/modelsstorage"
|
|
"appPlatform/models/modelssystempermission"
|
|
"appPlatform/overall"
|
|
"bytes"
|
|
"crypto/md5"
|
|
"crypto/rand"
|
|
"crypto/sha1"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"math"
|
|
"math/big"
|
|
"reflect"
|
|
"sort"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/mozillazg/go-pinyin"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// 全局函数处理
|
|
// 时间相关处理类
|
|
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
|
|
}
|
|
|
|
// 获取UUID
|
|
func GetUUid(workId int64) (uuId int64) {
|
|
snowflakeId, snowflakeErr := snowflake.NewWorker(workId)
|
|
if snowflakeErr != nil {
|
|
uuId = TableNumber()
|
|
} else {
|
|
uuId = snowflakeId.GetId()
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取随机数
|
|
func GetRandNumber(max int) (num int64) {
|
|
maxVal := int64(math.Pow10(max)) - 1
|
|
minVal := int64(math.Pow10(max - 1))
|
|
|
|
// fmt.Printf("max:%v\nmaxVal:%v\nminVal:%v\n", max, maxVal, minVal)
|
|
if maxVal < 1 {
|
|
maxVal = 9
|
|
}
|
|
if minVal < 1 {
|
|
minVal = 1
|
|
}
|
|
result, _ := rand.Int(rand.Reader, big.NewInt(int64(maxVal)))
|
|
num = result.Int64() + int64(minVal)
|
|
return
|
|
}
|
|
|
|
// 初始化map(泛型)
|
|
func MapOut[T GenericityVariable]() (data map[T]interface{}) {
|
|
data = make(map[T]interface{}) //必可不少,分配内存
|
|
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)
|
|
} else {
|
|
dateStr = "1"
|
|
}
|
|
dateStr = "1"
|
|
// fmt.Printf("获取是电话卡-------------->%v------------>%v------------>%v\n", dateStr, datMonthFloat, datMonthFloatErr)
|
|
case 20:
|
|
timeTemplate = "20060102"
|
|
case 21:
|
|
timeTemplate = "200601"
|
|
case 22:
|
|
timeTemplate = "01-02"
|
|
case 23: //当前日期为本月第几周
|
|
monthFirstDayStr := DateToTimeStampOld(UnixTimeToDay(timeStamp, 10) + "-01 00:00:00") //获取指定月第一天时间戳
|
|
dayTime := time.Unix(monthFirstDayStr, 0)
|
|
dayOfWeek := int(dayTime.Weekday()) //获取本月第一天是周几
|
|
if dayOfWeek == 0 {
|
|
dayOfWeek = 7
|
|
}
|
|
|
|
dayNumber, dayNumberErr := strconv.ParseInt(UnixTimeToDay(timeStamp, 9), 10, 64) //获取今天是几号
|
|
if dayNumberErr != nil {
|
|
dayNumber = 1
|
|
}
|
|
daysAndWeeksDiff := dayNumber - (8 - int64(dayOfWeek))
|
|
if daysAndWeeksDiff <= 0 {
|
|
dateStr = "1"
|
|
} else {
|
|
daysAndWeeksDiffFlot, daysAndWeeksDiffFloatErr := strconv.ParseFloat(strconv.FormatInt(daysAndWeeksDiff, 10), 10)
|
|
if daysAndWeeksDiffFloatErr == nil {
|
|
daysWeeksDiffVal := math.Ceil(daysAndWeeksDiffFlot/7) + 1
|
|
dateStr = strconv.FormatFloat(daysWeeksDiffVal, 'f', -1, 64)
|
|
} else {
|
|
dateStr = "1"
|
|
}
|
|
}
|
|
case 24:
|
|
timeTemplate = "2006.01.02"
|
|
case 25:
|
|
timeTemplate = "2006.01"
|
|
case 26:
|
|
timeTemplate = "01.02"
|
|
case 27:
|
|
timeTemplate = "2006.01.02 15:04:05"
|
|
case 28:
|
|
timeTemplate = "2006012"
|
|
case 29:
|
|
timeTemplate = "200612"
|
|
case 30:
|
|
timeTemplate = "0612"
|
|
case 31:
|
|
timeTemplate = "20061"
|
|
case 32:
|
|
timeTemplate = "06"
|
|
case 33:
|
|
timeTemplate = "0612"
|
|
case 34:
|
|
timeTemplate = "061"
|
|
case 35:
|
|
timeTemplate = "0102"
|
|
case 36:
|
|
timeTemplate = "012"
|
|
case 37:
|
|
timeTemplate = "12"
|
|
case 38:
|
|
timeTemplate = "1"
|
|
case 39:
|
|
timeTemplate = "2"
|
|
case 40:
|
|
timeTemplate = "2006/01"
|
|
case 41: //当前年第几周
|
|
timeDay := TimeUnixToTime(timeStamp, "s")
|
|
year, week := timeDay.ISOWeek()
|
|
dateStr = fmt.Sprintf("%v年第%v周", year, week)
|
|
return dateStr
|
|
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 DateToTimeStampOld(dataStr string) (timeStamp int64) {
|
|
tmp := "2006-01-02 15:04:05"
|
|
res, _ := time.ParseInLocation(tmp, dataStr, time.Local)
|
|
timeStamp = res.Unix()
|
|
return
|
|
}
|
|
|
|
// 数据库查询翻页
|
|
func LimitPage(page, pageSize int) (offSet int) {
|
|
if page < 1 {
|
|
page = 1
|
|
}
|
|
offSet = pageSize * (page - 1)
|
|
if offSet < 0 {
|
|
offSet = 0
|
|
}
|
|
return
|
|
}
|
|
|
|
// 数据库查询翻页
|
|
func LimitPage64(page, pageSize int64) (offSet int64) {
|
|
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
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
/*
|
|
*加密算法
|
|
*/
|
|
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 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 Intersect[T GenericityVariable](a, b []T) []T {
|
|
inter := make([]T, 0)
|
|
mp := make(map[T]bool)
|
|
|
|
for _, s := range a {
|
|
if _, ok := mp[s]; !ok {
|
|
mp[s] = true
|
|
}
|
|
}
|
|
for _, s := range b {
|
|
if _, ok := mp[s]; ok {
|
|
inter = append(inter, s)
|
|
}
|
|
}
|
|
|
|
return inter
|
|
}
|
|
|
|
//判断类型转换成
|
|
/*
|
|
字符转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 valData := val.(type) {
|
|
case string:
|
|
return strconv.ParseInt(valData, 10, 64)
|
|
case int:
|
|
return int64(valData), nil
|
|
case int8:
|
|
return int64(valData), nil
|
|
case int16:
|
|
return int64(valData), nil
|
|
case int32:
|
|
return int64(valData), nil
|
|
case int64:
|
|
return valData, nil
|
|
case uint:
|
|
return int64(valData), nil
|
|
case uint8:
|
|
return int64(valData), nil
|
|
case uint16:
|
|
return int64(valData), nil
|
|
case uint32:
|
|
return int64(valData), nil
|
|
case uint64:
|
|
return int64(valData), nil
|
|
case float64:
|
|
val := strconv.FormatFloat(valData, 'f', -1, 64)
|
|
valInt, err := strconv.ParseInt(val, 10, 64)
|
|
return valInt, err
|
|
default:
|
|
return 0, nil
|
|
}
|
|
return 0, nil
|
|
}
|
|
|
|
// 获取人员TokenRedis 信息
|
|
func GetUserRedisToken(number string) (manCont modelshr.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 == false {
|
|
err.Error()
|
|
return
|
|
}
|
|
// fmt.Printf("%v\n", useMap)
|
|
err = MapToStruct(useMap, &manCont, "json")
|
|
return
|
|
}
|
|
|
|
// 获取人员Redis信息
|
|
func GetUserRedisCont(number string) (manCont modelshr.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 == false {
|
|
err.Error()
|
|
return
|
|
}
|
|
// fmt.Printf("%v\n", useMap)
|
|
// var manInfo models.ManCont
|
|
err = MapToStruct(useMap, &manCont, "json")
|
|
// manCont = manInfo
|
|
return
|
|
}
|
|
|
|
// 获取人员Redis信息返回指针
|
|
func GetUserRedisContPointer(number string) (manCont modelshr.ManCont, err error) {
|
|
redisMyContKey := fmt.Sprintf("ScanCode:Authentication:UserCont_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, number)
|
|
// fmt.Printf("redisMyContKey------------>%v\n", redisMyContKey)
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS5)
|
|
useMap, isTrue := redisClient.HashGetAll(redisMyContKey)
|
|
if isTrue == false {
|
|
err.Error()
|
|
return
|
|
}
|
|
// fmt.Printf("%v\n", useMap)
|
|
// var manInfo models.ManCont
|
|
err = MapToStruct(useMap, &manCont, "json")
|
|
// manCont = manInfo
|
|
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
|
|
}
|
|
|
|
// 翻页设置
|
|
func PageTurningSettings(gormDb *gorm.DB, page, pageSize int) *gorm.DB {
|
|
if page < 0 {
|
|
page = 1
|
|
}
|
|
if pageSize < 0 {
|
|
pageSize = 10
|
|
}
|
|
gormDb = gormDb.Limit(pageSize).Offset(LimitPage(page, pageSize))
|
|
return gormDb
|
|
}
|
|
|
|
//浮点数保留小数
|
|
/*
|
|
@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
|
|
}
|
|
|
|
// 递归查找
|
|
func RecursionOrgLeve(superior int64, leve int64) (groupId int64) {
|
|
if leve == 0 {
|
|
leve = 1
|
|
}
|
|
if superior == 0 {
|
|
return
|
|
}
|
|
var orgMap modelshr.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 GetOrgStructurees(orgId int64) (groupId, companyId, departmentId, sunDepartId, workShopId int64) {
|
|
if orgId == 0 {
|
|
return
|
|
}
|
|
var orgContTypeInfo modelshr.OrgContType
|
|
err := orgContTypeInfo.GetCont(map[string]interface{}{"`id`": orgId})
|
|
if err != nil {
|
|
return
|
|
}
|
|
switch orgContTypeInfo.Level {
|
|
case 1:
|
|
groupId = orgContTypeInfo.Id
|
|
case 2:
|
|
groupId = RecursionOrgLevees(orgId, orgContTypeInfo.Superior, 1)
|
|
workShopId = orgContTypeInfo.Id
|
|
case 3:
|
|
groupId = RecursionOrgLevees(orgId, orgContTypeInfo.Superior, 2)
|
|
companyId = orgContTypeInfo.Id
|
|
case 4:
|
|
groupId = RecursionOrgLevees(orgId, orgContTypeInfo.Superior, 2)
|
|
companyId = RecursionOrgLevees(orgId, orgContTypeInfo.Superior, 3)
|
|
departmentId = orgContTypeInfo.Id
|
|
case 5:
|
|
groupId = RecursionOrgLevees(orgId, orgContTypeInfo.Superior, 2)
|
|
companyId = RecursionOrgLevees(orgId, orgContTypeInfo.Superior, 3)
|
|
departmentId = RecursionOrgLevees(orgId, orgContTypeInfo.Superior, 4)
|
|
sunDepartId = orgContTypeInfo.Id
|
|
case 6:
|
|
groupId = RecursionOrgLevees(orgId, orgContTypeInfo.Superior, 2)
|
|
companyId = RecursionOrgLevees(orgId, orgContTypeInfo.Superior, 3)
|
|
departmentId = RecursionOrgLevees(orgId, orgContTypeInfo.Superior, 4)
|
|
sunDepartId = RecursionOrgLevees(orgId, orgContTypeInfo.Superior, 5)
|
|
workShopId = orgContTypeInfo.Id
|
|
default:
|
|
groupId = orgContTypeInfo.Id
|
|
companyId = orgContTypeInfo.Id
|
|
workShopId = orgContTypeInfo.Id
|
|
}
|
|
return
|
|
}
|
|
|
|
func RecursionOrgLevees(oldId, superior int64, leve int64) (groupId int64) {
|
|
if leve == 0 {
|
|
leve = 1
|
|
}
|
|
if superior == 0 {
|
|
return
|
|
}
|
|
var orgMap modelshr.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 modelshr.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 {
|
|
return
|
|
}
|
|
var orgAry []modelshr.AdministrativeOrganization
|
|
err := overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Select("`id`").Where("`state` = 1 AND `superior` = ?", superior).Find(&orgAry).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, v := range orgAry {
|
|
if IsInTrue[int64](v.Id, orgIdAry) == false {
|
|
orgIdAry = append(orgIdAry, v.Id)
|
|
GetDepartmentSun(v.Id, orgIdAry)
|
|
} else {
|
|
GetDepartmentSun(v.Id, orgIdAry)
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取集团或第一实权部门
|
|
func GetGroupOrDepartPower(parentId int64, departId ...int64) int64 {
|
|
if parentId == 0 {
|
|
return 0
|
|
}
|
|
var orgCont modelshr.AdministrativeOrganization
|
|
err := orgCont.GetCont(map[string]interface{}{"id": parentId}, "id", "organization_type", "superior", "ispower")
|
|
if err != nil {
|
|
return parentId
|
|
}
|
|
if len(departId) > 0 {
|
|
if orgCont.IsPower == 1 {
|
|
return orgCont.Id
|
|
}
|
|
return GetGroupOrDepartPower(orgCont.Superior, 1)
|
|
} else {
|
|
if orgCont.OrganizationType <= 2 {
|
|
return orgCont.Id
|
|
}
|
|
return GetGroupOrDepartPower(orgCont.Superior)
|
|
}
|
|
return orgCont.Id
|
|
}
|
|
|
|
// 判断指定日期是周几
|
|
func GetWeekday(date string) (string, error) {
|
|
layout := "2006-01-02"
|
|
t, err := time.Parse(layout, date)
|
|
if err != nil {
|
|
return fmt.Sprintf("%v", time.Sunday), err
|
|
}
|
|
dayOfWeek := t.Weekday()
|
|
|
|
var weekdays = [...]string{
|
|
"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六",
|
|
}
|
|
|
|
return fmt.Sprintf(weekdays[dayOfWeek]), nil
|
|
}
|
|
|
|
// 时间计算(年、季、月、周、日、时、分、秒)
|
|
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
|
|
}
|
|
|
|
/*
|
|
获取岗位权限
|
|
@ordid 行政组织
|
|
@postid 岗位
|
|
@system 系统标识
|
|
*/
|
|
func GetPostPower(ordid, postid int64, system string) (menuIdAry, menuUrl []string, err error) {
|
|
redisFileEmpowerKey := fmt.Sprintf("ScanCode:SystemEmpower:Authorize_%v_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, system, postid)
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS5)
|
|
empowerRedisToken, isTrue := redisClient.HashGetAll(redisFileEmpowerKey)
|
|
// fmt.Printf("empowerRedisToken------------->%v---------->isTrue------------->%v---------->redisFileEmpowerKey------------->%v\n", empowerRedisToken, isTrue, redisFileEmpowerKey)
|
|
if isTrue == false {
|
|
fmt.Printf("GetPostPower-1-->%v\n", empowerRedisToken["menuid"])
|
|
menuIdAry, menuUrl, err = readMenuList(postid, system)
|
|
writeRedisData := MapOut[string]()
|
|
writeRedisData["menuid"] = strings.Join(menuIdAry, ",")
|
|
writeRedisData["menuurl"] = strings.Join(menuUrl, "|_^_|")
|
|
redisClient.SetRedisTime(10800)
|
|
redisClient.HashMsetAdd(redisFileEmpowerKey, writeRedisData)
|
|
} else {
|
|
// fmt.Printf("GetPostPower-2-->%v\n", empowerRedisToken["menuid"])
|
|
menuIdAry = strings.Split(empowerRedisToken["menuid"], ",")
|
|
menuUrl = strings.Split(empowerRedisToken["menuurl"], "|_^_|")
|
|
// fmt.Printf("GetPostPower-3-->%v-->%v\n", len(menuIdAry), menuIdAry)
|
|
if len(menuIdAry) <= 1 {
|
|
menuIdAry, menuUrl, err = readMenuList(postid, system)
|
|
writeRedisData := MapOut[string]()
|
|
writeRedisData["menuid"] = strings.Join(menuIdAry, ",")
|
|
writeRedisData["menuurl"] = strings.Join(menuUrl, "|_^_|")
|
|
redisClient.SetRedisTime(10800)
|
|
redisClient.HashMsetAdd(redisFileEmpowerKey, writeRedisData)
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
/*
|
|
读取菜单
|
|
*/
|
|
func readMenuList(postid int64, system string) (menuIdAry, menuUrl []string, err error) {
|
|
var ponitId string
|
|
err = overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.Empower{}).Select("`point_id`").Where("`state` = 1 AND `post_id` = ? AND `system` = ?", postid, system).Find(&ponitId).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
menuIdAry = strings.Split(ponitId, ",")
|
|
if len(menuIdAry) < 1 {
|
|
return
|
|
}
|
|
switch system {
|
|
case "cangchu":
|
|
menuUrl, err = getStorageSystemEmpower(menuIdAry)
|
|
default:
|
|
//绩效考核系统
|
|
menuUrl, err = getKpiSystemEmpower(menuIdAry)
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
获取绩效考核系统授权菜单
|
|
@menuIdAry 菜单ID
|
|
*/
|
|
func getKpiSystemEmpower(menuIdAry []string) (menuUrl []string, err error) {
|
|
if len(menuIdAry) < 1 {
|
|
return
|
|
}
|
|
var empowerMenuUrl []string
|
|
err = overall.CONSTANT_DB_Master.Model(&modelsschool.SystemMenuSchool{}).Distinct("`m_url`").Where("`m_steat` = 1 AND `m_id` IN ?", menuIdAry).Find(&empowerMenuUrl).Error
|
|
if err != nil || len(empowerMenuUrl) < 1 {
|
|
return
|
|
}
|
|
for i := 0; i < len(empowerMenuUrl); i++ {
|
|
if empowerMenuUrl[i] != "#" && IsInTrue[string](empowerMenuUrl[i], menuUrl) == false {
|
|
menuUrl = append(menuUrl, empowerMenuUrl[i])
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
获取仓储考核系统授权菜单
|
|
@menuIdAry 菜单ID
|
|
*/
|
|
func getStorageSystemEmpower(menuIdAry []string) (menuUrl []string, err error) {
|
|
if len(menuIdAry) < 1 {
|
|
return
|
|
}
|
|
var empowerMenuUrl []string
|
|
err = overall.CONSTANT_DB_Storage.Model(&modelsstorage.AccesstoAddress{}).Distinct("`url`").Where("`state` = 1 AND `id` IN ?", menuIdAry).Find(&empowerMenuUrl).Error
|
|
if err != nil || len(empowerMenuUrl) < 1 {
|
|
return
|
|
}
|
|
// fmt.Printf("empowerMenuUrl---------->%v\n", empowerMenuUrl)
|
|
for i := 0; i < len(empowerMenuUrl); i++ {
|
|
if empowerMenuUrl[i] != "#" && empowerMenuUrl[i] != "" && IsInTrue[string](empowerMenuUrl[i], menuUrl) == false {
|
|
menuUrl = append(menuUrl, empowerMenuUrl[i])
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取公司最小主责部门
|
|
func GetMinMainDutyDeparment(company string) (organization []modelshr.AdministrativeOrganization) {
|
|
if company == "" {
|
|
return
|
|
}
|
|
var allOrg []modelshr.AdministrativeOrganization
|
|
err := overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Where("ispower = 1 AND state = 1 AND organization_type > 2 AND superior = ?", company).Find(&allOrg).Error
|
|
if err != nil || len(allOrg) < 1 {
|
|
return
|
|
}
|
|
for _, v := range allOrg {
|
|
sunOrgList, orgSunErr := GetSunOrgList(v.Id)
|
|
if orgSunErr == nil && len(sunOrgList) > 0 {
|
|
for _, sv := range sunOrgList {
|
|
organization = append(organization, sv)
|
|
}
|
|
} else {
|
|
organization = append(organization, v)
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取下级行政组织是否有主行政部门
|
|
func GetSunOrgList(orgId int64) (orgList []modelshr.AdministrativeOrganization, ovErr error) {
|
|
if orgId == 0 {
|
|
return
|
|
}
|
|
ovErr = overall.CONSTANT_DB_HR.Where("state = 1").Where("ispower = 1 AND superior = ?", orgId).Find(&orgList).Error
|
|
return
|
|
}
|
|
|
|
// 递归无限极菜单树
|
|
func GetMenuThree(jurisd int, parentId string, threeData []MenuContList) []PowerThree {
|
|
treeList := []PowerThree{}
|
|
for _, v := range threeData {
|
|
if v.ParentId == parentId {
|
|
child := GetMenuThree(jurisd, v.Id, threeData)
|
|
var node PowerThree
|
|
node.Id = v.Id
|
|
node.Name = v.Name
|
|
node.ParentId = v.ParentId
|
|
node.IsTrue = v.IsTrue
|
|
isTrue, menuOper := MenuOperation(jurisd, v.Id)
|
|
if isTrue == true {
|
|
node.MenuOperation = menuOper
|
|
// fmt.Printf("GetMenuThree-1111--%v--->%v\n", v.Id, menuOper)
|
|
}
|
|
node.Child = child
|
|
treeList = append(treeList, node)
|
|
}
|
|
}
|
|
return treeList
|
|
}
|
|
|
|
// 获取菜单操作项目
|
|
func MenuOperation(jurisd int, menuId string) (isTrue bool, operation []MenuContList) {
|
|
var operList []modelsschool.MenuOperation
|
|
isTrue = false
|
|
operErr := overall.CONSTANT_DB_Master.Where("`menu_id` = ?", menuId).Order("oper_id desc").Find(&operList).Error
|
|
if operErr != nil || len(operList) < 1 {
|
|
return
|
|
}
|
|
|
|
isTrue = true
|
|
for i := 0; i < len(operList); i++ {
|
|
var menSmaiCont MenuContList
|
|
menSmaiCont.Id = strconv.FormatInt(operList[i].OperId, 10)
|
|
menSmaiCont.Name = operList[i].OperTitle
|
|
menSmaiCont.ParentId = strconv.FormatInt(operList[i].MenuId, 10)
|
|
operation = append(operation, menSmaiCont)
|
|
}
|
|
// fmt.Printf("ApiUrl---%v--->%v--->%v--->%v\n", menuId, isTrue, operErr, operList)
|
|
return
|
|
}
|
|
|
|
/*
|
|
递归无限极菜单树
|
|
*/
|
|
func GetMenuThrees(jurisd int, parentId string, threeData []MenuContList) []PowerThree {
|
|
treeList := []PowerThree{}
|
|
for _, v := range threeData {
|
|
if v.ParentId == parentId {
|
|
child := GetMenuThrees(jurisd, v.Id, threeData)
|
|
var node PowerThree
|
|
node.Id = v.Id
|
|
node.Name = v.Name
|
|
node.ParentId = v.ParentId
|
|
node.Child = child
|
|
node.IsTrue = v.IsTrue
|
|
// fmt.Printf("GetMenuThree-22222--%v--->%v\n", v.Id, node)
|
|
treeList = append(treeList, node)
|
|
}
|
|
}
|
|
return treeList
|
|
}
|
|
|
|
// 获取责任人
|
|
func GetDepartmentLeader(userCont modelshr.PersonArchives) {
|
|
var orgContList []DepartmentIsPower
|
|
orgContList = GetAllFatherDeparment(userCont.AdminOrg, 1, orgContList)
|
|
//根据序号排序
|
|
sort.Slice(orgContList, func(i, j int) bool {
|
|
return orgContList[i].Sort < orgContList[j].Sort
|
|
})
|
|
jsonStr, _ := json.Marshal(orgContList)
|
|
fmt.Printf("orgList---------------->%v\n", string(jsonStr))
|
|
}
|
|
|
|
// 获取行政组织的所有上级实权部门
|
|
func GetAllFatherDeparment(orgId int64, sort int, oldCont []DepartmentIsPower) (orgContList []DepartmentIsPower) {
|
|
if orgId == 0 {
|
|
return
|
|
}
|
|
var orgCont modelshr.AdministrativeOrganization
|
|
err := orgCont.GetCont(map[string]interface{}{"id": orgId}, "id", "name", "organization_type", "superior", "ispower")
|
|
if err != nil {
|
|
return
|
|
}
|
|
if orgCont.OrganizationType <= 2 {
|
|
orgContList = oldCont
|
|
// jsonStr, _ := json.Marshal(oldCont)
|
|
// fmt.Printf("oldCont---------------->%v\n", string(jsonStr))
|
|
return
|
|
} else {
|
|
// jsonStr, _ := json.Marshal(oldCont)
|
|
// fmt.Printf("oldCont---------------->%v\n", string(jsonStr))
|
|
|
|
if orgCont.IsPower == 1 {
|
|
var orgListCont DepartmentIsPower
|
|
orgListCont.Id = strconv.FormatInt(orgCont.Id, 10)
|
|
orgListCont.Name = orgCont.Name
|
|
orgListCont.Superior = orgCont.Superior
|
|
orgListCont.OrganizationType = orgCont.OrganizationType
|
|
orgListCont.IsPower = orgCont.IsPower
|
|
orgListCont.Sort = sort
|
|
orgListCont.PowerPeople = GetDutyOrgAbourLeader(orgCont.Id)
|
|
oldCont = append(oldCont, orgListCont)
|
|
orgContList = oldCont
|
|
sort = sort + 1
|
|
}
|
|
return GetAllFatherDeparment(orgCont.Superior, sort, oldCont)
|
|
}
|
|
|
|
return orgContList
|
|
}
|
|
|
|
/*
|
|
获取主权行政组织责任岗位及相关人员
|
|
@ordId 行政组织ID
|
|
*/
|
|
func GetDutyOrgAbourLeader(ordId int64) (postAboutPeople []DepartSoverePostMan) {
|
|
//获取负责人岗位
|
|
var leaderPostList []modelshr.Position
|
|
err := overall.CONSTANT_DB_HR.Model(&modelshr.Position{}).Select("`id`,`name`").Where("`state` = 1 AND `person_in_charge` = 1 AND `administrative_organization` = ?", ordId).Find(&leaderPostList).Error
|
|
if err != nil || len(leaderPostList) < 1 {
|
|
return
|
|
}
|
|
var isIn []int64
|
|
for _, v := range leaderPostList {
|
|
if IsInTrue[int64](v.Id, isIn) == false { //岗位
|
|
var postAboutManCont DepartSoverePostMan
|
|
postAboutManCont.Id = strconv.FormatInt(v.Id, 10)
|
|
postAboutManCont.Name = v.Name
|
|
postAboutManCont.People = GetManInPostList(ordId, v.Id)
|
|
postAboutPeople = append(postAboutPeople, postAboutManCont)
|
|
}
|
|
}
|
|
return postAboutPeople
|
|
}
|
|
|
|
/*
|
|
获取岗位中的人及其职务
|
|
@ordId 行政组织ID
|
|
@postId 岗位ID
|
|
*/
|
|
func GetManInPostList(ordId, postId int64) (peopleList []PeopleSoverePostMan) {
|
|
//获取相关行政组织岗位的人员列表
|
|
var usList []modelshr.PersonArchives
|
|
err := overall.CONSTANT_DB_HR.Model(&modelshr.PersonArchives{}).Select("`id`,`number`,`name`,`job_id`").Where("`state` = 1 AND `admin_org` = ? AND `position` = ? AND `emp_type` IN ?", ordId, postId, overall.EmployeeStatusIng).Find(&usList).Error
|
|
if err != nil || len(usList) < 1 {
|
|
return
|
|
}
|
|
for _, v := range usList {
|
|
var peopleCont PeopleSoverePostMan
|
|
peopleCont.Id = strconv.FormatInt(v.Id, 10)
|
|
peopleCont.Number = v.Number
|
|
peopleCont.Name = v.Name
|
|
var duitesCont modelshr.Duties
|
|
duitesCont.GetCont(map[string]interface{}{"`id`": v.JobId}, "`id`", "`name`")
|
|
peopleCont.PostId = strconv.FormatInt(duitesCont.Id, 10)
|
|
peopleCont.PostName = duitesCont.Name
|
|
peopleList = append(peopleList, peopleCont)
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
获取上级审批
|
|
@userKey 用户KEy
|
|
@ordId 行政组织ID
|
|
@postId 岗位ID
|
|
@sort 排序
|
|
@contList 审批人列表
|
|
*/
|
|
func GetPositionList(userKey, ordId, postId int64, sort int, contList []PositionDigui) (listCont []PositionDigui) {
|
|
var positionCont modelshr.PostDutiesJob
|
|
err := positionCont.GetCont(map[string]interface{}{"`id`": postId})
|
|
if err != nil {
|
|
return
|
|
}
|
|
jsonStr, _ := json.Marshal(positionCont)
|
|
fmt.Printf("positionCont---------------->%v\n", string(jsonStr))
|
|
if positionCont.JobType < 2 {
|
|
listCont = contList
|
|
return
|
|
} else {
|
|
|
|
if positionCont.PersonInCharge == 1 {
|
|
peopelAry := GetPeopleInPostList(userKey, positionCont.AdministrativeOrganization, positionCont.Id)
|
|
if len(peopelAry) > 0 {
|
|
var cont PositionDigui
|
|
cont.Id = strconv.FormatInt(positionCont.Id, 10)
|
|
cont.Name = positionCont.Name
|
|
cont.OrgId = strconv.FormatInt(positionCont.AdministrativeOrganization, 10)
|
|
cont.Superior = strconv.FormatInt(positionCont.Superior, 10)
|
|
cont.Sort = sort
|
|
cont.People = peopelAry
|
|
contList = append(contList, cont)
|
|
}
|
|
listCont = contList
|
|
return GetPositionList(userKey, positionCont.AdministrativeOrganization, positionCont.Superior, sort+1, contList)
|
|
} else {
|
|
return GetPositionList(userKey, positionCont.AdministrativeOrganization, positionCont.Superior, sort+1, contList)
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
/*
|
|
获取岗位下人员列表
|
|
@userKey 用户KEy
|
|
@ordId 行政组织ID
|
|
@postId 岗位ID
|
|
*/
|
|
func GetPeopleInPostList(userKey, ordId, postId int64) (peopleList []PostPeople) {
|
|
isTrue := false
|
|
//获取相关行政组织岗位的人员列表
|
|
var usList []modelshr.PersonArchives
|
|
err := overall.CONSTANT_DB_HR.Model(&modelshr.PersonArchives{}).Select("`id`,`key`,`number`,`name`,`job_id`,`wechat`,`work_wechat`,`company`,`maindeparment`,`admin_org`,`job_id`").Where("`state` = 1 AND `admin_org` = ? AND `position` = ? AND `emp_type` IN ?", ordId, postId, overall.EmployeeStatusIng).Find(&usList).Error
|
|
if err != nil || len(usList) < 1 {
|
|
return
|
|
}
|
|
for _, v := range usList {
|
|
if v.Key == userKey {
|
|
isTrue = true
|
|
}
|
|
wechatStr := v.Wechat
|
|
if v.WorkWechat != "" {
|
|
wechatStr = v.WorkWechat
|
|
}
|
|
if wechatStr != "" {
|
|
var peopleCont PostPeople
|
|
peopleCont.Id = strconv.FormatInt(v.Id, 10)
|
|
peopleCont.Number = v.Number
|
|
peopleCont.Name = v.Name
|
|
|
|
peopleCont.Company = strconv.FormatInt(v.Company, 10)
|
|
if v.Company != 0 {
|
|
var companyCont modelshr.AdministrativeOrganization
|
|
companyCont.GetCont(map[string]interface{}{"`id`": v.Company}, "`name`")
|
|
peopleCont.CompanyName = companyCont.Name
|
|
}
|
|
|
|
if v.MainDeparment != 0 {
|
|
departmentId := GetGroupOrDepartPower(v.AdminOrg, 1)
|
|
peopleCont.Department = strconv.FormatInt(departmentId, 10)
|
|
var departCont modelshr.AdministrativeOrganization
|
|
departCont.GetCont(map[string]interface{}{"`id`": departmentId}, "`name`")
|
|
peopleCont.DepartmentName = departCont.Name
|
|
}
|
|
|
|
peopleCont.OrgId = strconv.FormatInt(v.AdminOrg, 10)
|
|
if v.AdminOrg != 0 {
|
|
var orgCont modelshr.AdministrativeOrganization
|
|
orgCont.GetCont(map[string]interface{}{"`id`": v.AdminOrg}, "`name`")
|
|
peopleCont.OrgName = orgCont.Name
|
|
}
|
|
|
|
var duitesCont modelshr.Duties
|
|
duitesCont.GetCont(map[string]interface{}{"`id`": v.JobId}, "`id`", "`name`")
|
|
peopleCont.DutiesId = strconv.FormatInt(duitesCont.Id, 10)
|
|
peopleCont.DutiesName = duitesCont.Name
|
|
peopleCont.Wechat = wechatStr
|
|
peopleList = append(peopleList, peopleCont)
|
|
}
|
|
|
|
}
|
|
fmt.Printf("%v\n", isTrue)
|
|
// if isTrue == true {
|
|
// var emptyAry []PostPeople
|
|
// peopleList = emptyAry
|
|
// }
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2022-11-19 15:01:33
|
|
@ 功能: 获取岗位权限信息
|
|
@ 参数
|
|
|
|
#orgId 行政组织
|
|
#postId 岗位
|
|
#systemName 系统
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func GetPostOfUsEmpowerCont(orgId, postId int64, systemName string) (sysPowerCont SystemPowerInfo, err error) {
|
|
|
|
redisFileKey := fmt.Sprintf("Licence:LoginApi_%v_%v_%v", systemName, orgId, postId)
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS3)
|
|
userRedisToken, isTrue := redisClient.HashGetAll(redisFileKey)
|
|
if isTrue == false {
|
|
var systemPowerCont modelssystempermission.Empower
|
|
err = systemPowerCont.GetCont(map[string]interface{}{"`ordid`": orgId, "`post_id`": postId, "`system`": systemName})
|
|
if err != nil {
|
|
return
|
|
}
|
|
sysPowerCont.Id = systemPowerCont.Id
|
|
sysPowerCont.OrdId = systemPowerCont.OrdId //行政组织"`
|
|
sysPowerCont.PostId = systemPowerCont.PostId //岗位ID"`
|
|
sysPowerCont.System = systemPowerCont.System //系统"`
|
|
sysPowerCont.PointId = systemPowerCont.PointId //权限点位"`
|
|
sysPowerCont.State = systemPowerCont.State //状态(1:启用;2:禁用;3:删除)"`
|
|
sysPowerCont.Time = systemPowerCont.Time //创建时间"`
|
|
sysPowerCont.Level = systemPowerCont.Level //授权范围等级(1:本部门;2:本分部;3:所有)"`
|
|
sysPowerCont.Organization = systemPowerCont.Organization //行政组织"`
|
|
sysPowerCont.PointIdList = strings.Split(systemPowerCont.PointId, ",")
|
|
sysPowerCont.OrganizationList = strings.Split(systemPowerCont.Organization, ",")
|
|
|
|
myContRedis := MapOut[string]()
|
|
myContRedis["id"] = systemPowerCont.Id
|
|
myContRedis["ordid"] = systemPowerCont.OrdId
|
|
myContRedis["postid"] = systemPowerCont.PostId
|
|
myContRedis["system"] = systemPowerCont.System
|
|
myContRedis["pointid"] = systemPowerCont.PointId
|
|
myContRedis["state"] = systemPowerCont.State
|
|
myContRedis["time"] = systemPowerCont.Time
|
|
myContRedis["level"] = systemPowerCont.Level
|
|
myContRedis["organization"] = systemPowerCont.Organization
|
|
|
|
redisClient.SetRedisTime(10800)
|
|
redisClient.HashMsetAdd(redisFileKey, myContRedis)
|
|
} else {
|
|
idInt, _ := strconv.ParseInt(userRedisToken["id"], 10, 64)
|
|
sysPowerCont.Id = idInt
|
|
orgIdInt, _ := strconv.ParseInt(userRedisToken["ordid"], 10, 64)
|
|
sysPowerCont.OrdId = orgIdInt //行政组织"`
|
|
postIdInt, _ := strconv.ParseInt(userRedisToken["postid"], 10, 64)
|
|
sysPowerCont.PostId = postIdInt //岗位ID"`
|
|
sysPowerCont.System = userRedisToken["system"] //系统"`
|
|
sysPowerCont.PointId = userRedisToken["pointid"] //权限点位"`
|
|
stateInt, _ := strconv.Atoi(userRedisToken["state"])
|
|
sysPowerCont.State = stateInt //状态(1:启用;2:禁用;3:删除)"`
|
|
timeInt, _ := strconv.ParseInt(userRedisToken["time"], 10, 64)
|
|
sysPowerCont.Time = timeInt //创建时间"`
|
|
levelInt, _ := strconv.Atoi(userRedisToken["level"])
|
|
sysPowerCont.Level = levelInt //授权范围等级(1:本部门;2:本分部;3:所有)"`
|
|
sysPowerCont.Organization = userRedisToken["organization"] //行政组织"`
|
|
sysPowerCont.PointIdList = strings.Split(userRedisToken["pointid"], ",")
|
|
sysPowerCont.OrganizationList = strings.Split(userRedisToken["organization"], ",")
|
|
writeRedisData := MapOut[string]()
|
|
for i, v := range userRedisToken {
|
|
writeRedisData[i] = v
|
|
}
|
|
redisClient.SetRedisTime(10800)
|
|
redisClient.HashMsetAdd(redisFileKey, writeRedisData)
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2022-11-19 15:03:42
|
|
@ 功能: 获取系统授权
|
|
@ 参数
|
|
|
|
#roleId 角色ID
|
|
#systemName 系统名称
|
|
#userKey 人员识别码
|
|
#orgId 行政组织
|
|
#postId 岗位
|
|
|
|
@ 返回值
|
|
|
|
#roleName 角色名称
|
|
#pointId 菜单权限
|
|
#operation 操作权限
|
|
#level 操作等级
|
|
|
|
@ 方法原型
|
|
|
|
#func GetNewAccredit(systemName, roleId string, userKey, orgId, postId int64) (roleName, pointId, operation string, level int)
|
|
*/
|
|
func GetNewAccredit(systemName, roleId string, userKey, orgId, postId int64) (roleName, pointId, operation string, level int) {
|
|
// fmt.Printf("jsonStr---1--->%v---->%v---->%v---->%v---->%v\n", systemName, roleId, userKey, orgId, postId)
|
|
redisFileKey := fmt.Sprintf("Licence:PowerLoginApi_%v_%v_%v_%v", systemName, userKey, orgId, postId)
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS3)
|
|
userRedisToken, isTrue := redisClient.HashGetAll(redisFileKey)
|
|
// fmt.Printf("jsonStr---2--->%v---->%v---->%v---->%v---->%v---->%v\n", systemName, roleId, userKey, orgId, postId, userRedisToken)
|
|
if isTrue == false {
|
|
|
|
var pointIdAry []string
|
|
var operationAry []string
|
|
if roleId != "" {
|
|
roleIdAry := strings.Split(roleId, ",")
|
|
var roleCont []modelssystempermission.SystemRole
|
|
if len(roleIdAry) > 0 {
|
|
//获取角色名称
|
|
err := overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.SystemRole{}).Select("`name`").Where("`id` IN ?", roleIdAry).Find(&roleCont).Error
|
|
if err == nil && len(roleCont) > 0 {
|
|
var roleNameAry []string
|
|
for _, rnv := range roleCont {
|
|
if IsInTrue[string](rnv.Name, roleNameAry) == false {
|
|
roleNameAry = append(roleNameAry, rnv.Name)
|
|
}
|
|
}
|
|
roleName = strings.Join(roleNameAry, "|")
|
|
}
|
|
//获取配置的所有角色权限
|
|
var roleEmpowerCont []modelssystempermission.RoleEmpower
|
|
err = overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.RoleEmpower{}).Select("`point_id`,`operation`,`level`").Where("`system` = ? AND `role_id` IN ?", systemName, roleIdAry).Find(&roleEmpowerCont).Error
|
|
if err == nil && len(roleEmpowerCont) > 0 {
|
|
for _, rev := range roleEmpowerCont {
|
|
menuList := strings.Split(rev.PointId, ",")
|
|
for _, mv := range menuList { //菜单权限
|
|
if mv != "" && IsInTrue[string](mv, pointIdAry) == false {
|
|
pointIdAry = append(pointIdAry, mv)
|
|
}
|
|
}
|
|
operList := strings.Split(rev.Operation, ",")
|
|
for _, ov := range operList { //操作权限
|
|
if ov != "" && IsInTrue[string](ov, operationAry) == false {
|
|
operationAry = append(operationAry, ov)
|
|
}
|
|
}
|
|
if level < rev.Level {
|
|
level = rev.Level //等级
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//获取行政组织授权
|
|
if orgId > 0 && postId > 0 {
|
|
var orgEmpowerCont modelssystempermission.Empower
|
|
orgEmpowerCont.GetCont(map[string]interface{}{"`ordid`": orgId, "`post_id`": postId, "`system`": systemName}, "`point_id`", "`operation`", "`level`")
|
|
if len(pointIdAry) < 1 { //判断是否已经配过权限
|
|
pointIdAry = strings.Split(orgEmpowerCont.PointId, ",")
|
|
} else {
|
|
guoduPoin := strings.Split(orgEmpowerCont.PointId, ",")
|
|
for _, pv := range guoduPoin { //合并权限
|
|
if pv != "" && IsInTrue[string](pv, pointIdAry) == false {
|
|
pointIdAry = append(pointIdAry, pv)
|
|
}
|
|
}
|
|
|
|
}
|
|
if len(operationAry) < 1 { //判断是否已经配过权限
|
|
operationAry = strings.Split(orgEmpowerCont.Operation, ",")
|
|
} else {
|
|
guoduOper := strings.Split(orgEmpowerCont.Operation, ",")
|
|
for _, gpv := range guoduOper { //合并权限
|
|
if gpv != "" && IsInTrue[string](gpv, operationAry) == false {
|
|
operationAry = append(operationAry, gpv)
|
|
}
|
|
}
|
|
|
|
}
|
|
if level < orgEmpowerCont.Level {
|
|
level = orgEmpowerCont.Level
|
|
}
|
|
}
|
|
pointId = strings.Join(pointIdAry, ",")
|
|
operation = strings.Join(operationAry, ",")
|
|
|
|
var powerCont EmpowerCont
|
|
powerCont.RoleName = roleName
|
|
powerCont.PointId = pointId
|
|
powerCont.Operation = operation
|
|
powerCont.Level = level
|
|
//组转写入redis
|
|
myContRedis := MapOut[string]()
|
|
myContRedis["roleName"] = roleName
|
|
myContRedis["pointid"] = pointId
|
|
myContRedis["operation"] = operation
|
|
myContRedis["level"] = level
|
|
redisClient.SetRedisTime(10800)
|
|
redisClient.HashMsetAdd(redisFileKey, myContRedis)
|
|
|
|
} else {
|
|
roleName = userRedisToken["roleName"]
|
|
pointId = userRedisToken["pointid"]
|
|
operation = userRedisToken["operation"]
|
|
level, _ = strconv.Atoi(userRedisToken["level"])
|
|
//组转写入redis
|
|
writeRedisData := MapOut[string]()
|
|
for i, v := range userRedisToken {
|
|
writeRedisData[i] = v
|
|
}
|
|
redisClient.SetRedisTime(10800)
|
|
redisClient.HashMsetAdd(redisFileKey, writeRedisData)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 步骤名称
|
|
func GetSetpName(setId int) (setpName string) {
|
|
switch setId {
|
|
case 1:
|
|
setpName = "创建申请"
|
|
case 2:
|
|
setpName = "审核"
|
|
case 3:
|
|
setpName = "责任划分"
|
|
case 4:
|
|
setpName = "整改措施"
|
|
case 5:
|
|
setpName = "整改验收"
|
|
case 6:
|
|
setpName = "抄送"
|
|
case 7:
|
|
// setpName = "部门负责人"
|
|
setpName = "审核确认"
|
|
default:
|
|
setpName = "创建申请"
|
|
}
|
|
return
|
|
}
|
|
|
|
// 步骤名称/节点类型 0:发起人;1:审批;2:抄送;3:执行节点;4:路由;5:条件;
|
|
func GetSetpNodeName(setId int) (setpName string) {
|
|
switch setId {
|
|
case 1:
|
|
setpName = "审核"
|
|
case 2:
|
|
setpName = "抄送"
|
|
case 3:
|
|
setpName = "执行"
|
|
case 4:
|
|
setpName = "路由"
|
|
case 5:
|
|
setpName = "条件条件"
|
|
default:
|
|
setpName = "发起申请"
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2022-10-01 10:44:41
|
|
@ 功能: 获取企业微信审批组相关负责人
|
|
@ 参数
|
|
|
|
#wechatTeamId 审批数据库节点ID
|
|
#departmentId 部门ID
|
|
|
|
@ 返回值
|
|
|
|
#userStrList 微信Openid
|
|
#err cuo
|
|
*/
|
|
func GetRefereeTeamWorkWechat(wechatTeamId, departmentId int64) (userStrList []string, err error) {
|
|
|
|
var orgCont modelshr.AdministrativeOrganization
|
|
if departmentId != 0 {
|
|
err = orgCont.GetCont(map[string]interface{}{"`id`": departmentId}, "`wechat_organization_id`")
|
|
// fmt.Printf("orgCont------------>%v\n", err)
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|
|
|
|
//获取角色组数据
|
|
var roleCont modelsschool.RoleGroup
|
|
if wechatTeamId != 0 {
|
|
err = roleCont.GetCont(map[string]interface{}{"`srg_id`": wechatTeamId}, "`srg_extatry`", "`srg_type`")
|
|
// fmt.Printf("orgCont:%v------------>roleCont:%v\n", err, roleCont)
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|
|
|
|
var roleUser []roleGroupBodyAry
|
|
if roleCont.Type == 1 {
|
|
//矩阵
|
|
roleList := MapOut[string]()
|
|
err = json.Unmarshal([]byte(roleCont.Contentes), &roleList)
|
|
|
|
if err != nil {
|
|
return
|
|
}
|
|
departmentIdStr := strconv.FormatInt(orgCont.WechatOrganizationId, 10)
|
|
// fmt.Printf("roleList------矩阵------>%v------>%v\n", roleList, departmentIdStr)
|
|
for i, v := range roleList {
|
|
if i == departmentIdStr {
|
|
jsonMAp, _ := json.Marshal(v)
|
|
json.Unmarshal(jsonMAp, &roleUser)
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
//个人
|
|
err = json.Unmarshal([]byte(roleCont.Contentes), &roleUser)
|
|
}
|
|
if len(roleUser) < 1 {
|
|
err = fmt.Errorf("没有数据!")
|
|
}
|
|
// fmt.Printf("roleUser------------>%v\n", roleUser)
|
|
for _, v := range roleUser {
|
|
if IsInTrue[string](v.Id, userStrList) == false {
|
|
userStrList = append(userStrList, v.Id)
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取指定月的起止时间
|
|
func GetAppointMonthStarAndEndTime(dayTime string) (startTime, endTime int64) {
|
|
dataTypeAll := "2006-01-02"
|
|
dayTime = fmt.Sprintf("%v-%v", dayTime, "01")
|
|
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
|
|
startTime = DateToTimeStampOld(startTimeStr)
|
|
endTime = DateToTimeStampOld(endTimeStr)
|
|
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
|
|
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
|
|
}
|
|
|
|
// 一天的起止时间(时间戳版本)
|
|
func TimeUnixDayStartAndEnd(timeVal int64) (start, end int64) {
|
|
timeStr := UnixTimeToDay(timeVal, 14)
|
|
startTimeStr := fmt.Sprintf("%v 00:00:00", timeStr)
|
|
endTimeStr := fmt.Sprintf("%v 23:59:59", timeStr)
|
|
start = DateToTimeStampOld(startTimeStr)
|
|
end = DateToTimeStampOld(endTimeStr)
|
|
return
|
|
}
|
|
|
|
// 计算日期差
|
|
func DayBetweenDate(oneDay, twoDay string) (int, error) {
|
|
const layout = "2006-01-02"
|
|
t1, err := time.Parse(layout, oneDay)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
t2, err := time.Parse(layout, twoDay)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
// 计算日期差
|
|
duration := t1.Sub(t2)
|
|
// 转换为天数
|
|
days := int(duration.Hours() / 24)
|
|
return days, nil
|
|
}
|
|
|
|
// 时间戳转换成time格式
|
|
func TimeUnixToTime(timeData int64, unit string) (res time.Time) {
|
|
timeStr := UnixTimeToDay(timeData, 11)
|
|
loc, _ := time.LoadLocation("Local")
|
|
layout, ok := timeLayoutMap[unit]
|
|
if !ok {
|
|
layout = timeLayoutMap["s"]
|
|
}
|
|
res, _ = time.ParseInLocation(layout, timeStr, loc)
|
|
return
|
|
}
|
|
|
|
// 递归无限极菜单树
|
|
/*
|
|
@jurisd 起始位置
|
|
@parentId 上级ID
|
|
@threeData 结果值
|
|
@oper 已付权限
|
|
*/
|
|
func GetMenuThreePeiQuan(jurisd int, parentId string, threeData []MenuContList, oper []string) []PowerThree {
|
|
treeList := []PowerThree{}
|
|
for _, v := range threeData {
|
|
if v.ParentId == parentId {
|
|
child := GetMenuThreePeiQuan(jurisd, v.Id, threeData, oper)
|
|
var node PowerThree
|
|
node.Id = v.Id
|
|
node.Name = v.Name
|
|
node.ParentId = v.ParentId
|
|
node.IsTrue = v.IsTrue
|
|
isTrue, menuOper := MenuOperationPeiQuan(jurisd, v.Id, oper)
|
|
if isTrue == true {
|
|
node.MenuOperation = menuOper
|
|
// fmt.Printf("GetMenuThree-1111--%v--->%v\n", v.Id, menuOper)
|
|
}
|
|
node.Child = child
|
|
treeList = append(treeList, node)
|
|
}
|
|
}
|
|
return treeList
|
|
}
|
|
|
|
// 配权
|
|
// 获取菜单操作项目
|
|
/*
|
|
@jurisd 起始位置
|
|
@menuId 菜单ID
|
|
@oper 已付权限
|
|
*/
|
|
func MenuOperationPeiQuan(jurisd int, menuId string, oper []string) (isTrue bool, operation []MenuContList) {
|
|
var operList []modelsschool.MenuOperation
|
|
isTrue = false
|
|
operErr := overall.CONSTANT_DB_Master.Where("`menu_id` = ?", menuId).Order("oper_id desc").Find(&operList).Error
|
|
if operErr != nil || len(operList) < 1 {
|
|
return
|
|
}
|
|
|
|
isTrue = true
|
|
for i := 0; i < len(operList); i++ {
|
|
var menSmaiCont MenuContList
|
|
idStr := strconv.FormatInt(operList[i].OperId, 10)
|
|
menSmaiCont.Id = idStr
|
|
menSmaiCont.Name = operList[i].OperTitle
|
|
menSmaiCont.ParentId = strconv.FormatInt(operList[i].MenuId, 10)
|
|
if IsInTrue[string](idStr, oper) == true {
|
|
menSmaiCont.IsTrue = true
|
|
}
|
|
operation = append(operation, menSmaiCont)
|
|
}
|
|
// fmt.Printf("ApiUrl---%v--->%v--->%v--->%v\n", menuId, isTrue, operErr, operList)
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-01-03 16:41:19
|
|
@ 功能: 合并数组
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func MergeStruct[T GenericityVariable](aryOen, aryTwo []T) (structAry []T) {
|
|
if len(aryOen) >= len(aryTwo) {
|
|
structAry = aryOen
|
|
for i := 0; i < len(aryTwo); i++ {
|
|
if IsInTrue[T](aryTwo[i], structAry) == false {
|
|
structAry = append(structAry, aryTwo[i])
|
|
}
|
|
}
|
|
} else {
|
|
structAry = aryTwo
|
|
for i := 0; i < len(aryOen); i++ {
|
|
if IsInTrue[T](aryOen[i], structAry) == false {
|
|
structAry = append(structAry, aryOen[i])
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-07-16 16:02:25
|
|
@ 功能: 一天的开始与结束时间
|
|
@day 日期
|
|
@class 1:返回时间戳,2:返回日期
|
|
*/
|
|
func OenDayStartOrEndTime(day string, class int) (startTime, endTime interface{}) {
|
|
var creTimeAll DateTimeTotimes
|
|
creTimeAll.BaisStrToTime(day)
|
|
timeVal := UnixTimeToDay(creTimeAll.AllTime, 14)
|
|
if class == 1 {
|
|
startTime = DateToTimeStampOld(fmt.Sprintf("%v 00:00:00", timeVal))
|
|
endTime = DateToTimeStampOld(fmt.Sprintf("%v 23:59:59", timeVal))
|
|
} else {
|
|
startTime = fmt.Sprintf("%v 00:00:00", timeVal)
|
|
endTime = fmt.Sprintf("%v 23:59:59", timeVal)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 根据字符串组合时间
|
|
//补全时间
|
|
/*
|
|
#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])
|
|
} else {
|
|
dateTime = fmt.Sprintf("%v-%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))
|
|
if orgTimeErr {
|
|
d.AllTime = orgTime
|
|
d.AllTimeString = dateTime
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
d.AllTimeString = UnixTimeToDay(d.AllTime, 11)
|
|
}
|
|
}
|
|
|
|
//统一图标计算最大值最小值方法
|
|
/*
|
|
maxVal 最大值
|
|
minVal 最小值
|
|
*/
|
|
func JudjeMaxOfMinVal(maxVal, minVal float64) (maxVals, minVals float64) {
|
|
if maxVal > 0 {
|
|
if minVal > 0 {
|
|
if maxVal < 10 {
|
|
if maxVal < 1 {
|
|
maxVal = math.Ceil(maxVal) + 0.1
|
|
minVals = math.Ceil(minVal) - 0.1
|
|
} else {
|
|
maxVal = math.Ceil(maxVal) + 1
|
|
minVals = math.Ceil(minVal) - 1
|
|
}
|
|
} else {
|
|
jianGe := math.Ceil((maxVal - minVal) / 5)
|
|
if jianGe <= 0 {
|
|
jianGe = 1
|
|
}
|
|
maxVals = math.Ceil(maxVal) + jianGe
|
|
minVals = math.Ceil(minVal) - jianGe
|
|
if minVals < 0 {
|
|
minVals = 0
|
|
}
|
|
}
|
|
} else {
|
|
jianGe := math.Ceil(maxVal / 5)
|
|
maxVals = math.Ceil(maxVal) + jianGe
|
|
}
|
|
} else {
|
|
if minVal > -1 {
|
|
minVals = minVal - 0.1
|
|
} else {
|
|
maxGuoDu := maxVal * -1
|
|
minGuoDu := minVal * -1
|
|
jianGe := math.Ceil((minGuoDu - maxGuoDu) / 5)
|
|
if jianGe > 0 {
|
|
minVals = minVal - jianGe
|
|
} else {
|
|
minVals = minVal - 1
|
|
}
|
|
}
|
|
|
|
}
|
|
// fmt.Printf("ge---1-->%v----->%v\n", maxVals, minVals)
|
|
return
|
|
}
|
|
|
|
// 获取行政组织所有上级
|
|
func (g *GetOrgAllParent) GetOrgParentAllId(orgId int64) {
|
|
if orgId == 0 {
|
|
return
|
|
}
|
|
var orgCont modelshr.AdministrativeOrganization
|
|
err := orgCont.GetCont(map[string]interface{}{"`id`": orgId, "`state`": 1}, "`superior`")
|
|
if err == nil {
|
|
if IsInTrue[int64](orgId, g.Id) == false {
|
|
g.Id = append(g.Id, orgId)
|
|
}
|
|
g.GetOrgParentAllId(orgCont.Superior)
|
|
} else {
|
|
return
|
|
}
|
|
}
|
|
|
|
// 获取所有下级
|
|
func (g *GetOrgAllParent) GetOrgSonAllId(orgId int64) {
|
|
var orgAry []int64
|
|
if orgId != 0 {
|
|
err := overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Select("`id`").Where("`state` = 1 AND `superior` = ?", orgId).Find(&orgAry).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, v := range orgAry {
|
|
if !IsInTrue[int64](v, g.Id) {
|
|
g.Id = append(g.Id, v)
|
|
g.GetOrgSonAllId(v)
|
|
} else {
|
|
g.GetOrgSonAllId(v)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
// 获取行政组织所有上级和下级
|
|
func HaveAllOrgRelation(orgId int64) []int64 {
|
|
// departmentId := RecursionOrgLeve(orgId, 4)
|
|
// fmt.Printf("获取行政组--->%v--->%v\n", departmentId, orgId)
|
|
var getAllOrg GetOrgAllParent
|
|
getAllOrg.GetOrgAllFatherId(orgId, 4)
|
|
getAllOrg.GetOrgSonAllId(orgId)
|
|
// getAllOrg.Id = append(getAllOrg.Id, orgId)
|
|
// getAllOrg.GetOrgParent(orgId, 4)
|
|
// fmt.Printf("获取行政组--2222->%v--->%v\n", getAllOrg.Id, orgId)
|
|
return getAllOrg.Id
|
|
}
|
|
|
|
// 获取指定等级行政组织所有上级
|
|
func (g *GetOrgAllParent) GetOrgAllFatherId(orgId, level int64) {
|
|
var orgCont modelshr.OrgContType
|
|
err := orgCont.GetCont(map[string]interface{}{"`id`": orgId, "`state`": 1}, "`superior`", "level")
|
|
if err == nil {
|
|
if !IsInTrue[int64](orgId, g.Id) {
|
|
g.Id = append(g.Id, orgId)
|
|
}
|
|
if orgCont.Level >= level {
|
|
g.GetOrgAllFatherId(orgCont.Superior, level)
|
|
}
|
|
} else {
|
|
return
|
|
}
|
|
}
|
|
|
|
// 获取上下级
|
|
func (g *GetOrgAllParent) GetOrgParent(orgId, level int64) {
|
|
if orgId != 0 {
|
|
var orgCont modelshr.OrgContType
|
|
err := orgCont.GetCont(map[string]interface{}{"`id`": orgId, "`state`": 1}, "`superior`", "level")
|
|
if err == nil {
|
|
|
|
// fmt.Printf("获取行政组--2222->%v--->%v\n", orgCont.Level, level)
|
|
if orgCont.Level >= level {
|
|
g.GetOrgSonAllId(orgId)
|
|
g.GetOrgParent(orgCont.Superior, level)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//计算得分
|
|
/*
|
|
参数
|
|
@targetScore 指标分值
|
|
@resultval 结算值
|
|
@allPrizes 全奖值
|
|
@zeroPrizes 零奖值
|
|
@CappingVals 封顶值
|
|
@typeClass 1:定性;2:定量;3:观察指标
|
|
|
|
返回说明
|
|
@scoreVal 计算得分
|
|
@allPrize 全奖值
|
|
@zeroPrize 零奖值
|
|
@CappingVal 封顶值
|
|
@achievement 达成率
|
|
func CalculateScore(targetScore int64, resultval, allPrizes, zeroPrizes, CappingVals float64, typeClass int) (scoreVal, allPrize, zeroPrize, CappingVal, achievement float64)
|
|
*/
|
|
func CalculateScore(targetScore int64, resultval, allPrizes, zeroPrizes, CappingVals float64, typeClass int) (scoreVal, allPrize, zeroPrize, CappingVal, achievement float64) {
|
|
allPrize = allPrizes / 100
|
|
zeroPrize = zeroPrizes / 100
|
|
CappingVal = CappingVals / 100
|
|
resultval = resultval / 100
|
|
|
|
//fmt.Printf("达成率--1-->targetScore:%v-->resultval:%v-->allPrize:%v-->zeroPrize:%v-->CappingVal:%v\n", targetScore, resultval, allPrize, zeroPrize, CappingVal)
|
|
|
|
//不修正精度的达成率
|
|
var achievementAll float64 = 0
|
|
|
|
if allPrize == 0 && zeroPrize == 0 { //全奖值与零奖值都为0 那么达成率 100 和实际得分是 指标分
|
|
achievement = 100
|
|
scoreVal = float64(targetScore)
|
|
if typeClass == 2 {
|
|
if resultval <= 0 {
|
|
scoreVal = 0
|
|
}
|
|
}
|
|
achievementAll = 100
|
|
//fmt.Printf("达成率--11-->%v-->%v-->%v-->%v-->%v-->%v-->%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
} else {
|
|
if allPrize > zeroPrize { //如果全奖值大于零奖值 执行一下操作
|
|
if resultval <= zeroPrize { //实际结算值小于零奖值 那么达成率和实际得分都是0
|
|
achievement = 0
|
|
scoreVal = 0
|
|
achievementAll = 0
|
|
// } else if resultval > allPrize { //实际结算值大于全奖值 执行一下操作
|
|
//fmt.Printf("达成率--7-->%v-->%v-->%v-->%v-->%v-->%v-->%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
} else { //实际结算值在全奖值 与 零奖值之间
|
|
chuShu := resultval - float64(zeroPrize)
|
|
beiChuShu := float64(allPrize) - float64(zeroPrize)
|
|
if beiChuShu != 0 {
|
|
achievement = DecimalEs(chuShu/beiChuShu, 4)
|
|
achievementAll = chuShu / beiChuShu
|
|
if achievement <= 0 {
|
|
//如果在全奖值大于零件值的情况下出现达成率为0或负数,则达成率和实际得分都是0
|
|
achievement = 0
|
|
scoreVal = 0
|
|
achievementAll = 0
|
|
//fmt.Printf("达成率--8-->%v-->%v-->%v-->%v-->%v-->%v-->%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
} else {
|
|
//fmt.Printf("达成率--9-1->targetScore:%v-->resultval:%v-->scoreVal:%v-->allPrize:%v-->zeroPrize:%v-->CappingVal:%v-->achievement:%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
if achievement*100 >= CappingVal {
|
|
//如果达成率大于等于封顶值
|
|
if CappingVal > 0 {
|
|
scoreVal = (CappingVal / 100) * float64(targetScore)
|
|
//fmt.Printf("达成率--9-2->targetScore:%v-->resultval:%v-->scoreVal:%v-->allPrize:%v-->zeroPrize:%v-->CappingVal:%v-->achievement:%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
} else {
|
|
//fmt.Printf("达成率--9-3->targetScore:%v-->resultval:%v-->scoreVal:%v-->allPrize:%v-->zeroPrize:%v-->CappingVal:%v-->achievement:%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
scoreVal = float64(targetScore)
|
|
}
|
|
|
|
} else {
|
|
// scoreVal = achievement * (float64(targetScore))
|
|
scoreVal = achievementAll * (float64(targetScore))
|
|
//fmt.Printf("达成率--9-4->targetScore:%v-->resultval:%v-->scoreVal:%v-->allPrize:%v-->zeroPrize:%v-->CappingVal:%v-->achievement:%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
|
|
}
|
|
//fmt.Printf("达成率--9-->targetScore:%v-->resultval:%v-->scoreVal:%v-->allPrize:%v-->zeroPrize:%v-->CappingVal:%v-->achievement:%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
}
|
|
achievement = DecimalEs(achievement*100, 4)
|
|
} else {
|
|
//被除数为0时 那么达成率和实际得分都是0
|
|
achievement = 0
|
|
scoreVal = 0
|
|
achievementAll = 0
|
|
//fmt.Printf("达成率--10-->%v-->%v-->%v-->%v-->%v-->%v-->%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
}
|
|
|
|
}
|
|
} else { //如果全奖值小于零奖值 执行一下操作
|
|
if resultval >= zeroPrize { //实际结算值大于零奖值 那么达成率和实际得分都是0
|
|
achievement = 0
|
|
scoreVal = 0
|
|
achievementAll = 0
|
|
//fmt.Printf("达成率--1-->%v-->%v-->%v-->%v-->%v-->%v-->%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
} else {
|
|
chuShu := resultval - float64(zeroPrize)
|
|
beiChuShu := float64(allPrize) - float64(zeroPrize)
|
|
if beiChuShu != 0 {
|
|
achievement = DecimalEs(chuShu/beiChuShu, 4)
|
|
achievementAll = chuShu / beiChuShu
|
|
if achievement <= 0 {
|
|
//如果在全奖值大于零件值的情况下出现达成率为0或负数,则达成率和实际得分都是0
|
|
achievement = 0
|
|
scoreVal = 0
|
|
achievementAll = 0
|
|
//fmt.Printf("达成率--2-->%v-->%v-->%v-->%v-->%v-->%v-->%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
} else {
|
|
if achievement*100 >= CappingVal {
|
|
//如果达成率大于等于封顶值
|
|
scoreVal = CappingVal * float64(targetScore) / 100
|
|
//fmt.Printf("达成率--3-->%v-->%v-->%v-->%v-->%v-->%v-->%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
} else {
|
|
// scoreVal = achievement * (float64(targetScore))
|
|
scoreVal = achievementAll * (float64(targetScore))
|
|
//fmt.Printf("达成率--4-->%v-->%v-->%v-->%v-->%v-->%v-->%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
}
|
|
}
|
|
achievement = DecimalEs(achievement*100, 4)
|
|
//fmt.Printf("达成率--6-->%v-->%v-->%v-->%v-->%v-->%v-->%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
} else {
|
|
//被除数为0时 那么达成率和实际得分都是0
|
|
achievement = 0
|
|
scoreVal = 0
|
|
achievementAll = 0
|
|
//fmt.Printf("达成率--5-->%v-->%v-->%v-->%v-->%v-->%v-->%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if typeClass == 3 {
|
|
scoreVal = float64(targetScore)
|
|
//fmt.Printf("达成率--11-->%v-->%v-->%v-->%v-->%v-->%v-->%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
}
|
|
scoreVal = DecimalEs(scoreVal, 2)
|
|
allPrize = DecimalEs(allPrize, 2)
|
|
zeroPrize = DecimalEs(zeroPrize, 2)
|
|
CappingVal = DecimalEs(CappingVal, 2)
|
|
achievement = DecimalEs(achievement, 4)
|
|
//fmt.Printf("达成率--12-->%v-->%v-->%v-->%v-->%v-->%v-->%v\n", targetScore, resultval, scoreVal, allPrize, zeroPrize, CappingVal, achievement)
|
|
return
|
|
}
|
|
|
|
// 字符串数子转int64
|
|
func StrNumberToInt64(val string, cheng float64) (valInt int64) {
|
|
valFloat, _ := strconv.ParseFloat(val, 64)
|
|
valFloatGd := DecimalEs(valFloat*cheng, 2)
|
|
valStr := strconv.FormatFloat(valFloatGd, 'f', -1, 64)
|
|
valInt, _ = strconv.ParseInt(valStr, 10, 64)
|
|
return
|
|
}
|
|
|
|
/*
|
|
递归无限极菜单树
|
|
*/
|
|
func GetMenuRouterThree(parentId int, threeData []modelAppPlatform.Menus) []MenusRouterThree {
|
|
treeList := []MenusRouterThree{}
|
|
for _, v := range threeData {
|
|
if v.ParentId == parentId {
|
|
child := GetMenuRouterThree(v.Id, threeData)
|
|
var node MenusRouterThree
|
|
node.Path = v.Path //路由路径
|
|
if v.Types == 5 {
|
|
// node.Path = fmt.Sprintf("%v?appid=%v&tableid=%v", v.Path, v.AppId, v.TableId)
|
|
}
|
|
node.AppId = v.AppId
|
|
node.TableId = v.TableId
|
|
node.Component = v.Component //组件路径
|
|
node.Redirect = v.Redirect //跳转链接
|
|
node.Name = v.Name //路由名称
|
|
var metaCont MenusRouterThreeMet
|
|
metaCont.Perm = strconv.FormatInt(v.Perm, 10)
|
|
metaCont.Title = v.Name //路由title
|
|
metaCont.Icon = v.Icon //ICON
|
|
if v.Visible == 1 {
|
|
metaCont.Hidden = false //否隐藏
|
|
} else {
|
|
metaCont.Hidden = true //否隐藏
|
|
}
|
|
metaCont.Roles = []string{} //拥有路由权限的角色编码
|
|
metaCont.KeepAlive = false //是否开启缓存
|
|
node.Meta = metaCont //路由属性类型
|
|
node.Children = child //子路由列表
|
|
// // fmt.Printf("GetMenuThree-22222--%v--->%v\n", v.Id, node)
|
|
treeList = append(treeList, node)
|
|
}
|
|
}
|
|
return treeList
|
|
}
|
|
|
|
/*
|
|
递归无限极菜单树
|
|
*/
|
|
func GetAppMenuThree(parentId int, threeData []modelAppPlatform.Menus) []AppMenusThree {
|
|
treeList := []AppMenusThree{}
|
|
for _, v := range threeData {
|
|
if v.ParentId == parentId {
|
|
child := GetAppMenuThree(v.Id, threeData)
|
|
var node AppMenusThree
|
|
node.Id = v.Id //
|
|
node.Name = v.Name //菜单名称"`
|
|
node.Types = v.Types //菜单类型(1-菜单;2-目录;3-外链;4-按钮权限"`
|
|
node.Path = v.Path //路由路径"`
|
|
node.Component = v.Component //组件路径(vue页面完整路径,省略.vue后缀)"`
|
|
node.Perm = v.Perm // 权限标识"`
|
|
node.Visible = v.Visible //显示状态(1:显示;2:隐藏,3:删除)"`
|
|
node.Sort = v.Sort //排序(数字越小排名越靠前))"`
|
|
node.Icon = v.Icon //菜单图标"`
|
|
node.Redirect = v.Redirect //跳转路径"`
|
|
node.ParentId = v.ParentId //父菜单ID"`
|
|
node.Time = v.Time //创建时间"`
|
|
node.Class = MenuType(v.Types)
|
|
node.PermCode = strconv.FormatInt(v.Perm, 10)
|
|
node.Children = child //子路由列表
|
|
// // fmt.Printf("GetMenuThree-22222--%v--->%v\n", v.Id, node)
|
|
treeList = append(treeList, node)
|
|
}
|
|
}
|
|
return treeList
|
|
}
|
|
func GetMenuOptionsThree(parentId int, threeData []modelAppPlatform.Menus) []AppMenusOptionsThree {
|
|
treeList := []AppMenusOptionsThree{}
|
|
for _, v := range threeData {
|
|
if v.ParentId == parentId {
|
|
child := GetMenuOptionsThree(v.Id, threeData)
|
|
var node AppMenusOptionsThree
|
|
node.Label = v.Name //路由名称
|
|
node.Value = v.Id //路由ID
|
|
node.Children = child //子路由列表
|
|
// // fmt.Printf("GetMenuThree-22222--%v--->%v\n", v.Id, node)
|
|
treeList = append(treeList, node)
|
|
}
|
|
}
|
|
return treeList
|
|
}
|
|
|
|
// 菜单类型对照
|
|
func MenuType(class int) string {
|
|
switch class {
|
|
case 1:
|
|
return "MENU"
|
|
case 2:
|
|
return "CATALOG"
|
|
case 3:
|
|
return "EXTLINK"
|
|
case 4:
|
|
return "BUTTON"
|
|
case 5:
|
|
return "MyApp"
|
|
default:
|
|
return "CATALOG"
|
|
}
|
|
return "CATALOG"
|
|
}
|
|
func MenuTypeToInt(class string) int {
|
|
switch class {
|
|
case "MENU":
|
|
return 1
|
|
case "CATALOG":
|
|
return 2
|
|
case "EXTLINK":
|
|
return 3
|
|
case "BUTTON":
|
|
return 4
|
|
case "MyApp":
|
|
return 5
|
|
default:
|
|
return 2
|
|
}
|
|
return 2
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-09-14 13:33:12
|
|
@ 功能: 获取指定括号中的数据
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func MatchBracket(s, starBracket, endBracket string) string {
|
|
i := strings.Index(s, starBracket)
|
|
if i >= 0 {
|
|
// fmt.Printf("match-i-->%v\n", i)
|
|
j := strings.Index(s[i:], endBracket)
|
|
if j >= 0 {
|
|
// fmt.Printf("match-j-->%v-->%v\n", j, s[i+1:i+j])
|
|
return s[i+1 : i+j]
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-09-14 16:01:13
|
|
@ 功能: 通用执行SQL原生语句
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func ExecSql(database, sqlStr string) (err error) {
|
|
|
|
switch database {
|
|
case "Master":
|
|
err = overall.CONSTANT_DB_Master.Exec(sqlStr).Error
|
|
case "AppPlatform":
|
|
err = overall.CONSTANT_DB_AppPlatform.Exec(sqlStr).Error
|
|
case "Wechat":
|
|
err = overall.CONSTANT_DB_Wechat.Exec(sqlStr).Error
|
|
case "HR":
|
|
err = overall.CONSTANT_DB_HR.Exec(sqlStr).Error
|
|
case "FILE_BOOK":
|
|
err = overall.CONSTANT_DB_FILE_BOOK.Exec(sqlStr).Error
|
|
case "ERROR_SUBJECT":
|
|
err = overall.CONSTANT_DB_ERROR_SUBJECT.Exec(sqlStr).Error
|
|
case "MY_TEST":
|
|
err = overall.CONSTANT_DB_MY_TEST.Exec(sqlStr).Error
|
|
case "SCORING":
|
|
err = overall.CONSTANT_DB_SCORING.Exec(sqlStr).Error
|
|
case "QA":
|
|
err = overall.CONSTANT_DB_QA.Exec(sqlStr).Error
|
|
case "BILLBOARD":
|
|
err = overall.CONSTANT_DB_BILLBOARD.Exec(sqlStr).Error
|
|
case "HEALTH":
|
|
err = overall.CONSTANT_DB_HEALTH.Exec(sqlStr).Error
|
|
case "KPI":
|
|
err = overall.CONSTANT_DB_KPI.Exec(sqlStr).Error
|
|
case "WECHAT_LOG":
|
|
err = overall.CONSTANT_DB_WECHAT_LOG.Exec(sqlStr).Error
|
|
case "MANAGE_ARCHIVES":
|
|
err = overall.CONSTANT_DB_MANAGE_ARCHIVES.Exec(sqlStr).Error
|
|
case "System_Permission":
|
|
err = overall.CONSTANT_DB_System_Permission.Exec(sqlStr).Error
|
|
case "DB_Storage":
|
|
err = overall.CONSTANT_DB_Storage.Exec(sqlStr).Error
|
|
case "DB_Server":
|
|
err = overall.CONSTANT_DB_Server.Exec(sqlStr).Error
|
|
case "Tidb":
|
|
err = overall.CONSTANT_DB_Tidb.Exec(sqlStr).Error
|
|
case "CustomerForm":
|
|
err = overall.CONSTANT_DB_CustomerForm.Exec(sqlStr).Error
|
|
default:
|
|
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-09-22 11:28:12
|
|
@ 功能: 获取指定行政组织id,所有子类
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (g *GetOrgAllParent) GetOrgSun(superior int64) {
|
|
var id []int64
|
|
if superior == 0 {
|
|
return
|
|
}
|
|
err := overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Select("`id`").Where("`state` = 1 AND `superior` = ?", superior).Find(&id).Error
|
|
if err != nil || len(id) < 1 {
|
|
return
|
|
}
|
|
for _, v := range id {
|
|
if !IsInTrue[int64](v, g.Id) {
|
|
g.Id = append(g.Id, v)
|
|
}
|
|
g.GetOrgSun(v)
|
|
}
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-11-27 09:44:25
|
|
@ 功能: 获取自定义App子菜单
|
|
*/
|
|
func (g *GetOrgAllParent) GetAppMenuSun(appKey, superior int64) {
|
|
var id []int64
|
|
if superior == 0 {
|
|
return
|
|
}
|
|
err := overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.Appmenus{}).Select("`id`").Where("`state` = 1 AND `type` = 1 AND `isLock` = 2 AND `appkey` = ? AND `parent` = ?", appKey, superior).Find(&id).Error
|
|
if err != nil || len(id) < 1 {
|
|
return
|
|
}
|
|
for _, v := range id {
|
|
if !IsInTrue[int64](v, g.Id) {
|
|
g.Id = append(g.Id, v)
|
|
}
|
|
g.GetAppMenuSun(appKey, v)
|
|
}
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-03-06 14:16:09
|
|
@ 功能: 获取指定自定义表单分组所有子分组
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (g *GetOrgAllParent) GetFormGroupSun(superior int64) {
|
|
if superior == 0 {
|
|
return
|
|
}
|
|
var id []int64
|
|
err := overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.CustomerFormGroup{}).Select("`id`").Where("`state` IN ? AND `superior` = ?", []int{1, 2}, superior).Find(&id).Error
|
|
if err != nil || len(id) < 1 {
|
|
return
|
|
}
|
|
for _, v := range id {
|
|
if !IsInTrue[int64](v, g.Id) {
|
|
g.Id = append(g.Id, v)
|
|
}
|
|
g.GetOrgSun(v)
|
|
}
|
|
}
|
|
|
|
// 类型转换
|
|
func TypeToClass(val interface{}, timeClass int) (str string) {
|
|
|
|
if typeVal, ok := val.(uint); ok {
|
|
str = UnixTimeToDay(int64(typeVal), timeClass)
|
|
} else if typeVal, ok := val.(uint8); ok {
|
|
str = UnixTimeToDay(int64(typeVal), timeClass)
|
|
} else if typeVal, ok := val.(uint16); ok {
|
|
str = UnixTimeToDay(int64(typeVal), timeClass)
|
|
} else if typeVal, ok := val.(uint32); ok {
|
|
str = UnixTimeToDay(int64(typeVal), timeClass)
|
|
} else if typeVal, ok := val.(uint64); ok {
|
|
str = UnixTimeToDay(int64(typeVal), timeClass)
|
|
} else if typeVal, ok := val.(int); ok {
|
|
str = UnixTimeToDay(int64(typeVal), timeClass)
|
|
} else if typeVal, ok := val.(int8); ok {
|
|
str = UnixTimeToDay(int64(typeVal), timeClass)
|
|
} else if typeVal, ok := val.(int16); ok {
|
|
str = UnixTimeToDay(int64(typeVal), timeClass)
|
|
} else if typeVal, ok := val.(int32); ok {
|
|
str = UnixTimeToDay(int64(typeVal), timeClass)
|
|
} else if typeVal, ok := val.(int64); ok {
|
|
str = UnixTimeToDay(typeVal, timeClass)
|
|
} else if typeVal, ok := val.(float32); ok {
|
|
str = UnixTimeToDay(int64(typeVal), timeClass)
|
|
} else if typeVal, ok := val.(float64); ok {
|
|
str = UnixTimeToDay(int64(typeVal), timeClass)
|
|
} else if typeVal, ok := val.(byte); ok {
|
|
valInt, valErr := strconv.ParseInt(string(typeVal), 10, 64)
|
|
if valErr == nil {
|
|
str = UnixTimeToDay(valInt, timeClass)
|
|
} else {
|
|
str = ""
|
|
}
|
|
} else if typeVal, ok := val.(string); ok {
|
|
valInt, valErr := strconv.ParseInt(typeVal, 10, 64)
|
|
if valErr == nil {
|
|
str = UnixTimeToDay(valInt, timeClass)
|
|
} else {
|
|
str = typeVal
|
|
}
|
|
} else {
|
|
str = ""
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-11-08 16:03:24
|
|
@ 功能: 根据身份证获取对应生日
|
|
@ 参数
|
|
|
|
#cardId 身份证号码
|
|
|
|
@ 返回值
|
|
|
|
#生日
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func GetBirthday(cardId string) string {
|
|
if len(cardId) < 15 {
|
|
return ""
|
|
}
|
|
// 兼容第一代15位身份证号码
|
|
if len(cardId) == 15 {
|
|
// 第一代身份证年份都是19开头的
|
|
return fmt.Sprintf("19%s", cardId[6:12])
|
|
} else {
|
|
return cardId[6:14]
|
|
}
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-11-08 16:10:28
|
|
@ 功能: 根据生日日期得到用户年龄
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (b *BirthdayAge) GetAgeByBirthday(cardId string) {
|
|
if len(cardId) < 15 {
|
|
return
|
|
}
|
|
birthday := GetBirthday(cardId)
|
|
if len(birthday) < 1 {
|
|
b.Age = 0
|
|
}
|
|
year, _ := strconv.Atoi(birthday[0:4])
|
|
month, _ := strconv.Atoi(birthday[4:6])
|
|
day, _ := strconv.Atoi(birthday[6:])
|
|
var months string
|
|
if month < 10 {
|
|
months = fmt.Sprintf("0%v", month)
|
|
} else {
|
|
months = strconv.Itoa(month)
|
|
}
|
|
var days string
|
|
if day < 10 {
|
|
days = fmt.Sprintf("0%v", day)
|
|
} else {
|
|
days = strconv.Itoa(day)
|
|
}
|
|
b.Birthday = fmt.Sprintf("%v-%v-%v", year, months, days)
|
|
// 计算当前日期与生日中年月日都差值
|
|
now := time.Now()
|
|
age := now.Year() - year
|
|
moreMonth := int(now.Month()) - month
|
|
moreDay := now.Day() - day
|
|
|
|
// 未到生日月份,或者到了月份,但未到生日日期,年龄都要减1岁
|
|
if moreMonth < 0 || (moreMonth == 0 && moreDay < 0) {
|
|
age--
|
|
}
|
|
// 不要出现负值
|
|
if age < 0 {
|
|
age = 0
|
|
}
|
|
|
|
b.Age = age
|
|
}
|
|
|
|
// 统计元素重复出现的次数
|
|
/*
|
|
@ary 数组切片
|
|
*/
|
|
func StatisticalDuplication[T GenericityVariable](ary []T) (mapAry map[T]int) {
|
|
mapAry = make(map[T]int)
|
|
count := 0
|
|
for i := 0; i < len(ary); i++ {
|
|
for n := 0; n < len(ary); n++ {
|
|
if ary[i] == ary[n] {
|
|
count++
|
|
}
|
|
}
|
|
mapAry[ary[i]] = count
|
|
count = 0
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-03-06 14:42:33
|
|
@ 功能: 生成自定义表单分组树
|
|
*/
|
|
func CustFormGroupTree(pid int64, treeList []modelAppPlatform.CustomerFormGroup) []CustomerFormGroupTree {
|
|
var TreeNodes []CustomerFormGroupTree
|
|
if reflect.ValueOf(treeList).IsValid() {
|
|
for _, v := range treeList {
|
|
if v.Superior == pid {
|
|
// v.Child = append(v.Child, CustFormGroupTree(v.Superior, treeList)...)
|
|
// TreeNodes = append(TreeNodes, v)
|
|
var treeInfo CustomerFormGroupTree
|
|
treeInfo.Id = v.Id
|
|
treeInfo.Title = v.Title //分组名称"`
|
|
treeInfo.Superior = v.Superior //父级"`
|
|
treeInfo.Sort = v.Sort //排序"`
|
|
treeInfo.Ordid = v.Ordid //归属行政组织"`
|
|
treeInfo.State = v.State //显示状态(1:启用;2:禁用,3:删除)"`
|
|
treeInfo.Time = v.Time //创建时间"`
|
|
treeInfo.Child = append(treeInfo.Child, CustFormGroupTree(v.Superior, treeList)...)
|
|
TreeNodes = append(TreeNodes, treeInfo)
|
|
}
|
|
}
|
|
}
|
|
return TreeNodes
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-04-02 11:19:41
|
|
@ 功能: 泛型类型断言
|
|
*/
|
|
func TypeToInterface(val interface{}) string {
|
|
switch balData := val.(type) {
|
|
case int:
|
|
return strconv.Itoa(balData)
|
|
case int8:
|
|
return strconv.FormatInt(int64(balData), 10)
|
|
case int16:
|
|
return strconv.FormatInt(int64(balData), 10)
|
|
case int32:
|
|
return strconv.FormatInt(int64(balData), 10)
|
|
case int64:
|
|
return strconv.FormatInt(balData, 10)
|
|
case uint:
|
|
return strconv.FormatUint(uint64(balData), 10)
|
|
case uint8:
|
|
return strconv.FormatUint(uint64(balData), 10)
|
|
case uint16:
|
|
return strconv.FormatUint(uint64(balData), 10)
|
|
case uint32:
|
|
return strconv.FormatUint(uint64(balData), 10)
|
|
case uint64:
|
|
return strconv.FormatUint(balData, 10)
|
|
case float32:
|
|
return fmt.Sprintf("%v", float64(balData))
|
|
case float64:
|
|
return fmt.Sprintf("%v", float64(balData))
|
|
default:
|
|
if balDataStr, ok := balData.(string); ok {
|
|
if balDataStr != "" {
|
|
return balDataStr
|
|
} else {
|
|
return ""
|
|
}
|
|
} else {
|
|
return ""
|
|
}
|
|
|
|
}
|
|
// if valDataStr, ok := val.(string); ok {
|
|
// if valDataStr != "" {
|
|
// return valDataStr
|
|
// } else {
|
|
// return ""
|
|
// }
|
|
// } else {
|
|
// return ""
|
|
// }
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-04-07 08:26:39
|
|
@ 功能: 去除字段保留字
|
|
*/
|
|
func RemoveReservedWord(val string) bool {
|
|
reservedWord := []string{"id", "masters_key", "creater_time", "edit_time", "flow_id", "states", "flowIsOpen", "explicate"}
|
|
return IsInTrue[string](val, reservedWord)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-04-07 08:26:39
|
|
@ 功能: 去除字段保留字
|
|
*/
|
|
func RemoveReservedWordTime(val string) bool {
|
|
reservedWord := []string{"datetimerange", "daterange", "monthrange"}
|
|
return IsInTrue[string](val, reservedWord)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-08-30 08:49:43
|
|
@ 功能: 输出班组
|
|
*/
|
|
func TeamidName(val int64) string {
|
|
switch val {
|
|
case 1:
|
|
return "长白班"
|
|
case 2:
|
|
return "甲班"
|
|
case 3:
|
|
return "乙班"
|
|
case 4:
|
|
return "丙班"
|
|
case 5:
|
|
return "丁班"
|
|
default:
|
|
return "未知"
|
|
}
|
|
return "未知"
|
|
}
|
|
func TeamidNameInt(val string) int64 {
|
|
switch val {
|
|
case "长白班":
|
|
return 1
|
|
case "甲班":
|
|
return 2
|
|
case "乙班":
|
|
return 3
|
|
case "丙班":
|
|
return 4
|
|
case "丁班":
|
|
return 5
|
|
default:
|
|
return 0
|
|
}
|
|
return 0
|
|
}
|
|
|
|
//取最大值
|
|
|
|
func GetMaxNum[T GenericityVariable](ary []T) T {
|
|
maxVal := ary[0]
|
|
if len(ary) == 0 {
|
|
return maxVal
|
|
}
|
|
|
|
for i := 1; i < len(ary); i++ {
|
|
if maxVal < ary[i] {
|
|
maxVal = ary[i]
|
|
}
|
|
}
|
|
|
|
return maxVal
|
|
}
|
|
|
|
// 数据库关系转换
|
|
func DatabaseIntToString(typeId int64) string {
|
|
switch typeId {
|
|
case 2:
|
|
return "RTD"
|
|
case 3:
|
|
return "TIDB"
|
|
case 4:
|
|
return "SqlServer"
|
|
case 5:
|
|
return "redis"
|
|
default:
|
|
return "mysql"
|
|
}
|
|
return "mysql"
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2025-01-16 08:35:07
|
|
@ 功能: 泛型去重
|
|
*/
|
|
func RemoveDuplicate[T GenericityVariable](ary []T) []T {
|
|
m := make(map[T]bool)
|
|
uniqueNumbers := []T{}
|
|
for _, v := range ary {
|
|
if !m[v] {
|
|
m[v] = true
|
|
uniqueNumbers = append(uniqueNumbers, v)
|
|
}
|
|
}
|
|
return uniqueNumbers
|
|
}
|
|
|
|
// 获得月份最后一天,最后一秒
|
|
func GetDaysInMonth(nextYear int, nextMonth int) DateTimeTotimes {
|
|
crueMonth := nextMonth + 1
|
|
if crueMonth > 12 {
|
|
crueMonth = crueMonth - 12
|
|
nextYear = nextYear + 1
|
|
}
|
|
firstDayOfNextMonth := time.Date(nextYear, time.Month(crueMonth), 1, 0, 0, 0, 0, time.UTC)
|
|
lastDayOfThisMonth := firstDayOfNextMonth.Add(-1 * time.Second)
|
|
// fmt.Println("本月最后一天时间:", lastDayOfThisMonth)
|
|
dates := lastDayOfThisMonth.Format("2006-01-02 15:04:05")
|
|
var creTimeAll DateTimeTotimes
|
|
creTimeAll.BaisStrToTime(dates)
|
|
return creTimeAll
|
|
}
|
|
|
|
// 获取指定时间的上个月的开始和结束时间
|
|
func GetLastMonthStartEnd(dayTime string) (int64, int64) {
|
|
// dataTypeAll := "2006-01-02"
|
|
// dayTime = fmt.Sprintf("%v-%v", dayTime, "01")
|
|
now := StringToTimeIng("d", dayTime)
|
|
// now := time.Now()
|
|
lastMonthFirstDay := now.AddDate(0, -1, -now.Day()+1)
|
|
lastMonthStart := time.Date(lastMonthFirstDay.Year(), lastMonthFirstDay.Month(), lastMonthFirstDay.Day(), 0, 0, 0, 0, now.Location()).Unix()
|
|
lastMonthEndDay := lastMonthFirstDay.AddDate(0, 1, -1)
|
|
lastMonthEnd := time.Date(lastMonthEndDay.Year(), lastMonthEndDay.Month(), lastMonthEndDay.Day(), 23, 59, 59, 0, now.Location()).Unix()
|
|
return lastMonthStart, lastMonthEnd
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2025-06-03 09:13:15
|
|
@ 功能: 计算整数长度
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func GetIntLength(n int64) int {
|
|
if n == 0 {
|
|
return 1
|
|
}
|
|
count := 0
|
|
// 处理负数的情况
|
|
if n < 0 {
|
|
n = -n
|
|
}
|
|
for n > 0 {
|
|
count++
|
|
n /= 10
|
|
}
|
|
return count
|
|
}
|
|
|
|
// 值处理
|
|
// 1:自动(原始值);2:整数;3:保留1位小数;4:保留2位小数;5:百分比;6:百分比1位小数;7:百分比2位小数;
|
|
func DataChuli(val float64, types int) interface{} {
|
|
var guodu interface{}
|
|
switch types {
|
|
case 2:
|
|
guodu = int64(val)
|
|
case 3:
|
|
guodu = fmt.Sprintf("%.1f", val)
|
|
case 4:
|
|
guodu = fmt.Sprintf("%.2f", val)
|
|
case 5:
|
|
guodu = fmt.Sprintf("%v%", val)
|
|
case 6:
|
|
guodu = fmt.Sprintf("%.1f%", val)
|
|
case 7:
|
|
guodu = fmt.Sprintf("%.2f%", val)
|
|
default:
|
|
guodu = val
|
|
}
|
|
return guodu
|
|
}
|
|
|