calendar.go 66 KB

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