morning_meeting_review.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "github.com/tealeg/xlsx"
  8. "hongze/hz_crm_api/controllers"
  9. "hongze/hz_crm_api/models"
  10. "hongze/hz_crm_api/models/cygx"
  11. "hongze/hz_crm_api/models/system"
  12. "hongze/hz_crm_api/services"
  13. cygxService "hongze/hz_crm_api/services/cygx"
  14. "hongze/hz_crm_api/services/elastic"
  15. "hongze/hz_crm_api/utils"
  16. "os"
  17. "path/filepath"
  18. "strconv"
  19. "strings"
  20. "time"
  21. )
  22. // 晨会点评
  23. type MorningMeetingController struct {
  24. controllers.BaseAuthController
  25. }
  26. // @Title 晨会点评列表
  27. // @Description 活动客户列表接口
  28. // @Param PageSize query int true "每页数据条数"
  29. // @Param CurrentIndex query int true "当前页页码,从1开始"
  30. // @Param KeyWord query string false "关键词搜索"
  31. // @Param MeetingTime query string false "晨会日期"
  32. // @Param Status query string false "发布状态,1,已发布,0未发布"
  33. // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
  34. // @Success 200 {object} cygx.CygxMorningMeetingReviewsList
  35. // @router /morningMeeting/list [get]
  36. func (this *MorningMeetingController) List() {
  37. br := new(models.BaseResponse).Init()
  38. defer func() {
  39. this.Data["json"] = br
  40. this.ServeJSON()
  41. }()
  42. sysUser := this.SysUser
  43. if sysUser == nil {
  44. br.Msg = "请登录"
  45. br.ErrMsg = "请登录,SysUser Is Empty"
  46. br.Ret = 408
  47. return
  48. }
  49. pageSize, _ := this.GetInt("PageSize")
  50. currentIndex, _ := this.GetInt("CurrentIndex")
  51. keyWord := this.GetString("KeyWord")
  52. meetingTimeDate := this.GetString("MeetingTime")
  53. status := this.GetString("Status")
  54. var startSize int
  55. var condition string
  56. var pars []interface{}
  57. if status != "" {
  58. condition += ` AND status = ` + status + ` `
  59. }
  60. if keyWord != "" {
  61. condition += ` AND ( industry_names LIKE '%` + keyWord + `%' )`
  62. }
  63. if meetingTimeDate != "" {
  64. //meetingTime := utils.StrDateToDate(meetingTimeDate) //时间字符串格式转时间格式
  65. //meetingTimeString := meetingTime.Format(utils.FormatDateTime)
  66. condition += ` AND meeting_time = ? `
  67. pars = append(pars, meetingTimeDate)
  68. }
  69. if pageSize <= 0 {
  70. pageSize = utils.PageSize20
  71. }
  72. if currentIndex <= 0 {
  73. currentIndex = 1
  74. }
  75. startSize = utils.StartIndex(currentIndex, pageSize)
  76. total, err := cygx.GetCygxMorningMeetingReviewsListCount(condition, pars)
  77. if err != nil {
  78. br.Msg = "获取失败"
  79. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  80. return
  81. }
  82. condition += ` ORDER BY publish_time DESC `
  83. resp := new(cygx.CygxMorningMeetingReviewsList)
  84. list, err := cygx.GetCygxMorningMeetingReviewsList(condition, pars, startSize, pageSize)
  85. if err != nil {
  86. br.Msg = "获取失败"
  87. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  88. return
  89. }
  90. var meetingIds []int
  91. for _, item := range list {
  92. respItem := cygx.CygxMorningMeetingReviewItem{
  93. Id: item.Id,
  94. MeetingTime: item.MeetingTime.Local().Format(utils.FormatDate),
  95. CreateTime: item.CreateTime.Local().Format(utils.FormatDateTime),
  96. ModifyTime: item.ModifyTime.Local().Format(utils.FormatDateTime),
  97. Status: item.Status,
  98. PartNums: item.PartNums,
  99. IndustryNames: item.IndustryNames,
  100. }
  101. if item.Status == 1 {
  102. respItem.PublishTime = item.PublishTime.Local().Format(utils.FormatDateTime)
  103. }
  104. meetingIds = append(meetingIds, item.Id)
  105. resp.List = append(resp.List, &respItem)
  106. }
  107. //PvUv 数量
  108. mapPv, mapUv := cygxService.GetCygxMorningMeetingReviewChapterHistoryPvUvMap(meetingIds)
  109. for _, v := range resp.List {
  110. v.Pv = mapPv[v.Id]
  111. v.Uv = mapUv[v.Id]
  112. }
  113. page := paging.GetPaging(currentIndex, pageSize, total)
  114. resp.Paging = page
  115. br.Ret = 200
  116. br.Success = true
  117. br.Msg = "获取成功"
  118. br.Data = resp
  119. }
  120. // @Title 新增晨会点评
  121. // @Description 新增晨会点评接口
  122. // @Param request body cygx.AddMorningMeetingReviewsReq true "type json string"
  123. // @Success 200 {object} "保存成功"
  124. // @router /morningMeeting/preserveAndPublish [post]
  125. func (this *MorningMeetingController) PreserveAndPublish() {
  126. br := new(models.BaseResponse).Init()
  127. defer func() {
  128. this.Data["json"] = br
  129. this.ServeJSON()
  130. }()
  131. sysUser := this.SysUser
  132. if sysUser == nil {
  133. br.Msg = "请登录"
  134. br.ErrMsg = "请登录,SysUser Is Empty"
  135. br.Ret = 408
  136. return
  137. }
  138. var reqList cygx.AddMorningMeetingReviewsReq
  139. err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqList)
  140. if err != nil {
  141. br.Msg = "参数解析异常!"
  142. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  143. return
  144. }
  145. meetingTime := utils.StrDateToDate(reqList.MeetingTime) //时间字符串格式转时间格式
  146. var industryNameslice []string
  147. for _, item := range reqList.List {
  148. industryNameslice = append(industryNameslice, item.IndustryName)
  149. }
  150. industryNames := strings.Join(industryNameslice, ",")
  151. if reqList.MeetingId <= 0 {
  152. //先新增主表
  153. reviewItem := cygx.CygxMorningMeetingReviews{
  154. MeetingTime: meetingTime,
  155. CreateTime: time.Now(),
  156. ModifyTime: time.Now(),
  157. PartNums: len(reqList.List),
  158. IndustryNames: industryNames,
  159. }
  160. if reqList.DoType == 1 {
  161. reviewItem.PublishTime = time.Now()
  162. reviewItem.Status = 1
  163. }
  164. meetingId, err := cygx.AddCygxMorningMeetingReviews(&reviewItem)
  165. if err != nil {
  166. br.Msg = "新增晨报点评失败!"
  167. br.ErrMsg = "新增晨报点评失败,Err:" + err.Error()
  168. return
  169. }
  170. for _, req := range reqList.List {
  171. if req.ChartPermissionId <= 0 || req.ChartPermissionName == "" {
  172. br.Msg = "行业不可为空"
  173. br.ErrMsg = "行业不可为空"
  174. return
  175. }
  176. if req.IndustryId <= 0 || req.ChartPermissionName == "" {
  177. br.Msg = "产业不可为空"
  178. br.ErrMsg = "产业不可为空"
  179. return
  180. }
  181. // 标的ID校验
  182. industrialSubjectIds := req.IndustrialSubjectIds
  183. if industrialSubjectIds != "" {
  184. industrialSubjectIdList := strings.Split(industrialSubjectIds, ",")
  185. for _, v := range industrialSubjectIdList {
  186. _, err := strconv.Atoi(v)
  187. if err != nil {
  188. br.Msg = "参数解析异常!"
  189. br.ErrMsg = "标的ID不规范,Err:" + err.Error() + industrialSubjectIds
  190. return
  191. }
  192. }
  193. }
  194. //解析报告链接中的ID
  195. var linkArticleId int
  196. if req.ReportLink != "" {
  197. linkArticleId, err = cygxService.GetReportLinkToArticleid(req.ReportLink)
  198. if err != nil {
  199. br.Msg = "操作失败"
  200. br.ErrMsg = "解析报告链接ID失败,Err:" + err.Error()
  201. return
  202. }
  203. }
  204. item := cygx.CygxMorningMeetingReviewChapter{
  205. MeetingTime: meetingTime,
  206. CreateTime: time.Now(),
  207. ModifyTime: time.Now(),
  208. IndustryId: req.IndustryId,
  209. IndustryName: req.IndustryName,
  210. ChartPermissionName: req.ChartPermissionName,
  211. ChartPermissionId: req.ChartPermissionId,
  212. IndustrialSubjectIds: req.IndustrialSubjectIds,
  213. MeetingId: meetingId,
  214. Content: req.Content,
  215. ReportLink: req.ReportLink,
  216. LinkArticleId: linkArticleId,
  217. Title: req.Title,
  218. }
  219. err := cygx.AddCygxMorningMeetingReviewChapter(&item)
  220. if err != nil {
  221. br.Msg = "新增晨报点评章节失败!"
  222. br.ErrMsg = "新增晨报点评章节失败,Err:" + err.Error()
  223. return
  224. }
  225. go cygxService.GetIndustrialManagementArticleNewPublishData(req.IndustryId)
  226. }
  227. br.Ret = 200
  228. br.Success = true
  229. if reqList.DoType == 0 {
  230. br.Msg = "保存成功"
  231. br.Data = meetingId
  232. } else {
  233. for _, item := range reqList.List {
  234. go services.SendWxMsgWithCygxMorningMeeting(int(meetingId), item.IndustryId, item.IndustryName)
  235. }
  236. //添加到首页最新
  237. listchapter, err := cygx.GetCygxMorningMeetingReviewsListById(int(meetingId))
  238. if err != nil {
  239. br.Msg = "获取失败"
  240. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  241. return
  242. }
  243. for _, itemchapter := range listchapter {
  244. //go cygxService.UpdateResourceData(itemchapter.Id, "meetingreviewchapt", "add", time.Now().Format(utils.FormatDateTime))
  245. go cygxService.UpdateMeetingreviewchaptResourceData(itemchapter.Id) //写入首页最新 cygx_resource_data 表
  246. go elastic.AddComprehensiveMeetingreviewchapt(itemchapter.Id) //Es添加晨会精华
  247. }
  248. br.Msg = "发布成功"
  249. br.Data = meetingId
  250. }
  251. } else {
  252. //更新
  253. reviewInfo, err := cygx.GetMorningMeetingReviewById(reqList.MeetingId)
  254. if err != nil {
  255. err = errors.New("报告信息有误, Err: " + err.Error())
  256. return
  257. }
  258. if reviewInfo == nil {
  259. br.Msg = "文章不存在"
  260. return
  261. }
  262. reviewItem := cygx.CygxMorningMeetingReviews{
  263. Id: reqList.MeetingId,
  264. MeetingTime: meetingTime,
  265. ModifyTime: time.Now(),
  266. PartNums: len(reqList.List),
  267. IndustryNames: industryNames,
  268. }
  269. if reqList.DoType == 1 {
  270. reviewItem.PublishTime = time.Now()
  271. reviewItem.Status = 1
  272. } else {
  273. reviewItem.PublishTime = reviewInfo.PublishTime
  274. reviewItem.Status = reviewInfo.Status
  275. }
  276. err = cygx.UpdateCygxMorningMeetingReviews(&reviewItem)
  277. if err != nil {
  278. br.Msg = "更新晨报点评失败!"
  279. br.ErrMsg = "更新晨报点评失败,Err:" + err.Error()
  280. return
  281. }
  282. if reviewInfo.PartNums > len(reqList.List) {
  283. //有删除
  284. chapterList, err := cygx.GetCygxMorningMeetingReviewsListById(reqList.MeetingId)
  285. if err != nil {
  286. br.Msg = "获取失败"
  287. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  288. return
  289. }
  290. chapterIdMap := make(map[int]int, 0)
  291. for _, chapter := range reqList.List {
  292. chapterIdMap[chapter.ChapterId] = chapter.ChapterId
  293. }
  294. for _, item := range chapterList {
  295. if _, ok := chapterIdMap[item.Id]; !ok {
  296. //删除该id
  297. err := cygx.DeleteMorningMeetingChapterById(item.Id)
  298. if err != nil {
  299. br.Msg = "删除失败"
  300. br.ErrMsg = "删除章节失败,Err:" + err.Error()
  301. return
  302. }
  303. go elastic.DeleteComprehensiveMeetingreviewchapt(item.Id) //Es删除晨会精华
  304. }
  305. }
  306. }
  307. for _, req := range reqList.List {
  308. if req.ChartPermissionId <= 0 || req.ChartPermissionName == "" {
  309. br.Msg = "行业不可为空"
  310. br.ErrMsg = "行业不可为空"
  311. return
  312. }
  313. if req.IndustryId <= 0 || req.ChartPermissionName == "" {
  314. br.Msg = "产业不可为空"
  315. br.ErrMsg = "产业不可为空"
  316. return
  317. }
  318. // 标的ID校验
  319. industrialSubjectIds := req.IndustrialSubjectIds
  320. if industrialSubjectIds != "" {
  321. industrialSubjectIdList := strings.Split(industrialSubjectIds, ",")
  322. for _, v := range industrialSubjectIdList {
  323. _, err := strconv.Atoi(v)
  324. if err != nil {
  325. br.Msg = "参数解析异常!"
  326. br.ErrMsg = "标的ID不规范,Err:" + err.Error() + industrialSubjectIds
  327. return
  328. }
  329. }
  330. }
  331. //解析报告链接中的ID
  332. var linkArticleId int
  333. if req.ReportLink != "" {
  334. linkArticleId, err = cygxService.GetReportLinkToArticleid(req.ReportLink)
  335. if err != nil {
  336. br.Msg = "操作失败"
  337. br.ErrMsg = "解析报告链接ID失败,Err:" + err.Error()
  338. return
  339. }
  340. }
  341. //有可能在编辑时新增了段落
  342. if req.ChapterId == 0 {
  343. item := cygx.CygxMorningMeetingReviewChapter{
  344. MeetingTime: meetingTime,
  345. CreateTime: time.Now(),
  346. ModifyTime: time.Now(),
  347. IndustryId: req.IndustryId,
  348. IndustryName: req.IndustryName,
  349. ChartPermissionName: req.ChartPermissionName,
  350. ChartPermissionId: req.ChartPermissionId,
  351. IndustrialSubjectIds: req.IndustrialSubjectIds,
  352. MeetingId: int64(reqList.MeetingId),
  353. Content: req.Content,
  354. ReportLink: req.ReportLink,
  355. LinkArticleId: linkArticleId,
  356. Title: req.Title,
  357. }
  358. err := cygx.AddCygxMorningMeetingReviewChapter(&item)
  359. if err != nil {
  360. br.Msg = "新增晨报点评章节失败!"
  361. br.ErrMsg = "新增晨报点评章节失败,Err:" + err.Error()
  362. return
  363. }
  364. } else {
  365. item := cygx.CygxMorningMeetingReviewChapter{
  366. Id: req.ChapterId,
  367. MeetingTime: meetingTime,
  368. ModifyTime: time.Now(),
  369. IndustryId: req.IndustryId,
  370. IndustryName: req.IndustryName,
  371. ChartPermissionName: req.ChartPermissionName,
  372. ChartPermissionId: req.ChartPermissionId,
  373. IndustrialSubjectIds: req.IndustrialSubjectIds,
  374. MeetingId: int64(reqList.MeetingId),
  375. Content: req.Content,
  376. ReportLink: req.ReportLink,
  377. LinkArticleId: linkArticleId,
  378. Title: req.Title,
  379. }
  380. err := cygx.UpdateCygxMorningMeetingReviewChapter(&item)
  381. if err != nil {
  382. br.Msg = "编辑晨报点评章节失败!"
  383. br.ErrMsg = "编辑晨报点评章节失败,Err:" + err.Error()
  384. return
  385. }
  386. }
  387. go cygxService.GetIndustrialManagementArticleNewPublishData(req.IndustryId)
  388. }
  389. for _, item := range reqList.List {
  390. // 更新产业布局时间 2023-05-22
  391. var industryIds []int
  392. industryIds = append(industryIds, item.IndustryId)
  393. go cygxService.UpdateIndustryLayoutTime(industryIds, false)
  394. }
  395. //添加到首页最新
  396. listchapter, err := cygx.GetCygxMorningMeetingReviewsListById(reqList.MeetingId)
  397. if err != nil {
  398. br.Msg = "获取失败"
  399. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  400. return
  401. }
  402. for _, itemchapter := range listchapter {
  403. go elastic.AddComprehensiveMeetingreviewchapt(itemchapter.Id) //Es添加晨会精华
  404. }
  405. br.Ret = 200
  406. br.Success = true
  407. if reqList.DoType == 0 {
  408. br.Msg = "保存成功"
  409. } else {
  410. for _, item := range reqList.List {
  411. go services.SendWxMsgWithCygxMorningMeeting(reqList.MeetingId, item.IndustryId, item.IndustryName)
  412. }
  413. for _, itemchapter := range listchapter {
  414. //go cygxService.UpdateResourceData(itemchapter.Id, "meetingreviewchapt", "add", time.Now().Format(utils.FormatDateTime))
  415. go cygxService.UpdateMeetingreviewchaptResourceData(itemchapter.Id) //写入首页最新 cygx_resource_data 表
  416. }
  417. br.Msg = "发布成功"
  418. }
  419. }
  420. }
  421. // @Title 晨会点评列表
  422. // @Description 活动客户列表接口
  423. // @Param MeetingId query int true "晨会点评id"
  424. // @Success 200 {object} cygx.ActivityCcustomerTypeList
  425. // @router /morningMeeting/detail [get]
  426. func (this *MorningMeetingController) Detail() {
  427. br := new(models.BaseResponse).Init()
  428. defer func() {
  429. this.Data["json"] = br
  430. this.ServeJSON()
  431. }()
  432. sysUser := this.SysUser
  433. if sysUser == nil {
  434. br.Msg = "请登录"
  435. br.ErrMsg = "请登录,SysUser Is Empty"
  436. br.Ret = 408
  437. return
  438. }
  439. meetingId, _ := this.GetInt("MeetingId")
  440. if meetingId <= 0 {
  441. br.Msg = "参数错误"
  442. br.ErrMsg = "晨会点评id有误!"
  443. return
  444. }
  445. list, err := cygx.GetCygxMorningMeetingReviewsListById(meetingId)
  446. if err != nil {
  447. br.Msg = "获取失败"
  448. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  449. return
  450. }
  451. reviewItem, err := cygx.GetMorningMeetingReviewById(meetingId)
  452. if err != nil {
  453. br.Msg = "获取失败"
  454. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  455. return
  456. }
  457. var resp cygx.CygxMorningMeetingReviewChapterResp
  458. var meetingTime string
  459. for _, chapter := range list {
  460. var subjectItemList []*cygx.IndustrialSubjectItem
  461. if chapter.IndustrialSubjectIds != "" {
  462. subjectList, err := cygx.GetIndustrySubjectListByIds(chapter.IndustrialSubjectIds)
  463. if err != nil {
  464. br.Msg = "获取失败"
  465. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  466. return
  467. }
  468. for _, subject := range subjectList {
  469. subjectItem := cygx.IndustrialSubjectItem{
  470. IndustrialSubjectId: subject.IndustrialSubjectId,
  471. SubjectName: subject.SubjectName,
  472. }
  473. subjectItemList = append(subjectItemList, &subjectItem)
  474. }
  475. }
  476. meetingTime = chapter.MeetingTime.Local().Format(utils.FormatDate)
  477. respItem := cygx.CygxMorningMeetingReviewChapterRespItem{
  478. Id: chapter.Id,
  479. MeetingTime: chapter.MeetingTime,
  480. CreateTime: chapter.CreateTime,
  481. ModifyTime: chapter.ModifyTime,
  482. IndustryId: chapter.IndustryId,
  483. IndustryName: chapter.IndustryName,
  484. ChartPermissionName: chapter.ChartPermissionName,
  485. ChartPermissionId: chapter.ChartPermissionId,
  486. IndustrialSubjectList: subjectItemList,
  487. MeetingId: chapter.MeetingId,
  488. Content: chapter.Content,
  489. Title: chapter.Title,
  490. ReportLink: chapter.ReportLink,
  491. }
  492. resp.List = append(resp.List, &respItem)
  493. }
  494. resp.MeetingTime = meetingTime
  495. resp.Status = reviewItem.Status
  496. br.Ret = 200
  497. br.Success = true
  498. br.Msg = "获取成功"
  499. br.Data = resp
  500. }
  501. // @Title 发布报告接口
  502. // @Description 发布报告
  503. // @Param request body cygx.MorningReviewPublishReq true "type json string"
  504. // @Success 200 Ret=200 发布成功
  505. // @router /morningMeeting/publish [post]
  506. func (this *MorningMeetingController) PublishReport() {
  507. br := new(models.BaseResponse).Init()
  508. defer func() {
  509. this.Data["json"] = br
  510. this.ServeJSON()
  511. }()
  512. var req cygx.MorningReviewPublishReq
  513. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  514. if err != nil {
  515. br.Msg = "参数解析异常!"
  516. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  517. return
  518. }
  519. reviewIds := req.ReviewIds
  520. if reviewIds == "" {
  521. br.Msg = "参数错误"
  522. br.ErrMsg = "参数错误,报告id不可为空"
  523. return
  524. }
  525. reviewArr := strings.Split(reviewIds, ",")
  526. for _, v := range reviewArr {
  527. vint, err := strconv.Atoi(v)
  528. if err != nil {
  529. br.Msg = "参数错误"
  530. br.ErrMsg = "参数错误,Err:" + err.Error()
  531. return
  532. }
  533. review, err := cygx.GetMorningMeetingReviewById(vint)
  534. if err != nil {
  535. br.Msg = "获取晨会点评信息失败"
  536. br.ErrMsg = "获取晨会点评信息失败,Err:" + err.Error()
  537. return
  538. }
  539. if review == nil {
  540. br.Msg = "晨会点评不存在"
  541. return
  542. }
  543. var tmpErr error
  544. if tmpErr = cygx.PublishMorningMeetingReviewById(review.Id); tmpErr != nil {
  545. br.Msg = "晨会点评发布失败"
  546. br.ErrMsg = "晨会点评发布失败, Err:" + tmpErr.Error() + ", review_id:" + strconv.Itoa(review.Id)
  547. return
  548. }
  549. list, err := cygx.GetCygxMorningMeetingReviewsListById(vint)
  550. if err != nil {
  551. br.Msg = "获取失败"
  552. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  553. return
  554. }
  555. for _, item := range list {
  556. fmt.Println(item.Id)
  557. go services.SendWxMsgWithCygxMorningMeeting(vint, item.IndustryId, item.IndustryName)
  558. //go cygxService.UpdateResourceData(item.Id, "meetingreviewchapt", "add", time.Now().Format(utils.FormatDateTime))
  559. go cygxService.UpdateMeetingreviewchaptResourceData(item.Id) //写入首页最新 cygx_resource_data 表
  560. go elastic.AddComprehensiveMeetingreviewchapt(item.Id) //Es添加晨会精华
  561. }
  562. }
  563. br.Ret = 200
  564. br.Success = true
  565. br.Msg = "发布成功"
  566. }
  567. // @Title 取消发布报告接口
  568. // @Description 取消发布报告
  569. // @Param request body cygx.MorningReviewPublishCancelReq true "type json string"
  570. // @Success 200 Ret=200 取消发布成功
  571. // @router /morningMeeting/publish/cancel [post]
  572. func (this *MorningMeetingController) PublishCancleReport() {
  573. br := new(models.BaseResponse).Init()
  574. defer func() {
  575. this.Data["json"] = br
  576. this.ServeJSON()
  577. }()
  578. var req cygx.MorningReviewPublishCancelReq
  579. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  580. if err != nil {
  581. br.Msg = "参数解析异常!"
  582. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  583. return
  584. }
  585. if req.ReviewId <= 0 {
  586. br.Msg = "参数错误"
  587. br.ErrMsg = "参数错误,晨会id不可为空"
  588. return
  589. }
  590. err = cygx.PublishCancelMorningMeetingReview(req.ReviewId)
  591. if err != nil {
  592. br.Msg = "取消发布失败"
  593. br.ErrMsg = "取消发布失败,Err:" + err.Error()
  594. return
  595. }
  596. list, err := cygx.GetCygxMorningMeetingReviewsListById(req.ReviewId)
  597. if err != nil {
  598. br.Msg = "获取失败"
  599. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  600. return
  601. }
  602. for _, item := range list {
  603. //go cygxService.UpdateResourceData(item.Id, "meetingreviewchapt", "delete", time.Now().Format(utils.FormatDateTime))
  604. go cygxService.UpdateMeetingreviewchaptResourceData(item.Id) //写入首页最新 cygx_resource_data 表
  605. go elastic.DeleteComprehensiveMeetingreviewchapt(item.Id) //Es删除晨会精华
  606. }
  607. var condition string
  608. var pars []interface{}
  609. condition += ` AND meeting_ids like '%` + strconv.Itoa(req.ReviewId) + `%' `
  610. listMeetingGather, err := cygx.GetCygxMorningMeetingGatherList(condition, pars, 0, 9999)
  611. if err != nil && err.Error() != utils.ErrNoRow() {
  612. br.Msg = "获取失败"
  613. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  614. return
  615. }
  616. if len(listMeetingGather) > 0 {
  617. var meetingGatherId int
  618. //var middelete string
  619. var meetingsliceId []string
  620. for _, v := range listMeetingGather {
  621. sliceId := strings.Split(v.MeetingIds, ",")
  622. for _, mid := range sliceId {
  623. if mid == strconv.Itoa(req.ReviewId) {
  624. meetingGatherId = v.Id
  625. meetingsliceId = sliceId
  626. }
  627. }
  628. }
  629. var newMeetingIds string
  630. if meetingGatherId > 0 {
  631. for _, v := range meetingsliceId {
  632. if strconv.Itoa(req.ReviewId) == v {
  633. continue
  634. }
  635. newMeetingIds += v + ","
  636. }
  637. newMeetingIds = strings.TrimRight(newMeetingIds, ",")
  638. err = cygx.UpdateCygxMorningMeetingGather(newMeetingIds, meetingGatherId)
  639. if err != nil {
  640. br.Msg = "取消发布失败"
  641. br.ErrMsg = "取消发布失败,Err:" + err.Error()
  642. return
  643. }
  644. }
  645. }
  646. br.Ret = 200
  647. br.Success = true
  648. br.Msg = "取消发布成功"
  649. }
  650. // @Title 删除报告接口
  651. // @Description 删除报告
  652. // @Param request body cygx.MorningReviewDeleteReq true "type json string"
  653. // @Success 200 Ret=200 删除成功
  654. // @router /morningMeeting/delete [post]
  655. func (this *MorningMeetingController) Delete() {
  656. br := new(models.BaseResponse).Init()
  657. defer func() {
  658. this.Data["json"] = br
  659. this.ServeJSON()
  660. }()
  661. var req cygx.MorningReviewDeleteReq
  662. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  663. if err != nil {
  664. br.Msg = "参数解析异常!"
  665. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  666. return
  667. }
  668. if req.ReviewId <= 0 {
  669. br.Msg = "参数错误"
  670. br.ErrMsg = "参数错误,报告id不可为空"
  671. return
  672. }
  673. if err := cygx.DeleteMorningReviewAndChapter(req.ReviewId); err != nil {
  674. br.Msg = "删除失败"
  675. br.ErrMsg = "删除报告失败, Err: " + err.Error()
  676. return
  677. }
  678. br.Ret = 200
  679. br.Success = true
  680. br.Msg = "删除成功"
  681. }
  682. // @Title 下载PV
  683. // @Description 下载PV接口
  684. // @Param MeetingId query int true "晨会点评id"
  685. // @Param IsExport query bool false "是否导出excel,默认是false"
  686. // @router /morningMeeting/list_pv [get]
  687. func (this *MorningMeetingController) ListPv() {
  688. br := new(models.BaseResponse).Init()
  689. defer func() {
  690. this.Data["json"] = br
  691. this.ServeJSON()
  692. }()
  693. AdminUser := this.SysUser
  694. if AdminUser == nil {
  695. br.Msg = "请登录"
  696. br.ErrMsg = "请登录,用户信息为空"
  697. br.Ret = 408
  698. return
  699. }
  700. meetingId, _ := this.GetInt("MeetingId")
  701. if meetingId < 1 {
  702. br.Msg = "请输入晨会ID"
  703. return
  704. }
  705. //是否导出报表
  706. isExport, _ := this.GetBool("IsExport")
  707. var condition string
  708. var pars []interface{}
  709. condition = ` AND meeting_id = ? ORDER BY id DESC `
  710. pars = append(pars, meetingId)
  711. var respList []*cygx.CygxMorningMeetingReviewChapterHistoryResp
  712. list, err := cygx.GetCygxMorningMeetingReviewChapterHistoryList(condition, pars)
  713. if err != nil {
  714. br.Msg = "获取失败"
  715. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  716. return
  717. }
  718. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  719. var isCanDownload bool
  720. adminInfo, errAdmin := system.GetSysUserById(AdminUser.AdminId)
  721. if errAdmin != nil {
  722. br.Msg = "获取失败"
  723. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  724. return
  725. }
  726. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  727. isCanDownload = true
  728. }
  729. //销售查看自己客户,销售组长查看组员
  730. if isCanDownload == false {
  731. mapMobile, err := cygxService.GetAdminLookUserMobile(adminInfo)
  732. if err != nil {
  733. br.Msg = "获取失败"
  734. br.ErrMsg = "获取失败,销售对应权限,Err:" + err.Error()
  735. return
  736. }
  737. for _, v := range list {
  738. if _, ok := mapMobile[v.Mobile]; ok {
  739. respList = append(respList, v)
  740. }
  741. }
  742. } else {
  743. respList = list
  744. }
  745. resp := cygx.CygxMorningMeetingReviewChapterHistoryResptListResp{
  746. List: list,
  747. }
  748. //导出excel
  749. if isExport {
  750. MorningMeetingHistoryListExport(this, resp, br)
  751. return
  752. }
  753. br.Ret = 200
  754. br.Success = true
  755. br.Msg = "获取成功"
  756. br.Data = resp
  757. }
  758. // MorningMeetingHistoryListExport 导出Excel
  759. func MorningMeetingHistoryListExport(this *MorningMeetingController, resp cygx.CygxMorningMeetingReviewChapterHistoryResptListResp, br *models.BaseResponse) {
  760. //创建excel
  761. dir, err := os.Executable()
  762. exPath := filepath.Dir(dir)
  763. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  764. xlsxFile := xlsx.NewFile()
  765. if err != nil {
  766. br.Msg = "生成文件失败"
  767. br.ErrMsg = "生成文件失败"
  768. return
  769. }
  770. style := xlsx.NewStyle()
  771. alignment := xlsx.Alignment{
  772. Horizontal: "center",
  773. Vertical: "center",
  774. WrapText: true,
  775. }
  776. style.Alignment = alignment
  777. style.ApplyAlignment = true
  778. sheet, err := xlsxFile.AddSheet("阅读明细")
  779. if err != nil {
  780. br.Msg = "新增Sheet失败"
  781. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  782. return
  783. }
  784. rowTitle := sheet.AddRow()
  785. cellA := rowTitle.AddCell()
  786. cellA.Value = "姓名"
  787. cellB := rowTitle.AddCell()
  788. cellB.Value = "手机号"
  789. cellC := rowTitle.AddCell()
  790. cellC.Value = "公司名称"
  791. cellD := rowTitle.AddCell()
  792. cellD.Value = "所属权益销售"
  793. cellE := rowTitle.AddCell()
  794. cellE.Value = "阅读时间"
  795. for _, item := range resp.List {
  796. row := sheet.AddRow()
  797. cellA := row.AddCell()
  798. cellA.Value = item.RealName
  799. cellB := row.AddCell()
  800. cellB.Value = item.Mobile
  801. cellC := row.AddCell()
  802. cellC.Value = item.CompanyName
  803. cellD := row.AddCell()
  804. cellD.Value = item.SellerName
  805. cellE := row.AddCell()
  806. cellE.Value = item.CreateTime
  807. }
  808. err = xlsxFile.Save(downLoadnFilePath)
  809. if err != nil {
  810. br.Msg = "保存文件失败"
  811. br.ErrMsg = "保存文件失败"
  812. return
  813. }
  814. downloadFileName := time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  815. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  816. defer func() {
  817. os.Remove(downLoadnFilePath)
  818. }()
  819. br.Ret = 200
  820. br.Success = true
  821. br.Msg = "导出成功"
  822. }