Browse Source

更改自动读取配置文件设置

master
超级管理员 3 years ago
parent
commit
ff1309b6de
  1. 229
      api/version1/postseting/postpc/targetpost.go
  2. 31
      api/version1/postseting/postpc/type.go
  3. 20
      apirouter/v1/postseting/pc.go
  4. 6
      config/configDatabase/database.yaml
  5. 6
      initialization/app/run.go
  6. 6
      initialization/databaseinit/mysql.go
  7. 13
      initialization/initviper/init_viper.go
  8. 18
      initialization/initviper/initreload.go
  9. 6
      initialization/nosql/redis.go

229
api/version1/postseting/postpc/targetpost.go

@ -49,7 +49,7 @@ func (a *ApiMethod) GetPostTarget(c *gin.Context) {
sendData.ScoringMethod = postTargetCont.ScoringMethod //计分方式(1:自动;2:手动)"`
sendData.VisibleRange = postTargetCont.VisibleRange //可见范围"`
sendData.VisibleGroup = postTargetCont.VisibleGroup //可见范围(集团)"`
_, sendData.RelevantPostsMan, _ = getTargetAboutPost(postTargetCont.ReleDepart, postTargetCont.Dimension, postTargetCont.Id)
_, sendData.RelevantPostsMan, _ = getTargetAboutPost(postTargetCont.ReleDepart, postTargetCont.Dimension, postTargetCont.Id, 2)
publicmethod.Result(0, sendData, c)
}
@ -58,14 +58,17 @@ func (a *ApiMethod) GetPostTarget(c *gin.Context) {
@departmentId 部门Id
@dimensionId 维度
@targetId 指标
@level 级别1部门级2岗位级
func getTargetAboutPost(departmentId, dimensionId, targetId int64, level int) (postId []int64, postPeopleList []postPeople, err error)
*/
func getTargetAboutPost(departmentId, dimensionId, targetId int64) (postId []int64, postPeopleList []postPeople, err error) {
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`post_id`").Where("`state` = 1 AND `level` = 2 AND `department_id` = ? AND `dimension_id` = ? AND `target_id` = ?").Find(&postId).Error
func getTargetAboutPost(departmentId, dimensionId, targetId int64, level int) (postId []int64, postPeopleList []postPeople, err error) {
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`post_id`").Where("`state` = 1 AND `level` = ? AND `department_id` = ? AND `dimension_id` = ? AND `target_id` = ?", level, departmentId, dimensionId, targetId).Find(&postId).Error
if len(postId) > 0 {
for i := 0; i < len(postId); i++ {
var postmanCont postPeople
postmanCont.Id = strconv.FormatInt(postId[i], 10)
_, postmanCont.Operator, _ = getTargetAboutPostMan(departmentId, postId[i], dimensionId, targetId)
_, postmanCont.Operator, _ = getTargetAboutPostMan(departmentId, postId[i], dimensionId, targetId, level)
postPeopleList = append(postPeopleList, postmanCont)
}
}
@ -78,9 +81,10 @@ func getTargetAboutPost(departmentId, dimensionId, targetId int64) (postId []int
@postid 岗位
@dimensionId 维度
@targetId 指标
@level 级别1部门级2岗位级
*/
func getTargetAboutPostMan(departmentId, postid, dimensionId, targetId int64) (peopleId []int64, postPeople []string, err error) {
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("`man_key`").Where("`state` = 1 AND `type` = 2 AND `department_id` = ? AND `post_id` = ? AND `dimension_id` = ? AND `target_id` = ?").Find(&peopleId).Error
func getTargetAboutPostMan(departmentId, postid, dimensionId, targetId int64, level int) (peopleId []int64, postPeople []string, err error) {
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("`man_key`").Where("`state` = 1 AND `type` = ? AND `department_id` = ? AND `post_id` = ? AND `dimension_id` = ? AND `target_id` = ?", level, departmentId, postid, dimensionId, targetId).Find(&peopleId).Error
if len(peopleId) > 0 {
for i := 0; i < len(peopleId); i++ {
postPeople = append(postPeople, strconv.FormatInt(peopleId[i], 10))
@ -270,3 +274,216 @@ func EditTargetTableDimenAboutPostOfDepart(dimensionId, targetId, targetSunId, b
}
}
}
// 编辑岗位指标
func (a *ApiMethod) EditPostTarget(c *gin.Context) {
var receivedValue editPostTargetCont
c.ShouldBindJSON(&receivedValue)
if receivedValue.Id == "" {
publicmethod.Result(1, receivedValue, c, "参数错误!")
return
}
where := publicmethod.MapOut[string]()
where["`id`"] = receivedValue.Id
var postTargetCont modelskpi.PostTarget
err := postTargetCont.GetCont(where)
if err != nil {
publicmethod.Result(107, err, c)
return
}
saveData := publicmethod.MapOut[string]()
if receivedValue.Title != "" && receivedValue.Title != postTargetCont.Title {
saveData["title"] = receivedValue.Title
}
if receivedValue.Type != 0 && receivedValue.Type != postTargetCont.Type {
saveData["type"] = receivedValue.Type
}
if receivedValue.ScoringMethod != 0 && receivedValue.ScoringMethod != postTargetCont.ScoringMethod {
saveData["scoring_method"] = receivedValue.ScoringMethod
}
if receivedValue.RelevantDepartments != "" {
departmentId, _ := strconv.ParseInt(receivedValue.RelevantDepartments, 10, 64)
if departmentId != postTargetCont.ReleDepart {
saveData["rele_depart"] = departmentId
}
}
if receivedValue.Dimension != "" {
dimensionId, _ := strconv.ParseInt(receivedValue.Dimension, 10, 64)
if dimensionId != postTargetCont.Dimension {
saveData["dimension"] = dimensionId
}
}
if receivedValue.Unit != "" && receivedValue.Unit != postTargetCont.Unit {
saveData["unit"] = receivedValue.Unit
}
if receivedValue.Cycle != 0 && receivedValue.Cycle != postTargetCont.Cycle {
saveData["cycle"] = receivedValue.Cycle
}
if receivedValue.CycleAttr != 0 && receivedValue.CycleAttr != postTargetCont.Cycleattr {
saveData["cycleattr"] = receivedValue.CycleAttr
}
if len(receivedValue.VisibleRange) > 0 {
visibleRangeStr := strings.Join(receivedValue.VisibleRange, ",")
if visibleRangeStr != postTargetCont.VisibleRange {
saveData["visible_range"] = visibleRangeStr
}
}
if len(receivedValue.VisibleGroup) > 0 {
visibleGroupStr := strings.Join(receivedValue.VisibleGroup, ",")
if visibleGroupStr != postTargetCont.VisibleGroup {
saveData["visible_group"] = visibleGroupStr
}
}
//获取岗位与提报人
var departAny []string
var peopletAny []string
for _, v := range receivedValue.RelevantPostsMan {
if publicmethod.IsInTrue[string](v.Id, departAny) == false {
departAny = append(departAny, v.Id)
}
if len(v.Operator) > 0 {
for _, ov := range v.Operator {
if publicmethod.IsInTrue[string](ov, peopletAny) == false {
peopletAny = append(peopletAny, ov)
}
}
}
}
if len(departAny) > 0 {
departPostStr := strings.Join(departAny, ",")
if departPostStr != postTargetCont.DepartmentsPost {
saveData["departments_post"] = departPostStr
//关联部门岗位
if len(departAny) > 0 {
syncSetinges.Add(1)
go EditTargetTableDimenAboutPostOfDepart(postTargetCont.Dimension, postTargetCont.Id, 0, 0, postTargetCont.ReleDepart, departAny, 2, postTargetCont.Type)
}
}
}
if len(peopletAny) > 0 {
reportStr := strings.Join(peopletAny, ",")
if reportStr != postTargetCont.Report {
saveData["report"] = reportStr
//关联考核岗位和提报人
for _, dv := range receivedValue.RelevantPostsMan {
postid, _ := strconv.ParseInt(dv.Id, 10, 64)
syncSetinges.Add(1)
go DepartAboutPostTargetReport(postTargetCont.Dimension, postTargetCont.Id, 0, 0, postTargetCont.ReleDepart, postid, dv.Operator, 2, postTargetCont.Type)
}
}
}
if len(saveData) > 0 {
saveData["time"] = time.Now().Unix()
saveErr := postTargetCont.EiteCont(where, saveData)
if saveErr != nil {
publicmethod.Result(106, saveErr, c)
} else {
publicmethod.Result(0, saveErr, c)
}
} else {
publicmethod.Result(0, err, c)
}
}
// 获取岗位指标关联部门相关岗位及提报人
func (a *ApiMethod) GetTargetAboutDepartToPostMan(c *gin.Context) {
var receivedValue publicmethod.PublicId
err := c.ShouldBindJSON(&receivedValue)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if receivedValue.Id == "" {
publicmethod.Result(101, receivedValue, c)
return
}
var postTargetCont modelskpi.PostTarget
err = postTargetCont.GetCont(map[string]interface{}{"`id`": receivedValue.Id})
if err != nil {
publicmethod.Result(107, err, c)
return
}
_, outData, _ := getTargetAboutPost(postTargetCont.ReleDepart, postTargetCont.Dimension, postTargetCont.Id, 2)
publicmethod.Result(0, outData, c)
}
// 添加岗位细则
func (a *ApiMethod) AddPostTargetCont(c *gin.Context) {
var receivedValue addPostContTarget
c.ShouldBindJSON(&receivedValue)
if receivedValue.TargetId == "" {
publicmethod.Result(1, receivedValue, c, "请选择岗位指标!")
return
}
if receivedValue.DepartmentId == "" {
publicmethod.Result(1, receivedValue, c, "请选择行政组织!")
return
}
if receivedValue.TargetSunTitle == "" {
publicmethod.Result(1, receivedValue, c, "请输入子栏目名称!")
return
}
if len(receivedValue.PostId) < 1 {
publicmethod.Result(1, receivedValue, c, "请选择岗位!")
return
}
if len(receivedValue.List) < 1 {
publicmethod.Result(1, receivedValue, c, "请输入指标细则!")
return
}
xiZeIsTrue := 1
for _, v := range receivedValue.List {
if v.Title == "" {
xiZeIsTrue = 2
break
}
if v.ReferenceScore == "" {
xiZeIsTrue = 2
break
}
if v.Unit == "" {
xiZeIsTrue = 2
break
}
}
if xiZeIsTrue != 1 {
publicmethod.Result(1, receivedValue, c, "请检查你输入的指标细则!其中有不符合标准的细则!")
return
}
targetSunIdInt, _ := strconv.ParseInt(receivedValue.TargetId, 10, 64)
deartmentIdInt, _ := strconv.ParseInt(receivedValue.DepartmentId, 10, 64)
//指标子栏目
var sunTargetCont modelskpi.PostSonTarget
sunErr := sunTargetCont.GetCont(map[string]interface{}{"`title`": receivedValue.TargetSunTitle, "`parent_id`": receivedValue.TargetId, "depart": receivedValue.DepartmentId}, "`id`")
if sunErr != nil {
sunTargetCont.Title = receivedValue.TargetSunTitle //标题"`
sunTargetCont.ParentId = targetSunIdInt //归属指标"`
sunTargetCont.Time = time.Now().Unix() //创建时间"`
sunTargetCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
sunTargetCont.Depart = deartmentIdInt //关联部门"`
sunTargetCont.DepartPost = strings.Join(receivedValue.PostId, ",")
sunTargetErr := overall.CONSTANT_DB_KPI.Create(&sunTargetCont).Error
if sunTargetErr != nil {
publicmethod.Result(104, sunTargetErr, c)
return
}
}
if sunTargetCont.Id == 0 {
publicmethod.Result(104, sunTargetCont, c)
return
}
//考核细则写入
// for _, lv := range receivedValue.List {
// }
}

31
api/version1/postseting/postpc/type.go

@ -166,3 +166,34 @@ type addPostTarget struct {
VisibleGroup []string `json:"visibleGroup"` //可见范围(集团)
RelevantPostsMan []postPeople `json:"relevantpostsman"` //相关岗位与提报人
}
// 编辑岗位指标
type editPostTargetCont struct {
publicmethod.PublicId
addPostTarget
}
// 添加岗位指标细则
type addPostContTarget struct {
TargetId string `json:"targetid"` //指标
DepartmentId string `json:"departmentid"` //行政组织
PostId []string `json:"postid"` //岗位
TargetSunTitle string `json:"targetsuntitle"` //子栏目
List []postContList `json:"list"` //指标细则
}
// 岗位指标细则
type postContList struct {
Title string `json:"title"` //考核内容
ReferenceScore string `json:"referencescore"` //考核标准
Unit string `json:"unit"` //单位
Class int `json:"class"` //1:减少;2:增加;3:无属性,现场确认加或减
Inspect []string `json:"inspect"` //检查方式(1:现场检查;2:资料检查;3:事件触发)
Cycle int `json:"cycle"` //1:班;2:天;3:周;4:月;5:季度;6:年
CycleAttr int `json:"cycleattr"` //频次
Evidence string `json:"evidence"` //客观证据
Explain string `json:"explain"` //备注说明
RelevantPostsMan []postPeople `json:"relevantpostsman"` //相关岗位与提报人
PunishMode int `json:"punishmode"` //处罚方式 1:扣分;2:现金处罚;3:扣分加现金
CashStandard string `json:"cashstandard"` //现金标准
}

20
apirouter/v1/postseting/pc.go

@ -12,14 +12,16 @@ func (a *ApiRouter) RouterGroupPc(router *gin.RouterGroup) {
var methodBinding = version1.AppApiEntry.PostPcApi
{
apiRouter.GET("", methodBinding.Index) //入口
apiRouter.POST("", methodBinding.Index) //入口
apiRouter.POST("getpostabouttarget", methodBinding.GetPostAboutTarget) //获取岗位相关指标
apiRouter.POST("quote_department_target", methodBinding.QuoteDepartmentTarget) //引用指标部门指标
apiRouter.POST("submit_post_scheme", methodBinding.SubmitPostScheme) //提交岗位考核方案
apiRouter.POST("get_post_scheme", methodBinding.GetPostScheme) //获取岗位方案内容列表
apiRouter.POST("get_copy_sheme_infor", methodBinding.GetCopyShemeInfor) //获取复制岗位考核方案
apiRouter.POST("get_post_target", methodBinding.GetPostTarget) //获取岗位指标详情
apiRouter.POST("add_post_target", methodBinding.AddPostTarget) //添加岗位指标
apiRouter.GET("", methodBinding.Index) //入口
apiRouter.POST("", methodBinding.Index) //入口
apiRouter.POST("getpostabouttarget", methodBinding.GetPostAboutTarget) //获取岗位相关指标
apiRouter.POST("quote_department_target", methodBinding.QuoteDepartmentTarget) //引用指标部门指标
apiRouter.POST("submit_post_scheme", methodBinding.SubmitPostScheme) //提交岗位考核方案
apiRouter.POST("get_post_scheme", methodBinding.GetPostScheme) //获取岗位方案内容列表
apiRouter.POST("get_copy_sheme_infor", methodBinding.GetCopyShemeInfor) //获取复制岗位考核方案
apiRouter.POST("get_post_target", methodBinding.GetPostTarget) //获取岗位指标详情
apiRouter.POST("add_post_target", methodBinding.AddPostTarget) //添加岗位指标
apiRouter.POST("dit_post_target", methodBinding.EditPostTarget) //编辑岗位指标
apiRouter.POST("get_target_about_depart_to_post_man", methodBinding.GetTargetAboutDepartToPostMan) //获取岗位指标关联部门相关岗位及提报人
}
}

6
config/configDatabase/database.yaml

@ -186,7 +186,7 @@ managearchives:
loc: 'Local' #时区
name: 'manage_archives' #数据库名称
username: 'root' #数据库用户民
password: 'root' #数据库密码
max_idle_conns: 100 #最大空闲数量
password: 'root' #数据库密码
max_idle_conns: 100 #最大空闲数量1
max_open_conns: 1500 #最大打开数量
gorm_log: true #是否开启gorm日志
gorm_log: true #是否开启gorm日志2

6
initialization/app/run.go

@ -2,7 +2,7 @@ package app
import (
"fmt"
"key_performance_indicators/initialization"
"key_performance_indicators/initialization/initviper"
"key_performance_indicators/initialization/route"
"key_performance_indicators/overall"
)
@ -11,11 +11,11 @@ type server interface {
ListenAndServe() error
}
//启动服务
// 启动服务
func RunItem() {
//加载基础配置
// var appConfig configApp.Server
initialization.RunViper(&overall.CONSTANT_CONFIG)
initviper.RunViper(&overall.CONSTANT_CONFIG)
// fmt.Printf("----------->%v", overall.CONSTANT_CONFIG)
routers := route.InitialRouter()
portStr := fmt.Sprintf(":%d", overall.CONSTANT_CONFIG.Appsetup.Port)

6
initialization/databaseinit/mysql.go

@ -2,13 +2,13 @@ package databaseinit
import (
"fmt"
"key_performance_indicators/initialization"
"key_performance_indicators/initialization/initviper"
"key_performance_indicators/overall"
)
func LoadDatabase() {
sqlConfig := overall.CONSTANT_MYSQL
initialization.RunViper(&sqlConfig, overall.ConfigDatabaseConstant)
initviper.RunViper(&sqlConfig, overall.ConfigDatabaseConstant)
//开启主数据库
overall.CONSTANT_DB_Master = sqlConfig.MasterMysql.OpenSql()
if overall.CONSTANT_DB_Master == nil {
@ -102,7 +102,7 @@ func LoadDatabase() {
}
//管理档案
overall.CONSTANT_DB_MANAGE_ARCHIVES = sqlConfig.Managearchives.OpenSql()
if overall.CONSTANT_DB_HR == nil {
if overall.CONSTANT_DB_MANAGE_ARCHIVES == nil {
fmt.Printf("%v数据库开启失败!\n", sqlConfig.Managearchives.Name)
} else {
fmt.Printf("%v数据库开启成功!\n", sqlConfig.Managearchives.Name)

13
initialization/init_viper.go → initialization/initviper/init_viper.go

@ -1,7 +1,6 @@
package initialization
package initviper
import (
"encoding/json"
"fmt"
"key_performance_indicators/overall"
@ -35,13 +34,21 @@ func RunViper(configInfo interface{}, path ...string) *viper.Viper {
fmt.Printf("配置文件已经更改:%v\n", e.Name)
if errSet := v.Unmarshal(&configInfo); errSet != nil {
fmt.Printf("新配置文件解析失败!系统继续使用原配置!失败原因:%s\n", errSet)
} else {
// LoadDatabase()
if e.Name == "config\\configDatabase\\database.yaml" {
LoadDatabase()
}
if e.Name == "config\\configNosql\\redis.yaml" {
LoadRedis()
}
}
})
//解析配置映射到切片
if errStruct := v.Unmarshal(&configInfo); errStruct != nil {
fmt.Printf("配置解析失败!原因:%s\n", errStruct)
}
json.Marshal(configInfo)
// json.Marshal(configInfo)
// cfi, _ := json.Marshal(configInfo)
// fmt.Printf("============>%v\n", string(cfi))
return v

18
initialization/initviper/initreload.go

@ -0,0 +1,18 @@
package initviper
import (
"key_performance_indicators/overall"
)
func LoadDatabase() {
sqlConfig := overall.CONSTANT_MYSQL
RunViper(&sqlConfig, overall.ConfigDatabaseConstant)
}
// 加载Redis
func LoadRedis() {
//读取Redis配置
redisConfig := overall.CONSTANT_Redis
RunViper(&redisConfig, overall.ConfigRedisConstant)
}

6
initialization/nosql/redis.go

@ -1,15 +1,15 @@
package nosql
import (
"key_performance_indicators/initialization"
"key_performance_indicators/initialization/initviper"
"key_performance_indicators/overall"
)
//加载Redis
// 加载Redis
func LoadRedis() {
//读取Redis配置
redisConfig := overall.CONSTANT_Redis
initialization.RunViper(&redisConfig, overall.ConfigRedisConstant)
initviper.RunViper(&redisConfig, overall.ConfigRedisConstant)
overall.CONSTANT_REDIS0 = redisConfig.MasterRedis.OpenRedis()
overall.CONSTANT_REDIS1 = redisConfig.MasterRedis1.OpenRedis()
overall.CONSTANT_REDIS2 = redisConfig.MasterRedis2.OpenRedis()

Loading…
Cancel
Save