device_api_controller.go 43KB

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