calendar.go 60 KB

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