calendar.go 61 KB

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