plugin
This commit is contained in:
parent
04b3d7cb57
commit
0161bb65a9
|
@ -3,8 +3,8 @@ package main
|
|||
import (
|
||||
"enterprise/common/config"
|
||||
"enterprise/common/global"
|
||||
_ "enterprise/plugin"
|
||||
"enterprise/server"
|
||||
_ "enterprise/service/salary_calculator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"enterprise/common/config"
|
||||
"enterprise/common/global"
|
||||
_ "enterprise/service/salary_calculator"
|
||||
_ "enterprise/plugin"
|
||||
"enterprise/worker"
|
||||
)
|
||||
|
||||
|
|
|
@ -22,14 +22,17 @@ func (d *ExternalCorpOrder) QueryOwnerOrder(owner string, startTime, endTime int
|
|||
tx := corpDB.Table(orderTable)
|
||||
|
||||
var o []*model.ExternalCorpOrder
|
||||
|
||||
tx.Where(orderTable+".status = ?", 2)
|
||||
if owner != "" {
|
||||
tx.Where("cp_user.username = ?", owner)
|
||||
}
|
||||
tx.Where(orderTable+".status = ?", 2)
|
||||
|
||||
tx.Where(orderTable+".pay_time >= ?", startTime)
|
||||
tx.Where(orderTable+".pay_time <= ?", endTime)
|
||||
if startTime > 0 {
|
||||
tx.Where(orderTable+".pay_time >= ?", startTime)
|
||||
}
|
||||
if endTime > 0 {
|
||||
tx.Where(orderTable+".pay_time <= ?", endTime)
|
||||
}
|
||||
|
||||
tx.Joins(fmt.Sprintf("LEFT JOIN cp_user ON %s.admin_id=cp_user.id", orderTable))
|
||||
tx = tx.Find(&o)
|
||||
|
|
|
@ -6,24 +6,35 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
salaryFactory map[string]SalaryCalculatorFactory
|
||||
salaryFactory map[string]SalaryFactory
|
||||
staffFactory map[string]StaffFactory
|
||||
)
|
||||
|
||||
func init() {
|
||||
salaryFactory = make(map[string]SalaryCalculatorFactory)
|
||||
salaryFactory = make(map[string]SalaryFactory)
|
||||
staffFactory = make(map[string]StaffFactory)
|
||||
}
|
||||
|
||||
type SalaryCalculator interface {
|
||||
type Salary interface {
|
||||
Calculate(salary *model.StaffSalary) map[string]interface{}
|
||||
}
|
||||
|
||||
type SalaryCalculatorFactory func(corp *model.Corp, user *model.StaffUser) SalaryCalculator
|
||||
type Staff interface {
|
||||
Monitor(user *model.StaffUser)
|
||||
}
|
||||
|
||||
func RegisterSalaryCalculator(key string, factory SalaryCalculatorFactory) {
|
||||
type SalaryFactory func(corp *model.Corp, user *model.StaffUser) Salary
|
||||
type StaffFactory func(corp *model.Corp) Staff
|
||||
|
||||
func RegisterSalary(key string, factory SalaryFactory) {
|
||||
salaryFactory[key] = factory
|
||||
}
|
||||
|
||||
func NewSalaryCalculator(corp *model.Corp, user *model.StaffUser) SalaryCalculator {
|
||||
func RegisterStaff(key string, factory StaffFactory) {
|
||||
staffFactory[key] = factory
|
||||
}
|
||||
|
||||
func NewSalary(corp *model.Corp, user *model.StaffUser) Salary {
|
||||
factory := salaryFactory[cast.ToString(corp.Id)+"_"+user.Username]
|
||||
if factory == nil {
|
||||
factory = salaryFactory[cast.ToString(corp.Id)]
|
||||
|
@ -33,3 +44,11 @@ func NewSalaryCalculator(corp *model.Corp, user *model.StaffUser) SalaryCalculat
|
|||
}
|
||||
return factory(corp, user)
|
||||
}
|
||||
|
||||
func NewStaff(corp *model.Corp) Staff {
|
||||
factory := staffFactory[cast.ToString(corp.Id)]
|
||||
if factory == nil {
|
||||
return nil
|
||||
}
|
||||
return factory(corp)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package plugin
|
||||
|
||||
import "enterprise/common/registry"
|
||||
|
||||
func init() {
|
||||
registry.RegisterSalary("1000", NewSalary1000)
|
||||
registry.RegisterSalary("1002", NewSalary1002)
|
||||
|
||||
registry.RegisterStaff("1000", NewStaff1000)
|
||||
registry.RegisterStaff("1002", NewStaff1002)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package salary_calculator
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"enterprise/common/dao"
|
||||
|
@ -14,19 +14,19 @@ const (
|
|||
SalaryCalculatorOperation = "operation" //运营计算工资的方法
|
||||
)
|
||||
|
||||
type SalaryCalculator1000 struct {
|
||||
type Salary1000 struct {
|
||||
corp *model.Corp
|
||||
user *model.StaffUser
|
||||
}
|
||||
|
||||
func NewSalaryCalculator1000(corp *model.Corp, user *model.StaffUser) registry.SalaryCalculator {
|
||||
return &SalaryCalculator1000{
|
||||
func NewSalary1000(corp *model.Corp, user *model.StaffUser) registry.Salary {
|
||||
return &Salary1000{
|
||||
corp: corp,
|
||||
user: user,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SalaryCalculator1000) Calculate(salary *model.StaffSalary) map[string]interface{} {
|
||||
func (s *Salary1000) Calculate(salary *model.StaffSalary) map[string]interface{} {
|
||||
monthTime, _ := time.ParseInLocation("200601", salary.Month, time.Local)
|
||||
|
||||
data := make(map[string]interface{})
|
||||
|
@ -37,7 +37,7 @@ func (s *SalaryCalculator1000) Calculate(salary *model.StaffSalary) map[string]i
|
|||
return data
|
||||
}
|
||||
|
||||
func (s *SalaryCalculator1000) getAdOwnerProfit(salary *model.StaffSalary) float64 {
|
||||
func (s *Salary1000) getAdOwnerProfit(salary *model.StaffSalary) float64 {
|
||||
monthTime, _ := time.ParseInLocation("200601", salary.Month, time.Local)
|
||||
startDay := monthTime.Format("2006-01-02")
|
||||
endDay := monthTime.AddDate(0, 1, -1).Format("2006-01-02")
|
||||
|
@ -55,7 +55,7 @@ func (s *SalaryCalculator1000) getAdOwnerProfit(salary *model.StaffSalary) float
|
|||
return totalProfit
|
||||
}
|
||||
|
||||
func (s *SalaryCalculator1000) getKctAppProfit(month string) float64 {
|
||||
func (s *Salary1000) getKctAppProfit(month string) float64 {
|
||||
|
||||
monthTime, _ := time.ParseInLocation("200601", month, time.Local)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package salary_calculator
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"enterprise/common/dao"
|
||||
|
@ -8,19 +8,19 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type SalaryCalculator1002 struct {
|
||||
type Salary1002 struct {
|
||||
corp *model.Corp
|
||||
user *model.StaffUser
|
||||
}
|
||||
|
||||
func NewSalaryCalculator1002(corp *model.Corp, user *model.StaffUser) registry.SalaryCalculator {
|
||||
return &SalaryCalculator1002{
|
||||
func NewSalary1002(corp *model.Corp, user *model.StaffUser) registry.Salary {
|
||||
return &Salary1002{
|
||||
corp: corp,
|
||||
user: user,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SalaryCalculator1002) Calculate(salary *model.StaffSalary) map[string]interface{} {
|
||||
func (s *Salary1002) Calculate(salary *model.StaffSalary) map[string]interface{} {
|
||||
data := make(map[string]interface{})
|
||||
|
||||
//离职人员考勤异常
|
|
@ -0,0 +1,52 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"enterprise/common/global"
|
||||
"enterprise/common/model"
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Staff struct {
|
||||
}
|
||||
|
||||
func (s *Staff) MonitorWorkAge(user *model.StaffUser) {
|
||||
nowDate := time.Now()
|
||||
entryDate, _ := time.ParseInLocation("2006-01-02", user.EntryDate, time.Local)
|
||||
OfficialDate, _ := time.ParseInLocation("2006-01-02", user.OfficialDate, time.Local)
|
||||
|
||||
entryMonth := (nowDate.Year()-entryDate.Year())*12 + int(nowDate.Month()) - int(entryDate.Month())
|
||||
officalDay := (OfficialDate.Unix() - nowDate.Unix()) / 86400
|
||||
log.Infof("staff[%s] entryDate[%s] spanMonth[%.1f]", user.Username, user.EntryDate, float64(entryMonth)/12.0)
|
||||
|
||||
salary := user.GetSalary()
|
||||
if nowDate.Day() == 1 && entryMonth%6 == 0 {
|
||||
message := make([]string, 0)
|
||||
message = append(message, fmt.Sprintf("【员工半年提醒】[%s]", user.Realname))
|
||||
message = append(message, fmt.Sprintf("入职时间:%s", user.EntryDate))
|
||||
message = append(message, fmt.Sprintf("入职年限:%.1f", float64(entryMonth)/12))
|
||||
message = append(message, fmt.Sprintf("基本工资:%s", salary.Base))
|
||||
message = append(message, fmt.Sprintf("绩效工资:%s", salary.Target))
|
||||
message = append(message, fmt.Sprintf("身份证号:%s", user.Idno))
|
||||
|
||||
if err := global.SendCorpMessage(user.CorpId, []string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
|
||||
log.Errorf("send message error :%s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if officalDay > 0 && officalDay <= 30 && officalDay%7 == 0 {
|
||||
message := make([]string, 0)
|
||||
message = append(message, fmt.Sprintf("【员工转正提醒】[%s]", user.Realname))
|
||||
message = append(message, fmt.Sprintf("入职时间:%s", user.EntryDate))
|
||||
message = append(message, fmt.Sprintf("转正时间:%s", user.OfficialDate))
|
||||
message = append(message, fmt.Sprintf("基本工资:%s", salary.Base))
|
||||
message = append(message, fmt.Sprintf("绩效工资:%s", salary.Target))
|
||||
message = append(message, fmt.Sprintf("身份证号:%s", user.Idno))
|
||||
|
||||
if err := global.SendCorpMessage(user.CorpId, []string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
|
||||
log.Errorf("send message error :%s", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"enterprise/common/model"
|
||||
"enterprise/common/registry"
|
||||
)
|
||||
|
||||
type Staff1000 struct {
|
||||
Staff
|
||||
corp *model.Corp
|
||||
}
|
||||
|
||||
func NewStaff1000(corp *model.Corp) registry.Staff {
|
||||
return &Staff1000{
|
||||
corp: corp,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Staff1000) Monitor(user *model.StaffUser) {
|
||||
s.MonitorWorkAge(user)
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"enterprise/common/dao"
|
||||
"enterprise/common/global"
|
||||
"enterprise/common/model"
|
||||
"enterprise/common/registry"
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Staff1002 struct {
|
||||
Staff
|
||||
corp *model.Corp
|
||||
}
|
||||
|
||||
func NewStaff1002(corp *model.Corp) registry.Staff {
|
||||
return &Staff1002{
|
||||
corp: corp,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Staff1002) Monitor(user *model.StaffUser) {
|
||||
s.MonitorWorkAge(user)
|
||||
|
||||
nowDate := time.Now()
|
||||
entryDate, _ := time.ParseInLocation("2006-01-02", user.EntryDate, time.Local)
|
||||
entryDay := (nowDate.Unix() - entryDate.Unix()) / 86400
|
||||
if entryDay != 20 && entryDay != 40 {
|
||||
return
|
||||
}
|
||||
|
||||
// 1.订单
|
||||
orders, err := dao.NewExternalCorpOrder().QueryOwnerOrder(user.Username, 0, 0)
|
||||
if err != nil {
|
||||
log.Errorf("db error:%s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
message := make([]string, 0)
|
||||
message = append(message, fmt.Sprintf("【员工试用期提醒】[%s]", user.Realname))
|
||||
message = append(message, fmt.Sprintf("入职时间:%s", user.EntryDate))
|
||||
message = append(message, fmt.Sprintf("入职天数:%d", entryDay))
|
||||
message = append(message, fmt.Sprintf("订单总数:%d", len(orders)))
|
||||
|
||||
global.SendCorpMessage(user.CorpId, []string{"jiangyong", "zhangping"}, strings.Join(message, "\n"))
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package salary_calculator
|
||||
|
||||
import "enterprise/common/registry"
|
||||
|
||||
func init() {
|
||||
registry.RegisterSalaryCalculator("1000", NewSalaryCalculator1000)
|
||||
registry.RegisterSalaryCalculator("1002", NewSalaryCalculator1002)
|
||||
}
|
|
@ -104,7 +104,7 @@ func (s *StaffSalary) CalcSalary(salary *model.StaffSalary, month, expr string)
|
|||
func (s *StaffSalary) calculate(corp *model.Corp, salary *model.StaffSalary, expression string) {
|
||||
|
||||
//获取业务数据
|
||||
dataFactory := registry.NewSalaryCalculator(corp, s.user)
|
||||
dataFactory := registry.NewSalary(corp, s.user)
|
||||
var biz interface{} = nil
|
||||
if dataFactory != nil {
|
||||
biz = dataFactory.Calculate(salary)
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"enterprise/common/dao"
|
||||
"enterprise/common/global"
|
||||
"enterprise/common/model"
|
||||
"enterprise/common/registry"
|
||||
"enterprise/service"
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
@ -19,53 +20,31 @@ func NewStaff() *Staff {
|
|||
return &Staff{}
|
||||
}
|
||||
func (s *Staff) MontorWorkAge(corpId int64) {
|
||||
corp, err := dao.NewCorpDao().Get(corpId)
|
||||
if err != nil {
|
||||
log.Errorf("db error :%s", err.Error())
|
||||
return
|
||||
}
|
||||
if corp == nil {
|
||||
log.Errorf("corp[%d] is nil", corpId)
|
||||
return
|
||||
}
|
||||
|
||||
staffs, _, err := dao.NewStaffUserDao().Query(1, -1, corpId, model.StaffUserStatusOnline, "", "", "", "")
|
||||
if err != nil {
|
||||
log.Errorf("db error :%s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
nowDate := time.Now()
|
||||
staffPlugin := registry.NewStaff(corp)
|
||||
|
||||
for _, staff := range staffs {
|
||||
//离职的忽略
|
||||
if staff.LeaveDate != "" {
|
||||
if staff.LeaveDate != "" || staff.Status != model.StaffUserStatusOnline {
|
||||
continue
|
||||
}
|
||||
|
||||
entryDate, _ := time.ParseInLocation("2006-01-02", staff.EntryDate, time.Local)
|
||||
OfficialDate, _ := time.ParseInLocation("2006-01-02", staff.OfficialDate, time.Local)
|
||||
|
||||
entryMonth := (nowDate.Year()-entryDate.Year())*12 + int(nowDate.Month()) - int(entryDate.Month())
|
||||
officalDay := (OfficialDate.Unix() - nowDate.Unix()) / 86400
|
||||
log.Infof("staff[%s] entryDate[%s] spanMonth[%.1f]", staff.Username, staff.EntryDate, float64(entryMonth)/12.0)
|
||||
|
||||
salary := staff.GetSalary()
|
||||
if nowDate.Day() == 1 && entryMonth%6 == 0 {
|
||||
message := make([]string, 0)
|
||||
message = append(message, fmt.Sprintf("【员工半年提醒】[%s]", staff.Realname))
|
||||
message = append(message, fmt.Sprintf("入职时间:%s", staff.EntryDate))
|
||||
message = append(message, fmt.Sprintf("入职年限:%.1f", float64(entryMonth)/12))
|
||||
message = append(message, fmt.Sprintf("基本工资:%s", salary.Base))
|
||||
message = append(message, fmt.Sprintf("绩效工资:%s", salary.Target))
|
||||
message = append(message, fmt.Sprintf("身份证号:%s", staff.Idno))
|
||||
|
||||
if err := global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
|
||||
log.Errorf("send message error :%s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if officalDay > 0 && officalDay <= 30 && officalDay%7 == 0 {
|
||||
message := make([]string, 0)
|
||||
message = append(message, fmt.Sprintf("【员工转正提醒】[%s]", staff.Realname))
|
||||
message = append(message, fmt.Sprintf("入职时间:%s", staff.EntryDate))
|
||||
message = append(message, fmt.Sprintf("转正时间:%s", staff.OfficialDate))
|
||||
message = append(message, fmt.Sprintf("基本工资:%s", salary.Base))
|
||||
message = append(message, fmt.Sprintf("绩效工资:%s", salary.Target))
|
||||
message = append(message, fmt.Sprintf("身份证号:%s", staff.Idno))
|
||||
|
||||
if err := global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
|
||||
log.Errorf("send message error :%s", err.Error())
|
||||
}
|
||||
if staffPlugin != nil {
|
||||
staffPlugin.Monitor(staff)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue