rs_calendar_meeting_user.go 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. package roadshow
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/models/cygx"
  5. "hongze/hz_crm_api/utils"
  6. "strconv"
  7. "time"
  8. )
  9. type AddRsCalendarMeetingUserReq struct {
  10. RsCalendarId int `description:"日程ID"`
  11. UserId []int // 用户ID
  12. TagList []*AddRsCalendarMeetingUserTagReq
  13. RoadShowTheme string `description:"路演主题"`
  14. }
  15. type AddRsCalendarMeetingUserTagReq struct {
  16. TagType int `description:"标签类型"`
  17. TagId int `description:"标签ID"`
  18. }
  19. type RsCalendarMeetingUser struct {
  20. RsCalendarMeetingUserId int `orm:"column(rs_calendar_meeting_user_id);pk" description:"主键ID"`
  21. RsCalendarId int `description:"日程ID"`
  22. UserId int `description:"用户ID"`
  23. Mobile string `description:"手机号"`
  24. Email string `description:"邮箱"`
  25. CompanyId int `description:"公司ID"`
  26. CompanyName string `description:"公司名称"`
  27. RealName string `description:"用户实际名称"`
  28. Position string `description:"职位"`
  29. AdminId int `description:"管理员ID"`
  30. AdminName string `description:"管理员姓名"`
  31. RoadShowTheme string `description:"路演主题"`
  32. CreateTime time.Time `description:"创建时间"`
  33. ModifyTime time.Time `description:"修改时间"`
  34. }
  35. type RsCalendarMeetingUserResp struct {
  36. RsCalendarMeetingUserId int `description:"参会名单主键ID"`
  37. RealName string `description:"用户实际名称"`
  38. Position string `description:"职位"`
  39. RoadShowTheme string `description:"路演主题"`
  40. }
  41. type DeleteRsCalendarMeetingUserReq struct {
  42. RsCalendarMeetingUserId int `description:"参会名单主键ID"`
  43. }
  44. type RsCalendarMeetingUserListResp struct {
  45. List []*RsCalendarMeetingUserResp
  46. ListLebel []*cygx.RaiServeTagResp
  47. RoadShowTheme string `description:"路演主题"`
  48. }
  49. // MultiAddRsCalendarMeetingUser 批量添加RsCalendarMeetingUser
  50. func MultiAddRsCalendarMeetingUser(items []*RsCalendarMeetingUser, roadShowTheme string, rsCalendarId int) (err error) {
  51. to, err := orm.NewOrm().Begin()
  52. if err != nil {
  53. return
  54. }
  55. defer func() {
  56. if err != nil {
  57. _ = to.Rollback()
  58. } else {
  59. _ = to.Commit()
  60. }
  61. }()
  62. sql := ` UPDATE rs_calendar_meeting_user SET road_show_theme=? WHERE rs_calendar_id=? `
  63. _, err = to.Raw(sql, roadShowTheme, rsCalendarId).Exec()
  64. if err != nil {
  65. return
  66. }
  67. if len(items) > 0 {
  68. _, err = to.InsertMulti(len(items), items)
  69. if err != nil {
  70. return
  71. }
  72. }
  73. return
  74. }
  75. // 获取第一个提交参会信息内容
  76. func GetRsCalendarMeetingUserFirst(rsCalendarId int) (item *RsCalendarResearcher, err error) {
  77. o := orm.NewOrm()
  78. sql := `SELECT * FROM rs_calendar_meeting_user WHERE rs_calendar_id=? LIMIT 1 `
  79. err = o.Raw(sql, rsCalendarId).QueryRow(&item)
  80. return
  81. }
  82. // 删除
  83. func DeleteRsCalendarMeetingUser(rsCalendarMeetingUserID int) (err error) {
  84. o := orm.NewOrm()
  85. sql := ` DELETE FROM rs_calendar_meeting_user WHERE rs_calendar_meeting_user_id=? `
  86. _, err = o.Raw(sql, rsCalendarMeetingUserID).Exec()
  87. return err
  88. }
  89. // 获取数量
  90. func GetRsCalendarMeetingUserCountByUserId(userId int) (count int, err error) {
  91. o := orm.NewOrm()
  92. sqlCount := ` SELECT COUNT(1) AS count FROM rs_calendar_meeting_user WHERE user_id = ?`
  93. err = o.Raw(sqlCount, userId).QueryRow(&count)
  94. return
  95. }
  96. // 获取数量
  97. func GetRsCalendarMeetingUserCountByUserModel(condition string, pars []interface{}) (count int, err error) {
  98. o := orm.NewOrm()
  99. sqlCount := ` SELECT COUNT(1) AS count FROM rs_calendar_meeting_user as r
  100. WHERE 1= 1 `
  101. if condition != "" {
  102. sqlCount += condition
  103. }
  104. err = o.Raw(sqlCount, pars).QueryRow(&count)
  105. return
  106. }
  107. // 获取数量
  108. func GetRsCalendarMeetingUserCountByUserModelWeekly(condition string, pars []interface{}) (count int, err error) {
  109. o := orm.NewOrm()
  110. sqlCount := ` SELECT COUNT(1) AS count FROM rs_calendar_meeting_user AS r
  111. INNER JOIN user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  112. WHERE 1 = 1 `
  113. if condition != "" {
  114. sqlCount += condition
  115. }
  116. err = o.Raw(sqlCount, pars).QueryRow(&count)
  117. return
  118. }
  119. // 列表
  120. func GetRsCalendarMeetingUserList(condition string, pars []interface{}) (items *RsCalendarMeetingUserResp, err error) {
  121. o := orm.NewOrm()
  122. sql := `SELECT * FROM rs_calendar_meeting_user WHERE 1=1 `
  123. if condition != "" {
  124. sql += condition
  125. }
  126. err = o.Raw(sql, pars).QueryRow(&items)
  127. return
  128. }
  129. // 通过路演ID获取参会人员列表
  130. func GetRsCalendarMeetingUserListByRsCalendarId(rsCalendarId int) (items []*RsCalendarMeetingUserResp, err error) {
  131. o := orm.NewOrm()
  132. sql := `SELECT * FROM rs_calendar_meeting_user WHERE rs_calendar_id = ? `
  133. _, err = o.Raw(sql, rsCalendarId).QueryRows(&items)
  134. return
  135. }
  136. type RsCalendarMeetingUserCountResp struct {
  137. RsCalendarId int `description:"日程ID"`
  138. Total int `description:"数量"`
  139. }
  140. // 路演参会人员数量
  141. func GetRsCalendarMeetingUserListCount(rsCalendarIds []int) (items []*RsCalendarMeetingUserCountResp, err error) {
  142. lenNum := len(rsCalendarIds)
  143. if lenNum <= 0 {
  144. return
  145. }
  146. o := orm.NewOrm()
  147. sql := `SELECT rs_calendar_id ,COUNT(1) as total FROM rs_calendar_meeting_user WHERE rs_calendar_id IN ( ` + utils.GetOrmInReplace(lenNum) + `) GROUP BY rs_calendar_id `
  148. _, err = o.Raw(sql, rsCalendarIds).QueryRows(&items)
  149. return
  150. }
  151. type RsCalendarMeetingUserByRai struct {
  152. RsCalendarMeetingUserId int `orm:"column(rs_calendar_meeting_user_id);pk" description:"主键ID"`
  153. RsCalendarId int `description:"日程ID"`
  154. UserId int `description:"用户ID"`
  155. Mobile string `description:"手机号"`
  156. Email string `description:"邮箱"`
  157. CompanyId int `description:"公司ID"`
  158. CompanyName string `description:"公司名称"`
  159. RealName string `description:"用户实际名称"`
  160. StartDate string `description:"开始时间"`
  161. EndDate string `description:"结束时间"`
  162. EndTime string `description:"开始时间"`
  163. StartTime string `description:"结束时间"`
  164. StartWeek string `description:"起始周"`
  165. RoadshowType string `description:"路演形式"`
  166. ResearcherName string `description:"研究员姓名"`
  167. TagType int `description:"标签类型,1产业,2标的,3行业权限"`
  168. RoadShowTheme string `description:"路演主题"`
  169. }
  170. // 权益联系人列表获取相关信息
  171. func GetRsCalendarMeetingUserByRai(condition string, startSize, pageSize int) (total int, items []*RsCalendarMeetingUserByRai, err error) {
  172. o := orm.NewOrm()
  173. var sql string
  174. sql += `SELECT
  175. r.company_id,
  176. r.company_name,
  177. r.real_name,
  178. r.mobile,
  179. r.road_show_theme,
  180. b.start_date,
  181. b.end_date,
  182. b.start_time,
  183. b.end_time,
  184. b.start_week,
  185. b.researcher_name,
  186. a.roadshow_type,
  187. a.rs_calendar_id,
  188. g.tag_type
  189. FROM
  190. rs_calendar_meeting_user AS r
  191. INNER JOIN rs_calendar AS a ON a.rs_calendar_id = r.rs_calendar_id
  192. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id = b.rs_calendar_id
  193. LEFT JOIN rs_calendar_meeting_label_group AS g ON g.rs_calendar_id = b.rs_calendar_id
  194. WHERE
  195. 1 = 1 ` + condition + ` GROUP BY r.rs_calendar_meeting_user_id `
  196. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  197. err = o.Raw(totalSql).QueryRow(&total)
  198. if err != nil {
  199. return
  200. }
  201. sql += ` ORDER BY b.start_date DESC ,b.start_time DESC , a.rs_calendar_id DESC `
  202. if startSize > 0 || pageSize > 0 {
  203. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  204. }
  205. _, err = o.Raw(sql).QueryRows(&items)
  206. return
  207. }
  208. func GetRsCalendarMeetingUserByRaiWeekly(condition string, startSize, pageSize int) (total int, items []*RsCalendarMeetingUserByRai, err error) {
  209. o := orm.NewOrm()
  210. var sql string
  211. sql += `SELECT
  212. r.company_id,
  213. r.company_name,
  214. r.real_name,
  215. r.mobile,
  216. r.road_show_theme,
  217. b.start_date,
  218. b.end_date,
  219. b.start_time,
  220. b.end_time,
  221. b.start_week,
  222. b.researcher_name,
  223. a.roadshow_type,
  224. a.rs_calendar_id
  225. FROM
  226. rs_calendar_meeting_user AS r
  227. INNER JOIN rs_calendar AS a ON a.rs_calendar_id = r.rs_calendar_id
  228. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id = b.rs_calendar_id
  229. INNER JOIN user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
  230. WHERE
  231. 1 = 1 ` + condition
  232. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  233. err = o.Raw(totalSql).QueryRow(&total)
  234. if err != nil {
  235. return
  236. }
  237. sql += `ORDER BY b.start_date DESC ,b.start_time DESC , a.rs_calendar_id DESC `
  238. if startSize > 0 || pageSize > 0 {
  239. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  240. }
  241. _, err = o.Raw(sql).QueryRows(&items)
  242. return
  243. }