- 添加部门新增、编辑、删除接口及逻辑实现 - 添加员工新增、编辑、启用、禁用、删除接口及逻辑实现 - 更新配置文件支持组织ID配置 - 初始化金蝶客户端连接配置 - 优化部门与员工数据查询结构 - 增加提交、审核、反审等业务流程处理 - 完善错误处理与日志记录机制
124 lines
3.4 KiB
Go
124 lines
3.4 KiB
Go
package ik3cloud
|
|
|
|
import (
|
|
"encoding"
|
|
"fmt"
|
|
"ik3cloud/app/config"
|
|
"ik3cloud/app/lib/ik3cloud"
|
|
"ik3cloud/app/lib/logger"
|
|
"ik3cloud/app/lib/rpcplugin"
|
|
"io"
|
|
"path"
|
|
"reflect"
|
|
"time"
|
|
|
|
config2 "git.kumo.work/shama/service/config"
|
|
|
|
"github.com/rcrowley/go-metrics"
|
|
"github.com/shopspring/decimal"
|
|
"github.com/smallnest/rpcx/server"
|
|
"github.com/vmihailenco/msgpack/v5"
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap/zapcore"
|
|
"gopkg.in/natefinch/lumberjack.v2"
|
|
)
|
|
|
|
// RegisterBinaryExt registers a binary marshaler/unmarshaler for the given type.
|
|
// The type must be implemented both interfaces.
|
|
func RegisterBinaryExt[T encoding.BinaryMarshaler, _ interface {
|
|
encoding.BinaryUnmarshaler
|
|
*T
|
|
}](extID int8) {
|
|
var zero T
|
|
msgpack.RegisterExtEncoder(extID, zero, func(e *msgpack.Encoder, v reflect.Value) ([]byte, error) {
|
|
m := v.Interface().(encoding.BinaryMarshaler)
|
|
return m.MarshalBinary()
|
|
})
|
|
msgpack.RegisterExtDecoder(extID, zero, func(d *msgpack.Decoder, v reflect.Value, extLen int) error {
|
|
u := v.Addr().Interface().(encoding.BinaryUnmarshaler)
|
|
b := make([]byte, extLen)
|
|
if err := d.ReadFull(b); err != nil {
|
|
return err
|
|
}
|
|
return u.UnmarshalBinary(b)
|
|
})
|
|
}
|
|
|
|
// InitApp 初始化
|
|
func InitApp() (closes []func()) {
|
|
// 关闭资源
|
|
closes = []func(){}
|
|
// 初始化配置文件
|
|
config.InitConfig(&config.IniConfig{
|
|
ConfigPath: "config",
|
|
RunModelErrAllow: true,
|
|
})
|
|
|
|
var levels []zapcore.Level
|
|
for _, level := range config.Config.Log.Levels {
|
|
levels = append(levels, zapcore.Level(level))
|
|
}
|
|
// 初始化日志
|
|
logger.InitLogger(&logger.LoggerConfig{
|
|
Levels: levels,
|
|
ShowLine: config.Config.Log.ShowLine,
|
|
LogInConsole: config.Config.Log.LogInConsole,
|
|
EncodeLevel: logger.LowercaseColorLevelEncoder,
|
|
Prefix: config.Config.Log.Prefix,
|
|
Writer: func(conf *logger.LoggerConfig, filename string, level zapcore.Level) io.Writer {
|
|
maxAge := config.Config.Log.MaxAge
|
|
maxSize := config.Config.Log.MaxSize
|
|
maxBackups := config.Config.Log.MaxBackups
|
|
if level == zapcore.ErrorLevel {
|
|
maxAge = 0
|
|
maxSize = 0
|
|
maxBackups = 0
|
|
}
|
|
return &lumberjack.Logger{
|
|
Filename: path.Join(config.Config.Log.Director, filename+".log"),
|
|
MaxAge: maxAge, // days
|
|
Compress: true, // disabled by default
|
|
MaxSize: maxSize,
|
|
MaxBackups: maxBackups,
|
|
}
|
|
},
|
|
})
|
|
|
|
// 初始化rpc服务
|
|
config2.InitConfig(config2.Config{
|
|
RegistryServer: config.Config.Server.RegistryServer,
|
|
})
|
|
|
|
// 注册序列化
|
|
RegisterBinaryExt[decimal.Decimal](1)
|
|
|
|
// 初始化金蝶
|
|
if _, err := ik3cloud.InitClient(&ik3cloud.Config{
|
|
Host: config.Config.Ik3cloud.Host,
|
|
AccountId: config.Config.Ik3cloud.AccountId,
|
|
Username: config.Config.Ik3cloud.Username,
|
|
AppId: config.Config.Ik3cloud.AppId,
|
|
AppSecret: config.Config.Ik3cloud.AppSecret,
|
|
LanguageId: config.Config.Ik3cloud.LanguageId,
|
|
}); err != nil {
|
|
logger.Logger.Fatal("金蝶初始化失败", zap.Error(err))
|
|
}
|
|
return
|
|
}
|
|
|
|
// AddRegistryPlugin @Title 注册中心
|
|
func AddRegistryPlugin(s *server.Server) {
|
|
r := &rpcplugin.ConsulRegisterPlugin{
|
|
ServiceAddress: fmt.Sprintf("tcp@%s:%d", config.Config.Server.Host, config.Config.Server.Port),
|
|
ConsulServers: config.Config.Server.RegistryServer,
|
|
BasePath: config.Config.Server.BasePath,
|
|
Metrics: metrics.NewRegistry(),
|
|
UpdateInterval: time.Minute,
|
|
}
|
|
err := r.Start()
|
|
if err != nil {
|
|
logger.Logger.Fatal("注册中心初始化失败", zap.Error(err))
|
|
}
|
|
s.Plugins.Add(r)
|
|
}
|