industrial_management.go 40 KB

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