company_config.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. ConfigId int `gorm:"primaryKey;column:config_id;type:int(11);not null"`
  15. ConfigCode string `gorm:"column:config_code;type:varchar(50);default:''"` // 配置编码
  16. ConfigValue string `gorm:"column:config_value;type:text"` // 配置值
  17. Remark string `gorm:"column:remark;type:varchar(255);default:''"` // 备注信息
  18. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  19. }
  20. func GetConfigDetailByCode(configCode string) (item CrmConfig, err error) {
  21. sql := ` SELECT config_value FROM crm_config WHERE config_code=? `
  22. err = global.DEFAULT_DmSQL.Raw(sql, configCode).First(&item).Error
  23. return
  24. }
  25. // ConfEnAuthRole 配置-英文权限角色
  26. type ConfEnAuthRole struct {
  27. RoleCode string `description:"角色编码"`
  28. RoleName string `description:"角色名称"`
  29. SyncCrm bool `description:"是否同步CRM"`
  30. }
  31. // ConfigClassifyId
  32. // @Description: 后台配置的报告id
  33. type ConfigClassifyId struct {
  34. Debug int `json:"debug"`
  35. Release int `json:"release"`
  36. }
  37. // GetReportClassifyIdByConfigKey
  38. // @Description: 获取关联的报告id
  39. // @author: Roc
  40. // @datetime 2024-06-18 14:10:27
  41. // @param configKey string
  42. // @return classifyId int
  43. // @return err error
  44. func GetReportClassifyIdByConfigKey(configKey string) (classifyId int, err error) {
  45. // 别问为啥要从配置里拿=_=!
  46. conf, e := GetConfigDetailByCode(configKey)
  47. if e != nil {
  48. err = errors.New("获取配置的id失败, Err: " + e.Error())
  49. return
  50. }
  51. if conf.ConfigValue == "" {
  52. err = errors.New("ID配置有误")
  53. return
  54. }
  55. type TwoWeekIdConf struct {
  56. Debug []int
  57. Release []int
  58. }
  59. classifyIdConf := new(ConfigClassifyId)
  60. if e = json.Unmarshal([]byte(conf.ConfigValue), &classifyIdConf); e != nil {
  61. err = errors.New("解析ID配置失败, Err: " + e.Error())
  62. return
  63. }
  64. if utils.RunMode == "debug" {
  65. classifyId = classifyIdConf.Debug
  66. } else {
  67. classifyId = classifyIdConf.Release
  68. }
  69. return
  70. }