activity_meet_detail_log.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_cygx/utils"
  6. "strconv"
  7. "strings"
  8. "time"
  9. )
  10. // 报名
  11. type CygxActivityMeetDetailLog struct {
  12. AttendanceId int `orm:"column(attendance_id);pk;"description:"主键ID"`
  13. ActivityId int `description:"活动ID"`
  14. RealName string `description:"姓名"`
  15. Mobile string `description:"手机号"`
  16. CompanyName string `description:"公司名称"`
  17. CompanyId int `description:"公司id 不在数据库的用户为0"`
  18. CreateTime time.Time `description:"创建时间"`
  19. ActivityTime string `description:"活动时间"`
  20. }
  21. // 批量添加
  22. func AddCygxActivityMeetDetailLogMulti(items []*CygxActivityMeetDetailLog) (err error) {
  23. o := orm.NewOrm()
  24. if len(items) > 0 {
  25. //批量添加
  26. _, err = o.InsertMulti(len(items), items)
  27. }
  28. return
  29. }
  30. // 列表
  31. func GetCygxActivityMeetDetailLogList(condition string, pars []interface{}) (items []*CygxActivityMeetDetailLog, err error) {
  32. o := orm.NewOrm()
  33. sql := `SELECT * FROM cygx_activity_meet_detail_log as art WHERE 1= 1 `
  34. if condition != "" {
  35. sql += condition
  36. }
  37. _, err = o.Raw(sql, pars).QueryRows(&items)
  38. return
  39. }
  40. func GetOfflineMeetingDetailListCompanyIdStr(companyIdStr string) (item []*CygxActivityMeetDetailLog, err error) {
  41. if companyIdStr == "" {
  42. return
  43. }
  44. o := orm.NewOrm()
  45. sql := `SELECT * FROM cygx_activity_offline_meeting_detail WHERE company_id IN (` + companyIdStr + `)`
  46. _, err = o.Raw(sql).QueryRows(&item)
  47. return
  48. }
  49. func GetOfflineMeetingDetailListCompanyName(companyName string) (item []*CygxActivityMeetDetailLog, err error) {
  50. o := orm.NewOrm()
  51. sql := `SELECT l.*
  52. FROM
  53. cygx_activity_meet_detail_log AS l INNER JOIN company AS c ON c.company_name = l.company_name
  54. WHERE
  55. l.company_name IN (` + companyName + `) GROUP BY l.company_name`
  56. _, err = o.Raw(sql).QueryRows(&item)
  57. return
  58. }
  59. // 添加
  60. func AddCygxActivityMeetDetailLog(item *CygxActivityMeetDetailLog) (lastId int64, err error) {
  61. o := orm.NewOrm()
  62. lastId, err = o.Insert(item)
  63. return
  64. }
  65. func GetActivityMeetDetailLog(mobileStr string) (item []*CygxActivityMeetDetailLog, err error) {
  66. if mobileStr == "" {
  67. return
  68. }
  69. o := orm.NewOrm()
  70. sql := `SELECT l.*
  71. FROM
  72. cygx_activity_meet_detail_log as l
  73. WHERE l.mobile IN (` + mobileStr + `) GROUP BY l.mobile `
  74. _, err = o.Raw(sql).QueryRows(&item)
  75. return
  76. }
  77. func GetActivityMeetDetailLogByMobile() (item []*CygxActivityMeetDetailLog, err error) {
  78. o := orm.NewOrm()
  79. sql := `SELECT * FROM cygx_activity_meet_detail_log WHERE mobile !='' GROUP BY mobile `
  80. _, err = o.Raw(sql).QueryRows(&item)
  81. return
  82. }
  83. // 获取数量
  84. func GetActivityMeetDetailLogCount(condition string) (count int, err error) {
  85. o := orm.NewOrm()
  86. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_meet_detail_log WHERE 1=1 `
  87. if condition != "" {
  88. sqlCount += condition
  89. }
  90. err = o.Raw(sqlCount).QueryRow(&count)
  91. return
  92. }
  93. // 报名
  94. type CygxActivityMeetDetailLogCountResp struct {
  95. Mobile string `description:"手机号"`
  96. CompanyId int `description:"公司id 不在数据库的用户为0"`
  97. Count int `description:"公司id 不在数据库的用户为0"`
  98. }
  99. // 获取数量
  100. func GetActivityMeetDetailLogCountCompany(companyIds []int) (item []*CygxActivityMeetDetailLogCountResp, err error) {
  101. lenArr := len(companyIds)
  102. if lenArr == 0 {
  103. return
  104. }
  105. o := orm.NewOrm()
  106. sql := ` SELECT company_id, COUNT(1) AS count FROM cygx_activity_meet_detail_log WHERE 1=1 AND company_id IN (` + utils.GetOrmInReplace(lenArr) + `) GROUP BY company_id`
  107. _, err = o.Raw(sql, companyIds).QueryRows(&item)
  108. return
  109. }
  110. // 获取数量
  111. func GetActivityMeetDetailLogCountMobile(mobiles []string) (item []*CygxActivityMeetDetailLogCountResp, err error) {
  112. lenArr := len(mobiles)
  113. if lenArr == 0 {
  114. return
  115. }
  116. o := orm.NewOrm()
  117. sql := ` SELECT mobile, COUNT(1) AS count FROM cygx_activity_meet_detail_log WHERE 1=1 AND mobile IN (` + utils.GetOrmInReplace(lenArr) + `) GROUP BY company_id`
  118. _, err = o.Raw(sql, mobiles).QueryRows(&item)
  119. return
  120. }
  121. // 修改公司参会数量
  122. func UpdateActivityMeetDetailLog(companyName string, num int) (err error) {
  123. sql := ` UPDATE cygx_activity_meet_detail_log SET company_meet_num= ? WHERE company_name = ?`
  124. o := orm.NewOrm()
  125. _, err = o.Raw(sql, num, companyName).Exec()
  126. return
  127. }
  128. // 修改个人参会数量
  129. func UpdateActivityMeetDetailLogByUser(mobile string, num int) (err error) {
  130. sql := ` UPDATE cygx_activity_meet_detail_log SET user_meet_num= ? WHERE mobile = ?`
  131. o := orm.NewOrm()
  132. _, err = o.Raw(sql, num, mobile).Exec()
  133. return
  134. }
  135. // 添加线上到会记录(下载使用)
  136. func AddCygxActivityMeetDetailLogOnline(list []*CygxActivityAttendanceDetail, activityId int) (err error) {
  137. o, err := orm.NewOrm().Begin()
  138. if err != nil {
  139. return
  140. }
  141. defer func() {
  142. fmt.Println(err)
  143. if err == nil {
  144. o.Commit()
  145. } else {
  146. o.Rollback()
  147. }
  148. }()
  149. var CompanyName string
  150. var MobileStr string
  151. var items []*CygxActivityMeetDetailLog
  152. //删除原有数据
  153. sql := ` DELETE FROM cygx_activity_meet_detail_log WHERE activity_id = ?`
  154. _, err = o.Raw(sql, activityId).Exec()
  155. if err != nil {
  156. return
  157. }
  158. //插入新的数据
  159. for _, v := range list {
  160. item := new(CygxActivityMeetDetailLog)
  161. item.ActivityId = v.ActivityId
  162. item.Mobile = v.Mobile
  163. item.CompanyName = v.CompanyName
  164. item.CompanyId = v.CompanyId
  165. item.CreateTime = v.CreateTime
  166. CompanyName += "'" + v.CompanyName + "',"
  167. MobileStr += v.Mobile + ","
  168. items = append(items, item)
  169. }
  170. CompanyName = strings.TrimRight(CompanyName, ",")
  171. MobileStr = strings.TrimRight(MobileStr, ",")
  172. _, err = o.InsertMulti(1, items)
  173. listCompany, err := GetOfflineMeetingDetailListCompanyName(CompanyName)
  174. if err != nil {
  175. return
  176. }
  177. //修改公司对应的数量
  178. var condition string
  179. for _, v := range listCompany {
  180. var total int
  181. condition = ` AND company_name = '` + v.CompanyName + `' `
  182. total, err = GetActivityMeetDetailLogCount(condition)
  183. if err != nil {
  184. return
  185. }
  186. sql := ` UPDATE cygx_activity_meet_detail_log SET company_meet_num= ? WHERE company_name = ?`
  187. _, err = o.Raw(sql, total, v.CompanyName).Exec()
  188. if err != nil {
  189. return
  190. }
  191. }
  192. listMobile, err := GetActivityMeetDetailLog(MobileStr)
  193. if err != nil {
  194. return
  195. }
  196. //修改个人对应的数量
  197. for _, v := range listMobile {
  198. var total int
  199. condition = ` AND mobile = '` + v.Mobile + `' `
  200. total, err = GetActivityMeetDetailLogCount(condition)
  201. if err != nil {
  202. return
  203. }
  204. sql := ` UPDATE cygx_activity_meet_detail_log SET user_meet_num= ? WHERE mobile = ?`
  205. _, err = o.Raw(sql, total, v.Mobile).Exec()
  206. if err != nil {
  207. return
  208. }
  209. }
  210. return
  211. }
  212. // 添加线上到会记录
  213. func AddCygxActivityMeetDetailLogOnlineByListNew(list []*CygxActivityAttendanceDetail, activityIds string) (err error) {
  214. o, err := orm.NewOrm().Begin()
  215. if err != nil {
  216. return
  217. }
  218. defer func() {
  219. fmt.Println(err)
  220. if err == nil {
  221. o.Commit()
  222. } else {
  223. o.Rollback()
  224. }
  225. }()
  226. var CompanyName string
  227. var MobileStr string
  228. var items []*CygxActivityMeetDetailLog
  229. //删除原有数据
  230. sql := ` DELETE FROM cygx_activity_meet_detail_log WHERE activity_id IN (` + activityIds + `)`
  231. _, err = o.Raw(sql).Exec()
  232. if err != nil {
  233. return
  234. }
  235. //插入新的数据
  236. for _, v := range list {
  237. item := new(CygxActivityMeetDetailLog)
  238. item.ActivityId = v.ActivityId
  239. item.Mobile = v.Mobile
  240. fmt.Println(v.CompanyName)
  241. item.CompanyName = v.CompanyName
  242. item.CompanyId = v.CompanyId
  243. item.ActivityTime = v.ActivityTime
  244. item.CreateTime = v.CreateTime
  245. if strings.Index(CompanyName, v.CompanyName) == -1 && v.CompanyName != "" {
  246. CompanyName += "'" + v.CompanyName + "',"
  247. }
  248. if strings.Index(MobileStr, v.Mobile) == -1 && v.Mobile != "" {
  249. MobileStr += v.Mobile + ","
  250. }
  251. items = append(items, item)
  252. }
  253. CompanyName = strings.TrimRight(CompanyName, ",")
  254. MobileStr = strings.TrimRight(MobileStr, ",")
  255. _, err = o.InsertMulti(1, items)
  256. listCompany, err := GetOfflineMeetingDetailListCompanyName(CompanyName)
  257. fmt.Println("公司数量", len(listCompany))
  258. if err != nil {
  259. return
  260. }
  261. //修改公司对应的数量
  262. var condition string
  263. for _, v := range listCompany {
  264. var total int
  265. condition = ` AND company_name = '` + v.CompanyName + `' `
  266. total, err = GetActivityMeetDetailLogCount(condition)
  267. if err != nil {
  268. return
  269. }
  270. sql := ` UPDATE cygx_activity_meet_detail_log SET company_meet_num= ? WHERE company_name = ?`
  271. _, err = o.Raw(sql, total, v.CompanyName).Exec()
  272. fmt.Println("处理公司", v.CompanyName)
  273. if err != nil {
  274. return
  275. }
  276. }
  277. listMobile, err := GetActivityMeetDetailLog(MobileStr)
  278. fmt.Println("用户数量", len(listMobile))
  279. if err != nil {
  280. return
  281. }
  282. //修改个人对应的数量
  283. for _, v := range listMobile {
  284. var total int
  285. condition = ` AND mobile = '` + v.Mobile + `' `
  286. total, err = GetActivityMeetDetailLogCount(condition)
  287. if err != nil {
  288. return
  289. }
  290. sql := ` UPDATE cygx_activity_meet_detail_log SET user_meet_num= ? WHERE mobile = ?`
  291. _, err = o.Raw(sql, total, v.Mobile).Exec()
  292. fmt.Println("处理用户", v.Mobile)
  293. if err != nil {
  294. return
  295. }
  296. }
  297. fmt.Println("user_end")
  298. return
  299. }
  300. // 添加线下到会记录
  301. func AddCygxActivityMeetDetailLogOffline(activityId int) (err error) {
  302. o := orm.NewOrm()
  303. to, err := o.Begin()
  304. if err != nil {
  305. return
  306. }
  307. defer func() {
  308. if err != nil {
  309. fmt.Println(err)
  310. _ = to.Rollback()
  311. } else {
  312. _ = to.Commit()
  313. }
  314. }()
  315. var condition string
  316. var pars []interface{}
  317. condition = ` AND activity_id = ? `
  318. pars = append(pars, activityId)
  319. listOfflineMeeting, err := GetOfflineMeetingList(condition, pars)
  320. if err != nil {
  321. return
  322. }
  323. var meetingUids string
  324. for _, v := range listOfflineMeeting {
  325. meetingUids += strconv.Itoa(v.UserId) + ","
  326. }
  327. meetingUids = strings.TrimRight(meetingUids, ",")
  328. if meetingUids == "" {
  329. meetingUids = "-1"
  330. }
  331. var CompanyIdStr string
  332. var MobileStr string
  333. var items []*CygxActivityMeetDetailLog
  334. list, err := GetOfflineMeetingListByUser(meetingUids, activityId)
  335. fmt.Println(len(list))
  336. if err != nil {
  337. return
  338. }
  339. //删除原有数据
  340. sql := ` DELETE FROM cygx_activity_meet_detail_log WHERE activity_id = ?`
  341. _, err = to.Raw(sql, activityId).Exec()
  342. if err != nil {
  343. return
  344. }
  345. //插入新的数据
  346. for _, v := range list {
  347. item := new(CygxActivityMeetDetailLog)
  348. item.ActivityId = v.ActivityId
  349. item.Mobile = v.Mobile
  350. item.CompanyName = v.CompanyName
  351. item.CompanyId = v.CompanyId
  352. item.CreateTime = v.CreateTime
  353. CompanyIdStr += strconv.Itoa(v.CompanyId) + ","
  354. if v.Mobile != "" {
  355. MobileStr += v.Mobile + ","
  356. }
  357. items = append(items, item)
  358. }
  359. CompanyIdStr = strings.TrimRight(CompanyIdStr, ",")
  360. MobileStr = strings.TrimRight(MobileStr, ",")
  361. for _, v := range items {
  362. _, err = to.Insert(v)
  363. if err != nil {
  364. return
  365. }
  366. }
  367. listCompanyId, err := GetOfflineMeetingDetailListCompanyIdStr(CompanyIdStr)
  368. if err != nil {
  369. return
  370. }
  371. //修改公司对应的数量
  372. //var condition string
  373. for _, v := range listCompanyId {
  374. var total int
  375. condition = ` AND company_name = '` + v.CompanyName + `' `
  376. total, err = GetActivityMeetDetailLogCount(condition)
  377. if err != nil {
  378. return
  379. }
  380. sql := ` UPDATE cygx_activity_meet_detail_log SET company_meet_num= ? WHERE company_name = ?`
  381. _, err = to.Raw(sql, total, v.CompanyName).Exec()
  382. if err != nil {
  383. return
  384. }
  385. }
  386. listMobile, err := GetActivityMeetDetailLog(MobileStr)
  387. if err != nil {
  388. return
  389. }
  390. //修改个人对应的数量
  391. for _, v := range listMobile {
  392. var total int
  393. condition = ` AND mobile = '` + v.Mobile + `' `
  394. total, err = GetActivityMeetDetailLogCount(condition)
  395. if err != nil {
  396. return
  397. }
  398. sql := ` UPDATE cygx_activity_meet_detail_log SET user_meet_num= ? WHERE mobile = ?`
  399. _, err = to.Raw(sql, total, v.Mobile).Exec()
  400. if err != nil {
  401. return
  402. }
  403. }
  404. return
  405. }
  406. // 添加线上到会记录
  407. func AddCygxActivityMeetDetailLogOnlineByList(list []*CygxActivityAttendanceDetail, activityIds string) (err error) {
  408. o, err := orm.NewOrm().Begin()
  409. if err != nil {
  410. return
  411. }
  412. defer func() {
  413. fmt.Println(err)
  414. if err == nil {
  415. o.Commit()
  416. } else {
  417. o.Rollback()
  418. }
  419. }()
  420. var CompanyName string
  421. var MobileStr string
  422. var items []*CygxActivityMeetDetailLog
  423. //删除原有数据
  424. sql := ` DELETE FROM cygx_activity_meet_detail_log WHERE activity_id IN (` + activityIds + `)`
  425. _, err = o.Raw(sql).Exec()
  426. if err != nil {
  427. return
  428. }
  429. //插入新的数据
  430. for _, v := range list {
  431. item := new(CygxActivityMeetDetailLog)
  432. item.ActivityId = v.ActivityId
  433. item.Mobile = v.Mobile
  434. fmt.Println(v.CompanyName)
  435. item.CompanyName = v.CompanyName
  436. item.CompanyId = v.CompanyId
  437. item.ActivityTime = v.ActivityTime
  438. item.CreateTime = v.CreateTime
  439. if strings.Index(CompanyName, v.CompanyName) == -1 && v.CompanyName != "" {
  440. CompanyName += "'" + v.CompanyName + "',"
  441. }
  442. if strings.Index(MobileStr, v.Mobile) == -1 && v.Mobile != "" {
  443. MobileStr += v.Mobile + ","
  444. }
  445. items = append(items, item)
  446. }
  447. CompanyName = strings.TrimRight(CompanyName, ",")
  448. MobileStr = strings.TrimRight(MobileStr, ",")
  449. _, err = o.InsertMulti(1, items)
  450. listCompany, err := GetOfflineMeetingDetailListCompanyName(CompanyName)
  451. fmt.Println("公司数量", len(listCompany))
  452. if err != nil {
  453. return
  454. }
  455. //修改公司对应的数量
  456. var condition string
  457. for _, v := range listCompany {
  458. var total int
  459. condition = ` AND company_name = '` + v.CompanyName + `' `
  460. total, err = GetActivityMeetDetailLogCount(condition)
  461. if err != nil {
  462. return
  463. }
  464. sql := ` UPDATE cygx_activity_meet_detail_log SET company_meet_num= ? WHERE company_name = ?`
  465. _, err = o.Raw(sql, total, v.CompanyName).Exec()
  466. fmt.Println("处理公司", v.CompanyName)
  467. if err != nil {
  468. return
  469. }
  470. }
  471. listMobile, err := GetActivityMeetDetailLog(MobileStr)
  472. fmt.Println("用户数量", len(listMobile))
  473. if err != nil {
  474. return
  475. }
  476. //修改个人对应的数量
  477. for _, v := range listMobile {
  478. var total int
  479. condition = ` AND mobile = '` + v.Mobile + `' `
  480. total, err = GetActivityMeetDetailLogCount(condition)
  481. if err != nil {
  482. return
  483. }
  484. sql := ` UPDATE cygx_activity_meet_detail_log SET user_meet_num= ? WHERE mobile = ?`
  485. _, err = o.Raw(sql, total, v.Mobile).Exec()
  486. fmt.Println("处理用户", v.Mobile)
  487. if err != nil {
  488. return
  489. }
  490. }
  491. fmt.Println("user_end")
  492. return
  493. }
  494. // UpdateActivitySpecialSignupNumMulti 批量修改个人参会数量
  495. func UpdateCygxActivityMeetDetailLogMobileNumMulti(items []*CygxActivityMeetDetailLogCountResp) (err error) {
  496. o := orm.NewOrm()
  497. p, err := o.Raw("UPDATE cygx_activity_meet_detail_log SET user_meet_num = ? WHERE mobile = ?").Prepare()
  498. if err != nil {
  499. return
  500. }
  501. defer func() {
  502. _ = p.Close()
  503. }()
  504. for _, v := range items {
  505. _, err = p.Exec(v.Count, v.Mobile)
  506. if err != nil {
  507. return
  508. }
  509. }
  510. return
  511. }
  512. // UpdateActivitySpecialSignupNumMulti 批量修改机构参会数量
  513. func UpdateCygxActivityMeetDetailLogCompanyNumMulti(items []*CygxActivityMeetDetailLogCountResp) (err error) {
  514. o := orm.NewOrm()
  515. p, err := o.Raw("UPDATE cygx_activity_meet_detail_log SET company_meet_num = ? WHERE company_id = ?").Prepare()
  516. if err != nil {
  517. return
  518. }
  519. defer func() {
  520. _ = p.Close()
  521. }()
  522. for _, v := range items {
  523. _, err = p.Exec(v.Count, v.CompanyId)
  524. if err != nil {
  525. return
  526. }
  527. }
  528. return
  529. }