instrument.go 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. package instrument
  2. import (
  3. "encoding/json"
  4. "strconv"
  5. "strings"
  6. "time"
  7. "dashoo.cn/backend/api/business/instrument"
  8. . "dashoo.cn/backend/api/controllers"
  9. "dashoo.cn/business2/organize"
  10. "dashoo.cn/business2/userRole"
  11. "dashoo.cn/utils"
  12. )
  13. type InstrumentController struct {
  14. BaseController
  15. }
  16. //保存附件UI model
  17. //type maintainlogFormmodel struct {
  18. // MaintainLogId int
  19. // AttachmodelList []MaintainLogAttachmentarrt // 上传附件
  20. //}
  21. //type InstrumentDetail struct {
  22. // Id int
  23. // Code string
  24. // Name string
  25. // Brand string
  26. // Classification string
  27. // State int
  28. // Remarks string
  29. // CreateBy string
  30. // CreateUserId int
  31. // ModifiedBy string
  32. // ModifiedUserId int
  33. //}
  34. //type InstrumentModel struct {
  35. // Code string
  36. // HeartbeatTime int64
  37. // ServiceTime time.Time
  38. // CreateBy string
  39. // CreateUserId int
  40. // ModifiedBy string
  41. // ModifiedUserId int
  42. //}
  43. // @Title 初始化设备信息列表
  44. // @Description 设备列表
  45. // @Success 200
  46. // @router /initlistdata [get]
  47. func (this *InstrumentController) GetEquipmentData() {
  48. page := this.GetPageInfoForm()
  49. userSvc := userRole.GetUserService(utils.DBE)
  50. organizeSvc := organize.GetOrganizeService(utils.DBE)
  51. departList := organizeSvc.GetChildByTopId(this.User.DepartmentId)
  52. //取出当前部门及下级部门的所有用户列表
  53. var subUserList []userRole.Base_User
  54. whereUser := " 1=1 "
  55. whereUser += " and DepartmentId in (" + departList + ")"
  56. userSvc.GetEntities(&subUserList, whereUser)
  57. var userIds string
  58. for _, tmpUser := range subUserList {
  59. userIds += strconv.Itoa(tmpUser.Id) + ","
  60. }
  61. userIds = strings.Trim(userIds, ",")
  62. where := " 1=1 "
  63. where += " AND CreateUserId in (" + userIds + ")"
  64. orderby := "Id desc"
  65. Order := this.GetString("Order")
  66. Prop := this.GetString("Prop")
  67. if Order != "" && Prop != "" {
  68. orderby = Prop + " " + Order
  69. }
  70. Code := this.GetString("Code")
  71. if Code != "" {
  72. where = where + " and ( Code like '%" + Code + "%' || Name like '%" + Code + "%')"
  73. }
  74. Name := this.GetString("Name")
  75. if Name != "" {
  76. where = where + " and Classification = '" + Name + "' "
  77. }
  78. Supplier := this.GetString("Supplier")
  79. if Supplier != "" {
  80. where = where + " and Supplier like '%" + Supplier + "%' "
  81. }
  82. Model := this.GetString("Model")
  83. if Model != "" {
  84. where = where + " and Model like '%" + Model + "%' "
  85. }
  86. CalibrationTime := this.GetString("CalibrationTime")
  87. if CalibrationTime != "" {
  88. dates := strings.Split(CalibrationTime, ",")
  89. if len(dates) == 2 {
  90. minDate := dates[0]
  91. maxDate := dates[1]
  92. where = where + " and CalibrationTime>='" + minDate + "' and CalibrationTime<='" + maxDate + "'"
  93. }
  94. }
  95. svc := instrument.GetInstrumentService(utils.DBE)
  96. total, list := svc.GetInstrumentList(this.User.AccCode+InstrumentName, page.CurrentPage, page.Size, orderby, where)
  97. var datainfo DataInfo
  98. datainfo.Items = list
  99. datainfo.CurrentItemCount = total
  100. this.Data["json"] = &datainfo
  101. this.ServeJSON()
  102. }
  103. // @Title 新增设备
  104. // @Description 新增设备信息
  105. // @Success 200
  106. // @router /addinstument [post]
  107. func (this *InstrumentController) Addinstument() {
  108. var testlistentity instrument.Instrument
  109. var jsonblob = this.Ctx.Input.RequestBody
  110. json.Unmarshal(jsonblob, &testlistentity)
  111. testlistentity.CreateBy = this.User.Realname
  112. testlistentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  113. svc := instrument.GetInstrumentService(utils.DBE)
  114. _, err := svc.InsertEntityBytbl(this.User.AccCode+InstrumentName, &testlistentity)
  115. var errinfo ErrorInfo
  116. if err == nil {
  117. errinfo.Message = "保存成功!"
  118. errinfo.Code = 0
  119. this.Data["json"] = &errinfo
  120. this.ServeJSON()
  121. } else {
  122. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  123. errinfo.Code = -1
  124. this.Data["json"] = &errinfo
  125. this.ServeJSON()
  126. }
  127. }
  128. // @Title 获取列表
  129. // @Description get user by token
  130. // @Success 200 {object} []instrument.LimsCertificate
  131. // @router /cerlist/:id [get]
  132. func (this *InstrumentController) GetEntityList() {
  133. //获取分页信息
  134. page := this.GetPageInfoForm()
  135. where := " 1=1 "
  136. orderby := "Id"
  137. asc := false
  138. Order := this.GetString("Order")
  139. Prop := this.GetString("Prop")
  140. if Order != "" && Prop != "" {
  141. orderby = Prop
  142. if Order == "asc" {
  143. asc = true
  144. }
  145. }
  146. InstrumentNo := this.Ctx.Input.Param(":id")
  147. if InstrumentNo != "" {
  148. where = where + " and InstrumentNo = " + InstrumentNo
  149. }
  150. svc := instrument.GetInstrumentService(utils.DBE)
  151. var list []instrument.LimsCertificate
  152. total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
  153. var datainfo DataInfo
  154. datainfo.Items = list
  155. datainfo.CurrentItemCount = total
  156. datainfo.PageIndex = page.CurrentPage
  157. datainfo.ItemsPerPage = page.Size
  158. this.Data["json"] = &datainfo
  159. this.ServeJSON()
  160. }
  161. // @Title 获取实体 ---设备证书
  162. // @Description 获取实体
  163. // @Success 200 {object} instrument.LimsCertificate
  164. // @router /getcer/:id [get]
  165. func (this *InstrumentController) GetEntity() {
  166. Id := this.Ctx.Input.Param(":id")
  167. var model instrument.LimsCertificate
  168. svc := instrument.GetInstrumentService(utils.DBE)
  169. svc.GetEntityByIdBytbl(this.User.AccCode+LimsCertificateName, Id, &model)
  170. this.Data["json"] = &model
  171. this.ServeJSON()
  172. }
  173. // @Title 添加 ---设备证书
  174. // @Description 新增
  175. // @Param body body instrument.LimsCertificate
  176. // @Success 200 {object} controllers.Request
  177. // @router /addcer [post]
  178. func (this *InstrumentController) AddCerEntity() {
  179. var model instrument.LimsCertificate
  180. var jsonBlob = this.Ctx.Input.RequestBody
  181. svc := instrument.GetInstrumentService(utils.DBE)
  182. json.Unmarshal(jsonBlob, &model)
  183. model.CreateOn = time.Now()
  184. model.CreateBy = this.User.Realname
  185. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  186. //model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int()
  187. _, err := svc.InsertEntityBytbl(this.User.AccCode+LimsCertificateName, &model)
  188. var errinfo ErrorDataInfo
  189. if err == nil {
  190. //新增
  191. errinfo.Message = "添加成功!"
  192. errinfo.Code = 0
  193. errinfo.Item = model.Id
  194. this.Data["json"] = &errinfo
  195. this.ServeJSON()
  196. } else {
  197. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  198. errinfo.Code = -1
  199. this.Data["json"] = &errinfo
  200. this.ServeJSON()
  201. }
  202. }
  203. // @Title 修改实体 ---设备证书
  204. // @Description 修改实体
  205. // @Param body body instrument.LimsCertificate
  206. // @Success 200 {object} controllers.Request
  207. // @router /updatecer/:id [post]
  208. func (this *InstrumentController) UpdateEntity() {
  209. id := this.Ctx.Input.Param(":id")
  210. var errinfo ErrorInfo
  211. if id == "" {
  212. errinfo.Message = "操作失败!请求信息不完整"
  213. errinfo.Code = -2
  214. this.Data["json"] = &errinfo
  215. this.ServeJSON()
  216. return
  217. }
  218. var model instrument.LimsCertificate
  219. svc := instrument.GetInstrumentService(utils.DBE)
  220. var jsonBlob = this.Ctx.Input.RequestBody
  221. json.Unmarshal(jsonBlob, &model)
  222. model.ModifiedOn = time.Now()
  223. model.ModifiedBy = this.User.Realname
  224. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  225. cols := []string{
  226. "Id",
  227. "InstrumentNo",
  228. "InstrumentName",
  229. "CerNum",
  230. "StandardUnit",
  231. "StandVal",
  232. "Uncertainty",
  233. "EffectDate",
  234. "CreateOn",
  235. "CreateUserId",
  236. "CreateBy",
  237. "ModifiedOn",
  238. "ModifiedUserId",
  239. "ModifiedBy",
  240. }
  241. err := svc.UpdateEntityBytbl(this.User.AccCode+LimsCertificateName, id, &model, cols)
  242. if err == nil {
  243. errinfo.Message = "修改成功!"
  244. errinfo.Code = 0
  245. this.Data["json"] = &errinfo
  246. this.ServeJSON()
  247. } else {
  248. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  249. errinfo.Code = -1
  250. this.Data["json"] = &errinfo
  251. this.ServeJSON()
  252. }
  253. }
  254. // @Title 删除单条信息 ---设备证书
  255. // @Description
  256. // @Success 200 {object} ErrorInfo
  257. // @Failure 403 :id 为空
  258. // @router /deletecer/:Id [delete]
  259. func (this *InstrumentController) DeleteEntity() {
  260. Id := this.Ctx.Input.Param(":Id")
  261. var errinfo ErrorInfo
  262. if Id == "" {
  263. errinfo.Message = "操作失败!请求信息不完整"
  264. errinfo.Code = -2
  265. this.Data["json"] = &errinfo
  266. this.ServeJSON()
  267. return
  268. }
  269. var model instrument.LimsCertificate
  270. var entityempty instrument.LimsCertificate
  271. svc := instrument.GetInstrumentService(utils.DBE)
  272. opdesc := "删除-" + Id
  273. err := svc.DeleteOperationAndWriteLogBytbl(this.User.AccCode+LimsCertificateName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "钻井日报")
  274. if err == nil {
  275. errinfo.Message = "删除成功"
  276. errinfo.Code = 0
  277. this.Data["json"] = &errinfo
  278. this.ServeJSON()
  279. } else {
  280. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  281. errinfo.Code = -1
  282. this.Data["json"] = &errinfo
  283. this.ServeJSON()
  284. }
  285. }
  286. // @Title 删除信息 ---设备证书
  287. // @Description
  288. // @Success 200 {object} ErrorInfo
  289. // @Failure 403 :id 为空
  290. // @router /deletecerall/:Id [delete]
  291. func (this *InstrumentController) DeleteAllEntity() {
  292. InstrumentNo := this.Ctx.Input.Param(":Id")
  293. var errinfo ErrorInfo
  294. if InstrumentNo == "" {
  295. errinfo.Message = "操作失败!请求信息不完整"
  296. errinfo.Code = -2
  297. this.Data["json"] = &errinfo
  298. this.ServeJSON()
  299. return
  300. }
  301. var where string
  302. if InstrumentNo != "" {
  303. where = where + " InstrumentNo = " + InstrumentNo
  304. }
  305. svc := instrument.GetInstrumentService(utils.DBE)
  306. err := svc.DeleteEntityBytbl(this.User.AccCode+LimsCertificateName,where)
  307. if err == nil {
  308. errinfo.Message = "删除成功"
  309. errinfo.Code = 0
  310. this.Data["json"] = &errinfo
  311. this.ServeJSON()
  312. } else {
  313. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  314. errinfo.Code = -1
  315. this.Data["json"] = &errinfo
  316. this.ServeJSON()
  317. }
  318. }
  319. // @Title 获取设备编辑信息
  320. // @Description
  321. // @Success 200
  322. // @router /editinstumentinfo/:id [get]
  323. func (this *InstrumentController) GetEditData() {
  324. id := this.Ctx.Input.Param(":id")
  325. var model instrument.Instrument
  326. var errinfo ErrorInfo
  327. if id == "" {
  328. errinfo.Message = "操作失败!请求信息不完整"
  329. errinfo.Code = -2
  330. this.Data["json"] = &errinfo
  331. this.ServeJSON()
  332. return
  333. }
  334. svc := instrument.GetInstrumentService(utils.DBE)
  335. svc.GetEntityByWhere(this.User.AccCode+InstrumentName, "Id="+id, &model)
  336. this.Data["json"] = &model
  337. this.ServeJSON()
  338. }
  339. // @Title 保存编辑设备信息
  340. // @Param body body body "注意"
  341. // @Success 200
  342. // @router /saveeditinstument/:Id [put]
  343. func (this *InstrumentController) SaveEditData() {
  344. Id := this.Ctx.Input.Param(":Id")
  345. var errinfo ErrorInfo
  346. if Id == "" {
  347. errinfo.Message = "操作失败!请求信息不完整"
  348. errinfo.Code = -2
  349. this.Data["json"] = &errinfo
  350. this.ServeJSON()
  351. return
  352. }
  353. var model instrument.Instrument
  354. var jsonblob = this.Ctx.Input.RequestBody
  355. json.Unmarshal(jsonblob, &model)
  356. var entityempty instrument.Instrument
  357. model.ModifiedBy = this.User.Realname
  358. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  359. svc := instrument.GetInstrumentService(utils.DBE)
  360. opdesc := "编辑设备-" + model.Code
  361. var cols []string = []string{"Code", "Name", "Supplier", "Model", "Brand", "Classification", "State", "Remarks", "CalibrationTime", "CalibrationDeadline", "CalibrationDeadlineType", "HeartbeatTime"}
  362. err := svc.UpdateOperationAndWriteLogBytbl(this.User.AccCode+InstrumentName, BaseOperationLogName, Id, &model, &entityempty, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "设备管理")
  363. if err == nil {
  364. errinfo.Message = "操作成功!"
  365. errinfo.Code = 0
  366. this.Data["json"] = &errinfo
  367. this.ServeJSON()
  368. } else {
  369. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  370. errinfo.Code = -1
  371. this.Data["json"] = &errinfo
  372. this.ServeJSON()
  373. }
  374. }
  375. // @Title 删除设备信息
  376. // @Description
  377. // @Success 200 {object} ErrorInfo
  378. // @Failure 403 :id 为空
  379. // @router /deleteinstument/:Id [delete]
  380. func (this *InstrumentController) Deleteinstrument() {
  381. Id := this.Ctx.Input.Param(":Id")
  382. var errinfo ErrorInfo
  383. if Id == "" {
  384. errinfo.Message = "操作失败!请求信息不完整"
  385. errinfo.Code = -2
  386. this.Data["json"] = &errinfo
  387. this.ServeJSON()
  388. return
  389. }
  390. where := " Id= " + Id
  391. svc := instrument.GetInstrumentService(utils.DBE)
  392. svc.DeleteInstrumenstate(this.User.AccCode+InstrumentName, this.User.AccCode+InstrumenstateName, where)
  393. err := svc.DeleteEntityBytbl(this.User.AccCode+InstrumentName, where)
  394. if err == nil {
  395. errinfo.Message = "删除成功"
  396. errinfo.Code = 0
  397. this.Data["json"] = &errinfo
  398. this.ServeJSON()
  399. } else {
  400. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  401. errinfo.Code = -1
  402. this.Data["json"] = &errinfo
  403. this.ServeJSON()
  404. }
  405. }
  406. // @Title 更新信息
  407. // @Description 每10S获取一次仪器信息
  408. // @Success 200 {object} controllers.Request
  409. // @router /updateeveryminute [put]
  410. //func (this *InstrumentController) UpdateInfo() {
  411. // var model instrument.Instrumenstate
  412. // var jsonblob = this.Ctx.Input.RequestBody
  413. // json.Unmarshal(jsonblob, &model)
  414. // var errinfo ErrorInfo
  415. // svc := instrument.GetInstrumentService(utils.DBE)
  416. // if model.Code == "" {
  417. // errinfo.Message = "操作失败!请求信息不完整"
  418. // errinfo.Code = -2
  419. // this.Data["json"] = &errinfo
  420. // this.ServeJSON()
  421. // return
  422. // }
  423. // where := " where Code= '" + model.Code + "'"
  424. // timeLayout := "2006-01-02 15:04:05" //时间转换模板
  425. // dataTimeStr := time.Unix(model.ReportTime, 0).Format(timeLayout) //格式化时间戳
  426. // err := svc.UpdateInstrumentdata(accode+InstrumenstateName, accode+InstrumentName, dataTimeStr, where)
  427. // if err == nil {
  428. // errinfo.Message = "操作成功!"
  429. // errinfo.Code = 0
  430. // this.Data["json"] = &errinfo
  431. // this.ServeJSON()
  432. // } else {
  433. // errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  434. // errinfo.Code = -1
  435. // this.Data["json"] = &errinfo
  436. // this.ServeJSON()
  437. // }
  438. //}
  439. // @Title 根据用户AccCode get检验主表 客户原始信息内容
  440. // @Description get user by token
  441. // @Success 200 {object} models.Userblood
  442. // @router /initInstrumenMaintainLoglist [get]
  443. func (this *InstrumentController) InitInstrumenMaintainLoglist() {
  444. page := this.GetPageInfoForm()
  445. userSvc := userRole.GetUserService(utils.DBE)
  446. organizeSvc := organize.GetOrganizeService(utils.DBE)
  447. departList := organizeSvc.GetChildByTopId(this.User.DepartmentId)
  448. //取出当前部门及下级部门的所有用户列表
  449. var subUserList []userRole.Base_User
  450. whereUser := " 1=1 "
  451. whereUser += " and DepartmentId in (" + departList + ")"
  452. userSvc.GetEntities(&subUserList, whereUser)
  453. var userIds string
  454. for _, tmpUser := range subUserList {
  455. userIds += strconv.Itoa(tmpUser.Id) + ","
  456. }
  457. userIds = strings.Trim(userIds, ",")
  458. where := " 1=1 "
  459. where += " AND CreateUserId in (" + userIds + ")"
  460. InstrumenCode := this.GetString("InstrumenCode")
  461. InstrumenName := this.GetString("InstrumenName")
  462. OperaUser := this.GetString("OperaUser")
  463. var list []instrument.InstrumenMaintainLog
  464. svc := instrument.GetInstrumentService(utils.DBE)
  465. orderby := "OperaOn"
  466. asc := false
  467. Order := this.GetString("Order")
  468. Prop := this.GetString("Prop")
  469. if Order != "" && Prop != "" {
  470. orderby = Prop
  471. if Order == "asc" {
  472. asc = true
  473. }
  474. }
  475. if InstrumenCode != "" {
  476. where = where + " and ( InstrumenName like '%" + InstrumenCode + "%' || InstrumenCode like '%" + InstrumenCode + "%')"
  477. }
  478. paramid := this.GetString("paramid")
  479. if paramid != "" {
  480. where = where + " and InstrumenId =" + paramid
  481. }
  482. if OperaUser != "" {
  483. where = where + " and OperaUser like '%" + OperaUser + "%'"
  484. }
  485. if InstrumenName != "" {
  486. where = where + " and OperaTpye like '%" + InstrumenName + "%'"
  487. }
  488. OperaOn := this.GetString("OperaOn")
  489. if OperaOn != "" {
  490. dates := strings.Split(OperaOn, ",")
  491. if len(dates) == 2 {
  492. minDate := dates[0]
  493. maxDate := dates[1]
  494. where = where + " and OperaOn>='" + minDate + "' and OperaOn<='" + maxDate + "'"
  495. }
  496. }
  497. total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
  498. var datainfo DataInfo
  499. datainfo.Items = list
  500. datainfo.CurrentItemCount = total
  501. this.Data["json"] = &datainfo
  502. this.ServeJSON()
  503. }
  504. // @Title 添加质量管理
  505. // @Description 新增质量管理
  506. // @Param body body business.device.DeviceChannels "质量管理"
  507. // @Success 200 {object} controllers.Request
  508. // @router /addinstrumenMaintainLog [post]
  509. func (this *InstrumentController) AddinstrumenMaintainLog() {
  510. var testlistentity instrument.InstrumenMaintainLog
  511. var jsonblob = this.Ctx.Input.RequestBody
  512. json.Unmarshal(jsonblob, &testlistentity)
  513. testlistentity.CreateBy = this.User.Realname
  514. testlistentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  515. svc := instrument.GetInstrumentService(utils.DBE)
  516. _, err := svc.InsertEntityBytbl(this.User.AccCode+InstrumenMaintainLogName, &testlistentity)
  517. var errinfo ErrorDataInfo
  518. if err == nil {
  519. errinfo.Message = "操作成功!"
  520. errinfo.Code = 0
  521. errinfo.Item = testlistentity.Id
  522. this.Data["json"] = &errinfo
  523. this.ServeJSON()
  524. } else {
  525. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  526. errinfo.Code = -1
  527. this.Data["json"] = &errinfo
  528. this.ServeJSON()
  529. }
  530. }
  531. // @Title 获取质量管理 编辑时回显信息
  532. // @Description
  533. // @Success 200
  534. // @router /getinstrumenMaintainLog/:id [get]
  535. func (this *InstrumentController) GetinstrumenMaintainLog() {
  536. id := this.Ctx.Input.Param(":id")
  537. var model instrument.InstrumenMaintainLog
  538. var errinfo ErrorInfo
  539. if id == "" {
  540. errinfo.Message = "操作失败!请求信息不完整"
  541. errinfo.Code = -2
  542. this.Data["json"] = &errinfo
  543. this.ServeJSON()
  544. return
  545. }
  546. svc := instrument.GetInstrumentService(utils.DBE)
  547. svc.GetEntityByWhere(this.User.AccCode+InstrumenMaintainLogName, "Id="+id, &model)
  548. this.Data["json"] = &model
  549. this.ServeJSON()
  550. }
  551. // @Title 保存编辑质量管理
  552. // @Param body body body "注意"
  553. // @Success 200
  554. // @router /saveeditmaintainlog/:Id [put]
  555. func (this *InstrumentController) Saveeditmaintainlog() {
  556. Id := this.Ctx.Input.Param(":Id")
  557. var errinfo ErrorInfo
  558. if Id == "" {
  559. errinfo.Message = "操作失败!请求信息不完整"
  560. errinfo.Code = -2
  561. this.Data["json"] = &errinfo
  562. this.ServeJSON()
  563. return
  564. }
  565. var model instrument.InstrumenMaintainLog
  566. var jsonblob = this.Ctx.Input.RequestBody
  567. json.Unmarshal(jsonblob, &model)
  568. var entityempty instrument.InstrumenMaintainLog
  569. model.ModifiedBy = this.User.Realname
  570. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  571. svc := instrument.GetInstrumentService(utils.DBE)
  572. opdesc := "质量管理-" + model.InstrumenCode
  573. var cols []string = []string{"InstrumenId", "InstrumenName", "InstrumenCode", "OperaRemark", "OperaTpye", "OperaUser", "OperaOn"}
  574. err := svc.UpdateOperationAndWriteLogBytbl(this.User.AccCode+InstrumenMaintainLogName, BaseOperationLogName, Id, &model, &entityempty, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "设备管理")
  575. if err == nil {
  576. errinfo.Message = "操作成功!"
  577. errinfo.Code = 0
  578. this.Data["json"] = &errinfo
  579. this.ServeJSON()
  580. } else {
  581. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  582. errinfo.Code = -1
  583. this.Data["json"] = &errinfo
  584. this.ServeJSON()
  585. }
  586. }
  587. // @Title 删除质量表
  588. // @Description
  589. // @Success 200 {object} ErrorInfo
  590. // @Failure 403 :id 为空
  591. // @router /deletemaintainlog/:Id [delete]
  592. func (this *InstrumentController) Deletemaintainlog() {
  593. Id := this.Ctx.Input.Param(":Id")
  594. var errinfo ErrorInfo
  595. if Id == "" {
  596. errinfo.Message = "操作失败!请求信息不完整"
  597. errinfo.Code = -2
  598. this.Data["json"] = &errinfo
  599. this.ServeJSON()
  600. return
  601. }
  602. where := " Id= " + Id
  603. svc := instrument.GetInstrumentService(utils.DBE)
  604. err := svc.DeleteEntityBytbl(this.User.AccCode+InstrumenMaintainLogName, where)
  605. if err == nil {
  606. errinfo.Message = "删除成功"
  607. errinfo.Code = 0
  608. this.Data["json"] = &errinfo
  609. this.ServeJSON()
  610. } else {
  611. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  612. errinfo.Code = -1
  613. this.Data["json"] = &errinfo
  614. this.ServeJSON()
  615. }
  616. }
  617. // @Title 根据用户AccCode get检验主表 客户原始信息内容
  618. // @Description get user by token
  619. // @Success 200 {object} models.Userblood
  620. // @router /initinstrumenrunrecordlist [get]
  621. func (this *InstrumentController) Initinstrumenrunrecordlist() {
  622. page := this.GetPageInfoForm()
  623. InstrumenCode := this.GetString("InstrumenCode")
  624. var list []instrument.InstrumenRunRecord
  625. svc := instrument.GetInstrumentService(utils.DBE)
  626. userSvc := userRole.GetUserService(utils.DBE)
  627. organizeSvc := organize.GetOrganizeService(utils.DBE)
  628. departList := organizeSvc.GetChildByTopId(this.User.DepartmentId)
  629. //取出当前部门及下级部门的所有用户列表
  630. var subUserList []userRole.Base_User
  631. whereUser := " 1=1 "
  632. whereUser += " and DepartmentId in (" + departList + ")"
  633. userSvc.GetEntities(&subUserList, whereUser)
  634. var userIds string
  635. for _, tmpUser := range subUserList {
  636. userIds += strconv.Itoa(tmpUser.Id) + ","
  637. }
  638. userIds = strings.Trim(userIds, ",")
  639. where := " 1=1 "
  640. where += " AND CreateUserId in (" + userIds + ")"
  641. orderby := "Id"
  642. asc := false
  643. Order := this.GetString("Order")
  644. Prop := this.GetString("Prop")
  645. if Order != "" && Prop != "" {
  646. orderby = Prop
  647. if Order == "asc" {
  648. asc = true
  649. }
  650. }
  651. CreateBy := this.GetString("CreateBy")
  652. if CreateBy != "" {
  653. where = where + " and CreateBy like '%" + CreateBy + "%'"
  654. }
  655. paramid := this.GetString("paramid")
  656. if paramid != "" {
  657. where = where + " and InstrumentId =" + paramid
  658. }
  659. if InstrumenCode != "" {
  660. where = where + " and ( InstrumenName like '%" + InstrumenCode + "%' || InstrumenCode like '%" + InstrumenCode + "%')"
  661. }
  662. CreateOnstart, _ := this.GetInt64("CreateOnstart")
  663. if CreateOnstart != 0 {
  664. where = where + " and CreateOn >'" + time.Unix(CreateOnstart, 0).Format("2006-01-02") + "'"
  665. }
  666. CreateOnend, _ := this.GetInt64("CreateOnend")
  667. if CreateOnend != 0 {
  668. where = where + " and CreateOn <'" + time.Unix(CreateOnend, 0).Format("2006-01-02") + " 23:59:59'"
  669. }
  670. total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
  671. var datainfo DataInfo
  672. datainfo.Items = list
  673. datainfo.CurrentItemCount = total
  674. this.Data["json"] = &datainfo
  675. this.ServeJSON()
  676. }
  677. // @Title 添加质量管理
  678. // @Description 新增质量管理
  679. // @Param body body business.device.DeviceChannels "质量管理"
  680. // @Success 200 {object} controllers.Request
  681. // @router /addinstrumenrunrecord [post]
  682. func (this *InstrumentController) Addinstrumenrunrecord() {
  683. var testlistentity instrument.InstrumenRunRecord
  684. var jsonblob = this.Ctx.Input.RequestBody
  685. json.Unmarshal(jsonblob, &testlistentity)
  686. testlistentity.CreateBy = this.User.Realname
  687. testlistentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  688. svc := instrument.GetInstrumentService(utils.DBE)
  689. _, err := svc.InsertEntityBytbl(this.User.AccCode+InstrumenRunRecordName, &testlistentity)
  690. var errinfo ErrorInfo
  691. if err == nil {
  692. errinfo.Message = "操作成功!"
  693. errinfo.Code = 0
  694. this.Data["json"] = &errinfo
  695. this.ServeJSON()
  696. } else {
  697. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  698. errinfo.Code = -1
  699. this.Data["json"] = &errinfo
  700. this.ServeJSON()
  701. }
  702. }
  703. // @Title 获取运行记录 编辑时回显信息
  704. // @Description
  705. // @Success 200
  706. // @router /getinstrumenrunrecord/:id [get]
  707. func (this *InstrumentController) Getinstrumenrunrecord() {
  708. id := this.Ctx.Input.Param(":id")
  709. var model instrument.InstrumenRunRecord
  710. var errinfo ErrorInfo
  711. if id == "" {
  712. errinfo.Message = "操作失败!请求信息不完整"
  713. errinfo.Code = -2
  714. this.Data["json"] = &errinfo
  715. this.ServeJSON()
  716. return
  717. }
  718. svc := instrument.GetInstrumentService(utils.DBE)
  719. svc.GetEntityByWhere(this.User.AccCode+InstrumenRunRecordName, "Id="+id, &model)
  720. this.Data["json"] = &model
  721. this.ServeJSON()
  722. }
  723. // @Title 保存附件
  724. // @Description 保存附件
  725. // @Success 200 {object}
  726. // @router /savesampleattach [put]
  727. //func (this *InstrumentController) SaveSampleAttach() {
  728. // // 获得前端传输的model
  729. // var jsonblob = this.Ctx.Input.RequestBody
  730. // var upmodel maintainlogFormmodel
  731. // json.Unmarshal(jsonblob, &upmodel)
  732. // var errinfo ErrorInfo
  733. // if len(upmodel.AttachmodelList) == 0 {
  734. // errinfo.Message = "上传失败!无附件信息"
  735. // errinfo.Code = -3
  736. // this.Data["json"] = &errinfo
  737. // this.ServeJSON()
  738. // return
  739. // }
  740. // //---附件---
  741. // var attachmodel instrument.InstrumenMaintainLogAttachment
  742. // attachmodel.CreateBy = this.User.Realname
  743. // attachmodel.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  744. // attachmodel.MaintainLogId = upmodel.MaintainLogId
  745. // svc := instrument.GetInstrumentService(utils.DBE)
  746. // var err error
  747. // for _, val := range upmodel.AttachmodelList {
  748. // attachmodel.FileId = val.FileId
  749. // attachmodel.FileName = val.FileName
  750. // attachmodel.FileSize = val.FileSize
  751. // attachmodel.Host = val.Host
  752. // attachmodel.UploadDesc = val.UploadDesc
  753. // _, err = svc.InsertEntityBytbl(this.User.AccCode+InstrumenMaintainLogAttachmentName, &attachmodel)
  754. // }
  755. // if err == nil {
  756. // errinfo.Message = "保存成功"
  757. // errinfo.Code = 0
  758. // this.Data["json"] = &errinfo
  759. // this.ServeJSON()
  760. // } else {
  761. // errinfo.Message = "上传失败!" + utils.AlertProcess(err.Error())
  762. // errinfo.Code = -1
  763. // this.Data["json"] = &errinfo
  764. // this.ServeJSON()
  765. // }
  766. //}
  767. // @Title 获设备表下拉
  768. // @Description get SampleType by token
  769. // @Success 200 {object} id.name
  770. // @router /selectlist [get]
  771. func (this *InstrumentController) Selectlist() {
  772. svc := instrument.GetInstrumentService(utils.DBE)
  773. var list []SelectIdNameModel
  774. svc.GetDatasByCols(&list, "1=1", "Id", []string{"Id", "Name"}, this.User.AccCode+InstrumentName)
  775. var datainfo DataInfo
  776. datainfo.Items = list
  777. this.Data["json"] = &datainfo
  778. this.ServeJSON()
  779. }
  780. // @Title 质量管理 根据设备名称查找
  781. // @Description get SampleType by token
  782. // @Success 200 {object} controllers.Request
  783. // @router /getInstrumenCode [get]
  784. func (this *InstrumentController) GetInstrumenCode() {
  785. svc := instrument.GetInstrumentService(utils.DBE)
  786. Id := this.GetString("Id")
  787. var entity instrument.Instrument
  788. where := " Id=" + Id + ""
  789. entity = svc.QueryCoustominfomationEntity(where, this.User.AccCode)
  790. var datainfo DataInfo
  791. datainfo.Items = entity
  792. this.Data["json"] = &datainfo
  793. this.ServeJSON()
  794. }
  795. // @Title 添加质量管理
  796. // @Description 新增质量管理
  797. // @Param body body business.device.DeviceChannels "质量管理"
  798. // @Success 200 {object} controllers.Request
  799. // @router /arrtinstrumenMaintainLoggetId [post]
  800. func (this *InstrumentController) ArrtinstrumenMaintainLoggetId() {
  801. var testlistentity instrument.InstrumenMaintainLog
  802. var jsonblob = this.Ctx.Input.RequestBody
  803. json.Unmarshal(jsonblob, &testlistentity)
  804. testlistentity.CreateBy = this.User.Realname
  805. testlistentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  806. svc := instrument.GetInstrumentService(utils.DBE)
  807. svc.InsertEntityBytbl(this.User.AccCode+InstrumenMaintainLogName, &testlistentity)
  808. this.Data["json"] = &testlistentity
  809. this.ServeJSON()
  810. }
  811. // @Title 质量管理根据id信息查询附件
  812. // @Description get user by token
  813. // @Success 200 {object} models.Userblood
  814. // @router /getMaintainLogAttachment [get]
  815. func (this *InstrumentController) GetMaintainLogAttachment() {
  816. MaintainLogId := this.GetString("MaintainLogId")
  817. svc := instrument.GetInstrumentService(utils.DBE)
  818. where := " MaintainLogId= '" + MaintainLogId + "'"
  819. total := svc.GetMaintainLogAttachment(this.User.AccCode+InstrumenMaintainLogAttachmentName, where)
  820. var datainfo DataInfo
  821. datainfo.Items = total
  822. this.Data["json"] = &datainfo
  823. this.ServeJSON()
  824. }
  825. // @Title 根据维护记录表Id删除质量附件表
  826. // @Description
  827. // @Success 200 {object} ErrorInfo
  828. // @Failure 403 :id 为空
  829. // @router /maintainLogAttachmentdeletearrt/:Id [delete]
  830. func (this *InstrumentController) MaintainLogAttachmentdeletearrt() {
  831. Id := this.Ctx.Input.Param(":Id")
  832. var errinfo ErrorInfo
  833. if Id == "" {
  834. errinfo.Message = "操作失败!请求信息不完整"
  835. errinfo.Code = -2
  836. this.Data["json"] = &errinfo
  837. this.ServeJSON()
  838. return
  839. }
  840. where := " MaintainLogId= " + Id
  841. svc := instrument.GetInstrumentService(utils.DBE)
  842. err := svc.DeleteEntityBytbl(this.User.AccCode+InstrumenMaintainLogAttachmentName, where)
  843. if err == nil {
  844. errinfo.Message = "删除成功"
  845. errinfo.Code = 0
  846. this.Data["json"] = &errinfo
  847. this.ServeJSON()
  848. } else {
  849. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  850. errinfo.Code = -1
  851. this.Data["json"] = &errinfo
  852. this.ServeJSON()
  853. }
  854. }
  855. // @Title 获取质量管理 编辑时回显信息
  856. // @Description
  857. // @Success 200
  858. // @router /getinstrumenMaintainLogaddedit/:id [get]
  859. func (this *InstrumentController) GetinstrumenMaintainLogaddedit() {
  860. id := this.Ctx.Input.Param(":id")
  861. var model instrument.InstrumenMaintainLog
  862. var errinfo ErrorInfo
  863. if id == "" {
  864. errinfo.Message = "操作失败!请求信息不完整"
  865. errinfo.Code = -2
  866. this.Data["json"] = &errinfo
  867. this.ServeJSON()
  868. return
  869. }
  870. svc := instrument.GetInstrumentService(utils.DBE)
  871. svc.GetEntityByWhere(this.User.AccCode+InstrumenMaintainLogName, "InstrumenId="+id, &model)
  872. this.Data["json"] = &model
  873. this.ServeJSON()
  874. }
  875. // @Title 判断设备编码是否存在
  876. // @Description get user by token
  877. // @Success 200 {object} models.Userblood
  878. // @router /getCode [get]
  879. func (this *InstrumentController) GetCode() {
  880. Code := this.GetString("Code")
  881. svc := instrument.GetInstrumentService(utils.DBE)
  882. where := " Code= '" + Code + "'"
  883. total := svc.GetCode(this.User.AccCode+InstrumentName, where)
  884. var datainfo DataInfo
  885. datainfo.Items = total
  886. this.Data["json"] = &datainfo
  887. this.ServeJSON()
  888. }
  889. // @Title 添加设备运行信息
  890. // @Success 200 {object} controllers.Request
  891. // @router /postinstrument [post]
  892. func (this *InstrumentController) Addinstrumentruninfo() {
  893. var model instrument.InstrumenRunRecord
  894. var jsonblob = this.Ctx.Input.RequestBody
  895. json.Unmarshal(jsonblob, &model)
  896. model.CreateBy = this.User.Realname
  897. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  898. svc := instrument.GetInstrumentService(utils.DBE)
  899. _, err := svc.InsertEntityBytbl(this.User.AccCode+InstrumenRunRecordName, &model)
  900. var errinfo ErrorDataInfo
  901. if err == nil {
  902. errinfo.Message = "操作成功!"
  903. errinfo.Code = 0
  904. errinfo.Item = model.Id
  905. this.Data["json"] = &errinfo
  906. this.ServeJSON()
  907. } else {
  908. errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
  909. errinfo.Code = -1
  910. this.Data["json"] = &errinfo
  911. this.ServeJSON()
  912. }
  913. }
  914. // @Title 删除设备运行信息
  915. // @Description
  916. // @Success 200 {object} ErrorInfo
  917. // @Failure 403 :id 为空
  918. // @router /deleteinstumentruninfo/:Id [delete]
  919. func (this *InstrumentController) Deleteinstrumentruninfo() {
  920. Id := this.Ctx.Input.Param(":Id")
  921. var errinfo ErrorInfo
  922. if Id == "" {
  923. errinfo.Message = "操作失败!请求信息不完整"
  924. errinfo.Code = -2
  925. this.Data["json"] = &errinfo
  926. this.ServeJSON()
  927. return
  928. }
  929. where := " Id= " + Id
  930. svc := instrument.GetInstrumentService(utils.DBE)
  931. err := svc.DeleteEntityBytMybl(this.User.AccCode+CellsPreparationInfoDetailName, this.User.AccCode+InstrumenRunRecordName, where)
  932. if err == nil {
  933. errinfo.Message = "删除成功"
  934. errinfo.Code = 0
  935. this.Data["json"] = &errinfo
  936. this.ServeJSON()
  937. } else {
  938. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  939. errinfo.Code = -1
  940. this.Data["json"] = &errinfo
  941. this.ServeJSON()
  942. }
  943. }
  944. // @Title 获取关联设备的列表
  945. // @Description get user by token
  946. // @Success 200 {object} []instrument.InstrumentGroup
  947. // @router /instrumentgrouplist [get]
  948. func (this *InstrumentController) GetInstrumentGroup() {
  949. //获取分页信息
  950. page := this.GetPageInfoForm()
  951. where := " 1=1 "
  952. orderby := "Id"
  953. asc := false
  954. Order := this.GetString("Order")
  955. Prop := this.GetString("Prop")
  956. if Order != "" && Prop != "" {
  957. orderby = Prop
  958. if Order == "asc" {
  959. asc = true
  960. }
  961. }
  962. svc := instrument.GetInstrumentService(utils.DBE)
  963. instsvc := instrument.GetInstrumentService(utils.DBE)
  964. var list []instrument.LimsInstrumentGroup
  965. total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
  966. for i := 0; i < len(list); i++ {
  967. instsvc.GetEntityById(list[i].SADID, instsvc)
  968. }
  969. var datainfo DataInfo
  970. datainfo.Items = list
  971. datainfo.CurrentItemCount = total
  972. datainfo.PageIndex = page.CurrentPage
  973. datainfo.ItemsPerPage = page.Size
  974. this.Data["json"] = &datainfo
  975. this.ServeJSON()
  976. }
  977. // @Title 获取字典列表
  978. // @Description get user by token
  979. // @Success 200 {object} map[string]interface{}
  980. // @router /dictlist [get]
  981. func (this *InstrumentController) GetDictList() {
  982. dictList := make(map[string]interface{})
  983. instsvc := instrument.GetInstrumentService(utils.DBE)
  984. // 检测仪器--压力变送器
  985. var list []instrument.Instrument
  986. where := "Classification='压力变送器'"
  987. instsvc.GetEntitysByWhere(this.User.AccCode+InstrumentName, where, &list)
  988. dictList["DifPressTran"] = list
  989. // 检测仪器--安全附件检测仪
  990. var list1 []instrument.Instrument
  991. where = "Classification='安全附件检测仪'"
  992. instsvc.GetEntitysByWhere(this.User.AccCode+InstrumentName, where, &list1)
  993. dictList["SafAccDetector"] = list1
  994. // 检测仪器--热式气体质量流量计
  995. var list2 []instrument.Instrument
  996. where = "Classification='热式气体质量流量计'"
  997. instsvc.GetEntitysByWhere(this.User.AccCode+InstrumentName, where, &list2)
  998. dictList["GasFlowMeter"] = list2
  999. var datainfo DataInfo
  1000. datainfo.Items = dictList
  1001. this.Data["json"] = &datainfo
  1002. this.ServeJSON()
  1003. }
  1004. // @Title 添加
  1005. // @Description 新增仪器关联
  1006. // @Param body body instrument.LimsInstrumentGroup
  1007. // @Success 200 {object} controllers.Request
  1008. // @router /addinstrumentgroup [post]
  1009. func (this *InstrumentController) AddEntity() {
  1010. var model instrument.LimsInstrumentGroup
  1011. var jsonBlob = this.Ctx.Input.RequestBody
  1012. svc := instrument.GetInstrumentService(utils.DBE)
  1013. json.Unmarshal(jsonBlob, &model)
  1014. model.CreateOn = time.Now()
  1015. model.CreateBy = this.User.Realname
  1016. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  1017. //model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int()
  1018. _, err := svc.InsertEntityBytbl(this.User.AccCode+LimsInstrumentGroup, &model)
  1019. var errinfo ErrorDataInfo
  1020. if err == nil {
  1021. //新增
  1022. errinfo.Message = "添加成功!"
  1023. errinfo.Code = 0
  1024. errinfo.Item = model.Id
  1025. this.Data["json"] = &errinfo
  1026. this.ServeJSON()
  1027. } else {
  1028. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  1029. errinfo.Code = -1
  1030. this.Data["json"] = &errinfo
  1031. this.ServeJSON()
  1032. }
  1033. }
  1034. // @Title 删除设备关联
  1035. // @Description
  1036. // @Success 200 {object} ErrorInfo
  1037. // @Failure 403 :id 为空
  1038. // @router /deleteinstrumentgroup/:Id [delete]
  1039. func (this *InstrumentController) DeleteInstrumentGroup() {
  1040. Id := this.Ctx.Input.Param(":Id")
  1041. var errinfo ErrorInfo
  1042. if Id == "" {
  1043. errinfo.Message = "操作失败!请求信息不完整"
  1044. errinfo.Code = -2
  1045. this.Data["json"] = &errinfo
  1046. this.ServeJSON()
  1047. return
  1048. }
  1049. where := " Id= " + Id
  1050. svc := instrument.GetInstrumentService(utils.DBE)
  1051. err := svc.DeleteEntityBytbl(this.User.AccCode+LimsInstrumentGroup, where)
  1052. if err == nil {
  1053. errinfo.Message = "删除成功"
  1054. errinfo.Code = 0
  1055. this.Data["json"] = &errinfo
  1056. this.ServeJSON()
  1057. } else {
  1058. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  1059. errinfo.Code = -1
  1060. this.Data["json"] = &errinfo
  1061. this.ServeJSON()
  1062. }
  1063. }
  1064. // @Title 修改实体
  1065. // @Description 修改实体
  1066. // @Param body body limsreportleakprotect.LimsReportLeakProtect
  1067. // @Success 200 {object} controllers.Request
  1068. // @router /updateinstrumentgroup/:id [post]
  1069. func (this *InstrumentController) UpdateInstrumentGroup() {
  1070. id := this.Ctx.Input.Param(":id")
  1071. var errinfo ErrorInfo
  1072. if id == "" {
  1073. errinfo.Message = "操作失败!请求信息不完整"
  1074. errinfo.Code = -2
  1075. this.Data["json"] = &errinfo
  1076. this.ServeJSON()
  1077. return
  1078. }
  1079. var model instrument.LimsInstrumentGroup
  1080. svc := instrument.GetInstrumentService(utils.DBE)
  1081. var jsonBlob = this.Ctx.Input.RequestBody
  1082. json.Unmarshal(jsonBlob, &model)
  1083. model.ModifiedOn = time.Now()
  1084. model.ModifiedBy = this.User.Realname
  1085. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  1086. cols := []string{
  1087. "SADID",
  1088. "GasFlowMeterID",
  1089. "DifPressTranID",
  1090. "SAD",
  1091. "GasFlowMeter",
  1092. "DifPressTran",
  1093. "Remark",
  1094. "CreateOn",
  1095. "CreateUserId",
  1096. "CreateBy",
  1097. "ModifiedOn",
  1098. "ModifiedUserId",
  1099. "ModifiedBy",
  1100. }
  1101. err := svc.UpdateEntityBytbl(this.User.AccCode+LimsInstrumentGroup, id, &model, cols)
  1102. if err == nil {
  1103. errinfo.Message = "修改成功!"
  1104. errinfo.Code = 0
  1105. this.Data["json"] = &errinfo
  1106. this.ServeJSON()
  1107. } else {
  1108. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  1109. errinfo.Code = -1
  1110. this.Data["json"] = &errinfo
  1111. this.ServeJSON()
  1112. }
  1113. }