morning_meeting_review.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  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. go cygxService.UpdateIndustrialManagementTimeLineDateList3ByRedis(item.IndustryId) //处理产业管理时间线相关内容的数据
  236. }
  237. //添加到首页最新
  238. listchapter, err := cygx.GetCygxMorningMeetingReviewsListById(int(meetingId))
  239. if err != nil {
  240. br.Msg = "获取失败"
  241. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  242. return
  243. }
  244. for _, itemchapter := range listchapter {
  245. //go cygxService.UpdateResourceData(itemchapter.Id, "meetingreviewchapt", "add", time.Now().Format(utils.FormatDateTime))
  246. go cygxService.UpdateMeetingreviewchaptResourceData(itemchapter.Id) //写入首页最新 cygx_resource_data 表
  247. go elastic.AddComprehensiveMeetingreviewchapt(itemchapter.Id) //Es添加晨会精华
  248. }
  249. br.Msg = "发布成功"
  250. br.Data = meetingId
  251. }
  252. } else {
  253. //更新
  254. reviewInfo, err := cygx.GetMorningMeetingReviewById(reqList.MeetingId)
  255. if err != nil {
  256. err = errors.New("报告信息有误, Err: " + err.Error())
  257. return
  258. }
  259. if reviewInfo == nil {
  260. br.Msg = "文章不存在"
  261. return
  262. }
  263. reviewItem := cygx.CygxMorningMeetingReviews{
  264. Id: reqList.MeetingId,
  265. MeetingTime: meetingTime,
  266. ModifyTime: time.Now(),
  267. PartNums: len(reqList.List),
  268. IndustryNames: industryNames,
  269. }
  270. if reqList.DoType == 1 {
  271. reviewItem.PublishTime = time.Now()
  272. reviewItem.Status = 1
  273. } else {
  274. reviewItem.PublishTime = reviewInfo.PublishTime
  275. reviewItem.Status = reviewInfo.Status
  276. }
  277. err = cygx.UpdateCygxMorningMeetingReviews(&reviewItem)
  278. if err != nil {
  279. br.Msg = "更新晨报点评失败!"
  280. br.ErrMsg = "更新晨报点评失败,Err:" + err.Error()
  281. return
  282. }
  283. if reviewInfo.PartNums > len(reqList.List) {
  284. //有删除
  285. chapterList, err := cygx.GetCygxMorningMeetingReviewsListById(reqList.MeetingId)
  286. if err != nil {
  287. br.Msg = "获取失败"
  288. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  289. return
  290. }
  291. chapterIdMap := make(map[int]int, 0)
  292. for _, chapter := range reqList.List {
  293. chapterIdMap[chapter.ChapterId] = chapter.ChapterId
  294. }
  295. for _, item := range chapterList {
  296. if _, ok := chapterIdMap[item.Id]; !ok {
  297. //删除该id
  298. err := cygx.DeleteMorningMeetingChapterById(item.Id)
  299. if err != nil {
  300. br.Msg = "删除失败"
  301. br.ErrMsg = "删除章节失败,Err:" + err.Error()
  302. return
  303. }
  304. go elastic.DeleteComprehensiveMeetingreviewchapt(item.Id) //Es删除晨会精华
  305. }
  306. }
  307. }
  308. for _, req := range reqList.List {
  309. if req.ChartPermissionId <= 0 || req.ChartPermissionName == "" {
  310. br.Msg = "行业不可为空"
  311. br.ErrMsg = "行业不可为空"
  312. return
  313. }
  314. if req.IndustryId <= 0 || req.ChartPermissionName == "" {
  315. br.Msg = "产业不可为空"
  316. br.ErrMsg = "产业不可为空"
  317. return
  318. }
  319. // 标的ID校验
  320. industrialSubjectIds := req.IndustrialSubjectIds
  321. if industrialSubjectIds != "" {
  322. industrialSubjectIdList := strings.Split(industrialSubjectIds, ",")
  323. for _, v := range industrialSubjectIdList {
  324. _, err := strconv.Atoi(v)
  325. if err != nil {
  326. br.Msg = "参数解析异常!"
  327. br.ErrMsg = "标的ID不规范,Err:" + err.Error() + industrialSubjectIds
  328. return
  329. }
  330. }
  331. }
  332. //解析报告链接中的ID
  333. var linkArticleId int
  334. if req.ReportLink != "" {
  335. linkArticleId, err = cygxService.GetReportLinkToArticleid(req.ReportLink)
  336. if err != nil {
  337. br.Msg = "操作失败"
  338. br.ErrMsg = "解析报告链接ID失败,Err:" + err.Error()
  339. return
  340. }
  341. }
  342. //有可能在编辑时新增了段落
  343. if req.ChapterId == 0 {
  344. item := cygx.CygxMorningMeetingReviewChapter{
  345. MeetingTime: meetingTime,
  346. CreateTime: time.Now(),
  347. ModifyTime: time.Now(),
  348. IndustryId: req.IndustryId,
  349. IndustryName: req.IndustryName,
  350. ChartPermissionName: req.ChartPermissionName,
  351. ChartPermissionId: req.ChartPermissionId,
  352. IndustrialSubjectIds: req.IndustrialSubjectIds,
  353. MeetingId: int64(reqList.MeetingId),
  354. Content: req.Content,
  355. ReportLink: req.ReportLink,
  356. LinkArticleId: linkArticleId,
  357. Title: req.Title,
  358. }
  359. err := cygx.AddCygxMorningMeetingReviewChapter(&item)
  360. if err != nil {
  361. br.Msg = "新增晨报点评章节失败!"
  362. br.ErrMsg = "新增晨报点评章节失败,Err:" + err.Error()
  363. return
  364. }
  365. } else {
  366. item := cygx.CygxMorningMeetingReviewChapter{
  367. Id: req.ChapterId,
  368. MeetingTime: meetingTime,
  369. ModifyTime: time.Now(),
  370. IndustryId: req.IndustryId,
  371. IndustryName: req.IndustryName,
  372. ChartPermissionName: req.ChartPermissionName,
  373. ChartPermissionId: req.ChartPermissionId,
  374. IndustrialSubjectIds: req.IndustrialSubjectIds,
  375. MeetingId: int64(reqList.MeetingId),
  376. Content: req.Content,
  377. ReportLink: req.ReportLink,
  378. LinkArticleId: linkArticleId,
  379. Title: req.Title,
  380. }
  381. err := cygx.UpdateCygxMorningMeetingReviewChapter(&item)
  382. if err != nil {
  383. br.Msg = "编辑晨报点评章节失败!"
  384. br.ErrMsg = "编辑晨报点评章节失败,Err:" + err.Error()
  385. return
  386. }
  387. }
  388. go cygxService.GetIndustrialManagementArticleNewPublishData(req.IndustryId)
  389. }
  390. for _, item := range reqList.List {
  391. // 更新产业布局时间 2023-05-22
  392. var industryIds []int
  393. industryIds = append(industryIds, item.IndustryId)
  394. go cygxService.UpdateIndustryLayoutTime(industryIds, false)
  395. }
  396. //添加到首页最新
  397. listchapter, err := cygx.GetCygxMorningMeetingReviewsListById(reqList.MeetingId)
  398. if err != nil {
  399. br.Msg = "获取失败"
  400. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  401. return
  402. }
  403. for _, itemchapter := range listchapter {
  404. go elastic.AddComprehensiveMeetingreviewchapt(itemchapter.Id) //Es添加晨会精华
  405. }
  406. br.Ret = 200
  407. br.Success = true
  408. if reqList.DoType == 0 {
  409. br.Msg = "保存成功"
  410. } else {
  411. for _, item := range reqList.List {
  412. go services.SendWxMsgWithCygxMorningMeeting(reqList.MeetingId, item.IndustryId, item.IndustryName)
  413. go cygxService.UpdateIndustrialManagementTimeLineDateList3ByRedis(item.IndustryId) //处理产业管理时间线相关内容的数据
  414. }
  415. for _, itemchapter := range listchapter {
  416. //go cygxService.UpdateResourceData(itemchapter.Id, "meetingreviewchapt", "add", time.Now().Format(utils.FormatDateTime))
  417. go cygxService.UpdateMeetingreviewchaptResourceData(itemchapter.Id) //写入首页最新 cygx_resource_data 表
  418. }
  419. br.Msg = "发布成功"
  420. }
  421. }
  422. }
  423. // @Title 晨会点评列表
  424. // @Description 活动客户列表接口
  425. // @Param MeetingId query int true "晨会点评id"
  426. // @Success 200 {object} cygx.ActivityCcustomerTypeList
  427. // @router /morningMeeting/detail [get]
  428. func (this *MorningMeetingController) Detail() {
  429. br := new(models.BaseResponse).Init()
  430. defer func() {
  431. this.Data["json"] = br
  432. this.ServeJSON()
  433. }()
  434. sysUser := this.SysUser
  435. if sysUser == nil {
  436. br.Msg = "请登录"
  437. br.ErrMsg = "请登录,SysUser Is Empty"
  438. br.Ret = 408
  439. return
  440. }
  441. meetingId, _ := this.GetInt("MeetingId")
  442. if meetingId <= 0 {
  443. br.Msg = "参数错误"
  444. br.ErrMsg = "晨会点评id有误!"
  445. return
  446. }
  447. list, err := cygx.GetCygxMorningMeetingReviewsListById(meetingId)
  448. if err != nil {
  449. br.Msg = "获取失败"
  450. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  451. return
  452. }
  453. reviewItem, err := cygx.GetMorningMeetingReviewById(meetingId)
  454. if err != nil {
  455. br.Msg = "获取失败"
  456. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  457. return
  458. }
  459. var resp cygx.CygxMorningMeetingReviewChapterResp
  460. var meetingTime string
  461. for _, chapter := range list {
  462. var subjectItemList []*cygx.IndustrialSubjectItem
  463. if chapter.IndustrialSubjectIds != "" {
  464. subjectList, err := cygx.GetIndustrySubjectListByIds(chapter.IndustrialSubjectIds)
  465. if err != nil {
  466. br.Msg = "获取失败"
  467. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  468. return
  469. }
  470. for _, subject := range subjectList {
  471. subjectItem := cygx.IndustrialSubjectItem{
  472. IndustrialSubjectId: subject.IndustrialSubjectId,
  473. SubjectName: subject.SubjectName,
  474. }
  475. subjectItemList = append(subjectItemList, &subjectItem)
  476. }
  477. }
  478. meetingTime = chapter.MeetingTime.Local().Format(utils.FormatDate)
  479. respItem := cygx.CygxMorningMeetingReviewChapterRespItem{
  480. Id: chapter.Id,
  481. MeetingTime: chapter.MeetingTime,
  482. CreateTime: chapter.CreateTime,
  483. ModifyTime: chapter.ModifyTime,
  484. IndustryId: chapter.IndustryId,
  485. IndustryName: chapter.IndustryName,
  486. ChartPermissionName: chapter.ChartPermissionName,
  487. ChartPermissionId: chapter.ChartPermissionId,
  488. IndustrialSubjectList: subjectItemList,
  489. MeetingId: chapter.MeetingId,
  490. Content: chapter.Content,
  491. Title: chapter.Title,
  492. ReportLink: chapter.ReportLink,
  493. }
  494. resp.List = append(resp.List, &respItem)
  495. }
  496. resp.MeetingTime = meetingTime
  497. resp.Status = reviewItem.Status
  498. br.Ret = 200
  499. br.Success = true
  500. br.Msg = "获取成功"
  501. br.Data = resp
  502. }
  503. // @Title 发布报告接口
  504. // @Description 发布报告
  505. // @Param request body cygx.MorningReviewPublishReq true "type json string"
  506. // @Success 200 Ret=200 发布成功
  507. // @router /morningMeeting/publish [post]
  508. func (this *MorningMeetingController) PublishReport() {
  509. br := new(models.BaseResponse).Init()
  510. defer func() {
  511. this.Data["json"] = br
  512. this.ServeJSON()
  513. }()
  514. var req cygx.MorningReviewPublishReq
  515. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  516. if err != nil {
  517. br.Msg = "参数解析异常!"
  518. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  519. return
  520. }
  521. reviewIds := req.ReviewIds
  522. if reviewIds == "" {
  523. br.Msg = "参数错误"
  524. br.ErrMsg = "参数错误,报告id不可为空"
  525. return
  526. }
  527. reviewArr := strings.Split(reviewIds, ",")
  528. for _, v := range reviewArr {
  529. vint, err := strconv.Atoi(v)
  530. if err != nil {
  531. br.Msg = "参数错误"
  532. br.ErrMsg = "参数错误,Err:" + err.Error()
  533. return
  534. }
  535. review, err := cygx.GetMorningMeetingReviewById(vint)
  536. if err != nil {
  537. br.Msg = "获取晨会点评信息失败"
  538. br.ErrMsg = "获取晨会点评信息失败,Err:" + err.Error()
  539. return
  540. }
  541. if review == nil {
  542. br.Msg = "晨会点评不存在"
  543. return
  544. }
  545. var tmpErr error
  546. if tmpErr = cygx.PublishMorningMeetingReviewById(review.Id); tmpErr != nil {
  547. br.Msg = "晨会点评发布失败"
  548. br.ErrMsg = "晨会点评发布失败, Err:" + tmpErr.Error() + ", review_id:" + strconv.Itoa(review.Id)
  549. return
  550. }
  551. list, err := cygx.GetCygxMorningMeetingReviewsListById(vint)
  552. if err != nil {
  553. br.Msg = "获取失败"
  554. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  555. return
  556. }
  557. for _, item := range list {
  558. fmt.Println(item.Id)
  559. go services.SendWxMsgWithCygxMorningMeeting(vint, item.IndustryId, item.IndustryName)
  560. go cygxService.UpdateIndustrialManagementTimeLineDateList3ByRedis(item.IndustryId) //处理产业管理时间线相关内容的数据
  561. //go cygxService.UpdateResourceData(item.Id, "meetingreviewchapt", "add", time.Now().Format(utils.FormatDateTime))
  562. go cygxService.UpdateMeetingreviewchaptResourceData(item.Id) //写入首页最新 cygx_resource_data 表
  563. go elastic.AddComprehensiveMeetingreviewchapt(item.Id) //Es添加晨会精华
  564. }
  565. }
  566. br.Ret = 200
  567. br.Success = true
  568. br.Msg = "发布成功"
  569. }
  570. // @Title 取消发布报告接口
  571. // @Description 取消发布报告
  572. // @Param request body cygx.MorningReviewPublishCancelReq true "type json string"
  573. // @Success 200 Ret=200 取消发布成功
  574. // @router /morningMeeting/publish/cancel [post]
  575. func (this *MorningMeetingController) PublishCancleReport() {
  576. br := new(models.BaseResponse).Init()
  577. defer func() {
  578. this.Data["json"] = br
  579. this.ServeJSON()
  580. }()
  581. var req cygx.MorningReviewPublishCancelReq
  582. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  583. if err != nil {
  584. br.Msg = "参数解析异常!"
  585. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  586. return
  587. }
  588. if req.ReviewId <= 0 {
  589. br.Msg = "参数错误"
  590. br.ErrMsg = "参数错误,晨会id不可为空"
  591. return
  592. }
  593. err = cygx.PublishCancelMorningMeetingReview(req.ReviewId)
  594. if err != nil {
  595. br.Msg = "取消发布失败"
  596. br.ErrMsg = "取消发布失败,Err:" + err.Error()
  597. return
  598. }
  599. list, err := cygx.GetCygxMorningMeetingReviewsListById(req.ReviewId)
  600. if err != nil {
  601. br.Msg = "获取失败"
  602. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  603. return
  604. }
  605. for _, item := range list {
  606. //go cygxService.UpdateResourceData(item.Id, "meetingreviewchapt", "delete", time.Now().Format(utils.FormatDateTime))
  607. go cygxService.UpdateMeetingreviewchaptResourceData(item.Id) //写入首页最新 cygx_resource_data 表
  608. go elastic.DeleteComprehensiveMeetingreviewchapt(item.Id) //Es删除晨会精华
  609. go cygxService.UpdateIndustrialManagementTimeLineDateList3ByRedis(item.IndustryId) //处理产业管理时间线相关内容的数据
  610. }
  611. var condition string
  612. var pars []interface{}
  613. condition += ` AND meeting_ids like '%` + strconv.Itoa(req.ReviewId) + `%' `
  614. listMeetingGather, err := cygx.GetCygxMorningMeetingGatherList(condition, pars, 0, 9999)
  615. if err != nil && err.Error() != utils.ErrNoRow() {
  616. br.Msg = "获取失败"
  617. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  618. return
  619. }
  620. if len(listMeetingGather) > 0 {
  621. var meetingGatherId int
  622. //var middelete string
  623. var meetingsliceId []string
  624. for _, v := range listMeetingGather {
  625. sliceId := strings.Split(v.MeetingIds, ",")
  626. for _, mid := range sliceId {
  627. if mid == strconv.Itoa(req.ReviewId) {
  628. meetingGatherId = v.Id
  629. meetingsliceId = sliceId
  630. }
  631. }
  632. }
  633. var newMeetingIds string
  634. if meetingGatherId > 0 {
  635. for _, v := range meetingsliceId {
  636. if strconv.Itoa(req.ReviewId) == v {
  637. continue
  638. }
  639. newMeetingIds += v + ","
  640. }
  641. newMeetingIds = strings.TrimRight(newMeetingIds, ",")
  642. err = cygx.UpdateCygxMorningMeetingGather(newMeetingIds, meetingGatherId)
  643. if err != nil {
  644. br.Msg = "取消发布失败"
  645. br.ErrMsg = "取消发布失败,Err:" + err.Error()
  646. return
  647. }
  648. }
  649. }
  650. br.Ret = 200
  651. br.Success = true
  652. br.Msg = "取消发布成功"
  653. }
  654. // @Title 删除报告接口
  655. // @Description 删除报告
  656. // @Param request body cygx.MorningReviewDeleteReq true "type json string"
  657. // @Success 200 Ret=200 删除成功
  658. // @router /morningMeeting/delete [post]
  659. func (this *MorningMeetingController) Delete() {
  660. br := new(models.BaseResponse).Init()
  661. defer func() {
  662. this.Data["json"] = br
  663. this.ServeJSON()
  664. }()
  665. var req cygx.MorningReviewDeleteReq
  666. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  667. if err != nil {
  668. br.Msg = "参数解析异常!"
  669. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  670. return
  671. }
  672. if req.ReviewId <= 0 {
  673. br.Msg = "参数错误"
  674. br.ErrMsg = "参数错误,报告id不可为空"
  675. return
  676. }
  677. if err := cygx.DeleteMorningReviewAndChapter(req.ReviewId); err != nil {
  678. br.Msg = "删除失败"
  679. br.ErrMsg = "删除报告失败, Err: " + err.Error()
  680. return
  681. }
  682. br.Ret = 200
  683. br.Success = true
  684. br.Msg = "删除成功"
  685. }
  686. // @Title 下载PV
  687. // @Description 下载PV接口
  688. // @Param MeetingId query int true "晨会点评id"
  689. // @Param IsExport query bool false "是否导出excel,默认是false"
  690. // @router /morningMeeting/list_pv [get]
  691. func (this *MorningMeetingController) ListPv() {
  692. br := new(models.BaseResponse).Init()
  693. defer func() {
  694. this.Data["json"] = br
  695. this.ServeJSON()
  696. }()
  697. AdminUser := this.SysUser
  698. if AdminUser == nil {
  699. br.Msg = "请登录"
  700. br.ErrMsg = "请登录,用户信息为空"
  701. br.Ret = 408
  702. return
  703. }
  704. meetingId, _ := this.GetInt("MeetingId")
  705. if meetingId < 1 {
  706. br.Msg = "请输入晨会ID"
  707. return
  708. }
  709. //是否导出报表
  710. isExport, _ := this.GetBool("IsExport")
  711. var condition string
  712. var pars []interface{}
  713. condition = ` AND meeting_id = ? ORDER BY id DESC `
  714. pars = append(pars, meetingId)
  715. var respList []*cygx.CygxMorningMeetingReviewChapterHistoryResp
  716. list, err := cygx.GetCygxMorningMeetingReviewChapterHistoryList(condition, pars)
  717. if err != nil {
  718. br.Msg = "获取失败"
  719. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  720. return
  721. }
  722. //超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
  723. var isCanDownload bool
  724. adminInfo, errAdmin := system.GetSysUserById(AdminUser.AdminId)
  725. if errAdmin != nil {
  726. br.Msg = "获取失败"
  727. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  728. return
  729. }
  730. if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
  731. isCanDownload = true
  732. }
  733. //销售查看自己客户,销售组长查看组员
  734. if isCanDownload == false {
  735. mapMobile, err := cygxService.GetAdminLookUserMobile(adminInfo)
  736. if err != nil {
  737. br.Msg = "获取失败"
  738. br.ErrMsg = "获取失败,销售对应权限,Err:" + err.Error()
  739. return
  740. }
  741. for _, v := range list {
  742. if _, ok := mapMobile[v.Mobile]; ok {
  743. respList = append(respList, v)
  744. }
  745. }
  746. } else {
  747. respList = list
  748. }
  749. resp := cygx.CygxMorningMeetingReviewChapterHistoryResptListResp{
  750. List: list,
  751. }
  752. //导出excel
  753. if isExport {
  754. MorningMeetingHistoryListExport(this, resp, br)
  755. return
  756. }
  757. br.Ret = 200
  758. br.Success = true
  759. br.Msg = "获取成功"
  760. br.Data = resp
  761. }
  762. // MorningMeetingHistoryListExport 导出Excel
  763. func MorningMeetingHistoryListExport(this *MorningMeetingController, resp cygx.CygxMorningMeetingReviewChapterHistoryResptListResp, br *models.BaseResponse) {
  764. //创建excel
  765. dir, err := os.Executable()
  766. exPath := filepath.Dir(dir)
  767. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  768. xlsxFile := xlsx.NewFile()
  769. if err != nil {
  770. br.Msg = "生成文件失败"
  771. br.ErrMsg = "生成文件失败"
  772. return
  773. }
  774. style := xlsx.NewStyle()
  775. alignment := xlsx.Alignment{
  776. Horizontal: "center",
  777. Vertical: "center",
  778. WrapText: true,
  779. }
  780. style.Alignment = alignment
  781. style.ApplyAlignment = true
  782. sheet, err := xlsxFile.AddSheet("阅读明细")
  783. if err != nil {
  784. br.Msg = "新增Sheet失败"
  785. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  786. return
  787. }
  788. rowTitle := sheet.AddRow()
  789. cellA := rowTitle.AddCell()
  790. cellA.Value = "姓名"
  791. cellB := rowTitle.AddCell()
  792. cellB.Value = "手机号"
  793. cellC := rowTitle.AddCell()
  794. cellC.Value = "公司名称"
  795. cellD := rowTitle.AddCell()
  796. cellD.Value = "所属权益销售"
  797. cellE := rowTitle.AddCell()
  798. cellE.Value = "阅读时间"
  799. for _, item := range resp.List {
  800. row := sheet.AddRow()
  801. cellA := row.AddCell()
  802. cellA.Value = item.RealName
  803. cellB := row.AddCell()
  804. cellB.Value = item.Mobile
  805. cellC := row.AddCell()
  806. cellC.Value = item.CompanyName
  807. cellD := row.AddCell()
  808. cellD.Value = item.SellerName
  809. cellE := row.AddCell()
  810. cellE.Value = item.CreateTime
  811. }
  812. err = xlsxFile.Save(downLoadnFilePath)
  813. if err != nil {
  814. br.Msg = "保存文件失败"
  815. br.ErrMsg = "保存文件失败"
  816. return
  817. }
  818. downloadFileName := time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  819. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  820. defer func() {
  821. os.Remove(downLoadnFilePath)
  822. }()
  823. br.Ret = 200
  824. br.Success = true
  825. br.Msg = "导出成功"
  826. }