mysteel_chemical_data.go 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/models/data_manage/request"
  7. "eta/eta_api/models/data_manage/response"
  8. "eta/eta_api/models/system"
  9. "eta/eta_api/services/alarm_msg"
  10. "eta/eta_api/services/data"
  11. "eta/eta_api/services/data_stat"
  12. etaTrialService "eta/eta_api/services/eta_trial"
  13. "eta/eta_api/utils"
  14. "fmt"
  15. "os"
  16. "path/filepath"
  17. "sort"
  18. "strconv"
  19. "strings"
  20. "time"
  21. "github.com/rdlucklib/rdluck_tools/paging"
  22. "github.com/tealeg/xlsx"
  23. )
  24. // MysteelChemicalClassify
  25. // @Title 上海钢联数据分类
  26. // @Description 上海钢联分类接口
  27. // @Success 200 {object} data_manage.BaseFromMysteelChemicalClassifyItems
  28. // @router /mysteel_chemical/classify [get]
  29. func (this *EdbInfoController) MysteelChemicalClassify() {
  30. br := new(models.BaseResponse).Init()
  31. defer func() {
  32. this.Data["json"] = br
  33. this.ServeJSON()
  34. }()
  35. sysUser := this.SysUser
  36. if sysUser == nil {
  37. br.Msg = "请登录"
  38. br.ErrMsg = "请登录,SysUser Is Empty"
  39. br.Ret = 408
  40. return
  41. }
  42. rootList, err := data_manage.GetBaseFromMysteelChemicalClassifyByParentId(0)
  43. if err != nil && err.Error() != utils.ErrNoRow() {
  44. br.Msg = "获取失败"
  45. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  46. return
  47. }
  48. classifyAll, err := data_manage.GetAllBaseFromMysteelChemicalClassify()
  49. if err != nil && err.Error() != utils.ErrNoRow() {
  50. br.Msg = "获取失败"
  51. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  52. return
  53. }
  54. rootChildMap := make(map[int][]*data_manage.BaseFromMysteelChemicalClassifyItems)
  55. for _, v := range classifyAll {
  56. v.UniqueCode = fmt.Sprint(v.BaseFromMysteelChemicalClassifyId)
  57. button := data.GetMysteelChemicalOpButton(sysUser, v.SysUserId)
  58. button.AddButton = false //不管有没有权限,二级分类都是没有添加按钮的
  59. v.Button = button
  60. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  61. }
  62. nodeAll := make([]*data_manage.BaseFromMysteelChemicalClassifyItems, 0)
  63. for k, v := range rootList {
  64. button := data.GetMysteelChemicalOpButton(sysUser, v.SysUserId)
  65. rootList[k].Button = button
  66. rootList[k].UniqueCode = fmt.Sprint(v.BaseFromMysteelChemicalClassifyId)
  67. if existItems, ok := rootChildMap[v.BaseFromMysteelChemicalClassifyId]; ok {
  68. v.Children = existItems
  69. } else {
  70. items := make([]*data_manage.BaseFromMysteelChemicalClassifyItems, 0)
  71. v.Children = items
  72. }
  73. nodeAll = append(nodeAll, v)
  74. }
  75. br.Ret = 200
  76. br.Success = true
  77. br.Msg = "获取成功"
  78. br.Data = nodeAll
  79. }
  80. // MysteelChemicalIndexList
  81. // @Title 上海钢联数据指标列表
  82. // @Description 上海钢联数据指标列表接口
  83. // @Success 200 {object} data_manage.BaseFromMysteelChemicalIndexResp
  84. // @router /mysteel_chemical/index/list [get]
  85. func (this *EdbInfoController) MysteelChemicalIndexList() {
  86. br := new(models.BaseResponse).Init()
  87. defer func() {
  88. this.Data["json"] = br
  89. this.ServeJSON()
  90. }()
  91. sysUser := this.SysUser
  92. if sysUser == nil {
  93. br.Msg = "请登录"
  94. br.ErrMsg = "请登录,SysUser Is Empty"
  95. br.Ret = 408
  96. return
  97. }
  98. classifyId, _ := this.GetInt("BaseFromMysteelChemicalClassifyId")
  99. if classifyId <= 0 {
  100. br.Msg = "请选择正确的分类"
  101. return
  102. }
  103. allBaseFromMysteelChemicalIndex, err := data_manage.GetMysteelChemicalIndexByClassifyId(classifyId)
  104. if err != nil && err.Error() != utils.ErrNoRow() {
  105. br.Msg = "获取失败"
  106. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  107. return
  108. }
  109. nodeAll := make([]*data_manage.BaseFromMysteelChemicalClassifyItems, 0)
  110. for _, v := range allBaseFromMysteelChemicalIndex {
  111. v.UniqueCode = fmt.Sprint(v.BaseFromMysteelChemicalClassifyId, "_", v.BaseFromMysteelChemicalIndexId)
  112. button := data.GetMysteelChemicalOpButton(sysUser, v.SysUserId)
  113. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  114. v.Button = button
  115. nodeAll = append(nodeAll, v)
  116. }
  117. ret := &data_manage.BaseFromMysteelChemicalIndexResp{
  118. List: nodeAll,
  119. }
  120. br.Ret = 200
  121. br.Success = true
  122. br.Msg = "获取成功"
  123. br.Data = ret
  124. }
  125. // AddMysteelChemicalClassify
  126. // @Title 新增分类
  127. // @Description 新增分类接口
  128. // @Param request body data_manage.AddBaseFromMysteelChemicalClassifyReq true "type json string"
  129. // @Success 200 Ret=200 保存成功
  130. // @router /mysteel_chemical/classify/add [post]
  131. func (this *EdbClassifyController) AddMysteelChemicalClassify() {
  132. br := new(models.BaseResponse).Init()
  133. defer func() {
  134. this.Data["json"] = br
  135. this.ServeJSON()
  136. }()
  137. var req request.AddBaseFromMysteelChemicalClassifyReq
  138. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  139. if err != nil {
  140. br.Msg = "参数解析异常!"
  141. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  142. return
  143. }
  144. if req.ClassifyName == "" {
  145. br.Msg = "请输入分类名称"
  146. br.IsSendEmail = false
  147. return
  148. }
  149. req.ClassifyName = utils.TrimStr(req.ClassifyName)
  150. req.ClassifyName = strings.Replace(req.ClassifyName, "/t", "", -1)
  151. //添加指标
  152. mysteelChemicalClassifyInfo, err, errMsg := data.AddMysteelChemicalClassify(req.ClassifyName, req.ParentId, req.Level, this.SysUser.AdminId, this.SysUser.RealName, this.Lang)
  153. if errMsg != `` {
  154. br.Msg = errMsg
  155. br.ErrMsg = errMsg
  156. if err != nil {
  157. br.ErrMsg = errMsg + ";Err:" + err.Error()
  158. } else {
  159. br.IsSendEmail = false
  160. }
  161. return
  162. }
  163. // 如果是添加一级分类,那么默认加上 价格、供应、需求、库存 四个二级分类
  164. if mysteelChemicalClassifyInfo.ParentId == 0 {
  165. secondClassifyList := []string{"价格", "供应", "需求", "库存"}
  166. for _, v := range secondClassifyList {
  167. _, _, tmpErrMsg := data.AddMysteelChemicalClassify(v, mysteelChemicalClassifyInfo.BaseFromMysteelChemicalClassifyId, mysteelChemicalClassifyInfo.Level, this.SysUser.AdminId, this.SysUser.RealName, this.Lang)
  168. if tmpErrMsg != `` {
  169. go alarm_msg.SendAlarmMsg("上海钢联-添加一级分类时,默认添加二级分类失败,一级分类名称:"+req.ClassifyName+",二级分类名称:"+v+", Err:"+tmpErrMsg, 3)
  170. return
  171. }
  172. }
  173. }
  174. resp := response.AddMysteelChemicalClassifyResp{
  175. BaseFromMysteelChemicalClassifyId: mysteelChemicalClassifyInfo.BaseFromMysteelChemicalClassifyId,
  176. UniqueCode: fmt.Sprint(mysteelChemicalClassifyInfo.BaseFromMysteelChemicalClassifyId),
  177. }
  178. br.Data = resp
  179. br.Ret = 200
  180. br.Msg = "保存成功"
  181. br.Success = true
  182. br.IsAddLog = true
  183. }
  184. // EditMysteelChemicalClassify
  185. // @Title 修改分类
  186. // @Description 修改分类接口
  187. // @Param request body data_manage.EditBaseFromMysteelChemicalClassifyReq true "type json string"
  188. // @Success 200 Ret=200 修改成功
  189. // @router /mysteel_chemical/classify/edit [post]
  190. func (this *EdbClassifyController) EditMysteelChemicalClassify() {
  191. br := new(models.BaseResponse).Init()
  192. defer func() {
  193. this.Data["json"] = br
  194. this.ServeJSON()
  195. }()
  196. var req request.EditBaseFromMysteelChemicalClassifyReq
  197. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  198. if err != nil {
  199. br.Msg = "参数解析异常!"
  200. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  201. return
  202. }
  203. if req.ClassifyName == "" {
  204. br.Msg = "请输入分类名称"
  205. br.IsSendEmail = false
  206. return
  207. }
  208. if req.BaseFromMysteelChemicalClassifyId <= 0 {
  209. br.Msg = "参数错误"
  210. br.IsSendEmail = false
  211. return
  212. }
  213. err, errMsg := data.EditMysteelChemicalClassify(req.BaseFromMysteelChemicalClassifyId, req.ClassifyName, this.Lang, this.SysUser)
  214. if errMsg != `` {
  215. br.Msg = errMsg
  216. br.ErrMsg = errMsg
  217. if err != nil {
  218. br.ErrMsg = errMsg + ";Err:" + err.Error()
  219. } else {
  220. br.IsSendEmail = false
  221. }
  222. return
  223. }
  224. br.Ret = 200
  225. br.Msg = "保存成功"
  226. br.Success = true
  227. br.IsAddLog = true
  228. }
  229. // MoveMysteelChemicalClassify
  230. // @Title 分类移动接口
  231. // @Description 分类移动接口
  232. // @Success 200 {object} data_manage.MoveBaseFromMysteelChemicalClassifyReq
  233. // @router /mysteel_chemical/classify/move [post]
  234. func (this *EdbClassifyController) MoveMysteelChemicalClassify() {
  235. br := new(models.BaseResponse).Init()
  236. defer func() {
  237. this.Data["json"] = br
  238. this.ServeJSON()
  239. }()
  240. sysUser := this.SysUser
  241. if sysUser == nil {
  242. br.Msg = "请登录"
  243. br.ErrMsg = "请登录,SysUser Is Empty"
  244. br.Ret = 408
  245. return
  246. }
  247. var req request.MoveBaseFromMysteelChemicalClassifyReq
  248. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  249. if err != nil {
  250. br.Msg = "参数解析异常!"
  251. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  252. return
  253. }
  254. if req.BaseFromMysteelChemicalClassifyId <= 0 {
  255. br.Msg = "参数错误"
  256. br.ErrMsg = "分类id小于等于0"
  257. br.IsSendEmail = false
  258. return
  259. }
  260. err, errMsg := data.MoveMysteelChemicalClassify(req.BaseFromMysteelChemicalClassifyId, req.ParentBaseFromMysteelChemicalClassifyId, req.PrevBaseFromMysteelChemicalClassifyId, req.NextBaseFromMysteelChemicalClassifyId, this.SysUser)
  261. if errMsg != `` {
  262. br.Msg = errMsg
  263. br.ErrMsg = errMsg
  264. if err != nil {
  265. br.ErrMsg = err.Error()
  266. } else {
  267. br.IsSendEmail = false
  268. }
  269. return
  270. }
  271. br.Ret = 200
  272. br.Success = true
  273. br.IsAddLog = true
  274. br.Msg = "移动成功"
  275. }
  276. // DeleteMysteelChemicalClassify
  277. // @Title 删除分类
  278. // @Description 删除分类接口
  279. // @Param request body data_manage.DelBaseFromMysteelChemicalClassifyReq true "type json string"
  280. // @Success 200 Ret=200 删除成功
  281. // @router /mysteel_chemical/classify/del [post]
  282. func (this *EdbClassifyController) DeleteMysteelChemicalClassify() {
  283. br := new(models.BaseResponse).Init()
  284. defer func() {
  285. this.Data["json"] = br
  286. this.ServeJSON()
  287. }()
  288. var req request.DelBaseFromMysteelChemicalClassifyReq
  289. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  290. if err != nil {
  291. br.Msg = "参数解析异常!"
  292. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  293. return
  294. }
  295. if req.BaseFromMysteelChemicalClassifyId < 0 {
  296. br.Msg = "参数错误"
  297. br.IsSendEmail = false
  298. return
  299. }
  300. err, errMsg := data.DelMysteelChemicalClassify(req.BaseFromMysteelChemicalClassifyId, this.SysUser)
  301. if errMsg != `` {
  302. br.Msg = errMsg
  303. br.ErrMsg = errMsg
  304. if err != nil {
  305. br.ErrMsg = errMsg + ";Err:" + err.Error()
  306. } else {
  307. br.IsSendEmail = false
  308. }
  309. return
  310. }
  311. br.Ret = 200
  312. br.Msg = "删除成功"
  313. br.Success = true
  314. br.IsAddLog = true
  315. }
  316. // MysteelChemicalSearch
  317. // @Title 上海钢联指标查询
  318. // @Description 上海钢联指标查询
  319. // @Param BaseFromMysteelChemicalClassifyId query int true "分类id"
  320. // @Param Keyword query string true "名称关键词"
  321. // @Success 200 {object} data_manage.LzFrequency
  322. // @router /mysteel_chemical/search [get]
  323. func (this *EdbInfoController) MysteelChemicalSearch() {
  324. br := new(models.BaseResponse).Init()
  325. defer func() {
  326. this.Data["json"] = br
  327. this.ServeJSON()
  328. }()
  329. sysUser := this.SysUser
  330. if sysUser == nil {
  331. br.Msg = "请登录"
  332. br.ErrMsg = "请登录,SysUser Is Empty"
  333. br.Ret = 408
  334. return
  335. }
  336. classifyId, _ := this.GetInt("BaseFromMysteelChemicalClassifyId")
  337. var condition string
  338. var pars []interface{}
  339. if classifyId > 0 {
  340. condition += " AND base_from_mysteel_chemical_classify_id=? "
  341. pars = append(pars, classifyId)
  342. }
  343. keyword := this.GetString("Keyword")
  344. if keyword != `` {
  345. condition += " AND (index_name like ? OR index_code like ?) "
  346. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  347. }
  348. list, err := data_manage.GetMysteelChemicalIndex(condition, pars)
  349. if err != nil {
  350. br.Msg = "获取失败"
  351. br.ErrMsg = "获取失败,Err:" + err.Error()
  352. return
  353. }
  354. classifyIds := make([]int, 0)
  355. for _, v := range list {
  356. v.UniqueCode = fmt.Sprint(v.BaseFromMysteelChemicalClassifyId, "_", v.Id)
  357. if v.BaseFromMysteelChemicalClassifyId > 0 {
  358. classifyIds = append(classifyIds, v.BaseFromMysteelChemicalClassifyId)
  359. }
  360. }
  361. if len(classifyIds) > 0 {
  362. // 查询父级分类信息
  363. classifyList, e := data_manage.GetBaseFromMysteelChemicalClassifyByIds(classifyIds)
  364. if e != nil {
  365. br.Msg = "获取目录信息失败"
  366. br.ErrMsg = "获取失获取目录信息失败,Err:" + err.Error()
  367. return
  368. }
  369. classifyListMap := make(map[int]int, 0)
  370. for _, v := range classifyList {
  371. classifyListMap[v.BaseFromMysteelChemicalClassifyId] = v.ParentId
  372. }
  373. for _, v := range list {
  374. v.UniqueCode = fmt.Sprint(v.BaseFromMysteelChemicalClassifyId, "_", v.Id)
  375. if p, ok := classifyListMap[v.BaseFromMysteelChemicalClassifyId]; ok {
  376. v.ParentClassifyId = p
  377. }
  378. }
  379. }
  380. br.Ret = 200
  381. br.Success = true
  382. br.Msg = "获取成功"
  383. br.Data = list
  384. }
  385. // MysteelChemicalFrequency
  386. // @Title 上海钢联数据频度
  387. // @Description 上海钢联数据频度接口
  388. // @Param BaseFromMysteelChemicalClassifyId query int true "分类id"
  389. // @Param BaseFromMysteelChemicalIndexId query int true "上海钢联指标id"
  390. // @Param Keyword query string true "名称关键词"
  391. // @Success 200 {object} data_manage.LzFrequency
  392. // @router /mysteel_chemical/frequency [get]
  393. func (this *EdbInfoController) MysteelChemicalFrequency() {
  394. br := new(models.BaseResponse).Init()
  395. defer func() {
  396. this.Data["json"] = br
  397. this.ServeJSON()
  398. }()
  399. sysUser := this.SysUser
  400. if sysUser == nil {
  401. br.Msg = "请登录"
  402. br.ErrMsg = "请登录,SysUser Is Empty"
  403. br.Ret = 408
  404. return
  405. }
  406. var condition string
  407. var pars []interface{}
  408. var classifyId int
  409. var frequency string
  410. // 指定指标
  411. indexId, _ := this.GetInt("BaseFromMysteelChemicalIndexId")
  412. if indexId > 0 {
  413. condition += " AND base_from_mysteel_chemical_index_id = ? "
  414. pars = append(pars, indexId)
  415. } else {
  416. classifyId, _ = this.GetInt("BaseFromMysteelChemicalClassifyId")
  417. if classifyId <= 0 {
  418. br.Msg = "请选择分类"
  419. br.ErrMsg = "请选择分类"
  420. return
  421. }
  422. }
  423. if classifyId > 0 {
  424. condition += " AND base_from_mysteel_chemical_classify_id=? "
  425. pars = append(pars, classifyId)
  426. }
  427. if frequency != `` {
  428. condition += " AND frequency=? "
  429. pars = append(pars, frequency)
  430. }
  431. // 关键词搜索
  432. keyword := this.GetString("Keyword")
  433. if keyword != `` {
  434. condition += " AND (index_name like ? OR index_code like ?) "
  435. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  436. }
  437. edbFrequencyList := make([]string, 0)
  438. frequencyList, err := data_manage.GetMysteelChemicalFrequency(condition, pars)
  439. for _, unit := range frequencyList {
  440. edbFrequencyList = append(edbFrequencyList, unit.Frequency)
  441. }
  442. edbFrequencyList = sortEdbFrequency(edbFrequencyList)
  443. for i, v := range edbFrequencyList {
  444. frequencyList[i].Frequency = v
  445. }
  446. if err != nil {
  447. br.Msg = "获取频度失败"
  448. br.ErrMsg = "获取频度失败,Err:" + err.Error()
  449. return
  450. }
  451. br.Ret = 200
  452. br.Success = true
  453. br.Msg = "获取成功"
  454. br.Data = frequencyList
  455. }
  456. // MysteelChemicalData
  457. // @Title 获取上海钢联数据
  458. // @Description 获取上海钢联数据
  459. // @Param BaseFromMysteelChemicalClassifyId query int true "分类id"
  460. // @Param BaseFromMysteelChemicalIndexId query int true "上海钢联指标id"
  461. // @Param Frequency query string true "频度名称"
  462. // @Param Keyword query string true "名称关键词"
  463. // @Param PageSize query int true "每页数据条数"
  464. // @Param CurrentIndex query int true "当前页页码,从1开始"
  465. // @Success 200 {object} data_manage.LzFrequency
  466. // @router /mysteel_chemical/data [get]
  467. func (this *EdbInfoController) MysteelChemicalData() {
  468. br := new(models.BaseResponse).Init()
  469. defer func() {
  470. this.Data["json"] = br
  471. this.ServeJSON()
  472. }()
  473. sysUser := this.SysUser
  474. if sysUser == nil {
  475. br.Msg = "请登录"
  476. br.ErrMsg = "请登录,SysUser Is Empty"
  477. br.Ret = 408
  478. return
  479. }
  480. pageSize, _ := this.GetInt("PageSize")
  481. currentIndex, _ := this.GetInt("CurrentIndex")
  482. var startSize int
  483. if pageSize <= 0 {
  484. pageSize = utils.PageSize20
  485. }
  486. if currentIndex <= 0 {
  487. currentIndex = 1
  488. }
  489. startSize = utils.StartIndex(currentIndex, pageSize)
  490. var condition string
  491. var pars []interface{}
  492. var classifyId int
  493. var frequency string
  494. // 指定指标
  495. indexId, _ := this.GetInt("BaseFromMysteelChemicalIndexId")
  496. if indexId > 0 {
  497. condition += " AND base_from_mysteel_chemical_index_id = ? "
  498. pars = append(pars, indexId)
  499. } else {
  500. classifyId, _ = this.GetInt("BaseFromMysteelChemicalClassifyId")
  501. if classifyId <= 0 {
  502. br.Msg = "请选择分类"
  503. br.ErrMsg = "请选择分类"
  504. br.IsSendEmail = false
  505. return
  506. }
  507. frequency = this.GetString("Frequency")
  508. if frequency == "" {
  509. br.Msg = "请选择频度"
  510. br.ErrMsg = "请选择频度"
  511. br.IsSendEmail = false
  512. return
  513. }
  514. }
  515. if classifyId > 0 {
  516. condition += " AND base_from_mysteel_chemical_classify_id=? "
  517. pars = append(pars, classifyId)
  518. }
  519. if frequency != `` {
  520. condition += " AND frequency=? "
  521. pars = append(pars, frequency)
  522. }
  523. // 关键词搜索
  524. keyword := this.GetString("Keyword")
  525. if keyword != `` {
  526. condition += " AND (index_name like ? OR index_code like ?) "
  527. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  528. }
  529. //获取指标
  530. list, err := data_manage.GetMysteelChemicalIndex(condition, pars)
  531. if err != nil {
  532. br.Msg = "获取数据失败"
  533. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  534. return
  535. }
  536. for k, v := range list {
  537. total, err := data_manage.GetMysteelChemicalIndexDataCount(v.IndexCode)
  538. page := paging.GetPaging(currentIndex, pageSize, total)
  539. dataList, err := data_manage.GetMysteelChemicalIndexData(v.IndexCode, startSize, pageSize)
  540. if err != nil {
  541. br.Msg = "获取数据失败"
  542. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  543. return
  544. }
  545. if dataList == nil {
  546. dataList = make([]*data_manage.MysteelChemicalData, 0)
  547. }
  548. edbInfo, err := data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, v.IndexCode)
  549. if err != nil && err.Error() != utils.ErrNoRow() {
  550. br.Msg = "获取数据失败"
  551. br.ErrMsg = "获取指标库统计数据失败,Err:" + err.Error()
  552. return
  553. }
  554. if edbInfo == nil {
  555. list[k].EdbInfoId = 0
  556. } else {
  557. list[k].EdbInfoId = edbInfo.EdbInfoId
  558. }
  559. list[k].DataList = dataList
  560. list[k].Paging = page
  561. }
  562. br.Ret = 200
  563. br.Success = true
  564. br.Msg = "获取成功"
  565. br.Data = list
  566. }
  567. // MysteelChemicalExport
  568. // @Title 导出上海钢联数据
  569. // @Description 导出上海钢联数据
  570. // @Param BaseFromMysteelChemicalClassifyId query int true "分类"
  571. // @Param BaseFromMysteelChemicalIndexId query string true "上海钢联指标id"
  572. // @Param Keyword query string true "名称关键词"
  573. // @Success 200 导出成功
  574. // @router /mysteel_chemical/export/dataList [get]
  575. func (this *EdbClassifyController) MysteelChemicalExport() {
  576. br := new(models.BaseResponse).Init()
  577. defer func() {
  578. this.Data["json"] = br
  579. this.ServeJSON()
  580. }()
  581. sysUser := this.SysUser
  582. if sysUser == nil {
  583. br.Msg = "请重新登录"
  584. return
  585. }
  586. classifyId, _ := this.GetInt("BaseFromMysteelChemicalClassifyId") //分类
  587. frequency := this.GetString("Frequency")
  588. dir, _ := os.Executable()
  589. exPath := filepath.Dir(dir)
  590. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  591. xlsxFile := xlsx.NewFile()
  592. var condition string
  593. var pars []interface{}
  594. indexId, _ := this.GetInt("BaseFromMysteelChemicalIndexId")
  595. if indexId > 0 {
  596. condition += " AND base_from_mysteel_chemical_index_id = ? "
  597. pars = append(pars, indexId)
  598. }
  599. if classifyId > 0 {
  600. condition += " AND base_from_mysteel_chemical_classify_id=? "
  601. pars = append(pars, classifyId)
  602. }
  603. if frequency != `` {
  604. condition += " AND frequency=? "
  605. pars = append(pars, frequency)
  606. }
  607. // 关键词搜索
  608. keyword := this.GetString("Keyword")
  609. if keyword != `` {
  610. condition += " AND (index_name like ? OR index_code like ?) "
  611. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  612. }
  613. var frequencies []string
  614. frequencieSet := make(map[string]struct{})
  615. frequencyList, err := data_manage.GetMysteelChemicalFrequency(condition, pars)
  616. if err != nil {
  617. br.Msg = "获取频度失败"
  618. br.ErrMsg = "获取频度失败,Err:" + err.Error()
  619. return
  620. }
  621. for _, v := range frequencyList {
  622. if _, ok := frequencieSet[v.Frequency]; !ok {
  623. frequencies = append(frequencies, v.Frequency)
  624. frequencieSet[v.Frequency] = struct{}{}
  625. }
  626. }
  627. secNameList := make([]*data_manage.MysteelChemicalList, 0)
  628. for _, frequency := range frequencies {
  629. //获取指标
  630. var tmpCondition string
  631. var tmpPars []interface{}
  632. if indexId > 0 {
  633. tmpCondition += " AND base_from_mysteel_chemical_index_id = ? "
  634. tmpPars = append(pars, indexId)
  635. }
  636. if classifyId > 0 {
  637. tmpCondition += " AND base_from_mysteel_chemical_classify_id=? "
  638. tmpPars = append(pars, classifyId)
  639. }
  640. if frequency != `` {
  641. tmpCondition += " AND frequency=? "
  642. tmpPars = append(pars, frequency)
  643. }
  644. // 关键词搜索
  645. keyword := this.GetString("Keyword")
  646. if keyword != `` {
  647. tmpCondition += " AND (index_name like ? OR index_code like ?) "
  648. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  649. }
  650. //获取指标
  651. secNameList, err = data_manage.GetMysteelChemicalIndex(tmpCondition, tmpPars)
  652. if err != nil {
  653. fmt.Println("获取数据失败,Err:" + err.Error())
  654. return
  655. }
  656. if len(secNameList) <= 0 {
  657. fmt.Println("secNameList长度为0")
  658. return
  659. }
  660. sheetNew, err := xlsxFile.AddSheet(frequency)
  661. if err != nil {
  662. fmt.Println("新增Sheet失败", err.Error())
  663. return
  664. }
  665. //sheetNew.SetColWidth()
  666. //获取指标数据
  667. windRow := sheetNew.AddRow()
  668. secNameRow := sheetNew.AddRow()
  669. indexCodeRow := sheetNew.AddRow()
  670. frequencyRow := sheetNew.AddRow()
  671. unitRow := sheetNew.AddRow()
  672. lastModifyDateRow := sheetNew.AddRow()
  673. var indexIdList []int
  674. for _, sv := range secNameList {
  675. indexIdList = append(indexIdList, sv.Id)
  676. }
  677. dataTimeList, err := data_manage.GetBaseFromMysteelChemicalDataTimeByIndexId(indexIdList)
  678. if err != nil {
  679. fmt.Println("获取数据时间失败", err.Error())
  680. return
  681. }
  682. //获取分类下指标最大数据量
  683. setRowIndex := 6
  684. for rk, dv := range dataTimeList {
  685. rowIndex := setRowIndex + rk
  686. row := sheetNew.Row(rowIndex)
  687. displayDate, _ := time.Parse(utils.FormatDate, dv)
  688. displayDateCell := row.AddCell()
  689. style := new(xlsx.Style)
  690. style.ApplyAlignment = true
  691. style.Alignment.WrapText = true
  692. displayDateCell.SetStyle(style)
  693. displayDateCell.SetDate(displayDate)
  694. }
  695. for k, sv := range secNameList {
  696. //获取数据
  697. dataList, err := data_manage.GetMysteelChemicalIndexDataByCode(sv.IndexCode)
  698. if err != nil {
  699. br.Msg = "获取数据失败"
  700. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  701. return
  702. }
  703. if k == 0 {
  704. windRow.AddCell().SetValue("钢联")
  705. secNameRow.AddCell().SetValue("指标名称")
  706. indexCodeRow.AddCell().SetValue("指标ID")
  707. frequencyRow.AddCell().SetValue("频率")
  708. unitRow.AddCell().SetValue("单位")
  709. lastModifyDateRow.AddCell().SetValue("更新时间")
  710. }
  711. if len(dataList) == 0 {
  712. continue
  713. }
  714. secNameRow.AddCell().SetValue(sv.IndexName)
  715. indexCodeRow.AddCell().SetValue(sv.IndexCode)
  716. frequencyRow.AddCell().SetValue(sv.FrequencyName)
  717. unitRow.AddCell().SetValue(sv.UnitName)
  718. lastModifyDateRow.AddCell().SetValue(sv.UpdateTime)
  719. dataInfoMap := make(map[string]*data_manage.MysteelChemicalData)
  720. for _, dv := range dataList {
  721. dataInfoMap[dv.DataTime] = dv
  722. }
  723. for rk, dtv := range dataTimeList {
  724. rowIndex := setRowIndex + rk
  725. row := sheetNew.Row(rowIndex)
  726. displayDateCell := row.AddCell()
  727. tmpData, ok := dataInfoMap[dtv]
  728. if ok {
  729. displayDateCell.SetValue(tmpData.InputValue)
  730. }
  731. }
  732. }
  733. }
  734. err = xlsxFile.Save(downLoadnFilePath)
  735. if err != nil {
  736. //有指标无数据时先导出一遍空表
  737. sheet, err := xlsxFile.AddSheet("无数据")
  738. if err != nil {
  739. br.Msg = "新增Sheet失败"
  740. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  741. return
  742. }
  743. rowSecName := sheet.AddRow()
  744. celSecName := rowSecName.AddCell()
  745. celSecName.SetValue("")
  746. err = xlsxFile.Save(downLoadnFilePath)
  747. if err != nil {
  748. br.Msg = "保存文件失败"
  749. br.ErrMsg = "保存文件失败"
  750. return
  751. }
  752. }
  753. fileName := "上海钢联"
  754. fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
  755. this.Ctx.Output.Download(downLoadnFilePath, fileName)
  756. defer func() {
  757. os.Remove(downLoadnFilePath)
  758. }()
  759. br.Ret = 200
  760. br.Success = true
  761. br.Msg = "success"
  762. }
  763. // AddMysteelChemical
  764. // @Title 新增上海钢联指标
  765. // @Description 新增上海钢联指标接口
  766. // @Param request body data_manage.AddEdbClassifyReq true "type json string"
  767. // @Success 200 Ret=200 保存成功
  768. // @router /mysteel_chemical/add [post]
  769. func (this *EdbClassifyController) AddMysteelChemical() {
  770. br := new(models.BaseResponse).Init()
  771. defer func() {
  772. this.Data["json"] = br
  773. this.ServeJSON()
  774. }()
  775. var req request.AddBaseFromMysteelChemicalReq
  776. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  777. if err != nil {
  778. br.Msg = "参数解析异常!"
  779. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  780. return
  781. }
  782. resp := new(response.AddMysteelChemicalIndexInfoResp)
  783. conf, err := models.GetBusinessConf()
  784. if err != nil {
  785. br.Msg = "添加指标失败"
  786. br.ErrMsg = "获取业务配置失败,Err:" + err.Error()
  787. return
  788. }
  789. // 判断上海钢联的数据刷新方式
  790. if conf["MySteelDataMethod"] == "api" {
  791. if len(req.List) > 150 {
  792. br.Msg = "添加指标失败,指标数量不能超过150条"
  793. return
  794. }
  795. ok, errMsg, err := data.HealthCheckMysteelChemicalApi()
  796. if err != nil {
  797. br.Msg = "添加指标失败"
  798. br.ErrMsg = "上海钢联数据接口异常,Err:" + err.Error()
  799. return
  800. }
  801. if !ok {
  802. br.Msg = errMsg
  803. return
  804. }
  805. addMySteelList := make([]*data_manage.BaseFromMysteelChemicalIndex, 0)
  806. for _, v := range req.List {
  807. if v.IndexCode == "" {
  808. br.Msg = "请输入指标ID"
  809. br.IsSendEmail = false
  810. return
  811. }
  812. if v.BaseFromMysteelChemicalClassifyId <= 0 {
  813. br.Msg = "请选择分类"
  814. br.IsSendEmail = false
  815. return
  816. }
  817. var updateTime1, updateTime2 string
  818. if v.UpdateTime != `` {
  819. updateTimeList := strings.Split(v.UpdateTime, ",")
  820. updateTime1 = updateTimeList[0]
  821. if len(updateTimeList) > 1 {
  822. updateTime2 = updateTimeList[1]
  823. }
  824. }
  825. v.IndexCode = utils.TrimStr(v.IndexCode)
  826. v.IndexCode = strings.Replace(v.IndexCode, "\t", "", -1)
  827. addMySteelList = append(addMySteelList, &data_manage.BaseFromMysteelChemicalIndex{
  828. BaseFromMysteelChemicalClassifyId: v.BaseFromMysteelChemicalClassifyId,
  829. IndexCode: strings.ToUpper(v.IndexCode),
  830. IndexName: "",
  831. Unit: "",
  832. Frequency: "",
  833. StartDate: "",
  834. EndDate: "",
  835. Describe: "",
  836. Source: "api",
  837. TerminalCode: "",
  838. UpdateWeek: v.UpdateWeek,
  839. UpdateTime: updateTime1,
  840. UpdateTime2: updateTime2,
  841. SysUserId: this.SysUser.AdminId,
  842. SysUserRealName: this.SysUser.RealName,
  843. ModifyTime: time.Now(),
  844. CreateTime: time.Now(),
  845. })
  846. }
  847. mySteelChemicalIndexInfos, err, errMsg := data.BatchAddMysteelChemicalIndex(addMySteelList, this.Lang)
  848. if err != nil {
  849. br.Msg = errMsg
  850. br.ErrMsg = errMsg + ";Err:" + err.Error()
  851. return
  852. }
  853. if len(mySteelChemicalIndexInfos) > 0 {
  854. resp.BaseFromMysteelChemicalIndexId = mySteelChemicalIndexInfos[0].BaseFromMysteelChemicalIndexId
  855. resp.IndexCode = mySteelChemicalIndexInfos[0].IndexCode
  856. resp.UniqueCode = fmt.Sprint(mySteelChemicalIndexInfos[0].BaseFromMysteelChemicalClassifyId, "_", mySteelChemicalIndexInfos[0].BaseFromMysteelChemicalIndexId)
  857. }
  858. for _, v := range mySteelChemicalIndexInfos {
  859. err = utils.Rc.LPush(utils.CACHE_MYSTEEL_CHEMICAL_ADD_DATA, v.IndexCode)
  860. if err != nil {
  861. br.Msg = "添加指标失败" + v.IndexCode
  862. br.ErrMsg = "添加指标缓存失败" + v.IndexCode + ";Err:" + err.Error()
  863. return
  864. }
  865. }
  866. } else {
  867. for i, v := range req.List {
  868. if v.IndexCode == "" {
  869. br.Msg = "请输入指标ID"
  870. br.IsSendEmail = false
  871. return
  872. }
  873. if v.BaseFromMysteelChemicalClassifyId <= 0 {
  874. br.Msg = "请选择分类"
  875. br.IsSendEmail = false
  876. return
  877. }
  878. v.IndexCode = utils.TrimStr(v.IndexCode)
  879. v.IndexCode = strings.Replace(v.IndexCode, "\t", "", -1)
  880. //添加指标
  881. mysteelChemicalIndexInfo, err, errMsg := data.AddMysteelChemicalIndex(v.BaseFromMysteelChemicalClassifyId, strings.ToUpper(v.IndexCode), v.UpdateWeek, v.UpdateTime, this.SysUser.AdminId, this.SysUser.RealName, this.Lang)
  882. if errMsg != `` {
  883. br.Msg = errMsg
  884. br.ErrMsg = errMsg
  885. if err != nil {
  886. br.ErrMsg = errMsg + ";Err:" + err.Error()
  887. } else {
  888. br.IsSendEmail = false
  889. }
  890. return
  891. }
  892. if i == 0 {
  893. resp.BaseFromMysteelChemicalIndexId = mysteelChemicalIndexInfo.BaseFromMysteelChemicalIndexId
  894. resp.IndexCode = mysteelChemicalIndexInfo.IndexCode
  895. resp.UniqueCode = fmt.Sprint(mysteelChemicalIndexInfo.BaseFromMysteelChemicalClassifyId, "_", mysteelChemicalIndexInfo.BaseFromMysteelChemicalIndexId)
  896. }
  897. }
  898. }
  899. br.Data = resp
  900. br.Ret = 200
  901. br.Msg = "保存成功"
  902. br.Success = true
  903. br.IsAddLog = true
  904. }
  905. func sortEdbFrequency(frequencyList []string) (newFrequencyList []string) {
  906. var frequencyMap1 = map[string]int{
  907. "日度": 1,
  908. "周度": 2,
  909. "旬度": 3,
  910. "月度": 4,
  911. "季度": 5,
  912. "半年度": 6,
  913. "年度": 7,
  914. }
  915. var frequencyMap2 = map[int]string{
  916. 1: "日度",
  917. 2: "周度",
  918. 3: "旬度",
  919. 4: "月度",
  920. 5: "季度",
  921. 6: "半年度",
  922. 7: "年度",
  923. }
  924. idList := make([]int, 0)
  925. for _, frequency := range frequencyList {
  926. idList = append(idList, frequencyMap1[frequency])
  927. }
  928. sort.Ints(idList)
  929. for _, id := range idList {
  930. newFrequencyList = append(newFrequencyList, frequencyMap2[id])
  931. }
  932. return
  933. }
  934. // EditMysteelChemical
  935. // @Title 编辑上海钢联指标
  936. // @Description 新增上海钢联指标接口
  937. // @Param request body data_manage.AddEdbClassifyReq true "type json string"
  938. // @Success 200 Ret=200 保存成功
  939. // @router /mysteel_chemical/edit [post]
  940. func (this *EdbClassifyController) EditMysteelChemical() {
  941. br := new(models.BaseResponse).Init()
  942. defer func() {
  943. this.Data["json"] = br
  944. this.ServeJSON()
  945. }()
  946. var req request.AddBaseFromMysteelChemicalReqItem
  947. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  948. if err != nil {
  949. br.Msg = "参数解析异常!"
  950. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  951. return
  952. }
  953. if req.BaseFromMysteelChemicalIndexId <= 0 {
  954. br.Msg = "请选择指标"
  955. br.IsSendEmail = false
  956. return
  957. }
  958. if req.BaseFromMysteelChemicalClassifyId <= 0 {
  959. br.Msg = "请选择分类"
  960. br.IsSendEmail = false
  961. return
  962. }
  963. //编辑指标
  964. mysteelChemicalIndexInfo, err, errMsg := data.EditMysteelChemicalIndex(req.BaseFromMysteelChemicalIndexId, req.BaseFromMysteelChemicalClassifyId, req.UpdateWeek, req.UpdateTime, this.SysUser)
  965. if errMsg != `` {
  966. br.Msg = errMsg
  967. br.ErrMsg = errMsg
  968. if err != nil {
  969. br.ErrMsg = errMsg + ";Err:" + err.Error()
  970. } else {
  971. br.IsSendEmail = false
  972. }
  973. return
  974. }
  975. resp := response.AddMysteelChemicalIndexInfoResp{
  976. BaseFromMysteelChemicalIndexId: mysteelChemicalIndexInfo.BaseFromMysteelChemicalIndexId,
  977. IndexCode: mysteelChemicalIndexInfo.IndexCode,
  978. UniqueCode: fmt.Sprint(mysteelChemicalIndexInfo.BaseFromMysteelChemicalClassifyId, "_", mysteelChemicalIndexInfo.BaseFromMysteelChemicalIndexId),
  979. }
  980. br.Data = resp
  981. br.Ret = 200
  982. br.Msg = "保存成功"
  983. br.Success = true
  984. br.IsAddLog = true
  985. }
  986. // DeleteMysteelChemical
  987. // @Title 删除指标
  988. // @Description 删除指标接口
  989. // @Param request body data_manage.DelBaseFromMysteelChemicalReq true "type json string"
  990. // @Success 200 Ret=200 删除成功
  991. // @router /mysteel_chemical/del [post]
  992. func (this *EdbClassifyController) DeleteMysteelChemical() {
  993. br := new(models.BaseResponse).Init()
  994. defer func() {
  995. this.Data["json"] = br
  996. this.ServeJSON()
  997. }()
  998. var req request.DelBaseFromMysteelChemicalReq
  999. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1000. if err != nil {
  1001. br.Msg = "参数解析异常!"
  1002. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1003. return
  1004. }
  1005. if req.BaseFromMysteelChemicalIndexId < 0 {
  1006. br.Msg = "参数错误"
  1007. br.IsSendEmail = false
  1008. return
  1009. }
  1010. err, errMsg := data.DelMysteelChemical(req.BaseFromMysteelChemicalIndexId, this.SysUser)
  1011. if errMsg != `` {
  1012. br.Msg = errMsg
  1013. br.ErrMsg = errMsg
  1014. if err != nil {
  1015. br.ErrMsg = errMsg + ";Err:" + err.Error()
  1016. } else {
  1017. br.IsSendEmail = false
  1018. }
  1019. return
  1020. }
  1021. br.Ret = 200
  1022. br.Msg = "删除成功"
  1023. br.Success = true
  1024. br.IsAddLog = true
  1025. }
  1026. // MoveMysteelChemical
  1027. // @Title 指标移动接口
  1028. // @Description 分类移动接口
  1029. // @Success 200 {object} data_manage.MoveBaseFromMysteelChemicalReq
  1030. // @router /mysteel_chemical/move [post]
  1031. func (this *EdbClassifyController) MoveMysteelChemical() {
  1032. br := new(models.BaseResponse).Init()
  1033. defer func() {
  1034. this.Data["json"] = br
  1035. this.ServeJSON()
  1036. }()
  1037. sysUser := this.SysUser
  1038. if sysUser == nil {
  1039. br.Msg = "请登录"
  1040. br.ErrMsg = "请登录,SysUser Is Empty"
  1041. br.Ret = 408
  1042. return
  1043. }
  1044. var req request.MoveBaseFromMysteelChemicalReq
  1045. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1046. if err != nil {
  1047. br.Msg = "参数解析异常!"
  1048. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1049. return
  1050. }
  1051. if req.BaseFromMysteelChemicalIndexId <= 0 {
  1052. br.Msg = "参数错误"
  1053. br.ErrMsg = "指标id小于等于0"
  1054. br.IsSendEmail = false
  1055. return
  1056. }
  1057. if req.BaseFromMysteelChemicalClassifyId <= 0 {
  1058. br.Msg = "请选择分类"
  1059. br.ErrMsg = "请选择分类"
  1060. br.IsSendEmail = false
  1061. return
  1062. }
  1063. err, errMsg := data.MoveMysteelChemical(req.BaseFromMysteelChemicalIndexId, req.BaseFromMysteelChemicalClassifyId, req.PrevBaseFromMysteelChemicalIndexId, req.NextBaseFromMysteelChemicalIndexId, this.SysUser)
  1064. if errMsg != `` {
  1065. br.Msg = errMsg
  1066. br.ErrMsg = errMsg
  1067. if err != nil {
  1068. br.ErrMsg = err.Error()
  1069. } else {
  1070. br.IsSendEmail = false
  1071. }
  1072. return
  1073. }
  1074. br.Ret = 200
  1075. br.Success = true
  1076. br.IsAddLog = true
  1077. br.Msg = "移动成功"
  1078. }
  1079. // MysteelChemicalDetail
  1080. // @Title 上海钢联指标详情
  1081. // @Description 上海钢联指标详情接口
  1082. // @Param BaseFromMysteelChemicalIndexId query string true "上海钢联指标id"
  1083. // @Success 200 {object} data_manage.BaseFromMysteelChemicalClassifyItems
  1084. // @router /mysteel_chemical/detail [get]
  1085. func (this *EdbInfoController) MysteelChemicalDetail() {
  1086. br := new(models.BaseResponse).Init()
  1087. defer func() {
  1088. this.Data["json"] = br
  1089. this.ServeJSON()
  1090. }()
  1091. sysUser := this.SysUser
  1092. if sysUser == nil {
  1093. br.Msg = "请登录"
  1094. br.ErrMsg = "请登录,SysUser Is Empty"
  1095. br.Ret = 408
  1096. return
  1097. }
  1098. indexId, _ := this.GetInt("BaseFromMysteelChemicalIndexId")
  1099. if indexId <= 0 {
  1100. br.Msg = "请选择指标"
  1101. br.IsSendEmail = false
  1102. return
  1103. }
  1104. item, err := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId)
  1105. if err != nil {
  1106. br.Msg = "获取失败"
  1107. br.ErrMsg = "获取失败,Err:" + err.Error()
  1108. }
  1109. if item.UpdateTime2 != `` {
  1110. item.UpdateTime = item.UpdateTime + "," + item.UpdateTime2
  1111. }
  1112. br.Ret = 200
  1113. br.Success = true
  1114. br.Msg = "获取成功"
  1115. br.Data = item
  1116. }
  1117. // MysteelChemicalDetail
  1118. // @Title 上海钢联指标详情
  1119. // @Description 上海钢联指标详情接口
  1120. // @Param BaseFromMysteelChemicalIndexId query string true "上海钢联指标id"
  1121. // @Success 200 {object} data_manage.BaseFromMysteelChemicalClassifyItems
  1122. // @router /mysteel_chemical/refresh [get]
  1123. func (this *EdbInfoController) MysteelChemicalRefresh() {
  1124. br := new(models.BaseResponse).Init()
  1125. defer func() {
  1126. this.Data["json"] = br
  1127. this.ServeJSON()
  1128. }()
  1129. sysUser := this.SysUser
  1130. if sysUser == nil {
  1131. br.Msg = "请登录"
  1132. br.ErrMsg = "请登录,SysUser Is Empty"
  1133. br.Ret = 408
  1134. return
  1135. }
  1136. // 每次刷新都需要两分钟的等待时间
  1137. setNxKey := utils.CACHE_KEY_MYSTEEL_REFRESH
  1138. if !utils.Rc.SetNX(setNxKey, 1, 2*60*time.Second) {
  1139. br.Msg = "系统正在处理数据生成,请2分钟之后刷新"
  1140. br.IsSendEmail = false
  1141. return
  1142. }
  1143. indexId, _ := this.GetInt("BaseFromMysteelChemicalIndexId")
  1144. if indexId <= 0 {
  1145. br.Msg = "请选择指标"
  1146. br.IsSendEmail = false
  1147. return
  1148. }
  1149. item, err := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId)
  1150. if err != nil {
  1151. br.Msg = "获取失败"
  1152. br.ErrMsg = "获取失败,Err:" + err.Error()
  1153. }
  1154. if item.MergeFilePath == "" {
  1155. br.Msg = "系统正在处理数据生成,请5分钟之后刷新"
  1156. br.IsSendEmail = false
  1157. return
  1158. }
  1159. go data.CurlRefreshMysteelChemicalData(item.MergeFilePath)
  1160. br.Ret = 200
  1161. br.Success = true
  1162. br.Msg = "刷新成功"
  1163. br.Data = item
  1164. }
  1165. // NameCheck
  1166. // @Title 重名校验
  1167. // @Description 批量新增
  1168. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  1169. // @Success 200 string "操作成功"
  1170. // @router /mysteel_chemical/name_check [post]
  1171. func (c *EdbInfoController) NameCheck() {
  1172. br := new(models.BaseResponse).Init()
  1173. defer func() {
  1174. if br.ErrMsg == "" {
  1175. br.IsSendEmail = false
  1176. }
  1177. c.Data["json"] = br
  1178. c.ServeJSON()
  1179. }()
  1180. sysUser := c.SysUser
  1181. if sysUser == nil {
  1182. br.Msg = "请登录"
  1183. br.ErrMsg = "请登录,SysUser Is Empty"
  1184. br.Ret = 408
  1185. return
  1186. }
  1187. var req []*data_manage.NameCheckEdbInfoReq
  1188. if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
  1189. br.Msg = "参数解析异常!"
  1190. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  1191. return
  1192. }
  1193. if len(req) == 0 {
  1194. br.Msg = "请选择指标"
  1195. return
  1196. }
  1197. codeMax := 30
  1198. codeLen := len(req)
  1199. if codeLen > codeMax {
  1200. br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
  1201. return
  1202. }
  1203. type NameCheckResult struct {
  1204. EdbCode string
  1205. EdbName string
  1206. Exist bool
  1207. }
  1208. indexNames := make([]string, 0)
  1209. resp := make([]*NameCheckResult, 0)
  1210. for _, v := range req {
  1211. v.EdbCode = strings.TrimSpace(v.EdbCode)
  1212. if v.EdbCode == "" {
  1213. br.Msg = "指标ID不可为空"
  1214. return
  1215. }
  1216. v.EdbName = strings.TrimSpace(v.EdbName)
  1217. if v.EdbName == "" {
  1218. br.Msg = "请输入指标名称"
  1219. return
  1220. }
  1221. indexNames = append(indexNames, v.EdbName)
  1222. resp = append(resp, &NameCheckResult{
  1223. EdbCode: v.EdbCode,
  1224. EdbName: v.EdbName,
  1225. })
  1226. dataItems, err := data_manage.GetEdbDataAllByEdbCode(v.EdbCode, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, 0, utils.EDB_DATA_LIMIT)
  1227. if err != nil && err.Error() != utils.ErrNoRow() {
  1228. br.Msg = "获取失败"
  1229. br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
  1230. return
  1231. }
  1232. if len(dataItems) <= 0 {
  1233. respItem, err := data.AddEdbData(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, v.EdbCode, v.Frequency)
  1234. if err != nil {
  1235. br.Msg = "获取失败"
  1236. br.ErrMsg = "获取失败,Err:" + err.Error()
  1237. return
  1238. }
  1239. if respItem.Ret != 200 {
  1240. br.Msg = "未搜索到该指标"
  1241. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + v.EdbCode
  1242. return
  1243. }
  1244. }
  1245. }
  1246. // 重名校验
  1247. edbList, e := data_manage.GetEdbInfoByNameArr(indexNames, utils.EDB_INFO_TYPE)
  1248. if e != nil {
  1249. br.Msg = "操作失败"
  1250. br.ErrMsg = "获取重名指标失败, Err: " + e.Error()
  1251. return
  1252. }
  1253. nameExists := make(map[string]bool)
  1254. for _, v := range edbList {
  1255. nameExists[v.EdbName] = true
  1256. }
  1257. if len(nameExists) > 0 {
  1258. for _, v := range resp {
  1259. v.Exist = nameExists[v.EdbName]
  1260. }
  1261. }
  1262. br.Data = resp
  1263. br.Msg = "校验成功"
  1264. br.Ret = 200
  1265. br.Success = true
  1266. }
  1267. // BatchAdd
  1268. // @Title 批量新增
  1269. // @Description 批量新增
  1270. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  1271. // @Success 200 string "操作成功"
  1272. // @router /mysteel_chemical/batch_add [post]
  1273. func (this *EdbInfoController) BatchAdd() {
  1274. br := new(models.BaseResponse).Init()
  1275. defer func() {
  1276. if br.ErrMsg == "" {
  1277. br.IsSendEmail = false
  1278. }
  1279. this.Data["json"] = br
  1280. this.ServeJSON()
  1281. }()
  1282. sysUser := this.SysUser
  1283. if sysUser == nil {
  1284. br.Msg = "请登录"
  1285. br.ErrMsg = "请登录,SysUser Is Empty"
  1286. br.Ret = 408
  1287. return
  1288. }
  1289. deleteCache := true
  1290. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_MYSTEEL_CHEMICAL_" + strconv.Itoa(sysUser.AdminId)
  1291. defer func() {
  1292. if deleteCache {
  1293. _ = utils.Rc.Delete(cacheKey)
  1294. }
  1295. }()
  1296. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1297. deleteCache = false
  1298. br.Msg = "系统处理中,请稍后重试!"
  1299. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  1300. return
  1301. }
  1302. var req []*data_manage.AddEdbInfoReq
  1303. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1304. br.Msg = "参数解析异常!"
  1305. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  1306. return
  1307. }
  1308. if len(req) == 0 {
  1309. br.Msg = "请选择指标"
  1310. return
  1311. }
  1312. if len(req) > 30 {
  1313. br.Msg = "批量添加指标数量不得超过30个"
  1314. return
  1315. }
  1316. for _, v := range req {
  1317. v.EdbCode = strings.TrimSpace(v.EdbCode)
  1318. if v.EdbCode == "" {
  1319. br.Msg = "指标ID不可为空"
  1320. return
  1321. }
  1322. v.EdbName = strings.TrimSpace(v.EdbName)
  1323. if v.EdbName == "" {
  1324. br.Msg = "请输入指标名称"
  1325. return
  1326. }
  1327. v.Frequency = strings.TrimSpace(v.Frequency)
  1328. if v.Frequency == "" {
  1329. br.Msg = "请选择频度"
  1330. return
  1331. }
  1332. v.Unit = strings.TrimSpace(v.Unit)
  1333. if v.Unit == "" {
  1334. br.Msg = "请输入单位"
  1335. return
  1336. }
  1337. if v.ClassifyId <= 0 {
  1338. br.Msg = "请选择分类"
  1339. return
  1340. }
  1341. }
  1342. // 限定同一时间最多批量新增30个指标
  1343. for _, v := range req {
  1344. var r data.MysteelChemicalIndexSource2EdbReq
  1345. r.EdbCode = v.EdbCode
  1346. r.EdbName = v.EdbName
  1347. r.Frequency = v.Frequency
  1348. r.Unit = v.Unit
  1349. r.ClassifyId = v.ClassifyId
  1350. r.AdminId = sysUser.AdminId
  1351. r.AdminRealName = sysUser.RealName
  1352. edbInfo, e, errMsg, skip := data.MysteelChemicalIndexSource2Edb(r, this.Lang)
  1353. if e != nil {
  1354. br.Msg = "操作失败"
  1355. if errMsg != "" {
  1356. br.Msg = errMsg
  1357. }
  1358. br.ErrMsg = e.Error()
  1359. return
  1360. }
  1361. if skip {
  1362. continue
  1363. }
  1364. // 试用平台更新用户累计新增指标数
  1365. if utils.BusinessCode == utils.BusinessCodeSandbox {
  1366. go func() {
  1367. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  1368. if e != nil {
  1369. tips := fmt.Sprintf("试用平台更新用户累计新增指标数-获取用户失败, Err: " + e.Error())
  1370. utils.FileLog.Info(tips)
  1371. return
  1372. }
  1373. if adminItem.DepartmentName != "ETA试用客户" {
  1374. return
  1375. }
  1376. var ur etaTrialService.EtaTrialUserReq
  1377. ur.Mobile = adminItem.Mobile
  1378. _, _ = etaTrialService.UpdateUserIndexNum(ur)
  1379. }()
  1380. }
  1381. // 新增操作日志
  1382. {
  1383. edbLog := new(data_manage.EdbInfoLog)
  1384. edbLog.EdbInfoId = edbInfo.EdbInfoId
  1385. edbLog.SourceName = edbInfo.SourceName
  1386. edbLog.Source = edbInfo.Source
  1387. edbLog.EdbCode = edbInfo.EdbCode
  1388. edbLog.EdbName = edbInfo.EdbName
  1389. edbLog.ClassifyId = edbInfo.ClassifyId
  1390. edbLog.SysUserId = sysUser.AdminId
  1391. edbLog.SysUserRealName = sysUser.RealName
  1392. edbLog.CreateTime = time.Now()
  1393. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1394. edbLog.Status = "新增指标"
  1395. edbLog.Method = this.Ctx.Input.URI()
  1396. go data_manage.AddEdbInfoLog(edbLog)
  1397. }
  1398. }
  1399. br.Msg = "操作成功"
  1400. br.Ret = 200
  1401. br.Success = true
  1402. br.IsAddLog = true
  1403. }
  1404. // EdbInfoAdd
  1405. // @Title 新增指标接口
  1406. // @Description 新增指标接口
  1407. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  1408. // @Success Ret=200 保存成功
  1409. // @router /mysteel_chemical/edb_info/add [post]
  1410. func (this *EdbInfoController) Add() {
  1411. br := new(models.BaseResponse).Init()
  1412. defer func() {
  1413. this.Data["json"] = br
  1414. this.ServeJSON()
  1415. }()
  1416. sysUser := this.SysUser
  1417. if sysUser == nil {
  1418. br.Msg = "请登录"
  1419. br.ErrMsg = "请登录,SysUser Is Empty"
  1420. br.Ret = 408
  1421. return
  1422. }
  1423. deleteCache := true
  1424. cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  1425. defer func() {
  1426. if deleteCache {
  1427. utils.Rc.Delete(cacheKey)
  1428. }
  1429. }()
  1430. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1431. deleteCache = false
  1432. br.Msg = "系统处理中,请稍后重试!"
  1433. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  1434. return
  1435. }
  1436. var req data_manage.AddEdbInfoReq
  1437. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1438. if err != nil {
  1439. br.Msg = "参数解析异常!"
  1440. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1441. return
  1442. }
  1443. req.EdbName = strings.Trim(req.EdbName, " ")
  1444. req.EdbCode = strings.Trim(req.EdbCode, " ")
  1445. if req.EdbCode == "" {
  1446. br.Msg = "指标ID不能为空"
  1447. return
  1448. }
  1449. if req.EdbName == "" {
  1450. br.Msg = "指标名称不能为空"
  1451. return
  1452. }
  1453. if req.Frequency == "" {
  1454. br.Msg = "频率不能为空"
  1455. return
  1456. }
  1457. if req.Unit == "" {
  1458. br.Msg = "单位不能为空"
  1459. return
  1460. }
  1461. if req.ClassifyId <= 0 {
  1462. br.Msg = "请选择分类"
  1463. return
  1464. }
  1465. tmpInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(req.EdbCode)
  1466. if err != nil {
  1467. if err.Error() != utils.ErrNoRow() {
  1468. br.Msg = "获取失败"
  1469. br.ErrMsg = "获取失败,Err:" + err.Error()
  1470. return
  1471. }
  1472. }
  1473. var source int
  1474. if tmpInfo != nil {
  1475. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  1476. } else {
  1477. br.Msg = "指标不存在"
  1478. return
  1479. }
  1480. // 指标入库
  1481. edbInfo, err, errMsg, isSendEmail := data.EdbInfoAdd(source, utils.DATA_SUB_SOURCE_EDB, req.ClassifyId, req.EdbCode, req.EdbName, req.Frequency, req.Unit, req.StartDate, req.EndDate, sysUser.AdminId, sysUser.RealName, this.Lang)
  1482. if err != nil {
  1483. br.Msg = "保存失败"
  1484. if errMsg != `` {
  1485. br.Msg = errMsg
  1486. }
  1487. br.ErrMsg = err.Error()
  1488. br.IsSendEmail = isSendEmail
  1489. return
  1490. }
  1491. // 试用平台更新用户累计新增指标数
  1492. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  1493. if e != nil {
  1494. br.Msg = "操作失败"
  1495. br.ErrMsg = "获取系统用户数据失败,Err:" + e.Error()
  1496. return
  1497. }
  1498. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  1499. go func() {
  1500. var r etaTrialService.EtaTrialUserReq
  1501. r.Mobile = adminItem.Mobile
  1502. _, _ = etaTrialService.UpdateUserIndexNum(r)
  1503. }()
  1504. }
  1505. //新增操作日志
  1506. {
  1507. // 添加钢联指标更新日志
  1508. if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  1509. go data_stat.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", sysUser, 2)
  1510. }
  1511. edbLog := new(data_manage.EdbInfoLog)
  1512. edbLog.EdbInfoId = edbInfo.EdbInfoId
  1513. edbLog.SourceName = edbInfo.SourceName
  1514. edbLog.Source = edbInfo.Source
  1515. edbLog.EdbCode = edbInfo.EdbCode
  1516. edbLog.EdbName = edbInfo.EdbName
  1517. edbLog.ClassifyId = edbInfo.ClassifyId
  1518. edbLog.SysUserId = sysUser.AdminId
  1519. edbLog.SysUserRealName = sysUser.RealName
  1520. edbLog.CreateTime = time.Now()
  1521. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1522. edbLog.Status = "新增指标"
  1523. edbLog.Method = this.Ctx.Input.URI()
  1524. go data_manage.AddEdbInfoLog(edbLog)
  1525. }
  1526. // 更新es
  1527. go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  1528. resp := new(data_manage.AddEdbInfoResp)
  1529. resp.EdbInfoId = edbInfo.EdbInfoId
  1530. resp.UniqueCode = edbInfo.UniqueCode
  1531. br.Ret = 200
  1532. br.Success = true
  1533. br.Msg = "保存成功"
  1534. br.Data = resp
  1535. br.IsAddLog = true
  1536. }
  1537. // AddCheck
  1538. // @Title 新增校验
  1539. // @Description 新增校验
  1540. // @Param request body request.BusinessDataBatchAddCheckReq true "type json string"
  1541. // @Success 200 string "操作成功"
  1542. // @router /mysteel_chemical/edb_info/add_check [post]
  1543. func (c *EdbInfoController) AddCheck() {
  1544. br := new(models.BaseResponse).Init()
  1545. defer func() {
  1546. if br.ErrMsg == "" {
  1547. br.IsSendEmail = false
  1548. }
  1549. c.Data["json"] = br
  1550. c.ServeJSON()
  1551. }()
  1552. sysUser := c.SysUser
  1553. if sysUser == nil {
  1554. br.Msg = "请登录"
  1555. br.ErrMsg = "请登录,SysUser Is Empty"
  1556. br.Ret = 408
  1557. return
  1558. }
  1559. var req *data_manage.BatchAddCheckReq
  1560. if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
  1561. br.Msg = "参数解析异常!"
  1562. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  1563. return
  1564. }
  1565. codeMax := 30
  1566. codeLen := len(req.IndexCodes)
  1567. // 获取指标库已有指标
  1568. existsEdb, e := data_manage.GetEdbCodesBySource(utils.DATA_SOURCE_MYSTEEL_CHEMICAL)
  1569. if e != nil {
  1570. br.Msg = "获取失败"
  1571. br.ErrMsg = "获取自有数据已添加的指标失败, Err: " + e.Error()
  1572. return
  1573. }
  1574. existMap := make(map[string]*data_manage.EdbInfo)
  1575. for _, v := range existsEdb {
  1576. existMap[v.EdbCode] = v
  1577. }
  1578. obj := data_manage.BaseFromMysteelChemicalIndex{}
  1579. if codeLen == 0 {
  1580. br.Msg = "请选择指标"
  1581. return
  1582. }
  1583. if codeLen > codeMax {
  1584. br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
  1585. return
  1586. }
  1587. // 查询选中的指标
  1588. cond := fmt.Sprintf(` AND %s IN (%s)`, data_manage.BaseFromMysteelChemicalIndexCols.IndexCode, utils.GetOrmInReplace(codeLen))
  1589. pars := make([]interface{}, 0)
  1590. pars = append(pars, req.IndexCodes)
  1591. list, e := obj.GeItemsByCondition(cond, pars, 0)
  1592. if e != nil {
  1593. br.Msg = "获取失败"
  1594. br.ErrMsg = "获取自有数据原始指标列表失败, Err: " + e.Error()
  1595. return
  1596. }
  1597. if len(list) > codeMax {
  1598. br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
  1599. return
  1600. }
  1601. resp := make([]*data_manage.BaseFromMysteelChemicalIndexItem, 0)
  1602. for _, v := range list {
  1603. if v.EdbInfoId > 0 {
  1604. v.EdbExist = 1
  1605. }
  1606. resp = append(resp, v)
  1607. }
  1608. br.Data = resp
  1609. br.Msg = "校验成功"
  1610. br.Ret = 200
  1611. br.Success = true
  1612. }
  1613. // MysteelChemicalSearch
  1614. // @Title 上海钢联指标查询
  1615. // @Description 上海钢联指标查询
  1616. // @Param BaseFromMysteelChemicalClassifyIds query string true "分类id"
  1617. // @Param Keyword query string true "名称关键词"
  1618. // @Success 200 {object} data_manage.LzFrequency
  1619. // @router /mysteel_chemical/batch_search [get]
  1620. func (this *EdbInfoController) MysteelChemicalBatchSearch() {
  1621. br := new(models.BaseResponse).Init()
  1622. defer func() {
  1623. this.Data["json"] = br
  1624. this.ServeJSON()
  1625. }()
  1626. sysUser := this.SysUser
  1627. if sysUser == nil {
  1628. br.Msg = "请登录"
  1629. br.ErrMsg = "请登录,SysUser Is Empty"
  1630. br.Ret = 408
  1631. return
  1632. }
  1633. classifyIdStr := this.GetString("BaseFromMysteelChemicalClassifyIds")
  1634. var condition string
  1635. var pars []interface{}
  1636. classifyIds := strings.Split(classifyIdStr, ",")
  1637. if len(classifyIds) > 0 && classifyIds[0] != `` {
  1638. condition += " AND base_from_mysteel_chemical_classify_id IN (" + utils.GetOrmInReplace(len(classifyIds)) + " ) "
  1639. pars = append(pars, classifyIds)
  1640. }
  1641. keyword := this.GetString("Keyword")
  1642. if keyword != `` {
  1643. condition += " AND (index_name like ? OR index_code like ?) "
  1644. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  1645. }
  1646. if classifyIdStr == `` && keyword == `` {
  1647. var list = make([]*data_manage.MysteelChemicalList, 0)
  1648. br.Ret = 200
  1649. br.Success = true
  1650. br.Msg = "获取成功"
  1651. br.Data = list
  1652. return
  1653. }
  1654. list, err := data_manage.GetMysteelChemicalIndex(condition, pars)
  1655. if err != nil {
  1656. br.Msg = "获取失败"
  1657. br.ErrMsg = "获取失败,Err:" + err.Error()
  1658. return
  1659. }
  1660. classifyIdInts := make([]int, 0)
  1661. for _, v := range list {
  1662. v.UniqueCode = fmt.Sprint(v.BaseFromMysteelChemicalClassifyId, "_", v.Id)
  1663. if v.BaseFromMysteelChemicalClassifyId > 0 {
  1664. classifyIdInts = append(classifyIdInts, v.BaseFromMysteelChemicalClassifyId)
  1665. }
  1666. }
  1667. if len(classifyIdInts) > 0 {
  1668. // 查询父级分类信息
  1669. classifyList, e := data_manage.GetBaseFromMysteelChemicalClassifyByIds(classifyIdInts)
  1670. if e != nil {
  1671. br.Msg = "获取目录信息失败"
  1672. br.ErrMsg = "获取失获取目录信息失败,Err:" + e.Error()
  1673. return
  1674. }
  1675. classifyListMap := make(map[int]int, 0)
  1676. for _, v := range classifyList {
  1677. classifyListMap[v.BaseFromMysteelChemicalClassifyId] = v.ParentId
  1678. }
  1679. for _, v := range list {
  1680. v.UniqueCode = fmt.Sprint(v.BaseFromMysteelChemicalClassifyId, "_", v.Id)
  1681. if p, ok := classifyListMap[v.BaseFromMysteelChemicalClassifyId]; ok {
  1682. v.ParentClassifyId = p
  1683. }
  1684. }
  1685. }
  1686. br.Ret = 200
  1687. br.Success = true
  1688. br.Msg = "获取成功"
  1689. br.Data = list
  1690. }