calendar.go 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065
  1. package rs
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/http"
  7. "hongze/hongze_mobile_admin/models/roadshow"
  8. "hongze/hongze_mobile_admin/models/tables/admin"
  9. "hongze/hongze_mobile_admin/services/alarm_msg"
  10. "hongze/hongze_mobile_admin/utils"
  11. "io/ioutil"
  12. netHttp "net/http"
  13. "net/url"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. type SyncCalendarFromShanghaiRecord struct {
  19. UserPhone string `description:"手机号"`
  20. StartDate string `description:"开始时间"`
  21. EndDate string `description:"结束时间"`
  22. }
  23. // 上海路演数据同步到自系统请求放到Redis
  24. func InsertSyncCalendarFromShanghaiLPush(userPhone, startDate, endDate string) bool {
  25. log := &SyncCalendarFromShanghaiRecord{UserPhone: userPhone, StartDate: startDate, EndDate: endDate}
  26. if utils.Re == nil {
  27. err := utils.Rc.LPush(utils.CACHE_KEY_SHANG_HAI_RS_CALENDAR_API, log)
  28. if err != nil {
  29. fmt.Println(err)
  30. go alarm_msg.SendAlarmMsg("上海路演数据同步到自系统 失败;InsertSyncCalendarFromShanghaiLPush ERR:"+err.Error(), 3)
  31. }
  32. return true
  33. }
  34. return false
  35. }
  36. // getAccessToken token内部请求接口
  37. func getAccessToken() (tokenData roadshow.TokenData, err error) {
  38. defer func() {
  39. if err != nil {
  40. //go utils.SendEmail(utils.APPNAME+"更新上海的token失败:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
  41. go alarm_msg.SendAlarmMsg("更新上海的token失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
  42. }
  43. }()
  44. getUrl := fmt.Sprintf(utils.CRM_OPEN_API_URL+"/v1/auth/getAccessToken?app_key=%s&app_secret=%s", utils.CRM_OPEN_API_APP_KEY, utils.CRM_OPEN_API_APP_SECRET)
  45. body, err := http.Get(getUrl)
  46. if err != nil {
  47. err = errors.New("NewRequest Err:" + err.Error())
  48. return
  49. }
  50. var tokenResp roadshow.GetTokenResp
  51. err = json.Unmarshal(body, &tokenResp)
  52. if err != nil {
  53. err = errors.New("Unmarshal Err:" + err.Error())
  54. return
  55. }
  56. if tokenResp.Code != 1 {
  57. err = errors.New("getAccessToken err:" + tokenResp.Msg)
  58. return
  59. }
  60. tokenData = tokenResp.TokenData
  61. return
  62. }
  63. // refreshAccessToken 强制刷新获取accessToken
  64. func refreshAccessToken() (token string, err error) {
  65. defer func() {
  66. if err != nil {
  67. //go utils.SendEmail(utils.APPNAME+"获取上海的token失败:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
  68. go alarm_msg.SendAlarmMsg("获取上海的token失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
  69. }
  70. }()
  71. tokenInfo, tmpErr := getAccessToken()
  72. if tmpErr != nil {
  73. err = tmpErr
  74. return
  75. }
  76. token = tokenInfo.AccessToken
  77. //token存入redis
  78. err = utils.Rc.Put("SH_ACCESS_TOKEN", token, time.Duration(tokenInfo.ExpireIn-600)*time.Second)
  79. if err != nil {
  80. //go utils.SendEmail(utils.APPNAME+"获取上海的token失败:"+time.Now().Format("2006-01-02 15:04:05"), "上海token存入redis失败:", utils.EmailSendToUsers)
  81. go alarm_msg.SendAlarmMsg("获取上海的token失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:上海token存入redis失败", 3)
  82. }
  83. return
  84. }
  85. // getCalendarFrom 获取上海方的路演活动列表
  86. func getCalendarFrom(userPhone, startDate, endDate string) (list []roadshow.UserCalendar, err error) {
  87. exUrl := utils.CRM_OPEN_API_URL + "/v1/calendar/userCalendarList"
  88. form := url.Values{
  89. "user_phone": {userPhone},
  90. "start_time": {startDate},
  91. "end_time": {endDate},
  92. }
  93. body, err := getCurl(exUrl, form, 0)
  94. if err != nil {
  95. err = errors.New("NewRequest Err:" + err.Error())
  96. return
  97. }
  98. var userCalendarList roadshow.UserCalendarList
  99. err = json.Unmarshal(body, &userCalendarList)
  100. if err != nil {
  101. err = errors.New("Unmarshal Err:" + err.Error())
  102. return
  103. }
  104. list = userCalendarList.Data
  105. //fmt.Println(response)
  106. //userCalendarList := response.([]interface{})
  107. //
  108. //for _, userCalendar := range userCalendarList {
  109. // fmt.Println(userCalendar)
  110. // fmt.Printf("type :%T;\n", userCalendar)
  111. // //list = append(list, userCalendar.(roadshow.UserCalendar))
  112. //}
  113. //fmt.Println(userCalendarList)
  114. //list = userCalendarList
  115. return
  116. }
  117. // creatSHCalendar 新增上海日历活动
  118. func creatSHCalendar(userPhone, toUserPhone, content, startTime, endTime string, calendarType int8, selfCalendarId int) (err error, errMsg string) {
  119. logMsg := ``
  120. defer func() {
  121. if err != nil {
  122. if logMsg != `` {
  123. errMsg = logMsg
  124. }
  125. }
  126. }()
  127. finalUrl := utils.CRM_OPEN_API_URL + "/v1/Calendar/create"
  128. form := url.Values{
  129. "user_phone": {userPhone},
  130. "to_user_phone": {toUserPhone},
  131. "content": {content},
  132. "start_time": {startTime},
  133. "end_time": {endTime},
  134. }
  135. //发送创建请求
  136. body, err, logMsg := postCurl(finalUrl, form, 0)
  137. if err != nil {
  138. err = errors.New("NewRequest Err:" + err.Error())
  139. return
  140. }
  141. var creatSHCalendarResp roadshow.CreatSHCalendarResp
  142. err = json.Unmarshal(body, &creatSHCalendarResp)
  143. if err != nil {
  144. err = errors.New("Unmarshal Err:" + err.Error())
  145. return
  146. }
  147. calendar := creatSHCalendarResp.Data
  148. //上海系统id
  149. sThirdId := calendar.CalendarID
  150. thirdId, err := strconv.Atoi(sThirdId)
  151. if err != nil {
  152. err = errors.New("string to int Err:" + err.Error())
  153. return
  154. }
  155. // 添加自系统与上海系统的路演关系
  156. relationItem := roadshow.RsCalendarRelation{
  157. UserPhone: userPhone,
  158. CalendarType: calendarType,
  159. SelfCalendarId: selfCalendarId,
  160. ThirdCalendarId: thirdId,
  161. Title: content,
  162. ResearcherMobile: toUserPhone,
  163. ModifyTime: time.Now(),
  164. CreateTime: time.Now(),
  165. }
  166. _, err = roadshow.AddRsCalendarRelation(&relationItem)
  167. if err != nil {
  168. err = errors.New("AddRsCalendarRelation Err:" + err.Error())
  169. fmt.Println(err)
  170. return
  171. }
  172. return
  173. }
  174. // updateSHCalendar 内部函数,只用于发送修改上海日历的http请求
  175. func updateSHCalendar(thirdCalendarId, researcherMobile, content, startTime, endTime string) (calendarResp roadshow.CreatSHCalendarResp, err error) {
  176. finalUrl := utils.CRM_OPEN_API_URL + "/v1/Calendar/update"
  177. form := url.Values{
  178. "calendar_id": {thirdCalendarId},
  179. "to_user_phone": {researcherMobile},
  180. "content": {content},
  181. "start_time": {startTime},
  182. "end_time": {endTime},
  183. }
  184. //发送创建请求
  185. _, err, _ = postCurl(finalUrl, form, 0)
  186. if err != nil {
  187. err = errors.New("NewRequest Err:" + err.Error())
  188. return
  189. }
  190. return
  191. }
  192. // deleteSHCalendar 删除上海方的路演
  193. func deleteSHCalendar(userPhone string, calendarId int) (err error) {
  194. finalUrl := utils.CRM_OPEN_API_URL + "/v1/Calendar/delete"
  195. form := url.Values{
  196. "user_phone": {userPhone},
  197. "calendar_id": {fmt.Sprintf("%v", calendarId)},
  198. }
  199. //发送创建请求
  200. _, err, _ = postCurl(finalUrl, form, 0)
  201. if err != nil {
  202. err = errors.New("NewRequest Err:" + err.Error())
  203. return
  204. }
  205. return
  206. }
  207. // ShResponse 上海数据返回结构体
  208. type ShResponse struct {
  209. Code int `json:"code" description:"1:正常返回;4001:token失效"`
  210. Msg string `json:"msg" description:"文字描述"`
  211. Time int `json:"time" description:"时间戳"`
  212. Data interface{} `json:"data" description:"业务数据"`
  213. }
  214. // getCurl get请求上海接口
  215. func getCurl(urlStr string, params url.Values, num int) (body []byte, err error) {
  216. defer func() {
  217. if err != nil {
  218. //go utils.SendEmail(utils.APPNAME+"get请求上海接口失败:"+time.Now().Format("2006-01-02 15:04:05"), "get请求上海接口失败:"+err.Error(), utils.EmailSendToUsers)
  219. go alarm_msg.SendAlarmMsg("get请求上海接口失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:get请求上海接口失败", 3)
  220. }
  221. }()
  222. token, err := GetAccessToken(false)
  223. if err != nil {
  224. return
  225. }
  226. params.Add("access_token", token)
  227. getUrl := urlStr + "?" + params.Encode()
  228. body, err = http.Get(getUrl)
  229. if err != nil {
  230. utils.FileLog.Info(fmt.Sprint("get Err:", err.Error(), ";url:", getUrl, ";params:", params.Encode(), ";response:", string(body)))
  231. err = errors.New("NewRequest Err:" + err.Error())
  232. return
  233. }
  234. var response ShResponse
  235. err = json.Unmarshal(body, &response)
  236. if err != nil {
  237. utils.FileLog.Info(fmt.Sprint("get Err:", err.Error(), ";url:", getUrl, ";params:", params.Encode(), ";response:", string(body)))
  238. err = errors.New("Unmarshal Err:" + err.Error())
  239. return
  240. }
  241. //如果是token失效,同时只是第一次请求(没有尝试强制刷新token,那么重新请求)
  242. if response.Code == 4001 && num <= 0 {
  243. utils.FileLog.Info(fmt.Sprint("get data err", ";url:", getUrl, ";params:", params.Encode(), ";response:", string(body)))
  244. //token失效
  245. _, tmpErr := refreshAccessToken()
  246. if tmpErr != nil {
  247. err = tmpErr
  248. }
  249. num++
  250. params.Del("access_token")
  251. return getCurl(urlStr, params, num)
  252. } else if response.Code != 1 {
  253. utils.FileLog.Info(fmt.Sprint("get data err", ";url:", getUrl, ";params:", params.Encode(), ";response:", string(body)))
  254. err = errors.New(response.Msg)
  255. return
  256. }
  257. return
  258. }
  259. // postCurl post请求上海接口
  260. func postCurl(urlStr string, form url.Values, num int) (body []byte, err error, errMsg string) {
  261. logMsg := ``
  262. defer func() {
  263. if err != nil {
  264. if logMsg != `` {
  265. errMsg = logMsg
  266. //go utils.SendEmail(utils.APPNAME+"post请求上海接口失败:"+time.Now().Format("2006-01-02 15:04:05"), "post请求上海接口失败:"+errMsg, utils.EmailSendToUsers)
  267. go alarm_msg.SendAlarmMsg("post请求上海接口失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+errMsg, 3)
  268. }
  269. }
  270. }()
  271. token, err := GetAccessToken(false)
  272. if err != nil {
  273. return
  274. }
  275. finalUrl := urlStr + "?access_token=" + token
  276. //发送创建请求
  277. resp, err := netHttp.PostForm(finalUrl, form)
  278. if err != nil {
  279. err = errors.New("NewRequest Err:" + err.Error())
  280. return
  281. }
  282. defer resp.Body.Close()
  283. //解析resp并且存入关联表
  284. body, err = ioutil.ReadAll(resp.Body)
  285. if err != nil {
  286. logMsg = fmt.Sprint("post err; request:", form.Encode(), "; errMsg:", err.Error())
  287. utils.FileLog.Info(logMsg)
  288. return
  289. }
  290. logMsg = fmt.Sprint("post request:", form.Encode(), "; response:", string(body))
  291. utils.FileLog.Info(logMsg)
  292. var response ShResponse
  293. err = json.Unmarshal(body, &response)
  294. if err != nil {
  295. utils.FileLog.Info("post Err:", err.Error(), ";url:", finalUrl, ";params:", form.Encode(), ";response:", string(body))
  296. err = errors.New("Unmarshal Err:" + err.Error())
  297. return
  298. }
  299. utils.FileLog.Info(fmt.Sprint("post request url:", finalUrl, ";params:", form.Encode(), ";response:", string(body)))
  300. //如果是token失效,同时只是第一次请求(没有尝试强制刷新token,那么重新请求)
  301. if response.Code == 4001 && num <= 0 {
  302. //token失效
  303. _, tmpErr := refreshAccessToken()
  304. if tmpErr != nil {
  305. err = tmpErr
  306. }
  307. num++
  308. return postCurl(urlStr, form, num)
  309. } else if response.Code != 1 {
  310. utils.FileLog.Info(fmt.Sprint("post data err", ";url:", finalUrl, ";params:", form.Encode(), ";response:", string(body)))
  311. err = errors.New(response.Msg)
  312. return
  313. }
  314. return
  315. }
  316. // GetAccessToken 获取accessToken
  317. func GetAccessToken(isRefresh bool) (token string, err error) {
  318. defer func() {
  319. if err != nil {
  320. //go utils.SendEmail(utils.APPNAME+"获取上海的token失败:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
  321. go alarm_msg.SendAlarmMsg("获取上海的token失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
  322. }
  323. }()
  324. token, redisErr := utils.Rc.RedisString("SH_ACCESS_TOKEN")
  325. //如果从redis中accessToken 获取失败或者token为空了,再或者需要强制刷新了,那么重新获取accessToken
  326. if redisErr != nil || token == `` || isRefresh {
  327. return refreshAccessToken()
  328. }
  329. return
  330. }
  331. // CalendarToSH 创建活动时同步上海的前置函数
  332. func CalendarToSH(rsCalendar roadshow.RsCalendar, researcher roadshow.RsCalendarResearcher) {
  333. var err error
  334. errMsg := ``
  335. defer func() {
  336. if err != nil {
  337. errMsg = err.Error() + ";" + errMsg
  338. //go utils.SendEmail(utils.APPNAME+"新建上海研究员日历失败:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
  339. go alarm_msg.SendAlarmMsg("新建上海研究员日历失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
  340. }
  341. }()
  342. //redis获取创建者及研究员信息
  343. userInfo, err := getAdminInfoById(rsCalendar.SysUserId)
  344. if err != nil {
  345. utils.FileLog.Info("getAdminInfoById err: " + err.Error())
  346. return
  347. }
  348. researcherInfo, err := getAdminInfoById(researcher.ResearcherId)
  349. if err != nil {
  350. utils.FileLog.Info("getAdminInfoById err: " + err.Error())
  351. return
  352. }
  353. sTime, _ := time.ParseInLocation(utils.FormatDateTime, researcher.StartDate+" "+researcher.StartTime, time.Now().Location())
  354. startTime := sTime.Format("2006-01-02 15:04")
  355. eTime, _ := time.ParseInLocation(utils.FormatDateTime, researcher.EndDate+" "+researcher.EndTime, time.Now().Location())
  356. endTime := eTime.Format("2006-01-02 15:04")
  357. // 创建上海路演日程
  358. err, errMsg = creatSHCalendar(userInfo.Mobile, researcherInfo.Mobile, rsCalendar.CompanyName+rsCalendar.Title, startTime, endTime, 1, researcher.RsCalendarResearcherId)
  359. if err != nil {
  360. utils.FileLog.Info("CreatSHCalendar err: " + err.Error())
  361. fmt.Println(err)
  362. return
  363. }
  364. // 更新路演与研究员关系表的同步字段
  365. whereParams := make(map[string]interface{})
  366. updateParams := make(map[string]interface{})
  367. whereParams["rs_calendar_researcher_id"] = researcher.RsCalendarResearcherId
  368. updateParams["is_synced"] = 1
  369. updateParams["modify_time"] = time.Now()
  370. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  371. if err != nil {
  372. utils.FileLog.Info("UpdateCalendarResearcher err: " + err.Error())
  373. fmt.Println("UpdateCalendarResearcher err: " + err.Error())
  374. return
  375. }
  376. // 更新路演的同步字段
  377. calWhereParams := make(map[string]interface{})
  378. calWhereParams["rs_calendar_id"] = rsCalendar.RsCalendarId
  379. err = roadshow.UpdateRsCalendar(calWhereParams, updateParams)
  380. if err != nil {
  381. utils.FileLog.Info("UpdateRsCalendar err: " + err.Error())
  382. fmt.Println("UpdateRsCalendar err: " + err.Error())
  383. return
  384. }
  385. }
  386. // MatterToSH 创建事项时同步上海的前置函数
  387. func MatterToSH(matter roadshow.RsMatters) (err error) {
  388. errMsg := ``
  389. defer func() {
  390. if err != nil {
  391. errMsg = err.Error() + ";" + errMsg
  392. //go utils.SendEmail(utils.APPNAME+"新建上海研究员事项失败:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
  393. go alarm_msg.SendAlarmMsg("新建上海研究员事项失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
  394. }
  395. }()
  396. //获取研究员信息
  397. researcherInfo, err := getAdminInfoById(matter.SysUserId)
  398. if err != nil {
  399. //utils.FileLog.Info("getAdminInfoById err: " + err.Error())
  400. return
  401. }
  402. sTime, _ := time.ParseInLocation(utils.FormatDateTime, matter.StartDate+" "+matter.StartTime, time.Now().Location())
  403. startTime := sTime.Format("2006-01-02 15:04")
  404. eTime, _ := time.ParseInLocation(utils.FormatDateTime, matter.EndDate+" "+matter.EndTime, time.Now().Location())
  405. endTime := eTime.Format("2006-01-02 15:04")
  406. err, errMsg = creatSHCalendar(researcherInfo.Mobile, researcherInfo.Mobile, matter.MatterContent, startTime, endTime, 2, matter.RsMattersId)
  407. if err != nil {
  408. return
  409. }
  410. // 修改事项的同步字段
  411. updateParams := make(map[string]interface{})
  412. whereParams := make(map[string]interface{})
  413. updateParams["is_synced"] = 1
  414. whereParams["rs_matters_id"] = matter.RsMattersId
  415. err = roadshow.UpdateRsMatters(whereParams, updateParams)
  416. if err != nil {
  417. err = fmt.Errorf("UpdateRsMatters err: " + err.Error())
  418. }
  419. return
  420. }
  421. // UpdateSHCalendar 更新上海日历活动
  422. func UpdateSHCalendar(rsCalendarId, rsCalendarResearcherId int, activityType, roadshowType, activityCategory, roadshowPlatform, province, city string, calendarResearcherList []*roadshow.CalendarResearcher) (err error) {
  423. errMsg := ``
  424. defer func() {
  425. if errMsg != `` {
  426. //go utils.SendEmail(utils.APPNAME+"更新上海日历活动失败:"+time.Now().Format("2006-01-02 15:04:05"), errMsg, utils.EmailSendToUsers)
  427. go alarm_msg.SendAlarmMsg("更新上海日历活动失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+errMsg, 3)
  428. }
  429. }()
  430. //查询关联表获取信息
  431. var condition string
  432. var pars []interface{}
  433. condition = ` AND self_calendar_id = ? and calendar_type = 1 `
  434. pars = append(pars, rsCalendarResearcherId)
  435. relationItem, err := roadshow.GetRelationByPars(condition, pars)
  436. if err != nil {
  437. err = errors.New("GetRelationByPars err:" + err.Error())
  438. //go utils.SendEmail(utils.APPNAME+"上海关联表查询失败:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
  439. go alarm_msg.SendAlarmMsg("上海关联表查询失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
  440. fmt.Println(err)
  441. return
  442. }
  443. //需要同时修改创建人及研究员的日历(目前听说只有1个,先按一个处理吧)
  444. for _, researcher := range calendarResearcherList {
  445. sTime, _ := time.ParseInLocation(utils.FormatDateTime, researcher.StartDate+" "+researcher.StartTime, time.Now().Location())
  446. startTime := sTime.Format("2006-01-02 15:04")
  447. eTime, _ := time.ParseInLocation(utils.FormatDateTime, researcher.EndDate+" "+researcher.EndTime, time.Now().Location())
  448. endTime := eTime.Format("2006-01-02 15:04")
  449. title := getTitle(activityType, roadshowType, activityCategory, roadshowPlatform, province, city)
  450. //发送更新请求
  451. _, err = updateSHCalendar(fmt.Sprintf("%v", relationItem.ThirdCalendarId), relationItem.ResearcherMobile, title, startTime, endTime)
  452. if err != nil {
  453. errMsg += fmt.Sprint("更新研究员日历信息:", relationItem.ThirdCalendarId, ";err:"+err.Error(), ";")
  454. }
  455. //// 更新路演活动的信息
  456. //calWhereParams := make(map[string]interface{})
  457. //calWhereParams["rs_calendar_id"] = rsCalendarId
  458. //err = roadshow.UpdateRsCalendarRelation(calWhereParams, updateParams)
  459. //if err != nil {
  460. // errMsg += fmt.Sprint("UpdateRsCalendar:", relationItem.ThirdCalendarId, ";err:"+err.Error(), ";")
  461. // return
  462. //}
  463. }
  464. // 更新路演活动中 研究员的信息
  465. whereParams := make(map[string]interface{})
  466. updateParams := make(map[string]interface{})
  467. whereParams["rs_calendar_researcher_id"] = rsCalendarResearcherId
  468. updateParams["is_synced"] = 1
  469. updateParams["modify_time"] = time.Now()
  470. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  471. if err != nil {
  472. errMsg += fmt.Sprint("UpdateCalendarResearcher:", relationItem.ThirdCalendarId, ";err:"+err.Error(), ";")
  473. return
  474. }
  475. // 更新路演活动的信息
  476. calWhereParams := make(map[string]interface{})
  477. calWhereParams["rs_calendar_id"] = rsCalendarId
  478. err = roadshow.UpdateRsCalendar(calWhereParams, updateParams)
  479. if err != nil {
  480. errMsg += fmt.Sprint("UpdateRsCalendar:", relationItem.ThirdCalendarId, ";err:"+err.Error(), ";")
  481. return
  482. }
  483. return
  484. }
  485. // UpdateSHCalendarByMatter 更新上海日历活动
  486. func UpdateSHCalendarByMatter(req roadshow.UpdateMattersReq) (err error) {
  487. defer func() {
  488. if err != nil {
  489. //go utils.SendEmail(utils.APPNAME+"更新上海日历活动失败:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
  490. go alarm_msg.SendAlarmMsg("更新上海日历活动失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
  491. }
  492. }()
  493. if err != nil {
  494. return
  495. }
  496. //需要同时修改创建人及研究员的日历
  497. //查询关联表获取信息
  498. var condition string
  499. var pars []interface{}
  500. condition = ` AND self_calendar_id = ? and calendar_type = 2 `
  501. pars = append(pars, req.RsMattersId)
  502. relationItem, err := roadshow.GetRelationByPars(condition, pars)
  503. if err != nil {
  504. err = errors.New("GetRelationByPars err:" + err.Error())
  505. //go utils.SendEmail(utils.APPNAME+"上海关联表查询失败:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
  506. go alarm_msg.SendAlarmMsg("上海关联表查询失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
  507. fmt.Println(err)
  508. return
  509. }
  510. sTime, _ := time.ParseInLocation(utils.FormatDateTime, req.StartDate+" "+req.StartTime, time.Now().Location())
  511. startTime := sTime.Format("2006-01-02 15:04")
  512. eTime, _ := time.ParseInLocation(utils.FormatDateTime, req.EndDate+" "+req.EndTime, time.Now().Location())
  513. endTime := eTime.Format("2006-01-02 15:04")
  514. //发送更新请求
  515. _, err = updateSHCalendar(fmt.Sprintf("%v", relationItem.ThirdCalendarId), relationItem.ResearcherMobile, relationItem.CustomerName+relationItem.Content, startTime, endTime)
  516. if err == nil {
  517. updateParams := make(map[string]interface{})
  518. whereParams := make(map[string]interface{})
  519. updateParams["is_synced"] = 1
  520. whereParams["rs_matters_id"] = req.RsMattersId
  521. err = roadshow.UpdateRsMatters(whereParams, updateParams)
  522. if err != nil {
  523. utils.FileLog.Info("UpdateRsMatters err: " + err.Error())
  524. fmt.Println("UpdateRsMatters err: " + err.Error())
  525. return
  526. }
  527. }
  528. return
  529. }
  530. // DeleteSHCalendar 删除上海日历活动
  531. func DeleteSHCalendar(rsCalendarResearcherId int) (err error) {
  532. defer func() {
  533. if err != nil {
  534. //go utils.SendEmail(utils.APPNAME+"删除上海日历活动失败:"+time.Now().Format("2006-01-02 15:04:05"), fmt.Sprint("关系id:", rsCalendarResearcherId, ";err:", err.Error()), utils.EmailSendToUsers)
  535. go alarm_msg.SendAlarmMsg("删除上海日历活动失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+fmt.Sprint("关系id:", rsCalendarResearcherId, ";err:", err.Error()), 3)
  536. }
  537. }()
  538. var condition string
  539. var pars []interface{}
  540. condition = ` AND self_calendar_id = ? and calendar_type = 1 `
  541. pars = append(pars, rsCalendarResearcherId)
  542. relationItem, err := roadshow.GetRelationByPars(condition, pars)
  543. if err != nil {
  544. logInfo := fmt.Sprint("删除上海日历活动失败;rsCalendarResearcherId:,", rsCalendarResearcherId, " ;GetRelationByPars err"+err.Error())
  545. err = errors.New(logInfo)
  546. utils.FileLog.Info(logInfo)
  547. if err.Error() == utils.ErrNoRow() {
  548. err = nil
  549. return
  550. }
  551. return
  552. }
  553. //删除上海方的路演
  554. err = deleteSHCalendar(relationItem.UserPhone, relationItem.ThirdCalendarId)
  555. if err != nil {
  556. return
  557. }
  558. //删除活动表及事项表
  559. err = roadshow.DeleteRsCalendarRelation(relationItem.RelationId)
  560. if err != nil {
  561. err = errors.New("DeleteRsCalendarRelation err:" + err.Error())
  562. return
  563. }
  564. return
  565. }
  566. // DeleteSHMatter 删除上海日历事项
  567. func DeleteSHMatter(matterId int) (err error) {
  568. defer func() {
  569. if err != nil {
  570. //go utils.SendEmail(utils.APPNAME+"删除上海日历事项失败:", "删除上海研究员日历失败 "+err.Error(), utils.EmailSendToUsers)
  571. go alarm_msg.SendAlarmMsg("删除上海研究员日历失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
  572. }
  573. }()
  574. var condition string
  575. var pars []interface{}
  576. condition = ` AND self_calendar_id = ? and calendar_type = 2 `
  577. pars = append(pars, matterId)
  578. relationItem, err := roadshow.GetRelationByPars(condition, pars)
  579. if err != nil {
  580. err = errors.New(fmt.Sprint("删除上海日历事项失败;matterId:,", matterId, " ;GetRelationByPars err"+err.Error()))
  581. utils.FileLog.Info(err.Error())
  582. if err.Error() == utils.ErrNoRow() {
  583. err = nil
  584. return
  585. }
  586. return
  587. }
  588. //删除上海方的路演
  589. err = deleteSHCalendar(relationItem.UserPhone, relationItem.ThirdCalendarId)
  590. //删除活动表及事项表
  591. err = roadshow.DeleteRsCalendarRelation(relationItem.RelationId)
  592. if err != nil {
  593. err = errors.New("DeleteRsCalendarRelation err:" + err.Error())
  594. return
  595. }
  596. return
  597. }
  598. // SyncCalendarFromShanghai 上海路演数据同步到自系统
  599. func SyncCalendarFromShanghai(userPhone, startDate, endDate string) (err error) {
  600. errMsg := ``
  601. defer func() {
  602. if errMsg != `` {
  603. //fmt.Println("err:", errMsg)
  604. //go utils.SendEmail(utils.APPNAME+"上海路演数据同步到自系统失败:"+time.Now().Format("2006-01-02 15:04:05"), errMsg, utils.EmailSendToUsers)
  605. go alarm_msg.SendAlarmMsg("上海路演数据同步到自系统失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+errMsg, 3)
  606. }
  607. }()
  608. //fmt.Println(userPhone, startDate, endDate)
  609. endDateTime, err := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  610. if err != nil {
  611. errMsg = `结束日期转time类型失败,err:` + err.Error()
  612. return
  613. }
  614. //往后延迟一天,避免截止到当天
  615. endDate = endDateTime.AddDate(0, 0, 1).Format(utils.FormatDate)
  616. currDay := time.Now().Format(utils.FormatDate)
  617. nowDateTime, _ := time.ParseInLocation(utils.FormatDate, currDay, time.Local)
  618. //如果传入的结束日期早于当前日期,那么就不去查询了
  619. if endDateTime.Before(nowDateTime) {
  620. return
  621. }
  622. //获取当前研究员信息
  623. userPhoneInfo, err := getAdminInfo(userPhone)
  624. if err != nil {
  625. errMsg += fmt.Sprint("获取手机号信息失败:手机号:", userPhone, ";err:"+err.Error(), ";")
  626. return
  627. }
  628. //根据研究员和开始/结束日期获取上海的活动路演
  629. rsCalendarResearcherList, err := roadshow.GetRsCalendarResearcherInfoIByResearcherIdAndDate(userPhoneInfo.AdminId, currDay, endDate)
  630. if err != nil {
  631. errMsg += fmt.Sprint("获取研究员日程信息失败:手机号:", userPhone, ";err:"+err.Error(), ";")
  632. return
  633. }
  634. //待删除的活动路演
  635. deleteRsCalendarResearcherMap := make(map[int][]*roadshow.RsCalendarResearcherRelationInfo)
  636. for _, v := range rsCalendarResearcherList {
  637. tmpList, ok := deleteRsCalendarResearcherMap[v.ThirdCalendarId]
  638. if !ok {
  639. tmpList = make([]*roadshow.RsCalendarResearcherRelationInfo, 0)
  640. }
  641. tmpList = append(tmpList, v)
  642. deleteRsCalendarResearcherMap[v.ThirdCalendarId] = tmpList
  643. }
  644. //以当前日期作为起始日期去同步
  645. list, err := getCalendarFrom(userPhone, currDay, endDate)
  646. if err != nil {
  647. errMsg = fmt.Sprint("获取第三方路演日历数据失败,", "userPhone:", userPhone, ";currDay:", currDay, ";endDate:", endDate, ";err:"+err.Error())
  648. return
  649. }
  650. thirdIdList := make([]int, 0)
  651. if len(list) > 0 {
  652. for _, v := range list {
  653. thirdIdList = append(thirdIdList, v.ID)
  654. //移除还存在的活动,保留不存在的活动
  655. delete(deleteRsCalendarResearcherMap, v.ID)
  656. }
  657. rsCalendarRelationList, tmpErr := roadshow.GetRsCalendarRelationListByThirdIds(thirdIdList)
  658. if tmpErr != nil {
  659. err = tmpErr
  660. errMsg = "获取关联列表失败,err:" + tmpErr.Error()
  661. return
  662. }
  663. rsCalendarRelationMap := make(map[int]*roadshow.RsCalendarRelation)
  664. for _, rsCalendarRelation := range rsCalendarRelationList {
  665. rsCalendarRelationMap[rsCalendarRelation.ThirdCalendarId] = rsCalendarRelation
  666. }
  667. for _, v := range list {
  668. //展示优先级:1、customer_name 2、project_name 3、title 需求池953
  669. if v.CustomerName != "" {
  670. v.Title = v.CustomerName
  671. } else if v.ProjectName != "" {
  672. v.Title = v.ProjectName
  673. }
  674. if rsCalendarRelation, ok := rsCalendarRelationMap[v.ID]; ok {
  675. //存在的话,那么就去查找对应的信息
  676. if rsCalendarRelation.CalendarType == 1 {
  677. //路演
  678. rsCalendarResearcherInfo, tmpErr := roadshow.GetRsCalendarResearcherById(rsCalendarRelation.SelfCalendarId)
  679. if tmpErr != nil {
  680. errMsg += fmt.Sprint("第三方日历ID:", v.ID, "获取路演研究员信息失败;err:"+tmpErr.Error(), ";")
  681. continue
  682. }
  683. rsCalendarInfo, tmpErr := roadshow.GetRsCalendarById(rsCalendarResearcherInfo.RsCalendarId)
  684. if tmpErr != nil {
  685. errMsg += fmt.Sprint("第三方日历ID:", v.ID, "获取路演信息失败;err:"+tmpErr.Error(), ";")
  686. continue
  687. }
  688. if rsCalendarInfo.Source == 0 { //自系统创建的路演活动,不需要依靠上海方来修改
  689. continue
  690. }
  691. //是否去同步变更数据库
  692. isUpdateSync := false
  693. //是否变更
  694. isUpdate := false
  695. if v.StartTime != rsCalendarRelation.StartTime {
  696. isUpdate = true
  697. }
  698. if v.EndTime != rsCalendarRelation.EndTime {
  699. isUpdate = true
  700. }
  701. if v.Title != rsCalendarRelation.Title {
  702. isUpdate = true
  703. }
  704. if rsCalendarResearcherInfo.Status == 4 { // 被删除了,现在是需要更新
  705. isUpdate = true
  706. }
  707. researcherList := make([]admin.AdminItem, 0)
  708. researcherMap := make(map[int]admin.AdminItem)
  709. addResearcherList := make([]admin.AdminItem, 0) // 需要新增的研究员
  710. delResearcherIdList := make([]int, 0) //需要删除的路演活动与研究员的关系id
  711. updateResearcherList := make([]*roadshow.RsCalendarResearcher, 0) //待更新的路演活动中研究员信息
  712. if v.ResearcherMobile != rsCalendarRelation.ResearcherMobile {
  713. //研究员变更了,需要去改表
  714. isUpdateSync = true
  715. researcherMobileList := strings.Split(v.ResearcherMobile, ",")
  716. if len(researcherMobileList) > 0 {
  717. for _, mobile := range researcherMobileList {
  718. researcherInfo, tmpErr := getAdminInfo(mobile)
  719. if tmpErr != nil {
  720. errMsg += fmt.Sprint("第三方日历ID:", v.ID, "获取研究员失败,研究员手机号:", mobile, ";err:"+tmpErr.Error(), ";")
  721. continue
  722. }
  723. if researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR ||
  724. researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RESEARCHR ||
  725. researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR ||
  726. researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  727. researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
  728. researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  729. researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  730. researcherList = append(researcherList, researcherInfo)
  731. researcherMap[researcherInfo.AdminId] = researcherInfo
  732. }
  733. }
  734. }
  735. //没有研究员
  736. if len(researcherList) <= 0 {
  737. errMsg += fmt.Sprint("第三方日历ID:", v.ID, ";对方研究员信息失败;")
  738. continue
  739. }
  740. rsCalendarResearcherList, tmpErr := roadshow.GetRsCalendarResearcherListByRsCalendarId(rsCalendarInfo.RsCalendarId)
  741. if tmpErr != nil {
  742. errMsg += fmt.Sprint("第三方日历ID:", v.ID, "获取路演活动中的研究员列表失败,路演活动ID:", rsCalendarInfo.RsCalendarId, ";err:"+tmpErr.Error(), ";")
  743. continue
  744. }
  745. //现有活动中的研究员
  746. rsCalendarResearcherMap := make(map[int]*roadshow.RsCalendarResearcher)
  747. for _, rsCalendarResearcher := range rsCalendarResearcherList {
  748. if _, ok := researcherMap[rsCalendarResearcher.ResearcherId]; ok {
  749. if isUpdate {
  750. updateResearcherList = append(updateResearcherList, rsCalendarResearcher)
  751. }
  752. } else {
  753. delResearcherIdList = append(delResearcherIdList, rsCalendarResearcher.RsCalendarResearcherId)
  754. }
  755. rsCalendarResearcherMap[rsCalendarResearcher.ResearcherId] = rsCalendarResearcher
  756. }
  757. //校验是否需要新增研究员
  758. for adminId, researcherInfo := range researcherMap {
  759. //如果
  760. if _, ok := rsCalendarResearcherMap[adminId]; !ok {
  761. addResearcherList = append(addResearcherList, researcherInfo)
  762. }
  763. }
  764. } else if isUpdate { //如果有字段更新,那么需要将所有的研究员信息更新
  765. isUpdateSync = true
  766. rsCalendarResearcherList, tmpErr := roadshow.GetRsCalendarResearcherListByRsCalendarId(rsCalendarInfo.RsCalendarId)
  767. if tmpErr != nil {
  768. errMsg += fmt.Sprint("第三方日历ID:", v.ID, "获取路演活动中的研究员列表失败,路演活动ID:", rsCalendarInfo.RsCalendarId, ";err:"+tmpErr.Error(), ";")
  769. continue
  770. }
  771. for _, rsCalendarResearcher := range rsCalendarResearcherList {
  772. updateResearcherList = append(updateResearcherList, rsCalendarResearcher)
  773. }
  774. }
  775. if isUpdateSync {
  776. tmpErr = roadshow.UpdateSyncRsCalendarRelation(v, rsCalendarInfo, rsCalendarRelation, updateResearcherList, delResearcherIdList, addResearcherList)
  777. if tmpErr != nil {
  778. err = tmpErr
  779. errMsg += fmt.Sprint("第三方日历ID:", v.ID, "修改关联关系失败;err:"+tmpErr.Error(), ";")
  780. return
  781. }
  782. }
  783. } else {
  784. //事项
  785. //事项都是由自系统创建的,不需要依靠上海方来修改
  786. }
  787. } else {
  788. //数据不存在
  789. createUser, tmpErr := getAdminInfo(v.UserPhone)
  790. if tmpErr != nil {
  791. errMsg += fmt.Sprint("第三方日历ID:", v.ID, "获取创建人失败,创建人手机号:", v.UserPhone, ";err:"+tmpErr.Error(), ";")
  792. continue
  793. }
  794. //研究员列表
  795. researcherList := make([]admin.AdminItem, 0)
  796. researcherMobileList := strings.Split(v.ResearcherMobile, ",")
  797. if len(researcherMobileList) > 0 {
  798. for _, mobile := range researcherMobileList {
  799. researcherInfo, tmpErr := getAdminInfo(mobile)
  800. if tmpErr != nil {
  801. errMsg += fmt.Sprint("第三方日历ID:", v.ID, "获取研究员失败,研究员手机号:", mobile, ";err:"+tmpErr.Error(), ";")
  802. continue
  803. }
  804. if researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR ||
  805. researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RESEARCHR ||
  806. researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR ||
  807. researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  808. researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
  809. researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  810. researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN ||
  811. researcherInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  812. researcherList = append(researcherList, researcherInfo)
  813. }
  814. }
  815. }
  816. //没有研究员
  817. if len(researcherList) <= 0 {
  818. continue
  819. }
  820. //数据入库
  821. tmpErr = roadshow.SyncRsCalendarRelation(v, createUser, researcherList)
  822. if tmpErr != nil {
  823. err = tmpErr
  824. errMsg += fmt.Sprint("第三方日历ID:", v.ID, "绑定关联关系失败;err:"+tmpErr.Error(), ";")
  825. continue
  826. }
  827. //fmt.Println("createUser:", createUser)
  828. }
  829. }
  830. }
  831. //上海那边已经删除了路演,这边也要同步删除
  832. for _, deleteRsCalendarResearcherList := range deleteRsCalendarResearcherMap {
  833. for _, deleteRsCalendarResearcher := range deleteRsCalendarResearcherList {
  834. // 更新路演与研究员关系表的状态字段
  835. whereParams := make(map[string]interface{})
  836. updateParams := make(map[string]interface{})
  837. whereParams["rs_calendar_researcher_id"] = deleteRsCalendarResearcher.RsCalendarResearcherId
  838. updateParams["status"] = 4
  839. updateParams["modify_time"] = time.Now()
  840. tmpErr := roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  841. if tmpErr != nil {
  842. err = tmpErr
  843. errMsg += fmt.Sprint("第三方日历ID:", deleteRsCalendarResearcher.ThirdCalendarId, "删除关联关系失败;err:"+tmpErr.Error(), ";")
  844. continue
  845. }
  846. // 更新路演的同步字段
  847. //calWhereParams := make(map[string]interface{})
  848. //calUpdateParams := make(map[string]interface{})
  849. //calWhereParams["rs_calendar_id"] = deleteRsCalendarResearcher.RsCalendarId
  850. //updateParams["is_synced"] = 1
  851. //err = roadshow.UpdateRsCalendar(calWhereParams, calUpdateParams)
  852. }
  853. }
  854. return
  855. }
  856. // CreateOaUser 新增系统用户
  857. func CreateOaUser(mobile, username string, groupId int) (err error) {
  858. defer func() {
  859. if err != nil {
  860. errMsg := fmt.Sprint("手机号:", mobile, ";username:", username, ";分组id:", groupId, ";err:", err.Error())
  861. //go utils.SendEmail(utils.APPNAME+"系统用户同步到上海失败:"+time.Now().Format("2006-01-02 15:04:05"), errMsg, utils.EmailSendToUsers)
  862. go alarm_msg.SendAlarmMsg("系统用户同步到上海失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+errMsg, 3)
  863. }
  864. }()
  865. finalUrl := utils.CRM_OPEN_API_URL + "/v1/OaUser/create"
  866. //发送创建请求
  867. form := url.Values{}
  868. form.Add("mobile", mobile)
  869. form.Add("username", username)
  870. form.Add("group_id", fmt.Sprint(groupId))
  871. //发送创建请求
  872. _, err, _ = postCurl(finalUrl, form, 0)
  873. if err != nil {
  874. err = errors.New("NewRequest Err:" + err.Error())
  875. return
  876. }
  877. return
  878. }
  879. // getAdminInfo 通过手机号获取用户信息
  880. func getAdminInfo(mobile string) (adminInfo admin.AdminItem, err error) {
  881. adminMap := make(map[string]admin.AdminItem)
  882. redisAdminData, redisErr := utils.Rc.RedisString(utils.CACHE_KEY_ADMIN)
  883. if redisErr != nil {
  884. list, err := admin.GetSysuserList("", []interface{}{}, 0, 1000)
  885. // GetSysuserList
  886. for _, tmpAdminInfo := range list {
  887. adminMap[tmpAdminInfo.Mobile] = *tmpAdminInfo
  888. }
  889. //入缓存
  890. redisJsonData, err := json.Marshal(adminMap)
  891. if err == nil {
  892. _ = utils.Rc.Put(utils.CACHE_KEY_ADMIN, string(redisJsonData), time.Minute*30)
  893. }
  894. } else {
  895. err := json.Unmarshal([]byte(redisAdminData), &adminMap)
  896. if err != nil {
  897. fmt.Println("用户数据,json转换失败:", err)
  898. }
  899. }
  900. adminInfo, ok := adminMap[mobile]
  901. if !ok {
  902. err = fmt.Errorf("找不到该手机号用户,mobile:" + mobile)
  903. }
  904. return
  905. }
  906. // getAdminInfoById 通过用户id获取用户信息
  907. func getAdminInfoById(sysId int) (adminInfo admin.AdminItem, err error) {
  908. adminMap := make(map[int]admin.AdminItem)
  909. redisAdminData, redisErr := utils.Rc.RedisString(utils.CACHE_KEY_ADMIN_ID)
  910. if redisErr != nil {
  911. list, err := admin.GetSysuserList("", []interface{}{}, 0, 1000)
  912. // GetSysuserList
  913. for _, tmpAdminInfo := range list {
  914. adminMap[tmpAdminInfo.AdminId] = *tmpAdminInfo
  915. }
  916. //入缓存
  917. redisJsonData, err := json.Marshal(adminMap)
  918. if err == nil {
  919. _ = utils.Rc.Put(utils.CACHE_KEY_ADMIN_ID, string(redisJsonData), time.Minute*30)
  920. }
  921. } else {
  922. err := json.Unmarshal([]byte(redisAdminData), &adminMap)
  923. if err != nil {
  924. fmt.Println("用户数据,json转换失败:", err)
  925. }
  926. }
  927. adminInfo, ok := adminMap[sysId]
  928. if !ok {
  929. err = fmt.Errorf("找不到该用户id,sysId:" + fmt.Sprint(sysId))
  930. }
  931. return
  932. }
  933. func getTitle(activityType, roadshowType, activityCategory, roadshowPlatform, province, city string) string {
  934. var title string
  935. switch activityType {
  936. case "内部会议":
  937. title = "内部会议"
  938. case "公开会议", "路演":
  939. if roadshowType == "线上" {
  940. title = roadshowType + activityType + roadshowPlatform
  941. } else {
  942. title = roadshowType + activityType + province + city
  943. }
  944. case "报告电话会":
  945. title = activityCategory + "电话会"
  946. }
  947. return title
  948. }
  949. // GetAllActivityType 获取全部的活动分类
  950. func GetAllActivityType() (list []*roadshow.ActivityTypeList, err error) {
  951. list, err = roadshow.GetActivityTypeListByActivityTypePId(0)
  952. if err != nil {
  953. return
  954. }
  955. for _, v := range list {
  956. tmpList, tmpErr := roadshow.GetActivityTypeListByActivityTypePId(v.ActivityTypeId)
  957. if tmpErr != nil {
  958. err = tmpErr
  959. return
  960. }
  961. v.ChildList = tmpList
  962. }
  963. return
  964. }
  965. // GetCalendarFrom 获取上海方的路演活动列表
  966. func GetCalendarFrom(userPhone, startDate, endDate string) (list []roadshow.UserCalendar, err error) {
  967. list, err = getCalendarFrom(userPhone, startDate, endDate)
  968. return
  969. }