|
|
@@ -3,9 +3,10 @@ package tmpzcgf
|
|
|
import (
|
|
|
"dashoo.cn/backend/api/business/oilsupplier/suppliercertsub"
|
|
|
. "dashoo.cn/backend/api/mydb"
|
|
|
- "github.com/go-xorm/xorm"
|
|
|
-
|
|
|
|
|
|
+ "strconv"
|
|
|
+ "fmt"
|
|
|
+ "github.com/go-xorm/xorm"
|
|
|
)
|
|
|
|
|
|
type TmpCertSession struct {
|
|
|
@@ -13,17 +14,16 @@ type TmpCertSession struct {
|
|
|
}
|
|
|
|
|
|
type TmpCertEntity struct {
|
|
|
-
|
|
|
- SupplierCertId int "xorm:"
|
|
|
- SupplierTypeCode string
|
|
|
- AccessRange string
|
|
|
+ SupplierCertId int `xorm:"INT"`
|
|
|
+ SupplierTypeCode string `xorm:" VARCHAR"`
|
|
|
+ AccessRange string `xorm:"VARCHAR"`
|
|
|
}
|
|
|
|
|
|
-type SubClassId struct{
|
|
|
- id int
|
|
|
+type SubClassId struct {
|
|
|
+ Id int
|
|
|
}
|
|
|
|
|
|
-type AllId struct{
|
|
|
+type AllId struct {
|
|
|
Id int
|
|
|
}
|
|
|
|
|
|
@@ -34,69 +34,83 @@ func GetTmpCertService(session *xorm.Session) *TmpCertSession {
|
|
|
}
|
|
|
|
|
|
//获取tmp_zcgf所有Id
|
|
|
-func (s *TmpCertSession) GetAllId() []AllId{
|
|
|
+func (s *TmpCertSession) GetAllId() []AllId {
|
|
|
var ids []AllId
|
|
|
- sql := `SELECT
|
|
|
- id
|
|
|
- FROM
|
|
|
- tmp_zcgf`
|
|
|
+ sql := "SELECT id FROM tmp_zcgf"
|
|
|
s.Session.SQL(sql).Find(&ids)
|
|
|
+ fmt.Println(sql)
|
|
|
return ids
|
|
|
}
|
|
|
|
|
|
//从tmp_zcgf获取一条数据
|
|
|
-func (s *TmpCertSession) SelectOne(id int) TmpCertEntity {
|
|
|
- var one TmpCertEntity
|
|
|
- sql := `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 =` + string(id)
|
|
|
- s.Session.SQL(sql).Find(&one)
|
|
|
- return one
|
|
|
+func (s *TmpCertSession) SelectOne(id int) TmpCertEntity{
|
|
|
+ var one []TmpCertEntity
|
|
|
+ var result TmpCertEntity
|
|
|
+ //var result TmpCertEntity
|
|
|
+ //var resultsSlice []map[string][]byte
|
|
|
+ strId := strconv.Itoa(id)
|
|
|
+ //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 "+
|
|
|
+ // "JOIN oilsuppliercert c ON b.id = c.SupplierId AND a.准入类别 = c.SupplierTypeName WHERE a.id =" +strId
|
|
|
+ ///
|
|
|
+ //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"
|
|
|
+ //LogError(err)
|
|
|
+ //sql := "SELECT id, 国家 country , 级别 class FROM tmp_zcgf where id=8803"
|
|
|
+ //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"
|
|
|
+ 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
|
|
|
+ fmt.Println(sql)
|
|
|
+ //s.Session.SQL(sql).Get(&one)
|
|
|
+ s.Session.SQL(sql).Find(&one)
|
|
|
+ if len(one)>0 {
|
|
|
+ result = one[0]
|
|
|
+ }
|
|
|
+ //fmt.Println("123",result)
|
|
|
+
|
|
|
+ // results := resultsSlice[0]
|
|
|
+ // one.AccessRange = string(results["AccessRange"])
|
|
|
+ // one.SupplierCertId = results["SupplierCertId"]
|
|
|
+ // one.SupplierTypeCode = string(results["SupplierTypeCode"])
|
|
|
+ //s.Session.Table("TmpCertEntity").SQL(sql).Find(&one)
|
|
|
+ return result
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//获取subClassId
|
|
|
func (s *TmpCertSession) GetSubClassId(code string, supplierTypeCode string) int{
|
|
|
//var subClassName
|
|
|
- var id SubClassId
|
|
|
+ var subClassId SubClassId
|
|
|
var tableName string
|
|
|
- switch supplierTypeCode{
|
|
|
+ switch supplierTypeCode {
|
|
|
case "01":
|
|
|
tableName = "OilGoodsAptitudeClass"
|
|
|
- //subClassName = []goodsaptitudeclass.OilGoodsAptitudeClass
|
|
|
case "02":
|
|
|
tableName = "OilBasisBuild"
|
|
|
- //subClassName = []basisbuild.OilBasisBuild
|
|
|
case "03":
|
|
|
tableName = "OilTechnologyServiceClass"
|
|
|
- //subClassName = []technologyserviceclass.OilTechnologyServiceClass
|
|
|
}
|
|
|
- var sql = `SELECT id FROM`+tableName+`WHERE 1 = 1 AND code =`+ code
|
|
|
-
|
|
|
- s.Session.SQL(sql).Find(&id)
|
|
|
- return id.id
|
|
|
-
|
|
|
+ var sql = `SELECT id FROM ` + tableName + ` WHERE code = '` + code+ `'`
|
|
|
+ fmt.Println(sql)
|
|
|
+ //a, err := s.Session.SQL(sql).Find(&subClassId)
|
|
|
+ s.Session.SQL(sql).Get(&subClassId)
|
|
|
+
|
|
|
+ // fmt.Println(result)
|
|
|
+ // if err!=nil{
|
|
|
+ // fmt.Println(err)
|
|
|
+ // }
|
|
|
+ sub := subClassId.Id
|
|
|
+ return sub
|
|
|
+ //a := s.Session.SQL(sql).Find(&subClassId)
|
|
|
+ //fmt.Println("a:",&a)
|
|
|
+ //fmt.Println("subclassid:",subClassId)
|
|
|
}
|
|
|
|
|
|
func (s *TmpCertSession) InsertSupplierCertSub(sub suppliercertsub.OilSupplierCertSub) error {
|
|
|
- var supplierId = string(sub.SupplierId)
|
|
|
- var supplierCertId = string(sub.SupplierCertId)
|
|
|
- var supplierTypeCode = sub.SupplierTypeCode
|
|
|
- var subClassId = string(sub.SubClassId)
|
|
|
- var code = sub.Code
|
|
|
- var name = sub.Name
|
|
|
- sql := `INSERT INTO OilSupplierCertSub ( SupplierId, SupplierCertId, SupplierTypeCode, SubClassId, CODE, NAME )
|
|
|
- VALUES ( ’` + supplierId+`‘,‘`+supplierCertId+`','`+supplierTypeCode+`','`+subClassId+`','`+code+`','`+name+`')`
|
|
|
-
|
|
|
- _,err := s.Session.Query(sql)
|
|
|
+ //var supplierId = string(sub.SupplierId)
|
|
|
+ var supplierCertId = string(sub.SupplierCertId)
|
|
|
+ var supplierTypeCode = sub.SupplierTypeCode
|
|
|
+ var subClassId = string(sub.SubClassId)
|
|
|
+ var code = sub.Code
|
|
|
+ var name = sub.Name
|
|
|
+ sql := `INSERT INTO OilSupplierCertSub_tmp ( SupplierCertId, SupplierTypeCode, SubClassId, CODE, NAME ) VALUES ('` + supplierCertId + `','` + supplierTypeCode + `','` + subClassId + `','` + code + `','` + name + `')`
|
|
|
+
|
|
|
+ _, err := s.Session.Query(sql)
|
|
|
return err
|
|
|
}
|
|
|
-
|