target.go 104 KB

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