enterprise/server/service/calculator.go

46 lines
1.1 KiB
Go

package service
import (
"enterprise/common/dao"
"enterprise/server/api"
"enterprise/server/session"
CommonService "enterprise/service"
log "github.com/sirupsen/logrus"
"github.com/spf13/cast"
"time"
)
type Calculator struct {
}
func NewCalculator() *Calculator {
return &Calculator{}
}
func (c *Calculator) Test(sess *session.AdminSession, req *api.TestCalculatorReq) interface{} {
staffUser, err := dao.NewStaffUserDao().Get(cast.ToInt64(req.StaffId))
session.CheckDBError(err)
session.CheckNilError(staffUser, "员工不存在")
if staffUser.CorpId != sess.GetCorpId() {
panic("不要乱来")
}
salaryServ := CommonService.NewStaffSalary(staffUser)
salary, err := salaryServ.CalcSalary(nil, time.Now().AddDate(0, -1, 0).Format("200601"), req.Expression)
if err != nil {
log.Errorf("CalcSalary error :%s", err.Error())
panic(err.Error())
}
if salary == nil {
panic("没有工资")
}
apiSalary := new(api.Salary)
apiSalary.From(salary)
userSalary := staffUser.GetSalary()
apiSalary.Realname = staffUser.Realname
apiSalary.TargetSalary = userSalary.Target
apiSalary.BaseSalary = userSalary.Base
return apiSalary
}