target.go 118 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081
  1. /*
  2. * Copyright (c) 2023. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  3. * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
  4. * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
  5. * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
  6. * Vestibulum commodo. Ut rhoncus gravida arcu.
  7. */
  8. package controllers
  9. import (
  10. "encoding/json"
  11. "eta/eta_api/models"
  12. "eta/eta_api/models/data_manage"
  13. "eta/eta_api/models/data_source"
  14. "eta/eta_api/models/system"
  15. "eta/eta_api/services/alarm_msg"
  16. "eta/eta_api/services/data"
  17. "eta/eta_api/utils"
  18. "fmt"
  19. "os"
  20. "path/filepath"
  21. "reflect"
  22. "sort"
  23. "strconv"
  24. "strings"
  25. "time"
  26. "github.com/rdlucklib/rdluck_tools/paging"
  27. "github.com/shopspring/decimal"
  28. "github.com/tealeg/xlsx"
  29. )
  30. // TargetController 手工指标服务(鉴权)
  31. type TargetController struct {
  32. BaseAuthController
  33. }
  34. // TargetCommonController 手工指标服务(不鉴权)
  35. type TargetCommonController struct {
  36. BaseCommonController
  37. }
  38. // DataList
  39. // @Title 获取指标列表
  40. // @Description 获取指标列表接口
  41. // @Param PageSize query int true "每页数据条数"
  42. // @Param CurrentIndex query int true "当前页页码,从1开始"
  43. // @Param StartDate query string true "开始日期"
  44. // @Param EndDate query string true "结束日期"
  45. // @Param Frequency query string true "频度"
  46. // @Param ClassifyId query int true "分类"
  47. // @Param KeyWord query string true "名称关键词"
  48. // @Param TradeCode query string true "指标唯一编码"
  49. // @Success 200 {object} models.DataListResp
  50. // @router /data/list [get]
  51. func (this *TargetController) DataList() {
  52. br := new(models.BaseResponse).Init()
  53. defer func() {
  54. this.Data["json"] = br
  55. this.ServeJSON()
  56. }()
  57. pageSize, _ := this.GetInt("PageSize")
  58. currentIndex, _ := this.GetInt("CurrentIndex")
  59. keyWord := this.GetString("KeyWord")
  60. startDate := this.GetString("StartDate")
  61. endDate := this.GetString("EndDate")
  62. frequency := this.GetString("Frequency")
  63. tradeCode := this.GetString("TradeCode")
  64. classifyId, _ := this.GetInt("ClassifyId") //分类
  65. var startSize int
  66. if pageSize <= 0 {
  67. pageSize = utils.PageSize20
  68. }
  69. if currentIndex <= 0 {
  70. currentIndex = 1
  71. }
  72. startSize = utils.StartIndex(currentIndex, pageSize)
  73. var condition string
  74. var pars []interface{}
  75. if keyWord != "" {
  76. condition += ` AND a.SEC_NAME LIKE ? `
  77. pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
  78. }
  79. if startDate != "" {
  80. condition += ` AND c.DT >= ? `
  81. pars = append(pars, startDate)
  82. }
  83. if endDate != "" {
  84. condition += ` AND c.DT <= ? `
  85. pars = append(pars, endDate)
  86. }
  87. if frequency != "" {
  88. condition += ` AND a.frequency = ? `
  89. pars = append(pars, frequency)
  90. }
  91. if classifyId > 0 {
  92. condition += ` AND a.classify_id = ? `
  93. pars = append(pars, classifyId)
  94. }
  95. if tradeCode != "" {
  96. condition += ` AND c.TRADE_CODE = ? `
  97. pars = append(pars, tradeCode)
  98. }
  99. total, err := models.GetDataListCount(condition, pars)
  100. if err != nil {
  101. br.Msg = "获取失败"
  102. br.ErrMsg = "获取失败,Err:" + err.Error()
  103. return
  104. }
  105. list, err := models.GetDataList(condition, pars, startSize, pageSize)
  106. if err != nil {
  107. br.Msg = "获取失败"
  108. br.ErrMsg = "获取失败,Err:" + err.Error()
  109. return
  110. }
  111. page := paging.GetPaging(currentIndex, pageSize, total)
  112. resp := new(models.DataListResp)
  113. resp.Paging = page
  114. if len(list) <= 0 {
  115. list = make([]*models.DataList, 0)
  116. }
  117. resp.List = list
  118. br.Ret = 200
  119. br.Success = true
  120. br.Msg = "获取成功"
  121. br.Data = resp
  122. }
  123. // DataAdd
  124. // @Title 录入数据
  125. // @Description 录入数据接口
  126. // @Param request body models.DataAddReq true "type json string"
  127. // @Success 200 Ret=200 录入成功
  128. // @router /data/add [post]
  129. func (this *TargetController) DataAdd() {
  130. br := new(models.BaseResponse).Init()
  131. defer func() {
  132. this.Data["json"] = br
  133. this.ServeJSON()
  134. }()
  135. var req models.DataAddReq
  136. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  137. if err != nil {
  138. br.Msg = "参数解析异常!"
  139. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  140. return
  141. }
  142. if req.TradeCode == "" {
  143. br.Msg = "指标编码不可为空!"
  144. return
  145. }
  146. if req.CreateDate == "" {
  147. br.Msg = "请选择日期"
  148. return
  149. }
  150. item, err := models.GetDataInfo(req.TradeCode, req.CreateDate)
  151. if err != nil && err.Error() != utils.ErrNoRow() {
  152. br.Msg = "获取信息失败!"
  153. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  154. return
  155. }
  156. if item != nil {
  157. br.Msg = "该指标当前日期下,数据已录入"
  158. return
  159. }
  160. edbdata := new(models.Edbdata)
  161. edbdata.TradeCode = req.TradeCode
  162. edbdata.Dt = req.CreateDate
  163. edbdata.Close = req.Close
  164. edbdata.ModifyTime = time.Now()
  165. _, err = models.AddEdbdata(edbdata)
  166. if err != nil {
  167. br.Msg = "新增失败"
  168. br.ErrMsg = "新增失败,Err:" + err.Error()
  169. return
  170. }
  171. // 添加操作记录
  172. go func() {
  173. record := &models.EdbinfoOpRecord{
  174. TradeCode: edbdata.TradeCode,
  175. Remark: "更新数据",
  176. UserId: this.SysUser.AdminId,
  177. UserName: this.SysUser.RealName,
  178. CreateTime: time.Now(),
  179. }
  180. data.ModifyManualEdbMaxMinDate(edbdata.TradeCode)
  181. _ = record.Create()
  182. //将该指标的code加入到 “手工数据导入后刷新” 缓存
  183. if utils.Re == nil {
  184. err := utils.Rc.LPush(utils.CACHE_IMPORT_MANUAL_DATA, req.TradeCode)
  185. if err != nil {
  186. fmt.Println("CACHE_IMPORT_MANUAL_DATA LPush Err:" + err.Error())
  187. }
  188. }
  189. }()
  190. br.Ret = 200
  191. br.Success = true
  192. br.Msg = "新增成功"
  193. }
  194. // DataEdit
  195. // @Title 编辑数据
  196. // @Description 编辑数据接口
  197. // @Param request body models.DataEditReq true "type json string"
  198. // @Success 200 Ret=200 编辑数据成功
  199. // @router /data/edit [post]
  200. func (this *TargetController) DataEdit() {
  201. br := new(models.BaseResponse).Init()
  202. defer func() {
  203. this.Data["json"] = br
  204. this.ServeJSON()
  205. }()
  206. var req models.DataEditReq
  207. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  208. if err != nil {
  209. br.Msg = "参数解析异常!"
  210. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  211. return
  212. }
  213. if req.TradeCode == "" {
  214. br.Msg = "指标编码不可为空!"
  215. return
  216. }
  217. if req.CreateDate == "" {
  218. br.Msg = "请选择日期"
  219. return
  220. }
  221. close := ""
  222. loc := reflect.ValueOf(req.Close).Kind().String()
  223. if loc == "string" {
  224. close = req.Close.(string)
  225. } else if loc == "int" {
  226. closeInt := req.Close.(int)
  227. close = strconv.Itoa(closeInt)
  228. } else if loc == "float64" {
  229. close64 := req.Close.(float64)
  230. close = strconv.FormatFloat(close64, 'g', 30, 64)
  231. } else {
  232. close = ""
  233. }
  234. edbdata := new(models.Edbdata)
  235. edbdata.TradeCode = req.TradeCode
  236. edbdata.Dt = req.CreateDate
  237. edbdata.Close = close
  238. edbdata.ModifyTime = time.Now()
  239. if req.OldCreateDate == "" {
  240. item, err := models.GetDataInfo(req.TradeCode, req.CreateDate)
  241. if err != nil && err.Error() != utils.ErrNoRow() {
  242. br.Msg = "获取信息失败!"
  243. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  244. return
  245. }
  246. if item == nil { //新增
  247. _, err = models.AddEdbdata(edbdata)
  248. if err != nil {
  249. br.Msg = "新增失败"
  250. br.ErrMsg = "新增失败,Err:" + err.Error()
  251. return
  252. }
  253. } else { //修改
  254. err = models.EditEdbdata(edbdata)
  255. if err != nil {
  256. br.Msg = "编辑失败"
  257. br.ErrMsg = "编辑失败,Err:" + err.Error()
  258. return
  259. }
  260. }
  261. } else {
  262. if req.CreateDate == req.OldCreateDate { //修改
  263. err = models.EditEdbdata(edbdata)
  264. if err != nil {
  265. br.Msg = "编辑失败"
  266. br.ErrMsg = "编辑失败,Err:" + err.Error()
  267. return
  268. }
  269. } else {
  270. item, err := models.GetDataInfo(req.TradeCode, req.CreateDate)
  271. if err != nil && err.Error() != utils.ErrNoRow() {
  272. br.Msg = "获取信息失败!"
  273. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  274. return
  275. }
  276. if item == nil {
  277. _, err = models.AddEdbdata(edbdata)
  278. if err != nil {
  279. br.Msg = "新增失败"
  280. br.ErrMsg = "新增失败,Err:" + err.Error()
  281. return
  282. }
  283. } else {
  284. err = models.EditEdbdata(edbdata)
  285. if err != nil {
  286. br.Msg = "编辑失败"
  287. br.ErrMsg = "编辑失败,Err:" + err.Error()
  288. return
  289. }
  290. }
  291. oldItem, err := models.GetDataInfo(req.TradeCode, req.OldCreateDate)
  292. if err != nil && err.Error() != utils.ErrNoRow() {
  293. br.Msg = "获取信息失败!"
  294. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  295. return
  296. }
  297. if oldItem != nil {
  298. record := new(models.EdbdataDeleteRecord)
  299. record.TradeCode = oldItem.TradeCode
  300. record.Dt = oldItem.Dt
  301. record.Close = oldItem.Close
  302. record.ModifyTime = oldItem.ModifyTime
  303. record.CreateTime = time.Now()
  304. record.SysUserId = this.SysUser.AdminId
  305. _, err = models.AddEdbdataDeleteRecord(record)
  306. if err != nil {
  307. br.Msg = "编辑失败"
  308. br.ErrMsg = "新增删除记录失败,Err:" + err.Error()
  309. return
  310. }
  311. //删除数据
  312. models.DeleteEdbData(req.TradeCode, req.OldCreateDate)
  313. }
  314. }
  315. }
  316. // 数据操作完后的最大最小值/指标库更新
  317. {
  318. go func() {
  319. data.ModifyManualEdbMaxMinDate(req.TradeCode)
  320. //将该指标的code加入到 “手工数据导入后刷新” 缓存
  321. if utils.Re == nil {
  322. err := utils.Rc.LPush(utils.CACHE_IMPORT_MANUAL_DATA, req.TradeCode)
  323. if err != nil {
  324. fmt.Println("CACHE_IMPORT_MANUAL_DATA LPush Err:" + err.Error())
  325. }
  326. }
  327. }()
  328. }
  329. br.Ret = 200
  330. br.Success = true
  331. br.Msg = "编辑成功"
  332. }
  333. // BatchDataEdit
  334. // @Title 批量编辑数据
  335. // @Description 批量编辑数据接口
  336. // @Param request body models.BatchDataEditReq true "type json string"
  337. // @Success 200 Ret=200 编辑数据成功
  338. // @router /data/batch_edit [post]
  339. func (this *TargetController) BatchDataEdit() {
  340. br := new(models.BaseResponse).Init()
  341. defer func() {
  342. this.Data["json"] = br
  343. this.ServeJSON()
  344. }()
  345. var req models.BatchDataEditReq
  346. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  347. if err != nil {
  348. br.Msg = "参数解析异常!"
  349. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  350. return
  351. }
  352. if req.CreateDate == req.OldCreateDate { //修改
  353. br.Msg = "开始日期与结束日期一致!"
  354. return
  355. }
  356. edbDataEditList := make([]data.EdbDataEdit, 0)
  357. for _, trade := range req.List {
  358. if trade.TradeCode == "" {
  359. br.Msg = "指标编码不可为空!"
  360. return
  361. }
  362. close := ""
  363. loc := reflect.ValueOf(trade.Close).Kind().String()
  364. if loc == "string" {
  365. close = trade.Close.(string)
  366. } else if loc == "int" {
  367. closeInt := trade.Close.(int)
  368. close = strconv.Itoa(closeInt)
  369. } else if loc == "float64" {
  370. close64 := trade.Close.(float64)
  371. close = strconv.FormatFloat(close64, 'g', 30, 64)
  372. } else {
  373. close = ""
  374. }
  375. edbDataEdit := data.EdbDataEdit{
  376. OldCreateDate: req.OldCreateDate,
  377. CreateDate: req.CreateDate,
  378. TradeCode: trade.TradeCode,
  379. Close: close,
  380. }
  381. edbDataEditList = append(edbDataEditList, edbDataEdit)
  382. }
  383. //批量修改
  384. failEdbDataList, err := data.BatchEdbData(req.OldCreateDate, req.CreateDate, edbDataEditList, this.SysUser.AdminId)
  385. if err != nil {
  386. br.Msg = "批量修改失败"
  387. br.ErrMsg = "批量修改失败:" + err.Error()
  388. return
  389. }
  390. br.Ret = 200
  391. br.Success = true
  392. br.Data = failEdbDataList
  393. br.Msg = "编辑成功"
  394. }
  395. // TargetList
  396. // @Title 指标列表
  397. // @Description 指标列表接口
  398. // @Param PageSize query int true "每页数据条数"
  399. // @Param CurrentIndex query int true "当前页页码,从1开始"
  400. // @Param StartDate query string true "开始日期"
  401. // @Param EndDate query string true "结束日期"
  402. // @Param Frequency query string true "频度"
  403. // @Param ClassifyId query int true "分类"
  404. // @Param KeyWord query string true "名称关键词"
  405. // @Success 200 {object} models.TargetListResp
  406. // @router /target/list [get]
  407. func (this *TargetController) TargetList() {
  408. br := new(models.BaseResponse).Init()
  409. defer func() {
  410. this.Data["json"] = br
  411. this.ServeJSON()
  412. }()
  413. sysUser := this.SysUser
  414. if sysUser == nil {
  415. br.Msg = "请登录"
  416. br.Ret = 408
  417. return
  418. }
  419. resp := new(models.TargetListResp)
  420. pageSize, _ := this.GetInt("PageSize")
  421. currentIndex, _ := this.GetInt("CurrentIndex")
  422. keyWord := this.GetString("KeyWord")
  423. startDate := this.GetString("StartDate")
  424. endDate := this.GetString("EndDate")
  425. frequency := this.GetString("Frequency")
  426. classifyId, _ := this.GetInt("ClassifyId") //分类
  427. var startSize int
  428. if pageSize <= 0 {
  429. pageSize = utils.PageSize20
  430. }
  431. if currentIndex <= 0 {
  432. currentIndex = 1
  433. }
  434. startSize = utils.StartIndex(currentIndex, pageSize)
  435. var condition string
  436. var pars []interface{}
  437. userId := sysUser.AdminId
  438. //超管账号可以查看分类下的所有频度数据
  439. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  440. userId = 0
  441. }
  442. //获取账户所拥有权限的分类id集合
  443. classifyIdStrList, err := data.GetEdbClassifyListByAdminId(int64(userId))
  444. if err != nil {
  445. br.Msg = "获取分类数据失败"
  446. return
  447. }
  448. total := 0
  449. list := make([]*models.EdbinfoItem, 0)
  450. //有分类数据权限才查询
  451. if len(classifyIdStrList) > 0 {
  452. condition += ` AND a.classify_id in (` + strings.Join(classifyIdStrList, ",") + `) `
  453. //关键字
  454. if keyWord != "" {
  455. condition += ` AND (a.SEC_NAME LIKE '%` + keyWord + `%' or a.TRADE_CODE LIKE '%` + keyWord + `%' )`
  456. }
  457. if startDate != "" {
  458. startDate = startDate + " 00:00:00"
  459. condition += ` AND a.create_date >= ? `
  460. pars = append(pars, startDate)
  461. }
  462. if endDate != "" {
  463. endDate = endDate + " 23:59:59"
  464. condition += ` AND a.create_date <= ? `
  465. pars = append(pars, endDate)
  466. }
  467. if frequency != "" {
  468. condition += ` AND a.frequency = ? `
  469. pars = append(pars, frequency)
  470. }
  471. if classifyId > 0 {
  472. condition += ` AND a.classify_id = ? `
  473. pars = append(pars, classifyId)
  474. }
  475. mobile := sysUser.Mobile
  476. total, err = models.GetEdbinfoListCount(condition, pars, mobile, sysUser.RoleType)
  477. if err != nil {
  478. br.Msg = "获取失败"
  479. br.ErrMsg = "获取失败,Err:" + err.Error()
  480. return
  481. }
  482. tmpList, err := models.GetEdbinfoItemList(condition, pars, startSize, pageSize, mobile, sysUser.RoleType)
  483. if err != nil {
  484. br.Msg = "获取失败"
  485. br.ErrMsg = "获取失败,Err:" + err.Error()
  486. return
  487. }
  488. if len(tmpList) <= 0 {
  489. list = make([]*models.EdbinfoItem, 0)
  490. } else {
  491. list = tmpList
  492. }
  493. systemUserMap := make(map[int]string)
  494. for k, v := range list {
  495. userName, ok := systemUserMap[v.UserId]
  496. if ok == false {
  497. systemUser, _ := system.GetSysAdminById(v.UserId)
  498. if systemUser != nil {
  499. userName = systemUser.RealName
  500. } else {
  501. userName = `无`
  502. }
  503. systemUserMap[v.UserId] = userName
  504. }
  505. list[k].UserName = userName
  506. }
  507. }
  508. page := paging.GetPaging(currentIndex, pageSize, total)
  509. resp.Paging = page
  510. resp.List = list
  511. br.Ret = 200
  512. br.Success = true
  513. br.Msg = "获取成功"
  514. br.Data = resp
  515. }
  516. // TargetAdd
  517. // @Title 录入指标
  518. // @Description 录入指标接口
  519. // @Param request body models.EdbinfoAddReq true "type json string"
  520. // @Success 200 Ret=200 录入成功
  521. // @router /target/add [post]
  522. func (this *TargetController) TargetAdd() {
  523. br := new(models.BaseResponse).Init()
  524. defer func() {
  525. this.Data["json"] = br
  526. this.ServeJSON()
  527. }()
  528. var req models.EdbinfoAddReq
  529. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  530. if err != nil {
  531. br.Msg = "参数解析异常!"
  532. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  533. return
  534. }
  535. sysUser := this.SysUser
  536. if sysUser == nil {
  537. br.Msg = "请重新登录"
  538. return
  539. }
  540. tradeCode, err := models.GetMaxTradeCode()
  541. if err != nil {
  542. br.Msg = "获取数据失败"
  543. br.ErrMsg = "获取最大交易编码失败,Err:" + err.Error()
  544. return
  545. }
  546. maxTradeCode, err := utils.GetMaxTradeCode(tradeCode)
  547. if err != nil {
  548. br.Msg = "数据异常"
  549. br.ErrMsg = "获取编码信息失败,Err:" + err.Error()
  550. return
  551. }
  552. if maxTradeCode == "" {
  553. br.Msg = "编码为空,请联系技术"
  554. br.ErrMsg = "编码为空,请联系技术"
  555. return
  556. }
  557. if req.SecName == "" {
  558. br.Msg = "指标名称不能为空"
  559. return
  560. }
  561. item, err := models.GetEdbinfoBySecName(req.SecName)
  562. if err != nil && err.Error() != utils.ErrNoRow() {
  563. br.Msg = "获取信息失败!"
  564. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  565. return
  566. }
  567. if item != nil {
  568. br.Msg = "指标名称已存在"
  569. return
  570. }
  571. err = models.AddEdbinfo(maxTradeCode, req.SecName, req.Unit, "手动", req.Frequency, req.NoticeTime, req.ClassifyId, sysUser.AdminId, sysUser.RealName)
  572. if err != nil {
  573. br.Msg = "新增失败"
  574. br.ErrMsg = "新增失败,Err:" + err.Error()
  575. return
  576. }
  577. err = models.AddEdbinfoUser(maxTradeCode, sysUser.Mobile)
  578. if err != nil {
  579. br.Msg = "新增失败"
  580. br.ErrMsg = "新增失败,Err:" + err.Error()
  581. return
  582. }
  583. br.Ret = 200
  584. br.Success = true
  585. br.Msg = "新增成功"
  586. }
  587. // TargetEdit
  588. // @Title 编辑指标
  589. // @Description 编辑指标
  590. // @Param request body models.EdbinfoEditReq true "type json string"
  591. // @Success 200 Ret=200 录入成功
  592. // @router /target/edit [post]
  593. func (this *TargetController) TargetEdit() {
  594. br := new(models.BaseResponse).Init()
  595. defer func() {
  596. this.Data["json"] = br
  597. this.ServeJSON()
  598. }()
  599. var req models.EdbinfoEditReq
  600. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  601. if err != nil {
  602. br.Msg = "参数解析异常!"
  603. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  604. return
  605. }
  606. sysUser := this.SysUser
  607. if sysUser == nil {
  608. br.Msg = "请重新登录"
  609. return
  610. }
  611. if req.TradeCode == "" {
  612. br.Msg = "数据异常"
  613. br.ErrMsg = "最大编码为空"
  614. return
  615. }
  616. if req.SecName == "" {
  617. br.Msg = "指标名称不能为空"
  618. return
  619. }
  620. item, err := models.GetEdbinfoBySecName(req.SecName)
  621. if err != nil && err.Error() != utils.ErrNoRow() {
  622. br.Msg = "获取信息失败!"
  623. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  624. return
  625. }
  626. if item != nil {
  627. if req.TradeCode != item.TradeCode {
  628. br.Msg = "指标名称已存在"
  629. return
  630. }
  631. }
  632. err = models.EditEdbinfo(req.TradeCode, req.SecName, req.Unit, req.Frequency, req.NoticeTime, req.ClassifyId)
  633. if err != nil {
  634. br.Msg = "编辑失败"
  635. br.ErrMsg = "编辑失败,Err:" + err.Error()
  636. return
  637. }
  638. br.Ret = 200
  639. br.Success = true
  640. br.Msg = "编辑成功"
  641. }
  642. // TargetSearch
  643. // @Title 搜索指标
  644. // @Description 搜索指标
  645. // @Param ClassifyId query int true "分类"
  646. // @Param KeyWord query string true "名称关键词"
  647. // @Success 200 {object} models.SearchTargetListResp
  648. // @router /target/search [get]
  649. func (this *TargetController) TargetSearch() {
  650. br := new(models.BaseResponse).Init()
  651. defer func() {
  652. this.Data["json"] = br
  653. this.ServeJSON()
  654. }()
  655. sysUser := this.SysUser
  656. if sysUser == nil {
  657. br.Msg = "请登录"
  658. br.Ret = 408
  659. return
  660. }
  661. classifyId, _ := this.GetInt("ClassifyId")
  662. keyWord := this.GetString("KeyWord")
  663. list, err := models.SearchTargetEntry(classifyId, keyWord)
  664. if err != nil {
  665. br.Msg = "获取失败"
  666. br.ErrMsg = "获取失败,Err:" + err.Error()
  667. return
  668. }
  669. resp := new(models.SearchTargetListResp)
  670. resp.List = list
  671. br.Ret = 200
  672. br.Success = true
  673. br.Msg = "获取成功"
  674. br.Data = resp
  675. }
  676. // ClassifyList
  677. // @Title 获取分类
  678. // @Description 获取分类
  679. // @Success 200 {object} models.EdbdataClassifyResp
  680. // @router /classify [get]
  681. func (this *TargetController) ClassifyList() {
  682. br := new(models.BaseResponse).Init()
  683. defer func() {
  684. this.Data["json"] = br
  685. this.ServeJSON()
  686. }()
  687. sysUser := this.SysUser
  688. if sysUser == nil {
  689. br.Msg = "请登录"
  690. br.Ret = 408
  691. return
  692. }
  693. //mobile := sysUser.Mobile
  694. //var wxUserId int64
  695. //if mobile != "" {
  696. // wxUser, err := models.GetUserByMobile(mobile)
  697. // if err != nil && err.Error() != utils.ErrNoRow() {
  698. // br.Msg = "获取用户信息失败"
  699. // br.ErrMsg = "获取用户信息失败,err:" + err.Error()
  700. // return
  701. // }
  702. // if wxUser != nil {
  703. // wxUserId = wxUser.UserId
  704. // }
  705. //}
  706. var wxUserId int64
  707. wxUserId = int64(sysUser.AdminId)
  708. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  709. wxUserId = 0
  710. }
  711. list, err := models.GetEdbdataClassify(wxUserId)
  712. if err != nil {
  713. br.Msg = "获取失败"
  714. br.ErrMsg = "获取失败,Err:" + err.Error()
  715. return
  716. }
  717. classifyIdStrList := make([]string, 0)
  718. for _, classifyList := range list {
  719. if classifyList.Child != nil {
  720. for _, classify := range classifyList.Child {
  721. classifyIdStrList = append(classifyIdStrList, strconv.Itoa(classify.ClassifyId))
  722. }
  723. }
  724. }
  725. if len(classifyIdStrList) > 0 {
  726. edbInfoGroupCountList, err := models.GetEdbInfoGroupCountByClassifyIds(strings.Join(classifyIdStrList, ","))
  727. if err != nil {
  728. br.Msg = "获取失败"
  729. br.ErrMsg = "获取分类下有数据的指标数量失败,Err:" + err.Error()
  730. return
  731. }
  732. edbInfoGroupCountMap := make(map[int]int)
  733. for _, edbInfoGroupCount := range edbInfoGroupCountList {
  734. edbInfoGroupCountMap[edbInfoGroupCount.ClassifyId] = edbInfoGroupCount.Count
  735. }
  736. for _, classifyList := range list {
  737. classifyList.UniqueCode = utils.MD5(fmt.Sprint(classifyList.ClassifyId))
  738. if classifyList.Child != nil {
  739. for _, classify := range classifyList.Child {
  740. if total, ok := edbInfoGroupCountMap[classify.ClassifyId]; ok {
  741. classify.EdbInfoTotal = total
  742. classify.UniqueCode = utils.MD5(fmt.Sprint(classify.ClassifyId))
  743. }
  744. }
  745. }
  746. }
  747. }
  748. resp := new(models.EdbdataClassifyResp)
  749. resp.List = list
  750. br.Ret = 200
  751. br.Success = true
  752. br.Msg = "获取成功"
  753. br.Data = resp
  754. }
  755. // TemplateDownload
  756. // @Title 下载模板
  757. // @Description 下载模板
  758. // @Success 200 {object} models.EdbdataClassifyResp
  759. // @Param Source query int false "来源:1:模板1;2:模板2"
  760. // @router /template [get]
  761. func (this *TargetCommonController) TemplateDownload() {
  762. br := new(models.BaseResponse).Init()
  763. defer func() {
  764. this.Data["json"] = br
  765. this.ServeJSON()
  766. }()
  767. source, _ := this.GetInt("Source")
  768. switch source {
  769. case 2:
  770. this.Ctx.Output.Download("./static/template/导入模板2.xlsx", "数据导入模板2.xlsx")
  771. default:
  772. this.Ctx.Output.Download("./static/template/导入模板1.xlsx", "数据导入模板1.xlsx")
  773. }
  774. //this.Ctx.Output.Download("./static/数据导入模板.xlsx", "数据导入模板.xlsx")
  775. br.Ret = 200
  776. br.Success = true
  777. br.Msg = "下载成功"
  778. }
  779. // TemplateDownload
  780. // @Title 下载模板
  781. // @Description 下载模板
  782. // @Success 200 {object} models.EdbdataClassifyResp
  783. // @router /template/en [get]
  784. func (this *TargetCommonController) TemplateDownloadEn() {
  785. br := new(models.BaseResponse).Init()
  786. defer func() {
  787. this.Data["json"] = br
  788. this.ServeJSON()
  789. }()
  790. this.Ctx.Output.Download("./static/Data Import Template.xlsx", "Data Import Template.xlsx")
  791. br.Ret = 200
  792. br.Success = true
  793. br.Msg = "下载成功"
  794. }
  795. // ImportFailListDownload
  796. // @Title 下载失败列表
  797. // @Description 下载失败列表
  798. // @Success 200 {object} models.EdbdataClassifyResp
  799. // @router /import/failList [get]
  800. func (this *TargetController) ImportFailListDownload() {
  801. br := new(models.BaseResponse).Init()
  802. defer func() {
  803. this.Data["json"] = br
  804. this.ServeJSON()
  805. }()
  806. sysUser := this.SysUser
  807. if sysUser == nil {
  808. br.Msg = "请重新登录"
  809. return
  810. }
  811. item, err := models.GetFailList(sysUser.AdminId)
  812. if err != nil {
  813. br.Msg = "获取数据失败"
  814. br.Msg = "获取数据失败,Err:" + err.Error()
  815. return
  816. }
  817. xlsxFile := xlsx.NewFile()
  818. SheetName := "导入失败数据"
  819. if this.Lang == utils.EnLangVersion {
  820. SheetName = "Import Fail List"
  821. }
  822. sheet, err := xlsxFile.AddSheet(SheetName)
  823. headRow := sheet.AddRow()
  824. headRow.AddCell().SetValue("品种/Variety")
  825. headRow.AddCell().SetValue("指标名称/Indicator Name")
  826. headRow.AddCell().SetValue("指标日期/Indicator Date")
  827. headRow.AddCell().SetValue("值/Value")
  828. headRow.AddCell().SetValue("频度/Frequency")
  829. headRow.AddCell().SetValue("单位/Unit")
  830. headRow.AddCell().SetValue("备注/Note")
  831. for _, v := range item {
  832. row := sheet.AddRow()
  833. row.AddCell().SetValue(v.ClassifyName)
  834. row.AddCell().SetValue(v.SecName)
  835. row.AddCell().SetValue(v.CreateDate)
  836. row.AddCell().SetString(v.Close)
  837. row.AddCell().SetValue(v.Frequency)
  838. row.AddCell().SetValue(v.Unit)
  839. row.AddCell().SetValue(v.Remark)
  840. }
  841. fileName := time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  842. savePath := "./static/" + fileName
  843. err = xlsxFile.Save(savePath)
  844. if err != nil {
  845. br.Msg = "文件保存失败"
  846. br.ErrMsg = "文件保存失败,Err:" + err.Error()
  847. return
  848. }
  849. defer func() {
  850. os.Remove(savePath)
  851. }()
  852. finalFileName := "失败列表.xlsx"
  853. if this.Lang == utils.EnLangVersion {
  854. finalFileName = "Failure List.xlsx"
  855. }
  856. this.Ctx.Output.Download(savePath, finalFileName)
  857. }
  858. // ExportDataList
  859. // @Title 导出数据
  860. // @Description 导出数据列表
  861. // @Param StartDate query string true "开始日期"
  862. // @Param EndDate query string true "结束日期"
  863. // @Param Frequency query string true "频度"
  864. // @Param ClassifyId query int true "分类"
  865. // @Param KeyWord query string true "名称关键词"
  866. // @Param TradeCode query string true "指标唯一编码"
  867. // @Param Mobile query string true "手机号"
  868. // @Success 200 导出成功
  869. // @router /export/dataList [get]
  870. func (this *TargetController) ExportDataList() {
  871. br := new(models.BaseResponse).Init()
  872. defer func() {
  873. this.Data["json"] = br
  874. this.ServeJSON()
  875. }()
  876. sysUser := this.SysUser
  877. if sysUser == nil {
  878. br.Msg = "请重新登录"
  879. return
  880. }
  881. keyWord := this.GetString("KeyWord")
  882. startDate := this.GetString("StartDate")
  883. endDate := this.GetString("EndDate")
  884. frequency := this.GetString("Frequency")
  885. classifyId, _ := this.GetInt("ClassifyId") //分类
  886. mobile := this.GetString("Mobile") //分类
  887. tradeCode := this.GetString("TradeCode") //指标唯一编码
  888. var condition string
  889. var pars []interface{}
  890. // 指标名称
  891. if keyWord != "" {
  892. condition += ` AND a.SEC_NAME LIKE '%` + keyWord + `%'`
  893. }
  894. //分类ID
  895. if tradeCode != "" {
  896. condition += ` AND a.TRADE_CODE = ? `
  897. pars = append(pars, tradeCode)
  898. }
  899. if startDate != "" {
  900. condition += ` AND c.DT >= ? `
  901. pars = append(pars, startDate)
  902. }
  903. if endDate != "" {
  904. condition += ` AND c.DT <= ? `
  905. pars = append(pars, endDate)
  906. }
  907. if frequency != "" {
  908. condition += ` AND a.frequency = ? `
  909. pars = append(pars, frequency)
  910. }
  911. permissionUserId := sysUser.AdminId
  912. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  913. permissionUserId = 0
  914. }
  915. childClassifyIdList := make([]int, 0)
  916. // 所属分类
  917. if classifyId > 0 {
  918. // 获取有用权限的分类
  919. classifyList, err := models.GetEdbdataClassify(int64(permissionUserId))
  920. if err != nil {
  921. return
  922. }
  923. var isParent bool
  924. for _, v := range classifyList {
  925. if v.ClassifyId == classifyId {
  926. isParent = true
  927. childClassifyIdList = append(childClassifyIdList, v.ClassifyId)
  928. if v.Child != nil && len(v.Child) > 0 {
  929. for _, vv := range v.Child {
  930. childClassifyIdList = append(childClassifyIdList, vv.ClassifyId)
  931. }
  932. }
  933. break
  934. }
  935. }
  936. // 如果是最小级,那么就把自己放进去
  937. if !isParent {
  938. childClassifyIdList = append(childClassifyIdList, classifyId)
  939. }
  940. }
  941. // 如果所选分类是一级时,那么是一级下的所有分类;如果是二级时,那么是二级自己本身
  942. num := len(childClassifyIdList)
  943. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
  944. pars = append(pars, childClassifyIdList)
  945. if mobile != "" {
  946. condition += ` AND d.mobile=? `
  947. pars = append(pars, mobile)
  948. }
  949. userId := sysUser.AdminId
  950. //超管账号可以查看分类下的所有频度数据
  951. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  952. userId = 0
  953. }
  954. //获取账户所拥有权限的分类id集合
  955. classifyIdStrList, err := data.GetEdbClassifyListByAdminId(int64(userId))
  956. if err != nil {
  957. br.Msg = "获取分类数据失败"
  958. return
  959. }
  960. dir, _ := os.Executable()
  961. exPath := filepath.Dir(dir)
  962. downloadFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  963. xlsxFile := xlsx.NewFile()
  964. if err != nil {
  965. br.Msg = "生成文件失败"
  966. br.ErrMsg = "生成文件失败"
  967. return
  968. }
  969. var frequencies []string
  970. if len(childClassifyIdList) > 0 {
  971. frequencies, err = models.GetEdbDataFrequencyByClassifyIdList(childClassifyIdList)
  972. if err != nil {
  973. br.Msg = "查询频度失败"
  974. br.ErrMsg = "查询频度失败"
  975. return
  976. }
  977. } else if tradeCode != `` {
  978. manualEdb, err := models.GetEdbinfoByTradeCode(tradeCode)
  979. if err != nil {
  980. br.Msg = "查询指标信息失败"
  981. br.ErrMsg = "查询指标信息失败,err:" + err.Error()
  982. return
  983. }
  984. frequencies = append(frequencies, manualEdb.Frequency)
  985. } else if keyWord != `` {
  986. frequencies, err = models.GetEdbDataFrequencyByKeyord(keyWord)
  987. if err != nil {
  988. br.Msg = "查询频度失败"
  989. br.ErrMsg = "查询频度失败"
  990. return
  991. }
  992. } else {
  993. // 啥也没选的情况下
  994. frequencies = append(frequencies, `日度`, `周度`, `月度`, `季度`, `半年度`, `年度`)
  995. }
  996. fileName := `手工数据`
  997. if frequencies == nil {
  998. sheet, err := xlsxFile.AddSheet("无数据")
  999. if err != nil {
  1000. br.Msg = "新增Sheet失败"
  1001. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1002. return
  1003. }
  1004. rowSecName := sheet.AddRow()
  1005. celSecName := rowSecName.AddCell()
  1006. celSecName.SetValue("")
  1007. }
  1008. for _, frequency := range frequencies {
  1009. secNameList := make([]*models.EdbdataExportList, 0)
  1010. if len(classifyIdStrList) > 0 {
  1011. newCondition := condition
  1012. newCondition += ` AND a.classify_id in (` + strings.Join(classifyIdStrList, ",") + `) `
  1013. newCondition += ` AND a.frequency = ? `
  1014. pars := append(pars, frequency)
  1015. tmpSecNameList, err := models.GetEdbdataSecName(newCondition, pars)
  1016. if err != nil {
  1017. br.Msg = "获取数据失败"
  1018. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1019. return
  1020. }
  1021. secNameList = tmpSecNameList
  1022. }
  1023. var sheet *xlsx.Sheet
  1024. if len(secNameList) > 0 {
  1025. sheet, err = xlsxFile.AddSheet(frequency)
  1026. if err != nil {
  1027. br.Msg = "新增Sheet失败"
  1028. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1029. return
  1030. }
  1031. fileName = secNameList[0].ClassifyName
  1032. } else {
  1033. continue
  1034. }
  1035. //获取指标数据
  1036. rowSecName := sheet.AddRow()
  1037. celSecName := rowSecName.AddCell()
  1038. celSecName.SetValue("指标名称")
  1039. rowFrequency := sheet.AddRow()
  1040. celFrequency := rowFrequency.AddCell()
  1041. celFrequency.SetValue("频率")
  1042. rowUnit := sheet.AddRow()
  1043. celUnit := rowUnit.AddCell()
  1044. celUnit.SetValue("单位")
  1045. rowModifyDate := sheet.AddRow()
  1046. rowModifyCell := rowModifyDate.AddCell()
  1047. rowModifyCell.SetValue("更新时间")
  1048. dataMap := make(map[string]map[string]*models.EdbdataItem)
  1049. var tradeCodeList []string
  1050. for _, v := range secNameList {
  1051. cellSenName := rowSecName.AddCell()
  1052. cellSenName.SetValue(v.SecName)
  1053. celFrequency := rowFrequency.AddCell()
  1054. celFrequency.SetValue(v.Frequency)
  1055. celUnit := rowUnit.AddCell()
  1056. celUnit.SetValue(v.Unit)
  1057. rowModifyCell := rowModifyDate.AddCell()
  1058. rowModifyCell.SetValue(v.Dt)
  1059. tradeCodeList = append(tradeCodeList, v.TradeCode)
  1060. items, err := models.GetEdbdataAllByTradeCode(v.TradeCode)
  1061. if err != nil && err.Error() != utils.ErrNoRow() {
  1062. br.ErrMsg = "GetEdbdataAllByTradeCode,Err:" + err.Error()
  1063. br.Msg = "获取数据失败"
  1064. return
  1065. }
  1066. for _, item := range items {
  1067. if dataMap[item.TradeCode] == nil {
  1068. dataMap[item.TradeCode] = make(map[string]*models.EdbdataItem)
  1069. }
  1070. dataMap[item.TradeCode][item.Dt] = item
  1071. fmt.Println(item.TradeCode, item.Dt)
  1072. }
  1073. }
  1074. tradeCodeStr := strings.Join(tradeCodeList, "','")
  1075. tradeCodeStr = "'" + tradeCodeStr + "'"
  1076. dateList, err := models.GetEdbdataList(tradeCodeStr)
  1077. if err != nil {
  1078. br.Msg = "获取数据失败"
  1079. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1080. return
  1081. }
  1082. for _, n := range dateList {
  1083. rowData := sheet.AddRow()
  1084. celDate := rowData.AddCell()
  1085. celDate.SetValue(n.Dt)
  1086. for _, m := range secNameList {
  1087. celData := rowData.AddCell()
  1088. fmt.Println(m.TradeCode)
  1089. fmt.Println(n.Dt)
  1090. if dataMap[m.TradeCode][n.Dt] != nil {
  1091. celData.SetValue(dataMap[m.TradeCode][n.Dt].Close)
  1092. }
  1093. }
  1094. }
  1095. }
  1096. err = xlsxFile.Save(downloadFilePath)
  1097. if err != nil {
  1098. //有指标无数据时先导出一遍空表
  1099. sheet, err := xlsxFile.AddSheet("无数据")
  1100. if err != nil {
  1101. br.Msg = "新增Sheet失败"
  1102. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1103. return
  1104. }
  1105. rowSecName := sheet.AddRow()
  1106. celSecName := rowSecName.AddCell()
  1107. celSecName.SetValue("")
  1108. err = xlsxFile.Save(downloadFilePath)
  1109. if err != nil {
  1110. br.Msg = "保存文件失败"
  1111. br.ErrMsg = "保存文件失败"
  1112. return
  1113. }
  1114. }
  1115. defer func() {
  1116. os.Remove(downloadFilePath)
  1117. }()
  1118. fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
  1119. this.Ctx.Output.Download(downloadFilePath, fileName)
  1120. br.Ret = 200
  1121. br.Success = true
  1122. br.Msg = "success"
  1123. }
  1124. // DataList
  1125. // @Title 导出数据
  1126. // @Description 导出数据列表
  1127. // @Param StartDate query string true "开始日期"
  1128. // @Param EndDate query string true "结束日期"
  1129. // @Param Frequency query string true "频度"
  1130. // @Param ClassifyId query int true "分类"
  1131. // @Param KeyWord query string true "名称关键词"
  1132. // @Param Mobile query string true "手机号"
  1133. // @Success 200 导出成功
  1134. // @router /dataList [get]
  1135. func (this *TargetCommonController) DataList() {
  1136. br := new(models.BaseResponse).Init()
  1137. defer func() {
  1138. this.Data["json"] = br
  1139. this.ServeJSON()
  1140. }()
  1141. br.Msg = "成功"
  1142. br.Ret = 200
  1143. }
  1144. // DataDelete
  1145. // @Title 数据删除
  1146. // @Description 数据删除
  1147. // @Param request body models.DataDeleteReq true "type json string"
  1148. // @Success 200 Ret=200 录入成功
  1149. // @router /data/delete [post]
  1150. func (this *TargetController) DataDelete() {
  1151. br := new(models.BaseResponse).Init()
  1152. defer func() {
  1153. this.Data["json"] = br
  1154. this.ServeJSON()
  1155. }()
  1156. var req models.DataDeleteReq
  1157. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1158. if err != nil {
  1159. br.Msg = "参数解析异常!"
  1160. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1161. return
  1162. }
  1163. sysUser := this.SysUser
  1164. if sysUser == nil {
  1165. br.Msg = "请重新登录"
  1166. return
  1167. }
  1168. if req.TradeCode == "" {
  1169. br.Msg = "指标编码不可为空"
  1170. br.ErrMsg = "指标编码不可为空"
  1171. return
  1172. }
  1173. if req.CreateDate == "" {
  1174. br.Msg = "数据录入日期不可为空"
  1175. return
  1176. }
  1177. item, err := models.GetDataInfo(req.TradeCode, req.CreateDate)
  1178. if err != nil && err.Error() != utils.ErrNoRow() {
  1179. br.Msg = "获取信息失败!"
  1180. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1181. return
  1182. }
  1183. if item == nil {
  1184. br.Msg = "数据不存在"
  1185. return
  1186. }
  1187. err = models.DataDelete(req.TradeCode, req.CreateDate, item.Close, item.ModifyTime, sysUser.AdminId)
  1188. if err != nil {
  1189. br.Msg = "删除失败"
  1190. br.ErrMsg = "删除失败,Err:" + err.Error()
  1191. return
  1192. }
  1193. br.Ret = 200
  1194. br.Success = true
  1195. br.Msg = "删除成功"
  1196. }
  1197. // DataCheck
  1198. // @Title 数据删除校验
  1199. // @Description 数据删除校验
  1200. // @Param TradeCode query string true "指标唯一编码"
  1201. // @Param CreateDate query string true "数据录入日期"
  1202. // @Success Ret=200 可删除
  1203. // @router /data/check [get]
  1204. func (this *TargetController) DataCheck() {
  1205. br := new(models.BaseResponse).Init()
  1206. defer func() {
  1207. this.Data["json"] = br
  1208. this.ServeJSON()
  1209. }()
  1210. tradeCode := this.GetString("TradeCode")
  1211. createDate := this.GetString("CreateDate")
  1212. sysUser := this.SysUser
  1213. if sysUser == nil {
  1214. br.Msg = "请重新登录"
  1215. return
  1216. }
  1217. if tradeCode == "" {
  1218. br.Msg = "指标编码不可为空"
  1219. return
  1220. }
  1221. if createDate == "" {
  1222. br.Msg = "请选择日期"
  1223. return
  1224. }
  1225. resp := new(models.DataCheckResp)
  1226. item, err := models.GetDataInfo(tradeCode, createDate)
  1227. if err != nil && err.Error() != utils.ErrNoRow() {
  1228. br.Msg = "获取数据失败"
  1229. br.Msg = "获取数据失败,Err:" + err.Error()
  1230. return
  1231. }
  1232. if item != nil {
  1233. resp.Status = 1
  1234. resp.Close = item.Close
  1235. } else {
  1236. resp.Status = 0
  1237. }
  1238. br.Ret = 200
  1239. br.Success = true
  1240. br.Msg = "检测成功"
  1241. br.Data = resp
  1242. }
  1243. // TargetCheck
  1244. // @Title 指标删除校验
  1245. // @Description 指标删除校验
  1246. // @Param TradeCode query string true "指标唯一编码"
  1247. // @Success Ret=200 可删除
  1248. // @router /target/check [get]
  1249. func (this *TargetController) TargetCheck() {
  1250. br := new(models.BaseResponse).Init()
  1251. defer func() {
  1252. this.Data["json"] = br
  1253. this.ServeJSON()
  1254. }()
  1255. tradeCode := this.GetString("TradeCode")
  1256. sysUser := this.SysUser
  1257. if sysUser == nil {
  1258. br.Msg = "请重新登录"
  1259. return
  1260. }
  1261. if tradeCode == "" {
  1262. br.Msg = "指标编码不可为空"
  1263. return
  1264. }
  1265. resp := new(models.DataCheckResp)
  1266. count, err := data_manage.GetEdbInfoCount(utils.DATA_SOURCE_MANUAL, tradeCode)
  1267. if err != nil && err.Error() != utils.ErrNoRow() {
  1268. br.Msg = "获取数据失败"
  1269. br.Msg = "获取数据失败,Err:" + err.Error()
  1270. return
  1271. }
  1272. if count > 0 {
  1273. resp.Status = 1
  1274. } else {
  1275. resp.Status = 0
  1276. }
  1277. br.Ret = 200
  1278. br.Success = true
  1279. br.Msg = "指标不存在关联数据,可直接删除"
  1280. br.Data = resp
  1281. }
  1282. // TargetDelete
  1283. // @Title 指标删除
  1284. // @Description 指标删除
  1285. // @Param request body models.TargetDeleteReq true "type json string"
  1286. // @Success Ret=200 删除成功
  1287. // @router /target/delete [post]
  1288. func (this *TargetController) TargetDelete() {
  1289. br := new(models.BaseResponse).Init()
  1290. defer func() {
  1291. this.Data["json"] = br
  1292. this.ServeJSON()
  1293. }()
  1294. var req models.TargetDeleteReq
  1295. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1296. if err != nil {
  1297. br.Msg = "参数解析异常!"
  1298. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1299. return
  1300. }
  1301. if req.TradeCode == "" {
  1302. br.Msg = "指标编码不可为空"
  1303. return
  1304. }
  1305. //判断是否在指标数据导入的过程,如果是在该过程,那么就不允许用户操作
  1306. key := "import:edbinfo:data:" + req.TradeCode
  1307. if utils.Rc.IsExist(key) {
  1308. br.Msg = "该指标正在导入数据中,请稍后操作"
  1309. return
  1310. }
  1311. err = models.TargetDelete(req.TradeCode)
  1312. if err != nil {
  1313. br.Msg = "删除失败"
  1314. br.Msg = "删除失败,Err:" + err.Error()
  1315. return
  1316. }
  1317. br.Ret = 200
  1318. br.Success = true
  1319. br.IsAddLog = true
  1320. br.Msg = "删除成功"
  1321. }
  1322. // GetResearcher
  1323. // @Title 获取研究员
  1324. // @Description 获取研究员
  1325. // @Success 200 {object} models.ResearcherListResp
  1326. // @router /getResearcher [get]
  1327. func (this *TargetController) GetResearcher() {
  1328. br := new(models.BaseResponse).Init()
  1329. defer func() {
  1330. this.Data["json"] = br
  1331. this.ServeJSON()
  1332. }()
  1333. sysUser := this.SysUser
  1334. if sysUser == nil {
  1335. br.Msg = "请重新登录"
  1336. return
  1337. }
  1338. var err error
  1339. list := make([]*models.Researcher, 0)
  1340. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  1341. sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  1342. sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1343. list, err = models.GetResearcherEntry()
  1344. if err != nil {
  1345. br.Msg = "获取数据失败"
  1346. br.Msg = "获取数据失败,Err:" + err.Error()
  1347. return
  1348. }
  1349. } else if sysUser.Role == "hggroup" {
  1350. mobileStr := "'15888577277','15888856487','15158848535','13651627324' "
  1351. list, err = models.GetResearcherEntryByMobile(mobileStr)
  1352. if err != nil {
  1353. br.Msg = "获取数据失败"
  1354. br.Msg = "获取数据失败,Err:" + err.Error()
  1355. return
  1356. }
  1357. } else if sysUser.AdminName == "dfma" {
  1358. list, err = models.GetResearcherEntry()
  1359. if err != nil {
  1360. br.Msg = "获取数据失败"
  1361. br.Msg = "获取数据失败,Err:" + err.Error()
  1362. return
  1363. }
  1364. }
  1365. resp := new(models.ResearcherListResp)
  1366. resp.List = list
  1367. br.Ret = 200
  1368. br.Success = true
  1369. br.Msg = "获取成功"
  1370. br.Data = resp
  1371. }
  1372. // GetTargetItems
  1373. // @Title 获取研究员指标
  1374. // @Description 获取研究员指标
  1375. // @Param Mobile query string true "手机号"
  1376. // @Param ClassifyId query int true "分类id"
  1377. // @Success 200 {object} models.ResearcherListResp
  1378. // @router /getTargetItems [get]
  1379. func (this *TargetController) GetTargetItems() {
  1380. br := new(models.BaseResponse).Init()
  1381. defer func() {
  1382. this.Data["json"] = br
  1383. this.ServeJSON()
  1384. }()
  1385. sysUser := this.SysUser
  1386. if sysUser == nil {
  1387. br.Msg = "请重新登录"
  1388. return
  1389. }
  1390. mobile := this.GetString("Mobile")
  1391. if mobile == "" {
  1392. mobile = sysUser.Mobile
  1393. }
  1394. classifyId, _ := this.GetInt("ClassifyId")
  1395. items, err := models.GetTargetItems(mobile, classifyId)
  1396. if err != nil {
  1397. br.ErrMsg = "获取失败,Err:" + err.Error()
  1398. br.Msg = "获取失败"
  1399. return
  1400. }
  1401. resp := new(models.TargetItemsResp)
  1402. resp.List = items
  1403. br.Ret = 200
  1404. br.Success = true
  1405. br.Msg = "获取成功"
  1406. br.Data = resp
  1407. }
  1408. // ExportLongzhong
  1409. // @Title 隆众数据下载
  1410. // @Description 隆众数据下载接口
  1411. // @Success 200 {object} models.ResearcherListResp
  1412. // @router /export/longzhong [get]
  1413. func (this *TargetCommonController) ExportLongzhong() {
  1414. br := new(models.BaseResponse).Init()
  1415. defer func() {
  1416. this.Data["json"] = br
  1417. this.ServeJSON()
  1418. }()
  1419. parentId := 4
  1420. classifyList, err := models.GetEdbdataClassifyByParentId(parentId)
  1421. if err != nil {
  1422. return
  1423. }
  1424. xlsxFile := xlsx.NewFile()
  1425. if err != nil {
  1426. fmt.Println("生成文件失败" + err.Error())
  1427. return
  1428. }
  1429. dir, _ := os.Executable()
  1430. exPath := filepath.Dir(dir)
  1431. downLoadnFilePath := exPath + "/static/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1432. for _, v := range classifyList {
  1433. fmt.Println(v.ClassifyId, v.ClassifyName)
  1434. //获取指标
  1435. secNameList, err := data_source.GetLongzhonginfoByClassifyId(v.ClassifyId)
  1436. if err != nil {
  1437. fmt.Println("获取数据失败,Err:" + err.Error())
  1438. return
  1439. }
  1440. if len(secNameList) <= 0 {
  1441. continue
  1442. }
  1443. sheetNew, err := xlsxFile.AddSheet(v.ClassifyName)
  1444. if err != nil {
  1445. fmt.Println("新增Sheet失败", err.Error())
  1446. return
  1447. }
  1448. //sheetNew.SetColWidth()
  1449. //获取指标数据
  1450. windRow := sheetNew.AddRow()
  1451. secNameRow := sheetNew.AddRow()
  1452. frequencyRow := sheetNew.AddRow()
  1453. unitRow := sheetNew.AddRow()
  1454. lastModifyDateRow := sheetNew.AddRow()
  1455. //获取分类下指标最大数据量
  1456. dataMax, err := data_source.GetLongzhongDataMaxCount(v.ClassifyId)
  1457. if err != nil {
  1458. fmt.Println("获取指标最大数据量失败", err.Error())
  1459. return
  1460. }
  1461. for k, sv := range secNameList {
  1462. fmt.Println("line 399:", v.ClassifyId, v.ClassifyName, sv.SecName, sv.Frequency)
  1463. windRow.AddCell().SetValue("Wind")
  1464. secNameRow.AddCell().SetValue("指标名称")
  1465. frequencyRow.AddCell().SetValue("频率")
  1466. unitRow.AddCell().SetValue("单位")
  1467. lastModifyDateRow.AddCell().SetValue("更新时间")
  1468. secNameRow.AddCell().SetValue(sv.SecName)
  1469. frequencyRow.AddCell().SetValue(sv.Frequency)
  1470. unitRow.AddCell().SetValue(sv.Unit)
  1471. lastModifyDateRow.AddCell().SetValue(sv.LastModifyDate)
  1472. windRow.AddCell()
  1473. windRow.AddCell()
  1474. secNameRow.AddCell()
  1475. frequencyRow.AddCell()
  1476. unitRow.AddCell()
  1477. lastModifyDateRow.AddCell()
  1478. min := k * 3
  1479. sheetNew.SetColWidth(min, min, 15)
  1480. //获取数据
  1481. dataList, err := data_source.GetLongzhongDataById(sv.LongzhonginfoId)
  1482. if err != nil {
  1483. br.Msg = "获取数据失败"
  1484. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1485. return
  1486. }
  1487. if len(dataList) <= 0 {
  1488. for n := 0; n < dataMax; n++ {
  1489. rowIndex := 5 + n
  1490. row := sheetNew.Row(rowIndex)
  1491. row.AddCell()
  1492. row.AddCell()
  1493. row.AddCell()
  1494. }
  1495. } else {
  1496. endRowIndex := 0
  1497. for rk, dv := range dataList {
  1498. rowIndex := 5 + rk
  1499. row := sheetNew.Row(rowIndex)
  1500. displayDate, _ := time.Parse(utils.FormatDate, dv.DisplayTime)
  1501. displayDateCell := row.AddCell()
  1502. style := new(xlsx.Style)
  1503. style.ApplyAlignment = true
  1504. style.Alignment.WrapText = true
  1505. displayDateCell.SetStyle(style)
  1506. displayDateCell.SetDate(displayDate)
  1507. row.AddCell().SetFloat(dv.Close)
  1508. row.AddCell()
  1509. endRowIndex = rowIndex
  1510. }
  1511. if len(dataList) < dataMax {
  1512. dataLen := dataMax - len(dataList)
  1513. for n := 0; n < dataLen; n++ {
  1514. rowIndex := (endRowIndex + 1) + n
  1515. row := sheetNew.Row(rowIndex)
  1516. row.AddCell()
  1517. row.AddCell()
  1518. row.AddCell()
  1519. }
  1520. }
  1521. }
  1522. }
  1523. }
  1524. err = xlsxFile.Save(downLoadnFilePath)
  1525. if err != nil {
  1526. br.Msg = "保存文件失败"
  1527. br.ErrMsg = "保存文件失败"
  1528. return
  1529. }
  1530. fileName := "隆众石化数据" + time.Now().Format("200601021504") + ".xlsx"
  1531. this.Ctx.Output.Download(downLoadnFilePath, fileName)
  1532. defer func() {
  1533. os.Remove(downLoadnFilePath)
  1534. }()
  1535. br.Ret = 200
  1536. br.Success = true
  1537. br.Msg = "success"
  1538. }
  1539. // ExportLongzhongPrice
  1540. // @Title 隆众价格数据下载
  1541. // @Description 隆众价格数据下载接口
  1542. // @Success 200 {object} models.ResearcherListResp
  1543. // @router /export/longzhong/price [get]
  1544. func (this *TargetCommonController) ExportLongzhongPrice() {
  1545. br := new(models.BaseResponse).Init()
  1546. defer func() {
  1547. this.Data["json"] = br
  1548. this.ServeJSON()
  1549. }()
  1550. classifyList, err := models.GetLzPriceClassify()
  1551. if err != nil {
  1552. return
  1553. }
  1554. xlsxFile := xlsx.NewFile()
  1555. if err != nil {
  1556. fmt.Println("生成文件失败" + err.Error())
  1557. return
  1558. }
  1559. dir, _ := os.Executable()
  1560. exPath := filepath.Dir(dir)
  1561. downLoadnFilePath := exPath + "/static/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1562. for _, v := range classifyList {
  1563. //获取指标
  1564. secNameList, err := models.GetLongzhongpriceinfoByClassifyName(v.ProductName)
  1565. if err != nil {
  1566. fmt.Println("获取数据失败,Err:" + err.Error())
  1567. return
  1568. }
  1569. if len(secNameList) <= 0 {
  1570. continue
  1571. }
  1572. sheetNew, err := xlsxFile.AddSheet(v.ProductName)
  1573. if err != nil {
  1574. fmt.Println("新增Sheet失败", err.Error())
  1575. return
  1576. }
  1577. //获取指标数据
  1578. windRow := sheetNew.AddRow()
  1579. secNameRow := sheetNew.AddRow()
  1580. frequencyRow := sheetNew.AddRow()
  1581. unitRow := sheetNew.AddRow()
  1582. lastModifyDateRow := sheetNew.AddRow()
  1583. marketRow := sheetNew.AddRow()
  1584. manufactureRow := sheetNew.AddRow()
  1585. standardRow := sheetNew.AddRow() //规格
  1586. modelNameRow := sheetNew.AddRow() //规格型号
  1587. titleRow := sheetNew.AddRow()
  1588. //获取分类下指标最大数据量
  1589. dataMax, err := models.GetLongzhongPriceDataMaxCount(v.ProductName)
  1590. if err != nil {
  1591. fmt.Println("获取指标最大数据量失败", err.Error())
  1592. return
  1593. }
  1594. for k, sv := range secNameList {
  1595. fmt.Println("line 399:", v.ProductName, sv.InfoTypeRemark, sv.AreaName)
  1596. windRow.AddCell().SetString("Wind")
  1597. secNameRow.AddCell().SetValue("分类")
  1598. frequencyRow.AddCell().SetValue("价格类型")
  1599. unitRow.AddCell().SetValue("单位")
  1600. lastModifyDateRow.AddCell().SetValue("地区")
  1601. marketRow.AddCell().SetValue("市场名称")
  1602. manufactureRow.AddCell().SetValue("厂家名称")
  1603. standardRow.AddCell().SetValue("规格")
  1604. modelNameRow.AddCell().SetValue("规格型号")
  1605. secNameRow.AddCell().SetValue(sv.InfoTypeRemark)
  1606. frequencyRow.AddCell().SetValue(sv.PriceType)
  1607. unitRow.AddCell().SetValue(sv.Unit)
  1608. lastModifyDateRow.AddCell().SetValue(sv.AreaName)
  1609. marketRow.AddCell().SetValue(sv.MarketName)
  1610. manufactureRow.AddCell().SetValue(sv.ManufactureName)
  1611. standardRow.AddCell().SetValue(sv.Standard)
  1612. modelNameRow.AddCell().SetValue(sv.ModelName)
  1613. windRow.AddCell()
  1614. windRow.AddCell()
  1615. windRow.AddCell()
  1616. windRow.AddCell()
  1617. secNameRow.AddCell()
  1618. frequencyRow.AddCell()
  1619. unitRow.AddCell()
  1620. lastModifyDateRow.AddCell()
  1621. marketRow.AddCell()
  1622. manufactureRow.AddCell()
  1623. standardRow.AddCell()
  1624. modelNameRow.AddCell()
  1625. secNameRow.AddCell()
  1626. frequencyRow.AddCell()
  1627. unitRow.AddCell()
  1628. lastModifyDateRow.AddCell()
  1629. marketRow.AddCell()
  1630. manufactureRow.AddCell()
  1631. standardRow.AddCell()
  1632. modelNameRow.AddCell()
  1633. secNameRow.AddCell()
  1634. frequencyRow.AddCell()
  1635. unitRow.AddCell()
  1636. lastModifyDateRow.AddCell()
  1637. marketRow.AddCell()
  1638. manufactureRow.AddCell()
  1639. standardRow.AddCell()
  1640. modelNameRow.AddCell()
  1641. titleRow.AddCell().SetValue("价格日期")
  1642. titleRow.AddCell().SetValue("价格")
  1643. titleRow.AddCell().SetValue("低端价格")
  1644. titleRow.AddCell().SetValue("高端价格")
  1645. titleRow.AddCell()
  1646. min := k * 5
  1647. sheetNew.SetColWidth(min, min, 15)
  1648. //获取数据
  1649. dataList, err := models.GetLongzhongPriceDataById(sv.LongzhongpriceinfoId)
  1650. if err != nil {
  1651. fmt.Println("GetLongzhongDataById Err:" + err.Error())
  1652. return
  1653. }
  1654. rowStart := 10
  1655. if len(dataList) <= 0 {
  1656. for n := 0; n < dataMax; n++ {
  1657. rowIndex := rowStart + n
  1658. row := sheetNew.Row(rowIndex)
  1659. row.AddCell()
  1660. row.AddCell()
  1661. row.AddCell()
  1662. row.AddCell()
  1663. row.AddCell()
  1664. }
  1665. } else {
  1666. endRowIndex := 0
  1667. for rk, dv := range dataList {
  1668. rowIndex := rowStart + rk
  1669. row := sheetNew.Row(rowIndex)
  1670. priceDate, _ := time.Parse(utils.FormatDate, dv.PriceDate)
  1671. row.AddCell().SetDate(priceDate)
  1672. row.AddCell().SetFloat(dv.Price)
  1673. row.AddCell().SetFloat(dv.LowPrice)
  1674. row.AddCell().SetFloat(dv.HighPrice)
  1675. row.AddCell()
  1676. endRowIndex = rowIndex
  1677. }
  1678. if len(dataList) < dataMax {
  1679. dataLen := dataMax - len(dataList)
  1680. for n := 0; n < dataLen; n++ {
  1681. rowIndex := (endRowIndex + 1) + n
  1682. row := sheetNew.Row(rowIndex)
  1683. row.AddCell()
  1684. row.AddCell()
  1685. row.AddCell()
  1686. row.AddCell()
  1687. row.AddCell()
  1688. }
  1689. }
  1690. }
  1691. }
  1692. }
  1693. err = xlsxFile.Save(downLoadnFilePath)
  1694. if err != nil {
  1695. br.Msg = "保存文件失败"
  1696. br.ErrMsg = "保存文件失败"
  1697. return
  1698. }
  1699. fileName := "隆众价格数据" + time.Now().Format("200601021504") + ".xlsx"
  1700. this.Ctx.Output.Download(downLoadnFilePath, fileName)
  1701. defer func() {
  1702. os.Remove(downLoadnFilePath)
  1703. }()
  1704. br.Ret = 200
  1705. br.Success = true
  1706. br.Msg = "success"
  1707. }
  1708. // ExportLongzhongSurvey
  1709. // @Title 隆众调研数据下载
  1710. // @Description 隆众调研数据下载接口
  1711. // @Success 200 {object} models.ResearcherListResp
  1712. // @router /export/longzhong/survey [get]
  1713. func (this *TargetCommonController) ExportLongzhongSurvey() {
  1714. br := new(models.BaseResponse).Init()
  1715. defer func() {
  1716. this.Data["json"] = br
  1717. this.ServeJSON()
  1718. }()
  1719. classifyList, err := models.GetLzSurveyClassify()
  1720. if err != nil {
  1721. return
  1722. }
  1723. xlsxFile := xlsx.NewFile()
  1724. if err != nil {
  1725. fmt.Println("生成文件失败" + err.Error())
  1726. return
  1727. }
  1728. dir, _ := os.Executable()
  1729. exPath := filepath.Dir(dir)
  1730. downLoadnFilePath := exPath + "/static/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1731. for _, v := range classifyList {
  1732. //获取指标
  1733. secNameList, err := models.GetLongzhongSurveyProductByClassifyName(v.ProductName)
  1734. if err != nil {
  1735. fmt.Println("获取数据失败,Err:" + err.Error())
  1736. return
  1737. }
  1738. if len(secNameList) <= 0 {
  1739. continue
  1740. }
  1741. sheetNew, err := xlsxFile.AddSheet(v.ProductName)
  1742. if err != nil {
  1743. fmt.Println("新增Sheet失败", err.Error())
  1744. return
  1745. }
  1746. //sheetNew.SetColWidth()
  1747. //获取指标数据
  1748. windRow := sheetNew.AddRow()
  1749. secNameRow := sheetNew.AddRow()
  1750. indexCodeRow := sheetNew.AddRow()
  1751. frequencyRow := sheetNew.AddRow()
  1752. unitRow := sheetNew.AddRow()
  1753. lastModifyDateRow := sheetNew.AddRow()
  1754. //获取分类下指标最大数据量
  1755. dataMax, err := data_source.GetLongzhongSurveyDataMaxCount(v.ProductName)
  1756. if err != nil {
  1757. fmt.Println("获取指标最大数据量失败", err.Error())
  1758. return
  1759. }
  1760. setRowIndex := 6
  1761. for k, sv := range secNameList {
  1762. windRow.AddCell().SetValue("隆众")
  1763. secNameRow.AddCell().SetValue("指标名称")
  1764. indexCodeRow.AddCell().SetValue("指标ID")
  1765. frequencyRow.AddCell().SetValue("频率")
  1766. unitRow.AddCell().SetValue("单位")
  1767. lastModifyDateRow.AddCell().SetValue("更新时间")
  1768. secNameRow.AddCell().SetValue(sv.SampleName + sv.BreedName + sv.Custom + sv.QuotaName)
  1769. indexCodeRow.AddCell().SetValue(sv.LzCode)
  1770. if sv.Frequency == 1 {
  1771. frequencyRow.AddCell().SetValue("日度")
  1772. } else if sv.Frequency == 2 {
  1773. frequencyRow.AddCell().SetValue("周度")
  1774. } else if sv.Frequency == 3 {
  1775. frequencyRow.AddCell().SetValue("月度")
  1776. } else if sv.Frequency == 4 {
  1777. frequencyRow.AddCell().SetValue("季度")
  1778. } else if sv.Frequency == 5 {
  1779. frequencyRow.AddCell().SetValue("年度")
  1780. } else if sv.Frequency == 99 {
  1781. frequencyRow.AddCell().SetValue("无固定频率")
  1782. }
  1783. unitRow.AddCell().SetValue(sv.UnitName)
  1784. lastModifyDateRow.AddCell().SetValue(sv.EndDate)
  1785. windRow.AddCell()
  1786. windRow.AddCell()
  1787. secNameRow.AddCell()
  1788. indexCodeRow.AddCell()
  1789. frequencyRow.AddCell()
  1790. unitRow.AddCell()
  1791. lastModifyDateRow.AddCell()
  1792. min := k * 3
  1793. sheetNew.SetColWidth(min, min, 15)
  1794. //获取数据
  1795. dataList, err := data_source.GetLongzhongSurveyDataById(sv.SurveyProductId)
  1796. if err != nil {
  1797. br.Msg = "获取数据失败"
  1798. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1799. return
  1800. }
  1801. if len(dataList) <= 0 {
  1802. for n := 0; n < dataMax; n++ {
  1803. rowIndex := setRowIndex + n
  1804. row := sheetNew.Row(rowIndex)
  1805. row.AddCell()
  1806. row.AddCell()
  1807. row.AddCell()
  1808. }
  1809. } else {
  1810. endRowIndex := 0
  1811. for rk, dv := range dataList {
  1812. rowIndex := setRowIndex + rk
  1813. row := sheetNew.Row(rowIndex)
  1814. displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
  1815. displayDateCell := row.AddCell()
  1816. style := new(xlsx.Style)
  1817. style.ApplyAlignment = true
  1818. style.Alignment.WrapText = true
  1819. displayDateCell.SetStyle(style)
  1820. displayDateCell.SetDate(displayDate)
  1821. row.AddCell().SetFloat(dv.InputValue)
  1822. row.AddCell()
  1823. endRowIndex = rowIndex
  1824. }
  1825. if len(dataList) < dataMax {
  1826. dataLen := dataMax - len(dataList)
  1827. for n := 0; n < dataLen; n++ {
  1828. rowIndex := (endRowIndex + 1) + n
  1829. row := sheetNew.Row(rowIndex)
  1830. row.AddCell()
  1831. row.AddCell()
  1832. row.AddCell()
  1833. }
  1834. }
  1835. }
  1836. }
  1837. }
  1838. err = xlsxFile.Save(downLoadnFilePath)
  1839. if err != nil {
  1840. br.Msg = "保存文件失败"
  1841. br.ErrMsg = "保存文件失败"
  1842. return
  1843. }
  1844. fileName := "隆众调研数据" + time.Now().Format("200601021504") + ".xlsx"
  1845. this.Ctx.Output.Download(downLoadnFilePath, fileName)
  1846. defer func() {
  1847. os.Remove(downLoadnFilePath)
  1848. }()
  1849. br.Ret = 200
  1850. br.Success = true
  1851. br.Msg = "success"
  1852. }
  1853. // TargetUnitList
  1854. // @Title 指标列表
  1855. // @Description 指标列表接口
  1856. // @Success 200 {object} []string
  1857. // @router /target/unit_list [get]
  1858. func (this *TargetController) TargetUnitList() {
  1859. br := new(models.BaseResponse).Init()
  1860. defer func() {
  1861. this.Data["json"] = br
  1862. this.ServeJSON()
  1863. }()
  1864. sysUser := this.SysUser
  1865. if sysUser == nil {
  1866. br.Msg = "请登录"
  1867. br.Ret = 408
  1868. return
  1869. }
  1870. list, err := models.GetEdbUnitList()
  1871. if err != nil {
  1872. br.Msg = "获取失败"
  1873. br.ErrMsg = "获取失败,Err:" + err.Error()
  1874. return
  1875. }
  1876. edbUnitList := make([]string, 0)
  1877. for _, unit := range list {
  1878. edbUnitList = append(edbUnitList, unit.Unit)
  1879. }
  1880. br.Ret = 200
  1881. br.Success = true
  1882. br.Msg = "获取成功"
  1883. br.Data = edbUnitList
  1884. }
  1885. // TargetFrequencyList
  1886. // @Title 指标频度列表
  1887. // @Description 指标频度列表接口
  1888. // @Param ClassifyId query int true "分类"
  1889. // @Success 200 {object} []string
  1890. // @router /target/frequency_list [get]
  1891. func (this *TargetController) TargetFrequencyList() {
  1892. br := new(models.BaseResponse).Init()
  1893. defer func() {
  1894. this.Data["json"] = br
  1895. this.ServeJSON()
  1896. }()
  1897. sysUser := this.SysUser
  1898. if sysUser == nil {
  1899. br.Msg = "请登录"
  1900. br.Ret = 408
  1901. return
  1902. }
  1903. classifyId, _ := this.GetInt("ClassifyId") //分类
  1904. if classifyId <= 0 {
  1905. br.Msg = "分类ID必传"
  1906. return
  1907. }
  1908. userId := sysUser.AdminId
  1909. //超管账号可以查看分类下的所有频度数据
  1910. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  1911. userId = 0
  1912. }
  1913. list, err := models.GetEdbFrequencyList(classifyId, userId)
  1914. if err != nil {
  1915. br.Msg = "获取失败"
  1916. br.ErrMsg = "获取失败,Err:" + err.Error()
  1917. return
  1918. }
  1919. edbFrequencyList := make([]string, 0)
  1920. for _, unit := range list {
  1921. edbFrequencyList = append(edbFrequencyList, unit.Frequency)
  1922. }
  1923. edbFrequencyList = sortEdbFrequency(edbFrequencyList)
  1924. br.Ret = 200
  1925. br.Success = true
  1926. br.Msg = "获取成功"
  1927. br.Data = edbFrequencyList
  1928. }
  1929. func sortEdbFrequency(frequencyList []string) (newFrequencyList []string) {
  1930. var frequencyMap1 = map[string]int{
  1931. "日度": 1,
  1932. "周度": 2,
  1933. "旬度": 3,
  1934. "月度": 4,
  1935. "季度": 5,
  1936. "半年度": 6,
  1937. "年度": 7,
  1938. }
  1939. var frequencyMap2 = map[int]string{
  1940. 1: "日度",
  1941. 2: "周度",
  1942. 3: "旬度",
  1943. 4: "月度",
  1944. 5: "季度",
  1945. 6: "半年度",
  1946. 7: "年度",
  1947. }
  1948. idList := make([]int, 0)
  1949. for _, frequency := range frequencyList {
  1950. idList = append(idList, frequencyMap1[frequency])
  1951. }
  1952. sort.Ints(idList)
  1953. for _, id := range idList {
  1954. newFrequencyList = append(newFrequencyList, frequencyMap2[id])
  1955. }
  1956. return
  1957. }
  1958. // TargetItemList
  1959. // @Title 获取研究员指标
  1960. // @Description 获取研究员指标
  1961. // @Param Frequency query string false "频度;枚举值:日度、周度、旬度、月度、季度、半年度、年度"
  1962. // @Param Keyword query string false "关键字搜索"
  1963. // @Param TradeCode query string false "指标唯一编码"
  1964. // @Param ClassifyId query int false "分类id"
  1965. // @Param EdbShowType query string true "指标展示类型:0,1,2; 0:不管有没有数据,指标都展示出来, 1:只展示有数据的指标, 2:只展示没有数据的指标"
  1966. // @Success 200 {object} models.TargetItemListResp
  1967. // @router /target/item_list [get]
  1968. func (this *TargetController) TargetItemList() {
  1969. br := new(models.BaseResponse).Init()
  1970. defer func() {
  1971. this.Data["json"] = br
  1972. this.ServeJSON()
  1973. }()
  1974. sysUser := this.SysUser
  1975. if sysUser == nil {
  1976. br.Msg = "请重新登录"
  1977. return
  1978. }
  1979. //频度
  1980. frequency := this.GetString("Frequency")
  1981. //关键字
  1982. keyword := this.GetString("Keyword")
  1983. //指标编码
  1984. tradeCode := this.GetString("TradeCode")
  1985. userId := sysUser.AdminId
  1986. //超管账号可以查看分类下的所有频度数据
  1987. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  1988. userId = 0
  1989. }
  1990. //获取账户所拥有权限的分类id集合
  1991. classifyIdStrList, err := data.GetEdbClassifyListByAdminId(int64(userId))
  1992. if err != nil {
  1993. br.Msg = "获取分类数据失败"
  1994. return
  1995. }
  1996. classifyId, _ := this.GetInt("ClassifyId")
  1997. edbShowType, _ := this.GetInt("EdbShowType")
  1998. list, err := models.GetTargetItemList(classifyId, edbShowType, frequency, keyword, tradeCode, classifyIdStrList)
  1999. if err != nil {
  2000. br.ErrMsg = "获取失败,Err:" + err.Error()
  2001. br.Msg = "获取失败"
  2002. return
  2003. }
  2004. edbTradeCodeList := make([]string, 0)
  2005. //频度数据
  2006. frequencyMap := make(map[string]int)
  2007. for _, edb := range list {
  2008. edbTradeCodeList = append(edbTradeCodeList, edb.TradeCode)
  2009. frequencyMap[edb.Frequency] = 0
  2010. }
  2011. frequencyList := make([]string, 0)
  2012. for k := range frequencyMap {
  2013. frequencyList = append(frequencyList, k)
  2014. }
  2015. frequencyList = sortEdbFrequency(frequencyList)
  2016. if len(edbTradeCodeList) > 0 {
  2017. edbTradeCodeStr := `"` + strings.Join(edbTradeCodeList, `","`) + `"`
  2018. edbDataList, err := models.GetEdbDataListByCodes(edbTradeCodeStr)
  2019. if err != nil {
  2020. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  2021. br.Msg = "获取失败"
  2022. return
  2023. }
  2024. edbDataMap := make(map[string][]*models.Edbdata, 0)
  2025. for _, edbData := range edbDataList {
  2026. if _, ok := edbDataMap[edbData.TradeCode]; ok {
  2027. edbDataMap[edbData.TradeCode] = append(edbDataMap[edbData.TradeCode], edbData)
  2028. } else {
  2029. tmpEdbDataList := make([]*models.Edbdata, 0)
  2030. tmpEdbDataList = append(tmpEdbDataList, edbData)
  2031. edbDataMap[edbData.TradeCode] = tmpEdbDataList
  2032. }
  2033. }
  2034. //nowWeek := time.Now().Weekday().String() //当前周几
  2035. myYear := time.Now().Year() //当前年份
  2036. myMonth := time.Now().Format("01") //当前月份
  2037. //当前周的周一与周日
  2038. nowWeekFirstDay := utils.GetNowWeekMonday()
  2039. nowWeekLastDay := utils.GetNowWeekLastDay()
  2040. //当前月的一号与最后一天
  2041. nowMonthFirstDay := utils.GetNowMonthFirstDay()
  2042. nowMonthLastDay := utils.GetNowMonthLastDay()
  2043. //当前季度的第一天与最后一天
  2044. nowQuarterFirstDay := utils.GetNowQuarterFirstDay()
  2045. nowQuarterLastDay := utils.GetNowQuarterLastDay()
  2046. //当前半年的第一天与最后一天
  2047. nowHalfYearFirstDay := utils.GetNowHalfYearFirstDay()
  2048. nowHalfYearLastDay := utils.GetNowHalfYearLastDay()
  2049. // 当前年的第一天与最后一天
  2050. nowYearFirstDay := utils.GetNowYearFirstDay()
  2051. nowYearLastDay := utils.GetNowYearLastDay()
  2052. for _, edb := range list {
  2053. edb.Status = "未完成"
  2054. if dataList, ok := edbDataMap[edb.TradeCode]; ok {
  2055. edb.DataList = dataList
  2056. dataDtTime, _ := time.ParseInLocation(utils.FormatDate, dataList[0].Dt, time.Now().Location()) //最近的一条数据时间
  2057. switch edb.Frequency {
  2058. case "日度":
  2059. if time.Now().After(dataDtTime.AddDate(0, 0, 1)) {
  2060. edb.ModifyDate = time.Now().Format(utils.FormatDate)
  2061. } else {
  2062. edb.ModifyDate = dataDtTime.AddDate(0, 0, 1).Format(utils.FormatDate)
  2063. edb.Status = "完成"
  2064. }
  2065. case "周度":
  2066. //if edb.NoticeTime != "" {
  2067. // noticeArr := strings.Split(edb.NoticeTime, " ")
  2068. // noticeWeek := noticeArr[0]
  2069. // addDay := 0
  2070. //
  2071. // if nowWeek == "Sunday" {
  2072. // if noticeWeek == "周日" {
  2073. // addDay = 0
  2074. // } else if noticeWeek == "周一" {
  2075. // addDay = 1
  2076. // } else if noticeWeek == "周二" {
  2077. // addDay = 2
  2078. // } else if noticeWeek == "周三" {
  2079. // addDay = 3
  2080. // } else if noticeWeek == "周四" {
  2081. // addDay = 4
  2082. // } else if noticeWeek == "周五" {
  2083. // addDay = 5
  2084. // } else if noticeWeek == "周六" {
  2085. // addDay = 6
  2086. // } else {
  2087. // addDay = 0
  2088. // }
  2089. // } else if nowWeek == "Monday" {
  2090. // if noticeWeek == "周日" {
  2091. // addDay = 6
  2092. // } else if noticeWeek == "周一" {
  2093. // addDay = 0
  2094. // } else if noticeWeek == "周二" {
  2095. // addDay = 1
  2096. // } else if noticeWeek == "周三" {
  2097. // addDay = 2
  2098. // } else if noticeWeek == "周四" {
  2099. // addDay = 3
  2100. // } else if noticeWeek == "周五" {
  2101. // addDay = 4
  2102. // } else if noticeWeek == "周六" {
  2103. // addDay = 5
  2104. // } else {
  2105. // addDay = 0
  2106. // }
  2107. // } else if nowWeek == "Tuesday" {
  2108. // if noticeWeek == "周日" {
  2109. // addDay = 5
  2110. // } else if noticeWeek == "周一" {
  2111. // addDay = 6
  2112. // } else if noticeWeek == "周二" {
  2113. // addDay = 0
  2114. // } else if noticeWeek == "周三" {
  2115. // addDay = 1
  2116. // } else if noticeWeek == "周四" {
  2117. // addDay = 2
  2118. // } else if noticeWeek == "周五" {
  2119. // addDay = 3
  2120. // } else if noticeWeek == "周六" {
  2121. // addDay = 4
  2122. // } else {
  2123. // addDay = 0
  2124. // }
  2125. // } else if nowWeek == "Wednesday" {
  2126. // if noticeWeek == "周日" {
  2127. // addDay = 4
  2128. // } else if noticeWeek == "周一" {
  2129. // addDay = 5
  2130. // } else if noticeWeek == "周二" {
  2131. // addDay = 6
  2132. // } else if noticeWeek == "周三" {
  2133. // addDay = 0
  2134. // } else if noticeWeek == "周四" {
  2135. // addDay = 1
  2136. // } else if noticeWeek == "周五" {
  2137. // addDay = 2
  2138. // } else if noticeWeek == "周六" {
  2139. // addDay = 3
  2140. // } else {
  2141. // addDay = 0
  2142. // }
  2143. // } else if nowWeek == "Thursday" {
  2144. // if noticeWeek == "周日" {
  2145. // addDay = 3
  2146. // } else if noticeWeek == "周一" {
  2147. // addDay = 4
  2148. // } else if noticeWeek == "周二" {
  2149. // addDay = 5
  2150. // } else if noticeWeek == "周三" {
  2151. // addDay = 6
  2152. // } else if noticeWeek == "周四" {
  2153. // addDay = 0
  2154. // } else if noticeWeek == "周五" {
  2155. // addDay = 1
  2156. // } else if noticeWeek == "周六" {
  2157. // addDay = 2
  2158. // } else {
  2159. // addDay = 0
  2160. // }
  2161. // } else if nowWeek == "Friday" {
  2162. // if noticeWeek == "周日" {
  2163. // addDay = 2
  2164. // } else if noticeWeek == "周一" {
  2165. // addDay = 3
  2166. // } else if noticeWeek == "周二" {
  2167. // addDay = 4
  2168. // } else if noticeWeek == "周三" {
  2169. // addDay = 5
  2170. // } else if noticeWeek == "周四" {
  2171. // addDay = 6
  2172. // } else if noticeWeek == "周五" {
  2173. // addDay = 0
  2174. // } else if noticeWeek == "周六" {
  2175. // addDay = 1
  2176. // } else {
  2177. // addDay = 0
  2178. // }
  2179. // } else if nowWeek == "Saturday" {
  2180. // if noticeWeek == "周日" {
  2181. // addDay = 1
  2182. // } else if noticeWeek == "周一" {
  2183. // addDay = 2
  2184. // } else if noticeWeek == "周二" {
  2185. // addDay = 3
  2186. // } else if noticeWeek == "周三" {
  2187. // addDay = 4
  2188. // } else if noticeWeek == "周四" {
  2189. // addDay = 5
  2190. // } else if noticeWeek == "周五" {
  2191. // addDay = 6
  2192. // } else if noticeWeek == "周六" {
  2193. // addDay = 0
  2194. // } else {
  2195. // addDay = 0
  2196. // }
  2197. // }
  2198. //
  2199. // modifyDate := time.Now().AddDate(0, 0, addDay)
  2200. // if modifyDate.After(dataDtTime.AddDate(0, 0, 1)) {
  2201. // edb.ModifyDate = modifyDate.Format(utils.FormatDate)
  2202. // } else {
  2203. // edb.ModifyDate = modifyDate.AddDate(0, 0, 7).Format(utils.FormatDate)
  2204. // edb.Status = "完成"
  2205. // }
  2206. //} else {
  2207. // if startWeekDay.Unix() <= dataDtTime.Unix() {
  2208. // edb.ModifyDate = endWeekDay.AddDate(0, 0, 7).Format(utils.FormatDate)
  2209. // edb.Status = "完成"
  2210. // } else {
  2211. // edb.ModifyDate = endWeekDay.Format(utils.FormatDate)
  2212. // }
  2213. //}
  2214. modifyDate := nowWeekLastDay //下次更新日期
  2215. if edb.NoticeTime != "" {
  2216. addDay := 7
  2217. noticeArr := strings.Split(edb.NoticeTime, " ")
  2218. noticeWeek := noticeArr[0]
  2219. switch noticeWeek {
  2220. case "周一":
  2221. addDay = 1
  2222. case "周二":
  2223. addDay = 2
  2224. case "周三":
  2225. addDay = 3
  2226. case "周四":
  2227. addDay = 4
  2228. case "周五":
  2229. addDay = 5
  2230. case "周六":
  2231. addDay = 6
  2232. case "周日":
  2233. addDay = 7
  2234. }
  2235. modifyDate = modifyDate.AddDate(0, 0, addDay-7)
  2236. }
  2237. if nowWeekFirstDay.Before(dataDtTime) {
  2238. edb.ModifyDate = modifyDate.AddDate(0, 0, 7).Format(utils.FormatDate)
  2239. edb.Status = "完成"
  2240. } else {
  2241. edb.ModifyDate = modifyDate.Format(utils.FormatDate)
  2242. }
  2243. case "月度":
  2244. addDay := 0
  2245. modifyDate := nowMonthLastDay //下次更新日期
  2246. if edb.NoticeTime != "" {
  2247. strArr := strings.Split(edb.NoticeTime, "日")
  2248. tmpAddDay, tmpErr := strconv.Atoi(strArr[0])
  2249. if tmpErr != nil {
  2250. continue
  2251. }
  2252. addDay = tmpAddDay - 1
  2253. modifyDate = nowMonthFirstDay.AddDate(0, 0, addDay)
  2254. }
  2255. if nowMonthFirstDay.Before(dataDtTime) {
  2256. if int(time.Now().Month()) != int(nowMonthFirstDay.Month()) {
  2257. edb.ModifyDate = nowMonthLastDay.Format(utils.FormatDate)
  2258. } else {
  2259. month := nowMonthLastDay.Month() + 1
  2260. edb.ModifyDate = time.Date(nowMonthLastDay.Year(), month, 1, 0, 0, 0, 0, modifyDate.Location()).AddDate(0, 1, -1).Format(utils.FormatDate)
  2261. }
  2262. edb.Status = "完成"
  2263. } else {
  2264. edb.ModifyDate = modifyDate.Format(utils.FormatDate)
  2265. }
  2266. case "季度":
  2267. //每季度更新数据时间
  2268. if nowQuarterFirstDay.After(dataDtTime) {
  2269. edb.ModifyDate = nowQuarterLastDay.Format(utils.FormatDate)
  2270. } else {
  2271. edb.ModifyDate = nowQuarterLastDay.AddDate(0, 3, 0).Format(utils.FormatDate)
  2272. edb.Status = "完成"
  2273. }
  2274. case "半年度":
  2275. //每半年度更新数据时间
  2276. if nowHalfYearFirstDay.After(dataDtTime) {
  2277. edb.ModifyDate = nowHalfYearLastDay.Format(utils.FormatDate)
  2278. } else {
  2279. month := nowHalfYearLastDay.Month() + 1
  2280. edb.ModifyDate = time.Date(nowMonthLastDay.Year(), month, 1, 0, 0, 0, 0, nowHalfYearLastDay.Location()).AddDate(0, 6, -1).Format(utils.FormatDate)
  2281. edb.Status = "完成"
  2282. }
  2283. case "年度":
  2284. //每年度更新数据时间
  2285. if nowYearFirstDay.After(dataDtTime) {
  2286. edb.ModifyDate = nowYearLastDay.Format(utils.FormatDate)
  2287. } else {
  2288. edb.ModifyDate = nowYearLastDay.AddDate(1, 0, 0).Format(utils.FormatDate)
  2289. edb.Status = "完成"
  2290. }
  2291. }
  2292. } else {
  2293. edb.DataList = make([]*models.Edbdata, 0)
  2294. switch edb.Frequency {
  2295. case "日度":
  2296. edb.ModifyDate = time.Now().Format(utils.FormatDate)
  2297. case "周度":
  2298. modifyDate := nowWeekLastDay //下次更新日期
  2299. if edb.NoticeTime != "" {
  2300. addDay := 7
  2301. noticeArr := strings.Split(edb.NoticeTime, " ")
  2302. noticeWeek := noticeArr[0]
  2303. switch noticeWeek {
  2304. case "周一":
  2305. addDay = 1
  2306. case "周二":
  2307. addDay = 2
  2308. case "周三":
  2309. addDay = 3
  2310. case "周四":
  2311. addDay = 4
  2312. case "周五":
  2313. addDay = 5
  2314. case "周六":
  2315. addDay = 6
  2316. case "周日":
  2317. addDay = 7
  2318. }
  2319. modifyDate = modifyDate.AddDate(0, 0, addDay-7)
  2320. }
  2321. edb.ModifyDate = modifyDate.Format(utils.FormatDate)
  2322. case "月度":
  2323. if edb.NoticeTime != "" {
  2324. var modifyDateStr string
  2325. strArr := strings.Split(edb.NoticeTime, "日")
  2326. modifyDateStr = strconv.Itoa(myYear) + "-" + myMonth + "-" + strArr[0]
  2327. edb.ModifyDate = modifyDateStr
  2328. } else {
  2329. edb.ModifyDate = nowMonthFirstDay.AddDate(0, 1, -1).Format(utils.FormatDate)
  2330. }
  2331. case "季度":
  2332. edb.ModifyDate = utils.GetNowQuarterLastDay().Format(utils.FormatDate)
  2333. case "半年度":
  2334. edb.ModifyDate = utils.GetNowHalfYearLastDay().Format(utils.FormatDate)
  2335. case "年度":
  2336. edb.ModifyDate = utils.GetNowYearLastDay().Format(utils.FormatDate)
  2337. }
  2338. }
  2339. }
  2340. }
  2341. resp := models.TargetItemListResp{
  2342. List: list,
  2343. FrequencyList: frequencyList,
  2344. }
  2345. br.Ret = 200
  2346. br.Success = true
  2347. br.Msg = "获取成功"
  2348. //br.Data = resp
  2349. br.Data = resp
  2350. }
  2351. // TargetItemNameList
  2352. // @Title 获取研究员指标
  2353. // @Description 获取研究员指标
  2354. // @Param Frequency query string false "频度;枚举值:日度、周度、月度、季度、半年度、年度"
  2355. // @Param Keyword query string false "关键字搜索"
  2356. // @Param TradeCode query string false "指标唯一编码"
  2357. // @Param ClassifyId query int false "分类id"
  2358. // @Param EdbShowType query string true "指标展示类型:0,1,2; 0:不管有没有数据,指标都展示出来, 1:只展示有数据的指标, 2:只展示没有数据的指标"
  2359. // @Success 200 {object} models.TargetItemListResp
  2360. // @router /target/item_name_list [get]
  2361. func (this *TargetController) TargetItemNameList() {
  2362. br := new(models.BaseResponse).Init()
  2363. defer func() {
  2364. this.Data["json"] = br
  2365. this.ServeJSON()
  2366. }()
  2367. sysUser := this.SysUser
  2368. if sysUser == nil {
  2369. br.Msg = "请重新登录"
  2370. return
  2371. }
  2372. //频度
  2373. frequency := this.GetString("Frequency")
  2374. //关键字
  2375. keyword := this.GetString("Keyword")
  2376. //指标编码
  2377. tradeCode := this.GetString("TradeCode")
  2378. userId := sysUser.AdminId
  2379. //超管账号可以查看分类下的所有频度数据
  2380. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  2381. userId = 0
  2382. }
  2383. //获取账户所拥有权限的分类id集合
  2384. classifyIdStrList, err := data.GetEdbClassifyListByAdminId(int64(userId))
  2385. if err != nil {
  2386. br.Msg = "获取分类数据失败"
  2387. return
  2388. }
  2389. classifyId, _ := this.GetInt("ClassifyId")
  2390. edbShowType, _ := this.GetInt("EdbShowType")
  2391. list, err := models.GetTargetItemList(classifyId, edbShowType, frequency, keyword, tradeCode, classifyIdStrList)
  2392. if err != nil {
  2393. br.ErrMsg = "获取失败,Err:" + err.Error()
  2394. br.Msg = "获取失败"
  2395. return
  2396. }
  2397. resp := models.TargetItemListResp{
  2398. List: list,
  2399. }
  2400. br.Ret = 200
  2401. br.Success = true
  2402. br.Msg = "获取成功"
  2403. //br.Data = resp
  2404. br.Data = resp
  2405. }
  2406. // BatchDataDeleteByDate
  2407. // @Title 根据日期批量删除指标的数据
  2408. // @Description 根据日期批量删除指标的数据接口
  2409. // @Param request body models.BatchDataDeleteReq true "type json string"
  2410. // @Success 200 Ret=200 删除数据成功
  2411. // @router /data/batch_delete_by_date [post]
  2412. func (this *TargetController) BatchDataDeleteByDate() {
  2413. br := new(models.BaseResponse).Init()
  2414. defer func() {
  2415. this.Data["json"] = br
  2416. this.ServeJSON()
  2417. }()
  2418. var req models.BatchDataDeleteReq
  2419. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2420. if err != nil {
  2421. br.Msg = "参数解析异常!"
  2422. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2423. return
  2424. }
  2425. if len(req.TradeCodeList) <= 0 {
  2426. br.Msg = "至少传入一个指标编码!"
  2427. return
  2428. }
  2429. if req.CreateDate == "" {
  2430. br.Msg = "请选择日期"
  2431. return
  2432. }
  2433. TradeCodeStr := `"` + strings.Join(req.TradeCodeList, `","`) + `"`
  2434. //删除数据
  2435. err = models.BatchDeleteEdbDataByDate(TradeCodeStr, req.CreateDate, this.SysUser.AdminId)
  2436. if err != nil {
  2437. br.Msg = "删除失败!"
  2438. br.ErrMsg = "删除失败,Err:" + err.Error()
  2439. return
  2440. }
  2441. br.Ret = 200
  2442. br.Success = true
  2443. br.Msg = "删除成功"
  2444. }
  2445. // BatchDataDeleteByTradeCode
  2446. // @Title 批量删除指标的数据
  2447. // @Description 批量删除指标的数据接口
  2448. // @Param request body models.TargetDeleteReq true "type json string"
  2449. // @Success 200 Ret=200 删除数据成功
  2450. // @router /data/batch_delete [post]
  2451. func (this *TargetController) BatchDataDeleteByTradeCode() {
  2452. br := new(models.BaseResponse).Init()
  2453. defer func() {
  2454. this.Data["json"] = br
  2455. this.ServeJSON()
  2456. }()
  2457. var req models.TargetDeleteReq
  2458. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2459. if err != nil {
  2460. br.Msg = "参数解析异常!"
  2461. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2462. return
  2463. }
  2464. if req.TradeCode == "" {
  2465. br.Msg = "指标编码不可为空"
  2466. return
  2467. }
  2468. //删除数据
  2469. err = models.BatchDeleteEdbData(req.TradeCode, this.SysUser.AdminId)
  2470. if err != nil {
  2471. br.Msg = "删除失败!"
  2472. br.ErrMsg = "删除失败,Err:" + err.Error()
  2473. return
  2474. }
  2475. br.Ret = 200
  2476. br.Success = true
  2477. br.Msg = "删除成功"
  2478. }
  2479. // EdbTemplateDownload
  2480. // @Title 下载指标导入模板
  2481. // @Description 下载指标导入模板
  2482. // @router /target/template [get]
  2483. func (this *TargetCommonController) EdbTemplateDownload() {
  2484. br := new(models.BaseResponse).Init()
  2485. defer func() {
  2486. this.Data["json"] = br
  2487. this.ServeJSON()
  2488. }()
  2489. this.Ctx.Output.Download("./static/指标导入模板.xlsx", "指标导入模板.xlsx")
  2490. br.Ret = 200
  2491. br.Success = true
  2492. br.Msg = "下载成功"
  2493. }
  2494. // ImportTarget
  2495. // @Title 导入指标
  2496. // @Description 导入指标接口
  2497. // @Success 200 Ret=200 导入成功
  2498. // @router /target/import [post]
  2499. func (this *TargetController) ImportTarget() {
  2500. br := new(models.BaseResponse).Init()
  2501. defer func() {
  2502. this.Data["json"] = br
  2503. this.ServeJSON()
  2504. }()
  2505. sysUser := this.SysUser
  2506. if sysUser == nil {
  2507. br.Msg = "请重新登录"
  2508. return
  2509. }
  2510. file, _, err := this.GetFile("ImportTargetFile")
  2511. if err != nil {
  2512. br.Msg = "获取文件失败"
  2513. br.ErrMsg = "获取文件失败,Err:" + err.Error()
  2514. return
  2515. }
  2516. path := "./static/手工指标数据导入_" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  2517. defer func() {
  2518. file.Close()
  2519. os.Remove(path)
  2520. }()
  2521. err = this.SaveToFile("ImportTargetFile", path)
  2522. if err != nil {
  2523. br.Msg = "文件保存失败"
  2524. br.ErrMsg = "文件保存失败,Err:" + err.Error()
  2525. return
  2526. }
  2527. xlFile, err := xlsx.OpenFile(path)
  2528. if err != nil {
  2529. fmt.Println(err.Error())
  2530. br.Msg = "excel打开失败"
  2531. br.ErrMsg = "excel打开失败,Err:" + err.Error()
  2532. return
  2533. }
  2534. //分类map
  2535. classifyMap := make(map[string]*models.EdbdataClassify)
  2536. //获取当前账号拥有的所有分类权限
  2537. userId := sysUser.AdminId
  2538. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  2539. userId = 0
  2540. }
  2541. classifyList, err := models.GetEdbdataClassify(int64(userId))
  2542. for _, classify := range classifyList {
  2543. if classify.Child != nil {
  2544. for _, child := range classify.Child {
  2545. classifyMap[child.ClassifyName] = child
  2546. }
  2547. }
  2548. }
  2549. failDatas := make([]*models.EdbImportFail, 0)
  2550. // 遍历sheet页读取
  2551. for _, sheet := range xlFile.Sheets {
  2552. fmt.Println("sheet name: ", sheet.Name)
  2553. //遍历行读取
  2554. maxRow := sheet.MaxRow
  2555. fmt.Println("maxRow:", maxRow)
  2556. fmt.Println("maxRow")
  2557. for i := 0; i < maxRow; i++ {
  2558. if i > 1 {
  2559. row := sheet.Row(i)
  2560. cells := row.Cells
  2561. if len(cells) >= 4 {
  2562. cell1 := cells[0].Value //指标名称
  2563. secName := strings.Trim(cell1, " ")
  2564. if secName == "" { //过滤空白行
  2565. continue
  2566. }
  2567. cell2 := cells[1].Value
  2568. frequency := strings.Trim(cell2, " ") //频度
  2569. classifyName := cells[2].Value //分类
  2570. classifyName = strings.Trim(classifyName, " ")
  2571. unit := cells[3].Value //单位
  2572. unit = strings.Trim(unit, " ")
  2573. //获取分类
  2574. classify, ok := classifyMap[classifyName]
  2575. if !ok {
  2576. failItem := &models.EdbImportFail{
  2577. ClassifyName: classifyName,
  2578. Frequency: frequency,
  2579. SecName: secName,
  2580. Unit: unit,
  2581. Remark: "分类不存在",
  2582. SysUserId: strconv.Itoa(sysUser.AdminId),
  2583. }
  2584. failDatas = append(failDatas, failItem)
  2585. continue
  2586. }
  2587. tradeCode, err := models.GetMaxTradeCode()
  2588. if err != nil {
  2589. failItem := &models.EdbImportFail{
  2590. ClassifyName: classifyName,
  2591. Frequency: frequency,
  2592. SecName: secName,
  2593. Unit: unit,
  2594. Remark: "获取数据失败",
  2595. SysUserId: strconv.Itoa(sysUser.AdminId),
  2596. }
  2597. failDatas = append(failDatas, failItem)
  2598. continue
  2599. //br.Msg = "获取数据失败"
  2600. //br.ErrMsg = "获取最大交易编码失败,Err:" + err.Error()
  2601. //return
  2602. }
  2603. if tradeCode == "" {
  2604. failItem := &models.EdbImportFail{
  2605. ClassifyName: classifyName,
  2606. Frequency: frequency,
  2607. SecName: secName,
  2608. Unit: unit,
  2609. Remark: "数据异常",
  2610. SysUserId: strconv.Itoa(sysUser.AdminId),
  2611. }
  2612. failDatas = append(failDatas, failItem)
  2613. continue
  2614. }
  2615. maxTradeCode, err := utils.GetMaxTradeCode(tradeCode)
  2616. if err != nil {
  2617. failItem := &models.EdbImportFail{
  2618. ClassifyName: classifyName,
  2619. Frequency: frequency,
  2620. SecName: secName,
  2621. Unit: unit,
  2622. Remark: "数据异常",
  2623. SysUserId: strconv.Itoa(sysUser.AdminId),
  2624. }
  2625. failDatas = append(failDatas, failItem)
  2626. continue
  2627. //br.Msg = "数据异常"
  2628. //br.ErrMsg = "获取编码信息失败,Err:" + err.Error()
  2629. //return
  2630. }
  2631. if maxTradeCode == "" {
  2632. failItem := &models.EdbImportFail{
  2633. ClassifyName: classifyName,
  2634. Frequency: frequency,
  2635. SecName: secName,
  2636. Unit: unit,
  2637. Remark: "编码为空,请联系技术",
  2638. SysUserId: strconv.Itoa(sysUser.AdminId),
  2639. }
  2640. failDatas = append(failDatas, failItem)
  2641. continue
  2642. //br.Msg = "编码为空,请联系技术"
  2643. //br.ErrMsg = "编码为空,请联系技术"
  2644. //return
  2645. }
  2646. if secName == "" {
  2647. failItem := &models.EdbImportFail{
  2648. ClassifyName: classifyName,
  2649. Frequency: frequency,
  2650. SecName: secName,
  2651. Unit: unit,
  2652. Remark: "指标名称不能为空",
  2653. SysUserId: strconv.Itoa(sysUser.AdminId),
  2654. }
  2655. failDatas = append(failDatas, failItem)
  2656. continue
  2657. //br.Msg = "指标名称不能为空"
  2658. //return
  2659. }
  2660. item, err := models.GetEdbinfoBySecName(secName)
  2661. if err != nil && err.Error() != utils.ErrNoRow() {
  2662. failItem := &models.EdbImportFail{
  2663. ClassifyName: classifyName,
  2664. Frequency: frequency,
  2665. SecName: secName,
  2666. Unit: unit,
  2667. Remark: "获取信息失败",
  2668. SysUserId: strconv.Itoa(sysUser.AdminId),
  2669. }
  2670. failDatas = append(failDatas, failItem)
  2671. continue
  2672. //br.Msg = "获取信息失败!"
  2673. //br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2674. //return
  2675. }
  2676. //存在该指标,那么退出当前循环,进入下一循环
  2677. if item != nil {
  2678. failItem := &models.EdbImportFail{
  2679. ClassifyName: classifyName,
  2680. Frequency: frequency,
  2681. SecName: secName,
  2682. Unit: unit,
  2683. Remark: "指标已存在",
  2684. SysUserId: strconv.Itoa(sysUser.AdminId),
  2685. }
  2686. failDatas = append(failDatas, failItem)
  2687. continue
  2688. }
  2689. err = models.AddEdbinfo(maxTradeCode, secName, unit, "手动", frequency, "", classify.ClassifyId, sysUser.AdminId, sysUser.RealName)
  2690. if err != nil {
  2691. failItem := &models.EdbImportFail{
  2692. ClassifyName: classifyName,
  2693. Frequency: frequency,
  2694. SecName: secName,
  2695. Unit: unit,
  2696. Remark: "导入失败",
  2697. SysUserId: strconv.Itoa(sysUser.AdminId),
  2698. }
  2699. failDatas = append(failDatas, failItem)
  2700. continue
  2701. //br.Msg = "导入失败"
  2702. //br.ErrMsg = "导入失败,Err:" + err.Error()
  2703. //return
  2704. }
  2705. err = models.AddEdbinfoUser(maxTradeCode, sysUser.Mobile)
  2706. if err != nil {
  2707. failItem := &models.EdbImportFail{
  2708. ClassifyName: classifyName,
  2709. Frequency: frequency,
  2710. SecName: secName,
  2711. Unit: unit,
  2712. Remark: "创建账号关系失败",
  2713. SysUserId: strconv.Itoa(sysUser.AdminId),
  2714. }
  2715. failDatas = append(failDatas, failItem)
  2716. continue
  2717. //br.Msg = "导入失败"
  2718. //br.ErrMsg = "导入失败,Err:" + err.Error()
  2719. //return
  2720. }
  2721. }
  2722. }
  2723. }
  2724. }
  2725. resp := new(models.EdbdataImportResp)
  2726. if len(failDatas) > 0 {
  2727. //先删除导入失败记录
  2728. _ = models.DelEdbImportFail(sysUser.AdminId)
  2729. //错误信息字符串切片,最后作为发送邮件通知使用
  2730. failContents := make([]string, 0)
  2731. for _, v := range failDatas {
  2732. failContents = append(failContents, fmt.Sprint(v.SecName, "导入失败:", v.Remark))
  2733. err = models.AddEdbImportFail(v)
  2734. if err != nil {
  2735. go alarm_msg.SendAlarmMsg("导入数据 新增失败记录失败,Err:"+err.Error(), 3)
  2736. //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入指标 新增失败记录失败:Err:"+err.Error(), utils.EmailSendToUsers)
  2737. }
  2738. }
  2739. //导入失败的话,最后统一邮件提醒就好啦,不需要每次都去提醒
  2740. go alarm_msg.SendAlarmMsg("导入数据 存在部分数据导入失败,Err:"+err.Error(), 3)
  2741. //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入指标 存在部分数据导入失败:"+strings.Join(failContents, ";"), utils.EmailSendToUsers)
  2742. resp.Status = 1
  2743. resp.Msg = "存在部分导入失败"
  2744. } else {
  2745. resp.Status = 0
  2746. }
  2747. br.Ret = 200
  2748. br.Success = true
  2749. br.Msg = "导入成功"
  2750. br.Data = resp
  2751. }
  2752. // ImportTargetFailListDownload
  2753. // @Title 下载指标数据导入失败列表
  2754. // @Description 下载指标数据导入失败列表
  2755. // @router /import_target/failList [get]
  2756. func (this *TargetController) ImportTargetFailListDownload() {
  2757. br := new(models.BaseResponse).Init()
  2758. defer func() {
  2759. this.Data["json"] = br
  2760. this.ServeJSON()
  2761. }()
  2762. sysUser := this.SysUser
  2763. if sysUser == nil {
  2764. br.Msg = "请重新登录"
  2765. return
  2766. }
  2767. item, err := models.GetEdbImportFailList(sysUser.AdminId)
  2768. if err != nil {
  2769. br.Msg = "获取数据失败"
  2770. br.Msg = "获取数据失败,Err:" + err.Error()
  2771. return
  2772. }
  2773. xlsxFile := xlsx.NewFile()
  2774. sheet, err := xlsxFile.AddSheet("导入失败数据")
  2775. headRow := sheet.AddRow()
  2776. headRow.AddCell().SetValue("指标名称")
  2777. headRow.AddCell().SetValue("频度")
  2778. headRow.AddCell().SetValue("品种分类")
  2779. headRow.AddCell().SetValue("单位")
  2780. headRow.AddCell().SetValue("备注")
  2781. for _, v := range item {
  2782. row := sheet.AddRow()
  2783. row.AddCell().SetValue(v.SecName)
  2784. row.AddCell().SetValue(v.Frequency)
  2785. row.AddCell().SetValue(v.ClassifyName)
  2786. row.AddCell().SetValue(v.Unit)
  2787. row.AddCell().SetValue(v.Remark)
  2788. }
  2789. fileName := time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  2790. savePath := "./static/" + fileName
  2791. err = xlsxFile.Save(savePath)
  2792. if err != nil {
  2793. br.Msg = "文件保存失败"
  2794. br.ErrMsg = "文件保存失败,Err:" + err.Error()
  2795. return
  2796. }
  2797. defer func() {
  2798. os.Remove(savePath)
  2799. }()
  2800. this.Ctx.Output.Download(savePath, "失败列表.xlsx")
  2801. }
  2802. // ExcelDataAdd
  2803. // @Title 复制EXCEL数据保存
  2804. // @Description 复制EXCEL数据保存
  2805. // @Param request body models.ExcelStyleReq true "type json string"
  2806. // @Success 200
  2807. // @router /target/excel_style/add [post]
  2808. func (this *TargetController) ExcelDataAdd() {
  2809. br := new(models.BaseResponse).Init()
  2810. var err error
  2811. errs := make([]string, 0)
  2812. defer func() {
  2813. if len(errs) > 0 {
  2814. go alarm_msg.SendAlarmMsg("新增复制EXCEL数据 新增或修改数据失败,Err:"+strings.Join(errs, ","), 3)
  2815. }
  2816. this.Data["json"] = br
  2817. this.ServeJSON()
  2818. }()
  2819. sysUser := this.SysUser
  2820. if sysUser == nil {
  2821. br.Msg = "请重新登录"
  2822. return
  2823. }
  2824. //频度
  2825. //frequency := this.GetString("Frequency")
  2826. //
  2827. //关键字
  2828. //keyword := this.GetString("Keyword")
  2829. //指标编码
  2830. //tradeCode := this.GetString("TradeCode")
  2831. //
  2832. //userId := sysUser.AdminId
  2833. //超管账号可以查看分类下的所有频度数据
  2834. //if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  2835. // userId = 0
  2836. //}
  2837. //
  2838. //list, err := models.GetExcelData()
  2839. //if err != nil {
  2840. // br.ErrMsg = "获取失败,Err:" + err.Error()
  2841. // br.Msg = "获取失败"
  2842. // return
  2843. //}
  2844. var req data_manage.ExcelStyleReq
  2845. err = json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2846. if err != nil {
  2847. br.Msg = "参数解析异常!"
  2848. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2849. return
  2850. }
  2851. //指标map
  2852. targetMap := make(map[string]*models.Edbinfo)
  2853. var cellDataList []map[string]interface{}
  2854. var dataList [][]map[string]interface{}
  2855. //var configList []map[string]interface{}
  2856. for _, item := range req.CellData {
  2857. v := item.(map[string]interface{})
  2858. cellDataList = append(cellDataList, v)
  2859. }
  2860. valueIndex := 0
  2861. var secNameList []string
  2862. var frequencyList []string
  2863. var unitList []string
  2864. var dateList []string
  2865. dateValueMap := make(map[string]map[int]string)
  2866. //取到所有数据
  2867. for i := range req.Data {
  2868. //取到一行
  2869. if i > 4 {
  2870. //先拿下日期列表
  2871. if req.Data[i] == nil || req.Data[i][0] == nil {
  2872. continue
  2873. }
  2874. //fmt.Println("i:", i)
  2875. //fmt.Println(req.Data[i])
  2876. //fmt.Println(req.Data[i][0])
  2877. dateMap := req.Data[i][0].(map[string]interface{})
  2878. _, ok := dateMap["m"]
  2879. if ok {
  2880. dateList = append(dateList, dateMap["m"].(string))
  2881. //fmt.Println("dateList:", dateList)
  2882. } else {
  2883. continue
  2884. }
  2885. }
  2886. for j, dataArr := range req.Data[i] {
  2887. //每一列
  2888. if dataArr == nil {
  2889. continue
  2890. }
  2891. dataMap := dataArr.(map[string]interface{})
  2892. if dataList == nil {
  2893. dataList = make([][]map[string]interface{}, len(req.Data))
  2894. }
  2895. if dataList[i] == nil {
  2896. dataList[i] = make([]map[string]interface{}, len(req.Data[i]))
  2897. }
  2898. dataList[i][j] = dataMap
  2899. //fmt.Println("dataMap", dataMap["m"])
  2900. v, _ := dataMap["m"]
  2901. //指标名称列表
  2902. if v == "指标名称" {
  2903. for nameIndex := 1; nameIndex < len(req.Data[i]); nameIndex++ {
  2904. if req.Data[i][nameIndex] == nil {
  2905. break
  2906. }
  2907. secNameMap := req.Data[i][nameIndex].(map[string]interface{})
  2908. secName, _ := secNameMap["m"]
  2909. if secName == nil {
  2910. continue
  2911. }
  2912. secNameList = append(secNameList, secNameMap["m"].(string))
  2913. //fmt.Println("secName:", secNameList)
  2914. }
  2915. }
  2916. //频度列表
  2917. if v == "频度" {
  2918. for nameIndex := 1; nameIndex < len(req.Data[i]); nameIndex++ {
  2919. if req.Data[i][nameIndex] == nil {
  2920. break
  2921. }
  2922. frequencyMap := req.Data[i][nameIndex].(map[string]interface{})
  2923. frequency, _ := frequencyMap["m"]
  2924. if frequency == nil {
  2925. continue
  2926. }
  2927. frequencyList = append(frequencyList, frequencyMap["m"].(string))
  2928. //fmt.Println("frequencyList:", frequencyList)
  2929. }
  2930. }
  2931. //单位列表
  2932. if v == "单位" {
  2933. for nameIndex := 1; nameIndex < len(req.Data[i]); nameIndex++ {
  2934. if req.Data[i][nameIndex] == nil {
  2935. break
  2936. }
  2937. unitMap := req.Data[i][nameIndex].(map[string]interface{})
  2938. unit, _ := unitMap["m"]
  2939. if unit == nil {
  2940. continue
  2941. }
  2942. unitList = append(unitList, unitMap["m"].(string))
  2943. //fmt.Println("unitList:", unitList)
  2944. }
  2945. }
  2946. //数据列表
  2947. //var valueList []string
  2948. valueListMap := make(map[int]string)
  2949. if i > 4 {
  2950. for index := 1; index < len(req.Data[i]); index++ {
  2951. if req.Data[i][index] == nil {
  2952. continue
  2953. }
  2954. valueMap := req.Data[i][index].(map[string]interface{})
  2955. value, _ := valueMap["m"]
  2956. if value == nil {
  2957. continue
  2958. }
  2959. valueListMap[index] = valueMap["m"].(string)
  2960. // 09-27 千位分隔符时用 "m" 取字符串存数据库会把逗号当小数点,现在换用 "v" 直接取数字再转为字符串,看看会不会有问题
  2961. if ct, ok := valueMap["ct"].(map[string]interface{}); ok {
  2962. fa, _ := ct["fa"]
  2963. if fa == "#,##0.000" {
  2964. value = valueMap["v"]
  2965. floatValue := valueMap["v"].(float64)
  2966. valueListMap[index] = strconv.FormatFloat(floatValue, 'f', -1, 64)
  2967. }
  2968. }
  2969. //valueList = append(valueList, valueMap["m"].(string))
  2970. //fmt.Println("valueList:", valueList)
  2971. }
  2972. dateMap := req.Data[i][0].(map[string]interface{})
  2973. date := dateMap["m"].(string)
  2974. dateValueMap[date] = valueListMap
  2975. }
  2976. }
  2977. //firstCell := req.Data[i][0]
  2978. //if firstCell == nil {
  2979. // continue
  2980. //}
  2981. //dataMap := firstCell.(map[string]interface{})
  2982. //if dataList == nil {
  2983. // dataList = make([][]map[string]interface{}, len(req.Data[i]))
  2984. //}
  2985. //if dataList[i] == nil {
  2986. // dataList[i] = make([]map[string]interface{}, len(req.Data[i]))
  2987. //}
  2988. //dataList[i][0] = dataMap
  2989. //fmt.Println("dataMap", dataMap["m"])
  2990. //v, _ := dataMap["m"]
  2991. ////指标名称
  2992. //if v == "指标名称" {
  2993. // secNameMap := req.Data[i][1].(map[string]interface{})
  2994. // secName = secNameMap["m"].(string)
  2995. // fmt.Println("secName:", secName)
  2996. //}
  2997. ////频度
  2998. //if v == "频度" {
  2999. // frequencyMap := req.Data[i][1].(map[string]interface{})
  3000. // frequency = frequencyMap["m"].(string)
  3001. // fmt.Println("frequency:", frequency)
  3002. //}
  3003. ////单位
  3004. //if v == "单位" {
  3005. // unitMap := req.Data[i][1].(map[string]interface{})
  3006. // unit = unitMap["m"].(string)
  3007. // fmt.Println("unit:", unit)
  3008. //}
  3009. //
  3010. ////日期
  3011. //dateMap := req.Data[i][1].(map[string]interface{})
  3012. //createDate = dateMap["m"].(string)
  3013. //
  3014. ////值
  3015. //valueMap := req.Data[i][valueIndex].(map[string]interface{})
  3016. //closeVal = valueMap["m"].(string)
  3017. //新增指标
  3018. //errMsg := services.AddEdbItem(secName, unit, frequency, req.ClassifyId, sysUser)
  3019. //if errMsg == "" {
  3020. // br.Msg = "新增指标异常!"
  3021. // br.ErrMsg = errMsg
  3022. // return
  3023. //}
  3024. valueIndex++
  3025. }
  3026. //var excelId int64
  3027. //保存EXCEL样式
  3028. //{
  3029. // cellData, err := json.Marshal(cellDataList)
  3030. // if err != nil {
  3031. // br.Msg = "参数解析异常!"
  3032. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3033. // return
  3034. // }
  3035. // config, err := json.Marshal(req.Config)
  3036. // if err != nil {
  3037. // br.Msg = "参数解析异常!"
  3038. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3039. // return
  3040. // }
  3041. // datas, err := json.Marshal(dataList)
  3042. // if err != nil {
  3043. // br.Msg = "参数解析异常!"
  3044. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3045. // return
  3046. // }
  3047. // excelItem := data_manage.ExcelStyle{
  3048. // CellData: string(cellData),
  3049. // Config: string(config),
  3050. // Data: string(datas),
  3051. // }
  3052. // excelId, err = models.AddExcelData(&excelItem)
  3053. // if err != nil {
  3054. // br.ErrMsg = "获取失败,Err:" + err.Error()
  3055. // br.Msg = "获取失败"
  3056. // return
  3057. // }
  3058. //
  3059. // //判断映射表是否已经存在
  3060. // count, err := data_manage.GetExcelEdbdataMappingCount(req.ClassifyId, target.TradeCode, frequency)
  3061. // if err != nil {
  3062. // br.ErrMsg = "GetExcelEdbdataMappingCount,Err:" + err.Error()
  3063. // br.Msg = "新增映射表失败"
  3064. // return
  3065. // }
  3066. // mappingItem := data_manage.ExcelEdbdataMapping{
  3067. // ExcelId: excelId,
  3068. // ClassifyId: req.ClassifyId,
  3069. // Frequency: frequency,
  3070. // TradeCode: target.TradeCode,
  3071. // CreateTime: time.Now(),
  3072. // }
  3073. // if count == 0{
  3074. // //新增
  3075. // err := data_manage.AddExcelEdbdataMapping(&mappingItem)
  3076. // if err != nil {
  3077. // br.ErrMsg = "AddExcelEdbdataMapping,Err:" + err.Error()
  3078. // br.Msg = "新增映射表失败"
  3079. // return
  3080. // }
  3081. // }
  3082. //}
  3083. // 所有的指标数据map
  3084. edbCodeDataMap := make(map[string]map[string]string)
  3085. addEdbTradeMap := make(map[string]bool)
  3086. updateEdbTradeMap := make(map[string]bool)
  3087. updateDataTradeMap := make(map[string]bool)
  3088. defer func() {
  3089. go func(addEdbTradeMap, updateEdbTradeMap, updateDataTradeMap map[string]bool) {
  3090. addRecordList := make([]*models.EdbinfoOpRecord, 0)
  3091. for tradeCode := range addEdbTradeMap {
  3092. addRecordList = append(addRecordList, &models.EdbinfoOpRecord{
  3093. TradeCode: tradeCode,
  3094. Remark: "创建指标",
  3095. UserId: sysUser.AdminId,
  3096. UserName: sysUser.RealName,
  3097. CreateTime: time.Now(),
  3098. })
  3099. }
  3100. for tradeCode := range updateEdbTradeMap {
  3101. addRecordList = append(addRecordList, &models.EdbinfoOpRecord{
  3102. TradeCode: tradeCode,
  3103. Remark: "编辑指标",
  3104. UserId: sysUser.AdminId,
  3105. UserName: sysUser.RealName,
  3106. CreateTime: time.Now(),
  3107. })
  3108. }
  3109. for tradeCode := range updateDataTradeMap {
  3110. addRecordList = append(addRecordList, &models.EdbinfoOpRecord{
  3111. TradeCode: tradeCode,
  3112. Remark: "更新数据",
  3113. UserId: sysUser.AdminId,
  3114. UserName: sysUser.RealName,
  3115. CreateTime: time.Now(),
  3116. })
  3117. }
  3118. if len(addRecordList) > 0 {
  3119. obj := models.EdbinfoOpRecord{}
  3120. _ = obj.MulCreate(addRecordList)
  3121. }
  3122. //将该指标的code加入到 “手工数据导入后刷新” 缓存
  3123. if utils.Re == nil {
  3124. for tradeCode := range updateDataTradeMap {
  3125. // 更新手工数据的最大最小值
  3126. data.ModifyManualEdbMaxMinDate(tradeCode)
  3127. //将该指标的code加入到 “手工数据导入后刷新” 缓存
  3128. err := utils.Rc.LPush(utils.CACHE_IMPORT_MANUAL_DATA, tradeCode)
  3129. if err != nil {
  3130. fmt.Println("CACHE_IMPORT_MANUAL_DATA LPush Err:" + err.Error())
  3131. }
  3132. }
  3133. }
  3134. }(addEdbTradeMap, updateEdbTradeMap, updateDataTradeMap)
  3135. }()
  3136. //超管账号可以查看分类下的所有频度数据
  3137. userId := sysUser.AdminId
  3138. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3139. userId = 0
  3140. }
  3141. //获取账户所拥有权限的分类id集合
  3142. classifyIdList, err := data.GetUserManualClassifyIdList(userId)
  3143. if err != nil {
  3144. br.Msg = "获取分类数据失败"
  3145. br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
  3146. return
  3147. }
  3148. if !utils.InArrayByInt(classifyIdList, req.ClassifyId) {
  3149. br.Msg = "无权访问"
  3150. br.ErrMsg = "无权访问"
  3151. br.IsSendEmail = false
  3152. return
  3153. }
  3154. //操作指标,新增指标及数据等
  3155. {
  3156. for i := 0; i < len(secNameList); i++ {
  3157. //fmt.Println("len(secNameList):", len(secNameList))
  3158. secName := secNameList[i]
  3159. frequency := frequencyList[i]
  3160. //防止填了指标名称后没填单位报错
  3161. if len(unitList) < len(secNameList) {
  3162. br.Msg = "单位填写异常!"
  3163. br.ErrMsg = "单位填写异常!"
  3164. return
  3165. }
  3166. unit := unitList[i]
  3167. for j, s := range dateList {
  3168. var closeVal string
  3169. //valueList, ok := dateValueMap[s]
  3170. valueMap, ok := dateValueMap[s]
  3171. //fmt.Println("valueMap:", valueMap)
  3172. if ok {
  3173. createDate := dateList[j]
  3174. //if i < len(valueList) {
  3175. // closeVal = valueList[i]
  3176. //} else {
  3177. // continue
  3178. //}
  3179. closeVal, ok = valueMap[i+1]
  3180. target, ok2 := targetMap[secName]
  3181. if !ok2 {
  3182. tmpTarget, err := models.GetTargetBySecName(secName)
  3183. if err != nil {
  3184. //如果是找不到该指标,那么新增指标
  3185. if err.Error() == utils.ErrNoRow() {
  3186. //if frequency == "" {
  3187. // failItem := new(models.EdbdataImportFail)
  3188. // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
  3189. // failItem.ClassifyName = classifyName
  3190. // failItem.CreateDate = createDate
  3191. // failItem.SecName = secName
  3192. // failItem.Close = closeVal
  3193. // failItem.Remark = "新增指标失败,频度字段为空"
  3194. // failItem.Frequency = frequency
  3195. // failItem.Unit = unit
  3196. // failDatas = append(failDatas, failItem)
  3197. // continue
  3198. //}
  3199. //if unit == "" {
  3200. // failItem := new(models.EdbdataImportFail)
  3201. // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
  3202. // failItem.ClassifyName = classifyName
  3203. // failItem.CreateDate = createDate
  3204. // failItem.SecName = secName
  3205. // failItem.Close = closeVal
  3206. // failItem.Remark = "新增指标失败,单位字段为空"
  3207. // failItem.Frequency = frequency
  3208. // failItem.Unit = unit
  3209. // failDatas = append(failDatas, failItem)
  3210. // continue
  3211. //}
  3212. tmpErr := data.AddEdbInfo(secName, unit, frequency, "", sysUser.Mobile, req.ClassifyId, sysUser.AdminId, sysUser.RealName)
  3213. if tmpErr != nil {
  3214. //fmt.Println("AddEdbInfo err:", err.Error())
  3215. utils.FileLogData.Error("AddEdbInfo err :%s", tmpErr.Error())
  3216. continue
  3217. }
  3218. tmpTarget, tmpErr := models.GetTargetBySecName(secName)
  3219. target = tmpTarget
  3220. targetMap[secName] = target
  3221. // 指标新增
  3222. addEdbTradeMap[target.TradeCode] = true
  3223. } else {
  3224. fmt.Println("导入数据 获取指标:Err:" + err.Error())
  3225. }
  3226. } else {
  3227. target = tmpTarget
  3228. targetMap[secName] = target
  3229. }
  3230. }
  3231. // 没有该分类品种权限的话,那么就过滤
  3232. if !utils.InArrayByInt(classifyIdList, target.ClassifyId) {
  3233. continue
  3234. }
  3235. // 指标信息变更,需要更新
  3236. if frequency != target.Frequency || unit != target.Unit || req.ClassifyId != target.ClassifyId {
  3237. fmt.Println("更新指标频度或单位")
  3238. err = models.ModifyEdbinfo(target.TradeCode, unit, frequency, req.ClassifyId)
  3239. if err != nil {
  3240. fmt.Println("EditEdbinfo err:", err.Error())
  3241. return
  3242. }
  3243. // 指标信息变更
  3244. if _, isAdd := addEdbTradeMap[target.TradeCode]; !isAdd {
  3245. updateEdbTradeMap[target.TradeCode] = true
  3246. }
  3247. }
  3248. //判断指标数据是否已经存在
  3249. tmpDataMap, ok2 := edbCodeDataMap[target.TradeCode]
  3250. if !ok2 {
  3251. tmpDataMap = make(map[string]string)
  3252. targetDataList, tmpErr := models.GetTargetsDataList(target.TradeCode)
  3253. if tmpErr != nil {
  3254. err = tmpErr
  3255. }
  3256. for _, tmpData := range targetDataList {
  3257. tmpDataMap[tmpData.Dt] = tmpData.Close
  3258. }
  3259. edbCodeDataMap[target.TradeCode] = tmpDataMap
  3260. }
  3261. //判断数据是否已经存在
  3262. tmpVal, ok3 := tmpDataMap[createDate]
  3263. //数据已存在,进行更新操作
  3264. if ok3 {
  3265. if closeVal != "" {
  3266. // 库里面的数据
  3267. tmpValDecimal, tmpErr := decimal.NewFromString(tmpVal)
  3268. if tmpErr != nil {
  3269. fmt.Println("tmpVal Parse err:", tmpErr.Error())
  3270. err = tmpErr
  3271. continue
  3272. }
  3273. // 用户填写的数据
  3274. closeValDecimal, tmpErr := decimal.NewFromString(closeVal)
  3275. if tmpErr != nil {
  3276. fmt.Println("closeVal Parse err:", tmpErr.Error())
  3277. err = tmpErr
  3278. continue
  3279. }
  3280. if !tmpValDecimal.Equal(closeValDecimal) {
  3281. fmt.Println("更新数值")
  3282. err = models.ModifyTargetsDataByImport(target.TradeCode, createDate, closeVal)
  3283. if err != nil {
  3284. fmt.Println("ModifyTargetsDataByImport err:", err.Error())
  3285. errs = append(errs, err.Error())
  3286. //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 修改数据失败:Err:"+err.Error(), utils.EmailSendToUsers)
  3287. }
  3288. // 指标数据变更
  3289. updateDataTradeMap[target.TradeCode] = true
  3290. }
  3291. } else {
  3292. fmt.Println("删除数值")
  3293. err = models.DeleteTargetsDataByImport(target.TradeCode, createDate)
  3294. if err != nil {
  3295. fmt.Println("DeleteTargetsDataByImport err:", err.Error())
  3296. errs = append(errs, err.Error())
  3297. //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 修改数据失败:Err:"+err.Error(), utils.EmailSendToUsers)
  3298. }
  3299. // 指标数据变更
  3300. updateDataTradeMap[target.TradeCode] = true
  3301. }
  3302. } else { //数据不存在,进行新增操作
  3303. if target.TradeCode != "" && createDate != "" && closeVal != "" {
  3304. fmt.Println("新增")
  3305. models.AddTargetsDataByImport(target.TradeCode, createDate, closeVal)
  3306. if err != nil {
  3307. fmt.Println("AddTargetsDataByImport err:", err.Error())
  3308. errs = append(errs, err.Error())
  3309. //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 新增数据失败:Err:"+err.Error(), utils.EmailSendToUsers)
  3310. }
  3311. tmpDataMap[createDate] = closeVal
  3312. edbCodeDataMap[target.TradeCode] = tmpDataMap
  3313. // 指标数据变更
  3314. updateDataTradeMap[target.TradeCode] = true
  3315. }
  3316. }
  3317. //保存关联表
  3318. //{
  3319. // //判断映射表是否已经存在
  3320. // count, err := data_manage.GetExcelEdbdataMappingCount(req.ClassifyId, target.TradeCode, frequency)
  3321. // if err != nil {
  3322. // br.ErrMsg = "GetExcelEdbdataMappingCount,Err:" + err.Error()
  3323. // br.Msg = "新增映射表失败"
  3324. // return
  3325. // }
  3326. // mappingItem := data_manage.ExcelEdbdataMapping{
  3327. // ExcelId: excelId,
  3328. // ClassifyId: req.ClassifyId,
  3329. // Frequency: frequency,
  3330. // TradeCode: target.TradeCode,
  3331. // CreateTime: time.Now(),
  3332. // }
  3333. // if count == 0{
  3334. // //新增
  3335. // err := data_manage.AddExcelEdbdataMapping(&mappingItem)
  3336. // if err != nil {
  3337. // br.ErrMsg = "AddExcelEdbdataMapping,Err:" + err.Error()
  3338. // br.Msg = "新增映射表失败"
  3339. // return
  3340. // }
  3341. // }
  3342. //}
  3343. }
  3344. }
  3345. }
  3346. }
  3347. //resp := models.TargetItemListResp{
  3348. // List: list,
  3349. //}
  3350. br.Ret = 200
  3351. br.Success = true
  3352. br.Msg = "获取成功"
  3353. //br.Data = resp
  3354. //br.Data = list
  3355. }
  3356. // ExcelDataEdit
  3357. // @Title 在线Excel编辑
  3358. // @Description 在线Excel编辑
  3359. // @Param ClassifyId query string false "指标唯一编码"
  3360. // @Param TradeCode query string false "指标唯一编码"
  3361. // @Param Frequency query string true "频度"
  3362. // @Success 200
  3363. // @router /target/excel_style/edit [get]
  3364. func (this *TargetController) ExcelDataEdit() {
  3365. br := new(models.BaseResponse).Init()
  3366. defer func() {
  3367. this.Data["json"] = br
  3368. this.ServeJSON()
  3369. }()
  3370. sysUser := this.SysUser
  3371. if sysUser == nil {
  3372. br.Msg = "请重新登录"
  3373. return
  3374. }
  3375. //指标编码
  3376. //tradeCode := this.GetString("TradeCode")
  3377. classifyId, _ := this.GetInt("ClassifyId")
  3378. frequency := this.GetString("Frequency")
  3379. excelId, err := data_manage.GetExcelEdbdataMappingByTradeCode(classifyId, frequency)
  3380. if err != nil {
  3381. br.Msg = "查找关联表失败"
  3382. br.ErrMsg = "GetExcelEdbdataMappingByTradeCode,Err:" + err.Error()
  3383. return
  3384. }
  3385. item, err := data_manage.GetExcelStyleById(*excelId)
  3386. if err != nil {
  3387. br.Msg = "查找样式失败"
  3388. br.ErrMsg = "GetExcelStyleById,Err:" + err.Error()
  3389. return
  3390. }
  3391. br.Ret = 200
  3392. br.Success = true
  3393. br.Msg = "获取成功"
  3394. //br.Data = resp
  3395. br.Data = item
  3396. }
  3397. //// ImportData
  3398. //// @Title 导入数据
  3399. //// @Description 导入数据
  3400. //// @Param EntryFile query file true "文件"
  3401. //// @Success 200 Ret=200 录入成功
  3402. //// @router /import/data [post]
  3403. //func (c *ManualEdbController) ImportData() {
  3404. // br := new(models.BaseResponse).Init()
  3405. // defer func() {
  3406. // c.Data["json"] = br
  3407. // c.ServeJSON()
  3408. // }()
  3409. // sysUser := c.SysUser
  3410. // if sysUser == nil {
  3411. // br.Msg = "请重新登录"
  3412. // return
  3413. // }
  3414. // file, _, err := c.GetFile("EntryFile")
  3415. // if err != nil {
  3416. // br.Msg = "获取文件失败"
  3417. // br.ErrMsg = "获取文件失败,Err:" + err.Error()
  3418. // return
  3419. // }
  3420. // path := "./static/数据导入_" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  3421. // defer file.Close()
  3422. // err = c.SaveToFile("EntryFile", path)
  3423. // if err != nil {
  3424. // br.Msg = "文件保存失败"
  3425. // br.ErrMsg = "文件保存失败,Err:" + err.Error()
  3426. // return
  3427. // }
  3428. // if utils.RunMode == "debug" {
  3429. // defer os.Remove(path)
  3430. // }
  3431. // xlFile, err := xlsx.OpenFile(path)
  3432. // if err != nil {
  3433. // fmt.Println(err.Error())
  3434. // return
  3435. // }
  3436. //
  3437. // //超管账号可以查看分类下的所有频度数据
  3438. // userId := sysUser.AdminId
  3439. // if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3440. // userId = 0
  3441. // }
  3442. // //获取账户所拥有权限的分类id集合
  3443. // classifyNameStrList, edbDataClassifyMap, err := data.GetEdbClassifyNameListByAdminId(int64(userId))
  3444. // if err != nil {
  3445. // br.Msg = "获取分类数据失败"
  3446. // return
  3447. // }
  3448. //
  3449. // //导入成功数量
  3450. // successCount := 0
  3451. // //导入失败数据
  3452. // failDatas := make([]*models.EdbdataImportFail, 0)
  3453. //
  3454. // //指标map
  3455. // targetMap := make(map[string]*models.Edbinfo)
  3456. // defer func() {
  3457. // for _, target := range targetMap {
  3458. // //结束后,清除掉对应的缓存
  3459. // key := "import:edbinfo:data:" + target.TradeCode
  3460. // utils.Rc.Delete(key)
  3461. //
  3462. // //将该指标的code加入到 “手工数据导入后刷新” 缓存
  3463. // if utils.Re == nil {
  3464. // err := utils.Rc.LPush(utils.CACHE_IMPORT_MANUAL_DATA, target.TradeCode)
  3465. // if err != nil {
  3466. // fmt.Println("CACHE_IMPORT_MANUAL_DATA LPush Err:" + err.Error())
  3467. // }
  3468. // }
  3469. // }
  3470. // }()
  3471. //
  3472. // // 所有的指标数据map
  3473. // edbCodeDataMap := make(map[string]map[string]string)
  3474. //
  3475. // // 遍历sheet页读取
  3476. // for _, sheet := range xlFile.Sheets {
  3477. // fmt.Println("sheet name: ", sheet.Name)
  3478. // //遍历行读取
  3479. // maxRow := sheet.MaxRow
  3480. // fmt.Println("maxRow:", maxRow)
  3481. // fmt.Println("maxRow")
  3482. // for i := 0; i < maxRow; i++ {
  3483. // if i == 1 {
  3484. // row := sheet.Row(i)
  3485. // cells := row.Cells
  3486. // if len(cells) < 6 {
  3487. // br.ErrMsg = "导入文件异常,请下载最新导入模板文件"
  3488. // br.Msg = "导入文件异常,请下载最新导入模板文件"
  3489. // return
  3490. // }
  3491. // templateFail := false
  3492. // if cells[0].Value != "品种分类" && cells[0].Value != "Species Category" {
  3493. // templateFail = true
  3494. // }
  3495. // if cells[1].Value != "录入日期" && cells[1].Value != "Input Date" {
  3496. // templateFail = true
  3497. // }
  3498. // if cells[2].Value != "指标名称" && cells[2].Value != "Indicator Name Indicator Name" {
  3499. // templateFail = true
  3500. // }
  3501. // if cells[3].Value != "值" && cells[3].Value != "Value" {
  3502. // templateFail = true
  3503. // }
  3504. // if cells[4].Value != "频度" && cells[4].Value != "Frequency" {
  3505. // templateFail = true
  3506. // }
  3507. // if cells[5].Value != "单位" && cells[5].Value != "Unit" {
  3508. // templateFail = true
  3509. // }
  3510. // if templateFail {
  3511. // br.ErrMsg = "导入文件异常,请下载最新导入模板文件"
  3512. // br.Msg = "导入文件异常,请下载最新导入模板文件"
  3513. // return
  3514. // }
  3515. // }
  3516. // if i > 1 {
  3517. // row := sheet.Row(i)
  3518. // cells := row.Cells
  3519. // if len(cells) >= 6 {
  3520. // classifyName := cells[0].Value //分类
  3521. // if classifyName == "" { //过滤空白行
  3522. // continue
  3523. // }
  3524. // cell1 := cells[1].Value
  3525. // //createDate := utils.ConvertToFormatDay(cell1) //录入日期
  3526. // createDate := cell1
  3527. // cell2 := cells[2].Value //指标名称
  3528. // secName := utils.TrimStr(cell2)
  3529. // frequency := cells[4].Value //频度
  3530. // unit := cells[5].Value //单位
  3531. //
  3532. // closeVal := cells[3].Value //值
  3533. // if strings.Contains(closeVal, "#N/A") {
  3534. // continue
  3535. // }
  3536. //
  3537. // //校验表格中的日期格式
  3538. // if strings.Contains(createDate, "-") {
  3539. // //如果是带有 - 的普通日期格式文本
  3540. // _, timeErr := time.Parse("2006-1-2", createDate)
  3541. // if timeErr != nil {
  3542. // failItem := new(models.EdbdataImportFail)
  3543. // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
  3544. // failItem.ClassifyName = classifyName
  3545. // failItem.CreateDate = createDate
  3546. // failItem.SecName = secName
  3547. // failItem.Close = closeVal
  3548. // failItem.Remark = "日期格式异常"
  3549. // failItem.Frequency = frequency
  3550. // failItem.Unit = unit
  3551. // failDatas = append(failDatas, failItem)
  3552. // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 获取分类:Err:"+err.Error(), utils.EmailSendToUsers)
  3553. // continue
  3554. // }
  3555. // } else if strings.Contains(createDate, "/") {
  3556. // //如果是带有 / 的普通日期格式文本
  3557. // createDateTime, timeErr := time.Parse("2006/1/2", createDate)
  3558. // if timeErr != nil {
  3559. // failItem := new(models.EdbdataImportFail)
  3560. // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
  3561. // failItem.ClassifyName = classifyName
  3562. // failItem.CreateDate = createDate
  3563. // failItem.SecName = secName
  3564. // failItem.Close = closeVal
  3565. // failItem.Remark = "日期格式异常"
  3566. // failItem.Frequency = frequency
  3567. // failItem.Unit = unit
  3568. // failDatas = append(failDatas, failItem)
  3569. // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 获取分类:Err:"+err.Error(), utils.EmailSendToUsers)
  3570. // continue
  3571. // }
  3572. // createDate = createDateTime.Format("2006-01-02")
  3573. // } else {
  3574. // //可能是excel的日期格式
  3575. // _, tmpErr := strconv.Atoi(createDate)
  3576. // if tmpErr != nil {
  3577. // failItem := new(models.EdbdataImportFail)
  3578. // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
  3579. // failItem.ClassifyName = classifyName
  3580. // failItem.CreateDate = createDate
  3581. // failItem.SecName = secName
  3582. // failItem.Close = closeVal
  3583. // failItem.Remark = "日期格式异常"
  3584. // failItem.Frequency = frequency
  3585. // failItem.Unit = unit
  3586. // failDatas = append(failDatas, failItem)
  3587. // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 获取分类:Err:"+err.Error(), utils.EmailSendToUsers)
  3588. // continue
  3589. // }
  3590. // createDate = utils.ConvertToFormatDay(createDate) //录入日期
  3591. // }
  3592. //
  3593. // closeValFloat, err := cells[3].Float() //值
  3594. //
  3595. // if err != nil {
  3596. // failItem := new(models.EdbdataImportFail)
  3597. // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
  3598. // failItem.ClassifyName = classifyName
  3599. // failItem.CreateDate = createDate
  3600. // failItem.SecName = secName
  3601. // failItem.Close = cells[3].Value
  3602. // failItem.Remark = "值类型异常"
  3603. // failItem.Frequency = frequency
  3604. // failItem.Unit = unit
  3605. // failDatas = append(failDatas, failItem)
  3606. // continue
  3607. // }
  3608. // newDecimal := decimal.NewFromFloat(closeValFloat)
  3609. // newDecimal.Round(4)
  3610. // closeVal = newDecimal.String()
  3611. // if strings.Contains(closeVal, "#N/A") {
  3612. // continue
  3613. // }
  3614. // //closeVal := closeValFloat.
  3615. //
  3616. // //判断指标,类型,等数据是否正常
  3617. // classifyName = strings.Trim(classifyName, " ")
  3618. // frequency = utils.TrimStr(frequency)
  3619. // unit = utils.TrimStr(unit)
  3620. //
  3621. // // 成功数量超过20个指标,那就不导入了
  3622. // if len(targetMap) >= 150 {
  3623. // failItem := new(models.EdbdataImportFail)
  3624. // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
  3625. // failItem.ClassifyName = classifyName
  3626. // failItem.CreateDate = createDate
  3627. // failItem.SecName = secName
  3628. // failItem.Close = closeVal
  3629. // failItem.Remark = "导入指标数量过多"
  3630. // failItem.Frequency = frequency
  3631. // failItem.Unit = unit
  3632. // failDatas = append(failDatas, failItem)
  3633. // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 获取分类:Err:"+err.Error(), utils.EmailSendToUsers)
  3634. // continue
  3635. // }
  3636. //
  3637. // if !strings.Contains(strings.Join(classifyNameStrList, ","), classifyName) {
  3638. // failItem := new(models.EdbdataImportFail)
  3639. // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
  3640. // failItem.ClassifyName = classifyName
  3641. // failItem.CreateDate = createDate
  3642. // failItem.SecName = secName
  3643. // failItem.Close = closeVal
  3644. // failItem.Remark = "没有该品种分类权限"
  3645. // failItem.Frequency = frequency
  3646. // failItem.Unit = unit
  3647. // failDatas = append(failDatas, failItem)
  3648. // continue
  3649. // }
  3650. // //fmt.Println(classifyName, createDate, secName, closeVal)
  3651. //
  3652. // //获取指标分类信息
  3653. // classify, ok := edbDataClassifyMap[classifyName]
  3654. // if !ok {
  3655. // failItem := new(models.EdbdataImportFail)
  3656. // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
  3657. // failItem.ClassifyName = classifyName
  3658. // failItem.CreateDate = createDate
  3659. // failItem.SecName = secName
  3660. // failItem.Close = closeVal
  3661. // failItem.Remark = "指标分类不存在"
  3662. // failItem.Frequency = frequency
  3663. // failItem.Unit = unit
  3664. // failDatas = append(failDatas, failItem)
  3665. // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 获取分类:Err:"+err.Error(), utils.EmailSendToUsers)
  3666. // continue
  3667. // }
  3668. //
  3669. // //判断指标是否存在
  3670. // target, ok := targetMap[secName]
  3671. // if !ok {
  3672. // tmpTarget, err := models.GetTargetBySecName(secName)
  3673. // if err != nil {
  3674. // //如果是找不到该指标,那么新增指标
  3675. // if err.Error() == utils.ErrNoRow() {
  3676. // if frequency == "" {
  3677. // failItem := new(models.EdbdataImportFail)
  3678. // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
  3679. // failItem.ClassifyName = classifyName
  3680. // failItem.CreateDate = createDate
  3681. // failItem.SecName = secName
  3682. // failItem.Close = closeVal
  3683. // failItem.Remark = "新增指标失败,频度字段为空"
  3684. // failItem.Frequency = frequency
  3685. // failItem.Unit = unit
  3686. // failDatas = append(failDatas, failItem)
  3687. // continue
  3688. // }
  3689. // if unit == "" {
  3690. // failItem := new(models.EdbdataImportFail)
  3691. // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
  3692. // failItem.ClassifyName = classifyName
  3693. // failItem.CreateDate = createDate
  3694. // failItem.SecName = secName
  3695. // failItem.Close = closeVal
  3696. // failItem.Remark = "新增指标失败,单位字段为空"
  3697. // failItem.Frequency = frequency
  3698. // failItem.Unit = unit
  3699. // failDatas = append(failDatas, failItem)
  3700. // continue
  3701. // }
  3702. // tmpErr := data.AddEdbInfo(secName, unit, frequency, "", sysUser.Mobile, classify.ClassifyId, sysUser.AdminId)
  3703. // if tmpErr != nil {
  3704. // fmt.Println("line 158")
  3705. // failItem := new(models.EdbdataImportFail)
  3706. // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
  3707. // failItem.ClassifyName = classifyName
  3708. // failItem.CreateDate = createDate
  3709. // failItem.SecName = secName
  3710. // failItem.Close = closeVal
  3711. // failItem.Remark = "新增指标失败"
  3712. // failItem.Frequency = frequency
  3713. // failItem.Unit = unit
  3714. // failDatas = append(failDatas, failItem)
  3715. // continue
  3716. // }
  3717. // tmpTarget, tmpErr := models.GetTargetBySecName(secName)
  3718. // target = tmpTarget
  3719. // targetMap[secName] = target
  3720. // } else {
  3721. // fmt.Println("导入数据 获取指标:Err:" + err.Error())
  3722. // }
  3723. // } else {
  3724. // target = tmpTarget
  3725. // targetMap[secName] = target
  3726. // }
  3727. //
  3728. // //设置10分钟缓存,不允许其他地方删除
  3729. // key := "import:edbinfo:data:" + target.TradeCode
  3730. // utils.Rc.SetNX(key, 1, time.Second*600)
  3731. // }
  3732. //
  3733. // if target == nil {
  3734. // fmt.Println("指标不存在")
  3735. // failItem := new(models.EdbdataImportFail)
  3736. // failItem.SysUserId = strconv.Itoa(sysUser.AdminId)
  3737. // failItem.ClassifyName = classifyName
  3738. // failItem.CreateDate = createDate
  3739. // failItem.SecName = secName
  3740. // failItem.Close = closeVal
  3741. // failItem.Remark = "指标不存在"
  3742. // failItem.Frequency = frequency
  3743. // failItem.Unit = unit
  3744. // failDatas = append(failDatas, failItem)
  3745. // continue
  3746. // }
  3747. //
  3748. // //更新指标信息
  3749. // updateCols := make([]string, 0)
  3750. // //更新指标分类
  3751. // if target.ClassifyId <= 0 && classify.ClassifyId > 0 {
  3752. // target.ClassifyId = classify.ClassifyId
  3753. // updateCols = append(updateCols, "ClassifyId")
  3754. // }
  3755. // if target.Frequency != frequency {
  3756. // target.Frequency = frequency
  3757. // target.NoticeTime = ""
  3758. // updateCols = append(updateCols, "Frequency", "NoticeTime")
  3759. // }
  3760. // if target.Unit != unit {
  3761. // target.Unit = unit
  3762. // updateCols = append(updateCols, "Unit")
  3763. // }
  3764. // if len(updateCols) > 0 {
  3765. // _ = target.Update(updateCols)
  3766. // }
  3767. //
  3768. // // 判断指标数据列表是否已经存在
  3769. // tmpDataMap, ok := edbCodeDataMap[target.TradeCode]
  3770. // if !ok {
  3771. // tmpDataMap = make(map[string]string)
  3772. // dataList, tmpErr := models.GetTargetsDataList(target.TradeCode)
  3773. // if tmpErr != nil {
  3774. // go alarm_msg.SendAlarmMsg("导入数据"+target.TradeCode+" 获取指标的数据失败,Err:"+err.Error(), 3)
  3775. // }
  3776. // for _, tmpData := range dataList {
  3777. // tmpDataMap[tmpData.Dt] = tmpData.Close
  3778. // }
  3779. // edbCodeDataMap[target.TradeCode] = tmpDataMap
  3780. // }
  3781. //
  3782. // //判断数据是否已经存在
  3783. // tmpVal, ok := tmpDataMap[createDate]
  3784. // //数据已存在,进行更新操作
  3785. // if ok {
  3786. // if tmpVal != closeVal {
  3787. // err = models.ModifyTargetsDataByImport(target.TradeCode, createDate, closeVal)
  3788. // if err != nil {
  3789. // go alarm_msg.SendAlarmMsg("导入数据 修改数据失败,Err:"+err.Error(), 3)
  3790. // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 修改数据失败:Err:"+err.Error(), utils.EmailSendToUsers)
  3791. // }
  3792. // }
  3793. // } else { //数据不存在,进行新增操作
  3794. // if target.TradeCode != "" && createDate != "" && closeVal != "" {
  3795. // models.AddTargetsDataByImport(target.TradeCode, createDate, closeVal)
  3796. // if err != nil {
  3797. // go alarm_msg.SendAlarmMsg("导入数据 新增数据失败,Err:"+err.Error(), 3)
  3798. // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 新增数据失败:Err:"+err.Error(), utils.EmailSendToUsers)
  3799. // }
  3800. // tmpDataMap[createDate] = closeVal
  3801. // edbCodeDataMap[target.TradeCode] = tmpDataMap
  3802. // }
  3803. // }
  3804. // successCount++
  3805. // } else {
  3806. // //br.ErrMsg = "请填写导入内容"
  3807. // //br.Msg = "请填写导入内容"
  3808. // //return
  3809. // }
  3810. // }
  3811. // }
  3812. // }
  3813. // resp := models.EdbdataImportResp{
  3814. // SuccessCount: successCount,
  3815. // FailCount: len(failDatas),
  3816. // }
  3817. // fmt.Println("failDatas:", len(failDatas))
  3818. // if len(failDatas) > 0 {
  3819. // //先删除导入失败记录
  3820. // _ = models.DelEdbDataImportFail(sysUser.AdminId)
  3821. // //错误信息字符串切片,最后作为发送邮件通知使用
  3822. // failContents := make([]string, 0)
  3823. // for _, v := range failDatas {
  3824. // failContents = append(failContents, fmt.Sprint(v.SecName, "导入失败:", v.Remark))
  3825. // err = models.AddEdbdataImportFail(v)
  3826. // if err != nil {
  3827. // go alarm_msg.SendAlarmMsg("导入数据 新增失败记录失败,Err:"+err.Error(), 3)
  3828. // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 新增失败记录失败:Err:"+err.Error(), utils.EmailSendToUsers)
  3829. // }
  3830. // }
  3831. // //导入失败的话,最后统一邮件提醒就好啦,不需要每次都去提醒
  3832. // go alarm_msg.SendAlarmMsg("导入数据 存在部分数据导入失败:"+strings.Join(failContents, ";"), 3)
  3833. // //go utils.SendEmail(utils.APPNAME+"失败提醒", "导入数据 存在部分数据导入失败:"+strings.Join(failContents, ";"), utils.EmailSendToUsers)
  3834. //
  3835. // if successCount == 0 {
  3836. // resp.Status = -1
  3837. // resp.Msg = "导入失败"
  3838. // } else {
  3839. // resp.Status = 1
  3840. // resp.Msg = "存在部分导入失败"
  3841. // }
  3842. // } else {
  3843. // resp.Status = 0
  3844. // }
  3845. // br.Msg = "导入成功"
  3846. // br.Ret = 200
  3847. // br.Success = true
  3848. // br.Data = resp
  3849. //}