应用集成平台服务端
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.

867 lines
27 KiB

9 months ago
package menus
import (
"appPlatform/middleware/grocerystore"
"appPlatform/models/modelshr"
"appPlatform/models/teamlog"
"appPlatform/overall"
"appPlatform/overall/publicmethod"
"encoding/json"
"fmt"
"sort"
"strconv"
"time"
"github.com/gin-gonic/gin"
)
/*
*
@ 作者: 秦东
@ 时间: 2025-01-21 15:41:06
@ 功能: 添加工作时间设置
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) AddTeamTime(c *gin.Context) {
var requestData SetWorkTime
err := c.ShouldBindJSON(&requestData)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if requestData.Name == "" {
publicmethod.Result(101, requestData, c)
return
}
if len(requestData.List) < 1 {
publicmethod.Result(1, requestData, c, "没有划分工作时间段!")
return
}
isTrue := true
for _, v := range requestData.List {
if v.Title == "" || v.StartTime == "" || v.EndTime == "" {
isTrue = false
}
}
if !isTrue {
publicmethod.Result(1, requestData, c, "您划分的工作时间段,有不符合规定的!请改正!")
return
}
timeKey := publicmethod.GetUUid(5)
//工作时间段类型
var workTimeType modelshr.WorkTimeType
//判断是否有同类型的安排
err = workTimeType.GetCont(map[string]interface{}{"`name`": requestData.Name}, "`id`")
if err == nil {
publicmethod.Result(1, requestData, c, "该名称已经存在!请不要重复添加!")
return
}
workTimeType.Id = timeKey
workTimeType.Name = requestData.Name //type:string comment:类型名称 version:2022-11-13 16:57
workTimeType.State = 1 //类型:(1:启用;2:禁用;3:删除) version:2022-11-13 16:57
workTimeType.Time = time.Now().Unix()
//工作时段
var workTimeList []modelshr.WorkingTimePeriod
for i, lv := range requestData.List {
var workTimeCont modelshr.WorkingTimePeriod
workTimeCont.Name = lv.Title //type:string comment:工作时间段名称 version:2022-11-13 16:59
workTimeCont.Time = time.Now().Unix() //type:int64 comment:编辑时间;0 version:2022-11-13 16:59
workTimeCont.TypeId = timeKey //type:int64 comment:类型 version:2022-11-13 16:59
workTimeCont.StartTime = lv.StartTime //type:string comment:开始时间 version:2022-11-13 16:59
workTimeCont.EndTime = lv.EndTime //type:string comment:结束时间 version:2022-11-13 16:59
workTimeCont.State = 1
workTimeCont.Sort = i + 1
workTimeList = append(workTimeList, workTimeCont)
}
err = overall.CONSTANT_DB_HR.Create(&workTimeType).Error
if err != nil {
publicmethod.Result(104, requestData, c)
return
}
WriteWorkTime(timeKey, workTimeList)
publicmethod.Result(0, requestData, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2022-12-13 18:06:08
@ 功能: 写入工作时段
@ 参数
#key 类型ID
#workTimeList 时段列表
@ 返回值
#err 返回状态
@ 方法原型
# WriteWorkTime(key int64, workTimeList []modelshr.WorkingTimePeriod) (err error)
*/
func WriteWorkTime(key int64, workTimeList []modelshr.WorkingTimePeriod) (err error) {
var workTimeCont modelshr.WorkingTimePeriod
workTimeCont.DelCont(map[string]interface{}{"`type_id`": key})
err = overall.CONSTANT_DB_HR.Create(&workTimeList).Error
return
}
/*
*
@ 作者: 秦东
@ 时间: 2022-12-14 09:20:07
@ 功能: 编辑时间段
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) EditWorkTimeCont(c *gin.Context) {
var requestData EditWorkTimeConts
err := c.ShouldBindJSON(&requestData)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if requestData.Id == "" {
publicmethod.Result(101, requestData, c)
return
}
if requestData.Name == "" {
publicmethod.Result(101, requestData, c)
return
}
if len(requestData.List) < 1 {
publicmethod.Result(1, requestData, c, "没有划分工作时间段!")
return
}
isTrue := true
for _, v := range requestData.List {
if v.Title == "" || v.StartTime == "" || v.EndTime == "" {
isTrue = false
}
// beginTime := fmt.Sprintf("%v",)
}
if !isTrue {
publicmethod.Result(1, requestData, c, "您划分的工作时间段,有不符合规定的!请改正!")
return
}
wher := publicmethod.MapOut[string]()
wher["id"] = requestData.Id
var oldCont modelshr.WorkTimeType
err = oldCont.GetCont(wher)
if err != nil {
publicmethod.Result(107, err, c)
return
}
editCont := publicmethod.MapOut[string]()
editCont["name"] = requestData.Name
// editCont["rule"] = requestData.Rule
editCont["time"] = time.Now().Unix()
err = oldCont.EiteCont(wher, editCont)
if err != nil {
publicmethod.Result(106, err, c)
return
}
//工作时段
EditPeriodTime(oldCont.Id, requestData.List)
publicmethod.Result(0, err, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2022-12-16 17:10:13
@ 功能: 编辑工作时段
@ 参数
#typeId 类型识别符
#ruleList 分班时间表
@ 返回值
#
@ 方法原型
#
*/
func EditPeriodTime(typeId int64, ruleList []TemaTimes) {
var workTimeCont modelshr.WorkingTimePeriod
workTimeListCont, _ := workTimeCont.ContMap(map[string]interface{}{"`type_id`": typeId})
var editId []string
var saveData []modelshr.WorkingTimePeriod
for i, v := range ruleList {
if v.Id != "" {
var workTimeContJudge modelshr.WorkingTimePeriod
err := workTimeContJudge.GetCont(map[string]interface{}{"`id`": v.Id})
if err == nil {
if publicmethod.IsInTrue[string](v.Id, editId) == false {
editId = append(editId, v.Id)
}
editCont := publicmethod.MapOut[string]()
editCont["`sort`"] = i + 1
editCont["`state`"] = 1
editCont["`name`"] = v.Title
editCont["`time`"] = time.Now().Unix()
editCont["`start_time`"] = v.StartTime
editCont["`end_time`"] = v.EndTime
var workTimeContEs modelshr.WorkingTimePeriod
workTimeContEs.EiteCont(map[string]interface{}{"`id`": v.Id}, editCont)
} else {
var workTimeContAdd modelshr.WorkingTimePeriod
workTimeContAdd.Sort = i + 1
workTimeContAdd.Name = v.Title //type:string comment:工作时间段名称 version:2022-11-13 16:59
workTimeContAdd.Time = time.Now().Unix() //type:int64 comment:编辑时间;0 version:2022-11-13 16:59
workTimeContAdd.TypeId = typeId //type:int64 comment:类型 version:2022-11-13 16:59
workTimeContAdd.StartTime = v.StartTime //type:string comment:开始时间 version:2022-11-13 16:59
workTimeContAdd.EndTime = v.EndTime //type:string comment:结束时间 version:2022-11-13 16:59
saveData = append(saveData, workTimeContAdd)
}
} else {
var workTimeContAdd modelshr.WorkingTimePeriod
workTimeContAdd.Name = v.Title //type:string comment:工作时间段名称 version:2022-11-13 16:59
workTimeContAdd.Time = time.Now().Unix() //type:int64 comment:编辑时间;0 version:2022-11-13 16:59
workTimeContAdd.TypeId = typeId //type:int64 comment:类型 version:2022-11-13 16:59
workTimeContAdd.StartTime = v.StartTime //type:string comment:开始时间 version:2022-11-13 16:59
workTimeContAdd.EndTime = v.EndTime //type:string comment:结束时间 version:2022-11-13 16:59
workTimeContAdd.Sort = i + 1
saveData = append(saveData, workTimeContAdd)
}
}
//将不在使用的项目删除
for _, dv := range workTimeListCont {
idStr := strconv.FormatInt(dv.Id, 10)
if publicmethod.IsInTrue[string](idStr, editId) == false {
editCont := publicmethod.MapOut[string]()
editCont["`state`"] = 3
editCont["`time`"] = time.Now().Unix()
var workTimeContEss modelshr.WorkingTimePeriod
workTimeContEss.EiteCont(map[string]interface{}{"`id`": dv.Id}, editCont)
}
}
if len(saveData) > 0 {
overall.CONSTANT_DB_HR.Create(&saveData)
}
}
/*
*
@ 作者: 秦东
@ 时间: 2025-01-23 09:41:25
@ 功能: 编辑制度轮询规则
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) SaveCycleRules(c *gin.Context) {
var requestData JieShoeTeamsRules
c.ShouldBindJSON(&requestData)
if requestData.Id == "" {
publicmethod.Result(101, requestData, c)
return
}
if len(requestData.List) <= 0 {
publicmethod.Result(101, requestData, c)
return
}
teamIsOk := true
cycleIsOk := false
for _, v := range requestData.List {
if v.Id == "" || len(v.List) <= 0 {
teamIsOk = false
}
for _, lv := range v.List {
if lv.Id != 0 {
cycleIsOk = true
}
}
}
if !teamIsOk || !cycleIsOk {
publicmethod.Result(101, requestData, c)
return
}
var teamsRulesInfo modelshr.TeamsRules
teamsRulesInfo.DelCont(map[string]interface{}{"`ruleTypeId`": requestData.Id})
var sendMap []interface{}
for _, v := range requestData.List {
for _, lv := range v.List {
var teamsRulesInfoNew modelshr.TeamsRules
teamsRulesInfoNew.RuleTypeId, _ = strconv.ParseInt(requestData.Id, 10, 64)
teamsRulesInfoNew.RuleTypeName = requestData.Name
teamsRulesInfoNew.Cycle = requestData.Cycle
teamsRulesInfoNew.TeamsId, _ = strconv.ParseInt(v.Id, 10, 64)
teamsRulesInfoNew.TeamsName = v.Name
teamsRulesInfoNew.CycleSort = lv.Id
teamsRulesInfoNew.CycleName = lv.Name
teamsRulesInfoNew.CycleWorkTime, _ = strconv.ParseInt(lv.Value, 10, 64)
if lv.Value != "" {
teamsRulesInfoNew.CycleWorkName = lv.Days
}
teamsRulesInfoNew.Time = time.Now().Unix()
sendMap = append(sendMap, teamsRulesInfoNew)
overall.CONSTANT_DB_HR.Create(&teamsRulesInfoNew)
}
}
publicmethod.Result(0, sendMap, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2025-01-23 10:49:25
@ 功能: 获取轮询规则
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) GainCycleRule(c *gin.Context) {
var requestData publicmethod.PublicId
err := c.ShouldBindJSON(&requestData)
var sendData JieShoeTeamsRules
if err != nil {
publicmethod.Result(200, sendData, c)
return
}
if requestData.Id == "" {
publicmethod.Result(200, sendData, c)
return
}
var teamsRulesList []modelshr.TeamsRules
overall.CONSTANT_DB_HR.Where("`ruleTypeId` = ?", requestData.Id).Find(&teamsRulesList)
if len(teamsRulesList) < 1 {
publicmethod.Result(200, sendData, c)
return
}
var workTimeTypeInfo modelshr.WorkTimeType
err = workTimeTypeInfo.GetCont(map[string]interface{}{"`id`": requestData.Id}, "`name`")
if err != nil {
publicmethod.Result(200, sendData, c)
return
}
sendData.Id = requestData.Id
sendData.Name = workTimeTypeInfo.Name
// var workPeriodList []modelshr.WorkingTimePeriod
// overall.CONSTANT_DB_HR.Where("`type_id` = ?", requestData.Id).Find(&workPeriodList)
// if len(workPeriodList) < 1 {
// publicmethod.Result(200, sendData, c)
// return
// }
var teamIdAry []int64
var teamsAry []RulesInfo
for _, v := range teamsRulesList {
if !publicmethod.IsInTrue[int64](v.TeamsId, teamIdAry) {
teamIdAry = append(teamIdAry, v.TeamsId)
var teamsInfo RulesInfo
teamsInfo.Id = strconv.FormatInt(v.TeamsId, 10)
teamsInfo.Name = v.TeamsName
teamsAry = append(teamsAry, teamsInfo)
}
}
if len(teamsAry) < 1 {
publicmethod.Result(200, sendData, c)
return
}
for i, v := range teamsAry {
for _, tv := range teamsRulesList {
tvId := strconv.FormatInt(tv.TeamsId, 10)
// fmt.Printf("%v------%v\n", tvId, v.Id)
if tvId == v.Id {
var cycleInfo CycleRulesInfo
cycleInfo.Id = tv.CycleSort
cycleInfo.Name = tv.CycleName
if tv.CycleWorkTime != 0 {
cycleInfo.Value = strconv.FormatInt(tv.CycleWorkTime, 10)
}
fmt.Printf("%v------%v------%v\n", tvId, tv.CycleWorkTime, cycleInfo.Value)
cycleInfo.Days = tv.CycleWorkName
sendData.Cycle = tv.Cycle
teamsAry[i].List = append(teamsAry[i].List, cycleInfo)
}
}
}
sendData.List = teamsAry
publicmethod.Result(0, sendData, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2025-01-23 14:47:50
@ 功能: 解析日历生成排班顺序(新版本)
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) AnalysisMonthRulersNews(c *gin.Context) {
var requestData AnYuePaiBan
c.ShouldBindJSON(&requestData)
if requestData.OrgId == "" {
publicmethod.Result(1, requestData, c, "未知行政单位")
return
}
var sendMonthList []interface{}
orgIdInt, _ := strconv.ParseInt(requestData.OrgId, 10, 64)
menuCont, cureeOrgId, err := CureeRunRules(orgIdInt)
fmt.Printf("%v\n", cureeOrgId)
if err != nil {
publicmethod.Result(200, sendMonthList, c)
return
}
//获取源点起始工作时间段
menuCont.BegainTime = publicmethod.UnixTimeToDay(menuCont.StartTime, 14)
menuCont.TypeIdStr = strconv.FormatInt(menuCont.TypeId, 10)
//获取倒班规则
var paiBanType modelshr.WorkTimeType
paiBanType.GetCont(map[string]interface{}{"`id`": menuCont.TypeId}, " `name`")
menuCont.TypeName = paiBanType.Name
//作息时间
var zuoXiTime []modelshr.WorkingTimePeriod
overall.CONSTANT_DB_HR.Where("`state` = 1 AND `type_id` = ?", menuCont.TypeId).Order("`sort` ASC").Find(&zuoXiTime)
//轮询规则
var lunXunShiXu []modelshr.TeamsRules
overall.CONSTANT_DB_HR.Where("`ruleTypeId` = ?", menuCont.TypeId).Find(&lunXunShiXu)
if len(zuoXiTime) < 1 || len(lunXunShiXu) < 1 {
for _, v := range requestData.MonthAllDay {
var listSynv CalendarList
sendMonthList = append(sendMonthList, TimeHaveAry(v, listSynv.List))
}
publicmethod.Result(200, sendMonthList, c)
return
}
cycle := 1
for _, v := range lunXunShiXu {
cycle = v.Cycle
}
// val,_:=json.Marshal(menuCont)
// sendMa := publicmethod.MapOut[string]()
// sendMa["menuCont"] = menuCont
// sendMa["lunXunShiXu"] = lunXunShiXu
// sendMa["orgIdInt"] = orgIdInt
// publicmethod.Result(200, sendMa, c)
// return
//Step 4: 计算当前时间段与原点关系
switch cycle {
case 2:
//作息时间
var zuoXiTimeOne modelshr.WorkingTimePeriod
overall.CONSTANT_DB_HR.Where("`state` = 1 AND `type_id` = ?", menuCont.TypeId).Order("`sort` ASC").First(&zuoXiTimeOne)
for _, v := range requestData.MonthAllDay {
var listSynv CalendarList
inDate := menuCont.changBaiBan(v, zuoXiTimeOne, lunXunShiXu)
listSynv.List = append(listSynv.List, inDate)
sendMonthList = append(sendMonthList, TimeHaveAry(v, listSynv.List))
}
default:
lastDayNumber := 0
var starTemasTime publicmethod.DateTimeTotimes
starTemasTime.BaisStrToTime(menuCont.BegainTime)
for _, v := range requestData.MonthAllDay {
var listSynv CalendarList
for _, wv := range v {
var wvTimeAll publicmethod.DateTimeTotimes
wvTimeAll.BaisStrToTime(wv.Date)
if wvTimeAll.AllTime < starTemasTime.AllTime {
lastDayNumber++
} else if wvTimeAll.AllTime == starTemasTime.AllTime {
listAry := menuCont.RuleYuanDianRunNew(wv, wvTimeAll, zuoXiTime, lunXunShiXu)
inDate := publicmethod.MapOut[string]()
inDate[wv.Date] = listAry
listSynv.List = append(listSynv.List, inDate)
} else {
sjc := ((wvTimeAll.AllTime - starTemasTime.AllTime) / 86400) + 1
listAry := menuCont.SpecifyDateTeamsNew(wv, wvTimeAll, zuoXiTime, lunXunShiXu, sjc)
inDate := publicmethod.MapOut[string]()
inDate[wv.Date] = listAry
listSynv.List = append(listSynv.List, inDate)
}
}
sendMonthList = append(sendMonthList, TimeHaveAry(v, listSynv.List))
}
}
publicmethod.Result(0, sendMonthList, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2025-01-21 08:52:46
@ 功能: 原点日期排班设定
@ 参数
#dataInfo 当前日期属性
#timeVal 当天日期参数
#zuoXiTime 作息时间
#lunXunShiXu 轮询列表
#RedisKey说明 SchedulingTeam:StartingPoint_行政组织_年月日_倒班制度
@ 返回值
#logMap 当天安排
@ 方法原型
#
*/
func (g *GenesInfo) RuleYuanDianRunNew(dataInfo CalendarStructure, timeVal publicmethod.DateTimeTotimes, zuoXiTime []modelshr.WorkingTimePeriod, lunXunShiXu []modelshr.TeamsRules) (logMap []map[string]interface{}) {
dayRedisKey := fmt.Sprintf("SchedulingTeam:StartingPoint_%v_%v%v%v_%v_1", g.OrgId, timeVal.Years, timeVal.Months, timeVal.Days, g.TypeId)
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS2)
isTrue, logContent := redisClient.Get(dayRedisKey)
var dayTimeLog []teamlog.TeamsLog
if isTrue { //redis存在获取redis数据
json.Unmarshal([]byte(logContent), &logMap)
json.Unmarshal([]byte(logContent), &dayTimeLog)
// fmt.Printf("Step1: %v\n", logContent)
} else { //redis不存在从数据库中获取数据
overall.CONSTANT_DB_TeamsLog.Model(&teamlog.TeamsLog{}).Where("`orgId` = ? AND `years` = ? AND `months` = ? AND `days` = ? AND `ismId` = ?", g.OrgId, timeVal.Years, timeVal.Months, timeVal.Days, g.TypeId).Order("`sort` ASC").Find(&logMap)
if len(logMap) > 0 { //数据库中存在直接用数据的数据
redisClient.SetRedisTime(5256000)
jsonVal, _ := json.Marshal(logMap)
redisClient.Set(dayRedisKey, string(jsonVal))
json.Unmarshal([]byte(jsonVal), &dayTimeLog)
} else { //数据库中不存在开始计算
sort.Slice(zuoXiTime, func(i, j int) bool {
return zuoXiTime[i].StartTime < zuoXiTime[j].StartTime
})
for _, v := range zuoXiTime {
cyclesInfo := GainRuleCycleTeams(lunXunShiXu, 1, v.Id)
fmt.Printf("cyclesInfo--->%v\n", cyclesInfo)
var logInfo teamlog.TeamsLog
overall.CONSTANT_DB_TeamsLog.Where("`orgId` = ? AND `years` = ? AND `months` = ? AND `days` = ? AND `ismId` = ? AND `rankId` = ? AND `rulesId` = ? AND `teamsId` = ?", g.OrgId, timeVal.Years, timeVal.Months, timeVal.Days, g.TypeId, v.Id, cyclesInfo.TeamsId, cyclesInfo.TeamsId).Order("`sort` ASC").First(&logInfo)
if logInfo.Id == 0 {
logInfo.OrgId = g.OrgId //班组ID"`
logInfo.TeamsTime = timeVal.AllTime //日期"`
logInfo.IsmId = g.TypeId //制度ID"`
logInfo.RankId = v.Id //班次"`
logInfo.RulesId = cyclesInfo.TeamsId //轮询规则Id"`
logInfo.Days, _ = strconv.Atoi(timeVal.Days) //日"`
logInfo.Months, _ = strconv.Atoi(timeVal.Months) //月"`
logInfo.Years, _ = strconv.Atoi(timeVal.Years) //年"`
logInfo.Time = time.Now().Unix() //编辑时间"`
logInfo.IsmName = g.TypeName
logInfo.RankName = v.Name
logInfo.RulesName = cyclesInfo.TeamsName
logInfo.Sort = v.Sort
logInfo.TeamsId = cyclesInfo.TeamsId
logInfo.StartTime = v.StartTime
logInfo.EndTime = v.EndTime
overall.CONSTANT_DB_TeamsLog.Create(&logInfo)
}
dayTimeLog = append(dayTimeLog, logInfo)
jsonVal, _ := json.Marshal(logInfo)
valMap := publicmethod.MapOut[string]()
json.Unmarshal(jsonVal, &valMap)
logMap = append(logMap, valMap)
}
redisClient.SetRedisTime(5256000)
jsonVal, _ := json.Marshal(logMap)
redisClient.Set(dayRedisKey, string(jsonVal))
}
}
if len(dayTimeLog) > 0 {
allRulesLog = dayTimeLog[len(dayTimeLog)-1]
}
return
}
/*
*
@ 作者: 秦东
@ 时间: 2025-01-23 16:03:33
@ 功能: 获取轮询中的班组
#lunXunShiXu 轮询规则
#sort 第几步
#cycleWorkTime 工作段Id
*/
func GainRuleCycleTeams(lunXunShiXu []modelshr.TeamsRules, sort int64, cycleWorkTime int64) (cycleInfo modelshr.TeamsRules) {
fmt.Printf("\n\n\n\n\n 获取轮询中的班组---------sort:%v--------cycleWorkTime:%v----lunXunShiXu:%v--》\n\n\n\n\n ", sort, cycleWorkTime, lunXunShiXu)
for _, v := range lunXunShiXu {
if v.CycleSort == sort && v.CycleWorkTime == cycleWorkTime {
cycleInfo = v
}
}
return
}
/*
*
@ 作者: 秦东
@ 时间: 2025-01-23 16:27:05
@ 功能:
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (g *GenesInfo) SpecifyDateTeamsNew(dataInfo CalendarStructure, timeVal publicmethod.DateTimeTotimes, zuoXiTime []modelshr.WorkingTimePeriod, lunXunShiXu []modelshr.TeamsRules, differeTime int64) (logMap []map[string]interface{}) {
// differeTime = differeTime + 1
fmt.Printf("\n\n\n\n\ndataInfo---1---->%v---->%v---->%v\n\n\n\n\n", timeVal.Years, timeVal.Months, timeVal.Days)
dayRedisKey := fmt.Sprintf("SchedulingTeam:StartingPoint_%v_%v%v%v_%v_1", g.OrgId, timeVal.Years, timeVal.Months, timeVal.Days, g.TypeId)
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS2)
isTrue, logContent := redisClient.Get(dayRedisKey)
var dayTimeLog []teamlog.TeamsLog
// isTrue = false
if isTrue { //redis存在获取redis数据
json.Unmarshal([]byte(logContent), &logMap)
json.Unmarshal([]byte(logContent), &dayTimeLog)
// fmt.Printf("Step1: %v\n", logContent)
} else { //redis不存在从数据库中获取数据
var teamIdAry []int64
for _, v := range lunXunShiXu {
if !publicmethod.IsInTrue[int64](v.CycleWorkTime, teamIdAry) {
teamIdAry = append(teamIdAry, v.CycleWorkTime)
}
}
teamMap := make(map[int64][]modelshr.TeamsRules)
fmt.Printf("teanAry---3---->%v\n", teamIdAry)
for _, v := range teamIdAry {
var teanAry []modelshr.TeamsRules
for _, tv := range lunXunShiXu {
if v == tv.CycleWorkTime {
teanAry = append(teanAry, tv)
}
}
fmt.Printf("teanAry------->%v\n", teanAry)
if len(teanAry) > 0 {
teamMap[v] = append(teamMap[v], teanAry...)
}
fmt.Printf("teanAry---1---->%v\n", teamMap)
}
overall.CONSTANT_DB_TeamsLog.Model(&teamlog.TeamsLog{}).Where("`orgId` = ? AND `years` = ? AND `months` = ? AND `days` = ? AND `ismId` = ?", g.OrgId, timeVal.Years, timeVal.Months, timeVal.Days, g.TypeId).Order("`sort` ASC").Find(&logMap)
if len(logMap) > 0 { //数据库中存在直接用数据的数据
redisClient.SetRedisTime(5256000)
jsonVal, _ := json.Marshal(logMap)
redisClient.Set(dayRedisKey, string(jsonVal))
json.Unmarshal([]byte(jsonVal), &dayTimeLog)
} else { //数据库中不存在开始计算
sort.Slice(zuoXiTime, func(i, j int) bool {
return zuoXiTime[i].StartTime < zuoXiTime[j].StartTime
})
for _, v := range zuoXiTime {
var ruleStep int64 = 1
if workVal, isOk := teamMap[v.Id]; isOk {
lenNunm := len(workVal)
if differeTime > int64(lenNunm) {
ruleStep = int64(differeTime) % int64(lenNunm)
if ruleStep == 0 {
ruleStep = int64(lenNunm)
}
} else {
ruleStep = int64(differeTime)
}
fmt.Printf("\n\n\n\ncyclesInfo--->%v--->%v\n\n\n\n", lenNunm, differeTime)
}
cyclesInfo := GainRuleCycleTeams(lunXunShiXu, ruleStep, v.Id)
fmt.Printf("\n\n\n\ncyclesInfo--->%v--->%v\n\n\n\n", cyclesInfo, ruleStep)
var logInfo teamlog.TeamsLog
overall.CONSTANT_DB_TeamsLog.Where("`orgId` = ? AND `years` = ? AND `months` = ? AND `days` = ? AND `ismId` = ? AND `rankId` = ? AND `rulesId` = ? AND `teamsId` = ?", g.OrgId, timeVal.Years, timeVal.Months, timeVal.Days, g.TypeId, v.Id, cyclesInfo.TeamsId, cyclesInfo.TeamsId).Order("`sort` ASC").First(&logInfo)
if logInfo.Id == 0 {
logInfo.OrgId = g.OrgId //班组ID"`
logInfo.TeamsTime = timeVal.AllTime //日期"`
logInfo.IsmId = g.TypeId //制度ID"`
logInfo.RankId = v.Id //班次"`
logInfo.RulesId = cyclesInfo.TeamsId //轮询规则Id"`
logInfo.Days, _ = strconv.Atoi(timeVal.Days) //日"`
logInfo.Months, _ = strconv.Atoi(timeVal.Months) //月"`
logInfo.Years, _ = strconv.Atoi(timeVal.Years) //年"`
logInfo.Time = time.Now().Unix() //编辑时间"`
logInfo.IsmName = g.TypeName
logInfo.RankName = v.Name
logInfo.RulesName = cyclesInfo.TeamsName
logInfo.Sort = v.Sort
logInfo.TeamsId = cyclesInfo.TeamsId
logInfo.StartTime = v.StartTime
logInfo.EndTime = v.EndTime
overall.CONSTANT_DB_TeamsLog.Create(&logInfo)
}
dayTimeLog = append(dayTimeLog, logInfo)
jsonVal, _ := json.Marshal(logInfo)
valMap := publicmethod.MapOut[string]()
json.Unmarshal(jsonVal, &valMap)
logMap = append(logMap, valMap)
}
redisClient.SetRedisTime(5256000)
jsonVal, _ := json.Marshal(logMap)
redisClient.Set(dayRedisKey, string(jsonVal))
}
}
if len(dayTimeLog) > 0 {
allRulesLog = dayTimeLog[len(dayTimeLog)-1]
}
return
}
/*
*
@ 作者: 秦东
@ 时间: 2025-01-24 11:35:54
@ 功能:
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) AnalysisWeekRulers(c *gin.Context) {
var requestData AnZhouPaiBan
c.ShouldBindJSON(&requestData)
if requestData.OrgId == "" {
publicmethod.Result(1, requestData, c, "未知行政单位")
return
}
var sendMonthList interface{}
orgIdInt, _ := strconv.ParseInt(requestData.OrgId, 10, 64)
menuCont, cureeOrgId, err := CureeRunRules(orgIdInt)
fmt.Printf("%v\n", cureeOrgId)
if err != nil {
publicmethod.Result(200, sendMonthList, c)
return
}
//获取源点起始工作时间段
menuCont.BegainTime = publicmethod.UnixTimeToDay(menuCont.StartTime, 14)
menuCont.TypeIdStr = strconv.FormatInt(menuCont.TypeId, 10)
//获取倒班规则
var paiBanType modelshr.WorkTimeType
paiBanType.GetCont(map[string]interface{}{"`id`": menuCont.TypeId}, " `name`")
menuCont.TypeName = paiBanType.Name
//作息时间
var zuoXiTime []modelshr.WorkingTimePeriod
overall.CONSTANT_DB_HR.Where("`state` = 1 AND `type_id` = ?", menuCont.TypeId).Order("`sort` ASC").Find(&zuoXiTime)
//轮询规则
var lunXunShiXu []modelshr.TeamsRules
overall.CONSTANT_DB_HR.Where("`ruleTypeId` = ?", menuCont.TypeId).Find(&lunXunShiXu)
if len(zuoXiTime) < 1 || len(lunXunShiXu) < 1 {
var listSynv CalendarList
sendMonthList = TimeHaveAry(requestData.WeekAllDay, listSynv.List)
publicmethod.Result(200, sendMonthList, c)
return
}
cycle := 1
for _, v := range lunXunShiXu {
cycle = v.Cycle
}
var sendCont []CalendarStructure
switch cycle {
case 2:
var zuoXiTimeOne modelshr.WorkingTimePeriod
overall.CONSTANT_DB_HR.Where("`state` = 1 AND `type_id` = ?", menuCont.TypeId).Order("`sort` ASC").First(&zuoXiTimeOne)
var listSynv CalendarList
inDate := menuCont.changBaiBan(requestData.WeekAllDay, zuoXiTimeOne, lunXunShiXu)
listSynv.List = append(listSynv.List, inDate)
sendCont = TimeHaveAry(requestData.WeekAllDay, listSynv.List)
default:
lastDayNumber := 0
var starTemasTime publicmethod.DateTimeTotimes
starTemasTime.BaisStrToTime(menuCont.BegainTime)
var listSynv CalendarList
for _, wv := range requestData.WeekAllDay {
var wvTimeAll publicmethod.DateTimeTotimes
wvTimeAll.BaisStrToTime(wv.Date)
if wvTimeAll.AllTime < starTemasTime.AllTime {
lastDayNumber++
} else if wvTimeAll.AllTime == starTemasTime.AllTime {
listAry := menuCont.RuleYuanDianRunNew(wv, wvTimeAll, zuoXiTime, lunXunShiXu)
inDate := publicmethod.MapOut[string]()
inDate[wv.Date] = listAry
listSynv.List = append(listSynv.List, inDate)
} else {
sjc := ((wvTimeAll.AllTime - starTemasTime.AllTime) / 86400) + 1
listAry := menuCont.SpecifyDateTeamsNew(wv, wvTimeAll, zuoXiTime, lunXunShiXu, sjc)
inDate := publicmethod.MapOut[string]()
inDate[wv.Date] = listAry
listSynv.List = append(listSynv.List, inDate)
}
}
sendCont = TimeHaveAry(requestData.WeekAllDay, listSynv.List)
}
if len(sendCont) == 1 {
var onInfo CalendarStructure
for _, v := range sendCont {
onInfo = v
}
publicmethod.Result(0, onInfo, c)
return
}
sendMonthList = sendCont
publicmethod.Result(0, sendMonthList, c)
}