config
This commit is contained in:
parent
1d7becb7c1
commit
cb1a1c6f42
|
@ -10,6 +10,7 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
config.LoadServerConfig()
|
config.LoadServerConfig()
|
||||||
config.LoadAliPay()
|
config.LoadAliPay()
|
||||||
|
config.LoadCorpConfig()
|
||||||
global.InitGlobal()
|
global.InitGlobal()
|
||||||
|
|
||||||
if err := server.Start(); err != nil {
|
if err := server.Start(); err != nil {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
config.LoadServerConfig()
|
config.LoadServerConfig()
|
||||||
config.LoadAliPay()
|
config.LoadAliPay()
|
||||||
|
config.LoadCorpConfig()
|
||||||
global.InitGlobal()
|
global.InitGlobal()
|
||||||
|
|
||||||
worker.InitCorp()
|
worker.InitCorp()
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/smbrave/goutil"
|
||||||
|
"github.com/spf13/cast"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
corpConfig map[int64]map[string]interface{}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
corpConfig = make(map[int64]map[string]interface{})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 配置优先级 环境变量>数据库配置>大于文件配置
|
||||||
|
func LoadCorpConfig() {
|
||||||
|
fileList, err := goutil.FileList("conf/corp/")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
filePath := "conf/corp/default.json"
|
||||||
|
cfgBody, _ := os.ReadFile(filePath)
|
||||||
|
defParams := make(map[string]interface{})
|
||||||
|
if err := json.Unmarshal(cfgBody, &defParams); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range fileList {
|
||||||
|
if !strings.HasSuffix(file, ".json") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
appId := cast.ToInt64(strings.TrimRight(file, ".json"))
|
||||||
|
filePath = fmt.Sprintf("conf/corp/%s", file)
|
||||||
|
cfgBody, _ = os.ReadFile(filePath)
|
||||||
|
p := make(map[string]interface{})
|
||||||
|
if err := json.Unmarshal(cfgBody, &p); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
allParmas := make(map[string]interface{})
|
||||||
|
for k, v := range defParams {
|
||||||
|
allParmas[k] = v
|
||||||
|
}
|
||||||
|
for k, v := range p {
|
||||||
|
allParmas[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("corpId[%d] config[%s]", appId, goutil.EncodeJSON(allParmas))
|
||||||
|
corpConfig[appId] = allParmas
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetCorpConfig(corpId int64, key string, def ...interface{}) interface{} {
|
||||||
|
|
||||||
|
if _, ok := corpConfig[corpId]; !ok {
|
||||||
|
if len(def) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return def[0]
|
||||||
|
}
|
||||||
|
cfg := corpConfig[corpId]
|
||||||
|
if v, ok := cfg[key]; ok {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(def) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return def[0]
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"staff_config": [
|
||||||
|
{
|
||||||
|
"name": "目标绩效",
|
||||||
|
"key": "target"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "社保扣除",
|
||||||
|
"key": "social_deduct"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "公积金扣除",
|
||||||
|
"key": "house_deduct"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"staff_config": [
|
||||||
|
{
|
||||||
|
"name": "目标绩效",
|
||||||
|
"key": "target"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "社保扣除",
|
||||||
|
"key": "social_deduct"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "公积金扣除",
|
||||||
|
"key": "house_deduct"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
{}
|
|
@ -20,7 +20,6 @@ type StaffUser struct {
|
||||||
EntryDate string `json:"entry_date"`
|
EntryDate string `json:"entry_date"`
|
||||||
OfficialDate string `json:"official_date"`
|
OfficialDate string `json:"official_date"`
|
||||||
LeaveDate string `json:"leave_date"`
|
LeaveDate string `json:"leave_date"`
|
||||||
Config string `json:"config"`
|
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
||||||
SalaryBase string `json:"salary_base"`
|
SalaryBase string `json:"salary_base"`
|
||||||
|
@ -31,6 +30,8 @@ type StaffUser struct {
|
||||||
PayeeBankName string `json:"payee_bank_name"`
|
PayeeBankName string `json:"payee_bank_name"`
|
||||||
PayeeBankCard string `json:"payee_bank_card"`
|
PayeeBankCard string `json:"payee_bank_card"`
|
||||||
PayeeApliayUid string `json:"payee_apliay_uid"`
|
PayeeApliayUid string `json:"payee_apliay_uid"`
|
||||||
|
|
||||||
|
Config interface{} `json:"config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type StaffListReq struct {
|
type StaffListReq struct {
|
||||||
|
@ -55,7 +56,6 @@ type StaffUpdateReq struct {
|
||||||
EntryDate string `json:"entry_date"`
|
EntryDate string `json:"entry_date"`
|
||||||
OfficialDate string `json:"official_date"`
|
OfficialDate string `json:"official_date"`
|
||||||
LeaveDate string `json:"leave_date"`
|
LeaveDate string `json:"leave_date"`
|
||||||
Config string `json:"config"`
|
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
||||||
SalaryBase string `json:"salary_base"`
|
SalaryBase string `json:"salary_base"`
|
||||||
|
@ -65,6 +65,8 @@ type StaffUpdateReq struct {
|
||||||
PayeeBankName string `json:"payee_bank_name"`
|
PayeeBankName string `json:"payee_bank_name"`
|
||||||
PayeeBankCard string `json:"payee_bank_card"`
|
PayeeBankCard string `json:"payee_bank_card"`
|
||||||
PayeeAlipayUid string `json:"payee_alipay_uid"`
|
PayeeAlipayUid string `json:"payee_alipay_uid"`
|
||||||
|
|
||||||
|
Config map[string]interface{} `json:"config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StaffUser) From(m *model.StaffUser) {
|
func (s *StaffUser) From(m *model.StaffUser) {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"enterprise/common/config"
|
||||||
"enterprise/common/dao"
|
"enterprise/common/dao"
|
||||||
"enterprise/server/api"
|
"enterprise/server/api"
|
||||||
"enterprise/server/service"
|
"enterprise/server/service"
|
||||||
|
@ -52,6 +54,9 @@ func (s *Staff) List(ctx *gin.Context) {
|
||||||
staffs, total, err := dao.NewStaffUserDao().Query(req.Page, req.Size, sess.GetCorpId(), cast.ToInt(req.Status), req.Username, req.Realname, req.Phone, req.Idno)
|
staffs, total, err := dao.NewStaffUserDao().Query(req.Page, req.Size, sess.GetCorpId(), cast.ToInt(req.Status), req.Username, req.Realname, req.Phone, req.Idno)
|
||||||
session.CheckDBError(err)
|
session.CheckDBError(err)
|
||||||
items := make([]*api.StaffUser, 0)
|
items := make([]*api.StaffUser, 0)
|
||||||
|
|
||||||
|
corpStaffConfig := cast.ToSlice(config.GetCorpConfig(sess.GetCorpId(), "staff_config", nil))
|
||||||
|
|
||||||
for _, st := range staffs {
|
for _, st := range staffs {
|
||||||
i := new(api.StaffUser)
|
i := new(api.StaffUser)
|
||||||
i.From(st)
|
i.From(st)
|
||||||
|
@ -59,6 +64,17 @@ func (s *Staff) List(ctx *gin.Context) {
|
||||||
if calculator != nil {
|
if calculator != nil {
|
||||||
i.SalaryCalculatorName = calculator.Name
|
i.SalaryCalculatorName = calculator.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// config
|
||||||
|
var staffConfig map[string]interface{}
|
||||||
|
json.Unmarshal([]byte(st.Config), &staffConfig)
|
||||||
|
config := make([]map[string]interface{}, 0)
|
||||||
|
for _, kv := range corpStaffConfig {
|
||||||
|
obj := cast.ToStringMap(kv)
|
||||||
|
obj["value"] = staffConfig[cast.ToString(obj["key"])]
|
||||||
|
config = append(config, obj)
|
||||||
|
}
|
||||||
|
i.Config = config
|
||||||
items = append(items, i)
|
items = append(items, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"enterprise/common/dao"
|
"enterprise/common/dao"
|
||||||
"enterprise/common/model"
|
"enterprise/common/model"
|
||||||
"enterprise/server/api"
|
"enterprise/server/api"
|
||||||
|
@ -103,7 +104,6 @@ func (s *StaffUser) Update(sess *session.AdminSession, req *api.StaffUpdateReq)
|
||||||
staffUser.Idno = goutil.If(req.Idno != "", req.Idno, staffUser.Idno)
|
staffUser.Idno = goutil.If(req.Idno != "", req.Idno, staffUser.Idno)
|
||||||
staffUser.EntryDate = goutil.If(req.EntryDate != "", req.EntryDate, staffUser.EntryDate)
|
staffUser.EntryDate = goutil.If(req.EntryDate != "", req.EntryDate, staffUser.EntryDate)
|
||||||
staffUser.OfficialDate = goutil.If(req.OfficialDate != "", req.OfficialDate, staffUser.OfficialDate)
|
staffUser.OfficialDate = goutil.If(req.OfficialDate != "", req.OfficialDate, staffUser.OfficialDate)
|
||||||
staffUser.Config = goutil.If(req.Config != "", req.Config, staffUser.Config)
|
|
||||||
|
|
||||||
staffSalary := staffUser.GetSalary()
|
staffSalary := staffUser.GetSalary()
|
||||||
staffSalary.Base = goutil.If(req.SalaryBase != "", req.SalaryBase, staffSalary.Base)
|
staffSalary.Base = goutil.If(req.SalaryBase != "", req.SalaryBase, staffSalary.Base)
|
||||||
|
@ -128,6 +128,15 @@ func (s *StaffUser) Update(sess *session.AdminSession, req *api.StaffUpdateReq)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(req.Config) != 0 {
|
||||||
|
var cfg map[string]interface{}
|
||||||
|
json.Unmarshal([]byte(staffUser.Config), &cfg)
|
||||||
|
for k, v := range req.Config {
|
||||||
|
cfg[k] = v
|
||||||
|
}
|
||||||
|
staffUser.Config = goutil.EncodeJSON(cfg)
|
||||||
|
}
|
||||||
|
|
||||||
err = dao.NewStaffUserDao().Update(staffUser)
|
err = dao.NewStaffUserDao().Update(staffUser)
|
||||||
session.CheckDBError(err)
|
session.CheckDBError(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue