equipment.go 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. package equipment
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "strconv"
  6. "strings"
  7. "time"
  8. "dashoo.cn/backend/api/business/authcode"
  9. "dashoo.cn/backend/api/business/currboxcapacity"
  10. "dashoo.cn/backend/api/business/equipment"
  11. "dashoo.cn/backend/api/business/lastordernum"
  12. "dashoo.cn/backend/api/business/role"
  13. "dashoo.cn/backend/api/business/samplesinfo"
  14. "dashoo.cn/backend/api/business/shelfset"
  15. . "dashoo.cn/backend/api/controllers"
  16. "dashoo.cn/business2/permission"
  17. "dashoo.cn/utils"
  18. . "dashoo.cn/utils/db"
  19. )
  20. // 设备异常报警接口说明
  21. type EquipmentController struct {
  22. BaseController
  23. }
  24. type Equipments struct {
  25. CurrBoxCapacity []currboxcapacity.CurrBoxCapacity
  26. Equipment equipment.Equipment
  27. }
  28. type EquipmentInfo struct {
  29. Equipment equipment.EquipmentView
  30. SampleCount int
  31. ShelfCount int64
  32. BoxCount int64
  33. SensorData []SensorsShowData
  34. SensorCount int
  35. }
  36. type SensorsShowData struct {
  37. AuthCode string
  38. SensorNo string
  39. Temperature string
  40. Time time.Time
  41. }
  42. type EquipmentModel struct {
  43. Code string `json:"Code,omitempty"` // 设备编码
  44. Name string `json:"Name,omitempty"` // 设备名
  45. Brand string `json:"Brand,omitempty"` // 品牌
  46. ModelVersion string `json:"ModelVersion,omitempty"` // 型号
  47. ModelId int `json:"ModelId,omitempty"` // 型号ID
  48. RowNum int `json:"RowNum,omitempty"` // 名称
  49. ColumnNum int `json:"ColumnNum,omitempty"` // 接收日期
  50. Width string `json:"Width,omitempty"` // 可用容量
  51. Height string `json:"Height,omitempty"` // 单位(容量)
  52. Depth string `json:"Depth,omitempty"` // 有效日期
  53. TCode []string `json:"TCode,omitempty"` // 样本内码
  54. Shelf_X int `json:"shelf_x,omitempty"` // 样本来源
  55. Shelf_y int `json:"shelf_y,omitempty"` // 备注
  56. Box_X int `json:"box_x,omitempty"` // 样本来源
  57. Box_y int `json:"box_y,omitempty"` // 备注
  58. ValidityDate int64 `json:"ValidityDate,omitempty"` // 备注
  59. UseDate int64 `json:"UseDate,omitempty"` // 备注
  60. ProduceDate int64 `json:"ProduceDate,omitempty"` // 备注
  61. Checkedstr string `json:"checkedstr,omitempty"` // 样本类型
  62. Remark string `json:"Remark,omitempty"` // 位置信息
  63. DItem int `json:"DItem,omitempty"` // 设备类型19:贝尔Cryobiobank13K液氮罐;20:贝尔Cryobiobank13K_BloodBag液氮罐
  64. }
  65. // @Title 报警项目列表
  66. // @Description 报警项目列表
  67. // @Success 200 {object} business.device.DeviceChannels
  68. // @router /list [get]
  69. func (this *EquipmentController) List() {
  70. page := this.GetPageInfoForm()
  71. svc := equipment.GetEquipmentService(utils.DBE)
  72. svcPermission := permission.GetPermissionService(utils.DBE)
  73. eids := svcPermission.GetEquipmentIdById(utils.ToStr(this.User.Id))
  74. where := " a.AccCode = '" + this.User.AccCode + "'"
  75. if eids != "" {
  76. where = where + " and (a.CreateUserId= " + utils.ToStr(this.User.Id) + " or a.Id in (" + eids + "))"
  77. } else {
  78. where = where + "and a.CreateUserId= " + utils.ToStr(this.User.Id)
  79. }
  80. searchkey := this.GetString("searchkey")
  81. if searchkey != "" {
  82. where = where + " and (a.Code like '%" + searchkey + "%' or a.Name like '%" + searchkey + "%') "
  83. }
  84. total, list := svc.GetEquipmenViewtList(page.CurrentPage, page.Size, "a.Id desc", where)
  85. var equipmentsinfos []EquipmentInfo
  86. for i := 0; i < len(list); i++ {
  87. var equipmentsinfo EquipmentInfo
  88. equipmentsinfo.Equipment = list[i]
  89. //样本总数
  90. svcsample := samplesinfo.GetSamplesInfoService(utils.DBE)
  91. tblsample := this.User.AccCode + SamplesDetailtbName
  92. wheresample := " IState=1 and DeletionStateCode=0 and EquipmentId = " + utils.ToStr(list[i].Id)
  93. samplenum := svcsample.GetSampleOwnCount(tblsample, wheresample)
  94. equipmentsinfo.SampleCount = samplenum
  95. //冻存架总数
  96. whereshelf := " AccCode='" + this.User.AccCode + "' and EquipmentId = " + utils.ToStr(list[i].Id)
  97. svcshelf := shelfset.GetshelfsetService(utils.DBE)
  98. equipmentsinfo.ShelfCount = svcshelf.GetShelfCount(whereshelf)
  99. //冻存盒总数
  100. equipmentsinfo.BoxCount = svcshelf.GetBoxCount(whereshelf)
  101. //Sensor序列号
  102. var esentitylist []equipment.EquipmentSensors
  103. wheresensor := "where AccCode='" + this.User.AccCode + "' and EquipmentId=" + utils.ToStr(list[i].Id)
  104. esentitylist = svc.GetSensorsList(wheresensor)
  105. var sensorshowdatalist []SensorsShowData
  106. for j := 0; j < len(esentitylist); j++ {
  107. var sensorshowdata SensorsShowData
  108. sensorshowdata.AuthCode = esentitylist[j].AuthCode
  109. sensorshowdata.SensorNo = esentitylist[j].SensorNo
  110. sensorshowdatalist = append(sensorshowdatalist, sensorshowdata)
  111. }
  112. equipmentsinfo.SensorCount = len(esentitylist)
  113. equipmentsinfo.SensorData = sensorshowdatalist
  114. equipmentsinfos = append(equipmentsinfos, equipmentsinfo)
  115. }
  116. var datainfo DataInfo
  117. datainfo.Items = equipmentsinfos
  118. datainfo.CurrentItemCount = total
  119. this.Data["json"] = &datainfo
  120. this.ServeJSON()
  121. }
  122. // @Title 容器列表
  123. // @Description 容器列表所有容器数据
  124. // @Success 200 {object} business.device.DeviceChannels
  125. // @router /equipalllist [get]
  126. func (this *EquipmentController) EquipAllList() {
  127. svc := equipment.GetEquipmentService(utils.DBE)
  128. svcrole := role.GetRoleService(utils.DBE)
  129. roleids := svcrole.GetRoleidsByuid(utils.ToStr(this.User.Id))
  130. where := " a.AccCode = '" + this.User.AccCode + "'"
  131. where = where + " and (a.CreateUserId=" + utils.ToStr(this.User.Id) + " or a.Id in (select EquipmentId Id FROM Base_RoleEquipment where RoleId in (" + strings.Join(roleids, ",") + ")))"
  132. Name := this.GetString("Name")
  133. if Name != "" {
  134. where = where + " and Name like '%" + Name + "%' "
  135. }
  136. total, list := svc.GetEquipmenViewtList(0, 0, "a.Id desc", where)
  137. var datainfo DataInfo
  138. datainfo.Items = list
  139. datainfo.CurrentItemCount = total
  140. this.Data["json"] = &datainfo
  141. this.ServeJSON()
  142. }
  143. // @Title 名字id列表
  144. // @Description 获取设备的名字与id列表
  145. // @Success 200 {object} business.device.DeviceChannels
  146. // @router /elist [get]
  147. func (this *EquipmentController) NameIdList() {
  148. svc := equipment.GetEquipmentService(utils.DBE)
  149. svcPermission := permission.GetPermissionService(utils.DBE)
  150. eids := svcPermission.GetEquipmentIdById(utils.ToStr(this.User.Id))
  151. where := " a.AccCode = '" + this.User.AccCode + "'"
  152. if eids != "" {
  153. where = where + " and (a.CreateUserId= " + utils.ToStr(this.User.Id) + " or a.Id in (" + eids + "))"
  154. } else {
  155. where = where + "and a.CreateUserId= " + utils.ToStr(this.User.Id)
  156. }
  157. var list []string
  158. _, entities := svc.GetEquipmenViewtList(0, 0, "a.Id desc", where)
  159. for i := 0; i < len(entities); i++ {
  160. list = append(list, entities[i].Name)
  161. list = append(list, utils.ToStr(entities[i].Id))
  162. }
  163. var datainfo DataInfo
  164. datainfo.Items = list
  165. this.Data["json"] = &datainfo
  166. this.ServeJSON()
  167. }
  168. // @Title 获取品牌数据
  169. // @Description 获取品牌数据
  170. // @Success 200 {object} business.device.DeviceChannels
  171. // @router /brands [get]
  172. func (this *EquipmentController) GetBrands() {
  173. svc := equipment.GetEquipmentService(utils.DBE)
  174. // 获得所有的品牌
  175. brands := svc.GetAllBrands(this.User.AccCode)
  176. var datainfo DataInfo
  177. datainfo.Items = brands
  178. this.Data["json"] = &datainfo
  179. this.ServeJSON()
  180. }
  181. // @Title 根据品牌取型号
  182. // @Description 设备列表
  183. // @Success 200 {object} business.device.DeviceChannels
  184. // @router /dmodels/:brand [get]
  185. func (this *EquipmentController) Dmodels() {
  186. brand := this.Ctx.Input.Param(":brand")
  187. svc := equipment.GetEquipmentService(utils.DBE)
  188. // 获得所有的品牌
  189. dmodels := svc.GetModelsByBrand(brand, this.User.AccCode)
  190. var datainfo DataInfo
  191. datainfo.Items = dmodels
  192. this.Data["json"] = &datainfo
  193. this.ServeJSON()
  194. }
  195. // @Title 报警器列表
  196. // @Description 设备列表
  197. // @Success 200 {object} business.device.DeviceChannels
  198. // @router /photo/:id [get]
  199. func (this *EquipmentController) GetPhoto() {
  200. id := this.Ctx.Input.Param(":id")
  201. svc := equipment.GetEquipmentService(utils.DBE)
  202. // 获得对应型号的照片数据
  203. var entity equipment.EquipMentModel
  204. where := "DModel='" + id + "'"
  205. svc.GetEntity(&entity, where)
  206. var datainfo DataInfo
  207. realArr := [2]string{entity.Photo, entity.SpareData}
  208. datainfo.Items = realArr
  209. this.Data["json"] = &datainfo
  210. this.ServeJSON()
  211. }
  212. // @Title 根据型号获取设备信息
  213. // @Description 根据型号获取设备信息
  214. // @Success 200 {object} business.device.DeviceChannels
  215. // @router /getbydmodel/:dmodel [get]
  216. func (this *EquipmentController) GetBydModel() {
  217. dmodel := this.Ctx.Input.Param(":dmodel")
  218. svc := equipment.GetEquipmentService(utils.DBE)
  219. var entity equipment.EquipMentModel
  220. where := "Id='" + dmodel + "'"
  221. svc.GetEntity(&entity, where)
  222. this.Data["json"] = &entity
  223. this.ServeJSON()
  224. }
  225. // @Title 根据Id获取设备信息
  226. // @Description 根据型号获取设备信息
  227. // @Success 200 {object} business.device.DeviceChannels
  228. // @router /getmodel/:id [get]
  229. func (this *EquipmentController) GetModel() {
  230. id := this.Ctx.Input.Param(":id")
  231. svc := equipment.GetEquipmentService(utils.DBE)
  232. entity := svc.GetEquipmentViewById(id)
  233. this.Data["json"] = &entity
  234. this.ServeJSON()
  235. }
  236. // @Title 根据ID判断是否有冻存架使用
  237. // @Description 根据ID判断是否有冻存架使用
  238. // @Success 200 {object} business.device.DeviceChannels
  239. // @router /getisusedbyshelf/:id [get]
  240. func (this *EquipmentController) GetisUsedByShelf() {
  241. id := this.Ctx.Input.Param(":id")
  242. var shelf shelfset.Shelf
  243. svcshelf := shelfset.GetshelfsetService(utils.DBE)
  244. has := svcshelf.GetShelfByEquipment(id, &shelf)
  245. var errinfo ErrorInfo
  246. if has {
  247. errinfo.Code = 0
  248. errinfo.Message = "有冻存架"
  249. } else {
  250. errinfo.Code = -1
  251. errinfo.Message = "无冻存架"
  252. }
  253. this.Data["json"] = &errinfo
  254. this.ServeJSON()
  255. }
  256. // @Title 创建报警项目
  257. // @Description 创建报警项目
  258. // @Param body body business.device.DeviceChannels "报警项目信息"
  259. // @Success 200 {object} controllers.Request
  260. // @router /editequip/:id [put]
  261. func (this *EquipmentController) EditEquipment() {
  262. id := this.Ctx.Input.Param(":id")
  263. // 获得前端传输的model
  264. var model EquipmentModel
  265. var jsonblob = this.Ctx.Input.RequestBody
  266. json.Unmarshal(jsonblob, &model)
  267. //赋值
  268. var equip equipment.Equipment
  269. equip.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  270. equip.ModifiedBy = this.User.Realname
  271. equip.Remark = model.Remark
  272. equip.Code = model.Code
  273. equip.ModelId = model.ModelId
  274. equip.Name = model.Name
  275. equip.Brand = model.Brand
  276. equip.ModelVersion = model.ModelVersion
  277. equip.Item = 1 // 立式 取消了这项选择
  278. equip.RowNum = model.RowNum
  279. equip.ColumnNum = model.ColumnNum
  280. equip.Width, _ = utils.StrTo(model.Width).Float32()
  281. equip.Height, _ = utils.StrTo(model.Height).Float32()
  282. equip.Depth, _ = utils.StrTo(model.Depth).Float32()
  283. equip.SampleType = model.Checkedstr
  284. equip.ProduceDate = time.Unix(model.ProduceDate/1000, 0)
  285. equip.UseDate = time.Unix(model.UseDate/1000, 0)
  286. equip.ValidityDate = time.Unix(model.ValidityDate/1000, 0)
  287. // 初始化服务
  288. var errinfo ErrorInfo
  289. var equipempty equipment.Equipment
  290. svc := equipment.GetEquipmentService(utils.DBE)
  291. // 处理数据, 保存设备
  292. var cols []string = []string{"ModelId", "ModifiedUserId", "ModifiedBy", "Remark", "Code", "Name", "Brand", "ModelVersion", "Item", "RowNum", "ColumnNum", "Width", "Height", "Depth", "SampleType", "ProduceDate", "UseDate", "ValidityDate"}
  293. opdesc := "修改设备-" + equip.Name
  294. err := svc.UpdateEntityAndWriteLog(id, &equip, &equipempty, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "设备管理")
  295. //删除Sensors
  296. wheresensor := " where AccCode='" + this.User.AccCode + "' and EquipmentId=" + id
  297. svc.DeleteSensors(wheresensor)
  298. //添加Sensors
  299. //添加Sensors
  300. if len(model.TCode) > 0 {
  301. sensorsinfoarr := model.TCode
  302. for i := 0; i < len(sensorsinfoarr); i++ {
  303. // sensordata := strings.Split(sensorsinfoarr[i], ";")
  304. var esentity equipment.EquipmentSensors
  305. esentity.AccCode = this.User.AccCode
  306. esentity.EquipmentId, _ = utils.StrTo(id).Int()
  307. // 授权码暂时取消
  308. // esentity.AuthCode = sensordata[0]
  309. esentity.SensorNo = sensorsinfoarr[i]
  310. esentity.CreateBy = this.User.Realname
  311. esentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  312. _, _ = svc.InsertEntity(&esentity)
  313. }
  314. }
  315. // 错误检测
  316. if err != nil {
  317. errinfo.Message = "编辑设备失败!"
  318. errinfo.Code = -1
  319. this.Data["json"] = &errinfo
  320. this.ServeJSON()
  321. return
  322. } else {
  323. errinfo.Message = "编辑设备成功!"
  324. errinfo.Code = 0
  325. this.Data["json"] = &errinfo
  326. this.ServeJSON()
  327. return
  328. }
  329. }
  330. // @Title 复制所选设备
  331. // @Description 复制所选设备
  332. // @Param body body business.device.DeviceChannels "报警项目信息"
  333. // @Success 200 {object} controllers.Request
  334. // @router /copyequip/:id [put]
  335. func (this *EquipmentController) CopyEquipment() {
  336. id := this.Ctx.Input.Param(":id")
  337. var entity equipment.Equipment
  338. svc := equipment.GetEquipmentService(utils.DBE)
  339. svc.GetEntityById(id, &entity)
  340. entity.Id = 0
  341. entity.Name = entity.Name + utils.ToStr(time.Now())[7:19]
  342. entity.Code = entity.Code + utils.ToStr(time.Now())[7:19]
  343. entity.HCode = ""
  344. entity.ModifiedUserId = 0
  345. entity.ModifiedBy = ""
  346. entity.CreateBy = this.User.Realname
  347. entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  348. _, err := svc.InsertEntity(&entity)
  349. new_id := entity.Id
  350. var shelf_list []shelfset.Shelf
  351. where := "EquipmentId=" + id
  352. svc.GetEntities(&shelf_list, where)
  353. svcshelf := shelfset.GetshelfsetService(utils.DBE)
  354. lastdata := svcshelf.GetLastShelfNum(this.User.AccCode)
  355. num_lastdata, _ := utils.StrTo(lastdata[1:]).Int64()
  356. for i := 0; i < len(shelf_list); i++ {
  357. old_shelf_id := shelf_list[i].Id
  358. shelf_list[i].Id = 0
  359. shelf_list[i].Code = "F" + utils.ToStr(num_lastdata)
  360. shelf_list[i].BarCode = "F" + utils.ToStr(num_lastdata)
  361. shelf_list[i].EquipmentId = new_id
  362. shelf_list[i].ModifiedBy = ""
  363. shelf_list[i].ModifiedUserId = 0
  364. shelf_list[i].CreateBy = this.User.Realname
  365. shelf_list[i].CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  366. num_lastdata = num_lastdata + 1
  367. _, err = svc.InsertEntity(&shelf_list[i])
  368. new_shelf_id := shelf_list[i].Id
  369. var box_list []shelfset.Box
  370. where1 := "EquipmentId=" + id + " and ShelfId=" + utils.ToStr(old_shelf_id)
  371. svc.GetEntities(&box_list, where1)
  372. lastdata_box := svcshelf.GetLastBoxNum(this.User.AccCode)
  373. num_lastdata_box, _ := utils.StrTo(lastdata_box[1:]).Int64()
  374. for j := 0; j < len(box_list); j++ {
  375. box_list[j].Id = 0
  376. box_list[j].Code = "B" + utils.ToStr(num_lastdata_box)
  377. box_list[j].BarCode = "B" + utils.ToStr(num_lastdata_box)
  378. box_list[j].EquipmentId = new_id
  379. box_list[j].ShelfId = new_shelf_id
  380. box_list[j].ModifiedBy = ""
  381. box_list[j].ModifiedUserId = 0
  382. box_list[j].CreateBy = this.User.Realname
  383. box_list[j].CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  384. num_lastdata_box = num_lastdata_box + 1
  385. _, err = svc.InsertEntity(&box_list[j])
  386. }
  387. num_lastdata_box = num_lastdata_box - 1
  388. var lastnum lastordernum.LastOrderNum
  389. lastnum.LastNum = "B" + utils.ToStr(num_lastdata_box)
  390. svcshelf.UpdateBoxNum(lastnum, this.User.AccCode)
  391. var currboxcapacitys currboxcapacity.CurrBoxCapacity
  392. svc.GetEntity(&currboxcapacitys, where1)
  393. currboxcapacitys.Id = 0
  394. currboxcapacitys.EquipmentId = new_id
  395. currboxcapacitys.ShelfId = new_shelf_id
  396. _, err = svc.InsertEntity(&currboxcapacitys)
  397. }
  398. num_lastdata = num_lastdata - 1
  399. var lastnum_shelf lastordernum.LastOrderNum
  400. lastnum_shelf.LastNum = "F" + utils.ToStr(num_lastdata)
  401. svcshelf.UpdateShelfNum(lastnum_shelf, this.User.AccCode)
  402. var errinfo ErrorInfo
  403. // 错误检测
  404. if err != nil {
  405. errinfo.Message = "复制设备失败!"
  406. errinfo.Code = -1
  407. this.Data["json"] = &errinfo
  408. this.ServeJSON()
  409. return
  410. } else {
  411. errinfo.Message = "复制设备成功!"
  412. errinfo.Code = 0
  413. this.Data["json"] = &errinfo
  414. this.ServeJSON()
  415. return
  416. }
  417. }
  418. // @Title 创建容器设备数据
  419. // @Description 创建容器设备数据
  420. // @Param body body business.device.DeviceChannels "报警项目信息"
  421. // @Success 200 {object} controllers.Request
  422. // @router / [post]
  423. func (this *EquipmentController) AddEquipment() {
  424. // 获得前端传输的model
  425. var model EquipmentModel
  426. var jsonblob = this.Ctx.Input.RequestBody
  427. json.Unmarshal(jsonblob, &model)
  428. //赋值
  429. var equip equipment.Equipment
  430. equip.AccCode = this.User.AccCode
  431. equip.Code = model.Code
  432. equip.ModelId = model.ModelId
  433. equip.Name = model.Name
  434. equip.Brand = model.Brand
  435. equip.ModelVersion = model.ModelVersion
  436. equip.Item = 1 // 立式 取消了这项选择
  437. equip.RowNum = model.RowNum
  438. equip.ColumnNum = model.ColumnNum
  439. equip.Width, _ = utils.StrTo(model.Width).Float32()
  440. equip.Height, _ = utils.StrTo(model.Height).Float32()
  441. equip.Depth, _ = utils.StrTo(model.Depth).Float32()
  442. equip.SampleType = model.Checkedstr
  443. equip.State = 1 //默认启用
  444. equip.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  445. equip.CreateBy = this.User.Realname
  446. equip.Remark = model.Remark
  447. equip.ProduceDate = time.Unix(model.ProduceDate/1000, 0)
  448. equip.UseDate = time.Unix(model.UseDate/1000, 0)
  449. equip.ValidityDate = time.Unix(model.ValidityDate/1000, 0)
  450. //添加设备
  451. svc := equipment.GetEquipmentService(utils.DBE)
  452. _, err := svc.InsertEntity(&equip)
  453. var errinfo ErrorInfo
  454. if err != nil {
  455. errinfo.Message = "添加设备失败!" + err.Error()
  456. errinfo.Code = -2
  457. this.Data["json"] = &errinfo
  458. this.ServeJSON()
  459. return
  460. }
  461. //同步添加冻存架
  462. // 19:贝尔Cryobiobank13K液氮罐;20:贝尔Cryobiobank13K_BloodBag液氮罐
  463. if model.DItem == 19 {
  464. shelf_x_int := 1
  465. shelf_y_int := 1
  466. box_x_int := 1
  467. box_y_int := 1
  468. svcshelf := shelfset.GetshelfsetService(utils.DBE)
  469. lastdata := svcshelf.GetLastShelfNum(this.User.AccCode)
  470. num_lastdata, _ := utils.StrTo(lastdata[1:]).Int64()
  471. lastdata_box := svcshelf.GetLastBoxNum(this.User.AccCode)
  472. num_lastdata_box, _ := utils.StrTo(lastdata_box[1:]).Int64()
  473. for i := 1; i <= equip.RowNum; i++ {
  474. for j := 1; j <= equip.ColumnNum; j++ {
  475. if j == 4 { //第4个为小型格4行5x5冻存盒
  476. shelf_x_int = 1
  477. shelf_y_int = 10
  478. box_x_int = 5
  479. box_y_int = 5
  480. } else { //其他为大型格12行10x10冻存盒
  481. shelf_x_int = 1
  482. shelf_y_int = 10
  483. box_x_int = 10
  484. box_y_int = 10
  485. }
  486. var shelfempty shelfset.Shelf
  487. shelfempty.AccCode = this.User.AccCode
  488. shelfempty.EquipmentId = equip.Id
  489. shelfempty.Code = "F" + utils.ToStr(num_lastdata)
  490. shelfempty.BarCode = "F" + utils.ToStr(num_lastdata)
  491. shelfempty.RowNum = shelf_x_int
  492. shelfempty.ColumnNum = shelf_y_int
  493. shelfempty.XStation = j
  494. shelfempty.YStation = i
  495. shelfempty.SampleType = equip.SampleType
  496. shelfempty.CreateBy = this.User.Realname
  497. shelfempty.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  498. num_lastdata = num_lastdata + 1
  499. _, err = svcshelf.InsertEntity(&shelfempty)
  500. sqlfield := " AccCode,EquipmentId,ShelfId,XStation,YStation,RowNum,ColumnNum,"
  501. sqlvalue := "'" + this.User.AccCode + "'," + utils.ToStr(equip.Id) + "," + utils.ToStr(shelfempty.Id) + "," + utils.ToStr(j) + "," + utils.ToStr(i) + "," + utils.ToStr(shelf_x_int) + "," + utils.ToStr(shelf_y_int) + ","
  502. ii, jj := shelf_x_int, shelf_y_int
  503. //添加冻存盒
  504. if box_x_int > 0 && box_y_int > 0 {
  505. for e := 0; e < ii; e++ {
  506. charname := Boxlinename(e + 1)
  507. for f := 0; f < jj; f++ {
  508. fieldname := fmt.Sprintf("%v%v", charname, f+1)
  509. if f == jj-1 && e == ii-1 {
  510. sqlfield += fieldname
  511. sqlvalue += "-1"
  512. } else {
  513. sqlfield += fieldname + ","
  514. sqlvalue += "-1,"
  515. }
  516. }
  517. }
  518. for a := 1; a <= shelf_x_int; a++ {
  519. for b := 1; b <= shelf_y_int; b++ {
  520. var boxempty shelfset.Box
  521. boxempty.AccCode = this.User.AccCode
  522. boxempty.EquipmentId = equip.Id
  523. boxempty.ShelfId = shelfempty.Id
  524. boxempty.Code = "B" + utils.ToStr(num_lastdata_box)
  525. boxempty.BarCode = "B" + utils.ToStr(num_lastdata_box)
  526. boxempty.YStation = a
  527. boxempty.XStation = b
  528. boxempty.RowNum = box_x_int
  529. boxempty.ColumnNum = box_y_int
  530. boxempty.SampleType = equip.SampleType
  531. boxempty.CreateBy = this.User.Realname
  532. boxempty.CreateBy = this.User.Realname
  533. num_lastdata_box = num_lastdata_box + 1
  534. _, err = svc.InsertEntity(&boxempty)
  535. }
  536. }
  537. } else {
  538. for e := 0; e < ii; e++ {
  539. charname := Boxlinename(e + 1)
  540. for f := 0; f < jj; f++ {
  541. fieldname := fmt.Sprintf("%v%v", charname, f+1)
  542. if f == jj-1 && e == ii-1 {
  543. sqlfield += fieldname
  544. sqlvalue += "-2"
  545. } else {
  546. sqlfield += fieldname + ","
  547. sqlvalue += "-2,"
  548. }
  549. }
  550. }
  551. }
  552. svc1 := currboxcapacity.GetCurrboxcapacityService(utils.DBE)
  553. svc1.Add(sqlfield, sqlvalue)
  554. }
  555. }
  556. num_lastdata_box = num_lastdata_box - 1
  557. var lastnum lastordernum.LastOrderNum
  558. lastnum.LastNum = "B" + utils.ToStr(num_lastdata_box)
  559. svcshelf.UpdateBoxNum(lastnum, this.User.AccCode)
  560. num_lastdata = num_lastdata - 1
  561. var lastnum_shelf lastordernum.LastOrderNum
  562. lastnum_shelf.LastNum = "F" + utils.ToStr(num_lastdata)
  563. svcshelf.UpdateShelfNum(lastnum_shelf, this.User.AccCode)
  564. } else if model.DItem == 20 {
  565. shelf_x_int := 1
  566. shelf_y_int := 6
  567. box_x_int := 1
  568. box_y_int := 1
  569. svcshelf := shelfset.GetshelfsetService(utils.DBE)
  570. lastdata := svcshelf.GetLastShelfNum(this.User.AccCode)
  571. num_lastdata, _ := utils.StrTo(lastdata[1:]).Int64()
  572. lastdata_box := svcshelf.GetLastBoxNum(this.User.AccCode)
  573. num_lastdata_box, _ := utils.StrTo(lastdata_box[1:]).Int64()
  574. for i := 1; i <= equip.RowNum; i++ {
  575. for j := 1; j <= equip.ColumnNum; j++ {
  576. var shelfempty shelfset.Shelf
  577. shelfempty.AccCode = this.User.AccCode
  578. shelfempty.EquipmentId = equip.Id
  579. shelfempty.Code = "F" + utils.ToStr(num_lastdata)
  580. shelfempty.BarCode = "F" + utils.ToStr(num_lastdata)
  581. shelfempty.RowNum = shelf_x_int
  582. shelfempty.ColumnNum = shelf_y_int
  583. shelfempty.XStation = j
  584. shelfempty.YStation = i
  585. shelfempty.SampleType = equip.SampleType
  586. shelfempty.CreateBy = this.User.Realname
  587. shelfempty.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  588. num_lastdata = num_lastdata + 1
  589. _, err = svcshelf.InsertEntity(&shelfempty)
  590. sqlfield := " AccCode,EquipmentId,ShelfId,XStation,YStation,RowNum,ColumnNum,"
  591. sqlvalue := "'" + this.User.AccCode + "'," + utils.ToStr(equip.Id) + "," + utils.ToStr(shelfempty.Id) + "," + utils.ToStr(j) + "," + utils.ToStr(i) + "," + utils.ToStr(shelf_x_int) + "," + utils.ToStr(shelf_y_int) + ","
  592. ii, jj := shelf_x_int, shelf_y_int
  593. //添加冻存盒
  594. if box_x_int > 0 && box_y_int > 0 {
  595. for e := 0; e < ii; e++ {
  596. charname := Boxlinename(e + 1)
  597. for f := 0; f < jj; f++ {
  598. fieldname := fmt.Sprintf("%v%v", charname, f+1)
  599. if f == jj-1 && e == ii-1 {
  600. sqlfield += fieldname
  601. sqlvalue += "-1"
  602. } else {
  603. sqlfield += fieldname + ","
  604. sqlvalue += "-1,"
  605. }
  606. }
  607. }
  608. for a := 1; a <= shelf_x_int; a++ {
  609. for b := 1; b <= shelf_y_int; b++ {
  610. var boxempty shelfset.Box
  611. boxempty.AccCode = this.User.AccCode
  612. boxempty.EquipmentId = equip.Id
  613. boxempty.ShelfId = shelfempty.Id
  614. boxempty.Code = "B" + utils.ToStr(num_lastdata_box)
  615. boxempty.BarCode = "B" + utils.ToStr(num_lastdata_box)
  616. boxempty.YStation = a
  617. boxempty.XStation = b
  618. boxempty.RowNum = box_x_int
  619. boxempty.ColumnNum = box_y_int
  620. boxempty.SampleType = equip.SampleType
  621. boxempty.CreateBy = this.User.Realname
  622. boxempty.CreateBy = this.User.Realname
  623. num_lastdata_box = num_lastdata_box + 1
  624. _, err = svc.InsertEntity(&boxempty)
  625. }
  626. }
  627. } else {
  628. for e := 0; e < ii; e++ {
  629. charname := Boxlinename(e + 1)
  630. for f := 0; f < jj; f++ {
  631. fieldname := fmt.Sprintf("%v%v", charname, f+1)
  632. if f == jj-1 && e == ii-1 {
  633. sqlfield += fieldname
  634. sqlvalue += "-2"
  635. } else {
  636. sqlfield += fieldname + ","
  637. sqlvalue += "-2,"
  638. }
  639. }
  640. }
  641. }
  642. svc1 := currboxcapacity.GetCurrboxcapacityService(utils.DBE)
  643. svc1.Add(sqlfield, sqlvalue)
  644. }
  645. }
  646. num_lastdata_box = num_lastdata_box - 1
  647. var lastnum lastordernum.LastOrderNum
  648. lastnum.LastNum = "B" + utils.ToStr(num_lastdata_box)
  649. svcshelf.UpdateBoxNum(lastnum, this.User.AccCode)
  650. num_lastdata = num_lastdata - 1
  651. var lastnum_shelf lastordernum.LastOrderNum
  652. lastnum_shelf.LastNum = "F" + utils.ToStr(num_lastdata)
  653. svcshelf.UpdateShelfNum(lastnum_shelf, this.User.AccCode)
  654. } else {
  655. if model.Shelf_X > 0 && model.Shelf_y > 0 {
  656. shelf_x_int := model.Shelf_X
  657. shelf_y_int := model.Shelf_y
  658. box_x_int := model.Box_X
  659. box_y_int := model.Box_y
  660. svcshelf := shelfset.GetshelfsetService(utils.DBE)
  661. lastdata := svcshelf.GetLastShelfNum(this.User.AccCode)
  662. num_lastdata, _ := utils.StrTo(lastdata[1:]).Int64()
  663. lastdata_box := svcshelf.GetLastBoxNum(this.User.AccCode)
  664. num_lastdata_box, _ := utils.StrTo(lastdata_box[1:]).Int64()
  665. for i := 1; i <= equip.RowNum; i++ {
  666. for j := 1; j <= equip.ColumnNum; j++ {
  667. var shelfempty shelfset.Shelf
  668. shelfempty.AccCode = this.User.AccCode
  669. shelfempty.EquipmentId = equip.Id
  670. shelfempty.Code = "F" + utils.ToStr(num_lastdata)
  671. shelfempty.BarCode = "F" + utils.ToStr(num_lastdata)
  672. shelfempty.RowNum = shelf_x_int
  673. shelfempty.ColumnNum = shelf_y_int
  674. shelfempty.XStation = j
  675. shelfempty.YStation = i
  676. shelfempty.SampleType = equip.SampleType
  677. shelfempty.CreateBy = this.User.Realname
  678. shelfempty.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  679. num_lastdata = num_lastdata + 1
  680. _, err = svcshelf.InsertEntity(&shelfempty)
  681. sqlfield := " AccCode,EquipmentId,ShelfId,XStation,YStation,RowNum,ColumnNum,"
  682. sqlvalue := "'" + this.User.AccCode + "'," + utils.ToStr(equip.Id) + "," + utils.ToStr(shelfempty.Id) + "," + utils.ToStr(j) + "," + utils.ToStr(i) + "," + utils.ToStr(shelf_x_int) + "," + utils.ToStr(shelf_y_int) + ","
  683. ii, jj := shelf_x_int, shelf_y_int
  684. //添加冻存盒
  685. if box_x_int > 0 && box_y_int > 0 {
  686. for e := 0; e < ii; e++ {
  687. charname := Boxlinename(e + 1)
  688. for f := 0; f < jj; f++ {
  689. fieldname := fmt.Sprintf("%v%v", charname, f+1)
  690. if f == jj-1 && e == ii-1 {
  691. sqlfield += fieldname
  692. sqlvalue += "-1"
  693. } else {
  694. sqlfield += fieldname + ","
  695. sqlvalue += "-1,"
  696. }
  697. }
  698. }
  699. for a := 1; a <= shelf_x_int; a++ {
  700. for b := 1; b <= shelf_y_int; b++ {
  701. var boxempty shelfset.Box
  702. boxempty.AccCode = this.User.AccCode
  703. boxempty.EquipmentId = equip.Id
  704. boxempty.ShelfId = shelfempty.Id
  705. boxempty.Code = "B" + utils.ToStr(num_lastdata_box)
  706. boxempty.BarCode = "B" + utils.ToStr(num_lastdata_box)
  707. boxempty.YStation = a
  708. boxempty.XStation = b
  709. boxempty.RowNum = box_x_int
  710. boxempty.ColumnNum = box_y_int
  711. boxempty.SampleType = equip.SampleType
  712. boxempty.CreateBy = this.User.Realname
  713. boxempty.CreateBy = this.User.Realname
  714. num_lastdata_box = num_lastdata_box + 1
  715. _, err = svc.InsertEntity(&boxempty)
  716. }
  717. }
  718. } else {
  719. for e := 0; e < ii; e++ {
  720. charname := Boxlinename(e + 1)
  721. for f := 0; f < jj; f++ {
  722. fieldname := fmt.Sprintf("%v%v", charname, f+1)
  723. if f == jj-1 && e == ii-1 {
  724. sqlfield += fieldname
  725. sqlvalue += "-2"
  726. } else {
  727. sqlfield += fieldname + ","
  728. sqlvalue += "-2,"
  729. }
  730. }
  731. }
  732. }
  733. svc1 := currboxcapacity.GetCurrboxcapacityService(utils.DBE)
  734. svc1.Add(sqlfield, sqlvalue)
  735. }
  736. }
  737. num_lastdata_box = num_lastdata_box - 1
  738. var lastnum lastordernum.LastOrderNum
  739. lastnum.LastNum = "B" + utils.ToStr(num_lastdata_box)
  740. svcshelf.UpdateBoxNum(lastnum, this.User.AccCode)
  741. num_lastdata = num_lastdata - 1
  742. var lastnum_shelf lastordernum.LastOrderNum
  743. lastnum_shelf.LastNum = "F" + utils.ToStr(num_lastdata)
  744. svcshelf.UpdateShelfNum(lastnum_shelf, this.User.AccCode)
  745. }
  746. }
  747. //添加Sensors
  748. if len(model.TCode) > 0 {
  749. sensorsinfoarr := model.TCode
  750. for i := 0; i < len(sensorsinfoarr); i++ {
  751. // sensordata := strings.Split(sensorsinfoarr[i], ";")
  752. var esentity equipment.EquipmentSensors
  753. esentity.AccCode = this.User.AccCode
  754. esentity.EquipmentId = equip.Id
  755. // 授权码暂时取消
  756. // esentity.AuthCode = sensordata[0]
  757. esentity.SensorNo = sensorsinfoarr[i]
  758. esentity.CreateBy = this.User.Realname
  759. esentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  760. _, _ = svc.InsertEntity(&esentity)
  761. }
  762. }
  763. errinfo.Message = "添加设备成功!"
  764. errinfo.Code = 0
  765. this.Data["json"] = &errinfo
  766. this.ServeJSON()
  767. }
  768. // @Title 删除容器设备
  769. // @Description 删除容器设备
  770. // @Param code path string true "需要删除的传感器编号"
  771. // @Success 200 {object} ErrorInfo
  772. // @Failure 403 :id 为空
  773. // @router delequip/:id [delete]
  774. func (this *EquipmentController) EquipmentDelete() {
  775. id := this.Ctx.Input.Param(":id")
  776. name := this.GetString("name")
  777. var entity equipment.Equipment
  778. var entityempty equipment.Equipment
  779. svc := equipment.GetEquipmentService(utils.DBE)
  780. opdesc := "删除设备-" + name
  781. err := svc.DeleteEntityAndWriteLog(id, &entity, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "设备管理")
  782. //删除样本
  783. svc1 := shelfset.GetshelfsetService(utils.DBE)
  784. where_shelf := "EquipmentId =" + id
  785. var shelfempty shelfset.Shelf
  786. svc1.DeleteEntity(&shelfempty, where_shelf)
  787. var currboxcapacitys currboxcapacity.CurrBoxCapacity
  788. svc1.DeleteEntity(&currboxcapacitys, where_shelf)
  789. var boxempty shelfset.Box
  790. svc1.DeleteEntity(&boxempty, where_shelf)
  791. //删除Sensors
  792. wheresensor := "where AccCode='" + this.User.AccCode + "' and EquipmentId=" + id
  793. svc.DeleteSensors(wheresensor)
  794. var errinfo ErrorInfo
  795. // 错误检测
  796. if err != nil {
  797. errinfo.Message = "删除设备失败!"
  798. errinfo.Code = -1
  799. this.Data["json"] = &errinfo
  800. this.ServeJSON()
  801. return
  802. } else {
  803. errinfo.Message = "删除设备成功!"
  804. errinfo.Code = 0
  805. this.Data["json"] = &errinfo
  806. this.ServeJSON()
  807. }
  808. }
  809. // @Title 更新所有冻存盒颜色值
  810. // @Description 更新所有冻存盒颜色值
  811. // @Param code path string true "需要删除的传感器编号"
  812. // @Success 200 {object} ErrorInfo
  813. // @Failure 403 :id 为空
  814. // @router /refresh [put]
  815. func (this *EquipmentController) RefreshCapacity() {
  816. s := currboxcapacity.GetCurrboxcapacityService(utils.DBE)
  817. var acccodes []Id_Str //账户AccCode列表
  818. curracccode := this.User.AccCode
  819. if curracccode == "" {
  820. sqltables := "select distinct AccCode Id from Equipment "
  821. s.DBE.Sql(sqltables).Find(&acccodes)
  822. } else { //账户内部刷新
  823. acccodes = append(acccodes, Id_Str{curracccode})
  824. }
  825. var tablename string //表名
  826. var boxdata []samplesinfo.SampleBoxCount
  827. for _, v := range acccodes {
  828. tablename = string(v.Id) + "SamplesDetail" //样本表名
  829. var fieldname, updatesql string
  830. whereshelf := " where AccCode = '" + v.Id + "'"
  831. var shelflist []shelfset.Shelf
  832. shelflist = s.GetShelfList(whereshelf) //获取冻存架列表
  833. for si := 0; si < len(shelflist); si++ { //循环遍历冻存架,去样本库中查找样本
  834. fieldStr := " UpdateTime= now() "
  835. updateStr := " UpdateTime= now() "
  836. //先将所有的状态置成-1//////////////////////////开始/////////////////////////////////
  837. var boxlist []shelfset.Box
  838. boxlist = s.GetBoxByShelfId(utils.ToStr(shelflist[si].Id))
  839. boxlistcount := len(boxlist)
  840. for bi := 0; bi < boxlistcount; bi++ {
  841. updatename := Boxlinename(boxlist[bi].YStation) + utils.ToStr(boxlist[bi].XStation)
  842. updateStr = updateStr + ","
  843. updateStr = updateStr + updatename + "= -1"
  844. }
  845. if updateStr != "" {
  846. updatesql = " update CurrBoxCapacity set " + updateStr + " where ShelfId = " + utils.ToStr(shelflist[si].Id)
  847. fmt.Println(updatesql)
  848. _, err := s.DBE.Exec(updatesql)
  849. LogError(err)
  850. }
  851. //先将所有的状态置成-1//////////////////////////结束/////////////////////////////////
  852. //更改冻存盒的实际状态////////////////////开始//////////////////////////////////////
  853. boxwhere := " where IState=1 and DeletionStateCode = 0 and ShelfId =" + utils.ToStr(shelflist[si].Id) + ""
  854. svc := samplesinfo.GetSamplesInfoService(utils.DBE)
  855. boxdata = svc.QuerySampleBoxDataList(tablename, boxwhere) //一个冻存盒Id是一条数据
  856. if len(boxdata) > 0 {
  857. for i := 0; i < len(boxdata); i++ {
  858. box := new(shelfset.Box)
  859. s.GetBoxById(utils.ToStr(boxdata[i].BoxId), box)
  860. if box.Id == 0 { //如果找不到冻存盒
  861. continue
  862. } else {
  863. fieldStr = fieldStr + ","
  864. boxdata[i].AllCount = int(box.RowNum * box.ColumnNum)
  865. crate := float64(boxdata[i].CurrCount) / float64(boxdata[i].AllCount) * 100
  866. c_str := strconv.FormatFloat(crate, 'f', 2, 64)
  867. c_f64, _ := strconv.ParseFloat(c_str, 64)
  868. boxdata[i].CurrRate = c_f64
  869. fieldname = Boxlinename(box.YStation) + utils.ToStr(box.XStation)
  870. }
  871. fieldStr = fieldStr + fieldname + "=" + utils.ToStr(boxdata[i].CurrRate)
  872. }
  873. if fieldStr != "" {
  874. updatesql = " update CurrBoxCapacity set " + fieldStr + " where ShelfId = " + utils.ToStr(shelflist[si].Id)
  875. fmt.Println(updatesql)
  876. _, err := s.DBE.Exec(updatesql)
  877. LogError(err)
  878. }
  879. }
  880. //更改冻存盒的实际状态//////////////////////结束////////////////////////////////////
  881. }
  882. }
  883. }
  884. // @Title 获取传感器列表
  885. // @Description 获取传感器列表
  886. // @Success 200 {object} business.device.DeviceChannels
  887. // @router /getsensorslist [get]
  888. func (this *EquipmentController) GetSensorsList() {
  889. svcauthcode := authcode.GetAuthCodeService(utils.DBE)
  890. var aclist []authcode.AuthCode
  891. whereac := " AccCode='" + this.User.AccCode + "'"
  892. aclist = svcauthcode.GetList(" Id desc limit 1 ", whereac)
  893. keystr := ""
  894. if len(aclist) > 0 {
  895. keystr = aclist[0].AuthCode
  896. }
  897. ////支持多个授权码
  898. // for i := 0; i < len(aclist); i++ {
  899. // if ki == len(aclist)-1 {
  900. // keystr = keystr + "'" + aclist[i].AuthCode + "'"
  901. // } else {
  902. // keystr = keystr + "'" + aclist[i].AuthCode + "'" + ","
  903. // }
  904. // }
  905. //调接口获取sensors
  906. var ccsensor []equipment.CCSensor
  907. if keystr != "" {
  908. strUrlwaring := utils.Cfg.MustValue("server", "dataapiurl") + "/channels/channels"
  909. json.Unmarshal(ApiKeyRequest(strUrlwaring, "GET", keystr, nil), &ccsensor)
  910. }
  911. var datainfo DataInfo
  912. datainfo.Items = ccsensor
  913. this.Data["json"] = &datainfo
  914. this.ServeJSON()
  915. }
  916. // @Title 验证传感器编号是否有权限
  917. // @Description 获取传感器列表
  918. // @Success 200 {object} business.device.DeviceChannels
  919. // @router /validsensorsispermi [get]
  920. func (this *EquipmentController) ValidsensorsisPermi() {
  921. svcauthcode := authcode.GetAuthCodeService(utils.DBE)
  922. var aclist []authcode.AuthCode
  923. whereac := " AccCode='" + this.User.AccCode + "'"
  924. aclist = svcauthcode.GetList(" Id desc limit 1 ", whereac)
  925. var errinfo ErrorInfo
  926. if len(aclist) == 0 {
  927. errinfo.Message = "请先设置授权码"
  928. errinfo.Code = -2
  929. this.Data["json"] = &errinfo
  930. this.ServeJSON()
  931. return
  932. }
  933. keystr := aclist[0].AuthCode
  934. sensors := this.GetString("sensors")
  935. sensorarr := strings.Split(sensors, ",")
  936. //调接口获取sensors
  937. var ccsensor []equipment.CCSensor
  938. if keystr != "" {
  939. strUrlwaring := utils.Cfg.MustValue("server", "dataapiurl") + "/channels/channels"
  940. json.Unmarshal(ApiKeyRequest(strUrlwaring, "GET", keystr, nil), &ccsensor)
  941. }
  942. isok := false //是否通过验证
  943. nohavesensor := "" // 不存在的sensor
  944. for si := 0; si < len(sensorarr); si++ {
  945. isok = false
  946. for i := 0; i < len(ccsensor); i++ {
  947. if ccsensor[i].Serial == sensorarr[si] {
  948. isok = true
  949. break
  950. }
  951. }
  952. if !isok {
  953. nohavesensor = sensorarr[si]
  954. break
  955. }
  956. }
  957. if isok {
  958. errinfo.Message = "验证通过!"
  959. errinfo.Code = 0
  960. this.Data["json"] = &errinfo
  961. this.ServeJSON()
  962. } else {
  963. errinfo.Message = "模块序列号" + nohavesensor + "不存在"
  964. errinfo.Code = -1
  965. this.Data["json"] = &errinfo
  966. this.ServeJSON()
  967. }
  968. }
  969. // @Title 根据容器id获取温度模块
  970. // @Description 获取传感器列表
  971. // @Success 200 {object} business.device.DeviceChannels
  972. // @router /getsensorsbyequid [get]
  973. func (this *EquipmentController) GetSensorsbyEquid() {
  974. equid := this.GetString("equid")
  975. svc := equipment.GetEquipmentService(utils.DBE)
  976. var esentitylist []equipment.EquipmentSensors
  977. wheresensor := "where AccCode='" + this.User.AccCode + "' and EquipmentId=" + equid
  978. esentitylist = svc.GetSensorsList(wheresensor)
  979. this.Data["json"] = esentitylist
  980. this.ServeJSON()
  981. }
  982. // @Title 报警器列表
  983. // @Description 设备列表
  984. // @Success 200 {object} business.device.DeviceChannels
  985. // @router /bindequipment/:id [get]
  986. func (this *EquipmentController) GetEquipmentByOrganId() {
  987. id := this.Ctx.Input.Param(":id")
  988. svc := equipment.GetEquipmentService(utils.DBE)
  989. var entity []equipment.Equipment
  990. where := "OrganizeId='" + id + "'"
  991. svc.GetEntities(&entity, where)
  992. var datainfo DataInfo
  993. datainfo.Items = entity
  994. this.Data["json"] = &datainfo
  995. this.ServeJSON()
  996. }
  997. // @Title 样本库获取容器列表
  998. // @Description BioBank获取设备的名字与id、层数列表
  999. // @Success 200 {object} business.device.DeviceChannels
  1000. // @router /equipmentlist [get]
  1001. //func (this *EquipmentController) NameIdRowList() {
  1002. // svc := equipment.GetEquipmentService(utils.DBE)
  1003. // svcrole := role.GetRoleService(utils.DBE)
  1004. // roleids := svcrole.GetRoleidsByuid(utils.ToStr(this.User.Id))
  1005. // where := " a.AccCode = '" + this.User.AccCode + "'"
  1006. // where = where + " and (a.CreateUserId=" + utils.ToStr(this.User.Id) + " or a.Id in (select EquipmentId Id FROM Base_RoleEquipment where RoleId in (" + strings.Join(roleids, ",") + ")))"
  1007. // var list []string
  1008. // _, entities := svc.GetEquipmenViewtList(0, 0, "a.Id desc", where)
  1009. // for i := 0; i < len(entities); i++ {
  1010. // list = append(list, entities[i].Name)
  1011. // list = append(list, utils.ToStr(entities[i].Id))
  1012. // list = append(list, utils.ToStr(entities[i].RowNum))
  1013. // list = append(list, utils.ToStr(entities[i].ColumnNum))
  1014. // list = append(list, utils.ToStr(entities[i].DItem))
  1015. // }
  1016. // var datainfo DataInfo
  1017. // datainfo.Items = list
  1018. // this.Data["json"] = &datainfo
  1019. // this.ServeJSON()
  1020. //}
  1021. // @Title 样本库获取Shelf列表
  1022. // @Description BioBank获取设备的名字与id、层数列表
  1023. // @Success 200 {object} business.device.DeviceChannels
  1024. // @router /shelflist [get]
  1025. //func (this *EquipmentController) Shelflist() {
  1026. // EquipmentId := this.GetString("EquipmentId")
  1027. // var list []shelfset.Shelf
  1028. // svc := equipment.GetEquipmentService(utils.DBE)
  1029. // where := " EquipmentId ='" + EquipmentId + "'"
  1030. // svc.GetEntitysByWhere(ShelfName, where, &list)
  1031. // var datainfo DataInfo
  1032. // datainfo.Items = list
  1033. // this.Data["json"] = &datainfo
  1034. // this.ServeJSON()
  1035. //}
  1036. // @Title 样本库获取Box列表
  1037. // @Description BioBank获取设备的名字与id、层数列表
  1038. // @Success 200 {object} business.device.DeviceChannels
  1039. // @router /boxlist [get]
  1040. //func (this *EquipmentController) Boxlist() {
  1041. // Shelf := this.GetString("Shelf")
  1042. // var list []shelfset.Box
  1043. // svc := equipment.GetEquipmentService(utils.DBE)
  1044. // where := " ShelfId ='" + Shelf + "'"
  1045. // svc.GetEntitysByWhere(BoxName, where, &list)
  1046. // var datainfo DataInfo
  1047. // datainfo.Items = list
  1048. // this.Data["json"] = &datainfo
  1049. // this.ServeJSON()
  1050. //}