device_api_controller.go 43KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  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. updateErr := service.UpdateDeviceZone(zone)
  546. if updateErr != nil {
  547. this.ErrorLog("修改设备分区失败:%v", updateErr)
  548. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  549. return
  550. }
  551. this.ServeSuccessJSON(nil)
  552. }
  553. // /api/device/zone/disable [post] DisableZone
  554. // @param id:int
  555. func (this *DeviceAPIController) DisableZone() {
  556. zoneID, _ := this.GetInt64("id")
  557. if zoneID <= 0 {
  558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  559. return
  560. }
  561. adminUserInfo := this.GetAdminUserInfo()
  562. zone, getZoneErr := service.GetDeviceZoneByID(adminUserInfo.CurrentOrgId, zoneID)
  563. if getZoneErr != nil {
  564. this.ErrorLog("获取设备分区失败:%v", getZoneErr)
  565. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  566. return
  567. } else if zone == nil {
  568. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceZoneNotExist)
  569. return
  570. }
  571. if zone.Status == 1 {
  572. countOfDeviceNumber, getCountErr := service.GetDeviceNumberCountForZoneID(adminUserInfo.CurrentOrgId, zoneID)
  573. if getCountErr != nil {
  574. this.ErrorLog("获取分区内床位数量失败:%v", getCountErr)
  575. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  576. return
  577. }
  578. if countOfDeviceNumber != 0 {
  579. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceZoneCannotDisable)
  580. return
  581. }
  582. zone.Status = 0
  583. zone.ModifyTime = time.Now().Unix()
  584. updateErr := service.UpdateDeviceZone(zone)
  585. if updateErr != nil {
  586. this.ErrorLog("删除分区失败:%v", updateErr)
  587. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  588. return
  589. }
  590. }
  591. this.ServeSuccessJSON(nil)
  592. }
  593. // /api/device/groups [get] GetGroups
  594. func (this *DeviceAPIController) GetGroups() {
  595. adminInfo := this.GetAdminUserInfo()
  596. groups, getGroupsErr := service.GetAllValidDeviceGroups(adminInfo.CurrentOrgId)
  597. if getGroupsErr != nil {
  598. //beego.Error("获取设备分组列表失败:", getGroupsErr)
  599. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  600. return
  601. }
  602. this.ServeSuccessJSON(map[string]interface{}{
  603. "groups": groups,
  604. })
  605. }
  606. // /api/device/group/create [post] CreateGroup
  607. // @param name:string
  608. func (this *DeviceAPIController) CreateGroup() {
  609. name := this.GetString("name")
  610. if len(name) == 0 {
  611. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  612. return
  613. }
  614. adminInfo := this.GetAdminUserInfo()
  615. group, createErr := service.CreateDeviceGroup(adminInfo.CurrentOrgId, name)
  616. if createErr != nil {
  617. this.ErrorLog("创建设备分组失败:%v", createErr)
  618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  619. return
  620. }
  621. this.ServeSuccessJSON(map[string]interface{}{
  622. "group": group,
  623. })
  624. }
  625. // /api/device/group/modify [post] ModifyGroup
  626. // @param id:int
  627. // @param name:string
  628. func (this *DeviceAPIController) ModifyGroup() {
  629. id, _ := this.GetInt64("id")
  630. name := this.GetString("name")
  631. if id <= 0 || len(name) == 0 {
  632. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. return
  634. }
  635. adminInfo := this.GetAdminUserInfo()
  636. group, getGroupErr := service.GetDeviceGroupByID(adminInfo.CurrentOrgId, id)
  637. if getGroupErr != nil {
  638. this.ErrorLog("获取设备分组失败:%v", getGroupErr)
  639. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  640. return
  641. } else if group == nil || group.Status != 1 {
  642. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceGroupNotExist)
  643. return
  644. }
  645. group.Name = name
  646. group.ModifyTime = time.Now().Unix()
  647. updateErr := service.UpdateDeviceGroup(group)
  648. if updateErr != nil {
  649. this.ErrorLog("修改设备分组失败:%v", updateErr)
  650. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  651. return
  652. }
  653. this.ServeSuccessJSON(nil)
  654. }
  655. // /api/device/group/disable [post] DisableGroup
  656. // @param id:int
  657. func (this *DeviceAPIController) DisableGroup() {
  658. groupID, _ := this.GetInt64("id")
  659. if groupID <= 0 {
  660. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  661. return
  662. }
  663. adminUserInfo := this.GetAdminUserInfo()
  664. group, getGroupErr := service.GetDeviceGroupByID(adminUserInfo.CurrentOrgId, groupID)
  665. if getGroupErr != nil {
  666. this.ErrorLog("获取设备分组失败:%v", getGroupErr)
  667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  668. return
  669. } else if group == nil {
  670. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceGroupNotExist)
  671. return
  672. }
  673. if group.Status == 1 {
  674. countOfDeviceNumber, getCountErr := service.GetDeviceNumberCountForGroupID(adminUserInfo.CurrentOrgId, groupID)
  675. if getCountErr != nil {
  676. this.ErrorLog("获取分组内床位数量失败:%v", getCountErr)
  677. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  678. return
  679. }
  680. if countOfDeviceNumber != 0 {
  681. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceZoneCannotDisable)
  682. return
  683. }
  684. group.Status = 0
  685. group.ModifyTime = time.Now().Unix()
  686. updateErr := service.UpdateDeviceGroup(group)
  687. if updateErr != nil {
  688. this.ErrorLog("删除分组失败:%v", updateErr)
  689. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  690. return
  691. }
  692. }
  693. this.ServeSuccessJSON(nil)
  694. }
  695. // /api/device/numbers [get] GetNumbers
  696. func (this *DeviceAPIController) GetNumbers() {
  697. adminInfo := this.GetAdminUserInfo()
  698. numbers, getNumbersErr := service.GetAllValidDeviceNumbers(adminInfo.CurrentOrgId)
  699. if getNumbersErr != nil {
  700. //beego.Error("获取机号列表失败:", getNumbersErr)
  701. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  702. return
  703. }
  704. this.ServeSuccessJSON(map[string]interface{}{
  705. "numbers": numbers,
  706. })
  707. }
  708. // /api/device/number/create [post] CreateNumber
  709. // @param number:string
  710. // @param zone:int
  711. // @param group:int
  712. func (this *DeviceAPIController) CreateNumber() {
  713. num := this.GetString("number")
  714. zoneID, _ := this.GetInt64("zone")
  715. groupID, _ := this.GetInt64("group")
  716. if len(num) == 0 || zoneID <= 0 || groupID <= 0 {
  717. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  718. return
  719. }
  720. adminInfo := this.GetAdminUserInfo()
  721. zone, getZoneErr := service.GetDeviceZoneByID(adminInfo.CurrentOrgId, zoneID)
  722. if getZoneErr != nil {
  723. this.ErrorLog("获取设备分区失败:%v", getZoneErr)
  724. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  725. return
  726. } else if zone == nil || zone.Status != 1 {
  727. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceZoneNotExist)
  728. return
  729. }
  730. group, getGroupErr := service.GetDeviceGroupByID(adminInfo.CurrentOrgId, groupID)
  731. if getGroupErr != nil {
  732. this.ErrorLog("获取设备分组失败:%v", getGroupErr)
  733. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  734. return
  735. } else if group == nil || group.Status != 1 {
  736. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceGroupNotExist)
  737. return
  738. }
  739. number, createErr := service.CreateDeviceNumber(adminInfo.CurrentOrgId, num, zoneID, groupID)
  740. if createErr != nil {
  741. this.ErrorLog("创建机号失败:%v", createErr)
  742. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  743. return
  744. }
  745. numberJson := map[string]interface{}{
  746. "id": number.ID,
  747. "number": number.Number,
  748. "zone_id": number.ZoneID,
  749. "group_id": number.GroupID,
  750. "zone_name": zone.Name,
  751. "group_name": group.Name,
  752. }
  753. this.ServeSuccessJSON(map[string]interface{}{
  754. "number": numberJson,
  755. })
  756. }
  757. // /api/device/number/modify [post] ModifyNumber
  758. // @param id:int
  759. // @param number:string
  760. // @param zone:int
  761. // @param group:int
  762. func (this *DeviceAPIController) ModifyNumber() {
  763. id, _ := this.GetInt64("id")
  764. num := this.GetString("number")
  765. zoneID, _ := this.GetInt64("zone")
  766. groupID, _ := this.GetInt64("group")
  767. if id <= 0 || len(num) == 0 || zoneID <= 0 || groupID <= 0 {
  768. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  769. return
  770. }
  771. adminInfo := this.GetAdminUserInfo()
  772. number, getNumberErr := service.GetDeviceNumberByID(adminInfo.CurrentOrgId, id)
  773. if getNumberErr != nil {
  774. this.ErrorLog("获取机号失败:%v", getNumberErr)
  775. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  776. return
  777. } else if number == nil || number.Status != 1 {
  778. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  779. return
  780. }
  781. zone, getZoneErr := service.GetDeviceZoneByID(adminInfo.CurrentOrgId, zoneID)
  782. if getZoneErr != nil {
  783. this.ErrorLog("获取设备分区失败:%v", getZoneErr)
  784. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  785. return
  786. } else if zone == nil || zone.Status != 1 {
  787. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceZoneNotExist)
  788. return
  789. }
  790. group, getGroupErr := service.GetDeviceGroupByID(adminInfo.CurrentOrgId, groupID)
  791. if getGroupErr != nil {
  792. this.ErrorLog("获取设备分组失败:%v", getGroupErr)
  793. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  794. return
  795. } else if group == nil || group.Status != 1 {
  796. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceGroupNotExist)
  797. return
  798. }
  799. number.Number = num
  800. number.ZoneID = zoneID
  801. number.GroupID = groupID
  802. updateErr := service.UpdateDeviceNumber(number)
  803. if updateErr != nil {
  804. this.ErrorLog("修改机号失败:%v", updateErr)
  805. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  806. return
  807. }
  808. numberJson := map[string]interface{}{
  809. "id": number.ID,
  810. "number": number.Number,
  811. "zone_id": number.ZoneID,
  812. "group_id": number.GroupID,
  813. "zone_name": zone.Name,
  814. "group_name": group.Name,
  815. }
  816. this.ServeSuccessJSON(map[string]interface{}{
  817. "number": numberJson,
  818. })
  819. }
  820. // /api/device/number/disable [post] DisableNumber
  821. // @param id:int
  822. func (this *DeviceAPIController) DisableNumber() {
  823. deviceNumberID, _ := this.GetInt64("id")
  824. if deviceNumberID <= 0 {
  825. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  826. return
  827. }
  828. adminUserInfo := this.GetAdminUserInfo()
  829. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, deviceNumberID)
  830. if getDeviceNumberErr != nil {
  831. this.ErrorLog("获取机号失败:%v", getDeviceNumberErr)
  832. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  833. return
  834. } else if deviceNumber == nil {
  835. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  836. return
  837. }
  838. if deviceNumber.Status == 1 {
  839. countOfDevice, getCountErr := service.GetDeviceCountForDeviceNumberID(adminUserInfo.CurrentOrgId, deviceNumberID)
  840. if getCountErr != nil {
  841. this.ErrorLog("获取床位的设备数量失败:%v", getCountErr)
  842. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  843. return
  844. } else if countOfDevice != 0 {
  845. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberCannotDisableCuzDevice)
  846. return
  847. }
  848. now := time.Now()
  849. todayStr := now.Format("2006-01-02")
  850. today, _ := utils.ParseTimeStringToTime("2006-01-02", todayStr)
  851. countOfSch, getSchCountErr := service.GetScheduleCountForDeviceNumber(adminUserInfo.CurrentOrgId, deviceNumberID, today.Unix())
  852. if getSchCountErr != nil {
  853. this.ErrorLog("获取床位的排班失败:%v", getSchCountErr)
  854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  855. return
  856. } else if countOfSch != 0 {
  857. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberCannotDisableCuzSchedule)
  858. return
  859. }
  860. countOfSchTempItem, getSchTempItemCountErr := service.GetScheduleTemplateItemCountForDeviceNumber(adminUserInfo.CurrentOrgId, deviceNumberID)
  861. if getSchTempItemCountErr != nil {
  862. this.ErrorLog("获取床位的排班模板失败:%v", getSchTempItemCountErr)
  863. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  864. return
  865. } else if countOfSchTempItem != 0 {
  866. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberCannotDisableCuzSchTemplate)
  867. return
  868. }
  869. deviceNumber.Status = 0
  870. deviceNumber.ModifyTime = time.Now().Unix()
  871. updateErr := service.UpdateDeviceNumber(deviceNumber)
  872. if updateErr != nil {
  873. this.ErrorLog("删除床位号失败:%V", updateErr)
  874. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  875. return
  876. }
  877. }
  878. this.ServeSuccessJSON(nil)
  879. }
  880. func (this *DeviceAPIController) GetAllSubregion() {
  881. adminInfo := this.GetAdminUserInfo()
  882. zones, getZonesErr := service.GetAllValidDeviceZones(adminInfo.CurrentOrgId)
  883. if getZonesErr != nil {
  884. this.ErrorLog("获取设备分区列表失败:%v", getZonesErr)
  885. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  886. return
  887. }
  888. numbers, getNumbersErr := service.GetAllValidDeviceNumbers(adminInfo.CurrentOrgId)
  889. if getNumbersErr != nil {
  890. this.ErrorLog("获取床位失败:%v", getNumbersErr)
  891. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  892. return
  893. }
  894. devicenumber, err := service.GetAllBedNumber(adminInfo.CurrentOrgId)
  895. fmt.Println("err", err)
  896. this.ServeSuccessJSON(map[string]interface{}{
  897. "zones": zones,
  898. "numbers": numbers,
  899. "devicenumber": devicenumber,
  900. })
  901. }
  902. //func (this *DeviceAPIController) SaveManageInfo() {
  903. // adminUserInfo := this.GetAdminUserInfo()
  904. // orgid := adminUserInfo.CurrentOrgId
  905. // fmt.Println("机构id",orgid)
  906. // dataBody := make(map[string]interface{}, 0)
  907. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  908. // fmt.Println("err",err)
  909. // serial_numbe:= int64(dataBody["serial_number"].(float64))
  910. // fmt.Println("序列号",serial_numbe)
  911. // device_type := int64(dataBody["device_type"].(float64))
  912. // fmt.Println("设备类型",device_type)
  913. // bed_number := int64(dataBody["bed_number"].(float64))
  914. // fmt.Println("床位号",bed_number)
  915. // //通过床位id获取区号id
  916. // number, err := service.GetZoneId(bed_number, orgid)
  917. // fmt.Println("获取分区id错误",err)
  918. // device_name := dataBody["device_name"].(string)
  919. // fmt.Println("设备名称",device_name)
  920. // manufacture_factory := dataBody["manufacture_factory"].(string)
  921. // fmt.Println("生产厂家",manufacture_factory)
  922. // service_manufacturer := dataBody["service_manufacturer"].(string)
  923. // fmt.Println("维修厂家",service_manufacturer)
  924. // unit_type := dataBody["unit_type"].(string)
  925. // fmt.Println("设备型号",unit_type)
  926. // use_section := dataBody["use_section"].(string)
  927. // fmt.Println("使用科室",use_section)
  928. // section_number := dataBody["section_number"].(string)
  929. // fmt.Println("科室编号",section_number)
  930. // buy_date := dataBody["buy_date"].(string)
  931. // fmt.Println("buy_date",buy_date)
  932. // timeLayout := "2006-01-02 15:04:05"
  933. // theTime, err := utils.ParseTimeStringToTime(timeLayout, buy_date+" 00:00:00")
  934. // buydate := theTime.Unix()
  935. // int_num := *(*int)(unsafe.Pointer(&buydate))
  936. // if(int_num<0){
  937. // buydate = 0
  938. // }
  939. // fmt.Println("购买日期",buydate)
  940. //
  941. // install_date := dataBody["install_date"].(string)
  942. // toTime, err := utils.ParseTimeStringToTime(timeLayout, install_date+" 00:00:00")
  943. // installdate := toTime.Unix()
  944. // buy_num := *(*int)(unsafe.Pointer(&installdate))
  945. // if(buy_num < 0){
  946. // installdate = 0
  947. // }
  948. // fmt.Println("安装日期",installdate)
  949. //
  950. // start_date := dataBody["start_date"].(string)
  951. // stringToTime, err := utils.ParseTimeStringToTime(timeLayout, start_date+" 00:00:00")
  952. // startdate := stringToTime.Unix()
  953. // start_num := *(*int)(unsafe.Pointer(&startdate))
  954. // if(start_num < 0){
  955. // startdate = 0
  956. // }
  957. // fmt.Println("启用日期",startdate)
  958. //
  959. // maintenance_engineer := dataBody["maintenance_engineer"].(string)
  960. // fmt.Println("维修工程",maintenance_engineer)
  961. // telephone := dataBody["telephone"].(string)
  962. // fmt.Println("telephone",telephone)
  963. // guarantee_date := dataBody["guarantee_date"].(string)
  964. // fmt.Println("保修期限",guarantee_date)
  965. // machine_status := int64(dataBody["machine_status"].(float64))
  966. // fmt.Println("机器状态",machine_status)
  967. // user_total := dataBody["user_total"].(string)
  968. // fmt.Println("初次使用次数",user_total)
  969. // disinfection_mode := int64(dataBody["Disinfection_mode"].(float64))
  970. // fmt.Println("消毒方式",disinfection_mode)
  971. // remarks := dataBody["remarks"].(string)
  972. // fmt.Println("备注",remarks)
  973. // rubbish_date := dataBody["rubbish_date"].(string)
  974. // timeStringToTime, err := utils.ParseTimeStringToTime(timeLayout, rubbish_date+" 00:00:00")
  975. // rubbishdate := timeStringToTime.Unix()
  976. // rubb_num := *(*int)(unsafe.Pointer(&rubbishdate))
  977. // if(rubb_num < 0){
  978. // rubbishdate = 0
  979. // }
  980. // fmt.Println("报废日期",rubbishdate)
  981. // rubbish_reason := int64(dataBody["rubbish_reason"].(float64))
  982. // fmt.Println("报废原因",rubbish_reason)
  983. // user_year := dataBody["user_year"].(string)
  984. // fmt.Println("使用年限",user_year)
  985. // work_time := dataBody["work_time"].(string)
  986. // fmt.Println("工作时长",work_time)
  987. // treat_types := dataBody["treat_type"].([]interface{})
  988. // revers := int64(dataBody["revers_mode"].(float64))
  989. // fmt.Println("反渗模式",revers)
  990. // ids := make([]int64, 0)
  991. // for _, treat := range treat_types {
  992. // id := int64(treat.(float64))
  993. // ids = append(ids, id)
  994. // }
  995. // fmt.Println("治疗模式",treat_types)
  996. // addmacher := &models.DeviceAddmacher{
  997. // SerialNumber: serial_numbe,
  998. // DeviceType: device_type,
  999. // BedNumber: number.Number,
  1000. // BedId:bed_number,
  1001. // ZoneId:number.ZoneID,
  1002. // DeviceName: device_name,
  1003. // ManufactureFactory: manufacture_factory,
  1004. // ServiceManufacturer: service_manufacturer,
  1005. // UnitType: unit_type,
  1006. // UseSection: use_section,
  1007. // SectionNumber: section_number,
  1008. // BuyDate: buydate,
  1009. // InstallDate: installdate,
  1010. // StartDate: startdate,
  1011. // MaintenaceEngineer: maintenance_engineer,
  1012. // Telephone: telephone,
  1013. // GuaranteeDate: guarantee_date,
  1014. // MachineStatus: machine_status,
  1015. // UserTotal: user_total,
  1016. // DisinfectionMode: disinfection_mode,
  1017. // Remarks: remarks,
  1018. // RubbishDate: rubbishdate,
  1019. // RubbishReason: rubbish_reason,
  1020. // UserYear: user_year,
  1021. // WorkTime: work_time,
  1022. // ReversMode: revers,
  1023. // Status: 1,
  1024. // Ctime: time.Now().Unix(),
  1025. // UserOrgId: orgid,
  1026. // }
  1027. // err = service.CreateMacher(addmacher)
  1028. // fmt.Println("添加数据错误是什么",err)
  1029. // if err !=nil{
  1030. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  1031. // return
  1032. // }
  1033. // deviceAddmacher, err := service.GetLastMacherData(orgid)
  1034. // fmt.Println("错误是什么" ,err)
  1035. // service.AddTreatMode(deviceAddmacher.ID,orgid,ids)
  1036. // this.ServeSuccessJSON(map[string]interface{}{
  1037. // "addmacher":addmacher,
  1038. // })
  1039. //}
  1040. func (this *DeviceAPIController) GetAllMachineInfo() {
  1041. page, _ := this.GetInt64("page")
  1042. fmt.Println("page是什么", page)
  1043. limit, _ := this.GetInt64("limit")
  1044. fmt.Println("limit是什么", limit)
  1045. searchKey := this.GetString("searchKey")
  1046. fmt.Println("searcheKey", searchKey)
  1047. zoneid, _ := this.GetInt64("zoneid")
  1048. fmt.Println("区号id", zoneid)
  1049. equipmentid, _ := this.GetInt64("equipmentid")
  1050. fmt.Println("equipmentid", equipmentid)
  1051. statusid, _ := this.GetInt64("statusid")
  1052. fmt.Println("statusid", statusid)
  1053. adminUserInfo := this.GetAdminUserInfo()
  1054. orgid := adminUserInfo.CurrentOrgId
  1055. addmahcer, total, err := service.GetAllMachineInfo(page, limit, searchKey, zoneid, equipmentid, statusid, orgid)
  1056. //fmt.Println("err------------------------------------------------------", err)
  1057. if err != nil {
  1058. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查询设备失败")
  1059. return
  1060. }
  1061. this.ServeSuccessJSON(map[string]interface{}{
  1062. "addmahcer": addmahcer,
  1063. "total": total,
  1064. })
  1065. }
  1066. func (this *DeviceAPIController) GetAllMachine() {
  1067. adminUserInfo := this.GetAdminUserInfo()
  1068. orgid := adminUserInfo.CurrentOrgId
  1069. fmt.Println("机构id", orgid)
  1070. zoneid, _ := this.GetInt64("zoneid")
  1071. fmt.Println("zoneid", zoneid)
  1072. //number, err := service.GetZoneId(zoneid, orgid)
  1073. //classid, _ := this.GetInt64("classid")
  1074. //fmt.Println("classid", classid)
  1075. deviceid, _ := this.GetInt64("deviceid")
  1076. fmt.Println("deviceid", deviceid)
  1077. //now := time.Now()
  1078. //var week = int(now.Weekday())
  1079. //weeks := int64(week)
  1080. //fmt.Println("星期几",weeks)
  1081. timeStr := time.Now().Format("2006-01-02")
  1082. timeLayout := "2006-01-02 15:04:05"
  1083. fmt.Println("timeStr:", timeStr)
  1084. timeStringToTime, err := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  1085. timenow := timeStringToTime.Unix()
  1086. fmt.Println("timenow是什么", timenow)
  1087. fmt.Println("时间搓", timeStringToTime.Unix())
  1088. addmahcer, err := service.GetAllMachine(zoneid, 0, deviceid, timenow, orgid)
  1089. if err != nil {
  1090. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查询设备失败")
  1091. return
  1092. }
  1093. this.ServeSuccessJSON(map[string]interface{}{
  1094. "addmahcer": addmahcer,
  1095. })
  1096. }
  1097. func (this *DeviceAPIController) GetMachineDetail() {
  1098. id, _ := this.GetInt64("id")
  1099. adminUserInfo := this.GetAdminUserInfo()
  1100. orgid := adminUserInfo.CurrentOrgId
  1101. fmt.Println("orgid", orgid)
  1102. addmacher, err := service.GetMachineDetail(id, orgid)
  1103. fmt.Print("err--------------------------------------------", err)
  1104. warning, err := service.GetTimeWarning(id, orgid)
  1105. germ, err := service.GetTimeLast(id, orgid)
  1106. clean, err := service.GetTimeLastData(id, orgid)
  1107. //zone, err := service.GetZoneName(addmacher.ZoneId, orgid)
  1108. fmt.Println("报错小明", err)
  1109. number, err := service.GetAllBedNumberTwo(orgid, id)
  1110. mode, errr := service.GetTreatModel(id, orgid)
  1111. fmt.Println("mode是什么", mode)
  1112. fmt.Println("错误是什么", errr)
  1113. if err != nil {
  1114. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查询单个失败")
  1115. return
  1116. }
  1117. this.ServeSuccessJSON(map[string]interface{}{
  1118. "addmacher": addmacher,
  1119. "mode": mode,
  1120. "number": number,
  1121. "warning": warning,
  1122. "germ": germ,
  1123. "clean": clean,
  1124. //"zone": zone,
  1125. })
  1126. }
  1127. func (this *DeviceAPIController) GetAllMachineTwo() {
  1128. adminUserInfo := this.GetAdminUserInfo()
  1129. orgid := adminUserInfo.CurrentOrgId
  1130. fmt.Println("机构id", orgid)
  1131. zoneid, _ := this.GetInt64("zoneid")
  1132. fmt.Println("zoneid", zoneid)
  1133. //number, err := service.GetZoneId(zoneid, orgid)
  1134. //classid, _ := this.GetInt64("classid")
  1135. //fmt.Println("classid", classid)
  1136. deviceid, _ := this.GetInt64("deviceid")
  1137. fmt.Println("deviceid", deviceid)
  1138. //now := time.Now()
  1139. //var week = int(now.Weekday())
  1140. //weeks := int64(week)
  1141. //fmt.Println("星期几",weeks)
  1142. timeStr := time.Now().Format("2006-01-02")
  1143. timeLayout := "2006-01-02 15:04:05"
  1144. fmt.Println("timeStr:", timeStr)
  1145. timeStringToTime, err := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  1146. timenow := timeStringToTime.Unix()
  1147. fmt.Println("timenow是什么", timenow)
  1148. fmt.Println("时间搓", timeStringToTime.Unix())
  1149. addmahcer, err := service.GetAllMachine(zoneid, 0, deviceid, timenow, orgid)
  1150. if err != nil {
  1151. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查询设备失败")
  1152. return
  1153. }
  1154. this.ServeSuccessJSON(map[string]interface{}{
  1155. "addmahcer": addmahcer,
  1156. })
  1157. }