tmpCertSubSession.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package tmpzcgf
  2. import (
  3. "dashoo.cn/backend/api/business/oilsupplier/suppliercertsub"
  4. . "dashoo.cn/backend/api/mydb"
  5. "fmt"
  6. "strconv"
  7. "github.com/go-xorm/xorm"
  8. )
  9. type TmpCertEntity struct {
  10. SupplierCertId int `xorm:"INT"`
  11. SupplierTypeCode string `xorm:" VARCHAR"`
  12. AccessRange string `xorm:"VARCHAR"`
  13. }
  14. type SubClassId struct {
  15. Id int
  16. }
  17. type AllId struct {
  18. Id int
  19. }
  20. /** type TmpCertSession struct {
  21. MySessionBase
  22. }
  23. func GetTmpCertService(session *xorm.Session) *TmpCertSession {
  24. s := new(TmpCertSession)
  25. s.Session = session
  26. return s
  27. } */
  28. type TmpCertSession struct {
  29. MyServiceBase
  30. }
  31. func GetTmpCertService(xormEngine *xorm.Engine) *TmpCertSession {
  32. s := new(TmpCertSession)
  33. s.DBE = xormEngine
  34. return s
  35. }
  36. //获取tmp_zcgf所有Id
  37. func (s *TmpCertSession) GetAllId() []AllId {
  38. var ids []AllId
  39. sql := "SELECT id FROM tmp_zcgf"
  40. s.DBE.SQL(sql).Find(&ids)
  41. fmt.Println(sql)
  42. return ids
  43. }
  44. //从tmp_zcgf获取一条数据
  45. func (s *TmpCertSession) SelectOne(id int) TmpCertEntity {
  46. var one []TmpCertEntity
  47. var result TmpCertEntity
  48. //var result TmpCertEntity
  49. //var resultsSlice []map[string][]byte
  50. strId := strconv.Itoa(id)
  51. //sql := "SELECT a.准入范围 as AccessRange, c.id as SupplierCertId,c.SupplierTypeCode as SupplierTypeCode FROM tmp_zcgf a LEFT JOIN oilsupplier b ON a.企业名称 = b.SupplierName "+
  52. // "JOIN oilsuppliercert c ON b.id = c.SupplierId AND a.准入类别 = c.SupplierTypeName WHERE a.id =" +strId
  53. ///
  54. //sql := "select AccessRange, SupplierTypeCode, SupplierCertId FROM (SELECT a.准入范围 AccessRange, c.id SupplierCertId,c.SupplierTypeCode SupplierTypeCode FROM tmp_zcgf a LEFT JOIN oilsupplier b ON a.企业名称 = b.SupplierName JOIN oilsuppliercert c ON b.id = c.SupplierId AND a.准入类别 = c.SupplierTypeName WHERE a.id =" + strId + ") TmpCertEntity"
  55. //LogError(err)
  56. //sql := "SELECT id, 国家 country , 级别 class FROM tmp_zcgf where id=8803"
  57. //sql := "select AccessRange, SupplierTypeCode, SupplierCertId FROM (SELECT a.准入范围 AccessRange, c.id SupplierCertId,c.SupplierTypeCode SupplierTypeCode FROM tmp_zcgf a JOIN oilsupplier b ON a.企业名称 = b.SupplierName JOIN oilsuppliercert c ON b.id = c.SupplierId AND a.准入类别 = c.SupplierTypeName WHERE a.id =8830) TmpCertEntity"
  58. sql := "SELECT tmp_zcgf.`准入范围` AS AccessRange, OilSupplierCert.SupplierTypeCode, OilSupplierCert.id SupplierCertId FROM OilSupplier INNER JOIN OilSupplierCert ON OilSupplier.Id = OilSupplierCert.SupplierId INNER JOIN tmp_zcgf ON tmp_zcgf.`企业名称` = OilSupplier.supplierName AND tmp_zcgf.`准入类别` = OilSupplierCert.SupplierTypeName WHERE tmp_zcgf.ID = " + strId
  59. fmt.Println(sql)
  60. //s.Session.SQL(sql).Get(&one)
  61. s.DBE.SQL(sql).Find(&one)
  62. if len(one) > 0 {
  63. result = one[0]
  64. }
  65. //fmt.Println("123",result)
  66. // results := resultsSlice[0]
  67. // one.AccessRange = string(results["AccessRange"])
  68. // one.SupplierCertId = results["SupplierCertId"]
  69. // one.SupplierTypeCode = string(results["SupplierTypeCode"])
  70. //s.Session.Table("TmpCertEntity").SQL(sql).Find(&one)
  71. return result
  72. }
  73. //获取subClassId
  74. func (s *TmpCertSession) GetSubClassId(code string, supplierTypeCode string) int {
  75. //var subClassName
  76. var subClassId SubClassId
  77. var tableName string
  78. switch supplierTypeCode {
  79. case "01":
  80. tableName = "OilGoodsAptitudeClass"
  81. case "02":
  82. tableName = "OilBasisBuild"
  83. case "03":
  84. tableName = "OilTechnologyServiceClass"
  85. }
  86. var sql = `SELECT id FROM ` + tableName + ` WHERE code = '` + code + `'`
  87. fmt.Println(sql)
  88. //a, err := s.Session.SQL(sql).Find(&subClassId)
  89. s.DBE.SQL(sql).Get(&subClassId)
  90. // fmt.Println(result)
  91. // if err!=nil{
  92. // fmt.Println(err)
  93. // }
  94. sub := subClassId.Id
  95. return sub
  96. //a := s.Session.SQL(sql).Find(&subClassId)
  97. //fmt.Println("a:",&a)
  98. //fmt.Println("subclassid:",subClassId)
  99. }
  100. func (s *TmpCertSession) InsertSupplierCertSub(sub suppliercertsub.OilSupplierCertSub) error {
  101. //var supplierId = string(sub.SupplierId)
  102. var supplierCertId = string(sub.SupplierCertId)
  103. var supplierTypeCode = sub.SupplierTypeCode
  104. var subClassId = string(sub.SubClassId)
  105. var code = sub.Code
  106. var name = sub.Name
  107. sql := `INSERT INTO OilSupplierCertSub_tmp ( SupplierCertId, SupplierTypeCode, SubClassId, CODE, NAME ) VALUES ('` + supplierCertId + `','` + supplierTypeCode + `','` + subClassId + `','` + code + `','` + name + `')`
  108. _, err := s.DBE.Query(sql)
  109. return err
  110. }