calendar.go 64 KB

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