1494 lines
48 KiB
Go
1494 lines
48 KiB
Go
|
package oa
|
|||
|
|
|||
|
import (
|
|||
|
"context"
|
|||
|
"dubbo.apache.org/dubbo-go/v3/common/logger"
|
|||
|
"fmt"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/api/account"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/api/oa"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/api/rule"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/e"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/model/login"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/model/oa_model"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/serializer"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/service"
|
|||
|
account2 "github.com/fonchain_enterprise/fonchain-main/pkg/service/account"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/utils/holiday"
|
|||
|
"github.com/gin-gonic/gin"
|
|||
|
"github.com/jinzhu/copier"
|
|||
|
"math"
|
|||
|
"strconv"
|
|||
|
"strings"
|
|||
|
"time"
|
|||
|
)
|
|||
|
|
|||
|
/*
|
|||
|
考勤状态 出勤天数(实际打卡天数,有迟到、早退、正常打卡的,都算) 平均工时 休息( 总天数 - 出勤天数) 缺卡次数 补卡次数 迟到次数 早退次数 旷工 外勤 加班时长 请假次数
|
|||
|
参数 : 月份 ( 2023-01 )
|
|||
|
*/
|
|||
|
|
|||
|
func AttendanceCollectionV1(c *gin.Context) {
|
|||
|
req := oa_model.AttendanceCollectionReq{}
|
|||
|
if err := c.ShouldBind(&req); err != nil {
|
|||
|
logger.Errorf("AttendanceCollectionReq ShouldBind err", err)
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: err.Error(),
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
/* ES 操作 */
|
|||
|
//go es.BulkIndexAccountInfo(es.OaIndex)
|
|||
|
/* ES 操作 */
|
|||
|
|
|||
|
collectionRes := new(oa_model.AttendanceCollectionRes)
|
|||
|
collectionRes.Staffs = make([]oa_model.StaffCollection, 0)
|
|||
|
|
|||
|
// 获取 查询的 日期 列表
|
|||
|
month := req.Month
|
|||
|
if len(strings.Split(month, "-")) == 2 {
|
|||
|
month = month + "-25"
|
|||
|
}
|
|||
|
|
|||
|
// 查询 月份在 当前 月之后 则返回空
|
|||
|
if service.CheckMonthIsAfter(month) {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.GetMsg(e.SUCCESS),
|
|||
|
Data: collectionRes,
|
|||
|
Status: e.Ok,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
dates := make([]string, 0)
|
|||
|
//if req.Month == time.Now().Format("2006-01") {
|
|||
|
// dates = holiday.SplitDates(month, time.Now().Format("2006-01-02"), "2006-01-02")
|
|||
|
//} else {
|
|||
|
dates = holiday.SplitMonthV1(month, "2006-01-02")
|
|||
|
//}
|
|||
|
|
|||
|
var err error
|
|||
|
|
|||
|
if req.DepartmentName != "" || req.StaffName != "" || req.Status != 0 {
|
|||
|
oaMonthReq := new(oa.OaMonthReq)
|
|||
|
_ = copier.CopyWithOption(&oaMonthReq, req, copier.Option{DeepCopy: true})
|
|||
|
oaMonthReq.Page = 1
|
|||
|
oaMonthReq.PageSize = 99999
|
|||
|
oaMonthRes, err := service.GrpcOAImpl.QueryOaMonthInfoIsBatch(context.Background(), oaMonthReq)
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.ErrQueryOaMonth,
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
}
|
|||
|
for i := 0; i < len(oaMonthRes.OaMonths); i++ {
|
|||
|
if oaMonthRes.OaMonths[i].Status == true {
|
|||
|
collectionRes.FullAttendance += 1
|
|||
|
} else {
|
|||
|
collectionRes.Abnormal += 1
|
|||
|
}
|
|||
|
collectionRes.OutWorkTotal += oaMonthRes.OaMonths[i].OutWork
|
|||
|
collectionRes.MakeUpTotal += oaMonthRes.OaMonths[i].MakeUp
|
|||
|
|
|||
|
staffCollection := new(oa_model.StaffCollection)
|
|||
|
_ = copier.CopyWithOption(&staffCollection, oaMonthRes.OaMonths[i], copier.Option{DeepCopy: true})
|
|||
|
collectionRes.Staffs = append(collectionRes.Staffs, *staffCollection)
|
|||
|
}
|
|||
|
|
|||
|
goto end
|
|||
|
}
|
|||
|
|
|||
|
err = service.AttendanceCollectionHandleV1(collectionRes, month, dates)
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: err.Error(),
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
end:
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.GetMsg(e.SUCCESS),
|
|||
|
Data: collectionRes,
|
|||
|
Status: e.Ok,
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
func AttendanceCollectionV2(c *gin.Context) {
|
|||
|
req := oa.OaMonthReq{}
|
|||
|
if err := c.ShouldBind(&req); err != nil {
|
|||
|
logger.Errorf("AttendanceCollectionReq ShouldBind err", err)
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: err.Error(),
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
/* ES 操作 */
|
|||
|
//go es.BulkIndexAccountInfo(es.OaIndex)
|
|||
|
/* ES 操作 */
|
|||
|
|
|||
|
collectionRes := new(oa_model.AttendanceCollectionRes)
|
|||
|
collectionRes.Staffs = make([]oa_model.StaffCollection, 0)
|
|||
|
|
|||
|
oAMonth, err := service.GrpcOAImpl.QueryOaMonthInfoIsBatch(context.Background(), &req)
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.ErrQueryOaMonth,
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
oaMonthCollectionReq := new(oa.OaMonthReq)
|
|||
|
oaMonthCollectionReq.Month = req.Month
|
|||
|
oaMonthCollectionRes, err := service.GrpcOAImpl.QueryOaMonthInfoIsBatch(context.Background(), oaMonthCollectionReq)
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.ErrQueryOaMonth,
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
for i := 0; i < len(oAMonth.OaMonths); i++ {
|
|||
|
staffCollection := new(oa_model.StaffCollection)
|
|||
|
_ = copier.CopyWithOption(&staffCollection, oAMonth.OaMonths[i], copier.Option{DeepCopy: true})
|
|||
|
collectionRes.Staffs = append(collectionRes.Staffs, *staffCollection)
|
|||
|
}
|
|||
|
|
|||
|
if oAMonth.Total != 0 {
|
|||
|
collectionRes.Total = oAMonth.Total
|
|||
|
}
|
|||
|
|
|||
|
for i := 0; i < len(oaMonthCollectionRes.OaMonths); i++ {
|
|||
|
if oaMonthCollectionRes.OaMonths[i].Status == true {
|
|||
|
collectionRes.FullAttendance += 1
|
|||
|
} else {
|
|||
|
collectionRes.Abnormal += 1
|
|||
|
}
|
|||
|
collectionRes.OutWorkTotal += oaMonthCollectionRes.OaMonths[i].OutWork
|
|||
|
collectionRes.MakeUpTotal += oaMonthCollectionRes.OaMonths[i].MakeUp
|
|||
|
}
|
|||
|
|
|||
|
//go func(month string) {
|
|||
|
// saveCollectionRes := new(oa_model.AttendanceCollectionRes)
|
|||
|
// saveCollectionRes.Staffs = make([]oa_model.StaffCollection, 0)
|
|||
|
// err = service.AttendanceCollectionHandleV1(saveCollectionRes, month+"-25", holiday.SplitMonthV1(month+"-25", "2006-01-02"))
|
|||
|
// if err != nil {
|
|||
|
// logger.Errorf("AttendanceCollectionHandleV1 err is : %v", err.Error())
|
|||
|
// return
|
|||
|
// }
|
|||
|
//
|
|||
|
// batch := new(oa.SaveOaMonthIsBatch)
|
|||
|
// saveOaMonths := make([]*oa.OaMonth, 0)
|
|||
|
//
|
|||
|
// for i := 0; i < len(saveCollectionRes.Staffs); i++ {
|
|||
|
// saveOaMonth := new(oa.OaMonth)
|
|||
|
// err = copier.CopyWithOption(&saveOaMonth, saveCollectionRes.Staffs[i], copier.Option{DeepCopy: true})
|
|||
|
// if saveOaMonth.StaffUID == 89 {
|
|||
|
// fmt.Println("================================================== saveOaMonth ================================================== ")
|
|||
|
// fmt.Println("saveOaMonth.StaffUID is : ", saveOaMonth.StaffUID)
|
|||
|
// fmt.Printf("saveOaMonth is : %+v", saveOaMonth)
|
|||
|
// fmt.Println("================================================== saveOaMonth ================================================== ")
|
|||
|
// }
|
|||
|
// if err != nil {
|
|||
|
// logger.Error(" copier.CopyWithOption(&saveOaMonth, collectionRes.Staffs[i], copier.Option{DeepCopy: true}) err", err.Error())
|
|||
|
// return
|
|||
|
// }
|
|||
|
// saveOaMonth.Date = time.Now().Format("2006-01-02 15:04:05")
|
|||
|
// saveOaMonth.Month = month
|
|||
|
// saveOaMonth.PositionName = saveCollectionRes.Staffs[i].PositionName
|
|||
|
// saveOaMonth.DepartmentName = saveCollectionRes.Staffs[i].DepartmentName
|
|||
|
// saveOaMonths = append(saveOaMonths, saveOaMonth)
|
|||
|
// }
|
|||
|
// batch.OaMonths = saveOaMonths
|
|||
|
// saveRes, saveErr := service.GrpcOAImpl.SaveOaMonthInfoIsBatch(context.Background(), batch)
|
|||
|
// if saveErr != nil {
|
|||
|
// logger.Error(" SaveOaMonthInfoIsBatch interface err", saveErr.Error())
|
|||
|
// }
|
|||
|
//
|
|||
|
// if saveRes.Msg != "" {
|
|||
|
// logger.Error(" SaveOaMonthInfoIsBatch return err", saveRes.Msg)
|
|||
|
// }
|
|||
|
//
|
|||
|
//}(req.Month)
|
|||
|
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.GetMsg(e.SUCCESS),
|
|||
|
Data: collectionRes,
|
|||
|
Status: e.Ok,
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
func _AttendanceCollectionHandle(c *gin.Context, collectionRes *oa_model.AttendanceCollectionRes, month string) error {
|
|||
|
dates := holiday.SplitMonth(month, "2006-01-02")
|
|||
|
// 获取 员工 列表
|
|||
|
accountReq := new(account.ListRequest)
|
|||
|
accountReq.Domain = "fontree"
|
|||
|
accountReq.Page = 1
|
|||
|
accountReq.PageSize = 9999
|
|||
|
accountRes, err := service.AccountProvider.List(context.Background(), accountReq)
|
|||
|
if err != nil {
|
|||
|
//service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
// Msg: err.Error(),
|
|||
|
// Status: e.Failed,
|
|||
|
//})
|
|||
|
return err
|
|||
|
}
|
|||
|
|
|||
|
//查询部门
|
|||
|
puRequest := &rule.PositionUserListRequest{}
|
|||
|
puRes, err := service.RuleProvider.PositionUserList(context.Background(), puRequest)
|
|||
|
|
|||
|
if err != nil {
|
|||
|
//service.Error(c, e.Error, err)
|
|||
|
return err
|
|||
|
}
|
|||
|
|
|||
|
for i := 0; i < len(accountRes.Data); i++ {
|
|||
|
for j := 0; j < len(puRes.Data); j++ {
|
|||
|
if accountRes.Data[i].ID == puRes.Data[j].UserId {
|
|||
|
accountRes.Data[i].Positions = append(accountRes.Data[i].Positions, &account.PositionUser{PositionName: puRes.Data[j].DepartmentName})
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//holidayRes := make([]*holiday.RespData, 0)
|
|||
|
|
|||
|
// 获取 休息天数 总天数 - 工作天数 (注:周一到周五 法定调休 均为 工作日)
|
|||
|
holidayRes, err := holiday.GetMultiData(holiday.ConvertTime(dates[0]), holiday.ConvertTime(dates[len(dates)-1]), true)
|
|||
|
if err != nil {
|
|||
|
//service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
// Msg: err.Error(),
|
|||
|
// Status: e.Failed,
|
|||
|
//})
|
|||
|
return err
|
|||
|
}
|
|||
|
|
|||
|
// 获取 工作周期
|
|||
|
userInfo := login.GetUserInfoFromC(c)
|
|||
|
queryTimeOptions := make([]oa_model.QueryTimeOption, 0)
|
|||
|
for i := 0; i < len(userInfo.PositionUsers); i++ {
|
|||
|
queryTimeOption := oa_model.QueryTimeOption{
|
|||
|
PositionUID: strconv.FormatUint(userInfo.PositionUsers[i].PositionID, 10),
|
|||
|
DepartmentUID: strconv.FormatUint(userInfo.PositionUsers[i].DepartmentId, 10),
|
|||
|
}
|
|||
|
queryTimeOptions = append(queryTimeOptions, queryTimeOption)
|
|||
|
}
|
|||
|
startDay, endDay, err := service.WorkingTimeWeekBest(queryTimeOptions)
|
|||
|
if err != nil {
|
|||
|
fmt.Println("WorkDays err is :", err.Error())
|
|||
|
return err
|
|||
|
}
|
|||
|
|
|||
|
isWeek := make(map[int]int, 0)
|
|||
|
|
|||
|
for i := startDay; i <= endDay; i++ {
|
|||
|
isWeek[i] = i
|
|||
|
}
|
|||
|
|
|||
|
commonWorkDays := holiday.GetCommonWorkDays(holidayRes, isWeek)
|
|||
|
|
|||
|
restDays := len(holidayRes) - len(commonWorkDays)
|
|||
|
|
|||
|
fmt.Println("step ============================== 01 ============================== ")
|
|||
|
|
|||
|
outWorkDates := holiday.SplitMonth(month, "2006-01-02")
|
|||
|
|
|||
|
// 获取 每位员工的 信息
|
|||
|
for i := 0; i < len(accountRes.Data); i++ {
|
|||
|
collection := new(oa_model.StaffCollection)
|
|||
|
collection, err = service.StaffAttendanceCollectionHandleV2(accountRes.Data[i].ID, month, dates, restDays, []int32{e.ApprovalWorkStatusDoing, e.ApprovalWorkStatusOk, e.ApprovalWorkStatusFail}, outWorkDates)
|
|||
|
if err != nil {
|
|||
|
//service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
// Msg: err.Error(),
|
|||
|
// Status: e.Failed,
|
|||
|
//})
|
|||
|
return err
|
|||
|
}
|
|||
|
|
|||
|
if collection.OutWork != 0 {
|
|||
|
collectionRes.OutWorkTotal += collection.OutWork
|
|||
|
}
|
|||
|
|
|||
|
if collection.MakeUp != 0 {
|
|||
|
collectionRes.MakeUpTotal += 1
|
|||
|
}
|
|||
|
|
|||
|
if collection.Status {
|
|||
|
collectionRes.FullAttendance += 1
|
|||
|
} else {
|
|||
|
collectionRes.Abnormal += 1
|
|||
|
}
|
|||
|
|
|||
|
// 算旷工时 会把 休息日算上 所以 要 减去 休息日(基础)
|
|||
|
collection.MissDay = collection.MissDay - int32(restDays)
|
|||
|
|
|||
|
collection.StaffName = accountRes.Data[i].NickName
|
|||
|
|
|||
|
positionNames := make([]string, 0)
|
|||
|
|
|||
|
for j := 0; j < len(accountRes.Data[i].Positions); j++ {
|
|||
|
positionNames = append(positionNames, accountRes.Data[i].Positions[j].PositionName)
|
|||
|
}
|
|||
|
|
|||
|
collection.PositionName = strings.Join(positionNames, ",")
|
|||
|
|
|||
|
fmt.Printf("前 判断 collection info 内容: %+v", collection)
|
|||
|
fmt.Println()
|
|||
|
|
|||
|
if collection.Miss == 0 && collection.Late == 0 && collection.Before == 0 && collection.MissDay == 0 {
|
|||
|
fmt.Printf("后 判断 collection info 内容: %+v", collection)
|
|||
|
fmt.Println()
|
|||
|
collection.Status = true
|
|||
|
} else {
|
|||
|
collection.Status = false
|
|||
|
}
|
|||
|
|
|||
|
collectionRes.Staffs = append(collectionRes.Staffs, *collection)
|
|||
|
fmt.Println("step ============================== 03 ============================== ")
|
|||
|
fmt.Printf(" 请假 collection is : %+v \n", collection)
|
|||
|
fmt.Println("step ============================== 03 ============================== ")
|
|||
|
}
|
|||
|
|
|||
|
fmt.Println("step ============================== 04 ============================== ")
|
|||
|
|
|||
|
return nil
|
|||
|
}
|
|||
|
|
|||
|
// StaffAttendanceCollection
|
|||
|
// 数量统计
|
|||
|
func StaffAttendanceCollectionV1(c *gin.Context) {
|
|||
|
req := oa_model.AttendanceCollectionReq{}
|
|||
|
if err := c.ShouldBind(&req); err != nil {
|
|||
|
logger.Errorf("AttendanceCollectionReq ShouldBind err", err)
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: err.Error(),
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
userInfo := login.Info{}
|
|||
|
|
|||
|
if req.StaffUID == 0 {
|
|||
|
userInfo = login.GetUserInfoFromC(c)
|
|||
|
req.StaffUID = userInfo.ID
|
|||
|
} else {
|
|||
|
res, err := account2.GetUserInfoById(c, req.StaffUID, "")
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: err.Error(),
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
userInfo.ID = res.ID
|
|||
|
userInfo.PositionUsers = res.PositionUsers
|
|||
|
userInfo.NickName = res.NickName
|
|||
|
}
|
|||
|
|
|||
|
collection := new(oa_model.StaffCollection)
|
|||
|
|
|||
|
// 获取 查询的 日期 列表
|
|||
|
month := req.Month
|
|||
|
if len(strings.Split(month, "-")) == 2 {
|
|||
|
month = month + "-25"
|
|||
|
}
|
|||
|
|
|||
|
fmt.Println("month is :== ", month)
|
|||
|
|
|||
|
/*// 查询 月份在 当前 月之后 则返回空
|
|||
|
if checkMonthIsAfter(month) {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.GetMsg(e.SUCCESS),
|
|||
|
Data: collection,
|
|||
|
Status: e.Ok,
|
|||
|
})
|
|||
|
return
|
|||
|
}*/
|
|||
|
|
|||
|
dates := make([]string, 0)
|
|||
|
outWorkDates := make([]string, 0)
|
|||
|
//if req.Month == time.Now().Format("2006-01") {
|
|||
|
// dates = holiday.SplitDates(month, time.Now().Format("2006-01-02"), "2006-01-02")
|
|||
|
//} else {
|
|||
|
dates = holiday.SplitMonthV1(month, "2006-01-02")
|
|||
|
//}
|
|||
|
|
|||
|
outWorkDates = holiday.SplitMonthV1(month, "2006-01-02")
|
|||
|
|
|||
|
// 获取 休息天数 总天数 - 工作天数 (注:周一到周五 法定调休 均为 工作日)
|
|||
|
holidayRes, err := holiday.GetMultiData(holiday.ConvertTime(dates[0]), holiday.ConvertTime(dates[len(dates)-1]), true)
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.ErrQueryMultiData,
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
// 获取 工作周期
|
|||
|
queryTimeOptions := make([]oa_model.QueryTimeOption, 0)
|
|||
|
for i := 0; i < len(userInfo.PositionUsers); i++ {
|
|||
|
queryTimeOption := oa_model.QueryTimeOption{
|
|||
|
PositionUID: strconv.FormatUint(userInfo.PositionUsers[i].PositionID, 10),
|
|||
|
DepartmentUID: strconv.FormatUint(userInfo.PositionUsers[i].DepartmentId, 10),
|
|||
|
}
|
|||
|
queryTimeOptions = append(queryTimeOptions, queryTimeOption)
|
|||
|
}
|
|||
|
startDay, endDay, err := service.WorkingTimeWeekBest(queryTimeOptions)
|
|||
|
if err != nil {
|
|||
|
fmt.Println("WorkingTimeWeekBest err is :", err.Error())
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: err.Error(),
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
isWeek := make(map[int]int, 0)
|
|||
|
|
|||
|
for i := startDay; i <= endDay; i++ {
|
|||
|
isWeek[i] = i
|
|||
|
}
|
|||
|
|
|||
|
//commonWorkDays := holiday.GetCommonWorkDays(holidayRes, isWeek)
|
|||
|
|
|||
|
restDays := 0
|
|||
|
|
|||
|
for j := 0; j < len(holidayRes); j++ {
|
|||
|
if !holidayRes[j].IsToday {
|
|||
|
if holidayRes[j].Type != 0 {
|
|||
|
restDays++
|
|||
|
}
|
|||
|
} else {
|
|||
|
break
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
collection, err = service.StaffAttendanceCollectionHandleV2(req.StaffUID, month, dates, restDays, []int32{e.ApprovalWorkStatusOk}, outWorkDates)
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: err.Error(),
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if service.CheckMonthIsAfter(month) {
|
|||
|
collection.RestDays = 0
|
|||
|
}
|
|||
|
|
|||
|
// 算旷工时 会把 休息日算上 所以 要 减去 休息日
|
|||
|
//collection.MissDay = collection.MissDay - int32(restDays)
|
|||
|
|
|||
|
collection.StaffName = userInfo.NickName
|
|||
|
|
|||
|
positionNames := make([]string, 0)
|
|||
|
|
|||
|
for j := 0; j < len(userInfo.PositionUsers); j++ {
|
|||
|
positionNames = append(positionNames, userInfo.PositionUsers[j].PositionName)
|
|||
|
}
|
|||
|
|
|||
|
collection.PositionName = strings.Join(positionNames, ",")
|
|||
|
|
|||
|
//go func(saveCollection *oa_model.StaffCollection, saveMonth string) {
|
|||
|
//
|
|||
|
// if saveCollection == nil {
|
|||
|
// return
|
|||
|
// }
|
|||
|
//
|
|||
|
// batch := new(oa.SaveOaMonthIsBatch)
|
|||
|
// saveOaMonths := make([]*oa.OaMonth, 0)
|
|||
|
// saveOaMonth := new(oa.OaMonth)
|
|||
|
// err = copier.CopyWithOption(&saveOaMonth, saveCollection, copier.Option{DeepCopy: true})
|
|||
|
// saveOaMonth.Date = time.Now().Format("2006-01-02 15:04:05")
|
|||
|
// saveOaMonth.Month = saveMonth
|
|||
|
// saveOaMonths = append(saveOaMonths, saveOaMonth)
|
|||
|
// batch.OaMonths = saveOaMonths
|
|||
|
//
|
|||
|
// saveRes, saveErr := service.GrpcOAImpl.SaveOaMonthInfoIsBatch(context.Background(), batch)
|
|||
|
// if saveErr != nil {
|
|||
|
// logger.Error(" SaveOaMonthInfoIsBatch interface err", saveErr.Error())
|
|||
|
// }
|
|||
|
//
|
|||
|
// if saveRes.Msg != "" {
|
|||
|
// logger.Error(" SaveOaMonthInfoIsBatch return err", saveRes.Msg)
|
|||
|
// }
|
|||
|
//
|
|||
|
//}(collection, req.Month)
|
|||
|
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.GetMsg(e.SUCCESS),
|
|||
|
Data: collection,
|
|||
|
Status: e.Ok,
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
func _staffAttendanceCollectionHandle(staffUID uint64, month string, dates []string, restDays int) (collection *oa_model.StaffCollection, err error) {
|
|||
|
collection = new(oa_model.StaffCollection)
|
|||
|
collection, err = service.StaffCollectionClickInV2(staffUID, month, dates)
|
|||
|
if err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
|
|||
|
fmt.Println("step ============================== 02 ============================== ")
|
|||
|
fmt.Printf(" 打卡 collection is : %+v \n", collection)
|
|||
|
fmt.Println("step ============================== 02 ============================== ")
|
|||
|
|
|||
|
collection.RestDays = int32(restDays)
|
|||
|
|
|||
|
// oa 申请 请假 加班 调休
|
|||
|
applyReq := new(oa.ApplyRecordReq)
|
|||
|
applyReq.StaffUID = collection.StaffUID
|
|||
|
applyReq.ApplyType = []string{
|
|||
|
oa_model.TypeLeave, // 请假
|
|||
|
oa_model.TypeSick,
|
|||
|
oa_model.TypeAnnualLeave,
|
|||
|
oa_model.TypeMaritalLeave,
|
|||
|
oa_model.TypeMatingCheckLeave,
|
|||
|
oa_model.TypeMaternityLeave,
|
|||
|
oa_model.TypePaternityLeave,
|
|||
|
oa_model.TypeParentalLeave,
|
|||
|
oa_model.TypeNursingLeave,
|
|||
|
oa_model.TypeFuneralLeave,
|
|||
|
oa_model.TypeDayOff, // 调休
|
|||
|
oa_model.TypeOverTime, // 加班
|
|||
|
oa_model.TypeOutWork, // 外勤
|
|||
|
//oa_model.TypeMakeUp, // 补卡
|
|||
|
}
|
|||
|
applyReq.ApplyStatus = []int32{e.ApprovalWorkStatusOk}
|
|||
|
applyReq.BeginTime = dates[0]
|
|||
|
applyReq.EndTime = dates[len(dates)-1]
|
|||
|
applyReq.Page = 1
|
|||
|
applyReq.PageSize = 1000
|
|||
|
applyRes, err := service.GrpcOAImpl.QueryOaApply(context.Background(), applyReq)
|
|||
|
if err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
|
|||
|
for i := 0; i < len(applyRes.Data); i++ {
|
|||
|
if applyRes.Data[i].ApplyType == oa_model.TypeLeave ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypeSick ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypeAnnualLeave ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypeMaritalLeave ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypeMatingCheckLeave ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypeMaternityLeave ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypePaternityLeave ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypeParentalLeave ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypeNursingLeave ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypeFuneralLeave {
|
|||
|
collection.Leave += 1
|
|||
|
}
|
|||
|
|
|||
|
if applyRes.Data[i].ApplyType == oa_model.TypeDayOff {
|
|||
|
collection.DayOff += 1
|
|||
|
}
|
|||
|
if applyRes.Data[i].ApplyType == oa_model.TypeOverTime {
|
|||
|
collection.OverWork += applyRes.Data[i].Hours
|
|||
|
|
|||
|
// 判断 加班时间时候是 周末 如果是 则需要 在 工作日 +1 休息日 -1
|
|||
|
applyDate, err := holiday.GetSingleData(holiday.ConvertTime(applyRes.Data[i].ApplyTimes[0].Date), true)
|
|||
|
if err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
|
|||
|
if applyDate.Type != 0 {
|
|||
|
collection.RestDays -= 1
|
|||
|
collection.WorkDays += 1
|
|||
|
}
|
|||
|
}
|
|||
|
if applyRes.Data[i].ApplyType == oa_model.TypeOutWork {
|
|||
|
collection.OutWork += 1
|
|||
|
}
|
|||
|
//if applyRes.Data[i].ApplyType == oa_model.TypeMakeUp {
|
|||
|
// collection.MakeUp += 1
|
|||
|
//}
|
|||
|
}
|
|||
|
|
|||
|
fmt.Println("step ============================== 03 ============================== ")
|
|||
|
fmt.Printf(" 审批 collection is : %+v \n", collection)
|
|||
|
fmt.Println("step ============================== 03 ============================== ")
|
|||
|
|
|||
|
return collection, nil
|
|||
|
}
|
|||
|
|
|||
|
// StaffAttendanceCollectionDetail
|
|||
|
// 详情统计
|
|||
|
func StaffAttendanceCollectionDetailV1(c *gin.Context) {
|
|||
|
req := oa_model.AttendanceCollectionReq{}
|
|||
|
if err := c.ShouldBind(&req); err != nil {
|
|||
|
logger.Errorf("StaffAttendanceCollectionDetail ShouldBind err", err)
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: err.Error(),
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if req.StaffUID == 0 {
|
|||
|
userInfo := login.GetUserInfoFromC(c)
|
|||
|
|
|||
|
req.StaffUID = userInfo.ID
|
|||
|
}
|
|||
|
|
|||
|
collectionDetail := new(oa_model.CollectionDetailRes)
|
|||
|
|
|||
|
fmt.Println("step : ================================= 1 =================================")
|
|||
|
|
|||
|
// 获取 查询的 日期 列表
|
|||
|
month := req.Month
|
|||
|
if len(strings.Split(month, "-")) == 2 {
|
|||
|
month = month + "-01"
|
|||
|
}
|
|||
|
|
|||
|
// 查询 月份在 当前 月之后 则返回空
|
|||
|
if service.CheckMonthIsAfter(month) {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.GetMsg(e.SUCCESS),
|
|||
|
Data: collectionDetail,
|
|||
|
Status: e.Ok,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
dates := make([]string, 0)
|
|||
|
if req.Month == time.Now().Format("2006-01") {
|
|||
|
dates = holiday.SplitDates(month, time.Now().Format("2006-01-02"), "2006-01-02")
|
|||
|
} else {
|
|||
|
dates = holiday.SplitMonth(month, "2006-01-02")
|
|||
|
}
|
|||
|
|
|||
|
// 获取 休息天数 总天数 - 工作天数 (注:周一到周五 法定调休 均为 工作日)
|
|||
|
holidayRes, err := holiday.GetMultiData(holiday.ConvertTime(dates[0]), holiday.ConvertTime(dates[len(dates)-1]), true)
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.ErrQueryMultiData,
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
holidayMap := make(map[string]*holiday.RespData, 0)
|
|||
|
for i := 0; i < len(holidayRes); i++ {
|
|||
|
var (
|
|||
|
yearStr string
|
|||
|
dayStr string
|
|||
|
monthStr string
|
|||
|
)
|
|||
|
yearStr = strconv.Itoa(int(holidayRes[i].Year))
|
|||
|
if holidayRes[i].Day < 10 {
|
|||
|
dayStr = "0" + strconv.Itoa(int(holidayRes[i].Day))
|
|||
|
} else {
|
|||
|
dayStr = strconv.Itoa(int(holidayRes[i].Day))
|
|||
|
}
|
|||
|
if holidayRes[i].Month < 10 {
|
|||
|
monthStr = "0" + strconv.Itoa(int(holidayRes[i].Month))
|
|||
|
} else {
|
|||
|
monthStr = strconv.Itoa(int(holidayRes[i].Month))
|
|||
|
}
|
|||
|
holidayMap[yearStr+"-"+monthStr+"-"+dayStr] = holidayRes[i]
|
|||
|
if holidayRes[i].Type > 0 {
|
|||
|
collectionDetail.RestDays = append(collectionDetail.RestDays, oa_model.CommonInfo{
|
|||
|
Date: yearStr + "-" + monthStr + "-" + dayStr,
|
|||
|
Weekly: oa_model.WeekZhCN[holidayRes[i].WeekDay],
|
|||
|
})
|
|||
|
}
|
|||
|
}
|
|||
|
fmt.Println(holidayMap)
|
|||
|
|
|||
|
fmt.Println("step : ================================= 2 =================================")
|
|||
|
fmt.Println()
|
|||
|
|
|||
|
// 获取 oa 申请 信息
|
|||
|
applyReq := new(oa.ApplyRecordReq)
|
|||
|
applyReq.StaffUID = req.StaffUID
|
|||
|
applyReq.ApplyType = []string{
|
|||
|
oa_model.TypeLeave, // 请假
|
|||
|
oa_model.TypeSick,
|
|||
|
oa_model.TypeAnnualLeave,
|
|||
|
oa_model.TypeMaritalLeave,
|
|||
|
oa_model.TypeMatingCheckLeave,
|
|||
|
oa_model.TypeMaternityLeave,
|
|||
|
oa_model.TypePaternityLeave,
|
|||
|
oa_model.TypeParentalLeave,
|
|||
|
oa_model.TypeNursingLeave,
|
|||
|
oa_model.TypeFuneralLeave,
|
|||
|
oa_model.TypeDayOff, // 调休
|
|||
|
oa_model.TypeOverTime, // 加班
|
|||
|
oa_model.TypeOutWork, // 外勤
|
|||
|
oa_model.TypeMakeUp, // 补卡
|
|||
|
}
|
|||
|
applyReq.ApplyStatus = []int32{e.ApprovalWorkStatusOk}
|
|||
|
applyReq.BeginTime = dates[0]
|
|||
|
applyReq.EndTime = dates[len(dates)-1]
|
|||
|
applyReq.Page = 1
|
|||
|
applyReq.PageSize = 1000
|
|||
|
applyRes, err := service.GrpcOAImpl.QueryOaApply(context.Background(), applyReq)
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.ErrQueryOaApply,
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
fmt.Println("applyRes ============================ start ======================================")
|
|||
|
fmt.Printf("applyRes : %+v\n", applyRes)
|
|||
|
fmt.Println("applyRes ============================ end ======================================")
|
|||
|
fmt.Println()
|
|||
|
|
|||
|
fmt.Println("step : ================================= 3 =================================")
|
|||
|
fmt.Println()
|
|||
|
|
|||
|
makeUp := make([]oa_model.CommonInfo, 0)
|
|||
|
leave := make([]oa_model.CommonInfo, 0)
|
|||
|
dayOff := make([]oa_model.CommonInfo, 0)
|
|||
|
overWork := make([]oa_model.CommonInfo, 0)
|
|||
|
outWork := make([]oa_model.CommonInfo, 0)
|
|||
|
|
|||
|
for i := 0; i < len(applyRes.Data); i++ {
|
|||
|
commonInfo := oa_model.CommonInfo{}
|
|||
|
commonInfo.UUID = applyRes.Data[i].UUID
|
|||
|
commonInfo.Hours = applyRes.Data[i].Hours
|
|||
|
commonInfo.Days = applyRes.Data[i].Days
|
|||
|
commonInfo.LeaveType = applyRes.Data[i].ApplyType
|
|||
|
commonInfo.ApplyTimes = make([]*oa_model.ApplyTime, 0)
|
|||
|
|
|||
|
weeklys := make([]string, 0)
|
|||
|
for j := 0; j < len(applyRes.Data[i].ApplyTimes); j++ {
|
|||
|
at := &oa_model.ApplyTime{
|
|||
|
Date: applyRes.Data[i].ApplyTimes[j].Date,
|
|||
|
Hour: applyRes.Data[i].ApplyTimes[j].Hour,
|
|||
|
M: applyRes.Data[i].ApplyTimes[j].M,
|
|||
|
}
|
|||
|
commonInfo.ApplyTimes = append(commonInfo.ApplyTimes, at)
|
|||
|
fmt.Println("at.Date :", at.Date)
|
|||
|
fmt.Println("holidayMap[at.Date] :", holidayMap[at.Date])
|
|||
|
//fmt.Println("holidayMap[at.Date].WeekDay :", holidayMap[at.Date].WeekDay)
|
|||
|
if holidayMap[at.Date] != nil {
|
|||
|
weeklys = append(weeklys, oa_model.WeekZhCN[holidayMap[at.Date].WeekDay])
|
|||
|
} else {
|
|||
|
v, _ := holiday.GetCacheHolidayInfo([]string{strings.ReplaceAll(at.Date, "-", "")})
|
|||
|
if len(v) == 1 {
|
|||
|
weeklys = append(weeklys, oa_model.WeekZhCN[v[0].WeekDay])
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
if len(weeklys) == 1 {
|
|||
|
commonInfo.Weekly = weeklys[0]
|
|||
|
} else if len(weeklys) > 1 {
|
|||
|
commonInfo.Weekly = strings.Join(weeklys, " - ")
|
|||
|
}
|
|||
|
|
|||
|
//copier.CopyWithOption(&commonInfo.ApplyTimes, applyRes.Data[i].ApplyTimes, copier.Option{DeepCopy: true})
|
|||
|
if applyRes.Data[i].ApplyType == oa_model.TypeMakeUp {
|
|||
|
makeUp = append(makeUp, commonInfo)
|
|||
|
} else if applyRes.Data[i].ApplyType == oa_model.TypeOverTime {
|
|||
|
overWork = append(overWork, commonInfo)
|
|||
|
} else if applyRes.Data[i].ApplyType == oa_model.TypeDayOff {
|
|||
|
dayOff = append(dayOff, commonInfo)
|
|||
|
} else if applyRes.Data[i].ApplyType == oa_model.TypeOutWork {
|
|||
|
commonInfo.ApplyOutAddress = applyRes.Data[i].OutWorkAddress
|
|||
|
outWork = append(outWork, commonInfo)
|
|||
|
} else if applyRes.Data[i].ApplyType == oa_model.TypeLeave ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypeSick ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypeAnnualLeave ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypeMaritalLeave ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypeMatingCheckLeave ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypeMaternityLeave ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypePaternityLeave ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypeParentalLeave ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypeNursingLeave ||
|
|||
|
applyRes.Data[i].ApplyType == oa_model.TypeFuneralLeave {
|
|||
|
leave = append(leave, commonInfo)
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
fmt.Println("step : ================================= 4 =================================")
|
|||
|
fmt.Println()
|
|||
|
|
|||
|
collectionDetail.MakeUp = makeUp
|
|||
|
collectionDetail.Leave = leave
|
|||
|
collectionDetail.DayOff = dayOff
|
|||
|
collectionDetail.OverWork = overWork
|
|||
|
collectionDetail.OutWork = outWork
|
|||
|
|
|||
|
fmt.Println("collectionDetail ============================ start ======================================")
|
|||
|
fmt.Printf("collectionDetail : %+v\n", collectionDetail)
|
|||
|
fmt.Println("collectionDetail ============================ end ======================================")
|
|||
|
fmt.Println()
|
|||
|
|
|||
|
// 打卡 记录 查询 统计
|
|||
|
recordReq := new(oa.OARecordReq)
|
|||
|
recordReq.StaffUID = req.StaffUID
|
|||
|
recordReq.Dates = dates
|
|||
|
recordReq.Page = 1
|
|||
|
recordReq.PageSize = 9999
|
|||
|
recordRes, err := service.GrpcOAImpl.OARecord(context.Background(), recordReq)
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: err.Error(),
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
fmt.Println("recordRes ============================ start ======================================")
|
|||
|
fmt.Printf("recordRes : %+v\n", recordRes)
|
|||
|
fmt.Println("recordRes ============================ end ======================================")
|
|||
|
fmt.Println()
|
|||
|
|
|||
|
averageHour := make([]oa_model.CommonInfo, 0)
|
|||
|
workDays := make([]oa_model.CommonInfo, 0)
|
|||
|
miss := make([]oa_model.CommonInfo, 0)
|
|||
|
late := make([]oa_model.CommonInfo, 0)
|
|||
|
before := make([]oa_model.CommonInfo, 0)
|
|||
|
missDay := make([]oa_model.CommonInfo, 0)
|
|||
|
|
|||
|
for i := 0; i < len(recordRes.Data); i++ {
|
|||
|
var hours float64
|
|||
|
// 判断 是否是 旷工
|
|||
|
/*
|
|||
|
旷工: 考勤记录为空 且 workDate 为工作日
|
|||
|
考勤记录不为空 且 考勤记录均为 miss
|
|||
|
*/
|
|||
|
if len(recordRes.Data[i].Records) == 0 {
|
|||
|
res, err := holiday.GetSingleData(holiday.ConvertTime(recordRes.Data[i].WorkDate), true)
|
|||
|
fmt.Println("recordRes.Data[i].Records == nil ============================ start ======================================")
|
|||
|
fmt.Printf("recordRes.Data[i].Records == nil : %+v\n", res)
|
|||
|
fmt.Println("recordRes.Data[i].Records == nil err :", err)
|
|||
|
fmt.Println("recordRes.Data[i].Records == nil ============================ end ======================================")
|
|||
|
fmt.Println()
|
|||
|
if err == nil && res.Type == 0 {
|
|||
|
missDay = append(missDay, oa_model.CommonInfo{
|
|||
|
Date: recordRes.Data[i].WorkDate,
|
|||
|
Weekly: oa_model.WeekZhCN[holidayMap[recordRes.Data[i].WorkDate].WeekDay],
|
|||
|
Days: 1,
|
|||
|
})
|
|||
|
}
|
|||
|
continue
|
|||
|
}
|
|||
|
|
|||
|
isMissDay := 0
|
|||
|
for k := 0; k < len(recordRes.Data[i].Records); k++ {
|
|||
|
if recordRes.Data[i].Records[k].ActionType == oa_model.TypeMiss {
|
|||
|
isMissDay += 1
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if isMissDay == len(recordRes.Data[i].Records) {
|
|||
|
missDay = append(missDay, oa_model.CommonInfo{
|
|||
|
Date: recordRes.Data[i].WorkDate,
|
|||
|
Weekly: oa_model.WeekZhCN[holidayMap[recordRes.Data[i].WorkDate].WeekDay],
|
|||
|
Days: 1,
|
|||
|
})
|
|||
|
continue
|
|||
|
}
|
|||
|
// ========================= 旷工 ==========================================
|
|||
|
|
|||
|
for j := 0; j < len(recordRes.Data[i].Records); j = j + 2 {
|
|||
|
if recordRes.Data[i].Records[j].ActionType == oa_model.TypeLate {
|
|||
|
commonInfo := oa_model.CommonInfo{
|
|||
|
Date: recordRes.Data[i].WorkDate,
|
|||
|
Weekly: oa_model.WeekZhCN[holidayMap[recordRes.Data[i].WorkDate].WeekDay],
|
|||
|
Time: strings.Split(recordRes.Data[i].Records[j].ActionTime, " ")[1],
|
|||
|
}
|
|||
|
late = append(late, commonInfo)
|
|||
|
}
|
|||
|
if recordRes.Data[i].Records[j].ActionType == oa_model.TypeBefore {
|
|||
|
commonInfo := oa_model.CommonInfo{
|
|||
|
Date: recordRes.Data[i].WorkDate,
|
|||
|
Weekly: oa_model.WeekZhCN[holidayMap[recordRes.Data[i].WorkDate].WeekDay],
|
|||
|
Time: strings.Split(recordRes.Data[i].Records[j].ActionTime, " ")[1],
|
|||
|
}
|
|||
|
before = append(before, commonInfo)
|
|||
|
}
|
|||
|
if recordRes.Data[i].Records[j].ActionType == oa_model.TypeMiss {
|
|||
|
commonInfo := oa_model.CommonInfo{
|
|||
|
Date: recordRes.Data[i].WorkDate,
|
|||
|
Weekly: oa_model.WeekZhCN[holidayMap[recordRes.Data[i].WorkDate].WeekDay],
|
|||
|
Time: recordRes.Data[i].Records[j].WorkTime,
|
|||
|
}
|
|||
|
miss = append(miss, commonInfo)
|
|||
|
}
|
|||
|
|
|||
|
if j+1 >= len(recordRes.Data[i].Records) {
|
|||
|
break
|
|||
|
}
|
|||
|
|
|||
|
if recordRes.Data[i].Records[j+1].ActionType == oa_model.TypeMiss {
|
|||
|
commonInfo := oa_model.CommonInfo{
|
|||
|
Date: recordRes.Data[i].WorkDate,
|
|||
|
Weekly: oa_model.WeekZhCN[holidayMap[recordRes.Data[i].WorkDate].WeekDay],
|
|||
|
Time: recordRes.Data[i].Records[j+1].WorkTime,
|
|||
|
}
|
|||
|
miss = append(miss, commonInfo)
|
|||
|
}
|
|||
|
|
|||
|
fmt.Println("son step : ================================= 1 =================================")
|
|||
|
fmt.Println()
|
|||
|
|
|||
|
if recordRes.Data[i].Records[j+1].ActionType == oa_model.TypeLate {
|
|||
|
commonInfo := oa_model.CommonInfo{
|
|||
|
Date: recordRes.Data[i].WorkDate,
|
|||
|
Weekly: oa_model.WeekZhCN[holidayMap[recordRes.Data[i].WorkDate].WeekDay],
|
|||
|
Time: strings.Split(recordRes.Data[i].Records[j+1].ActionTime, " ")[1],
|
|||
|
}
|
|||
|
late = append(late, commonInfo)
|
|||
|
}
|
|||
|
|
|||
|
if recordRes.Data[i].Records[j+1].ActionType == oa_model.TypeBefore {
|
|||
|
commonInfo := oa_model.CommonInfo{
|
|||
|
Date: recordRes.Data[i].WorkDate,
|
|||
|
Weekly: oa_model.WeekZhCN[holidayMap[recordRes.Data[i].WorkDate].WeekDay],
|
|||
|
Time: strings.Split(recordRes.Data[i].Records[j+1].ActionTime, " ")[1],
|
|||
|
}
|
|||
|
before = append(before, commonInfo)
|
|||
|
}
|
|||
|
fmt.Println("son step : ================================= 2 =================================")
|
|||
|
fmt.Println()
|
|||
|
|
|||
|
// 判断是否是 缺卡 是 跳过
|
|||
|
if recordRes.Data[i].Records[j].ActionType == oa_model.TypeMiss || recordRes.Data[i].Records[j+1].ActionType == oa_model.TypeMiss {
|
|||
|
continue
|
|||
|
}
|
|||
|
fmt.Println("son step : ================================= 3 =================================")
|
|||
|
fmt.Println()
|
|||
|
|
|||
|
// 成对 出现
|
|||
|
var startTime time.Time
|
|||
|
var endTime time.Time
|
|||
|
startTime, _ = time.ParseInLocation("2006-01-02 15:04:05", recordRes.Data[i].Records[j].ActionTime+":00", time.Local)
|
|||
|
|
|||
|
endTime, _ = time.ParseInLocation("2006-01-02 15:04:05", recordRes.Data[i].Records[j+1].ActionTime+":00", time.Local)
|
|||
|
|
|||
|
hours = hours + endTime.Sub(startTime).Hours()
|
|||
|
fmt.Println("son step : ================================= 4 =================================")
|
|||
|
fmt.Println("计算时长 : ", j, hours)
|
|||
|
fmt.Println()
|
|||
|
}
|
|||
|
|
|||
|
if hours > 0 {
|
|||
|
averageHour = append(averageHour, oa_model.CommonInfo{
|
|||
|
Date: recordRes.Data[i].WorkDate,
|
|||
|
Weekly: oa_model.WeekZhCN[holidayMap[recordRes.Data[i].WorkDate].WeekDay],
|
|||
|
Hours: service.HandleHourLeaveFive(hours),
|
|||
|
})
|
|||
|
workDays = append(workDays, oa_model.CommonInfo{Date: recordRes.Data[i].WorkDate, Weekly: oa_model.WeekZhCN[holidayMap[recordRes.Data[i].WorkDate].WeekDay]})
|
|||
|
}
|
|||
|
|
|||
|
if hours == 0 && isMissDay != len(recordRes.Data[i].Records) {
|
|||
|
averageHour = append(averageHour, oa_model.CommonInfo{
|
|||
|
Date: recordRes.Data[i].WorkDate,
|
|||
|
Weekly: oa_model.WeekZhCN[holidayMap[recordRes.Data[i].WorkDate].WeekDay],
|
|||
|
Hours: 0,
|
|||
|
})
|
|||
|
workDays = append(workDays, oa_model.CommonInfo{Date: recordRes.Data[i].WorkDate, Weekly: oa_model.WeekZhCN[holidayMap[recordRes.Data[i].WorkDate].WeekDay]})
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
fmt.Println("step : ================================= 5 =================================")
|
|||
|
fmt.Println()
|
|||
|
|
|||
|
collectionDetail.AverageHour = averageHour
|
|||
|
collectionDetail.WorkDays = workDays
|
|||
|
collectionDetail.Late = late
|
|||
|
collectionDetail.Miss = miss
|
|||
|
collectionDetail.Before = before
|
|||
|
collectionDetail.MissDay = missDay
|
|||
|
|
|||
|
fmt.Println("collectionDetail ============================ start ======================================")
|
|||
|
fmt.Printf("collectionDetail : %+v\n", collectionDetail)
|
|||
|
fmt.Println("collectionDetail ============================ end ======================================")
|
|||
|
fmt.Println()
|
|||
|
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.GetMsg(e.SUCCESS),
|
|||
|
Data: collectionDetail,
|
|||
|
Status: e.Ok,
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
func StaffAttendanceCollectionDetailV2(c *gin.Context) {
|
|||
|
req := oa_model.AttendanceCollectionReq{}
|
|||
|
if err := c.ShouldBind(&req); err != nil {
|
|||
|
logger.Errorf("StaffAttendanceCollectionDetail ShouldBind err", err)
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: err.Error(),
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
userInfo := login.Info{}
|
|||
|
|
|||
|
if req.StaffUID == 0 {
|
|||
|
userInfo = login.GetUserInfoFromC(c)
|
|||
|
req.StaffUID = userInfo.ID
|
|||
|
} else {
|
|||
|
res, err := account2.GetUserInfoById(c, req.StaffUID, "")
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.ErrQueryUser,
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
userInfo.ID = res.ID
|
|||
|
userInfo.PositionUsers = res.PositionUsers
|
|||
|
userInfo.NickName = res.NickName
|
|||
|
}
|
|||
|
|
|||
|
collectionDetail := new(oa_model.CollectionDetailRes)
|
|||
|
|
|||
|
fmt.Println("step : ================================= 1 =================================")
|
|||
|
|
|||
|
// 获取 查询的 日期 列表
|
|||
|
month := req.Month
|
|||
|
if len(strings.Split(month, "-")) == 2 {
|
|||
|
month = month + "-25"
|
|||
|
}
|
|||
|
|
|||
|
/*// 查询 月份在 当前 月之后 则返回空
|
|||
|
if checkMonthIsAfter(month) {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.GetMsg(e.SUCCESS),
|
|||
|
Data: collectionDetail,
|
|||
|
Status: e.Ok,
|
|||
|
})
|
|||
|
return
|
|||
|
}*/
|
|||
|
|
|||
|
dates := make([]string, 0)
|
|||
|
outWorkDates := make([]string, 0)
|
|||
|
//if req.Month == time.Now().Format("2006-01") {
|
|||
|
// dates = holiday.SplitDates(month, time.Now().Format("2006-01-02"), "2006-01-02")
|
|||
|
//} else {
|
|||
|
dates = holiday.SplitMonthV1(month, "2006-01-02")
|
|||
|
//}
|
|||
|
outWorkDates = holiday.SplitMonthV1(month, "2006-01-02")
|
|||
|
|
|||
|
fmt.Println("========================================== dates ========================================== ")
|
|||
|
fmt.Printf("dates is :== %+v\n", dates)
|
|||
|
fmt.Println("========================================== dates ========================================== ")
|
|||
|
|
|||
|
var err error
|
|||
|
collectionDetail, err = service.StaffCollectionDetail(dates, req.StaffUID, outWorkDates)
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: err.Error(),
|
|||
|
Status: e.Ok,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.GetMsg(e.SUCCESS),
|
|||
|
Data: collectionDetail,
|
|||
|
Status: e.Ok,
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
/*
|
|||
|
出勤天数 平均工时 休息 缺卡 迟到 早退 旷工 外勤
|
|||
|
*/
|
|||
|
func _staffCollectionClickIn(staffUID uint64, month string, date []string) (collection *oa_model.StaffCollection, err error) {
|
|||
|
collection = new(oa_model.StaffCollection)
|
|||
|
|
|||
|
/*
|
|||
|
// 查询 统计记录
|
|||
|
collection, err = findCollection(staffUID, month)
|
|||
|
if err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
*/
|
|||
|
// 查询 考勤记录
|
|||
|
recordReq := new(oa.OARecordReq)
|
|||
|
recordReq.StaffUID = staffUID
|
|||
|
recordReq.Dates = date
|
|||
|
recordReq.Page = 1
|
|||
|
recordReq.PageSize = 9999
|
|||
|
recordRes, err := service.GrpcOAImpl.OARecord(context.Background(), recordReq)
|
|||
|
if err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
|
|||
|
var (
|
|||
|
totalHour float64 // 时长
|
|||
|
hourDay float64 // 用于 计算 平均工时
|
|||
|
workDays int32 // 用于 统计 考勤天数
|
|||
|
missDay int32 // 旷工次数
|
|||
|
outWork int32 // 外勤次数
|
|||
|
late int32 // 迟到次数
|
|||
|
before int32 // 早退次数
|
|||
|
miss int32 // 缺卡次数
|
|||
|
makeUp int32 // 补卡次数
|
|||
|
)
|
|||
|
|
|||
|
// 不计入 totalHour 的 不参与 平均工时计算
|
|||
|
for i := 0; i < len(recordRes.Data); i++ {
|
|||
|
// 缺卡 缺卡次数 和 考勤班次 次数一致 则 算旷工
|
|||
|
var (
|
|||
|
isMissDay bool = true
|
|||
|
//isWork bool = false
|
|||
|
//isOut bool = false
|
|||
|
//isLate bool = false
|
|||
|
//isBefore bool = false
|
|||
|
hours float64
|
|||
|
)
|
|||
|
|
|||
|
for j := 0; j < len(recordRes.Data[i].Records); j++ {
|
|||
|
// 用于 确认是否 旷工
|
|||
|
if recordRes.Data[i].Records[j].ActionType == oa_model.TypeMiss {
|
|||
|
miss += 1
|
|||
|
isMissDay = true
|
|||
|
//isWork = false
|
|||
|
} else {
|
|||
|
isMissDay = false
|
|||
|
//isWork = true
|
|||
|
}
|
|||
|
if recordRes.Data[i].Records[j].ActionType == oa_model.TypeOutWork {
|
|||
|
outWork += 1
|
|||
|
}
|
|||
|
if recordRes.Data[i].Records[j].ActionType == oa_model.TypeLate {
|
|||
|
late += 1
|
|||
|
}
|
|||
|
if recordRes.Data[i].Records[j].ActionType == oa_model.TypeBefore {
|
|||
|
before += 1
|
|||
|
}
|
|||
|
if recordRes.Data[i].Records[j].ActionType == oa_model.TypeMakeUp {
|
|||
|
makeUp += 1
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if isMissDay {
|
|||
|
missDay += 1
|
|||
|
} else {
|
|||
|
workDays += 1
|
|||
|
}
|
|||
|
|
|||
|
//fmt.Println("========================================== recordRes.Data[i].Records ========================================== ")
|
|||
|
//fmt.Printf("recordRes.Data[i].Records is : %+v \n", recordRes.Data[i].Records)
|
|||
|
//fmt.Println("========================================== recordRes.Data[i].Records =========================================== ")
|
|||
|
//fmt.Println()
|
|||
|
|
|||
|
// 统计工时 没有 完整的 上下班 打卡 记录 则 不计算 平均工时
|
|||
|
for j := 0; j < len(recordRes.Data[i].Records); j = j + 2 {
|
|||
|
|
|||
|
if j+1 >= len(recordRes.Data[i].Records) {
|
|||
|
break
|
|||
|
}
|
|||
|
|
|||
|
// 判断是否是 缺卡 是 跳过
|
|||
|
if recordRes.Data[i].Records[j].ActionType == oa_model.TypeMiss || recordRes.Data[i].Records[j+1].ActionType == oa_model.TypeMiss {
|
|||
|
continue
|
|||
|
}
|
|||
|
|
|||
|
// 成对 出现
|
|||
|
//now := time.Now().Format("2006-01-02")
|
|||
|
var startTime time.Time
|
|||
|
var endTime time.Time
|
|||
|
//if recordRes.Data[i].Records[j].ActionType != oa_model.TypeCommon {
|
|||
|
// startTime, _ = time.ParseInLocation("2006-01-02 15:04:05", now+" "+recordRes.Data[i].Records[j].WorkTime+":00", time.Local)
|
|||
|
//} else {
|
|||
|
startTime, _ = time.ParseInLocation("2006-01-02 15:04:05", recordRes.Data[i].Records[j].ActionTime+":00", time.Local)
|
|||
|
//}
|
|||
|
|
|||
|
//if recordRes.Data[i].Records[j+1].ActionType != oa_model.TypeCommon {
|
|||
|
// endTime, _ = time.ParseInLocation("2006-01-02 15:04:05", now+" "+recordRes.Data[i].Records[j+1].WorkTime+":00", time.Local)
|
|||
|
//} else {
|
|||
|
endTime, _ = time.ParseInLocation("2006-01-02 15:04:05", recordRes.Data[i].Records[j+1].ActionTime+":00", time.Local)
|
|||
|
//}
|
|||
|
|
|||
|
//fmt.Println("========================================== startTime endTime ========================================== ")
|
|||
|
//fmt.Println("startTime is : ", startTime)
|
|||
|
//fmt.Println("endTime is : ", endTime)
|
|||
|
//fmt.Println("========================================== startTime endTime ========================================== ")
|
|||
|
//fmt.Println()
|
|||
|
|
|||
|
hours = hours + endTime.Sub(startTime).Hours()
|
|||
|
//fmt.Println("========================================== hours ========================================== ")
|
|||
|
//fmt.Println("hours is : ", hours)
|
|||
|
//fmt.Println("========================================== hours ========================================== ")
|
|||
|
//fmt.Println()
|
|||
|
//j = j + 2
|
|||
|
}
|
|||
|
|
|||
|
if hours > 0 {
|
|||
|
hourDay += 1
|
|||
|
totalHour += hours
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
collection.StaffUID = staffUID
|
|||
|
collection.WorkDays = workDays
|
|||
|
collection.Miss = miss
|
|||
|
collection.MakeUp = makeUp
|
|||
|
collection.Late = late
|
|||
|
collection.Before = before
|
|||
|
collection.MissDay = missDay
|
|||
|
collection.OutWork = outWork
|
|||
|
|
|||
|
//fmt.Println("========================================== totalHour hourDay ========================================== ")
|
|||
|
//fmt.Println("totalHour is : ", totalHour)
|
|||
|
//fmt.Println("hourDay is : ", hourDay)
|
|||
|
//fmt.Println("========================================== totalHour hourDay = ========================================== ")
|
|||
|
//fmt.Println()
|
|||
|
|
|||
|
if totalHour != 0 && hourDay != 0 {
|
|||
|
averageHour, _ := strconv.ParseFloat(strconv.FormatFloat(math.Trunc(totalHour/hourDay*math.Pow10(1))/math.Pow10(1), 'f', -1, 64), 64)
|
|||
|
//fmt.Println("========================================== averageHour ========================================== ")
|
|||
|
//fmt.Println("averageHour is : ", averageHour)
|
|||
|
//fmt.Println("========================================== averageHour ========================================== ")
|
|||
|
//fmt.Println()
|
|||
|
collection.AverageHour = float32(averageHour)
|
|||
|
}
|
|||
|
|
|||
|
if collection.Miss != 0 || collection.Late != 0 || collection.Before != 0 || collection.MissDay != 0 {
|
|||
|
collection.Status = false
|
|||
|
}
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
func findCollection(staffUID uint64, month string) (collection *oa_model.StaffCollection, err error) {
|
|||
|
req := new(oa.OaMonthReq)
|
|||
|
req.StaffUID = append(req.StaffUID, staffUID)
|
|||
|
// 将 month 由 2023-01-01 -> 2023-01
|
|||
|
m, _ := time.ParseInLocation("2006-01-02", month, time.Local)
|
|||
|
req.Month = m.Format("2006-01")
|
|||
|
res, err := service.GrpcOAImpl.QueryOaMonthInfo(context.Background(), req)
|
|||
|
if err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
collection = new(oa_model.StaffCollection)
|
|||
|
copier.CopyWithOption(&collection, res, copier.Option{DeepCopy: true})
|
|||
|
return collection, nil
|
|||
|
}
|
|||
|
|
|||
|
// QueryAbnormal
|
|||
|
// 查询 异常 (审批未通过的 缺卡、迟到、早退的考勤记录)
|
|||
|
func QueryAbnormal(c *gin.Context) {
|
|||
|
req := oa_model.AbnormalReq{}
|
|||
|
if err := c.ShouldBind(&req); err != nil {
|
|||
|
logger.Errorf("AbnormalReq ShouldBind err", err)
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: err.Error(),
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if req.StaffUID == 0 {
|
|||
|
userInfo := login.GetUserInfoFromC(c)
|
|||
|
|
|||
|
//提交人
|
|||
|
req.StaffUID = userInfo.ID
|
|||
|
}
|
|||
|
|
|||
|
abnormals := make([]oa_model.AbnormalRes, 0)
|
|||
|
|
|||
|
applyReq := new(oa.ApplyRecordReq)
|
|||
|
applyReq.StaffUID = req.StaffUID
|
|||
|
applyReq.ApplyStartTime = req.StartDate + " 00:00:00"
|
|||
|
applyReq.ApplyEndTime = req.EndDate + " 23:59:59"
|
|||
|
//applyReq.Page = req.Page
|
|||
|
//applyReq.PageSize = req.PageSize
|
|||
|
applyReq.ApplyStatus = []int32{e.ApprovalWorkStatusFail}
|
|||
|
applyRes, err := service.GrpcOAImpl.QueryOaApply(context.Background(), applyReq)
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.ErrQueryOaApply,
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
for i := 0; i < len(applyRes.Data); i++ {
|
|||
|
abnormals = append(abnormals, oa_model.AbnormalRes{
|
|||
|
UUID: applyRes.Data[i].UUID,
|
|||
|
Date: applyRes.Data[i].ActionTime,
|
|||
|
AbnormalType: applyRes.Data[i].ApplyType,
|
|||
|
Description: "未通过",
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
abnormalRecordReq := new(oa.AbnormalRecordReq)
|
|||
|
abnormalRecordReq.StaffUID = req.StaffUID
|
|||
|
abnormalRecordReq.StartDate = req.StartDate
|
|||
|
abnormalRecordReq.EndDate = req.EndDate
|
|||
|
abnormalRecordReq.Page = 1
|
|||
|
abnormalRecordReq.PageSize = 9999
|
|||
|
abnormalRecordRes, err := service.GrpcOAImpl.AbnormalRecord(context.Background(), abnormalRecordReq)
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.ErrQueryAbnormalOaRecord,
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
for i := 0; i < len(abnormalRecordRes.Data); i++ {
|
|||
|
abnormals = append(abnormals, oa_model.AbnormalRes{
|
|||
|
UUID: abnormalRecordRes.Data[i].UUID,
|
|||
|
Date: abnormalRecordRes.Data[i].WorkDate + " " + abnormalRecordRes.Data[i].WorkTime,
|
|||
|
AbnormalType: abnormalRecordRes.Data[i].ActionType,
|
|||
|
Description: oa_model.TypeZhCN[abnormalRecordRes.Data[i].ActionType],
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.GetMsg(e.SUCCESS),
|
|||
|
Data: abnormals,
|
|||
|
Status: e.Ok,
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
func QueryOther(c *gin.Context) {
|
|||
|
req := oa.OtherRecordReq{}
|
|||
|
if err := c.ShouldBind(&req); err != nil {
|
|||
|
logger.Errorf("QueryOther ShouldBind err", err)
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: err.Error(),
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if req.Page == 0 {
|
|||
|
req.Page = 1
|
|||
|
}
|
|||
|
|
|||
|
if req.PageSize == 0 {
|
|||
|
req.PageSize = 99999
|
|||
|
}
|
|||
|
|
|||
|
res, err := service.GrpcOAImpl.OtherRecord(context.Background(), &req)
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.ErrQueryOaRecord,
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.GetMsg(e.SUCCESS),
|
|||
|
Data: res,
|
|||
|
Status: e.Ok,
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
/*
|
|||
|
用于 判断 oaMonth 中 生成数据时间 和 统计的月份 是否一致
|
|||
|
如果 一致 则 更新
|
|||
|
不一致 则 不更新
|
|||
|
*/
|
|||
|
|
|||
|
func checkMonthIsCurrent(month string) bool {
|
|||
|
queryMonth, _ := time.ParseInLocation("2006-01-02 15:04:05", month+" 00:00:00", time.Local)
|
|||
|
currentMonth, _ := time.ParseInLocation("2006-01-02 15:04:05", time.Now().Format("2006-01")+"-01"+" 00:00:00", time.Local)
|
|||
|
return queryMonth.Equal(currentMonth)
|
|||
|
}
|
|||
|
|
|||
|
// MakeUpNum
|
|||
|
// 查询 已补卡 及 剩余补卡次数
|
|||
|
func MakeUpNum(c *gin.Context) {
|
|||
|
|
|||
|
req := oa_model.MakeUpNumReq{}
|
|||
|
if err := c.ShouldBind(&req); err != nil {
|
|||
|
logger.Errorf("MakeUpNumReq ShouldBind err", err)
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: err.Error(),
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
// 补卡总数
|
|||
|
makeUpNumReq := oa.OaSettingReq{}
|
|||
|
makeUpNumReq.Keyword = e.MakeUpNum
|
|||
|
|
|||
|
makeUpNumRes, err := service.GrpcOAImpl.QueryOaSetting(context.Background(), &makeUpNumReq)
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.ErrQueryOaSetting,
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
totalNum := int64(makeUpNumRes.Data[len(makeUpNumRes.Data)-len(makeUpNumRes.Data)].Value.Num)
|
|||
|
|
|||
|
// 已使用 补卡次数
|
|||
|
makeUpUsedReq := new(oa.ApplyRecordReq)
|
|||
|
|
|||
|
userInfo := login.GetUserInfoFromC(c)
|
|||
|
makeUpUsedReq.StaffUID = userInfo.ID
|
|||
|
//makeUpUsedReq.StaffUID = 40
|
|||
|
|
|||
|
makeUpUsedReq.Page = 1
|
|||
|
makeUpUsedReq.Page = 9999
|
|||
|
makeUpUsedReq.ApplyStatus = []int32{e.ApprovalWorkStatusDoing, e.ApprovalWorkStatusOk}
|
|||
|
|
|||
|
// 当前月
|
|||
|
dates := make([]string, 0)
|
|||
|
if req.Month == "" {
|
|||
|
dates = holiday.SplitMonthV1(holiday.CurrentMonth()+"-25", "2006-01-02")
|
|||
|
} else {
|
|||
|
dates = holiday.SplitMonthV1(req.Month+"-25", "2006-01-02")
|
|||
|
}
|
|||
|
|
|||
|
makeUpUsedReq.BeginTime = dates[0]
|
|||
|
makeUpUsedReq.EndTime = dates[len(dates)-1]
|
|||
|
makeUpUsedReq.ApplyType = []string{e.MakeUp}
|
|||
|
|
|||
|
makeUpUsedRes, err := service.GrpcOAImpl.QueryOaApply(context.Background(), makeUpUsedReq)
|
|||
|
if err != nil {
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.ErrQueryOaApply,
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
temp := "%s - %s 已申请 %v 次补卡,剩余 %v 次"
|
|||
|
res := oa_model.MakeUpNumRes{}
|
|||
|
res.Num = totalNum - makeUpUsedRes.Total
|
|||
|
res.Title = fmt.Sprintf(temp, dates[0], dates[len(dates)-1], makeUpUsedRes.Total, totalNum-makeUpUsedRes.Total)
|
|||
|
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Data: res,
|
|||
|
Status: e.Ok,
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
func AttendanceCollectionTest(c *gin.Context) {
|
|||
|
req := oa_model.AttendanceCollectionReq{}
|
|||
|
if err := c.ShouldBind(&req); err != nil {
|
|||
|
logger.Errorf("AttendanceCollectionReq ShouldBind err", err)
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: err.Error(),
|
|||
|
Status: e.Failed,
|
|||
|
})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
saveCollectionRes := new(oa_model.AttendanceCollectionRes)
|
|||
|
saveCollectionRes.Staffs = make([]oa_model.StaffCollection, 0)
|
|||
|
err := service.AttendanceCollectionHandleV1(saveCollectionRes, req.Month, holiday.SplitMonthV1(req.Month+"-25", "2006-01-02"))
|
|||
|
if err != nil {
|
|||
|
logger.Errorf("AttendanceCollectionHandleV1 err is : %v", err.Error())
|
|||
|
}
|
|||
|
|
|||
|
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
|
|||
|
Msg: e.GetMsg(e.SUCCESS),
|
|||
|
Data: saveCollectionRes,
|
|||
|
Status: e.Ok,
|
|||
|
})
|
|||
|
}
|