equipment.go 46 KB

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