industrial_management.go 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/tealeg/xlsx"
  6. "hongze/hz_crm_api/controllers"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/cygx"
  9. cygxService "hongze/hz_crm_api/services/cygx"
  10. "hongze/hz_crm_api/utils"
  11. "os"
  12. "path/filepath"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. // 产业管理
  18. type IndustrialManagementController struct {
  19. controllers.BaseAuthController
  20. }
  21. //func init() {
  22. // fmt.Println("init start")
  23. // go cygxService.UpdateOriginIndustryLayoutTime()
  24. // fmt.Println("init end")
  25. //}
  26. // @Title 获取一级分类
  27. // @Description 获取一级分类接口
  28. // @Param HideMacro query bool false "是否隐藏宏观(默认不隐藏)"
  29. // @Param IsHideResearch query bool false "是否隐藏买方研选(默认不隐藏)"
  30. // @Param IsCeLueReport query bool false "是否是策略平台的报告类型"
  31. // @Success 200 {object} cygx.ChartPermissionResp
  32. // @router /chartPermission/first [get]
  33. func (this *IndustrialManagementController) ChartPermissionList() {
  34. br := new(models.BaseResponse).Init()
  35. defer func() {
  36. this.Data["json"] = br
  37. this.ServeJSON()
  38. }()
  39. // 是否隐藏宏观
  40. hideMacro, _ := this.GetBool("HideMacro")
  41. isHideResearch, _ := this.GetBool("IsHideResearch")
  42. isCeLueReport, _ := this.GetBool("IsCeLueReport")
  43. resp := new(cygx.ChartPermissionResp)
  44. list, err := cygx.GetChartPermissionAll()
  45. if err != nil {
  46. br.Msg = "获取信息失败"
  47. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  48. return
  49. }
  50. //判断是否是策略平台的报告类型
  51. if isCeLueReport {
  52. for _, v := range list {
  53. if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN || v.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  54. continue
  55. }
  56. resp.List = append(resp.List, v)
  57. }
  58. //item := new(cygx.ChartPermission)
  59. //item.PermissionName = utils.GU_SHOU_NAME
  60. //item.ChartPermissionId = utils.GU_SHOU_ID
  61. //resp.List = append(resp.List, item)
  62. } else {
  63. for _, v := range list {
  64. if (v.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN || v.PermissionName == utils.YAN_XUAN_KOU_DIAN_BAO_NAME) && isHideResearch {
  65. continue
  66. }
  67. resp.List = append(resp.List, v)
  68. }
  69. // 查研观向7.4-新增一个宏观
  70. if !hideMacro {
  71. macro := &cygx.ChartPermission{
  72. ChartPermissionId: 1,
  73. PermissionName: "宏观",
  74. }
  75. resp.List = append(resp.List, macro)
  76. }
  77. }
  78. br.Ret = 200
  79. br.Success = true
  80. br.Msg = "获取成功"
  81. br.Data = resp
  82. }
  83. // @Title 获取带有图标的一级分类
  84. // @Description 获取带有图标的一级分类接口
  85. // @Param Havestrategy query int true "是否有策略,1有,0无 默认无"
  86. // @Success 200 {object} cygx.ChartPermissionResp
  87. // @router /chartPermission/firstHaveIco [get]
  88. func (this *IndustrialManagementController) ChartPermissionListIco() {
  89. br := new(models.BaseResponse).Init()
  90. defer func() {
  91. this.Data["json"] = br
  92. this.ServeJSON()
  93. }()
  94. havestrategy, _ := this.GetInt("Havestrategy")
  95. var condition string
  96. if havestrategy > 0 {
  97. condition = ` AND chart_permission_id IN (19,20,21,22,23) `
  98. } else {
  99. condition = ` AND chart_permission_id IN (19,20,21,22) OR ( chart_permission_name = '周期' AND product_id = 2 ) `
  100. }
  101. list, err := cygx.GetChartPermissionIco(condition)
  102. if err != nil {
  103. br.Msg = "获取信息失败"
  104. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  105. return
  106. }
  107. for k := range list {
  108. list[k].IcoLink = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202109/20210909/aoa5IKOh4uTS1BPwvdGQ3ape4gwN.jpg"
  109. }
  110. resp := new(cygx.ChartPermissionResp)
  111. resp.List = list
  112. br.Ret = 200
  113. br.Success = true
  114. br.Msg = "获取成功"
  115. br.Data = resp
  116. }
  117. // @Title 获取一级分类无策略
  118. // @Description 获取一级分类接口
  119. // @Success 200 {object} cygx.ChartPermissionResp
  120. // @router /chartPermission/noTacticsfirst [get]
  121. func (this *IndustrialManagementController) NoTacticsChartPermissionList() {
  122. br := new(models.BaseResponse).Init()
  123. defer func() {
  124. this.Data["json"] = br
  125. this.ServeJSON()
  126. }()
  127. list, err := cygx.GetChartPermissionAllNoTactics()
  128. if err != nil {
  129. br.Msg = "获取信息失败"
  130. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  131. return
  132. }
  133. resp := new(cygx.ChartPermissionResp)
  134. resp.List = list
  135. br.Ret = 200
  136. br.Success = true
  137. br.Msg = "获取成功"
  138. br.Data = resp
  139. }
  140. // @Title 获取一级分类(包含其它)
  141. // @Description 获取一级分类(包含其它)接口
  142. // @Success 200 {object} cygx.ChartPermissionResp
  143. // @router /chartPermission/noTacticsfirstOther [get]
  144. func (this *IndustrialManagementController) NoTacticsChartPermissionOtherList() {
  145. br := new(models.BaseResponse).Init()
  146. defer func() {
  147. this.Data["json"] = br
  148. this.ServeJSON()
  149. }()
  150. list, err := cygx.GetChartPermissionOtherAll()
  151. if err != nil {
  152. br.Msg = "获取信息失败"
  153. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  154. return
  155. }
  156. resp := new(cygx.ChartPermissionResp)
  157. resp.List = list
  158. br.Ret = 200
  159. br.Success = true
  160. br.Msg = "获取成功"
  161. br.Data = resp
  162. }
  163. // @Title 产品内测一级分类接口,包含,医药消费科技制造策略
  164. // @Description 产品内测一级分类接口,包含,医药消费科技制造策略
  165. // @Success 200 {object} cygx.ChartPermissionResp
  166. // @router /chartPermission/firstProduct [get]
  167. func (this *IndustrialManagementController) ChartPermissionFirstProduct() {
  168. br := new(models.BaseResponse).Init()
  169. defer func() {
  170. this.Data["json"] = br
  171. this.ServeJSON()
  172. }()
  173. resp := new(cygx.ChartPermissionResp)
  174. list, err := cygx.GetChartPermissionAll()
  175. if err != nil {
  176. br.Msg = "获取信息失败"
  177. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  178. return
  179. }
  180. //医药消费科技制造策略
  181. for _, v := range list {
  182. if v.PermissionName == utils.YI_YAO_NAME || v.PermissionName == utils.XIAO_FEI_NAME || v.PermissionName == utils.KE_JI_NAME || v.PermissionName == utils.ZHI_ZAO_NAME || v.PermissionName == utils.CE_LUE_NAME || v.PermissionName == utils.GU_SHOU_NAME || v.PermissionName == utils.ZHOU_QI_NAME {
  183. resp.List = append(resp.List, v)
  184. }
  185. }
  186. br.Ret = 200
  187. br.Success = true
  188. br.Msg = "获取成功"
  189. br.Data = resp
  190. }
  191. // @Title 专项产业调研活动一级行业分类
  192. // @Description 专项产业调研活动一级行业分类接口
  193. // @Success 200 {object} cygx.ChartPermissionResp
  194. // @router /chartPermission/activitySpecial [get]
  195. func (this *IndustrialManagementController) ChartPermissionListActivitySpecial() {
  196. br := new(models.BaseResponse).Init()
  197. defer func() {
  198. this.Data["json"] = br
  199. this.ServeJSON()
  200. }()
  201. resp := new(cygx.ChartPermissionResp)
  202. list, err := cygx.GetChartPermissionAll()
  203. if err != nil {
  204. br.Msg = "获取信息失败"
  205. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  206. return
  207. }
  208. //医药、消费、科技、制造、策略,固收,周期
  209. for _, v := range list {
  210. if v.PermissionName == utils.YI_YAO_NAME || v.PermissionName == utils.XIAO_FEI_NAME || v.PermissionName == utils.KE_JI_NAME || v.PermissionName == utils.ZHI_ZAO_NAME || v.PermissionName == utils.CE_LUE_NAME || v.PermissionName == utils.GU_SHOU_NAME || v.PermissionName == utils.ZHOU_QI_NAME {
  211. resp.List = append(resp.List, v)
  212. }
  213. }
  214. br.Ret = 200
  215. br.Success = true
  216. br.Msg = "获取成功"
  217. br.Data = resp
  218. }
  219. // @Title 添加产业
  220. // @Description 添加产业接口
  221. // @Param request body cygx.IndustrialManagementAdd true "type json string"
  222. // @Success Ret=200 {object} cygx.NewId
  223. // @router /industrialManagement/add [post]
  224. func (this *IndustrialManagementController) IndustrialManagementAdd() {
  225. br := new(models.BaseResponse).Init()
  226. defer func() {
  227. this.Data["json"] = br
  228. this.ServeJSON()
  229. }()
  230. sysUser := this.SysUser
  231. if sysUser == nil {
  232. br.Msg = "请登录"
  233. br.ErrMsg = "请登录,SysUser Is Empty"
  234. br.Ret = 408
  235. return
  236. }
  237. var req cygx.IndustrialManagementAdd
  238. var pars []interface{}
  239. var condition string
  240. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  241. if err != nil {
  242. br.Msg = "参数解析异常!"
  243. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  244. return
  245. }
  246. source := req.Source
  247. permissionName := req.PermissionName
  248. if source != 2 && source != 3 {
  249. source = 1
  250. }
  251. if req.IndustryName == "" {
  252. br.Msg = "请输入产业名称"
  253. return
  254. }
  255. if permissionName == "" {
  256. if req.ChartPermissionId < 1 {
  257. br.Msg = "请选择所属行业"
  258. return
  259. }
  260. } else {
  261. req.ChartPermissionId = 31 //研选ID
  262. }
  263. // 查研观向7.4-不再手动填写布局时间, 而是第一次新增报告/活动的时候自动更新布局时间
  264. if source == 1 {
  265. //if req.LayoutTime == "" {
  266. // br.Msg = "请输入布局时间"
  267. // return
  268. //}
  269. if req.RecommendedIndex < 0 {
  270. br.Msg = "请输入推荐指数"
  271. return
  272. }
  273. if req.RecommendedIndex < 0 || req.RecommendedIndex > 100 {
  274. br.Msg = "推荐指数范围在0-100之间"
  275. return
  276. }
  277. } else {
  278. req.LayoutTime = time.Now().Format(utils.FormatDateTime)
  279. }
  280. item := new(cygx.CygxIndustrialManagement)
  281. item.ChartPermissionId = req.ChartPermissionId
  282. item.IndustryName = req.IndustryName
  283. item.RecommendedIndex = req.RecommendedIndex
  284. item.LayoutTime = req.LayoutTime
  285. item.IsNewLabel = req.IsNewLabel
  286. item.Source = source
  287. if req.IsNewLabel == 0 {
  288. item.IsHandNewLabel = 1
  289. }
  290. item.CreateTime = time.Now()
  291. condition = `AND product_id=2 AND show_type=1 AND is_other=0 AND chart_permission_id = ` + strconv.Itoa(req.ChartPermissionId)
  292. totalChartPermissionId, _ := cygx.GetChartPermissionCount(condition, pars)
  293. if totalChartPermissionId < 1 {
  294. br.Msg = "分类ID不存在,请重新填写"
  295. br.ErrMsg = "分类ID不存在,请重新填写:" + strconv.Itoa(req.ChartPermissionId)
  296. return
  297. }
  298. //如果是通过产业模块正常添加
  299. if source == 1 {
  300. condition = ` AND source != 1 AND industry_name = '` + req.IndustryName + `'`
  301. totalSource, err := cygx.GetIndustrialManagementCount(condition, pars)
  302. if err != nil {
  303. br.Msg = "添加失败"
  304. br.ErrMsg = "添加失败 Err:" + err.Error()
  305. return
  306. }
  307. if totalSource > 0 {
  308. // 修改来源为正常添加
  309. err = cygx.EditIndustrialManagementFromAct(item)
  310. if err != nil {
  311. br.Msg = "添加失败"
  312. br.ErrMsg = "添加失败 Err:" + err.Error()
  313. return
  314. }
  315. br.Msg = "该产业已存在"
  316. br.ErrMsg = "名称已经存在,请重新填写:" + req.IndustryName
  317. return
  318. }
  319. }
  320. // 查研观向7.4-全行业(包括研选)重名校验
  321. //if permissionName == "研选" {
  322. // condition = ` AND industry_name = '` + req.IndustryName + `'`
  323. //} else {
  324. // condition = ` AND source = 1 AND industry_name = '` + req.IndustryName + `'`
  325. //}
  326. condition = ` AND industry_name = '` + req.IndustryName + `'`
  327. total, err := cygx.GetIndustrialManagementCount(condition, pars)
  328. if err != nil {
  329. br.Msg = "添加失败"
  330. br.ErrMsg = "添加失败 Err:" + err.Error()
  331. return
  332. }
  333. if total > 0 {
  334. br.Msg = "该产业已存在"
  335. br.ErrMsg = "名称已经存在,请重新填写:" + req.IndustryName
  336. return
  337. }
  338. newId, err := cygx.AddIndustrialManagement(item)
  339. if err != nil {
  340. br.Msg = "添加失败"
  341. br.ErrMsg = "添加失败 Err:" + err.Error()
  342. return
  343. }
  344. go cygxService.AddUserIndustryFllowByNewId(int(newId)) //现了新的产业,给选择推送方式的用户自动添加关注
  345. resp := new(cygx.NewId)
  346. resp.NewId = strconv.Itoa(int(newId))
  347. resp.ChartPermissionId = req.ChartPermissionId
  348. br.Data = resp
  349. br.Ret = 200
  350. br.Success = true
  351. br.Msg = "添加成功"
  352. br.IsAddLog = true
  353. }
  354. // @Title 获取产业列表
  355. // @Description 获取产业列表接口
  356. // @Param ChartPermissionId query int true "分类ID"
  357. // @Param OrderColumn query int false "排序字段 ,AddTime添加时间 ,Recommended推荐指数 ,ReportTime 报告更新时间 "
  358. // @Param KeyWord query string false "搜索关键词"
  359. // @Success Ret=200 {object} cygx.GetIndustrialManagementList
  360. // @router /industrialManagement/list [get]
  361. func (this *IndustrialManagementController) IndustrialManagementlist() {
  362. br := new(models.BaseResponse).Init()
  363. defer func() {
  364. this.Data["json"] = br
  365. this.ServeJSON()
  366. }()
  367. sysUser := this.SysUser
  368. if sysUser == nil {
  369. br.Msg = "请登录"
  370. br.ErrMsg = "请登录,SysUser Is Empty"
  371. br.Ret = 408
  372. return
  373. }
  374. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  375. orderColumn := this.GetString("OrderColumn")
  376. keyWord := this.GetString("KeyWord")
  377. if chartPermissionId < 1 {
  378. br.Msg = "请输入分类ID"
  379. return
  380. }
  381. if orderColumn != "Recommended" && orderColumn != "ReportTime" {
  382. orderColumn = "AddTime"
  383. }
  384. var condition string
  385. if keyWord != "" {
  386. condition += ` AND (man.industry_name LIKE '%` + keyWord + `%' ) `
  387. }
  388. condition += ` AND man.chart_permission_id = ` + strconv.Itoa(chartPermissionId)
  389. // @Param OrderColumn query int true "排序字段 ,AddTime 添加时间 ,Recommended 推荐指数 ,ReportTime 报告更新时间 "
  390. //var list []*cygx.CygxIndustrialManagementNum
  391. //var err error
  392. //var orderSrt string
  393. //if orderColumn == "Recommended" {
  394. // orderSrt = "man.recommended_index DESC,update_time DESC"
  395. //} else {
  396. // orderSrt = "update_time DESC"
  397. //}
  398. //
  399. //if orderColumn == "AddTime" {
  400. // listAddTime, errAddTime := cygx.GetIndustrialManagementAll(condition, "create_time")
  401. // list = listAddTime
  402. // err = errAddTime
  403. //} else if orderColumn == "Recommended" {
  404. // listAddTime, errAddTime := cygx.GetIndustrialManagementAllByReportTime(condition, orderSrt)
  405. // list = listAddTime
  406. // err = errAddTime
  407. //} else {
  408. // listAddTime, errAddTime := cygx.GetIndustrialManagementAllByReportTime(condition, orderSrt)
  409. // list = listAddTime
  410. // err = errAddTime
  411. //}
  412. //if err != nil {
  413. // br.Msg = "获取信息失败"
  414. // br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  415. // return
  416. //}
  417. // 查研观向7.4-研选产业同时需要查询弘则覆盖的产业
  418. var isCover bool
  419. var conditionCover string
  420. var pars []interface{}
  421. if chartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  422. // 获取弘则覆盖产业IDs
  423. coverIds, e := cygx.GetYxIndustryUseHzIndustryIds()
  424. if e != nil {
  425. br.Msg = "获取信息失败"
  426. br.ErrMsg = "获取弘则覆盖产业IDs失败, Err: " + e.Error()
  427. return
  428. }
  429. if len(coverIds) > 0 {
  430. isCover = true
  431. conditionCover += ` AND man.industrial_management_id IN (` + utils.GetOrmInReplace(len(coverIds)) + `)`
  432. pars = append(pars, coverIds)
  433. }
  434. }
  435. orderMap := map[string]string{
  436. "AddTime": ` create_time ASC`,
  437. "Recommended": ` recommended_index DESC, update_time DESC`,
  438. "ReportTime": ` update_time DESC`,
  439. }
  440. orderRule := orderMap[orderColumn]
  441. if orderRule == `` {
  442. orderRule = ` create_time ASC`
  443. }
  444. list, e := cygx.GetIndustryListWithHzCover(condition, conditionCover, orderRule, isCover, pars)
  445. if e != nil {
  446. br.Msg = "获取信息失败"
  447. br.ErrMsg = "获取产业信息失败, Err: " + e.Error()
  448. return
  449. }
  450. for k, v := range list {
  451. if v.ArtNum > 0 || v.ActNum > 0 {
  452. list[k].IsRelevance = true
  453. }
  454. }
  455. resp := new(cygx.GetIndustrialManagementList)
  456. resp.List = list
  457. br.Ret = 200
  458. br.Success = true
  459. br.Msg = "获取成功"
  460. br.Data = resp
  461. }
  462. // @Title 获取产业详情
  463. // @Description 获取产业详情接口
  464. // @Param IndustrialManagementId query int true "产业ID"
  465. // @Success Ret=200 {object} cygx.CygxIndustrialManagementDetailRep
  466. // @router /industrialManagement/industrialManagementDetail [get]
  467. func (this *IndustrialManagementController) IndustrialManagementDetail() {
  468. br := new(models.BaseResponse).Init()
  469. defer func() {
  470. this.Data["json"] = br
  471. this.ServeJSON()
  472. }()
  473. sysUser := this.SysUser
  474. if sysUser == nil {
  475. br.Msg = "请登录"
  476. br.ErrMsg = "请登录,SysUser Is Empty"
  477. br.Ret = 408
  478. return
  479. }
  480. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  481. if industrialManagementId < 1 {
  482. br.Msg = "请输入分类ID"
  483. return
  484. }
  485. detail, err := cygx.GetIndustrialManagemenDetailById(industrialManagementId)
  486. if err != nil {
  487. br.Msg = "获取信息失败"
  488. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  489. return
  490. }
  491. resp := new(cygx.CygxIndustrialManagementDetailRep)
  492. resp.IndustrialManagementId = detail.IndustrialManagementId
  493. resp.IndustryName = detail.IndustryName
  494. resp.ChartPermissionId = detail.ChartPermissionId
  495. resp.RecommendedIndex = detail.RecommendedIndex
  496. resp.CreateTime = detail.CreateTime
  497. resp.LayoutTime = detail.LayoutTime
  498. resp.IsNewLabel = detail.IsNewLabel
  499. resp.IsDeepLabel = detail.IsDeepLabel
  500. resultTime := detail.CreateTime.AddDate(0, 2, 0).Format(utils.FormatDateTime)
  501. if utils.StrTimeToTime(resultTime).After(time.Now()) {
  502. resp.IsShowNewLabel = true
  503. }
  504. count, err := cygx.GetIndustrialManagementGroupArtCount(industrialManagementId)
  505. if err != nil {
  506. br.Msg = "获取信息失败"
  507. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  508. return
  509. }
  510. countDeep, err := cygx.GetIndustrialManagementGroupArtCountByDeep(industrialManagementId)
  511. if err != nil {
  512. br.Msg = "获取信息失败"
  513. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  514. return
  515. }
  516. if count >= 10 && countDeep > 0 {
  517. resp.IsShowDeepLabel = true
  518. }
  519. br.Ret = 200
  520. br.Success = true
  521. br.Msg = "获取成功"
  522. br.Data = resp
  523. }
  524. // @Title 修改产业
  525. // @Description 修改产业接口
  526. // @Param request body cygx.CygxIndustrialManagementEdit true "type json string"
  527. // @Success Ret=200 修改产业成功
  528. // @router /industrialManagement/edit [post]
  529. func (this *IndustrialManagementController) IndustrialManagementEdit() {
  530. br := new(models.BaseResponse).Init()
  531. defer func() {
  532. this.Data["json"] = br
  533. this.ServeJSON()
  534. }()
  535. sysUser := this.SysUser
  536. if sysUser == nil {
  537. br.Msg = "请登录"
  538. br.ErrMsg = "请登录,SysUser Is Empty"
  539. br.Ret = 408
  540. return
  541. }
  542. var req cygx.CygxIndustrialManagementEdit
  543. var pars []interface{}
  544. var condition string
  545. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  546. if err != nil {
  547. br.Msg = "参数解析异常!"
  548. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  549. return
  550. }
  551. if req.IndustryName == "" {
  552. br.Msg = "请输入产业名称"
  553. return
  554. }
  555. industrialManagementId := req.IndustrialManagementId
  556. condition = ` AND industrial_management_id = ` + strconv.Itoa(req.IndustrialManagementId)
  557. totalIndustrialManagement, _ := cygx.GetIndustrialManagementCount(condition, pars)
  558. if totalIndustrialManagement < 1 {
  559. br.Msg = "修改失败"
  560. br.ErrMsg = "信息不存在!"
  561. return
  562. }
  563. //if req.LayoutTime == "" {
  564. // br.Msg = "请输入布局时间"
  565. // return
  566. //}
  567. if req.RecommendedIndex < 0 {
  568. br.Msg = "请输入推荐指数"
  569. return
  570. }
  571. if req.RecommendedIndex < 0 || req.RecommendedIndex > 100 {
  572. br.Msg = "推荐指数范围在0-100之间"
  573. return
  574. }
  575. condition = ` AND product_id=2 AND show_type=1 AND is_other=0 AND chart_permission_id = ` + strconv.Itoa(req.ChartPermissionId)
  576. totalChartPermissionId, _ := cygx.GetChartPermissionCount(condition, pars)
  577. if totalChartPermissionId < 1 {
  578. br.Msg = "分类ID不存在,请重新填写"
  579. br.ErrMsg = "分类ID不存在,请重新填写:" + strconv.Itoa(req.ChartPermissionId)
  580. return
  581. }
  582. // 查研观向7.4-全行业(包括研选)重名校验
  583. condition = ` AND industry_name = '` + req.IndustryName + `' AND industrial_management_id != ` + strconv.Itoa(req.IndustrialManagementId)
  584. //condition = ` AND industry_name = '` + req.IndustryName + `' AND industrial_management_id != ` + strconv.Itoa(req.IndustrialManagementId) + ` AND chart_permission_id = ` + strconv.Itoa(req.ChartPermissionId)
  585. total, _ := cygx.GetIndustrialManagementCount(condition, pars)
  586. if total > 0 {
  587. br.Msg = "产业已存在,请重新填写"
  588. br.ErrMsg = "名称已经存在,请重新填写:" + req.IndustryName
  589. return
  590. }
  591. //condition = ` AND recommended_index = ` + strconv.Itoa(req.RecommendedIndex) + ` AND chart_permission_id = ` + strconv.Itoa(req.ChartPermissionId) + ` AND industrial_management_id != ` + strconv.Itoa(req.IndustrialManagementId)
  592. //totalRecommendedIndex, _ := cygx.GetIndustrialManagementCount(condition, pars)
  593. //if totalRecommendedIndex > 0 {
  594. // br.Msg = "推荐指数已经存在,请重新填写"
  595. // br.ErrMsg = "推荐指数已经存在,请重新填写:" + strconv.Itoa(req.RecommendedIndex)
  596. // return
  597. //}
  598. item := new(cygx.CygxIndustrialManagement)
  599. item.ChartPermissionId = req.ChartPermissionId
  600. item.IndustryName = req.IndustryName
  601. item.RecommendedIndex = req.RecommendedIndex
  602. //item.LayoutTime = req.LayoutTime
  603. item.IndustrialManagementId = req.IndustrialManagementId
  604. item.IsNewLabel = req.IsNewLabel
  605. item.IsDeepLabel = req.IsDeepLabel
  606. detail, err := cygx.GetIndustrialManagemenDetailById(industrialManagementId)
  607. if err != nil {
  608. br.Msg = "获取信息失败"
  609. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  610. return
  611. }
  612. resultTime := detail.CreateTime.AddDate(0, 2, 0).Format(utils.FormatDateTime)
  613. if utils.StrTimeToTime(resultTime).After(time.Now()) && req.IsNewLabel == 0 {
  614. item.IsHandNewLabel = 1
  615. }
  616. count, err := cygx.GetIndustrialManagementGroupArtCount(industrialManagementId)
  617. if err != nil {
  618. br.Msg = "获取信息失败"
  619. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  620. return
  621. }
  622. countDeep, err := cygx.GetIndustrialManagementGroupArtCountByDeep(industrialManagementId)
  623. if err != nil {
  624. br.Msg = "获取信息失败"
  625. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  626. return
  627. }
  628. if count >= 10 && countDeep > 0 && req.IsDeepLabel == 0 {
  629. item.IsHandDeepLabel = 1
  630. }
  631. if (count < 10 || countDeep == 0) && req.IsDeepLabel == 1 {
  632. item.IsHandDeepLabel = 1
  633. }
  634. err = cygx.EditIndustrialManagement(item)
  635. if err != nil {
  636. br.Msg = "编辑失败"
  637. br.ErrMsg = "修改失败 Err:" + err.Error()
  638. return
  639. }
  640. go cygx.UpdateIndustrialManagementSubjectNames(industrialManagementId, req.IndustryName)
  641. // 查研观向7.4-更新产业布局时间
  642. industryIds := make([]int, 0)
  643. industryIds = append(industryIds, industrialManagementId)
  644. go cygxService.UpdateIndustryLayoutTime(industryIds, false)
  645. br.Ret = 200
  646. br.Success = true
  647. br.Msg = "编辑成功"
  648. br.IsAddLog = true
  649. }
  650. // @Title 删除产业
  651. // @Description 删除产业接口
  652. // @Param IndustrialManagementId query int true "产业ID"
  653. // @Param request body models.BannerDeleteReq true "type json string"
  654. // @Success Ret=200
  655. // @router /industrialManagement/delete [post]
  656. func (this *IndustrialManagementController) IndustrialManagementDelete() {
  657. br := new(models.BaseResponse).Init()
  658. defer func() {
  659. this.Data["json"] = br
  660. this.ServeJSON()
  661. }()
  662. sysUser := this.SysUser
  663. if sysUser == nil {
  664. br.Msg = "请登录"
  665. br.ErrMsg = "请登录,SysUser Is Empty"
  666. br.Ret = 408
  667. return
  668. }
  669. var req cygx.IndustrialManagementDelte
  670. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  671. if err != nil {
  672. br.Msg = "参数解析异常!"
  673. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  674. return
  675. }
  676. IndustrialManagementId := req.IndustrialManagementId
  677. if IndustrialManagementId < 1 {
  678. br.Msg = "请输入产业ID"
  679. return
  680. }
  681. count, _ := cygx.GetIndustrialManagementGroupArtCount(IndustrialManagementId)
  682. if count > 0 {
  683. br.Ret = 460
  684. br.Msg = "当前产业下有关联报告,请将相关报告重新归类后再删除"
  685. return
  686. }
  687. countAct, err := cygx.GetIndustrialManagementGroupActCount(IndustrialManagementId)
  688. if err != nil {
  689. br.Msg = "删除失败"
  690. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  691. return
  692. }
  693. if countAct > 0 {
  694. br.Ret = 460
  695. br.Msg = "当前产业下有关联活动,请将相关活动重新归类后再删除"
  696. return
  697. }
  698. var pars []interface{}
  699. var condition string
  700. condition = ` AND industrial_management_id = ` + strconv.Itoa(IndustrialManagementId)
  701. totalIndustrialManagement, _ := cygx.GetIndustrialManagementCount(condition, pars)
  702. if totalIndustrialManagement < 1 {
  703. br.Msg = "删除失败"
  704. br.ErrMsg = "信息不存在!"
  705. return
  706. }
  707. err = cygx.DeleteIndustrialManagement(IndustrialManagementId)
  708. if err != nil {
  709. br.Msg = "删除信息失败"
  710. br.ErrMsg = "删除信息失败,Err:" + err.Error()
  711. return
  712. }
  713. br.Ret = 200
  714. br.Success = true
  715. br.Msg = "已删除"
  716. br.IsAddLog = true
  717. }
  718. // @Title 获取产业报告数量详情
  719. // @Description 获取产业报告数量详情接口
  720. // @Param IndustrialManagementId query int true "产业ID"
  721. // @Success Ret=200 {object} cygx.IndustrialManagementDetial
  722. // @router /industrialManagement/detail [get]
  723. func (this *IndustrialManagementController) Detail() {
  724. br := new(models.BaseResponse).Init()
  725. defer func() {
  726. this.Data["json"] = br
  727. this.ServeJSON()
  728. }()
  729. sysUser := this.SysUser
  730. if sysUser == nil {
  731. br.Msg = "请登录"
  732. br.ErrMsg = "请登录,SysUser Is Empty"
  733. br.Ret = 408
  734. return
  735. }
  736. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  737. if industrialManagementId < 1 {
  738. br.Msg = "请输入分类ID"
  739. return
  740. }
  741. industrialManagementInfo, err := cygx.GetindustrialManagemenById(industrialManagementId)
  742. if err != nil {
  743. br.Msg = "获取信息失败"
  744. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  745. return
  746. }
  747. listArtType, errList := cygx.GetIndustrialManagementArtTypeList(industrialManagementId)
  748. if errList != nil {
  749. br.Msg = "获取信息失败"
  750. br.ErrMsg = "获取列表信息失败,Err:" + errList.Error()
  751. return
  752. }
  753. var list []*cygx.IndustrialManagementArtTypeList
  754. mapArtType := make(map[string]*cygx.IndustrialManagementArtTypeList)
  755. for _, v := range listArtType {
  756. if mapArtType[v.MatchTypeName] == nil {
  757. mapArtType[v.MatchTypeName] = v
  758. } else {
  759. mapArtType[v.MatchTypeName].ArtNum += v.ArtNum
  760. }
  761. }
  762. for _, v := range mapArtType {
  763. list = append(list, v)
  764. }
  765. resp := new(cygx.IndustrialManagementDetial)
  766. if industrialManagementInfo.LayoutTime == utils.EmptyDateTimeStr {
  767. resp.LayoutTime = ""
  768. } else {
  769. //resultTime := utils.StrTimeToTime(industrialManagementInfo.LayoutTime) //时间字符串格式转时间格式
  770. //var oldTime string
  771. //if industrialManagementInfo.CreateTime.After(resultTime) {
  772. // oldTime = resultTime.Format(utils.FormatDateTime)
  773. //} else {
  774. // oldTime = industrialManagementInfo.CreateTime.Format(utils.FormatDateTime)
  775. //}
  776. //if industrialManagementInfo.ArtNum == 0 {
  777. // oldTime = resultTime.Format(utils.FormatDateTime)
  778. //}
  779. //resp.LayoutTime = utils.TimeRemoveHms(oldTime)
  780. resp.LayoutTime = utils.TimeRemoveHms(industrialManagementInfo.LayoutTime)
  781. }
  782. // 查研观向7.4-细分活动类型为"弘则活动"和"研选活动"
  783. //count, err := cygx.GetIndustrialManagementGroupActCount(industrialManagementId)
  784. //if err != nil {
  785. // br.Msg = "获取信息失败"
  786. // br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  787. // return
  788. //}
  789. //item := new(cygx.IndustrialManagementArtTypeList)
  790. //item.ArtNum = count
  791. //item.MatchTypeName = "相关活动"
  792. //list = append(list, item)
  793. countList, e := cygx.GetIndustryActCountGroupByType(industrialManagementId)
  794. if e != nil {
  795. br.Msg = "获取信息失败"
  796. br.ErrMsg = "获取产业关联的活动数失败, Err: " + e.Error()
  797. return
  798. }
  799. //针对研选的路演精华做单独处理 判断有没有路演精华这个类型,如果有就做相加,没有就做合并
  800. countYxLyjh, e := cygx.GetIndustrialManagementArtYxLYJH(industrialManagementId)
  801. if e != nil && e.Error() != utils.ErrNoRow() {
  802. br.Msg = "获取信息失败"
  803. br.ErrMsg = "获取产业关联的活动数失败, Err: " + e.Error()
  804. return
  805. }
  806. var haveYxLyjh bool
  807. for _, v := range list {
  808. if v.MatchTypeName == utils.CYGX_LYJH {
  809. v.ArtNum += countYxLyjh
  810. haveYxLyjh = true
  811. }
  812. }
  813. if !haveYxLyjh {
  814. lyjhCount := new(cygx.IndustrialManagementArtTypeList)
  815. lyjhCount.MatchTypeName = utils.CYGX_LYJH
  816. lyjhCount.ArtNum = countYxLyjh
  817. list = append(list, lyjhCount)
  818. }
  819. hzCount := new(cygx.IndustrialManagementArtTypeList)
  820. hzCount.MatchTypeName = utils.CYGX_ACTIVITY_TYPE_NAME_HZ
  821. yxCount := new(cygx.IndustrialManagementArtTypeList)
  822. yxCount.MatchTypeName = utils.CYGX_ACTIVITY_TYPE_NAME_YX
  823. for i := range countList {
  824. if countList[i].ActivityType == utils.CYGX_ACTIVITY_TYPE_NAME_HZ {
  825. hzCount.ArtNum = countList[i].ActivityCount
  826. }
  827. if countList[i].ActivityType == utils.CYGX_ACTIVITY_TYPE_NAME_YX {
  828. yxCount.ArtNum = countList[i].ActivityCount
  829. }
  830. }
  831. list = append(list, hzCount, yxCount)
  832. resp.ArtTotalNum = industrialManagementInfo.ArtNum
  833. resp.List = list
  834. br.Ret = 200
  835. br.Success = true
  836. br.Msg = "获取成功"
  837. br.Data = resp
  838. }
  839. // @Title 产业导出
  840. // @Description 产业导出接口
  841. // @Success 200 {object} cygx.ChartPermissionResp
  842. // @router /industrialManagement/export [get]
  843. func (this *IndustrialManagementController) ChartPermissionExport() {
  844. br := new(models.BaseResponse).Init()
  845. defer func() {
  846. this.Data["json"] = br
  847. this.ServeJSON()
  848. }()
  849. sysUser := this.SysUser
  850. if sysUser == nil {
  851. br.Msg = "请登录"
  852. br.ErrMsg = "请登录,SysUser Is Empty"
  853. return
  854. }
  855. resp := new(cygx.CanDownload)
  856. if sysUser.Authority == 1 || sysUser.Authority == 3 {
  857. resp.IsCanDownload = true
  858. }
  859. if sysUser.Role == "admin" {
  860. resp.IsCanDownload = true
  861. }
  862. if sysUser.RoleTypeCode == "rai_admin" || sysUser.RoleTypeCode == "ficc_admin" || sysUser.RoleTypeCode == "admin" {
  863. resp.IsCanDownload = true
  864. }
  865. if resp.IsCanDownload == false {
  866. br.Msg = "你没有预览权限"
  867. return
  868. }
  869. chartPermissionIdStrList, err := cygx.GetChartPermissionIdStr()
  870. if err != nil {
  871. br.Msg = "获取信息失败"
  872. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  873. return
  874. }
  875. //生成excel文件
  876. dir, err := os.Executable()
  877. exPath := filepath.Dir(dir)
  878. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  879. xlsxFile := xlsx.NewFile()
  880. if err != nil {
  881. br.Msg = "生成文件失败"
  882. br.ErrMsg = "生成文件失败"
  883. return
  884. }
  885. //普通样式
  886. style := xlsx.NewStyle()
  887. alignment := xlsx.Alignment{
  888. Horizontal: "center",
  889. Vertical: "center",
  890. WrapText: true,
  891. }
  892. //设置默认字体和文字大小
  893. xlsx.SetDefaultFont(12, "宋体")
  894. style.Alignment = alignment
  895. style.ApplyAlignment = true
  896. //标题样式
  897. titleStyle := xlsx.NewStyle()
  898. titleFont := xlsx.NewFont(20, "宋体")
  899. titleFont.Bold = true
  900. titleStyle.Font = *titleFont
  901. titleStyle.Alignment = alignment
  902. //titleStyle.ApplyAlignment = true
  903. //表头
  904. headerStyle := xlsx.NewStyle()
  905. headerFont := xlsx.NewFont(12, "宋体")
  906. headerFont.Bold = true
  907. headerStyle.Font = *headerFont
  908. headerStyle.Alignment = alignment
  909. headerStyle.ApplyAlignment = true
  910. //导入报表
  911. sheel, err := xlsxFile.AddSheet("预览报表")
  912. if err != nil {
  913. br.Msg = "新增Sheet失败"
  914. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  915. return
  916. }
  917. //设置列宽
  918. sheel.SetColWidth(0, 0, 28)
  919. sheel.SetColWidth(1, 1, 18)
  920. sheel.SetColWidth(2, 2, 18)
  921. sheel.SetColWidth(3, 3, 18)
  922. sheel.SetColWidth(4, 4, 40)
  923. //标题行
  924. titleRow := sheel.AddRow()
  925. titleRow.SetHeight(40)
  926. //标题列
  927. titleCell := titleRow.AddCell()
  928. titleCell.HMerge = 6 //向右合并列数,不包括自身列
  929. titleCell.SetValue("预览")
  930. titleCell.SetStyle(titleStyle)
  931. //表头
  932. headerRow := sheel.AddRow()
  933. headerRow.SetHeight(18)
  934. cellA := headerRow.AddCell()
  935. cellA.SetValue("行业")
  936. cellA.SetStyle(headerStyle)
  937. cellB := headerRow.AddCell()
  938. cellB.SetValue("行业报告数量")
  939. cellB.SetStyle(headerStyle)
  940. cellC := headerRow.AddCell()
  941. cellC.SetValue("产业分类")
  942. cellC.SetStyle(headerStyle)
  943. cellD := headerRow.AddCell()
  944. cellD.SetValue("推荐指数")
  945. cellD.SetStyle(headerStyle)
  946. cellE := headerRow.AddCell()
  947. cellE.SetValue("研究员")
  948. cellE.SetStyle(headerStyle)
  949. cellF := headerRow.AddCell()
  950. cellF.SetValue("覆盖标的")
  951. cellF.SetStyle(headerStyle)
  952. cellG := headerRow.AddCell()
  953. cellG.SetValue("产业报告数量")
  954. cellG.SetStyle(headerStyle)
  955. listMatchType, err := cygx.CygxReportMappingMatchTypeList()
  956. if err != nil {
  957. br.Msg = "获取失败"
  958. br.ErrMsg = "获取失败,Err:" + err.Error()
  959. return
  960. }
  961. for _, v := range chartPermissionIdStrList {
  962. if err != nil {
  963. br.Msg = "获取信息失败"
  964. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  965. return
  966. }
  967. industrialManagementList, err := cygx.GetIndustrialManagementIdStr(v.ChartPermissionId)
  968. if err != nil {
  969. br.Msg = "获取信息失败"
  970. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  971. return
  972. }
  973. matchTypeList, err := cygx.GetMatchTypeList(v.ChartPermissionId)
  974. fmt.Println(matchTypeList)
  975. if err != nil {
  976. br.Msg = "获取信息失败"
  977. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  978. return
  979. }
  980. var matchTypeStr string
  981. for _, vmatchType := range listMatchType {
  982. matchTypeStr += vmatchType.MatchTypeName + "(0),"
  983. }
  984. matchTypeStr = strings.TrimRight(matchTypeStr, ",")
  985. countReport, _ := cygx.GetchartPermissionReportNameCount(v.ChartPermissionId)
  986. chartPermissionReportName := v.MatchTypeName + "(" + strconv.Itoa(countReport) + ")"
  987. if v.ChartPermissionName == "消费" {
  988. chartPermissionReportName = "/"
  989. }
  990. if len(industrialManagementList) < 1 {
  991. dataRow := sheel.AddRow()
  992. dataRow.SetHeight(18)
  993. cellA := dataRow.AddCell()
  994. cellA.SetString(v.ChartPermissionName)
  995. cellA.SetStyle(style)
  996. cellB := dataRow.AddCell()
  997. cellB.SetString(chartPermissionReportName)
  998. cellB.SetStyle(style)
  999. cellC := dataRow.AddCell()
  1000. cellC.SetString("")
  1001. cellC.SetStyle(style)
  1002. cellD := dataRow.AddCell()
  1003. cellD.SetString("")
  1004. cellD.SetStyle(style)
  1005. cellE := dataRow.AddCell()
  1006. cellE.SetString("")
  1007. cellE.SetStyle(style)
  1008. cellF := dataRow.AddCell()
  1009. cellF.SetString("")
  1010. cellF.SetStyle(style)
  1011. cellG := dataRow.AddCell()
  1012. cellG.SetString(matchTypeStr)
  1013. cellG.SetStyle(style)
  1014. } else {
  1015. for k2, v2 := range industrialManagementList {
  1016. subList, err := cygx.GetIndustrialSubjectAll(v2.IndustrialManagementId)
  1017. if err != nil {
  1018. br.Msg = "获取信息失败"
  1019. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  1020. return
  1021. }
  1022. analystList, err := cygx.GetIndustrialAnalystAll(v2.IndustrialManagementId)
  1023. if err != nil {
  1024. br.Msg = "获取信息失败"
  1025. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  1026. return
  1027. }
  1028. var subjectNameStr string
  1029. var analystNameStr string
  1030. var reportNumStr string
  1031. for _, v3 := range subList {
  1032. if v2.IndustrialManagementId == v3.IndustrialManagementId {
  1033. subjectNameStr += v3.SubjectName + ","
  1034. }
  1035. }
  1036. for _, v3 := range analystList {
  1037. if v2.IndustrialManagementId == v3.IndustrialManagementId {
  1038. analystNameStr += v3.AnalystName + ","
  1039. }
  1040. }
  1041. for _, vMt := range listMatchType {
  1042. countRe, _ := cygx.GetReportCount(v.ChartPermissionId, v2.IndustrialManagementId, vMt.MatchTypeName)
  1043. reportNumStr += vMt.MatchTypeName + "(" + strconv.Itoa(countRe) + ")" + ","
  1044. }
  1045. industrialManagementList[k2].SubjectName = strings.TrimRight(subjectNameStr, ",")
  1046. industrialManagementList[k2].AnalystName = strings.TrimRight(analystNameStr, ",")
  1047. industrialManagementList[k2].ReportNum = strings.TrimRight(reportNumStr, ",")
  1048. }
  1049. for k4, v4 := range industrialManagementList {
  1050. dataRow := sheel.AddRow()
  1051. dataRow.SetHeight(18)
  1052. cellA := dataRow.AddCell()
  1053. cellA.SetString(v.ChartPermissionName)
  1054. if k4 < len(industrialManagementList)-1 {
  1055. cellA.VMerge = 1 // span1 向下合并1格
  1056. }
  1057. cellA.SetStyle(style)
  1058. cellB := dataRow.AddCell()
  1059. if k4 < len(industrialManagementList)-1 {
  1060. cellB.VMerge = 1 // span1 向下合并1格
  1061. }
  1062. fmt.Println(len(industrialManagementList))
  1063. cellB.SetString(chartPermissionReportName)
  1064. cellB.SetStyle(style)
  1065. cellC := dataRow.AddCell()
  1066. cellC.SetString(v4.IndustryName)
  1067. cellC.SetStyle(style)
  1068. cellD := dataRow.AddCell()
  1069. cellD.SetString(strconv.Itoa(v4.RecommendedIndex))
  1070. cellD.SetStyle(style)
  1071. cellE := dataRow.AddCell()
  1072. cellE.SetString(v4.AnalystName)
  1073. cellE.SetStyle(style)
  1074. cellF := dataRow.AddCell()
  1075. cellF.SetString(v4.SubjectName)
  1076. cellF.SetStyle(style)
  1077. cellG := dataRow.AddCell()
  1078. cellG.SetString(v4.ReportNum)
  1079. cellG.SetStyle(style)
  1080. }
  1081. }
  1082. }
  1083. err = xlsxFile.Save(downLoadnFilePath)
  1084. if err != nil {
  1085. br.Msg = "保存文件失败"
  1086. br.ErrMsg = "保存文件失败"
  1087. return
  1088. }
  1089. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1090. downloadFileName := "产业管理预览" + randStr + ".xlsx"
  1091. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1092. defer func() {
  1093. os.Remove(downLoadnFilePath)
  1094. }()
  1095. br.Ret = 200
  1096. br.Success = true
  1097. br.Msg = "导出成功"
  1098. }
  1099. // @Title 获取关联产业列表
  1100. // @Description 获取关联产业列表接口
  1101. // @Param KeyWord query string false "搜索关键词"
  1102. // @Success Ret=200 {object} cygx.GetCygxIndustrialManagementList
  1103. // @router /industrialManagement/listByName [get]
  1104. func (this *IndustrialManagementController) IndustrialManagementlistByName() {
  1105. br := new(models.BaseResponse).Init()
  1106. defer func() {
  1107. this.Data["json"] = br
  1108. this.ServeJSON()
  1109. }()
  1110. sysUser := this.SysUser
  1111. if sysUser == nil {
  1112. br.Msg = "请登录"
  1113. br.ErrMsg = "请登录,SysUser Is Empty"
  1114. br.Ret = 408
  1115. return
  1116. }
  1117. var condition string
  1118. var conditionKeyWord string
  1119. keyWord := this.GetString("KeyWord")
  1120. charInfo, err := cygx.GetCategoryInfoByName(utils.CHART_PERMISSION_NAME_MF_YANXUAN)
  1121. if err != nil {
  1122. br.Msg = "获取信息失败"
  1123. br.ErrMsg = "获取信息失败,找不到研选分类信息Err:" + err.Error()
  1124. return
  1125. }
  1126. if keyWord != "" {
  1127. condition = ` AND industry_name LIKE '%` + keyWord + `%' AND chart_permission_id = ` + strconv.Itoa(charInfo.ChartPermissionId)
  1128. } else {
  1129. condition = ` AND industrial_management_id = 0 `
  1130. }
  1131. listIndustrial, err := cygx.GetIndustrialManagement(condition)
  1132. if err != nil {
  1133. br.Msg = "获取失败"
  1134. br.ErrMsg = "获取失败,Err:" + err.Error()
  1135. return
  1136. }
  1137. for _, v := range listIndustrial {
  1138. conditionKeyWord += "'" + v.IndustryName + "',"
  1139. }
  1140. if conditionKeyWord != "" {
  1141. conditionKeyWord = strings.TrimRight(conditionKeyWord, ",")
  1142. conditionKeyWord = ` AND industry_map_name NOT IN ( ` + conditionKeyWord + `)`
  1143. }
  1144. if keyWord != "" {
  1145. condition = ` AND industry_map_name LIKE '%` + keyWord + `%' AND level = 4 ` + conditionKeyWord
  1146. } else {
  1147. condition = ` AND industry_map_id = 0 `
  1148. }
  1149. listMap, err := cygx.GetIndustrialMapListName(condition)
  1150. if err != nil {
  1151. br.Msg = "获取失败"
  1152. br.ErrMsg = "获取失败,Err:" + err.Error()
  1153. return
  1154. }
  1155. resp := new(cygx.GetCygxIndustrialManagementList)
  1156. for _, v := range listMap {
  1157. item := new(cygx.ArtGroupIndustrialManagementRep)
  1158. item.IndustryName = v.IndustryMapName
  1159. listIndustrial = append(listIndustrial, item)
  1160. }
  1161. resp.List = listIndustrial
  1162. br.Ret = 200
  1163. br.Success = true
  1164. br.Msg = "获取成功"
  1165. br.Data = resp
  1166. }
  1167. // @Title 一级分类所关联的产业列表
  1168. // @Description 获取一级分类所关联的产业列表接口
  1169. // @Success 200 {object} cygx.ChartPermissionResp
  1170. // @router /chartPermission/listIndustrial [get]
  1171. func (this *IndustrialManagementController) ListIndustrial() {
  1172. br := new(models.BaseResponse).Init()
  1173. defer func() {
  1174. this.Data["json"] = br
  1175. this.ServeJSON()
  1176. }()
  1177. list, err := cygx.GetChartPermissionAllNoTactics()
  1178. if err != nil {
  1179. br.Msg = "获取信息失败"
  1180. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  1181. return
  1182. }
  1183. for k, v := range list {
  1184. listIndustrial, err := cygx.GetIndustrialManagementAllCheckName(v.ChartPermissionId, "create_time")
  1185. if err != nil {
  1186. br.Msg = "获取信息失败"
  1187. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  1188. return
  1189. }
  1190. list[k].List = listIndustrial
  1191. }
  1192. resp := new(cygx.ChartPermissionResp)
  1193. resp.List = list
  1194. br.Ret = 200
  1195. br.Success = true
  1196. br.Msg = "获取成功"
  1197. br.Data = resp
  1198. }
  1199. // @Title 产业、标的模糊查询
  1200. // @Description 产业、标的模糊查询接口
  1201. // @Param KeyWord query string false "搜索关键词"
  1202. // @Success Ret=200 {object} cygx.GetIndustrialManagementList
  1203. // @router /industrialManagement/search [get]
  1204. func (this *IndustrialManagementController) IndustrialSearch() {
  1205. br := new(models.BaseResponse).Init()
  1206. defer func() {
  1207. this.Data["json"] = br
  1208. this.ServeJSON()
  1209. }()
  1210. sysUser := this.SysUser
  1211. if sysUser == nil {
  1212. br.Msg = "请登录"
  1213. br.ErrMsg = "请登录,SysUser Is Empty"
  1214. br.Ret = 408
  1215. return
  1216. }
  1217. keyWord := this.GetString("KeyWord")
  1218. if keyWord == "" {
  1219. br.Msg = "请输入关键词"
  1220. return
  1221. }
  1222. var condition string
  1223. if keyWord != "" {
  1224. condition += ` AND (man.industry_name LIKE '%` + keyWord + `%' ) `
  1225. }
  1226. var list []*cygx.CygxIndustrialManagementNum
  1227. var err error
  1228. var orderSrt string
  1229. orderSrt = " man.recommended_index DESC,update_time DESC"
  1230. listAddTime, err := cygx.GetIndustrialManagementAllByReportTime(condition, orderSrt)
  1231. if err != nil {
  1232. br.Msg = "获取信息失败"
  1233. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  1234. return
  1235. }
  1236. list = listAddTime
  1237. if keyWord != "" {
  1238. condition = ` AND (sub.subject_name LIKE '%` + keyWord + `%' ) GROUP BY sub.subject_name `
  1239. }
  1240. listSubject, err := cygx.GetIndustrialSubjectAllByIds(condition)
  1241. if err != nil {
  1242. br.Msg = "获取信息失败"
  1243. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  1244. return
  1245. }
  1246. for _, v := range listSubject {
  1247. item := new(cygx.CygxIndustrialManagementNum)
  1248. item.IndustryName = v.SubjectName
  1249. list = append(list, item)
  1250. }
  1251. if len(list) == 0 {
  1252. list = make([]*cygx.CygxIndustrialManagementNum, 0)
  1253. }
  1254. resp := new(cygx.GetIndustrialManagementList)
  1255. resp.List = list
  1256. br.Ret = 200
  1257. br.Success = true
  1258. br.Msg = "获取成功"
  1259. br.Data = resp
  1260. }
  1261. // @Title 移动产业
  1262. // @Description 移动产业
  1263. // @Param request body cygx.IndustryMove true "type json string"
  1264. // @Success Ret=200 string "操作成功"
  1265. // @router /industrialManagement/move [post]
  1266. func (this *IndustrialManagementController) IndustryMove() {
  1267. br := new(models.BaseResponse).Init()
  1268. defer func() {
  1269. this.Data["json"] = br
  1270. this.ServeJSON()
  1271. }()
  1272. sysUser := this.SysUser
  1273. if sysUser == nil {
  1274. br.Msg = "请登录"
  1275. br.ErrMsg = "请登录,SysUser Is Empty"
  1276. br.Ret = 408
  1277. return
  1278. }
  1279. var req cygx.IndustryMove
  1280. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1281. br.Msg = "参数解析异常!"
  1282. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  1283. return
  1284. }
  1285. if req.IndustrialManagementId <= 0 || req.ChartPermissionId <= 0 {
  1286. br.Msg = "参数有误"
  1287. return
  1288. }
  1289. item, e := cygx.GetIndustrialManagementInfo(req.IndustrialManagementId)
  1290. if e != nil {
  1291. br.Msg = "移动失败"
  1292. br.ErrMsg = "获取产业信息失败, Err: " + e.Error()
  1293. return
  1294. }
  1295. if item.ChartPermissionId == req.ChartPermissionId {
  1296. br.Msg = "产业已在该行业下, 无需移动"
  1297. return
  1298. }
  1299. updateCols := []string{"ChartPermissionId"}
  1300. item.ChartPermissionId = req.ChartPermissionId
  1301. if e = item.Update(updateCols); e != nil {
  1302. br.Msg = "移动失败"
  1303. br.ErrMsg = "更新产业信息失败, Err: " + e.Error()
  1304. return
  1305. }
  1306. br.Ret = 200
  1307. br.Success = true
  1308. br.Msg = "操作成功"
  1309. }