device_api_controller.go 44KB

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