4
0

samplessourceService.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package samplessource
  2. import (
  3. //"fmt"
  4. "strconv"
  5. . "dashoo.cn/backend/api/mydb"
  6. "dashoo.cn/utils"
  7. . "dashoo.cn/utils/db"
  8. "github.com/go-xorm/xorm"
  9. )
  10. type SamplesSourceService struct {
  11. MyServiceBase
  12. }
  13. func GetSamplesSourceService(xormEngine *xorm.Engine) *SamplesSourceService {
  14. s := new(SamplesSourceService)
  15. s.DBE = xormEngine
  16. return s
  17. }
  18. //获取扩展字段列
  19. func (s *SamplesSourceService) QueryZBackList(acccode string) []String_Id {
  20. List := make([]String_Id, 0)
  21. sql := "select distinct FieldName Id from DonorsNoteItem where FieldNo>10 and AccCode ='" + acccode + "' order by Id "
  22. utils.DBE.Sql(sql).Find(&List)
  23. return List
  24. }
  25. //判断委托单号是否存在,返回总数
  26. func (s *SamplesSourceService) GetInnerNo(maintable string, where string) int64 {
  27. var sql string
  28. var total int64
  29. sql = `select count(*) from ` + maintable + ` where ` + where
  30. resultsSlice, err := s.DBE.Query(sql)
  31. LogError(err)
  32. if len(resultsSlice) > 0 {
  33. results := resultsSlice[0]
  34. for _, value := range results {
  35. total, err = strconv.ParseInt(string(value), 10, 64)
  36. LogError(err)
  37. break
  38. }
  39. }
  40. return total
  41. }
  42. //获取样本来源信息用于导出
  43. func (s *SamplesSourceService) GetSampleSourceInfo(donors, testmain, donorsdetail, where string) []DonorsInfoWithDetail {
  44. if where == "" {
  45. where = " 1=1 "
  46. }
  47. var sql string
  48. sql = `select * from ( select a.AccCode,a.Id,a.IdCard,a.InnerNo,a.Name,a.Sex,a.CompanyName,a.Duty,a.Birthday,a.Age,a.Telephone,a.Email,a.Nation,a.HomeAddress,a.IllnessName,a.Remark, b.InspectionNum, group_concat(c.PathologicalNum) as PathologicalNum
  49. from ` + donors + ` a
  50. left join ` + testmain + ` b on a.Id=b.SourceId
  51. left join ` + donorsdetail + ` c on c.ParentId=a.Id
  52. where ` + where + ` group by a.Id,a.IdCard,a.Name,b.InspectionNum) as m `
  53. List := make([]DonorsInfoWithDetail, 0)
  54. utils.DBE.Sql(sql).Find(&List)
  55. return List
  56. }