industrial_management.go 42 KB

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