device_api_controller.go 43KB

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