target.go 118 KB

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