mysteel_chemical_data.go 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844
  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. frequencyList, err := data_manage.GetMysteelChemicalFrequency(condition, pars)
  615. for _, v := range frequencyList {
  616. frequencies = append(frequencies, v.Frequency)
  617. }
  618. fileName := `钢联化工数据`
  619. if frequencies == nil {
  620. sheet, err := xlsxFile.AddSheet("无数据")
  621. if err != nil {
  622. br.Msg = "新增Sheet失败"
  623. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  624. return
  625. }
  626. rowSecName := sheet.AddRow()
  627. celSecName := rowSecName.AddCell()
  628. celSecName.SetValue("")
  629. }
  630. for _, frequency := range frequencies {
  631. //获取指标
  632. var tmpCondition string
  633. var tmpPars []interface{}
  634. if indexId > 0 {
  635. tmpCondition += " AND base_from_mysteel_chemical_index_id = ? "
  636. tmpPars = append(pars, indexId)
  637. }
  638. if classifyId > 0 {
  639. tmpCondition += " AND base_from_mysteel_chemical_classify_id=? "
  640. tmpPars = append(pars, classifyId)
  641. }
  642. if frequency != `` {
  643. tmpCondition += " AND frequency=? "
  644. tmpPars = append(pars, frequency)
  645. }
  646. // 关键词搜索
  647. keyword := this.GetString("Keyword")
  648. if keyword != `` {
  649. tmpCondition += " AND (index_name like ? OR index_code like ?) "
  650. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  651. }
  652. //获取指标
  653. secNameList, err := data_manage.GetMysteelChemicalIndex(tmpCondition, tmpPars)
  654. if err != nil {
  655. fmt.Println("获取数据失败,Err:" + err.Error())
  656. return
  657. }
  658. if len(secNameList) <= 0 {
  659. fmt.Println("secNameList长度为0")
  660. return
  661. }
  662. sheetNew, err := xlsxFile.AddSheet(frequency)
  663. if err != nil {
  664. fmt.Println("新增Sheet失败", err.Error())
  665. return
  666. }
  667. //sheetNew.SetColWidth()
  668. //获取指标数据
  669. windRow := sheetNew.AddRow()
  670. secNameRow := sheetNew.AddRow()
  671. indexCodeRow := sheetNew.AddRow()
  672. frequencyRow := sheetNew.AddRow()
  673. unitRow := sheetNew.AddRow()
  674. lastModifyDateRow := sheetNew.AddRow()
  675. //获取分类下指标最大数据量
  676. dataMax, err := data_manage.GetBaseFromMysteelChemicalDataMaxCount(classifyId)
  677. if err != nil {
  678. fmt.Println("获取指标最大数据量失败", err.Error())
  679. return
  680. }
  681. fmt.Println("dataMax:", dataMax)
  682. setRowIndex := 6
  683. for k, sv := range secNameList {
  684. //获取数据
  685. dataList, err := data_manage.GetMysteelChemicalIndexDataByCode(sv.IndexCode)
  686. if err != nil {
  687. br.Msg = "获取数据失败"
  688. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  689. return
  690. }
  691. if len(dataList) > 0 {
  692. windRow.AddCell().SetValue("钢联")
  693. secNameRow.AddCell().SetValue("指标名称")
  694. indexCodeRow.AddCell().SetValue("指标ID")
  695. frequencyRow.AddCell().SetValue("频率")
  696. unitRow.AddCell().SetValue("单位")
  697. lastModifyDateRow.AddCell().SetValue("更新时间")
  698. secNameRow.AddCell().SetValue(sv.IndexName)
  699. indexCodeRow.AddCell().SetValue(sv.IndexCode)
  700. frequencyRow.AddCell().SetValue(sv.FrequencyName)
  701. unitRow.AddCell().SetValue(sv.UnitName)
  702. lastModifyDateRow.AddCell().SetValue(sv.UpdateTime)
  703. windRow.AddCell()
  704. windRow.AddCell()
  705. secNameRow.AddCell()
  706. indexCodeRow.AddCell()
  707. frequencyRow.AddCell()
  708. unitRow.AddCell()
  709. lastModifyDateRow.AddCell()
  710. min := k * 3
  711. sheetNew.SetColWidth(min, min, 15)
  712. if len(dataList) <= 0 {
  713. for n := 0; n < dataMax; n++ {
  714. rowIndex := setRowIndex + n
  715. row := sheetNew.Row(rowIndex)
  716. row.AddCell()
  717. row.AddCell()
  718. row.AddCell()
  719. }
  720. } else {
  721. endRowIndex := 0
  722. for rk, dv := range dataList {
  723. rowIndex := setRowIndex + rk
  724. row := sheetNew.Row(rowIndex)
  725. displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
  726. displayDateCell := row.AddCell()
  727. style := new(xlsx.Style)
  728. style.ApplyAlignment = true
  729. style.Alignment.WrapText = true
  730. displayDateCell.SetStyle(style)
  731. displayDateCell.SetDate(displayDate)
  732. row.AddCell().SetValue(dv.InputValue)
  733. row.AddCell()
  734. endRowIndex = rowIndex
  735. }
  736. if len(dataList) < dataMax {
  737. dataLen := dataMax - len(dataList)
  738. for n := 0; n < dataLen; n++ {
  739. rowIndex := (endRowIndex + 1) + n
  740. row := sheetNew.Row(rowIndex)
  741. row.AddCell()
  742. row.AddCell()
  743. row.AddCell()
  744. }
  745. }
  746. }
  747. }
  748. }
  749. }
  750. err = xlsxFile.Save(downLoadnFilePath)
  751. if err != nil {
  752. //有指标无数据时先导出一遍空表
  753. sheet, err := xlsxFile.AddSheet("无数据")
  754. if err != nil {
  755. br.Msg = "新增Sheet失败"
  756. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  757. return
  758. }
  759. rowSecName := sheet.AddRow()
  760. celSecName := rowSecName.AddCell()
  761. celSecName.SetValue("")
  762. err = xlsxFile.Save(downLoadnFilePath)
  763. if err != nil {
  764. br.Msg = "保存文件失败"
  765. br.ErrMsg = "保存文件失败"
  766. return
  767. }
  768. }
  769. fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
  770. this.Ctx.Output.Download(downLoadnFilePath, fileName)
  771. defer func() {
  772. os.Remove(downLoadnFilePath)
  773. }()
  774. br.Ret = 200
  775. br.Success = true
  776. br.Msg = "success"
  777. }
  778. // AddMysteelChemical
  779. // @Title 新增钢联化工指标
  780. // @Description 新增钢联化工指标接口
  781. // @Param request body data_manage.AddEdbClassifyReq true "type json string"
  782. // @Success 200 Ret=200 保存成功
  783. // @router /mysteel_chemical/add [post]
  784. func (this *EdbClassifyController) AddMysteelChemical() {
  785. br := new(models.BaseResponse).Init()
  786. defer func() {
  787. this.Data["json"] = br
  788. this.ServeJSON()
  789. }()
  790. var req request.AddBaseFromMysteelChemicalReq
  791. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  792. if err != nil {
  793. br.Msg = "参数解析异常!"
  794. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  795. return
  796. }
  797. resp := new(response.AddMysteelChemicalIndexInfoResp)
  798. conf, err := models.GetBusinessConf()
  799. if err != nil {
  800. br.Msg = "添加指标失败"
  801. br.ErrMsg = "获取业务配置失败,Err:" + err.Error()
  802. return
  803. }
  804. // 判断钢联化工的数据刷新方式
  805. if conf["MySteelDataMethod"] == "api" {
  806. if len(req.List) > 150 {
  807. br.Msg = "添加指标失败,指标数量不能超过150条"
  808. return
  809. }
  810. ok, errMsg, err := data.HealthCheckMysteelChemicalApi()
  811. if err != nil {
  812. br.Msg = "添加指标失败"
  813. br.ErrMsg = "钢联化工数据接口异常,Err:" + err.Error()
  814. return
  815. }
  816. if !ok {
  817. br.Msg = errMsg
  818. return
  819. }
  820. addMySteelList := make([]*data_manage.BaseFromMysteelChemicalIndex, 0)
  821. for _, v := range req.List {
  822. if v.IndexCode == "" {
  823. br.Msg = "请输入指标ID"
  824. br.IsSendEmail = false
  825. return
  826. }
  827. if v.BaseFromMysteelChemicalClassifyId <= 0 {
  828. br.Msg = "请选择分类"
  829. br.IsSendEmail = false
  830. return
  831. }
  832. var updateTime1, updateTime2 string
  833. if v.UpdateTime != `` {
  834. updateTimeList := strings.Split(v.UpdateTime, ",")
  835. updateTime1 = updateTimeList[0]
  836. if len(updateTimeList) > 1 {
  837. updateTime2 = updateTimeList[1]
  838. }
  839. }
  840. v.IndexCode = utils.TrimStr(v.IndexCode)
  841. v.IndexCode = strings.Replace(v.IndexCode, "\t", "", -1)
  842. addMySteelList = append(addMySteelList, &data_manage.BaseFromMysteelChemicalIndex{
  843. BaseFromMysteelChemicalClassifyId: v.BaseFromMysteelChemicalClassifyId,
  844. IndexCode: strings.ToUpper(v.IndexCode),
  845. IndexName: "",
  846. Unit: "",
  847. Frequency: "",
  848. StartDate: "",
  849. EndDate: "",
  850. Describe: "",
  851. Source: "api",
  852. TerminalCode: "",
  853. UpdateWeek: v.UpdateWeek,
  854. UpdateTime: updateTime1,
  855. UpdateTime2: updateTime2,
  856. SysUserId: this.SysUser.AdminId,
  857. SysUserRealName: this.SysUser.RealName,
  858. ModifyTime: time.Now(),
  859. CreateTime: time.Now(),
  860. })
  861. }
  862. mySteelChemicalIndexInfos, err, errMsg := data.BatchAddMysteelChemicalIndex(addMySteelList, this.Lang)
  863. if err != nil {
  864. br.Msg = errMsg
  865. br.ErrMsg = errMsg + ";Err:" + err.Error()
  866. return
  867. }
  868. if len(mySteelChemicalIndexInfos) > 0 {
  869. resp.BaseFromMysteelChemicalIndexId = mySteelChemicalIndexInfos[0].BaseFromMysteelChemicalIndexId
  870. resp.IndexCode = mySteelChemicalIndexInfos[0].IndexCode
  871. resp.UniqueCode = fmt.Sprint(mySteelChemicalIndexInfos[0].BaseFromMysteelChemicalClassifyId, "_", mySteelChemicalIndexInfos[0].BaseFromMysteelChemicalIndexId)
  872. }
  873. for _, v := range mySteelChemicalIndexInfos {
  874. err = utils.Rc.LPush(utils.CACHE_MYSTEEL_CHEMICAL_ADD_DATA, v.IndexCode)
  875. if err != nil {
  876. br.Msg = "添加指标失败" + v.IndexCode
  877. br.ErrMsg = "添加指标缓存失败" + v.IndexCode + ";Err:" + err.Error()
  878. return
  879. }
  880. }
  881. } else {
  882. for i, v := range req.List {
  883. if v.IndexCode == "" {
  884. br.Msg = "请输入指标ID"
  885. br.IsSendEmail = false
  886. return
  887. }
  888. if v.BaseFromMysteelChemicalClassifyId <= 0 {
  889. br.Msg = "请选择分类"
  890. br.IsSendEmail = false
  891. return
  892. }
  893. v.IndexCode = utils.TrimStr(v.IndexCode)
  894. v.IndexCode = strings.Replace(v.IndexCode, "\t", "", -1)
  895. //添加指标
  896. mysteelChemicalIndexInfo, err, errMsg := data.AddMysteelChemicalIndex(v.BaseFromMysteelChemicalClassifyId, strings.ToUpper(v.IndexCode), v.UpdateWeek, v.UpdateTime, this.SysUser.AdminId, this.SysUser.RealName, this.Lang)
  897. if errMsg != `` {
  898. br.Msg = errMsg
  899. br.ErrMsg = errMsg
  900. if err != nil {
  901. br.ErrMsg = errMsg + ";Err:" + err.Error()
  902. } else {
  903. br.IsSendEmail = false
  904. }
  905. return
  906. }
  907. if i == 0 {
  908. resp.BaseFromMysteelChemicalIndexId = mysteelChemicalIndexInfo.BaseFromMysteelChemicalIndexId
  909. resp.IndexCode = mysteelChemicalIndexInfo.IndexCode
  910. resp.UniqueCode = fmt.Sprint(mysteelChemicalIndexInfo.BaseFromMysteelChemicalClassifyId, "_", mysteelChemicalIndexInfo.BaseFromMysteelChemicalIndexId)
  911. }
  912. }
  913. }
  914. br.Data = resp
  915. br.Ret = 200
  916. br.Msg = "保存成功"
  917. br.Success = true
  918. br.IsAddLog = true
  919. }
  920. func sortEdbFrequency(frequencyList []string) (newFrequencyList []string) {
  921. var frequencyMap1 = map[string]int{
  922. "日度": 1,
  923. "周度": 2,
  924. "旬度": 3,
  925. "月度": 4,
  926. "季度": 5,
  927. "半年度": 6,
  928. "年度": 7,
  929. }
  930. var frequencyMap2 = map[int]string{
  931. 1: "日度",
  932. 2: "周度",
  933. 3: "旬度",
  934. 4: "月度",
  935. 5: "季度",
  936. 6: "半年度",
  937. 7: "年度",
  938. }
  939. idList := make([]int, 0)
  940. for _, frequency := range frequencyList {
  941. idList = append(idList, frequencyMap1[frequency])
  942. }
  943. sort.Ints(idList)
  944. for _, id := range idList {
  945. newFrequencyList = append(newFrequencyList, frequencyMap2[id])
  946. }
  947. return
  948. }
  949. // EditMysteelChemical
  950. // @Title 编辑钢联化工指标
  951. // @Description 新增钢联化工指标接口
  952. // @Param request body data_manage.AddEdbClassifyReq true "type json string"
  953. // @Success 200 Ret=200 保存成功
  954. // @router /mysteel_chemical/edit [post]
  955. func (this *EdbClassifyController) EditMysteelChemical() {
  956. br := new(models.BaseResponse).Init()
  957. defer func() {
  958. this.Data["json"] = br
  959. this.ServeJSON()
  960. }()
  961. var req request.AddBaseFromMysteelChemicalReqItem
  962. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  963. if err != nil {
  964. br.Msg = "参数解析异常!"
  965. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  966. return
  967. }
  968. if req.BaseFromMysteelChemicalIndexId <= 0 {
  969. br.Msg = "请选择指标"
  970. br.IsSendEmail = false
  971. return
  972. }
  973. if req.BaseFromMysteelChemicalClassifyId <= 0 {
  974. br.Msg = "请选择分类"
  975. br.IsSendEmail = false
  976. return
  977. }
  978. //编辑指标
  979. mysteelChemicalIndexInfo, err, errMsg := data.EditMysteelChemicalIndex(req.BaseFromMysteelChemicalIndexId, req.BaseFromMysteelChemicalClassifyId, req.UpdateWeek, req.UpdateTime, this.SysUser)
  980. if errMsg != `` {
  981. br.Msg = errMsg
  982. br.ErrMsg = errMsg
  983. if err != nil {
  984. br.ErrMsg = errMsg + ";Err:" + err.Error()
  985. } else {
  986. br.IsSendEmail = false
  987. }
  988. return
  989. }
  990. resp := response.AddMysteelChemicalIndexInfoResp{
  991. BaseFromMysteelChemicalIndexId: mysteelChemicalIndexInfo.BaseFromMysteelChemicalIndexId,
  992. IndexCode: mysteelChemicalIndexInfo.IndexCode,
  993. UniqueCode: fmt.Sprint(mysteelChemicalIndexInfo.BaseFromMysteelChemicalClassifyId, "_", mysteelChemicalIndexInfo.BaseFromMysteelChemicalIndexId),
  994. }
  995. br.Data = resp
  996. br.Ret = 200
  997. br.Msg = "保存成功"
  998. br.Success = true
  999. br.IsAddLog = true
  1000. }
  1001. // DeleteMysteelChemical
  1002. // @Title 删除指标
  1003. // @Description 删除指标接口
  1004. // @Param request body data_manage.DelBaseFromMysteelChemicalReq true "type json string"
  1005. // @Success 200 Ret=200 删除成功
  1006. // @router /mysteel_chemical/del [post]
  1007. func (this *EdbClassifyController) DeleteMysteelChemical() {
  1008. br := new(models.BaseResponse).Init()
  1009. defer func() {
  1010. this.Data["json"] = br
  1011. this.ServeJSON()
  1012. }()
  1013. var req request.DelBaseFromMysteelChemicalReq
  1014. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1015. if err != nil {
  1016. br.Msg = "参数解析异常!"
  1017. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1018. return
  1019. }
  1020. if req.BaseFromMysteelChemicalIndexId < 0 {
  1021. br.Msg = "参数错误"
  1022. br.IsSendEmail = false
  1023. return
  1024. }
  1025. err, errMsg := data.DelMysteelChemical(req.BaseFromMysteelChemicalIndexId, this.SysUser)
  1026. if errMsg != `` {
  1027. br.Msg = errMsg
  1028. br.ErrMsg = errMsg
  1029. if err != nil {
  1030. br.ErrMsg = errMsg + ";Err:" + err.Error()
  1031. } else {
  1032. br.IsSendEmail = false
  1033. }
  1034. return
  1035. }
  1036. br.Ret = 200
  1037. br.Msg = "删除成功"
  1038. br.Success = true
  1039. br.IsAddLog = true
  1040. }
  1041. // MoveMysteelChemical
  1042. // @Title 指标移动接口
  1043. // @Description 分类移动接口
  1044. // @Success 200 {object} data_manage.MoveBaseFromMysteelChemicalReq
  1045. // @router /mysteel_chemical/move [post]
  1046. func (this *EdbClassifyController) MoveMysteelChemical() {
  1047. br := new(models.BaseResponse).Init()
  1048. defer func() {
  1049. this.Data["json"] = br
  1050. this.ServeJSON()
  1051. }()
  1052. sysUser := this.SysUser
  1053. if sysUser == nil {
  1054. br.Msg = "请登录"
  1055. br.ErrMsg = "请登录,SysUser Is Empty"
  1056. br.Ret = 408
  1057. return
  1058. }
  1059. var req request.MoveBaseFromMysteelChemicalReq
  1060. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1061. if err != nil {
  1062. br.Msg = "参数解析异常!"
  1063. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1064. return
  1065. }
  1066. if req.BaseFromMysteelChemicalIndexId <= 0 {
  1067. br.Msg = "参数错误"
  1068. br.ErrMsg = "指标id小于等于0"
  1069. br.IsSendEmail = false
  1070. return
  1071. }
  1072. if req.BaseFromMysteelChemicalClassifyId <= 0 {
  1073. br.Msg = "请选择分类"
  1074. br.ErrMsg = "请选择分类"
  1075. br.IsSendEmail = false
  1076. return
  1077. }
  1078. err, errMsg := data.MoveMysteelChemical(req.BaseFromMysteelChemicalIndexId, req.BaseFromMysteelChemicalClassifyId, req.PrevBaseFromMysteelChemicalIndexId, req.NextBaseFromMysteelChemicalIndexId, this.SysUser)
  1079. if errMsg != `` {
  1080. br.Msg = errMsg
  1081. br.ErrMsg = errMsg
  1082. if err != nil {
  1083. br.ErrMsg = err.Error()
  1084. } else {
  1085. br.IsSendEmail = false
  1086. }
  1087. return
  1088. }
  1089. br.Ret = 200
  1090. br.Success = true
  1091. br.IsAddLog = true
  1092. br.Msg = "移动成功"
  1093. }
  1094. // MysteelChemicalDetail
  1095. // @Title 钢联化工指标详情
  1096. // @Description 钢联化工指标详情接口
  1097. // @Param BaseFromMysteelChemicalIndexId query string true "钢联化工指标id"
  1098. // @Success 200 {object} data_manage.BaseFromMysteelChemicalClassifyItems
  1099. // @router /mysteel_chemical/detail [get]
  1100. func (this *EdbInfoController) MysteelChemicalDetail() {
  1101. br := new(models.BaseResponse).Init()
  1102. defer func() {
  1103. this.Data["json"] = br
  1104. this.ServeJSON()
  1105. }()
  1106. sysUser := this.SysUser
  1107. if sysUser == nil {
  1108. br.Msg = "请登录"
  1109. br.ErrMsg = "请登录,SysUser Is Empty"
  1110. br.Ret = 408
  1111. return
  1112. }
  1113. indexId, _ := this.GetInt("BaseFromMysteelChemicalIndexId")
  1114. if indexId <= 0 {
  1115. br.Msg = "请选择指标"
  1116. br.IsSendEmail = false
  1117. return
  1118. }
  1119. item, err := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId)
  1120. if err != nil {
  1121. br.Msg = "获取失败"
  1122. br.ErrMsg = "获取失败,Err:" + err.Error()
  1123. }
  1124. if item.UpdateTime2 != `` {
  1125. item.UpdateTime = item.UpdateTime + "," + item.UpdateTime2
  1126. }
  1127. br.Ret = 200
  1128. br.Success = true
  1129. br.Msg = "获取成功"
  1130. br.Data = item
  1131. }
  1132. // MysteelChemicalDetail
  1133. // @Title 钢联化工指标详情
  1134. // @Description 钢联化工指标详情接口
  1135. // @Param BaseFromMysteelChemicalIndexId query string true "钢联化工指标id"
  1136. // @Success 200 {object} data_manage.BaseFromMysteelChemicalClassifyItems
  1137. // @router /mysteel_chemical/refresh [get]
  1138. func (this *EdbInfoController) MysteelChemicalRefresh() {
  1139. br := new(models.BaseResponse).Init()
  1140. defer func() {
  1141. this.Data["json"] = br
  1142. this.ServeJSON()
  1143. }()
  1144. sysUser := this.SysUser
  1145. if sysUser == nil {
  1146. br.Msg = "请登录"
  1147. br.ErrMsg = "请登录,SysUser Is Empty"
  1148. br.Ret = 408
  1149. return
  1150. }
  1151. // 每次刷新都需要两分钟的等待时间
  1152. setNxKey := utils.CACHE_KEY_MYSTEEL_REFRESH
  1153. if !utils.Rc.SetNX(setNxKey, 1, 2*60*time.Second) {
  1154. br.Msg = "系统正在处理数据生成,请2分钟之后刷新"
  1155. br.IsSendEmail = false
  1156. return
  1157. }
  1158. indexId, _ := this.GetInt("BaseFromMysteelChemicalIndexId")
  1159. if indexId <= 0 {
  1160. br.Msg = "请选择指标"
  1161. br.IsSendEmail = false
  1162. return
  1163. }
  1164. item, err := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId)
  1165. if err != nil {
  1166. br.Msg = "获取失败"
  1167. br.ErrMsg = "获取失败,Err:" + err.Error()
  1168. }
  1169. if item.MergeFilePath == "" {
  1170. br.Msg = "系统正在处理数据生成,请5分钟之后刷新"
  1171. br.IsSendEmail = false
  1172. return
  1173. }
  1174. go data.CurlRefreshMysteelChemicalData(item.MergeFilePath)
  1175. br.Ret = 200
  1176. br.Success = true
  1177. br.Msg = "刷新成功"
  1178. br.Data = item
  1179. }
  1180. // NameCheck
  1181. // @Title 重名校验
  1182. // @Description 批量新增
  1183. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  1184. // @Success 200 string "操作成功"
  1185. // @router /mysteel_chemical/name_check [post]
  1186. func (c *EdbInfoController) NameCheck() {
  1187. br := new(models.BaseResponse).Init()
  1188. defer func() {
  1189. if br.ErrMsg == "" {
  1190. br.IsSendEmail = false
  1191. }
  1192. c.Data["json"] = br
  1193. c.ServeJSON()
  1194. }()
  1195. sysUser := c.SysUser
  1196. if sysUser == nil {
  1197. br.Msg = "请登录"
  1198. br.ErrMsg = "请登录,SysUser Is Empty"
  1199. br.Ret = 408
  1200. return
  1201. }
  1202. var req []*data_manage.NameCheckEdbInfoReq
  1203. if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
  1204. br.Msg = "参数解析异常!"
  1205. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  1206. return
  1207. }
  1208. if len(req) == 0 {
  1209. br.Msg = "请选择指标"
  1210. return
  1211. }
  1212. codeMax := 30
  1213. codeLen := len(req)
  1214. if codeLen > codeMax {
  1215. br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
  1216. return
  1217. }
  1218. type NameCheckResult struct {
  1219. EdbCode string
  1220. EdbName string
  1221. Exist bool
  1222. }
  1223. indexNames := make([]string, 0)
  1224. resp := make([]*NameCheckResult, 0)
  1225. for _, v := range req {
  1226. v.EdbCode = strings.TrimSpace(v.EdbCode)
  1227. if v.EdbCode == "" {
  1228. br.Msg = "指标ID不可为空"
  1229. return
  1230. }
  1231. v.EdbName = strings.TrimSpace(v.EdbName)
  1232. if v.EdbName == "" {
  1233. br.Msg = "请输入指标名称"
  1234. return
  1235. }
  1236. indexNames = append(indexNames, v.EdbName)
  1237. resp = append(resp, &NameCheckResult{
  1238. EdbCode: v.EdbCode,
  1239. EdbName: v.EdbName,
  1240. })
  1241. dataItems, err := data_manage.GetEdbDataAllByEdbCode(v.EdbCode, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, 0, utils.EDB_DATA_LIMIT)
  1242. if err != nil && err.Error() != utils.ErrNoRow() {
  1243. br.Msg = "获取失败"
  1244. br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
  1245. return
  1246. }
  1247. if len(dataItems) <= 0 {
  1248. respItem, err := data.AddEdbData(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, v.EdbCode, v.Frequency)
  1249. if err != nil {
  1250. br.Msg = "获取失败"
  1251. br.ErrMsg = "获取失败,Err:" + err.Error()
  1252. return
  1253. }
  1254. if respItem.Ret != 200 {
  1255. br.Msg = "未搜索到该指标"
  1256. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + v.EdbCode
  1257. return
  1258. }
  1259. }
  1260. }
  1261. // 重名校验
  1262. edbList, e := data_manage.GetEdbInfoByNameArr(indexNames, utils.EDB_INFO_TYPE)
  1263. if e != nil {
  1264. br.Msg = "操作失败"
  1265. br.ErrMsg = "获取重名指标失败, Err: " + e.Error()
  1266. return
  1267. }
  1268. nameExists := make(map[string]bool)
  1269. for _, v := range edbList {
  1270. nameExists[v.EdbName] = true
  1271. }
  1272. if len(nameExists) > 0 {
  1273. for _, v := range resp {
  1274. v.Exist = nameExists[v.EdbName]
  1275. }
  1276. }
  1277. br.Data = resp
  1278. br.Msg = "校验成功"
  1279. br.Ret = 200
  1280. br.Success = true
  1281. }
  1282. // BatchAdd
  1283. // @Title 批量新增
  1284. // @Description 批量新增
  1285. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  1286. // @Success 200 string "操作成功"
  1287. // @router /mysteel_chemical/batch_add [post]
  1288. func (this *EdbInfoController) BatchAdd() {
  1289. br := new(models.BaseResponse).Init()
  1290. defer func() {
  1291. if br.ErrMsg == "" {
  1292. br.IsSendEmail = false
  1293. }
  1294. this.Data["json"] = br
  1295. this.ServeJSON()
  1296. }()
  1297. sysUser := this.SysUser
  1298. if sysUser == nil {
  1299. br.Msg = "请登录"
  1300. br.ErrMsg = "请登录,SysUser Is Empty"
  1301. br.Ret = 408
  1302. return
  1303. }
  1304. deleteCache := true
  1305. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_MYSTEEL_CHEMICAL_" + strconv.Itoa(sysUser.AdminId)
  1306. defer func() {
  1307. if deleteCache {
  1308. _ = utils.Rc.Delete(cacheKey)
  1309. }
  1310. }()
  1311. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1312. deleteCache = false
  1313. br.Msg = "系统处理中,请稍后重试!"
  1314. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  1315. return
  1316. }
  1317. var req []*data_manage.AddEdbInfoReq
  1318. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1319. br.Msg = "参数解析异常!"
  1320. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  1321. return
  1322. }
  1323. if len(req) == 0 {
  1324. br.Msg = "请选择指标"
  1325. return
  1326. }
  1327. if len(req) > 30 {
  1328. br.Msg = "批量添加指标数量不得超过30个"
  1329. return
  1330. }
  1331. for _, v := range req {
  1332. v.EdbCode = strings.TrimSpace(v.EdbCode)
  1333. if v.EdbCode == "" {
  1334. br.Msg = "指标ID不可为空"
  1335. return
  1336. }
  1337. v.EdbName = strings.TrimSpace(v.EdbName)
  1338. if v.EdbName == "" {
  1339. br.Msg = "请输入指标名称"
  1340. return
  1341. }
  1342. v.Frequency = strings.TrimSpace(v.Frequency)
  1343. if v.Frequency == "" {
  1344. br.Msg = "请选择频度"
  1345. return
  1346. }
  1347. v.Unit = strings.TrimSpace(v.Unit)
  1348. if v.Unit == "" {
  1349. br.Msg = "请输入单位"
  1350. return
  1351. }
  1352. if v.ClassifyId <= 0 {
  1353. br.Msg = "请选择分类"
  1354. return
  1355. }
  1356. }
  1357. // 限定同一时间最多批量新增30个指标
  1358. for _, v := range req {
  1359. var r data.MysteelChemicalIndexSource2EdbReq
  1360. r.EdbCode = v.EdbCode
  1361. r.EdbName = v.EdbName
  1362. r.Frequency = v.Frequency
  1363. r.Unit = v.Unit
  1364. r.ClassifyId = v.ClassifyId
  1365. r.AdminId = sysUser.AdminId
  1366. r.AdminRealName = sysUser.RealName
  1367. edbInfo, e, errMsg, skip := data.MysteelChemicalIndexSource2Edb(r, this.Lang)
  1368. if e != nil {
  1369. br.Msg = "操作失败"
  1370. if errMsg != "" {
  1371. br.Msg = errMsg
  1372. }
  1373. br.ErrMsg = e.Error()
  1374. return
  1375. }
  1376. if skip {
  1377. continue
  1378. }
  1379. // 试用平台更新用户累计新增指标数
  1380. if utils.BusinessCode == utils.BusinessCodeSandbox {
  1381. go func() {
  1382. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  1383. if e != nil {
  1384. tips := fmt.Sprintf("试用平台更新用户累计新增指标数-获取用户失败, Err: " + e.Error())
  1385. utils.FileLog.Info(tips)
  1386. return
  1387. }
  1388. if adminItem.DepartmentName != "ETA试用客户" {
  1389. return
  1390. }
  1391. var ur etaTrialService.EtaTrialUserReq
  1392. ur.Mobile = adminItem.Mobile
  1393. _, _ = etaTrialService.UpdateUserIndexNum(ur)
  1394. }()
  1395. }
  1396. // 新增操作日志
  1397. {
  1398. edbLog := new(data_manage.EdbInfoLog)
  1399. edbLog.EdbInfoId = edbInfo.EdbInfoId
  1400. edbLog.SourceName = edbInfo.SourceName
  1401. edbLog.Source = edbInfo.Source
  1402. edbLog.EdbCode = edbInfo.EdbCode
  1403. edbLog.EdbName = edbInfo.EdbName
  1404. edbLog.ClassifyId = edbInfo.ClassifyId
  1405. edbLog.SysUserId = sysUser.AdminId
  1406. edbLog.SysUserRealName = sysUser.RealName
  1407. edbLog.CreateTime = time.Now()
  1408. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1409. edbLog.Status = "新增指标"
  1410. edbLog.Method = this.Ctx.Input.URI()
  1411. go data_manage.AddEdbInfoLog(edbLog)
  1412. }
  1413. }
  1414. br.Msg = "操作成功"
  1415. br.Ret = 200
  1416. br.Success = true
  1417. br.IsAddLog = true
  1418. }
  1419. // EdbInfoAdd
  1420. // @Title 新增指标接口
  1421. // @Description 新增指标接口
  1422. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  1423. // @Success Ret=200 保存成功
  1424. // @router /mysteel_chemical/edb_info/add [post]
  1425. func (this *EdbInfoController) Add() {
  1426. br := new(models.BaseResponse).Init()
  1427. defer func() {
  1428. this.Data["json"] = br
  1429. this.ServeJSON()
  1430. }()
  1431. sysUser := this.SysUser
  1432. if sysUser == nil {
  1433. br.Msg = "请登录"
  1434. br.ErrMsg = "请登录,SysUser Is Empty"
  1435. br.Ret = 408
  1436. return
  1437. }
  1438. deleteCache := true
  1439. cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  1440. defer func() {
  1441. if deleteCache {
  1442. utils.Rc.Delete(cacheKey)
  1443. }
  1444. }()
  1445. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1446. deleteCache = false
  1447. br.Msg = "系统处理中,请稍后重试!"
  1448. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  1449. return
  1450. }
  1451. var req data_manage.AddEdbInfoReq
  1452. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1453. if err != nil {
  1454. br.Msg = "参数解析异常!"
  1455. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1456. return
  1457. }
  1458. req.EdbName = strings.Trim(req.EdbName, " ")
  1459. req.EdbCode = strings.Trim(req.EdbCode, " ")
  1460. if req.EdbCode == "" {
  1461. br.Msg = "指标ID不能为空"
  1462. return
  1463. }
  1464. if req.EdbName == "" {
  1465. br.Msg = "指标名称不能为空"
  1466. return
  1467. }
  1468. if req.Frequency == "" {
  1469. br.Msg = "频率不能为空"
  1470. return
  1471. }
  1472. if req.Unit == "" {
  1473. br.Msg = "单位不能为空"
  1474. return
  1475. }
  1476. if req.ClassifyId <= 0 {
  1477. br.Msg = "请选择分类"
  1478. return
  1479. }
  1480. tmpInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(req.EdbCode)
  1481. if err != nil {
  1482. if err.Error() != utils.ErrNoRow() {
  1483. br.Msg = "获取失败"
  1484. br.ErrMsg = "获取失败,Err:" + err.Error()
  1485. return
  1486. }
  1487. }
  1488. var source int
  1489. if tmpInfo != nil {
  1490. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  1491. } else {
  1492. br.Msg = "指标不存在"
  1493. return
  1494. }
  1495. // 指标入库
  1496. 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)
  1497. if err != nil {
  1498. br.Msg = "保存失败"
  1499. if errMsg != `` {
  1500. br.Msg = errMsg
  1501. }
  1502. br.ErrMsg = err.Error()
  1503. br.IsSendEmail = isSendEmail
  1504. return
  1505. }
  1506. // 试用平台更新用户累计新增指标数
  1507. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  1508. if e != nil {
  1509. br.Msg = "操作失败"
  1510. br.ErrMsg = "获取系统用户数据失败,Err:" + e.Error()
  1511. return
  1512. }
  1513. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  1514. go func() {
  1515. var r etaTrialService.EtaTrialUserReq
  1516. r.Mobile = adminItem.Mobile
  1517. _, _ = etaTrialService.UpdateUserIndexNum(r)
  1518. }()
  1519. }
  1520. //新增操作日志
  1521. {
  1522. // 添加钢联指标更新日志
  1523. if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  1524. go data_stat.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", sysUser, 2)
  1525. }
  1526. edbLog := new(data_manage.EdbInfoLog)
  1527. edbLog.EdbInfoId = edbInfo.EdbInfoId
  1528. edbLog.SourceName = edbInfo.SourceName
  1529. edbLog.Source = edbInfo.Source
  1530. edbLog.EdbCode = edbInfo.EdbCode
  1531. edbLog.EdbName = edbInfo.EdbName
  1532. edbLog.ClassifyId = edbInfo.ClassifyId
  1533. edbLog.SysUserId = sysUser.AdminId
  1534. edbLog.SysUserRealName = sysUser.RealName
  1535. edbLog.CreateTime = time.Now()
  1536. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1537. edbLog.Status = "新增指标"
  1538. edbLog.Method = this.Ctx.Input.URI()
  1539. go data_manage.AddEdbInfoLog(edbLog)
  1540. }
  1541. // 更新es
  1542. go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  1543. resp := new(data_manage.AddEdbInfoResp)
  1544. resp.EdbInfoId = edbInfo.EdbInfoId
  1545. resp.UniqueCode = edbInfo.UniqueCode
  1546. br.Ret = 200
  1547. br.Success = true
  1548. br.Msg = "保存成功"
  1549. br.Data = resp
  1550. br.IsAddLog = true
  1551. }
  1552. // AddCheck
  1553. // @Title 新增校验
  1554. // @Description 新增校验
  1555. // @Param request body request.BusinessDataBatchAddCheckReq true "type json string"
  1556. // @Success 200 string "操作成功"
  1557. // @router /mysteel_chemical/edb_info/add_check [post]
  1558. func (c *EdbInfoController) AddCheck() {
  1559. br := new(models.BaseResponse).Init()
  1560. defer func() {
  1561. if br.ErrMsg == "" {
  1562. br.IsSendEmail = false
  1563. }
  1564. c.Data["json"] = br
  1565. c.ServeJSON()
  1566. }()
  1567. sysUser := c.SysUser
  1568. if sysUser == nil {
  1569. br.Msg = "请登录"
  1570. br.ErrMsg = "请登录,SysUser Is Empty"
  1571. br.Ret = 408
  1572. return
  1573. }
  1574. var req *data_manage.MysteelChemicalDataBatchAddCheckReq
  1575. if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
  1576. br.Msg = "参数解析异常!"
  1577. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  1578. return
  1579. }
  1580. codeMax := 30
  1581. codeLen := len(req.IndexCodes)
  1582. // 获取指标库已有指标
  1583. existsEdb, e := data_manage.GetEdbCodesBySource(utils.DATA_SOURCE_MYSTEEL_CHEMICAL)
  1584. if e != nil {
  1585. br.Msg = "获取失败"
  1586. br.ErrMsg = "获取自有数据已添加的指标失败, Err: " + e.Error()
  1587. return
  1588. }
  1589. existMap := make(map[string]*data_manage.EdbInfo)
  1590. for _, v := range existsEdb {
  1591. existMap[v.EdbCode] = v
  1592. }
  1593. obj := data_manage.BaseFromMysteelChemicalIndex{}
  1594. if codeLen == 0 {
  1595. br.Msg = "请选择指标"
  1596. return
  1597. }
  1598. if codeLen > codeMax {
  1599. br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
  1600. return
  1601. }
  1602. // 查询选中的指标
  1603. cond := fmt.Sprintf(` AND %s IN (%s)`, data_manage.BaseFromMysteelChemicalIndexCols.IndexCode, utils.GetOrmInReplace(codeLen))
  1604. pars := make([]interface{}, 0)
  1605. pars = append(pars, req.IndexCodes)
  1606. list, e := obj.GeItemsByCondition(cond, pars, 0)
  1607. if e != nil {
  1608. br.Msg = "获取失败"
  1609. br.ErrMsg = "获取自有数据原始指标列表失败, Err: " + e.Error()
  1610. return
  1611. }
  1612. if len(list) > codeMax {
  1613. br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
  1614. return
  1615. }
  1616. resp := make([]*data_manage.BaseFromMysteelChemicalIndexItem, 0)
  1617. for _, v := range list {
  1618. if v.EdbInfoId > 0 {
  1619. v.EdbExist = 1
  1620. }
  1621. resp = append(resp, v)
  1622. }
  1623. br.Data = resp
  1624. br.Msg = "校验成功"
  1625. br.Ret = 200
  1626. br.Success = true
  1627. }
  1628. // MysteelChemicalSearch
  1629. // @Title 钢联化工指标查询
  1630. // @Description 钢联化工指标查询
  1631. // @Param BaseFromMysteelChemicalClassifyIds query string true "分类id"
  1632. // @Param Keyword query string true "名称关键词"
  1633. // @Success 200 {object} data_manage.LzFrequency
  1634. // @router /mysteel_chemical/batch_search [get]
  1635. func (this *EdbInfoController) MysteelChemicalBatchSearch() {
  1636. br := new(models.BaseResponse).Init()
  1637. defer func() {
  1638. this.Data["json"] = br
  1639. this.ServeJSON()
  1640. }()
  1641. sysUser := this.SysUser
  1642. if sysUser == nil {
  1643. br.Msg = "请登录"
  1644. br.ErrMsg = "请登录,SysUser Is Empty"
  1645. br.Ret = 408
  1646. return
  1647. }
  1648. classifyIdStr := this.GetString("BaseFromMysteelChemicalClassifyIds")
  1649. var condition string
  1650. var pars []interface{}
  1651. classifyIds := strings.Split(classifyIdStr, ",")
  1652. if len(classifyIds) > 0 && classifyIds[0] != `` {
  1653. condition += " AND base_from_mysteel_chemical_classify_id IN (" + utils.GetOrmInReplace(len(classifyIds)) + " ) "
  1654. pars = append(pars, classifyIds)
  1655. }
  1656. keyword := this.GetString("Keyword")
  1657. if keyword != `` {
  1658. condition += " AND (index_name like ? OR index_code like ?) "
  1659. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  1660. }
  1661. if classifyIdStr == `` && keyword == `` {
  1662. var list = make([]*data_manage.MysteelChemicalList, 0)
  1663. br.Ret = 200
  1664. br.Success = true
  1665. br.Msg = "获取成功"
  1666. br.Data = list
  1667. return
  1668. }
  1669. list, err := data_manage.GetMysteelChemicalIndex(condition, pars)
  1670. if err != nil {
  1671. br.Msg = "获取失败"
  1672. br.ErrMsg = "获取失败,Err:" + err.Error()
  1673. return
  1674. }
  1675. classifyIdInts := make([]int, 0)
  1676. for _, v := range list {
  1677. v.UniqueCode = fmt.Sprint(v.BaseFromMysteelChemicalClassifyId, "_", v.Id)
  1678. if v.BaseFromMysteelChemicalClassifyId > 0 {
  1679. classifyIdInts = append(classifyIdInts, v.BaseFromMysteelChemicalClassifyId)
  1680. }
  1681. }
  1682. if len(classifyIdInts) > 0 {
  1683. // 查询父级分类信息
  1684. classifyList, e := data_manage.GetBaseFromMysteelChemicalClassifyByIds(classifyIdInts)
  1685. if e != nil {
  1686. br.Msg = "获取目录信息失败"
  1687. br.ErrMsg = "获取失获取目录信息失败,Err:" + e.Error()
  1688. return
  1689. }
  1690. classifyListMap := make(map[int]int, 0)
  1691. for _, v := range classifyList {
  1692. classifyListMap[v.BaseFromMysteelChemicalClassifyId] = v.ParentId
  1693. }
  1694. for _, v := range list {
  1695. v.UniqueCode = fmt.Sprint(v.BaseFromMysteelChemicalClassifyId, "_", v.Id)
  1696. if p, ok := classifyListMap[v.BaseFromMysteelChemicalClassifyId]; ok {
  1697. v.ParentClassifyId = p
  1698. }
  1699. }
  1700. }
  1701. br.Ret = 200
  1702. br.Success = true
  1703. br.Msg = "获取成功"
  1704. br.Data = list
  1705. }