device_api_controller.go 44KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  1. package controllers
  2. import (
  3. "XT_New/utils"
  4. "github.com/jinzhu/gorm"
  5. "time"
  6. "XT_New/enums"
  7. "XT_New/models"
  8. "XT_New/service"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. )
  12. func DeviceAPIControllerRegistRouters() {
  13. beego.Router("/api/device/initdata", &DeviceAPIController{}, "get:GetDeviceManageInitData")
  14. // 设备基本信息
  15. beego.Router("/api/devices", &DeviceAPIController{}, "get:GetDevices")
  16. beego.Router("/api/device/baseinfo", &DeviceAPIController{}, "get:GetDeviceBaseInfo")
  17. beego.Router("/api/device/create", &DeviceAPIController{}, "post:CreateDevice")
  18. beego.Router("/api/device/modify", &DeviceAPIController{}, "post:ModifyDevice")
  19. beego.Router("/api/device/disable", &DeviceAPIController{}, "post:DisableDevice")
  20. // 分区
  21. beego.Router("/api/device/zones", &DeviceAPIController{}, "get:GetZones")
  22. beego.Router("/api/device/zone/create", &DeviceAPIController{}, "post:CreateZone")
  23. beego.Router("/api/device/zone/modify", &DeviceAPIController{}, "post:ModifyZone")
  24. beego.Router("/api/device/zone/disable", &DeviceAPIController{}, "post:DisableZone")
  25. // 分组
  26. beego.Router("/api/device/groups", &DeviceAPIController{}, "get:GetGroups")
  27. beego.Router("/api/device/group/create", &DeviceAPIController{}, "post:CreateGroup")
  28. beego.Router("/api/device/group/modify", &DeviceAPIController{}, "post:ModifyGroup")
  29. beego.Router("/api/device/group/disable", &DeviceAPIController{}, "post:DisableGroup")
  30. // 机号
  31. beego.Router("/api/device/numbers", &DeviceAPIController{}, "get:GetNumbers")
  32. beego.Router("/api/device/number/create", &DeviceAPIController{}, "post:CreateNumber")
  33. beego.Router("/api/device/number/modify", &DeviceAPIController{}, "post:ModifyNumber")
  34. beego.Router("/api/device/number/disable", &DeviceAPIController{}, "post:DisableNumber")
  35. //透析机管理
  36. beego.Router("/api/management/getallsubregion", &DeviceAPIController{}, "get:GetAllSubregion")
  37. //beego.Router("/api/management/savemanageinfo",&DeviceAPIController{},"post:SaveManageInfo")
  38. beego.Router("/api/management/getallmachineinfo", &DeviceAPIController{}, "get:GetAllMachineInfo")
  39. beego.Router("/api/management/getallmachine", &DeviceAPIController{}, "get:GetAllMachine")
  40. beego.Router("/api/management/getmachinedetail", &DeviceAPIController{}, "get:GetMachineDetail")
  41. beego.Router("/api/management/getallmachinetwo", &DeviceAPIController{}, "get:GetAllMachineTwo")
  42. }
  43. type DeviceAPIController struct {
  44. BaseAuthAPIController
  45. }
  46. // /api/device/initdata [get] GetDeviceManageInitData
  47. func (this *DeviceAPIController) GetDeviceManageInitData() {
  48. adminInfo := this.GetAdminUserInfo()
  49. zones, getZonesErr := service.GetAllValidDeviceZonesOne(adminInfo.CurrentOrgId)
  50. if getZonesErr != nil {
  51. this.ErrorLog("获取设备分区列表失败:%v", getZonesErr)
  52. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  53. return
  54. }
  55. groups, getGroupsErr := service.GetAllValidDeviceGroups(adminInfo.CurrentOrgId)
  56. if getGroupsErr != nil {
  57. this.ErrorLog("获取设备分组列表失败:%v", getGroupsErr)
  58. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  59. return
  60. }
  61. numbers, getNumbersErr := service.GetAllValidDeviceNumbers(adminInfo.CurrentOrgId)
  62. if getNumbersErr != nil {
  63. this.ErrorLog("获取设备机号列表失败:%v", getNumbersErr)
  64. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  65. return
  66. }
  67. this.ServeSuccessJSON(map[string]interface{}{
  68. "zones": zones,
  69. "groups": groups,
  70. "numbers": numbers,
  71. })
  72. }
  73. // /api/devices [get] GetDevices
  74. // @param type?:int 1.透析机 2.水处理机 其他.全部
  75. // @param zone?:int
  76. func (this *DeviceAPIController) GetDevices() {
  77. type_, _ := this.GetInt("type")
  78. zoneID, _ := this.GetInt64("zone")
  79. if type_ < 0 || type_ > 2 {
  80. type_ = 0
  81. }
  82. if zoneID < 0 {
  83. zoneID = 0
  84. }
  85. adminInfo := this.GetAdminUserInfo()
  86. devices, getDevicesErr := service.GetValidDevicesBy(adminInfo.CurrentOrgId, type_, zoneID)
  87. if getDevicesErr != nil {
  88. this.ErrorLog("获取设备列表失败:%v", getDevicesErr)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. return
  91. }
  92. this.ServeSuccessJSON(map[string]interface{}{
  93. "devices": devices,
  94. })
  95. }
  96. // /api/device/baseinfo [get] GetDeviceBaseInfo
  97. // @param id:int models.Device.ID
  98. func (this *DeviceAPIController) GetDeviceBaseInfo() {
  99. deviceID, _ := this.GetInt64("id")
  100. if deviceID <= 0 {
  101. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  102. return
  103. }
  104. adminInfo := this.GetAdminUserInfo()
  105. device, getDeviceErr := service.GetDeviceByID(adminInfo.CurrentOrgId, deviceID)
  106. if getDeviceErr != nil {
  107. this.ErrorLog("获取设备失败:%v", getDeviceErr)
  108. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  109. return
  110. } else if device == nil || device.Status != 1 {
  111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNotExist)
  112. return
  113. }
  114. if device.DeviceType == 1 {
  115. dmDevice, getDMDeviceErr := service.GetDMDeviceByID(adminInfo.CurrentOrgId, device.DMID)
  116. if getDMDeviceErr != nil {
  117. this.ErrorLog("获取透析机失败:%v", getDMDeviceErr)
  118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  119. return
  120. } else if dmDevice == nil || dmDevice.Status != 1 {
  121. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNotExist)
  122. return
  123. }
  124. this.ServeSuccessJSON(map[string]interface{}{
  125. "device_type": device.DeviceType,
  126. "device_number_id": device.DeviceNumberID,
  127. "device_info": dmDevice,
  128. })
  129. } else if device.DeviceType == 2 {
  130. wteDevice, getWTEDeviceErr := service.GetWTEDeviceByID(adminInfo.CurrentOrgId, device.WTEID)
  131. if getWTEDeviceErr != nil {
  132. this.ErrorLog("获取水处理机失败:%v", getWTEDeviceErr)
  133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  134. return
  135. } else if wteDevice == nil || wteDevice.Status != 1 {
  136. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNotExist)
  137. return
  138. }
  139. this.ServeSuccessJSON(map[string]interface{}{
  140. "device_type": device.DeviceType,
  141. "device_number_id": device.DeviceNumberID,
  142. "device_info": wteDevice,
  143. })
  144. }
  145. }
  146. // /api/device/create [post] CreateDevice
  147. // @param type:int 设备类型 1.透析机 2.水处理机
  148. // @param serial_number:string 序列号
  149. // @param name:string 设备名
  150. // @param device_number_id?:int 机号
  151. // @param manufacturer?:string 生产厂家
  152. // @param repair_factory?:string 维修厂家
  153. // @param model?:string 型号
  154. // @param department?:string 使用科室
  155. // @param department_number?:string 科室编号
  156. // @param purchase_date?:int 购买日期
  157. // @param install_date?:int 安装日期
  158. // @param commissioning_date?:int 启用日期
  159. // @param maintainer?:string 维修工程师
  160. // @param maintenance_call?:string 维修联系电话
  161. // @param warranty_period?:string 保修期限
  162. // @param device_status?:int 机器状态 1.使用机 2.备用机 3.急诊机 4.报废机
  163. // @param initial_use_times?:int 初始使用次数
  164. // @param mark?:string 备注
  165. // @param retirement_date?:int 报废日期
  166. // @param retirement_reason?:string 报废原因
  167. // @param service_life?:int 使用年限
  168. // @param working_time?:int 工作时长
  169. // @param treatment_mode?:string 治疗模式 type = 1
  170. // @param reverse_osmosis_mode?:int 反渗模式 type = 2
  171. func (this *DeviceAPIController) CreateDevice() {
  172. deviceType, _ := this.GetInt("type")
  173. serialNumber := this.GetString("serial_number")
  174. deviceName := this.GetString("name")
  175. if deviceType < 1 || 2 < deviceType || len(serialNumber) == 0 || len(deviceName) == 0 {
  176. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  177. return
  178. }
  179. deviceNumberID, _ := this.GetInt64("device_number_id")
  180. manufacturer := this.GetString("manufacturer")
  181. repairFactory := this.GetString("repair_factory")
  182. model := this.GetString("model")
  183. department := this.GetString("department")
  184. departmentNumber := this.GetString("department_number")
  185. purchaseDate, _ := this.GetInt64("purchase_date")
  186. installDate, _ := this.GetInt64("install_date")
  187. commissioningDate, _ := this.GetInt64("commissioning_date")
  188. maintainer := this.GetString("maintainer")
  189. maintenanceCall := this.GetString("maintenance_call")
  190. warrantyPeriod := this.GetString("warranty_period")
  191. deviceStatus, _ := this.GetInt("device_status")
  192. initialUseTimes, _ := this.GetInt("initial_use_times")
  193. mark := this.GetString("mark")
  194. retirementDate, _ := this.GetInt64("retirement_date")
  195. retirementReason := this.GetString("retirement_reason")
  196. serviceLife, _ := this.GetInt("service_life")
  197. workingTime, _ := this.GetInt("working_time")
  198. treatmentMode := this.GetString("treatment_mode")
  199. reverseOsmosisMode, _ := this.GetInt("reverse_osmosis_mode")
  200. adminInfo := this.GetAdminUserInfo()
  201. var deviceNumber *models.DeviceNumber
  202. if deviceNumberID != 0 {
  203. var getNumberErr error
  204. deviceNumber, getNumberErr = service.GetDeviceNumberByID(adminInfo.CurrentOrgId, deviceNumberID)
  205. if getNumberErr != nil {
  206. this.ErrorLog("获取机号失败:%v", getNumberErr)
  207. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  208. return
  209. } else if deviceNumber == nil || deviceNumber.Status != 1 {
  210. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  211. return
  212. }
  213. }
  214. if deviceStatus < 1 || 4 < deviceStatus {
  215. deviceStatus = 0
  216. }
  217. if deviceType == 1 {
  218. dmDevice := &models.DeviceDM{
  219. OrgID: adminInfo.CurrentOrgId,
  220. SerialNumber: serialNumber,
  221. Name: deviceName,
  222. Manufacturer: manufacturer,
  223. RepairFactory: repairFactory,
  224. Model: model,
  225. Department: department,
  226. DepartmentNumber: departmentNumber,
  227. PurchaseDate: purchaseDate,
  228. InstallDate: installDate,
  229. CommissioningDate: commissioningDate,
  230. Maintainer: maintainer,
  231. MaintenanceCall: maintenanceCall,
  232. WarrantyPeriod: warrantyPeriod,
  233. DeviceStatus: deviceStatus,
  234. InitialUseTimes: initialUseTimes,
  235. Mark: mark,
  236. RetirementDate: retirementDate,
  237. RetirementReason: retirementReason,
  238. ServiceLife: serviceLife,
  239. WorkingTime: workingTime,
  240. TreatmentMode: treatmentMode,
  241. }
  242. device, createErr := service.CreateDMDevice(dmDevice, deviceNumber)
  243. if createErr != nil {
  244. this.ErrorLog("创建血透机失败:%v")
  245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  246. return
  247. }
  248. this.ServeSuccessJSON(map[string]interface{}{
  249. "device": device,
  250. })
  251. } else if deviceType == 2 {
  252. wteDevice := &models.DeviceWTE{
  253. OrgID: adminInfo.CurrentOrgId,
  254. SerialNumber: serialNumber,
  255. Name: deviceName,
  256. Manufacturer: manufacturer,
  257. RepairFactory: repairFactory,
  258. Model: model,
  259. Department: department,
  260. DepartmentNumber: departmentNumber,
  261. PurchaseDate: purchaseDate,
  262. InstallDate: installDate,
  263. CommissioningDate: commissioningDate,
  264. Maintainer: maintainer,
  265. MaintenanceCall: maintenanceCall,
  266. WarrantyPeriod: warrantyPeriod,
  267. DeviceStatus: deviceStatus,
  268. InitialUseTimes: initialUseTimes,
  269. Mark: mark,
  270. RetirementDate: retirementDate,
  271. RetirementReason: retirementReason,
  272. ServiceLife: serviceLife,
  273. WorkingTime: workingTime,
  274. ReverseOsmosisMode: reverseOsmosisMode,
  275. }
  276. device, createErr := service.CreateWTEDevice(wteDevice, deviceNumber)
  277. if createErr != nil {
  278. this.ErrorLog("创建水处理机失败:%v")
  279. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  280. return
  281. }
  282. this.ServeSuccessJSON(map[string]interface{}{
  283. "device": device,
  284. })
  285. }
  286. }
  287. // /api/device/modify [post] ModifyDevice
  288. // @param device_id:int 设备 ID(models.Device.ID)
  289. // @param serial_number:string 序列号
  290. // @param name:string 设备名
  291. // @param device_number_id?:int 机号
  292. // @param manufacturer?:string 生产厂家
  293. // @param repair_factory?:string 维修厂家
  294. // @param model?:string 型号
  295. // @param department?:string 使用科室
  296. // @param department_number?:string 科室编号
  297. // @param purchase_date?:int 购买日期
  298. // @param install_date?:int 安装日期
  299. // @param commissioning_date?:int 启用日期
  300. // @param maintainer?:string 维修工程师
  301. // @param maintenance_call?:string 维修联系电话
  302. // @param warranty_period?:string 保修期限
  303. // @param device_status?:int 机器状态 1.使用机 2.备用机 3.急诊机 4.报废机
  304. // @param initial_use_times?:int 初始使用次数
  305. // @param mark?:string 备注
  306. // @param retirement_date?:int 报废日期
  307. // @param retirement_reason?:string 报废原因
  308. // @param service_life?:int 使用年限
  309. // @param working_time?:int 工作时长
  310. // @param treatment_mode?:string 治疗模式 type = 1
  311. // @param reverse_osmosis_mode?:int 反渗模式 type = 2
  312. func (this *DeviceAPIController) ModifyDevice() {
  313. deviceID, _ := this.GetInt64("device_id")
  314. serialNumber := this.GetString("serial_number")
  315. deviceName := this.GetString("name")
  316. if deviceID <= 0 || len(serialNumber) == 0 || len(deviceName) == 0 {
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. deviceNumberID, _ := this.GetInt64("device_number_id")
  321. manufacturer := this.GetString("manufacturer")
  322. repairFactory := this.GetString("repair_factory")
  323. model := this.GetString("model")
  324. department := this.GetString("department")
  325. departmentNumber := this.GetString("department_number")
  326. purchaseDate, _ := this.GetInt64("purchase_date")
  327. installDate, _ := this.GetInt64("install_date")
  328. commissioningDate, _ := this.GetInt64("commissioning_date")
  329. maintainer := this.GetString("maintainer")
  330. maintenanceCall := this.GetString("maintenance_call")
  331. warrantyPeriod := this.GetString("warranty_period")
  332. deviceStatus, _ := this.GetInt("device_status")
  333. initialUseTimes, _ := this.GetInt("initial_use_times")
  334. mark := this.GetString("mark")
  335. retirementDate, _ := this.GetInt64("retirement_date")
  336. retirementReason := this.GetString("retirement_reason")
  337. serviceLife, _ := this.GetInt("service_life")
  338. workingTime, _ := this.GetInt("working_time")
  339. treatmentMode := this.GetString("treatment_mode")
  340. reverseOsmosisMode, _ := this.GetInt("reverse_osmosis_mode")
  341. adminInfo := this.GetAdminUserInfo()
  342. var deviceNumber *models.DeviceNumber
  343. if deviceNumberID != 0 {
  344. var getNumberErr error
  345. deviceNumber, getNumberErr = service.GetDeviceNumberByID(adminInfo.CurrentOrgId, deviceNumberID)
  346. if getNumberErr != nil {
  347. this.ErrorLog("获取机号失败:%v", getNumberErr)
  348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  349. return
  350. } else if deviceNumber == nil || deviceNumber.Status != 1 {
  351. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  352. return
  353. }
  354. }
  355. if deviceStatus < 1 || 4 < deviceStatus {
  356. deviceStatus = 0
  357. }
  358. device, getDeviceErr := service.GetDeviceByID(adminInfo.CurrentOrgId, deviceID)
  359. if getDeviceErr != nil {
  360. this.ErrorLog("获取设备失败:%v", getDeviceErr)
  361. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  362. return
  363. } else if device == nil || device.Status != 1 {
  364. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNotExist)
  365. return
  366. }
  367. if device.DeviceType == 1 {
  368. dmDevice, getDMDeviceErr := service.GetDMDeviceByID(adminInfo.CurrentOrgId, device.DMID)
  369. if getDMDeviceErr != nil {
  370. this.ErrorLog("获取透析机失败:%v", getDMDeviceErr)
  371. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  372. return
  373. } else if dmDevice == nil || dmDevice.Status != 1 {
  374. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNotExist)
  375. return
  376. }
  377. dmDevice.SerialNumber = serialNumber
  378. dmDevice.Name = deviceName
  379. dmDevice.Manufacturer = manufacturer
  380. dmDevice.RepairFactory = repairFactory
  381. dmDevice.Model = model
  382. dmDevice.Department = department
  383. dmDevice.DepartmentNumber = departmentNumber
  384. dmDevice.PurchaseDate = purchaseDate
  385. dmDevice.InstallDate = installDate
  386. dmDevice.CommissioningDate = commissioningDate
  387. dmDevice.Maintainer = maintainer
  388. dmDevice.MaintenanceCall = maintenanceCall
  389. dmDevice.WarrantyPeriod = warrantyPeriod
  390. dmDevice.DeviceStatus = deviceStatus
  391. dmDevice.InitialUseTimes = initialUseTimes
  392. dmDevice.Mark = mark
  393. dmDevice.RetirementDate = retirementDate
  394. dmDevice.RetirementReason = retirementReason
  395. dmDevice.ServiceLife = serviceLife
  396. dmDevice.WorkingTime = workingTime
  397. dmDevice.TreatmentMode = treatmentMode
  398. updateErr := service.UpdateDMDevice(dmDevice, deviceNumber, device)
  399. if updateErr != nil {
  400. this.ErrorLog("更新血透机失败:%v", updateErr)
  401. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  402. return
  403. }
  404. this.ServeSuccessJSON(map[string]interface{}{
  405. "device": device,
  406. })
  407. } else if device.DeviceType == 2 {
  408. wteDevice, getWTEDeviceErr := service.GetWTEDeviceByID(adminInfo.CurrentOrgId, device.WTEID)
  409. if getWTEDeviceErr != nil {
  410. this.ErrorLog("获取水处理机失败:%v", getWTEDeviceErr)
  411. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  412. return
  413. } else if wteDevice == nil || wteDevice.Status != 1 {
  414. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNotExist)
  415. return
  416. }
  417. wteDevice.SerialNumber = serialNumber
  418. wteDevice.Name = deviceName
  419. wteDevice.Manufacturer = manufacturer
  420. wteDevice.RepairFactory = repairFactory
  421. wteDevice.Model = model
  422. wteDevice.Department = department
  423. wteDevice.DepartmentNumber = departmentNumber
  424. wteDevice.PurchaseDate = purchaseDate
  425. wteDevice.InstallDate = installDate
  426. wteDevice.CommissioningDate = commissioningDate
  427. wteDevice.Maintainer = maintainer
  428. wteDevice.MaintenanceCall = maintenanceCall
  429. wteDevice.WarrantyPeriod = warrantyPeriod
  430. wteDevice.DeviceStatus = deviceStatus
  431. wteDevice.InitialUseTimes = initialUseTimes
  432. wteDevice.Mark = mark
  433. wteDevice.RetirementDate = retirementDate
  434. wteDevice.RetirementReason = retirementReason
  435. wteDevice.ServiceLife = serviceLife
  436. wteDevice.WorkingTime = workingTime
  437. wteDevice.ReverseOsmosisMode = reverseOsmosisMode
  438. updateErr := service.UpdateWTEDevice(wteDevice, deviceNumber, device)
  439. if updateErr != nil {
  440. this.ErrorLog("更新水处理机失败:%v", updateErr)
  441. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  442. return
  443. }
  444. this.ServeSuccessJSON(map[string]interface{}{
  445. "device": device,
  446. })
  447. }
  448. }
  449. // /api/device/disable [post] DisableDevice
  450. // @param id:int
  451. func (this *DeviceAPIController) DisableDevice() {
  452. deviceID, _ := this.GetInt64("id")
  453. if deviceID <= 0 {
  454. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  455. return
  456. }
  457. adminUserInfo := this.GetAdminUserInfo()
  458. device, getDeviceErr := service.GetDeviceByID(adminUserInfo.CurrentOrgId, deviceID)
  459. if getDeviceErr != nil {
  460. this.ErrorLog("获取设备失败:%v", getDeviceErr)
  461. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  462. return
  463. } else if device == nil {
  464. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNotExist)
  465. return
  466. }
  467. if device.Status == 1 {
  468. device.Status = 0
  469. device.ModifyTime = time.Now().Unix()
  470. updateErr := service.UpdateDevice(device)
  471. if updateErr != nil {
  472. this.ErrorLog("删除设备失败:%v", updateErr)
  473. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  474. return
  475. }
  476. }
  477. this.ServeSuccessJSON(nil)
  478. }
  479. // /api/device/zones [get] GetZones
  480. func (this *DeviceAPIController) GetZones() {
  481. adminInfo := this.GetAdminUserInfo()
  482. zones, getZonesErr := service.GetAllValidDeviceZonesOne(adminInfo.CurrentOrgId)
  483. if getZonesErr != nil {
  484. this.ErrorLog("获取设备分区列表失败:%v", getZonesErr)
  485. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  486. return
  487. }
  488. this.ServeSuccessJSON(map[string]interface{}{
  489. "zones": zones,
  490. })
  491. }
  492. // /api/device/zone/create [post] CreateZone
  493. // @param name:string
  494. // @param type:int
  495. func (this *DeviceAPIController) CreateZone() {
  496. name := this.GetString("name")
  497. type_, _ := this.GetInt("type")
  498. if len(name) == 0 || type_ <= 0 {
  499. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  500. return
  501. }
  502. adminInfo := this.GetAdminUserInfo()
  503. _, errcode := service.GetZoneByName(name, adminInfo.CurrentOrgId)
  504. fmt.Println("errcode=----------", errcode)
  505. if errcode == gorm.ErrRecordNotFound {
  506. zone, createErr := service.CreateDeviceZone(adminInfo.CurrentOrgId, name, type_)
  507. if createErr != nil {
  508. this.ErrorLog("创建设备分区失败:%v", createErr)
  509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  510. return
  511. }
  512. this.ServeSuccessJSON(map[string]interface{}{
  513. "zone": zone,
  514. })
  515. } else if errcode == nil {
  516. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  517. return
  518. }
  519. }
  520. // /api/device/zone/modify [post] ModifyZone
  521. // @param id:int
  522. // @param name:string
  523. // @param type:int
  524. func (this *DeviceAPIController) ModifyZone() {
  525. id, _ := this.GetInt64("id")
  526. name := this.GetString("name")
  527. type_, _ := this.GetInt("type")
  528. if id <= 0 || len(name) == 0 || type_ <= 0 {
  529. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  530. return
  531. }
  532. adminInfo := this.GetAdminUserInfo()
  533. zone, getZoneErr := service.GetDeviceZoneByID(adminInfo.CurrentOrgId, id)
  534. if getZoneErr != nil {
  535. this.ErrorLog("获取设备分区失败:%v", getZoneErr)
  536. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  537. return
  538. } else if zone == nil || zone.Status != 1 {
  539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceZoneNotExist)
  540. return
  541. }
  542. zone.Name = name
  543. zone.Type = type_
  544. zone.ModifyTime = time.Now().Unix()
  545. byName, _ := service.GetZoneByNameOne(name, adminInfo.CurrentOrgId)
  546. if byName.ID > 0 && byName.ID != id {
  547. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  548. return
  549. }
  550. updateErr := service.UpdateDeviceZone(zone)
  551. if updateErr != nil {
  552. this.ErrorLog("修改设备分区失败:%v", updateErr)
  553. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  554. return
  555. }
  556. this.ServeSuccessJSON(nil)
  557. }
  558. // /api/device/zone/disable [post] DisableZone
  559. // @param id:int
  560. func (this *DeviceAPIController) DisableZone() {
  561. zoneID, _ := this.GetInt64("id")
  562. if zoneID <= 0 {
  563. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  564. return
  565. }
  566. adminUserInfo := this.GetAdminUserInfo()
  567. zone, getZoneErr := service.GetDeviceZoneByID(adminUserInfo.CurrentOrgId, zoneID)
  568. if getZoneErr != nil {
  569. this.ErrorLog("获取设备分区失败:%v", getZoneErr)
  570. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  571. return
  572. } else if zone == nil {
  573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceZoneNotExist)
  574. return
  575. }
  576. if zone.Status == 1 {
  577. countOfDeviceNumber, getCountErr := service.GetDeviceNumberCountForZoneID(adminUserInfo.CurrentOrgId, zoneID)
  578. if getCountErr != nil {
  579. this.ErrorLog("获取分区内床位数量失败:%v", getCountErr)
  580. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  581. return
  582. }
  583. if countOfDeviceNumber != 0 {
  584. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceZoneCannotDisable)
  585. return
  586. }
  587. zone.Status = 0
  588. zone.ModifyTime = time.Now().Unix()
  589. updateErr := service.UpdateDeviceZone(zone)
  590. if updateErr != nil {
  591. this.ErrorLog("删除分区失败:%v", updateErr)
  592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  593. return
  594. }
  595. }
  596. this.ServeSuccessJSON(nil)
  597. }
  598. // /api/device/groups [get] GetGroups
  599. func (this *DeviceAPIController) GetGroups() {
  600. adminInfo := this.GetAdminUserInfo()
  601. groups, getGroupsErr := service.GetAllValidDeviceGroups(adminInfo.CurrentOrgId)
  602. if getGroupsErr != nil {
  603. //beego.Error("获取设备分组列表失败:", getGroupsErr)
  604. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  605. return
  606. }
  607. this.ServeSuccessJSON(map[string]interface{}{
  608. "groups": groups,
  609. })
  610. }
  611. // /api/device/group/create [post] CreateGroup
  612. // @param name:string
  613. func (this *DeviceAPIController) CreateGroup() {
  614. name := this.GetString("name")
  615. if len(name) == 0 {
  616. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  617. return
  618. }
  619. adminInfo := this.GetAdminUserInfo()
  620. _, errcode := service.GetDeviceGroupName(name, adminInfo.CurrentOrgId)
  621. if errcode == gorm.ErrRecordNotFound {
  622. group, createErr := service.CreateDeviceGroup(adminInfo.CurrentOrgId, name)
  623. if createErr != nil {
  624. this.ErrorLog("创建设备分组失败:%v", createErr)
  625. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  626. return
  627. }
  628. this.ServeSuccessJSON(map[string]interface{}{
  629. "group": group,
  630. })
  631. } else if errcode == nil {
  632. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  633. return
  634. }
  635. }
  636. // /api/device/group/modify [post] ModifyGroup
  637. // @param id:int
  638. // @param name:string
  639. func (this *DeviceAPIController) ModifyGroup() {
  640. id, _ := this.GetInt64("id")
  641. name := this.GetString("name")
  642. if id <= 0 || len(name) == 0 {
  643. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  644. return
  645. }
  646. adminInfo := this.GetAdminUserInfo()
  647. group, getGroupErr := service.GetDeviceGroupByID(adminInfo.CurrentOrgId, id)
  648. if getGroupErr != nil {
  649. this.ErrorLog("获取设备分组失败:%v", getGroupErr)
  650. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  651. return
  652. } else if group == nil || group.Status != 1 {
  653. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceGroupNotExist)
  654. return
  655. }
  656. group.Name = name
  657. group.ModifyTime = time.Now().Unix()
  658. byName, getGroupErr := service.GetUpdateDeviceGroupByName(name, adminInfo.CurrentOrgId)
  659. if byName.ID > 0 && byName.ID != id {
  660. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  661. return
  662. }
  663. updateErr := service.UpdateDeviceGroup(group)
  664. if updateErr != nil {
  665. this.ErrorLog("修改设备分组失败:%v", updateErr)
  666. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  667. return
  668. }
  669. this.ServeSuccessJSON(nil)
  670. }
  671. // /api/device/group/disable [post] DisableGroup
  672. // @param id:int
  673. func (this *DeviceAPIController) DisableGroup() {
  674. groupID, _ := this.GetInt64("id")
  675. if groupID <= 0 {
  676. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  677. return
  678. }
  679. adminUserInfo := this.GetAdminUserInfo()
  680. group, getGroupErr := service.GetDeviceGroupByID(adminUserInfo.CurrentOrgId, groupID)
  681. if getGroupErr != nil {
  682. this.ErrorLog("获取设备分组失败:%v", getGroupErr)
  683. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  684. return
  685. } else if group == nil {
  686. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceGroupNotExist)
  687. return
  688. }
  689. if group.Status == 1 {
  690. countOfDeviceNumber, getCountErr := service.GetDeviceNumberCountForGroupID(adminUserInfo.CurrentOrgId, groupID)
  691. if getCountErr != nil {
  692. this.ErrorLog("获取分组内床位数量失败:%v", getCountErr)
  693. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  694. return
  695. }
  696. if countOfDeviceNumber != 0 {
  697. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceZoneCannotDisable)
  698. return
  699. }
  700. group.Status = 0
  701. group.ModifyTime = time.Now().Unix()
  702. updateErr := service.UpdateDeviceGroup(group)
  703. if updateErr != nil {
  704. this.ErrorLog("删除分组失败:%v", updateErr)
  705. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  706. return
  707. }
  708. }
  709. this.ServeSuccessJSON(nil)
  710. }
  711. // /api/device/numbers [get] GetNumbers
  712. func (this *DeviceAPIController) GetNumbers() {
  713. adminInfo := this.GetAdminUserInfo()
  714. numbers, getNumbersErr := service.GetAllValidDeviceNumbers(adminInfo.CurrentOrgId)
  715. if getNumbersErr != nil {
  716. //beego.Error("获取机号列表失败:", getNumbersErr)
  717. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  718. return
  719. }
  720. this.ServeSuccessJSON(map[string]interface{}{
  721. "numbers": numbers,
  722. })
  723. }
  724. // /api/device/number/create [post] CreateNumber
  725. // @param number:string
  726. // @param zone:int
  727. // @param group:int
  728. func (this *DeviceAPIController) CreateNumber() {
  729. num := this.GetString("number")
  730. zoneID, _ := this.GetInt64("zone")
  731. groupID, _ := this.GetInt64("group")
  732. sort, _ := this.GetInt64("sort")
  733. if len(num) == 0 || zoneID <= 0 || groupID <= 0 {
  734. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  735. return
  736. }
  737. adminInfo := this.GetAdminUserInfo()
  738. zone, getZoneErr := service.GetDeviceZoneByID(adminInfo.CurrentOrgId, zoneID)
  739. if getZoneErr != nil {
  740. this.ErrorLog("获取设备分区失败:%v", getZoneErr)
  741. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  742. return
  743. } else if zone == nil || zone.Status != 1 {
  744. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceZoneNotExist)
  745. return
  746. }
  747. group, getGroupErr := service.GetDeviceGroupByID(adminInfo.CurrentOrgId, groupID)
  748. if getGroupErr != nil {
  749. this.ErrorLog("获取设备分组失败:%v", getGroupErr)
  750. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  751. return
  752. } else if group == nil || group.Status != 1 {
  753. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceGroupNotExist)
  754. return
  755. }
  756. _, errcode := service.GetCreateDeviceNumber(num, adminInfo.CurrentOrgId)
  757. if errcode == gorm.ErrRecordNotFound {
  758. number, createErr := service.CreateDeviceNumber(adminInfo.CurrentOrgId, num, zoneID, groupID, sort)
  759. if createErr != nil {
  760. this.ErrorLog("创建机号失败:%v", createErr)
  761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  762. return
  763. }
  764. numberJson := map[string]interface{}{
  765. "id": number.ID,
  766. "number": number.Number,
  767. "zone_id": number.ZoneID,
  768. "group_id": number.GroupID,
  769. "zone_name": zone.Name,
  770. "group_name": group.Name,
  771. "sort": number.Sort,
  772. }
  773. this.ServeSuccessJSON(map[string]interface{}{
  774. "number": numberJson,
  775. })
  776. } else if errcode == nil {
  777. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  778. return
  779. }
  780. }
  781. // /api/device/number/modify [post] ModifyNumber
  782. // @param id:int
  783. // @param number:string
  784. // @param zone:int
  785. // @param group:int
  786. func (this *DeviceAPIController) ModifyNumber() {
  787. id, _ := this.GetInt64("id")
  788. num := this.GetString("number")
  789. zoneID, _ := this.GetInt64("zone")
  790. groupID, _ := this.GetInt64("group")
  791. sort, _ := this.GetInt64("sort")
  792. if id <= 0 || len(num) == 0 || zoneID <= 0 || groupID <= 0 {
  793. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  794. return
  795. }
  796. adminInfo := this.GetAdminUserInfo()
  797. number, getNumberErr := service.GetDeviceNumberByID(adminInfo.CurrentOrgId, id)
  798. if getNumberErr != nil {
  799. this.ErrorLog("获取机号失败:%v", getNumberErr)
  800. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  801. return
  802. } else if number == nil || number.Status != 1 {
  803. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  804. return
  805. }
  806. zone, getZoneErr := service.GetDeviceZoneByID(adminInfo.CurrentOrgId, zoneID)
  807. if getZoneErr != nil {
  808. this.ErrorLog("获取设备分区失败:%v", getZoneErr)
  809. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  810. return
  811. } else if zone == nil || zone.Status != 1 {
  812. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceZoneNotExist)
  813. return
  814. }
  815. group, getGroupErr := service.GetDeviceGroupByID(adminInfo.CurrentOrgId, groupID)
  816. if getGroupErr != nil {
  817. this.ErrorLog("获取设备分组失败:%v", getGroupErr)
  818. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  819. return
  820. } else if group == nil || group.Status != 1 {
  821. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceGroupNotExist)
  822. return
  823. }
  824. number.Number = num
  825. number.ZoneID = zoneID
  826. number.GroupID = groupID
  827. number.Sort = sort
  828. byName, _ := service.GetDeviceNumberByName(num, zoneID, adminInfo.CurrentOrgId)
  829. if byName.ID > 0 && byName.ID != id {
  830. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  831. return
  832. }
  833. updateErr := service.UpdateDeviceNumber(number)
  834. //查询该床位是否绑定设备
  835. _, errcode := service.GetAddMacherByBedId(id, adminInfo.CurrentOrgId)
  836. if errcode == nil {
  837. //修改设备管理机器分区
  838. addmacher := models.DeviceAddmacher{
  839. ZoneId: zoneID,
  840. }
  841. service.UpdateAddmacherByBedId(id, addmacher)
  842. }
  843. if updateErr != nil {
  844. this.ErrorLog("修改机号失败:%v", updateErr)
  845. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  846. return
  847. }
  848. numberJson := map[string]interface{}{
  849. "id": number.ID,
  850. "number": number.Number,
  851. "zone_id": number.ZoneID,
  852. "group_id": number.GroupID,
  853. "zone_name": zone.Name,
  854. "group_name": group.Name,
  855. "sort": number.Sort,
  856. }
  857. this.ServeSuccessJSON(map[string]interface{}{
  858. "number": numberJson,
  859. })
  860. }
  861. // /api/device/number/disable [post] DisableNumber
  862. // @param id:int
  863. func (this *DeviceAPIController) DisableNumber() {
  864. deviceNumberID, _ := this.GetInt64("id")
  865. if deviceNumberID <= 0 {
  866. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  867. return
  868. }
  869. adminUserInfo := this.GetAdminUserInfo()
  870. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, deviceNumberID)
  871. if getDeviceNumberErr != nil {
  872. this.ErrorLog("获取机号失败:%v", getDeviceNumberErr)
  873. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  874. return
  875. } else if deviceNumber == nil {
  876. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  877. return
  878. }
  879. if deviceNumber.Status == 1 {
  880. countOfDevice, getCountErr := service.GetDeviceCountForDeviceNumberID(adminUserInfo.CurrentOrgId, deviceNumberID)
  881. if getCountErr != nil {
  882. this.ErrorLog("获取床位的设备数量失败:%v", getCountErr)
  883. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  884. return
  885. } else if countOfDevice != 0 {
  886. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberCannotDisableCuzDevice)
  887. return
  888. }
  889. now := time.Now()
  890. todayStr := now.Format("2006-01-02")
  891. today, _ := utils.ParseTimeStringToTime("2006-01-02", todayStr)
  892. countOfSch, getSchCountErr := service.GetScheduleCountForDeviceNumber(adminUserInfo.CurrentOrgId, deviceNumberID, today.Unix())
  893. if getSchCountErr != nil {
  894. this.ErrorLog("获取床位的排班失败:%v", getSchCountErr)
  895. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  896. return
  897. } else if countOfSch != 0 {
  898. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberCannotDisableCuzSchedule)
  899. return
  900. }
  901. countOfSchTempItem, getSchTempItemCountErr := service.GetScheduleTemplateItemCountForDeviceNumber(adminUserInfo.CurrentOrgId, deviceNumberID)
  902. if getSchTempItemCountErr != nil {
  903. this.ErrorLog("获取床位的排班模板失败:%v", getSchTempItemCountErr)
  904. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  905. return
  906. } else if countOfSchTempItem != 0 {
  907. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberCannotDisableCuzSchTemplate)
  908. return
  909. }
  910. deviceNumber.Status = 0
  911. deviceNumber.ModifyTime = time.Now().Unix()
  912. updateErr := service.UpdateDeviceNumber(deviceNumber)
  913. if updateErr != nil {
  914. this.ErrorLog("删除床位号失败:%V", updateErr)
  915. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  916. return
  917. }
  918. }
  919. this.ServeSuccessJSON(nil)
  920. }
  921. func (this *DeviceAPIController) GetAllSubregion() {
  922. adminInfo := this.GetAdminUserInfo()
  923. zones, getZonesErr := service.GetAllValidDeviceZones(adminInfo.CurrentOrgId)
  924. if getZonesErr != nil {
  925. this.ErrorLog("获取设备分区列表失败:%v", getZonesErr)
  926. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  927. return
  928. }
  929. numbers, getNumbersErr := service.GetAllValidDeviceNumbers(adminInfo.CurrentOrgId)
  930. if getNumbersErr != nil {
  931. this.ErrorLog("获取床位失败:%v", getNumbersErr)
  932. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  933. return
  934. }
  935. devicenumber, err := service.GetAllBedNumber(adminInfo.CurrentOrgId)
  936. fmt.Println("err", err)
  937. this.ServeSuccessJSON(map[string]interface{}{
  938. "zones": zones,
  939. "numbers": numbers,
  940. "devicenumber": devicenumber,
  941. })
  942. }
  943. //func (this *DeviceAPIController) SaveManageInfo() {
  944. // adminUserInfo := this.GetAdminUserInfo()
  945. // orgid := adminUserInfo.CurrentOrgId
  946. // fmt.Println("机构id",orgid)
  947. // dataBody := make(map[string]interface{}, 0)
  948. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  949. // fmt.Println("err",err)
  950. // serial_numbe:= int64(dataBody["serial_number"].(float64))
  951. // fmt.Println("序列号",serial_numbe)
  952. // device_type := int64(dataBody["device_type"].(float64))
  953. // fmt.Println("设备类型",device_type)
  954. // bed_number := int64(dataBody["bed_number"].(float64))
  955. // fmt.Println("床位号",bed_number)
  956. // //通过床位id获取区号id
  957. // number, err := service.GetZoneId(bed_number, orgid)
  958. // fmt.Println("获取分区id错误",err)
  959. // device_name := dataBody["device_name"].(string)
  960. // fmt.Println("设备名称",device_name)
  961. // manufacture_factory := dataBody["manufacture_factory"].(string)
  962. // fmt.Println("生产厂家",manufacture_factory)
  963. // service_manufacturer := dataBody["service_manufacturer"].(string)
  964. // fmt.Println("维修厂家",service_manufacturer)
  965. // unit_type := dataBody["unit_type"].(string)
  966. // fmt.Println("设备型号",unit_type)
  967. // use_section := dataBody["use_section"].(string)
  968. // fmt.Println("使用科室",use_section)
  969. // section_number := dataBody["section_number"].(string)
  970. // fmt.Println("科室编号",section_number)
  971. // buy_date := dataBody["buy_date"].(string)
  972. // fmt.Println("buy_date",buy_date)
  973. // timeLayout := "2006-01-02 15:04:05"
  974. // theTime, err := utils.ParseTimeStringToTime(timeLayout, buy_date+" 00:00:00")
  975. // buydate := theTime.Unix()
  976. // int_num := *(*int)(unsafe.Pointer(&buydate))
  977. // if(int_num<0){
  978. // buydate = 0
  979. // }
  980. // fmt.Println("购买日期",buydate)
  981. //
  982. // install_date := dataBody["install_date"].(string)
  983. // toTime, err := utils.ParseTimeStringToTime(timeLayout, install_date+" 00:00:00")
  984. // installdate := toTime.Unix()
  985. // buy_num := *(*int)(unsafe.Pointer(&installdate))
  986. // if(buy_num < 0){
  987. // installdate = 0
  988. // }
  989. // fmt.Println("安装日期",installdate)
  990. //
  991. // start_date := dataBody["start_date"].(string)
  992. // stringToTime, err := utils.ParseTimeStringToTime(timeLayout, start_date+" 00:00:00")
  993. // startdate := stringToTime.Unix()
  994. // start_num := *(*int)(unsafe.Pointer(&startdate))
  995. // if(start_num < 0){
  996. // startdate = 0
  997. // }
  998. // fmt.Println("启用日期",startdate)
  999. //
  1000. // maintenance_engineer := dataBody["maintenance_engineer"].(string)
  1001. // fmt.Println("维修工程",maintenance_engineer)
  1002. // telephone := dataBody["telephone"].(string)
  1003. // fmt.Println("telephone",telephone)
  1004. // guarantee_date := dataBody["guarantee_date"].(string)
  1005. // fmt.Println("保修期限",guarantee_date)
  1006. // machine_status := int64(dataBody["machine_status"].(float64))
  1007. // fmt.Println("机器状态",machine_status)
  1008. // user_total := dataBody["user_total"].(string)
  1009. // fmt.Println("初次使用次数",user_total)
  1010. // disinfection_mode := int64(dataBody["Disinfection_mode"].(float64))
  1011. // fmt.Println("消毒方式",disinfection_mode)
  1012. // remarks := dataBody["remarks"].(string)
  1013. // fmt.Println("备注",remarks)
  1014. // rubbish_date := dataBody["rubbish_date"].(string)
  1015. // timeStringToTime, err := utils.ParseTimeStringToTime(timeLayout, rubbish_date+" 00:00:00")
  1016. // rubbishdate := timeStringToTime.Unix()
  1017. // rubb_num := *(*int)(unsafe.Pointer(&rubbishdate))
  1018. // if(rubb_num < 0){
  1019. // rubbishdate = 0
  1020. // }
  1021. // fmt.Println("报废日期",rubbishdate)
  1022. // rubbish_reason := int64(dataBody["rubbish_reason"].(float64))
  1023. // fmt.Println("报废原因",rubbish_reason)
  1024. // user_year := dataBody["user_year"].(string)
  1025. // fmt.Println("使用年限",user_year)
  1026. // work_time := dataBody["work_time"].(string)
  1027. // fmt.Println("工作时长",work_time)
  1028. // treat_types := dataBody["treat_type"].([]interface{})
  1029. // revers := int64(dataBody["revers_mode"].(float64))
  1030. // fmt.Println("反渗模式",revers)
  1031. // ids := make([]int64, 0)
  1032. // for _, treat := range treat_types {
  1033. // id := int64(treat.(float64))
  1034. // ids = append(ids, id)
  1035. // }
  1036. // fmt.Println("治疗模式",treat_types)
  1037. // addmacher := &models.DeviceAddmacher{
  1038. // SerialNumber: serial_numbe,
  1039. // DeviceType: device_type,
  1040. // BedNumber: number.Number,
  1041. // BedId:bed_number,
  1042. // ZoneId:number.ZoneID,
  1043. // DeviceName: device_name,
  1044. // ManufactureFactory: manufacture_factory,
  1045. // ServiceManufacturer: service_manufacturer,
  1046. // UnitType: unit_type,
  1047. // UseSection: use_section,
  1048. // SectionNumber: section_number,
  1049. // BuyDate: buydate,
  1050. // InstallDate: installdate,
  1051. // StartDate: startdate,
  1052. // MaintenaceEngineer: maintenance_engineer,
  1053. // Telephone: telephone,
  1054. // GuaranteeDate: guarantee_date,
  1055. // MachineStatus: machine_status,
  1056. // UserTotal: user_total,
  1057. // DisinfectionMode: disinfection_mode,
  1058. // Remarks: remarks,
  1059. // RubbishDate: rubbishdate,
  1060. // RubbishReason: rubbish_reason,
  1061. // UserYear: user_year,
  1062. // WorkTime: work_time,
  1063. // ReversMode: revers,
  1064. // Status: 1,
  1065. // Ctime: time.Now().Unix(),
  1066. // UserOrgId: orgid,
  1067. // }
  1068. // err = service.CreateMacher(addmacher)
  1069. // fmt.Println("添加数据错误是什么",err)
  1070. // if err !=nil{
  1071. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  1072. // return
  1073. // }
  1074. // deviceAddmacher, err := service.GetLastMacherData(orgid)
  1075. // fmt.Println("错误是什么" ,err)
  1076. // service.AddTreatMode(deviceAddmacher.ID,orgid,ids)
  1077. // this.ServeSuccessJSON(map[string]interface{}{
  1078. // "addmacher":addmacher,
  1079. // })
  1080. //}
  1081. func (this *DeviceAPIController) GetAllMachineInfo() {
  1082. page, _ := this.GetInt64("page")
  1083. limit, _ := this.GetInt64("limit")
  1084. searchKey := this.GetString("searchKey")
  1085. zoneid, _ := this.GetInt64("zoneid")
  1086. equipmentid, _ := this.GetInt64("equipmentid")
  1087. statusid, _ := this.GetInt64("statusid")
  1088. adminUserInfo := this.GetAdminUserInfo()
  1089. orgid := adminUserInfo.CurrentOrgId
  1090. addmahcer, total, err := service.GetAllMachineInfo(page, limit, searchKey, zoneid, equipmentid, statusid, orgid)
  1091. if err != nil {
  1092. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查询设备失败")
  1093. return
  1094. }
  1095. this.ServeSuccessJSON(map[string]interface{}{
  1096. "addmahcer": addmahcer,
  1097. "total": total,
  1098. })
  1099. }
  1100. func (this *DeviceAPIController) GetAllMachine() {
  1101. adminUserInfo := this.GetAdminUserInfo()
  1102. orgid := adminUserInfo.CurrentOrgId
  1103. fmt.Println("机构id", orgid)
  1104. zoneid, _ := this.GetInt64("zoneid")
  1105. fmt.Println("zoneid", zoneid)
  1106. //number, err := service.GetZoneId(zoneid, orgid)
  1107. //classid, _ := this.GetInt64("classid")
  1108. //fmt.Println("classid", classid)
  1109. deviceid, _ := this.GetInt64("deviceid")
  1110. fmt.Println("deviceid", deviceid)
  1111. //now := time.Now()
  1112. //var week = int(now.Weekday())
  1113. //weeks := int64(week)
  1114. //fmt.Println("星期几",weeks)
  1115. timeStr := time.Now().Format("2006-01-02")
  1116. timeLayout := "2006-01-02 15:04:05"
  1117. fmt.Println("timeStr:", timeStr)
  1118. timeStringToTime, err := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  1119. timenow := timeStringToTime.Unix()
  1120. fmt.Println("timenow是什么", timenow)
  1121. fmt.Println("时间搓", timeStringToTime.Unix())
  1122. addmahcer, err := service.GetAllMachine(zoneid, 0, deviceid, timenow, orgid)
  1123. if err != nil {
  1124. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查询设备失败")
  1125. return
  1126. }
  1127. this.ServeSuccessJSON(map[string]interface{}{
  1128. "addmahcer": addmahcer,
  1129. })
  1130. }
  1131. func (this *DeviceAPIController) GetMachineDetail() {
  1132. id, _ := this.GetInt64("id")
  1133. adminUserInfo := this.GetAdminUserInfo()
  1134. orgid := adminUserInfo.CurrentOrgId
  1135. fmt.Println("orgid", orgid)
  1136. addmacher, err := service.GetMachineDetail(id, orgid)
  1137. fmt.Print("err", err)
  1138. warning, err := service.GetTimeWarning(id, orgid)
  1139. germ, err := service.GetTimeLast(id, orgid)
  1140. clean, err := service.GetTimeLastData(id, orgid)
  1141. //zone, err := service.GetZoneName(addmacher.ZoneId, orgid)
  1142. fmt.Println("报错小明", err)
  1143. number, err := service.GetAllBedNumberTwo(orgid, id)
  1144. mode, errr := service.GetTreatModel(id, orgid)
  1145. fmt.Println("mode是什么", mode)
  1146. fmt.Println("错误是什么", errr)
  1147. if err != nil {
  1148. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查询单个失败")
  1149. return
  1150. }
  1151. this.ServeSuccessJSON(map[string]interface{}{
  1152. "addmacher": addmacher,
  1153. "mode": mode,
  1154. "number": number,
  1155. "warning": warning,
  1156. "germ": germ,
  1157. "clean": clean,
  1158. //"zone": zone,
  1159. })
  1160. }
  1161. func (this *DeviceAPIController) GetAllMachineTwo() {
  1162. adminUserInfo := this.GetAdminUserInfo()
  1163. orgid := adminUserInfo.CurrentOrgId
  1164. fmt.Println("机构id", orgid)
  1165. zoneid, _ := this.GetInt64("zoneid")
  1166. fmt.Println("zoneid", zoneid)
  1167. //number, err := service.GetZoneId(zoneid, orgid)
  1168. //classid, _ := this.GetInt64("classid")
  1169. //fmt.Println("classid", classid)
  1170. deviceid, _ := this.GetInt64("deviceid")
  1171. fmt.Println("deviceid", deviceid)
  1172. //now := time.Now()
  1173. //var week = int(now.Weekday())
  1174. //weeks := int64(week)
  1175. //fmt.Println("星期几",weeks)
  1176. timeStr := time.Now().Format("2006-01-02")
  1177. timeLayout := "2006-01-02 15:04:05"
  1178. fmt.Println("timeStr:", timeStr)
  1179. timeStringToTime, err := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  1180. timenow := timeStringToTime.Unix()
  1181. fmt.Println("timenow是什么", timenow)
  1182. fmt.Println("时间搓", timeStringToTime.Unix())
  1183. addmahcer, err := service.GetAllMachine(zoneid, 0, deviceid, timenow, orgid)
  1184. if err != nil {
  1185. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查询设备失败")
  1186. return
  1187. }
  1188. this.ServeSuccessJSON(map[string]interface{}{
  1189. "addmahcer": addmahcer,
  1190. })
  1191. }