samplesapplyService.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package samplesapply
  2. import (
  3. "dashoo.cn/backend/api/controllers"
  4. "fmt"
  5. "strconv"
  6. . "dashoo.cn/backend/api/mydb"
  7. "dashoo.cn/utils"
  8. . "dashoo.cn/utils/db"
  9. "github.com/go-xorm/xorm"
  10. )
  11. type SamplesApplyService struct {
  12. MyServiceBase
  13. }
  14. func GetSamplesApplyService(xormEngine *xorm.Engine) *SamplesApplyService {
  15. s := new(SamplesApplyService)
  16. s.DBE = xormEngine
  17. return s
  18. }
  19. //关联容器获取存储位置
  20. func (s *SamplesApplyService) GetApplySamplesDetail(acccode string, pageIndex, itemsPerPage int64, order, where string) (int64, []Applydetailmodel) {
  21. var err error
  22. var total int64
  23. if order != "" {
  24. order = " order by " + order
  25. }
  26. //获取总记录数
  27. if where == "" {
  28. where = "1=1"
  29. }
  30. tbldetail := acccode + "SamplesApplyDetail"
  31. mainsam := acccode + "SamplesMain"
  32. sqlCount := " select count(*) from " + tbldetail + " where " + where
  33. fmt.Println(sqlCount)
  34. var sql string
  35. sql = ` select a.*,b.Code ECode,c.YStation ShelfY,d.XStation BoxX,d.YStation BoxY,e.SourceId,e.SourceName from ` + tbldetail + ` a
  36. left join Equipment b on a.EquipmentId = b.Id
  37. left join Shelf c on a.ShelfId = c.Id
  38. left join Box d on a.BoxId = d.Id
  39. left join ` + mainsam + ` e on e.SampleCode = a.SampleCode
  40. where ` + where + order + `
  41. limit ` + utils.ToStr((pageIndex-1)*itemsPerPage) + "," + utils.ToStr(itemsPerPage) + ""
  42. fmt.Println(sql)
  43. List := make([]Applydetailmodel, 0)
  44. utils.DBE.Sql(sql).Find(&List)
  45. resultsSlice, err := s.DBE.Query(sqlCount)
  46. LogError(err)
  47. if len(resultsSlice) > 0 {
  48. results := resultsSlice[0]
  49. for _, value := range results {
  50. total, err = strconv.ParseInt(string(value), 10, 64)
  51. LogError(err)
  52. break
  53. }
  54. }
  55. return total, List
  56. }
  57. func (s *SamplesApplyService) QueryApplySamplesDetail(acccode ,entryno string) ([]Applydetailmodel) {
  58. var err error
  59. var where string
  60. if where == "" {
  61. where = "1=1"
  62. }
  63. var sql string
  64. sql="SELECT t1.* FROM smkfjSamplesApplyDetail t1 , smkfjSamplesApply t2 WHERE t1.parentid=t2.id AND t2.entryno='"+entryno+"'"
  65. List := make([]Applydetailmodel, 0)
  66. utils.DBE.Sql(sql).Find(&List)
  67. LogError(err)
  68. return List
  69. }
  70. // 获取分页列表
  71. func (s *SamplesApplyService) GetApplyViewtList(pageIndex, itemsPerPage int64, applytable string, order, where string) (int64, []SamplesApply) {
  72. var err error
  73. var total int64
  74. //获取总记录数
  75. sqlCount := `select count(*) from ` + applytable + ` where ` + where
  76. var sql, limitstr string = "", ""
  77. if pageIndex > 0 {
  78. limitstr = ` limit ` + utils.ToStr((pageIndex-1)*itemsPerPage) + "," + utils.ToStr(itemsPerPage)
  79. }
  80. sql = `select * from ` + applytable + ` where ` + where + ` order by ` + order + limitstr
  81. List := make([]SamplesApply, 0)
  82. utils.DBE.Sql(sql).Find(&List)
  83. resultsSlice, err := s.DBE.Query(sqlCount)
  84. LogError(err)
  85. if len(resultsSlice) > 0 {
  86. results := resultsSlice[0]
  87. for _, value := range results {
  88. total, err = strconv.ParseInt(string(value), 10, 64)
  89. LogError(err)
  90. break
  91. }
  92. }
  93. fmt.Println("-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0", List)
  94. return total, List
  95. }
  96. func (s *SamplesApplyService) QuerySampleApplyDetailByBarCode(acccode string ,barcode string ) (entity SamplesApplyDetail){
  97. tableName:=acccode+controllers.SamplesApplyDetailName
  98. sql:="select a.* from "+tableName+" a where a.barcode= '"+barcode+"'"
  99. utils.DBE.Sql(sql).Get(&entity)
  100. return
  101. }
  102. func (s *SamplesApplyService) QuerySampleDetailByBarCode(acccode string ,barcode string ) (entity SamplesApplyDetail){
  103. tableName:=acccode+controllers.SamplesApplyDetailName
  104. sql:="select a.* from "+tableName+" a where a.barcode= '"+barcode+"'"
  105. utils.DBE.Sql(sql).Get(&entity)
  106. return
  107. }