industrial_subject.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "hongze/hz_crm_api/controllers"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/cygx"
  7. "hongze/hz_crm_api/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. // 标的管理
  13. type IndustrialSubjectController struct {
  14. controllers.BaseAuthController
  15. }
  16. // @Title 添加标的
  17. // @Description 添加标的接口
  18. // @Param request body cygx.IndustrialSubjectAdd true "type json string"
  19. // @Success Ret=200 添加标的成功 {object} cygx.NewId
  20. // @router /industrialSubject/add [post]
  21. func (this *IndustrialSubjectController) IndustrialSubjectAdd() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. sysUser := this.SysUser
  28. if sysUser == nil {
  29. br.Msg = "请登录"
  30. br.ErrMsg = "请登录,SysUser Is Empty"
  31. br.Ret = 408
  32. return
  33. }
  34. var req cygx.IndustrialSubjectAdd
  35. var pars []interface{}
  36. var condition string
  37. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  38. if err != nil {
  39. br.Msg = "参数解析异常!"
  40. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  41. return
  42. }
  43. subjectName := req.SubjectName
  44. source := req.Source
  45. industrialManagementId := req.IndustrialManagementId
  46. if subjectName == "" {
  47. br.Msg = "请输标的名称"
  48. return
  49. }
  50. if source != 2 && source != 3 {
  51. source = 1
  52. }
  53. subjectName = strings.Replace(subjectName, " ", "", -1)
  54. item := new(cygx.CygxIndustrialSubject)
  55. var items []*cygx.CygxIndustrialSubject
  56. item.IndustrialManagementId = req.IndustrialManagementId
  57. item.SubjectName = subjectName
  58. item.CreateTime = time.Now()
  59. item.Source = source
  60. subjectNameList := strings.Split(subjectName, "{|}")
  61. if len(subjectNameList) > 1 {
  62. for _, v := range subjectNameList {
  63. condition = `AND subject_name = '` + v + `' AND industrial_management_id = ` + strconv.Itoa(req.IndustrialManagementId)
  64. total, _ := cygx.GetIndustrialSubjectCount(condition, pars)
  65. if total > 0 {
  66. br.Msg = "标的已经存在,请重新填写"
  67. br.ErrMsg = "名称已经存在,请重新填写:" + v
  68. return
  69. }
  70. item := new(cygx.CygxIndustrialSubject)
  71. item.IndustrialManagementId = req.IndustrialManagementId
  72. item.SubjectName = v
  73. item.CreateTime = time.Now()
  74. item.Source = source
  75. items = append(items, item)
  76. }
  77. } else {
  78. condition = `AND subject_name = '` + req.SubjectName + `' AND industrial_management_id = ` + strconv.Itoa(req.IndustrialManagementId)
  79. total, _ := cygx.GetIndustrialSubjectCount(condition, pars)
  80. if total > 0 {
  81. br.Msg = "标的已经存在,请重新填写"
  82. br.ErrMsg = "名称已经存在,请重新填写:" + req.SubjectName
  83. return
  84. }
  85. }
  86. condition = `AND industrial_management_id = ` + strconv.Itoa(req.IndustrialManagementId)
  87. totalIndustrialManagement, _ := cygx.GetIndustrialManagementCount(condition, pars)
  88. if totalIndustrialManagement < 1 {
  89. br.Msg = "产业名称不存在,请重新填写"
  90. br.ErrMsg = "产业名称不存在,请重新填写,IndustrialManagementId:" + strconv.Itoa(req.IndustrialManagementId)
  91. return
  92. }
  93. detail, err := cygx.GetIndustrialManagemenDetailById(industrialManagementId)
  94. if err != nil {
  95. br.Msg = "获取信息失败"
  96. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  97. return
  98. }
  99. var newIdStr string
  100. if len(subjectNameList) > 1 {
  101. newId, err := cygx.AddIndustrialSubjectList(items)
  102. if err != nil {
  103. br.Msg = "新增失败"
  104. br.ErrMsg = "新增失败 Err:" + err.Error()
  105. return
  106. }
  107. newIdStr = newId
  108. } else {
  109. newId, err := cygx.AddIndustrialSubject(item)
  110. if err != nil {
  111. br.Msg = "新增失败"
  112. br.ErrMsg = "新增失败 Err:" + err.Error()
  113. return
  114. }
  115. newIdStr = strconv.Itoa(int(newId))
  116. }
  117. resp := new(cygx.NewId)
  118. resp.NewId = newIdStr
  119. go cygx.UpdateIndustrialManagementSubjectNames(industrialManagementId, detail.IndustryName)
  120. br.Ret = 200
  121. br.Success = true
  122. br.Data = resp
  123. br.Msg = "新增成功"
  124. br.IsAddLog = true
  125. }
  126. // @Title 获取标的列表
  127. // @Description 获取标的列表接口
  128. // @Param IndustrialManagementId query int true "分类ID"
  129. // @Success Ret=200 {object} cygx.GetIndustrialSubjectList
  130. // @router /industrialSubject/list [get]
  131. func (this *IndustrialSubjectController) IndustrialSubjectlist() {
  132. br := new(models.BaseResponse).Init()
  133. defer func() {
  134. this.Data["json"] = br
  135. this.ServeJSON()
  136. }()
  137. sysUser := this.SysUser
  138. if sysUser == nil {
  139. br.Msg = "请登录"
  140. br.ErrMsg = "请登录,SysUser Is Empty"
  141. br.Ret = 408
  142. return
  143. }
  144. IndustrialManagementId, _ := this.GetInt("IndustrialManagementId")
  145. if IndustrialManagementId < 1 {
  146. br.Msg = "请输入分类ID"
  147. return
  148. }
  149. list, err := cygx.GetIndustrialSubjectAll(IndustrialManagementId)
  150. if err != nil {
  151. br.Msg = "获取信息失败"
  152. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  153. return
  154. }
  155. for k, v := range list {
  156. if v.ArtNum > 0 {
  157. list[k].IsRelevance = true
  158. }
  159. }
  160. resp := new(cygx.GetIndustrialSubjectNumList)
  161. resp.List = list
  162. br.Ret = 200
  163. br.Success = true
  164. br.Msg = "获取成功"
  165. br.Data = resp
  166. }
  167. // @Title 修改
  168. // @Description 修改接口
  169. // @Param request body cygx.CygxIndustrialSubject true "type json string"
  170. // @Success Ret=200 修改成功
  171. // @router /industrialSubject/edit [post]
  172. func (this *IndustrialSubjectController) IndustrialSubjectEdit() {
  173. br := new(models.BaseResponse).Init()
  174. defer func() {
  175. this.Data["json"] = br
  176. this.ServeJSON()
  177. }()
  178. sysUser := this.SysUser
  179. if sysUser == nil {
  180. br.Msg = "请登录"
  181. br.ErrMsg = "请登录,SysUser Is Empty"
  182. br.Ret = 408
  183. return
  184. }
  185. var req cygx.CygxIndustrialSubject
  186. var pars []interface{}
  187. var condition string
  188. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  189. if err != nil {
  190. br.Msg = "参数解析异常!"
  191. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  192. return
  193. }
  194. if req.SubjectName == "" {
  195. br.Msg = "请输入名称"
  196. return
  197. }
  198. //industrialManagementId := req.IndustrialManagementId
  199. industrialSubjectId := req.IndustrialSubjectId
  200. condition = `AND industrial_subject_id = ` + strconv.Itoa(industrialSubjectId)
  201. totalIndustrialSubject, _ := cygx.GetIndustrialSubjectCount(condition, pars)
  202. if totalIndustrialSubject < 1 {
  203. br.Msg = "修改失败"
  204. br.ErrMsg = "修改失败,标的不存在,IndustrialSubjectId:" + strconv.Itoa(industrialSubjectId)
  205. return
  206. }
  207. condition = `AND industrial_management_id = ` + strconv.Itoa(req.IndustrialManagementId)
  208. detailSubjecj, err := cygx.GetIndustrialSubjectDetailById(industrialSubjectId)
  209. if err != nil {
  210. br.Msg = "获取信息失败"
  211. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  212. return
  213. }
  214. detail, err := cygx.GetIndustrialManagemenDetailById(detailSubjecj.IndustrialManagementId)
  215. if err != nil {
  216. br.Msg = "获取信息失败"
  217. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  218. return
  219. }
  220. item := new(cygx.CygxIndustrialSubject)
  221. item.IndustrialManagementId = req.IndustrialManagementId
  222. item.SubjectName = req.SubjectName
  223. item.IndustrialSubjectId = req.IndustrialSubjectId
  224. err = cygx.EditIndustrialSubject(item)
  225. if err != nil {
  226. br.Msg = "修改失败"
  227. br.ErrMsg = "修改失败 Err:" + err.Error()
  228. return
  229. }
  230. go cygx.UpdateIndustrialManagementSubjectNames(detail.IndustrialManagementId, detail.IndustryName)
  231. br.Ret = 200
  232. br.Success = true
  233. br.Msg = "修改成功"
  234. br.IsAddLog = true
  235. }
  236. // @Title 删除标的
  237. // @Description 删除标的接口
  238. // @Param IndustrialSubjectId query int true "标的ID"
  239. // @Success Ret=200 {object} cygx.NewId
  240. // @router /industrialSubject/delete [post]
  241. func (this *IndustrialSubjectController) IndustrialSubjectDelete() {
  242. br := new(models.BaseResponse).Init()
  243. defer func() {
  244. this.Data["json"] = br
  245. this.ServeJSON()
  246. }()
  247. sysUser := this.SysUser
  248. if sysUser == nil {
  249. br.Msg = "请登录"
  250. br.ErrMsg = "请登录,SysUser Is Empty"
  251. br.Ret = 408
  252. return
  253. }
  254. var req cygx.IndustrialSubjectDelete
  255. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  256. if err != nil {
  257. br.Msg = "参数解析异常!"
  258. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  259. return
  260. }
  261. industrialSubjectId := req.IndustrialSubjectId
  262. if industrialSubjectId < 1 {
  263. br.Msg = "请输入标的ID"
  264. return
  265. }
  266. count, _ := cygx.GetIndustrialSubjectGroupArtCount(industrialSubjectId)
  267. if count > 0 {
  268. br.Ret = 460
  269. br.Msg = "当前标的下有关联报告,请将相关报告归类后再删除"
  270. return
  271. }
  272. detailSubjecj, err := cygx.GetIndustrialSubjectDetailById(industrialSubjectId)
  273. if err != nil {
  274. br.Msg = "获取信息失败"
  275. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  276. return
  277. }
  278. detailIndustrialManagemen, err := cygx.GetIndustrialManagemenDetailById(detailSubjecj.IndustrialManagementId)
  279. if err != nil {
  280. br.Msg = "获取信息失败"
  281. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  282. return
  283. }
  284. err = cygx.DeleteIndustrialSubject(industrialSubjectId)
  285. if err != nil {
  286. br.Msg = "删除信息失败"
  287. br.ErrMsg = "删除信息失败,Err:" + err.Error()
  288. return
  289. }
  290. go cygx.UpdateIndustrialManagementSubjectNames(detailIndustrialManagemen.IndustrialManagementId, detailIndustrialManagemen.IndustryName)
  291. br.Ret = 200
  292. br.Success = true
  293. br.Msg = "删除成功"
  294. br.IsAddLog = true
  295. }
  296. // @Title 通过多个产业获取标的列表
  297. // @Description 通过多个产业获取标的列表接口
  298. // @Param IndustrialManagementIdStr query string true "分类ID,多个使用 ,隔开列如 1,3,5"
  299. // @Param ArticleId int string false "文章ID"
  300. // @Param KeyWord query string false "搜索关键词"
  301. // @Success Ret=200 {object} cygx.GetIndustrialSubjectList
  302. // @router /industrialSubject/listIds [get]
  303. func (this *IndustrialSubjectController) IndustrialSubjectlistIds() {
  304. br := new(models.BaseResponse).Init()
  305. defer func() {
  306. this.Data["json"] = br
  307. this.ServeJSON()
  308. }()
  309. sysUser := this.SysUser
  310. if sysUser == nil {
  311. br.Msg = "请登录"
  312. br.ErrMsg = "请登录,SysUser Is Empty"
  313. br.Ret = 408
  314. return
  315. }
  316. industrialManagementIdStr := this.GetString("IndustrialManagementIdStr")
  317. keyWord := this.GetString("KeyWord")
  318. articleId, _ := this.GetInt("ArticleId")
  319. if industrialManagementIdStr == "" {
  320. br.Msg = "请输入分类ID"
  321. return
  322. }
  323. var industrialMap = make(map[int]string)
  324. var condition string
  325. if keyWord != "" {
  326. condition += ` AND (sub.subject_name LIKE '%` + keyWord + `%' ) `
  327. }
  328. if industrialManagementIdStr != "" {
  329. condition += ` AND sub.industrial_management_id IN (` + industrialManagementIdStr + `) `
  330. }
  331. list, err := cygx.GetIndustrialSubjectAllByIds(condition)
  332. if err != nil {
  333. br.Msg = "获取信息失败"
  334. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  335. return
  336. }
  337. for k, v := range list {
  338. if v.ArtNum > 0 {
  339. list[k].IsRelevance = true
  340. }
  341. industrialMap[v.IndustrialSubjectId] = v.SubjectName
  342. }
  343. if articleId > 0 {
  344. subjectList, err := cygx.GetSubjectArticleGroupManagementList(articleId)
  345. if err != nil && err.Error() != utils.ErrNoRow() {
  346. br.Msg = "获取信息失败"
  347. br.ErrMsg = "获取活动关联的标的列表信息失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(articleId)
  348. return
  349. }
  350. for _, v := range subjectList {
  351. if industrialMap[v.IndustrialSubjectId] == "" {
  352. item := new(cygx.CygxIndustrialSubjectNum)
  353. item.IndustrialSubjectId = v.IndustrialSubjectId
  354. item.SubjectName = v.SubjectName
  355. list = append(list, item)
  356. }
  357. }
  358. }
  359. resp := new(cygx.GetIndustrialSubjectNumList)
  360. resp.List = list
  361. br.Ret = 200
  362. br.Success = true
  363. br.Msg = "获取成功"
  364. br.Data = resp
  365. }
  366. // @Title 获取关联标的列表
  367. // @Description 获取关联标的列表接口
  368. // @Param KeyWord query string false "搜索关键词"
  369. // @Success Ret=200 {object} cygx.ArtGroupIndustrialSubjectRepList
  370. // @router /industrialSubject/listByName [get]
  371. func (this *IndustrialSubjectController) IndustrialSubjectByName() {
  372. br := new(models.BaseResponse).Init()
  373. defer func() {
  374. this.Data["json"] = br
  375. this.ServeJSON()
  376. }()
  377. sysUser := this.SysUser
  378. if sysUser == nil {
  379. br.Msg = "请登录"
  380. br.ErrMsg = "请登录,SysUser Is Empty"
  381. br.Ret = 408
  382. return
  383. }
  384. var condition string
  385. var conditionKeyWord string
  386. keyWord := this.GetString("KeyWord")
  387. if keyWord != "" {
  388. keyWord = strings.Replace(keyWord, "'", "", -1)
  389. keyWord = strings.Replace(keyWord, "%", "", -1)
  390. condition = ` AND s.subject_name LIKE '%` + keyWord + `%' `
  391. } else {
  392. condition = ` AND industrial_subject_id = 0 `
  393. }
  394. listSubject, err := cygx.GetIndustrialSubjectListName(condition)
  395. if err != nil {
  396. br.Msg = "获取失败"
  397. br.ErrMsg = "获取失败,Err:" + err.Error()
  398. return
  399. }
  400. for _, v := range listSubject {
  401. conditionKeyWord += "'" + v.SubjectName + "',"
  402. }
  403. if conditionKeyWord != "" {
  404. conditionKeyWord = strings.TrimRight(conditionKeyWord, ",")
  405. conditionKeyWord = ` AND industry_map_name NOT IN ( ` + conditionKeyWord + `)`
  406. }
  407. if keyWord != "" {
  408. condition = ` AND industry_map_name LIKE '%` + keyWord + `%' AND level = 5 ` + conditionKeyWord
  409. } else {
  410. condition = ` AND industry_map_id = 0 `
  411. }
  412. listMap, err := cygx.GetIndustrialMapListName(condition)
  413. if err != nil {
  414. br.Msg = "获取失败"
  415. br.ErrMsg = "获取失败,Err:" + err.Error()
  416. return
  417. }
  418. resp := new(cygx.ArtGroupIndustrialSubjectRepList)
  419. for _, v := range listMap {
  420. item := new(cygx.ArtGroupIndustrialSubjectRep)
  421. item.SubjectName = v.IndustryMapName
  422. listSubject = append(listSubject, item)
  423. }
  424. resp.List = listSubject
  425. br.Ret = 200
  426. br.Success = true
  427. br.Msg = "获取成功"
  428. br.Data = resp
  429. }
  430. // @Title 通过行业获取关联标的列表
  431. // @Description 通过行业获取关联标的列表接口
  432. // @Param KeyWord query string false "搜索关键词"
  433. // @Param ChartPermissionId query int true "分类ID"
  434. // @Success Ret=200 {object} cygx.CygxIndustrialSubjectList
  435. // @router /industrialSubject/search [get]
  436. func (this *IndustrialSubjectController) IndustrialSubjectSearch() {
  437. br := new(models.BaseResponse).Init()
  438. defer func() {
  439. this.Data["json"] = br
  440. this.ServeJSON()
  441. }()
  442. sysUser := this.SysUser
  443. if sysUser == nil {
  444. br.Msg = "请登录"
  445. br.ErrMsg = "请登录,SysUser Is Empty"
  446. br.Ret = 408
  447. return
  448. }
  449. var condition string
  450. keyWord := this.GetString("KeyWord")
  451. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  452. if keyWord != "" {
  453. condition = ` AND s.subject_name LIKE '%` + keyWord + `%' `
  454. }
  455. if chartPermissionId > 0 {
  456. condition += ` AND m.chart_permission_id = ` + strconv.Itoa(chartPermissionId)
  457. }
  458. listSubject, err := cygx.GetIndustrialSubjectListNameByChartId(condition)
  459. if err != nil {
  460. br.Msg = "获取失败"
  461. br.ErrMsg = "获取失败,Err:" + err.Error()
  462. return
  463. }
  464. resp := new(cygx.CygxIndustrialSubjectList)
  465. resp.List = listSubject
  466. br.Ret = 200
  467. br.Success = true
  468. br.Msg = "获取成功"
  469. br.Data = resp
  470. }
  471. // @Title 获取标的关联产业详情
  472. // @Description 获取标的关联产业详情接口
  473. // @Param KeyWord query string false "搜索关键词"
  474. // @Success Ret=200 {object} cygx.IndustrialNameListRep
  475. // @router /industrialSubject/searchInfo [get]
  476. func (this *IndustrialSubjectController) SearchInfo() {
  477. br := new(models.BaseResponse).Init()
  478. defer func() {
  479. this.Data["json"] = br
  480. this.ServeJSON()
  481. }()
  482. sysUser := this.SysUser
  483. if sysUser == nil {
  484. br.Msg = "请登录"
  485. br.ErrMsg = "请登录,SysUser Is Empty"
  486. br.Ret = 408
  487. return
  488. }
  489. var nameList []*cygx.SubjectNameListRep
  490. var condition string
  491. keyWord := this.GetString("KeyWord")
  492. if keyWord != "" {
  493. condition = ` AND subject_name ='` + keyWord + `' `
  494. } else {
  495. br.Msg = "请输入搜索内容"
  496. return
  497. }
  498. listSubject, err := cygx.GetIndustrialSubjectListNameByName(condition)
  499. if err != nil {
  500. br.Msg = "获取失败"
  501. br.ErrMsg = "获取失败,Err:" + err.Error()
  502. return
  503. }
  504. if len(listSubject) > 0 {
  505. mapIndustrial := make(map[int]string)
  506. mapIndustrialName := make(map[string]string)
  507. mapSubjectName := make(map[string]string)
  508. listIndustrial, err := cygx.GetIndustrialManagement("")
  509. if err != nil {
  510. br.Msg = "获取失败"
  511. br.ErrMsg = "获取失败,Err:" + err.Error()
  512. return
  513. }
  514. listSubjectAll, err := cygx.GetIndustrialSubjectListNameByName("")
  515. if err != nil {
  516. br.Msg = "获取失败"
  517. br.ErrMsg = "获取失败,Err:" + err.Error()
  518. return
  519. }
  520. for _, v := range listIndustrial {
  521. if v.IndustryName != "" {
  522. mapIndustrial[v.IndustrialManagementId] = v.IndustryName
  523. }
  524. }
  525. for _, v := range listSubject {
  526. item := new(cygx.SubjectNameListRep)
  527. if mapIndustrial[v.IndustrialManagementId] != "" {
  528. if mapIndustrialName[mapIndustrial[v.IndustrialManagementId]] == "" {
  529. item.Name = mapIndustrial[v.IndustrialManagementId]
  530. for _, v2 := range listSubjectAll {
  531. itemV2 := new(cygx.SubjectNameRep)
  532. if v2.IndustrialManagementId == v.IndustrialManagementId {
  533. if mapSubjectName[v2.SubjectName+mapIndustrial[v.IndustrialManagementId]] == "" {
  534. itemV2.Name = v2.SubjectName
  535. item.List = append(item.List, itemV2)
  536. mapSubjectName[v2.SubjectName+mapIndustrial[v.IndustrialManagementId]] = v2.SubjectName
  537. }
  538. }
  539. }
  540. nameList = append(nameList, item)
  541. }
  542. mapIndustrialName[mapIndustrial[v.IndustrialManagementId]] = mapIndustrial[v.IndustrialManagementId]
  543. }
  544. }
  545. }
  546. resp := new(cygx.IndustrialNameListRep)
  547. resp.List = nameList
  548. br.Ret = 200
  549. br.Success = true
  550. br.Msg = "获取成功"
  551. br.Data = resp
  552. }
  553. // @Title 标的关联的报告活动数量详情
  554. // @Description 标的关联的报告活动数量详情
  555. // @Param SubjectId query string true "标的ID"
  556. // @Success Ret=200 {object} cygx.IndustrySubjectCountDetail
  557. // @router /industrialSubject/countDetail [get]
  558. func (this *IndustrialSubjectController) CountDetail() {
  559. br := new(models.BaseResponse).Init()
  560. defer func() {
  561. this.Data["json"] = br
  562. this.ServeJSON()
  563. }()
  564. sysUser := this.SysUser
  565. if sysUser == nil {
  566. br.Msg = "请登录"
  567. br.ErrMsg = "请登录,SysUser Is Empty"
  568. br.Ret = 408
  569. return
  570. }
  571. subjectId, _ := this.GetInt("SubjectId")
  572. if subjectId < 1 {
  573. br.Msg = "参数有误"
  574. return
  575. }
  576. resp := new(cygx.IndustrySubjectCountDetail)
  577. // 文章数量统计
  578. artCountList, e := cygx.GetIndustrySubjectArtTypeCountList(subjectId)
  579. if e != nil {
  580. br.Msg = "获取信息失败"
  581. br.ErrMsg = "获取标的关联的报告数失败, Err: " + e.Error()
  582. return
  583. }
  584. totalNum := 0
  585. for i := range artCountList {
  586. totalNum += artCountList[i].ArtNum
  587. }
  588. // 活动数量统计-细分活动类型为"弘则活动"和"研选活动"
  589. actCountList, e := cygx.GetIndustrySubjectActCountGroupByType(subjectId)
  590. if e != nil {
  591. br.Msg = "获取信息失败"
  592. br.ErrMsg = "获取标的关联的活动数失败, Err: " + e.Error()
  593. return
  594. }
  595. hzCount := new(cygx.IndustrySubjectArtTypeCountList)
  596. hzCount.MatchTypeName = utils.CYGX_ACTIVITY_TYPE_NAME_HZ
  597. yxCount := new(cygx.IndustrySubjectArtTypeCountList)
  598. yxCount.MatchTypeName = utils.CYGX_ACTIVITY_TYPE_NAME_YX
  599. for i := range actCountList {
  600. if actCountList[i].ActivityType == utils.CYGX_ACTIVITY_TYPE_NAME_HZ {
  601. hzCount.ArtNum = actCountList[i].ActivityCount
  602. }
  603. if actCountList[i].ActivityType == utils.CYGX_ACTIVITY_TYPE_NAME_YX {
  604. yxCount.ArtNum = actCountList[i].ActivityCount
  605. }
  606. }
  607. artCountList = append(artCountList, hzCount, yxCount)
  608. resp.ArtTotalNum = totalNum
  609. resp.List = artCountList
  610. br.Ret = 200
  611. br.Success = true
  612. br.Msg = "获取成功"
  613. br.Data = resp
  614. }
  615. // @Title 通过行业获取关联标的列表
  616. // @Description 通过行业获取关联标的列表接口
  617. // @Param KeyWord query string false "搜索关键词"
  618. // @Param ChartPermissionId query int true "分类ID"
  619. // @Success Ret=200 {object} cygx.CygxIndustrialSubjectList
  620. // @router /industrialAndSubject/search [get]
  621. func (this *IndustrialSubjectController) IndustrialAndSubjectSearch() {
  622. br := new(models.BaseResponse).Init()
  623. defer func() {
  624. this.Data["json"] = br
  625. this.ServeJSON()
  626. }()
  627. sysUser := this.SysUser
  628. if sysUser == nil {
  629. br.Msg = "请登录"
  630. br.ErrMsg = "请登录,SysUser Is Empty"
  631. br.Ret = 408
  632. return
  633. }
  634. var condition string
  635. keyWord := this.GetString("KeyWord")
  636. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  637. if keyWord != "" {
  638. condition = ` AND s.subject_name LIKE '%` + keyWord + `%' `
  639. }
  640. if chartPermissionId > 0 {
  641. condition += ` AND m.chart_permission_id = ` + strconv.Itoa(chartPermissionId)
  642. }
  643. listSubject, err := cygx.GetIndustrialSubjectListNameByChartId(condition)
  644. if err != nil {
  645. br.Msg = "获取失败"
  646. br.ErrMsg = "获取失败,Err:" + err.Error()
  647. return
  648. }
  649. condition = ` AND industry_name LIKE '%` + keyWord + `%' AND chart_permission_id = ` + strconv.Itoa(chartPermissionId)
  650. listIndustrial, err := cygx.GetIndustrialManagement(condition)
  651. if err != nil {
  652. br.Msg = "获取失败"
  653. br.ErrMsg = "获取失败,Err:" + err.Error()
  654. return
  655. }
  656. listResp := make([]*cygx.CygxIndustrialSubjectListRep, 0)
  657. for _, v := range listIndustrial {
  658. item := new(cygx.CygxIndustrialSubjectListRep)
  659. item.IndustryName = v.IndustryName
  660. item.IndustrialManagementId = v.IndustrialManagementId
  661. item.ShowName = v.IndustryName
  662. listResp = append(listResp, item)
  663. }
  664. for _, v := range listSubject {
  665. v.ShowName = v.SubjectName
  666. listResp = append(listResp, v)
  667. }
  668. resp := new(cygx.CygxIndustrialSubjectList)
  669. resp.List = listResp
  670. br.Ret = 200
  671. br.Success = true
  672. br.Msg = "获取成功"
  673. br.Data = resp
  674. }