| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228 |
- package instrument
- import (
- "encoding/json"
- "strconv"
- "strings"
- "time"
- "dashoo.cn/backend/api/business/instrument"
- . "dashoo.cn/backend/api/controllers"
- "dashoo.cn/business2/organize"
- "dashoo.cn/business2/userRole"
- "dashoo.cn/utils"
- )
- type InstrumentController struct {
- BaseController
- }
- //保存附件UI model
- //type maintainlogFormmodel struct {
- // MaintainLogId int
- // AttachmodelList []MaintainLogAttachmentarrt // 上传附件
- //}
- //type InstrumentDetail struct {
- // Id int
- // Code string
- // Name string
- // Brand string
- // Classification string
- // State int
- // Remarks string
- // CreateBy string
- // CreateUserId int
- // ModifiedBy string
- // ModifiedUserId int
- //}
- //type InstrumentModel struct {
- // Code string
- // HeartbeatTime int64
- // ServiceTime time.Time
- // CreateBy string
- // CreateUserId int
- // ModifiedBy string
- // ModifiedUserId int
- //}
- // @Title 初始化设备信息列表
- // @Description 设备列表
- // @Success 200
- // @router /initlistdata [get]
- func (this *InstrumentController) GetEquipmentData() {
- page := this.GetPageInfoForm()
- userSvc := userRole.GetUserService(utils.DBE)
- organizeSvc := organize.GetOrganizeService(utils.DBE)
- departList := organizeSvc.GetChildByTopId(this.User.DepartmentId)
- //取出当前部门及下级部门的所有用户列表
- var subUserList []userRole.Base_User
- whereUser := " 1=1 "
- whereUser += " and DepartmentId in (" + departList + ")"
- userSvc.GetEntities(&subUserList, whereUser)
- var userIds string
- for _, tmpUser := range subUserList {
- userIds += strconv.Itoa(tmpUser.Id) + ","
- }
- userIds = strings.Trim(userIds, ",")
- where := " 1=1 "
- where += " AND CreateUserId in (" + userIds + ")"
- orderby := "Id desc"
- Order := this.GetString("Order")
- Prop := this.GetString("Prop")
- if Order != "" && Prop != "" {
- orderby = Prop + " " + Order
- }
- Code := this.GetString("Code")
- if Code != "" {
- where = where + " and ( Code like '%" + Code + "%' || Name like '%" + Code + "%')"
- }
- Name := this.GetString("Name")
- if Name != "" {
- where = where + " and Classification = '" + Name + "' "
- }
- Supplier := this.GetString("Supplier")
- if Supplier != "" {
- where = where + " and Supplier like '%" + Supplier + "%' "
- }
- Model := this.GetString("Model")
- if Model != "" {
- where = where + " and Model like '%" + Model + "%' "
- }
- CalibrationTime := this.GetString("CalibrationTime")
- if CalibrationTime != "" {
- dates := strings.Split(CalibrationTime, ",")
- if len(dates) == 2 {
- minDate := dates[0]
- maxDate := dates[1]
- where = where + " and CalibrationTime>='" + minDate + "' and CalibrationTime<='" + maxDate + "'"
- }
- }
- svc := instrument.GetInstrumentService(utils.DBE)
- total, list := svc.GetInstrumentList(this.User.AccCode+InstrumentName, page.CurrentPage, page.Size, orderby, where)
- var datainfo DataInfo
- datainfo.Items = list
- datainfo.CurrentItemCount = total
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 新增设备
- // @Description 新增设备信息
- // @Success 200
- // @router /addinstument [post]
- func (this *InstrumentController) Addinstument() {
- var testlistentity instrument.Instrument
- var jsonblob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonblob, &testlistentity)
- testlistentity.CreateBy = this.User.Realname
- testlistentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- svc := instrument.GetInstrumentService(utils.DBE)
- _, err := svc.InsertEntityBytbl(this.User.AccCode+InstrumentName, &testlistentity)
- var errinfo ErrorInfo
- if err == nil {
- errinfo.Message = "保存成功!"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 获取列表
- // @Description get user by token
- // @Success 200 {object} []instrument.LimsCertificate
- // @router /cerlist/:id [get]
- func (this *InstrumentController) GetEntityList() {
- //获取分页信息
- page := this.GetPageInfoForm()
- where := " 1=1 "
- orderby := "Id"
- asc := false
- Order := this.GetString("Order")
- Prop := this.GetString("Prop")
- if Order != "" && Prop != "" {
- orderby = Prop
- if Order == "asc" {
- asc = true
- }
- }
- InstrumentNo := this.Ctx.Input.Param(":id")
- if InstrumentNo != "" {
- where = where + " and InstrumentNo = " + InstrumentNo
- }
- svc := instrument.GetInstrumentService(utils.DBE)
- var list []instrument.LimsCertificate
- total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
- var datainfo DataInfo
- datainfo.Items = list
- datainfo.CurrentItemCount = total
- datainfo.PageIndex = page.CurrentPage
- datainfo.ItemsPerPage = page.Size
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 获取实体 ---设备证书
- // @Description 获取实体
- // @Success 200 {object} instrument.LimsCertificate
- // @router /getcer/:id [get]
- func (this *InstrumentController) GetEntity() {
- Id := this.Ctx.Input.Param(":id")
- var model instrument.LimsCertificate
- svc := instrument.GetInstrumentService(utils.DBE)
- svc.GetEntityByIdBytbl(this.User.AccCode+LimsCertificateName, Id, &model)
- this.Data["json"] = &model
- this.ServeJSON()
- }
- // @Title 添加 ---设备证书
- // @Description 新增
- // @Param body body instrument.LimsCertificate
- // @Success 200 {object} controllers.Request
- // @router /addcer [post]
- func (this *InstrumentController) AddCerEntity() {
- var model instrument.LimsCertificate
- var jsonBlob = this.Ctx.Input.RequestBody
- svc := instrument.GetInstrumentService(utils.DBE)
- json.Unmarshal(jsonBlob, &model)
- model.CreateOn = time.Now()
- model.CreateBy = this.User.Realname
- model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- //model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int()
- _, err := svc.InsertEntityBytbl(this.User.AccCode+LimsCertificateName, &model)
- var errinfo ErrorDataInfo
- if err == nil {
- //新增
- errinfo.Message = "添加成功!"
- errinfo.Code = 0
- errinfo.Item = model.Id
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 修改实体 ---设备证书
- // @Description 修改实体
- // @Param body body instrument.LimsCertificate
- // @Success 200 {object} controllers.Request
- // @router /updatecer/:id [post]
- func (this *InstrumentController) UpdateEntity() {
- id := this.Ctx.Input.Param(":id")
- var errinfo ErrorInfo
- if id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- var model instrument.LimsCertificate
- svc := instrument.GetInstrumentService(utils.DBE)
- var jsonBlob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonBlob, &model)
- model.ModifiedOn = time.Now()
- model.ModifiedBy = this.User.Realname
- model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
- cols := []string{
- "Id",
- "InstrumentNo",
- "InstrumentName",
- "CerNum",
- "StandardUnit",
- "StandVal",
- "Uncertainty",
- "EffectDate",
- "CreateOn",
- "CreateUserId",
- "CreateBy",
- "ModifiedOn",
- "ModifiedUserId",
- "ModifiedBy",
- }
- err := svc.UpdateEntityBytbl(this.User.AccCode+LimsCertificateName, id, &model, cols)
- if err == nil {
- errinfo.Message = "修改成功!"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 删除单条信息 ---设备证书
- // @Description
- // @Success 200 {object} ErrorInfo
- // @Failure 403 :id 为空
- // @router /deletecer/:Id [delete]
- func (this *InstrumentController) DeleteEntity() {
- Id := this.Ctx.Input.Param(":Id")
- var errinfo ErrorInfo
- if Id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- var model instrument.LimsCertificate
- var entityempty instrument.LimsCertificate
- svc := instrument.GetInstrumentService(utils.DBE)
- opdesc := "删除-" + Id
- err := svc.DeleteOperationAndWriteLogBytbl(this.User.AccCode+LimsCertificateName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "钻井日报")
- if err == nil {
- errinfo.Message = "删除成功"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 删除信息 ---设备证书
- // @Description
- // @Success 200 {object} ErrorInfo
- // @Failure 403 :id 为空
- // @router /deletecerall/:Id [delete]
- func (this *InstrumentController) DeleteAllEntity() {
- InstrumentNo := this.Ctx.Input.Param(":Id")
- var errinfo ErrorInfo
- if InstrumentNo == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- var where string
- if InstrumentNo != "" {
- where = where + " InstrumentNo = " + InstrumentNo
- }
- svc := instrument.GetInstrumentService(utils.DBE)
- err := svc.DeleteEntityBytbl(this.User.AccCode+LimsCertificateName,where)
- if err == nil {
- errinfo.Message = "删除成功"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 获取设备编辑信息
- // @Description
- // @Success 200
- // @router /editinstumentinfo/:id [get]
- func (this *InstrumentController) GetEditData() {
- id := this.Ctx.Input.Param(":id")
- var model instrument.Instrument
- var errinfo ErrorInfo
- if id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- svc := instrument.GetInstrumentService(utils.DBE)
- svc.GetEntityByWhere(this.User.AccCode+InstrumentName, "Id="+id, &model)
- this.Data["json"] = &model
- this.ServeJSON()
- }
- // @Title 保存编辑设备信息
- // @Param body body body "注意"
- // @Success 200
- // @router /saveeditinstument/:Id [put]
- func (this *InstrumentController) SaveEditData() {
- Id := this.Ctx.Input.Param(":Id")
- var errinfo ErrorInfo
- if Id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- var model instrument.Instrument
- var jsonblob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonblob, &model)
- var entityempty instrument.Instrument
- model.ModifiedBy = this.User.Realname
- model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
- svc := instrument.GetInstrumentService(utils.DBE)
- opdesc := "编辑设备-" + model.Code
- var cols []string = []string{"Code", "Name", "Supplier", "Model", "Brand", "Classification", "State", "Remarks", "CalibrationTime", "CalibrationDeadline", "CalibrationDeadlineType", "HeartbeatTime"}
- err := svc.UpdateOperationAndWriteLogBytbl(this.User.AccCode+InstrumentName, BaseOperationLogName, Id, &model, &entityempty, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "设备管理")
- if err == nil {
- errinfo.Message = "操作成功!"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 删除设备信息
- // @Description
- // @Success 200 {object} ErrorInfo
- // @Failure 403 :id 为空
- // @router /deleteinstument/:Id [delete]
- func (this *InstrumentController) Deleteinstrument() {
- Id := this.Ctx.Input.Param(":Id")
- var errinfo ErrorInfo
- if Id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- where := " Id= " + Id
- svc := instrument.GetInstrumentService(utils.DBE)
- svc.DeleteInstrumenstate(this.User.AccCode+InstrumentName, this.User.AccCode+InstrumenstateName, where)
- err := svc.DeleteEntityBytbl(this.User.AccCode+InstrumentName, where)
- if err == nil {
- errinfo.Message = "删除成功"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 更新信息
- // @Description 每10S获取一次仪器信息
- // @Success 200 {object} controllers.Request
- // @router /updateeveryminute [put]
- //func (this *InstrumentController) UpdateInfo() {
- // var model instrument.Instrumenstate
- // var jsonblob = this.Ctx.Input.RequestBody
- // json.Unmarshal(jsonblob, &model)
- // var errinfo ErrorInfo
- // svc := instrument.GetInstrumentService(utils.DBE)
- // if model.Code == "" {
- // errinfo.Message = "操作失败!请求信息不完整"
- // errinfo.Code = -2
- // this.Data["json"] = &errinfo
- // this.ServeJSON()
- // return
- // }
- // where := " where Code= '" + model.Code + "'"
- // timeLayout := "2006-01-02 15:04:05" //时间转换模板
- // dataTimeStr := time.Unix(model.ReportTime, 0).Format(timeLayout) //格式化时间戳
- // err := svc.UpdateInstrumentdata(accode+InstrumenstateName, accode+InstrumentName, dataTimeStr, where)
- // if err == nil {
- // errinfo.Message = "操作成功!"
- // errinfo.Code = 0
- // this.Data["json"] = &errinfo
- // this.ServeJSON()
- // } else {
- // errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
- // errinfo.Code = -1
- // this.Data["json"] = &errinfo
- // this.ServeJSON()
- // }
- //}
- // @Title 根据用户AccCode get检验主表 客户原始信息内容
- // @Description get user by token
- // @Success 200 {object} models.Userblood
- // @router /initInstrumenMaintainLoglist [get]
- func (this *InstrumentController) InitInstrumenMaintainLoglist() {
- page := this.GetPageInfoForm()
- userSvc := userRole.GetUserService(utils.DBE)
- organizeSvc := organize.GetOrganizeService(utils.DBE)
- departList := organizeSvc.GetChildByTopId(this.User.DepartmentId)
- //取出当前部门及下级部门的所有用户列表
- var subUserList []userRole.Base_User
- whereUser := " 1=1 "
- whereUser += " and DepartmentId in (" + departList + ")"
- userSvc.GetEntities(&subUserList, whereUser)
- var userIds string
- for _, tmpUser := range subUserList {
- userIds += strconv.Itoa(tmpUser.Id) + ","
- }
- userIds = strings.Trim(userIds, ",")
- where := " 1=1 "
- where += " AND CreateUserId in (" + userIds + ")"
- InstrumenCode := this.GetString("InstrumenCode")
- InstrumenName := this.GetString("InstrumenName")
- OperaUser := this.GetString("OperaUser")
- var list []instrument.InstrumenMaintainLog
- svc := instrument.GetInstrumentService(utils.DBE)
- orderby := "OperaOn"
- asc := false
- Order := this.GetString("Order")
- Prop := this.GetString("Prop")
- if Order != "" && Prop != "" {
- orderby = Prop
- if Order == "asc" {
- asc = true
- }
- }
- if InstrumenCode != "" {
- where = where + " and ( InstrumenName like '%" + InstrumenCode + "%' || InstrumenCode like '%" + InstrumenCode + "%')"
- }
- paramid := this.GetString("paramid")
- if paramid != "" {
- where = where + " and InstrumenId =" + paramid
- }
- if OperaUser != "" {
- where = where + " and OperaUser like '%" + OperaUser + "%'"
- }
- if InstrumenName != "" {
- where = where + " and OperaTpye like '%" + InstrumenName + "%'"
- }
- OperaOn := this.GetString("OperaOn")
- if OperaOn != "" {
- dates := strings.Split(OperaOn, ",")
- if len(dates) == 2 {
- minDate := dates[0]
- maxDate := dates[1]
- where = where + " and OperaOn>='" + minDate + "' and OperaOn<='" + maxDate + "'"
- }
- }
- total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
- var datainfo DataInfo
- datainfo.Items = list
- datainfo.CurrentItemCount = total
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 添加质量管理
- // @Description 新增质量管理
- // @Param body body business.device.DeviceChannels "质量管理"
- // @Success 200 {object} controllers.Request
- // @router /addinstrumenMaintainLog [post]
- func (this *InstrumentController) AddinstrumenMaintainLog() {
- var testlistentity instrument.InstrumenMaintainLog
- var jsonblob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonblob, &testlistentity)
- testlistentity.CreateBy = this.User.Realname
- testlistentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- svc := instrument.GetInstrumentService(utils.DBE)
- _, err := svc.InsertEntityBytbl(this.User.AccCode+InstrumenMaintainLogName, &testlistentity)
- var errinfo ErrorDataInfo
- if err == nil {
- errinfo.Message = "操作成功!"
- errinfo.Code = 0
- errinfo.Item = testlistentity.Id
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 获取质量管理 编辑时回显信息
- // @Description
- // @Success 200
- // @router /getinstrumenMaintainLog/:id [get]
- func (this *InstrumentController) GetinstrumenMaintainLog() {
- id := this.Ctx.Input.Param(":id")
- var model instrument.InstrumenMaintainLog
- var errinfo ErrorInfo
- if id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- svc := instrument.GetInstrumentService(utils.DBE)
- svc.GetEntityByWhere(this.User.AccCode+InstrumenMaintainLogName, "Id="+id, &model)
- this.Data["json"] = &model
- this.ServeJSON()
- }
- // @Title 保存编辑质量管理
- // @Param body body body "注意"
- // @Success 200
- // @router /saveeditmaintainlog/:Id [put]
- func (this *InstrumentController) Saveeditmaintainlog() {
- Id := this.Ctx.Input.Param(":Id")
- var errinfo ErrorInfo
- if Id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- var model instrument.InstrumenMaintainLog
- var jsonblob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonblob, &model)
- var entityempty instrument.InstrumenMaintainLog
- model.ModifiedBy = this.User.Realname
- model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
- svc := instrument.GetInstrumentService(utils.DBE)
- opdesc := "质量管理-" + model.InstrumenCode
- var cols []string = []string{"InstrumenId", "InstrumenName", "InstrumenCode", "OperaRemark", "OperaTpye", "OperaUser", "OperaOn"}
- err := svc.UpdateOperationAndWriteLogBytbl(this.User.AccCode+InstrumenMaintainLogName, BaseOperationLogName, Id, &model, &entityempty, cols, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "设备管理")
- if err == nil {
- errinfo.Message = "操作成功!"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 删除质量表
- // @Description
- // @Success 200 {object} ErrorInfo
- // @Failure 403 :id 为空
- // @router /deletemaintainlog/:Id [delete]
- func (this *InstrumentController) Deletemaintainlog() {
- Id := this.Ctx.Input.Param(":Id")
- var errinfo ErrorInfo
- if Id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- where := " Id= " + Id
- svc := instrument.GetInstrumentService(utils.DBE)
- err := svc.DeleteEntityBytbl(this.User.AccCode+InstrumenMaintainLogName, where)
- if err == nil {
- errinfo.Message = "删除成功"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 根据用户AccCode get检验主表 客户原始信息内容
- // @Description get user by token
- // @Success 200 {object} models.Userblood
- // @router /initinstrumenrunrecordlist [get]
- func (this *InstrumentController) Initinstrumenrunrecordlist() {
- page := this.GetPageInfoForm()
- InstrumenCode := this.GetString("InstrumenCode")
- var list []instrument.InstrumenRunRecord
- svc := instrument.GetInstrumentService(utils.DBE)
- userSvc := userRole.GetUserService(utils.DBE)
- organizeSvc := organize.GetOrganizeService(utils.DBE)
- departList := organizeSvc.GetChildByTopId(this.User.DepartmentId)
- //取出当前部门及下级部门的所有用户列表
- var subUserList []userRole.Base_User
- whereUser := " 1=1 "
- whereUser += " and DepartmentId in (" + departList + ")"
- userSvc.GetEntities(&subUserList, whereUser)
- var userIds string
- for _, tmpUser := range subUserList {
- userIds += strconv.Itoa(tmpUser.Id) + ","
- }
- userIds = strings.Trim(userIds, ",")
- where := " 1=1 "
- where += " AND CreateUserId in (" + userIds + ")"
- orderby := "Id"
- asc := false
- Order := this.GetString("Order")
- Prop := this.GetString("Prop")
- if Order != "" && Prop != "" {
- orderby = Prop
- if Order == "asc" {
- asc = true
- }
- }
- CreateBy := this.GetString("CreateBy")
- if CreateBy != "" {
- where = where + " and CreateBy like '%" + CreateBy + "%'"
- }
- paramid := this.GetString("paramid")
- if paramid != "" {
- where = where + " and InstrumentId =" + paramid
- }
- if InstrumenCode != "" {
- where = where + " and ( InstrumenName like '%" + InstrumenCode + "%' || InstrumenCode like '%" + InstrumenCode + "%')"
- }
- CreateOnstart, _ := this.GetInt64("CreateOnstart")
- if CreateOnstart != 0 {
- where = where + " and CreateOn >'" + time.Unix(CreateOnstart, 0).Format("2006-01-02") + "'"
- }
- CreateOnend, _ := this.GetInt64("CreateOnend")
- if CreateOnend != 0 {
- where = where + " and CreateOn <'" + time.Unix(CreateOnend, 0).Format("2006-01-02") + " 23:59:59'"
- }
- total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
- var datainfo DataInfo
- datainfo.Items = list
- datainfo.CurrentItemCount = total
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 添加质量管理
- // @Description 新增质量管理
- // @Param body body business.device.DeviceChannels "质量管理"
- // @Success 200 {object} controllers.Request
- // @router /addinstrumenrunrecord [post]
- func (this *InstrumentController) Addinstrumenrunrecord() {
- var testlistentity instrument.InstrumenRunRecord
- var jsonblob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonblob, &testlistentity)
- testlistentity.CreateBy = this.User.Realname
- testlistentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- svc := instrument.GetInstrumentService(utils.DBE)
- _, err := svc.InsertEntityBytbl(this.User.AccCode+InstrumenRunRecordName, &testlistentity)
- var errinfo ErrorInfo
- if err == nil {
- errinfo.Message = "操作成功!"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 获取运行记录 编辑时回显信息
- // @Description
- // @Success 200
- // @router /getinstrumenrunrecord/:id [get]
- func (this *InstrumentController) Getinstrumenrunrecord() {
- id := this.Ctx.Input.Param(":id")
- var model instrument.InstrumenRunRecord
- var errinfo ErrorInfo
- if id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- svc := instrument.GetInstrumentService(utils.DBE)
- svc.GetEntityByWhere(this.User.AccCode+InstrumenRunRecordName, "Id="+id, &model)
- this.Data["json"] = &model
- this.ServeJSON()
- }
- // @Title 保存附件
- // @Description 保存附件
- // @Success 200 {object}
- // @router /savesampleattach [put]
- //func (this *InstrumentController) SaveSampleAttach() {
- // // 获得前端传输的model
- // var jsonblob = this.Ctx.Input.RequestBody
- // var upmodel maintainlogFormmodel
- // json.Unmarshal(jsonblob, &upmodel)
- // var errinfo ErrorInfo
- // if len(upmodel.AttachmodelList) == 0 {
- // errinfo.Message = "上传失败!无附件信息"
- // errinfo.Code = -3
- // this.Data["json"] = &errinfo
- // this.ServeJSON()
- // return
- // }
- // //---附件---
- // var attachmodel instrument.InstrumenMaintainLogAttachment
- // attachmodel.CreateBy = this.User.Realname
- // attachmodel.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- // attachmodel.MaintainLogId = upmodel.MaintainLogId
- // svc := instrument.GetInstrumentService(utils.DBE)
- // var err error
- // for _, val := range upmodel.AttachmodelList {
- // attachmodel.FileId = val.FileId
- // attachmodel.FileName = val.FileName
- // attachmodel.FileSize = val.FileSize
- // attachmodel.Host = val.Host
- // attachmodel.UploadDesc = val.UploadDesc
- // _, err = svc.InsertEntityBytbl(this.User.AccCode+InstrumenMaintainLogAttachmentName, &attachmodel)
- // }
- // if err == nil {
- // errinfo.Message = "保存成功"
- // errinfo.Code = 0
- // this.Data["json"] = &errinfo
- // this.ServeJSON()
- // } else {
- // errinfo.Message = "上传失败!" + utils.AlertProcess(err.Error())
- // errinfo.Code = -1
- // this.Data["json"] = &errinfo
- // this.ServeJSON()
- // }
- //}
- // @Title 获设备表下拉
- // @Description get SampleType by token
- // @Success 200 {object} id.name
- // @router /selectlist [get]
- func (this *InstrumentController) Selectlist() {
- svc := instrument.GetInstrumentService(utils.DBE)
- var list []SelectIdNameModel
- svc.GetDatasByCols(&list, "1=1", "Id", []string{"Id", "Name"}, this.User.AccCode+InstrumentName)
- var datainfo DataInfo
- datainfo.Items = list
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 质量管理 根据设备名称查找
- // @Description get SampleType by token
- // @Success 200 {object} controllers.Request
- // @router /getInstrumenCode [get]
- func (this *InstrumentController) GetInstrumenCode() {
- svc := instrument.GetInstrumentService(utils.DBE)
- Id := this.GetString("Id")
- var entity instrument.Instrument
- where := " Id=" + Id + ""
- entity = svc.QueryCoustominfomationEntity(where, this.User.AccCode)
- var datainfo DataInfo
- datainfo.Items = entity
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 添加质量管理
- // @Description 新增质量管理
- // @Param body body business.device.DeviceChannels "质量管理"
- // @Success 200 {object} controllers.Request
- // @router /arrtinstrumenMaintainLoggetId [post]
- func (this *InstrumentController) ArrtinstrumenMaintainLoggetId() {
- var testlistentity instrument.InstrumenMaintainLog
- var jsonblob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonblob, &testlistentity)
- testlistentity.CreateBy = this.User.Realname
- testlistentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- svc := instrument.GetInstrumentService(utils.DBE)
- svc.InsertEntityBytbl(this.User.AccCode+InstrumenMaintainLogName, &testlistentity)
- this.Data["json"] = &testlistentity
- this.ServeJSON()
- }
- // @Title 质量管理根据id信息查询附件
- // @Description get user by token
- // @Success 200 {object} models.Userblood
- // @router /getMaintainLogAttachment [get]
- func (this *InstrumentController) GetMaintainLogAttachment() {
- MaintainLogId := this.GetString("MaintainLogId")
- svc := instrument.GetInstrumentService(utils.DBE)
- where := " MaintainLogId= '" + MaintainLogId + "'"
- total := svc.GetMaintainLogAttachment(this.User.AccCode+InstrumenMaintainLogAttachmentName, where)
- var datainfo DataInfo
- datainfo.Items = total
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 根据维护记录表Id删除质量附件表
- // @Description
- // @Success 200 {object} ErrorInfo
- // @Failure 403 :id 为空
- // @router /maintainLogAttachmentdeletearrt/:Id [delete]
- func (this *InstrumentController) MaintainLogAttachmentdeletearrt() {
- Id := this.Ctx.Input.Param(":Id")
- var errinfo ErrorInfo
- if Id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- where := " MaintainLogId= " + Id
- svc := instrument.GetInstrumentService(utils.DBE)
- err := svc.DeleteEntityBytbl(this.User.AccCode+InstrumenMaintainLogAttachmentName, where)
- if err == nil {
- errinfo.Message = "删除成功"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 获取质量管理 编辑时回显信息
- // @Description
- // @Success 200
- // @router /getinstrumenMaintainLogaddedit/:id [get]
- func (this *InstrumentController) GetinstrumenMaintainLogaddedit() {
- id := this.Ctx.Input.Param(":id")
- var model instrument.InstrumenMaintainLog
- var errinfo ErrorInfo
- if id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- svc := instrument.GetInstrumentService(utils.DBE)
- svc.GetEntityByWhere(this.User.AccCode+InstrumenMaintainLogName, "InstrumenId="+id, &model)
- this.Data["json"] = &model
- this.ServeJSON()
- }
- // @Title 判断设备编码是否存在
- // @Description get user by token
- // @Success 200 {object} models.Userblood
- // @router /getCode [get]
- func (this *InstrumentController) GetCode() {
- Code := this.GetString("Code")
- svc := instrument.GetInstrumentService(utils.DBE)
- where := " Code= '" + Code + "'"
- total := svc.GetCode(this.User.AccCode+InstrumentName, where)
- var datainfo DataInfo
- datainfo.Items = total
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 添加设备运行信息
- // @Success 200 {object} controllers.Request
- // @router /postinstrument [post]
- func (this *InstrumentController) Addinstrumentruninfo() {
- var model instrument.InstrumenRunRecord
- var jsonblob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonblob, &model)
- model.CreateBy = this.User.Realname
- model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- svc := instrument.GetInstrumentService(utils.DBE)
- _, err := svc.InsertEntityBytbl(this.User.AccCode+InstrumenRunRecordName, &model)
- var errinfo ErrorDataInfo
- if err == nil {
- errinfo.Message = "操作成功!"
- errinfo.Code = 0
- errinfo.Item = model.Id
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 删除设备运行信息
- // @Description
- // @Success 200 {object} ErrorInfo
- // @Failure 403 :id 为空
- // @router /deleteinstumentruninfo/:Id [delete]
- func (this *InstrumentController) Deleteinstrumentruninfo() {
- Id := this.Ctx.Input.Param(":Id")
- var errinfo ErrorInfo
- if Id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- where := " Id= " + Id
- svc := instrument.GetInstrumentService(utils.DBE)
- err := svc.DeleteEntityBytMybl(this.User.AccCode+CellsPreparationInfoDetailName, this.User.AccCode+InstrumenRunRecordName, where)
- if err == nil {
- errinfo.Message = "删除成功"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 获取关联设备的列表
- // @Description get user by token
- // @Success 200 {object} []instrument.InstrumentGroup
- // @router /instrumentgrouplist [get]
- func (this *InstrumentController) GetInstrumentGroup() {
- //获取分页信息
- page := this.GetPageInfoForm()
- where := " 1=1 "
- orderby := "Id"
- asc := false
- Order := this.GetString("Order")
- Prop := this.GetString("Prop")
- if Order != "" && Prop != "" {
- orderby = Prop
- if Order == "asc" {
- asc = true
- }
- }
- svc := instrument.GetInstrumentService(utils.DBE)
- instsvc := instrument.GetInstrumentService(utils.DBE)
- var list []instrument.LimsInstrumentGroup
- total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
- for i := 0; i < len(list); i++ {
- instsvc.GetEntityById(list[i].SADID, instsvc)
- }
- var datainfo DataInfo
- datainfo.Items = list
- datainfo.CurrentItemCount = total
- datainfo.PageIndex = page.CurrentPage
- datainfo.ItemsPerPage = page.Size
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 获取字典列表
- // @Description get user by token
- // @Success 200 {object} map[string]interface{}
- // @router /dictlist [get]
- func (this *InstrumentController) GetDictList() {
- dictList := make(map[string]interface{})
- instsvc := instrument.GetInstrumentService(utils.DBE)
- // 检测仪器--压力变送器
- var list []instrument.Instrument
- where := "Classification='压力变送器'"
- instsvc.GetEntitysByWhere(this.User.AccCode+InstrumentName, where, &list)
- dictList["DifPressTran"] = list
- // 检测仪器--安全附件检测仪
- var list1 []instrument.Instrument
- where = "Classification='安全附件检测仪'"
- instsvc.GetEntitysByWhere(this.User.AccCode+InstrumentName, where, &list1)
- dictList["SafAccDetector"] = list1
- // 检测仪器--热式气体质量流量计
- var list2 []instrument.Instrument
- where = "Classification='热式气体质量流量计'"
- instsvc.GetEntitysByWhere(this.User.AccCode+InstrumentName, where, &list2)
- dictList["GasFlowMeter"] = list2
- var datainfo DataInfo
- datainfo.Items = dictList
- this.Data["json"] = &datainfo
- this.ServeJSON()
- }
- // @Title 添加
- // @Description 新增仪器关联
- // @Param body body instrument.LimsInstrumentGroup
- // @Success 200 {object} controllers.Request
- // @router /addinstrumentgroup [post]
- func (this *InstrumentController) AddEntity() {
- var model instrument.LimsInstrumentGroup
- var jsonBlob = this.Ctx.Input.RequestBody
- svc := instrument.GetInstrumentService(utils.DBE)
- json.Unmarshal(jsonBlob, &model)
- model.CreateOn = time.Now()
- model.CreateBy = this.User.Realname
- model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- //model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int()
- _, err := svc.InsertEntityBytbl(this.User.AccCode+LimsInstrumentGroup, &model)
- var errinfo ErrorDataInfo
- if err == nil {
- //新增
- errinfo.Message = "添加成功!"
- errinfo.Code = 0
- errinfo.Item = model.Id
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 删除设备关联
- // @Description
- // @Success 200 {object} ErrorInfo
- // @Failure 403 :id 为空
- // @router /deleteinstrumentgroup/:Id [delete]
- func (this *InstrumentController) DeleteInstrumentGroup() {
- Id := this.Ctx.Input.Param(":Id")
- var errinfo ErrorInfo
- if Id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- where := " Id= " + Id
- svc := instrument.GetInstrumentService(utils.DBE)
- err := svc.DeleteEntityBytbl(this.User.AccCode+LimsInstrumentGroup, where)
- if err == nil {
- errinfo.Message = "删除成功"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 修改实体
- // @Description 修改实体
- // @Param body body limsreportleakprotect.LimsReportLeakProtect
- // @Success 200 {object} controllers.Request
- // @router /updateinstrumentgroup/:id [post]
- func (this *InstrumentController) UpdateInstrumentGroup() {
- id := this.Ctx.Input.Param(":id")
- var errinfo ErrorInfo
- if id == "" {
- errinfo.Message = "操作失败!请求信息不完整"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- return
- }
- var model instrument.LimsInstrumentGroup
- svc := instrument.GetInstrumentService(utils.DBE)
- var jsonBlob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonBlob, &model)
- model.ModifiedOn = time.Now()
- model.ModifiedBy = this.User.Realname
- model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
- cols := []string{
- "SADID",
- "GasFlowMeterID",
- "DifPressTranID",
- "SAD",
- "GasFlowMeter",
- "DifPressTran",
- "Remark",
- "CreateOn",
- "CreateUserId",
- "CreateBy",
- "ModifiedOn",
- "ModifiedUserId",
- "ModifiedBy",
- }
- err := svc.UpdateEntityBytbl(this.User.AccCode+LimsInstrumentGroup, id, &model, cols)
- if err == nil {
- errinfo.Message = "修改成功!"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
|