device_api_controller.go 44KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  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.GetAllValidDeviceZones(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.GetAllValidDeviceZones(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. if len(num) == 0 || zoneID <= 0 || groupID <= 0 {
  733. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  734. return
  735. }
  736. adminInfo := this.GetAdminUserInfo()
  737. zone, getZoneErr := service.GetDeviceZoneByID(adminInfo.CurrentOrgId, zoneID)
  738. if getZoneErr != nil {
  739. this.ErrorLog("获取设备分区失败:%v", getZoneErr)
  740. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  741. return
  742. } else if zone == nil || zone.Status != 1 {
  743. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceZoneNotExist)
  744. return
  745. }
  746. group, getGroupErr := service.GetDeviceGroupByID(adminInfo.CurrentOrgId, groupID)
  747. if getGroupErr != nil {
  748. this.ErrorLog("获取设备分组失败:%v", getGroupErr)
  749. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  750. return
  751. } else if group == nil || group.Status != 1 {
  752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceGroupNotExist)
  753. return
  754. }
  755. _, errcode := service.GetCreateDeviceNumber(num, adminInfo.CurrentOrgId)
  756. if errcode == gorm.ErrRecordNotFound {
  757. number, createErr := service.CreateDeviceNumber(adminInfo.CurrentOrgId, num, zoneID, groupID)
  758. if createErr != nil {
  759. this.ErrorLog("创建机号失败:%v", createErr)
  760. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  761. return
  762. }
  763. numberJson := map[string]interface{}{
  764. "id": number.ID,
  765. "number": number.Number,
  766. "zone_id": number.ZoneID,
  767. "group_id": number.GroupID,
  768. "zone_name": zone.Name,
  769. "group_name": group.Name,
  770. }
  771. this.ServeSuccessJSON(map[string]interface{}{
  772. "number": numberJson,
  773. })
  774. } else if errcode == nil {
  775. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  776. return
  777. }
  778. }
  779. // /api/device/number/modify [post] ModifyNumber
  780. // @param id:int
  781. // @param number:string
  782. // @param zone:int
  783. // @param group:int
  784. func (this *DeviceAPIController) ModifyNumber() {
  785. id, _ := this.GetInt64("id")
  786. num := this.GetString("number")
  787. zoneID, _ := this.GetInt64("zone")
  788. groupID, _ := this.GetInt64("group")
  789. if id <= 0 || len(num) == 0 || zoneID <= 0 || groupID <= 0 {
  790. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  791. return
  792. }
  793. adminInfo := this.GetAdminUserInfo()
  794. number, getNumberErr := service.GetDeviceNumberByID(adminInfo.CurrentOrgId, id)
  795. if getNumberErr != nil {
  796. this.ErrorLog("获取机号失败:%v", getNumberErr)
  797. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  798. return
  799. } else if number == nil || number.Status != 1 {
  800. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  801. return
  802. }
  803. zone, getZoneErr := service.GetDeviceZoneByID(adminInfo.CurrentOrgId, zoneID)
  804. if getZoneErr != nil {
  805. this.ErrorLog("获取设备分区失败:%v", getZoneErr)
  806. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  807. return
  808. } else if zone == nil || zone.Status != 1 {
  809. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceZoneNotExist)
  810. return
  811. }
  812. group, getGroupErr := service.GetDeviceGroupByID(adminInfo.CurrentOrgId, groupID)
  813. if getGroupErr != nil {
  814. this.ErrorLog("获取设备分组失败:%v", getGroupErr)
  815. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  816. return
  817. } else if group == nil || group.Status != 1 {
  818. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceGroupNotExist)
  819. return
  820. }
  821. number.Number = num
  822. number.ZoneID = zoneID
  823. number.GroupID = groupID
  824. byName, _ := service.GetDeviceNumberByName(num, adminInfo.CurrentOrgId)
  825. if byName.ID > 0 && byName.ID != id {
  826. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  827. return
  828. }
  829. updateErr := service.UpdateDeviceNumber(number)
  830. if updateErr != nil {
  831. this.ErrorLog("修改机号失败:%v", updateErr)
  832. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  833. return
  834. }
  835. numberJson := map[string]interface{}{
  836. "id": number.ID,
  837. "number": number.Number,
  838. "zone_id": number.ZoneID,
  839. "group_id": number.GroupID,
  840. "zone_name": zone.Name,
  841. "group_name": group.Name,
  842. }
  843. this.ServeSuccessJSON(map[string]interface{}{
  844. "number": numberJson,
  845. })
  846. }
  847. // /api/device/number/disable [post] DisableNumber
  848. // @param id:int
  849. func (this *DeviceAPIController) DisableNumber() {
  850. deviceNumberID, _ := this.GetInt64("id")
  851. if deviceNumberID <= 0 {
  852. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  853. return
  854. }
  855. adminUserInfo := this.GetAdminUserInfo()
  856. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, deviceNumberID)
  857. if getDeviceNumberErr != nil {
  858. this.ErrorLog("获取机号失败:%v", getDeviceNumberErr)
  859. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  860. return
  861. } else if deviceNumber == nil {
  862. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  863. return
  864. }
  865. if deviceNumber.Status == 1 {
  866. countOfDevice, getCountErr := service.GetDeviceCountForDeviceNumberID(adminUserInfo.CurrentOrgId, deviceNumberID)
  867. if getCountErr != nil {
  868. this.ErrorLog("获取床位的设备数量失败:%v", getCountErr)
  869. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  870. return
  871. } else if countOfDevice != 0 {
  872. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberCannotDisableCuzDevice)
  873. return
  874. }
  875. now := time.Now()
  876. todayStr := now.Format("2006-01-02")
  877. today, _ := utils.ParseTimeStringToTime("2006-01-02", todayStr)
  878. countOfSch, getSchCountErr := service.GetScheduleCountForDeviceNumber(adminUserInfo.CurrentOrgId, deviceNumberID, today.Unix())
  879. if getSchCountErr != nil {
  880. this.ErrorLog("获取床位的排班失败:%v", getSchCountErr)
  881. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  882. return
  883. } else if countOfSch != 0 {
  884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberCannotDisableCuzSchedule)
  885. return
  886. }
  887. countOfSchTempItem, getSchTempItemCountErr := service.GetScheduleTemplateItemCountForDeviceNumber(adminUserInfo.CurrentOrgId, deviceNumberID)
  888. if getSchTempItemCountErr != nil {
  889. this.ErrorLog("获取床位的排班模板失败:%v", getSchTempItemCountErr)
  890. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  891. return
  892. } else if countOfSchTempItem != 0 {
  893. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberCannotDisableCuzSchTemplate)
  894. return
  895. }
  896. deviceNumber.Status = 0
  897. deviceNumber.ModifyTime = time.Now().Unix()
  898. updateErr := service.UpdateDeviceNumber(deviceNumber)
  899. if updateErr != nil {
  900. this.ErrorLog("删除床位号失败:%V", updateErr)
  901. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  902. return
  903. }
  904. }
  905. this.ServeSuccessJSON(nil)
  906. }
  907. func (this *DeviceAPIController) GetAllSubregion() {
  908. adminInfo := this.GetAdminUserInfo()
  909. zones, getZonesErr := service.GetAllValidDeviceZones(adminInfo.CurrentOrgId)
  910. if getZonesErr != nil {
  911. this.ErrorLog("获取设备分区列表失败:%v", getZonesErr)
  912. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  913. return
  914. }
  915. numbers, getNumbersErr := service.GetAllValidDeviceNumbers(adminInfo.CurrentOrgId)
  916. if getNumbersErr != nil {
  917. this.ErrorLog("获取床位失败:%v", getNumbersErr)
  918. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  919. return
  920. }
  921. devicenumber, err := service.GetAllBedNumber(adminInfo.CurrentOrgId)
  922. fmt.Println("err", err)
  923. this.ServeSuccessJSON(map[string]interface{}{
  924. "zones": zones,
  925. "numbers": numbers,
  926. "devicenumber": devicenumber,
  927. })
  928. }
  929. //func (this *DeviceAPIController) SaveManageInfo() {
  930. // adminUserInfo := this.GetAdminUserInfo()
  931. // orgid := adminUserInfo.CurrentOrgId
  932. // fmt.Println("机构id",orgid)
  933. // dataBody := make(map[string]interface{}, 0)
  934. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  935. // fmt.Println("err",err)
  936. // serial_numbe:= int64(dataBody["serial_number"].(float64))
  937. // fmt.Println("序列号",serial_numbe)
  938. // device_type := int64(dataBody["device_type"].(float64))
  939. // fmt.Println("设备类型",device_type)
  940. // bed_number := int64(dataBody["bed_number"].(float64))
  941. // fmt.Println("床位号",bed_number)
  942. // //通过床位id获取区号id
  943. // number, err := service.GetZoneId(bed_number, orgid)
  944. // fmt.Println("获取分区id错误",err)
  945. // device_name := dataBody["device_name"].(string)
  946. // fmt.Println("设备名称",device_name)
  947. // manufacture_factory := dataBody["manufacture_factory"].(string)
  948. // fmt.Println("生产厂家",manufacture_factory)
  949. // service_manufacturer := dataBody["service_manufacturer"].(string)
  950. // fmt.Println("维修厂家",service_manufacturer)
  951. // unit_type := dataBody["unit_type"].(string)
  952. // fmt.Println("设备型号",unit_type)
  953. // use_section := dataBody["use_section"].(string)
  954. // fmt.Println("使用科室",use_section)
  955. // section_number := dataBody["section_number"].(string)
  956. // fmt.Println("科室编号",section_number)
  957. // buy_date := dataBody["buy_date"].(string)
  958. // fmt.Println("buy_date",buy_date)
  959. // timeLayout := "2006-01-02 15:04:05"
  960. // theTime, err := utils.ParseTimeStringToTime(timeLayout, buy_date+" 00:00:00")
  961. // buydate := theTime.Unix()
  962. // int_num := *(*int)(unsafe.Pointer(&buydate))
  963. // if(int_num<0){
  964. // buydate = 0
  965. // }
  966. // fmt.Println("购买日期",buydate)
  967. //
  968. // install_date := dataBody["install_date"].(string)
  969. // toTime, err := utils.ParseTimeStringToTime(timeLayout, install_date+" 00:00:00")
  970. // installdate := toTime.Unix()
  971. // buy_num := *(*int)(unsafe.Pointer(&installdate))
  972. // if(buy_num < 0){
  973. // installdate = 0
  974. // }
  975. // fmt.Println("安装日期",installdate)
  976. //
  977. // start_date := dataBody["start_date"].(string)
  978. // stringToTime, err := utils.ParseTimeStringToTime(timeLayout, start_date+" 00:00:00")
  979. // startdate := stringToTime.Unix()
  980. // start_num := *(*int)(unsafe.Pointer(&startdate))
  981. // if(start_num < 0){
  982. // startdate = 0
  983. // }
  984. // fmt.Println("启用日期",startdate)
  985. //
  986. // maintenance_engineer := dataBody["maintenance_engineer"].(string)
  987. // fmt.Println("维修工程",maintenance_engineer)
  988. // telephone := dataBody["telephone"].(string)
  989. // fmt.Println("telephone",telephone)
  990. // guarantee_date := dataBody["guarantee_date"].(string)
  991. // fmt.Println("保修期限",guarantee_date)
  992. // machine_status := int64(dataBody["machine_status"].(float64))
  993. // fmt.Println("机器状态",machine_status)
  994. // user_total := dataBody["user_total"].(string)
  995. // fmt.Println("初次使用次数",user_total)
  996. // disinfection_mode := int64(dataBody["Disinfection_mode"].(float64))
  997. // fmt.Println("消毒方式",disinfection_mode)
  998. // remarks := dataBody["remarks"].(string)
  999. // fmt.Println("备注",remarks)
  1000. // rubbish_date := dataBody["rubbish_date"].(string)
  1001. // timeStringToTime, err := utils.ParseTimeStringToTime(timeLayout, rubbish_date+" 00:00:00")
  1002. // rubbishdate := timeStringToTime.Unix()
  1003. // rubb_num := *(*int)(unsafe.Pointer(&rubbishdate))
  1004. // if(rubb_num < 0){
  1005. // rubbishdate = 0
  1006. // }
  1007. // fmt.Println("报废日期",rubbishdate)
  1008. // rubbish_reason := int64(dataBody["rubbish_reason"].(float64))
  1009. // fmt.Println("报废原因",rubbish_reason)
  1010. // user_year := dataBody["user_year"].(string)
  1011. // fmt.Println("使用年限",user_year)
  1012. // work_time := dataBody["work_time"].(string)
  1013. // fmt.Println("工作时长",work_time)
  1014. // treat_types := dataBody["treat_type"].([]interface{})
  1015. // revers := int64(dataBody["revers_mode"].(float64))
  1016. // fmt.Println("反渗模式",revers)
  1017. // ids := make([]int64, 0)
  1018. // for _, treat := range treat_types {
  1019. // id := int64(treat.(float64))
  1020. // ids = append(ids, id)
  1021. // }
  1022. // fmt.Println("治疗模式",treat_types)
  1023. // addmacher := &models.DeviceAddmacher{
  1024. // SerialNumber: serial_numbe,
  1025. // DeviceType: device_type,
  1026. // BedNumber: number.Number,
  1027. // BedId:bed_number,
  1028. // ZoneId:number.ZoneID,
  1029. // DeviceName: device_name,
  1030. // ManufactureFactory: manufacture_factory,
  1031. // ServiceManufacturer: service_manufacturer,
  1032. // UnitType: unit_type,
  1033. // UseSection: use_section,
  1034. // SectionNumber: section_number,
  1035. // BuyDate: buydate,
  1036. // InstallDate: installdate,
  1037. // StartDate: startdate,
  1038. // MaintenaceEngineer: maintenance_engineer,
  1039. // Telephone: telephone,
  1040. // GuaranteeDate: guarantee_date,
  1041. // MachineStatus: machine_status,
  1042. // UserTotal: user_total,
  1043. // DisinfectionMode: disinfection_mode,
  1044. // Remarks: remarks,
  1045. // RubbishDate: rubbishdate,
  1046. // RubbishReason: rubbish_reason,
  1047. // UserYear: user_year,
  1048. // WorkTime: work_time,
  1049. // ReversMode: revers,
  1050. // Status: 1,
  1051. // Ctime: time.Now().Unix(),
  1052. // UserOrgId: orgid,
  1053. // }
  1054. // err = service.CreateMacher(addmacher)
  1055. // fmt.Println("添加数据错误是什么",err)
  1056. // if err !=nil{
  1057. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  1058. // return
  1059. // }
  1060. // deviceAddmacher, err := service.GetLastMacherData(orgid)
  1061. // fmt.Println("错误是什么" ,err)
  1062. // service.AddTreatMode(deviceAddmacher.ID,orgid,ids)
  1063. // this.ServeSuccessJSON(map[string]interface{}{
  1064. // "addmacher":addmacher,
  1065. // })
  1066. //}
  1067. func (this *DeviceAPIController) GetAllMachineInfo() {
  1068. page, _ := this.GetInt64("page")
  1069. fmt.Println("page是什么", page)
  1070. limit, _ := this.GetInt64("limit")
  1071. fmt.Println("limit是什么", limit)
  1072. searchKey := this.GetString("searchKey")
  1073. fmt.Println("searcheKey", searchKey)
  1074. zoneid, _ := this.GetInt64("zoneid")
  1075. fmt.Println("区号id", zoneid)
  1076. equipmentid, _ := this.GetInt64("equipmentid")
  1077. fmt.Println("equipmentid", equipmentid)
  1078. statusid, _ := this.GetInt64("statusid")
  1079. fmt.Println("statusid", statusid)
  1080. adminUserInfo := this.GetAdminUserInfo()
  1081. orgid := adminUserInfo.CurrentOrgId
  1082. addmahcer, total, err := service.GetAllMachineInfo(page, limit, searchKey, zoneid, equipmentid, statusid, orgid)
  1083. //fmt.Println("err------------------------------------------------------", err)
  1084. if err != nil {
  1085. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查询设备失败")
  1086. return
  1087. }
  1088. this.ServeSuccessJSON(map[string]interface{}{
  1089. "addmahcer": addmahcer,
  1090. "total": total,
  1091. })
  1092. }
  1093. func (this *DeviceAPIController) GetAllMachine() {
  1094. adminUserInfo := this.GetAdminUserInfo()
  1095. orgid := adminUserInfo.CurrentOrgId
  1096. fmt.Println("机构id", orgid)
  1097. zoneid, _ := this.GetInt64("zoneid")
  1098. fmt.Println("zoneid", zoneid)
  1099. //number, err := service.GetZoneId(zoneid, orgid)
  1100. //classid, _ := this.GetInt64("classid")
  1101. //fmt.Println("classid", classid)
  1102. deviceid, _ := this.GetInt64("deviceid")
  1103. fmt.Println("deviceid", deviceid)
  1104. //now := time.Now()
  1105. //var week = int(now.Weekday())
  1106. //weeks := int64(week)
  1107. //fmt.Println("星期几",weeks)
  1108. timeStr := time.Now().Format("2006-01-02")
  1109. timeLayout := "2006-01-02 15:04:05"
  1110. fmt.Println("timeStr:", timeStr)
  1111. timeStringToTime, err := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  1112. timenow := timeStringToTime.Unix()
  1113. fmt.Println("timenow是什么", timenow)
  1114. fmt.Println("时间搓", timeStringToTime.Unix())
  1115. addmahcer, err := service.GetAllMachine(zoneid, 0, deviceid, timenow, orgid)
  1116. if err != nil {
  1117. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查询设备失败")
  1118. return
  1119. }
  1120. this.ServeSuccessJSON(map[string]interface{}{
  1121. "addmahcer": addmahcer,
  1122. })
  1123. }
  1124. func (this *DeviceAPIController) GetMachineDetail() {
  1125. id, _ := this.GetInt64("id")
  1126. adminUserInfo := this.GetAdminUserInfo()
  1127. orgid := adminUserInfo.CurrentOrgId
  1128. fmt.Println("orgid", orgid)
  1129. addmacher, err := service.GetMachineDetail(id, orgid)
  1130. fmt.Print("err--------------------------------------------", err)
  1131. warning, err := service.GetTimeWarning(id, orgid)
  1132. germ, err := service.GetTimeLast(id, orgid)
  1133. clean, err := service.GetTimeLastData(id, orgid)
  1134. //zone, err := service.GetZoneName(addmacher.ZoneId, orgid)
  1135. fmt.Println("报错小明", err)
  1136. number, err := service.GetAllBedNumberTwo(orgid, id)
  1137. mode, errr := service.GetTreatModel(id, orgid)
  1138. fmt.Println("mode是什么", mode)
  1139. fmt.Println("错误是什么", errr)
  1140. if err != nil {
  1141. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查询单个失败")
  1142. return
  1143. }
  1144. this.ServeSuccessJSON(map[string]interface{}{
  1145. "addmacher": addmacher,
  1146. "mode": mode,
  1147. "number": number,
  1148. "warning": warning,
  1149. "germ": germ,
  1150. "clean": clean,
  1151. //"zone": zone,
  1152. })
  1153. }
  1154. func (this *DeviceAPIController) GetAllMachineTwo() {
  1155. adminUserInfo := this.GetAdminUserInfo()
  1156. orgid := adminUserInfo.CurrentOrgId
  1157. fmt.Println("机构id", orgid)
  1158. zoneid, _ := this.GetInt64("zoneid")
  1159. fmt.Println("zoneid", zoneid)
  1160. //number, err := service.GetZoneId(zoneid, orgid)
  1161. //classid, _ := this.GetInt64("classid")
  1162. //fmt.Println("classid", classid)
  1163. deviceid, _ := this.GetInt64("deviceid")
  1164. fmt.Println("deviceid", deviceid)
  1165. //now := time.Now()
  1166. //var week = int(now.Weekday())
  1167. //weeks := int64(week)
  1168. //fmt.Println("星期几",weeks)
  1169. timeStr := time.Now().Format("2006-01-02")
  1170. timeLayout := "2006-01-02 15:04:05"
  1171. fmt.Println("timeStr:", timeStr)
  1172. timeStringToTime, err := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  1173. timenow := timeStringToTime.Unix()
  1174. fmt.Println("timenow是什么", timenow)
  1175. fmt.Println("时间搓", timeStringToTime.Unix())
  1176. addmahcer, err := service.GetAllMachine(zoneid, 0, deviceid, timenow, orgid)
  1177. if err != nil {
  1178. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查询设备失败")
  1179. return
  1180. }
  1181. this.ServeSuccessJSON(map[string]interface{}{
  1182. "addmahcer": addmahcer,
  1183. })
  1184. }