device_api_controller.go 43KB

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