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() } }