company_record.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. package services
  2. import (
  3. "fmt"
  4. "hongze/hz_crm_api/models"
  5. "hongze/hz_crm_api/models/company"
  6. "hongze/hz_crm_api/models/cygx"
  7. "hongze/hz_crm_api/models/system"
  8. "hongze/hz_crm_api/services/alarm_msg"
  9. "hongze/hz_crm_api/utils"
  10. "time"
  11. )
  12. // 权益客户新增历史备注
  13. func AddCompanyHistoryRemark(item *company.CompanyHistoryRemark) {
  14. var err error
  15. defer func() {
  16. if err != nil {
  17. fmt.Println(err)
  18. go alarm_msg.SendAlarmMsg("权益客户新增历史备注,失败:"+err.Error()+fmt.Sprint(item), 2)
  19. }
  20. }()
  21. err = company.AddCompanyHistoryRemark(item)
  22. return
  23. }
  24. // 删除权益客户新增历史备注
  25. func DelCompanyHistoryRemark(tableName string, tableId int) {
  26. if tableName == "" {
  27. return
  28. }
  29. var err error
  30. defer func() {
  31. if err != nil {
  32. fmt.Println(err)
  33. go alarm_msg.SendAlarmMsg(fmt.Sprintf("权益客户新增历史备注,失败:"+err.Error()+"tableName:", tableName, "tableId", tableId), 2)
  34. }
  35. }()
  36. err = company.DelCompanyHistoryRemark(tableName, tableId)
  37. return
  38. }
  39. //func init() {
  40. // AddCompanyHistoryRemarkInit()
  41. //}
  42. // 权益客户新增历史备注脚本
  43. func AddCompanyHistoryRemarkInit() {
  44. var err error
  45. defer func() {
  46. if err != nil {
  47. fmt.Println(err)
  48. }
  49. }()
  50. sysUserList, err := system.GetAdminList()
  51. if err != nil {
  52. fmt.Println(err)
  53. return
  54. }
  55. mapadmin := make(map[int]string)
  56. for _, v := range sysUserList {
  57. mapadmin[v.AdminId] = v.RealName
  58. }
  59. listHistory, e := company.GetCompanyHistoryRemarkListinit()
  60. if e != nil {
  61. fmt.Println(e)
  62. return
  63. }
  64. makHistoryMap := make(map[string]bool)
  65. for _, v := range listHistory {
  66. makHistoryMap[fmt.Sprintf("id_", v.TableId, "name_", v.TableName)] = true
  67. }
  68. var items []*company.CompanyHistoryRemark
  69. recordOB := new(company.CompanyServiceRecord)
  70. recordCond := ""
  71. recordPars := make([]interface{}, 0)
  72. records, e := recordOB.GetItemsByCondition(recordCond, recordPars, []string{}, "")
  73. if e != nil {
  74. fmt.Println(e)
  75. return
  76. }
  77. //company_service_record
  78. for _, v := range records {
  79. if makHistoryMap[fmt.Sprintf("id_", v.CompanyServiceRecordId, "name_", v.TableName)] {
  80. continue
  81. }
  82. item := new(company.CompanyHistoryRemark)
  83. item.CompanyId = v.CompanyId
  84. item.Content = v.Content
  85. item.SysAdminId = v.SysAdminId
  86. item.SysAdminName = v.SysAdminName
  87. item.CreateTime = time.Now()
  88. item.ModifyTime = time.Now()
  89. item.ShowTime = v.CreateTime
  90. item.CompanyId = v.CompanyId
  91. item.TableId = v.CompanyServiceRecordId
  92. item.TableName = "company_service_record"
  93. items = append(items, item)
  94. }
  95. //company_product_remark
  96. listRemark, e := company.GetRemarkListInit()
  97. if e != nil {
  98. fmt.Println(e)
  99. return
  100. }
  101. for _, v := range listRemark {
  102. if makHistoryMap[fmt.Sprintf("id_", v.CompanyProductRemarkId, "name_", "company_product_remark")] {
  103. continue
  104. }
  105. item := new(company.CompanyHistoryRemark)
  106. item.CompanyId = v.CompanyId
  107. item.Content = v.Remark
  108. item.SysAdminId = v.SysUserId
  109. item.SysAdminName = v.SysRealName
  110. item.CreateTime = time.Now()
  111. item.ModifyTime = time.Now()
  112. item.ShowTime = v.CreateTime
  113. item.CompanyId = v.CompanyId
  114. item.TableId = v.CompanyProductRemarkId
  115. item.TableName = "company_product_remark"
  116. items = append(items, item)
  117. }
  118. //company_product_remark end
  119. var condition string
  120. var pars []interface{}
  121. condition += ` AND product_id = 2 ORDER BY create_time DESC `
  122. listrenewed_note, err := company.GetCompanyNoRenewedNoteList(condition, pars, 0, 0)
  123. if err != nil {
  124. fmt.Println(err)
  125. return
  126. }
  127. //company_no_renewed_note
  128. for _, v := range listrenewed_note {
  129. if makHistoryMap[fmt.Sprintf("id_", v.NoRenewedNoteId, "name_", "company_no_renewed_note")] {
  130. continue
  131. }
  132. item := new(company.CompanyHistoryRemark)
  133. item.CompanyId = v.CompanyId
  134. item.Content = v.Content
  135. item.SysAdminId = v.AdminId
  136. item.SysAdminName = mapadmin[v.AdminId]
  137. item.CreateTime = time.Now()
  138. item.ModifyTime = time.Now()
  139. item.ShowTime = utils.StrTimeToTime(v.CreateTime)
  140. item.CompanyId = v.CompanyId
  141. item.TableId = v.NoRenewedNoteId
  142. item.TableName = "company_no_renewed_note"
  143. items = append(items, item)
  144. }
  145. //company_no_renewed_note end
  146. //company_renewal_reason
  147. listRenewa, e := models.GetMoreRenewalReasoninit()
  148. if e != nil {
  149. fmt.Println(e)
  150. return
  151. }
  152. for _, v := range listRenewa {
  153. if makHistoryMap[fmt.Sprintf("id_", v.CompanyRenewalReasonId, "name_", "company_renewal_reason")] {
  154. continue
  155. }
  156. item := new(company.CompanyHistoryRemark)
  157. item.CompanyId = v.CompanyId
  158. item.Content = v.RenewalReason
  159. //item.SysAdminId = v.SysUserId
  160. //item.SysAdminName = v.SysRealName
  161. item.CreateTime = time.Now()
  162. item.ModifyTime = time.Now()
  163. item.ShowTime = v.CreateTime
  164. item.CompanyId = v.CompanyId
  165. item.TableId = v.CompanyRenewalReasonId
  166. item.TableName = "company_renewal_reason"
  167. items = append(items, item)
  168. }
  169. //company_renewal_reason end
  170. //cygx_user_feedback
  171. // 权益服务明细表
  172. listUserFeedback, e := cygx.GetCygxUserFeedbackListInit()
  173. if e != nil {
  174. fmt.Println(e)
  175. return
  176. }
  177. for _, v := range listUserFeedback {
  178. if makHistoryMap[fmt.Sprintf("id_", v.UserFeedbackId, "name_", "cygx_user_feedback")] {
  179. continue
  180. }
  181. item := new(company.CompanyHistoryRemark)
  182. item.CompanyId = v.CompanyId
  183. item.Content = v.Content
  184. item.SysAdminId = v.AdminId
  185. item.SysAdminName = mapadmin[v.AdminId]
  186. item.CreateTime = time.Now()
  187. item.ModifyTime = time.Now()
  188. item.ShowTime = v.CreateTime
  189. item.CompanyId = v.CompanyId
  190. item.UserId = v.UserId
  191. item.Mobile = v.Mobile
  192. item.Email = v.Email
  193. item.RealName = v.RealName
  194. item.TableId = v.UserFeedbackId
  195. item.TableName = "cygx_user_feedback"
  196. items = append(items, item)
  197. }
  198. if len(items) > 0 {
  199. var itemsAdd []*company.CompanyHistoryRemark
  200. for k, v := range items {
  201. v.ProductId = 2
  202. itemsAdd = append(itemsAdd, v)
  203. if len(itemsAdd)%2000 == 0 {
  204. fmt.Println(k)
  205. e = company.AddCompanyHistoryRemarkMultiinit(itemsAdd)
  206. if e != nil {
  207. fmt.Println(e)
  208. return
  209. }
  210. itemsAdd = make([]*company.CompanyHistoryRemark, 0)
  211. }
  212. }
  213. e = company.AddCompanyHistoryRemarkMultiinit(itemsAdd)
  214. if e != nil {
  215. fmt.Println(e)
  216. return
  217. }
  218. }
  219. //cygx_user_feedback end
  220. fmt.Println(len(items))
  221. fmt.Println(len(records))
  222. return
  223. }