db.go 121 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590
  1. package api
  2. import (
  3. "database/sql"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/astaxie/beego/logs"
  7. "io/ioutil"
  8. "log"
  9. "math"
  10. "net/http"
  11. "os"
  12. "path"
  13. "regexp"
  14. "strconv"
  15. "strings"
  16. "time"
  17. "kpt.xdmy/apiserver/service"
  18. "github.com/360EntSecGroup-Skylar/excelize"
  19. "github.com/jmoiron/sqlx"
  20. "github.com/pkg/errors"
  21. // "github.com/360EntSecGroup-Skylar/excelize"
  22. "github.com/Anderson-Lu/gofasion/gofasion"
  23. "github.com/axetroy/go-fs"
  24. "github.com/gin-gonic/gin"
  25. "github.com/tealeg/xlsx"
  26. // "github.com/xormplus/xorm"
  27. "kpt.xdmy/apiserver/routers/restful"
  28. "kpt.xdmy/pkg/app"
  29. "kpt.xdmy/pkg/e"
  30. "kpt.xdmy/pkg/logging"
  31. "kpt.xdmy/pkg/setting"
  32. "kpt.xdmy/pkg/util"
  33. )
  34. // @Summary 根据SQL执行得到数据集
  35. // @Tags getData
  36. // @Accept json
  37. // @Produce json
  38. // @Param sql query string true "sql"
  39. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  40. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  41. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  42. // @Router /data/getdata [POST]
  43. func GetData(c *gin.Context) {
  44. appG := app.Gin{C: c}
  45. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  46. fsion := gofasion.NewFasion(string(dataByte))
  47. sqlstr := fsion.Get("sql").ValueStr()
  48. offset := fsion.Get("offset").ValueDefaultInt(0)
  49. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  50. returntype := fsion.Get("returntype").ValueDefaultStr("map")
  51. queryData, err := getDataBySql(sqlstr, offset, pagecount, returntype, nil)
  52. if err != nil {
  53. appG.Response(http.StatusOK, e.ERROR, err.Error())
  54. } else {
  55. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  56. }
  57. }
  58. func Testpartitions(c *gin.Context) {
  59. appG := app.Gin{C: c}
  60. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  61. fsion := gofasion.NewFasion(string(dataByte))
  62. databaseName := fsion.Get("databaseName").ValueStr() //获取新数据库名称
  63. user := fsion.Get("user").ValueStr() //获取新数据库用户
  64. passWord := fsion.Get("passWord").ValueStr() //获取新数据库名称
  65. host := fsion.Get("host").ValueStr() //获取新数据库名称
  66. port := fsion.Get("port").ValueStr()
  67. sqlstr := "SELECT sql FROM sql_new "
  68. var sqlname string
  69. err1 := restful.BasicList(sqlstr, nil, &sqlname)
  70. if err1 != nil {
  71. appG.Response(http.StatusOK, e.SUCCESS, "失败:"+err1.Error())
  72. }
  73. sqlstrs := strings.Split(sqlname, ";") //分割sql
  74. // sqlstrs := strings.Split(p["sql"].(string), ";") //分割sql
  75. connecting := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", user, passWord, host, port, "mysql")
  76. mydb, err := sql.Open("mysql", connecting) //连接新连接
  77. if err != nil {
  78. println("err1", err.Error())
  79. }
  80. _, err = mydb.Exec("CREATE DATABASE IF NOT EXISTS `" + databaseName + "`") // 创建数据库
  81. if err != nil {
  82. println("err2", err.Error())
  83. }
  84. mydb.Close()
  85. connecting = fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", user, passWord, host, port, databaseName) //连接新数据库,创建表格
  86. mydb, err = sql.Open("mysql", connecting)
  87. if err != nil {
  88. println("err3", err.Error())
  89. }
  90. defer mydb.Close()
  91. if err == nil {
  92. mydb.SetMaxOpenConns(10)
  93. mydb.SetMaxIdleConns(10)
  94. }
  95. errmsg := ""
  96. if err == nil {
  97. //tx ,_ :=mydb.Begin()
  98. for _, sqlstr := range sqlstrs {
  99. //println("sqlstr---",sqlstr)
  100. if sqlstr == "" {
  101. continue
  102. }
  103. _, err = mydb.Exec(sqlstr)
  104. if err != nil {
  105. println("err4", err.Error())
  106. errmsg = err.Error()
  107. }
  108. }
  109. }
  110. if errmsg == "" {
  111. appG.Response(http.StatusOK, e.SUCCESS, "成功"+databaseName)
  112. } else {
  113. appG.Response(http.StatusOK, e.SUCCESS, "失败"+errmsg)
  114. }
  115. }
  116. func TestData(c *gin.Context) {
  117. appG := app.Gin{C: c}
  118. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  119. fsion := gofasion.NewFasion(string(dataByte))
  120. sqlstr := fsion.Get("sql").ValueStr()
  121. token := ""
  122. if tempv, exists := c.Get("jwt_username"); exists {
  123. token = tempv.(string)
  124. }
  125. appG.Response(http.StatusOK, e.SUCCESS, "你录入的名字是:"+sqlstr+";token:"+token)
  126. }
  127. // GetDataByName
  128. // @Summary 根据APISQL表中SQL执行得到数据集
  129. // @Tags GetDataByName
  130. // @Accept json
  131. // @Produce json
  132. // @Param sqlname body string true "sqlname"
  133. // @Param offset body int true "offset"
  134. // @Param pagecount body int true "pagecount"
  135. // @Param returntype body string true "returntype"
  136. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  137. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  138. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  139. // @Router /data/GetDataByName [POST]
  140. func GetDataByName(c *gin.Context) {
  141. appG := app.Gin{C: c}
  142. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  143. fsion := gofasion.NewFasion(string(dataByte))
  144. sqlnamestr := fsion.Get("name").ValueStr()
  145. offset := fsion.Get("offset").ValueDefaultInt(0)
  146. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  147. returntype := fsion.Get("returntype").ValueDefaultStr("map")
  148. getTotal := fsion.Get("getTotal").ValueStr()
  149. paramsTest := fsion.Get("parammaps")
  150. if sqlnamestr == "getBuyeCode" {
  151. pagecount = 9999
  152. }
  153. fmt.Println(paramsTest.Get("partClass").ValueStr())
  154. sql, p := restful.GetSqlByNameDBT(sqlnamestr, nil)
  155. if sql != "" {
  156. s_params := make([]interface{}, 0)
  157. if fsion.HasKey("parammaps") {
  158. parammaps := fsion.Get("parammaps")
  159. if sqlnamestr != "getNoMesList" && sqlnamestr != "getNoMesCount" {
  160. logging.Info("GetDataByName", c.Keys, c.Request.RemoteAddr, sqlnamestr, parammaps.ValueStr())
  161. }
  162. paramslist := strings.Split(p, ",")
  163. if len(paramslist) > 0 && p != "" {
  164. for _, value := range paramslist {
  165. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  166. if tempv, exists := c.Get("jwt_username"); exists {
  167. s_params = append(s_params, tempv.(string))
  168. } else {
  169. s_params = append(s_params, "")
  170. }
  171. } else {
  172. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  173. }
  174. }
  175. }
  176. } else if fsion.HasKey("params") {
  177. params := fsion.Get("params").Array()
  178. logging.Info("GetDataByName", c.Keys, c.Request.RemoteAddr, sqlnamestr, params)
  179. for _, v_params := range params {
  180. s_params = append(s_params, v_params.ValueStr())
  181. }
  182. }
  183. if returntype == "xlsx" {
  184. var xlsxfile *xlsx.File
  185. xlsxfile, _ = restful.QueryByXlsx(sql, s_params)
  186. //c.File("c:/dd.xlsx")
  187. c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  188. c.Header("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
  189. c.Header("Content-Transfer-Encoding", "binary")
  190. _ = xlsxfile.Write(c.Writer)
  191. } else {
  192. // queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params, tx)
  193. queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params)
  194. if getTotal == "total3" {
  195. totalData := make(map[string]interface{})
  196. queryData1 := queryData.(map[string]interface{})
  197. totalData["total3"] = queryData1["total"]
  198. appG.Response(http.StatusOK, e.SUCCESS, totalData)
  199. return
  200. }
  201. if sqlnamestr == "getMenuByRole" {
  202. var list []interface{}
  203. data := make(map[string]interface{})
  204. for _, item := range queryData.(map[string]interface{})["lists"].([]map[string]interface{}) {
  205. fmt.Println(item["menu_id"])
  206. list = append(list, item["menu_id"])
  207. }
  208. data["menu_id"] = list
  209. queryData.(map[string]interface{})["lists"] = data
  210. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  211. return
  212. } else if sqlnamestr == "getRoleByUser" {
  213. var list []interface{}
  214. data := make(map[string]interface{})
  215. for _, item := range queryData.(map[string]interface{})["lists"].([]map[string]interface{}) {
  216. fmt.Println(item["role_id"])
  217. list = append(list, item["role_id"])
  218. }
  219. data["role_id"] = list
  220. queryData.(map[string]interface{})["lists"] = data
  221. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  222. return
  223. } else if sqlnamestr == "updateEQStartStop" {
  224. tx, err := restful.Dbs.Beginx()
  225. defer func() {
  226. switch {
  227. case err != nil:
  228. fmt.Println("__error:", err)
  229. if tx != nil {
  230. tx.Rollback()
  231. }
  232. default:
  233. if tx != nil {
  234. err = tx.Commit()
  235. }
  236. }
  237. }()
  238. parammaps := fsion.Get("parammaps")
  239. username, _ := c.Get("jwt_username")
  240. queryData, _ := getDataBySqlT("select maintenance from equipment where id = ? ", 0, 0, "", []interface{}{parammaps.Get("id").ValueStr()})
  241. for _, value := range queryData.(map[string]interface{})["list"].([]map[string]interface{}) {
  242. for _, maintenance := range strings.Split(value["maintenance"].(string), ",") {
  243. if parammaps.Get("SSPstatue").ValueStr() == "启用" {
  244. _, err := tx.Exec(` INSERT INTO wxworkmsg(DATE,userid,msg,formcode,TYPE,note)values(now(),
  245. ?,concat("设备启停通知:\n设备资产编号:",(select eqCode from equipment where id = ? ),"\n用途:",(select purpose from equipment where id = ? ),"\n由报修人",(select empname from emp where empcode = ? limit 1),"启用\n时间:",now()),(select eqCode from equipment where id = ? ),1,null)`,
  246. maintenance, parammaps.Get("id").ValueStr(), parammaps.Get("id").ValueStr(), username, parammaps.Get("id").ValueStr())
  247. fmt.Println(err)
  248. } else {
  249. _, err := tx.Exec(` INSERT INTO wxworkmsg(DATE,userid,msg,formcode,TYPE,note)values(now(),
  250. ?,concat("设备启停通知:\n设备资产编号:",(select eqCode from equipment where id = ? ),"\n用途:",(select purpose from equipment where id = ? ),"\n由报修人",(select empname from emp where empcode = ? limit 1 ),"停机\n时间:",now()),(select eqCode from equipment where id = ? ),1,null)`,
  251. maintenance, parammaps.Get("id").ValueStr(), parammaps.Get("id").ValueStr(), username, parammaps.Get("id").ValueStr())
  252. fmt.Println(err)
  253. }
  254. }
  255. }
  256. } else if sqlnamestr == "UkdoneRatePasture" {
  257. }
  258. if err != nil {
  259. logging.Error("GetDataByName err: ", err)
  260. msg := geterrmsg(err.Error())
  261. appG.Response(http.StatusOK, e.ERROR, msg)
  262. } else {
  263. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  264. }
  265. }
  266. } else {
  267. appG.Response(http.StatusOK, e.SUCCESS, nil)
  268. }
  269. defer c.Request.Body.Close()
  270. }
  271. // @Summary 根据APISQL表中SQL执行得到数据集
  272. // @Tags GetDataByName
  273. // @Accept json
  274. // @Produce json
  275. // @Param sqlname body string true "sqlname"
  276. // @Param offset body int true "offset"
  277. // @Param pagecount body int true "pagecount"
  278. // @Param returntype body string true "returntype"
  279. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  280. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  281. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  282. // @Router /data/GetDataByName [POST]
  283. func EasSync(c *gin.Context) {
  284. appG := app.Gin{C: c}
  285. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  286. fsion := gofasion.NewFasion(string(dataByte))
  287. typeIn := fsion.Get("typeIn").ValueDefaultInt(0)
  288. billCode := fsion.Get("billCode").ValueStr()
  289. logging.Error("EasSync date: ", typeIn, billCode)
  290. //typeInstr := fsion.Get("typeIn").ValueStr()
  291. //println(typeInstr,typeIn)
  292. // 用于判断备件干什么的和eas同步
  293. err := util.EASBillSync(typeIn, billCode, "1")
  294. if err != nil {
  295. logging.Error("EasSync err: ", err)
  296. appG.Response(http.StatusOK, e.ERROR, err.Error())
  297. } else {
  298. appG.Response(http.StatusOK, e.SUCCESS, "成功")
  299. }
  300. }
  301. func GetDataByNameOPEN(c *gin.Context) {
  302. appG := app.Gin{C: c}
  303. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  304. fsion := gofasion.NewFasion(string(dataByte))
  305. sqlnamestr := fsion.Get("name").ValueStr()
  306. sqlnamestr = sqlnamestr + "OPEN"
  307. offset := fsion.Get("offset").ValueDefaultInt(0)
  308. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  309. returntype := fsion.Get("returntype").ValueDefaultStr("map")
  310. sql, p := restful.GetSqlByNameDBT(sqlnamestr, nil)
  311. //fmt.Println("sql========\n",sqlnamestr,sql)
  312. if sql != "" {
  313. s_params := make([]interface{}, 0)
  314. if fsion.HasKey("parammaps") {
  315. parammaps := fsion.Get("parammaps")
  316. if sqlnamestr != "getNoMesList" && sqlnamestr != "getNoMesCount" {
  317. logging.Info("GetDataByName", c.Keys, c.Request.RemoteAddr, sqlnamestr, parammaps.ValueStr())
  318. }
  319. paramslist := strings.Split(p, ",")
  320. if len(paramslist) > 0 && p != "" {
  321. for _, value := range paramslist {
  322. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  323. if tempv, exists := c.Get("jwt_username"); exists {
  324. s_params = append(s_params, tempv.(string))
  325. } else {
  326. s_params = append(s_params, "")
  327. }
  328. } else {
  329. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  330. }
  331. }
  332. }
  333. } else if fsion.HasKey("params") {
  334. params := fsion.Get("params").Array()
  335. logging.Info("GetDataByName", c.Keys, c.Request.RemoteAddr, sqlnamestr, params)
  336. for _, v_params := range params {
  337. s_params = append(s_params, v_params.ValueStr())
  338. }
  339. }
  340. if returntype == "xlsx" {
  341. var xlsxfile *xlsx.File
  342. xlsxfile, _ = restful.QueryByXlsx(sql, s_params)
  343. //c.File("c:/dd.xlsx")
  344. c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  345. c.Header("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
  346. c.Header("Content-Transfer-Encoding", "binary")
  347. _ = xlsxfile.Write(c.Writer)
  348. } else {
  349. // queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params, tx)
  350. queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params)
  351. if err != nil {
  352. logging.Error("GetDataByName err: ", err)
  353. msg := geterrmsg(err.Error())
  354. appG.Response(http.StatusOK, e.ERROR, msg)
  355. } else {
  356. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  357. }
  358. }
  359. } else {
  360. appG.Response(http.StatusOK, e.SUCCESS, nil)
  361. }
  362. }
  363. func geterrmsg(errstr string) (msgstr string) {
  364. var hzRegexp = regexp.MustCompile("^[\u4e00-\u9fa5]$") // 判断是否为汉字
  365. rs := []rune(errstr)
  366. if len(rs) == 0 {
  367. msgstr = errstr
  368. return
  369. }
  370. if hzRegexp.MatchString(string(rs[0])) {
  371. msgstr = errstr
  372. return
  373. }
  374. if strings.Contains(errstr, "Duplicate entry") {
  375. strs := strings.Split(errstr, ` key '`)
  376. if len(strs) > 1 {
  377. if len(strs[len(strs)-1]) > 1 {
  378. errstr = "Duplicate entry :" + strs[len(strs)-1]
  379. }
  380. }
  381. }
  382. msg, err := restful.MapStrList("SELECT msg FROM err_msg where err = ? ", errstr)
  383. if err != nil {
  384. msgstr = errstr
  385. return
  386. }
  387. if msg == nil || len(msg) == 0 {
  388. var param []interface{}
  389. param = append(param, errstr, errstr)
  390. go func() {
  391. tx, err := restful.Dbs.Beginx()
  392. defer func() {
  393. switch {
  394. case err != nil:
  395. logging.Error("tx.Begin 事务启动失败__error:", err)
  396. if tx != nil {
  397. tx.Rollback()
  398. }
  399. default:
  400. if tx != nil {
  401. err = tx.Commit()
  402. }
  403. }
  404. if tx != nil {
  405. }
  406. }()
  407. _, err = restful.ExecQueryT("insert into err_msg(err,msg) VALUES(?,?) ON DUPLICATE KEY UPDATE err=err", param, tx)
  408. if err != nil {
  409. logging.Error("insert into err_msg(err,msg) err", err)
  410. }
  411. }()
  412. msgstr = errstr
  413. } else {
  414. msgstr = msg[0]["msg"]
  415. }
  416. return
  417. }
  418. // @Summary 根据APISQL表中SQL执行得到数据集
  419. // @Tags GetDataByNameForm
  420. // @Accept json
  421. // @Produce json
  422. // @Param sqlname body json true "sqlname"
  423. // @Param offset query int true "offset"
  424. // @Param pagecount query int true "pagecount"
  425. // @Param returntype query string true "returntype"
  426. // @Param s formData json true "ss"
  427. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  428. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  429. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  430. // @Router /data/GetDataByNameForm [POST]
  431. func GetDataByNameForm(c *gin.Context) {
  432. appG := app.Gin{C: c}
  433. //sqlnamestr := c.PostForm("measureNumber")
  434. //dataByte, _ := ioutil.ReadAll(c.Request.Body)
  435. //fsion := gofasion.NewFasion(string(dataByte))
  436. //sqlnamestr := fsion.Get("name").ValueStr()
  437. //offset := fsion.Get("offset").ValueInt()
  438. //pagecount := fsion.Get("pagecount").ValueInt()
  439. //returntype := fsion.Get("returntype").ValueStr()
  440. //params := fsion.Get("params").Array()
  441. c.Request.ParseForm()
  442. params := c.Request.Form
  443. offset := 0
  444. pageSize_ := 0
  445. returntype := params.Get("page")
  446. if returntype == "" {
  447. returntype = "0"
  448. }
  449. if tempv, exists := c.Get("jwt_username"); exists {
  450. params.Set("JwtUserName", tempv.(string))
  451. } else {
  452. params.Set("JwtUserName", "")
  453. }
  454. sqlnamestr := params.Get("name")
  455. logging.Info("GetDataByNameForm ", c.Keys, sqlnamestr)
  456. s_params := make([]interface{}, 0)
  457. if returntype == "1" {
  458. pageNum, error := strconv.Atoi(params.Get("pageNum"))
  459. if error != nil {
  460. appG.ResponseEq(http.StatusOK, e.ERROR, 0, "页码不是整数")
  461. }
  462. pageSize, error := strconv.Atoi(params.Get("pageSize"))
  463. if error != nil {
  464. appG.ResponseEq(http.StatusOK, e.ERROR, 0, "每页行数不是整数")
  465. }
  466. pageSize_ = pageSize
  467. offset = pageNum
  468. }
  469. sql, p := restful.GetSqlByNameDB(sqlnamestr)
  470. paramslist := strings.Split(p, ",")
  471. if len(paramslist) > 0 && p != "" {
  472. for _, value := range paramslist {
  473. s_params = append(s_params, params.Get(strings.Trim(value, " ")))
  474. }
  475. }
  476. if sql != "" {
  477. if returntype == "xlsx" {
  478. var xlsxfile *xlsx.File
  479. xlsxfile, _ = restful.QueryByXlsx(sql, s_params)
  480. c.Header("Content-Type", "application/octet-stream")
  481. c.Header("Content-Disposition", "attachment; filename="+sqlnamestr+".xlsx")
  482. c.Header("Content-Transfer-Encoding", "binary")
  483. _ = xlsxfile.Write(c.Writer)
  484. } else {
  485. queryData, err := getDataBySql(sql, offset, pageSize_, returntype, s_params)
  486. if err != nil {
  487. appG.ResponseEq(http.StatusOK, e.ERROR, 1, err.Error())
  488. } else {
  489. appG.ResponseEq(http.StatusOK, e.SUCCESS, 0, queryData)
  490. }
  491. }
  492. } else {
  493. appG.ResponseEq(http.StatusOK, e.SUCCESS, 0, "后台没有数据接口")
  494. }
  495. }
  496. // @Summary 递归获取所有
  497. // @Tags menu
  498. // @Accept json
  499. // @Produce json
  500. // @Param Ton query string true "Ton"
  501. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  502. // @Router /authdata/GetRoleMenus [GET]
  503. func GetRecuDataByName(c *gin.Context) {
  504. appG := app.Gin{C: c}
  505. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  506. fsion := gofasion.NewFasion(string(dataByte))
  507. sqlnamestr := fsion.Get("name").ValueStr()
  508. parentidname := fsion.Get("idname").ValueStr()
  509. sql, p := restful.GetSqlByNameDB(sqlnamestr)
  510. params := make(map[string]interface{})
  511. s_params := make([]interface{}, 0)
  512. if fsion.HasKey("params") {
  513. for _, v_params := range fsion.Get("params").Array() {
  514. s_params = append(s_params, v_params.ValueStr())
  515. }
  516. params["params"] = s_params
  517. } else {
  518. jparams := fsion.Get("parammaps")
  519. paramslist := strings.Split(p, ",")
  520. if len(paramslist) > 0 && p != "" {
  521. for _, value := range paramslist {
  522. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  523. if tempv, exists := c.Get("jwt_username"); exists {
  524. params[value] = tempv.(string)
  525. } else {
  526. params[value] = ""
  527. }
  528. } else {
  529. params[value] = jparams.Get(strings.Trim(value, " ")).ValueStr()
  530. }
  531. }
  532. }
  533. }
  534. queryData, err := GetRecuData_BySql(sql, p, parentidname, params, fsion.HasKey("params"))
  535. logging.Info("sqlname parammaps", c.Keys, c.Request.RemoteAddr, sqlnamestr, params)
  536. if err != nil {
  537. appG.Response(http.StatusOK, e.ERROR, err.Error())
  538. }
  539. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  540. }
  541. // @Summary 根据APISQL表中SQL执行得到数据集
  542. // @Tags GetDataByNames
  543. // @Accept json
  544. // @Produce json
  545. // @RequestBody sqlname query string true "sqlname"
  546. // @Param offset query int true "offset"
  547. // @Param pagecount query int true "pagecount"
  548. // @Param returntype query string true "returntype"
  549. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  550. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  551. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  552. // @Router /data/GetDataByNames [POST]
  553. func GetDataByNames(c *gin.Context) {
  554. appG := app.Gin{C: c}
  555. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  556. fsion := gofasion.NewFasion(string(dataByte))
  557. sqlParams := fsion.Array()
  558. queryData := make(map[string]interface{})
  559. for _, v := range sqlParams {
  560. fsion2 := gofasion.NewFasion(v.Json())
  561. logging.Info("GetDataByNames", c.Keys, fsion2.Get("name").ValueStr(), c.Request.RemoteAddr)
  562. // p是sql表中的sql语句中的变量差数格式
  563. sql, p := restful.GetSqlByNameDB(fsion2.Get("name").ValueStr())
  564. if sql == "" {
  565. errorm := make(map[string]interface{})
  566. errorm["code"] = e.ERROR
  567. errorm["message"] = "sql没找到"
  568. queryData[fsion2.Get("name").ValueStr()] = errorm
  569. continue
  570. } else if sql != "" {
  571. offset := fsion2.Get("offset").ValueInt()
  572. pagecount := fsion2.Get("pagecount").ValueInt()
  573. returntype := fsion2.Get("returntype").ValueStr()
  574. // s_params 是用来存储sql中需要的参数
  575. s_params := make([]interface{}, 0)
  576. // 这边是判断是传过来的是参数格式如果是map格式的是需要在apisql表中查询params字段
  577. if fsion2.HasKey("parammaps") {
  578. parammaps := fsion2.Get("parammaps")
  579. paramslist := strings.Split(p, ",")
  580. if len(paramslist) > 0 && p != "" {
  581. for _, value := range paramslist {
  582. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  583. if tempv, exists := c.Get("jwt_username"); exists {
  584. s_params = append(s_params, tempv.(string))
  585. } else {
  586. s_params = append(s_params, "")
  587. }
  588. } else {
  589. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  590. }
  591. }
  592. }
  593. } else if fsion2.HasKey("params") {
  594. params := fsion2.Get("params").Array()
  595. for _, v_params := range params {
  596. s_params = append(s_params, v_params.ValueStr())
  597. }
  598. }
  599. queryData1, err := getDataBySql(sql, offset, pagecount, returntype, s_params)
  600. if err != nil {
  601. errorm := make(map[string]interface{})
  602. errorm["code"] = e.ERROR
  603. errorm["message"] = err.Error()
  604. queryData[fsion2.Get("name").ValueStr()] = errorm
  605. logging.Error("GetDataByNames err: ", err)
  606. continue
  607. } else {
  608. queryData[fsion2.Get("name").ValueStr()] = queryData1
  609. }
  610. }
  611. }
  612. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  613. }
  614. // @Summary 根据APISQL表中SQL执行得到数据集
  615. // @Tags PostDataByNameForm
  616. // @Accept json
  617. // @Produce json
  618. // @Param sqlname query string true "sqlname"
  619. // @Param offset query int true "offset"
  620. // @Param pagecount query int true "pagecount"
  621. // @Param returntype query string true "returntype"
  622. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  623. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误朱红彬彬"}"
  624. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  625. // @Router /data/PostDataByNameForm [POST]
  626. func PostDataByNameForm(c *gin.Context) {
  627. appG := app.Gin{C: c}
  628. c.Request.ParseForm()
  629. params := c.Request.Form
  630. sqlnamestr := params.Get("name")
  631. logging.Info("PostDataByNameForm ", c.Keys, sqlnamestr)
  632. s_params := make([]interface{}, 0)
  633. sql, p := restful.GetSqlByNameDB(sqlnamestr)
  634. paramslist := strings.Split(p, ",")
  635. if len(paramslist) > 0 {
  636. for _, value := range paramslist {
  637. s_params = append(s_params, params.Get(strings.Trim(value, " ")))
  638. }
  639. }
  640. if sql != "" {
  641. queryData, err := execDataBySql(sql, s_params)
  642. if err != nil {
  643. appG.ResponseEq(http.StatusOK, e.ERROR, 1, err.Error())
  644. } else {
  645. appG.ResponseEq(http.StatusOK, e.SUCCESS, 0, queryData)
  646. }
  647. } else {
  648. appG.ResponseEq(http.StatusOK, e.SUCCESS, 0, "后台没有数据接口")
  649. }
  650. }
  651. func GetReportform(c *gin.Context) {
  652. appG := app.Gin{C: c}
  653. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  654. fsion := gofasion.NewFasion(string(dataByte))
  655. sqlnamestr := fsion.Get("name").ValueStr()
  656. parammaps := fsion.Get("parammaps")
  657. logging.Info("GetReportform ", c.Keys, sqlnamestr, parammaps)
  658. queryData, _ := praseReportform(sqlnamestr, parammaps)
  659. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  660. }
  661. func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion) (queryData map[string]interface{}, err error) {
  662. switch sqlnamestr {
  663. case "getpSumNow", "getpSumNowWater", "getpSumNowElec", "getpSumNowDiesel":
  664. queryData, err = getpSumNow(sqlnamestr, parammaps)
  665. case "getPastureSumMonth", "getPastureSumMonthWater", "getPastureSumMonthElec", "getPastureSumMonthDiesel":
  666. queryData, err = getPastureSumMonth(sqlnamestr, parammaps)
  667. case "getPastureSumDayWater", "getPastureSumDayElec", "getPastureSumDayDiesel":
  668. queryData, err = getPastureSumDay(sqlnamestr, parammaps)
  669. case "getPastureSumDay":
  670. queryData, err = getPastureSumDay1(sqlnamestr, parammaps)
  671. case "geteqclassSumMonth", "geteqclassSumMonthWater", "geteqclassSumMonthElec", "geteqclassSumMonthDiesel":
  672. queryData, err = geteqclassSumMonth(sqlnamestr, parammaps)
  673. case "geteCowWaterList", "geteCowElecList", "geteCowDieselList", "geteCowMaintainList", "geteCowAllList":
  674. queryData, err = geteCow(sqlnamestr, parammaps)
  675. case "geteCowWaterMonthList", "geteCowElecMonthList", "geteCowDieselMonthList", "geteCowMaintainMonthList", "geteCowAllMonthList":
  676. queryData, err = geteCowMonth(sqlnamestr, parammaps)
  677. case "getEqRunSurveyListPasture":
  678. queryData, err = getEqRunSurveyListPasture(sqlnamestr, parammaps)
  679. case "geteqclassFeeSum", "geteqclassFeeSumPasture":
  680. queryData, err = geteqclassFeeSum(sqlnamestr, parammaps)
  681. case "getEqRunSurveyListDay":
  682. queryData, err = getEqRunSurveyListDay(sqlnamestr, parammaps)
  683. case "getReportEqCostYear":
  684. queryData, err = geteqCostYear(sqlnamestr, parammaps)
  685. case "getReportEqCostMonth":
  686. queryData, err = geteqCostMonth(sqlnamestr, parammaps)
  687. case "homepagePastureInfor":
  688. queryData, err = homepagePastureInfor(sqlnamestr, parammaps)
  689. case "homepageEqstatus":
  690. queryData, err = homepageEqstatus(sqlnamestr, parammaps)
  691. case "homepageEqRunstatueListPasture", "homepageEqRunstatueListEqclass":
  692. queryData, err = homepageEqRunstatue(sqlnamestr, parammaps)
  693. case "homepageFeeWX", "homepageFeeWater", "homepageFeeElec", "homepageFeeDiesel":
  694. queryData, err = homepageFee(sqlnamestr, parammaps)
  695. default:
  696. queryData, err = nil, nil
  697. }
  698. return
  699. }
  700. func homepageFee(sqlnamestr string, parammaps *gofasion.Fasion) (map[string]interface{}, error) {
  701. queryData := make(map[string]interface{})
  702. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  703. pastureName := parammaps.Get(strings.Trim("pastureName", " ")).ValueStr()
  704. pSumNow, err := restful.MapStrList(sqlNow, pastureName, pastureName, pastureName, pastureName, pastureName, pastureName, pastureName, pastureName, pastureName, pastureName)
  705. if err != nil {
  706. log.Default().Printf("homepageFee queryx: %v", err)
  707. }
  708. typeStr := parammaps.Get(strings.Trim("type", " ")).ValueStr()
  709. list1s := make([]string, 1)
  710. list2s := make([]string, 1)
  711. list3s := make([]string, 1)
  712. list4s := make([]string, 1)
  713. list5s := make([]string, 1)
  714. list6s := make([]string, 1)
  715. list7s := make([]string, 1)
  716. list8s := make([]string, 1)
  717. list1s[0] = typeStr
  718. for _, value := range pSumNow {
  719. list2s[0] = value["monthBudget"]
  720. list3s[0] = value["sumPrice"]
  721. list4s[0] = value["monthBudgetL"]
  722. list5s[0] = value["sumPriceL"]
  723. list6s[0] = value["monthBudget"]
  724. list7s[0] = value["sumPrice"]
  725. list8s[0] = value["cowS"]
  726. }
  727. queryData["data1"] = list1s
  728. queryData["data2"] = list2s
  729. queryData["data3"] = list3s
  730. queryData["data4"] = list4s
  731. queryData["data5"] = list5s
  732. queryData["data6"] = list6s
  733. queryData["data7"] = list7s
  734. queryData["data8"] = list8s
  735. queryData["code"] = 0
  736. queryData["message"] = "ok"
  737. return queryData, nil
  738. }
  739. func homepageEqRunstatue(sqlnamestr string, parammaps *gofasion.Fasion) (map[string]interface{}, error) {
  740. queryData := make(map[string]interface{})
  741. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  742. pastureName := parammaps.Get(strings.Trim("pastureName", " ")).ValueStr()
  743. typeStr := parammaps.Get(strings.Trim("type", " ")).ValueStr()
  744. pSumNow, _ := restful.MapStrList(sqlNow, pastureName)
  745. list1s := make([]string, 0)
  746. list2s := make([]string, 0)
  747. list3s := make([]string, 1)
  748. list3s[0] = typeStr
  749. for _, value := range pSumNow {
  750. list1s = append(list1s, value["name"])
  751. list2s = append(list2s, value["rate"])
  752. }
  753. queryData["data1"] = list1s
  754. queryData["data2"] = list2s
  755. queryData["data3"] = list3s
  756. queryData["code"] = 0
  757. queryData["message"] = "ok"
  758. return queryData, nil
  759. }
  760. func homepageEqstatus(sqlnamestr string, parammaps *gofasion.Fasion) (map[string]interface{}, error) {
  761. queryData := make(map[string]interface{})
  762. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  763. pastureName := parammaps.Get(strings.Trim("pastureName", " ")).ValueStr()
  764. pSumNow, _ := restful.MapStrList(sqlNow, pastureName, pastureName)
  765. list1s := make([]string, 0)
  766. list2s := make([]string, 0)
  767. for _, value := range pSumNow {
  768. list1s = append(list1s, value["status"])
  769. list2s = append(list2s, value["cou"])
  770. }
  771. queryData["data1"] = list1s
  772. queryData["data2"] = list2s
  773. queryData["code"] = 0
  774. queryData["message"] = "ok"
  775. return queryData, nil
  776. }
  777. func homepagePastureInfor(sqlnamestr string, parammaps *gofasion.Fasion) (map[string]interface{}, error) {
  778. queryData := make(map[string]interface{})
  779. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  780. pSumNow, _ := restful.MapStrList(sqlNow)
  781. lolalists := make([]map[string]interface{}, 0)
  782. pasturelists := make([]map[string]interface{}, 0)
  783. lolalist := make(map[string]interface{}, 1)
  784. for _, value := range pSumNow {
  785. lola := make([]string, 0)
  786. pasturelist := make(map[string]interface{}, 1)
  787. lola = append(lola, value["longitude"])
  788. lola = append(lola, value["latitude"])
  789. lolalist[value["name"]] = lola
  790. pasturelist["name"] = value["name"]
  791. pasturelist["value"] = value["name"]
  792. pasturelists = append(pasturelists, pasturelist)
  793. }
  794. lolalists = append(lolalists, lolalist)
  795. queryData["data1"] = lolalists
  796. queryData["data2"] = pasturelists
  797. queryData["code"] = 0
  798. queryData["message"] = "ok"
  799. return queryData, nil
  800. }
  801. func geteqCostMonth(sqlnamestr string, parammaps *gofasion.Fasion) (map[string]interface{}, error) {
  802. queryData := make(map[string]interface{})
  803. receiveTime := parammaps.Get(strings.Trim("receiveTime", " ")).ValueStr()
  804. eqId := parammaps.Get(strings.Trim("eqId", " ")).ValueStr()
  805. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  806. pSumNow, _ := restful.MapStrList(sqlNow, receiveTime, eqId, receiveTime, receiveTime, eqId, receiveTime, receiveTime)
  807. chartData := make(map[string]interface{})
  808. months := []string{}
  809. upkeepCost := []string{}
  810. repireCost := []string{}
  811. //lastTotal,nowTotal := 0,0
  812. a := true
  813. month := ""
  814. for i := 1; i <= 12; i++ {
  815. if i < 10 {
  816. month = receiveTime + "-0" + strconv.Itoa(i)
  817. } else {
  818. month = receiveTime + "-" + strconv.Itoa(i)
  819. }
  820. months = append(months, month)
  821. for _, va := range pSumNow {
  822. if va["yearR"][5:] == month[5:] {
  823. upkeepCost = append(upkeepCost, va["Ucost"])
  824. repireCost = append(repireCost, va["Rcost"])
  825. a = false
  826. }
  827. }
  828. if a {
  829. upkeepCost = append(upkeepCost, "0")
  830. repireCost = append(repireCost, "0")
  831. }
  832. a = true
  833. }
  834. chartData["months"] = months
  835. chartData["upkeepCost"] = upkeepCost
  836. chartData["repireCost"] = repireCost
  837. queryData["chart_data"] = chartData
  838. queryData["code"] = 0
  839. queryData["message"] = "ok"
  840. return queryData, nil
  841. }
  842. func geteqCostYear(sqlnamestr string, parammaps *gofasion.Fasion) (map[string]interface{}, error) {
  843. queryData := make(map[string]interface{})
  844. //receiveTime :=parammaps.Get(strings.Trim("receiveTime", " ")).ValueStr()
  845. eqId := parammaps.Get(strings.Trim("eqId", " ")).ValueStr()
  846. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  847. pSumNow, _ := restful.MapStrList(sqlNow, eqId, eqId, eqId)
  848. //restful.M
  849. chartData := make(map[string]interface{})
  850. year := []string{}
  851. upkeepCost := []string{}
  852. repireCost := []string{}
  853. for _, va := range pSumNow {
  854. year = append(year, va["yearR"])
  855. upkeepCost = append(upkeepCost, va["Ucost"])
  856. repireCost = append(repireCost, va["Rcost"])
  857. }
  858. chartData["year"] = year
  859. chartData["upkeepCost"] = upkeepCost
  860. chartData["repireCost"] = repireCost
  861. queryData["chart_data"] = chartData
  862. queryData["code"] = 0
  863. queryData["message"] = "ok"
  864. return queryData, nil
  865. }
  866. func geteCowMonth(sqlnamestr string, parammaps *gofasion.Fasion) (map[string]interface{}, error) {
  867. queryData := make(map[string]interface{})
  868. receiveTime := parammaps.Get(strings.Trim("year", " ")).ValueStr()
  869. pastureNames := parammaps.Get(strings.Trim("pastureName", " ")).ValueStr()
  870. var pSumNow, pSumLast []map[string]string
  871. if sqlnamestr == "geteCowAllMonthList" {
  872. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  873. pSumNow, _ = restful.MapStrList(sqlNow, receiveTime, receiveTime, receiveTime, receiveTime, receiveTime, receiveTime, pastureNames)
  874. tempTime, _ := strconv.Atoi(receiveTime)
  875. receiveTimetemp := strconv.Itoa(tempTime - 1)
  876. pSumLast, _ = restful.MapStrList(sqlNow, receiveTimetemp, receiveTimetemp, receiveTimetemp, receiveTimetemp, receiveTimetemp, receiveTimetemp, pastureNames)
  877. } else {
  878. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  879. pSumNow, _ = restful.MapStrList(sqlNow, receiveTime, receiveTime, receiveTime, pastureNames)
  880. tempTime, _ := strconv.Atoi(receiveTime)
  881. receiveTimetemp := strconv.Itoa(tempTime - 1)
  882. pSumLast, _ = restful.MapStrList(sqlNow, receiveTimetemp, receiveTimetemp, receiveTimetemp, pastureNames)
  883. }
  884. chartData := make(map[string]interface{})
  885. months := []string{}
  886. lastYear := []string{}
  887. nowYear := []string{}
  888. budgetYear := []string{}
  889. //lastTotal,nowTotal := 0,0
  890. a, b := true, true
  891. month := ""
  892. for i := 1; i <= 12; i++ {
  893. if i < 10 {
  894. month = receiveTime + "-0" + strconv.Itoa(i)
  895. } else {
  896. month = receiveTime + "-" + strconv.Itoa(i)
  897. }
  898. months = append(months, month)
  899. for _, va := range pSumNow {
  900. if va["month"][5:] == month[5:] {
  901. nowYear = append(nowYear, va["psum"])
  902. budgetYear = append(budgetYear, va["lsum"])
  903. a = false
  904. }
  905. }
  906. for _, va := range pSumLast {
  907. if va["month"][5:] == month[5:] {
  908. lastYear = append(lastYear, va["psum"])
  909. b = false
  910. }
  911. }
  912. if a {
  913. nowYear = append(nowYear, "0")
  914. budgetYear = append(budgetYear, "0")
  915. }
  916. if b {
  917. lastYear = append(lastYear, "0")
  918. }
  919. a = true
  920. b = true
  921. }
  922. chartData["months"] = months
  923. chartData["lastYear"] = lastYear
  924. chartData["nowYear"] = nowYear
  925. chartData["budgetYear"] = budgetYear
  926. queryData["chart_data"] = chartData
  927. queryData["code"] = 0
  928. queryData["message"] = "ok"
  929. return queryData, nil
  930. }
  931. func getEqRunSurveyListDay(sqlnamestr string, parammaps *gofasion.Fasion) (map[string]interface{}, error) {
  932. queryData := make(map[string]interface{})
  933. receiveTime := parammaps.Get(strings.Trim("praseTime", " ")).ValueStr()
  934. pastureNames := parammaps.Get(strings.Trim("pastureName", " ")).ValueStr()
  935. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  936. pSumNow, _ := restful.MapStrList(sqlNow, pastureNames, receiveTime)
  937. if pSumNow == nil {
  938. return nil, nil
  939. }
  940. typeName := make([]map[string]interface{}, 4)
  941. ma := make(map[string]interface{})
  942. ma1 := make(map[string]interface{})
  943. ma2 := make(map[string]interface{})
  944. ma3 := make(map[string]interface{})
  945. ma["name"] = "在用"
  946. ma["value"] = pSumNow[0]["eqUse"]
  947. typeName[0] = ma
  948. ma1["name"] = "闲置"
  949. ma1["value"] = pSumNow[0]["eqXZ"]
  950. typeName[1] = ma1
  951. ma2["name"] = "报废"
  952. ma2["value"] = pSumNow[0]["eqBF"]
  953. typeName[2] = ma2
  954. ma3["name"] = "封存"
  955. ma3["value"] = pSumNow[0]["eqFC"]
  956. typeName[3] = ma3
  957. queryData["psm"] = typeName
  958. queryData["code"] = 0
  959. queryData["total"] = pSumNow[0]["eqSum"]
  960. queryData["message"] = "ok"
  961. return queryData, nil
  962. }
  963. func getEqRunSurveyListPasture(sqlnamestr string, parammaps *gofasion.Fasion) (map[string]interface{}, error) {
  964. queryData := make(map[string]interface{})
  965. receiveTime := parammaps.Get(strings.Trim("praseTime", " ")).ValueStr()
  966. pastureNames, _ := restful.MapStrList("SELECT `name` FROM pasture order by sort")
  967. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  968. pSumNow, _ := restful.MapStrList(sqlNow, receiveTime)
  969. chartData := make(map[string]interface{})
  970. pasture := []string{}
  971. eqUse := []string{}
  972. eqXZ := []string{}
  973. eqBF := []string{}
  974. eqFC := []string{}
  975. //lastTotal,nowTotal := 0,0
  976. a := true
  977. for _, value := range pastureNames {
  978. pasture = append(pasture, value["name"])
  979. for _, va := range pSumNow {
  980. if va["pastureName"] == value["name"] {
  981. eqUset, _ := strconv.Atoi(va["eqUse"])
  982. eqSumt, _ := strconv.Atoi(va["eqSum"])
  983. eqXZt, _ := strconv.Atoi(va["eqXZ"])
  984. eqBFt, _ := strconv.Atoi(va["eqBF"])
  985. eqFCt, _ := strconv.Atoi(va["eqFC"])
  986. eqUsetem := float64(eqUset) / float64(eqSumt) * 100
  987. eqXZtem := float64(eqXZt) / float64(eqSumt) * 100
  988. eqBFtem := float64(eqBFt) / float64(eqSumt) * 100
  989. eqFCtem := float64(eqFCt) / float64(eqSumt) * 100
  990. eqUse = append(eqUse, strconv.FormatFloat(eqUsetem, 'f', 2, 64))
  991. //eqSum = append(eqSum, va["eqSum"])
  992. eqXZ = append(eqXZ, strconv.FormatFloat(eqXZtem, 'f', 2, 64))
  993. eqBF = append(eqBF, strconv.FormatFloat(eqBFtem, 'f', 2, 64))
  994. eqFC = append(eqFC, strconv.FormatFloat(eqFCtem, 'f', 2, 64))
  995. a = false
  996. }
  997. }
  998. if a {
  999. eqUse = append(eqUse, "0")
  1000. //eqSum = append(eqSum, "0")
  1001. eqXZ = append(eqXZ, "0")
  1002. eqBF = append(eqBF, "0")
  1003. eqFC = append(eqFC, "0")
  1004. }
  1005. a = true
  1006. }
  1007. chartData["pastureName"] = pasture
  1008. chartData["eqUseRate"] = eqUse
  1009. //chartData["eqSum"] = eqSum
  1010. chartData["eqXZRate"] = eqXZ
  1011. chartData["eqBFRate"] = eqBF
  1012. chartData["eqFCRate"] = eqFC
  1013. queryData["chart_data"] = chartData
  1014. queryData["code"] = 0
  1015. queryData["message"] = "ok"
  1016. return queryData, nil
  1017. }
  1018. func geteqclassFeeSum(sqlnamestr string, parammaps *gofasion.Fasion) (map[string]interface{}, error) {
  1019. queryData := make(map[string]interface{})
  1020. year := parammaps.Get(strings.Trim("year", " ")).ValueStr()
  1021. month := parammaps.Get(strings.Trim("month", " ")).ValueStr()
  1022. eqClassName := parammaps.Get(strings.Trim("eqClassName", " ")).ValueStr()
  1023. PastureName := parammaps.Get("PastureName").ValueStr()
  1024. DepartmentName := parammaps.Get("DepartmentName").ValueStr()
  1025. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  1026. pSumNow, err := restful.MapStrList(sqlNow, year, month, eqClassName, eqClassName, PastureName, PastureName, DepartmentName, DepartmentName)
  1027. if len(pSumNow) == 0 {
  1028. log.Default().Printf("geteqclassFeeSum result is empty")
  1029. }
  1030. fmt.Println(err)
  1031. chartData := make(map[string]interface{})
  1032. eqUse := []string{}
  1033. eqXZ := []string{}
  1034. for _, va := range pSumNow {
  1035. eqUse = append(eqUse, va["psum"])
  1036. eqXZ = append(eqXZ, va["typeName"])
  1037. }
  1038. chartData["data1"] = eqUse
  1039. chartData["data2"] = eqXZ
  1040. queryData["chart_data"] = chartData
  1041. queryData["code"] = 0
  1042. queryData["message"] = "ok"
  1043. return queryData, nil
  1044. }
  1045. func geteqclassSumMonth(sqlnamestr string, parammaps *gofasion.Fasion) (map[string]interface{}, error) {
  1046. queryData := make(map[string]interface{})
  1047. receiveTime := parammaps.Get(strings.Trim("receiveTime", " ")).ValueStr()
  1048. pastureNames := parammaps.Get(strings.Trim("pastureName", " ")).ValueStr()
  1049. deptName := parammaps.Get(strings.Trim("deptName", " ")).ValueStr()
  1050. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  1051. pSumNow, _ := restful.MapStrList(sqlNow, pastureNames, receiveTime, deptName)
  1052. if len(pSumNow) == 0 {
  1053. log.Default().Printf("geteqclassSumMonth result is empty")
  1054. }
  1055. chartData := make(map[string]interface{})
  1056. typeName := []string{}
  1057. eqCost := []string{}
  1058. for _, va := range pSumNow {
  1059. typeName = append(typeName, va["typeName"])
  1060. eqCost = append(eqCost, va["psum"])
  1061. }
  1062. chartData["typeName"] = typeName
  1063. chartData["eqCost"] = eqCost
  1064. queryData["chart_data"] = chartData
  1065. queryData["code"] = 0
  1066. queryData["message"] = "ok"
  1067. return queryData, nil
  1068. }
  1069. func getPastureSumDay(sqlnamestr string, parammaps *gofasion.Fasion) (map[string]interface{}, error) {
  1070. queryData := make(map[string]interface{})
  1071. receiveTime := parammaps.Get(strings.Trim("receiveTime", " ")).ValueStr()
  1072. pastureNames := parammaps.Get(strings.Trim("pastureName", " ")).ValueStr()
  1073. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  1074. pSumNow, _ := restful.MapStrList(sqlNow, pastureNames, receiveTime)
  1075. if len(pSumNow) == 0 {
  1076. log.Default().Printf("getPastureSumDay result is empty")
  1077. }
  1078. tempTime, _ := strconv.Atoi(receiveTime[:4])
  1079. receiveTimetemp := strconv.Itoa(tempTime-1) + receiveTime[4:]
  1080. pSumLast, _ := restful.MapStrList(sqlNow, pastureNames, receiveTimetemp)
  1081. chartData := make(map[string]interface{})
  1082. months := []string{}
  1083. lastYear := []string{}
  1084. nowYear := []string{}
  1085. //lastTotal,nowTotal := 0,0
  1086. a, b := true, true
  1087. month := ""
  1088. dayCount := GetMonthCount(receiveTime)
  1089. for i := 1; i <= dayCount; i++ {
  1090. if i < 10 {
  1091. month = receiveTime + "-0" + strconv.Itoa(i)
  1092. } else {
  1093. month = receiveTime + "-" + strconv.Itoa(i)
  1094. }
  1095. months = append(months, strconv.Itoa(i))
  1096. for _, va := range pSumNow {
  1097. if va["month"][8:] == month[8:] {
  1098. nowYear = append(nowYear, va["psum"])
  1099. a = false
  1100. }
  1101. }
  1102. for _, va := range pSumLast {
  1103. if va["month"][8:] == month[8:] {
  1104. lastYear = append(lastYear, va["psum"])
  1105. b = false
  1106. }
  1107. }
  1108. if a {
  1109. if month[:] > time.Now().Format("2006-01-02") {
  1110. nowYear = append(nowYear, "")
  1111. } else {
  1112. nowYear = append(nowYear, "0")
  1113. }
  1114. }
  1115. if b {
  1116. lastYear = append(lastYear, "0")
  1117. }
  1118. a = true
  1119. b = true
  1120. }
  1121. chartData["day"] = months
  1122. chartData["lastYear"] = lastYear
  1123. chartData["nowYear"] = nowYear
  1124. queryData["chart_data"] = chartData
  1125. queryData["code"] = 0
  1126. queryData["message"] = "ok"
  1127. return queryData, nil
  1128. }
  1129. func getPastureSumDay1(sqlnamestr string, parammaps *gofasion.Fasion) (map[string]interface{}, error) {
  1130. queryData := make(map[string]interface{})
  1131. receiveTime := parammaps.Get(strings.Trim("receiveTime", " ")).ValueStr()
  1132. pastureNames := parammaps.Get(strings.Trim("pastureName", " ")).ValueStr()
  1133. departmentName := parammaps.Get(strings.Trim("departmentName", " ")).ValueStr()
  1134. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  1135. pSumNow, _ := restful.MapStrList(sqlNow, pastureNames, receiveTime, departmentName, departmentName, departmentName, departmentName, departmentName, departmentName)
  1136. if len(pSumNow) == 0 {
  1137. log.Default().Printf("getPastureSumDay1query is empty")
  1138. }
  1139. tempTime, _ := strconv.Atoi(receiveTime[:4])
  1140. receiveTimetemp := strconv.Itoa(tempTime-1) + receiveTime[4:]
  1141. pSumLast, _ := restful.MapStrList(sqlNow, pastureNames, receiveTimetemp, departmentName, departmentName, departmentName, departmentName, departmentName, departmentName)
  1142. if len(pSumLast) == 0 {
  1143. log.Default().Printf("getPastureSumDay1 query is empty")
  1144. }
  1145. chartData := make(map[string]interface{})
  1146. months := []string{}
  1147. lastYear := []string{}
  1148. nowYear := []string{}
  1149. a, b := true, true
  1150. month := ""
  1151. for i := 1; i <= 12; i++ {
  1152. if i < 10 {
  1153. month = receiveTime[:4] + "-0" + strconv.Itoa(i)
  1154. } else {
  1155. month = receiveTime[:4] + "-" + strconv.Itoa(i)
  1156. }
  1157. months = append(months, month)
  1158. for _, va := range pSumNow {
  1159. if va["month"][5:7] == month[5:] {
  1160. nowYear = append(nowYear, va["psum"])
  1161. a = false
  1162. }
  1163. }
  1164. for _, va := range pSumLast {
  1165. if va["month"][5:7] == month[5:] {
  1166. lastYear = append(lastYear, va["psum"])
  1167. b = false
  1168. }
  1169. }
  1170. if a {
  1171. if month[:] > time.Now().Format("2006-01") {
  1172. nowYear = append(nowYear, "")
  1173. } else {
  1174. nowYear = append(nowYear, "0")
  1175. }
  1176. }
  1177. if b {
  1178. lastYear = append(lastYear, "0")
  1179. }
  1180. a = true
  1181. b = true
  1182. }
  1183. chartData["months"] = months
  1184. chartData["lastYear"] = lastYear
  1185. chartData["nowYear"] = nowYear
  1186. queryData["chart_data"] = chartData
  1187. queryData["code"] = 0
  1188. queryData["message"] = "ok"
  1189. return queryData, nil
  1190. }
  1191. func GetMonthCount(receiveTime string) (days int) {
  1192. year, _ := strconv.Atoi(receiveTime[:4])
  1193. month, _ := strconv.Atoi(receiveTime[5:])
  1194. if month != 2 {
  1195. if month == 4 || month == 6 || month == 9 || month == 11 {
  1196. days = 30
  1197. } else {
  1198. days = 31
  1199. }
  1200. } else {
  1201. if ((year%4) == 0 && (year%100) != 0) || (year%400) == 0 {
  1202. days = 29
  1203. } else {
  1204. days = 28
  1205. }
  1206. }
  1207. return
  1208. }
  1209. func getPastureSumMonth(sqlnamestr string, parammaps *gofasion.Fasion) (map[string]interface{}, error) {
  1210. queryData := make(map[string]interface{})
  1211. receiveTime := parammaps.Get(strings.Trim("receiveTime", " ")).ValueStr()
  1212. pastureNames := parammaps.Get(strings.Trim("pastureName", " ")).ValueStr()
  1213. departmentName := parammaps.Get(strings.Trim("departmentName", " ")).ValueStr()
  1214. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  1215. var pSumNow []map[string]string
  1216. if sqlnamestr == "getPastureSumMonth" {
  1217. pSumNow, _ = restful.MapStrList(sqlNow, pastureNames, receiveTime, departmentName, departmentName, departmentName, departmentName, departmentName, departmentName)
  1218. } else {
  1219. pSumNow, _ = restful.MapStrList(sqlNow, pastureNames, receiveTime)
  1220. }
  1221. tempTime, _ := strconv.Atoi(receiveTime)
  1222. receiveTimetemp := strconv.Itoa(tempTime - 1)
  1223. var pSumLast []map[string]string
  1224. if sqlnamestr == "getPastureSumMonth" {
  1225. pSumLast, _ = restful.MapStrList(sqlNow, pastureNames, receiveTimetemp, departmentName, departmentName, departmentName, departmentName, departmentName, departmentName)
  1226. } else {
  1227. pSumLast, _ = restful.MapStrList(sqlNow, pastureNames, receiveTimetemp)
  1228. }
  1229. chartData := make(map[string]interface{})
  1230. months := []string{}
  1231. lastYear := []string{}
  1232. nowYear := []string{}
  1233. //lastTotal,nowTotal := 0,0
  1234. a, b := true, true
  1235. month := ""
  1236. for i := 1; i <= 12; i++ {
  1237. if i < 10 {
  1238. month = receiveTime + "-0" + strconv.Itoa(i)
  1239. } else {
  1240. month = receiveTime + "-" + strconv.Itoa(i)
  1241. }
  1242. months = append(months, month)
  1243. for _, va := range pSumNow {
  1244. if va["month"][5:] == month[5:] {
  1245. nowYear = append(nowYear, va["psum"])
  1246. a = false
  1247. }
  1248. }
  1249. for _, va := range pSumLast {
  1250. if va["month"][5:] == month[5:] {
  1251. lastYear = append(lastYear, va["psum"])
  1252. b = false
  1253. }
  1254. }
  1255. if a {
  1256. if month[:] > time.Now().Format("2006-01") {
  1257. nowYear = append(nowYear, "")
  1258. } else {
  1259. nowYear = append(nowYear, "0")
  1260. }
  1261. }
  1262. if b {
  1263. lastYear = append(lastYear, "0")
  1264. }
  1265. a = true
  1266. b = true
  1267. }
  1268. chartData["months"] = months
  1269. chartData["lastYear"] = lastYear
  1270. chartData["nowYear"] = nowYear
  1271. queryData["chart_data"] = chartData
  1272. queryData["code"] = 0
  1273. queryData["message"] = "ok"
  1274. return queryData, nil
  1275. }
  1276. func geteCow(sqlnamestr string, parammaps *gofasion.Fasion) (map[string]interface{}, error) {
  1277. queryData := make(map[string]interface{})
  1278. receiveTime := parammaps.Get(strings.Trim("year", " ")).ValueStr()
  1279. pastureNames, _ := restful.MapStrList("SELECT `name` FROM pasture where `name` <> '现代牧业' and vendor = 1 and" +
  1280. " id not in(620,1238,1239,1240,1241,1242,1243,1244) order by sort ")
  1281. var pSumNow, pSumLast []map[string]string
  1282. rTime := ""
  1283. if sqlnamestr == "geteCowAllList" {
  1284. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  1285. if receiveTime == time.Now().Format("2006") {
  1286. rTime = time.Now().Format("2006-01-02")
  1287. } else {
  1288. rTime = receiveTime + "-12-31"
  1289. }
  1290. pSumNow, _ = restful.MapStrList(sqlNow, receiveTime, rTime, receiveTime, rTime, receiveTime, rTime, receiveTime, rTime, receiveTime, rTime, receiveTime, rTime)
  1291. if receiveTime == time.Now().Format("2006") {
  1292. rTime = time.Now().AddDate(-1, 0, 0).Format("2006-01-02")
  1293. } else {
  1294. rTime = receiveTime + "-12-31"
  1295. }
  1296. receiveTimei, _ := strconv.Atoi(receiveTime)
  1297. receiveTime = strconv.Itoa(receiveTimei - 1)
  1298. pSumLast, _ = restful.MapStrList(sqlNow, receiveTime, rTime, receiveTime, rTime, receiveTime, rTime, receiveTime, rTime, receiveTime, rTime, receiveTime, rTime)
  1299. } else {
  1300. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  1301. if receiveTime == time.Now().Format("2006") {
  1302. rTime = time.Now().Format("2006-01-02")
  1303. } else {
  1304. rTime = receiveTime + "-12-31"
  1305. }
  1306. pSumNow, _ = restful.MapStrList(sqlNow, receiveTime, rTime, receiveTime, rTime, receiveTime, rTime)
  1307. if receiveTime == time.Now().Format("2006") {
  1308. rTime = time.Now().AddDate(-1, 0, 0).Format("2006-01-02")
  1309. } else {
  1310. rTime = receiveTime + "-12-31"
  1311. }
  1312. receiveTimei, _ := strconv.Atoi(receiveTime)
  1313. receiveTime = strconv.Itoa(receiveTimei - 1)
  1314. pSumLast, _ = restful.MapStrList(sqlNow, receiveTime, rTime, receiveTime, rTime, receiveTime, rTime)
  1315. }
  1316. chartData := make(map[string]interface{})
  1317. pasture := []string{}
  1318. lastYear := []string{}
  1319. nowYear := []string{}
  1320. budgetYear := []string{}
  1321. //lastTotal,nowTotal := 0,0
  1322. //var pastureList []string
  1323. for _, va := range pSumNow {
  1324. b := true
  1325. nowYear = append(nowYear, va["psum"])
  1326. budgetYear = append(budgetYear, va["lsum"])
  1327. fmt.Println(va["psum"])
  1328. for _, va1 := range pSumLast {
  1329. if va1["name"] == va["name"] {
  1330. lastYear = append(lastYear, va1["psum"])
  1331. b = false
  1332. }
  1333. }
  1334. if b {
  1335. lastYear = append(lastYear, "0.00")
  1336. }
  1337. pasture = append(pasture, va["name"])
  1338. //pastureList = append(pastureList, va["name"])
  1339. }
  1340. for _, value := range pastureNames {
  1341. a, b, exist := true, true, false
  1342. for _, pasturename := range pasture {
  1343. if value["name"] == pasturename {
  1344. exist = true
  1345. break
  1346. }
  1347. }
  1348. if !exist {
  1349. //for _, va := range pSumNow {
  1350. // if va["name"] == value["name"] {
  1351. // nowYear = append(nowYear, va["psum"])
  1352. // budgetYear = append(budgetYear, va["lsum"])
  1353. // a = false
  1354. // }
  1355. //}
  1356. for _, va := range pSumLast {
  1357. if va["name"] == value["name"] {
  1358. lastYear = append(lastYear, va["psum"])
  1359. b = false
  1360. }
  1361. }
  1362. if a {
  1363. nowYear = append(nowYear, "0.0000")
  1364. budgetYear = append(budgetYear, "0.0000")
  1365. }
  1366. if b {
  1367. lastYear = append(lastYear, "0.0000")
  1368. }
  1369. pasture = append(pasture, value["name"])
  1370. }
  1371. //
  1372. //a = true
  1373. //b = true
  1374. }
  1375. chartData["pasture"] = pasture
  1376. chartData["lastYear"] = lastYear
  1377. chartData["nowYear"] = nowYear
  1378. chartData["budgetYear"] = budgetYear
  1379. queryData["chart_data"] = chartData
  1380. queryData["code"] = 0
  1381. queryData["message"] = "ok"
  1382. return queryData, nil
  1383. }
  1384. func getpSumNow(sqlnamestr string, parammaps *gofasion.Fasion) (map[string]interface{}, error) {
  1385. queryData := make(map[string]interface{})
  1386. receiveTime := parammaps.Get(strings.Trim("receiveTime", " ")).ValueStr()
  1387. departmentName := parammaps.Get(strings.Trim("departmentName", " ")).ValueStr()
  1388. center := parammaps.Get("center").ValueStr()
  1389. pastureNames, _ := restful.MapStrList("SELECT `name` FROM pasture where `name` <> '现代牧业' and (center = ? or ? = '' ) order by sort", center, center)
  1390. rTime := ""
  1391. sqlNow, _ := restful.GetSqlByNameDB(sqlnamestr)
  1392. var pSumNow []map[string]string
  1393. if sqlnamestr == "getpSumNow" {
  1394. pSumNow, _ = restful.MapStrList(sqlNow, rTime, rTime, receiveTime, receiveTime, departmentName, departmentName, departmentName, departmentName, departmentName, center, center)
  1395. } else {
  1396. pSumNow, _ = restful.MapStrList(sqlNow, rTime, rTime, receiveTime, center, center)
  1397. }
  1398. //pSumNow, _ := restful.MapStrList(sqlNow, rTime, rTime, receiveTime,departmentName,departmentName,departmentName,departmentName,departmentName,departmentName)
  1399. receiveTimei, _ := strconv.Atoi(receiveTime)
  1400. if receiveTime == time.Now().Format("2006") {
  1401. rTime = time.Now().AddDate(-1, 0, 0).Format("2006-01-02")
  1402. } else {
  1403. rTime = receiveTime + "-12-31"
  1404. }
  1405. receiveTime = strconv.Itoa(receiveTimei - 1)
  1406. var pSumLast []map[string]string
  1407. if sqlnamestr == "getpSumNow" {
  1408. pSumLast, _ = restful.MapStrList(sqlNow, rTime, rTime, receiveTime, receiveTime, departmentName, departmentName, departmentName, departmentName, departmentName, center, center)
  1409. } else {
  1410. pSumLast, _ = restful.MapStrList(sqlNow, rTime, rTime, receiveTime)
  1411. }
  1412. //pSumLast, _ = restful.MapStrList(sqlNow, rTime, rTime, receiveTime,departmentName,departmentName,departmentName,departmentName,departmentName,departmentName)
  1413. chartData := make(map[string]interface{})
  1414. pasture := []string{}
  1415. lastYear := []string{}
  1416. nowYear := []string{}
  1417. //lastTotal,nowTotal := 0,0
  1418. a, b := true, true
  1419. for _, value := range pastureNames {
  1420. pasture = append(pasture, value["name"])
  1421. for _, va := range pSumNow {
  1422. if va["name"] == value["name"] {
  1423. nowYear = append(nowYear, va["psum"])
  1424. a = false
  1425. }
  1426. }
  1427. for _, va := range pSumLast {
  1428. if va["name"] == value["name"] {
  1429. lastYear = append(lastYear, va["psum"])
  1430. b = false
  1431. }
  1432. }
  1433. if a {
  1434. nowYear = append(nowYear, "0")
  1435. }
  1436. if b {
  1437. lastYear = append(lastYear, "0")
  1438. }
  1439. a = true
  1440. b = true
  1441. }
  1442. chartData["pasture"] = pasture
  1443. chartData["lastYear"] = lastYear
  1444. chartData["nowYear"] = nowYear
  1445. queryData["chart_data"] = chartData
  1446. queryData["code"] = 0
  1447. queryData["message"] = "ok"
  1448. return queryData, nil
  1449. }
  1450. func GetUpkeepPlan(c *gin.Context) {
  1451. appG := app.Gin{C: c}
  1452. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  1453. fsion := gofasion.NewFasion(string(dataByte))
  1454. sqlnamestr := fsion.Get("name").ValueStr()
  1455. offset := fsion.Get("offset").ValueDefaultInt(0)
  1456. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  1457. returntype := fsion.Get("returntype").ValueDefaultStr("map")
  1458. month := fsion.Get("month").ValueDefaultStr("map")
  1459. logging.Info("GetUpkeepPlan ", c.Keys, sqlnamestr, month)
  1460. sql, p := restful.GetSqlByNameDBT(sqlnamestr, nil)
  1461. if sql != "" {
  1462. s_params := make([]interface{}, 0)
  1463. if fsion.HasKey("parammaps") {
  1464. parammaps := fsion.Get("parammaps")
  1465. paramslist := strings.Split(p, ",")
  1466. if len(paramslist) > 0 && p != "" {
  1467. for _, value := range paramslist {
  1468. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  1469. if tempv, exists := c.Get("jwt_username"); exists {
  1470. s_params = append(s_params, tempv.(string))
  1471. } else {
  1472. s_params = append(s_params, "")
  1473. }
  1474. } else {
  1475. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  1476. }
  1477. }
  1478. }
  1479. } else if fsion.HasKey("params") {
  1480. params := fsion.Get("params").Array()
  1481. for _, v_params := range params {
  1482. s_params = append(s_params, v_params.ValueStr())
  1483. }
  1484. }
  1485. if returntype == "xlsx" {
  1486. var xlsxfile *xlsx.File
  1487. xlsxfile, _ = restful.QueryByXlsx(sql, s_params)
  1488. //c.File("c:/dd.xlsx")
  1489. c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  1490. c.Header("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
  1491. c.Header("Content-Transfer-Encoding", "binary")
  1492. _ = xlsxfile.Write(c.Writer)
  1493. } else {
  1494. // queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params, tx)
  1495. queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params)
  1496. if err != nil {
  1497. appG.Response(http.StatusOK, e.ERROR, err.Error())
  1498. } else {
  1499. for index, value := range queryData.(map[string]interface{})["list"].([]map[string]interface{}) {
  1500. if v, ok := value["id"]; ok {
  1501. //month = "2020-03"
  1502. seviceplans, _ := restful.MapStrList("SELECT seviceplan.* FROM seviceplan WHERE seviceplan.eqId = ? AND (seviceplan.month=? OR (SELECT COUNT(*) FROM bigupkeep WHERE seviceplanId = seviceplan.`id` AND plantime BETWEEN CONCAT(?,'-01') AND CONCAT(?,'-31'))>0) ", v, month, month, month) //获取保养计划
  1503. if seviceplans != nil {
  1504. for _, va := range seviceplans { //根据保养计划获取保养单
  1505. //day,_ :=strconv.Atoi(va["day"])
  1506. bigupkeeps, _ := restful.MapStrList("SELECT * FROM bigupkeep where seviceplanId = ? and plantime between concat(?,'-01') and concat(?,'-31') ", va["id"], month, month) //获取保养计划中的保养单
  1507. //buk := make(map[string]map[string]string)
  1508. for _, bu := range bigupkeeps { //日期为key ,保养单为value 存到map中
  1509. jstr := ""
  1510. if bu["plantime"][8:9] == "0" {
  1511. jstr = "m" + bu["plantime"][9:]
  1512. } else {
  1513. jstr = "m" + bu["plantime"][8:]
  1514. }
  1515. if bu["flowCompeleted"] < "2" && bu["plantime"] < time.Now().Add(-24*time.Hour).Format("2006-01-02") { //如果保养状态是0并且小于当前日期 则状态已延期2
  1516. queryData.(map[string]interface{})["list"].([]map[string]interface{})[index][jstr] = va["upkeepName"] + "#" + va["id"] + "#2" + "#" + bu["id"] + "#" + bu["pushbackId"]
  1517. } else {
  1518. if bu["flowCompeleted"] >= "2" {
  1519. queryData.(map[string]interface{})["list"].([]map[string]interface{})[index][jstr] = va["upkeepName"] + "#" + va["id"] + "#1" + "#" + bu["id"] + "#" + bu["pushbackId"]
  1520. } else {
  1521. queryData.(map[string]interface{})["list"].([]map[string]interface{})[index][jstr] = va["upkeepName"] + "#" + va["id"] + "#0" + "#" + bu["id"] + "#" + bu["pushbackId"]
  1522. }
  1523. }
  1524. queryData.(map[string]interface{})["list"].([]map[string]interface{})[index]["month"] = va["month"] // 导出报表时,报表中需要显示月份
  1525. }
  1526. }
  1527. }
  1528. }
  1529. }
  1530. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  1531. }
  1532. }
  1533. } else {
  1534. appG.Response(http.StatusOK, e.SUCCESS, nil)
  1535. }
  1536. }
  1537. func GetAccount(c *gin.Context) {
  1538. appG := app.Gin{C: c}
  1539. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  1540. fsion := gofasion.NewFasion(string(dataByte))
  1541. sqlnamestr := fsion.Get("name").ValueStr()
  1542. offset := fsion.Get("offset").ValueDefaultInt(0)
  1543. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  1544. returntype := fsion.Get("returntype").ValueDefaultStr("map")
  1545. sql, p := restful.GetSqlByNameDBT(sqlnamestr, nil)
  1546. //fmt.Println("sql========\n",sqlnamestr,sql)
  1547. if sql != "" {
  1548. s_params := make([]interface{}, 0)
  1549. if fsion.HasKey("parammaps") {
  1550. parammaps := fsion.Get("parammaps")
  1551. if sqlnamestr != "getNoMesList" && sqlnamestr != "getNoMesCount" {
  1552. logging.Info("GetDataByName", c.Keys, c.Request.RemoteAddr, sqlnamestr, parammaps.ValueStr())
  1553. }
  1554. paramslist := strings.Split(p, ",")
  1555. if len(paramslist) > 0 && p != "" {
  1556. for _, value := range paramslist {
  1557. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  1558. if tempv, exists := c.Get("jwt_username"); exists {
  1559. s_params = append(s_params, tempv.(string))
  1560. } else {
  1561. s_params = append(s_params, "")
  1562. }
  1563. } else {
  1564. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  1565. }
  1566. }
  1567. fmt.Println("params parse end")
  1568. }
  1569. } else if fsion.HasKey("params") {
  1570. params := fsion.Get("params").Array()
  1571. logging.Info("GetDataByName", c.Keys, c.Request.RemoteAddr, sqlnamestr, params)
  1572. for _, v_params := range params {
  1573. s_params = append(s_params, v_params.ValueStr())
  1574. }
  1575. }
  1576. if returntype == "xlsx" {
  1577. var xlsxfile *xlsx.File
  1578. xlsxfile, _ = restful.QueryByXlsx(sql, s_params)
  1579. //c.File("c:/dd.xlsx")
  1580. c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  1581. c.Header("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
  1582. c.Header("Content-Transfer-Encoding", "binary")
  1583. _ = xlsxfile.Write(c.Writer)
  1584. } else {
  1585. // queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params, tx)
  1586. queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params)
  1587. if err != nil {
  1588. logging.Error("GetDataByName err: ", err)
  1589. msg := geterrmsg(err.Error())
  1590. appG.Response(http.StatusOK, e.ERROR, msg)
  1591. //appG.Response(http.StatusOK, e.ERROR, err.Error())
  1592. } else {
  1593. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  1594. }
  1595. }
  1596. } else {
  1597. appG.Response(http.StatusOK, e.SUCCESS, nil)
  1598. }
  1599. }
  1600. // @Summary 根据APISQL表中SQL执行得到数据集
  1601. // @Tags PostDataByName
  1602. // @Accept json
  1603. // @Produce json
  1604. // @Param sqlname query string true "sqlname"
  1605. // @Param offset query int true "offset"
  1606. // @Param pagecount query int true "pagecount"
  1607. // @Param returntype query string true "returntype"
  1608. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  1609. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  1610. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  1611. // @Router /data/PostDataByName [POST]
  1612. func PostDataByName(c *gin.Context) {
  1613. appG := app.Gin{C: c}
  1614. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  1615. fsion := gofasion.NewFasion(string(dataByte))
  1616. sqlnamestr := fsion.Get("name").ValueStr()
  1617. parammaps := fsion.Get("parammaps")
  1618. if sqlnamestr == "partsCharge" && parammaps.Get("statue").ValueInt() == 1 {
  1619. //fmt.Println("jinlaile")
  1620. defer func() {
  1621. go util.EASBillSync(5, fsion.Get("parammaps").Get("id").ValueStr(), fsion.Get("parammaps").Get("statue").ValueStr())
  1622. }()
  1623. //go CheckEASWebServiceParts(fsion.Get("parammaps").Get("statue").ValueStr(),fsion.Get("parammaps").Get("id").ValueStr())
  1624. }
  1625. s_params := make([]interface{}, 0)
  1626. tx, err := restful.Dbs.Beginx()
  1627. defer func() {
  1628. switch {
  1629. case err != nil:
  1630. fmt.Println("__error:", err)
  1631. if tx != nil {
  1632. tx.Rollback()
  1633. }
  1634. default:
  1635. if tx != nil {
  1636. err = tx.Commit()
  1637. }
  1638. }
  1639. }()
  1640. sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
  1641. if sql != "" {
  1642. if fsion.HasKey("parammaps") {
  1643. parammaps := fsion.Get("parammaps")
  1644. logging.Info("PostDataByName ", c.Keys, c.Request.RemoteAddr, sqlnamestr, parammaps.ValueStr())
  1645. paramslist := strings.Split(p, ",")
  1646. if len(paramslist) > 0 && p != "" {
  1647. for _, value := range paramslist {
  1648. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  1649. if tempv, exists := c.Get("jwt_username"); exists {
  1650. s_params = append(s_params, tempv.(string))
  1651. } else {
  1652. s_params = append(s_params, "")
  1653. }
  1654. } else {
  1655. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  1656. }
  1657. }
  1658. }
  1659. } else if fsion.HasKey("params") {
  1660. params := fsion.Get("params").Array()
  1661. logging.Info("PostDataByName ", c.Keys, c.Request.RemoteAddr, sqlnamestr, params)
  1662. for _, v_params := range params {
  1663. s_params = append(s_params, v_params.ValueStr())
  1664. }
  1665. }
  1666. queryData, err := execDataBySqlT(sql, s_params, tx)
  1667. if err != nil {
  1668. logging.Error("PostDataByName err: ", err)
  1669. //appG.Response(http.StatusOK, e.ERROR, err.Error())
  1670. msg := geterrmsg(err.Error())
  1671. appG.Response(http.StatusOK, e.ERROR, msg)
  1672. } else {
  1673. if sqlnamestr == "updateEQStartStop" {
  1674. parammaps := fsion.Get("parammaps")
  1675. username, _ := c.Get("jwt_username")
  1676. queryData, _ := getDataBySqlT("select maintenance from equipment where id = ? ", 0, 0, "", []interface{}{parammaps.Get("id").ValueStr()})
  1677. for _, value := range queryData.(map[string]interface{})["list"].([]map[string]interface{}) {
  1678. for _, maintenance := range strings.Split(value["maintenance"].(string), ",") {
  1679. if parammaps.Get("SSPstatue").ValueStr() == "启用" {
  1680. _, err := tx.Exec(` INSERT INTO wxworkmsg(DATE,userid,msg,formcode,TYPE,note)values(now(),
  1681. ?,concat("设备启停通知:\n设备资产编号:",(select eqCode from equipment where id = ? ),"\n用途:",(select purpose from equipment where id = ? ),"\n由报修人",(select empname from emp where empcode = ? limit 1),"启用\n时间:",now()),(select eqCode from equipment where id = ? ),1,null)`,
  1682. maintenance, parammaps.Get("id").ValueStr(), parammaps.Get("id").ValueStr(), username, parammaps.Get("id").ValueStr())
  1683. fmt.Println(err)
  1684. } else {
  1685. _, err := tx.Exec(` INSERT INTO wxworkmsg(DATE,userid,msg,formcode,TYPE,note)values(now(),
  1686. ?,concat("设备启停通知:\n设备资产编号:",(select eqCode from equipment where id = ? ),"\n用途:",(select purpose from equipment where id = ? ),"\n由报修人",(select empname from emp where empcode = ? limit 1 ),"停机\n时间:",now()),(select eqCode from equipment where id = ? ),1,null)`,
  1687. maintenance, parammaps.Get("id").ValueStr(), parammaps.Get("id").ValueStr(), username, parammaps.Get("id").ValueStr())
  1688. fmt.Println(err)
  1689. }
  1690. }
  1691. }
  1692. } else if restful.GetUserVendor(c.MustGet("jwt_username").(string)) == 1 && (sqlnamestr == "updateBigbuydetailStatu" || sqlnamestr == "shutDownBigrefunddetail") {
  1693. err = service.NextProcurement(sqlnamestr, parammaps.Get("id").ValueStr(), tx)
  1694. if err != nil {
  1695. appG.Response(http.StatusOK, e.ERROR, err.Error())
  1696. return
  1697. }
  1698. }
  1699. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  1700. }
  1701. } else {
  1702. appG.Response(http.StatusOK, e.SUCCESS, nil)
  1703. }
  1704. }
  1705. func PostThirdPartyData(c *gin.Context) {
  1706. appG := app.Gin{C: c}
  1707. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  1708. tempval_ := make(map[string]interface{})
  1709. tempval := make([]map[string]interface{}, 0)
  1710. err := json.Unmarshal(dataByte, &tempval_)
  1711. logging.Info("PostThirdPartyData ", c.Keys, c.Request.RemoteAddr, tempval_["name"])
  1712. //logging.Info("PostThirdPartyData ", c.Keys, c.Request.RemoteAddr, tempval_["name"],tempval_)
  1713. if err != nil {
  1714. logging.Error("PostThirdPartyData Unmarshal error:", err)
  1715. } else {
  1716. if v, ok := tempval_["list"].([]interface{}); ok {
  1717. for _, Tvalue := range v {
  1718. if v1, ok := Tvalue.(map[string]interface{}); ok {
  1719. tempval = append(tempval, v1)
  1720. }
  1721. }
  1722. }
  1723. tx, err := restful.Dbs.Beginx()
  1724. if err != nil {
  1725. logging.Error("tx.Begin 事务启动失败__error:", err)
  1726. }
  1727. defer func() {
  1728. switch {
  1729. case err != nil:
  1730. fmt.Println("__error:", err)
  1731. if tx != nil {
  1732. tx.Rollback()
  1733. }
  1734. default:
  1735. if tx != nil {
  1736. err = tx.Commit()
  1737. }
  1738. }
  1739. if tx != nil {
  1740. }
  1741. }()
  1742. if err == nil {
  1743. sqlname, ok := tempval_["name"]
  1744. if ok {
  1745. }
  1746. sql, p := restful.GetSqlByNameDBT(sqlname.(string), tx)
  1747. if sql == "" {
  1748. appG.Response(http.StatusOK, e.ERROR, "调用接口不存在")
  1749. }
  1750. //s_params := make([]interface{}, 0)
  1751. paramslist := strings.Split(p, ",")
  1752. resname := ""
  1753. for _, paramvalue := range tempval {
  1754. s_params := make([]interface{}, 0)
  1755. if len(paramslist) > 0 && p != "" {
  1756. for _, value := range paramslist {
  1757. s_params = append(s_params, paramvalue[value])
  1758. //fmt.Println(value,paramvalue[value])
  1759. }
  1760. }
  1761. var res []map[string]string
  1762. res, err = restful.MapStrList("select id from measure where meterNumber = ? and meterType = '电表' and isdel = 0", paramvalue["meterNumber"])
  1763. if len(res) == 0 || err != nil {
  1764. switch paramvalue["meterNumber"].(type) {
  1765. case string:
  1766. resname = paramvalue["meterNumber"].(string)
  1767. }
  1768. err = errors.New("电表不存在")
  1769. break
  1770. }
  1771. _, err = execDataBySqlT(sql, s_params, tx)
  1772. if err != nil {
  1773. switch paramvalue["meterNumber"].(type) {
  1774. case string:
  1775. resname = paramvalue["meterNumber"].(string)
  1776. }
  1777. break
  1778. }
  1779. }
  1780. if err == nil {
  1781. appG.Response(http.StatusOK, e.SUCCESS, "ok")
  1782. } else {
  1783. msg := geterrmsg(err.Error())
  1784. appG.Response(http.StatusOK, e.ERROR, msg+" "+resname)
  1785. //appG.Response(http.StatusOK, e.ERROR, err.Error())
  1786. }
  1787. }
  1788. }
  1789. if err != nil {
  1790. msg := geterrmsg(err.Error())
  1791. appG.Response(http.StatusOK, e.ERROR, msg)
  1792. //appG.Response(http.StatusOK, e.ERROR, err.Error())
  1793. }
  1794. }
  1795. func PostDataByNameOPEN(c *gin.Context) {
  1796. appG := app.Gin{C: c}
  1797. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  1798. fsion := gofasion.NewFasion(string(dataByte))
  1799. sqlnamestr := fsion.Get("name").ValueStr()
  1800. sqlnamestr = sqlnamestr + "OPEN"
  1801. s_params := make([]interface{}, 0)
  1802. tx, err := restful.Dbs.Beginx()
  1803. defer func() {
  1804. switch {
  1805. case err != nil:
  1806. fmt.Println("__error:", err)
  1807. if tx != nil {
  1808. tx.Rollback()
  1809. }
  1810. default:
  1811. if tx != nil {
  1812. err = tx.Commit()
  1813. }
  1814. }
  1815. }()
  1816. sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
  1817. if sql != "" {
  1818. if fsion.HasKey("parammaps") {
  1819. parammaps := fsion.Get("parammaps")
  1820. logging.Info("PostDataByName ", c.Keys, c.Request.RemoteAddr, sqlnamestr, parammaps.ValueStr())
  1821. paramslist := strings.Split(p, ",")
  1822. if len(paramslist) > 0 && p != "" {
  1823. for _, value := range paramslist {
  1824. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  1825. if tempv, exists := c.Get("jwt_username"); exists {
  1826. s_params = append(s_params, tempv.(string))
  1827. } else {
  1828. s_params = append(s_params, "")
  1829. }
  1830. } else {
  1831. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  1832. }
  1833. }
  1834. }
  1835. } else if fsion.HasKey("params") {
  1836. params := fsion.Get("params").Array()
  1837. logging.Info("PostDataByName ", c.Keys, c.Request.RemoteAddr, sqlnamestr, params)
  1838. for _, v_params := range params {
  1839. s_params = append(s_params, v_params.ValueStr())
  1840. }
  1841. }
  1842. queryData, err := execDataBySqlT(sql, s_params, tx)
  1843. if err != nil {
  1844. logging.Error("PostDataByName err: ", err)
  1845. //appG.Response(http.StatusOK, e.ERROR, err.Error())
  1846. msg := geterrmsg(err.Error())
  1847. appG.Response(http.StatusOK, e.ERROR, msg)
  1848. } else {
  1849. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  1850. }
  1851. } else {
  1852. appG.Response(http.StatusOK, e.SUCCESS, nil)
  1853. }
  1854. }
  1855. // @Summary 根据APISQL表中SQL执行得到数据集
  1856. // @Tags ExecDataByConfig
  1857. // @Accept json
  1858. // @Produce json
  1859. // @Param sqlname query string true "sqlname"
  1860. // @Param offset query int true "offset"
  1861. // @Param pagecount query int true "pagecount"
  1862. // @Param returntype query string true "returntype"
  1863. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  1864. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  1865. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  1866. // @Router /data/PostDataByName [POST]
  1867. func ExecDataByConfig(c *gin.Context) {
  1868. appG := app.Gin{C: c}
  1869. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  1870. tempval_ := make(map[string]interface{})
  1871. tempCommon := make(map[string]interface{})
  1872. tempval := make([]map[string]interface{}, 0)
  1873. err := json.Unmarshal(dataByte, &tempval_)
  1874. logging.Info("ExecDataByConfig ", c.Keys, c.Request.RemoteAddr, tempval_["common"], tempval_["data"])
  1875. if err != nil {
  1876. fmt.Println("error:", err)
  1877. } else {
  1878. if v, ok := tempval_["common"].(map[string]interface{}); ok {
  1879. tempCommon = v
  1880. }
  1881. if v, ok := tempval_["data"].([]interface{}); ok {
  1882. for _, Tvalue := range v {
  1883. if v1, ok := Tvalue.(map[string]interface{}); ok {
  1884. tempval = append(tempval, v1)
  1885. }
  1886. }
  1887. }
  1888. tx, err := restful.Dbs.Beginx()
  1889. if err != nil {
  1890. logging.Error("tx.Begin 事务启动失败__error:", err)
  1891. }
  1892. defer func(tx *sqlx.Tx) {
  1893. if err != nil {
  1894. fmt.Println("__error:", err)
  1895. if tx != nil {
  1896. err := tx.Rollback()
  1897. if err != nil {
  1898. fmt.Println(err)
  1899. }
  1900. }
  1901. } else {
  1902. if tx != nil {
  1903. err = tx.Commit()
  1904. }
  1905. }
  1906. }(tx)
  1907. //}
  1908. if err == nil {
  1909. if tempv, exists := c.Get("jwt_username"); exists {
  1910. tempCommon["jwt_username"] = tempv.(string)
  1911. }
  1912. for _, paramvalue := range tempval {
  1913. if _, ok := paramvalue["resultname"]; !ok {
  1914. paramvalue["resultname"] = paramvalue["name"]
  1915. }
  1916. if paramvalue["name"] == "insertBigPartrefund" {
  1917. if _, ok := paramvalue["parammaps"].(map[string]interface{})["buyeCode"]; ok {
  1918. tx.Exec(` update bigrefunddetail set statu = 2 where buyeCode = ? `, paramvalue["parammaps"].(map[string]interface{})["buyeCode"])
  1919. }
  1920. }
  1921. _, err = ExecDataParam(paramvalue, tempCommon, tempval, nil, nil, tx)
  1922. if err != nil {
  1923. logging.Error("ExecDataParam error:", err)
  1924. break
  1925. }
  1926. }
  1927. if err == nil {
  1928. vendor := restful.GetUserVendor(c.MustGet("jwt_username").(string))
  1929. err = NextService(tempval, tx, vendor)
  1930. if err != nil {
  1931. appG.Response(http.StatusOK, e.ERROR, err.Error())
  1932. return
  1933. }
  1934. if tempCommon["returnmap"] != nil && tempCommon["returnmap"] != "" {
  1935. appG.Response(http.StatusOK, e.SUCCESS, tempval)
  1936. } else {
  1937. appG.Response(http.StatusOK, e.SUCCESS, "成功执行!")
  1938. }
  1939. } else {
  1940. msg := geterrmsg(err.Error())
  1941. appG.Response(http.StatusOK, e.ERROR, msg)
  1942. }
  1943. }
  1944. }
  1945. if err != nil {
  1946. msg := geterrmsg(err.Error())
  1947. appG.Response(http.StatusOK, e.ERROR, msg)
  1948. //appG.Response(http.StatusOK, e.ERROR, err.Error())
  1949. }
  1950. // 开协程
  1951. defer func() {
  1952. if restful.GetUserVendor(c.MustGet("jwt_username").(string)) == 0 {
  1953. go BillType(tempval_)
  1954. }
  1955. }()
  1956. }
  1957. func BillType(tempval_ map[string]interface{}) {
  1958. var typein int
  1959. switch tempval_["data"].(type) {
  1960. case []interface{}:
  1961. if len(tempval_["data"].([]interface{})) > 0 {
  1962. name := tempval_["data"].([]interface{})[0].(map[string]interface{})["name"]
  1963. switch name {
  1964. case "insertBigPartlaid":
  1965. billcode := tempval_["data"].([]interface{})[0].(map[string]interface{})["parammaps"].(map[string]interface{})["laidCode"]
  1966. laidType := interfacetostringv2(tempval_["data"].([]interface{})[0].(map[string]interface{})["parammaps"].(map[string]interface{})["laidType"])
  1967. if laidType != "2" {
  1968. typein = 1
  1969. } else {
  1970. typein = 6
  1971. }
  1972. _ = util.EASBillSync(typein, billcode, "")
  1973. case "insertBigPartUse":
  1974. billcode := tempval_["data"].([]interface{})[0].(map[string]interface{})["parammaps"].(map[string]interface{})["useForm"]
  1975. usetypev := interfacetostringv2(tempval_["data"].([]interface{})[0].(map[string]interface{})["parammaps"].(map[string]interface{})["useType"])
  1976. if usetypev != "4" {
  1977. typein = 2
  1978. } else {
  1979. typein = 7
  1980. }
  1981. _ = util.EASBillSync(typein, billcode, "")
  1982. case "insertBigPartquit":
  1983. billcode := tempval_["data"].([]interface{})[0].(map[string]interface{})["parammaps"].(map[string]interface{})["useForm"]
  1984. _ = util.EASBillSync(3, billcode, "")
  1985. case "PartRefundCharge1":
  1986. billcode := tempval_["data"].([]interface{})[0].(map[string]interface{})["parammaps"].(map[string]interface{})["id"]
  1987. statue := interfacetostringv2(tempval_["data"].([]interface{})[0].(map[string]interface{})["parammaps"].(map[string]interface{})["statue"])
  1988. if statue == "5" {
  1989. _ = util.EASBillSync(4, billcode, "")
  1990. }
  1991. }
  1992. }
  1993. }
  1994. }
  1995. func interfacetostring(val interface{}) string {
  1996. switch val.(type) {
  1997. case string:
  1998. ss := val.(string)
  1999. return ss
  2000. case int:
  2001. ss := val.(int)
  2002. return strconv.Itoa(ss)
  2003. case int64:
  2004. ss := val.(int64)
  2005. return strconv.FormatInt(ss, 10)
  2006. case float64:
  2007. ss := val.(float64)
  2008. return strconv.FormatFloat(ss, 'E', -1, 32)
  2009. }
  2010. return ""
  2011. }
  2012. func interfacetostringv2(val interface{}) string {
  2013. switch val.(type) {
  2014. case string:
  2015. ss := val.(string)
  2016. return ss
  2017. case int:
  2018. ss := val.(int)
  2019. return strconv.Itoa(ss)
  2020. case int64:
  2021. ss := val.(int64)
  2022. return strconv.FormatInt(ss, 10)
  2023. case float64:
  2024. ss := int(val.(float64))
  2025. return strconv.Itoa(ss)
  2026. }
  2027. return ""
  2028. }
  2029. func getParamValue(parammaps map[string]interface{}, value string, ParamMap []map[string]interface{}) string {
  2030. if valuestring, ok := parammaps[strings.Trim(value, " ")].(string); ok {
  2031. tempstrb := strings.IndexAny(valuestring, "@")
  2032. tempstre := strings.IndexAny(valuestring, ".")
  2033. if tempstrb > -1 && tempstre > -1 {
  2034. for _, ParamMapList := range ParamMap {
  2035. if v, ok := ParamMapList["resultname"]; ok {
  2036. if v == valuestring[tempstrb+1:tempstre] {
  2037. if v1, ok := ParamMapList["resultmaps"]; ok {
  2038. if newA, ok := v1.([]map[string]interface{}); ok {
  2039. return interfacetostring(newA[0][valuestring[tempstre+1:]])
  2040. } else if newA, ok := v1.(map[string]interface{}); ok {
  2041. return interfacetostring(newA[valuestring[tempstre+1:]])
  2042. }
  2043. }
  2044. }
  2045. }
  2046. }
  2047. } else {
  2048. return valuestring
  2049. }
  2050. } else if valuestring, ok := parammaps[strings.Trim(value, " ")].(float64); ok {
  2051. return strconv.FormatInt(int64(valuestring), 10)
  2052. }
  2053. return ""
  2054. }
  2055. func getParamValue_(parammaps map[string]interface{}, value string, ParamMap map[string]interface{}) string {
  2056. if valuestring, ok := parammaps[strings.Trim(value, " ")].(string); ok {
  2057. tempstrb := strings.IndexAny(valuestring, "@")
  2058. tempstre := strings.IndexAny(valuestring, ".")
  2059. if tempstrb > -1 && tempstre > -1 {
  2060. if v, ok := ParamMap[valuestring[tempstre+1:]]; ok {
  2061. if s, ok := v.(string); ok {
  2062. return s
  2063. } else if s, ok := v.(float64); ok {
  2064. return strconv.FormatInt(int64(s), 10)
  2065. }
  2066. }
  2067. }
  2068. }
  2069. return ""
  2070. }
  2071. func ExecDataParam(fasion map[string]interface{}, CommonParamMap map[string]interface{}, ParamMap []map[string]interface{}, ParentParamMap map[string]interface{}, sameParamMap []map[string]interface{}, tx *sqlx.Tx) ([]map[string]interface{}, error) {
  2072. sqlname := fasion["name"].(string)
  2073. sqltype := "" //v 校验/s1 查询/sm 查询/e 执行
  2074. defer func() {
  2075. if sqlname == "batchPartsSH" {
  2076. id := ""
  2077. switch ParentParamMap["id"].(type) {
  2078. case float64:
  2079. id = strconv.Itoa(int(ParentParamMap["id"].(float64)))
  2080. case string:
  2081. id = ParentParamMap["id"].(string)
  2082. case int:
  2083. id = strconv.Itoa(ParentParamMap["id"].(int))
  2084. }
  2085. go util.EASBillSync(5, id, "1")
  2086. //go CheckEASWebServiceParts("1",id)
  2087. }
  2088. }()
  2089. if v, ok := fasion["type"]; ok {
  2090. sqltype = v.(string)
  2091. }
  2092. sql := ""
  2093. p := ""
  2094. s_params := make([]interface{}, 0)
  2095. if sqltype != "" {
  2096. sql, p = restful.GetSqlByName(sqlname, nil)
  2097. //sqlApi, _ := model.GetApisqlByName(sqlname)
  2098. if v, ok := fasion["parammaps"].(map[string]interface{}); ok {
  2099. paramslist := strings.Split(p, ",")
  2100. if len(paramslist) > 0 && p != "" {
  2101. for _, value := range paramslist {
  2102. ss := ""
  2103. if ss == "" && CommonParamMap != nil {
  2104. if valuestring, ok := v[strings.Trim(value, " ")].(string); ok {
  2105. ss = valuestring
  2106. tempstrb := strings.IndexAny(valuestring, "@")
  2107. tempstre := strings.IndexAny(valuestring, ".")
  2108. if (tempstre > tempstrb) && (strings.ToLower(valuestring[tempstrb+1:tempstre]) == "common") {
  2109. if CommonParamMap[valuestring[tempstre+1:]] != nil {
  2110. ss = CommonParamMap[valuestring[tempstre+1:]].(string)
  2111. }
  2112. } else {
  2113. ss = ""
  2114. }
  2115. }
  2116. }
  2117. if ss == "" && ParentParamMap != nil {
  2118. ss = getParamValue_(v, value, ParentParamMap)
  2119. }
  2120. if ss == "" && sameParamMap != nil {
  2121. ss = getParamValue(v, value, sameParamMap)
  2122. }
  2123. if ss == "" && ParamMap != nil {
  2124. ss = getParamValue(v, value, ParamMap)
  2125. }
  2126. s_params = append(s_params, ss)
  2127. }
  2128. }
  2129. }
  2130. }
  2131. fmt.Println("=========")
  2132. if sql == "" {
  2133. sqltype = ""
  2134. }
  2135. if sqltype == "s1" {
  2136. tempValParam, err := restful.QueryByMap(sql, 0, 1, s_params)
  2137. if v, ok := tempValParam.(map[string]interface{}); ok {
  2138. fasion["resultmaps"] = v["list"].([]map[string]interface{})
  2139. }
  2140. if err != nil {
  2141. return nil, err
  2142. }
  2143. err = ExitsChildrenParam(fasion, tempValParam, ParamMap, CommonParamMap, tx)
  2144. if err != nil {
  2145. return nil, err
  2146. }
  2147. return tempValParam.(map[string]interface{})["list"].([]map[string]interface{}), err
  2148. } else if sqltype == "sm" {
  2149. tempValParam, err := restful.QueryByMap(sql, 0, 0, s_params)
  2150. if v, ok := tempValParam.(map[string]interface{}); ok {
  2151. fasion["resultmaps"] = v["list"].([]map[string]interface{})
  2152. } else {
  2153. fmt.Println("sm", tempValParam)
  2154. }
  2155. if err != nil {
  2156. return nil, err
  2157. }
  2158. err = ExitsChildrenParam(fasion, tempValParam, ParamMap, CommonParamMap, tx)
  2159. if err != nil {
  2160. return nil, err
  2161. }
  2162. return tempValParam.(map[string]interface{})["list"].([]map[string]interface{}), err
  2163. } else if sqltype == "v" {
  2164. tempValParam, err := restful.QueryByMap(sql, 0, 1, s_params)
  2165. if v, ok := tempValParam.(map[string]interface{}); ok {
  2166. fasion["resultmaps"] = v["list"].([]map[string]interface{})
  2167. } else {
  2168. fmt.Println("v", tempValParam)
  2169. }
  2170. if err != nil {
  2171. return nil, err
  2172. }
  2173. if tempValParam.(map[string]interface{})["list"].([]map[string]interface{})[0]["vmsg"] != "" {
  2174. return nil, errors.New(tempValParam.(map[string]interface{})["list"].([]map[string]interface{})[0]["vmsg"].(string))
  2175. }
  2176. } else if sqltype == "e" {
  2177. tempVal_arrary := make([]map[string]interface{}, 0)
  2178. tempVal_map := make(map[string]interface{})
  2179. tempValParam, err := restful.ExecQueryT(sql, s_params, tx)
  2180. if err == nil {
  2181. fasion["resultmaps"] = tempValParam.(map[string]interface{})
  2182. tempVal_map["result"] = tempValParam.(map[string]interface{})["result"]
  2183. tempVal_map["LastInsertId"] = tempValParam.(map[string]interface{})["LastInsertId"]
  2184. tempVal_arrary = append(tempVal_arrary, tempVal_map)
  2185. return tempVal_arrary, err
  2186. }
  2187. return nil, err
  2188. } else {
  2189. if tempValParam, ok := fasion["resultmaps"].(map[string]interface{}); ok {
  2190. err := ExitsChildrenParam(fasion, tempValParam, ParamMap, CommonParamMap, tx)
  2191. if err != nil {
  2192. return nil, err
  2193. }
  2194. return nil, err
  2195. }
  2196. }
  2197. return nil, nil
  2198. }
  2199. func ExitsChildrenParam(fasion map[string]interface{}, tempValParam interface{}, ParamMap []map[string]interface{}, commonParam map[string]interface{}, tx *sqlx.Tx) error {
  2200. var err error
  2201. subarray, ok := fasion["children"]
  2202. if ok {
  2203. for _, v := range tempValParam.(map[string]interface{})["list"].([]interface{}) { //遍历父集有多少行数据
  2204. tempVal_arrary := make([]map[string]interface{}, 0)
  2205. for _, subarrayvalue := range subarray.([]interface{}) { //遍历所有执行命令
  2206. tempVal_ := make(map[string]interface{})
  2207. if _, ok := subarrayvalue.(map[string]interface{})["resultname"]; !ok {
  2208. tempVal_["resultname"] = subarrayvalue.(map[string]interface{})["name"]
  2209. } else {
  2210. tempVal_["resultname"] = subarrayvalue.(map[string]interface{})["resultname"]
  2211. }
  2212. tempVal_["resultmaps"], err = ExecDataParam(subarrayvalue.(map[string]interface{}), commonParam, ParamMap, v.(map[string]interface{}), tempVal_arrary, tx) //递归调用执行
  2213. if err != nil {
  2214. return err
  2215. }
  2216. tempVal_arrary = append(tempVal_arrary, tempVal_)
  2217. }
  2218. v.(map[string]interface{})["children"] = tempVal_arrary
  2219. }
  2220. }
  2221. return nil
  2222. }
  2223. // @Summary 删除图片
  2224. // @Tags RemovePicByName
  2225. // @Accept json
  2226. // @Produce json
  2227. // @Param sqlname query string true "sqlname"
  2228. // @Param offset query int true "offset"
  2229. // @Param pagecount query int true "pagecount"
  2230. // @Param returntype query string true "returntype"
  2231. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  2232. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  2233. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  2234. // @Router /data/PostDataByName [POST]
  2235. func RemovePicByName(c *gin.Context) {
  2236. logging.Info("RemovePicByName ", c.Keys)
  2237. appG := app.Gin{C: c}
  2238. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  2239. fsion := gofasion.NewFasion(string(dataByte))
  2240. sqlnamestr := fsion.Get("name").ValueStr()
  2241. picname := fsion.Get("picname").ValueStr()
  2242. sql, _ := restful.GetSqlByNameDB(sqlnamestr)
  2243. params := fsion.Get("params").Array()
  2244. s_params := make([]interface{}, 0)
  2245. for _, v_params := range params {
  2246. s_params = append(s_params, v_params.ValueStr())
  2247. }
  2248. if sql != "" {
  2249. queryData, err := execDataBySql(sql, s_params)
  2250. if picname != "" {
  2251. // Destination
  2252. distPath := path.Join(setting.CurrentPath, setting.AppSetting.ImageSavePath, picname)
  2253. err := os.Remove(distPath) //删除文件test.txt
  2254. if err != nil {
  2255. //如果删除失败则输出 file remove Error!
  2256. fmt.Println("file remove Error!")
  2257. //输出错误详细信息
  2258. fmt.Printf("%s", err)
  2259. } else {
  2260. //如果删除成功则输出 file remove OK!
  2261. fmt.Print("file remove OK!")
  2262. }
  2263. distPath = path.Join(setting.CurrentPath, setting.AppSetting.ThumbnailSavePath, picname)
  2264. err = os.Remove(distPath) //删除文件test.txt
  2265. if err != nil {
  2266. //如果删除失败则输出 file remove Error!
  2267. fmt.Println("file remove Error!")
  2268. //输出错误详细信息
  2269. fmt.Printf("%s", err)
  2270. } else {
  2271. //如果删除成功则输出 file remove OK!
  2272. fmt.Print("file remove OK!")
  2273. }
  2274. }
  2275. if err != nil {
  2276. appG.Response(http.StatusOK, e.ERROR, err.Error())
  2277. } else {
  2278. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  2279. }
  2280. } else {
  2281. appG.Response(http.StatusOK, e.SUCCESS, nil)
  2282. }
  2283. }
  2284. // @Summary 删除文件
  2285. // @Tags RemoveFileByName
  2286. // @Accept json
  2287. // @Produce json
  2288. // @Param sqlname query string true "sqlname"
  2289. // @Param offset query int true "offset"
  2290. // @Param pagecount query int true "pagecount"
  2291. // @Param returntype query string true "returntype"
  2292. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  2293. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  2294. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  2295. // @Router /data/PostDataByName [POST]
  2296. func RemoveFileByName(c *gin.Context) {
  2297. appG := app.Gin{C: c}
  2298. id := c.Param("id")
  2299. logging.Info("DownloadFile ", c.Keys, id)
  2300. eqdoc, err := restful.MapStrList("SELECT * FROM eq_doc where id = ? ", id)
  2301. if eqdoc == nil {
  2302. appG.Response(http.StatusOK, e.ERROR, err.Error())
  2303. return
  2304. }
  2305. distPath := path.Join(setting.CurrentPath, setting.AppSetting.FileSavePath, eqdoc[0]["docpath"], eqdoc[0]["newdocname"])
  2306. err = os.Remove(distPath) //删除文件test.txt
  2307. if err != nil {
  2308. //如果删除失败则输出 file remove Error!
  2309. fmt.Println("file remove Error!")
  2310. //输出错误详细信息
  2311. fmt.Printf("%s", err)
  2312. appG.Response(http.StatusOK, e.ERROR, err.Error())
  2313. return
  2314. }
  2315. fmt.Print("file remove OK!")
  2316. _, err = restful.MapStrList("delete FROM eq_doc where id = ? ", id)
  2317. if err != nil {
  2318. log.Default().Printf("RemoveFileByName:%v", err)
  2319. }
  2320. appG.Response(http.StatusOK, e.SUCCESS, "OK")
  2321. //dataByte, _ := ioutil.ReadAll(c.Request.Body)
  2322. //fsion := gofasion.NewFasion(string(dataByte))
  2323. //sqlnamestr := fsion.Get("name").ValueStr()
  2324. //filename := fsion.Get("filename").ValueStr()
  2325. //sql, _ := restful.GetSqlByNameDB(sqlnamestr)
  2326. //params := fsion.Get("params").Array()
  2327. //s_params := make([]interface{}, 0)
  2328. //for _, v_params := range params {
  2329. // s_params = append(s_params, v_params.ValueStr())
  2330. //}
  2331. //if sql != "" {
  2332. // queryData, err := execDataBySql(sql, s_params)
  2333. //
  2334. // if filename != "" {
  2335. // // Destination
  2336. // distPath := path.Join(setting.CurrentPath, setting.AppSetting.FileSavePath, filename)
  2337. //
  2338. // err := os.Remove(distPath) //删除文件test.txt
  2339. // if err != nil {
  2340. // //如果删除失败则输出 file remove Error!
  2341. // fmt.Println("file remove Error!")
  2342. // //输出错误详细信息
  2343. // fmt.Printf("%s", err)
  2344. // } else {
  2345. // //如果删除成功则输出 file remove OK!
  2346. // fmt.Print("file remove OK!")
  2347. // }
  2348. // }
  2349. // if err != nil {
  2350. // appG.Response(http.StatusOK, e.ERROR, err.Error())
  2351. // } else {
  2352. // appG.Response(http.StatusOK, e.SUCCESS, "OK")
  2353. // }
  2354. //} else {
  2355. // appG.Response(http.StatusOK, e.SUCCESS, nil)
  2356. //}
  2357. }
  2358. // @Summary 根据APISQL表中SQL执行得到数据集
  2359. // @Tags PostDataByName
  2360. // @Accept json
  2361. // @Produce json
  2362. // @Param sqlname query string true "sqlname"
  2363. // @Param offset query int true "offset"
  2364. // @Param pagecount query int true "pagecount"
  2365. // @Param returntype query string true "returntype"
  2366. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  2367. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  2368. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  2369. // @Router /data/PostDataByName [POST]
  2370. func UpdateDataRelation(c *gin.Context) {
  2371. appG := app.Gin{C: c}
  2372. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  2373. fsion := gofasion.NewFasion(string(dataByte))
  2374. tablename := fsion.Get("name").ValueStr()
  2375. dataname := fsion.Get("dataname").ValueStr()
  2376. datavalue := fsion.Get("datavalue").ValueStr()
  2377. valuename := fsion.Get("valuename").ValueStr()
  2378. logging.Info("UpdateDataRelation ", c.Keys, c.Request.RemoteAddr, tablename, dataname, datavalue, valuename)
  2379. values := fsion.Get("values").Array()
  2380. tx, err := restful.Dbs.Beginx()
  2381. defer func() {
  2382. switch {
  2383. case err != nil:
  2384. fmt.Println("__error:", err)
  2385. if tx != nil {
  2386. tx.Rollback()
  2387. }
  2388. default:
  2389. if tx != nil {
  2390. err = tx.Commit()
  2391. }
  2392. }
  2393. }()
  2394. insertSqlstr := "insert into " + tablename + "( " + dataname + "," + valuename + ") select DISTINCT ?, ? from DUAL " +
  2395. " where NOT EXISTS (select " + valuename + " from " + tablename + " where " + valuename + " = ? and " + dataname + " = ?)"
  2396. d_params := make([]interface{}, 4)
  2397. d_params[0] = datavalue
  2398. s_params := ""
  2399. for _, v_values := range values {
  2400. d_params[1] = v_values.ValueStr()
  2401. if s_params == "" {
  2402. s_params = v_values.ValueStr()
  2403. } else {
  2404. s_params = s_params + "," + v_values.ValueStr()
  2405. }
  2406. d_params[2] = d_params[1]
  2407. d_params[3] = d_params[0]
  2408. _, err := execDataBySqlT(insertSqlstr, d_params, tx)
  2409. if err != nil {
  2410. appG.Response(http.StatusOK, e.ERROR, err.Error())
  2411. break
  2412. }
  2413. }
  2414. if s_params != "" {
  2415. deleteSqlstr := "delete from " + tablename + " " +
  2416. " where " + dataname + " = " + datavalue + " and " + valuename + " not in (" + s_params + ")"
  2417. queryData, err := execDataBySqlT(deleteSqlstr, nil, tx)
  2418. if err != nil {
  2419. appG.Response(http.StatusOK, e.ERROR, err.Error())
  2420. } else if err == nil {
  2421. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  2422. }
  2423. } else {
  2424. deleteSqlstr := "delete from " + tablename + " " +
  2425. " where " + dataname + " = " + datavalue
  2426. queryData, err := execDataBySqlT(deleteSqlstr, nil, tx)
  2427. if err != nil {
  2428. appG.Response(http.StatusOK, e.ERROR, err.Error())
  2429. } else if err == nil {
  2430. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  2431. }
  2432. }
  2433. }
  2434. // @Summary 根据APISQL表中SQL执行得到数据集
  2435. // @Tags PostDatasByName
  2436. // @Accept json
  2437. // @Produce json
  2438. // @Param sqlname query string true "sqlname"
  2439. // @Param offset query int true "offset"
  2440. // @Param pagecount query int true "pagecount"
  2441. // @Param returntype query string true "returntype"
  2442. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  2443. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  2444. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  2445. // @Router /data/PostDatasByName [POST]
  2446. func PostDataByNames(c *gin.Context) {
  2447. appG := app.Gin{C: c}
  2448. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  2449. fsion := gofasion.NewFasion(string(dataByte))
  2450. sqlParams := fsion.Get("array").Array()
  2451. queryData := make(map[string]interface{})
  2452. for _, v := range sqlParams {
  2453. fsion2 := gofasion.NewFasion(v.Json())
  2454. logging.Info("PostDataByNames ", c.Keys, fsion2.Get("name").ValueStr())
  2455. sql, p := restful.GetSqlByNameDB(fsion2.Get("name").ValueStr())
  2456. if sql == "" {
  2457. errorm := make(map[string]interface{})
  2458. errorm["code"] = e.ERROR
  2459. errorm["message"] = "sql没有找到"
  2460. errorm["param"] = ""
  2461. queryData[fsion2.Get("name").ValueStr()] = errorm
  2462. continue
  2463. } else if sql != "" {
  2464. s_params := make([]interface{}, 0)
  2465. if fsion2.HasKey("parammaps") {
  2466. parammaps := fsion2.Get("parammaps")
  2467. paramslist := strings.Split(p, ",")
  2468. if len(paramslist) > 0 && p != "" {
  2469. for _, value := range paramslist {
  2470. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  2471. if tempv, exists := c.Get("jwt_username"); exists {
  2472. s_params = append(s_params, tempv.(string))
  2473. } else {
  2474. s_params = append(s_params, "")
  2475. }
  2476. } else {
  2477. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  2478. }
  2479. }
  2480. }
  2481. } else if fsion2.HasKey("params") {
  2482. params := fsion2.Get("params").Array()
  2483. for _, v_params := range params {
  2484. s_params = append(s_params, v_params.ValueStr())
  2485. }
  2486. }
  2487. _, err := execDataBySql(sql, s_params)
  2488. if err != nil {
  2489. logging.Error("PostDataByName err: ", err)
  2490. errorm := make(map[string]interface{})
  2491. errorm["code"] = e.ERROR
  2492. errorm["message"] = err.Error()
  2493. errorm["msg"] = "fail"
  2494. errorm["param"] = s_params
  2495. queryData[fsion2.Get("name").ValueStr()] = errorm
  2496. continue
  2497. } else {
  2498. errorm := make(map[string]interface{})
  2499. errorm["code"] = e.SUCCESS
  2500. errorm["message"] = "success"
  2501. errorm["msg"] = "ok"
  2502. queryData[fsion2.Get("name").ValueStr()] = errorm
  2503. continue
  2504. }
  2505. } else {
  2506. errorm := make(map[string]interface{})
  2507. errorm["code"] = e.ERROR
  2508. errorm["message"] = "NO SQL"
  2509. errorm["param"] = ""
  2510. queryData[fsion2.Get("name").ValueStr()] = errorm
  2511. }
  2512. }
  2513. //appG.Response(http.StatusOK, e.SUCCESS, msg)
  2514. appG.Response(http.StatusOK, e.SUCCESS, queryData)
  2515. }
  2516. func getDataBySql(sqlstr string, offset, pagecount int, returntype string, params []interface{}) (interface{}, error) {
  2517. if offset > 0 {
  2518. offset = offset - 1
  2519. }
  2520. if returntype == "list" {
  2521. queryData, err := restful.QueryByList(sqlstr, offset, pagecount, params)
  2522. return queryData, err
  2523. } else if returntype == "listlist" {
  2524. queryData, err := restful.QueryByListList(sqlstr, offset, pagecount, params)
  2525. return queryData, err
  2526. } else {
  2527. queryData, err := restful.QueryByMap(sqlstr, offset, pagecount, params)
  2528. return queryData, err
  2529. }
  2530. }
  2531. // func getDataBySqlT(sqlstr string, offset, pagecount int, returntype string, params []interface{}, tx *sqlx.Tx) (interface{}, error) {
  2532. func getDataBySqlT(sqlstr string, offset, pagecount int, returntype string, params []interface{}) (interface{}, error) {
  2533. if offset > 0 {
  2534. offset = offset - 1
  2535. }
  2536. if returntype == "list" {
  2537. // queryData, err := restful.QueryByListT(sqlstr, offset, pagecount, params, tx)
  2538. queryData, err := restful.QueryByListT(sqlstr, offset, pagecount, params)
  2539. return queryData, err
  2540. } else if returntype == "listlist" {
  2541. // queryData, err := restful.QueryByListListT(sqlstr, offset, pagecount, params, tx)
  2542. queryData, err := restful.QueryByListListT(sqlstr, offset, pagecount, params)
  2543. return queryData, err
  2544. } else {
  2545. // queryData, err := restful.QueryByMapT(sqlstr, offset, pagecount, params, tx)
  2546. queryData, err := restful.QueryByMapT(sqlstr, offset, pagecount, params)
  2547. return queryData, err
  2548. }
  2549. }
  2550. func GetRecuData_BySql(sql string, Params string, idname string, thisParams map[string]interface{}, isList bool) (interface{}, error) {
  2551. paramslist := strings.Split(Params, ",")
  2552. s_params := make([]interface{}, 0)
  2553. if isList {
  2554. for _, v_params := range thisParams["params"].([]interface{}) {
  2555. s_params = append(s_params, v_params)
  2556. }
  2557. } else {
  2558. paramslist := strings.Split(Params, ",")
  2559. if len(paramslist) > 0 && Params != "" {
  2560. for _, value := range paramslist {
  2561. s_params = append(s_params, thisParams[strings.Trim(value, " ")])
  2562. }
  2563. }
  2564. }
  2565. queryData, err := restful.QueryByMapMenu(sql, 0, 0, s_params)
  2566. for _, queryData_ := range queryData {
  2567. if v, ok := queryData_["haschildren"]; (ok && v.(int64) > 0) || !ok {
  2568. if isList {
  2569. //fmt.Println(idname, "-------------- -queryData_[idname]", queryData_)
  2570. if queryData_[idname] != nil {
  2571. thisParams["params"].([]interface{})[len(thisParams["params"].([]interface{}))-1] = queryData_[idname].(interface{})
  2572. }
  2573. } else {
  2574. if queryData_[idname] != nil {
  2575. thisParams[idname] = queryData_[idname].(interface{})
  2576. }
  2577. if len(paramslist) > 0 && Params != "" {
  2578. s_params = make([]interface{}, 0)
  2579. for _, value := range paramslist {
  2580. s_params = append(s_params, thisParams[strings.Trim(value, " ")])
  2581. }
  2582. }
  2583. }
  2584. queryData_["children"], _ = GetRecuData_BySql(sql, Params, idname, thisParams, isList)
  2585. } else {
  2586. }
  2587. }
  2588. return queryData, err
  2589. }
  2590. func execDataBySql(sqlstr string, params []interface{}) (interface{}, error) {
  2591. queryData, err := restful.ExecQuery(sqlstr, params)
  2592. return queryData, err
  2593. }
  2594. func execDataBySqlT(sqlstr string, params []interface{}, tx *sqlx.Tx) (interface{}, error) {
  2595. queryData, err := restful.ExecQueryT(sqlstr, params, tx)
  2596. return queryData, err
  2597. }
  2598. func ExecDataBySql(sqlstr string, params []interface{}) (interface{}, error) {
  2599. queryData, err := restful.ExecQuery(sqlstr, params)
  2600. return queryData, err
  2601. }
  2602. // @Summary 导入excel文件到数据库,excel第一行作为参数
  2603. // @Tags ImportExcel
  2604. // @Accept json
  2605. // @Produce json
  2606. // @Param file query string true "文件名"
  2607. // @Param name header string true "执行sql的名字"
  2608. // @Success 200 {string} json "{ "code": 200, "data": {}, "msg": "ok" }"
  2609. // @Failure 400 {string} json "{"code":400, "data":null,"msg":"请求参数错误"}"
  2610. // @Failure 404 {string} json "{ "code": 404, "data":null,"msg":"请求参数错误"}"
  2611. // @Router /data/ImportExcel [POST]
  2612. // @param 备件编号,备件名称,规格型号,计量单位,品牌,计划量,单价,备注,jwt_username
  2613. // func ImportExcel(c *gin.Context) {
  2614. // log.Default().Println("Importing Excel================================")
  2615. // appG := app.Gin{C: c}
  2616. // file, _, err := c.Request.FormFile("file")
  2617. // if err != nil {
  2618. // logrus.Errorf("request.FormFile: %v", err)
  2619. // appG.Response(http.StatusOK, e.ERROR, err)
  2620. // return
  2621. // }
  2622. // xlsx1, err := excelize.OpenReader(file)
  2623. // if err != nil {
  2624. // logrus.Errorf("excelize.OpenReader: %v", err)
  2625. // appG.Response(http.StatusOK, e.ERROR, err)
  2626. // return
  2627. // }
  2628. // c.Request.ParseForm()
  2629. // params := c.Request.Form
  2630. // sheetname := params.Get("sheetname")
  2631. // rows := xlsx1.GetRows(sheetname)
  2632. // importParams := params.Get("importParams")
  2633. // paramslist := strings.Split(importParams, ",")
  2634. // sqlnamestr := params.Get("name")
  2635. // sql, _ := restful.GetSqlByNameDB(sqlnamestr)
  2636. // inputdata := ""
  2637. // ok := 0
  2638. // error := 0
  2639. // queryData := make([]interface{}, 0)
  2640. // data := make(map[string]interface{})
  2641. // if len(rows) > 10000 {
  2642. // rows = rows[:10000]
  2643. // }
  2644. // if len(rows) <= 1 {
  2645. // logrus.Errorln("表格为空")
  2646. // appG.Response(http.StatusOK, e.ERROR, errors.New("表格为空"))
  2647. // return
  2648. // }
  2649. // if len(rows[0]) < len(paramslist) {
  2650. // logrus.Errorln("表格缺少数据列")
  2651. // appG.Response(http.StatusOK, e.ERROR, errors.New("表格缺少数据列"))
  2652. // return
  2653. // }
  2654. // for i, v := range paramslist {
  2655. // if strings.Trim(rows[0][i], " ") != v {
  2656. // logrus.Errorln("表格数据列顺序不符合标准,或标题名称错误")
  2657. // appG.Response(http.StatusOK, e.ERROR, errors.New("表格数据列顺序不符合标准,或标题名称错误"))
  2658. // return
  2659. // }
  2660. // }
  2661. // for _, row := range rows[1:] {
  2662. // s_params := make([]interface{}, 0)
  2663. // outentry := make(map[string]interface{})
  2664. // for i := range row {
  2665. // row[i] = strings.TrimSpace(row[i])
  2666. // s_params = append(s_params, row[i])
  2667. // }
  2668. // uname := ""
  2669. // if tempv, b := c.Get("jwt_username"); b {
  2670. // uname = tempv.(string)
  2671. // }
  2672. // s_params = append(s_params, uname)
  2673. // outentry["input"] = inputdata
  2674. // log.Default().Printf("params=%v", s_params...)
  2675. // returnmsg, err := getDataBySql(sql, 0, 0, "4", s_params)
  2676. // returnmsgmap, _ := returnmsg.(map[string]interface{})
  2677. // returnmsgmap1, _ := returnmsgmap["list"].([]map[string]interface{})
  2678. // if err != nil {
  2679. // outentry["error_msg"] = err.Error()
  2680. // error++
  2681. // queryData = append(queryData, outentry)
  2682. // } else if (len(returnmsgmap1) > 0) && (returnmsgmap1[0]["msg"] == "success") {
  2683. // ok++
  2684. // } else {
  2685. // msg := geterrmsg(returnmsgmap1[0]["msg"].(string))
  2686. // outentry["error_msg"] = msg
  2687. // error++
  2688. // queryData = append(queryData, outentry)
  2689. // }
  2690. // }
  2691. // data["result"] = queryData
  2692. // data["success"] = ok
  2693. // data["err_count"] = error
  2694. // appG.Response(http.StatusOK, e.SUCCESS, data)
  2695. // }
  2696. func ImportExcel(c *gin.Context) {
  2697. appG := app.Gin{C: c}
  2698. inputdata := ""
  2699. if err := c.Request.ParseForm(); err != nil {
  2700. log.Default().Printf("request.parseform:%v", err)
  2701. appG.Response(http.StatusOK, e.ERROR, err)
  2702. return
  2703. }
  2704. params := c.Request.Form
  2705. // file, _, err := c.Request.FormFile("file")
  2706. fileHeader, err := c.FormFile("file")
  2707. file, err := fileHeader.Open()
  2708. if err != nil {
  2709. log.Default().Printf("multipart.FileHeader.open:%v", err)
  2710. appG.Response(http.StatusOK, e.ERROR, err)
  2711. return
  2712. }
  2713. if err != nil {
  2714. log.Default().Printf("request.FormFile: %v", err)
  2715. appG.Response(http.StatusOK, e.ERROR, err)
  2716. return
  2717. }
  2718. sqlnamestr := params.Get("name")
  2719. sheetname := params.Get("sheetname")
  2720. importParams := params.Get("importParams")
  2721. sql, _ := restful.GetSqlByNameDB(sqlnamestr)
  2722. // 备件编号,备件名称,规格型号,计量单位,品牌,计划量,单价,备注,jwt_username
  2723. paramslist := strings.Split(importParams, ",")
  2724. if sqlnamestr != "importGasoline" && sqlnamestr != "importCoal" && sqlnamestr != "importBiomass" && sqlnamestr != "importEnergy" {
  2725. paramslist = append(paramslist, "jwt_username")
  2726. }
  2727. queryData := make([]interface{}, 0)
  2728. xlsx1, err := excelize.OpenReader(file)
  2729. if err != nil {
  2730. log.Default().Printf("excelize.OpenReader:%v", err)
  2731. return
  2732. }
  2733. ok := 0
  2734. error := 0
  2735. rows := xlsx1.GetRows(sheetname)
  2736. if len(rows) > 10000 {
  2737. rows = rows[:10000]
  2738. }
  2739. for i, row := range rows {
  2740. if i > 0 {
  2741. if len(paramslist) > 0 {
  2742. s_params := make([]interface{}, 0)
  2743. entry := make(map[string]interface{})
  2744. outentry := make(map[string]interface{})
  2745. inputdata = ""
  2746. for _, value := range paramslist {
  2747. if strings.ToLower(strings.Trim(value, " ")) == "jwt_username" {
  2748. if tempv, exists := c.Get("jwt_username"); exists {
  2749. s_params = append(s_params, tempv.(string))
  2750. } else {
  2751. s_params = append(s_params, "")
  2752. }
  2753. } else {
  2754. for j, colCell := range rows[0] {
  2755. if strings.Trim(value, " ") == colCell {
  2756. for k, colCell1 := range row {
  2757. if j == k {
  2758. outentry[colCell] = colCell1
  2759. entry[colCell] = colCell1
  2760. //inputdata = inputdata + colCell + ":" + colCell1 + ";"
  2761. }
  2762. }
  2763. }
  2764. }
  2765. s_params = append(s_params, entry[strings.Trim(value, " ")])
  2766. }
  2767. }
  2768. outentry["input"] = inputdata
  2769. returnmsg, err := getDataBySql(sql, 0, 0, "4", s_params)
  2770. returnmsgmap, _ := returnmsg.(map[string]interface{})
  2771. returnmsgmap1, _ := returnmsgmap["list"].([]map[string]interface{})
  2772. log.Default().Printf("return:%v", returnmsgmap)
  2773. if err != nil {
  2774. outentry["error_msg"] = err.Error()
  2775. error++
  2776. queryData = append(queryData, outentry)
  2777. } else if (len(returnmsgmap1) > 0) && (returnmsgmap1[0]["msg"] == "success") {
  2778. ok++
  2779. } else {
  2780. error++
  2781. msg := ""
  2782. if len(returnmsgmap1) > 0 && returnmsgmap1[0]["msg"] != nil {
  2783. msg = geterrmsg(returnmsgmap1[0]["msg"].(string))
  2784. }
  2785. outentry["error_msg"] = msg
  2786. queryData = append(queryData, outentry)
  2787. }
  2788. }
  2789. }
  2790. }
  2791. data := make(map[string]interface{})
  2792. data["result"] = queryData
  2793. data["success"] = ok
  2794. data["err_count"] = error
  2795. appG.Response(http.StatusOK, e.SUCCESS, data)
  2796. }
  2797. func DownloadMailReport(context *gin.Context) {
  2798. dataByte, _ := ioutil.ReadAll(context.Request.Body)
  2799. fsion := gofasion.NewFasion(string(dataByte))
  2800. //filename := context.Param("filename")
  2801. sqlnamestr := fsion.Get("name").ValueStr()
  2802. pastureId := fsion.Get("pastureId").ValueStr()
  2803. pastureName := fsion.Get("pastureName").ValueStr()
  2804. date := fsion.Get("date").ValueStr()
  2805. filepath := ""
  2806. if sqlnamestr == "DownloadMailReportJY" {
  2807. filepath, _ = util.DownloadDataJT(date)
  2808. } else if sqlnamestr == "DownloadMailReportMC" {
  2809. filepath, _ = util.DownloadDataMC(pastureName, date, pastureId)
  2810. } else if sqlnamestr == "sssss" { // 平时用来拉数据的
  2811. util.Sssss()
  2812. } else if sqlnamestr == "DownloadEquipment" { // 设备指标导出方法
  2813. parammaps := fsion.Get("parammaps").ValueStr()
  2814. filepath, _ = util.DownloadEquipment(parammaps)
  2815. }
  2816. if filepath == "" {
  2817. http.NotFound(context.Writer, context.Request)
  2818. return
  2819. }
  2820. originFilePath := filepath
  2821. //println("originFilePath==========",originFilePath)
  2822. if fs.PathExists(originFilePath) == false {
  2823. // if the path not found
  2824. http.NotFound(context.Writer, context.Request)
  2825. return
  2826. }
  2827. http.ServeFile(context.Writer, context.Request, originFilePath)
  2828. }
  2829. // 资产标准管理判断牧场是否有选择的该部门
  2830. func PastureDepartment(c *gin.Context) {
  2831. appG := app.Gin{C: c}
  2832. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  2833. fsion := gofasion.NewFasion(string(dataByte))
  2834. paramMap := fsion.Get("param")
  2835. ids := paramMap.Get("ids").ValueStr()
  2836. deptName := paramMap.Get("deptName").ValueStr()
  2837. idList := strings.Split(ids, ",")
  2838. checkDeptList := make([]map[string]interface{}, 0)
  2839. for _, v := range idList {
  2840. aa, _ := strconv.Atoi(v)
  2841. data, err := restful.MapStrList("select * from department where pastureId=? and name=? and enable=1 and isDel=0 and isPasture=0", aa, deptName)
  2842. if err != nil {
  2843. fmt.Println(err)
  2844. } else {
  2845. list := make(map[string]interface{}, 1)
  2846. if len(data) == 0 {
  2847. list["id"] = v
  2848. list["enable"] = 0
  2849. } else {
  2850. list["id"] = v
  2851. list["enable"] = 1
  2852. }
  2853. checkDeptList = append(checkDeptList, list)
  2854. }
  2855. }
  2856. appG.Response(http.StatusOK, e.SUCCESS, checkDeptList)
  2857. }
  2858. // { 'label': '汶上', 'property': 'm1' }
  2859. // 资产标准管理
  2860. func Equipment(c *gin.Context) {
  2861. appG := app.Gin{C: c}
  2862. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  2863. fsion := gofasion.NewFasion(string(dataByte))
  2864. deptName := fsion.Get("deptName").ValueStr()
  2865. eqClassId := fsion.Get("eqClassId").ValueStr()
  2866. offset := fsion.Get("offset").ValueDefaultInt(0)
  2867. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  2868. dataList := make([]interface{}, 0)
  2869. pastureData, err := restful.MapStrList("select p.`name`,p.id from pasture p group by p.`name`")
  2870. str := "select eqS.id,eqS.deapartmentName deptName, eqS.`use`,eqclass.`typeName`,p.`name`,p.id pastureId ,eqS.eqClassId " +
  2871. " from equipment_standard eqS" +
  2872. " left join pasture p on p.id= eqS.pastureId" +
  2873. " left join eqclass on eqclass.id=eqS.eqClassId " +
  2874. " where (eqS.deapartmentName = :deptName or :deptName ='') and " +
  2875. " (eqS.eqClassId = :eqClassId or :eqClassId ='') " +
  2876. " group by deptName,eqClassId " +
  2877. " ORDER BY eqS.id DESC"
  2878. offset = offset - 1
  2879. if pagecount > 0 && offset > 0 {
  2880. offset = offset * pagecount
  2881. }
  2882. paramMap_3_6 := map[string]interface{}{"deptName": deptName, "eqClassId": eqClassId}
  2883. str += fmt.Sprintf("limit %d offset %d", pagecount, offset)
  2884. equipmentStandardData1, err := restful.MapStrList(str, paramMap_3_6)
  2885. //数据
  2886. equipmentStandardData2, err := restful.MapStrList("select eqS.deapartmentName deptName, eqS.id eqSId,eqS.equipmentNumber,p.`name`,p.id pastureId,eqS.eqClassId"+
  2887. " from equipment_standard eqS"+
  2888. " left join pasture p on p.id= eqS.pastureId "+
  2889. " left join eqclass eqc on eqc.id=eqS.eqClassId "+
  2890. "where (eqS.deapartmentName =? or ?='') and"+
  2891. " (eqS.eqClassId = ? or ?='') ", deptName, deptName, eqClassId, eqClassId)
  2892. sqlstr := str
  2893. params := make([]interface{}, 0)
  2894. for i := 0; i < 2; i++ {
  2895. param := make(map[string]interface{}, 0)
  2896. param["deptName"] = deptName
  2897. param["eqClassId"] = eqClassId
  2898. params = append(params, param)
  2899. }
  2900. label := make([]map[string]interface{}, 0)
  2901. if err != nil {
  2902. fmt.Println(err)
  2903. } else {
  2904. for i, v := range pastureData {
  2905. pasturelist := make(map[string]interface{}, 1)
  2906. pasturelist["label"] = v["name"]
  2907. pasturelist["id"] = v["id"]
  2908. pasturelist["property"] = "m" + strconv.Itoa(i+1)
  2909. label = append(label, pasturelist)
  2910. }
  2911. label2 := make([]map[string]interface{}, 0)
  2912. for _, s := range equipmentStandardData1 {
  2913. equipmentStandardList := make(map[string]interface{}, 1)
  2914. for i := 1; i <= len(label); i++ {
  2915. equipmentStandardList["m"+strconv.Itoa(i)] = ""
  2916. }
  2917. equipmentStandardList["deptName"] = s["deptName"]
  2918. equipmentStandardList["use"] = s["use"]
  2919. equipmentStandardList["typeName"] = s["typeName"]
  2920. equipmentStandardList["eqClassId"] = s["eqClassId"]
  2921. for _, z := range equipmentStandardData2 {
  2922. for e, x := range label {
  2923. if s["deptName"] == z["deptName"] && x["label"] == z["name"] && s["eqClassId"] == z["eqClassId"] {
  2924. equipmentStandardList["pastureId"+strconv.Itoa(e+1)] = x["id"]
  2925. equipmentStandardList[x["property"].(string)] = z["equipmentNumber"]
  2926. } else {
  2927. equipmentStandardList["pastureId"+strconv.Itoa(e+1)] = x["id"]
  2928. }
  2929. }
  2930. }
  2931. label2 = append(label2, equipmentStandardList)
  2932. }
  2933. if err != nil {
  2934. msg := geterrmsg(err.Error())
  2935. appG.Response(http.StatusOK, e.ERROR, msg)
  2936. } else {
  2937. dataList = append(dataList, label)
  2938. dataList = append(dataList, label2)
  2939. data := make(map[string]interface{})
  2940. recordcount := int64(0)
  2941. if pagecount > 1 {
  2942. sqlstr := fmt.Sprintf("SELECT COUNT(*) as count FROM (%s) a", sqlstr)
  2943. params := []interface{}{deptName, deptName, eqClassId, eqClassId}
  2944. err := restful.BasicList(sqlstr, params, &recordcount)
  2945. if err != nil {
  2946. log.Default().Printf("Equipment query error: %v", err)
  2947. }
  2948. }
  2949. if err != nil {
  2950. fmt.Println(err)
  2951. }
  2952. if recordcount == 0 {
  2953. recordcount = int64(len(equipmentStandardData1))
  2954. }
  2955. data["list"] = dataList
  2956. //data := make(map[string]interface{})
  2957. data["total"] = recordcount
  2958. data["code"] = 0
  2959. data["message"] = "ok"
  2960. if pagecount > 0 {
  2961. data["pages"] = math.Ceil(float64(recordcount) / float64(pagecount))
  2962. data["pageNum"] = math.Ceil(float64(offset+1) / float64(pagecount))
  2963. }
  2964. data["pageSize"] = pagecount
  2965. appG.Response(http.StatusOK, e.SUCCESS, data)
  2966. }
  2967. }
  2968. }
  2969. // 资产标准管理插入修改写在一起
  2970. func UpdateAndInsert(c *gin.Context) {
  2971. appG := app.Gin{C: c}
  2972. data := make(map[string]interface{}, 0)
  2973. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  2974. fsion := gofasion.NewFasion(string(dataByte))
  2975. param := fsion.Get("param")
  2976. check := fsion.Get("check").ValueStr()
  2977. tx, err := restful.Dbs.Beginx()
  2978. deptName := param.Get("deptName").ValueStr()
  2979. eqCode := param.Get("eqCode").ValueStr()
  2980. eqClassId, err := strconv.Atoi(param.Get("eqClassId").ValueStr())
  2981. use := param.Get("use").ValueStr()
  2982. paramStr := fsion.Get("param").ValueStr()
  2983. paramMap := make(map[string]interface{}, 0)
  2984. err = json.Unmarshal([]byte(paramStr), &paramMap)
  2985. fmt.Println(len(paramMap))
  2986. fmt.Println(paramMap)
  2987. // 标准库存
  2988. name := fsion.Get("name").ValueStr()
  2989. partClassId, err := strconv.Atoi(param.Get("partClassId").ValueStr())
  2990. ff := 0
  2991. if check == "insert" {
  2992. querydata := make([]map[string]string, 0)
  2993. if name == "partStandard" {
  2994. ff = 2
  2995. querydata, err = restful.MapStrList(" select * from part_standard where partClassId2 =? ", partClassId)
  2996. if querydata != nil {
  2997. //data["msg"]="请不输入重复数据"
  2998. msg := geterrmsg("请不输入重复数据")
  2999. appG.Response(http.StatusOK, e.ERROR, msg)
  3000. return
  3001. }
  3002. } else {
  3003. ff = 4
  3004. querydata, err = restful.MapStrList(" select * from equipment_standard where eqClassId =? and deapartmentName = ?", eqClassId, deptName)
  3005. if querydata != nil {
  3006. //data["msg"]="请不输入重复数据"
  3007. msg := geterrmsg("请不输入重复数据")
  3008. appG.Response(http.StatusOK, e.ERROR, msg)
  3009. return
  3010. }
  3011. }
  3012. for i := 1; i <= (len(paramMap)-ff)/2; i++ {
  3013. pastureId, err := strconv.Atoi(param.Get("pastureId" + strconv.Itoa(i)).ValueStr())
  3014. if err != nil {
  3015. }
  3016. if name == "partStandard" {
  3017. if param.Get("m"+strconv.Itoa(i)).ValueStr() != "" {
  3018. tx.Exec("call add_part_standard(?,?,?)", partClassId, pastureId, param.Get("m"+strconv.Itoa(i)))
  3019. }
  3020. } else {
  3021. if param.Get("m"+strconv.Itoa(i)).ValueStr() != "" {
  3022. tx.Exec("call add_equipment_standard(?,?,?,?,?,?)", deptName, use, eqClassId, pastureId, param.Get("m"+strconv.Itoa(i)).ValueStr(), eqCode)
  3023. }
  3024. }
  3025. }
  3026. if err != nil {
  3027. }
  3028. }
  3029. if check == "update" {
  3030. if name == "partStandard" {
  3031. ff = 2
  3032. tx.Exec("delete from part_standard where partClassId2 =?", partClassId)
  3033. for i := 1; i <= (len(paramMap)-ff)/2; i++ {
  3034. pastureId, err := strconv.Atoi(param.Get("pastureId" + strconv.Itoa(i)).ValueStr())
  3035. if err != nil {
  3036. }
  3037. if param.Get("m"+strconv.Itoa(i)).ValueStr() != "" {
  3038. tx.Exec("call add_part_standard(?,?,?)", partClassId, pastureId, param.Get("m"+strconv.Itoa(i)).ValueStr())
  3039. }
  3040. }
  3041. } else {
  3042. ff = 4
  3043. tx.Exec("delete from equipment_standard where deapartmentName=? and eqClassId=?", deptName, eqClassId)
  3044. for i := 1; i <= (len(paramMap)-ff)/2; i++ {
  3045. pastureId, err := strconv.Atoi(param.Get("pastureId" + strconv.Itoa(i)).ValueStr())
  3046. if err != nil {
  3047. }
  3048. if param.Get("m"+strconv.Itoa(i)).ValueStr() != "" {
  3049. tx.Exec("call add_equipment_standard(?,?,?,?,?,?)", deptName, use, eqClassId, pastureId, param.Get("m"+strconv.Itoa(i)).ValueStr(), eqCode)
  3050. // " WHERE deapartmentName=? and pastureId = ? and eqClassId=?", use, param.Get("m"+strconv.Itoa(i)).ValueStr(), deptName, pastureId,eqClassId).Execute()
  3051. }
  3052. }
  3053. }
  3054. if err != nil {
  3055. data["msg"] = "error"
  3056. data["error"] = err.Error()
  3057. appG.Response(http.StatusOK, e.SUCCESS, data)
  3058. }
  3059. }
  3060. if check == "delete" {
  3061. if name == "partStandard" {
  3062. for i := 1; i <= (len(paramMap)-ff)/2; i++ {
  3063. pastureId, err := strconv.Atoi(param.Get("pastureId" + strconv.Itoa(i)).ValueStr())
  3064. if err != nil {
  3065. }
  3066. tx.Exec("delete from part_standard where pastureId=? and partClassId2=?", pastureId, partClassId)
  3067. }
  3068. } else {
  3069. ff = 4
  3070. for i := 1; i <= (len(paramMap)-ff)/2; i++ {
  3071. pastureId, err := strconv.Atoi(param.Get("pastureId" + strconv.Itoa(i)).ValueStr())
  3072. if err != nil {
  3073. }
  3074. tx.Exec("delete from equipment_standard where deapartmentName=? and pastureId=? and eqClassId=?", deptName, pastureId, eqClassId)
  3075. }
  3076. }
  3077. }
  3078. data["msg"] = "ok"
  3079. appG.Response(http.StatusOK, e.SUCCESS, data)
  3080. defer func() {
  3081. switch {
  3082. case err != nil:
  3083. logging.Error("tx.Begin 事务启动失败__error:", err)
  3084. if tx != nil {
  3085. tx.Rollback()
  3086. }
  3087. default:
  3088. if tx != nil {
  3089. err = tx.Commit()
  3090. }
  3091. }
  3092. }()
  3093. }
  3094. func StandardPart(c *gin.Context) {
  3095. appG := app.Gin{C: c}
  3096. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  3097. fsion := gofasion.NewFasion(string(dataByte))
  3098. partClassId := fsion.Get("partClassId").ValueStr()
  3099. offset := fsion.Get("offset").ValueDefaultInt(0)
  3100. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  3101. pastureData, err := restful.MapStrList("select p.`name`,p.id from pasture p group by p.`name`")
  3102. //s_params := make([]interface{}, 0)
  3103. offset = offset - 1
  3104. if pagecount > 0 && offset > 0 {
  3105. offset = offset * pagecount
  3106. }
  3107. dataList := make([]interface{}, 0)
  3108. label := make([]map[string]interface{}, 0)
  3109. str := "select p_c.partName,p.`name`,p_s.pastureId,p_s.partClassId2 from part_standard p_s left join part_class p_c on p_c.id= p_s.partClassId2 " +
  3110. " left join pasture p on p.id = p_s.pastureId where p_s.partClassId2 = ? or ?='' " +
  3111. " GROUP BY p_s.partClassId2 ORDER BY p_s.id DESC"
  3112. str1 := "select p_s.standardMoney,p_s.partClassId2,p_s.pastureId,p.`name` from part_standard p_s left join pasture p on p.id=p_s.pastureId where p_s.partClassId2 = ? or ?=''"
  3113. str += fmt.Sprintf(" limit %d offset %d", pagecount, offset)
  3114. partStandardData1, err := restful.MapStrList(str, partClassId, partClassId)
  3115. //数据
  3116. partStandardData2, err := restful.MapStrList(str1, partClassId, partClassId)
  3117. if err != nil {
  3118. fmt.Println(err)
  3119. } else {
  3120. for i, v := range pastureData {
  3121. pasturelist := make(map[string]interface{}, 1)
  3122. pasturelist["label"] = v["name"]
  3123. pasturelist["id"] = v["id"]
  3124. pasturelist["property"] = "m" + strconv.Itoa(i+1)
  3125. label = append(label, pasturelist)
  3126. }
  3127. label2 := make([]map[string]interface{}, 0)
  3128. //equipmentStandardList := make(map[string]interface{}, 1)
  3129. for _, s := range partStandardData1 {
  3130. partStandardList := make(map[string]interface{}, 1)
  3131. for i := 1; i <= len(label); i++ {
  3132. partStandardList["m"+strconv.Itoa(i)] = ""
  3133. }
  3134. partStandardList["partClassId"] = s["partClassId2"]
  3135. partStandardList["partName"] = s["partName"]
  3136. for _, z := range partStandardData2 {
  3137. for e, x := range label {
  3138. if x["label"] == z["name"] && s["partClassId2"] == z["partClassId2"] {
  3139. partStandardList["pastureId"+strconv.Itoa(e+1)] = x["id"]
  3140. //equipmentStandardList["eqSId"+strconv.Itoa(e+1)] = z["eqSId"]
  3141. partStandardList[x["property"].(string)] = z["standardMoney"]
  3142. } else {
  3143. partStandardList["pastureId"+strconv.Itoa(e+1)] = x["id"]
  3144. }
  3145. }
  3146. }
  3147. label2 = append(label2, partStandardList)
  3148. }
  3149. if err != nil {
  3150. //logging.Error("GetDataByName err: ", err)
  3151. msg := geterrmsg(err.Error())
  3152. appG.Response(http.StatusOK, e.ERROR, msg)
  3153. } else {
  3154. dataList = append(dataList, label)
  3155. dataList = append(dataList, label2)
  3156. fmt.Println(label2)
  3157. data := make(map[string]interface{})
  3158. recordcount := int64(0)
  3159. if pagecount > 1 {
  3160. sqlstr := fmt.Sprintf("SELECT COUNT(*) as count FROM (%s) a", str)
  3161. params := []interface{}{partClassId, partClassId}
  3162. restful.BasicList(sqlstr, params, &recordcount)
  3163. if err != nil {
  3164. fmt.Println("s1", err)
  3165. }
  3166. }
  3167. if err != nil {
  3168. fmt.Println(err)
  3169. }
  3170. if recordcount == 0 {
  3171. recordcount = int64(len(partStandardData1))
  3172. }
  3173. data["list"] = dataList
  3174. //data := make(map[string]interface{})
  3175. data["total"] = recordcount
  3176. data["code"] = 0
  3177. data["message"] = "ok"
  3178. if pagecount > 0 {
  3179. data["pages"] = math.Ceil(float64(recordcount) / float64(pagecount))
  3180. data["pageNum"] = math.Ceil(float64(offset+1) / float64(pagecount))
  3181. }
  3182. data["pageSize"] = pagecount
  3183. //pageNum: 1 pageSize: 10 pages: 202 total: 2019
  3184. //data["pageNum"]=queryData
  3185. //data["pageNum"]=queryData["pageNum"]
  3186. appG.Response(http.StatusOK, e.SUCCESS, data)
  3187. }
  3188. }
  3189. }
  3190. func GetMtbfTable(c *gin.Context) {
  3191. appG := app.Gin{C: c}
  3192. //dataByte, _ := ioutil.ReadAll(c.Request.Body)
  3193. //fsion := gofasion.NewFasion(string(dataByte))
  3194. data := make(map[string]interface{})
  3195. data["name"] = "epans"
  3196. data["userId"] = "99"
  3197. appG.Response(http.StatusOK, e.SUCCESS, data)
  3198. }
  3199. func GetPartsListSGv2(c *gin.Context) {
  3200. appG := app.Gin{C: c}
  3201. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  3202. fsion := gofasion.NewFasion(string(dataByte))
  3203. sqlnamestr := fsion.Get("name").ValueStr()
  3204. params := fsion.Get("parammaps")
  3205. pastureId := params.Get("pastureId").ValueStr()
  3206. pastureName := params.Get("pastureName").ValueStr()
  3207. partCode := params.Get("partCode").ValueStr()
  3208. sql, _ := restful.GetSqlByNameDBT(sqlnamestr, nil)
  3209. partList, err := restful.MapStrList(sql, partCode, pastureId, pastureId, partCode, pastureId, partCode, partCode)
  3210. if err != nil {
  3211. logs.Error(err)
  3212. appG.Response(http.StatusInternalServerError, e.ERROR, false)
  3213. return
  3214. }
  3215. pastureSql := `select id from pasture_bigcontract where bigcontract_id in(select id from bigcontract
  3216. where contractCode like concat("%",?,"%")) and pasture_id = ?
  3217. union
  3218. select id from bigcontract where contractCode like concat("%",?,"%") and pastureId = ? `
  3219. var prices []string
  3220. var priceExist []string
  3221. resp := make(map[string]string)
  3222. for _, part := range partList {
  3223. pastureBigcontract, err := restful.MapStrList(pastureSql, part["contractCode"], pastureId, part["contractCode"], pastureId)
  3224. if err != nil {
  3225. logs.Error(err)
  3226. appG.Response(http.StatusInternalServerError, e.ERROR, false)
  3227. return
  3228. }
  3229. if len(pastureBigcontract) > 0 {
  3230. //partMap[part["contractCode"]] = true
  3231. priceExist = append(priceExist, part["price"])
  3232. part["price"] = ""
  3233. resp = part
  3234. } else {
  3235. //partMap[part["contractCode"]] = false
  3236. prices = append(prices, part["price"])
  3237. }
  3238. }
  3239. partMap := make(map[string]int64)
  3240. for i, p := range priceExist {
  3241. if _, ok := partMap[p]; !ok {
  3242. partMap[p] = partMap[p] + 1
  3243. if i == 0 {
  3244. resp["price"] = fmt.Sprintf("%s %s ", pastureName, p)
  3245. } else {
  3246. resp["price"] = fmt.Sprintf("%s ,%s %s ", resp["price"], pastureName, p)
  3247. }
  3248. }
  3249. }
  3250. for _, p := range prices {
  3251. if _, ok := partMap[p]; !ok {
  3252. partMap[p] = partMap[p] + 1
  3253. if len(resp["price"]) > 0 {
  3254. resp["price"] = fmt.Sprintf("%s ,现价格 %s ", resp["price"], p)
  3255. } else {
  3256. resp["price"] = fmt.Sprintf("现价格 %s ", p)
  3257. }
  3258. }
  3259. }
  3260. appG.Response(http.StatusOK, e.SUCCESS, map[string]interface{}{"list": []map[string]string{resp}})
  3261. }
  3262. func GetWaterAndElectricity(context *gin.Context) {
  3263. appG := app.Gin{C: context}
  3264. dataByte, _ := ioutil.ReadAll(context.Request.Body)
  3265. fsion := gofasion.NewFasion(string(dataByte))
  3266. //filename := context.Param("filename")
  3267. sqlnamestr := fsion.Get("name").ValueStr()
  3268. pastureName := fsion.Get("pastureId").ValueStr()
  3269. //pastureName := fsion.Get("pasture").ValueStr()
  3270. //date := fsion.Get("date").ValueStr()
  3271. parammap := fsion.Get("parammaps")
  3272. logging.Info("DownloadMailReport ", context.Keys, sqlnamestr, pastureName)
  3273. sqlnamesDepartment := []string{}
  3274. ///"维修费","水费","电费","柴油费","水量","电量","柴油用量"
  3275. if pastureName == "现代牧业" {
  3276. sqlnamesDepartment = []string{
  3277. "getChooseWaterPrice",
  3278. "getChooseElectricityPrice",
  3279. "getChooseMonthiolPrice"}
  3280. } else {
  3281. sqlnamesDepartment = []string{
  3282. "getChooseWaterPriceByPasture",
  3283. "getChooseElectricityPriceByPasture",
  3284. "getChooseMonthiolPriceByPasture"}
  3285. }
  3286. //if pastureId == "现代牧业" {
  3287. // sqlnames = []string{"getChooseEqMonthBudgetListSumAll", "getChooseMonthWX", "getChooseWaterPrice", "getChooseElectricityPrice", "getChooseMonthiolPrice",
  3288. // "getChooseMonthWater", "getChooseMonthElectricity", "getChooseMonthOilT", "getLgnitionChargePrice", "getChooseBiomassPrice", "getChooseGasolinePrice",
  3289. // "getChooseCoalPrice"}
  3290. //} else {
  3291. // sqlnames = []string{"getChooseEqMonthBudgetListSumAllByPasture", "getChooseMonthWXByPasture", "getChooseWaterPriceByPasture", "getChooseElectricityPriceByPasture", "getChooseMonthiolPriceByPasture",
  3292. // "getChooseMonthWaterByPasture", "getChooseMonthElectricityByPasture", "getChooseMonthOilTByPasture", "getLgnitionChargePriceByPasture", "getChooseBiomassPriceByPasture", "getChooseGasolinePriceByPasture",
  3293. // "getChooseCoalPriceByPasture"}
  3294. //}
  3295. respMapList := make([]map[string]string, 0)
  3296. for _, sqlname := range sqlnamesDepartment {
  3297. valuesMap, err := restful.MapStr("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", sqlname)
  3298. //parammap := make(map[string]interface{}, 0)
  3299. s_params := make([]interface{}, 0)
  3300. paramslist := strings.Split(valuesMap["params"], ",")
  3301. if len(paramslist) > 0 && valuesMap["params"] != "" {
  3302. for _, value := range paramslist {
  3303. if value == "pastureId" && parammap.Get("pastureId").ValueStr() == "" {
  3304. s_params = append(s_params, "现代牧业")
  3305. continue
  3306. }
  3307. s_params = append(s_params, parammap.Get(strings.Trim(value, " ")).ValueStr())
  3308. }
  3309. }
  3310. values, err := restful.MapStrList(valuesMap["sqlstr"], s_params...)
  3311. if err != nil {
  3312. fmt.Println(err)
  3313. } else {
  3314. for _, v := range values {
  3315. exist := false
  3316. for _, item := range respMapList {
  3317. if item["pastureName"] == v["pastureName"] {
  3318. exist = true
  3319. if sqlname == "getChooseWaterPrice" || sqlname == "getChooseWaterPriceByPasture" {
  3320. item["waterOneCowSumPrice"] = v["oneCowSumPrice"]
  3321. item["waterSumPrice"] = v["sumPrice"]
  3322. } else if sqlname == "getChooseElectricityPrice" || sqlname == "getChooseElectricityPriceByPasture" {
  3323. item["electricityOneCowSumPrice"] = v["oneCowSumPrice"]
  3324. item["electricitySumPrice"] = v["sumPrice"]
  3325. } else if sqlname == "getChooseMonthiolPrice" || sqlname == "getChooseMonthiolPriceByPasture" {
  3326. item["monthiolOneCowSumPrice"] = v["oneCowSumPrice"]
  3327. item["monthiolSumPrice"] = v["sumPrice"]
  3328. }
  3329. break
  3330. }
  3331. }
  3332. if !exist {
  3333. respMap := make(map[string]string, 0)
  3334. respMap["pastureName"] = v["pastureName"]
  3335. if sqlname == "getChooseWaterPrice" || sqlname == "getChooseWaterPriceByPasture" {
  3336. respMap["waterOneCowSumPrice"] = v["oneCowSumPrice"]
  3337. respMap["waterSumPrice"] = v["sumPrice"]
  3338. } else if sqlname == "getChooseElectricityPrice" || sqlname == "getChooseElectricityPriceByPasture" {
  3339. respMap["electricityOneCowSumPrice"] = v["oneCowSumPrice"]
  3340. respMap["electricitySumPrice"] = v["sumPrice"]
  3341. } else if sqlname == "getChooseMonthiolPrice" || sqlname == "getChooseMonthiolPriceByPasture" {
  3342. respMap["monthiolOneCowSumPrice"] = v["oneCowSumPrice"]
  3343. respMap["monthiolSumPrice"] = v["sumPrice"]
  3344. }
  3345. respMapList = append(respMapList, respMap)
  3346. }
  3347. }
  3348. }
  3349. }
  3350. appG.Response(http.StatusOK, e.SUCCESS, map[string]interface{}{"data": respMapList})
  3351. }