4
0

base.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. // Controller基础类,所有Controller会继承此类
  2. package controllers
  3. import (
  4. "encoding/base64"
  5. "errors"
  6. "fmt"
  7. "reflect"
  8. "strconv"
  9. "strings"
  10. "github.com/astaxie/beego"
  11. "dashoo.cn/backend/api/business/material"
  12. "dashoo.cn/backend/api/models"
  13. "dashoo.cn/business2/userRole"
  14. "dashoo.cn/utils"
  15. "dashoo.cn/utils/redis"
  16. )
  17. // Operations about tokens
  18. type BaseController struct {
  19. beego.Controller
  20. User *models.UserInfo
  21. }
  22. type ErrorInfo struct {
  23. Code int64 `json:"code"`
  24. Message string `json:"message,omitempty"`
  25. }
  26. type ErrorDataInfo struct {
  27. Code int64 `json:"code"`
  28. Message string `json:"message,omitempty"`
  29. Item interface{} `json:"item,omitempty"` //数据
  30. }
  31. type DataEntryInfo struct {
  32. Code int64 `json:"code"`
  33. Message string `json:"message,omitempty"`
  34. Item interface{} `json:"item,omitempty"` //数据
  35. Info int `json:"info"`
  36. CurrentItemCount int64 `json:"currentItemCount,omitempty"` //结果集中的条目数目
  37. ItemsPerPage int64 `json:"itemsPerPage,omitempty"` //每页记录数目
  38. StartIndex int64 `json:"startIndex,omitempty"` //items中第一个条目的索引
  39. TotalItemsx int64 `json:"totalItemsx,omitempty"` //当前集合中可用的总条目数
  40. PageIndex int64 `json:"pageIndex,omitempty"` //条目的当前页索引
  41. TotalPages int64 `json:"totalPages,omitempty"` //当前结果集中的总页数
  42. }
  43. type Request struct {
  44. Status int `json:"status"`
  45. Id string `json:"id"`
  46. Message string `json:"message"`
  47. }
  48. type PageInfo struct {
  49. CurrentPage int64 `form:"_currentPage"`
  50. Size int64 `form:"_size"`
  51. }
  52. type Status struct {
  53. Status int `json:"status"`
  54. Id string `json:"id"`
  55. Message string `json:"message"`
  56. }
  57. type ValidformStruct struct {
  58. Info string `json:"info"`
  59. Status string `json:"status"`
  60. Items interface{} `json:"items,omitempty"` //数据列表
  61. }
  62. var (
  63. Nsqdtcpaddr string
  64. Nsqtopic string
  65. SalesAdmin string = "SalesAdmin" //分销商管理员
  66. ProjectSourse string = "coldchain"
  67. DonorstbName string = "DonorsInfo"
  68. AnimaltbName string = "AnimalInfo" //动物样本源信息表
  69. MicrobialtbName string = "MicrobialInfo" //微生物表
  70. DonorslogtbName string = "DonorsLog"
  71. DonorsNoteItemName string = "DonorsNoteItem"
  72. IsUpdating string = "false"
  73. EquipmentModelName string = "EquipMentModel" //设备型号管理表
  74. SamplesLogtbName string = "SamplesLog"
  75. SamplesMaintbName string = "SamplesMain"
  76. SamplesDetailtbName string = "SamplesDetail"
  77. SamplesBusstbName string = "SamplesBusiness"
  78. SamplesDetailFiletbName string = "SamplesFileDetail" // 归档表
  79. SamplesAttachmenttbName string = "SamplesAttachment" // 附件表
  80. SampleSearchTemplateName string = "SampleSearchTemplate" // 样本搜索模版表
  81. SampleTestMainName string = "SampleTestMain" //样本检测信息主表
  82. SampleTestDetailName string = "SampleTestDetail" //样本检测子表
  83. SamplesBookName string = "SamplesBook" //样本列表
  84. SamplesBookDetailName string = "SamplesBookDetail" //样本列表详情
  85. SampleTypeName string = "SampleType" //样本类型
  86. STypeNoteItemName string = "STypeNoteItem" //样本特有扩展
  87. ManagementPreparationName string = "ManagementPreparation" //制备管理
  88. PreparationStepDataName string = "PreparationStepData" //制备步骤
  89. PreparationStepDetailDataName string = "PreparationStepDetailData" //制备操作详情
  90. ManagementControlName string = "ManagementPreparation" //质控管理
  91. ControlStepDataName string = "PreparationStepData" //质控步骤
  92. ControlStepDetailDataName string = "PreparationStepDetailData" //质控操作详情
  93. BaseOperationLogName string = "Base_OperationLog" //操作日志表
  94. MaterialInfoName string = "MaterialInfo" //库存信息表
  95. MaterialBatchKCName string = "MaterialBatchKC" //物料批次库存信息表
  96. MaterialStoreHouseName string = "MaterialStoreHouse" //仓库列表
  97. MaterialCKDetailName string = "MaterialCKDetail" //出库管理子表
  98. MaterialCKHeadName string = "MaterialCKHead" //出库管理主表
  99. MaterialPDDetailName string = "MaterialPDDetail" //盘点子表
  100. MaterialPDHeadName string = "MaterialPDHead" //盘点管理主表
  101. CellBloodName string = "CellBlood" //采血表
  102. TestTemplateName string = "TestTemplate" //检测模板
  103. PreparationTemplateName string = "PreparationTemplate"
  104. PreparationTemplateStepName string = "PreparationTemplateStep"
  105. PreparationTemplateStepDetailName string = "PreparationTemplateStepDetail"
  106. CellSaveName string = "CellSave" //细胞存储表
  107. Coustom_InformationName string = "Coustom_Information" //客户信息表
  108. Order_InformationName string = "Order_Information" //订单信息表
  109. GeneProductName string = "GeneProduct" //基因治疗表
  110. CellProductName string = "CellProduct" //细胞制备表
  111. MaterialRKDetailName string = "MaterialRKDetail" //库存表
  112. MaterialRKHeadName string = "MaterialRKHead" //入库主表
  113. TestSampleName string = "TestSample" //检验样本
  114. TestSampleDetailName string = "TestSampleDetail" //检验样本详情表
  115. TestSampleInfoName string = "TestSampleInfo" //检验样本信息
  116. TestSampleRelationName string = "TestSampleRelation" //样本套餐-采样关系表
  117. TestTransferOrdersName string = "TestTransferOrders" //检验交接单
  118. TestInfoName string = "TestInfo" //检验单
  119. TestInfoDetailName string = "TestInfoDetail" //检验结果
  120. TestItemsListName string = "TestItemsList" // 检验项目内容
  121. TestListName string = "TestList" //检验项目主表
  122. TestListDetailName string = "TestListDetail" //检验项目详情表
  123. TestLaboratoryName string = "TestLaboratory" //检验实验室
  124. TestQualityControlName string = "TestQualityControl" //质控数据
  125. TestControlParametersName string = "TestControlParameters" //质控品参数
  126. TestControlParametersDetailName string = "TestControlParametersDetail" //质控品详情
  127. AccusationParametersName string = "AccusationParameters"
  128. TestApplicationName string = "TestApplication" //检验申请单
  129. TestPackageCategoryName string = "TestPackageCategory" // 类别
  130. TestPrintTemplateName string = "TestPrintTemplate" //打印模板
  131. TestPackageName string = "TestPackage" //检验套餐
  132. TestPackageItemsName string = "TestPackageItems" //检验套餐项目明细
  133. InstrumentName string = "Instrument"
  134. Base_ItemTreeDetailsName string = "Base_ItemTreeDetails" //数据字典 文档结构
  135. Base_ItemDetailsName string = "Base_ItemDetails" //数据字典
  136. InstrumenMaintainLogName string = "InstrumenMaintainLog" //质量管理
  137. InstrumenstateName string = "Instrumenstate" //设备自动发送信息
  138. InstrumenRunRecordName string = "InstrumenRunRecord" //设备运行信息
  139. CustomerName string = "Customer" //客户原始信息内容
  140. CellsContractName string = "CellsContract" //合同管理
  141. CellsContractDetailName string = "CellsContractDetail" //合同详情
  142. CellsCollectionName string = "CellsCollection" //样本采集
  143. CellsCollectionDetailName string = "CellsCollectionDetail" //样本采集子表
  144. CellsCollectionSensorsName string = "CellsCollectionSensors" //采集单Sensor表
  145. CellsPrepareTemplateName string = "CellsPrepareTemplate" //Cells制备模板主表
  146. CellsPrepareTemplateStepName string = "CellsPrepareTemplateStep" //Cells制备模板步骤表
  147. CellsPrepareTemplateStepDetailName string = "CellsPrepareTemplateStepDetail" //Cells制备模板步骤详情表
  148. CellsPreparationName string = "CellsPreparation" //Cells制备表
  149. CellsPreparationInfoName string = "CellsPreparationInfo"
  150. CellsPreparationInfoDetailName string = "CellsPreparationInfoDetail"
  151. CellsPreparationSamplesName string = "CellsPreparationSamples" //Cells制备样本信息表
  152. CellsPreparationInfoDetailAttachmentName string = "CellsPreparationInfoDetailAttachment" //Cells制备附件表
  153. DonorsInfoAttachmentName string = "DonorsInfoAttachment" //样本采集附件
  154. InstrumenMaintainLogAttachmentName string = "InstrumenMaintainLogAttachment" //质量管理附件
  155. CellsContractAttachmentName string = "CellsContractAttachment" //合同管理附件
  156. CellsProductDeliveryName string = "CellsProductDelivery" //产品交付
  157. CellsProductDeliverySampleName string = "CellsProductDeliverySample" //交付详情
  158. CellsProductDeliveryAttachmentName string = "CellsProductDeliveryAttachment" //产品交付附件
  159. CellsPreparationTraceName string = "CellsPreparationTrace" //制备信息溯源表
  160. ControlTemplateName string = "ControlTemplate" //Cells质控备模板主表
  161. ControlTemplateStepName string = "ControlTemplateStep" //Cells质控模板步骤表
  162. ControlTemplateStepDetailName string = "ControlTemplateStepDetail" //Cells质控模板步骤详情表
  163. ControlName string = "Control" //Cells质控表
  164. ControlInfoName string = "ControlInfo"
  165. ControlInfoDetailName string = "ControlInfoDetail"
  166. ControlInfoDetailAttachmentName string = "ControlInfoDetailAttachment"
  167. ControlTraceName string = "ControlTrace" //制备信息溯源表
  168. DocumentInfoName string = "DocumentInfo" //文档
  169. DocumentHistoryName string = "DocumentHistory" //历史文档
  170. SamplesCustomorName string = "SamplesCustomor" //样本库客户信息表
  171. SamplesCommunicationName string = "SamplesCommunication" //样本库客户交流记录表
  172. SamplesProtocolName string = "SamplesProtocol" //样本库协议表
  173. SamplesProtocolDetailName string = "SamplesProtocolDetail" //样本库协议执行信息表
  174. DonorsDetailName string = "DonorsDetail" //样本库样本来源详情表
  175. ShelfName string = "Shelf" //设备冻存架表
  176. BoxName string = "Box" //设备冻存盒表
  177. GroupDetailName string = "GroupDetail" //样本库分组表
  178. SamplesApplyName string = "SamplesApply" //出入库申请表
  179. SamplesApplyDetailName string = "SamplesApplyDetail" //出入库申请详情表
  180. SamplesRecordName string = "SamplesRecord" //样本操作记录表
  181. LimsEntrustMainName string = "LimsEntrustMain" //LIMS委托管理
  182. TestPackageTypesName string = "TestPackageTypes" // LIMS检验类型
  183. LimsSampleTypeName string = "LimsSampleType" // LIMS样品类型
  184. LimsDocTemplateName string = "LimsDocTemplate" // lims模板
  185. LimsDocTemplateDetailName string = "LimsDocTemplateDetail" // lims模板详情
  186. LimsTaskBalanceName string = "LimsTaskBalance" // 任务分配表
  187. LimsDeliverName string = "LimsDeliver" //样品交接表
  188. LimsDeliverDetailName string = "LimsDeliverDetail" //样品交接详情表
  189. LimsPreparationName string = "LimsPreparation" //样品制备表
  190. LimsCreateReportName string = "LimsCreateReport" //报告生成
  191. LimsDateEntryName string = "LimsDateEntry" //数据录入
  192. LimsDocHistoryName string = "LimsDocHistory" //数据录入文档历史
  193. LimsEntrustSampleName string = "LimsEntrustSample" //委托样品明细表
  194. LimsEntrustSampleTypeName string = "LimsEntrustSampleType" //详情表
  195. LimsReportHuxfName string = "LimsReportHuxf" //呼吸阀检测数据记录表
  196. LimsReportYeyaqfName string = "LimsReportYeyaqf" //液压安全阀检测数据记录表
  197. LimsReportZuhqName string = "LimsReportZuhq" //阻火器检测数据记录表
  198. LimsReportElecGroundName string = "LimsReportElecGround" //电气接地装置检测原始记录
  199. LimsReportLeakProtectName string = "LimsReportLeakProtect" //漏电保护器检测数据记录表
  200. LimsReportEquipotentName string = "LimsReportEquipotent" //防雷装置(等电位)检测原始记录
  201. LimsReportLightProtectName string = "LimsReportLightProtect" //防雷装置检测原始记录
  202. LimsReportAmmeterName string = "LimsReportAmmeter" //电流表检测原始记录
  203. LimsReportKqpmName string = "LimsReportAirFoamGenerator" //空气泡沫产生器检测数据记录表
  204. LimsReportNoBeamPumpingUnitName string = "LimsReportNoBeamPumpingUnit" //无游梁式抽油机检测数据记录表
  205. LimsReportBeamPumpingUnitName string = "LimsReportBeamPumpingUnits" //游梁式抽油机检测数据记录表
  206. LimsDrillingDailyName string = "LimsDrillingDaily" //工程监督中心钻井工程监督日报
  207. LimsOilTestingDailyName string = "LimsOilTestingDaily" //试油监督日报表
  208. LimsReportSignName string = "LimsReportSign" //报告签发
  209. LimsReportHistoryName string = "LimsReportHistory" //报告历史
  210. LimsCustomerpositionName string = "LimsCustomerPosition"
  211. LimsPressureLeakName string = "LimsPressureLeak" //阻火器压力损失表
  212. LimsSpecifyStandardName string = "LimsSpecifyStandard" //Lims规格型号标准
  213. BaseUserName string = "Base_User" //用户表
  214. UserQualificationName string = "UserQualification" //用户资质表
  215. LimsInstrumentGroup string = "LimsInstrumentGroup" // 检测仪器关联
  216. OilAuditSettingName string = "Base_OilAuditSetting" // 单位审批步骤自定义配置
  217. )
  218. //分页信息及数据
  219. type DataInfo struct {
  220. CurrentItemCount int64 `json:"currentItemCount,omitempty"` //结果集中的条目数目
  221. ItemsPerPage int64 `json:"itemsPerPage,omitempty"` //每页记录数目
  222. StartIndex int64 `json:"startIndex,omitempty"` //items中第一个条目的索引
  223. TotalItemsx int64 `json:"totalItemsx,omitempty"` //当前集合中可用的总条目数
  224. PageIndex int64 `json:"pageIndex,omitempty"` //条目的当前页索引
  225. TotalPages int64 `json:"totalPages,omitempty"` //当前结果集中的总页数
  226. Items interface{} `json:"items,omitempty"` //数据列表
  227. }
  228. //下拉idname
  229. type SelectIdNameModel struct {
  230. Id int `json:"id"`
  231. Name string `json:"name"`
  232. }
  233. func (this *BaseController) Prepare() {
  234. find := false
  235. // 不需要做登录验证的页面
  236. urls := []string{"/api/auth", "/api/users/registemanage", "/printservice",
  237. "/api/webinterface/preparelist", "/api/webinterface/prepareinfo",
  238. "/api/sampletest_v/sampletest", "/api/sampletest_v/getpass", "/api/sampletest_v/editpass/",
  239. "/api/sampletest_v/donorsdetail", "/api/sampletest_v/testdetail", "/api/uploads/samplesinput", "/api/doctemplate_onlyoffice/callback", "/api/doctemplate_onlyoffice/viewcallback", "/api/limsupload/usersignimg",
  240. "/api/uploads/samplestypeimg", "/api/limsdataentry/historyimg/"}
  241. for _, v := range urls {
  242. fmt.Println("**this.Ctx.Input.URL()**", this.Ctx.Input.URL())
  243. if this.Ctx.Input.URL() == v {
  244. find = true
  245. break
  246. }
  247. if strings.Contains(this.Ctx.Input.URL(), "/api/sampletest_v/editpass/") {
  248. find = true
  249. fmt.Println("/api/sampletest_v/editpass/")
  250. break
  251. }
  252. if strings.Contains(this.Ctx.Input.URL(), "/api/limsdataentry/historyimg/") {
  253. find = true
  254. fmt.Println("/api/limsdataentry/historyimg/")
  255. break
  256. }
  257. }
  258. if !find { // 如果是登录操作不做验证
  259. var err error
  260. this.User, err = this.ParseToken()
  261. if err != nil { // token非法或已失效
  262. fmt.Println(err)
  263. this.Abort("401")
  264. }
  265. if this.User == nil {
  266. this.User = &models.UserInfo{}
  267. }
  268. svc := userRole.GetUserService(utils.DBE)
  269. usermodel := svc.GetUserInfoSelf(this.User.Username)
  270. this.User.Id = utils.ToStr(usermodel.Id)
  271. this.User.Realname = usermodel.Realname
  272. this.User.AccCode = usermodel.AccCode
  273. this.User.Description = usermodel.Description
  274. this.User.DepartmentId = usermodel.Departmentid
  275. this.User.Roles = utils.ToStr(usermodel.Roleid)
  276. beego.Debug("User:", this.User)
  277. }
  278. if this.User == nil {
  279. fmt.Println("user is null")
  280. this.User = &models.UserInfo{}
  281. }
  282. }
  283. // ParseToken parse JWT token in http header.
  284. func (this *BaseController) ParseToken() (*models.UserInfo, error) {
  285. authString := this.Ctx.Input.Header("Authorization")
  286. beego.Debug("AuthString:", authString)
  287. kv := strings.Split(authString, " ")
  288. if len(kv) != 2 || kv[0] != "Bearer" {
  289. beego.Error("AuthString invalid:", authString)
  290. return nil, errors.New("AuthString invalid")
  291. }
  292. tokenString := kv[1]
  293. pUserinfo, err := models.CheckToken(tokenString)
  294. return pUserinfo, err
  295. }
  296. //获取waterdrop帐号密码
  297. func (this *BaseController) GetuAndp() (string, string) {
  298. return "seedplatform", "seed@platformDASHOO.cn"
  299. //return "coldcloud", "CC@p1a2w3d4word"
  300. }
  301. //获取accode
  302. func (this *BaseController) GetAccode() string {
  303. return this.User.AccCode
  304. }
  305. //获取仓库Id
  306. func (this *BaseController) GetHouseIdByLoginuser() int {
  307. svc := material.GetMaterialService(utils.DBE)
  308. return svc.GetHouseIdByDepartmentId(this.User.AccCode+MaterialStoreHouseName, this.User.DepartmentId)
  309. }
  310. func (this *BaseController) GetupdbAndHost() (string, string, string, string) {
  311. return "coldcloud", "cc@1qaz2wsx", "coldcloud", "121.42.244.202:9086"
  312. }
  313. func (this *BaseController) GetPageInfoForm() (page PageInfo) {
  314. page.CurrentPage, _ = this.GetInt64("_currentPage")
  315. page.Size, _ = this.GetInt64("_size")
  316. return
  317. }
  318. //初始化redis
  319. func InitRedis() {
  320. poolnum := 5
  321. addr := utils.Cfg.MustValue("redis", "addr")
  322. redis.InitRedis(poolnum, addr)
  323. }
  324. //打印相关
  325. type PrintColType struct {
  326. JsonType string
  327. FieldIndex int
  328. FieldType string
  329. FieldSize int
  330. FieldName string
  331. Required bool
  332. }
  333. type PrintData struct {
  334. Data interface{}
  335. Cols []PrintColType
  336. }
  337. type PrintInfo struct {
  338. Alldata []PrintData `json:"alldata"`
  339. Vars []string `json:"vars"`
  340. }
  341. func AutoColType(source interface{}) (cols []PrintColType) {
  342. sObjT := reflect.TypeOf(source).Elem()
  343. for i := 0; i < sObjT.NumField(); i++ {
  344. fieldT := sObjT.Field(i)
  345. var fieldName, jsontype, datatype string = fieldT.Name, fieldT.Type.Kind().String(), "string"
  346. var fildsize = 2000
  347. switch fieldT.Type.Kind() {
  348. case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
  349. fildsize = 0
  350. datatype = "integer"
  351. case reflect.Float32, reflect.Float64:
  352. datatype = "float"
  353. fildsize = 0
  354. }
  355. cols = append(cols, PrintColType{jsontype, i, datatype, fildsize, fieldName, false})
  356. }
  357. return
  358. }
  359. //base64 解密
  360. const (
  361. base64Table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
  362. )
  363. var coder = base64.NewEncoding(base64Table)
  364. func Base64Decode(src string) string {
  365. co, _ := coder.DecodeString(src)
  366. return string(co)
  367. }
  368. func FloatPoint(value float64, bit int) float64 {
  369. value_str := strconv.FormatFloat(value, 'f', bit, 64)
  370. value_f64, _ := strconv.ParseFloat(value_str, 64)
  371. return value_f64
  372. }
  373. //===========ln
  374. type DetailsInfo struct {
  375. Code int64 `json:"code"`
  376. Message string `json:"message,omitempty"`
  377. Item interface{} `json:"item,omitempty"` //数据
  378. Types interface{} `json:"types,omitempty"` //检测类型
  379. }