device_api_controller.go 44KB

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