39d26891100c1a23fac266f98ad7457cbfd7b6c2.svn-base 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750
  1. package api
  2. import (
  3. "../../pkg/app"
  4. "../../pkg/e"
  5. "../../pkg/logging"
  6. "../../pkg/setting"
  7. "../../routers/restful"
  8. "bytes"
  9. "database/sql"
  10. "encoding/json"
  11. "errors"
  12. "fmt"
  13. "github.com/360EntSecGroup-Skylar/excelize"
  14. "github.com/Anderson-Lu/gofasion/gofasion"
  15. "github.com/gin-gonic/gin"
  16. "github.com/tealeg/xlsx"
  17. "github.com/xormplus/xorm"
  18. "io/ioutil"
  19. "net/http"
  20. "os"
  21. "path"
  22. "regexp"
  23. "strconv"
  24. "strings"
  25. "time"
  26. )
  27. // @Summary 根据SQL执行得到数据集
  28. // @Tags getData
  29. // @Accept json
  30. // @Produce json
  31. // @Param sql query string true "sql"
  32. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  33. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  34. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  35. // @Router /data/getdata [POST]
  36. func GetData(c *gin.Context) {
  37. appG := app.Gin{C: c}
  38. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  39. fsion := gofasion.NewFasion(string(dataByte))
  40. sqlstr := fsion.Get("sql").ValueStr()
  41. offset := fsion.Get("offset").ValueDefaultInt(0)
  42. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  43. returntype := fsion.Get("returntype").ValueDefaultStr("map")
  44. queryData, err := getDataBySql(sqlstr, offset, pagecount, returntype, nil)
  45. if err != nil {
  46. appG.Response(http.StatusOK, e.ERROR, err.Error())
  47. } else {
  48. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  49. }
  50. }
  51. func Testpartitions(c *gin.Context) {
  52. appG := app.Gin{C: c}
  53. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  54. fsion := gofasion.NewFasion(string(dataByte))
  55. databaseName := fsion.Get("databaseName").ValueStr() //获取新数据库名称
  56. user := fsion.Get("user").ValueStr() //获取新数据库用户
  57. passWord := fsion.Get("passWord").ValueStr() //获取新数据库名称
  58. host := fsion.Get("host").ValueStr() //获取新数据库名称
  59. port := fsion.Get("port").ValueStr() //获取新数据库名称
  60. sqls, err1 := restful.Engine.SQL("SELECT * FROM sql_new ").QueryString() //获取新数据库表
  61. if sqls == nil || err1 != nil {
  62. appG.Response(http.StatusOK, e.SUCCESS, "失败:"+err1.Error())
  63. }
  64. sqlstrs := strings.Split(sqls[0]["sql"], ";") //分割sql
  65. connecting := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", user, passWord, host, port, "mysql")
  66. mydb, err := sql.Open("mysql", connecting) //连接新连接
  67. if err != nil {
  68. println("err1", err.Error())
  69. }
  70. _, err = mydb.Exec("CREATE DATABASE IF NOT EXISTS `" + databaseName + "`") // 创建数据库
  71. if err != nil {
  72. println("err2", err.Error())
  73. }
  74. mydb.Close()
  75. connecting = fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", user, passWord, host, port, databaseName) //连接新数据库,创建表格
  76. mydb, err = sql.Open("mysql", connecting)
  77. if err != nil {
  78. println("err3", err.Error())
  79. }
  80. defer mydb.Close()
  81. if err == nil {
  82. mydb.SetMaxOpenConns(10)
  83. mydb.SetMaxIdleConns(10)
  84. }
  85. errmsg := ""
  86. if err == nil {
  87. //tx ,_ :=mydb.Begin()
  88. for _, sqlstr := range sqlstrs {
  89. //println("sqlstr---",sqlstr)
  90. if sqlstr == "" {
  91. continue
  92. }
  93. _, err = mydb.Exec(sqlstr)
  94. if err != nil {
  95. println("err4", err.Error())
  96. errmsg = err.Error()
  97. //err1 :=tx.Rollback()
  98. }
  99. }
  100. //_, err = mydb.Exec("CREATE TABLE `sql_new` (`sql` text DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1;")
  101. //err =tx.Commit()
  102. }
  103. if errmsg == "" {
  104. appG.Response(http.StatusOK, e.SUCCESS, "成功"+databaseName)
  105. } else {
  106. appG.Response(http.StatusOK, e.SUCCESS, "失败"+errmsg)
  107. }
  108. }
  109. func TestData(c *gin.Context) {
  110. appG := app.Gin{C: c}
  111. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  112. fsion := gofasion.NewFasion(string(dataByte))
  113. sqlstr := fsion.Get("sql").ValueStr()
  114. token := ""
  115. if tempv, exists := c.Get("jwt_username"); exists {
  116. token = tempv.(string)
  117. }
  118. appG.Response(http.StatusOK, e.SUCCESS, "你录入的名字是:"+sqlstr+";token:"+token)
  119. }
  120. // @Summary 根据APISQL表中SQL执行得到数据集
  121. // @Tags GetDataByName
  122. // @Accept json
  123. // @Produce json
  124. // @Param sqlname body string true "sqlname"
  125. // @Param offset body int true "offset"
  126. // @Param pagecount body int true "pagecount"
  127. // @Param returntype body string true "returntype"
  128. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  129. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  130. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  131. // @Router /data/GetDataByName [POST]
  132. func GetDataByName(c *gin.Context) {
  133. appG := app.Gin{C: c}
  134. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  135. fsion := gofasion.NewFasion(string(dataByte))
  136. sqlnamestr := fsion.Get("name").ValueStr()
  137. offset := fsion.Get("offset").ValueDefaultInt(0)
  138. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  139. returntype := fsion.Get("returntype").ValueDefaultStr("map")
  140. tx := restful.Engine.NewSession()
  141. err := tx.Begin()
  142. defer func() {
  143. switch {
  144. case err != nil:
  145. logging.Error("tx.Begin 事务启动失败__error:", err)
  146. if tx != nil {
  147. tx.Rollback()
  148. }
  149. default:
  150. if tx != nil {
  151. err = tx.Commit()
  152. }
  153. }
  154. if tx != nil {
  155. tx.Close()
  156. }
  157. }()
  158. sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
  159. if sql != "" {
  160. s_params := make([]interface{}, 0)
  161. if fsion.HasKey("parammaps") {
  162. parammaps := fsion.Get("parammaps")
  163. if sqlnamestr != "getNoMesList" && sqlnamestr != "getNoMesCount" {
  164. logging.Info("GetDataByName", c.Keys, c.Request.RemoteAddr, sqlnamestr, parammaps.ValueStr())
  165. }
  166. paramslist := strings.Split(p, ",")
  167. if len(paramslist) > 0 && p != "" {
  168. for _, value := range paramslist {
  169. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  170. if tempv, exists := c.Get("jwt_username"); exists {
  171. s_params = append(s_params, tempv.(string))
  172. } else {
  173. s_params = append(s_params, "")
  174. }
  175. } else {
  176. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  177. }
  178. }
  179. }
  180. } else if fsion.HasKey("params") {
  181. params := fsion.Get("params").Array()
  182. logging.Info("GetDataByName", c.Keys, c.Request.RemoteAddr, sqlnamestr, params)
  183. for _, v_params := range params {
  184. s_params = append(s_params, v_params.ValueStr())
  185. }
  186. }
  187. if returntype == "xlsx" {
  188. var xlsxfile *xlsx.File
  189. xlsxfile, _ = restful.QueryByXlsx(sql, s_params)
  190. //c.File("c:/dd.xlsx")
  191. c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  192. c.Header("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
  193. c.Header("Content-Transfer-Encoding", "binary")
  194. _ = xlsxfile.Write(c.Writer)
  195. } else {
  196. queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params, tx)
  197. if err != nil {
  198. logging.Error("GetDataByName err: ", err)
  199. msg := geterrmsg(err.Error())
  200. appG.Response(http.StatusOK, e.ERROR, msg)
  201. } else {
  202. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  203. }
  204. }
  205. } else {
  206. appG.Response(http.StatusOK, e.SUCCESS, nil)
  207. }
  208. }
  209. // @Summary 根据APISQL表中SQL执行得到数据集
  210. // @Tags GetDataByName
  211. // @Accept json
  212. // @Produce json
  213. // @Param sqlname body string true "sqlname"
  214. // @Param offset body int true "offset"
  215. // @Param pagecount body int true "pagecount"
  216. // @Param returntype body string true "returntype"
  217. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  218. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  219. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  220. // @Router /data/GetDataByName [POST]
  221. func GetDataBySqlIN(c *gin.Context) {
  222. appG := app.Gin{C: c}
  223. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  224. fsion := gofasion.NewFasion(string(dataByte))
  225. sqlnamestr := fsion.Get("name").ValueStr()
  226. offset := fsion.Get("offset").ValueDefaultInt(0)
  227. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  228. returntype := fsion.Get("returntype").ValueDefaultStr("map")
  229. tx := restful.Engine.NewSession()
  230. err := tx.Begin()
  231. defer func() {
  232. switch {
  233. case err != nil:
  234. logging.Error("tx.Begin 事务启动失败__error:", err)
  235. if tx != nil {
  236. tx.Rollback()
  237. }
  238. default:
  239. if tx != nil {
  240. err = tx.Commit()
  241. }
  242. }
  243. if tx != nil {
  244. tx.Close()
  245. }
  246. }()
  247. sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
  248. if sql != "" {
  249. s_params := make([]interface{}, 0)
  250. if fsion.HasKey("parammaps") {
  251. parammaps := fsion.Get("parammaps")
  252. if sqlnamestr != "getNoMesList" && sqlnamestr != "getNoMesCount" {
  253. logging.Info("GetDataByName", c.Keys, c.Request.RemoteAddr, sqlnamestr, parammaps.ValueStr())
  254. }
  255. paramslist := strings.Split(p, ",")
  256. if len(paramslist) > 0 && p != "" {
  257. for _, value := range paramslist {
  258. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  259. if tempv, exists := c.Get("jwt_username"); exists {
  260. s_params = append(s_params, tempv.(string))
  261. } else {
  262. s_params = append(s_params, "")
  263. }
  264. } else {
  265. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  266. }
  267. }
  268. }
  269. } else if fsion.HasKey("params") {
  270. params := fsion.Get("params").Array()
  271. logging.Info("GetDataByName", c.Keys, c.Request.RemoteAddr, sqlnamestr, params)
  272. for _, v_params := range params {
  273. s_params = append(s_params, v_params.ValueStr())
  274. }
  275. }
  276. if returntype == "xlsx" {
  277. var xlsxfile *xlsx.File
  278. xlsxfile, _ = restful.QueryByXlsx(sql, s_params)
  279. //c.File("c:/dd.xlsx")
  280. c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  281. c.Header("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
  282. c.Header("Content-Transfer-Encoding", "binary")
  283. _ = xlsxfile.Write(c.Writer)
  284. } else {
  285. queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params, tx)
  286. if err != nil {
  287. logging.Error("GetDataByName err: ", err)
  288. msg := geterrmsg(err.Error())
  289. appG.Response(http.StatusOK, e.ERROR, msg)
  290. } else {
  291. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  292. }
  293. }
  294. } else {
  295. appG.Response(http.StatusOK, e.SUCCESS, nil)
  296. }
  297. }
  298. // 错误处理
  299. // 将报错信息处理成汉字
  300. func geterrmsg(errstr string) (msgstr string) {
  301. var hzRegexp = regexp.MustCompile("^[\u4e00-\u9fa5]$") // 判断是否为汉字
  302. rs := []rune(errstr)
  303. if hzRegexp.MatchString(string(rs[0])) {
  304. msgstr = errstr
  305. return
  306. }
  307. if strings.Contains(errstr, "Duplicate entry") {
  308. strs := strings.Split(errstr, ` key '`)
  309. if len(strs) > 1 {
  310. if len(strs[len(strs)-1]) > 1 {
  311. errstr = "Duplicate entry :" + strs[len(strs)-1]
  312. }
  313. }
  314. }
  315. msg, err := restful.Engine.SQL("SELECT msg FROM err_msg where err = ? ", errstr).QueryString()
  316. if err != nil {
  317. msgstr = errstr
  318. return
  319. }
  320. if msg == nil || len(msg) == 0 {
  321. var param []interface{}
  322. param = append(param, errstr, errstr)
  323. go func() {
  324. tx := restful.Engine.NewSession()
  325. err := tx.Begin()
  326. defer func() {
  327. switch {
  328. case err != nil:
  329. logging.Error("tx.Begin 事务启动失败__error:", err)
  330. if tx != nil {
  331. tx.Rollback()
  332. }
  333. default:
  334. if tx != nil {
  335. err = tx.Commit()
  336. }
  337. }
  338. if tx != nil {
  339. tx.Close()
  340. }
  341. }()
  342. _, err = restful.ExecQueryT("insert into err_msg(err,msg) VALUES(?,?) ON DUPLICATE KEY UPDATE err=err", param, tx)
  343. if err != nil {
  344. logging.Error("insert into err_msg(err,msg) err", err)
  345. }
  346. }()
  347. msgstr = errstr
  348. } else {
  349. msgstr = msg[0]["msg"]
  350. }
  351. return
  352. }
  353. // @Summary 根据APISQL表中SQL执行得到数据集
  354. // @Tags GetDataByNameForm
  355. // @Accept json
  356. // @Produce json
  357. // @Param sqlname body json true "sqlname"
  358. // @Param offset query int true "offset"
  359. // @Param pagecount query int true "pagecount"
  360. // @Param returntype query string true "returntype"
  361. // @Param s formData json true "ss"
  362. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  363. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  364. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  365. // @Router /data/GetDataByNameForm [POST]
  366. func GetDataByNameForm(c *gin.Context) {
  367. appG := app.Gin{C: c}
  368. //sqlnamestr := c.PostForm("measureNumber")
  369. //dataByte, _ := ioutil.ReadAll(c.Request.Body)
  370. //fsion := gofasion.NewFasion(string(dataByte))
  371. //sqlnamestr := fsion.Get("name").ValueStr()
  372. //offset := fsion.Get("offset").ValueInt()
  373. //pagecount := fsion.Get("pagecount").ValueInt()
  374. //returntype := fsion.Get("returntype").ValueStr()
  375. //params := fsion.Get("params").Array()
  376. c.Request.ParseForm()
  377. params := c.Request.Form
  378. offset := 0
  379. pageSize_ := 0
  380. returntype := params.Get("page")
  381. if returntype == "" {
  382. returntype = "0"
  383. }
  384. if tempv, exists := c.Get("jwt_username"); exists {
  385. params.Set("JwtUserName", tempv.(string))
  386. } else {
  387. params.Set("JwtUserName", "")
  388. }
  389. sqlnamestr := params.Get("name")
  390. logging.Info("GetDataByNameForm ", c.Keys, sqlnamestr)
  391. s_params := make([]interface{}, 0)
  392. if returntype == "1" {
  393. pageNum, error := strconv.Atoi(params.Get("pageNum"))
  394. if error != nil {
  395. appG.ResponseEq(http.StatusOK, e.ERROR, 0, "页码不是整数")
  396. }
  397. pageSize, error := strconv.Atoi(params.Get("pageSize"))
  398. if error != nil {
  399. appG.ResponseEq(http.StatusOK, e.ERROR, 0, "每页行数不是整数")
  400. }
  401. pageSize_ = pageSize
  402. offset = pageNum
  403. }
  404. sql, p := restful.GetSqlByNameDB(sqlnamestr)
  405. paramslist := strings.Split(p, ",")
  406. if len(paramslist) > 0 && p != "" {
  407. for _, value := range paramslist {
  408. s_params = append(s_params, params.Get(strings.Trim(value, " ")))
  409. }
  410. }
  411. if sql != "" {
  412. if returntype == "xlsx" {
  413. var xlsxfile *xlsx.File
  414. xlsxfile, _ = restful.QueryByXlsx(sql, s_params)
  415. c.Header("Content-Type", "application/octet-stream")
  416. c.Header("Content-Disposition", "attachment; filename="+sqlnamestr+".xlsx")
  417. c.Header("Content-Transfer-Encoding", "binary")
  418. _ = xlsxfile.Write(c.Writer)
  419. } else {
  420. queryData, err := getDataBySql(sql, offset, pageSize_, returntype, s_params)
  421. if err != nil {
  422. appG.ResponseEq(http.StatusOK, e.ERROR, 1, err.Error())
  423. } else {
  424. appG.ResponseEq(http.StatusOK, e.SUCCESS, 0, queryData)
  425. }
  426. }
  427. } else {
  428. appG.ResponseEq(http.StatusOK, e.SUCCESS, 0, "后台没有数据接口")
  429. }
  430. }
  431. // @Summary 递归获取所有
  432. // @Tags menu
  433. // @Accept json
  434. // @Produce json
  435. // @Param Ton query string true "Ton"
  436. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  437. // @Router /authdata/GetRoleMenus [GET]
  438. func GetRecuDataByName(c *gin.Context) {
  439. appG := app.Gin{C: c}
  440. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  441. fsion := gofasion.NewFasion(string(dataByte))
  442. sqlnamestr := fsion.Get("name").ValueStr()
  443. parentidname := fsion.Get("idname").ValueStr()
  444. sql, p := restful.GetSqlByNameDB(sqlnamestr)
  445. params := make(map[string]interface{})
  446. s_params := make([]interface{}, 0)
  447. if fsion.HasKey("params") {
  448. for _, v_params := range fsion.Get("params").Array() {
  449. s_params = append(s_params, v_params.ValueStr())
  450. }
  451. params["params"] = s_params
  452. } else {
  453. jparams := fsion.Get("parammaps")
  454. paramslist := strings.Split(p, ",")
  455. if len(paramslist) > 0 && p != "" {
  456. for _, value := range paramslist {
  457. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  458. if tempv, exists := c.Get("jwt_username"); exists {
  459. params[value] = tempv.(string)
  460. } else {
  461. params[value] = ""
  462. }
  463. } else {
  464. params[value] = jparams.Get(strings.Trim(value, " ")).ValueStr()
  465. }
  466. }
  467. }
  468. }
  469. queryData, err := GetRecuData_BySql(sql, p, parentidname, params, fsion.HasKey("params"))
  470. logging.Info("sqlname parammaps", c.Keys, c.Request.RemoteAddr, sqlnamestr, params)
  471. if err != nil {
  472. appG.Response(http.StatusOK, e.ERROR, err.Error())
  473. }
  474. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  475. }
  476. // @Summary 根据APISQL表中SQL执行得到数据集
  477. // @Tags GetDataByNames
  478. // @Accept json
  479. // @Produce json
  480. // @RequestBody sqlname query string true "sqlname"
  481. // @Param offset query int true "offset"
  482. // @Param pagecount query int true "pagecount"
  483. // @Param returntype query string true "returntype"
  484. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  485. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  486. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  487. // @Router /data/GetDataByNames [POST]
  488. func GetDataByNames(c *gin.Context) {
  489. appG := app.Gin{C: c}
  490. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  491. fsion := gofasion.NewFasion(string(dataByte))
  492. sqlParams := fsion.Array()
  493. queryData := make(map[string]interface{})
  494. for _, v := range sqlParams {
  495. fsion2 := gofasion.NewFasion(v.Json())
  496. logging.Info("GetDataByNames", c.Keys, fsion2.Get("name").ValueStr(), c.Request.RemoteAddr)
  497. sql, p := restful.GetSqlByNameDB(fsion2.Get("name").ValueStr())
  498. if sql == "" {
  499. errorm := make(map[string]interface{})
  500. errorm["code"] = e.ERROR
  501. errorm["message"] = "sql没找到"
  502. queryData[fsion2.Get("name").ValueStr()] = errorm
  503. continue
  504. } else if sql != "" {
  505. offset := fsion2.Get("offset").ValueInt()
  506. pagecount := fsion2.Get("pagecount").ValueInt()
  507. returntype := fsion2.Get("returntype").ValueStr()
  508. s_params := make([]interface{}, 0)
  509. if fsion2.HasKey("parammaps") {
  510. parammaps := fsion2.Get("parammaps")
  511. paramslist := strings.Split(p, ",")
  512. if len(paramslist) > 0 && p != "" {
  513. for _, value := range paramslist {
  514. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  515. if tempv, exists := c.Get("jwt_username"); exists {
  516. s_params = append(s_params, tempv.(string))
  517. } else {
  518. s_params = append(s_params, "")
  519. }
  520. } else {
  521. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  522. }
  523. }
  524. }
  525. } else if fsion2.HasKey("params") {
  526. params := fsion2.Get("params").Array()
  527. for _, v_params := range params {
  528. s_params = append(s_params, v_params.ValueStr())
  529. }
  530. }
  531. queryData1, err := getDataBySql(sql, offset, pagecount, returntype, s_params)
  532. if err != nil {
  533. errorm := make(map[string]interface{})
  534. errorm["code"] = e.ERROR
  535. errorm["message"] = err.Error()
  536. queryData[fsion2.Get("name").ValueStr()] = errorm
  537. logging.Error("GetDataByNames err: ", err)
  538. continue
  539. } else {
  540. queryData[fsion2.Get("name").ValueStr()] = queryData1
  541. }
  542. }
  543. }
  544. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  545. }
  546. // @Summary 根据APISQL表中SQL执行得到数据集
  547. // @Tags PostDataByNameForm
  548. // @Accept json
  549. // @Produce json
  550. // @Param sqlname query string true "sqlname"
  551. // @Param offset query int true "offset"
  552. // @Param pagecount query int true "pagecount"
  553. // @Param returntype query string true "returntype"
  554. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  555. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误朱红彬彬"}"
  556. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  557. // @Router /data/PostDataByNameForm [POST]
  558. func PostDataByNameForm(c *gin.Context) {
  559. appG := app.Gin{C: c}
  560. c.Request.ParseForm()
  561. params := c.Request.Form
  562. sqlnamestr := params.Get("name")
  563. logging.Info("PostDataByNameForm ", c.Keys, sqlnamestr)
  564. s_params := make([]interface{}, 0)
  565. sql, p := restful.GetSqlByNameDB(sqlnamestr)
  566. paramslist := strings.Split(p, ",")
  567. if len(paramslist) > 0 {
  568. for _, value := range paramslist {
  569. s_params = append(s_params, params.Get(strings.Trim(value, " ")))
  570. }
  571. }
  572. if sql != "" {
  573. queryData, err := execDataBySql(sql, s_params)
  574. if err != nil {
  575. appG.ResponseEq(http.StatusOK, e.ERROR, 1, err.Error())
  576. } else {
  577. appG.ResponseEq(http.StatusOK, e.SUCCESS, 0, queryData)
  578. }
  579. } else {
  580. appG.ResponseEq(http.StatusOK, e.SUCCESS, 0, "后台没有数据接口")
  581. }
  582. }
  583. // @Summary 将数据集转换格式
  584. // @Tags PostDataByNameForm
  585. // @Accept json
  586. // @Produce json
  587. // @Param sqlname query string true "sqlname"
  588. // @Param offset query int true "offset"
  589. // @Param pagecount query int true "pagecount"
  590. // @Param returntype query string true "returntype"
  591. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  592. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误朱红彬彬"}"
  593. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  594. func GetReportform(c *gin.Context) {
  595. appG := app.Gin{C: c}
  596. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  597. fsion := gofasion.NewFasion(string(dataByte))
  598. sqlnamestr := fsion.Get("name").ValueStr()
  599. parammaps := fsion.Get("parammaps")
  600. logging.Info("GetReportform ", c.Keys, sqlnamestr, parammaps)
  601. tx := restful.Engine.NewSession()
  602. err := tx.Begin()
  603. defer func() {
  604. switch {
  605. case err != nil:
  606. if tx != nil {
  607. tx.Rollback()
  608. }
  609. default:
  610. if tx != nil {
  611. err = tx.Commit()
  612. }
  613. }
  614. if tx != nil {
  615. tx.Close()
  616. }
  617. }()
  618. queryData, err := praseReportform(sqlnamestr, parammaps, tx)
  619. if err != nil {
  620. appG.Response(http.StatusOK, e.ERROR, err.Error())
  621. } else {
  622. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  623. }
  624. }
  625. //保养计划
  626. func GetUpkeepPlan(c *gin.Context) {
  627. appG := app.Gin{C: c}
  628. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  629. fsion := gofasion.NewFasion(string(dataByte))
  630. sqlnamestr := fsion.Get("name").ValueStr()
  631. offset := fsion.Get("offset").ValueDefaultInt(0)
  632. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  633. returntype := fsion.Get("returntype").ValueDefaultStr("map")
  634. month := fsion.Get("month").ValueDefaultStr("map")
  635. logging.Info("GetUpkeepPlan ", c.Keys, sqlnamestr, month)
  636. tx := restful.Engine.NewSession()
  637. err := tx.Begin()
  638. defer func() {
  639. switch {
  640. case err != nil:
  641. if tx != nil {
  642. tx.Rollback()
  643. }
  644. default:
  645. if tx != nil {
  646. err = tx.Commit()
  647. }
  648. }
  649. if tx != nil {
  650. tx.Close()
  651. }
  652. }()
  653. sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
  654. if sql != "" {
  655. s_params := make([]interface{}, 0)
  656. if fsion.HasKey("parammaps") {
  657. parammaps := fsion.Get("parammaps")
  658. paramslist := strings.Split(p, ",")
  659. if len(paramslist) > 0 && p != "" {
  660. for _, value := range paramslist {
  661. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  662. if tempv, exists := c.Get("jwt_username"); exists {
  663. s_params = append(s_params, tempv.(string))
  664. } else {
  665. s_params = append(s_params, "")
  666. }
  667. } else {
  668. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  669. }
  670. }
  671. }
  672. } else if fsion.HasKey("params") {
  673. params := fsion.Get("params").Array()
  674. for _, v_params := range params {
  675. s_params = append(s_params, v_params.ValueStr())
  676. }
  677. }
  678. if returntype == "xlsx" {
  679. var xlsxfile *xlsx.File
  680. xlsxfile, _ = restful.QueryByXlsx(sql, s_params)
  681. //c.File("c:/dd.xlsx")
  682. c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  683. c.Header("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
  684. c.Header("Content-Transfer-Encoding", "binary")
  685. _ = xlsxfile.Write(c.Writer)
  686. } else {
  687. queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params, tx)
  688. if err != nil {
  689. appG.Response(http.StatusOK, e.ERROR, err.Error())
  690. } else {
  691. for index, value := range queryData.(map[string]interface{})["list"].([]map[string]interface{}) {
  692. if v, ok := value["id"]; ok {
  693. //month = "2020-03"
  694. seviceplans, _ := tx.SQL("SELECT * FROM seviceplan where eqId = ? and month=? ", v, month).QueryString() //获取保养计划
  695. if seviceplans != nil {
  696. for _, va := range seviceplans { //根据保养计划获取保养单
  697. //day,_ :=strconv.Atoi(va["day"])
  698. bigupkeeps, _ := tx.SQL("SELECT * FROM bigupkeep where seviceplanId = ?", va["id"]).QueryString() //获取保养计划中的保养单
  699. //buk := make(map[string]map[string]string)
  700. for _, bu := range bigupkeeps { //日期为key ,保养单为value 存到map中
  701. jstr := ""
  702. if bu["plantime"][8:9] == "0" {
  703. jstr = "m" + bu["plantime"][9:]
  704. } else {
  705. jstr = "m" + bu["plantime"][8:]
  706. }
  707. if bu["flowCompeleted"] < "2" && bu["plantime"] < time.Now().Format("2006-01-02") { //如果保养状态是0并且小于当前日期 则状态已延期2
  708. queryData.(map[string]interface{})["list"].([]map[string]interface{})[index][jstr] = va["upkeepName"] + "#" + va["id"] + "#2" + "#" + bu["id"] + "#" + bu["pushbackId"]
  709. } else {
  710. if bu["flowCompeleted"] >= "2" {
  711. queryData.(map[string]interface{})["list"].([]map[string]interface{})[index][jstr] = va["upkeepName"] + "#" + va["id"] + "#1" + "#" + bu["id"] + "#" + bu["pushbackId"]
  712. } else {
  713. queryData.(map[string]interface{})["list"].([]map[string]interface{})[index][jstr] = va["upkeepName"] + "#" + va["id"] + "#0" + "#" + bu["id"] + "#" + bu["pushbackId"]
  714. }
  715. }
  716. }
  717. }
  718. }
  719. }
  720. }
  721. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  722. }
  723. }
  724. } else {
  725. appG.Response(http.StatusOK, e.SUCCESS, nil)
  726. }
  727. }
  728. // @Summary 根据APISQL表中的两条SQL执行得到数据集,其中name1会根据name的每一条去执行
  729. // todo 优化性能 统一查询
  730. // @Tags PostDataByNameForm
  731. // @Accept json
  732. // @Produce json
  733. // @Param sqlname query string true "sqlname"
  734. // @Param offset query int true "offset"
  735. // @Param pagecount query int true "pagecount"
  736. // @Param returntype query string true "returntype"
  737. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  738. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误朱红彬彬"}"
  739. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  740. func GetArrList(c *gin.Context) {
  741. appG := app.Gin{C: c}
  742. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  743. fsion := gofasion.NewFasion(string(dataByte))
  744. sqlnamestr := fsion.Get("name").ValueStr()
  745. sqlnamestr1 := fsion.Get("name1").ValueStr()
  746. offset := fsion.Get("offset").ValueDefaultInt(0)
  747. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  748. returntype := fsion.Get("returntype").ValueDefaultStr("map")
  749. month := fsion.Get("month").ValueDefaultStr("map")
  750. logging.Info("GetUpkeepPlan ", c.Keys, sqlnamestr, month)
  751. tx := restful.Engine.NewSession()
  752. err := tx.Begin()
  753. defer func() {
  754. switch {
  755. case err != nil:
  756. if tx != nil {
  757. tx.Rollback()
  758. }
  759. default:
  760. if tx != nil {
  761. err = tx.Commit()
  762. }
  763. }
  764. if tx != nil {
  765. tx.Close()
  766. }
  767. }()
  768. sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
  769. sql1, p1 := restful.GetSqlByNameDBT(sqlnamestr1, tx)
  770. if sql != "" {
  771. s_params := make([]interface{}, 0)
  772. if fsion.HasKey("parammaps") {
  773. parammaps := fsion.Get("parammaps")
  774. paramslist := strings.Split(p, ",")
  775. if len(paramslist) > 0 && p != "" {
  776. for _, value := range paramslist {
  777. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  778. if tempv, exists := c.Get("jwt_username"); exists {
  779. s_params = append(s_params, tempv.(string))
  780. } else {
  781. s_params = append(s_params, "")
  782. }
  783. } else {
  784. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  785. }
  786. }
  787. }
  788. }
  789. queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params, tx)
  790. if err != nil {
  791. appG.Response(http.StatusOK, e.ERROR, err.Error())
  792. } else {
  793. paramslist1 := strings.Split(p1, ",")
  794. for index, value := range queryData.(map[string]interface{})["list"].([]map[string]interface{}) {
  795. s_params1 := make([]interface{}, 0)
  796. if len(paramslist1) > 0 && p1 != "" {
  797. for _, v := range paramslist1 {
  798. s_params1 = append(s_params1, value[strings.ToLower(strings.Trim(v, " "))])
  799. }
  800. }
  801. arr, _ := tx.SQL(sql1, s_params1...).QueryString() //获取
  802. queryData.(map[string]interface{})["list"].([]map[string]interface{})[index]["arrList"] = arr
  803. }
  804. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  805. }
  806. } else {
  807. appG.Response(http.StatusOK, e.SUCCESS, nil)
  808. }
  809. }
  810. func GetAccount(c *gin.Context) {
  811. appG := app.Gin{C: c}
  812. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  813. fsion := gofasion.NewFasion(string(dataByte))
  814. sqlnamestr := fsion.Get("name").ValueStr()
  815. offset := fsion.Get("offset").ValueDefaultInt(0)
  816. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  817. returntype := fsion.Get("returntype").ValueDefaultStr("map")
  818. tx := restful.Engine.NewSession()
  819. err := tx.Begin()
  820. defer func() {
  821. switch {
  822. case err != nil:
  823. logging.Error("tx.Begin 事务启动失败__error:", err)
  824. if tx != nil {
  825. tx.Rollback()
  826. }
  827. default:
  828. if tx != nil {
  829. err = tx.Commit()
  830. }
  831. }
  832. if tx != nil {
  833. tx.Close()
  834. }
  835. }()
  836. sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
  837. if sql != "" {
  838. s_params := make([]interface{}, 0)
  839. if fsion.HasKey("parammaps") {
  840. parammaps := fsion.Get("parammaps")
  841. if sqlnamestr != "getNoMesList" && sqlnamestr != "getNoMesCount" {
  842. logging.Info("GetDataByName", c.Keys, c.Request.RemoteAddr, sqlnamestr, parammaps.ValueStr())
  843. }
  844. paramslist := strings.Split(p, ",")
  845. if len(paramslist) > 0 && p != "" {
  846. for _, value := range paramslist {
  847. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  848. if tempv, exists := c.Get("jwt_username"); exists {
  849. s_params = append(s_params, tempv.(string))
  850. } else {
  851. s_params = append(s_params, "")
  852. }
  853. } else {
  854. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  855. }
  856. }
  857. }
  858. } else if fsion.HasKey("params") {
  859. params := fsion.Get("params").Array()
  860. logging.Info("GetDataByName", c.Keys, c.Request.RemoteAddr, sqlnamestr, params)
  861. for _, v_params := range params {
  862. s_params = append(s_params, v_params.ValueStr())
  863. }
  864. }
  865. if returntype == "xlsx" {
  866. var xlsxfile *xlsx.File
  867. xlsxfile, _ = restful.QueryByXlsx(sql, s_params)
  868. //c.File("c:/dd.xlsx")
  869. c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  870. c.Header("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
  871. c.Header("Content-Transfer-Encoding", "binary")
  872. _ = xlsxfile.Write(c.Writer)
  873. } else {
  874. queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params, tx)
  875. if err != nil {
  876. logging.Error("GetDataByName err: ", err)
  877. msg := geterrmsg(err.Error())
  878. appG.Response(http.StatusOK, e.ERROR, msg)
  879. //appG.Response(http.StatusOK, e.ERROR, err.Error())
  880. } else {
  881. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  882. }
  883. }
  884. } else {
  885. appG.Response(http.StatusOK, e.SUCCESS, nil)
  886. }
  887. }
  888. // @Summary 根据APISQL表中SQL执行得到数据集
  889. // @Tags PostDataByName
  890. // @Accept json
  891. // @Produce json
  892. // @Param sqlname query string true "sqlname"
  893. // @Param offset query int true "offset"
  894. // @Param pagecount query int true "pagecount"
  895. // @Param returntype query string true "returntype"
  896. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  897. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  898. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  899. // @Router /data/PostDataByName [POST]
  900. func PostDataByName(c *gin.Context) {
  901. appG := app.Gin{C: c}
  902. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  903. fsion := gofasion.NewFasion(string(dataByte))
  904. sqlnamestr := fsion.Get("name").ValueStr()
  905. s_params := make([]interface{}, 0)
  906. tx := restful.Engine.NewSession()
  907. err := tx.Begin()
  908. defer func() {
  909. switch {
  910. case err != nil:
  911. if tx != nil {
  912. tx.Rollback()
  913. }
  914. default:
  915. if tx != nil {
  916. err = tx.Commit()
  917. }
  918. }
  919. if tx != nil {
  920. tx.Close()
  921. }
  922. }()
  923. sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
  924. if sql != "" {
  925. if fsion.HasKey("parammaps") {
  926. parammaps := fsion.Get("parammaps")
  927. logging.Info("PostDataByName ", c.Keys, c.Request.RemoteAddr, sqlnamestr, parammaps.ValueStr())
  928. paramslist := strings.Split(p, ",")
  929. if len(paramslist) > 0 && p != "" {
  930. for _, value := range paramslist {
  931. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  932. if tempv, exists := c.Get("jwt_username"); exists {
  933. s_params = append(s_params, tempv.(string))
  934. } else {
  935. s_params = append(s_params, "")
  936. }
  937. } else if strings.ToLower(strings.Trim(value, " ")) == "snowid" {
  938. ids, err := setting.SnowIds.NextId()
  939. if err != nil {
  940. ids = time.Now().UnixNano()
  941. logging.Info("create SnowIds err", err)
  942. }
  943. s_params = append(s_params, ids)
  944. } else {
  945. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  946. }
  947. }
  948. }
  949. } else if fsion.HasKey("params") {
  950. params := fsion.Get("params").Array()
  951. logging.Info("PostDataByName ", c.Keys, c.Request.RemoteAddr, sqlnamestr, params)
  952. //ids,err := setting.SnowIds.NextId()
  953. //if err !=nil{
  954. // ids = time.Now().UnixNano()
  955. // logging.Info("create SnowIds err",err)
  956. //}
  957. //s_params = append(s_params, ids)
  958. for _, v_params := range params {
  959. s_params = append(s_params, v_params.ValueStr())
  960. }
  961. }
  962. queryData, err := execDataBySqlT(sql, s_params, tx)
  963. if err != nil {
  964. logging.Error("PostDataByName err: ", err)
  965. //appG.Response(http.StatusOK, e.ERROR, err.Error())
  966. msg := geterrmsg(err.Error())
  967. appG.Response(http.StatusOK, e.ERROR, msg)
  968. } else {
  969. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  970. }
  971. } else {
  972. appG.Response(http.StatusOK, e.SUCCESS, nil)
  973. }
  974. }
  975. //人脸识别/格润富德接口
  976. func GetRJSBData(c *gin.Context) {
  977. appG := app.Gin{C: c}
  978. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  979. fsion := gofasion.NewFasion(string(dataByte))
  980. sqlnamestr := fsion.Get("name").ValueStr()
  981. sqlnamestr1 := fsion.Get("name1").ValueStr()
  982. offset := fsion.Get("offset").ValueDefaultInt(0)
  983. pagecount := fsion.Get("plancount").ValueDefaultInt(0)
  984. returntype := fsion.Get("returntype").ValueDefaultStr("map")
  985. month := fsion.Get("month").ValueDefaultStr("map")
  986. logging.Info("GetUpkeepPlan ", c.Keys, sqlnamestr, month)
  987. tx := restful.Engine.NewSession()
  988. err := tx.Begin()
  989. defer func() {
  990. switch {
  991. case err != nil:
  992. if tx != nil {
  993. tx.Rollback()
  994. }
  995. default:
  996. if tx != nil {
  997. err = tx.Commit()
  998. }
  999. }
  1000. if tx != nil {
  1001. tx.Close()
  1002. }
  1003. }()
  1004. //STR :=Httppostdata("http://192.168.1.104:8081/authdata/GetDataBySqlIN","POST",string(dataByte),tx)
  1005. sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
  1006. sql1, p1 := restful.GetSqlByNameDBT(sqlnamestr1, tx)
  1007. if sql != "" {
  1008. s_params := make([]interface{}, 0)
  1009. if fsion.HasKey("parammaps") {
  1010. parammaps := fsion.Get("parammaps")
  1011. paramslist := strings.Split(p, ",")
  1012. if len(paramslist) > 0 && p != "" {
  1013. for _, value := range paramslist {
  1014. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  1015. if tempv, exists := c.Get("jwt_username"); exists {
  1016. s_params = append(s_params, tempv.(string))
  1017. } else {
  1018. s_params = append(s_params, "")
  1019. }
  1020. } else {
  1021. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  1022. }
  1023. }
  1024. }
  1025. }
  1026. queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params, tx)
  1027. if err != nil {
  1028. appG.Response(http.StatusOK, e.ERROR, err.Error())
  1029. } else {
  1030. paramslist1 := strings.Split(p1, ",")
  1031. for index, value := range queryData.(map[string]interface{})["list"].([]map[string]interface{}) {
  1032. s_params1 := make([]interface{}, 0)
  1033. if len(paramslist1) > 0 && p1 != "" {
  1034. for _, v := range paramslist1 {
  1035. s_params1 = append(s_params1, value[strings.ToLower(strings.Trim(v, " "))])
  1036. }
  1037. }
  1038. arr, _ := tx.SQL(sql1, s_params1...).QueryString() //获取
  1039. queryData.(map[string]interface{})["list"].([]map[string]interface{})[index]["arrList"] = arr
  1040. }
  1041. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  1042. }
  1043. } else {
  1044. appG.Response(http.StatusOK, e.SUCCESS, nil)
  1045. }
  1046. }
  1047. func PostRJSBData(c *gin.Context) {
  1048. appG := app.Gin{C: c}
  1049. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  1050. fsion := gofasion.NewFasion(string(dataByte))
  1051. logging.Info("PostRJSBData err: ", string(dataByte))
  1052. s_params := make([]interface{}, 0)
  1053. tx := restful.Engine.NewSession()
  1054. err := tx.Begin()
  1055. defer func() {
  1056. switch {
  1057. case err != nil:
  1058. if tx != nil {
  1059. tx.Rollback()
  1060. }
  1061. default:
  1062. if tx != nil {
  1063. err = tx.Commit()
  1064. }
  1065. }
  1066. if tx != nil {
  1067. tx.Close()
  1068. }
  1069. }()
  1070. sql, p := restful.GetSqlByNameDBT("updatedownloadedplanYJ", tx)
  1071. sql1, p1 := restful.GetSqlByNameDBT("updated1YJ", tx)
  1072. sql2, p2 := restful.GetSqlByNameDBT("updated1execYJ", tx)
  1073. sql3, p3 := restful.GetSqlByNameDBT("updated2YJ", tx)
  1074. if !fsion.HasKey("parammaps") {
  1075. appG.Response(http.StatusOK, e.ERROR, "参数解析失败")
  1076. return
  1077. }
  1078. parammaps := fsion.Get("parammaps")
  1079. paramslist := strings.Split(p, ",")
  1080. if len(paramslist) > 0 && p != "" {
  1081. for _, value := range paramslist {
  1082. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  1083. }
  1084. }
  1085. _, err = tx.SQL(sql, s_params...).Execute()
  1086. if err != nil {
  1087. logging.Error("PostRJSBData err: ", err)
  1088. msg := geterrmsg(err.Error())
  1089. appG.Response(http.StatusOK, e.ERROR, msg)
  1090. return
  1091. }
  1092. s_params = make([]interface{}, 0)
  1093. paramslist = strings.Split(p1, ",")
  1094. if len(paramslist) > 0 && p1 != "" {
  1095. for _, value := range paramslist {
  1096. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  1097. }
  1098. }
  1099. _, err = tx.SQL(sql1, s_params...).Execute()
  1100. if err != nil {
  1101. logging.Error("PostRJSBData1 err: ", err)
  1102. msg := geterrmsg(err.Error())
  1103. appG.Response(http.StatusOK, e.ERROR, msg)
  1104. return
  1105. }
  1106. s_params = make([]interface{}, 0)
  1107. paramslist = strings.Split(p2, ",")
  1108. if len(paramslist) > 0 && p2 != "" {
  1109. for _, value := range paramslist {
  1110. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  1111. }
  1112. }
  1113. _, err = tx.SQL(sql2, s_params...).Execute()
  1114. if err != nil {
  1115. logging.Error("PostRJSBData2 err: ", err)
  1116. msg := geterrmsg(err.Error())
  1117. appG.Response(http.StatusOK, e.ERROR, msg)
  1118. return
  1119. }
  1120. s_params = make([]interface{}, 0)
  1121. paramslist = strings.Split(p3, ",")
  1122. if len(paramslist) > 0 && p3 != "" {
  1123. for _, value := range paramslist {
  1124. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  1125. }
  1126. }
  1127. _, err = tx.SQL(sql3, s_params...).Execute()
  1128. if err != nil {
  1129. logging.Error("PostRJSBData3 err: ", err)
  1130. msg := geterrmsg(err.Error())
  1131. appG.Response(http.StatusOK, e.ERROR, msg)
  1132. return
  1133. }
  1134. appG.Response(http.StatusOK, e.SUCCESS, "ok")
  1135. }
  1136. func PostRJSBDatas(c *gin.Context) {
  1137. appG := app.Gin{C: c}
  1138. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  1139. fsions := gofasion.NewFasion(string(dataByte)).Array()
  1140. logging.Info("PostRJSBDatas err: ", string(dataByte))
  1141. tx := restful.Engine.NewSession()
  1142. err := tx.Begin()
  1143. defer func() {
  1144. switch {
  1145. case err != nil:
  1146. if tx != nil {
  1147. tx.Rollback()
  1148. }
  1149. default:
  1150. if tx != nil {
  1151. err = tx.Commit()
  1152. }
  1153. }
  1154. if tx != nil {
  1155. tx.Close()
  1156. }
  1157. }()
  1158. sql, p := restful.GetSqlByNameDBT("updatedownloadedplanYJ", tx)
  1159. sql1, p1 := restful.GetSqlByNameDBT("updated1YJV2", tx)
  1160. sql2, p2 := restful.GetSqlByNameDBT("updated1execYJV2", tx)
  1161. sql3, p3 := restful.GetSqlByNameDBT("updated2YJV2", tx)
  1162. for _, fsion := range fsions {
  1163. if !fsion.HasKey("parammaps") {
  1164. appG.Response(http.StatusOK, e.ERROR, "参数解析失败")
  1165. return
  1166. }
  1167. parammaps := fsion.Get("parammaps")
  1168. s_params := make([]interface{}, 0)
  1169. paramslist := strings.Split(p, ",")
  1170. if len(paramslist) > 0 && p != "" {
  1171. for _, value := range paramslist {
  1172. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  1173. }
  1174. }
  1175. _, err = tx.SQL(sql, s_params...).Execute()
  1176. if err != nil {
  1177. logging.Error("PostRJSBData err: ", err)
  1178. msg := geterrmsg(err.Error())
  1179. appG.Response(http.StatusOK, e.ERROR, msg)
  1180. return
  1181. }
  1182. s_params = make([]interface{}, 0)
  1183. paramslist = strings.Split(p1, ",")
  1184. if len(paramslist) > 0 && p1 != "" {
  1185. for _, value := range paramslist {
  1186. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  1187. }
  1188. }
  1189. _, err = tx.SQL(sql1, s_params...).Execute()
  1190. if err != nil {
  1191. logging.Error("PostRJSBData1 err: ", err)
  1192. msg := geterrmsg(err.Error())
  1193. appG.Response(http.StatusOK, e.ERROR, msg)
  1194. return
  1195. }
  1196. s_params = make([]interface{}, 0)
  1197. paramslist = strings.Split(p2, ",")
  1198. if len(paramslist) > 0 && p2 != "" {
  1199. for _, value := range paramslist {
  1200. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  1201. }
  1202. }
  1203. _, err = tx.SQL(sql2, s_params...).Execute()
  1204. if err != nil {
  1205. logging.Error("PostRJSBData2 err: ", err)
  1206. msg := geterrmsg(err.Error())
  1207. appG.Response(http.StatusOK, e.ERROR, msg)
  1208. return
  1209. }
  1210. s_params = make([]interface{}, 0)
  1211. paramslist = strings.Split(p3, ",")
  1212. if len(paramslist) > 0 && p3 != "" {
  1213. for _, value := range paramslist {
  1214. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  1215. }
  1216. }
  1217. _, err = tx.SQL(sql3, s_params...).Execute()
  1218. if err != nil {
  1219. logging.Error("PostRJSBData3 err: ", err)
  1220. msg := geterrmsg(err.Error())
  1221. appG.Response(http.StatusOK, e.ERROR, msg)
  1222. return
  1223. }
  1224. }
  1225. appG.Response(http.StatusOK, e.SUCCESS, "ok")
  1226. }
  1227. // @Summary 根据APISQL表中SQL执行得到数据集
  1228. // @Tags ExecDataByConfig
  1229. // @Accept json
  1230. // @Produce json
  1231. // @Param sqlname query string true "sqlname"
  1232. // @Param offset query int true "offset"
  1233. // @Param pagecount query int true "pagecount"
  1234. // @Param returntype query string true "returntype"
  1235. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  1236. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  1237. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  1238. // @Router /data/PostDataByName [POST]
  1239. func ExecDataByConfig(c *gin.Context) {
  1240. appG := app.Gin{C: c}
  1241. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  1242. tempval_ := make(map[string]interface{})
  1243. tempCommon := make(map[string]interface{})
  1244. tempval := make([]map[string]interface{}, 0)
  1245. err := json.Unmarshal(dataByte, &tempval_)
  1246. logging.Info("ExecDataByConfig ", c.Keys, c.Request.RemoteAddr, tempval_["common"], tempval_["data"])
  1247. if err != nil {
  1248. } else {
  1249. if v, ok := tempval_["common"].(map[string]interface{}); ok {
  1250. tempCommon = v
  1251. }
  1252. if v, ok := tempval_["data"].([]interface{}); ok {
  1253. for _, Tvalue := range v {
  1254. if v1, ok := Tvalue.(map[string]interface{}); ok {
  1255. tempval = append(tempval, v1)
  1256. }
  1257. }
  1258. }
  1259. tx := restful.Engine.NewSession()
  1260. err := tx.Begin()
  1261. if err != nil {
  1262. logging.Error("tx.Begin 事务启动失败__error:", err)
  1263. }
  1264. defer func() {
  1265. switch {
  1266. case err != nil:
  1267. if tx != nil {
  1268. tx.Rollback()
  1269. }
  1270. default:
  1271. if tx != nil {
  1272. err = tx.Commit()
  1273. }
  1274. }
  1275. if tx != nil {
  1276. tx.Close()
  1277. }
  1278. }()
  1279. if err == nil {
  1280. if tempv, exists := c.Get("jwt_username"); exists {
  1281. tempCommon["jwt_username"] = tempv.(string)
  1282. }
  1283. for _, paramvalue := range tempval {
  1284. if _, ok := paramvalue["resultname"]; !ok {
  1285. paramvalue["resultname"] = paramvalue["name"]
  1286. }
  1287. _, err = ExecDataParam(paramvalue, tempCommon, tempval, nil, nil, tx)
  1288. if err != nil {
  1289. logging.Error("ExecDataParam error:", err)
  1290. break
  1291. }
  1292. }
  1293. if err == nil {
  1294. if tempCommon["returnmap"] != nil && tempCommon["returnmap"] != "" {
  1295. appG.Response(http.StatusOK, e.SUCCESS, tempval)
  1296. } else {
  1297. appG.Response(http.StatusOK, e.SUCCESS, "成功执行!")
  1298. }
  1299. } else {
  1300. msg := geterrmsg(err.Error())
  1301. appG.Response(http.StatusOK, e.ERROR, msg)
  1302. //appG.Response(http.StatusOK, e.ERROR, err.Error())
  1303. }
  1304. }
  1305. }
  1306. if err != nil {
  1307. msg := geterrmsg(err.Error())
  1308. appG.Response(http.StatusOK, e.ERROR, msg)
  1309. //appG.Response(http.StatusOK, e.ERROR, err.Error())
  1310. }
  1311. }
  1312. func interfacetostring(val interface{}) string {
  1313. switch val.(type) {
  1314. case string:
  1315. ss := val.(string)
  1316. return ss
  1317. break
  1318. case int:
  1319. ss := val.(int)
  1320. return strconv.Itoa(ss)
  1321. break
  1322. case int64:
  1323. ss := val.(int64)
  1324. return strconv.FormatInt(ss, 10)
  1325. break
  1326. case float64:
  1327. ss := val.(float64)
  1328. return strconv.FormatFloat(ss, 'E', -1, 32)
  1329. break
  1330. }
  1331. return ""
  1332. }
  1333. func getParamValue(parammaps map[string]interface{}, value string, ParamMap []map[string]interface{}) string {
  1334. if valuestring, ok := parammaps[strings.Trim(value, " ")].(string); ok {
  1335. tempstrb := strings.IndexAny(valuestring, "@")
  1336. tempstre := strings.IndexAny(valuestring, ".")
  1337. if tempstrb > -1 && tempstre > -1 {
  1338. for _, ParamMapList := range ParamMap {
  1339. if v, ok := ParamMapList["resultname"]; ok {
  1340. if v == valuestring[tempstrb+1:tempstre] {
  1341. if v1, ok := ParamMapList["resultmaps"]; ok {
  1342. if newA, ok := v1.([]map[string]interface{}); ok {
  1343. return interfacetostring(newA[0][valuestring[tempstre+1:]])
  1344. } else if newA, ok := v1.(map[string]interface{}); ok {
  1345. return interfacetostring(newA[valuestring[tempstre+1:]])
  1346. }
  1347. }
  1348. }
  1349. }
  1350. }
  1351. } else {
  1352. return valuestring
  1353. }
  1354. } else if valuestring, ok := parammaps[strings.Trim(value, " ")].(float64); ok {
  1355. return strconv.FormatInt(int64(valuestring), 10)
  1356. }
  1357. return ""
  1358. }
  1359. func getParamValue_(parammaps map[string]interface{}, value string, ParamMap map[string]interface{}) string {
  1360. if valuestring, ok := parammaps[strings.Trim(value, " ")].(string); ok {
  1361. tempstrb := strings.IndexAny(valuestring, "@")
  1362. tempstre := strings.IndexAny(valuestring, ".")
  1363. if tempstrb > -1 && tempstre > -1 {
  1364. if v, ok := ParamMap[valuestring[tempstre+1:]]; ok {
  1365. if s, ok := v.(string); ok {
  1366. return s
  1367. } else if s, ok := v.(float64); ok {
  1368. return strconv.FormatInt(int64(s), 10)
  1369. }
  1370. }
  1371. }
  1372. }
  1373. return ""
  1374. }
  1375. func ExecDataParam(fasion map[string]interface{}, CommonParamMap map[string]interface{}, ParamMap []map[string]interface{}, ParentParamMap map[string]interface{}, sameParamMap []map[string]interface{}, tx *xorm.Session) ([]map[string]interface{}, error) {
  1376. sqlname := fasion["name"].(string)
  1377. sqltype := "" //v 校验/s1 查询/sm 查询/e 执行
  1378. if v, ok := fasion["type"]; ok {
  1379. sqltype = v.(string)
  1380. }
  1381. sql := ""
  1382. p := ""
  1383. s_params := make([]interface{}, 0)
  1384. if sqltype != "" {
  1385. sql, p = restful.GetSqlByName(sqlname, tx)
  1386. //sqlApi, _ := models.GetApisqlByName(sqlname)
  1387. if v, ok := fasion["parammaps"].(map[string]interface{}); ok {
  1388. paramslist := strings.Split(p, ",")
  1389. if len(paramslist) > 0 && p != "" {
  1390. for _, value := range paramslist {
  1391. ss := ""
  1392. if strings.ToLower(strings.Trim(value, " ")) == "snowid" {
  1393. ids, err := setting.SnowIds.NextId()
  1394. if err != nil {
  1395. ids = time.Now().UnixNano()
  1396. logging.Info("create SnowIds err", err)
  1397. }
  1398. s_params = append(s_params, ids)
  1399. } else {
  1400. if ss == "" && CommonParamMap != nil {
  1401. if valuestring, ok := v[strings.Trim(value, " ")].(string); ok {
  1402. ss = valuestring
  1403. tempstrb := strings.IndexAny(valuestring, "@")
  1404. tempstre := strings.IndexAny(valuestring, ".")
  1405. if (tempstre > tempstrb) && (strings.ToLower(valuestring[tempstrb+1:tempstre]) == "common") {
  1406. if CommonParamMap[valuestring[tempstre+1:]] != nil {
  1407. ss = CommonParamMap[valuestring[tempstre+1:]].(string)
  1408. }
  1409. } else {
  1410. ss = ""
  1411. }
  1412. }
  1413. }
  1414. if ss == "" && ParentParamMap != nil {
  1415. ss = getParamValue_(v, value, ParentParamMap)
  1416. }
  1417. if ss == "" && sameParamMap != nil {
  1418. ss = getParamValue(v, value, sameParamMap)
  1419. }
  1420. if ss == "" && ParamMap != nil {
  1421. ss = getParamValue(v, value, ParamMap)
  1422. }
  1423. s_params = append(s_params, ss)
  1424. }
  1425. }
  1426. }
  1427. }
  1428. }
  1429. if sql == "" {
  1430. sqltype = ""
  1431. }
  1432. if sqltype == "s1" {
  1433. tempValParam, err := restful.QueryByMap(sql, 0, 1, s_params)
  1434. if v, ok := tempValParam.(map[string]interface{}); ok {
  1435. fasion["resultmaps"] = v["list"].([]map[string]interface{})
  1436. }
  1437. if err != nil {
  1438. return nil, err
  1439. }
  1440. err = ExitsChildrenParam(fasion, tempValParam, ParamMap, CommonParamMap, tx)
  1441. if err != nil {
  1442. return nil, err
  1443. }
  1444. return tempValParam.(map[string]interface{})["list"].([]map[string]interface{}), err
  1445. } else if sqltype == "sm" {
  1446. tempValParam, err := restful.QueryByMap(sql, 0, 0, s_params)
  1447. if v, ok := tempValParam.(map[string]interface{}); ok {
  1448. fasion["resultmaps"] = v["list"].([]map[string]interface{})
  1449. } else {
  1450. }
  1451. if err != nil {
  1452. return nil, err
  1453. }
  1454. err = ExitsChildrenParam(fasion, tempValParam, ParamMap, CommonParamMap, tx)
  1455. if err != nil {
  1456. return nil, err
  1457. }
  1458. return tempValParam.(map[string]interface{})["list"].([]map[string]interface{}), err
  1459. } else if sqltype == "v" {
  1460. tempValParam, err := restful.QueryByMap(sql, 0, 1, s_params)
  1461. if v, ok := tempValParam.(map[string]interface{}); ok {
  1462. fasion["resultmaps"] = v["list"].([]map[string]interface{})
  1463. } else {
  1464. }
  1465. if err != nil {
  1466. return nil, err
  1467. }
  1468. if tempValParam.(map[string]interface{})["list"].([]map[string]interface{})[0]["vmsg"] != "" {
  1469. return nil, errors.New(tempValParam.(map[string]interface{})["list"].([]map[string]interface{})[0]["vmsg"].(string))
  1470. }
  1471. } else if sqltype == "e" {
  1472. tempVal_arrary := make([]map[string]interface{}, 0)
  1473. tempVal_map := make(map[string]interface{})
  1474. tempValParam, err := restful.ExecQueryT(sql, s_params, tx)
  1475. if err == nil {
  1476. fasion["resultmaps"] = tempValParam.(map[string]interface{})
  1477. tempVal_map["result"] = tempValParam.(map[string]interface{})["result"]
  1478. tempVal_map["LastInsertId"] = tempValParam.(map[string]interface{})["LastInsertId"]
  1479. tempVal_arrary = append(tempVal_arrary, tempVal_map)
  1480. return tempVal_arrary, err
  1481. }
  1482. return nil, err
  1483. } else {
  1484. if tempValParam, ok := fasion["resultmaps"].(map[string]interface{}); ok {
  1485. err := ExitsChildrenParam(fasion, tempValParam, ParamMap, CommonParamMap, tx)
  1486. if err != nil {
  1487. return nil, err
  1488. }
  1489. return nil, err
  1490. }
  1491. }
  1492. return nil, nil
  1493. }
  1494. func ExitsChildrenParam(fasion map[string]interface{}, tempValParam interface{}, ParamMap []map[string]interface{}, commonParam map[string]interface{}, tx *xorm.Session) error {
  1495. var err error
  1496. subarray, ok := fasion["children"]
  1497. if ok {
  1498. for _, v := range tempValParam.(map[string]interface{})["list"].([]interface{}) { //遍历父集有多少行数据
  1499. tempVal_arrary := make([]map[string]interface{}, 0)
  1500. for _, subarrayvalue := range subarray.([]interface{}) { //遍历所有执行命令
  1501. tempVal_ := make(map[string]interface{})
  1502. if _, ok := subarrayvalue.(map[string]interface{})["resultname"]; !ok {
  1503. tempVal_["resultname"] = subarrayvalue.(map[string]interface{})["name"]
  1504. } else {
  1505. tempVal_["resultname"] = subarrayvalue.(map[string]interface{})["resultname"]
  1506. }
  1507. tempVal_["resultmaps"], err = ExecDataParam(subarrayvalue.(map[string]interface{}), commonParam, ParamMap, v.(map[string]interface{}), tempVal_arrary, tx) //递归调用执行
  1508. if err != nil {
  1509. return err
  1510. }
  1511. tempVal_arrary = append(tempVal_arrary, tempVal_)
  1512. }
  1513. v.(map[string]interface{})["children"] = tempVal_arrary
  1514. }
  1515. }
  1516. return nil
  1517. }
  1518. // @Summary 删除图片
  1519. // @Tags RemovePicByName
  1520. // @Accept json
  1521. // @Produce json
  1522. // @Param sqlname query string true "sqlname"
  1523. // @Param offset query int true "offset"
  1524. // @Param pagecount query int true "pagecount"
  1525. // @Param returntype query string true "returntype"
  1526. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  1527. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  1528. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  1529. // @Router /data/PostDataByName [POST]
  1530. func RemovePicByName(c *gin.Context) {
  1531. logging.Info("RemovePicByName ", c.Keys)
  1532. appG := app.Gin{C: c}
  1533. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  1534. fsion := gofasion.NewFasion(string(dataByte))
  1535. sqlnamestr := fsion.Get("name").ValueStr()
  1536. picname := fsion.Get("picname").ValueStr()
  1537. sql, _ := restful.GetSqlByNameDB(sqlnamestr)
  1538. params := fsion.Get("params").Array()
  1539. s_params := make([]interface{}, 0)
  1540. for _, v_params := range params {
  1541. s_params = append(s_params, v_params.ValueStr())
  1542. }
  1543. if sql != "" {
  1544. queryData, err := execDataBySql(sql, s_params)
  1545. if picname != "" {
  1546. // Destination
  1547. distPath := path.Join(setting.CurrentPath, setting.AppSetting.ImageSavePath, picname)
  1548. err := os.Remove(distPath) //删除文件test.txt
  1549. if err != nil {
  1550. //如果删除失败则输出 file remove Error!
  1551. fmt.Println("file remove Error!")
  1552. //输出错误详细信息
  1553. fmt.Printf("%s", err)
  1554. } else {
  1555. //如果删除成功则输出 file remove OK!
  1556. fmt.Print("file remove OK!")
  1557. }
  1558. distPath = path.Join(setting.CurrentPath, setting.AppSetting.ThumbnailSavePath, picname)
  1559. err = os.Remove(distPath) //删除文件test.txt
  1560. if err != nil {
  1561. //如果删除失败则输出 file remove Error!
  1562. fmt.Println("file remove Error!")
  1563. //输出错误详细信息
  1564. fmt.Printf("%s", err)
  1565. } else {
  1566. //如果删除成功则输出 file remove OK!
  1567. fmt.Print("file remove OK!")
  1568. }
  1569. }
  1570. if err != nil {
  1571. appG.Response(http.StatusOK, e.ERROR, err.Error())
  1572. } else {
  1573. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  1574. }
  1575. } else {
  1576. appG.Response(http.StatusOK, e.SUCCESS, nil)
  1577. }
  1578. }
  1579. // @Summary 删除文件
  1580. // @Tags RemoveFileByName
  1581. // @Accept json
  1582. // @Produce json
  1583. // @Param sqlname query string true "sqlname"
  1584. // @Param offset query int true "offset"
  1585. // @Param pagecount query int true "pagecount"
  1586. // @Param returntype query string true "returntype"
  1587. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  1588. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  1589. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  1590. // @Router /data/PostDataByName [POST]
  1591. func RemoveFileByName(c *gin.Context) {
  1592. appG := app.Gin{C: c}
  1593. id := c.Param("id")
  1594. logging.Info("DownloadFile ", c.Keys, id)
  1595. eqdoc, err := restful.Engine.SQL("SELECT * FROM eq_doc where id = ? ", id).QueryString()
  1596. if eqdoc == nil {
  1597. appG.Response(http.StatusOK, e.ERROR, err.Error())
  1598. return
  1599. }
  1600. distPath := path.Join(setting.CurrentPath, setting.AppSetting.FileSavePath, eqdoc[0]["docpath"], eqdoc[0]["newdocname"])
  1601. err = os.Remove(distPath) //删除文件test.txt
  1602. if err != nil {
  1603. //如果删除失败则输出 file remove Error!
  1604. fmt.Println("file remove Error!")
  1605. //输出错误详细信息
  1606. fmt.Printf("%s", err)
  1607. appG.Response(http.StatusOK, e.ERROR, err.Error())
  1608. return
  1609. }
  1610. _, err = restful.Engine.SQL("delete FROM eq_doc where id = ? ", id).QueryString()
  1611. appG.Response(http.StatusOK, e.SUCCESS, "OK")
  1612. }
  1613. // @Summary 根据APISQL表中SQL执行得到数据集
  1614. // @Tags PostDataByName
  1615. // @Accept json
  1616. // @Produce json
  1617. // @Param sqlname query string true "sqlname"
  1618. // @Param offset query int true "offset"
  1619. // @Param pagecount query int true "pagecount"
  1620. // @Param returntype query string true "returntype"
  1621. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  1622. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  1623. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  1624. // @Router /data/PostDataByName [POST]
  1625. func UpdateDataRelation(c *gin.Context) {
  1626. appG := app.Gin{C: c}
  1627. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  1628. fsion := gofasion.NewFasion(string(dataByte))
  1629. tablename := fsion.Get("name").ValueStr()
  1630. dataname := fsion.Get("dataname").ValueStr()
  1631. datavalue := fsion.Get("datavalue").ValueStr()
  1632. valuename := fsion.Get("valuename").ValueStr()
  1633. logging.Info("UpdateDataRelation ", c.Keys, c.Request.RemoteAddr, tablename, dataname, datavalue, valuename)
  1634. values := fsion.Get("values").Array()
  1635. tx := restful.Engine.NewSession()
  1636. err := tx.Begin()
  1637. defer func() {
  1638. switch {
  1639. case err != nil:
  1640. if tx != nil {
  1641. tx.Rollback()
  1642. }
  1643. default:
  1644. if tx != nil {
  1645. err = tx.Commit()
  1646. }
  1647. }
  1648. if tx != nil {
  1649. tx.Close()
  1650. }
  1651. }()
  1652. insertSqlstr := "insert into " + tablename + "( " + dataname + "," + valuename + ") select DISTINCT ?, ? from DUAL " +
  1653. " where NOT EXISTS (select " + valuename + " from " + tablename + " where " + valuename + " = ? and " + dataname + " = ?)"
  1654. d_params := make([]interface{}, 4)
  1655. d_params[0] = datavalue
  1656. s_params := ""
  1657. for _, v_values := range values {
  1658. d_params[1] = v_values.ValueStr()
  1659. if s_params == "" {
  1660. s_params = v_values.ValueStr()
  1661. } else {
  1662. s_params = s_params + "," + v_values.ValueStr()
  1663. }
  1664. d_params[2] = d_params[1]
  1665. d_params[3] = d_params[0]
  1666. _, err := execDataBySqlT(insertSqlstr, d_params, tx)
  1667. if err != nil {
  1668. appG.Response(http.StatusOK, e.ERROR, err.Error())
  1669. break
  1670. }
  1671. }
  1672. if s_params != "" {
  1673. deleteSqlstr := "delete from " + tablename + " " +
  1674. " where " + dataname + " = " + datavalue + " and " + valuename + " not in (" + s_params + ")"
  1675. queryData, err := execDataBySqlT(deleteSqlstr, nil, tx)
  1676. if err != nil {
  1677. appG.Response(http.StatusOK, e.ERROR, err.Error())
  1678. } else if err == nil {
  1679. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  1680. }
  1681. } else {
  1682. deleteSqlstr := "delete from " + tablename + " " +
  1683. " where " + dataname + " = " + datavalue
  1684. queryData, err := execDataBySqlT(deleteSqlstr, nil, tx)
  1685. if err != nil {
  1686. appG.Response(http.StatusOK, e.ERROR, err.Error())
  1687. } else if err == nil {
  1688. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  1689. }
  1690. }
  1691. }
  1692. // @Summary 根据APISQL表中SQL执行得到数据集
  1693. // @Tags PostDatasByName
  1694. // @Accept json
  1695. // @Produce json
  1696. // @Param sqlname query string true "sqlname"
  1697. // @Param offset query int true "offset"
  1698. // @Param pagecount query int true "pagecount"
  1699. // @Param returntype query string true "returntype"
  1700. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  1701. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  1702. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  1703. // @Router /data/PostDatasByName [POST]
  1704. func PostDataByNames(c *gin.Context) {
  1705. appG := app.Gin{C: c}
  1706. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  1707. fsion := gofasion.NewFasion(string(dataByte))
  1708. sqlParams := fsion.Array()
  1709. queryData := make(map[string]interface{})
  1710. for _, v := range sqlParams {
  1711. fsion2 := gofasion.NewFasion(v.Json())
  1712. logging.Info("PostDataByNames ", c.Keys, fsion2.Get("name").ValueStr())
  1713. sql, p := restful.GetSqlByNameDB(fsion2.Get("name").ValueStr())
  1714. if sql == "" {
  1715. errorm := make(map[string]interface{})
  1716. errorm["code"] = e.ERROR
  1717. errorm["message"] = "sql没有找到"
  1718. errorm["param"] = ""
  1719. queryData[fsion2.Get("name").ValueStr()] = errorm
  1720. continue
  1721. } else if sql != "" {
  1722. s_params := make([]interface{}, 0)
  1723. if fsion2.HasKey("parammaps") {
  1724. parammaps := fsion2.Get("parammaps")
  1725. paramslist := strings.Split(p, ",")
  1726. if len(paramslist) > 0 && p != "" {
  1727. for _, value := range paramslist {
  1728. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  1729. if tempv, exists := c.Get("jwt_username"); exists {
  1730. s_params = append(s_params, tempv.(string))
  1731. } else {
  1732. s_params = append(s_params, "")
  1733. }
  1734. } else if strings.ToLower(strings.Trim(value, " ")) == "snowid" {
  1735. ids, err := setting.SnowIds.NextId()
  1736. if err != nil {
  1737. ids = time.Now().UnixNano()
  1738. logging.Info("create SnowIds err", err)
  1739. }
  1740. s_params = append(s_params, ids)
  1741. } else {
  1742. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  1743. }
  1744. }
  1745. }
  1746. } else if fsion2.HasKey("params") {
  1747. params := fsion2.Get("params").Array()
  1748. //ids,err := setting.SnowIds.NextId()
  1749. //if err !=nil{
  1750. // ids = time.Now().UnixNano()
  1751. // logging.Info("create SnowIds err",err)
  1752. //}
  1753. //s_params = append(s_params, ids)
  1754. for _, v_params := range params {
  1755. s_params = append(s_params, v_params.ValueStr())
  1756. }
  1757. }
  1758. _, err := execDataBySql(sql, s_params)
  1759. if err != nil {
  1760. logging.Error("PostDataByName err: ", err)
  1761. errorm := make(map[string]interface{})
  1762. errorm["code"] = e.ERROR
  1763. errorm["message"] = err.Error()
  1764. errorm["param"] = s_params
  1765. queryData[fsion2.Get("name").ValueStr()] = errorm
  1766. continue
  1767. } else {
  1768. errorm := make(map[string]interface{})
  1769. errorm["code"] = e.SUCCESS
  1770. errorm["message"] = "success"
  1771. queryData[fsion2.Get("name").ValueStr()] = errorm
  1772. continue
  1773. }
  1774. } else {
  1775. errorm := make(map[string]interface{})
  1776. errorm["code"] = e.ERROR
  1777. errorm["message"] = "NO SQL"
  1778. errorm["param"] = ""
  1779. queryData[fsion2.Get("name").ValueStr()] = errorm
  1780. }
  1781. }
  1782. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  1783. }
  1784. func getDataBySql(sqlstr string, offset, pagecount int, returntype string, params []interface{}) (interface{}, error) {
  1785. if offset > 0 {
  1786. offset = offset - 1
  1787. }
  1788. //if pagecount == 0 {
  1789. // pagecount = setting.AppSetting.PageSize
  1790. //}else if pagecount>setting.AppSetting.PageSize{
  1791. // pagecount = setting.AppSetting.PageSize
  1792. //}
  1793. if returntype == "list" {
  1794. queryData, err := restful.QueryByList(sqlstr, offset, pagecount, params)
  1795. return queryData, err
  1796. } else if returntype == "listlist" {
  1797. queryData, err := restful.QueryByListList(sqlstr, offset, pagecount, params)
  1798. return queryData, err
  1799. } else {
  1800. queryData, err := restful.QueryByMap(sqlstr, offset, pagecount, params)
  1801. return queryData, err
  1802. }
  1803. }
  1804. func getDataBySqlT(sqlstr string, offset, pagecount int, returntype string, params []interface{}, tx *xorm.Session) (interface{}, error) {
  1805. if offset > 0 {
  1806. offset = offset - 1
  1807. }
  1808. //if pagecount == 0 {
  1809. // pagecount = setting.AppSetting.PageSize
  1810. //}else if pagecount>setting.AppSetting.PageSize{
  1811. // pagecount = setting.AppSetting.PageSize
  1812. //}
  1813. if returntype == "list" {
  1814. queryData, err := restful.QueryByListT(sqlstr, offset, pagecount, params, tx)
  1815. return queryData, err
  1816. } else if returntype == "listlist" {
  1817. queryData, err := restful.QueryByListListT(sqlstr, offset, pagecount, params, tx)
  1818. return queryData, err
  1819. } else {
  1820. queryData, err := restful.QueryByMapT(sqlstr, offset, pagecount, params, tx)
  1821. return queryData, err
  1822. }
  1823. }
  1824. func GetRecuData_BySql(sql string, Params string, idname string, thisParams map[string]interface{}, isList bool) (interface{}, error) {
  1825. paramslist := strings.Split(Params, ",")
  1826. s_params := make([]interface{}, 0)
  1827. if isList {
  1828. for _, v_params := range thisParams["params"].([]interface{}) {
  1829. s_params = append(s_params, v_params)
  1830. }
  1831. } else {
  1832. paramslist := strings.Split(Params, ",")
  1833. if len(paramslist) > 0 && Params != "" {
  1834. for _, value := range paramslist {
  1835. s_params = append(s_params, thisParams[strings.Trim(value, " ")])
  1836. }
  1837. }
  1838. }
  1839. queryData, err := restful.QueryByMapMenu(sql, 0, 0, s_params)
  1840. for _, queryData_ := range queryData {
  1841. if v, ok := queryData_["haschildren"]; (ok && v.(int64) > 0) || !ok {
  1842. if isList {
  1843. if queryData_[idname] != nil {
  1844. thisParams["params"].([]interface{})[len(thisParams["params"].([]interface{}))-1] = queryData_[idname].(interface{})
  1845. }
  1846. } else {
  1847. if queryData_[idname] != nil {
  1848. thisParams[idname] = queryData_[idname].(interface{})
  1849. }
  1850. if len(paramslist) > 0 && Params != "" {
  1851. s_params = make([]interface{}, 0)
  1852. for _, value := range paramslist {
  1853. s_params = append(s_params, thisParams[strings.Trim(value, " ")])
  1854. }
  1855. }
  1856. }
  1857. queryData_["children"], _ = GetRecuData_BySql(sql, Params, idname, thisParams, isList)
  1858. } else {
  1859. }
  1860. }
  1861. return queryData, err
  1862. }
  1863. func execDataBySql(sqlstr string, params []interface{}) (interface{}, error) {
  1864. queryData, err := restful.ExecQuery(sqlstr, params)
  1865. return queryData, err
  1866. }
  1867. func execDataBySqlT(sqlstr string, params []interface{}, tx *xorm.Session) (interface{}, error) {
  1868. queryData, err := restful.ExecQueryT(sqlstr, params, tx)
  1869. return queryData, err
  1870. }
  1871. func ExecDataBySql(sqlstr string, params []interface{}) (interface{}, error) {
  1872. queryData, err := restful.ExecQuery(sqlstr, params)
  1873. return queryData, err
  1874. }
  1875. // @Summary 导入excel文件到数据库,excel第一行作为参数
  1876. // @Tags ImportExcel
  1877. // @Accept json
  1878. // @Produce json
  1879. // @Param file query string true "文件名"
  1880. // @Param name header string true "执行sql的名字"
  1881. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  1882. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  1883. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  1884. // @Router /data/ImportExcel [POST]
  1885. func ImportExcel(c *gin.Context) {
  1886. appG := app.Gin{C: c}
  1887. inputdata := ""
  1888. c.Request.ParseForm()
  1889. params := c.Request.Form
  1890. file, _, err := c.Request.FormFile("file")
  1891. if err != nil {
  1892. appG.Response(http.StatusOK, e.ERROR, err)
  1893. return
  1894. }
  1895. sqlnamestrs := params.Get("name")
  1896. sheetname := params.Get("sheetname")
  1897. pastureid := params.Get("pastureid")
  1898. //importParams := params.Get("importParams")
  1899. logging.Info("ImportExcel ", c.Keys, c.Request.RemoteAddr, sqlnamestrs)
  1900. //paramslist := strings.Split(importParams, ",")
  1901. //paramslist = append(paramslist, "jwt_username")
  1902. requiredParams := params.Get("requiredParams")
  1903. dateParams := params.Get("dateParams")
  1904. numParams := params.Get("numParams")
  1905. dateParamslist := strings.Split(dateParams, ",")
  1906. requiredParamslist := strings.Split(requiredParams, ",")
  1907. numParamslist := strings.Split(numParams, ",")
  1908. queryData := make([]interface{}, 0)
  1909. sqlslist := strings.Split(sqlnamestrs, ",")
  1910. xlsx1, err := excelize.OpenReader(file)
  1911. if err != nil {
  1912. fmt.Println(err)
  1913. return
  1914. }
  1915. ok := 0
  1916. error := 0
  1917. isdone := true
  1918. rows, _ := xlsx1.GetRows(sheetname)
  1919. if len(rows) > 10000 { // 限制1000条
  1920. rows = rows[:10000]
  1921. }
  1922. for i, row := range rows {
  1923. if i > 0 {
  1924. entry := make(map[string]interface{})
  1925. outentry := make(map[string]interface{})
  1926. for j, colCell := range rows[0] {
  1927. for k, colCell1 := range row {
  1928. if j == k {
  1929. outentry[colCell] = colCell1
  1930. entry[colCell] = colCell1
  1931. }
  1932. }
  1933. }
  1934. inputdata = ""
  1935. a := ""
  1936. for _, v := range dateParamslist {
  1937. if v == "" {
  1938. continue
  1939. }
  1940. if d, ok := outentry[strings.Trim(v, " ")]; ok {
  1941. dtime, err := TransfTime(d.(string))
  1942. if err != nil {
  1943. a = strings.Trim(v, " ")
  1944. break
  1945. }
  1946. outentry[strings.Trim(v, " ")] = dtime
  1947. }
  1948. }
  1949. if a != "" {
  1950. outentry["error_msg"] = a + " 格式错误"
  1951. error++
  1952. queryData = append(queryData, outentry)
  1953. continue
  1954. }
  1955. a = ""
  1956. for _, v := range requiredParamslist {
  1957. if v == "" {
  1958. continue
  1959. }
  1960. if d, ok := outentry[strings.Trim(v, " ")]; !ok || d == "" {
  1961. a = strings.Trim(v, " ")
  1962. break
  1963. }
  1964. }
  1965. if a != "" {
  1966. outentry["error_msg"] = a + " 未填或格式错误"
  1967. error++
  1968. queryData = append(queryData, outentry)
  1969. continue
  1970. }
  1971. a = ""
  1972. for _, v := range numParamslist {
  1973. if v == "" {
  1974. continue
  1975. }
  1976. d, ok := outentry[strings.Trim(v, " ")]
  1977. if !ok || d == "" {
  1978. outentry[strings.Trim(v, " ")] = 0
  1979. } else {
  1980. var fl float64
  1981. switch d.(type) {
  1982. case string:
  1983. fl, err = strconv.ParseFloat(d.(string), 64)
  1984. }
  1985. if err != nil || fl < 0 {
  1986. a = strings.Trim(v, " ")
  1987. break
  1988. }
  1989. }
  1990. }
  1991. if a != "" {
  1992. outentry["error_msg"] = a + " 为数值类型且不可为负数"
  1993. error++
  1994. queryData = append(queryData, outentry)
  1995. continue
  1996. }
  1997. tx := restful.Engine.NewSession()
  1998. err := tx.Begin()
  1999. for _, sqlnamestr := range sqlslist {
  2000. sql, paramslists := restful.GetSqlByNameDB(sqlnamestr)
  2001. paramslist := strings.Split(paramslists, ",")
  2002. if len(paramslist) > 0 {
  2003. s_params := make([]interface{}, 0)
  2004. for _, value := range paramslist {
  2005. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  2006. if tempv, exists := c.Get("jwt_username"); exists {
  2007. s_params = append(s_params, tempv.(string))
  2008. } else {
  2009. s_params = append(s_params, "")
  2010. }
  2011. } else if strings.ToLower(strings.Trim(value, " ")) == "pastureid" {
  2012. s_params = append(s_params, pastureid)
  2013. } else if strings.ToLower(strings.Trim(value, " ")) == "snowid" {
  2014. ids, err := setting.SnowIds.NextId()
  2015. if err != nil {
  2016. ids = time.Now().UnixNano()
  2017. logging.Info("create SnowIds err", err)
  2018. }
  2019. s_params = append(s_params, ids)
  2020. } else {
  2021. if outentry[strings.Trim(value, " ")] == nil {
  2022. s_params = append(s_params, "")
  2023. } else {
  2024. s_params = append(s_params, outentry[strings.Trim(value, " ")])
  2025. }
  2026. }
  2027. }
  2028. outentry["input"] = inputdata
  2029. returnmsgmap1, err := tx.SQL(sql, s_params...).Query().List()
  2030. if err != nil {
  2031. if tx != nil {
  2032. tx.Rollback()
  2033. }
  2034. if tx != nil {
  2035. tx.Close()
  2036. }
  2037. msg := geterrmsg(err.Error())
  2038. outentry["error_msg"] = msg
  2039. error++
  2040. queryData = append(queryData, outentry)
  2041. isdone = true
  2042. break
  2043. } else {
  2044. if len(returnmsgmap1) > 0 {
  2045. if va, ok := returnmsgmap1[0]["msg"]; ok && va != "" {
  2046. if tx != nil {
  2047. tx.Rollback()
  2048. }
  2049. if tx != nil {
  2050. tx.Close()
  2051. }
  2052. msg := geterrmsg(va.(string))
  2053. outentry["error_msg"] = msg
  2054. error++
  2055. queryData = append(queryData, outentry)
  2056. isdone = true
  2057. break
  2058. }
  2059. }
  2060. isdone = false
  2061. }
  2062. }
  2063. }
  2064. switch {
  2065. case err != nil:
  2066. if tx != nil {
  2067. tx.Rollback()
  2068. }
  2069. default:
  2070. if tx != nil {
  2071. err = tx.Commit()
  2072. }
  2073. }
  2074. if tx != nil {
  2075. tx.Close()
  2076. }
  2077. }
  2078. if !isdone {
  2079. ok++
  2080. isdone = true
  2081. }
  2082. }
  2083. data := make(map[string]interface{})
  2084. data["result"] = queryData
  2085. data["success"] = ok
  2086. data["err_count"] = error
  2087. appG.Response(http.StatusOK, e.SUCCESS, data)
  2088. }
  2089. func TransfTime(timestr string) (string, error) {
  2090. if timestr == "" {
  2091. return time.Now().Format("2006-01-02"), nil
  2092. }
  2093. days, err := strconv.Atoi(timestr)
  2094. if err != nil {
  2095. if len(timestr) == 8 && strings.Count(timestr, "-") == 2 {
  2096. return "20" + timestr[6:] + "-" + timestr[:5], nil
  2097. }
  2098. _, err := time.Parse("2006-01-02", timestr)
  2099. if err != nil {
  2100. t, err := time.Parse("2006/01/02", timestr)
  2101. if err != nil {
  2102. t, err := time.Parse("2006.01.02", timestr)
  2103. if err != nil {
  2104. return "", err
  2105. } else {
  2106. return t.Format("2006-01-02"), nil
  2107. }
  2108. } else {
  2109. return t.Format("2006-01-02"), nil
  2110. }
  2111. } else {
  2112. return timestr, nil
  2113. }
  2114. }
  2115. times, _ := time.Parse("2006-01-02", "1899-12-30")
  2116. times = times.AddDate(0, 0, days)
  2117. return times.Format("2006-01-02"), nil
  2118. }
  2119. func Createchart(c *gin.Context) {
  2120. appG := app.Gin{C: c}
  2121. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  2122. fsion := gofasion.NewFasion(string(dataByte))
  2123. chart_name := fsion.Get("chart_name").ValueStr()
  2124. desc := fsion.Get("desc").ValueStr()
  2125. pastureid := fsion.Get("pastureid").ValueStr()
  2126. source_id := fsion.Get("source_id").ValueStr()
  2127. emp := fsion.Get("emp").ValueStr()
  2128. content := fsion.Get("content").Json()
  2129. var mapResult map[string]interface{}
  2130. err1 := json.Unmarshal([]byte(content), &mapResult)
  2131. if err1 != nil {
  2132. fmt.Println("JsonToMapDemo err: ", err1)
  2133. }
  2134. tx := restful.Engine.NewSession()
  2135. err := tx.Begin()
  2136. defer func() {
  2137. switch {
  2138. case err != nil:
  2139. logging.Error("tx.Begin 事务启动失败__error:", err)
  2140. if tx != nil {
  2141. tx.Rollback()
  2142. }
  2143. default:
  2144. if tx != nil {
  2145. err = tx.Commit()
  2146. }
  2147. }
  2148. if tx != nil {
  2149. tx.Close()
  2150. }
  2151. }()
  2152. ids, err := setting.SnowIds.NextId()
  2153. if err != nil {
  2154. ids = time.Now().UnixNano()
  2155. logging.Info("create SnowIds err", err)
  2156. }
  2157. exec, err := tx.Exec("insert into chart(id,pastureid,cname,statue,emp,opratetime,content,sourceid)VALUEs(?,?,?,?,?,?,?)",
  2158. ids, pastureid, chart_name, 0, emp, desc, source_id)
  2159. if err != nil {
  2160. appG.Response(http.StatusOK, e.ERROR, err.Error())
  2161. } else {
  2162. appG.Response(http.StatusOK, e.SUCCESS, exec)
  2163. }
  2164. }
  2165. func Updatedashboard(c *gin.Context) {
  2166. appG := app.Gin{C: c}
  2167. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  2168. fsion := gofasion.NewFasion(string(dataByte))
  2169. dashboard_id := fsion.Get("dashboard_id").ValueStr()
  2170. pastureid := fsion.Get("pastureid").ValueStr()
  2171. content := fsion.Get("content").Json()
  2172. var mapResult map[string]interface{}
  2173. err1 := json.Unmarshal([]byte(content), &mapResult)
  2174. if err1 != nil {
  2175. fmt.Println("JsonToMapDemo err: ", err1)
  2176. }
  2177. layout := mapResult["layout"]
  2178. tx := restful.Engine.NewSession()
  2179. err := tx.Begin()
  2180. defer func() {
  2181. switch {
  2182. case err != nil:
  2183. logging.Error("tx.Begin 事务启动失败__error:", err)
  2184. if tx != nil {
  2185. tx.Rollback()
  2186. }
  2187. default:
  2188. if tx != nil {
  2189. err = tx.Commit()
  2190. }
  2191. }
  2192. if tx != nil {
  2193. tx.Close()
  2194. }
  2195. }()
  2196. exec, err := tx.SQL("select content from dashboard where pastureid=? and id=?", pastureid, dashboard_id).Query().List()
  2197. if err != nil {
  2198. println("2", err.Error())
  2199. appG.Response(http.StatusOK, e.ERROR, err.Error())
  2200. } else {
  2201. if exec != nil {
  2202. if exec[0]["content"] == nil {
  2203. mapR := make(map[string]interface{})
  2204. mapR["layout"] = layout
  2205. mjson, _ := json.Marshal(mapR)
  2206. mString := string(mjson)
  2207. exec1, err3 := tx.Exec("update dashboard set content=? where pastureid=? and id=?", mString, pastureid, dashboard_id)
  2208. if err3 != nil {
  2209. println("3", err3.Error())
  2210. appG.Response(http.StatusOK, e.ERROR, err3.Error())
  2211. } else {
  2212. appG.Response(http.StatusOK, e.SUCCESS, exec1)
  2213. }
  2214. } else {
  2215. var mapR map[string]interface{}
  2216. err2 := json.Unmarshal([]byte(exec[0]["content"].(string)), &mapR)
  2217. if err1 != nil {
  2218. fmt.Println("JsonToMapDemo err: ", err2)
  2219. }
  2220. mapR["layout"] = layout
  2221. mjson, _ := json.Marshal(mapR)
  2222. mString := string(mjson)
  2223. exec1, err3 := tx.Exec("update dashboard set content=? where pastureid=? and id=?", mString, pastureid, dashboard_id)
  2224. if err3 != nil {
  2225. println("3", err3.Error())
  2226. appG.Response(http.StatusOK, e.ERROR, err3.Error())
  2227. } else {
  2228. appG.Response(http.StatusOK, e.SUCCESS, exec1)
  2229. }
  2230. }
  2231. } else {
  2232. appG.Response(http.StatusOK, e.ERROR, "未找到对应的仪表盘")
  2233. }
  2234. }
  2235. }
  2236. func ExecSQL(c *gin.Context) {
  2237. appG := app.Gin{C: c}
  2238. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  2239. fsion := gofasion.NewFasion(string(dataByte))
  2240. content := fsion.Get("content").Json()
  2241. pastureid := fsion.Get("pastureid").ValueStr()
  2242. var mapResult map[string]interface{}
  2243. err1 := json.Unmarshal([]byte(content), &mapResult)
  2244. if err1 != nil {
  2245. fmt.Println("JsonToMapDemo err: ", err1)
  2246. }
  2247. sqlstr := "select "
  2248. groupstr := " GROUP BY "
  2249. for _, value := range mapResult["selectedDimension"].([]interface{}) {
  2250. sqlstr = sqlstr + value.(map[string]interface{})["Column"].(string) + ","
  2251. groupstr = groupstr + value.(map[string]interface{})["Column"].(string) + ","
  2252. }
  2253. for _, value := range mapResult["selectedCalcul"].([]interface{}) {
  2254. if value.(map[string]interface{})["calculFunc"].(string) == "none" {
  2255. sqlstr = sqlstr + value.(map[string]interface{})["Column"].(string) + ","
  2256. groupstr = groupstr + value.(map[string]interface{})["Column"].(string) + ","
  2257. } else if value.(map[string]interface{})["calculFunc"].(string) == "custbiaozhun" {
  2258. tem := "STDDEV" + "(" + value.(map[string]interface{})["Column"].(string) + ") as " + value.(map[string]interface{})["Column"].(string)
  2259. sqlstr = sqlstr + tem + ","
  2260. }else if value.(map[string]interface{})["calculFunc"].(string) == "custbianyi" {
  2261. tem := "STDDEV" + "(" + value.(map[string]interface{})["Column"].(string) + ")/ AVG(" +value.(map[string]interface{})["Column"].(string)+")as " + value.(map[string]interface{})["Column"].(string)
  2262. sqlstr = sqlstr + tem + ","
  2263. }else {
  2264. tem := value.(map[string]interface{})["calculFunc"].(string) + "(" + value.(map[string]interface{})["Column"].(string) + ") as " + value.(map[string]interface{})["Column"].(string)
  2265. sqlstr = sqlstr + tem + ","
  2266. }
  2267. }
  2268. if _, ok := mapResult["selectedCalcul2"]; ok {
  2269. for _, value := range mapResult["selectedCalcul2"].([]interface{}) {
  2270. if value.(map[string]interface{})["calculFunc"].(string) == "none" {
  2271. sqlstr = sqlstr + value.(map[string]interface{})["Column"].(string) + ","
  2272. groupstr = groupstr + value.(map[string]interface{})["Column"].(string) + ","
  2273. }else if value.(map[string]interface{})["calculFunc"].(string) == "custbiaozhun" {
  2274. tem := "STDDEV" + "(" + value.(map[string]interface{})["Column"].(string) + ") as " + value.(map[string]interface{})["Column"].(string)
  2275. sqlstr = sqlstr + tem + ","
  2276. }else if value.(map[string]interface{})["calculFunc"].(string) == "custbianyi" {
  2277. tem := "STDDEV" + "(" + value.(map[string]interface{})["Column"].(string) + ")/ AVG(" +value.(map[string]interface{})["Column"].(string)+")as " + value.(map[string]interface{})["Column"].(string)
  2278. sqlstr = sqlstr + tem + ","
  2279. }else {
  2280. tem := value.(map[string]interface{})["calculFunc"].(string) + "(" + value.(map[string]interface{})["Column"].(string) + ") as " + value.(map[string]interface{})["Column"].(string)
  2281. sqlstr = sqlstr + tem + ","
  2282. }
  2283. }
  2284. }
  2285. sqlstr = sqlstr[0 : len(sqlstr)-1]
  2286. sqlstr = sqlstr + " from " + mapResult["dataSrc"].(string)
  2287. sqlstr = sqlstr + " where pastureid=" + pastureid
  2288. if len(mapResult["filters"].([]interface{})) > 0 {
  2289. sqlstr = sqlstr + " and "
  2290. }
  2291. println(len(mapResult["filters"].([]interface{})), sqlstr)
  2292. for _, value := range mapResult["filters"].([]interface{}) {
  2293. switch value.(map[string]interface{})["filterOperator"].(string) {
  2294. case ">", "=", "<", ">=", "<=", "!=", "like":
  2295. sqlstr = sqlstr + value.(map[string]interface{})["filteCol"].(string) + value.(map[string]interface{})["filterOperator"].(string) + " " + value.(map[string]interface{})["value"].(map[string]interface{})["value1"].(string) + " AND "
  2296. case "IN":
  2297. sqlstr = sqlstr + value.(map[string]interface{})["filteCol"].(string) + " " + value.(map[string]interface{})["filterOperator"].(string) + "("
  2298. for _, value1 := range value.(map[string]interface{})["value"].(map[string]interface{})["arrValue"].([]interface{}) {
  2299. sqlstr = sqlstr + value1.(string) + ","
  2300. }
  2301. sqlstr = sqlstr[0 : len(sqlstr)-1]
  2302. sqlstr = sqlstr + ")" + " AND "
  2303. case "BETWEEN":
  2304. sqlstr = sqlstr + value.(map[string]interface{})["filteCol"].(string) + " " + value.(map[string]interface{})["filterOperator"].(string) + " " + value.(map[string]interface{})["value"].(map[string]interface{})["value1"].(string) + " and " + value.(map[string]interface{})["value"].(map[string]interface{})["value2"].(string) + " AND "
  2305. }
  2306. }
  2307. if len(mapResult["filters"].([]interface{})) > 0 {
  2308. sqlstr = sqlstr[0 : len(sqlstr)-4]
  2309. }
  2310. //
  2311. groupstr = groupstr[0 : len(groupstr)-1]
  2312. sqlstr = sqlstr + groupstr + " "
  2313. if len(mapResult["orderByStrs"].([]interface{})) > 0 {
  2314. sqlstr = sqlstr + " order by "
  2315. }
  2316. //
  2317. for key, value := range mapResult["orderByStrs"].([]interface{}) {
  2318. if key == len(mapResult["orderByStrs"].([]interface{}))-1 {
  2319. sqlstr = sqlstr + value.(string) + " "
  2320. } else {
  2321. sqlstr = sqlstr + value.(string) + ","
  2322. }
  2323. }
  2324. //
  2325. sqlstr = sqlstr + " limit " + strconv.Itoa(int(mapResult["limit"].(float64)))
  2326. tx := restful.Engine.NewSession()
  2327. err := tx.Begin()
  2328. defer func() {
  2329. switch {
  2330. case err != nil:
  2331. logging.Error("tx.Begin 事务启动失败__error:", err)
  2332. if tx != nil {
  2333. tx.Rollback()
  2334. }
  2335. default:
  2336. if tx != nil {
  2337. err = tx.Commit()
  2338. }
  2339. }
  2340. if tx != nil {
  2341. tx.Close()
  2342. }
  2343. }()
  2344. exec, err := tx.SQL(sqlstr).Query().List()
  2345. if err != nil {
  2346. appG.Response(http.StatusOK, e.ERROR, err.Error())
  2347. } else {
  2348. appG.Response(http.StatusOK, e.SUCCESS, exec)
  2349. }
  2350. }
  2351. func Dashboards(c *gin.Context) {
  2352. appG := app.Gin{C: c}
  2353. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  2354. fsion := gofasion.NewFasion(string(dataByte))
  2355. sqlnamestr := fsion.Get("name").ValueStr()
  2356. //sqlnamestr1 := fsion.Get("name1").ValueStr()
  2357. offset := fsion.Get("offset").ValueDefaultInt(0)
  2358. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  2359. returntype := fsion.Get("returntype").ValueDefaultStr("map")
  2360. month := fsion.Get("month").ValueDefaultStr("map")
  2361. logging.Info("GetUpkeepPlan ", c.Keys, sqlnamestr, month)
  2362. tx := restful.Engine.NewSession()
  2363. err := tx.Begin()
  2364. defer func() {
  2365. switch {
  2366. case err != nil:
  2367. if tx != nil {
  2368. tx.Rollback()
  2369. }
  2370. default:
  2371. if tx != nil {
  2372. err = tx.Commit()
  2373. }
  2374. }
  2375. if tx != nil {
  2376. tx.Close()
  2377. }
  2378. }()
  2379. sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
  2380. //sql1, p1 := restful.GetSqlByNameDBT(sqlnamestr1, tx)
  2381. if sql != "" {
  2382. s_params := make([]interface{}, 0)
  2383. if fsion.HasKey("parammaps") {
  2384. parammaps := fsion.Get("parammaps")
  2385. paramslist := strings.Split(p, ",")
  2386. if len(paramslist) > 0 && p != "" {
  2387. for _, value := range paramslist {
  2388. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  2389. if tempv, exists := c.Get("jwt_username"); exists {
  2390. s_params = append(s_params, tempv.(string))
  2391. } else {
  2392. s_params = append(s_params, "")
  2393. }
  2394. } else {
  2395. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  2396. }
  2397. }
  2398. }
  2399. }
  2400. queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params, tx)
  2401. if err != nil {
  2402. appG.Response(http.StatusOK, e.ERROR, err.Error())
  2403. } else {
  2404. //paramslist1 := strings.Split(p1, ",")
  2405. dids := make([]interface{}, 0)
  2406. for index, value := range queryData.(map[string]interface{})["list"].([]map[string]interface{}) {
  2407. var mapResult map[string]interface{}
  2408. dids = append(dids, value["dashboard_id"])
  2409. if value["content"] != nil {
  2410. err1 := json.Unmarshal([]byte(value["content"].(string)), &mapResult)
  2411. if err1 != nil {
  2412. println("JsonToMapDemo1 err: ", err1)
  2413. }
  2414. temap := make(map[string]interface{})
  2415. tem := mapResult["layout"].([]interface{})
  2416. if v, ok := value["chartids"]; ok {
  2417. chartids := strings.Split(v.(string), ",")
  2418. for _, va := range chartids {
  2419. a := false
  2420. for _, v2 := range tem {
  2421. if v2.(map[string]interface{})["id"].(string) == va {
  2422. a = true
  2423. //println("va1======",va)
  2424. }
  2425. }
  2426. if !a {
  2427. laytem := "{\"bottomLine\":[[3,18],[15,18]],\"h\":9,\"i\":\"" +
  2428. va + "\",\"id\":\"" + va +
  2429. "\",\"moved\":false,\"topLine\":[[3,9],[15,9]],\"w\":12,\"x\":0,\"xOffSet\":15,\"y\":100,\"yOffSet\":18}"
  2430. var mapTem map[string]interface{}
  2431. err1 := json.Unmarshal([]byte(laytem), &mapTem)
  2432. if err1 != nil {
  2433. println("JsonToMapDemo err: ", err1)
  2434. }
  2435. tem = append(tem, mapTem)
  2436. }
  2437. }
  2438. temap["layout"] = tem
  2439. queryData.(map[string]interface{})["list"].([]map[string]interface{})[index]["content"] = temap
  2440. }
  2441. } else {
  2442. temap := make(map[string]interface{})
  2443. tem := make([]interface{}, 0)
  2444. if v, ok := value["chartids"]; ok {
  2445. chartids := strings.Split(v.(string), ",")
  2446. for _, va := range chartids {
  2447. laytem := "{\"bottomLine\":[[3,18],[15,18]],\"h\":9,\"i\":\"" +
  2448. va + "\",\"id\":\"" + va +
  2449. "\",\"moved\":false,\"topLine\":[[3,9],[15,9]],\"w\":12,\"x\":0,\"xOffSet\":15,\"y\":0,\"yOffSet\":18}"
  2450. var mapTem map[string]interface{}
  2451. err1 := json.Unmarshal([]byte(laytem), &mapTem)
  2452. if err1 != nil {
  2453. println("JsonToMapDemo err: ", err1)
  2454. }
  2455. tem = append(tem, mapTem)
  2456. }
  2457. temap["layout"] = tem
  2458. queryData.(map[string]interface{})["list"].([]map[string]interface{})[index]["content"] = temap
  2459. }
  2460. }
  2461. }
  2462. queryData.(map[string]interface{})["order"] = dids
  2463. queryData.(map[string]interface{})["dashboards"] = queryData.(map[string]interface{})["list"]
  2464. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  2465. }
  2466. } else {
  2467. appG.Response(http.StatusOK, e.SUCCESS, nil)
  2468. }
  2469. }
  2470. func HttpPostData(url, RequestMethod, parammaps string, tx *xorm.Session) string {
  2471. fsion := gofasion.NewFasion(parammaps)
  2472. sqlnamestr := fsion.Get("name").ValueStr()
  2473. sqlnamestr1 := fsion.Get("name1").ValueStr()
  2474. offset := fsion.Get("offset").ValueDefaultInt(0)
  2475. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  2476. returntype := fsion.Get("returntype").ValueDefaultStr("map")
  2477. sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
  2478. sql1, p1 := restful.GetSqlByNameDBT(sqlnamestr1, tx)
  2479. body := []byte("")
  2480. if sql != "" {
  2481. s_params := make([]interface{}, 0)
  2482. if fsion.HasKey("parammaps") {
  2483. parammaps := fsion.Get("parammaps")
  2484. paramslist := strings.Split(p, ",")
  2485. if len(paramslist) > 0 && p != "" {
  2486. for _, value := range paramslist {
  2487. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  2488. }
  2489. }
  2490. }
  2491. queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params, tx)
  2492. if err != nil {
  2493. } else {
  2494. paramslist1 := strings.Split(p1, ",")
  2495. for index, value := range queryData.(map[string]interface{})["list"].([]map[string]interface{}) {
  2496. s_params1 := make([]interface{}, 0)
  2497. if len(paramslist1) > 0 && p1 != "" {
  2498. for _, v := range paramslist1 {
  2499. s_params1 = append(s_params1, value[strings.ToLower(strings.Trim(v, " "))])
  2500. }
  2501. }
  2502. arr, _ := tx.SQL(sql1, s_params1...).QueryString() //获取
  2503. queryData.(map[string]interface{})["list"].([]map[string]interface{})[index]["arrList"] = arr
  2504. body, _ = json.Marshal(queryData)
  2505. }
  2506. }
  2507. }
  2508. bs := bytes.NewBuffer(body)
  2509. client := &http.Client{}
  2510. //body1 := bytes.NewBuffer([]byte("{\"username\":\"00028\",\"password\":\"123456\"}"))
  2511. req, err := http.NewRequest(RequestMethod,
  2512. url,
  2513. bs,
  2514. )
  2515. if err != nil {
  2516. }
  2517. req.Header.Set("Content-Type", "application/json;charset=utf-8")
  2518. req.Header.Set("token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IjAwMDI4IiwicGFzc3dvcmQiOiJlMTBhZGMzOTQ5YmE1OWFiYmU1NmUwNTdmMjBmODgzZSIsImV4cCI6MTYxOTM4NjU0MiwiaXNzIjoiaHR0cHM6Ly9naXRodWIuY29tL2twdHl1bi9nby1hZG1pbi8ifQ.sJwnE9HTOVnDNOaeHqOQzi7cSydYkWS4uQHxtjY7UMY")
  2519. if err != nil {
  2520. // handle error
  2521. }
  2522. resp, err := client.Do(req)
  2523. if err != nil {
  2524. return ""
  2525. }
  2526. defer resp.Body.Close()
  2527. result_body, err := ioutil.ReadAll(resp.Body)
  2528. if err != nil {
  2529. return ""
  2530. }
  2531. fmt.Println(string(result_body))
  2532. return ""
  2533. }