staff_user

This commit is contained in:
jiangyong27 2025-04-02 15:46:39 +08:00
parent dbbdb8bd29
commit 9868bd0923
9 changed files with 176 additions and 6 deletions

View File

@ -26,7 +26,7 @@ type CorpConfig struct {
SocialDeduct string `json:"social_deduct"`
HouseDeduct string `json:"house_deduct"`
WorkerHouer string `json:"worker_houer"`
WorkerHour string `json:"worker_hour"`
}
type Corp struct {

View File

@ -1,6 +1,8 @@
package controller
import (
"bytes"
"encoding/json"
"enterprise/common/config"
"enterprise/common/dao"
"enterprise/common/model"
@ -10,6 +12,7 @@ import (
"github.com/gogap/errors"
log "github.com/sirupsen/logrus"
"github.com/smbrave/goutil"
"io"
"net/http"
"runtime"
"time"
@ -36,6 +39,22 @@ func (c *Base) Before(ctx *gin.Context) {
panic(config.ErrParam.New().Append(err))
}
//记录请求参数
ctx.Keys[session.ContextHeader] = header
if ctx.Request.Method == http.MethodPut || ctx.Request.Method == http.MethodPost {
bodyBytes, err := io.ReadAll(ctx.Request.Body)
if err != nil {
panic(config.ErrParam.New().Append(err))
}
defer ctx.Request.Body.Close()
bodyReader := bytes.NewReader(bodyBytes)
ctx.Request.Body = io.NopCloser(bodyReader)
var reqInf interface{}
json.Unmarshal(bodyBytes, &reqInf)
ctx.Keys[session.ContextRequest] = reqInf
}
if header.Token == "" { // 新用户没有extra所以extra中的配置不能对新用户生效
ctx.Keys[session.ContextSession] = session.NewAdminSession(&header, nil)
return

View File

@ -2,9 +2,12 @@ package controller
import (
"enterprise/common/config"
"enterprise/common/dao"
"enterprise/common/model"
"enterprise/server/api"
"enterprise/server/service"
"enterprise/server/session"
"enterprise/worker"
"github.com/gin-gonic/gin"
"github.com/spf13/cast"
"net/http"
@ -70,3 +73,22 @@ func (s *Salary) Delete(ctx *gin.Context) {
service.NewStaffSalary().Delete(ctx.Keys[session.ContextSession].(*session.AdminSession), id)
ctx.JSON(http.StatusOK, session.NewRspOk())
}
func (s *Salary) SyncStaffSalary(ctx *gin.Context) {
cid := cast.ToInt64(ctx.Query("cid"))
var err error
var corp *model.Corp
if cid != 0 {
corp, err = dao.NewCorpDao().Get(cid)
session.CheckDBError(err)
} else {
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
corp, err = dao.NewCorpDao().GetByHost(sess.GetHeader().Host)
session.CheckDBError(err)
}
session.CheckNilError(corp, "域名未绑定")
go new(worker.Staff).SyncStaffSalary(corp.Id, "")
ctx.JSON(http.StatusOK, session.NewRspOk())
}

View File

@ -30,6 +30,7 @@ func initRoutge(engine *gin.Engine) {
group.GET("/staff/salary", controller.NewStaff().Salary)
noTokenGroup.POST("/staff/login", controller.NewStaff().Login)
noTokenGroup.Any("/sync/salary", controller.NewSalary().SyncStaffSalary)
apiGroup.GET("/staff/salary", controller.NewSalary().List)
apiGroup.POST("/staff/salary", controller.NewSalary().Create)

View File

@ -136,7 +136,7 @@ func (a *Approve) handleVacation(detail *qyweixin.ApproveDetail, spStatus int) {
newData := new(model.ApprovalVacation)
newData.From(detail)
newData.CorpId = a.corp.Id
newData.VacationDuration = newData.VacationDuration / (float64(3600) * cast.ToFloat64(a.corp.GetConfig().WorkerHouer))
newData.VacationDuration = newData.VacationDuration / (float64(3600) * cast.ToFloat64(a.corp.GetConfig().WorkerHour))
dbDao := dao.NewApprovalVacationDao()
old, err := dbDao.GetBySpNo(a.corp.Id, detail.SpNo)

View File

@ -214,6 +214,7 @@ func (s *StaffSalary) getRealVacationDay(month string) (float64, float64) {
holiday := float64(0)
surplusHoliday := float64(0)
holidayMap := make(map[string]float64)
for _, vac := range approveVacations {
startTime, _ := time.ParseInLocation("2006-01-02 15:04:05", vac.VacationStartTime, time.Local)
endTime, _ := time.ParseInLocation("2006-01-02 15:04:05", vac.VacationEndTime, time.Local)
@ -224,8 +225,15 @@ func (s *StaffSalary) getRealVacationDay(month string) (float64, float64) {
} else {
holiday += vac.VacationDuration
//不是整天数,把剩余的算上
span := vac.VacationDuration - math.Floor(vac.VacationDuration)
surplusHoliday += goutil.If(math.Abs(span) < 0.000001, 0, 1-span)
if _, ok := holidayMap[vac.VacationDate]; !ok {
span := vac.VacationDuration - math.Floor(vac.VacationDuration)
if _, ok := holidayMap[vac.VacationDate]; !ok {
holidayMap[vac.VacationDate] = goutil.If(math.Abs(span) < 0.000001, 0, 1-span)
} else {
}
}
}
}
return holiday, surplusHoliday
@ -297,7 +305,7 @@ func (s *StaffSalary) getRealWorkDay(month string) float64 {
//其他按工作时长结算
if checkin.IsCheckin() {
shouldAttendHour := cast.ToFloat64(corp.GetConfig().WorkerHouer)
shouldAttendHour := cast.ToFloat64(corp.GetConfig().WorkerHour)
lackSecond := int64(float64(3600)*(1.5+shouldAttendHour)) - (checkin.EndTime - checkin.StartTime) //加上午休的1.5小时
if lackSecond > 0 {
lackHour := float64(lackSecond/3600 + 1) //按小时取整

View File

@ -0,0 +1,13 @@
package service
import "enterprise/common/model"
type StaffUserCheckin struct {
user *model.StaffUser
}
func NewStaffUserCheckin(user *model.StaffUser) *StaffUserCheckin {
return &StaffUserCheckin{
user: user,
}
}

View File

@ -0,0 +1,107 @@
package service
import (
"enterprise/common/dao"
"enterprise/common/model"
log "github.com/sirupsen/logrus"
"time"
)
type StaffUserVacation struct {
user *model.StaffUser
corp *model.Corp
month string
vacations []*model.ApprovalVacation
vacationsMap map[string]float64
}
func NewStaffUserVacation(corp *model.Corp, user *model.StaffUser, month string) *StaffUserVacation {
uv := &StaffUserVacation{
user: user,
corp: corp,
month: month,
vacationsMap: make(map[string]float64),
}
uv.loadArr()
uv.loadMaps()
return uv
}
func (v *StaffUserVacation) loadMaps() {
vacationMap := make(map[string]float64)
for _, vac := range v.vacations {
startTime, _ := time.ParseInLocation("2006-01-02 15:04:05", vac.VacationStartTime, time.Local)
endTime, _ := time.ParseInLocation("2006-01-02 15:04:05", vac.VacationEndTime, time.Local)
startDay := startTime.Format("2006-01-02")
endDay := endTime.Format("2006-01-02")
if startDay == endDay {
vacationMap[startDay] += vac.VacationDuration
continue
}
day := startTime.Format("2006-01-02")
for {
if day == startDay {
}
if day == endDay {
break
}
startTime = startTime.AddDate(0, 0, 1)
day = startTime.Format("2006-01-02")
}
}
//每天请假时长不超过1天
for k, duration := range vacationMap {
if duration > 1 {
vacationMap[k] = 1
}
}
v.vacationsMap = vacationMap
return
}
func (v *StaffUserVacation) loadArr() {
// 休假申请
approveVacations, err := dao.NewApprovalVacationDao().GetByUsername(v.user.CorpId, v.user.Username, v.month, "")
if err != nil {
log.Errorf("db error :%s", err.Error())
return
}
v.vacations = approveVacations
}
func (v *StaffUserVacation) GetTotalDay() float64 {
holiday := float64(0)
for _, vac := range v.vacations {
startTime, _ := time.ParseInLocation("2006-01-02 15:04:05", vac.VacationStartTime, time.Local)
endTime, _ := time.ParseInLocation("2006-01-02 15:04:05", vac.VacationEndTime, time.Local)
//同一天请假时长大于8小时算一天
if startTime.Format("2006-01-02") == endTime.Format("2006-01-02") && vac.VacationDuration > 1 {
holiday += 1
} else {
holiday += vac.VacationDuration
}
}
return holiday
}
func (v *StaffUserVacation) GetSurplusDay() float64 {
suplusDays := float64(0)
for _, duration := range v.vacationsMap {
if duration < 1 {
suplusDays += 1 - duration
}
}
return suplusDays
}

View File

@ -148,7 +148,7 @@ func (s *Approval) saveVacation(detail *qyweixin.ApproveDetail) {
newData := new(model.ApprovalVacation)
newData.CorpId = s.corp.Id
newData.From(detail)
newData.VacationDuration = newData.VacationDuration / (cast.ToFloat64(s.corpConfig.WorkerHouer) * float64(3600))
newData.VacationDuration = newData.VacationDuration / (cast.ToFloat64(s.corpConfig.WorkerHour) * float64(3600))
old, err := dbDao.GetBySpNo(s.corp.Id, detail.SpNo)
if err != nil {