calendar.go 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789
  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. roleTypeCode := adminItem.RoleTypeCode
  251. //销售
  252. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  253. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  254. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  255. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  256. condition += ` AND a.sys_user_id=?`
  257. pars = append(pars, adminItem.AdminId)
  258. }
  259. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR ||
  260. roleTypeCode == utils.ROLE_TYPE_CODE_RESEARCHR ||
  261. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR ||
  262. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  263. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
  264. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  265. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  266. condition += ` AND b.researcher_id=?`
  267. pars = append(pars, adminItem.AdminId)
  268. }
  269. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  270. condition += ` AND a.sys_user_id=?`
  271. pars = append(pars, adminItem.AdminId)
  272. }
  273. condition += ` AND a.activity_type IN('路演','公开会议') `
  274. if status == 1 {
  275. condition += ` AND b.status=?`
  276. pars = append(pars, 1)
  277. } else {
  278. condition += ` AND b.status IN(2,3,4,5,6)`
  279. }
  280. resp := new(roadshow.CalendarListResp)
  281. total, err := roadshow.GetCalendarListCount(condition, pars)
  282. if err != nil && err.Error() != utils.ErrNoRow() {
  283. this.FailWithMessage("获取信息失败!", "获取数据总数失败,GetCalendarListCount,Err:"+err.Error())
  284. return
  285. }
  286. page = paging.GetPaging(currentIndex, pageSize, total)
  287. dataList, err := roadshow.GetCalendarList(condition, pars, status, startSize, pageSize)
  288. if err != nil {
  289. this.FailWithMessage("获取信息失败!", "获取数据失败,GetCalendarList,Err:"+err.Error())
  290. return
  291. }
  292. resp.Paging = page
  293. resp.List = dataList
  294. this.OkDetailed(resp, "获取成功")
  295. }
  296. // CalendarList
  297. // @Title 内部会议和报告电话会日历列表
  298. // @Description 内部会议和报告电话会日历列表
  299. // @Param PageSize query int true "每页数据条数"
  300. // @Param CurrentIndex query int true "当前页页码,从1开始"
  301. // @Param CalendarType query int true "1:内部会议,2:报告电话会"
  302. // @Success 200 {object} rs.CalendarListResp
  303. // @router /calendar/type/list [get]
  304. func (this *CalendarController) CalendarTypeList() {
  305. adminItem := this.AdminWx
  306. pageSize, _ := this.GetInt("PageSize")
  307. currentIndex, _ := this.GetInt("CurrentIndex")
  308. calendarType, _ := this.GetInt("CalendarType")
  309. var total int
  310. page := paging.GetPaging(currentIndex, pageSize, total)
  311. var startSize int
  312. if pageSize <= 0 {
  313. pageSize = utils.PageSize10
  314. }
  315. if currentIndex <= 0 {
  316. currentIndex = 1
  317. }
  318. startSize = paging.StartIndex(currentIndex, pageSize)
  319. var condition string
  320. var pars []interface{}
  321. condition += ` AND b.researcher_id=?`
  322. pars = append(pars, adminItem.AdminId)
  323. if calendarType == 1 {
  324. condition += ` AND a.activity_type='内部会议' `
  325. condition += ` AND a.sys_user_id=?`
  326. pars = append(pars, adminItem.AdminId)
  327. }
  328. if calendarType == 2 {
  329. condition += ` AND a.activity_type='报告电话会' `
  330. }
  331. resp := new(roadshow.CalendarListResp)
  332. total, err := roadshow.GetCalendarListCount(condition, pars)
  333. if err != nil && err.Error() != utils.ErrNoRow() {
  334. this.FailWithMessage("获取信息失败!", "获取数据总数失败,GetCalendarListCount,Err:"+err.Error())
  335. return
  336. }
  337. page = paging.GetPaging(currentIndex, pageSize, total)
  338. dataList, err := roadshow.GetCalendarList(condition, pars, 0, startSize, pageSize)
  339. if err != nil {
  340. this.FailWithMessage("获取信息失败!", "获取数据失败,GetCalendarList,Err:"+err.Error())
  341. return
  342. }
  343. resp.Paging = page
  344. resp.List = dataList
  345. this.OkDetailed(resp, "获取成功")
  346. }
  347. // Accept
  348. // @Description 接受路演活动接口
  349. // @Param request body rs.AcceptReq true "type json string"
  350. // @Success Ret=200 保存成功
  351. // @router /accept [post]
  352. func (this *CalendarController) Accept() {
  353. //adminItem:=this.AdminWx
  354. var req roadshow.AcceptReq
  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 或 RsCalendarResearcherId 小于等于0:")
  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"] = 2
  392. updateParams["modify_time"] = time.Now()
  393. updateParams["approve_time"] = time.Now()
  394. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  395. if err != nil {
  396. this.FailWithMessage("获取数据失败!", "UpdateCalendarResearcher Err:"+err.Error())
  397. return
  398. }
  399. //模板消息通知
  400. {
  401. if rsCalendar != nil {
  402. sysAdmin, _ := admin.GetAdminById(rsCalendar.SysUserId)
  403. first := "【" + this.AdminWx.RealName + "】接受了你的【" + rsCalendar.ActivityType + "】申请"
  404. var keyword1 string
  405. if rsCalendar.ActivityType == "路演" {
  406. keyword1 = rsCalendar.CompanyName + "," + rsCalendar.RoadshowType + rsCalendar.ActivityType
  407. } else {
  408. keyword1 = rsCalendar.Theme + "," + rsCalendar.RoadshowType + rsCalendar.ActivityType
  409. }
  410. keyword2 := "已接受"
  411. remark := ""
  412. if sysAdmin.Mobile != "" {
  413. go services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, sysAdmin.Mobile, "", "")
  414. }
  415. }
  416. }
  417. this.OkDetailed(nil, "保存成功")
  418. }
  419. // @Title 拒绝路演活动接口
  420. // @Description 拒绝路演活动接口
  421. // @Param request body rs.RefuseReq true "type json string"
  422. // @Success Ret=200 保存成功
  423. // @router /refuse [post]
  424. func (this *CalendarController) Refuse() {
  425. //adminItem:=this.AdminWx
  426. var req roadshow.RefuseReq
  427. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  428. if err != nil {
  429. this.FailWithMessage("参数解析失败!", "参数解析失败,Err:"+err.Error())
  430. return
  431. }
  432. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  433. this.FailWithMessage("参数错误!", "参数错误!RsCalendarId:"+strconv.Itoa(req.RsCalendarId)+";RsCalendarResearcherId:"+strconv.Itoa(req.RsCalendarResearcherId))
  434. return
  435. }
  436. rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  437. if err != nil {
  438. this.FailWithMessage("获取数据失败!", "GetRsCalendarById,Err:"+err.Error())
  439. return
  440. }
  441. rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  442. if err != nil {
  443. this.FailWithMessage("获取数据失败!", "GetRsCalendarResearcherById,Err:"+err.Error())
  444. return
  445. }
  446. if rsCalendarResearcher.Status == 2 {
  447. this.FailWithMessage("已接受,不可进行拒绝操作!", "")
  448. return
  449. } else if rsCalendarResearcher.Status == 3 {
  450. this.FailWithMessage("已拒绝,不可进行重复操作!", "")
  451. return
  452. } else if rsCalendarResearcher.Status == 4 {
  453. this.FailWithMessage("已删除,不可进行拒绝操作!", "")
  454. return
  455. } else if rsCalendarResearcher.Status == 5 {
  456. this.FailWithMessage("已撤回,不可进行拒绝操作!", "")
  457. return
  458. }
  459. whereParams := make(map[string]interface{})
  460. updateParams := make(map[string]interface{})
  461. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  462. whereParams["rs_calendar_id"] = req.RsCalendarId
  463. updateParams["status"] = 3
  464. updateParams["refuse_reason"] = req.RefuseReason
  465. updateParams["refuse_time"] = time.Now()
  466. updateParams["modify_time"] = time.Now()
  467. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  468. if err != nil {
  469. this.FailWithMessage("保存失败", "保存失败!UpdateCalendarResearcher:"+err.Error())
  470. return
  471. }
  472. // 拒绝后需要删除上海的日程
  473. go rs.DeleteSHCalendar(req.RsCalendarResearcherId)
  474. //模板消息通知
  475. {
  476. if rsCalendar != nil {
  477. sysAdmin, _ := admin.GetAdminById(rsCalendar.SysUserId)
  478. first := "【" + this.AdminWx.RealName + "】拒绝了你的【" + rsCalendar.ActivityType + "】申请"
  479. var keyword1 string
  480. if rsCalendar.ActivityType == "路演" {
  481. keyword1 = rsCalendar.CompanyName + "," + rsCalendar.RoadshowType + rsCalendar.ActivityType
  482. } else {
  483. keyword1 = rsCalendar.Theme + "," + rsCalendar.RoadshowType + rsCalendar.ActivityType
  484. }
  485. keyword2 := "已拒绝"
  486. remark := req.RefuseReason
  487. if sysAdmin.Mobile != "" {
  488. go services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, sysAdmin.Mobile, "", "")
  489. }
  490. }
  491. }
  492. this.OkDetailed(nil, "保存成功")
  493. }
  494. // @Title 日历详情
  495. // @Description 日历详情接口
  496. // @Param RsCalendarId query int true "路演活动id"
  497. // @Param RsCalendarResearcherId query int true "活动研究员id"
  498. // @Success 200 {object} rs.CalendarDetailResp
  499. // @router /calendar/detail [get]
  500. func (this *CalendarController) CalendarDetail() {
  501. //adminItem:=this.AdminWx
  502. //roleTypeCode := adminItem.RoleTypeCode
  503. rsCalendarId, _ := this.GetInt("RsCalendarId")
  504. rsCalendarResearcherId, _ := this.GetInt("RsCalendarResearcherId")
  505. if rsCalendarId <= 0 || rsCalendarResearcherId <= 0 {
  506. this.FailWithMessage("参数错误", "rsCalendarId 或 rsCalendarResearcherId")
  507. return
  508. }
  509. calendarItem, err := roadshow.GetRsCalendarById(rsCalendarId)
  510. if err != nil {
  511. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarById:"+err.Error())
  512. return
  513. }
  514. rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(rsCalendarResearcherId)
  515. if err != nil {
  516. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  517. return
  518. }
  519. companyDetailView := new(roadshow.CompanyDetailView)
  520. if calendarItem != nil && calendarItem.CompanyId > 0 {
  521. companyId := calendarItem.CompanyId
  522. companyProductItem, err := models.GetCompanyProductByCompanyIdAndProductId(companyId, 1)
  523. if err != nil {
  524. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  525. return
  526. }
  527. permissionList, err := models.GetCompanyProductReportPermissionList(companyId, 1)
  528. if err != nil {
  529. this.FailWithMessage("搜索客户权限失败", "搜索客户权限失败!GetRsCalendarResearcherById:"+err.Error())
  530. return
  531. }
  532. var permissionArr []string
  533. for _, v := range permissionList {
  534. permissionArr = append(permissionArr, v.PermissionName)
  535. }
  536. readNum := companyProductItem.ViewTotal
  537. companyDetailView.CompanyId = companyProductItem.CompanyId
  538. companyDetailView.CompanyName = companyProductItem.CompanyName
  539. companyDetailView.Status = companyProductItem.Status
  540. companyDetailView.IndustryId = companyProductItem.IndustryId
  541. companyDetailView.IndustryName = companyProductItem.IndustryName
  542. companyDetailView.PermissionName = strings.Join(permissionArr, "/")
  543. companyDetailView.ReportReadTotal = readNum //ficc报告-累计阅读次数
  544. }
  545. resp := new(roadshow.CalendarDetailResp)
  546. resp.RsCalendarItem = calendarItem
  547. resp.RsCalendarResearcherItem = rsCalendarResearcherItem
  548. resp.CompanyDetail = companyDetailView
  549. this.OkDetailed(resp, "获取成功")
  550. }
  551. // @Title 事项列表
  552. // @Description 事项列表接口
  553. // @Param PageSize query int true "每页数据条数"
  554. // @Param CurrentIndex query int true "当前页页码,从1开始"
  555. // @Success 200 {object} rs.MattersListResp
  556. // @router /matters/list [get]
  557. func (this *CalendarController) MattersList() {
  558. sysUser := this.AdminWx
  559. if sysUser == nil {
  560. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  561. return
  562. }
  563. pageSize, _ := this.GetInt("PageSize")
  564. currentIndex, _ := this.GetInt("CurrentIndex")
  565. var total int
  566. page := paging.GetPaging(currentIndex, pageSize, total)
  567. var startSize int
  568. if pageSize <= 0 {
  569. pageSize = utils.PageSize10
  570. }
  571. if currentIndex <= 0 {
  572. currentIndex = 1
  573. }
  574. startSize = paging.StartIndex(currentIndex, pageSize)
  575. var condition string
  576. var pars []interface{}
  577. condition += ` AND a.sys_user_id=?`
  578. pars = append(pars, sysUser.AdminId)
  579. resp := new(roadshow.MattersListResp)
  580. total, err := roadshow.GetMattersListCount(condition, pars)
  581. if err != nil && err.Error() != utils.ErrNoRow() {
  582. this.FailWithMessage("获取事项信息失败", "获取事项信息失败,GetMattersListCount,Err:"+err.Error())
  583. return
  584. }
  585. page = paging.GetPaging(currentIndex, pageSize, total)
  586. dataList, err := roadshow.GetMattersList(condition, pars, startSize, pageSize)
  587. if err != nil {
  588. this.FailWithMessage("获取事项信息失败", "获取事项信息失败,GetMattersList,Err:"+err.Error())
  589. return
  590. }
  591. resp.Paging = page
  592. resp.List = dataList
  593. this.OkDetailed(resp, "获取成功")
  594. }
  595. // @Title 新增事项接口
  596. // @Description 新增事项接口
  597. // @Param request body rs.AddMattersReq true "type json string"
  598. // @Success Ret=200 保存成功
  599. // @router /matters/add [post]
  600. func (this *CalendarController) MattersAdd() {
  601. sysUser := this.AdminWx
  602. if sysUser == nil {
  603. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  604. return
  605. }
  606. deleteCache := true
  607. cacheKey := "CACHE_RS_MATTERS_ADD_" + strconv.Itoa(sysUser.AdminId)
  608. defer func() {
  609. if deleteCache {
  610. utils.Rc.Delete(cacheKey)
  611. }
  612. }()
  613. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  614. deleteCache = false
  615. this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!"+sysUser.RealName+";data:"+string(this.Ctx.Input.RequestBody))
  616. return
  617. }
  618. var req roadshow.AddMattersReq
  619. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  620. if err != nil {
  621. this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
  622. return
  623. }
  624. if req.StartDate == "" {
  625. this.FailWithMessage("请选择开始日期!", "请选择开始日期!")
  626. return
  627. }
  628. if req.EndDate == "" {
  629. this.FailWithMessage("请选择结束日期!", "请选择结束日期!")
  630. return
  631. }
  632. if req.StartTime == "" {
  633. this.FailWithMessage("请选择开始时间!", "请选择开始时间!")
  634. return
  635. }
  636. if req.EndTime == "" {
  637. this.FailWithMessage("请选择结束时间!", "请选择结束时间!")
  638. return
  639. }
  640. if req.StartWeek == "" {
  641. this.FailWithMessage("请选择周!", "请选择周!")
  642. return
  643. }
  644. if req.EndWeek == "" {
  645. this.FailWithMessage("请选择周!", "请选择周!")
  646. return
  647. }
  648. if req.MatterContent == "" {
  649. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  650. return
  651. }
  652. startDateTime := req.StartDate + " " + req.StartTime
  653. endDateTime := req.EndDate + " " + req.EndTime
  654. //校验事项时间冲突
  655. {
  656. matterCount, err := rs.CheckMatters(startDateTime, endDateTime, sysUser.AdminId, 0)
  657. if err != nil {
  658. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
  659. return
  660. }
  661. if matterCount > 0 {
  662. this.FailWithMessage("当前时间已被占用!", "时间冲突检测失败-CheckMattersCount!")
  663. return
  664. }
  665. }
  666. //校验活动时间冲突--待接受
  667. {
  668. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1", sysUser.AdminId, 0)
  669. if err != nil {
  670. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
  671. return
  672. }
  673. if calendarCount > 0 {
  674. this.FailWithMessage("当前时间与待处理的申请有冲突,请与相关销售沟通!", "时间冲突检测失败-CheckCalendarResearcherCount!")
  675. return
  676. }
  677. }
  678. //校验活动时间冲突--已接受
  679. {
  680. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "2", sysUser.AdminId, 0)
  681. if err != nil {
  682. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
  683. return
  684. }
  685. if calendarCount > 0 {
  686. this.FailWithMessage("当前时间已被占用!", "时间冲突检测失败-CheckCalendarResearcherCount!")
  687. return
  688. }
  689. }
  690. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  691. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  692. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  693. this.FailWithMessage("事项开始时间不能小于当前时间!", "事项开始时间不能小于当前时间!")
  694. return
  695. }
  696. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  697. this.FailWithMessage("事项结束时间不能小于当前时间!", "事项结束时间不能小于当前时间!")
  698. return
  699. }
  700. if startP.After(endP) || startP.Equal(endP) {
  701. this.FailWithMessage("事项开始时间应小于结束时间!", "事项开始时间应小于结束时间!")
  702. return
  703. }
  704. item := new(roadshow.RsMatters)
  705. item.SysUserId = sysUser.AdminId
  706. item.SysUserRealName = sysUser.RealName
  707. item.StartDate = req.StartDate
  708. item.EndDate = req.EndDate
  709. item.StartTime = req.StartTime
  710. item.EndTime = req.EndTime
  711. item.StartWeek = req.StartWeek
  712. item.EndWeek = req.EndWeek
  713. item.MatterContent = req.MatterContent
  714. item.Status = 1
  715. item.CreateTime = time.Now()
  716. item.ModifyTime = time.Now()
  717. id, err := roadshow.AddRsMatters(item)
  718. if err != nil {
  719. this.FailWithMessage("保存失败!", "保存失败,AddRsMatters Err:"+err.Error())
  720. return
  721. }
  722. item.RsMattersId = int(id)
  723. go rs.MatterToSH(*item)
  724. this.OkDetailed(nil, "保存成功")
  725. }
  726. // @Title 修改事项接口
  727. // @Description 修改事项接口
  728. // @Param request body rs.UpdateMattersReq true "type json string"
  729. // @Success Ret=200 保存成功
  730. // @router /matters/update [post]
  731. func (this *CalendarController) MattersUpdate() {
  732. sysUser := this.AdminWx
  733. if sysUser == nil {
  734. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  735. return
  736. }
  737. deleteCache := true
  738. cacheKey := "CACHE_RS_MATTERS_UPDATE_" + strconv.Itoa(sysUser.AdminId)
  739. defer func() {
  740. if deleteCache {
  741. utils.Rc.Delete(cacheKey)
  742. }
  743. }()
  744. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  745. deleteCache = false
  746. this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!")
  747. return
  748. }
  749. var req roadshow.UpdateMattersReq
  750. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  751. if err != nil {
  752. this.FailWithMessage("参数解析失败!", "参数解析失败,Err:"+err.Error())
  753. return
  754. }
  755. updateParams := make(map[string]interface{})
  756. if req.RsMattersId <= 0 {
  757. this.FailWithMessage("参数错误!", "参数错误")
  758. return
  759. }
  760. if req.StartDate == "" {
  761. this.FailWithMessage("请选择开始日期!", "请选择开始日期")
  762. return
  763. } else {
  764. updateParams["start_date"] = req.StartDate
  765. }
  766. if req.EndDate == "" {
  767. this.FailWithMessage("请选择结束日期!", "请选择结束日期")
  768. return
  769. } else {
  770. updateParams["end_date"] = req.EndDate
  771. }
  772. if req.StartTime == "" {
  773. this.FailWithMessage("请选择开始时间!", "请选择开始时间")
  774. return
  775. } else {
  776. updateParams["start_time"] = req.StartTime
  777. }
  778. if req.EndTime == "" {
  779. this.FailWithMessage("请选择结束时间!", "请选择结束时间")
  780. return
  781. } else {
  782. updateParams["end_time"] = req.EndTime
  783. }
  784. if req.StartWeek == "" {
  785. this.FailWithMessage("请选择周!", "请选择周")
  786. return
  787. } else {
  788. updateParams["start_week"] = req.StartWeek
  789. }
  790. if req.EndWeek == "" {
  791. this.FailWithMessage("请选择周!", "请选择周")
  792. return
  793. } else {
  794. updateParams["end_week"] = req.EndWeek
  795. }
  796. if req.MatterContent == "" {
  797. this.FailWithMessage("请选择研究员!", "请选择研究员")
  798. return
  799. } else {
  800. updateParams["matter_content"] = req.MatterContent
  801. }
  802. startDateTime := req.StartDate + " " + req.StartTime
  803. endDateTime := req.EndDate + " " + req.EndTime
  804. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  805. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  806. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  807. this.FailWithMessage("事项开始时间不能小于当前时间!", "事项开始时间不能小于当前时间!")
  808. return
  809. }
  810. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  811. this.FailWithMessage("事项结束时间不能小于当前时间!", "事项结束时间不能小于当前时间!")
  812. return
  813. }
  814. if startP.After(endP) || startP.Equal(endP) {
  815. this.FailWithMessage("事项开始时间应小于结束时间!", "事项开始时间应小于结束时间!")
  816. return
  817. }
  818. matterItem, err := roadshow.GetMattersById(req.RsMattersId)
  819. if err != nil {
  820. this.FailWithMessage("保存失败!", "保存失败,GetMattersById,Err:"+err.Error())
  821. return
  822. }
  823. //校验事项时间冲突
  824. {
  825. if matterItem != nil && (matterItem.StartDate != req.StartDate ||
  826. matterItem.StartTime != req.StartTime ||
  827. matterItem.EndDate != req.EndDate ||
  828. matterItem.EndTime != req.EndTime) {
  829. matterCount, err := rs.CheckMatters(startDateTime, endDateTime, sysUser.AdminId, matterItem.RsMattersId)
  830. if err != nil {
  831. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
  832. return
  833. }
  834. if matterCount > 0 {
  835. this.FailWithMessage("时间冲突,已存在时间段内的事项!", "时间冲突检测失败-CheckMattersCount!")
  836. return
  837. }
  838. }
  839. }
  840. //校验活动时间冲突--待接受
  841. {
  842. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1", sysUser.AdminId, 0)
  843. if err != nil {
  844. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
  845. return
  846. }
  847. if calendarCount > 0 {
  848. this.FailWithMessage("当前时间与待处理的申请有冲突,请与相关销售沟通!", "时间冲突检测失败-CheckCalendarResearcherCount!")
  849. return
  850. }
  851. }
  852. //校验活动时间冲突--待接受
  853. {
  854. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "2", sysUser.AdminId, 0)
  855. if err != nil {
  856. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
  857. return
  858. }
  859. if calendarCount > 0 {
  860. this.FailWithMessage("时间冲突,已存在时间段内的活动!", "时间冲突检测失败-CheckCalendarResearcherCount!")
  861. return
  862. }
  863. }
  864. whereParams := make(map[string]interface{})
  865. whereParams["rs_matters_id"] = req.RsMattersId
  866. updateParams["modify_time"] = time.Now()
  867. err = roadshow.UpdateRsMatters(whereParams, updateParams)
  868. if err != nil {
  869. this.FailWithMessage("保存失败!", "保存失败!UpdateRsMatters:"+err.Error())
  870. return
  871. }
  872. go rs.UpdateSHCalendarByMatter(req)
  873. this.OkDetailed(nil, "保存成功")
  874. }
  875. // @Title 删除事项接口
  876. // @Description 删除事项接口
  877. // @Param request body rs.DeleteMattersReq true "type json string"
  878. // @Success Ret=200 保存成功
  879. // @router /matters/delete [post]
  880. func (this *CalendarController) MattersDelete() {
  881. sysUser := this.AdminWx
  882. if sysUser == nil {
  883. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  884. return
  885. }
  886. var req roadshow.DeleteMattersReq
  887. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  888. if err != nil {
  889. this.FailWithMessage("参数解析失败", "参数解析失败,Err:"+err.Error())
  890. return
  891. }
  892. if req.RsMattersId <= 0 {
  893. this.FailWithMessage("参数错误", "参数错误")
  894. return
  895. }
  896. err = roadshow.DeleteRsMatters(req.RsMattersId)
  897. if err != nil {
  898. this.FailWithMessage("保存失败", "保存失败!DeleteRsMatters:"+err.Error())
  899. return
  900. }
  901. go rs.DeleteSHMatter(req.RsMattersId)
  902. this.OkDetailed(nil, "删除成功")
  903. }
  904. func getTitle(activityType, roadshowType, activityCategory, roadshowPlatform, province, city string) string {
  905. var title string
  906. switch activityType {
  907. case "内部会议":
  908. title = "内部会议"
  909. case "公开会议", "路演":
  910. if roadshowType == "线上" {
  911. title = roadshowType + activityType + roadshowPlatform
  912. } else {
  913. title = roadshowType + activityType + province + city
  914. }
  915. case "报告电话会":
  916. title = activityCategory + "电话会"
  917. }
  918. return title
  919. }
  920. // @Title 编辑路演活动接口
  921. // @Description编辑路演活动接口
  922. // @Param request body rs.EditActivityReq true "type json string"
  923. // @Success Ret=200 保存成功
  924. // @router /edit [post]
  925. func (this *CalendarController) Edit() {
  926. sysUser := this.AdminWx
  927. if sysUser == nil {
  928. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  929. return
  930. }
  931. deleteCache := true
  932. cacheKey := "CACHE_RS_ACTIVITY_WX_EDIT_" + strconv.Itoa(sysUser.AdminId)
  933. defer func() {
  934. if deleteCache {
  935. utils.Rc.Delete(cacheKey)
  936. }
  937. }()
  938. if !utils.Rc.SetNX(cacheKey, 1, 5*time.Second) {
  939. deleteCache = false
  940. this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!"+sysUser.RealName+";data:"+string(this.Ctx.Input.RequestBody))
  941. return
  942. }
  943. var req roadshow.EditActivityReq
  944. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  945. if err != nil {
  946. this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
  947. return
  948. }
  949. if req.RsCalendarId <= 0 {
  950. this.FailWithMessage("参数错误", "参数错误,RsCalendarId<=0")
  951. return
  952. }
  953. if req.RsCalendarResearcherId <= 0 {
  954. this.FailWithMessage("参数错误", "参数错误,RsCalendarResearcherId<=0")
  955. return
  956. }
  957. if req.ActivityType == "" {
  958. this.FailWithMessage("请选择活动类型", "请选择活动类型")
  959. return
  960. }
  961. if len(req.ResearcherList) <= 0 {
  962. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  963. return
  964. }
  965. researcherMap := make(map[int]string)
  966. var checkIsAdd []string
  967. for _, v := range req.ResearcherList {
  968. if v.ResearcherId <= 0 {
  969. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  970. return
  971. }
  972. if v.ResearcherName == "" {
  973. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  974. return
  975. }
  976. if v.StartDate == "" {
  977. this.FailWithMessage("请选择开始日期!", "请选择开始日期!")
  978. return
  979. }
  980. if v.EndDate == "" {
  981. this.FailWithMessage("请选择结束日期!", "请选择结束日期!")
  982. return
  983. }
  984. if v.StartTime == "" {
  985. this.FailWithMessage("请选择开始时间!", "请选择开始时间!")
  986. return
  987. }
  988. if v.EndTime == "" {
  989. this.FailWithMessage("请选择结束时间!", "请选择结束时间!")
  990. return
  991. }
  992. if v.StartWeek == "" {
  993. this.FailWithMessage("请选择周!", "请选择周!")
  994. return
  995. }
  996. if v.EndWeek == "" {
  997. this.FailWithMessage("请选择周!", "请选择周!")
  998. return
  999. }
  1000. if realName, ok := researcherMap[v.ResearcherId]; ok {
  1001. this.FailWithMessage("研究员:"+realName+" 被重复选择", "研究员:"+realName+" 被重复选择")
  1002. return
  1003. }
  1004. researcherMap[v.ResearcherId] = v.ResearcherName
  1005. startDateTime := v.StartDate + " " + v.StartTime
  1006. endDateTime := v.EndDate + " " + v.EndTime
  1007. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  1008. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  1009. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  1010. this.FailWithMessage("活动开始时间不能小于当前时间!", "活动开始时间不能小于当前时间!")
  1011. return
  1012. }
  1013. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  1014. this.FailWithMessage("活动结束时间不能小于当前时间!", "活动结束时间不能小于当前时间!")
  1015. return
  1016. }
  1017. if startP.After(endP) || startP.Equal(endP) {
  1018. this.FailWithMessage("活动开始时间应小于结束时间!", "活动开始时间应小于结束时间!")
  1019. return
  1020. }
  1021. /*
  1022. 时间冲突时,提示:xxx时间已被占用
  1023. 当有任意一个研究员时间有冲突时,所有申请订单都不发送。
  1024. */
  1025. rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherByRsCalendarIdAndResearcherId(req.RsCalendarId, v.ResearcherId)
  1026. var isAdd bool
  1027. if err != nil {
  1028. if err.Error() == utils.ErrNoRow() {
  1029. isAdd = true
  1030. } else {
  1031. this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherByRsCalendarIdAndResearcherId:"+err.Error())
  1032. return
  1033. }
  1034. }
  1035. var rsCalendarResearcherId int
  1036. if rsCalendarResearcherItem == nil {
  1037. isAdd = true
  1038. } else {
  1039. rsCalendarResearcherId = rsCalendarResearcherItem.RsCalendarResearcherId
  1040. }
  1041. //同步上海数据
  1042. researcherInfo, err := admin.GetAdminById(v.ResearcherId)
  1043. if err != nil {
  1044. this.FailWithMessage("研究员异常!", "研究员异常")
  1045. return
  1046. }
  1047. _ = rs.SyncCalendarFromShanghai(researcherInfo.Mobile, v.StartDate, v.EndDate)
  1048. //校验事项时间冲突
  1049. {
  1050. if isAdd || (rsCalendarResearcherItem != nil && (rsCalendarResearcherItem.StartDate != v.StartDate ||
  1051. rsCalendarResearcherItem.StartTime != v.StartTime ||
  1052. rsCalendarResearcherItem.EndDate != v.EndDate ||
  1053. rsCalendarResearcherItem.EndTime != v.EndTime)) {
  1054. matterCount, err := rs.CheckMatters(startDateTime, endDateTime, v.ResearcherId, 0)
  1055. if err != nil {
  1056. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
  1057. return
  1058. }
  1059. if matterCount > 0 {
  1060. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  1061. }
  1062. }
  1063. }
  1064. //校验活动时间冲突
  1065. {
  1066. if isAdd || (rsCalendarResearcherItem != nil && (rsCalendarResearcherItem.StartDate != v.StartDate ||
  1067. rsCalendarResearcherItem.StartTime != v.StartTime ||
  1068. rsCalendarResearcherItem.EndDate != v.EndDate ||
  1069. rsCalendarResearcherItem.EndTime != v.EndTime)) {
  1070. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, rsCalendarResearcherId)
  1071. if err != nil {
  1072. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
  1073. return
  1074. }
  1075. if calendarCount > 0 {
  1076. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  1077. }
  1078. }
  1079. }
  1080. }
  1081. if len(checkIsAdd) > 0 {
  1082. this.FailWithMessage(strings.Join(checkIsAdd, ",")+"时间已被占用!", "时间冲突检测失败-CheckMattersCount!")
  1083. return
  1084. }
  1085. rsCalendarItem, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  1086. if err != nil {
  1087. this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarById:"+err.Error())
  1088. return
  1089. }
  1090. if rsCalendarItem == nil {
  1091. this.FailWithMessage("保存失败!", "获取数据失败!GetRsCalendarById:"+err.Error())
  1092. return
  1093. }
  1094. calendarWhereParams := make(map[string]interface{})
  1095. calendarUpdateParams := make(map[string]interface{})
  1096. calendarWhereParams["rs_calendar_id"] = req.RsCalendarId
  1097. if req.ActivityType != "" {
  1098. calendarUpdateParams["activity_type"] = req.ActivityType
  1099. }
  1100. if req.RoadshowType != "" {
  1101. calendarUpdateParams["roadshow_type"] = req.RoadshowType
  1102. }
  1103. if req.RoadshowPlatform != "" {
  1104. calendarUpdateParams["roadshow_platform"] = req.RoadshowPlatform
  1105. }
  1106. if req.CompanyId > 0 {
  1107. calendarUpdateParams["company_id"] = req.CompanyId
  1108. }
  1109. if req.CompanyName != "" {
  1110. calendarUpdateParams["company_name"] = req.CompanyName
  1111. }
  1112. if req.ActivityCategory != "" {
  1113. calendarUpdateParams["activity_category"] = req.ActivityCategory
  1114. }
  1115. if req.Theme != "" {
  1116. calendarUpdateParams["theme"] = req.Theme
  1117. }
  1118. if req.CooperationName != "" {
  1119. calendarUpdateParams["cooperation_name"] = req.CooperationName
  1120. }
  1121. if req.Province != "" {
  1122. calendarUpdateParams["province"] = req.Province
  1123. }
  1124. if req.City != "" {
  1125. calendarUpdateParams["city"] = req.City
  1126. }
  1127. calendarUpdateParams["modify_time"] = time.Now()
  1128. calendarUpdateParams["title"] = getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City)
  1129. err = roadshow.UpdateRsCalendar(calendarWhereParams, calendarUpdateParams)
  1130. if err != nil {
  1131. this.FailWithMessage("保存失败!", "保存失败!UpdateRsCalendar:"+err.Error())
  1132. return
  1133. }
  1134. //newResearcherMap := make(map[int]string)
  1135. go rs.UpdateSHCalendar(req)
  1136. existList, err := roadshow.GetRsCalendarResearcherByCalendarId(req.RsCalendarId)
  1137. if err != nil {
  1138. this.FailWithMessage("保存失败!", "保存失败!GetRsCalendarResearcherByCalendarId:"+err.Error())
  1139. return
  1140. }
  1141. existResearcherMap := make(map[int]string)
  1142. for _, ev := range existList {
  1143. existResearcherMap[ev.ResearcherId] = ev.ResearcherName
  1144. }
  1145. if rsCalendarItem.ActivityType == "路演" || rsCalendarItem.ActivityType == "公开会议" {
  1146. for k, v := range req.ResearcherList {
  1147. rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  1148. if err != nil {
  1149. this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  1150. return
  1151. }
  1152. calendarResearcherWhereParams := make(map[string]interface{})
  1153. calendarResearcherUpdateParams := make(map[string]interface{})
  1154. calendarResearcherWhereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1155. calendarResearcherUpdateParams["researcher_id"] = v.ResearcherId
  1156. calendarResearcherUpdateParams["researcher_name"] = v.ResearcherName
  1157. if rsCalendarResearcherItem.Status == 3 || rsCalendarResearcherItem.Status == 5 {
  1158. calendarResearcherUpdateParams["status"] = 1
  1159. }
  1160. calendarResearcherUpdateParams["start_date"] = v.StartDate
  1161. calendarResearcherUpdateParams["end_date"] = v.EndDate
  1162. calendarResearcherUpdateParams["start_time"] = v.StartTime
  1163. calendarResearcherUpdateParams["end_time"] = v.EndTime
  1164. calendarResearcherUpdateParams["start_week"] = v.StartWeek
  1165. calendarResearcherUpdateParams["end_week"] = v.EndWeek
  1166. calendarResearcherUpdateParams["refuse_reason"] = ""
  1167. calendarResearcherUpdateParams["refuse_time"] = nil
  1168. calendarResearcherUpdateParams["delete_reason"] = ""
  1169. calendarResearcherUpdateParams["approve_time"] = nil
  1170. calendarResearcherUpdateParams["researcher_sort"] = k + 1
  1171. calendarResearcherUpdateParams["modify_time"] = time.Now()
  1172. calendarResearcherUpdateParams["create_time"] = time.Now()
  1173. err = roadshow.UpdateCalendarResearcher(calendarResearcherWhereParams, calendarResearcherUpdateParams)
  1174. if err != nil {
  1175. this.FailWithMessage("保存失败!", "保存失败!UpdateCalendarResearcher:"+err.Error())
  1176. return
  1177. }
  1178. if req.EditType == 2 {
  1179. //模板消息通知
  1180. go func() {
  1181. sysAdmin, _ := admin.GetAdminById(v.ResearcherId)
  1182. if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
  1183. first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  1184. keyword1 := sysUser.RealName
  1185. keyword2 := "--"
  1186. keyword3 := time.Now().Format(utils.FormatDateTime)
  1187. startDateSub := v.StartDate[5:]
  1188. startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  1189. var keyword4 string
  1190. if req.ActivityType == "路演" {
  1191. keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  1192. } else {
  1193. keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  1194. }
  1195. remark := "请尽快完成审批"
  1196. wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(req.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(rsCalendarResearcherItem.RsCalendarResearcherId)
  1197. openIdList, _ := models.GetAdminOpenIdByMobile(sysAdmin.Mobile)
  1198. if len(openIdList) > 0 {
  1199. services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
  1200. }
  1201. }
  1202. }()
  1203. }
  1204. }
  1205. } else {
  1206. err = roadshow.DeleteRsCalendarResearcher(req.RsCalendarId)
  1207. if err != nil {
  1208. this.FailWithMessage("保存失败!", "保存失败!DeleteRsCalendarResearcher:"+err.Error())
  1209. return
  1210. }
  1211. for k, v := range req.ResearcherList {
  1212. researcher := new(roadshow.RsCalendarResearcher)
  1213. researcher.RsCalendarId = req.RsCalendarId
  1214. researcher.ResearcherId = v.ResearcherId
  1215. researcher.ResearcherName = v.ResearcherName
  1216. researcher.StartDate = v.StartDate
  1217. researcher.EndDate = v.EndDate
  1218. researcher.StartTime = v.StartTime
  1219. researcher.EndTime = v.EndTime
  1220. researcher.StartWeek = v.StartWeek
  1221. researcher.EndWeek = v.EndWeek
  1222. researcher.CreateTime = time.Now()
  1223. researcher.ModifyTime = time.Now()
  1224. researcher.ResearcherSort = k + 1
  1225. if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
  1226. researcher.Status = 1
  1227. } else {
  1228. researcher.Status = 2
  1229. }
  1230. rsCalendarResearcherId, err := roadshow.AddRsCalendarResearcher(researcher)
  1231. if err != nil {
  1232. this.FailWithMessage("保存失败!", "保存日历活动-研究员信息失败!Err:"+err.Error())
  1233. return
  1234. }
  1235. go func() {
  1236. sysAdmin, _ := admin.GetAdminById(v.ResearcherId)
  1237. if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
  1238. first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  1239. keyword1 := sysUser.RealName
  1240. keyword2 := "--"
  1241. keyword3 := time.Now().Format(utils.FormatDateTime)
  1242. startDateSub := v.StartDate[5:]
  1243. startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  1244. var keyword4 string
  1245. if req.ActivityType == "路演" {
  1246. keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  1247. } else {
  1248. keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  1249. }
  1250. remark := "请尽快完成审批"
  1251. wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(req.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(int(rsCalendarResearcherId))
  1252. openIdList, _ := models.GetAdminOpenIdByMobile(sysAdmin.Mobile)
  1253. if len(openIdList) > 0 {
  1254. services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
  1255. }
  1256. }
  1257. }()
  1258. }
  1259. }
  1260. this.OkDetailed(nil, "保存成功")
  1261. }
  1262. // ResearcherList
  1263. // @Title 研究员列表
  1264. // @Description 研究员列表接口
  1265. // @Success 200 {object} rs.ResearcherGroup
  1266. // @router /researcher/list [get]
  1267. func (this *CalendarController) ResearcherList() {
  1268. sysUser := this.AdminWx
  1269. if sysUser == nil {
  1270. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1271. return
  1272. }
  1273. group, err := roadshow.GetResearcherGroup()
  1274. if err != nil {
  1275. this.FailWithMessage("获取信息失败!", "获取分组信息失败!Err:"+err.Error())
  1276. return
  1277. }
  1278. researcherList, err := roadshow.GetResearcher()
  1279. groupMap := make(map[int][]*roadshow.Researcher)
  1280. for _, v := range researcherList {
  1281. if v.RoleTypeCode == "ficc_admin" {
  1282. findItems := groupMap[1]
  1283. findItems = append(findItems, v)
  1284. groupMap[1] = findItems
  1285. } else {
  1286. if findItems, ok := groupMap[v.GroupId]; ok {
  1287. findItems = append(findItems, v)
  1288. groupMap[v.GroupId] = findItems
  1289. } else {
  1290. findItems = append(findItems, v)
  1291. groupMap[v.GroupId] = findItems
  1292. }
  1293. }
  1294. }
  1295. for _, v := range group {
  1296. v.ResearcherList = groupMap[v.GroupId]
  1297. }
  1298. this.OkDetailed(group, "获取成功")
  1299. }
  1300. // @Title 撤回路演活动接口
  1301. // @Description 撤回路演活动接口
  1302. // @Param request body rs.AcceptReq true "type json string"
  1303. // @Success Ret=200 保存成功
  1304. // @router /back [post]
  1305. func (this *CalendarController) Back() {
  1306. sysUser := this.AdminWx
  1307. if sysUser == nil {
  1308. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1309. return
  1310. }
  1311. var req roadshow.AcceptReq
  1312. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1313. if err != nil {
  1314. this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
  1315. return
  1316. }
  1317. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  1318. this.FailWithMessage("参数错误", "参数错误!RsCalendarId:"+strconv.Itoa(req.RsCalendarId)+";RsCalendarResearcherId:"+strconv.Itoa(req.RsCalendarResearcherId))
  1319. return
  1320. }
  1321. _, err = roadshow.GetRsCalendarById(req.RsCalendarId)
  1322. if err != nil {
  1323. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarById:"+err.Error())
  1324. return
  1325. }
  1326. rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  1327. if err != nil {
  1328. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  1329. return
  1330. }
  1331. if rsCalendarResearcher.Status == 2 {
  1332. this.FailWithMessage("已接受,不可进行撤回操作!", "已接受,不可进行撤回操作!")
  1333. return
  1334. } else if rsCalendarResearcher.Status == 3 {
  1335. this.FailWithMessage("已拒绝,不可进行撤回操作!", "已拒绝,不可进行撤回操作!")
  1336. return
  1337. } else if rsCalendarResearcher.Status == 4 {
  1338. this.FailWithMessage("已删除,不可进行撤回操作!", "已删除,不可进行撤回操作!")
  1339. return
  1340. } else if rsCalendarResearcher.Status == 5 {
  1341. this.FailWithMessage("已撤回,不可进行重复操作!", "已撤回,不可进行重复操作!")
  1342. return
  1343. }
  1344. whereParams := make(map[string]interface{})
  1345. updateParams := make(map[string]interface{})
  1346. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1347. whereParams["rs_calendar_id"] = req.RsCalendarId
  1348. updateParams["status"] = 5
  1349. updateParams["modify_time"] = time.Now()
  1350. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  1351. //撤回后,需要删除该日程
  1352. go rs.DeleteSHCalendar(req.RsCalendarResearcherId)
  1353. if err != nil {
  1354. this.FailWithMessage("保存失败", "保存失败!UpdateCalendarResearcher:"+err.Error())
  1355. return
  1356. }
  1357. this.OkDetailed(nil, "撤回成功")
  1358. }
  1359. // @Title 删除路演活动接口
  1360. // @Description 删除路演活动接口
  1361. // @Param request body rs.DeleteReq true "type json string"
  1362. // @Success Ret=200 保存成功
  1363. // @router /delete [post]
  1364. func (this *CalendarController) Delete() {
  1365. sysUser := this.AdminWx
  1366. if sysUser == nil {
  1367. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1368. return
  1369. }
  1370. var req roadshow.DeleteReq
  1371. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1372. if err != nil {
  1373. this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  1374. return
  1375. }
  1376. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  1377. this.FailWithMessage("参数错误!", "参数错误!RsCalendarId:"+strconv.Itoa(req.RsCalendarId)+";RsCalendarResearcherId:"+strconv.Itoa(req.RsCalendarResearcherId))
  1378. return
  1379. }
  1380. rsCalendarItem, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  1381. if err != nil {
  1382. this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarById:"+err.Error())
  1383. return
  1384. }
  1385. rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  1386. if err != nil {
  1387. this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  1388. return
  1389. }
  1390. if rsCalendarItem.ActivityType == "报告电话会" || rsCalendarItem.ActivityType == "内部会议" {
  1391. err = roadshow.DeleteCalendar(req.RsCalendarId, req.RsCalendarResearcherId)
  1392. if err != nil {
  1393. this.FailWithMessage("删除失败!", "删除失败!DeleteCalendar:"+err.Error())
  1394. return
  1395. }
  1396. } else {
  1397. whereParams := make(map[string]interface{})
  1398. updateParams := make(map[string]interface{})
  1399. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1400. whereParams["rs_calendar_id"] = req.RsCalendarId
  1401. updateParams["status"] = 4
  1402. updateParams["delete_reason"] = req.DeleteReason
  1403. updateParams["modify_time"] = time.Now()
  1404. updateParams["delete_time"] = time.Now()
  1405. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  1406. if err != nil {
  1407. this.FailWithMessage("删除失败!", "删除失败!UpdateCalendarResearcher:"+err.Error())
  1408. return
  1409. }
  1410. }
  1411. //`status` int(11) DEFAULT '0' COMMENT '1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束',
  1412. //待接受、已接受的情况,需要同步删除上海那边的日程
  1413. if rsCalendarResearcherItem.Status == 1 || rsCalendarResearcherItem.Status == 2 {
  1414. go rs.DeleteSHCalendar(rsCalendarResearcherItem.RsCalendarResearcherId)
  1415. }
  1416. //模板消息通知
  1417. {
  1418. go func() {
  1419. if rsCalendarItem != nil && rsCalendarResearcherItem != nil {
  1420. sysAdmin, _ := admin.GetAdminById(rsCalendarResearcherItem.ResearcherId)
  1421. first := "【" + sysUser.RealName + "】删除了你的【路演】安排"
  1422. var keyword1 string
  1423. if rsCalendarItem.ActivityType == "路演" {
  1424. keyword1 = rsCalendarItem.CompanyName + "," + rsCalendarItem.RoadshowType + rsCalendarItem.ActivityType
  1425. } else {
  1426. keyword1 = rsCalendarItem.Theme + "," + rsCalendarItem.RoadshowType + rsCalendarItem.ActivityType
  1427. }
  1428. keyword2 := "已删除"
  1429. remark := req.DeleteReason
  1430. wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(rsCalendarItem.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(rsCalendarResearcherItem.RsCalendarResearcherId)
  1431. openIdList, _ := models.GetAdminOpenIdByMobile(sysAdmin.Mobile)
  1432. if len(openIdList) > 0 {
  1433. services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, sysAdmin.Mobile)
  1434. }
  1435. }
  1436. }()
  1437. }
  1438. this.OkDetailed(nil, "删除成功")
  1439. }
  1440. // ResearcherList
  1441. // @Title 获取报告电话会类型
  1442. // @Description 获取报告电话会类型接口
  1443. // @Success 200 {object} rs.ResearcherGroup
  1444. // @router /activity/type/list [get]
  1445. func (this *CalendarController) ActivityTypeList() {
  1446. sysUser := this.AdminWx
  1447. if sysUser == nil {
  1448. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1449. return
  1450. }
  1451. // 获取所有的分类
  1452. list, err := rs.GetAllActivityType()
  1453. if err != nil {
  1454. this.FailWithMessage("获取活动类型列表失败", "获取活动类型列表失败,Err:"+err.Error())
  1455. return
  1456. }
  1457. this.OkDetailed(list, "获取成功")
  1458. }
  1459. // @Title 路演-研究员日历详情
  1460. // @Description 路演-研究员日历详情接口
  1461. // @Param StartDate query string true "开始日期"
  1462. // @Param EndDate query string true "结束日期日期"
  1463. // @Param ResearcherId query int true "研究员id"
  1464. // @Success 200 {object} roadshow.CalendarDetailResp
  1465. // @router /researcher/calendar/detail [get]
  1466. func (this *CalendarController) ResearcherCalendarDetail() {
  1467. sysUser := this.AdminWx
  1468. if sysUser == nil {
  1469. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1470. return
  1471. }
  1472. startDate := this.GetString("StartDate")
  1473. endDate := this.GetString("EndDate")
  1474. researcherId, _ := this.GetInt("ResearcherId")
  1475. if startDate == "" || endDate == "" {
  1476. this.FailWithMessage("参数错误!", "参数错误 StartDate"+startDate+" EndDate:"+endDate)
  1477. return
  1478. }
  1479. var condition string
  1480. var pars []interface{}
  1481. if researcherId <= 0 {
  1482. calendarList := make([]*roadshow.CalendarListView, 0)
  1483. matterList := make([]*roadshow.RsMatters, 0)
  1484. resp := new(roadshow.CalendarPanelDetailResp)
  1485. resp.CalendarList = calendarList
  1486. resp.RsMattersList = matterList
  1487. this.OkDetailed(resp, "删除成功")
  1488. return
  1489. } else {
  1490. condition += ` AND b.researcher_id =? `
  1491. pars = append(pars, researcherId)
  1492. }
  1493. //同步上海数据
  1494. researcherInfo, err := admin.GetAdminById(researcherId)
  1495. if err != nil {
  1496. this.FailWithMessage("研究员异常!", "研究员异常"+err.Error())
  1497. return
  1498. }
  1499. _ = rs.SyncCalendarFromShanghai(researcherInfo.Mobile, startDate, endDate)
  1500. condition += ` AND b.start_date>=?`
  1501. pars = append(pars, startDate)
  1502. condition += ` AND b.end_date<=?`
  1503. pars = append(pars, endDate)
  1504. condition += ` AND b.status IN(2,6) `
  1505. //pars = append(pars, 2)
  1506. calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
  1507. if err != nil {
  1508. this.FailWithMessage("获取数据失败!", "获取数据失败,GetCalendarDetailList Err:" + err.Error())
  1509. return
  1510. }
  1511. matterList, err := roadshow.GetRsMattersList(startDate, endDate, researcherId)
  1512. if err != nil {
  1513. this.FailWithMessage("获取数据失败!","获取数据失败,GetRsMattersList Err:" + err.Error())
  1514. return
  1515. }
  1516. if calendarList == nil {
  1517. calendarList = make([]*roadshow.CalendarListView, 0)
  1518. }
  1519. if matterList == nil {
  1520. matterList = make([]*roadshow.RsMatters, 0)
  1521. }
  1522. resp := new(roadshow.CalendarPanelDetailResp)
  1523. resp.CalendarList = calendarList
  1524. resp.RsMattersList = matterList
  1525. this.OkDetailed(resp, "删除成功")
  1526. }
  1527. // @Title 路演-我的日历详情
  1528. // @Description 路演-我的日历详情接口
  1529. // @Param StartDate query string true "开始日期"
  1530. // @Param EndDate query string true "结束日期日期"
  1531. // @Success 200 {object} roadshow.CalendarDetailResp
  1532. // @router /my/calendar/detail [get]
  1533. func (this *CalendarController) MyCalendarDetail() {
  1534. sysUser := this.AdminWx
  1535. if sysUser == nil {
  1536. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1537. return
  1538. }
  1539. startDate := this.GetString("StartDate")
  1540. endDate := this.GetString("EndDate")
  1541. if startDate == "" || endDate == "" {
  1542. this.FailWithMessage("参数错误!","参数错误 StartDate:"+startDate+" EndDate:"+endDate)
  1543. return
  1544. }
  1545. var condition string
  1546. var pars []interface{}
  1547. roleTypeCode := sysUser.RoleTypeCode
  1548. //销售
  1549. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  1550. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  1551. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  1552. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  1553. condition += ` AND a.sys_user_id=?`
  1554. pars = append(pars, sysUser.AdminId)
  1555. condition += ` AND a.activity_type IN('路演','公开会议') `
  1556. }
  1557. //研究员
  1558. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR ||
  1559. roleTypeCode == utils.ROLE_TYPE_CODE_RESEARCHR ||
  1560. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR ||
  1561. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  1562. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  1563. condition += ` AND b.researcher_id=?`
  1564. pars = append(pars, sysUser.AdminId)
  1565. }
  1566. //中级/普通/admin 管理员
  1567. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  1568. condition += ` AND a.sys_user_id=?`
  1569. pars = append(pars, sysUser.AdminId)
  1570. }
  1571. condition += ` AND b.start_date>=?`
  1572. pars = append(pars, startDate)
  1573. condition += ` AND b.end_date<=?`
  1574. pars = append(pars, endDate)
  1575. condition += ` AND b.status IN(2,6) `
  1576. //pars = append(pars, 2)
  1577. calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
  1578. if err != nil {
  1579. this.FailWithMessage("获取数据失败!","获取数据失败,GetCalendarDetailList Err:" + err.Error())
  1580. return
  1581. }
  1582. matterList, err := roadshow.GetRsMattersList(startDate, endDate, sysUser.AdminId)
  1583. if err != nil {
  1584. this.FailWithMessage("获取数据失败!","获取数据失败,GetRsMattersList Err:" + err.Error())
  1585. return
  1586. }
  1587. resp := new(roadshow.CalendarPanelDetailResp)
  1588. resp.CalendarList = calendarList
  1589. resp.RsMattersList = matterList
  1590. this.OkDetailed(resp, "删除成功")
  1591. }