calendar.go 64 KB

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