industry.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hz_crm_api/models/cygx"
  6. "hongze/hz_crm_api/services/alarm_msg"
  7. "hongze/hz_crm_api/utils"
  8. "time"
  9. )
  10. var (
  11. EmptyDateTimeStr = "0000-00-00 00:00:00"
  12. EmptyDateTimeStrFmot = "0001-01-01 00:00:00"
  13. )
  14. //func init() {
  15. // var industryIds []int
  16. // industryIds = append(industryIds, 607)
  17. // UpdateIndustryLayoutTime(industryIds, false)
  18. //}
  19. // UpdateIndustryLayoutTime 更新产业布局时间
  20. func UpdateIndustryLayoutTime(industryIds []int, forceUpdate bool) (err error) {
  21. defer func() {
  22. fmt.Println(err)
  23. if err != nil {
  24. go alarm_msg.SendAlarmMsg("更新产业布局时间失败, ErrMsg: "+err.Error(), 3)
  25. }
  26. }()
  27. idLen := len(industryIds)
  28. if idLen <= 0 {
  29. return
  30. }
  31. var condition string
  32. var pars []interface{}
  33. if idLen == 1 {
  34. condition = ` AND idy.industrial_management_id = ?`
  35. pars = append(pars, industryIds[0])
  36. } else {
  37. condition = ` AND idy.industrial_management_id IN (` + utils.GetOrmInReplace(idLen) + `)`
  38. pars = append(pars, industryIds)
  39. }
  40. list, e := cygx.GetIndustriesEarliestLayoutTime(condition, pars)
  41. if e != nil {
  42. err = errors.New("获取产业最早布局时间失败, Err: " + e.Error())
  43. return
  44. }
  45. mapLayoutTime := make(map[int]time.Time)
  46. for i := range list {
  47. // 强制更新
  48. if !forceUpdate {
  49. if list[i].LayoutTime != "" && list[i].LayoutTime != EmptyDateTimeStr {
  50. continue
  51. }
  52. }
  53. if list[i].MinArticleTime != "" && list[i].MinArticleTime != EmptyDateTimeStr {
  54. mapLayoutTime[list[i].IndustrialManagementId] = list[i].MinArticleTime2
  55. }
  56. }
  57. listMorningMeeting, e := cygx.GetIndustriesEarliestLayoutTimeByMorningMeeting(condition, pars)
  58. if e != nil {
  59. err = errors.New("获取产业最早布局时间失败, Err: " + e.Error())
  60. return
  61. }
  62. for i := range listMorningMeeting {
  63. // 强制更新
  64. if !forceUpdate {
  65. if listMorningMeeting[i].LayoutTime != "" && listMorningMeeting[i].LayoutTime != EmptyDateTimeStr {
  66. continue
  67. }
  68. }
  69. //earliestTime := ""
  70. if listMorningMeeting[i].MinArticleTime != "" && listMorningMeeting[i].MinArticleTime != EmptyDateTimeStr {
  71. //earliestTime = list[i].MinArticleTime
  72. if mapLayoutTime[listMorningMeeting[i].IndustrialManagementId].Format(utils.FormatDateTime) == EmptyDateTimeStrFmot {
  73. mapLayoutTime[listMorningMeeting[i].IndustrialManagementId] = listMorningMeeting[i].MinArticleTime2
  74. } else {
  75. if listMorningMeeting[i].MinArticleTime2.Before(mapLayoutTime[listMorningMeeting[i].IndustrialManagementId]) {
  76. mapLayoutTime[listMorningMeeting[i].IndustrialManagementId] = listMorningMeeting[i].MinArticleTime2
  77. }
  78. }
  79. }
  80. }
  81. for k, v := range mapLayoutTime {
  82. if e = cygx.UpdateIndustryLayoutTime(k, v.AddDate(0, 0, -10).Format(utils.FormatDateTime)); e != nil {
  83. err = errors.New("更新产业布局时间失败, Err: " + e.Error())
  84. return
  85. }
  86. }
  87. return
  88. }
  89. //func init() {
  90. // UpdateOriginIndustryLayoutTime()
  91. //}
  92. // UpdateOriginIndustryLayoutTime 更新所有产业布局时间
  93. func UpdateOriginIndustryLayoutTime() {
  94. var condition string
  95. var pars []interface{}
  96. industries, e := cygx.GetIndustryListByCondition(condition, pars)
  97. if e != nil {
  98. fmt.Println(e.Error())
  99. return
  100. }
  101. industryIds := make([]int, 0)
  102. for i := range industries {
  103. industryIds = append(industryIds, industries[i].IndustrialManagementId)
  104. }
  105. fmt.Println("开始更新")
  106. if e = UpdateIndustryLayoutTime(industryIds, true); e != nil {
  107. fmt.Println(e.Error())
  108. return
  109. }
  110. fmt.Println("更新完毕")
  111. return
  112. }