calendar.go 66 KB

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