industrial_management.go 41 KB

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