// Controller基础类,所有Controller会继承此类 package controllers import ( "encoding/base64" "errors" "fmt" "reflect" "strconv" "strings" "github.com/astaxie/beego" "dashoo.cn/business2/userRole" // "dashoo.cn/backend/api/business/material" "dashoo.cn/backend/api/models" "dashoo.cn/utils" "dashoo.cn/utils/redis" ) // Operations about tokens type BaseController struct { beego.Controller User *models.UserInfo } type ErrorInfo struct { Code int64 `json:"code"` Message string `json:"message,omitempty"` } type ErrorDataInfo struct { Code int64 `json:"code"` Message string `json:"message,omitempty"` Item interface{} `json:"item,omitempty"` //数据 } type DataEntryInfo struct { Code int64 `json:"code"` Message string `json:"message,omitempty"` Item interface{} `json:"item,omitempty"` //数据 Info int `json:"info"` CurrentItemCount int64 `json:"currentItemCount,omitempty"` //结果集中的条目数目 ItemsPerPage int64 `json:"itemsPerPage,omitempty"` //每页记录数目 StartIndex int64 `json:"startIndex,omitempty"` //items中第一个条目的索引 TotalItemsx int64 `json:"totalItemsx,omitempty"` //当前集合中可用的总条目数 PageIndex int64 `json:"pageIndex,omitempty"` //条目的当前页索引 TotalPages int64 `json:"totalPages,omitempty"` //当前结果集中的总页数 } type Request struct { Status int `json:"status"` Id string `json:"id"` Message string `json:"message"` } type PageInfo struct { CurrentPage int64 `form:"_currentPage"` Size int64 `form:"_size"` } type Status struct { Status int `json:"status"` Id string `json:"id"` Message string `json:"message"` } type ValidformStruct struct { Info string `json:"info"` Status string `json:"status"` Items interface{} `json:"items,omitempty"` //数据列表 } var ( Nsqdtcpaddr string Nsqtopic string SalesAdmin string = "SalesAdmin" //分销商管理员 ProjectSourse string = "coldchain" DonorstbName string = "DonorsInfo" DonorslogtbName string = "DonorsLog" DonorsNoteItemName string = "DonorsNoteItem" IsUpdating string = "false" EquipmentModelName string = "EquipMentModel" //设备型号管理表 SamplesLogtbName string = "SamplesLog" SamplesMaintbName string = "SamplesMain" SamplesDetailtbName string = "SamplesDetail" SamplesBusstbName string = "SamplesBusiness" SamplesDetailFiletbName string = "SamplesFileDetail" // 归档表 SamplesAttachmenttbName string = "SamplesAttachment" // 附件表 SampleSearchTemplateName string = "SampleSearchTemplate" // 样本搜索模版表 SampleTestMainName string = "SampleTestMain" //样本检测信息主表 SampleTestDetailName string = "SampleTestDetail" //样本检测子表 SamplesBookName string = "SamplesBook" //样本列表 SamplesBookDetailName string = "SamplesBookDetail" //样本列表详情 SampleTypeName string = "SampleType" //样本类型 STypeNoteItemName string = "STypeNoteItem" //样本特有扩展 ManagementPreparationName string = "ManagementPreparation" //制备管理 PreparationStepDataName string = "PreparationStepData" //制备步骤 PreparationStepDetailDataName string = "PreparationStepDetailData" //制备操作详情 ManagementControlName string = "ManagementPreparation" //质控管理 ControlStepDataName string = "PreparationStepData" //质控步骤 ControlStepDetailDataName string = "PreparationStepDetailData" //质控操作详情 BaseOperationLogName string = "Base_OperationLog" //操作日志表 MaterialInfoName string = "MaterialInfo" //库存信息表 MaterialBatchKCName string = "MaterialBatchKC" //物料批次库存信息表 MaterialStoreHouseName string = "MaterialStoreHouse" //仓库列表 MaterialCKDetailName string = "MaterialCKDetail" //出库管理子表 MaterialCKHeadName string = "MaterialCKHead" //出库管理主表 MaterialPDDetailName string = "MaterialPDDetail" //盘点子表 MaterialPDHeadName string = "MaterialPDHead" //盘点管理主表 MicrobialName string = "Microbial" //动物微生物表 CellBloodName string = "CellBlood" //采血表 TestTemplateName string = "TestTemplate" //检测模板 PreparationTemplateName string = "PreparationTemplate" PreparationTemplateStepName string = "PreparationTemplateStep" PreparationTemplateStepDetailName string = "PreparationTemplateStepDetail" CellSaveName string = "CellSave" //细胞存储表 Coustom_InformationName string = "Coustom_Information" //客户信息表 Order_InformationName string = "Order_Information" //订单信息表 GeneProductName string = "GeneProduct" //基因治疗表 CellProductName string = "CellProduct" //细胞制备表 MaterialRKDetailName string = "MaterialRKDetail" //库存表 MaterialRKHeadName string = "MaterialRKHead" //入库主表 TestSampleName string = "TestSample" //检验样本 TestSampleDetailName string = "TestSampleDetail" //检验样本详情表 TestSampleInfoName string = "TestSampleInfo" //检验样本信息 TestSampleRelationName string = "TestSampleRelation" //样本套餐-采样关系表 TestTransferOrdersName string = "TestTransferOrders" //检验交接单 TestInfoName string = "TestInfo" //检验单 TestInfoDetailName string = "TestInfoDetail" //检验结果 TestItemsListName string = "TestItemsList" // 检验项目内容 TestListName string = "TestList" //检验项目主表 TestListDetailName string = "TestListDetail" //检验项目详情表 TestLaboratoryName string = "TestLaboratory" //检验实验室 TestQualityControlName string = "TestQualityControl" //质控数据 TestControlParametersName string = "TestControlParameters" //质控品参数 TestControlParametersDetailName string = "TestControlParametersDetail" //质控品详情 AccusationParametersName string = "AccusationParameters" TestApplicationName string = "TestApplication" //检验申请单 TestPackageCategoryName string = "TestPackageCategory" // 类别 TestPrintTemplateName string = "TestPrintTemplate" //打印模板 TestPackageName string = "TestPackage" //检验套餐 TestPackageItemsName string = "TestPackageItems" //检验套餐项目明细 InstrumentName string = "Instrument" Base_ItemTreeDetailsName string = "Base_ItemTreeDetails" //数据字典 文档结构 Base_ItemDetailsName string = "Base_ItemDetails" //数据字典 InstrumenMaintainLogName string = "InstrumenMaintainLog" //质量管理 InstrumenstateName string = "Instrumenstate" //设备自动发送信息 InstrumenRunRecordName string = "InstrumenRunRecord" //设备运行信息 CustomerName string = "Customer" //客户原始信息内容 CellsContractName string = "CellsContract" //合同管理 CellsContractDetailName string = "CellsContractDetail" //合同详情 CellsCollectionName string = "CellsCollection" //样本采集 CellsCollectionDetailName string = "CellsCollectionDetail" //样本采集子表 CellsCollectionSensorsName string = "CellsCollectionSensors" //采集单Sensor表 CellsPrepareTemplateName string = "CellsPrepareTemplate" //Cells制备模板主表 CellsPrepareTemplateStepName string = "CellsPrepareTemplateStep" //Cells制备模板步骤表 CellsPrepareTemplateStepDetailName string = "CellsPrepareTemplateStepDetail" //Cells制备模板步骤详情表 CellsPreparationName string = "CellsPreparation" //Cells制备表 CellsPreparationInfoName string = "CellsPreparationInfo" CellsPreparationInfoDetailName string = "CellsPreparationInfoDetail" CellsPreparationSamplesName string = "CellsPreparationSamples" //Cells制备样本信息表 CellsPreparationInfoDetailAttachmentName string = "CellsPreparationInfoDetailAttachment" //Cells制备附件表 DonorsInfoAttachmentName string = "DonorsInfoAttachment" //样本采集附件 InstrumenMaintainLogAttachmentName string = "InstrumenMaintainLogAttachment" //质量管理附件 CellsContractAttachmentName string = "CellsContractAttachment" //合同管理附件 CellsProductDeliveryName string = "CellsProductDelivery" //产品交付 CellsProductDeliverySampleName string = "CellsProductDeliverySample" //交付详情 CellsProductDeliveryAttachmentName string = "CellsProductDeliveryAttachment" //产品交付附件 CellsPreparationTraceName string = "CellsPreparationTrace" //制备信息溯源表 ControlTemplateName string = "ControlTemplate" //Cells质控备模板主表 ControlTemplateStepName string = "ControlTemplateStep" //Cells质控模板步骤表 ControlTemplateStepDetailName string = "ControlTemplateStepDetail" //Cells质控模板步骤详情表 ControlName string = "Control" //Cells质控表 ControlInfoName string = "ControlInfo" ControlInfoDetailName string = "ControlInfoDetail" ControlInfoDetailAttachmentName string = "ControlInfoDetailAttachment" ControlTraceName string = "ControlTrace" //制备信息溯源表 DocumentInfoName string = "DocumentInfo" //文档 DocumentHistoryName string = "DocumentHistory" //历史文档 SamplesCustomorName string = "SamplesCustomor" //样本库客户信息表 SamplesCommunicationName string = "SamplesCommunication" //样本库客户交流记录表 SamplesProtocolName string = "SamplesProtocol" //样本库协议表 SamplesProtocolDetailName string = "SamplesProtocolDetail" //样本库协议执行信息表 DonorsDetailName string = "DonorsDetail" //样本库样本来源详情表 ShelfName string = "Shelf" //设备冻存架表 BoxName string = "Box" //设备冻存盒表 GroupDetailName string = "GroupDetail" //样本库分组表 SamplesApplyName string = "SamplesApply" //出入库申请表 SamplesApplyDetailName string = "SamplesApplyDetail" //出入库申请详情表 SamplesRecordName string = "SamplesRecord" //样本操作记录表 LimsEntrustMainName string = "LimsEntrustMain" //LIMS委托管理 TestPackageTypesName string = "TestPackageTypes" // LIMS检验类型 LimsSampleTypeName string = "LimsSampleType" // LIMS样品类型 LimsDocTemplateName string = "LimsDocTemplate" // lims模板 LimsDocTemplateDetailName string = "LimsDocTemplateDetail" // lims模板详情 LimsTaskBalanceName string = "LimsTaskBalance" // 任务分配表 LimsDeliverName string = "LimsDeliver" //样品交接表 LimsDeliverDetailName string = "LimsDeliverDetail" //样品交接详情表 LimsPreparationName string = "LimsPreparation" //样品制备表 LimsCreateReportName string = "LimsCreateReport" //报告生成 LimsDateEntryName string = "LimsDateEntry" //数据录入 LimsDocHistoryName string = "LimsDocHistory" //数据录入文档历史 LimsEntrustSampleName string = "LimsEntrustSample" //委托样品明细表 LimsEntrustSampleTypeName string = "LimsEntrustSampleType" //详情表 LimsReportHuxfName string = "LimsReportHuxf" //呼吸阀检测数据记录表 LimsReportYeyaqfName string = "LimsReportYeyaqf" //液压安全阀检测数据记录表 LimsReportZuhqName string = "LimsReportZuhq" //阻火器检测数据记录表 LimsReportElecGroundName string = "LimsReportElecGround" //电气接地装置检测原始记录 LimsReportLeakProtectName string = "LimsReportLeakProtect" //漏电保护器检测数据记录表 LimsReportEquipotentName string = "LimsReportEquipotent" //防雷装置(等电位)检测原始记录 LimsReportLightProtectName string = "LimsReportLightProtect" //防雷装置检测原始记录 LimsReportAmmeterName string = "LimsReportAmmeter" //电流表检测原始记录 LimsReportKqpmName string = "LimsReportAirFoamGenerator" //空气泡沫产生器检测数据记录表 LimsReportNoBeamPumpingUnitName string = "LimsReportNoBeamPumpingUnit" //无游梁式抽油机检测数据记录表 LimsReportBeamPumpingUnitName string = "LimsReportBeamPumpingUnits" //游梁式抽油机检测数据记录表 LimsDrillingDailyName string = "LimsDrillingDaily" //工程监督中心钻井工程监督日报 LimsOilTestingDailyName string = "LimsOilTestingDaily" //试油监督日报表 LimsReportSignName string = "LimsReportSign" //报告签发 LimsReportHistoryName string = "LimsReportHistory" //报告历史 LimsCustomerpositionName string = "LimsCustomerPosition" LimsPressureLeakName string = "LimsPressureLeak" //阻火器压力损失表 LimsSpecifyStandardName string = "LimsSpecifyStandard" //Lims规格型号标准 BaseUserName string = "Base_User" //用户表 UserQualificationName string = "UserQualification" //用户资质表 LimsInstrumentGroup string = "LimsInstrumentGroup" // 检测仪器关联 OilAuditSettingName string = "Base_OilAuditSetting" // 单位审批步骤自定义配置 OilAuditUserName string = "OilAuditUser" // 单位审批步骤 --审核人 OilBasisBuildName string = "OilBasisBuild" // 基建类资质对照表 OilGoodsAptitudeName string = "OilGoodsAptitude" // 物资类项目与资质对照表 OilTableFiledSettingName string = "OilTableFiledSetting" // 资质项目与字段对照表 OilTechnologyServiceName string = "OilTechnologyService" // 技术服务类资质对照表 OilSupplierName string = "OilSupplier" // 供方基本信息表 OilSupplierCertName string = "OilSupplierCert" // 供方准入证书信息表 OilSupplierCertSubName string = "OilSupplierCertSub" // 供方对应准入子分类表 OilSupplierCertAppendName string = "OilSupplierCertAppend" // 供方增项信息表 OilSupplierCertAppendSubName string = "OilSupplierCertAppendSub" // 供方增项信息分类表 OilSupplierFileName string = "OilSupplierFile" // 供方准入文件表 OilGoodsAptitudeClassName string = "OilGoodsAptitudeClass" // 物资类资质分类层级表 OilTechnologyServiceClassName string = "OilTechnologyServiceClass" // 技术服务类资质分类层级表 OilEnterpriseMajorEquipmentName string = "OilEnterpriseMajorEquipment" //企业主要装备情况 OilThreeYearsPerformanceName string = "OilThreeYearsPerformance" //近三年主要工程业绩 OilPatentStatisticalName string = "OilPatentStatistical" //拥有专利、专有技术及工法 OilWinningProjectName string = "OilWinningProject" //近三年获得省部级及以上主要技术、管理成果、获奖项目 OilTechsrvDetailViewName string = "oil_techsrv_detail_view" //技术服务类视图 OilGoodsAptDetailViewName string = "oil_goodsapt_detail_view" //物資类视图 OilTechsrvClassViewName string = "oil_techsrv_class_view" //技术服务类视图 OilGoodsAptClassViewName string = "oil_goodsapt_class_view" //物資类视图 OilClassOrgSettingName string = "OilClassOrgSetting" //分类部门审批配置表 OilAnnualAuditName string = "OilAnnualAudit" //年审表 OilSupplierOpinionName string = "OilSupplierOpinion" //追加意见表 OilInfoChangeItemName string = "OilInfoChangeItem" //信息变更表 OilInfoChangeName string = "OilInfoChange" //信息变更表 OilQualChangeMainName string = "OilQualChangeMain" //资质变更表 OilQualChangeDetailName string = "OilQualChangeDetail" //资质变更表 BaseTableHeader string = "Base_TableHeader" //资质配置字典信息表 BaseBadRecord string = "BadRecord" //不良记录表 OilSupplierCert2FileName string = "OilSupplierCert2File" // 准入与资质对应关系表 OilCorporateInfoName string = "OilCorporateInfo" //企业用户注册临时表 OilPaymentInfoName string = "OilPaymentInfo" //缴费信息 ) //分页信息及数据 type DataInfo struct { CurrentItemCount int64 `json:"currentItemCount,omitempty"` //结果集中的条目数目 ItemsPerPage int64 `json:"itemsPerPage,omitempty"` //每页记录数目 StartIndex int64 `json:"startIndex,omitempty"` //items中第一个条目的索引 TotalItemsx int64 `json:"totalItemsx,omitempty"` //当前集合中可用的总条目数 PageIndex int64 `json:"pageIndex,omitempty"` //条目的当前页索引 TotalPages int64 `json:"totalPages,omitempty"` //当前结果集中的总页数 Items interface{} `json:"items,omitempty"` //数据列表 } //下拉idname type SelectIdNameModel struct { Id int `json:"id"` Name string `json:"name"` } func (this *BaseController) Prepare() { find := false // 不需要做登录验证的页面 urls := []string{ "/api/auth", "/api/users/registemanage", "/printservice", "/api/uploads/samplestypeimg", "/api/workflow/historyimg/", "/api/document/getdocumentnameandtime", "/api/annualaudit/auditcallback", "/api/suppliercert/auditcallback", "/api/register/addentity", "/api/register/getsuppliername", "/api/register/getcommercialno", "/api/register/getdictlist", "/api/register/usernameisexist", "/api/rtx/call", "/api/organizes/getorglist", "/api/supplier/getauditerbydeptandnologin", "/api/rtx/ptrlogin", "/api/register/orgloginlist", "/api/register/getauditerbydept", "/api/register/getCode", "/api/register/updatepassword", } for _, v := range urls { fmt.Println("**this.Ctx.Input.URL()**", this.Ctx.Input.URL()) if this.Ctx.Input.URL() == v { find = true break } if strings.Contains(this.Ctx.Input.URL(), "/api/sampletest_v/editpass/") { find = true fmt.Println("/api/sampletest_v/editpass/") break } if strings.Contains(this.Ctx.Input.URL(), "/api/workflow/historyimg/") { find = true fmt.Println("/api/workflow/historyimg/") break } } if !find { // 如果是登录操作不做验证 var err error this.User, err = this.ParseToken() if err != nil { // token非法或已失效 fmt.Println(err) this.Abort("401") } if this.User == nil { this.User = &models.UserInfo{} } svc := userRole.GetUserService(utils.DBE) usermodel := svc.GetUserInfoSelf(this.User.Username) this.User.Id = utils.ToStr(usermodel.Id) this.User.Realname = usermodel.Realname this.User.AccCode = usermodel.AccCode this.User.Description = usermodel.Description this.User.DepartmentId = usermodel.Departmentid this.User.IsCompanyUser = usermodel.IsCompanyUser this.User.Uint = usermodel.Unit // this.User.Superior = usermodel.Superior this.User.Roles = utils.ToStr(usermodel.Roleid) beego.Debug("User:", this.User) } if this.User == nil { fmt.Println("user is null") this.User = &models.UserInfo{} } } // ParseToken parse JWT token in http header. func (this *BaseController) ParseToken() (*models.UserInfo, error) { authString := this.Ctx.Input.Header("Authorization") beego.Debug("AuthString:", authString) kv := strings.Split(authString, " ") if len(kv) != 2 || kv[0] != "Bearer" { beego.Error("AuthString invalid:", authString) return nil, errors.New("AuthString invalid") } tokenString := kv[1] pUserinfo, err := models.CheckToken(tokenString) return pUserinfo, err } //获取waterdrop帐号密码 func (this *BaseController) GetuAndp() (string, string) { return "seedplatform", "seed@platformDASHOO.cn" //return "coldcloud", "CC@p1a2w3d4word" } //获取accode func (this *BaseController) GetAccode() string { return this.User.AccCode } //获取仓库Id //func (this *BaseController) GetHouseIdByLoginuser() int { // svc := material.GetMaterialService(utils.DBE) // return svc.GetHouseIdByDepartmentId(this.User.AccCode+MaterialStoreHouseName, this.User.DepartmentId) //} func (this *BaseController) GetupdbAndHost() (string, string, string, string) { return "coldcloud", "cc@1qaz2wsx", "coldcloud", "121.42.244.202:9086" } func (this *BaseController) GetPageInfoForm() (page PageInfo) { page.CurrentPage, _ = this.GetInt64("_currentPage") page.Size, _ = this.GetInt64("_size") return } //初始化redis func InitRedis() { poolnum := 5 addr := utils.Cfg.MustValue("redis", "addr") redis.InitRedis(poolnum, addr) } //打印相关 type PrintColType struct { JsonType string FieldIndex int FieldType string FieldSize int FieldName string Required bool } type PrintData struct { Data interface{} Cols []PrintColType } type PrintInfo struct { Alldata []PrintData `json:"alldata"` Vars []string `json:"vars"` } func AutoColType(source interface{}) (cols []PrintColType) { sObjT := reflect.TypeOf(source).Elem() for i := 0; i < sObjT.NumField(); i++ { fieldT := sObjT.Field(i) var fieldName, jsontype, datatype string = fieldT.Name, fieldT.Type.Kind().String(), "string" var fildsize = 2000 switch fieldT.Type.Kind() { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: fildsize = 0 datatype = "integer" case reflect.Float32, reflect.Float64: datatype = "float" fildsize = 0 } cols = append(cols, PrintColType{jsontype, i, datatype, fildsize, fieldName, false}) } return } //base64 解密 const ( base64Table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" ) var coder = base64.NewEncoding(base64Table) func Base64Decode(src string) string { co, _ := coder.DecodeString(src) return string(co) } func FloatPoint(value float64, bit int) float64 { value_str := strconv.FormatFloat(value, 'f', bit, 64) value_f64, _ := strconv.ParseFloat(value_str, 64) return value_f64 } //===========ln type DetailsInfo struct { Code int64 `json:"code"` Message string `json:"message,omitempty"` Item interface{} `json:"item,omitempty"` //数据 Types interface{} `json:"types,omitempty"` //检测类型 }