2be3f1b064d95dc3cc515987a84c8771d2d65a06.svn-base 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754
  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 优化性能 children统一查询
  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. // 必输项参数 (字符串格式 "field1,field2,field3")
  1901. requiredParams := params.Get("requiredParams")
  1902. // 日期参数
  1903. dateParams := params.Get("dateParams")
  1904. // 数字参数
  1905. numParams := params.Get("numParams")
  1906. //将字符串分割开
  1907. dateParamslist := strings.Split(dateParams, ",")
  1908. requiredParamslist := strings.Split(requiredParams, ",")
  1909. numParamslist := strings.Split(numParams, ",")
  1910. queryData := make([]interface{}, 0)
  1911. sqlslist := strings.Split(sqlnamestrs, ",")
  1912. xlsx1, err := excelize.OpenReader(file)
  1913. if err != nil {
  1914. fmt.Println(err)
  1915. return
  1916. }
  1917. ok := 0
  1918. error := 0
  1919. isdone := true
  1920. rows, _ := xlsx1.GetRows(sheetname)
  1921. // 限制10000条,多余的截取掉
  1922. if len(rows) > 10000 {
  1923. rows = rows[:10000]
  1924. }
  1925. for i, row := range rows {
  1926. if i > 0 {
  1927. entry := make(map[string]interface{})
  1928. outentry := make(map[string]interface{})
  1929. for j, colCell := range rows[0] {
  1930. for k, colCell1 := range row {
  1931. if j == k {
  1932. outentry[colCell] = colCell1
  1933. entry[colCell] = colCell1
  1934. }
  1935. }
  1936. }
  1937. inputdata = ""
  1938. a := ""
  1939. //校验日期格式
  1940. for _, v := range dateParamslist {
  1941. if v == "" {
  1942. continue
  1943. }
  1944. if d, ok := outentry[strings.Trim(v, " ")]; ok {
  1945. dtime, err := TransfTime(d.(string))
  1946. if err != nil {
  1947. a = strings.Trim(v, " ")
  1948. break
  1949. }
  1950. outentry[strings.Trim(v, " ")] = dtime
  1951. }
  1952. }
  1953. if a != "" {
  1954. outentry["error_msg"] = a + " 格式错误"
  1955. error++
  1956. queryData = append(queryData, outentry)
  1957. continue
  1958. }
  1959. a = ""
  1960. //校验必填格式
  1961. for _, v := range requiredParamslist {
  1962. if v == "" {
  1963. continue
  1964. }
  1965. if d, ok := outentry[strings.Trim(v, " ")]; !ok || d == "" {
  1966. a = strings.Trim(v, " ")
  1967. break
  1968. }
  1969. }
  1970. if a != "" {
  1971. outentry["error_msg"] = a + " 未填或格式错误"
  1972. error++
  1973. queryData = append(queryData, outentry)
  1974. continue
  1975. }
  1976. a = ""
  1977. //校验数字格式
  1978. for _, v := range numParamslist {
  1979. if v == "" {
  1980. continue
  1981. }
  1982. d, ok := outentry[strings.Trim(v, " ")]
  1983. if !ok || d == "" {
  1984. outentry[strings.Trim(v, " ")] = 0
  1985. } else {
  1986. var fl float64
  1987. switch d.(type) {
  1988. case string:
  1989. fl, err = strconv.ParseFloat(d.(string), 64)
  1990. }
  1991. if err != nil || fl < 0 {
  1992. a = strings.Trim(v, " ")
  1993. break
  1994. }
  1995. }
  1996. }
  1997. if a != "" {
  1998. outentry["error_msg"] = a + " 为数值类型且不可为负数"
  1999. error++
  2000. queryData = append(queryData, outentry)
  2001. continue
  2002. }
  2003. tx := restful.Engine.NewSession()
  2004. err := tx.Begin()
  2005. for _, sqlnamestr := range sqlslist {
  2006. sql, paramslists := restful.GetSqlByNameDB(sqlnamestr)
  2007. paramslist := strings.Split(paramslists, ",")
  2008. if len(paramslist) > 0 {
  2009. s_params := make([]interface{}, 0)
  2010. for _, value := range paramslist {
  2011. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  2012. if tempv, exists := c.Get("jwt_username"); exists {
  2013. s_params = append(s_params, tempv.(string))
  2014. } else {
  2015. s_params = append(s_params, "")
  2016. }
  2017. } else if strings.ToLower(strings.Trim(value, " ")) == "pastureid" {
  2018. s_params = append(s_params, pastureid)
  2019. } else if strings.ToLower(strings.Trim(value, " ")) == "snowid" {
  2020. ids, err := setting.SnowIds.NextId()
  2021. if err != nil {
  2022. ids = time.Now().UnixNano()
  2023. logging.Info("create SnowIds err", err)
  2024. }
  2025. s_params = append(s_params, ids)
  2026. } else {
  2027. if outentry[strings.Trim(value, " ")] == nil {
  2028. s_params = append(s_params, "")
  2029. } else {
  2030. s_params = append(s_params, outentry[strings.Trim(value, " ")])
  2031. }
  2032. }
  2033. }
  2034. outentry["input"] = inputdata
  2035. returnmsgmap1, err := tx.SQL(sql, s_params...).Query().List()
  2036. if err != nil {
  2037. if tx != nil {
  2038. tx.Rollback()
  2039. }
  2040. if tx != nil {
  2041. tx.Close()
  2042. }
  2043. msg := geterrmsg(err.Error())
  2044. outentry["error_msg"] = msg
  2045. error++
  2046. queryData = append(queryData, outentry)
  2047. isdone = true
  2048. break
  2049. } else {
  2050. if len(returnmsgmap1) > 0 {
  2051. if va, ok := returnmsgmap1[0]["msg"]; ok && va != "" {
  2052. if tx != nil {
  2053. tx.Rollback()
  2054. }
  2055. if tx != nil {
  2056. tx.Close()
  2057. }
  2058. msg := geterrmsg(va.(string))
  2059. outentry["error_msg"] = msg
  2060. error++
  2061. queryData = append(queryData, outentry)
  2062. isdone = true
  2063. break
  2064. }
  2065. }
  2066. isdone = false
  2067. }
  2068. }
  2069. }
  2070. switch {
  2071. case err != nil:
  2072. if tx != nil {
  2073. tx.Rollback()
  2074. }
  2075. default:
  2076. if tx != nil {
  2077. err = tx.Commit()
  2078. }
  2079. }
  2080. if tx != nil {
  2081. tx.Close()
  2082. }
  2083. }
  2084. if !isdone {
  2085. ok++
  2086. isdone = true
  2087. }
  2088. }
  2089. data := make(map[string]interface{})
  2090. data["result"] = queryData
  2091. data["success"] = ok
  2092. data["err_count"] = error
  2093. appG.Response(http.StatusOK, e.SUCCESS, data)
  2094. }
  2095. func TransfTime(timestr string) (string, error) {
  2096. if timestr == "" {
  2097. return time.Now().Format("2006-01-02"), nil
  2098. }
  2099. days, err := strconv.Atoi(timestr)
  2100. if err != nil {
  2101. if len(timestr) == 8 && strings.Count(timestr, "-") == 2 {
  2102. return "20" + timestr[6:] + "-" + timestr[:5], nil
  2103. }
  2104. _, err := time.Parse("2006-01-02", timestr)
  2105. if err != nil {
  2106. t, err := time.Parse("2006/01/02", timestr)
  2107. if err != nil {
  2108. t, err := time.Parse("2006.01.02", timestr)
  2109. if err != nil {
  2110. return "", err
  2111. } else {
  2112. return t.Format("2006-01-02"), nil
  2113. }
  2114. } else {
  2115. return t.Format("2006-01-02"), nil
  2116. }
  2117. } else {
  2118. return timestr, nil
  2119. }
  2120. }
  2121. times, _ := time.Parse("2006-01-02", "1899-12-30")
  2122. times = times.AddDate(0, 0, days)
  2123. return times.Format("2006-01-02"), nil
  2124. }
  2125. func Createchart(c *gin.Context) {
  2126. appG := app.Gin{C: c}
  2127. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  2128. fsion := gofasion.NewFasion(string(dataByte))
  2129. chart_name := fsion.Get("chart_name").ValueStr()
  2130. desc := fsion.Get("desc").ValueStr()
  2131. pastureid := fsion.Get("pastureid").ValueStr()
  2132. source_id := fsion.Get("source_id").ValueStr()
  2133. emp := fsion.Get("emp").ValueStr()
  2134. content := fsion.Get("content").Json()
  2135. var mapResult map[string]interface{}
  2136. err1 := json.Unmarshal([]byte(content), &mapResult)
  2137. if err1 != nil {
  2138. fmt.Println("JsonToMapDemo err: ", err1)
  2139. }
  2140. tx := restful.Engine.NewSession()
  2141. err := tx.Begin()
  2142. defer func() {
  2143. switch {
  2144. case err != nil:
  2145. logging.Error("tx.Begin 事务启动失败__error:", err)
  2146. if tx != nil {
  2147. tx.Rollback()
  2148. }
  2149. default:
  2150. if tx != nil {
  2151. err = tx.Commit()
  2152. }
  2153. }
  2154. if tx != nil {
  2155. tx.Close()
  2156. }
  2157. }()
  2158. ids, err := setting.SnowIds.NextId()
  2159. if err != nil {
  2160. ids = time.Now().UnixNano()
  2161. logging.Info("create SnowIds err", err)
  2162. }
  2163. exec, err := tx.Exec("insert into chart(id,pastureid,cname,statue,emp,opratetime,content,sourceid)VALUEs(?,?,?,?,?,?,?)",
  2164. ids, pastureid, chart_name, 0, emp, desc, source_id)
  2165. if err != nil {
  2166. appG.Response(http.StatusOK, e.ERROR, err.Error())
  2167. } else {
  2168. appG.Response(http.StatusOK, e.SUCCESS, exec)
  2169. }
  2170. }
  2171. func Updatedashboard(c *gin.Context) {
  2172. appG := app.Gin{C: c}
  2173. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  2174. fsion := gofasion.NewFasion(string(dataByte))
  2175. dashboard_id := fsion.Get("dashboard_id").ValueStr()
  2176. pastureid := fsion.Get("pastureid").ValueStr()
  2177. content := fsion.Get("content").Json()
  2178. var mapResult map[string]interface{}
  2179. err1 := json.Unmarshal([]byte(content), &mapResult)
  2180. if err1 != nil {
  2181. fmt.Println("JsonToMapDemo err: ", err1)
  2182. }
  2183. layout := mapResult["layout"]
  2184. tx := restful.Engine.NewSession()
  2185. err := tx.Begin()
  2186. defer func() {
  2187. switch {
  2188. case err != nil:
  2189. logging.Error("tx.Begin 事务启动失败__error:", err)
  2190. if tx != nil {
  2191. tx.Rollback()
  2192. }
  2193. default:
  2194. if tx != nil {
  2195. err = tx.Commit()
  2196. }
  2197. }
  2198. if tx != nil {
  2199. tx.Close()
  2200. }
  2201. }()
  2202. exec, err := tx.SQL("select content from dashboard where pastureid=? and id=?", pastureid, dashboard_id).Query().List()
  2203. if err != nil {
  2204. println("2", err.Error())
  2205. appG.Response(http.StatusOK, e.ERROR, err.Error())
  2206. } else {
  2207. if exec != nil {
  2208. if exec[0]["content"] == nil {
  2209. mapR := make(map[string]interface{})
  2210. mapR["layout"] = layout
  2211. mjson, _ := json.Marshal(mapR)
  2212. mString := string(mjson)
  2213. exec1, err3 := tx.Exec("update dashboard set content=? where pastureid=? and id=?", mString, pastureid, dashboard_id)
  2214. if err3 != nil {
  2215. println("3", err3.Error())
  2216. appG.Response(http.StatusOK, e.ERROR, err3.Error())
  2217. } else {
  2218. appG.Response(http.StatusOK, e.SUCCESS, exec1)
  2219. }
  2220. } else {
  2221. var mapR map[string]interface{}
  2222. err2 := json.Unmarshal([]byte(exec[0]["content"].(string)), &mapR)
  2223. if err1 != nil {
  2224. fmt.Println("JsonToMapDemo err: ", err2)
  2225. }
  2226. mapR["layout"] = layout
  2227. mjson, _ := json.Marshal(mapR)
  2228. mString := string(mjson)
  2229. exec1, err3 := tx.Exec("update dashboard set content=? where pastureid=? and id=?", mString, pastureid, dashboard_id)
  2230. if err3 != nil {
  2231. println("3", err3.Error())
  2232. appG.Response(http.StatusOK, e.ERROR, err3.Error())
  2233. } else {
  2234. appG.Response(http.StatusOK, e.SUCCESS, exec1)
  2235. }
  2236. }
  2237. } else {
  2238. appG.Response(http.StatusOK, e.ERROR, "未找到对应的仪表盘")
  2239. }
  2240. }
  2241. }
  2242. func ExecSQL(c *gin.Context) {
  2243. appG := app.Gin{C: c}
  2244. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  2245. fsion := gofasion.NewFasion(string(dataByte))
  2246. content := fsion.Get("content").Json()
  2247. pastureid := fsion.Get("pastureid").ValueStr()
  2248. var mapResult map[string]interface{}
  2249. err1 := json.Unmarshal([]byte(content), &mapResult)
  2250. if err1 != nil {
  2251. fmt.Println("JsonToMapDemo err: ", err1)
  2252. }
  2253. sqlstr := "select "
  2254. groupstr := " GROUP BY "
  2255. for _, value := range mapResult["selectedDimension"].([]interface{}) {
  2256. sqlstr = sqlstr + value.(map[string]interface{})["Column"].(string) + ","
  2257. groupstr = groupstr + value.(map[string]interface{})["Column"].(string) + ","
  2258. }
  2259. for _, value := range mapResult["selectedCalcul"].([]interface{}) {
  2260. if value.(map[string]interface{})["calculFunc"].(string) == "none" {
  2261. sqlstr = sqlstr + value.(map[string]interface{})["Column"].(string) + ","
  2262. groupstr = groupstr + value.(map[string]interface{})["Column"].(string) + ","
  2263. } else if value.(map[string]interface{})["calculFunc"].(string) == "custbiaozhun" {
  2264. tem := "STDDEV" + "(" + value.(map[string]interface{})["Column"].(string) + ") as " + value.(map[string]interface{})["Column"].(string)
  2265. sqlstr = sqlstr + tem + ","
  2266. }else if value.(map[string]interface{})["calculFunc"].(string) == "custbianyi" {
  2267. tem := "STDDEV" + "(" + value.(map[string]interface{})["Column"].(string) + ")/ AVG(" +value.(map[string]interface{})["Column"].(string)+")as " + value.(map[string]interface{})["Column"].(string)
  2268. sqlstr = sqlstr + tem + ","
  2269. }else {
  2270. tem := value.(map[string]interface{})["calculFunc"].(string) + "(" + value.(map[string]interface{})["Column"].(string) + ") as " + value.(map[string]interface{})["Column"].(string)
  2271. sqlstr = sqlstr + tem + ","
  2272. }
  2273. }
  2274. if _, ok := mapResult["selectedCalcul2"]; ok {
  2275. for _, value := range mapResult["selectedCalcul2"].([]interface{}) {
  2276. if value.(map[string]interface{})["calculFunc"].(string) == "none" {
  2277. sqlstr = sqlstr + value.(map[string]interface{})["Column"].(string) + ","
  2278. groupstr = groupstr + value.(map[string]interface{})["Column"].(string) + ","
  2279. }else if value.(map[string]interface{})["calculFunc"].(string) == "custbiaozhun" {
  2280. tem := "STDDEV" + "(" + value.(map[string]interface{})["Column"].(string) + ") as " + value.(map[string]interface{})["Column"].(string)
  2281. sqlstr = sqlstr + tem + ","
  2282. }else if value.(map[string]interface{})["calculFunc"].(string) == "custbianyi" {
  2283. tem := "STDDEV" + "(" + value.(map[string]interface{})["Column"].(string) + ")/ AVG(" +value.(map[string]interface{})["Column"].(string)+")as " + value.(map[string]interface{})["Column"].(string)
  2284. sqlstr = sqlstr + tem + ","
  2285. }else {
  2286. tem := value.(map[string]interface{})["calculFunc"].(string) + "(" + value.(map[string]interface{})["Column"].(string) + ") as " + value.(map[string]interface{})["Column"].(string)
  2287. sqlstr = sqlstr + tem + ","
  2288. }
  2289. }
  2290. }
  2291. sqlstr = sqlstr[0 : len(sqlstr)-1]
  2292. sqlstr = sqlstr + " from " + mapResult["dataSrc"].(string)
  2293. sqlstr = sqlstr + " where pastureid=" + pastureid
  2294. if len(mapResult["filters"].([]interface{})) > 0 {
  2295. sqlstr = sqlstr + " and "
  2296. }
  2297. println(len(mapResult["filters"].([]interface{})), sqlstr)
  2298. for _, value := range mapResult["filters"].([]interface{}) {
  2299. switch value.(map[string]interface{})["filterOperator"].(string) {
  2300. case ">", "=", "<", ">=", "<=", "!=", "like":
  2301. 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 "
  2302. case "IN":
  2303. sqlstr = sqlstr + value.(map[string]interface{})["filteCol"].(string) + " " + value.(map[string]interface{})["filterOperator"].(string) + "("
  2304. for _, value1 := range value.(map[string]interface{})["value"].(map[string]interface{})["arrValue"].([]interface{}) {
  2305. sqlstr = sqlstr + value1.(string) + ","
  2306. }
  2307. sqlstr = sqlstr[0 : len(sqlstr)-1]
  2308. sqlstr = sqlstr + ")" + " AND "
  2309. case "BETWEEN":
  2310. 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 "
  2311. }
  2312. }
  2313. if len(mapResult["filters"].([]interface{})) > 0 {
  2314. sqlstr = sqlstr[0 : len(sqlstr)-4]
  2315. }
  2316. //
  2317. groupstr = groupstr[0 : len(groupstr)-1]
  2318. sqlstr = sqlstr + groupstr + " "
  2319. if len(mapResult["orderByStrs"].([]interface{})) > 0 {
  2320. sqlstr = sqlstr + " order by "
  2321. }
  2322. //
  2323. for key, value := range mapResult["orderByStrs"].([]interface{}) {
  2324. if key == len(mapResult["orderByStrs"].([]interface{}))-1 {
  2325. sqlstr = sqlstr + value.(string) + " "
  2326. } else {
  2327. sqlstr = sqlstr + value.(string) + ","
  2328. }
  2329. }
  2330. //
  2331. sqlstr = sqlstr + " limit " + strconv.Itoa(int(mapResult["limit"].(float64)))
  2332. tx := restful.Engine.NewSession()
  2333. err := tx.Begin()
  2334. defer func() {
  2335. switch {
  2336. case err != nil:
  2337. logging.Error("tx.Begin 事务启动失败__error:", err)
  2338. if tx != nil {
  2339. tx.Rollback()
  2340. }
  2341. default:
  2342. if tx != nil {
  2343. err = tx.Commit()
  2344. }
  2345. }
  2346. if tx != nil {
  2347. tx.Close()
  2348. }
  2349. }()
  2350. exec, err := tx.SQL(sqlstr).Query().List()
  2351. if err != nil {
  2352. appG.Response(http.StatusOK, e.ERROR, err.Error())
  2353. } else {
  2354. appG.Response(http.StatusOK, e.SUCCESS, exec)
  2355. }
  2356. }
  2357. func Dashboards(c *gin.Context) {
  2358. appG := app.Gin{C: c}
  2359. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  2360. fsion := gofasion.NewFasion(string(dataByte))
  2361. sqlnamestr := fsion.Get("name").ValueStr()
  2362. //sqlnamestr1 := fsion.Get("name1").ValueStr()
  2363. offset := fsion.Get("offset").ValueDefaultInt(0)
  2364. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  2365. returntype := fsion.Get("returntype").ValueDefaultStr("map")
  2366. month := fsion.Get("month").ValueDefaultStr("map")
  2367. logging.Info("GetUpkeepPlan ", c.Keys, sqlnamestr, month)
  2368. tx := restful.Engine.NewSession()
  2369. err := tx.Begin()
  2370. defer func() {
  2371. switch {
  2372. case err != nil:
  2373. if tx != nil {
  2374. tx.Rollback()
  2375. }
  2376. default:
  2377. if tx != nil {
  2378. err = tx.Commit()
  2379. }
  2380. }
  2381. if tx != nil {
  2382. tx.Close()
  2383. }
  2384. }()
  2385. sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
  2386. //sql1, p1 := restful.GetSqlByNameDBT(sqlnamestr1, tx)
  2387. if sql != "" {
  2388. s_params := make([]interface{}, 0)
  2389. if fsion.HasKey("parammaps") {
  2390. parammaps := fsion.Get("parammaps")
  2391. paramslist := strings.Split(p, ",")
  2392. if len(paramslist) > 0 && p != "" {
  2393. for _, value := range paramslist {
  2394. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  2395. if tempv, exists := c.Get("jwt_username"); exists {
  2396. s_params = append(s_params, tempv.(string))
  2397. } else {
  2398. s_params = append(s_params, "")
  2399. }
  2400. } else {
  2401. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  2402. }
  2403. }
  2404. }
  2405. }
  2406. queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params, tx)
  2407. if err != nil {
  2408. appG.Response(http.StatusOK, e.ERROR, err.Error())
  2409. } else {
  2410. //paramslist1 := strings.Split(p1, ",")
  2411. dids := make([]interface{}, 0)
  2412. for index, value := range queryData.(map[string]interface{})["list"].([]map[string]interface{}) {
  2413. var mapResult map[string]interface{}
  2414. dids = append(dids, value["dashboard_id"])
  2415. if value["content"] != nil {
  2416. err1 := json.Unmarshal([]byte(value["content"].(string)), &mapResult)
  2417. if err1 != nil {
  2418. println("JsonToMapDemo1 err: ", err1)
  2419. }
  2420. temap := make(map[string]interface{})
  2421. tem := mapResult["layout"].([]interface{})
  2422. if v, ok := value["chartids"]; ok {
  2423. chartids := strings.Split(v.(string), ",")
  2424. for _, va := range chartids {
  2425. a := false
  2426. for _, v2 := range tem {
  2427. if v2.(map[string]interface{})["id"].(string) == va {
  2428. a = true
  2429. //println("va1======",va)
  2430. }
  2431. }
  2432. if !a {
  2433. laytem := "{\"bottomLine\":[[3,18],[15,18]],\"h\":9,\"i\":\"" +
  2434. va + "\",\"id\":\"" + va +
  2435. "\",\"moved\":false,\"topLine\":[[3,9],[15,9]],\"w\":12,\"x\":0,\"xOffSet\":15,\"y\":100,\"yOffSet\":18}"
  2436. var mapTem map[string]interface{}
  2437. err1 := json.Unmarshal([]byte(laytem), &mapTem)
  2438. if err1 != nil {
  2439. println("JsonToMapDemo err: ", err1)
  2440. }
  2441. tem = append(tem, mapTem)
  2442. }
  2443. }
  2444. temap["layout"] = tem
  2445. queryData.(map[string]interface{})["list"].([]map[string]interface{})[index]["content"] = temap
  2446. }
  2447. } else {
  2448. temap := make(map[string]interface{})
  2449. tem := make([]interface{}, 0)
  2450. if v, ok := value["chartids"]; ok {
  2451. chartids := strings.Split(v.(string), ",")
  2452. for _, va := range chartids {
  2453. laytem := "{\"bottomLine\":[[3,18],[15,18]],\"h\":9,\"i\":\"" +
  2454. va + "\",\"id\":\"" + va +
  2455. "\",\"moved\":false,\"topLine\":[[3,9],[15,9]],\"w\":12,\"x\":0,\"xOffSet\":15,\"y\":0,\"yOffSet\":18}"
  2456. var mapTem map[string]interface{}
  2457. err1 := json.Unmarshal([]byte(laytem), &mapTem)
  2458. if err1 != nil {
  2459. println("JsonToMapDemo err: ", err1)
  2460. }
  2461. tem = append(tem, mapTem)
  2462. }
  2463. temap["layout"] = tem
  2464. queryData.(map[string]interface{})["list"].([]map[string]interface{})[index]["content"] = temap
  2465. }
  2466. }
  2467. }
  2468. queryData.(map[string]interface{})["order"] = dids
  2469. queryData.(map[string]interface{})["dashboards"] = queryData.(map[string]interface{})["list"]
  2470. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  2471. }
  2472. } else {
  2473. appG.Response(http.StatusOK, e.SUCCESS, nil)
  2474. }
  2475. }
  2476. func HttpPostData(url, RequestMethod, parammaps string, tx *xorm.Session) string {
  2477. fsion := gofasion.NewFasion(parammaps)
  2478. sqlnamestr := fsion.Get("name").ValueStr()
  2479. sqlnamestr1 := fsion.Get("name1").ValueStr()
  2480. offset := fsion.Get("offset").ValueDefaultInt(0)
  2481. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  2482. returntype := fsion.Get("returntype").ValueDefaultStr("map")
  2483. sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
  2484. sql1, p1 := restful.GetSqlByNameDBT(sqlnamestr1, tx)
  2485. body := []byte("")
  2486. if sql != "" {
  2487. s_params := make([]interface{}, 0)
  2488. if fsion.HasKey("parammaps") {
  2489. parammaps := fsion.Get("parammaps")
  2490. paramslist := strings.Split(p, ",")
  2491. if len(paramslist) > 0 && p != "" {
  2492. for _, value := range paramslist {
  2493. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  2494. }
  2495. }
  2496. }
  2497. queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params, tx)
  2498. if err != nil {
  2499. } else {
  2500. paramslist1 := strings.Split(p1, ",")
  2501. for index, value := range queryData.(map[string]interface{})["list"].([]map[string]interface{}) {
  2502. s_params1 := make([]interface{}, 0)
  2503. if len(paramslist1) > 0 && p1 != "" {
  2504. for _, v := range paramslist1 {
  2505. s_params1 = append(s_params1, value[strings.ToLower(strings.Trim(v, " "))])
  2506. }
  2507. }
  2508. arr, _ := tx.SQL(sql1, s_params1...).QueryString() //获取
  2509. queryData.(map[string]interface{})["list"].([]map[string]interface{})[index]["arrList"] = arr
  2510. body, _ = json.Marshal(queryData)
  2511. }
  2512. }
  2513. }
  2514. bs := bytes.NewBuffer(body)
  2515. client := &http.Client{}
  2516. //body1 := bytes.NewBuffer([]byte("{\"username\":\"00028\",\"password\":\"123456\"}"))
  2517. req, err := http.NewRequest(RequestMethod,
  2518. url,
  2519. bs,
  2520. )
  2521. if err != nil {
  2522. }
  2523. req.Header.Set("Content-Type", "application/json;charset=utf-8")
  2524. req.Header.Set("token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IjAwMDI4IiwicGFzc3dvcmQiOiJlMTBhZGMzOTQ5YmE1OWFiYmU1NmUwNTdmMjBmODgzZSIsImV4cCI6MTYxOTM4NjU0MiwiaXNzIjoiaHR0cHM6Ly9naXRodWIuY29tL2twdHl1bi9nby1hZG1pbi8ifQ.sJwnE9HTOVnDNOaeHqOQzi7cSydYkWS4uQHxtjY7UMY")
  2525. if err != nil {
  2526. // handle error
  2527. }
  2528. resp, err := client.Do(req)
  2529. if err != nil {
  2530. return ""
  2531. }
  2532. defer resp.Body.Close()
  2533. result_body, err := ioutil.ReadAll(resp.Body)
  2534. if err != nil {
  2535. return ""
  2536. }
  2537. fmt.Println(string(result_body))
  2538. return ""
  2539. }