calendar.go 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548
  1. package roadshow
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_mobile_admin/controllers"
  6. "hongze/hongze_mobile_admin/models"
  7. "hongze/hongze_mobile_admin/models/roadshow"
  8. "hongze/hongze_mobile_admin/models/tables/admin"
  9. "hongze/hongze_mobile_admin/services"
  10. "hongze/hongze_mobile_admin/services/rs"
  11. "hongze/hongze_mobile_admin/utils"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. //日历
  17. type CalendarController struct {
  18. controllers.BaseAuth
  19. }
  20. // @Title 新增路演活动接口
  21. // @Description 新增路演活动接口
  22. // @Param request body rs.AddActivityReq true "type json string"
  23. // @Success Ret=200 保存成功
  24. // @router /add [post]
  25. func (this *CalendarController) Add() {
  26. sysUser := this.AdminWx
  27. if sysUser == nil {
  28. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  29. return
  30. }
  31. deleteCache := true
  32. cacheKey := "CACHE_RS_ACTIVITY_WX_ADD_" + strconv.Itoa(sysUser.AdminId)
  33. defer func() {
  34. if deleteCache {
  35. utils.Rc.Delete(cacheKey)
  36. }
  37. }()
  38. if !utils.Rc.SetNX(cacheKey, 1, 5*time.Second) {
  39. deleteCache = false
  40. this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!"+sysUser.RealName+";data:"+string(this.Ctx.Input.RequestBody))
  41. return
  42. }
  43. var req roadshow.AddActivityReq
  44. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  45. if err != nil {
  46. this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
  47. return
  48. }
  49. if len(req.ResearcherList) <= 0 {
  50. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  51. return
  52. }
  53. researcherMap := make(map[int]string)
  54. var checkIsAdd []string
  55. //var tipMsg string
  56. for _, v := range req.ResearcherList {
  57. if v.ResearcherId <= 0 {
  58. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  59. return
  60. }
  61. if v.ResearcherName == "" {
  62. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  63. return
  64. }
  65. if v.StartDate == "" {
  66. this.FailWithMessage("请选择开始日期!", "请选择开始日期!")
  67. return
  68. }
  69. if v.EndDate == "" {
  70. this.FailWithMessage("请选择结束日期!", "请选择结束日期!")
  71. return
  72. }
  73. if v.StartTime == "" {
  74. this.FailWithMessage("请选择开始时间!", "请选择开始时间!")
  75. return
  76. }
  77. if v.EndTime == "" {
  78. this.FailWithMessage("请选择结束时间!", "请选择结束时间!")
  79. return
  80. }
  81. if v.StartWeek == "" {
  82. this.FailWithMessage("请选择周!", "请选择周!")
  83. return
  84. }
  85. if v.EndWeek == "" {
  86. this.FailWithMessage("请选择周!", "请选择周!")
  87. return
  88. }
  89. startDateTime := v.StartDate + " " + v.StartTime
  90. endDateTime := v.EndDate + " " + v.EndTime
  91. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  92. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  93. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  94. this.FailWithMessage("活动开始时间不能小于当前时间!", "活动开始时间不能小于当前时间!")
  95. return
  96. }
  97. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  98. this.FailWithMessage("活动结束时间不能小于当前时间!", "活动结束时间不能小于当前时间!")
  99. return
  100. }
  101. if startP.After(endP) || startP.Equal(endP) {
  102. this.FailWithMessage("活动开始时间应小于结束时间!", "活动开始时间应小于结束时间!")
  103. return
  104. }
  105. if realName, ok := researcherMap[v.ResearcherId]; ok {
  106. this.FailWithMessage("研究员:"+realName+" 被重复选择", "研究员:"+realName+" 被重复选择")
  107. return
  108. }
  109. researcherMap[v.ResearcherId] = v.ResearcherName
  110. //同步上海数据
  111. researcherInfo, err := admin.GetAdminWxById(v.ResearcherId)
  112. if err != nil {
  113. this.FailWithMessage("研究员异常", "获取研究员异常,Err:"+err.Error())
  114. return
  115. }
  116. _ = rs.SyncCalendarFromShanghai(researcherInfo.Mobile, v.StartDate, v.EndDate)
  117. //校验事项时间冲突
  118. {
  119. matterCount, err := rs.CheckMatters(startDateTime, endDateTime, v.ResearcherId, 0)
  120. if err != nil {
  121. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
  122. return
  123. }
  124. if matterCount > 0 {
  125. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  126. }
  127. }
  128. //校验活动时间冲突
  129. {
  130. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, 0)
  131. if err != nil {
  132. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendar!Err:"+err.Error())
  133. return
  134. }
  135. if calendarCount > 0 {
  136. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  137. }
  138. }
  139. }
  140. if len(checkIsAdd) > 0 {
  141. this.FailWithMessage(strings.Join(checkIsAdd, ",")+" 时间已被占用!", "时间冲突检测失败-CheckMattersCount!")
  142. return
  143. }
  144. rsCalendar := new(roadshow.RsCalendar)
  145. rsCalendar.SysUserId = sysUser.AdminId
  146. rsCalendar.SysUserRealName = sysUser.RealName
  147. rsCalendar.ActivityType = req.ActivityType
  148. rsCalendar.RoadshowType = req.RoadshowType
  149. rsCalendar.RoadshowPlatform = req.RoadshowPlatform
  150. rsCalendar.CompanyId = req.CompanyId
  151. rsCalendar.CompanyName = req.CompanyName
  152. rsCalendar.Province = req.Province
  153. rsCalendar.ProvinceCode = req.ProvinceCode
  154. rsCalendar.City = req.City
  155. rsCalendar.CityCode = req.CityCode
  156. rsCalendar.Theme = req.Theme
  157. rsCalendar.CooperationName = req.CooperationName
  158. rsCalendar.CreateTime = time.Now()
  159. rsCalendar.ModifyTime = time.Now()
  160. rsCalendar.ActivityCategory = req.ActivityCategory
  161. rsCalendar.Source = 0
  162. rsCalendar.Title = getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City)
  163. rsCalendarId, err := roadshow.AddRsCalendar(rsCalendar)
  164. if err != nil {
  165. this.FailWithMessage("保存失败", "保存日历活动信息失败!Err:"+err.Error())
  166. return
  167. }
  168. //if researcherId != 99 {
  169. for k, v := range req.ResearcherList {
  170. researcher := new(roadshow.RsCalendarResearcher)
  171. researcher.RsCalendarId = int(rsCalendarId)
  172. researcher.ResearcherId = v.ResearcherId
  173. researcher.ResearcherName = v.ResearcherName
  174. researcher.StartDate = v.StartDate
  175. researcher.EndDate = v.EndDate
  176. researcher.StartTime = v.StartTime
  177. researcher.EndTime = v.EndTime
  178. researcher.StartWeek = v.StartWeek
  179. researcher.EndWeek = v.EndWeek
  180. researcher.CreateTime = time.Now()
  181. researcher.ModifyTime = time.Now()
  182. researcher.ResearcherSort = k + 1
  183. if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
  184. researcher.Status = 1
  185. } else {
  186. researcher.Status = 2
  187. }
  188. rsCalendarResearcherId, err := roadshow.AddRsCalendarResearcher(researcher)
  189. if err != nil {
  190. this.FailWithMessage("保存失败", "保存日历活动-研究员信息失败!Err:"+err.Error())
  191. return
  192. }
  193. rsCalendar.RsCalendarId = int(rsCalendarId)
  194. researcher.RsCalendarResearcherId = int(rsCalendarResearcherId)
  195. go rs.CalendarToSH(*rsCalendar, *researcher)
  196. //模板消息通知
  197. {
  198. go func() {
  199. sysAdmin, _ := admin.GetAdminWxById(v.ResearcherId)
  200. if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
  201. first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  202. keyword1 := sysUser.RealName
  203. keyword2 := "--"
  204. keyword3 := time.Now().Format(utils.FormatDateTime)
  205. startDateSub := v.StartDate[5:]
  206. startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  207. var keyword4 string
  208. if req.ActivityType == "路演" {
  209. keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  210. } else {
  211. keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  212. }
  213. remark := "请尽快完成审批"
  214. wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(int(rsCalendarId)) + "&RsCalendarResearcherId=" + strconv.Itoa(int(rsCalendarResearcherId))
  215. openIdList, _ := models.GetAdminOpenIdByMobile(sysAdmin.Mobile)
  216. if len(openIdList) > 0 {
  217. services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
  218. }
  219. }
  220. }()
  221. }
  222. }
  223. this.OkDetailed(nil, "保存成功")
  224. }
  225. // CalendarList
  226. // @Title 我的日历列表
  227. // @Description 我的日历列表接口
  228. // @Param PageSize query int true "每页数据条数"
  229. // @Param CurrentIndex query int true "当前页页码,从1开始"
  230. // @Param Status query int true "1:待接受,2:包含,已接受,已拒绝,已删除"
  231. // @Success 200 {object} rs.CalendarListResp
  232. // @router /calendar/list [get]
  233. func (this *CalendarController) CalendarList() {
  234. adminItem := this.AdminWx
  235. status, _ := this.GetInt("Status")
  236. pageSize, _ := this.GetInt("PageSize")
  237. currentIndex, _ := this.GetInt("CurrentIndex")
  238. var total int
  239. page := paging.GetPaging(currentIndex, pageSize, total)
  240. var startSize int
  241. if pageSize <= 0 {
  242. pageSize = utils.PageSize10
  243. }
  244. if currentIndex <= 0 {
  245. currentIndex = 1
  246. }
  247. startSize = paging.StartIndex(currentIndex, pageSize)
  248. var condition string
  249. var pars []interface{}
  250. condition += ` AND b.researcher_id=?`
  251. pars = append(pars, adminItem.AdminId)
  252. condition += ` AND a.activity_type IN('路演','公开会议') `
  253. if status == 1 {
  254. condition += ` AND b.status=?`
  255. pars = append(pars, 1)
  256. } else {
  257. condition += ` AND b.status IN(2,3,4)`
  258. }
  259. resp := new(roadshow.CalendarListResp)
  260. total, err := roadshow.GetCalendarListCount(condition, pars)
  261. if err != nil && err.Error() != utils.ErrNoRow() {
  262. this.FailWithMessage("获取信息失败!", "获取数据总数失败,GetCalendarListCount,Err:"+err.Error())
  263. return
  264. }
  265. page = paging.GetPaging(currentIndex, pageSize, total)
  266. dataList, err := roadshow.GetCalendarList(condition, pars, status, startSize, pageSize)
  267. if err != nil {
  268. this.FailWithMessage("获取信息失败!", "获取数据失败,GetCalendarList,Err:"+err.Error())
  269. return
  270. }
  271. resp.Paging = page
  272. resp.List = dataList
  273. this.OkDetailed(resp, "获取成功")
  274. }
  275. // Accept
  276. // @Description 接受路演活动接口
  277. // @Param request body rs.AcceptReq true "type json string"
  278. // @Success Ret=200 保存成功
  279. // @router /accept [post]
  280. func (this *CalendarController) Accept() {
  281. //adminItem:=this.AdminWx
  282. var req roadshow.AcceptReq
  283. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  284. if err != nil {
  285. this.FailWithMessage("参数解析失败!", "参数解析失败,Err:"+err.Error())
  286. return
  287. }
  288. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  289. this.FailWithMessage("参数错误!", "RsCalendarId 或 RsCalendarResearcherId 小于等于0:")
  290. return
  291. }
  292. rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  293. if err != nil {
  294. this.FailWithMessage("获取数据失败!", "GetRsCalendarById Err:"+err.Error())
  295. return
  296. }
  297. rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  298. if err != nil {
  299. this.FailWithMessage("获取数据失败!", "GetRsCalendarResearcherById Err:"+err.Error())
  300. return
  301. }
  302. if rsCalendarResearcher.Status == 2 {
  303. this.FailWithMessage("已接受,不可重复操作!", "")
  304. return
  305. } else if rsCalendarResearcher.Status == 3 {
  306. this.FailWithMessage("已拒绝,不可进行接受操作!", "")
  307. return
  308. } else if rsCalendarResearcher.Status == 4 {
  309. this.FailWithMessage("已删除,不可进行接受操作!", "")
  310. return
  311. } else if rsCalendarResearcher.Status == 5 {
  312. this.FailWithMessage("已撤回,不可进行接受操作!", "")
  313. return
  314. }
  315. whereParams := make(map[string]interface{})
  316. updateParams := make(map[string]interface{})
  317. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  318. whereParams["rs_calendar_id"] = req.RsCalendarId
  319. updateParams["status"] = 2
  320. updateParams["modify_time"] = time.Now()
  321. updateParams["approve_time"] = time.Now()
  322. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  323. if err != nil {
  324. this.FailWithMessage("获取数据失败!", "UpdateCalendarResearcher Err:"+err.Error())
  325. return
  326. }
  327. //模板消息通知
  328. {
  329. if rsCalendar != nil {
  330. sysAdmin, _ := admin.GetAdminById(rsCalendar.SysUserId)
  331. first := "【" + this.AdminWx.RealName + "】接受了你的【" + rsCalendar.ActivityType + "】申请"
  332. var keyword1 string
  333. if rsCalendar.ActivityType == "路演" {
  334. keyword1 = rsCalendar.CompanyName + "," + rsCalendar.RoadshowType + rsCalendar.ActivityType
  335. } else {
  336. keyword1 = rsCalendar.Theme + "," + rsCalendar.RoadshowType + rsCalendar.ActivityType
  337. }
  338. keyword2 := "已接受"
  339. remark := ""
  340. if sysAdmin.Mobile != "" {
  341. go services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, sysAdmin.Mobile, "", "")
  342. }
  343. }
  344. }
  345. this.OkDetailed(nil, "保存成功")
  346. }
  347. // @Title 拒绝路演活动接口
  348. // @Description 拒绝路演活动接口
  349. // @Param request body rs.RefuseReq true "type json string"
  350. // @Success Ret=200 保存成功
  351. // @router /refuse [post]
  352. func (this *CalendarController) Refuse() {
  353. //adminItem:=this.AdminWx
  354. var req roadshow.RefuseReq
  355. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  356. if err != nil {
  357. this.FailWithMessage("参数解析失败!", "参数解析失败,Err:"+err.Error())
  358. return
  359. }
  360. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  361. this.FailWithMessage("参数错误!", "参数错误!RsCalendarId:"+strconv.Itoa(req.RsCalendarId)+";RsCalendarResearcherId:"+strconv.Itoa(req.RsCalendarResearcherId))
  362. return
  363. }
  364. rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  365. if err != nil {
  366. this.FailWithMessage("获取数据失败!", "GetRsCalendarById,Err:"+err.Error())
  367. return
  368. }
  369. rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  370. if err != nil {
  371. this.FailWithMessage("获取数据失败!", "GetRsCalendarResearcherById,Err:"+err.Error())
  372. return
  373. }
  374. if rsCalendarResearcher.Status == 2 {
  375. this.FailWithMessage("已接受,不可进行拒绝操作!", "")
  376. return
  377. } else if rsCalendarResearcher.Status == 3 {
  378. this.FailWithMessage("已拒绝,不可进行重复操作!", "")
  379. return
  380. } else if rsCalendarResearcher.Status == 4 {
  381. this.FailWithMessage("已删除,不可进行拒绝操作!", "")
  382. return
  383. } else if rsCalendarResearcher.Status == 5 {
  384. this.FailWithMessage("已撤回,不可进行拒绝操作!", "")
  385. return
  386. }
  387. whereParams := make(map[string]interface{})
  388. updateParams := make(map[string]interface{})
  389. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  390. whereParams["rs_calendar_id"] = req.RsCalendarId
  391. updateParams["status"] = 3
  392. updateParams["refuse_reason"] = req.RefuseReason
  393. updateParams["refuse_time"] = time.Now()
  394. updateParams["modify_time"] = time.Now()
  395. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  396. if err != nil {
  397. this.FailWithMessage("保存失败", "保存失败!UpdateCalendarResearcher:"+err.Error())
  398. return
  399. }
  400. // 拒绝后需要删除上海的日程
  401. go rs.DeleteSHCalendar(req.RsCalendarResearcherId)
  402. //模板消息通知
  403. {
  404. if rsCalendar != nil {
  405. sysAdmin, _ := admin.GetAdminById(rsCalendar.SysUserId)
  406. first := "【" + this.AdminWx.RealName + "】拒绝了你的【" + rsCalendar.ActivityType + "】申请"
  407. var keyword1 string
  408. if rsCalendar.ActivityType == "路演" {
  409. keyword1 = rsCalendar.CompanyName + "," + rsCalendar.RoadshowType + rsCalendar.ActivityType
  410. } else {
  411. keyword1 = rsCalendar.Theme + "," + rsCalendar.RoadshowType + rsCalendar.ActivityType
  412. }
  413. keyword2 := "已拒绝"
  414. remark := req.RefuseReason
  415. if sysAdmin.Mobile != "" {
  416. go services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, sysAdmin.Mobile, "", "")
  417. }
  418. }
  419. }
  420. this.OkDetailed(nil, "保存成功")
  421. }
  422. // @Title 日历详情
  423. // @Description 日历详情接口
  424. // @Param RsCalendarId query int true "路演活动id"
  425. // @Param RsCalendarResearcherId query int true "活动研究员id"
  426. // @Success 200 {object} rs.CalendarDetailResp
  427. // @router /calendar/detail [get]
  428. func (this *CalendarController) CalendarDetail() {
  429. //adminItem:=this.AdminWx
  430. //roleTypeCode := adminItem.RoleTypeCode
  431. rsCalendarId, _ := this.GetInt("RsCalendarId")
  432. rsCalendarResearcherId, _ := this.GetInt("RsCalendarResearcherId")
  433. if rsCalendarId <= 0 || rsCalendarResearcherId <= 0 {
  434. this.FailWithMessage("参数错误", "rsCalendarId 或 rsCalendarResearcherId")
  435. return
  436. }
  437. calendarItem, err := roadshow.GetRsCalendarById(rsCalendarId)
  438. if err != nil {
  439. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarById:"+err.Error())
  440. return
  441. }
  442. rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(rsCalendarResearcherId)
  443. if err != nil {
  444. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  445. return
  446. }
  447. companyDetailView := new(roadshow.CompanyDetailView)
  448. if calendarItem != nil && calendarItem.CompanyId > 0 {
  449. companyId := calendarItem.CompanyId
  450. companyProductItem, err := models.GetCompanyProductByCompanyIdAndProductId(companyId, 1)
  451. if err != nil {
  452. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  453. return
  454. }
  455. permissionList, err := models.GetCompanyProductReportPermissionList(companyId, 1)
  456. if err != nil {
  457. this.FailWithMessage("搜索客户权限失败", "搜索客户权限失败!GetRsCalendarResearcherById:"+err.Error())
  458. return
  459. }
  460. var permissionArr []string
  461. for _, v := range permissionList {
  462. permissionArr = append(permissionArr, v.PermissionName)
  463. }
  464. readNum := companyProductItem.ViewTotal
  465. companyDetailView.CompanyId = companyProductItem.CompanyId
  466. companyDetailView.CompanyName = companyProductItem.CompanyName
  467. companyDetailView.Status = companyProductItem.Status
  468. companyDetailView.IndustryId = companyProductItem.IndustryId
  469. companyDetailView.IndustryName = companyProductItem.IndustryName
  470. companyDetailView.PermissionName = strings.Join(permissionArr, "/")
  471. companyDetailView.ReportReadTotal = readNum //ficc报告-累计阅读次数
  472. }
  473. resp := new(roadshow.CalendarDetailResp)
  474. resp.RsCalendarItem = calendarItem
  475. resp.RsCalendarResearcherItem = rsCalendarResearcherItem
  476. resp.CompanyDetail = companyDetailView
  477. this.OkDetailed(resp, "获取成功")
  478. }
  479. // @Title 事项列表
  480. // @Description 事项列表接口
  481. // @Param PageSize query int true "每页数据条数"
  482. // @Param CurrentIndex query int true "当前页页码,从1开始"
  483. // @Success 200 {object} rs.MattersListResp
  484. // @router /matters/list [get]
  485. func (this *CalendarController) MattersList() {
  486. sysUser := this.AdminWx
  487. if sysUser == nil {
  488. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  489. return
  490. }
  491. pageSize, _ := this.GetInt("PageSize")
  492. currentIndex, _ := this.GetInt("CurrentIndex")
  493. var total int
  494. page := paging.GetPaging(currentIndex, pageSize, total)
  495. var startSize int
  496. if pageSize <= 0 {
  497. pageSize = utils.PageSize10
  498. }
  499. if currentIndex <= 0 {
  500. currentIndex = 1
  501. }
  502. startSize = paging.StartIndex(currentIndex, pageSize)
  503. var condition string
  504. var pars []interface{}
  505. condition += ` AND a.sys_user_id=?`
  506. pars = append(pars, sysUser.AdminId)
  507. resp := new(roadshow.MattersListResp)
  508. total, err := roadshow.GetMattersListCount(condition, pars)
  509. if err != nil && err.Error() != utils.ErrNoRow() {
  510. this.FailWithMessage("获取事项信息失败", "获取事项信息失败,GetMattersListCount,Err:"+err.Error())
  511. return
  512. }
  513. page = paging.GetPaging(currentIndex, pageSize, total)
  514. dataList, err := roadshow.GetMattersList(condition, pars, startSize, pageSize)
  515. if err != nil {
  516. this.FailWithMessage("获取事项信息失败", "获取事项信息失败,GetMattersList,Err:"+err.Error())
  517. return
  518. }
  519. resp.Paging = page
  520. resp.List = dataList
  521. this.OkDetailed(resp, "获取成功")
  522. }
  523. // @Title 新增事项接口
  524. // @Description 新增事项接口
  525. // @Param request body rs.AddMattersReq true "type json string"
  526. // @Success Ret=200 保存成功
  527. // @router /matters/add [post]
  528. func (this *CalendarController) MattersAdd() {
  529. sysUser := this.AdminWx
  530. if sysUser == nil {
  531. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  532. return
  533. }
  534. deleteCache := true
  535. cacheKey := "CACHE_RS_MATTERS_ADD_" + strconv.Itoa(sysUser.AdminId)
  536. defer func() {
  537. if deleteCache {
  538. utils.Rc.Delete(cacheKey)
  539. }
  540. }()
  541. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  542. deleteCache = false
  543. this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!"+sysUser.RealName+";data:"+string(this.Ctx.Input.RequestBody))
  544. return
  545. }
  546. var req roadshow.AddMattersReq
  547. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  548. if err != nil {
  549. this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
  550. return
  551. }
  552. if req.StartDate == "" {
  553. this.FailWithMessage("请选择开始日期!", "请选择开始日期!")
  554. return
  555. }
  556. if req.EndDate == "" {
  557. this.FailWithMessage("请选择结束日期!", "请选择结束日期!")
  558. return
  559. }
  560. if req.StartTime == "" {
  561. this.FailWithMessage("请选择开始时间!", "请选择开始时间!")
  562. return
  563. }
  564. if req.EndTime == "" {
  565. this.FailWithMessage("请选择结束时间!", "请选择结束时间!")
  566. return
  567. }
  568. if req.StartWeek == "" {
  569. this.FailWithMessage("请选择周!", "请选择周!")
  570. return
  571. }
  572. if req.EndWeek == "" {
  573. this.FailWithMessage("请选择周!", "请选择周!")
  574. return
  575. }
  576. if req.MatterContent == "" {
  577. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  578. return
  579. }
  580. startDateTime := req.StartDate + " " + req.StartTime
  581. endDateTime := req.EndDate + " " + req.EndTime
  582. //校验事项时间冲突
  583. {
  584. matterCount, err := rs.CheckMatters(startDateTime, endDateTime, sysUser.AdminId, 0)
  585. if err != nil {
  586. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
  587. return
  588. }
  589. if matterCount > 0 {
  590. this.FailWithMessage("当前时间已被占用!", "时间冲突检测失败-CheckMattersCount!")
  591. return
  592. }
  593. }
  594. //校验活动时间冲突--待接受
  595. {
  596. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1", sysUser.AdminId, 0)
  597. if err != nil {
  598. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
  599. return
  600. }
  601. if calendarCount > 0 {
  602. this.FailWithMessage("当前时间与待处理的申请有冲突,请与相关销售沟通!", "时间冲突检测失败-CheckCalendarResearcherCount!")
  603. return
  604. }
  605. }
  606. //校验活动时间冲突--已接受
  607. {
  608. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "2", sysUser.AdminId, 0)
  609. if err != nil {
  610. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
  611. return
  612. }
  613. if calendarCount > 0 {
  614. this.FailWithMessage("当前时间已被占用!", "时间冲突检测失败-CheckCalendarResearcherCount!")
  615. return
  616. }
  617. }
  618. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  619. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  620. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  621. this.FailWithMessage("事项开始时间不能小于当前时间!", "事项开始时间不能小于当前时间!")
  622. return
  623. }
  624. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  625. this.FailWithMessage("事项结束时间不能小于当前时间!", "事项结束时间不能小于当前时间!")
  626. return
  627. }
  628. if startP.After(endP) || startP.Equal(endP) {
  629. this.FailWithMessage("事项开始时间应小于结束时间!", "事项开始时间应小于结束时间!")
  630. return
  631. }
  632. item := new(roadshow.RsMatters)
  633. item.SysUserId = sysUser.AdminId
  634. item.SysUserRealName = sysUser.RealName
  635. item.StartDate = req.StartDate
  636. item.EndDate = req.EndDate
  637. item.StartTime = req.StartTime
  638. item.EndTime = req.EndTime
  639. item.StartWeek = req.StartWeek
  640. item.EndWeek = req.EndWeek
  641. item.MatterContent = req.MatterContent
  642. item.Status = 1
  643. item.CreateTime = time.Now()
  644. item.ModifyTime = time.Now()
  645. id, err := roadshow.AddRsMatters(item)
  646. if err != nil {
  647. this.FailWithMessage("保存失败!", "保存失败,AddRsMatters Err:"+err.Error())
  648. return
  649. }
  650. item.RsMattersId = int(id)
  651. go rs.MatterToSH(*item)
  652. this.OkDetailed(nil, "保存成功")
  653. }
  654. // @Title 修改事项接口
  655. // @Description 修改事项接口
  656. // @Param request body rs.UpdateMattersReq true "type json string"
  657. // @Success Ret=200 保存成功
  658. // @router /matters/update [post]
  659. func (this *CalendarController) MattersUpdate() {
  660. sysUser := this.AdminWx
  661. if sysUser == nil {
  662. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  663. return
  664. }
  665. deleteCache := true
  666. cacheKey := "CACHE_RS_MATTERS_UPDATE_" + strconv.Itoa(sysUser.AdminId)
  667. defer func() {
  668. if deleteCache {
  669. utils.Rc.Delete(cacheKey)
  670. }
  671. }()
  672. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  673. deleteCache = false
  674. this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!")
  675. return
  676. }
  677. var req roadshow.UpdateMattersReq
  678. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  679. if err != nil {
  680. this.FailWithMessage("参数解析失败!", "参数解析失败,Err:"+err.Error())
  681. return
  682. }
  683. updateParams := make(map[string]interface{})
  684. if req.RsMattersId <= 0 {
  685. this.FailWithMessage("参数错误!", "参数错误")
  686. return
  687. }
  688. if req.StartDate == "" {
  689. this.FailWithMessage("请选择开始日期!", "请选择开始日期")
  690. return
  691. } else {
  692. updateParams["start_date"] = req.StartDate
  693. }
  694. if req.EndDate == "" {
  695. this.FailWithMessage("请选择结束日期!", "请选择结束日期")
  696. return
  697. } else {
  698. updateParams["end_date"] = req.EndDate
  699. }
  700. if req.StartTime == "" {
  701. this.FailWithMessage("请选择开始时间!", "请选择开始时间")
  702. return
  703. } else {
  704. updateParams["start_time"] = req.StartTime
  705. }
  706. if req.EndTime == "" {
  707. this.FailWithMessage("请选择结束时间!", "请选择结束时间")
  708. return
  709. } else {
  710. updateParams["end_time"] = req.EndTime
  711. }
  712. if req.StartWeek == "" {
  713. this.FailWithMessage("请选择周!", "请选择周")
  714. return
  715. } else {
  716. updateParams["start_week"] = req.StartWeek
  717. }
  718. if req.EndWeek == "" {
  719. this.FailWithMessage("请选择周!", "请选择周")
  720. return
  721. } else {
  722. updateParams["end_week"] = req.EndWeek
  723. }
  724. if req.MatterContent == "" {
  725. this.FailWithMessage("请选择研究员!", "请选择研究员")
  726. return
  727. } else {
  728. updateParams["matter_content"] = req.MatterContent
  729. }
  730. startDateTime := req.StartDate + " " + req.StartTime
  731. endDateTime := req.EndDate + " " + req.EndTime
  732. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  733. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  734. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  735. this.FailWithMessage("事项开始时间不能小于当前时间!", "事项开始时间不能小于当前时间!")
  736. return
  737. }
  738. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  739. this.FailWithMessage("事项结束时间不能小于当前时间!", "事项结束时间不能小于当前时间!")
  740. return
  741. }
  742. if startP.After(endP) || startP.Equal(endP) {
  743. this.FailWithMessage("事项开始时间应小于结束时间!", "事项开始时间应小于结束时间!")
  744. return
  745. }
  746. matterItem, err := roadshow.GetMattersById(req.RsMattersId)
  747. if err != nil {
  748. this.FailWithMessage("保存失败!", "保存失败,GetMattersById,Err:"+err.Error())
  749. return
  750. }
  751. //校验事项时间冲突
  752. {
  753. if matterItem != nil && (matterItem.StartDate != req.StartDate ||
  754. matterItem.StartTime != req.StartTime ||
  755. matterItem.EndDate != req.EndDate ||
  756. matterItem.EndTime != req.EndTime) {
  757. matterCount, err := rs.CheckMatters(startDateTime, endDateTime, sysUser.AdminId, matterItem.RsMattersId)
  758. if err != nil {
  759. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
  760. return
  761. }
  762. if matterCount > 0 {
  763. this.FailWithMessage("时间冲突,已存在时间段内的事项!", "时间冲突检测失败-CheckMattersCount!")
  764. return
  765. }
  766. }
  767. }
  768. //校验活动时间冲突--待接受
  769. {
  770. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1", sysUser.AdminId, 0)
  771. if err != nil {
  772. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
  773. return
  774. }
  775. if calendarCount > 0 {
  776. this.FailWithMessage("当前时间与待处理的申请有冲突,请与相关销售沟通!", "时间冲突检测失败-CheckCalendarResearcherCount!")
  777. return
  778. }
  779. }
  780. //校验活动时间冲突--待接受
  781. {
  782. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "2", sysUser.AdminId, 0)
  783. if err != nil {
  784. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
  785. return
  786. }
  787. if calendarCount > 0 {
  788. this.FailWithMessage("时间冲突,已存在时间段内的活动!", "时间冲突检测失败-CheckCalendarResearcherCount!")
  789. return
  790. }
  791. }
  792. whereParams := make(map[string]interface{})
  793. whereParams["rs_matters_id"] = req.RsMattersId
  794. updateParams["modify_time"] = time.Now()
  795. err = roadshow.UpdateRsMatters(whereParams, updateParams)
  796. if err != nil {
  797. this.FailWithMessage("保存失败!", "保存失败!UpdateRsMatters:"+err.Error())
  798. return
  799. }
  800. go rs.UpdateSHCalendarByMatter(req)
  801. this.OkDetailed(nil, "保存成功")
  802. }
  803. // @Title 删除事项接口
  804. // @Description 删除事项接口
  805. // @Param request body rs.DeleteMattersReq true "type json string"
  806. // @Success Ret=200 保存成功
  807. // @router /matters/delete [post]
  808. func (this *CalendarController) MattersDelete() {
  809. sysUser := this.AdminWx
  810. if sysUser == nil {
  811. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  812. return
  813. }
  814. var req roadshow.DeleteMattersReq
  815. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  816. if err != nil {
  817. this.FailWithMessage("参数解析失败", "参数解析失败,Err:"+err.Error())
  818. return
  819. }
  820. if req.RsMattersId <= 0 {
  821. this.FailWithMessage("参数错误", "参数错误")
  822. return
  823. }
  824. err = roadshow.DeleteRsMatters(req.RsMattersId)
  825. if err != nil {
  826. this.FailWithMessage("保存失败", "保存失败!DeleteRsMatters:"+err.Error())
  827. return
  828. }
  829. go rs.DeleteSHMatter(req.RsMattersId)
  830. this.OkDetailed(nil, "删除成功")
  831. }
  832. func getTitle(activityType, roadshowType, activityCategory, roadshowPlatform, province, city string) string {
  833. var title string
  834. switch activityType {
  835. case "内部会议":
  836. title = "内部会议"
  837. case "公开会议", "路演":
  838. if roadshowType == "线上" {
  839. title = roadshowType + activityType + roadshowPlatform
  840. } else {
  841. title = roadshowType + activityType + province + city
  842. }
  843. case "报告电话会":
  844. title = activityCategory + "电话会"
  845. }
  846. return title
  847. }
  848. // @Title 编辑路演活动接口
  849. // @Description编辑路演活动接口
  850. // @Param request body rs.EditActivityReq true "type json string"
  851. // @Success Ret=200 保存成功
  852. // @router /edit [post]
  853. func (this *CalendarController) Edit() {
  854. sysUser := this.AdminWx
  855. if sysUser == nil {
  856. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  857. return
  858. }
  859. deleteCache := true
  860. cacheKey := "CACHE_RS_ACTIVITY_WX_EDIT_" + strconv.Itoa(sysUser.AdminId)
  861. defer func() {
  862. if deleteCache {
  863. utils.Rc.Delete(cacheKey)
  864. }
  865. }()
  866. if !utils.Rc.SetNX(cacheKey, 1, 5*time.Second) {
  867. deleteCache = false
  868. this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!"+sysUser.RealName+";data:"+string(this.Ctx.Input.RequestBody))
  869. return
  870. }
  871. var req roadshow.EditActivityReq
  872. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  873. if err != nil {
  874. this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
  875. return
  876. }
  877. if req.RsCalendarId <= 0 {
  878. this.FailWithMessage("参数错误", "参数错误,RsCalendarId<=0")
  879. return
  880. }
  881. if req.RsCalendarResearcherId <= 0 {
  882. this.FailWithMessage("参数错误", "参数错误,RsCalendarResearcherId<=0")
  883. return
  884. }
  885. if req.ActivityType == "" {
  886. this.FailWithMessage("请选择活动类型", "请选择活动类型")
  887. return
  888. }
  889. if len(req.ResearcherList) <= 0 {
  890. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  891. return
  892. }
  893. researcherMap := make(map[int]string)
  894. var checkIsAdd []string
  895. for _, v := range req.ResearcherList {
  896. if v.ResearcherId <= 0 {
  897. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  898. return
  899. }
  900. if v.ResearcherName == "" {
  901. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  902. return
  903. }
  904. if v.StartDate == "" {
  905. this.FailWithMessage("请选择开始日期!", "请选择开始日期!")
  906. return
  907. }
  908. if v.EndDate == "" {
  909. this.FailWithMessage("请选择结束日期!", "请选择结束日期!")
  910. return
  911. }
  912. if v.StartTime == "" {
  913. this.FailWithMessage("请选择开始时间!", "请选择开始时间!")
  914. return
  915. }
  916. if v.EndTime == "" {
  917. this.FailWithMessage("请选择结束时间!", "请选择结束时间!")
  918. return
  919. }
  920. if v.StartWeek == "" {
  921. this.FailWithMessage("请选择周!", "请选择周!")
  922. return
  923. }
  924. if v.EndWeek == "" {
  925. this.FailWithMessage("请选择周!", "请选择周!")
  926. return
  927. }
  928. if realName, ok := researcherMap[v.ResearcherId]; ok {
  929. this.FailWithMessage("研究员:"+realName+" 被重复选择", "研究员:"+realName+" 被重复选择")
  930. return
  931. }
  932. researcherMap[v.ResearcherId] = v.ResearcherName
  933. startDateTime := v.StartDate + " " + v.StartTime
  934. endDateTime := v.EndDate + " " + v.EndTime
  935. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  936. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  937. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  938. this.FailWithMessage("活动开始时间不能小于当前时间!", "活动开始时间不能小于当前时间!")
  939. return
  940. }
  941. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  942. this.FailWithMessage("活动结束时间不能小于当前时间!", "活动结束时间不能小于当前时间!")
  943. return
  944. }
  945. if startP.After(endP) || startP.Equal(endP) {
  946. this.FailWithMessage("活动开始时间应小于结束时间!", "活动开始时间应小于结束时间!")
  947. return
  948. }
  949. /*
  950. 时间冲突时,提示:xxx时间已被占用
  951. 当有任意一个研究员时间有冲突时,所有申请订单都不发送。
  952. */
  953. rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherByRsCalendarIdAndResearcherId(req.RsCalendarId, v.ResearcherId)
  954. var isAdd bool
  955. if err != nil {
  956. if err.Error() == utils.ErrNoRow() {
  957. isAdd = true
  958. } else {
  959. this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherByRsCalendarIdAndResearcherId:"+err.Error())
  960. return
  961. }
  962. }
  963. var rsCalendarResearcherId int
  964. if rsCalendarResearcherItem == nil {
  965. isAdd = true
  966. } else {
  967. rsCalendarResearcherId = rsCalendarResearcherItem.RsCalendarResearcherId
  968. }
  969. //同步上海数据
  970. researcherInfo, err := admin.GetAdminById(v.ResearcherId)
  971. if err != nil {
  972. this.FailWithMessage("研究员异常!", "研究员异常")
  973. return
  974. }
  975. _ = rs.SyncCalendarFromShanghai(researcherInfo.Mobile, v.StartDate, v.EndDate)
  976. //校验事项时间冲突
  977. {
  978. if isAdd || (rsCalendarResearcherItem != nil && (rsCalendarResearcherItem.StartDate != v.StartDate ||
  979. rsCalendarResearcherItem.StartTime != v.StartTime ||
  980. rsCalendarResearcherItem.EndDate != v.EndDate ||
  981. rsCalendarResearcherItem.EndTime != v.EndTime)) {
  982. matterCount, err := rs.CheckMatters(startDateTime, endDateTime, v.ResearcherId, 0)
  983. if err != nil {
  984. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
  985. return
  986. }
  987. if matterCount > 0 {
  988. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  989. }
  990. }
  991. }
  992. //校验活动时间冲突
  993. {
  994. if isAdd || (rsCalendarResearcherItem != nil && (rsCalendarResearcherItem.StartDate != v.StartDate ||
  995. rsCalendarResearcherItem.StartTime != v.StartTime ||
  996. rsCalendarResearcherItem.EndDate != v.EndDate ||
  997. rsCalendarResearcherItem.EndTime != v.EndTime)) {
  998. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, rsCalendarResearcherId)
  999. if err != nil {
  1000. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
  1001. return
  1002. }
  1003. if calendarCount > 0 {
  1004. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  1005. }
  1006. }
  1007. }
  1008. }
  1009. if len(checkIsAdd) > 0 {
  1010. this.FailWithMessage(strings.Join(checkIsAdd, ",")+"时间已被占用!", "时间冲突检测失败-CheckMattersCount!")
  1011. return
  1012. }
  1013. rsCalendarItem, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  1014. if err != nil {
  1015. this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarById:"+err.Error())
  1016. return
  1017. }
  1018. if rsCalendarItem == nil {
  1019. this.FailWithMessage("保存失败!", "获取数据失败!GetRsCalendarById:"+err.Error())
  1020. return
  1021. }
  1022. calendarWhereParams := make(map[string]interface{})
  1023. calendarUpdateParams := make(map[string]interface{})
  1024. calendarWhereParams["rs_calendar_id"] = req.RsCalendarId
  1025. if req.ActivityType != "" {
  1026. calendarUpdateParams["activity_type"] = req.ActivityType
  1027. }
  1028. if req.RoadshowType != "" {
  1029. calendarUpdateParams["roadshow_type"] = req.RoadshowType
  1030. }
  1031. if req.RoadshowPlatform != "" {
  1032. calendarUpdateParams["roadshow_platform"] = req.RoadshowPlatform
  1033. }
  1034. if req.CompanyId > 0 {
  1035. calendarUpdateParams["company_id"] = req.CompanyId
  1036. }
  1037. if req.CompanyName != "" {
  1038. calendarUpdateParams["company_name"] = req.CompanyName
  1039. }
  1040. if req.ActivityCategory != "" {
  1041. calendarUpdateParams["activity_category"] = req.ActivityCategory
  1042. }
  1043. if req.Theme != "" {
  1044. calendarUpdateParams["theme"] = req.Theme
  1045. }
  1046. if req.CooperationName != "" {
  1047. calendarUpdateParams["cooperation_name"] = req.CooperationName
  1048. }
  1049. if req.Province != "" {
  1050. calendarUpdateParams["province"] = req.Province
  1051. }
  1052. if req.City != "" {
  1053. calendarUpdateParams["city"] = req.City
  1054. }
  1055. calendarUpdateParams["modify_time"] = time.Now()
  1056. calendarUpdateParams["title"] = getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City)
  1057. err = roadshow.UpdateRsCalendar(calendarWhereParams, calendarUpdateParams)
  1058. if err != nil {
  1059. this.FailWithMessage("保存失败!", "保存失败!UpdateRsCalendar:"+err.Error())
  1060. return
  1061. }
  1062. //newResearcherMap := make(map[int]string)
  1063. go rs.UpdateSHCalendar(req)
  1064. existList, err := roadshow.GetRsCalendarResearcherByCalendarId(req.RsCalendarId)
  1065. if err != nil {
  1066. this.FailWithMessage("保存失败!", "保存失败!GetRsCalendarResearcherByCalendarId:"+err.Error())
  1067. return
  1068. }
  1069. existResearcherMap := make(map[int]string)
  1070. for _, ev := range existList {
  1071. existResearcherMap[ev.ResearcherId] = ev.ResearcherName
  1072. }
  1073. if rsCalendarItem.ActivityType == "路演" || rsCalendarItem.ActivityType == "公开会议" {
  1074. for k, v := range req.ResearcherList {
  1075. rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  1076. if err != nil {
  1077. this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  1078. return
  1079. }
  1080. calendarResearcherWhereParams := make(map[string]interface{})
  1081. calendarResearcherUpdateParams := make(map[string]interface{})
  1082. calendarResearcherWhereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1083. calendarResearcherUpdateParams["researcher_id"] = v.ResearcherId
  1084. calendarResearcherUpdateParams["researcher_name"] = v.ResearcherName
  1085. if rsCalendarResearcherItem.Status == 3 || rsCalendarResearcherItem.Status == 5 {
  1086. calendarResearcherUpdateParams["status"] = 1
  1087. }
  1088. calendarResearcherUpdateParams["start_date"] = v.StartDate
  1089. calendarResearcherUpdateParams["end_date"] = v.EndDate
  1090. calendarResearcherUpdateParams["start_time"] = v.StartTime
  1091. calendarResearcherUpdateParams["end_time"] = v.EndTime
  1092. calendarResearcherUpdateParams["start_week"] = v.StartWeek
  1093. calendarResearcherUpdateParams["end_week"] = v.EndWeek
  1094. calendarResearcherUpdateParams["refuse_reason"] = ""
  1095. calendarResearcherUpdateParams["refuse_time"] = nil
  1096. calendarResearcherUpdateParams["delete_reason"] = ""
  1097. calendarResearcherUpdateParams["approve_time"] = nil
  1098. calendarResearcherUpdateParams["researcher_sort"] = k + 1
  1099. calendarResearcherUpdateParams["modify_time"] = time.Now()
  1100. calendarResearcherUpdateParams["create_time"] = time.Now()
  1101. err = roadshow.UpdateCalendarResearcher(calendarResearcherWhereParams, calendarResearcherUpdateParams)
  1102. if err != nil {
  1103. this.FailWithMessage("保存失败!", "保存失败!UpdateCalendarResearcher:"+err.Error())
  1104. return
  1105. }
  1106. if req.EditType == 2 {
  1107. //模板消息通知
  1108. go func() {
  1109. sysAdmin, _ := admin.GetAdminById(v.ResearcherId)
  1110. if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
  1111. first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  1112. keyword1 := sysUser.RealName
  1113. keyword2 := "--"
  1114. keyword3 := time.Now().Format(utils.FormatDateTime)
  1115. startDateSub := v.StartDate[5:]
  1116. startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  1117. var keyword4 string
  1118. if req.ActivityType == "路演" {
  1119. keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  1120. } else {
  1121. keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  1122. }
  1123. remark := "请尽快完成审批"
  1124. wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(req.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(rsCalendarResearcherItem.RsCalendarResearcherId)
  1125. openIdList, _ := models.GetAdminOpenIdByMobile(sysAdmin.Mobile)
  1126. if len(openIdList) > 0 {
  1127. services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
  1128. }
  1129. }
  1130. }()
  1131. }
  1132. }
  1133. } else {
  1134. err = roadshow.DeleteRsCalendarResearcher(req.RsCalendarId)
  1135. if err != nil {
  1136. this.FailWithMessage("保存失败!", "保存失败!DeleteRsCalendarResearcher:"+err.Error())
  1137. return
  1138. }
  1139. for k, v := range req.ResearcherList {
  1140. researcher := new(roadshow.RsCalendarResearcher)
  1141. researcher.RsCalendarId = req.RsCalendarId
  1142. researcher.ResearcherId = v.ResearcherId
  1143. researcher.ResearcherName = v.ResearcherName
  1144. researcher.StartDate = v.StartDate
  1145. researcher.EndDate = v.EndDate
  1146. researcher.StartTime = v.StartTime
  1147. researcher.EndTime = v.EndTime
  1148. researcher.StartWeek = v.StartWeek
  1149. researcher.EndWeek = v.EndWeek
  1150. researcher.CreateTime = time.Now()
  1151. researcher.ModifyTime = time.Now()
  1152. researcher.ResearcherSort = k + 1
  1153. if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
  1154. researcher.Status = 1
  1155. } else {
  1156. researcher.Status = 2
  1157. }
  1158. rsCalendarResearcherId, err := roadshow.AddRsCalendarResearcher(researcher)
  1159. if err != nil {
  1160. this.FailWithMessage("保存失败!", "保存日历活动-研究员信息失败!Err:"+err.Error())
  1161. return
  1162. }
  1163. go func() {
  1164. sysAdmin, _ := admin.GetAdminById(v.ResearcherId)
  1165. if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
  1166. first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  1167. keyword1 := sysUser.RealName
  1168. keyword2 := "--"
  1169. keyword3 := time.Now().Format(utils.FormatDateTime)
  1170. startDateSub := v.StartDate[5:]
  1171. startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  1172. var keyword4 string
  1173. if req.ActivityType == "路演" {
  1174. keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  1175. } else {
  1176. keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  1177. }
  1178. remark := "请尽快完成审批"
  1179. wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(req.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(int(rsCalendarResearcherId))
  1180. openIdList, _ := models.GetAdminOpenIdByMobile(sysAdmin.Mobile)
  1181. if len(openIdList) > 0 {
  1182. services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
  1183. }
  1184. }
  1185. }()
  1186. }
  1187. }
  1188. this.OkDetailed(nil, "保存成功")
  1189. }
  1190. // ResearcherList
  1191. // @Title 研究员列表
  1192. // @Description 研究员列表接口
  1193. // @Success 200 {object} rs.ResearcherGroup
  1194. // @router /researcher/list [get]
  1195. func (this *CalendarController) ResearcherList() {
  1196. sysUser := this.AdminWx
  1197. if sysUser == nil {
  1198. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1199. return
  1200. }
  1201. group, err := roadshow.GetResearcherGroup()
  1202. if err != nil {
  1203. this.FailWithMessage("获取信息失败!", "获取分组信息失败!Err:"+err.Error())
  1204. return
  1205. }
  1206. researcherList, err := roadshow.GetResearcher()
  1207. groupMap := make(map[int][]*roadshow.Researcher)
  1208. for _, v := range researcherList {
  1209. if v.RoleTypeCode == "ficc_admin" {
  1210. findItems := groupMap[1]
  1211. findItems = append(findItems, v)
  1212. groupMap[1] = findItems
  1213. } else {
  1214. if findItems, ok := groupMap[v.GroupId]; ok {
  1215. findItems = append(findItems, v)
  1216. groupMap[v.GroupId] = findItems
  1217. } else {
  1218. findItems = append(findItems, v)
  1219. groupMap[v.GroupId] = findItems
  1220. }
  1221. }
  1222. }
  1223. for _, v := range group {
  1224. v.ResearcherList = groupMap[v.GroupId]
  1225. }
  1226. this.OkDetailed(group, "获取成功")
  1227. }
  1228. // @Title 撤回路演活动接口
  1229. // @Description 撤回路演活动接口
  1230. // @Param request body rs.AcceptReq true "type json string"
  1231. // @Success Ret=200 保存成功
  1232. // @router /back [post]
  1233. func (this *CalendarController) Back() {
  1234. sysUser := this.AdminWx
  1235. if sysUser == nil {
  1236. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1237. return
  1238. }
  1239. var req roadshow.AcceptReq
  1240. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1241. if err != nil {
  1242. this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
  1243. return
  1244. }
  1245. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  1246. this.FailWithMessage("参数错误", "参数错误!RsCalendarId:"+strconv.Itoa(req.RsCalendarId)+";RsCalendarResearcherId:"+strconv.Itoa(req.RsCalendarResearcherId))
  1247. return
  1248. }
  1249. _, err = roadshow.GetRsCalendarById(req.RsCalendarId)
  1250. if err != nil {
  1251. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarById:"+err.Error())
  1252. return
  1253. }
  1254. rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  1255. if err != nil {
  1256. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  1257. return
  1258. }
  1259. if rsCalendarResearcher.Status == 2 {
  1260. this.FailWithMessage("已接受,不可进行撤回操作!", "已接受,不可进行撤回操作!")
  1261. return
  1262. } else if rsCalendarResearcher.Status == 3 {
  1263. this.FailWithMessage("已拒绝,不可进行撤回操作!", "已拒绝,不可进行撤回操作!")
  1264. return
  1265. } else if rsCalendarResearcher.Status == 4 {
  1266. this.FailWithMessage("已删除,不可进行撤回操作!", "已删除,不可进行撤回操作!")
  1267. return
  1268. } else if rsCalendarResearcher.Status == 5 {
  1269. this.FailWithMessage("已撤回,不可进行重复操作!", "已撤回,不可进行重复操作!")
  1270. return
  1271. }
  1272. whereParams := make(map[string]interface{})
  1273. updateParams := make(map[string]interface{})
  1274. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1275. whereParams["rs_calendar_id"] = req.RsCalendarId
  1276. updateParams["status"] = 5
  1277. updateParams["modify_time"] = time.Now()
  1278. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  1279. //撤回后,需要删除该日程
  1280. go rs.DeleteSHCalendar(req.RsCalendarResearcherId)
  1281. if err != nil {
  1282. this.FailWithMessage("保存失败", "保存失败!UpdateCalendarResearcher:"+err.Error())
  1283. return
  1284. }
  1285. this.OkDetailed(nil, "撤回成功")
  1286. }
  1287. // @Title 删除路演活动接口
  1288. // @Description 删除路演活动接口
  1289. // @Param request body rs.DeleteReq true "type json string"
  1290. // @Success Ret=200 保存成功
  1291. // @router /delete [post]
  1292. func (this *CalendarController) Delete() {
  1293. sysUser := this.AdminWx
  1294. if sysUser == nil {
  1295. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1296. return
  1297. }
  1298. var req roadshow.DeleteReq
  1299. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1300. if err != nil {
  1301. this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  1302. return
  1303. }
  1304. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  1305. this.FailWithMessage("参数错误!", "参数错误!RsCalendarId:"+strconv.Itoa(req.RsCalendarId)+";RsCalendarResearcherId:"+strconv.Itoa(req.RsCalendarResearcherId))
  1306. return
  1307. }
  1308. rsCalendarItem, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  1309. if err != nil {
  1310. this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarById:"+err.Error())
  1311. return
  1312. }
  1313. rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  1314. if err != nil {
  1315. this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  1316. return
  1317. }
  1318. if rsCalendarItem.ActivityType == "报告电话会" || rsCalendarItem.ActivityType == "内部会议" {
  1319. err = roadshow.DeleteCalendar(req.RsCalendarId, req.RsCalendarResearcherId)
  1320. if err != nil {
  1321. this.FailWithMessage("删除失败!", "删除失败!DeleteCalendar:"+err.Error())
  1322. return
  1323. }
  1324. } else {
  1325. whereParams := make(map[string]interface{})
  1326. updateParams := make(map[string]interface{})
  1327. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1328. whereParams["rs_calendar_id"] = req.RsCalendarId
  1329. updateParams["status"] = 4
  1330. updateParams["delete_reason"] = req.DeleteReason
  1331. updateParams["modify_time"] = time.Now()
  1332. updateParams["delete_time"] = time.Now()
  1333. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  1334. if err != nil {
  1335. this.FailWithMessage("删除失败!", "删除失败!UpdateCalendarResearcher:"+err.Error())
  1336. return
  1337. }
  1338. }
  1339. //`status` int(11) DEFAULT '0' COMMENT '1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束',
  1340. //待接受、已接受的情况,需要同步删除上海那边的日程
  1341. if rsCalendarResearcherItem.Status == 1 || rsCalendarResearcherItem.Status == 2 {
  1342. go rs.DeleteSHCalendar(rsCalendarResearcherItem.RsCalendarResearcherId)
  1343. }
  1344. //模板消息通知
  1345. {
  1346. go func() {
  1347. if rsCalendarItem != nil && rsCalendarResearcherItem != nil {
  1348. sysAdmin, _ := admin.GetAdminById(rsCalendarResearcherItem.ResearcherId)
  1349. first := "【" + sysUser.RealName + "】删除了你的【路演】安排"
  1350. var keyword1 string
  1351. if rsCalendarItem.ActivityType == "路演" {
  1352. keyword1 = rsCalendarItem.CompanyName + "," + rsCalendarItem.RoadshowType + rsCalendarItem.ActivityType
  1353. } else {
  1354. keyword1 = rsCalendarItem.Theme + "," + rsCalendarItem.RoadshowType + rsCalendarItem.ActivityType
  1355. }
  1356. keyword2 := "已删除"
  1357. remark := req.DeleteReason
  1358. wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(rsCalendarItem.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(rsCalendarResearcherItem.RsCalendarResearcherId)
  1359. openIdList, _ := models.GetAdminOpenIdByMobile(sysAdmin.Mobile)
  1360. if len(openIdList) > 0 {
  1361. services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, sysAdmin.Mobile)
  1362. }
  1363. }
  1364. }()
  1365. }
  1366. this.OkDetailed(nil, "删除成功")
  1367. }
  1368. // ResearcherList
  1369. // @Title 获取报告电话会类型
  1370. // @Description 获取报告电话会类型接口
  1371. // @Success 200 {object} rs.ResearcherGroup
  1372. // @router /activity/type/list [get]
  1373. func (this *CalendarController) ActivityTypeList() {
  1374. sysUser := this.AdminWx
  1375. if sysUser == nil {
  1376. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1377. return
  1378. }
  1379. // 获取所有的分类
  1380. list, err := rs.GetAllActivityType()
  1381. if err != nil {
  1382. this.FailWithMessage("获取活动类型列表失败", "获取活动类型列表失败,Err:"+err.Error())
  1383. return
  1384. }
  1385. this.OkDetailed(list, "获取成功")
  1386. }