calendar.go 62 KB

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