company_config.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. type ConfEnAuthRole struct {
  26. RoleCode string `description:"角色编码"`
  27. RoleName string `description:"角色名称"`
  28. SyncCrm bool `description:"是否同步CRM"`
  29. }
  30. type ConfigClassifyId struct {
  31. Debug int `json:"debug"`
  32. Release int `json:"release"`
  33. }
  34. func GetReportClassifyIdByConfigKey(configKey string) (classifyId int, err error) {
  35. conf, e := GetConfigDetailByCode(configKey)
  36. if e != nil {
  37. err = errors.New("获取配置的id失败, Err: " + e.Error())
  38. return
  39. }
  40. if conf.ConfigValue == "" {
  41. err = errors.New("ID配置有误")
  42. return
  43. }
  44. type TwoWeekIdConf struct {
  45. Debug []int
  46. Release []int
  47. }
  48. classifyIdConf := new(ConfigClassifyId)
  49. if e = json.Unmarshal([]byte(conf.ConfigValue), &classifyIdConf); e != nil {
  50. err = errors.New("解析ID配置失败, Err: " + e.Error())
  51. return
  52. }
  53. if utils.RunMode == "debug" {
  54. classifyId = classifyIdConf.Debug
  55. } else {
  56. classifyId = classifyIdConf.Release
  57. }
  58. return
  59. }