| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- package tmpzcgf
- import (
- "dashoo.cn/backend/api/business/oilsupplier/suppliercertsub"
- . "dashoo.cn/backend/api/mydb"
- "fmt"
- "strconv"
- "github.com/go-xorm/xorm"
- )
- type TmpCertEntity struct {
- SupplierCertId int `xorm:"INT"`
- SupplierTypeCode string `xorm:" VARCHAR"`
- AccessRange string `xorm:"VARCHAR"`
- }
- type SubClassId struct {
- Id int
- }
- type AllId struct {
- Id int
- }
- /** type TmpCertSession struct {
- MySessionBase
- }
- func GetTmpCertService(session *xorm.Session) *TmpCertSession {
- s := new(TmpCertSession)
- s.Session = session
- return s
- } */
- type TmpCertSession struct {
- MyServiceBase
- }
- func GetTmpCertService(xormEngine *xorm.Engine) *TmpCertSession {
- s := new(TmpCertSession)
- s.DBE = xormEngine
- return s
- }
- //获取tmp_zcgf所有Id
- func (s *TmpCertSession) GetAllId() []AllId {
- var ids []AllId
- sql := "SELECT id FROM tmp_zcgf"
- s.DBE.SQL(sql).Find(&ids)
- fmt.Println(sql)
- return ids
- }
- //从tmp_zcgf获取一条数据
- 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.DBE.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 subClassId SubClassId
- var tableName string
- switch supplierTypeCode {
- case "01":
- tableName = "OilGoodsAptitudeClass"
- case "02":
- tableName = "OilBasisBuild"
- case "03":
- tableName = "OilTechnologyServiceClass"
- }
- var sql = `SELECT id FROM ` + tableName + ` WHERE code = '` + code + `'`
- fmt.Println(sql)
- //a, err := s.Session.SQL(sql).Find(&subClassId)
- s.DBE.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_tmp ( SupplierCertId, SupplierTypeCode, SubClassId, CODE, NAME ) VALUES ('` + supplierCertId + `','` + supplierTypeCode + `','` + subClassId + `','` + code + `','` + name + `')`
- _, err := s.DBE.Query(sql)
- return err
- }
|