target.go 119 KB

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