device_api_controller.go 44KB

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