manage_api_controller.go 107KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "strconv"
  12. "time"
  13. "unsafe"
  14. )
  15. type MachineApiController struct {
  16. BaseAuthAPIController
  17. }
  18. func ManageRouters() {
  19. beego.Router("/api/management/savemanageinfo", &MachineApiController{}, "post:SaveManageInfo")
  20. beego.Router("/api/management/updatemachineinfo", &MachineApiController{}, "post:UpdateMachineInfo")
  21. beego.Router("/api/manage/updatemacheinettwo", &MachineApiController{}, "post:Updatemacheinetwo")
  22. beego.Router("/api/management/getallequimentname", &MachineApiController{}, "get:GetAllEquimentName")
  23. beego.Router("/api/management/saveplan", &MachineApiController{}, "post:SavePlan")
  24. beego.Router("/api/management/getallplan", &MachineApiController{}, "get:GetAllPlan")
  25. beego.Router("/api/management/getallplandetail", &MachineApiController{}, "get:GetAllPlanDetail")
  26. beego.Router("/api/management/geteditmachine", &MachineApiController{}, "get:GetEditMahchine")
  27. beego.Router("/api/staff/deleteplans", &MachineApiController{}, "delete:DeletePlans")
  28. beego.Router("/api/manage/editplandetail", &MachineApiController{}, "get:EditPlanDetail")
  29. beego.Router("/api/manage/updateplaninfo", &MachineApiController{}, "post:UpdatePlanInfo")
  30. beego.Router("/api/manage/getcomprehensive", &MachineApiController{}, "get:GetComprehensive")
  31. beego.Router("/api/manage/saveinformation", &MachineApiController{}, "Post:SaveInformation")
  32. beego.Router("/api/manage/getpatientinfo", &MachineApiController{}, "Get:GetPatientInfo")
  33. beego.Router("/api/manage/changeclass", &MachineApiController{}, "Get:GetPatient")
  34. beego.Router("/api/manage/changepatient", &MachineApiController{}, "Get:ChangePatient")
  35. beego.Router("/api/manage/getallorganization", &MachineApiController{}, "Get:GetAllOrganization")
  36. beego.Router("/api/manage/getregisterinfo", &MachineApiController{}, "Get:GetRegisterInfo")
  37. beego.Router("/api/manage/getinformationdata", &MachineApiController{}, "Get:GetInformationData")
  38. beego.Router("/api/manage/getorgname", &MachineApiController{}, "Get:GetOrgName")
  39. beego.Router("/api/manage/savebacteria", &MachineApiController{}, "Post:SaveBacteria")
  40. beego.Router("/api/manage/savelincomycin", &MachineApiController{}, "Post:SaveLinconmycin")
  41. beego.Router("/api/manage/savequalitycontrol", &MachineApiController{}, "Post:SaveQualityControl")
  42. beego.Router("/api/manage/getallqulityinfo", &MachineApiController{}, "Get:GetAllQulityInfo")
  43. beego.Router("/api/manage/editculture", &MachineApiController{}, "Get:EditCulture")
  44. beego.Router("/api/manage/updateculture", &MachineApiController{}, "Post:UpdateCulture")
  45. beego.Router("/api/manage/deletecultrue", &MachineApiController{}, "delete:DeleteCultrue")
  46. beego.Router("/api/manage/editdialystate", &MachineApiController{}, "Get:EditDialystate")
  47. beego.Router("/api/manage/updatedialystate", &MachineApiController{}, "Post:Updatedialystate")
  48. beego.Router("/api/manage/deletedialystate", &MachineApiController{}, "delete:DeleteDialystate")
  49. beego.Router("/api/manage/edition", &MachineApiController{}, "Get:Edition")
  50. beego.Router("/api/manage/updateion", &MachineApiController{}, "Post:UpdateIon")
  51. beego.Router("/api/manage/deleteion", &MachineApiController{}, "delete:DeleteIon")
  52. beego.Router("/api/manage/query", &MachineApiController{}, "Get:GetQuery")
  53. beego.Router("/api/manage/saverepair", &MachineApiController{}, "Post:SaveRepair")
  54. beego.Router("/api/manage/getallrepair", &MachineApiController{}, "Get:GetAllRepair")
  55. beego.Router("/api/manage/editrepair", &MachineApiController{}, "Get:EditRepair")
  56. beego.Router("/api/manage/updaterepair", &MachineApiController{}, "Post:UpdateRepair")
  57. beego.Router("/api/manage/deleterepair", &MachineApiController{}, "delete:DeleteRepair")
  58. beego.Router("/api/manage/queryrepair", &MachineApiController{}, "Get:GetRepair")
  59. beego.Router("/api/manage/edituser", &MachineApiController{}, "Get:EditUser")
  60. beego.Router("/api/manage/deleteform", &MachineApiController{}, "delete:DeleteForm")
  61. beego.Router("/api/manage/updateform", &MachineApiController{}, "Post:UpdateForm")
  62. beego.Router("/api/manage/queryinfo", &MachineApiController{}, "Get:QueryInfo")
  63. beego.Router("/api/manage/insertautodata", &MachineApiController{}, "Get:InsertAutoData")
  64. beego.Router("/api/manage/getallequittype", &MachineApiController{}, "Get:GetAllEquitType")
  65. beego.Router("/api/manage/getuserform", &MachineApiController{}, "Get:GetUserForm")
  66. beego.Router("/api/manage/getbedform", &MachineApiController{}, "Get:GetBedForm")
  67. beego.Router("/api/manage/gettotalcount", &MachineApiController{}, "Get:GetTotalCount")
  68. beego.Router("/api/manage/getotalnumber", &MachineApiController{}, "Get:GetTotalNumber")
  69. beego.Router("/api/manage/gettimewarning", &MachineApiController{}, "Get:GetTimeWarning")
  70. beego.Router("/api/manage/savemanageinfotwo", &MachineApiController{}, "post:SaveManageinfoTwo")
  71. beego.Router("/api/management/updatemachineinfotwo", &MachineApiController{}, "post:UpdateMachinetwo")
  72. beego.Router("/api/manage/getallpatient", &MachineApiController{}, "get:GetAllpatient")
  73. beego.Router("/api/manage/changebed", &MachineApiController{}, "get:ChangeBed")
  74. beego.Router("/api/manage/getpatientdetail", &MachineApiController{}, "get:GetPatientDetail")
  75. beego.Router("/api/manage/changrun", &MachineApiController{}, "post:SaveReminder")
  76. beego.Router("/api/manage/getremanderdata", &MachineApiController{}, "get:GetRemanderData")
  77. beego.Router("/api/manage/opendelete", &MachineApiController{}, "delete:OpenDelete")
  78. beego.Router("/api/manage/deleteuserlogin", &MachineApiController{}, "delete:DeleteUserLogin")
  79. beego.Router("/api/manage/deletecultrues", &MachineApiController{}, "delete:DeleteCultrues")
  80. beego.Router("/api/manage/deletedialystates", &MachineApiController{}, "delete:DeleteDialystates")
  81. beego.Router("/api/manage/deleteions", &MachineApiController{}, "delete:Deleteions")
  82. beego.Router("/api/manage/deleterepairs", &MachineApiController{}, "delete:DeleteRepairs")
  83. beego.Router("/api/manage/savemode", &MachineApiController{}, "post:SaveMode")
  84. beego.Router("/api/manage/getallmode", &MachineApiController{}, "get:GetAllMode")
  85. beego.Router("/api/manage/editmode", &MachineApiController{}, "get:EditMode")
  86. beego.Router("/api/manage/updatemode", &MachineApiController{}, "post:UpdateMode")
  87. beego.Router("/api/manage/deletemode", &MachineApiController{}, "delete:DeleteMode")
  88. beego.Router("/api/manage/selectchange", &MachineApiController{}, "Get:SelectChange")
  89. beego.Router("/api/manage/selectbed", &MachineApiController{}, "get:SelectBed")
  90. beego.Router("/api/manage/getime", &MachineApiController{}, "get:GetTimeData")
  91. beego.Router("/api/manage/deleteimages", &MachineApiController{}, "delete:DeleteImages")
  92. beego.Router("/api/manage/getusermachtotalcount", &MachineApiController{}, "Get:GetUserMachTotalCount")
  93. beego.Router("/api/manage/getusertotalcount", &MachineApiController{}, "Get:GetUserTotalCount")
  94. }
  95. func (this *MachineApiController) SaveManageInfo() {
  96. adminUserInfo := this.GetAdminUserInfo()
  97. orgid := adminUserInfo.CurrentOrgId
  98. //fmt.Println("机构id", orgid)
  99. dataBody := make(map[string]interface{}, 0)
  100. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  101. //fmt.Println("err", err)
  102. //serial_numbe := int64(dataBody["serial_number"].(float64))
  103. serial_numbe := dataBody["serial_number"].(string)
  104. //fmt.Println("序列号", serial_numbe)
  105. device_type := int64(dataBody["device_type"].(float64))
  106. //fmt.Println("设备类型", device_type)
  107. bed_number := int64(dataBody["bed_number"].(float64))
  108. // fmt.Println("床位号", bed_number)
  109. //通过床位id获取区号id
  110. number, err := service.GetZoneId(bed_number, orgid)
  111. //fmt.Println("number", number)
  112. // fmt.Println("获取分区id错误", err)
  113. device_name := dataBody["device_name"].(string)
  114. // fmt.Println("设备名称", device_name)
  115. manufacture_factory := dataBody["manufacture_factory"].(string)
  116. //fmt.Println("生产厂家", manufacture_factory)
  117. service_manufacturer := dataBody["service_manufacturer"].(string)
  118. // fmt.Println("维修厂家", service_manufacturer)
  119. unittype := int64(dataBody["unit_type"].(float64))
  120. unit_type := strconv.FormatInt(unittype, 10)
  121. // fmt.Println("设备型号", unit_type)
  122. use_section := dataBody["use_section"].(string)
  123. //fmt.Println("使用科室", use_section)
  124. section_number := dataBody["section_number"].(string)
  125. // fmt.Println("科室编号", section_number)
  126. buy_date := dataBody["buy_date"].(string)
  127. // fmt.Println("buy_date", buy_date)
  128. timeLayout := "2006-01-02 15:04:05"
  129. theTime, err := utils.ParseTimeStringToTime(timeLayout, buy_date+" 00:00:00")
  130. buydate := theTime.Unix()
  131. int_num := *(*int)(unsafe.Pointer(&buydate))
  132. if int_num < 0 {
  133. buydate = 0
  134. }
  135. // fmt.Println("购买日期", buydate)
  136. install_date := dataBody["install_date"].(string)
  137. toTime, err := utils.ParseTimeStringToTime(timeLayout, install_date+" 00:00:00")
  138. installdate := toTime.Unix()
  139. buy_num := *(*int)(unsafe.Pointer(&installdate))
  140. if buy_num < 0 {
  141. installdate = 0
  142. }
  143. //fmt.Println("安装日期", installdate)
  144. start_date := dataBody["start_date"].(string)
  145. stringToTime, err := utils.ParseTimeStringToTime(timeLayout, start_date+" 00:00:00")
  146. startdate := stringToTime.Unix()
  147. start_num := *(*int)(unsafe.Pointer(&startdate))
  148. if start_num < 0 {
  149. startdate = 0
  150. }
  151. // fmt.Println("启用日期", startdate)
  152. maintenance_engineer := dataBody["maintenance_engineer"].(string)
  153. //fmt.Println("维修工程", maintenance_engineer)
  154. telephone := dataBody["telephone"].(string)
  155. //fmt.Println("telephone", telephone)
  156. guarantee_date := dataBody["guarantee_date"].(string)
  157. // fmt.Println("保修期限", guarantee_date)
  158. machine_status := int64(dataBody["machine_status"].(float64))
  159. //fmt.Println("机器状态", machine_status)
  160. user_total := dataBody["user_total"].(string)
  161. //fmt.Println("初次使用次数", user_total)
  162. disinfection_mode := int64(dataBody["Disinfection_mode"].(float64))
  163. //fmt.Println("消毒方式", disinfection_mode)
  164. remarks := dataBody["remarks"].(string)
  165. //fmt.Println("备注", remarks)
  166. rubbish_date := dataBody["rubbish_date"].(string)
  167. timeStringToTime, err := utils.ParseTimeStringToTime(timeLayout, rubbish_date+" 00:00:00")
  168. rubbishdate := timeStringToTime.Unix()
  169. rubb_num := *(*int)(unsafe.Pointer(&rubbishdate))
  170. if rubb_num < 0 {
  171. rubbishdate = 0
  172. }
  173. //fmt.Println("报废日期", rubbishdate)
  174. rubbish_reason := int64(dataBody["rubbish_reason"].(float64))
  175. //fmt.Println("报废原因", rubbish_reason)
  176. user_year := dataBody["user_year"].(string)
  177. // fmt.Println("使用年限", user_year)
  178. work_time := dataBody["work_time"].(string)
  179. //fmt.Println("工作时长", work_time)
  180. treat_types := dataBody["treat_type"].([]interface{})
  181. revers := int64(dataBody["revers_mode"].(float64))
  182. //fmt.Println("反渗模式", revers)
  183. ids := make([]int64, 0)
  184. for _, treat := range treat_types {
  185. id := int64(treat.(float64))
  186. ids = append(ids, id)
  187. }
  188. //查询机位号是否绑定设备
  189. thisAddmacher, err := service.GetEquitmentByBedID(bed_number, orgid)
  190. if thisAddmacher.ID > 0 {
  191. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEquitNoExist)
  192. return
  193. }
  194. addmacher := &models.DeviceAddmacher{
  195. SerialNumber: serial_numbe,
  196. DeviceType: device_type,
  197. BedNumber: number.Number,
  198. BedId: bed_number,
  199. //ZoneId: number.ZoneID,
  200. DeviceName: device_name,
  201. ManufactureFactory: manufacture_factory,
  202. ServiceManufacturer: service_manufacturer,
  203. UnitType: unittype,
  204. UseSection: use_section,
  205. SectionNumber: section_number,
  206. BuyDate: buydate,
  207. InstallDate: installdate,
  208. StartDate: startdate,
  209. MaintenaceEngineer: maintenance_engineer,
  210. Telephone: telephone,
  211. GuaranteeDate: guarantee_date,
  212. MachineStatus: machine_status,
  213. UserTotal: user_total,
  214. DisinfectionMode: disinfection_mode,
  215. Remarks: remarks,
  216. RubbishDate: rubbishdate,
  217. RubbishReason: rubbish_reason,
  218. UserYear: user_year,
  219. WorkTime: work_time,
  220. ReversMode: revers,
  221. Status: 1,
  222. Ctime: time.Now().Unix(),
  223. UserOrgId: orgid,
  224. }
  225. err = service.CreateMacher(addmacher)
  226. //fmt.Println("什么原因啊", err)
  227. if err != nil {
  228. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  229. return
  230. }
  231. deviceAddmacher, err := service.GetLastMacherData(orgid)
  232. // fmt.Println("错误是什么", err)
  233. equimentname := models.DeviceEquimentname{
  234. EquitmentName: unit_type,
  235. Status: 1,
  236. UserOrgId: orgid,
  237. Ctime: time.Now().Unix(),
  238. EquitmentId: deviceAddmacher.ID,
  239. BedId: bed_number,
  240. }
  241. error := service.AddTreatMode(deviceAddmacher.ID, orgid, ids)
  242. fmt.Println("error:", error)
  243. name, errcode := service.GetEquitmentName(unit_type, orgid)
  244. fmt.Print("错误", errcode)
  245. fmt.Print("name", name)
  246. err = service.CreateEquimentName(equimentname)
  247. //if errcode == gorm.ErrRecordNotFound {
  248. // err = service.CreateEquimentName(equimentname)
  249. //} else if errcode == nil {
  250. // fmt.Print("设备类型已经存在")
  251. //} else {
  252. // fmt.Print("设备类型已经存在")
  253. //}
  254. fmt.Println("添加设备型号失败", err)
  255. this.ServeSuccessJSON(map[string]interface{}{
  256. "addmacher": addmacher,
  257. })
  258. }
  259. func (this *MachineApiController) UpdateMachineInfo() {
  260. adminUserInfo := this.GetAdminUserInfo()
  261. orgid := adminUserInfo.CurrentOrgId
  262. //fmt.Println("机构id", orgid)
  263. dataBody := make(map[string]interface{}, 0)
  264. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  265. //fmt.Println("错误是", err)
  266. id := int64(dataBody["id"].(float64))
  267. fmt.Println("id是什么", id)
  268. //serial_number := int64(dataBody["serial_number"].(float64))
  269. serial_number := dataBody["serial_number"].(string)
  270. fmt.Println("序列号", serial_number)
  271. device_type := int64(dataBody["devicetype"].(float64))
  272. fmt.Println("设备类型", device_type)
  273. bed_number := int64(dataBody["bed_number"].(float64))
  274. fmt.Println("机位号", bed_number)
  275. number, err := service.GetZoneId(bed_number, orgid)
  276. //fmt.Println("number是多少", number)
  277. device_name := dataBody["device_name"].(string)
  278. //fmt.Println("设备名称", device_name)
  279. manufacture_factory := dataBody["manufacture_factory"].(string)
  280. //fmt.Println("生产厂家", manufacture_factory)
  281. service_manufacturer := dataBody["service_manufacturer"].(string)
  282. //fmt.Println("维修厂家", service_manufacturer)
  283. unit_type := int64(dataBody["unit_type"].(float64))
  284. //unit_type := strconv.FormatInt(unittype, 10)
  285. fmt.Println("设备型号", unit_type)
  286. use_section := dataBody["use_section"].(string)
  287. //fmt.Println("使用科室", use_section)
  288. section_number := dataBody["section_number"].(string)
  289. //fmt.Println("科室编号", section_number)
  290. buy_date := dataBody["buy_date"].(string)
  291. // fmt.Println("buy_date", buy_date)
  292. timeLayout := "2006-01-02 15:04:05"
  293. theTime, err := utils.ParseTimeStringToTime(timeLayout, buy_date+" 00:00:00")
  294. buydate := theTime.Unix()
  295. int_num := *(*int)(unsafe.Pointer(&buydate))
  296. if int_num < 0 {
  297. buydate = 0
  298. }
  299. fmt.Println("购买日期", buydate)
  300. install_date := dataBody["install_date"].(string)
  301. toTime, err := utils.ParseTimeStringToTime(timeLayout, install_date+" 00:00:00")
  302. installdate := toTime.Unix()
  303. buy_num := *(*int)(unsafe.Pointer(&installdate))
  304. if buy_num < 0 {
  305. installdate = 0
  306. }
  307. //fmt.Println("安装日期", installdate)
  308. start_date := dataBody["start_date"].(string)
  309. stringToTime, err := utils.ParseTimeStringToTime(timeLayout, start_date+" 00:00:00")
  310. startdate := stringToTime.Unix()
  311. start_num := *(*int)(unsafe.Pointer(&startdate))
  312. if start_num < 0 {
  313. startdate = 0
  314. }
  315. //fmt.Println("启用日期", startdate)
  316. maintenance_engineer := dataBody["maintenance_engineer"].(string)
  317. //fmt.Println("维修工程", maintenance_engineer)
  318. telephone := dataBody["telephone"].(string)
  319. //fmt.Println("telephone", telephone)
  320. guarantee_date := dataBody["guarantee_date"].(string)
  321. //fmt.Println("保修期限", guarantee_date)
  322. machine_status := int64(dataBody["machine_status"].(float64))
  323. //fmt.Println("机器状态", machine_status)
  324. user_total := dataBody["user_total"].(string)
  325. //fmt.Println("初次使用次数", user_total)
  326. remarks := dataBody["remarks"].(string)
  327. //fmt.Println("备注", remarks)
  328. rubbish_date := dataBody["rubbish_date"].(string)
  329. timeStringToTime, err := utils.ParseTimeStringToTime(timeLayout, rubbish_date+" 00:00:00")
  330. rubbishdate := timeStringToTime.Unix()
  331. rubb_num := *(*int)(unsafe.Pointer(&rubbishdate))
  332. if rubb_num < 0 {
  333. rubbishdate = 0
  334. }
  335. //fmt.Println("报废日期", rubbishdate)
  336. rubbish_reason := int64(dataBody["rubbish_reason"].(float64))
  337. //fmt.Println("报废原因", rubbish_reason)
  338. user_year := dataBody["user_year"].(string)
  339. //fmt.Println("使用年限", user_year)
  340. work_time := dataBody["work_time"].(string)
  341. //fmt.Println("工作时长", work_time)
  342. treat_types := dataBody["treat_type"].([]interface{})
  343. ids := make([]int64, 0)
  344. for _, treat := range treat_types {
  345. id := int64(treat.(float64))
  346. ids = append(ids, id)
  347. }
  348. fmt.Println("ids", ids)
  349. //service.GetModeName(unit_type)
  350. thisAddmacher, err := service.GetEquitmentByBedID(bed_number, orgid)
  351. if thisAddmacher.ID > 0 && thisAddmacher.ID != id {
  352. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  353. return
  354. }
  355. addmacher := models.DeviceAddmacher{
  356. ID: id,
  357. SerialNumber: serial_number,
  358. DeviceType: device_type,
  359. BedNumber: number.Number,
  360. BedId: bed_number,
  361. DeviceName: device_name,
  362. ManufactureFactory: manufacture_factory,
  363. ServiceManufacturer: service_manufacturer,
  364. UnitType: unit_type,
  365. UseSection: use_section,
  366. SectionNumber: section_number,
  367. BuyDate: buydate,
  368. InstallDate: installdate,
  369. StartDate: startdate,
  370. MaintenaceEngineer: maintenance_engineer,
  371. Telephone: telephone,
  372. GuaranteeDate: guarantee_date,
  373. MachineStatus: machine_status,
  374. UserTotal: user_total,
  375. Remarks: remarks,
  376. RubbishDate: rubbishdate,
  377. RubbishReason: rubbish_reason,
  378. UserYear: user_year,
  379. WorkTime: work_time,
  380. }
  381. //fmt.Println("addmacher", addmacher)
  382. err = service.UpdateMachine(id, orgid, &addmacher)
  383. //mt.Println("报错", err)
  384. //zone, err := service.GetZoneName(number.ZoneID, orgid)
  385. //fmt.Println("zoneerr",err)
  386. errors := service.UpdateTreatMode(id, orgid, ids)
  387. fmt.Println("更新透析模式失败", errors)
  388. if err != nil {
  389. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  390. return
  391. }
  392. this.ServeSuccessJSON(map[string]interface{}{
  393. "addmacher": addmacher,
  394. })
  395. }
  396. func (this *MachineApiController) UpdateMachinetwo() {
  397. adminUserInfo := this.GetAdminUserInfo()
  398. orgid := adminUserInfo.CurrentOrgId
  399. //fmt.Println("机构id", orgid)
  400. dataBody := make(map[string]interface{}, 0)
  401. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  402. //fmt.Println("错误是", err)
  403. id := int64(dataBody["id"].(float64))
  404. //fmt.Println("id是什么", id)
  405. //serial_number := int64(dataBody["serial_number"].(float64))
  406. bed_nunmber := dataBody["beds"].(string)
  407. //fmt.Print("机位号z", bes)
  408. // bed_nunmber := strconv.FormatInt(bes,10)
  409. serial_number := dataBody["serial_number"].(string)
  410. //fmt.Println("序列号", serial_number)
  411. device_type := int64(dataBody["devicetype"].(float64))
  412. //fmt.Println("设备类型", device_type)
  413. // bed_nunmber := dataBody["bed_number"].(string)
  414. //fmt.Println("床位好", bed_nunmber)
  415. device_name := dataBody["device_name"].(string)
  416. //fmt.Println("设备名称", device_name)
  417. manufacture_factory := dataBody["manufacture_factory"].(string)
  418. //fmt.Println("生产厂家", manufacture_factory)
  419. service_manufacturer := dataBody["service_manufacturer"].(string)
  420. //fmt.Println("维修厂家", service_manufacturer)
  421. unit_type := int64(dataBody["unit_type"].(float64))
  422. //unit_type := strconv.FormatInt(unittype, 10)
  423. //fmt.Println("设备型号", unit_type)
  424. use_section := dataBody["use_section"].(string)
  425. //fmt.Println("使用科室", use_section)
  426. section_number := dataBody["section_number"].(string)
  427. //fmt.Println("科室编号", section_number)
  428. buy_date := dataBody["buy_date"].(string)
  429. //fmt.Println("buy_date", buy_date)
  430. timeLayout := "2006-01-02 15:04:05"
  431. theTime, err := utils.ParseTimeStringToTime(timeLayout, buy_date+" 00:00:00")
  432. buydate := theTime.Unix()
  433. int_num := *(*int)(unsafe.Pointer(&buydate))
  434. if int_num < 0 {
  435. buydate = 0
  436. }
  437. //fmt.Println("购买日期", buydate)
  438. install_date := dataBody["install_date"].(string)
  439. toTime, err := utils.ParseTimeStringToTime(timeLayout, install_date+" 00:00:00")
  440. installdate := toTime.Unix()
  441. buy_num := *(*int)(unsafe.Pointer(&installdate))
  442. if buy_num < 0 {
  443. installdate = 0
  444. }
  445. //fmt.Println("安装日期", installdate)
  446. start_date := dataBody["start_date"].(string)
  447. stringToTime, err := utils.ParseTimeStringToTime(timeLayout, start_date+" 00:00:00")
  448. startdate := stringToTime.Unix()
  449. start_num := *(*int)(unsafe.Pointer(&startdate))
  450. if start_num < 0 {
  451. startdate = 0
  452. }
  453. //fmt.Println("启用日期", startdate)
  454. maintenance_engineer := dataBody["maintenance_engineer"].(string)
  455. //fmt.Println("维修工程", maintenance_engineer)
  456. telephone := dataBody["telephone"].(string)
  457. //fmt.Println("telephone", telephone)
  458. guarantee_date := dataBody["guarantee_date"].(string)
  459. //fmt.Println("保修期限", guarantee_date)
  460. machine_status := int64(dataBody["machine_status"].(float64))
  461. //fmt.Println("机器状态", machine_status)
  462. user_total := dataBody["user_total"].(string)
  463. //fmt.Println("初次使用次数", user_total)
  464. remarks := dataBody["remarks"].(string)
  465. //fmt.Println("备注", remarks)
  466. rubbish_date := dataBody["rubbish_date"].(string)
  467. timeStringToTime, err := utils.ParseTimeStringToTime(timeLayout, rubbish_date+" 00:00:00")
  468. rubbishdate := timeStringToTime.Unix()
  469. rubb_num := *(*int)(unsafe.Pointer(&rubbishdate))
  470. if rubb_num < 0 {
  471. rubbishdate = 0
  472. }
  473. //fmt.Println("报废日期", rubbishdate)
  474. rubbish_reason := int64(dataBody["rubbish_reason"].(float64))
  475. //fmt.Println("报废原因", rubbish_reason)
  476. user_year := dataBody["user_year"].(string)
  477. //fmt.Println("使用年限", user_year)
  478. work_time := dataBody["work_time"].(string)
  479. //fmt.Println("工作时长", work_time)
  480. disinfection_mode := int64(dataBody["Disinfection_mode"].(float64))
  481. revers_modes := int64(dataBody["revers_mode"].(float64))
  482. addmacher := models.DeviceAddmacher{
  483. ID: id,
  484. SerialNumber: serial_number,
  485. DeviceType: device_type,
  486. BedNumber: bed_nunmber,
  487. DeviceName: device_name,
  488. ManufactureFactory: manufacture_factory,
  489. ServiceManufacturer: service_manufacturer,
  490. UnitType: unit_type,
  491. UseSection: use_section,
  492. SectionNumber: section_number,
  493. BuyDate: buydate,
  494. InstallDate: installdate,
  495. StartDate: startdate,
  496. MaintenaceEngineer: maintenance_engineer,
  497. Telephone: telephone,
  498. GuaranteeDate: guarantee_date,
  499. MachineStatus: machine_status,
  500. UserTotal: user_total,
  501. Remarks: remarks,
  502. RubbishDate: rubbishdate,
  503. RubbishReason: rubbish_reason,
  504. UserYear: user_year,
  505. WorkTime: work_time,
  506. DisinfectionMode: disinfection_mode,
  507. ReversMode: revers_modes,
  508. }
  509. fmt.Println("addmacher", addmacher)
  510. err = service.UpdateMachine(id, orgid, &addmacher)
  511. fmt.Println("报错", err)
  512. if err != nil {
  513. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  514. return
  515. }
  516. this.ServeSuccessJSON(map[string]interface{}{
  517. "addmacher": addmacher,
  518. })
  519. }
  520. func (this *MachineApiController) Updatemacheinetwo() {
  521. adminUserInfo := this.GetAdminUserInfo()
  522. orgid := adminUserInfo.CurrentOrgId
  523. //fmt.Println("机构id", orgid)
  524. dataBody := make(map[string]interface{}, 0)
  525. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  526. //fmt.Println("错误是", err)
  527. id := int64(dataBody["id"].(float64))
  528. //fmt.Println("id是什么", id)
  529. //serial_number := int64(dataBody["serial_number"].(float64))
  530. serial_number := dataBody["serial_number"].(string)
  531. //fmt.Println("序列号", serial_number)
  532. device_type := int64(dataBody["devicetype"].(float64))
  533. //fmt.Println("设备类型", device_type)
  534. //bed_number := int64(dataBody["bed_number"].(float64))
  535. //fmt.Println("机位号", bed_number)
  536. bednumber := dataBody["bed_numbers"].(string)
  537. //fmt.Println("机位号", bednumber)
  538. //number, err := service.GetZoneId(bed_number, orgid)
  539. //fmt.Println("number是多少", number)
  540. device_name := dataBody["device_name"].(string)
  541. //fmt.Println("设备名称", device_name)
  542. manufacture_factory := dataBody["manufacture_factory"].(string)
  543. //fmt.Println("生产厂家", manufacture_factory)
  544. service_manufacturer := dataBody["service_manufacturer"].(string)
  545. //fmt.Println("维修厂家", service_manufacturer)
  546. unittype := int64(dataBody["unit_type"].(float64))
  547. //unit_type := strconv.FormatInt(unittype, 10)
  548. //fmt.Println("设备型号", unit_type)
  549. use_section := dataBody["use_section"].(string)
  550. //fmt.Println("使用科室", use_section)
  551. section_number := dataBody["section_number"].(string)
  552. //fmt.Println("科室编号", section_number)
  553. buy_date := dataBody["buy_date"].(string)
  554. //fmt.Println("buy_date", buy_date)
  555. timeLayout := "2006-01-02 15:04:05"
  556. theTime, err := utils.ParseTimeStringToTime(timeLayout, buy_date+" 00:00:00")
  557. buydate := theTime.Unix()
  558. int_num := *(*int)(unsafe.Pointer(&buydate))
  559. if int_num < 0 {
  560. buydate = 0
  561. }
  562. //fmt.Println("购买日期", buydate)
  563. install_date := dataBody["install_date"].(string)
  564. toTime, err := utils.ParseTimeStringToTime(timeLayout, install_date+" 00:00:00")
  565. installdate := toTime.Unix()
  566. buy_num := *(*int)(unsafe.Pointer(&installdate))
  567. if buy_num < 0 {
  568. installdate = 0
  569. }
  570. //fmt.Println("安装日期", installdate)
  571. start_date := dataBody["start_date"].(string)
  572. stringToTime, err := utils.ParseTimeStringToTime(timeLayout, start_date+" 00:00:00")
  573. startdate := stringToTime.Unix()
  574. start_num := *(*int)(unsafe.Pointer(&startdate))
  575. if start_num < 0 {
  576. startdate = 0
  577. }
  578. //fmt.Println("启用日期", startdate)
  579. maintenance_engineer := dataBody["maintenance_engineer"].(string)
  580. //fmt.Println("维修工程", maintenance_engineer)
  581. telephone := dataBody["telephone"].(string)
  582. //fmt.Println("telephone", telephone)
  583. guarantee_date := dataBody["guarantee_date"].(string)
  584. //fmt.Println("保修期限", guarantee_date)
  585. machine_status := int64(dataBody["machine_status"].(float64))
  586. //fmt.Println("机器状态", machine_status)
  587. user_total := dataBody["user_total"].(string)
  588. //fmt.Println("初次使用次数", user_total)
  589. remarks := dataBody["remarks"].(string)
  590. //fmt.Println("备注", remarks)
  591. rubbish_date := dataBody["rubbish_date"].(string)
  592. timeStringToTime, err := utils.ParseTimeStringToTime(timeLayout, rubbish_date+" 00:00:00")
  593. rubbishdate := timeStringToTime.Unix()
  594. rubb_num := *(*int)(unsafe.Pointer(&rubbishdate))
  595. if rubb_num < 0 {
  596. rubbishdate = 0
  597. }
  598. //fmt.Println("报废日期", rubbishdate)
  599. rubbish_reason := int64(dataBody["rubbish_reason"].(float64))
  600. //fmt.Println("报废原因", rubbish_reason)
  601. user_year := dataBody["user_year"].(string)
  602. //fmt.Println("使用年限", user_year)
  603. work_time := dataBody["work_time"].(string)
  604. //fmt.Println("工作时长", work_time)
  605. addmacher := models.DeviceAddmacher{
  606. ID: id,
  607. SerialNumber: serial_number,
  608. DeviceType: device_type,
  609. BedNumber: bednumber,
  610. DeviceName: device_name,
  611. ManufactureFactory: manufacture_factory,
  612. ServiceManufacturer: service_manufacturer,
  613. UnitType: unittype,
  614. UseSection: use_section,
  615. SectionNumber: section_number,
  616. BuyDate: buydate,
  617. InstallDate: installdate,
  618. StartDate: startdate,
  619. MaintenaceEngineer: maintenance_engineer,
  620. Telephone: telephone,
  621. GuaranteeDate: guarantee_date,
  622. MachineStatus: machine_status,
  623. UserTotal: user_total,
  624. Remarks: remarks,
  625. RubbishDate: rubbishdate,
  626. RubbishReason: rubbish_reason,
  627. UserYear: user_year,
  628. WorkTime: work_time,
  629. }
  630. //fmt.Println("addmacher", addmacher)
  631. err = service.UpdateMachine(id, orgid, &addmacher)
  632. //fmt.Println("报错", err)
  633. if err != nil {
  634. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  635. return
  636. }
  637. this.ServeSuccessJSON(map[string]interface{}{
  638. "addmacher": addmacher,
  639. })
  640. }
  641. func (this *MachineApiController) GetAllEquimentName() {
  642. adminUser := this.GetAdminUserInfo()
  643. orgid := adminUser.CurrentOrgId
  644. equit, err := service.GetAllEquimentName(orgid)
  645. if err != nil {
  646. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  647. return
  648. }
  649. this.ServeSuccessJSON(map[string]interface{}{
  650. "equit": equit,
  651. })
  652. }
  653. func (this *MachineApiController) SavePlan() {
  654. id, _ := this.GetInt64("id")
  655. //fmt.Println("设备id", id)
  656. adminUserInfo := this.GetAdminUserInfo()
  657. orgid := adminUserInfo.CurrentOrgId
  658. //fmt.Println("机构id", orgid)
  659. dataBody := make(map[string]interface{}, 0)
  660. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  661. //fmt.Println("错误是", err)
  662. device_type := int64(dataBody["device_type"].(float64))
  663. //fmt.Println("设备型号", device_type)
  664. disinfec_time := dataBody["disinfec_time"].(string)
  665. //fmt.Println("消毒时长", disinfec_time)
  666. time := dataBody["time"].([]interface{})
  667. //fmt.Println("时间", time)
  668. ids := make([]int64, 0)
  669. for _, t := range time {
  670. id := int64(t.(float64))
  671. ids = append(ids, id)
  672. }
  673. //fmt.Println("ids", ids)
  674. classtime := dataBody["class_time"].([]interface{})
  675. //fmt.Println("班次", classtime)
  676. classids := make([]int64, 0)
  677. for _, class := range classtime {
  678. id := int64(class.(float64))
  679. classids = append(classids, id)
  680. }
  681. //fmt.Println("classids", classids)
  682. way := int64(dataBody["way"].(float64))
  683. //fmt.Println("基表消毒方式", way)
  684. machinedisinfectant := int64(dataBody["machine_disinfectant"].(float64))
  685. //fmt.Println("基表消毒液", machinedisinfectant)
  686. disinfectantway := int64(dataBody["disinfectant_way"].(float64))
  687. //fmt.Println("液路消毒方式", disinfectantway)
  688. disinfectant := int64(dataBody["disinfectant"].(float64))
  689. //fmt.Println("液路消毒液", disinfectant)
  690. bed, err := service.GetBed(id)
  691. _, errcode := service.QueryPlan(orgid, device_type, ids, classids, id)
  692. fmt.Print("errcode ---------", errcode)
  693. if errcode == gorm.ErrRecordNotFound {
  694. err = service.AddPlan(orgid, device_type, disinfec_time, ids, classids, way, machinedisinfectant, disinfectantway, disinfectant, id, bed.BedId)
  695. if err != nil {
  696. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加计划失败")
  697. return
  698. }
  699. this.ServeSuccessJSON(map[string]interface{}{
  700. "msg": "msg",
  701. })
  702. } else if errcode == nil {
  703. this.ServeFailJsonSend(enums.ErrorCodeDataException, "已存在")
  704. return
  705. } else {
  706. this.ServeFailJsonSend(enums.ErrorCodeDataException, "已存在")
  707. return
  708. }
  709. }
  710. func (this *MachineApiController) GetAllPlan() {
  711. adminUserin := this.GetAdminUserInfo()
  712. orgid := adminUserin.CurrentOrgId
  713. plan, err := service.GetAllPlan(orgid)
  714. if err != nil {
  715. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  716. return
  717. }
  718. this.ServeSuccessJSON(map[string]interface{}{
  719. "plan": plan,
  720. })
  721. }
  722. func (this *MachineApiController) GetAllPlanDetail() {
  723. //id, _ := this.GetInt64("id")
  724. //更据设备ID获取设备型号
  725. //fmt.Print("=================失败ID",id)
  726. unitype := this.GetString("unitype")
  727. deviceType, err2 := service.GetDeviceType(unitype)
  728. fmt.Print("eer2", err2)
  729. adminUserInfo := this.GetAdminUserInfo()
  730. orgid := adminUserInfo.CurrentOrgId
  731. //fmt.Println("orgid", orgid)
  732. plandetail, err := service.GetAllPlanDetail(deviceType.ID, orgid)
  733. if err != nil {
  734. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  735. return
  736. }
  737. this.ServeSuccessJSON(map[string]interface{}{
  738. "plandetail": plandetail,
  739. })
  740. }
  741. func (this *MachineApiController) GetEditMahchine() {
  742. id, _ := this.GetInt64("id")
  743. fmt.Print("id", id)
  744. }
  745. func (this *MachineApiController) DeletePlans() {
  746. adminUserInfo := this.GetAdminUserInfo()
  747. OrgID := adminUserInfo.CurrentOrgId
  748. dataBody := make(map[string]interface{}, 0)
  749. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  750. if err != nil {
  751. utils.ErrorLog(err.Error())
  752. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  753. return
  754. }
  755. idsInters := dataBody["ids"].([]interface{})
  756. if len(idsInters) == 0 {
  757. if err != nil {
  758. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  759. return
  760. }
  761. }
  762. ids := make([]int64, 0)
  763. for _, idsInter := range idsInters {
  764. id := int64(idsInter.(float64))
  765. ids = append(ids, id)
  766. }
  767. err = service.DeletePlans(OrgID, ids)
  768. if err != nil {
  769. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败:("+err.Error()+")")
  770. return
  771. }
  772. returnData := make(map[string]interface{}, 0)
  773. returnData["msg"] = "ok"
  774. this.ServeSuccessJSON(returnData)
  775. return
  776. }
  777. func (this *MachineApiController) EditPlanDetail() {
  778. id, _ := this.GetInt64("id")
  779. adminUserInfo := this.GetAdminUserInfo()
  780. orgId := adminUserInfo.CurrentOrgId
  781. plan, err := service.GetPlanDetailById(id, orgId)
  782. fmt.Println("err", err)
  783. if err != nil {
  784. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败:("+err.Error()+")")
  785. return
  786. }
  787. this.ServeSuccessJSON(map[string]interface{}{
  788. "plan": plan,
  789. })
  790. }
  791. func (this *MachineApiController) UpdatePlanInfo() {
  792. dataBody := make(map[string]interface{}, 0)
  793. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  794. //fmt.Println("错误是", err)
  795. id := int64(dataBody["id"].(float64))
  796. //fmt.Println("id", id)
  797. device_type := int64(dataBody["device_type"].(float64))
  798. //fmt.Println("设备型号", device_type)
  799. disinfec_time := int64(dataBody["disinfec_time"].(float64))
  800. //fmt.Println("消毒时长", disinfec_time)
  801. time := int64(dataBody["time"].(float64))
  802. //fmt.Println("时间", time)
  803. classtime := int64(dataBody["class_time"].(float64))
  804. //fmt.Println("班次", classtime)
  805. way := int64(dataBody["way"].(float64))
  806. //fmt.Println("基表消毒方式", way)
  807. machinedisinfectant := int64(dataBody["machine_disinfectant"].(float64))
  808. //fmt.Println("基表消毒液", machinedisinfectant)
  809. disinfectantway := int64(dataBody["disinfectant_way"].(float64))
  810. fmt.Println("液路消毒方式", disinfectantway)
  811. disinfectant := int64(dataBody["disinfectant"].(float64))
  812. //fmt.Println("液路消毒液", disinfectant)
  813. adminUserInfo := this.GetAdminUserInfo()
  814. orgid := adminUserInfo.CurrentOrgId
  815. //fmt.Println("orgid", orgid)
  816. plan := models.DevicePlan{
  817. DeviceType: device_type,
  818. DisinfecTime: disinfec_time,
  819. Time: time,
  820. Classtime: classtime,
  821. Way: way,
  822. MachineDisinfectant: machinedisinfectant,
  823. DisinfectanWay: disinfectantway,
  824. Disinfectant: disinfectant,
  825. }
  826. err = service.UpdatePlanInfo(id, orgid, plan)
  827. fmt.Println("err", err)
  828. if err != nil {
  829. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败:("+err.Error()+")")
  830. return
  831. }
  832. this.ServeSuccessJSON(map[string]interface{}{
  833. "plan": plan,
  834. })
  835. }
  836. func (this *MachineApiController) GetComprehensive() {
  837. zone, _ := this.GetInt64("zone")
  838. //fmt.Println("分区", zone)
  839. number, _ := this.GetInt64("number")
  840. //fmt.Println("机号", number)
  841. devicetype, _ := this.GetInt64("devicetype")
  842. //fmt.Println("type", devicetype)
  843. year, _ := this.GetInt64("year")
  844. //fmt.Println("year", year)
  845. startTime := this.GetString("starttime")
  846. //fmt.Println("开始时间", startTime)
  847. timeLayout := "2006-01-02"
  848. loc, _ := time.LoadLocation("Local")
  849. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  850. starts := theTime.Unix()
  851. //fmt.Println("开始日期", starts)
  852. endtime := this.GetString("endtime")
  853. location, _ := time.ParseInLocation(timeLayout+" 15:04:05", endtime+" 00:00:00", loc)
  854. end := location.Unix()
  855. //fmt.Println("endtime", end)
  856. adminUserInfo := this.GetAdminUserInfo()
  857. orgid := adminUserInfo.CurrentOrgId
  858. macher, err := service.GetComprehensive(zone, number, devicetype, year, starts, end, orgid)
  859. if err != nil {
  860. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败:("+err.Error()+")")
  861. return
  862. }
  863. this.ServeSuccessJSON(map[string]interface{}{
  864. "macher": macher,
  865. })
  866. }
  867. func (this *MachineApiController) GetPatientInfo() {
  868. adminUser := this.GetAdminUserInfo()
  869. orgid := adminUser.CurrentOrgId
  870. //fmt.Println("机构id", orgid)
  871. id, _ := this.GetInt64("id")
  872. //fmt.Println("设备id", id)
  873. addmacher, _ := service.GetBedId(id)
  874. //fmt.Println("addmacher", addmacher.BedId)
  875. timeStr := time.Now().Format("2006-01-02")
  876. timeLayout := "2006-01-02 15:04:05"
  877. //fmt.Println("timeStr:", timeStr)
  878. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  879. timenow := timeStringToTime.Unix()
  880. fmt.Println("timenow是什么", timenow)
  881. //fmt.Println("时间搓", timeStringToTime.Unix())
  882. //获取当天床位号排班的所有病人
  883. schedules, err := service.GetPatientInfo(addmacher.BedId, timenow, orgid)
  884. //fmt.Println("错误", err)
  885. if err != nil {
  886. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败:("+err.Error()+")")
  887. return
  888. }
  889. this.ServeSuccessJSON(map[string]interface{}{
  890. "schedules": schedules,
  891. })
  892. }
  893. func (this *MachineApiController) GetPatient() {
  894. adminUser := this.GetAdminUserInfo()
  895. orgid := adminUser.CurrentOrgId
  896. //fmt.Println("机构id", orgid)
  897. equitid, _ := this.GetInt64("equitid")
  898. //fmt.Println("设备id", equitid)
  899. addmacher, _ := service.GetBedId(equitid)
  900. id, _ := this.GetInt64("id")
  901. //fmt.Println("班次id", id)
  902. timeStr := time.Now().Format("2006-01-02")
  903. timeLayout := "2006-01-02 15:04:05"
  904. //fmt.Println("timeStr:", timeStr)
  905. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  906. timenow := timeStringToTime.Unix()
  907. //fmt.Println("timenow是什么", timenow)
  908. schedules, err := service.GetPatient(addmacher.BedId, orgid, id, timenow)
  909. //fmt.Println("schedules", schedules.PartitionId)
  910. //获取区号姓名
  911. zone, _ := service.GetPartitionName(schedules.PartitionId)
  912. //获取机位号
  913. number, _ := service.GetPatientNumber(schedules.BedId)
  914. //获取上机时间和下机时间
  915. order, _ := service.GetDialysisOrder(timenow, schedules.PatientId, orgid)
  916. //获取透析方式
  917. prescription, _ := service.GetDialysisWay(timenow, schedules.PatientId, orgid)
  918. //获取透析时长
  919. dislysis, _ := service.GetDialysisTime(timenow, schedules.PatientId, orgid)
  920. if err != nil {
  921. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败:("+err.Error()+")")
  922. return
  923. }
  924. this.ServeSuccessJSON(map[string]interface{}{
  925. "patients": schedules,
  926. "zone": zone,
  927. "number": number,
  928. "order": order,
  929. "prescription": prescription,
  930. "dislysis": dislysis,
  931. })
  932. }
  933. func (this *MachineApiController) GetAllOrganization() {
  934. adminUserInfo := this.GetAdminUserInfo()
  935. orgid := adminUserInfo.CurrentOrgId
  936. //fmt.Println("orgid", orgid)
  937. appid := adminUserInfo.CurrentAppId
  938. //fmt.Println("appid", appid)
  939. approle, err := service.GetAllOrganization(orgid, appid)
  940. if err != nil {
  941. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  942. return
  943. }
  944. this.ServeSuccessJSON(map[string]interface{}{
  945. "approle": approle,
  946. })
  947. }
  948. func (this *MachineApiController) SaveInformation() {
  949. eid, _ := this.GetInt64("eid")
  950. fmt.Print("eid-------", eid)
  951. dataBody := make(map[string]interface{}, 0)
  952. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  953. //fmt.Println("错误是", err)
  954. adminUserInfo := this.GetAdminUserInfo()
  955. orgid := adminUserInfo.CurrentOrgId
  956. id := int64(dataBody["id"].(float64))
  957. fmt.Println("id", id)
  958. date := dataBody["date"].(string)
  959. timeLayout := "2006-01-02"
  960. loc, _ := time.LoadLocation("Local")
  961. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", date+" 00:00:00", loc)
  962. startdate := theTime.Unix()
  963. //fmt.Println("日期", startdate)
  964. classtype := int64(dataBody["classtype"].(float64))
  965. //fmt.Println("班次", classtype)
  966. zone := int64(dataBody["zone"].(float64))
  967. //fmt.Println("分区", zone)
  968. bednumber := int64(dataBody["bed_number"].(float64))
  969. //fmt.Println("床位号", bednumber)
  970. number, err := service.GetNumbers(bednumber, orgid)
  971. patient_time := int64(dataBody["patient_id"].(float64))
  972. //fmt.Println("患者", patient_time)
  973. contagion := dataBody["contagion"].(string)
  974. //fmt.Println("传染病", contagion)
  975. dialysis_mode := int64(dataBody["dialysis_mode"].(float64))
  976. //fmt.Println("透析方式", dialysis_mode)
  977. startDateStr := dataBody["start_time"].(string)
  978. //fmt.Println("上机时间", startDateStr)
  979. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startDateStr)
  980. //fmt.Println("上机时间", startDate.Unix())
  981. endDateStr := dataBody["end_time"].(string)
  982. endDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", endDateStr)
  983. //fmt.Println("下机时间", endDate.Unix())
  984. dialysis_time := dataBody["dialysis_time"].(string)
  985. //fmt.Println("透析时长", dialysis_time)
  986. //hyperfiletration := dataBody["hyperfiltratio"].(string)
  987. hyperfiletration := dataBody["hyperfiltratio"].(float64)
  988. //hyperfiletration := strconv.FormatInt(hyperfiltratios, 10)
  989. fmt.Println("实际超滤量", hyperfiletration)
  990. //weight_loss := dataBody["weight_loss"].(string)
  991. weight_loss := dataBody["weight_loss"].(float64)
  992. //weight_loss := strconv.FormatInt(weightloss, 10)
  993. fmt.Println("体重减少", weight_loss)
  994. warining_value := dataBody["warning_value"].(string)
  995. fmt.Println("预警值", warining_value)
  996. //user_total := dataBody["user_total"].(string)
  997. //fmt.Println("使用次数",user_total)
  998. usertotal := int64(dataBody["user_total"].(float64))
  999. user_total := strconv.FormatInt(usertotal, 10)
  1000. run := int64(dataBody["run"].(float64))
  1001. //fmt.Println("运行", run)
  1002. failure_stage := int64(dataBody["failure_stage"].(float64))
  1003. //fmt.Println("故事发生阶段", failure_stage)
  1004. falult_desciription := dataBody["fault_description"].(string)
  1005. //fmt.Println("故障描述", falult_desciription)
  1006. code_information := dataBody["code_information"].(string)
  1007. //fmt.Println("故障提示及代码", code_information)
  1008. //机器消毒
  1009. disinfect_type := int64(dataBody["disinfect_type"].(float64))
  1010. //fmt.Println("消毒方式", disinfect_type)
  1011. disinfectant_type := int64(dataBody["disinfectant_type"].(float64))
  1012. //fmt.Println("消毒液", disinfectant_type)
  1013. disinfection := int64(dataBody["disinfection"].(float64))
  1014. //fmt.Println("消毒状态", disinfection)
  1015. machine_run := int64(dataBody["machine_run"].(float64))
  1016. //fmt.Println("运行", machine_run)
  1017. //液路
  1018. fluid_path := int64(dataBody["fluid_path"].(float64))
  1019. //fmt.Println("液路消毒方式", fluid_path)
  1020. disinfectant := int64(dataBody["disinfectant"].(float64))
  1021. //fmt.Println("消毒液", disinfectant)
  1022. disinfection_status := int64(dataBody["disinfection_status"].(float64))
  1023. //fmt.Println("消毒状态", disinfection_status)
  1024. disinfection_residue := int64(dataBody["disinfection_residue"].(float64))
  1025. //fmt.Println("消毒液残留", disinfection_residue)
  1026. longtime := dataBody["longtime"].(string)
  1027. //fmt.Println("消毒时长", longtime)
  1028. start_DateStr := dataBody["starttime"].(string)
  1029. //fmt.Println("出发时间", startDateStr)
  1030. start_Date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", start_DateStr)
  1031. //fmt.Println("触发事件", start_Date.Unix())
  1032. end_DateStr := dataBody["endtime"].(string)
  1033. //fmt.Println("出发时间", startDateStr)
  1034. end_Date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", end_DateStr)
  1035. //fmt.Println("触发事件", end_Date.Unix())
  1036. dialysis_checked := int64(dataBody["dialysis_checked"].(float64))
  1037. //fmt.Println("更换", dialysis_checked)
  1038. dialysis_name := int64(dataBody["dialysis_name"].(float64))
  1039. //fmt.Println("名称", dialysis_name)
  1040. norms := dataBody["norms"].(string)
  1041. //fmt.Println("规格", norms)
  1042. dialysis_concentration := int64(dataBody["dialysis_concentration"].(float64))
  1043. //fmt.Println("浓度", dialysis_concentration)
  1044. germ_checked := int64(dataBody["germ_checked"].(float64))
  1045. //fmt.Println("更换", germ_checked)
  1046. germ_name := int64(dataBody["germ_name"].(float64))
  1047. //fmt.Println("名称", germ_name)
  1048. germ_number := dataBody["germ_number"].(string)
  1049. //fmt.Println("数量", germ_number)
  1050. clean := int64(dataBody["clean"].(float64))
  1051. //fmt.Println("清洁", clean)
  1052. sign_name := int64(dataBody["sign_name"].(float64))
  1053. //fmt.Println("签名", sign_name)
  1054. information, errinfor := service.GetInformation(eid, startdate, orgid)
  1055. fmt.Print("errinfor", errinfor)
  1056. fmt.Print("information", information)
  1057. if errinfor == gorm.ErrRecordNotFound {
  1058. infor := models.DeviceInformation{
  1059. Date: startdate,
  1060. Class: classtype,
  1061. // Zone: zone,
  1062. BedNumber: bednumber,
  1063. PatientId: patient_time,
  1064. Contagion: contagion,
  1065. DialysisMode: dialysis_mode,
  1066. StartTime: startDate.Unix(),
  1067. EndTime: endDate.Unix(),
  1068. DialysisHour: dialysis_time,
  1069. Hyperfiltratio: hyperfiletration,
  1070. WeightLoss: weight_loss,
  1071. WarningValue: warining_value,
  1072. UserTotal: user_total,
  1073. Move: run,
  1074. FailureStage: failure_stage,
  1075. FaultDescription: falult_desciription,
  1076. CodeInformation: code_information,
  1077. DisinfectantType: disinfectant_type,
  1078. DisinfectType: disinfect_type,
  1079. Disinfection: disinfection,
  1080. MachineRun: machine_run,
  1081. FluidPath: fluid_path,
  1082. Disinfectant: disinfectant,
  1083. DisinfectionStatus: disinfection_status,
  1084. DisinfectionResidue: disinfection_residue,
  1085. LongTime: longtime,
  1086. DisinfecStartime: start_Date.Unix(),
  1087. DisinfecEndtime: end_Date.Unix(),
  1088. DialysisChecked: dialysis_checked,
  1089. DialysisName: dialysis_name,
  1090. Norms: norms,
  1091. DialysisConcentration: dialysis_concentration,
  1092. GermChecked: germ_checked,
  1093. GermName: germ_name,
  1094. GermNumber: germ_number,
  1095. Clean: clean,
  1096. SignName: sign_name,
  1097. Ctime: time.Now().Unix(),
  1098. Status: 1,
  1099. UserOrgId: orgid,
  1100. EquimentId: eid,
  1101. Bed: number.Number,
  1102. Stime: startdate,
  1103. }
  1104. err = service.CreateUserInformation(&infor)
  1105. fmt.Println("使用登记错误是什么", err)
  1106. this.ServeSuccessJSON(map[string]interface{}{
  1107. "information": infor,
  1108. })
  1109. } else if errinfor == nil {
  1110. infor := models.DeviceInformation{
  1111. Date: startdate,
  1112. Class: classtype,
  1113. Zone: zone,
  1114. BedNumber: bednumber,
  1115. PatientId: patient_time,
  1116. Contagion: contagion,
  1117. DialysisMode: dialysis_mode,
  1118. StartTime: startDate.Unix(),
  1119. EndTime: endDate.Unix(),
  1120. DialysisHour: dialysis_time,
  1121. Hyperfiltratio: hyperfiletration,
  1122. WeightLoss: weight_loss,
  1123. WarningValue: warining_value,
  1124. UserTotal: user_total,
  1125. Move: run,
  1126. FailureStage: failure_stage,
  1127. FaultDescription: falult_desciription,
  1128. CodeInformation: code_information,
  1129. DisinfectantType: disinfectant_type,
  1130. DisinfectType: disinfect_type,
  1131. Disinfection: disinfection,
  1132. MachineRun: machine_run,
  1133. FluidPath: fluid_path,
  1134. Disinfectant: disinfectant,
  1135. DisinfectionStatus: disinfection_status,
  1136. DisinfectionResidue: disinfection_residue,
  1137. LongTime: longtime,
  1138. DisinfecStartime: start_Date.Unix(),
  1139. DisinfecEndtime: end_Date.Unix(),
  1140. DialysisChecked: dialysis_checked,
  1141. DialysisName: dialysis_name,
  1142. Norms: norms,
  1143. DialysisConcentration: dialysis_concentration,
  1144. GermChecked: germ_checked,
  1145. GermName: germ_name,
  1146. GermNumber: germ_number,
  1147. Clean: clean,
  1148. SignName: sign_name,
  1149. Ctime: time.Now().Unix(),
  1150. Status: 1,
  1151. UserOrgId: orgid,
  1152. EquimentId: eid,
  1153. Bed: number.Number,
  1154. }
  1155. informationdata, err := service.GetLastInformationdata(eid, startdate, orgid)
  1156. fmt.Print("informationdata----", informationdata.ID)
  1157. errors := service.UpadateForm(informationdata.ID, orgid, &infor)
  1158. //fmt.Print("报错", errors)
  1159. if errors != nil {
  1160. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  1161. return
  1162. }
  1163. this.ServeSuccessJSON(map[string]interface{}{
  1164. "infor": infor,
  1165. })
  1166. } else {
  1167. }
  1168. }
  1169. func (this *MachineApiController) ChangePatient() {
  1170. adminUser := this.GetAdminUserInfo()
  1171. orgid := adminUser.CurrentOrgId
  1172. fmt.Println("机构id", orgid)
  1173. equitid, _ := this.GetInt64("equitid")
  1174. fmt.Println("equitid", equitid)
  1175. id, _ := this.GetInt64("id")
  1176. fmt.Println("id", id)
  1177. }
  1178. func (this *MachineApiController) GetRegisterInfo() {
  1179. timeStr := time.Now().Format("2006-01-02")
  1180. timeLayout := "2006-01-02 15:04:05"
  1181. //fmt.Println("timeStr:", timeStr)
  1182. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  1183. timenow := timeStringToTime.Unix()
  1184. //fmt.Println("timenow是什么", timenow)
  1185. adminUser := this.GetAdminUserInfo()
  1186. orgid := adminUser.CurrentOrgId
  1187. appid := adminUser.CurrentAppId
  1188. id, _ := this.GetInt64("id")
  1189. //fmt.Println("设备id", id)
  1190. information, err := service.GetRegisterInfo(orgid, id, timenow)
  1191. fmt.Print("错误", err)
  1192. role, err := service.GetSignName(information.SignName, orgid, appid)
  1193. dislysis, _ := service.GetDialysisTime(timenow, information.PatientId, orgid)
  1194. //if err != nil {
  1195. // // this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  1196. // // return
  1197. // //}
  1198. this.ServeSuccessJSON(map[string]interface{}{
  1199. "information": information,
  1200. "role": role,
  1201. "dislysis": dislysis,
  1202. })
  1203. }
  1204. func (this *MachineApiController) GetInformationData() {
  1205. limit, _ := this.GetInt64("limit")
  1206. //fmt.Println("limit2", limit)
  1207. page, _ := this.GetInt64("page")
  1208. //fmt.Println("page", page)
  1209. adminUser := this.GetAdminUserInfo()
  1210. orgId := adminUser.CurrentOrgId
  1211. information, total, err := service.GetInformationData(limit, page, orgId)
  1212. if err != nil {
  1213. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  1214. return
  1215. }
  1216. this.ServeSuccessJSON(map[string]interface{}{
  1217. "information": information,
  1218. "total": total,
  1219. })
  1220. }
  1221. func (this *MachineApiController) GetOrgName() {
  1222. adminUser := this.GetAdminUserInfo()
  1223. orgid := adminUser.CurrentOrgId
  1224. org, err := service.GetOrgName(orgid)
  1225. if err != nil {
  1226. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  1227. return
  1228. }
  1229. this.ServeSuccessJSON(map[string]interface{}{
  1230. "org": org,
  1231. })
  1232. }
  1233. func (this *MachineApiController) SaveBacteria() {
  1234. id, _ := this.GetInt64("id")
  1235. //fmt.Println("id", id)
  1236. addmacher, _ := service.GetBedId(id)
  1237. //fmt.Println("addmache", addmacher.BedId)
  1238. adminUserInfo := this.GetAdminUserInfo()
  1239. orgid := adminUserInfo.CurrentOrgId
  1240. //fmt.Println("机构id", orgid)
  1241. dataBody := make(map[string]interface{}, 0)
  1242. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1243. //fmt.Println("err", err)
  1244. date := dataBody["date"].(string)
  1245. //fmt.Println("取样日期", date)
  1246. timeLayout := "2006-01-02"
  1247. loc, _ := time.LoadLocation("Local")
  1248. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", date+" 00:00:00", loc)
  1249. state_date := theTime.Unix()
  1250. //fmt.Println("取样日期", state_date)
  1251. specimen := int64(dataBody["specimen"].(float64))
  1252. //fmt.Println("取样标本", specimen)
  1253. cona := dataBody["concentrate_noa"].(string)
  1254. //fmt.Println("A浓缩液批号", cona)
  1255. conb := dataBody["concentrate_nob"].(string)
  1256. //fmt.Println("B浓批号", conb)
  1257. samplingLoactiona := int64(dataBody["sampling_locationa"].(float64))
  1258. //fmt.Println("采样部位", samplingLoactiona)
  1259. detectionUnit := dataBody["detection_unit"].(string)
  1260. //fmt.Println("检测单位", detectionUnit)
  1261. sampler := int64(dataBody["sampler"].(float64))
  1262. //fmt.Println("取样者", sampler)
  1263. reportDate := dataBody["reporting_date"].(string)
  1264. reportTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", reportDate+" 00:00:00", loc)
  1265. repDate := reportTime.Unix()
  1266. //fmt.Println("出报告日期", repDate)
  1267. detectionResult := dataBody["detection_result"].(string)
  1268. //fmt.Println("检测结果", detectionResult)
  1269. culture := models.DeviceCulture{
  1270. BedId: addmacher.BedId,
  1271. SpelingDate: state_date,
  1272. Specimen: specimen,
  1273. ConcentrateNoa: cona,
  1274. ConcentrateNob: conb,
  1275. SamplingLocationa: samplingLoactiona,
  1276. DetectionUnit: detectionUnit,
  1277. Sampler: sampler,
  1278. ReportingDate: repDate,
  1279. DetectionResult: detectionResult,
  1280. Ctime: time.Now().Unix(),
  1281. Status: 1,
  1282. UserOrgId: orgid,
  1283. EquitmentId: id,
  1284. Bed: addmacher.BedNumber,
  1285. }
  1286. err = service.CreateCulture(&culture)
  1287. //fmt.Println("创建细菌检测", err)
  1288. if err != nil {
  1289. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "添加失败:("+err.Error()+")")
  1290. return
  1291. }
  1292. this.ServeSuccessJSON(map[string]interface{}{
  1293. "culture": culture,
  1294. })
  1295. }
  1296. func (this *MachineApiController) SaveLinconmycin() {
  1297. timeLayout := "2006-01-02"
  1298. loc, _ := time.LoadLocation("Local")
  1299. id, _ := this.GetInt64("id")
  1300. //fmt.Println("id", id)
  1301. addmacher, _ := service.GetBedId(id)
  1302. //fmt.Println("addmache", addmacher.BedId)
  1303. adminUserInfo := this.GetAdminUserInfo()
  1304. orgid := adminUserInfo.CurrentOrgId
  1305. //fmt.Println("机构id", orgid)
  1306. dataBody := make(map[string]interface{}, 0)
  1307. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1308. //fmt.Println("err", err)
  1309. date := dataBody["sampling_date"].(string)
  1310. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", date+" 00:00:00", loc)
  1311. samp_date := theTime.Unix()
  1312. specimen := int64(dataBody["specimenb"].(float64))
  1313. //fmt.Println("取样标本", specimen)
  1314. cona := dataBody["concentrate_noc"].(string)
  1315. //fmt.Println("A浓缩液批号", cona)
  1316. conb := dataBody["concentrateb_nod"].(string)
  1317. //fmt.Println("B浓批号", conb)
  1318. samplinglocationb := int64(dataBody["sampling_locationb"].(float64))
  1319. //fmt.Println("采样部位", samplinglocationb)
  1320. detectionUnit := dataBody["detection_unit"].(string)
  1321. //fmt.Println("检测单位", detectionUnit)
  1322. samplerb := int64(dataBody["samplerb"].(float64))
  1323. //fmt.Println("取样者", samplerb)
  1324. reportDate := dataBody["reporting_dateb"].(string)
  1325. reportTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", reportDate+" 00:00:00", loc)
  1326. repDate := reportTime.Unix()
  1327. //fmt.Println("出报告日期", repDate)
  1328. detectionResult := dataBody["detection_resultb"].(string)
  1329. //fmt.Println("检测结果2", detectionResult)
  1330. dialysate := models.DeviceDialysate{
  1331. SamplingDate: samp_date,
  1332. Specimenb: specimen,
  1333. ConcentrateNoc: cona,
  1334. ConcentratebNod: conb,
  1335. SamplingLocationb: samplinglocationb,
  1336. DetectionUnit: detectionUnit,
  1337. Samplerb: samplerb,
  1338. ReportingDateb: repDate,
  1339. DetectionResultb: detectionResult,
  1340. Ctime: time.Now().Unix(),
  1341. Status: 1,
  1342. UserOrgId: orgid,
  1343. BedId: addmacher.BedId,
  1344. EquitmentId: id,
  1345. Bed: addmacher.BedNumber,
  1346. }
  1347. err = service.CreateDialysate(&dialysate)
  1348. //fmt.Println("报错", err)
  1349. if err != nil {
  1350. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "添加失败:("+err.Error()+")")
  1351. return
  1352. }
  1353. this.ServeSuccessJSON(map[string]interface{}{
  1354. "dialysate": dialysate,
  1355. })
  1356. }
  1357. func (this *MachineApiController) SaveQualityControl() {
  1358. id, _ := this.GetInt64("id")
  1359. //fmt.Println("id", id)
  1360. addmacher, _ := service.GetBedId(id)
  1361. //fmt.Println("addmache", addmacher.BedId)
  1362. adminUserInfo := this.GetAdminUserInfo()
  1363. orgid := adminUserInfo.CurrentOrgId
  1364. //fmt.Println("机构id", orgid)
  1365. dataBody := make(map[string]interface{}, 0)
  1366. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1367. //fmt.Println("err", err)
  1368. timeLayout := "2006-01-02"
  1369. loc, _ := time.LoadLocation("Local")
  1370. // 透析液离子浓度检测
  1371. dateb := dataBody["dateb"].(string)
  1372. inLocation, _ := time.ParseInLocation(timeLayout+" 15:04:05", dateb+" 00:00:00", loc)
  1373. dateB := inLocation.Unix()
  1374. //fmt.Println("取样日期", dateB)
  1375. samplerc := int64(dataBody["samplerc"].(float64))
  1376. //fmt.Println("取样者", samplerc)
  1377. concentratenof := dataBody["concentrate_nof"].(string)
  1378. //fmt.Println("浓A", concentratenof)
  1379. concentrateonog := dataBody["concentrate_nog"].(string)
  1380. //fmt.Println("浓B", concentrateonog)
  1381. dateReportc := dataBody["date_reportc"].(string)
  1382. parseInLocation, _ := time.ParseInLocation(timeLayout+" 15:04:05", dateReportc+" 00:00:00", loc)
  1383. datec := parseInLocation.Unix()
  1384. //fmt.Println("报告日期", datec)
  1385. actualNa := dataBody["actual_na"].(string)
  1386. //fmt.Println("钠", actualNa)
  1387. actualPna := dataBody["actual_pna"].(string)
  1388. //fmt.Println("配钠", actualPna)
  1389. actualK := dataBody["actual_k"].(string)
  1390. //fmt.Println("钾", actualK)
  1391. actualCa := dataBody["actual_ca"].(string)
  1392. //fmt.Println("钙", actualCa)
  1393. actualCi := dataBody["actual_ci"].(string)
  1394. //fmt.Println("氯", actualCi)
  1395. actualHco := dataBody["actual_hco"].(string)
  1396. //fmt.Println("HCO", actualHco)
  1397. actualMg := dataBody["actual_mg"].(string)
  1398. //fmt.Println("actualMg", actualMg)
  1399. actulaPH := dataBody["actual_ph"].(string)
  1400. //fmt.Println("PH", actulaPH)
  1401. remakes := dataBody["remakes"].(string)
  1402. //fmt.Println("备注", remakes)
  1403. detectionUnit := dataBody["detection_unit"].(string)
  1404. //fmt.Println("检测单位", detectionUnit)
  1405. ion := models.DeviceIon{
  1406. SamplingDate: dateB,
  1407. Samplerc: samplerc,
  1408. DetectionUnit: detectionUnit,
  1409. ConcentrateNof: concentratenof,
  1410. ConcentrateNog: concentrateonog,
  1411. DateReportc: datec,
  1412. ActualNa: actualNa,
  1413. ActualPna: actualPna,
  1414. ActualK: actualK,
  1415. ActualCa: actualCa,
  1416. ActualCi: actualCi,
  1417. ActualHco: actualHco,
  1418. ActualMg: actualMg,
  1419. ActualPh: actulaPH,
  1420. Remakes: remakes,
  1421. EquitmentId: id,
  1422. Status: 1,
  1423. UserOrgId: orgid,
  1424. Ctime: time.Now().Unix(),
  1425. BedId: addmacher.BedId,
  1426. Bed: addmacher.BedNumber,
  1427. }
  1428. createIon := service.CreateIon(&ion)
  1429. fmt.Println("报错", createIon)
  1430. if err != nil {
  1431. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "添加失败:("+err.Error()+")")
  1432. return
  1433. }
  1434. this.ServeSuccessJSON(map[string]interface{}{
  1435. "ion": ion,
  1436. })
  1437. }
  1438. func (this *MachineApiController) GetAllQulityInfo() {
  1439. adminUser := this.GetAdminUserInfo()
  1440. orgID := adminUser.CurrentOrgId
  1441. //fmt.Println("机构id", orgID)
  1442. cultures, err := service.GetAllCulture(orgID)
  1443. dialysate, _ := service.GetAllDialysate(orgID)
  1444. ions, _ := service.GetAllDeviceIon(orgID)
  1445. if err != nil {
  1446. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "添加失败:("+err.Error()+")")
  1447. return
  1448. }
  1449. this.ServeSuccessJSON(map[string]interface{}{
  1450. "cultures": cultures,
  1451. "dialysate": dialysate,
  1452. "ions": ions,
  1453. })
  1454. }
  1455. func (this *MachineApiController) EditCulture() {
  1456. id, _ := this.GetInt64("id")
  1457. //fmt.Println("id", id)
  1458. userid, _ := this.GetInt64("userid")
  1459. //fmt.Println("userid", userid)
  1460. role, _ := service.GetSampler(userid)
  1461. culture, err := service.GetCultureById(id)
  1462. if err != nil {
  1463. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  1464. return
  1465. }
  1466. this.ServeSuccessJSON(map[string]interface{}{
  1467. "culture": culture,
  1468. "role": role,
  1469. })
  1470. }
  1471. func (this *MachineApiController) UpdateCulture() {
  1472. dataBody := make(map[string]interface{}, 0)
  1473. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1474. //fmt.Println("err", err)
  1475. id := int64(dataBody["id"].(float64))
  1476. //fmt.Println("id", id)
  1477. date := dataBody["date"].(string)
  1478. //fmt.Println("取样日期", date)
  1479. timeLayout := "2006-01-02"
  1480. loc, _ := time.LoadLocation("Local")
  1481. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", date+" 00:00:00", loc)
  1482. state_date := theTime.Unix()
  1483. //fmt.Println("取样日期", state_date)
  1484. specimen := int64(dataBody["specimen"].(float64))
  1485. //fmt.Println("取样标本", specimen)
  1486. cona := dataBody["concentrate_noa"].(string)
  1487. //fmt.Println("A浓缩液批号", cona)
  1488. conb := dataBody["concentrate_nob"].(string)
  1489. //fmt.Println("B浓批号", conb)
  1490. samplingLoactiona := int64(dataBody["sampling_locationa"].(float64))
  1491. //fmt.Println("采样部位", samplingLoactiona)
  1492. detectionUnit := dataBody["detection_unit"].(string)
  1493. //fmt.Println("检测单位", detectionUnit)
  1494. sampler := int64(dataBody["sampler"].(float64))
  1495. //fmt.Println("取样者", sampler)
  1496. reportDate := dataBody["reporting_date"].(string)
  1497. reportTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", reportDate+" 00:00:00", loc)
  1498. repDate := reportTime.Unix()
  1499. //fmt.Println("出报告日期", repDate)
  1500. detectionResult := dataBody["detection_result"].(string)
  1501. //fmt.Println("检测结果", detectionResult)
  1502. adminUser := this.GetAdminUserInfo()
  1503. orgId := adminUser.CurrentOrgId
  1504. culture := models.DeviceCulture{
  1505. SpelingDate: state_date,
  1506. Specimen: specimen,
  1507. ConcentrateNoa: cona,
  1508. ConcentrateNob: conb,
  1509. SamplingLocationa: samplingLoactiona,
  1510. DetectionUnit: detectionUnit,
  1511. Sampler: sampler,
  1512. ReportingDate: repDate,
  1513. DetectionResult: detectionResult,
  1514. }
  1515. err = service.UpdateCulture(id, orgId, &culture)
  1516. if err != nil {
  1517. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  1518. return
  1519. }
  1520. this.ServeSuccessJSON(map[string]interface{}{
  1521. "culture": culture,
  1522. })
  1523. }
  1524. func (this *MachineApiController) DeleteCultrue() {
  1525. adminUserInfo := this.GetAdminUserInfo()
  1526. OrgID := adminUserInfo.CurrentOrgId
  1527. dataBody := make(map[string]interface{}, 0)
  1528. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1529. if err != nil {
  1530. utils.ErrorLog(err.Error())
  1531. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  1532. return
  1533. }
  1534. idsInters := dataBody["ids"].([]interface{})
  1535. if len(idsInters) == 0 {
  1536. if err != nil {
  1537. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  1538. return
  1539. }
  1540. }
  1541. ids := make([]int64, 0)
  1542. for _, idsInter := range idsInters {
  1543. id := int64(idsInter.(float64))
  1544. ids = append(ids, id)
  1545. }
  1546. fmt.Println("ids", ids)
  1547. err = service.DeleteCultrue(OrgID, ids)
  1548. fmt.Println("err", err)
  1549. if err != nil {
  1550. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败:("+err.Error()+")")
  1551. return
  1552. }
  1553. returnData := make(map[string]interface{}, 0)
  1554. returnData["msg"] = "ok"
  1555. this.ServeSuccessJSON(returnData)
  1556. return
  1557. }
  1558. func (this *MachineApiController) EditDialystate() {
  1559. id, _ := this.GetInt64("id")
  1560. fmt.Println("id是什么", id)
  1561. dialysate, err := service.GetDialystate(id)
  1562. if err != nil {
  1563. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  1564. return
  1565. }
  1566. this.ServeSuccessJSON(map[string]interface{}{
  1567. "dialysate": dialysate,
  1568. })
  1569. }
  1570. func (this *MachineApiController) Updatedialystate() {
  1571. timeLayout := "2006-01-02"
  1572. loc, _ := time.LoadLocation("Local")
  1573. dataBody := make(map[string]interface{}, 0)
  1574. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1575. fmt.Println("err", err)
  1576. id := int64(dataBody["id"].(float64))
  1577. fmt.Println("id", id)
  1578. samplingDate := dataBody["sampling_date"].(string)
  1579. sampdate, _ := time.ParseInLocation(timeLayout+" 15:04:05", samplingDate+" 00:00:00", loc)
  1580. samp_date := sampdate.Unix()
  1581. fmt.Println("取样日期", samp_date)
  1582. specimentb := int64(dataBody["specimenb"].(float64))
  1583. fmt.Println("取样标本", specimentb)
  1584. concentratec := dataBody["concentrate_noc"].(string)
  1585. fmt.Println("A浓缩液批号", concentratec)
  1586. concentraeb := dataBody["concentrateb_nod"].(string)
  1587. fmt.Println("B浓缩", concentraeb)
  1588. samplinglocationb := int64(dataBody["sampling_locationb"].(float64))
  1589. fmt.Println("采样部位", samplinglocationb)
  1590. samplerb := int64(dataBody["samplerb"].(float64))
  1591. fmt.Println("取样者", samplerb)
  1592. reportDateb := dataBody["reporting_dateb"].(string)
  1593. //fmt.Println("日期", reportDateb)
  1594. location, _ := time.ParseInLocation(timeLayout+" 15:04:05", reportDateb+" 00:00:00", loc)
  1595. report_date := location.Unix()
  1596. fmt.Println("出报告2日期", report_date)
  1597. detectionResultb := dataBody["detection_resultb"].(string)
  1598. fmt.Println("检测结果", detectionResultb)
  1599. detectionUnit := dataBody["detection_unit"].(string)
  1600. fmt.Println("检测单位", detectionUnit)
  1601. adminUser := this.GetAdminUserInfo()
  1602. orgid := adminUser.CurrentOrgId
  1603. dialysate := models.DeviceDialysate{
  1604. SamplingDate: samp_date,
  1605. Specimenb: specimentb,
  1606. ConcentrateNoc: concentratec,
  1607. ConcentratebNod: concentraeb,
  1608. SamplingLocationb: samplinglocationb,
  1609. DetectionUnit: detectionUnit,
  1610. Samplerb: samplerb,
  1611. ReportingDateb: report_date,
  1612. DetectionResultb: detectionResultb,
  1613. }
  1614. err = service.Updatedialystate(id, orgid, &dialysate)
  1615. if err != nil {
  1616. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  1617. return
  1618. }
  1619. this.ServeSuccessJSON(map[string]interface{}{
  1620. "dialysate": dialysate,
  1621. })
  1622. }
  1623. func (this *MachineApiController) DeleteDialystate() {
  1624. adminUserInfo := this.GetAdminUserInfo()
  1625. OrgID := adminUserInfo.CurrentOrgId
  1626. dataBody := make(map[string]interface{}, 0)
  1627. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1628. if err != nil {
  1629. utils.ErrorLog(err.Error())
  1630. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  1631. return
  1632. }
  1633. idsInters := dataBody["ids"].([]interface{})
  1634. if len(idsInters) == 0 {
  1635. if err != nil {
  1636. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  1637. return
  1638. }
  1639. }
  1640. ids := make([]int64, 0)
  1641. for _, idsInter := range idsInters {
  1642. id := int64(idsInter.(float64))
  1643. ids = append(ids, id)
  1644. }
  1645. fmt.Println("ids", ids)
  1646. err = service.DeleteDialystate(OrgID, ids)
  1647. fmt.Println("err", err)
  1648. if err != nil {
  1649. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败:("+err.Error()+")")
  1650. return
  1651. }
  1652. returnData := make(map[string]interface{}, 0)
  1653. returnData["msg"] = "ok"
  1654. this.ServeSuccessJSON(returnData)
  1655. return
  1656. }
  1657. func (this *MachineApiController) Edition() {
  1658. id, _ := this.GetInt64("id")
  1659. fmt.Println("id", id)
  1660. ion, err := service.GetIon(id)
  1661. if err != nil {
  1662. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  1663. return
  1664. }
  1665. this.ServeSuccessJSON(map[string]interface{}{
  1666. "ion": ion,
  1667. })
  1668. }
  1669. func (this *MachineApiController) UpdateIon() {
  1670. timeLayout := "2006-01-02"
  1671. loc, _ := time.LoadLocation("Local")
  1672. dataBody := make(map[string]interface{}, 0)
  1673. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1674. fmt.Println("err", err)
  1675. id := int64(dataBody["id"].(float64))
  1676. fmt.Println("id", id)
  1677. dateb := dataBody["dateb"].(string)
  1678. inLocation, _ := time.ParseInLocation(timeLayout+" 15:04:05", dateb+" 00:00:00", loc)
  1679. dateB := inLocation.Unix()
  1680. fmt.Println("取样日期", dateB)
  1681. samplerc := int64(dataBody["samplerc"].(float64))
  1682. fmt.Println("取样者", samplerc)
  1683. concentratenof := dataBody["concentrate_nof"].(string)
  1684. fmt.Println("浓A", concentratenof)
  1685. concentrateonog := dataBody["concentrate_nog"].(string)
  1686. fmt.Println("浓B", concentrateonog)
  1687. dateReportc := dataBody["date_reportc"].(string)
  1688. parseInLocation, _ := time.ParseInLocation(timeLayout+" 15:04:05", dateReportc+" 00:00:00", loc)
  1689. datec := parseInLocation.Unix()
  1690. fmt.Println("报告日期", datec)
  1691. actualNa := dataBody["actual_na"].(string)
  1692. fmt.Println("钠", actualNa)
  1693. actualPna := dataBody["actual_pna"].(string)
  1694. fmt.Println("配钠", actualPna)
  1695. actualK := dataBody["actual_k"].(string)
  1696. fmt.Println("钾", actualK)
  1697. actualCa := dataBody["actual_ca"].(string)
  1698. fmt.Println("钙", actualCa)
  1699. actualCi := dataBody["actual_ci"].(string)
  1700. fmt.Println("氯", actualCi)
  1701. actualHco := dataBody["actual_hco"].(string)
  1702. fmt.Println("HCO", actualHco)
  1703. actualMg := dataBody["actual_mg"].(string)
  1704. fmt.Println("actualMg", actualMg)
  1705. actulaPH := dataBody["actual_ph"].(string)
  1706. fmt.Println("PH", actulaPH)
  1707. remakes := dataBody["remakes"].(string)
  1708. fmt.Println("备注", remakes)
  1709. detectionUnit := dataBody["detection_unit"].(string)
  1710. fmt.Println("检测单位", detectionUnit)
  1711. ion := models.DeviceIon{
  1712. SamplingDate: dateB,
  1713. Samplerc: samplerc,
  1714. DetectionUnit: detectionUnit,
  1715. ConcentrateNof: concentratenof,
  1716. ConcentrateNog: concentrateonog,
  1717. DateReportc: datec,
  1718. ActualNa: actualNa,
  1719. ActualPna: actualPna,
  1720. ActualK: actualK,
  1721. ActualCa: actualCa,
  1722. ActualCi: actualCi,
  1723. ActualHco: actualHco,
  1724. ActualMg: actualMg,
  1725. ActualPh: actulaPH,
  1726. Remakes: remakes,
  1727. }
  1728. adminUser := this.GetAdminUserInfo()
  1729. orgId := adminUser.CurrentOrgId
  1730. err = service.UpdateIon(id, orgId, &ion)
  1731. if err != nil {
  1732. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  1733. return
  1734. }
  1735. this.ServeSuccessJSON(map[string]interface{}{
  1736. "ion": ion,
  1737. })
  1738. }
  1739. func (this *MachineApiController) DeleteIon() {
  1740. adminUserInfo := this.GetAdminUserInfo()
  1741. OrgID := adminUserInfo.CurrentOrgId
  1742. dataBody := make(map[string]interface{}, 0)
  1743. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1744. if err != nil {
  1745. utils.ErrorLog(err.Error())
  1746. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  1747. return
  1748. }
  1749. idsInters := dataBody["ids"].([]interface{})
  1750. if len(idsInters) == 0 {
  1751. if err != nil {
  1752. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  1753. return
  1754. }
  1755. }
  1756. ids := make([]int64, 0)
  1757. for _, idsInter := range idsInters {
  1758. id := int64(idsInter.(float64))
  1759. ids = append(ids, id)
  1760. }
  1761. fmt.Println("ids", ids)
  1762. err = service.DeleteIon(OrgID, ids)
  1763. if err != nil {
  1764. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败:("+err.Error()+")")
  1765. return
  1766. }
  1767. returnData := make(map[string]interface{}, 0)
  1768. returnData["msg"] = "ok"
  1769. this.ServeSuccessJSON(returnData)
  1770. return
  1771. }
  1772. func (this *MachineApiController) GetQuery() {
  1773. timeLayout := "2006-01-02"
  1774. loc, _ := time.LoadLocation("Local")
  1775. adminUserInfo := this.GetAdminUserInfo()
  1776. OrgID := adminUserInfo.CurrentOrgId
  1777. fmt.Println("orgid", OrgID)
  1778. bedid, _ := this.GetInt64("bedid")
  1779. fmt.Println("bedid", bedid)
  1780. startime := this.GetString("startime")
  1781. fmt.Println("starttime", startime)
  1782. inLocation, _ := time.ParseInLocation(timeLayout+" 15:04:05", startime+" 00:00:00", loc)
  1783. start := inLocation.Unix()
  1784. fmt.Println("start", start)
  1785. endtime := this.GetString("endtime")
  1786. fmt.Println("endtime", endtime)
  1787. endLocation, _ := time.ParseInLocation(timeLayout+" 15:04:05", endtime+" 00:00:00", loc)
  1788. end := endLocation.Unix()
  1789. fmt.Println("end", end)
  1790. cultures, err := service.GetCultureData(bedid, start, end, OrgID)
  1791. fmt.Print(err)
  1792. dialysate, err := service.GetDialysateData(bedid, start, end, OrgID)
  1793. ions, err := service.GetDeviceIonData(bedid, start, end, OrgID)
  1794. if err != nil {
  1795. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  1796. return
  1797. }
  1798. this.ServeSuccessJSON(map[string]interface{}{
  1799. "cultures": cultures,
  1800. "dialysate": dialysate,
  1801. "ions": ions,
  1802. })
  1803. }
  1804. func (this *MachineApiController) SaveRepair() {
  1805. timeLayout := "2006-01-02"
  1806. loc, _ := time.LoadLocation("Local")
  1807. adminUserInfo := this.GetAdminUserInfo()
  1808. id, _ := this.GetInt64("id")
  1809. fmt.Println("id", id)
  1810. addmacher, _ := service.GetBedId(id)
  1811. OrgID := adminUserInfo.CurrentOrgId
  1812. fmt.Println("orgid", OrgID)
  1813. dataBody := make(map[string]interface{}, 0)
  1814. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1815. fmt.Println("err", err)
  1816. gua_date := dataBody["guarantee_date"].(string)
  1817. fmt.Println("保修日期", gua_date)
  1818. inLocation, _ := time.ParseInLocation(timeLayout+" 15:04:05", gua_date+" 00:00:00", loc)
  1819. guaDate := inLocation.Unix()
  1820. fmt.Println("保修日期", guaDate)
  1821. startDateStr := dataBody["start_time"].(string)
  1822. fmt.Println("出发时间", startDateStr)
  1823. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startDateStr)
  1824. fmt.Println("触发事件", startDate.Unix())
  1825. arriveDateStr := dataBody["arrive_time"].(string)
  1826. fmt.Println("到达时间", arriveDateStr)
  1827. arriveDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", arriveDateStr)
  1828. fmt.Println("到达时间", arriveDate.Unix())
  1829. finishDateStr := dataBody["finish_time"].(string)
  1830. fmt.Println("完成时间", finishDateStr)
  1831. finishDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", finishDateStr)
  1832. fmt.Println("完成时间", finishDate.Unix())
  1833. totaldistance := dataBody["total_distance"].(string)
  1834. fmt.Println("总公里输", totaldistance)
  1835. failurestate := int64(dataBody["failure_stage"].(float64))
  1836. fmt.Println("故事范式阶段", failurestate)
  1837. codeInformation := dataBody["code_information"].(string)
  1838. fmt.Println("故事提示信息及代码", codeInformation)
  1839. faultdescription := dataBody["fault_description"].(string)
  1840. fmt.Println("故障描述", faultdescription)
  1841. causeAnalysis := dataBody["cause_analysis"].(string)
  1842. fmt.Println("原因分析", causeAnalysis)
  1843. treatmentprocess := dataBody["treatment_process"].(string)
  1844. fmt.Println("处理过程", treatmentprocess)
  1845. images := dataBody["images"].(string)
  1846. fmt.Println("上传图片", images)
  1847. exclude := int64(dataBody["exclude"].(float64))
  1848. fmt.Println("故障是否排除", exclude)
  1849. reason := dataBody["reason"].(string)
  1850. fmt.Println("原因", reason)
  1851. imageName := dataBody["imageName"].(string)
  1852. repair := models.DeviceRepair{
  1853. BedId: addmacher.BedId,
  1854. EquitmentId: id,
  1855. GuaranteeDate: guaDate,
  1856. StartTime: startDate.Unix(),
  1857. ArriveTime: arriveDate.Unix(),
  1858. FinishTime: finishDate.Unix(),
  1859. TotalDistance: totaldistance,
  1860. FailureStage: failurestate,
  1861. FaultDescription: faultdescription,
  1862. CauseAnalysis: causeAnalysis,
  1863. TreatmentProcess: treatmentprocess,
  1864. Images: images,
  1865. Exclude: exclude,
  1866. Reason: reason,
  1867. Status: 1,
  1868. UserOrgId: OrgID,
  1869. Ctime: time.Now().Unix(),
  1870. CodeInformation: codeInformation,
  1871. ImageName: imageName,
  1872. }
  1873. err = service.CreateRepair(&repair)
  1874. if err != nil {
  1875. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  1876. return
  1877. }
  1878. this.ServeSuccessJSON(map[string]interface{}{
  1879. "repair": repair,
  1880. })
  1881. }
  1882. func (this *MachineApiController) GetAllRepair() {
  1883. limit, _ := this.GetInt64("limit")
  1884. page, _ := this.GetInt64("page")
  1885. adminUser := this.GetAdminUserInfo()
  1886. orgID := adminUser.CurrentOrgId
  1887. repair, total, err := service.GetAllRepair(orgID, limit, page)
  1888. if err != nil {
  1889. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  1890. return
  1891. }
  1892. this.ServeSuccessJSON(map[string]interface{}{
  1893. "repair": repair,
  1894. "total": total,
  1895. })
  1896. }
  1897. func (this *MachineApiController) EditRepair() {
  1898. id, _ := this.GetInt64("id")
  1899. fmt.Println("id", id)
  1900. repair, err := service.EditRepair(id)
  1901. if err != nil {
  1902. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  1903. return
  1904. }
  1905. this.ServeSuccessJSON(map[string]interface{}{
  1906. "repair": repair,
  1907. })
  1908. }
  1909. func (this *MachineApiController) UpdateRepair() {
  1910. timeLayout := "2006-01-02"
  1911. loc, _ := time.LoadLocation("Local")
  1912. adminUserInfo := this.GetAdminUserInfo()
  1913. OrgID := adminUserInfo.CurrentOrgId
  1914. fmt.Println("orgid", OrgID)
  1915. dataBody := make(map[string]interface{}, 0)
  1916. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1917. fmt.Println("err", err)
  1918. id := int64(dataBody["id"].(float64))
  1919. gua_date := dataBody["guarantee_date"].(string)
  1920. fmt.Println("保修日期", gua_date)
  1921. inLocation, _ := time.ParseInLocation(timeLayout+" 15:04:05", gua_date+" 00:00:00", loc)
  1922. guaDate := inLocation.Unix()
  1923. fmt.Println("保修日期", guaDate)
  1924. startDateStr := dataBody["start_time"].(string)
  1925. fmt.Println("出发时间", startDateStr)
  1926. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startDateStr)
  1927. fmt.Println("触发事件", startDate.Unix())
  1928. arriveDateStr := dataBody["arrive_time"].(string)
  1929. fmt.Println("到达时间", arriveDateStr)
  1930. arriveDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", arriveDateStr)
  1931. fmt.Println("到达时间", arriveDate.Unix())
  1932. finishDateStr := dataBody["finish_time"].(string)
  1933. fmt.Println("完成时间", finishDateStr)
  1934. finishDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", finishDateStr)
  1935. fmt.Println("完成时间", finishDate.Unix())
  1936. totaldistance := dataBody["total_distance"].(string)
  1937. fmt.Println("总公里输", totaldistance)
  1938. failurestate := int64(dataBody["failure_stage"].(float64))
  1939. fmt.Println("故事范式阶段", failurestate)
  1940. codeInformation := dataBody["code_information"].(string)
  1941. fmt.Println("故事提示信息及代码", codeInformation)
  1942. faultdescription := dataBody["fault_description"].(string)
  1943. fmt.Println("故障描述", faultdescription)
  1944. causeAnalysis := dataBody["cause_analysis"].(string)
  1945. fmt.Println("原因分析", causeAnalysis)
  1946. treatmentprocess := dataBody["treatment_process"].(string)
  1947. fmt.Println("处理过程", treatmentprocess)
  1948. images := dataBody["images"].(string)
  1949. fmt.Println("上传图片", images)
  1950. exclude := int64(dataBody["exclude"].(float64))
  1951. fmt.Println("故障是否排除", exclude)
  1952. reason := dataBody["reason"].(string)
  1953. fmt.Println("原因", reason)
  1954. imageName := dataBody["image_name"].(string)
  1955. deviceRepair := models.DeviceRepair{
  1956. GuaranteeDate: guaDate,
  1957. StartTime: startDate.Unix(),
  1958. ArriveTime: arriveDate.Unix(),
  1959. FinishTime: finishDate.Unix(),
  1960. TotalDistance: totaldistance,
  1961. FailureStage: failurestate,
  1962. FaultDescription: faultdescription,
  1963. CauseAnalysis: causeAnalysis,
  1964. TreatmentProcess: treatmentprocess,
  1965. Images: images,
  1966. Exclude: exclude,
  1967. Reason: reason,
  1968. CodeInformation: codeInformation,
  1969. ImageName: imageName,
  1970. }
  1971. err = service.UpdateRepair(id, OrgID, &deviceRepair)
  1972. if err != nil {
  1973. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  1974. return
  1975. }
  1976. this.ServeSuccessJSON(map[string]interface{}{
  1977. "repair": deviceRepair,
  1978. })
  1979. }
  1980. func (this *MachineApiController) DeleteRepair() {
  1981. adminUserInfo := this.GetAdminUserInfo()
  1982. OrgID := adminUserInfo.CurrentOrgId
  1983. dataBody := make(map[string]interface{}, 0)
  1984. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1985. if err != nil {
  1986. utils.ErrorLog(err.Error())
  1987. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  1988. return
  1989. }
  1990. idsInters := dataBody["ids"].([]interface{})
  1991. if len(idsInters) == 0 {
  1992. if err != nil {
  1993. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  1994. return
  1995. }
  1996. }
  1997. ids := make([]int64, 0)
  1998. for _, idsInter := range idsInters {
  1999. id := int64(idsInter.(float64))
  2000. ids = append(ids, id)
  2001. }
  2002. fmt.Println("ids", ids)
  2003. err = service.DeleteRepair(OrgID, ids)
  2004. if err != nil {
  2005. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败:("+err.Error()+")")
  2006. return
  2007. }
  2008. returnData := make(map[string]interface{}, 0)
  2009. returnData["msg"] = "ok"
  2010. this.ServeSuccessJSON(returnData)
  2011. return
  2012. }
  2013. func (this *MachineApiController) GetRepair() {
  2014. timeLayout := "2006-01-02"
  2015. loc, _ := time.LoadLocation("Local")
  2016. adminUserInfo := this.GetAdminUserInfo()
  2017. OrgID := adminUserInfo.CurrentOrgId
  2018. fmt.Println("orgid", OrgID)
  2019. bedid, _ := this.GetInt64("bedid")
  2020. fmt.Println("bedid", bedid)
  2021. startime := this.GetString("startime")
  2022. fmt.Println("starttime", startime)
  2023. inLocation, _ := time.ParseInLocation(timeLayout+" 15:04:05", startime+" 00:00:00", loc)
  2024. start := inLocation.Unix()
  2025. fmt.Println("start", start)
  2026. endtime := this.GetString("endtime")
  2027. fmt.Println("endtime", endtime)
  2028. endLocation, _ := time.ParseInLocation(timeLayout+" 15:04:05", endtime+" 00:00:00", loc)
  2029. end := endLocation.Unix()
  2030. fmt.Println("end", end)
  2031. repair, err := service.GetRepair(bedid, start, end, OrgID)
  2032. if err != nil {
  2033. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  2034. return
  2035. }
  2036. this.ServeSuccessJSON(map[string]interface{}{
  2037. "repair": repair,
  2038. })
  2039. }
  2040. func (this *MachineApiController) EditUser() {
  2041. adminUser := this.GetAdminUserInfo()
  2042. orgId := adminUser.CurrentOrgId
  2043. id, _ := this.GetInt64("id")
  2044. fmt.Println("id", id)
  2045. patientid, _ := this.GetInt64("patientid")
  2046. device, err := service.GetUserInformation(id)
  2047. //获取初次使用记录
  2048. macher, err := service.GetUserTotalByMacher(device.EquimentId)
  2049. count, err := service.GetUserTotalCount(orgId, device.BedNumber)
  2050. patients, err := service.GetPatientInfoMation(patientid)
  2051. if err != nil {
  2052. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
  2053. return
  2054. }
  2055. this.ServeSuccessJSON(map[string]interface{}{
  2056. "device": device,
  2057. "patients": patients,
  2058. "count": count,
  2059. "macher": macher,
  2060. })
  2061. }
  2062. func (this *MachineApiController) DeleteForm() {
  2063. adminUserInfo := this.GetAdminUserInfo()
  2064. OrgID := adminUserInfo.CurrentOrgId
  2065. dataBody := make(map[string]interface{}, 0)
  2066. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2067. if err != nil {
  2068. utils.ErrorLog(err.Error())
  2069. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  2070. return
  2071. }
  2072. idsInters := dataBody["ids"].([]interface{})
  2073. if len(idsInters) == 0 {
  2074. if err != nil {
  2075. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  2076. return
  2077. }
  2078. }
  2079. ids := make([]int64, 0)
  2080. for _, idsInter := range idsInters {
  2081. id := int64(idsInter.(float64))
  2082. ids = append(ids, id)
  2083. }
  2084. fmt.Println("ids", ids)
  2085. err = service.DeleteForm(OrgID, ids)
  2086. if err != nil {
  2087. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败:("+err.Error()+")")
  2088. return
  2089. }
  2090. returnData := make(map[string]interface{}, 0)
  2091. returnData["msg"] = "ok"
  2092. this.ServeSuccessJSON(returnData)
  2093. return
  2094. }
  2095. func (this *MachineApiController) UpdateForm() {
  2096. dataBody := make(map[string]interface{}, 0)
  2097. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2098. fmt.Println("错误是", err)
  2099. adminUserInfo := this.GetAdminUserInfo()
  2100. orgid := adminUserInfo.CurrentOrgId
  2101. date := dataBody["spling_date"].(string)
  2102. timeLayout := "2006-01-02"
  2103. loc, _ := time.LoadLocation("Local")
  2104. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", date+" 00:00:00", loc)
  2105. startdate := theTime.Unix()
  2106. fmt.Println("日期", startdate)
  2107. id := int64(dataBody["id"].(float64))
  2108. fmt.Println("id", id)
  2109. classtype := int64(dataBody["classtype"].(float64))
  2110. fmt.Println("班次", classtype)
  2111. zone := int64(dataBody["zone"].(float64))
  2112. fmt.Println("分区", zone)
  2113. bednumber := int64(dataBody["bed_number"].(float64))
  2114. fmt.Println("床位号", bednumber)
  2115. number, _ := service.GetNumbers(bednumber, orgid)
  2116. patient_id := int64(dataBody["patient_id"].(float64))
  2117. fmt.Println("患者", patient_id)
  2118. contagion := dataBody["contagion"].(string)
  2119. fmt.Println("传染病", contagion)
  2120. dialysis_mode := int64(dataBody["dialysis_mode"].(float64))
  2121. fmt.Println("透析方式", dialysis_mode)
  2122. startDateStr := dataBody["start_time"].(string)
  2123. fmt.Println("上机时间", startDateStr)
  2124. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startDateStr)
  2125. fmt.Println("上机时间", startDate.Unix())
  2126. endDateStr := dataBody["end_time"].(string)
  2127. fmt.Println("上机时间", startDateStr)
  2128. endDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", endDateStr)
  2129. fmt.Println("上机时间", endDate.Unix())
  2130. dialysis_time := dataBody["dialysis_time"].(string)
  2131. fmt.Println("透析时长", dialysis_time)
  2132. hyperfiletration := dataBody["hyperfiltratio"].(float64)
  2133. fmt.Println("实际超滤量", hyperfiletration)
  2134. weight_loss := dataBody["weight_loss"].(float64)
  2135. fmt.Println("体重减少", weight_loss)
  2136. warining_value := dataBody["warning_value"].(string)
  2137. fmt.Println("预警值", warining_value)
  2138. //user_total := int64(dataBody["user_total"].(float64))
  2139. user_total := dataBody["user_total"].(string)
  2140. fmt.Println("使用次数", user_total)
  2141. run := int64(dataBody["run"].(float64))
  2142. fmt.Println("运行", run)
  2143. failure_stage := int64(dataBody["failure_stage"].(float64))
  2144. fmt.Println("故事发生阶段", failure_stage)
  2145. falult_desciription := dataBody["fault_description"].(string)
  2146. fmt.Println("故障描述", falult_desciription)
  2147. code_information := dataBody["code_information"].(string)
  2148. fmt.Println("故障提示及代码", code_information)
  2149. //机器消毒
  2150. disinfect_type := int64(dataBody["disinfect_type"].(float64))
  2151. fmt.Println("消毒方式", disinfect_type)
  2152. disinfectant_type := int64(dataBody["disinfectant_type"].(float64))
  2153. fmt.Println("消毒液", disinfectant_type)
  2154. disinfection := int64(dataBody["disinfection"].(float64))
  2155. fmt.Println("消毒状态", disinfection)
  2156. machine_run := int64(dataBody["machine_run"].(float64))
  2157. fmt.Println("运行", machine_run)
  2158. //液路
  2159. fluid_path := int64(dataBody["fluid_path"].(float64))
  2160. fmt.Println("液路消毒方式", fluid_path)
  2161. disinfectant := int64(dataBody["disinfectant"].(float64))
  2162. fmt.Println("消毒液", disinfectant)
  2163. disinfection_status := int64(dataBody["disinfection_status"].(float64))
  2164. fmt.Println("消毒状态", disinfection_status)
  2165. disinfection_residue := int64(dataBody["disinfection_residue"].(float64))
  2166. fmt.Println("消毒液残留", disinfection_residue)
  2167. longtime := dataBody["longtime"].(string)
  2168. fmt.Println("消毒时长", longtime)
  2169. starttime := dataBody["starttime"].(string)
  2170. disstarttime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", starttime)
  2171. distartime := disstarttime.Unix()
  2172. if distartime < 0 {
  2173. distartime = 0
  2174. }
  2175. //fmt.Println("开始消毒时间====", distartime)
  2176. entime := dataBody["endtime"].(string)
  2177. disendtime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", entime)
  2178. diendtime := disendtime.Unix()
  2179. fmt.Println("结束消毒时间", diendtime)
  2180. if diendtime < 0 {
  2181. diendtime = 0
  2182. }
  2183. dialysis_checked := int64(dataBody["dialysis_checked"].(float64))
  2184. //fmt.Println("更换", dialysis_checked)
  2185. dialysis_name := int64(dataBody["dialysis_name"].(float64))
  2186. fmt.Println("名称", dialysis_name)
  2187. norms := dataBody["norms"].(string)
  2188. fmt.Println("规格", norms)
  2189. dialysis_concentration := int64(dataBody["dialysis_concentration"].(float64))
  2190. fmt.Println("浓度", dialysis_concentration)
  2191. germ_checked := int64(dataBody["germ_checked"].(float64))
  2192. fmt.Println("更换", germ_checked)
  2193. germ_name := int64(dataBody["germ_name"].(float64))
  2194. fmt.Println("名称", germ_name)
  2195. //germ_number := int64(dataBody["germ_number"].(float64))
  2196. germ_number := dataBody["germ_number"].(string)
  2197. fmt.Println("数量", germ_number)
  2198. clean := int64(dataBody["clean"].(float64))
  2199. fmt.Println("清洁", clean)
  2200. sign_name := int64(dataBody["sign_name"].(float64))
  2201. fmt.Println("签名", sign_name)
  2202. equitment_id := int64(dataBody["equiment_id"].(float64))
  2203. fmt.Println("设备ID", equitment_id)
  2204. addmacher := models.DeviceAddmacher{
  2205. BedId: bednumber,
  2206. }
  2207. //更新床位号
  2208. err = service.UpdateAddMacherBedID(equitment_id, orgid, &addmacher)
  2209. fmt.Println("更新设备失败", err)
  2210. //更新区号
  2211. deviceNumber := models.DeviceNumber{
  2212. ZoneID: zone,
  2213. }
  2214. err = service.UpdatedZoneID(bednumber, orgid, &deviceNumber)
  2215. fmt.Println("更新区号失败", err)
  2216. information := models.DeviceInformation{
  2217. Date: startdate,
  2218. Class: classtype,
  2219. Zone: zone,
  2220. BedNumber: bednumber,
  2221. Contagion: contagion,
  2222. DialysisMode: dialysis_mode,
  2223. StartTime: startDate.Unix(),
  2224. EndTime: endDate.Unix(),
  2225. DialysisHour: dialysis_time,
  2226. Hyperfiltratio: hyperfiletration,
  2227. WeightLoss: weight_loss,
  2228. WarningValue: warining_value,
  2229. UserTotal: user_total,
  2230. Move: run,
  2231. FailureStage: failure_stage,
  2232. FaultDescription: falult_desciription,
  2233. CodeInformation: code_information,
  2234. DisinfectantType: disinfectant_type,
  2235. DisinfectType: disinfect_type,
  2236. Disinfection: disinfection,
  2237. MachineRun: machine_run,
  2238. FluidPath: fluid_path,
  2239. Disinfectant: disinfectant,
  2240. DisinfectionStatus: disinfection_status,
  2241. DisinfectionResidue: disinfection_residue,
  2242. LongTime: longtime,
  2243. DisinfecStartime: distartime,
  2244. DisinfecEndtime: diendtime,
  2245. DialysisChecked: dialysis_checked,
  2246. DialysisName: dialysis_name,
  2247. Norms: norms,
  2248. DialysisConcentration: dialysis_concentration,
  2249. GermChecked: germ_checked,
  2250. GermName: germ_name,
  2251. GermNumber: germ_number,
  2252. Clean: clean,
  2253. SignName: sign_name,
  2254. Ctime: time.Now().Unix(),
  2255. Status: 1,
  2256. UserOrgId: orgid,
  2257. EquimentId: id,
  2258. Bed: number.Number,
  2259. PatientId: patient_id,
  2260. }
  2261. err = service.UpadateForm(id, orgid, &information)
  2262. fmt.Println("报错", err)
  2263. if err != nil {
  2264. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "修改失败:("+err.Error()+")")
  2265. return
  2266. }
  2267. this.ServeSuccessJSON(map[string]interface{}{
  2268. "information": information,
  2269. })
  2270. }
  2271. func (this *MachineApiController) QueryInfo() {
  2272. zone, _ := this.GetInt64("zone")
  2273. fmt.Println("zone", zone)
  2274. //bed, _ := this.GetInt64("bed")
  2275. //fmt.Println("bed", bed)
  2276. bed, _ := this.GetInt64("bed")
  2277. startime := this.GetString("startime")
  2278. timeLayout := "2006-01-02"
  2279. loc, _ := time.LoadLocation("Local")
  2280. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", startime+" 00:00:00", loc)
  2281. startdate := theTime.Unix()
  2282. fmt.Println("开始时间", startdate)
  2283. endtime := this.GetString("endtime")
  2284. theTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", endtime+" 00:00:00", loc)
  2285. endtimes := theTimes.Unix()
  2286. fmt.Println("结束", endtimes)
  2287. limit, _ := this.GetInt64("limit")
  2288. fmt.Println("limit", limit)
  2289. page, _ := this.GetInt64("page")
  2290. fmt.Println("page", page)
  2291. adminUser := this.GetAdminUserInfo()
  2292. orgId := adminUser.CurrentOrgId
  2293. infor, total, err := service.QueryInfo(bed, startdate, endtimes, orgId, limit, page)
  2294. if err != nil {
  2295. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询:("+err.Error()+")")
  2296. return
  2297. }
  2298. this.ServeSuccessJSON(map[string]interface{}{
  2299. "infor": infor,
  2300. "total": total,
  2301. })
  2302. }
  2303. func (this *MachineApiController) InsertAutoData() {
  2304. id, _ := this.GetInt64("id")
  2305. addmacher, _ := service.GetBedId(id)
  2306. fmt.Println("床位号", addmacher.BedId)
  2307. adminUser := this.GetAdminUserInfo()
  2308. timeStr := time.Now().Format("2006-01-02")
  2309. timeLayout := "2006-01-02 15:04:05"
  2310. fmt.Println("timeStr:", timeStr)
  2311. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  2312. timenow := timeStringToTime.Unix()
  2313. fmt.Println("timenow是什么", timenow)
  2314. orgId := adminUser.CurrentOrgId
  2315. dialysis, err := service.GetPatientID(id, orgId, timenow)
  2316. if err != nil {
  2317. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询:("+err.Error()+")")
  2318. return
  2319. }
  2320. this.ServeSuccessJSON(map[string]interface{}{
  2321. "dialysis": dialysis,
  2322. })
  2323. }
  2324. func (this *MachineApiController) GetAllEquitType() {
  2325. adminUserInfo := this.GetAdminUserInfo()
  2326. orgID := adminUserInfo.CurrentOrgId
  2327. fmt.Println("orgId", orgID)
  2328. //equitname, err := service.GetAllEquitType(orgID)
  2329. //name, err := service.GetAllEquitName(orgID)
  2330. mode, err := service.GetAllMode(orgID)
  2331. fmt.Print(err)
  2332. if err != nil {
  2333. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询:("+err.Error()+")")
  2334. return
  2335. }
  2336. this.ServeSuccessJSON(map[string]interface{}{
  2337. "mode": mode,
  2338. })
  2339. }
  2340. func (this *MachineApiController) GetUserForm() {
  2341. id, _ := this.GetInt64("id")
  2342. fmt.Println("id是什么", id)
  2343. limit, _ := this.GetInt64("limit")
  2344. fmt.Println("limit", limit)
  2345. page, _ := this.GetInt64("page")
  2346. fmt.Println("page", page)
  2347. adminUserInfo := this.GetAdminUserInfo()
  2348. orgID := adminUserInfo.CurrentOrgId
  2349. fmt.Println("orgId", orgID)
  2350. information, total, err := service.GetUserForm(id, orgID, limit, page)
  2351. fmt.Print("information", information)
  2352. fmt.Println("错误", err)
  2353. addmacher, _ := service.GetBedNumber(id, orgID)
  2354. fmt.Println("addmacher", addmacher)
  2355. if err != nil {
  2356. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询:("+err.Error()+")")
  2357. return
  2358. }
  2359. this.ServeSuccessJSON(map[string]interface{}{
  2360. "information": information,
  2361. "total": total,
  2362. "addmacher": addmacher,
  2363. })
  2364. }
  2365. func (this *MachineApiController) GetBedForm() {
  2366. adminUser := this.GetAdminUserInfo()
  2367. orgId := adminUser.CurrentOrgId
  2368. id, _ := this.GetInt64("id")
  2369. fmt.Println("id", id)
  2370. addmacher, err := service.GetZoneForm(id)
  2371. bed, err := service.GetZoneId(addmacher.BedId, orgId)
  2372. fmt.Println("bed--------------------", bed.ZoneID)
  2373. number, err := service.GetBedForm(bed.ZoneID)
  2374. if err != nil {
  2375. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询:("+err.Error()+")")
  2376. return
  2377. }
  2378. this.ServeSuccessJSON(map[string]interface{}{
  2379. "addmacher": addmacher,
  2380. "number": number,
  2381. })
  2382. }
  2383. func (this *MachineApiController) GetTotalCount() {
  2384. info := this.GetAdminUserInfo()
  2385. orgid := info.CurrentOrgId
  2386. _, total, err := service.GetTotalCount(orgid)
  2387. fmt.Print("------------------------------声优", err)
  2388. if err != nil {
  2389. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询:("+err.Error()+")")
  2390. return
  2391. }
  2392. this.ServeSuccessJSON(map[string]interface{}{
  2393. "total": total,
  2394. })
  2395. }
  2396. func (this *MachineApiController) GetTotalNumber() {
  2397. id, _ := this.GetInt64("id")
  2398. fmt.Println("id", id)
  2399. info := this.GetAdminUserInfo()
  2400. orgId := info.CurrentOrgId
  2401. total, _ := service.GetTotalNumber(id, orgId)
  2402. //fmt.Println("total",total)
  2403. //fmt.Println("====================真的",err)
  2404. //if err != nil {
  2405. // this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询:("+err.Error()+")")
  2406. // return
  2407. //}
  2408. this.ServeSuccessJSON(map[string]interface{}{
  2409. "total": total,
  2410. })
  2411. }
  2412. func (this *MachineApiController) GetTimeWarning() {
  2413. id, _ := this.GetInt64("id")
  2414. fmt.Println("设备id", id)
  2415. adminUserInfo := this.GetAdminUserInfo()
  2416. orgId := adminUserInfo.CurrentOrgId
  2417. //获取透析机消毒液更换的最后一次更换日期
  2418. information, err := service.GetTimeWarning(id, orgId)
  2419. //获取透析机消毒液细菌过滤器的最后一次更换日期
  2420. deviceInformation, err := service.GetTimeLast(id, orgId)
  2421. //获取空气滤网清洁最后一次更换日期
  2422. clean, err := service.GetTimeLastData(id, orgId)
  2423. if err != nil {
  2424. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询:("+err.Error()+")")
  2425. return
  2426. }
  2427. this.ServeSuccessJSON(map[string]interface{}{
  2428. "informations": information,
  2429. "deviceInformation": deviceInformation,
  2430. "clean": clean,
  2431. })
  2432. }
  2433. func (this *MachineApiController) SaveManageinfoTwo() {
  2434. adminUserInfo := this.GetAdminUserInfo()
  2435. orgid := adminUserInfo.CurrentOrgId
  2436. fmt.Println("机构id", orgid)
  2437. dataBody := make(map[string]interface{}, 0)
  2438. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2439. fmt.Println("err", err)
  2440. serial_numbe := dataBody["serial_number"].(string)
  2441. fmt.Println("序列号", serial_numbe)
  2442. device_type := int64(dataBody["device_type"].(float64))
  2443. fmt.Println("设备类型", device_type)
  2444. //bed_number := dataBody["beds"].(string)
  2445. //fmt.Println("床位号", bed_number)
  2446. bed_number := this.GetString("beds")
  2447. device_name := dataBody["device_name"].(string)
  2448. fmt.Println("设备名称", device_name)
  2449. manufacture_factory := dataBody["manufacture_factory"].(string)
  2450. fmt.Println("生产厂家", manufacture_factory)
  2451. service_manufacturer := dataBody["service_manufacturer"].(string)
  2452. fmt.Println("维修厂家", service_manufacturer)
  2453. unit_type := int64(dataBody["unit_type"].(float64))
  2454. //unit_type := strconv.FormatInt(unittype, 10)
  2455. //fmt.Println("设备型号", unit_type)
  2456. use_section := dataBody["use_section"].(string)
  2457. fmt.Println("使用科室", use_section)
  2458. section_number := dataBody["section_number"].(string)
  2459. fmt.Println("科室编号", section_number)
  2460. buy_date := dataBody["buy_date"].(string)
  2461. fmt.Println("buy_date", buy_date)
  2462. timeLayout := "2006-01-02 15:04:05"
  2463. theTime, err := utils.ParseTimeStringToTime(timeLayout, buy_date+" 00:00:00")
  2464. buydate := theTime.Unix()
  2465. int_num := *(*int)(unsafe.Pointer(&buydate))
  2466. if int_num < 0 {
  2467. buydate = 0
  2468. }
  2469. fmt.Println("购买日期", buydate)
  2470. install_date := dataBody["install_date"].(string)
  2471. toTime, err := utils.ParseTimeStringToTime(timeLayout, install_date+" 00:00:00")
  2472. installdate := toTime.Unix()
  2473. buy_num := *(*int)(unsafe.Pointer(&installdate))
  2474. if buy_num < 0 {
  2475. installdate = 0
  2476. }
  2477. fmt.Println("安装日期", installdate)
  2478. start_date := dataBody["start_date"].(string)
  2479. stringToTime, err := utils.ParseTimeStringToTime(timeLayout, start_date+" 00:00:00")
  2480. startdate := stringToTime.Unix()
  2481. start_num := *(*int)(unsafe.Pointer(&startdate))
  2482. if start_num < 0 {
  2483. startdate = 0
  2484. }
  2485. fmt.Println("启用日期", startdate)
  2486. maintenance_engineer := dataBody["maintenance_engineer"].(string)
  2487. fmt.Println("维修工程", maintenance_engineer)
  2488. telephone := dataBody["telephone"].(string)
  2489. fmt.Println("telephone", telephone)
  2490. guarantee_date := dataBody["guarantee_date"].(string)
  2491. fmt.Println("保修期限", guarantee_date)
  2492. machine_status := int64(dataBody["machine_status"].(float64))
  2493. fmt.Println("机器状态", machine_status)
  2494. disinfection_mode := int64(dataBody["Disinfection_mode"].(float64))
  2495. fmt.Println("消毒方式", disinfection_mode)
  2496. remarks := dataBody["remarks"].(string)
  2497. fmt.Println("备注", remarks)
  2498. rubbish_date := dataBody["rubbish_date"].(string)
  2499. timeStringToTime, err := utils.ParseTimeStringToTime(timeLayout, rubbish_date+" 00:00:00")
  2500. rubbishdate := timeStringToTime.Unix()
  2501. rubb_num := *(*int)(unsafe.Pointer(&rubbishdate))
  2502. if rubb_num < 0 {
  2503. rubbishdate = 0
  2504. }
  2505. fmt.Println("报废日期", rubbishdate)
  2506. rubbish_reason := int64(dataBody["rubbish_reason"].(float64))
  2507. fmt.Println("报废原因", rubbish_reason)
  2508. user_year := dataBody["user_year"].(string)
  2509. fmt.Println("使用年限", user_year)
  2510. work_time := dataBody["work_time"].(string)
  2511. fmt.Println("工作时长", work_time)
  2512. revers := int64(dataBody["revers_mode"].(float64))
  2513. fmt.Println("反渗模式", revers)
  2514. addmacher := &models.DeviceAddmacher{
  2515. SerialNumber: serial_numbe,
  2516. DeviceType: device_type,
  2517. BedNumber: bed_number,
  2518. DeviceName: device_name,
  2519. ManufactureFactory: manufacture_factory,
  2520. ServiceManufacturer: service_manufacturer,
  2521. UnitType: unit_type,
  2522. UseSection: use_section,
  2523. SectionNumber: section_number,
  2524. BuyDate: buydate,
  2525. InstallDate: installdate,
  2526. StartDate: startdate,
  2527. MaintenaceEngineer: maintenance_engineer,
  2528. Telephone: telephone,
  2529. GuaranteeDate: guarantee_date,
  2530. MachineStatus: machine_status,
  2531. DisinfectionMode: disinfection_mode,
  2532. Remarks: remarks,
  2533. RubbishDate: rubbishdate,
  2534. RubbishReason: rubbish_reason,
  2535. UserYear: user_year,
  2536. WorkTime: work_time,
  2537. ReversMode: revers,
  2538. Status: 1,
  2539. Ctime: time.Now().Unix(),
  2540. UserOrgId: orgid,
  2541. }
  2542. err = service.CreateMacher(addmacher)
  2543. fmt.Println("什么原因啊", err)
  2544. if err != nil {
  2545. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  2546. return
  2547. }
  2548. this.ServeSuccessJSON(map[string]interface{}{
  2549. "addmacher": addmacher,
  2550. })
  2551. }
  2552. func (this *MachineApiController) GetAllpatient() {
  2553. adminUserInfo := this.GetAdminUserInfo()
  2554. orgid := adminUserInfo.CurrentOrgId
  2555. allpatient, err := service.GetAllpatient(orgid)
  2556. fmt.Print(err)
  2557. if err != nil {
  2558. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  2559. return
  2560. }
  2561. this.ServeSuccessJSON(map[string]interface{}{
  2562. "allpatient": allpatient,
  2563. })
  2564. }
  2565. func (this *MachineApiController) ChangeBed() {
  2566. id, _ := this.GetInt64("id")
  2567. fmt.Print("id", id)
  2568. info := this.GetAdminUserInfo()
  2569. orgId := info.CurrentOrgId
  2570. bed, err := service.ChangeBed(id, orgId)
  2571. if err != nil {
  2572. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  2573. return
  2574. }
  2575. this.ServeSuccessJSON(map[string]interface{}{
  2576. "bed": bed,
  2577. })
  2578. }
  2579. func (this *MachineApiController) GetPatientDetail() {
  2580. id, _ := this.GetInt64("id")
  2581. fmt.Print("id", id)
  2582. info := this.GetAdminUserInfo()
  2583. orgid := info.CurrentOrgId
  2584. patient, err := service.GetPatientDetail(id, orgid)
  2585. if err != nil {
  2586. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  2587. return
  2588. }
  2589. this.ServeSuccessJSON(map[string]interface{}{
  2590. "patient": patient,
  2591. })
  2592. }
  2593. func (this *MachineApiController) SaveReminder() {
  2594. id, _ := this.GetInt64("id")
  2595. fmt.Print("码字", id)
  2596. info := this.GetAdminUserInfo()
  2597. orgId := info.CurrentOrgId
  2598. remander := models.DeviceRemander{
  2599. IsRun: id,
  2600. Status: 1,
  2601. UserOrgId: orgId,
  2602. Ctime: time.Now().Unix(),
  2603. }
  2604. data, errs := service.GetRemanderData(orgId)
  2605. if errs == gorm.ErrRecordNotFound {
  2606. err := service.CreateRemander(&remander).Error()
  2607. fmt.Print(err)
  2608. } else if errs == nil {
  2609. deviceRemander := models.DeviceRemander{
  2610. ID: data.ID,
  2611. IsRun: id,
  2612. Status: 1,
  2613. UserOrgId: orgId,
  2614. Mtime: time.Now().Unix(),
  2615. }
  2616. err := service.UpdateRemander(&deviceRemander)
  2617. if err != nil {
  2618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2619. return
  2620. }
  2621. }
  2622. this.ServeSuccessJSON(map[string]interface{}{
  2623. "id": id,
  2624. })
  2625. return
  2626. }
  2627. func (this *MachineApiController) GetRemanderData() {
  2628. info := this.GetAdminUserInfo()
  2629. orgid := info.CurrentOrgId
  2630. data, err := service.GetRemanderData(orgid)
  2631. if err != nil {
  2632. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2633. return
  2634. }
  2635. this.ServeSuccessJSON(map[string]interface{}{
  2636. "remander": data,
  2637. })
  2638. }
  2639. func (this *MachineApiController) OpenDelete() {
  2640. id, _ := this.GetInt64("id")
  2641. err := service.DeletePlan(id)
  2642. if err != nil {
  2643. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败")
  2644. return
  2645. }
  2646. returnData := make(map[string]interface{}, 0)
  2647. returnData["msg"] = "ok"
  2648. this.ServeSuccessJSON(returnData)
  2649. return
  2650. }
  2651. func (this *MachineApiController) DeleteUserLogin() {
  2652. id, _ := this.GetInt64("id")
  2653. err := service.DeleteUserLogin(id)
  2654. if err != nil {
  2655. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败")
  2656. return
  2657. }
  2658. returnData := make(map[string]interface{}, 0)
  2659. returnData["msg"] = "ok"
  2660. this.ServeSuccessJSON(returnData)
  2661. return
  2662. }
  2663. func (this *MachineApiController) DeleteCultrues() {
  2664. id, _ := this.GetInt64("id")
  2665. err := service.DeleteCultrues(id)
  2666. if err != nil {
  2667. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败")
  2668. return
  2669. }
  2670. returnData := make(map[string]interface{}, 0)
  2671. returnData["msg"] = "ok"
  2672. this.ServeSuccessJSON(returnData)
  2673. return
  2674. }
  2675. func (this *MachineApiController) DeleteDialystates() {
  2676. id, _ := this.GetInt64("id")
  2677. err := service.DeleteDialystates(id)
  2678. if err != nil {
  2679. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败")
  2680. return
  2681. }
  2682. returnData := make(map[string]interface{}, 0)
  2683. returnData["msg"] = "ok"
  2684. this.ServeSuccessJSON(returnData)
  2685. return
  2686. }
  2687. func (this *MachineApiController) Deleteions() {
  2688. id, _ := this.GetInt64("id")
  2689. err := service.DeleteIons(id)
  2690. if err != nil {
  2691. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败")
  2692. return
  2693. }
  2694. returnData := make(map[string]interface{}, 0)
  2695. returnData["msg"] = "ok"
  2696. this.ServeSuccessJSON(returnData)
  2697. return
  2698. }
  2699. func (this *MachineApiController) DeleteRepairs() {
  2700. id, _ := this.GetInt64("id")
  2701. err := service.DeleteRepairs(id)
  2702. if err != nil {
  2703. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败")
  2704. return
  2705. }
  2706. returnData := make(map[string]interface{}, 0)
  2707. returnData["msg"] = "ok"
  2708. this.ServeSuccessJSON(returnData)
  2709. return
  2710. }
  2711. func (this *MachineApiController) SaveMode() {
  2712. adminUserInfo := this.GetAdminUserInfo()
  2713. orgid := adminUserInfo.CurrentOrgId
  2714. fmt.Println("机构id", orgid)
  2715. dataBody := make(map[string]interface{}, 0)
  2716. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2717. fmt.Println("err", err)
  2718. device_mode := dataBody["device_mode"].(string)
  2719. mode := models.DeviceMode{
  2720. DeviceMode: device_mode,
  2721. UserOrgId: orgid,
  2722. Status: 1,
  2723. Ctime: time.Now().Unix(),
  2724. }
  2725. _, errcode := service.GetMode(device_mode, orgid)
  2726. if errcode == gorm.ErrRecordNotFound {
  2727. err = service.SaveMode(&mode)
  2728. } else if errcode == nil {
  2729. fmt.Print("设备型号已存在")
  2730. } else {
  2731. fmt.Print("设备型号已存在")
  2732. }
  2733. if err != nil {
  2734. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2735. return
  2736. }
  2737. this.ServeSuccessJSON(map[string]interface{}{
  2738. "mode": mode,
  2739. })
  2740. }
  2741. func (this *MachineApiController) GetAllMode() {
  2742. fmt.Println("进来了没哟")
  2743. adminUserInfo := this.GetAdminUserInfo()
  2744. orgid := adminUserInfo.CurrentOrgId
  2745. mode, err := service.GetAllMode(orgid)
  2746. if err != nil {
  2747. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2748. return
  2749. }
  2750. this.ServeSuccessJSON(map[string]interface{}{
  2751. "mode": mode,
  2752. })
  2753. }
  2754. func (this *MachineApiController) EditMode() {
  2755. id, _ := this.GetInt64("id")
  2756. mode, err := service.GetModeById(id)
  2757. if err != nil {
  2758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2759. return
  2760. }
  2761. this.ServeSuccessJSON(map[string]interface{}{
  2762. "mode": mode,
  2763. })
  2764. }
  2765. func (this *MachineApiController) UpdateMode() {
  2766. id, _ := this.GetInt64("id")
  2767. dataBody := make(map[string]interface{}, 0)
  2768. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2769. fmt.Println("err", err)
  2770. device_mode := dataBody["device_mode"].(string)
  2771. mode := models.DeviceMode{DeviceMode: device_mode}
  2772. err = service.UpdateMode(id, mode)
  2773. if err != nil {
  2774. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2775. return
  2776. }
  2777. this.ServeSuccessJSON(map[string]interface{}{
  2778. "mode": mode,
  2779. })
  2780. }
  2781. func (this *MachineApiController) DeleteMode() {
  2782. id, _ := this.GetInt64("id")
  2783. adminUserInfo := this.GetAdminUserInfo()
  2784. orgid := adminUserInfo.CurrentOrgId
  2785. _, errcode := service.QueryDeviceMode(id, orgid)
  2786. if errcode == gorm.ErrRecordNotFound {
  2787. service.DeleteMode(id)
  2788. returnData := make(map[string]interface{}, 0)
  2789. returnData["msg"] = "ok"
  2790. this.ServeSuccessJSON(returnData)
  2791. return
  2792. } else if errcode == nil {
  2793. return
  2794. } else {
  2795. fmt.Print("设备型号已存在")
  2796. }
  2797. }
  2798. func (this *MachineApiController) SelectChange() {
  2799. id, _ := this.GetInt64("id")
  2800. adminUserInfo := this.GetAdminUserInfo()
  2801. orgid := adminUserInfo.CurrentOrgId
  2802. change, err := service.SelectChange(id, orgid)
  2803. //fmt.Print("---------------------------", err)
  2804. if err != nil {
  2805. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2806. return
  2807. }
  2808. this.ServeSuccessJSON(map[string]interface{}{
  2809. "change": change,
  2810. })
  2811. }
  2812. func (this *MachineApiController) SelectBed() {
  2813. id, _ := this.GetInt64("id")
  2814. adminUserInfo := this.GetAdminUserInfo()
  2815. orgid := adminUserInfo.CurrentOrgId
  2816. bed, err := service.SelectBed(id, orgid)
  2817. if err != nil {
  2818. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2819. return
  2820. }
  2821. this.ServeSuccessJSON(map[string]interface{}{
  2822. "zone": bed,
  2823. })
  2824. }
  2825. func (this *MachineApiController) GetTimeData() {
  2826. equitid, _ := this.GetInt64("equitid")
  2827. fmt.Print("equitid", equitid)
  2828. timeLayout := "2006-01-02 15:04:05"
  2829. todaytime := this.GetString("todaytime")
  2830. theTime, _ := utils.ParseTimeStringToTime(timeLayout, todaytime+" 00:00:00")
  2831. fmt.Print("时间", theTime.Unix())
  2832. adminUserInfo := this.GetAdminUserInfo()
  2833. orgid := adminUserInfo.CurrentOrgId
  2834. timeData, err := service.GetTimeData(equitid, orgid, theTime.Unix())
  2835. fmt.Print("报错", err)
  2836. timeDataTwo, err := service.GetTimeTwo(equitid, orgid, theTime.Unix())
  2837. timeDataThree, err := service.GetTimeThree(equitid, orgid, theTime.Unix())
  2838. fmt.Print("err报错了没有", err)
  2839. if err != nil {
  2840. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2841. return
  2842. }
  2843. this.ServeSuccessJSON(map[string]interface{}{
  2844. "timeData": timeData,
  2845. "timeDataTwo": timeDataTwo,
  2846. "timeDataThree": timeDataThree,
  2847. })
  2848. }
  2849. func (this *MachineApiController) DeleteImages() {
  2850. id, _ := this.GetInt64("id")
  2851. err := service.DeleteImages(id)
  2852. fmt.Print("err", err)
  2853. if err != nil {
  2854. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败")
  2855. return
  2856. }
  2857. returnData := make(map[string]interface{}, 0)
  2858. returnData["msg"] = "ok"
  2859. this.ServeSuccessJSON(returnData)
  2860. return
  2861. }
  2862. func (this *MachineApiController) GetUserMachTotalCount() {
  2863. adminUserInfo := this.GetAdminUserInfo()
  2864. orgid := adminUserInfo.CurrentOrgId
  2865. count, err := service.GetUserMachTotalCount(orgid)
  2866. if err != nil {
  2867. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2868. return
  2869. }
  2870. this.ServeSuccessJSON(map[string]interface{}{
  2871. "count": count,
  2872. })
  2873. }
  2874. func (this *MachineApiController) GetUserTotalCount() {
  2875. adminUserInfo := this.GetAdminUserInfo()
  2876. orgid := adminUserInfo.CurrentOrgId
  2877. id, _ := this.GetInt64("id")
  2878. count, err := service.GetUserTotalCount(orgid, id)
  2879. addmacher, err := service.GetUserTotal(orgid, id)
  2880. if err != nil {
  2881. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2882. return
  2883. }
  2884. this.ServeSuccessJSON(map[string]interface{}{
  2885. "count": count,
  2886. "addmacher": addmacher,
  2887. })
  2888. }