company_config.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package company
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta_gn/eta_api/global"
  6. "eta_gn/eta_api/utils"
  7. "time"
  8. )
  9. const (
  10. ConfAreaCodeListKey = "area_code_list" // 手机号区号列表
  11. ConfEnAuthRoleKey = "en_auth_role" // 英文权限角色配置Key
  12. )
  13. //type CrmConfig struct {
  14. // ConfigValue string `description:"详情"`
  15. //}
  16. type CrmConfig struct {
  17. ConfigId int `gorm:"primaryKey;column:config_id;type:int(11);not null"`
  18. ConfigCode string `gorm:"column:config_code;type:varchar(50);default:''"` // 配置编码
  19. ConfigValue string `gorm:"column:config_value;type:text"` // 配置值
  20. Remark string `gorm:"column:remark;type:varchar(255);default:''"` // 备注信息
  21. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  22. }
  23. //func GetConfigValueByCode(configCode string) (total int, err error) {
  24. // o := orm.NewOrm()
  25. // sql := ` SELECT config_value FROM crm_config WHERE config_code=? `
  26. // err = o.Raw(sql, configCode).QueryRow(&total)
  27. // return
  28. //}
  29. // 修改
  30. //func CrmConfigUpdate(newValue, configCode string) (err error) {
  31. // o := orm.NewOrm()
  32. // sql := `UPDATE crm_config SET config_value=? WHERE config_code= ?`
  33. // _, err = o.Raw(sql, newValue, configCode).Exec()
  34. // return
  35. //}
  36. func GetConfigDetailByCode(configCode string) (item CrmConfig, err error) {
  37. //o := orm.NewOrm()
  38. //sql := ` SELECT config_value FROM crm_config WHERE config_code=? `
  39. //err = o.Raw(sql, configCode).QueryRow(&item)
  40. sql := ` SELECT config_value FROM crm_config WHERE config_code=? `
  41. err = global.DEFAULT_DmSQL.Raw(sql, configCode).First(&item).Error
  42. return
  43. }
  44. // ConfEnAuthRole 配置-英文权限角色
  45. type ConfEnAuthRole struct {
  46. RoleCode string `description:"角色编码"`
  47. RoleName string `description:"角色名称"`
  48. SyncCrm bool `description:"是否同步CRM"`
  49. }
  50. // ConfigClassifyId
  51. // @Description: 后台配置的报告id
  52. type ConfigClassifyId struct {
  53. Debug int `json:"debug"`
  54. Release int `json:"release"`
  55. }
  56. // GetReportClassifyIdByConfigKey
  57. // @Description: 获取关联的报告id
  58. // @author: Roc
  59. // @datetime 2024-06-18 14:10:27
  60. // @param configKey string
  61. // @return classifyId int
  62. // @return err error
  63. func GetReportClassifyIdByConfigKey(configKey string) (classifyId int, err error) {
  64. // 别问为啥要从配置里拿=_=!
  65. conf, e := GetConfigDetailByCode(configKey)
  66. if e != nil {
  67. err = errors.New("获取配置的id失败, Err: " + e.Error())
  68. return
  69. }
  70. if conf.ConfigValue == "" {
  71. err = errors.New("ID配置有误")
  72. return
  73. }
  74. type TwoWeekIdConf struct {
  75. Debug []int
  76. Release []int
  77. }
  78. classifyIdConf := new(ConfigClassifyId)
  79. if e = json.Unmarshal([]byte(conf.ConfigValue), &classifyIdConf); e != nil {
  80. err = errors.New("解析ID配置失败, Err: " + e.Error())
  81. return
  82. }
  83. if utils.RunMode == "debug" {
  84. classifyId = classifyIdConf.Debug
  85. } else {
  86. classifyId = classifyIdConf.Release
  87. }
  88. return
  89. }