Company.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. package Account
  2. import (
  3. "Cold_Api/conf"
  4. "Cold_Api/controllers/lib"
  5. "encoding/json"
  6. "fmt"
  7. "github.com/astaxie/beego/cache"
  8. _ "github.com/astaxie/beego/cache/redis"
  9. "github.com/beego/beego/v2/adapter/orm"
  10. orm2 "github.com/beego/beego/v2/client/orm"
  11. "github.com/beego/beego/v2/core/logs"
  12. _ "github.com/go-sql-driver/mysql"
  13. "strconv"
  14. "sync"
  15. "time"
  16. )
  17. type Company struct {
  18. Id int `orm:"column(ID);size(11);auto;pk"`
  19. T_mid int `orm:"size(200);null"` // 上一级 ID
  20. T_name string `orm:"size(256);null"` // 公司名称
  21. T_key string `orm:"size(256);index;null"` // 公司密钥
  22. T_type int `orm:"size(256);default(1)"` // 公司类型 1-医药公司 2-运输企业
  23. T_plan string `orm:"type(text);null"` // 平面图
  24. T_data string `orm:"type(text);null"` // 大数据
  25. T_v3d string `orm:"type(text);null"` // 3D 视图
  26. T_path string `orm:"size(256);null"` // 公司路径 /0/1/5/
  27. T_money float32 `orm:"digits(12);decimals(2)"`
  28. T_State int `orm:"size(200);default(1)"` // 0删除 1正常
  29. T_warning int `orm:"size(20);default(1)"` // 是否处理报警信息 1处理 2不处理
  30. T_Charging int `orm:"size(11);default(0)"` // 记账扣费 公司ID 默认为:0 (自己)
  31. CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` // auto_now 每次 model 保存时都会对时间自动更新
  32. UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` // auto_now_add 第一次保存时才设置时间
  33. Children []Company `orm:"-"`
  34. }
  35. type Company_R struct {
  36. Id int
  37. T_mid int // 上一级 ID
  38. T_name string // 公司名称
  39. T_plan string // 平面图
  40. T_data string // 大数据
  41. T_v3d string // 3D 视图
  42. T_money float32 // 余额
  43. T_warning int // 报警统计
  44. T_key string
  45. T_type int // 公司类型 1-医药公司 2-运输企业
  46. T_Charging int
  47. Children []Company_R
  48. }
  49. func CompanyToCompany_R(r Company) (v Company_R) {
  50. v.Id = r.Id
  51. v.T_mid = r.T_mid
  52. v.T_name = r.T_name
  53. v.T_plan = r.T_plan
  54. v.T_data = r.T_data
  55. v.T_v3d = r.T_v3d
  56. v.T_money = r.T_money
  57. v.T_warning = r.T_warning
  58. v.T_key = r.T_key
  59. v.T_Charging = r.T_Charging
  60. v.T_type = r.T_type
  61. return v
  62. }
  63. func (t *Company) TableName() string {
  64. return "company" // 数据库名称 // ************** 替换 FormulaList **************
  65. }
  66. var redisCache_Company cache.Cache
  67. var Company_map *sync.Map // 泛型
  68. func init() {
  69. //注册模型
  70. Company_map = new(sync.Map)
  71. //注册模型
  72. orm.RegisterModel(new(Company))
  73. config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
  74. "redis_User_Company", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
  75. fmt.Println(config)
  76. var err error
  77. redisCache_Company, err = cache.NewCache("redis", config)
  78. if err != nil || redisCache_Company == nil {
  79. errMsg := "failed to init redis"
  80. logs.Error(errMsg, err)
  81. panic(errMsg)
  82. }
  83. }
  84. // ---------------- Redis -------------------
  85. func Redis_Company_Set(key string, r Company) (err error) {
  86. //json序列化
  87. str, err := json.Marshal(r)
  88. if err != nil {
  89. logs.Error(lib.FuncName(), err)
  90. return
  91. }
  92. err = redisCache_Company.Put(key, str, 24*time.Hour)
  93. if err != nil {
  94. logs.Error("set key:", key, ",value:", str, err)
  95. }
  96. return
  97. }
  98. func Redis_Company_Get(key string) (r Company, is bool) {
  99. if redisCache_Company.IsExist(key) {
  100. //println("找到key:",key)
  101. v := redisCache_Company.Get(key)
  102. err := json.Unmarshal(v.([]byte), &r)
  103. if err != nil {
  104. logs.Error(lib.FuncName(), err)
  105. return Company{}, false
  106. }
  107. return r, true
  108. }
  109. //println("没有 找到key:",key)
  110. return Company{}, false
  111. }
  112. func Redis_Company_DelK(key string) (err error) {
  113. err = redisCache_Company.Delete(key)
  114. if err != nil {
  115. logs.Error(lib.FuncName(), err)
  116. }
  117. return
  118. }
  119. // ---------------- 特殊方法 -------------------
  120. // 添加
  121. func Add_Company(var_ Company) (id int64, err error) {
  122. o := orm.NewOrm()
  123. o.Begin()
  124. var rand_x int64
  125. for true {
  126. var_.T_key = lib.GetRandstring(16, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", rand_x)
  127. err = o.Read(&var_, "T_key") // o.Read(&r,"Tokey") 如果不是 主键 就得指定字段名
  128. if err != nil {
  129. break
  130. }
  131. rand_x++
  132. }
  133. id, err = o.Insert(&var_)
  134. if err != nil {
  135. o.Rollback()
  136. logs.Error(lib.FuncName(), err)
  137. return id, err
  138. }
  139. T_Path := "/0/" + strconv.Itoa(int(id)) + "/"
  140. if var_.T_mid != 0 {
  141. Company_r, err := Read_Company_ById(var_.T_mid)
  142. if err != nil {
  143. o.Rollback()
  144. logs.Error(lib.FuncName(), err)
  145. return id, err
  146. }
  147. T_Path = Company_r.T_path + strconv.Itoa(int(id)) + "/"
  148. }
  149. var_.Id = int(id)
  150. var_.T_path = T_Path
  151. _, err = o.Update(&var_, "T_path")
  152. if err != nil {
  153. o.Rollback()
  154. logs.Error(lib.FuncName(), err)
  155. return id, err
  156. }
  157. o.Commit()
  158. Redis_Company_Set(strconv.Itoa(var_.Id), var_)
  159. return id, err
  160. }
  161. // 修改
  162. func Update_Company(m Company, cols ...string) bool {
  163. o := orm.NewOrm()
  164. num, err := o.Update(&m, cols...)
  165. if err != nil {
  166. logs.Error(lib.FuncName(), err)
  167. return false
  168. }
  169. logs.Info("Number of records updated in database:", num)
  170. Redis_Company_Set(strconv.Itoa(m.Id), m) // Redis 更新缓存
  171. return true
  172. }
  173. // 删除
  174. func Delete_Company(orm orm.Ormer, id int) bool {
  175. var m = Company{
  176. Id: id,
  177. T_State: 0,
  178. }
  179. num, err := orm.Update(&m, "T_State")
  180. if err != nil {
  181. logs.Error(lib.FuncName(), err)
  182. return false
  183. }
  184. logs.Info("Number of records updated in database:", num)
  185. Redis_Company_DelK(strconv.Itoa(m.Id))
  186. return true
  187. }
  188. // 获取 ById
  189. func Read_Company_ById(Id int) (r Company, e error) {
  190. if r, is := Redis_Company_Get(strconv.Itoa(Id)); is {
  191. //println("Redis_Get OK")
  192. return r, nil
  193. }
  194. o := orm.NewOrm()
  195. qs := o.QueryTable(new(Company))
  196. e = qs.Filter("Id", Id).Filter("T_State", 1).One(&r)
  197. if e != nil {
  198. logs.Error(lib.FuncName(), e)
  199. return
  200. }
  201. Redis_Company_Set(strconv.Itoa(r.Id), r) // Redis 更新缓存
  202. return r, e
  203. }
  204. func Read_Company_ByKey(key string) (r Company, e error) {
  205. if r, is := Redis_Company_Get(key); is {
  206. //println("Redis_Get OK")
  207. return r, nil
  208. }
  209. o := orm.NewOrm()
  210. qs := o.QueryTable(new(Company))
  211. e = qs.Filter("T_key", key).Filter("T_State", 1).One(&r)
  212. if e != nil {
  213. logs.Error(lib.FuncName(), e)
  214. return
  215. }
  216. Redis_Company_Set(key, r) // Redis 更新缓存
  217. return r, e
  218. }
  219. // 获取列表
  220. func Read_Company_Tree(admin_r Admin, T_name string) (CompanyList []Company_R) {
  221. // 内部用户未绑定公司
  222. if admin_r.T_pid == 0 && len(admin_r.T_pids) == 0 {
  223. return CompanyList
  224. }
  225. o := orm.NewOrm()
  226. // 也可以直接使用 Model 结构体作为表名
  227. qs := o.QueryTable(new(Company))
  228. var maps []Company
  229. cond := orm.NewCondition()
  230. cond1 := cond.And("T_State", 1)
  231. if admin_r.T_pid > 0 {
  232. cond1 = cond1.And("T_path__icontains", fmt.Sprintf("/%d/", admin_r.T_pid))
  233. }
  234. // 内部用户已绑定公司,* 绑定所有公司
  235. if len(admin_r.T_pids) > 0 && admin_r.T_pids != "*" {
  236. T_pids := lib.SplitStringToIntIds(admin_r.T_pids, "P")
  237. if len(T_pids) > 0 {
  238. cond1 = cond1.And("Id__in", ReadCompanyIds_T_pids(T_pids))
  239. }
  240. }
  241. if len(T_name) > 0 {
  242. cond1 = cond1.And("T_name__icontains", T_name)
  243. }
  244. _, err := qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&maps)
  245. if err != nil {
  246. logs.Error(lib.FuncName(), err)
  247. return CompanyList
  248. }
  249. parentMap, flag := getCompanyParent(maps)
  250. if flag {
  251. for i := 0; i < len(maps); i++ {
  252. if parentMap[maps[i].T_mid] {
  253. continue
  254. }
  255. r := Company_R{
  256. Id: maps[i].Id,
  257. T_mid: maps[i].T_mid,
  258. T_name: maps[i].T_name,
  259. T_plan: maps[i].T_plan,
  260. T_data: maps[i].T_data,
  261. T_v3d: maps[i].T_v3d,
  262. T_money: maps[i].T_money,
  263. T_warning: maps[i].T_warning,
  264. T_Charging: maps[i].T_Charging,
  265. T_key: maps[i].T_key,
  266. T_type: maps[i].T_type,
  267. Children: nil,
  268. }
  269. info := CompanyCall(maps, r)
  270. CompanyList = append(CompanyList, info)
  271. }
  272. } else {
  273. for i := 0; i < len(maps); i++ {
  274. r := Company_R{
  275. Id: maps[i].Id,
  276. T_mid: maps[i].T_mid,
  277. T_name: maps[i].T_name,
  278. T_plan: maps[i].T_plan,
  279. T_data: maps[i].T_data,
  280. T_v3d: maps[i].T_v3d,
  281. T_money: maps[i].T_money,
  282. T_warning: maps[i].T_warning,
  283. T_Charging: maps[i].T_Charging,
  284. T_key: maps[i].T_key,
  285. T_type: maps[i].T_type,
  286. Children: nil,
  287. }
  288. info := CompanyCall(maps, r)
  289. CompanyList = append(CompanyList, info)
  290. }
  291. }
  292. return CompanyList
  293. }
  294. func ReadCompanyIds_T_pids(T_pids []int) []int {
  295. var companyIds []int
  296. if len(T_pids) == 0 {
  297. return companyIds
  298. }
  299. var companyList []Company
  300. o := orm.NewOrm()
  301. qs := o.QueryTable(new(Company))
  302. _, err := qs.Filter("Id__in", T_pids).Filter("T_State", 1).All(&companyList)
  303. if err != nil {
  304. logs.Error(lib.FuncName(), err)
  305. return companyIds
  306. }
  307. for _, company := range companyList {
  308. subIds := ReadCompanyIds_T_path(company.T_path)
  309. companyIds = append(companyIds, subIds...)
  310. }
  311. return lib.IntIdsDistinct(companyIds)
  312. }
  313. // 通过T_pid查询所有子id
  314. func ReadCompanyIds_T_path(T_path string) (companyIds []int) {
  315. o := orm.NewOrm()
  316. qs := o.QueryTable(new(Company))
  317. var CompanyList []Company
  318. _, err := qs.Filter("T_path__startswith", T_path).Filter("T_State", 1).All(&CompanyList)
  319. if err != nil {
  320. logs.Error(lib.FuncName(), err)
  321. return companyIds
  322. }
  323. for _, v := range CompanyList {
  324. companyIds = append(companyIds, v.Id)
  325. }
  326. return companyIds
  327. }
  328. func ReadCompanyWarningIds_T_pids(T_pids []int) []int {
  329. var companyList []Company
  330. var companyIds []int
  331. o := orm.NewOrm()
  332. qs := o.QueryTable(new(Company))
  333. if len(T_pids) == 0 {
  334. return companyIds
  335. }
  336. _, err := qs.Filter("Id__in", T_pids).Filter("T_State", 1).Filter("T_warning", 1).All(&companyList)
  337. if err != nil {
  338. logs.Error(lib.FuncName(), err)
  339. return companyIds
  340. }
  341. for _, company := range companyList {
  342. subIds := ReadCompanyWarningIds_T_path(company.T_path)
  343. companyIds = append(companyIds, subIds...)
  344. }
  345. return lib.IntIdsDistinct(companyIds)
  346. }
  347. // 通过T_pid查询所有子id
  348. func ReadCompanyWarningIds_T_path(T_path string) (companyIds []int) {
  349. o := orm.NewOrm()
  350. qs := o.QueryTable(new(Company))
  351. var CompanyList []Company
  352. _, err := qs.Filter("T_path__startswith", T_path).Filter("T_State", 1).Filter("T_warning", 1).All(&CompanyList)
  353. if err != nil {
  354. logs.Error(lib.FuncName(), err)
  355. return companyIds
  356. }
  357. for _, v := range CompanyList {
  358. companyIds = append(companyIds, v.Id)
  359. }
  360. return companyIds
  361. }
  362. func Read_Company_List(T_name string) (CompanyList []Company_R) {
  363. o := orm.NewOrm()
  364. // 也可以直接使用 Model 结构体作为表名
  365. qs := o.QueryTable(new(Company))
  366. var maps []Company
  367. cond := orm.NewCondition()
  368. cond1 := cond.And("T_State", 1)
  369. if len(T_name) > 0 {
  370. cond1 = cond1.And("T_name__icontains", T_name)
  371. }
  372. _, err := qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&maps)
  373. if err != nil {
  374. logs.Error(lib.FuncName(), err)
  375. return CompanyList
  376. }
  377. parentMap, flag := getCompanyParent(maps)
  378. if flag {
  379. for i := 0; i < len(maps); i++ {
  380. if parentMap[maps[i].T_mid] {
  381. continue
  382. }
  383. r := Company_R{
  384. Id: maps[i].Id,
  385. T_mid: maps[i].T_mid,
  386. T_name: maps[i].T_name,
  387. T_plan: maps[i].T_plan,
  388. T_data: maps[i].T_data,
  389. T_v3d: maps[i].T_v3d,
  390. T_money: maps[i].T_money,
  391. T_warning: maps[i].T_warning,
  392. T_type: maps[i].T_type,
  393. Children: nil,
  394. }
  395. info := CompanyCall(maps, r)
  396. CompanyList = append(CompanyList, info)
  397. }
  398. } else {
  399. for i := 0; i < len(maps); i++ {
  400. r := Company_R{
  401. Id: maps[i].Id,
  402. T_mid: maps[i].T_mid,
  403. T_name: maps[i].T_name,
  404. T_plan: maps[i].T_plan,
  405. T_data: maps[i].T_data,
  406. T_v3d: maps[i].T_v3d,
  407. T_money: maps[i].T_money,
  408. T_warning: maps[i].T_warning,
  409. T_type: maps[i].T_type,
  410. Children: nil,
  411. }
  412. info := CompanyCall(maps, r)
  413. CompanyList = append(CompanyList, info)
  414. }
  415. }
  416. return CompanyList
  417. }
  418. // 获取运输企业公司列表
  419. func Read_Transport_Company_List(T_name string) (CompanyList []Company_R) {
  420. o := orm.NewOrm()
  421. // 也可以直接使用 Model 结构体作为表名
  422. qs := o.QueryTable(new(Company))
  423. var maps []Company
  424. cond := orm.NewCondition()
  425. cond1 := cond.And("T_State", 1).And("T_type", 2)
  426. if len(T_name) > 0 {
  427. cond1 = cond1.And("T_name__icontains", T_name)
  428. }
  429. _, err := qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&maps)
  430. if err != nil {
  431. logs.Error(lib.FuncName(), err)
  432. return CompanyList
  433. }
  434. parentMap, flag := getCompanyParent(maps)
  435. if flag {
  436. for i := 0; i < len(maps); i++ {
  437. if parentMap[maps[i].T_mid] {
  438. continue
  439. }
  440. r := Company_R{
  441. Id: maps[i].Id,
  442. T_mid: maps[i].T_mid,
  443. T_name: maps[i].T_name,
  444. T_plan: maps[i].T_plan,
  445. T_data: maps[i].T_data,
  446. T_v3d: maps[i].T_v3d,
  447. T_money: maps[i].T_money,
  448. T_warning: maps[i].T_warning,
  449. T_Charging: maps[i].T_Charging,
  450. T_key: maps[i].T_key,
  451. Children: nil,
  452. }
  453. info := CompanyCall(maps, r)
  454. CompanyList = append(CompanyList, info)
  455. }
  456. } else {
  457. for i := 0; i < len(maps); i++ {
  458. r := Company_R{
  459. Id: maps[i].Id,
  460. T_mid: maps[i].T_mid,
  461. T_name: maps[i].T_name,
  462. T_plan: maps[i].T_plan,
  463. T_data: maps[i].T_data,
  464. T_v3d: maps[i].T_v3d,
  465. T_money: maps[i].T_money,
  466. T_warning: maps[i].T_warning,
  467. T_Charging: maps[i].T_Charging,
  468. T_key: maps[i].T_key,
  469. Children: nil,
  470. }
  471. info := CompanyCall(maps, r)
  472. CompanyList = append(CompanyList, info)
  473. }
  474. }
  475. return CompanyList
  476. }
  477. func CompanyCall(CompanyList []Company, company Company_R) Company_R {
  478. list := CompanyList
  479. min := make([]Company_R, 0)
  480. for j := 0; j < len(list); j++ {
  481. if company.Id != list[j].T_mid {
  482. continue
  483. }
  484. mi := Company_R{}
  485. mi.Id = list[j].Id
  486. mi.T_mid = list[j].T_mid
  487. mi.T_name = list[j].T_name
  488. mi.T_plan = list[j].T_plan
  489. mi.T_data = list[j].T_data
  490. mi.T_v3d = list[j].T_v3d
  491. mi.T_money = list[j].T_money
  492. mi.T_warning = list[j].T_warning
  493. mi.T_Charging = list[j].T_Charging
  494. mi.T_key = list[j].T_key
  495. mi.T_type = list[j].T_type
  496. mi.Children = []Company_R{}
  497. ms := CompanyCall(CompanyList, mi)
  498. min = append(min, ms)
  499. }
  500. company.Children = min
  501. return company
  502. }
  503. func getCompanyParent(CompanyList []Company) (map[int]bool, bool) {
  504. list := CompanyList
  505. var flag = false
  506. var parentMap = map[int]bool{}
  507. for j := 0; j < len(list); j++ {
  508. parentMap[list[j].T_mid] = false
  509. }
  510. for j := 0; j < len(list); j++ {
  511. if _, ok := parentMap[list[j].Id]; !ok {
  512. continue
  513. }
  514. parentMap[list[j].Id] = true
  515. flag = true
  516. }
  517. return parentMap, flag
  518. }
  519. func Read_Company_List_All_ByT_name(T_name string) (maps []Company) {
  520. o := orm.NewOrm()
  521. // 也可以直接使用 Model 结构体作为表名
  522. qs := o.QueryTable(new(Company))
  523. cond := orm.NewCondition()
  524. if len(T_name) > 0 {
  525. cond = cond.And("T_name__icontains", T_name)
  526. }
  527. _, err := qs.SetCond((*orm2.Condition)(cond)).All(&maps)
  528. if err != nil {
  529. logs.Error(lib.FuncName(), err)
  530. return maps
  531. }
  532. return maps
  533. }
  534. // 获取内部用户绑定的公司列表
  535. func Read_Company_List_ByT_pids(T_pids string) (CompanyList []Company_R) {
  536. o := orm.NewOrm()
  537. // 也可以直接使用 Model 结构体作为表名
  538. qs := o.QueryTable(new(Company))
  539. var maps []Company
  540. cond := orm.NewCondition()
  541. cond1 := cond.And("T_State", 1)
  542. if len(T_pids) == 0 {
  543. return
  544. }
  545. if T_pids == "*" {
  546. _, err := qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&maps)
  547. if err != nil {
  548. logs.Error(lib.FuncName(), err)
  549. return CompanyList
  550. }
  551. } else {
  552. list := lib.SplitStringIds(T_pids, "P")
  553. cond1 = cond1.And("Id__in", list)
  554. _, err := qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&maps)
  555. if err != nil {
  556. logs.Error(lib.FuncName(), err)
  557. return CompanyList
  558. }
  559. }
  560. parentMap, flag := getCompanyParent(maps)
  561. if flag {
  562. for i := 0; i < len(maps); i++ {
  563. if parentMap[maps[i].T_mid] {
  564. continue
  565. }
  566. r := Company_R{
  567. Id: maps[i].Id,
  568. T_mid: maps[i].T_mid,
  569. T_name: maps[i].T_name,
  570. Children: nil,
  571. }
  572. info := CompanyCall(maps, r)
  573. CompanyList = append(CompanyList, info)
  574. }
  575. } else {
  576. for i := 0; i < len(maps); i++ {
  577. r := Company_R{
  578. Id: maps[i].Id,
  579. T_mid: maps[i].T_mid,
  580. T_name: maps[i].T_name,
  581. Children: nil,
  582. }
  583. info := CompanyCall(maps, r)
  584. CompanyList = append(CompanyList, info)
  585. }
  586. }
  587. return CompanyList
  588. }
  589. func Read_Company_All_Maps() {
  590. o := orm.NewOrm()
  591. var r []Company
  592. qs := o.QueryTable(new(Company))
  593. _, err := qs.All(&r)
  594. if err != nil {
  595. logs.Error(lib.FuncName(), err)
  596. }
  597. for _, v := range r {
  598. Company_map.Store(v.Id, v.T_name)
  599. }
  600. }
  601. func Read_Company_Get(id int) string {
  602. v, ok := Company_map.Load(id) /*如果确定是真实的,则存在,否则不存在 */
  603. if ok {
  604. return v.(string)
  605. } else {
  606. return ""
  607. }
  608. }