Bläddra i källkod

导入历史数据

yuedefeng 5 år sedan
förälder
incheckning
763b49e815

+ 12 - 12
src/dashoo.cn/backend/api/business/tmpzcgf/tmpzcgfSession.go

@@ -123,7 +123,7 @@ func (s *TmpzcgtSession) InsertSupplierCert() error {
 }
 
 func (s *TmpzcgtSession) UpdateSupplierCert() error {
-	sql := "UPDATE `OilSupplierCert` b SET b.SupplierId=(SELECT Id FROM OilSupplier a WHERE a.SupplierName = b.OutsideFlog)"
+	sql := "UPDATE `OilSupplierCert` b SET b.SupplierId=IFNULL((SELECT a.Id FROM OilSupplier a WHERE a.SupplierName = b.OutsideFlog AND a.Id IS NOT NULL  limit 1), 0)"
 	_, err := s.DBE.Query(sql)
 	return err
 }
@@ -271,8 +271,8 @@ func (s *TmpzcgtSession) InsertCertSub() error {
 }
 
 func (s *TmpzcgtSession) UpdateCertSub(where string) error {
-	sql := "UPDATE OilSupplierCertSub b SET b.SupplierId = (SELECT a.SupplierId FROM OilSupplierCert a WHERE a.GfId =b.OldId AND a.SupplierTypeCode = b.SupplierTypeCode )," +
-		"b.SupplierCertId = (SELECT a.Id FROM OilSupplierCert a WHERE a.GfId =b.OldId AND a.SupplierTypeCode = b.SupplierTypeCode ) " + where
+	sql := "UPDATE OilSupplierCertSub b SET b.SupplierId = IFNULL((SELECT a.SupplierId FROM OilSupplierCert a WHERE a.GfId =b.OldId AND a.SupplierTypeCode = b.SupplierTypeCode AND a.SupplierId IS NOT NULL limit 1 ), 0)," +
+		"b.SupplierCertId = (SELECT a.Id FROM OilSupplierCert a WHERE a.GfId =b.OldId AND a.SupplierTypeCode = b.SupplierTypeCode limit 1) " + where
 	_, err := s.DBE.Query(sql)
 	return err
 }
@@ -347,17 +347,17 @@ func (s *TmpzcgtSession) UpdateOilInfoChange() error {
 
 func (s *TmpzcgtSession) UpOilSupplierCertAppend() error {
 	sql := "UPDATE OilSupplierCertAppend b SET " +
-		"b.SupplierId = (SELECT a.`SupplierId` FROM OilSupplierCert a WHERE a.`GfId` = b.OldId AND a.SupplierTypeCode = b.AppendType), " +
-		"b.SupplierCertId = (SELECT a.`Id` FROM OilSupplierCert a WHERE a.`GfId` = b.OldId AND a.SupplierTypeCode = b.AppendType) "
+		"b.SupplierId = IFNULL((SELECT a.`SupplierId` FROM OilSupplierCert a WHERE a.`GfId` = b.OldId AND a.SupplierTypeCode = b.AppendType limit 1), 0), " +
+		"b.SupplierCertId = IFNULL((SELECT a.`Id` FROM OilSupplierCert a WHERE a.`GfId` = b.OldId AND a.SupplierTypeCode = b.AppendType limit 1), 0) "
 	_, err := s.DBE.Query(sql)
 	return err
 }
 
 func (s *TmpzcgtSession) UpdateCertSubIsType2(where string) error {
 	sql := "UPDATE OilSupplierCertSub b SET " +
-		"b.SupplierId = (SELECT a.`SupplierId` FROM OilSupplierCertAppend a WHERE a.`OldId` = b.OldId AND a.AppendType = b.SupplierTypeCode AND a.ApplyDate = b.CreateOn ), " +
-		"b.SupplierCertId = (SELECT a.`SupplierCertId` FROM OilSupplierCertAppend a WHERE a.`OldId` = b.OldId AND a.AppendType = b.SupplierTypeCode AND a.ApplyDate = b.CreateOn ), " +
-		"b.SupplierCertAppendId = (SELECT a.`Id` FROM OilSupplierCertAppend a WHERE a.`OldId` = b.OldId AND a.AppendType = b.SupplierTypeCode AND a.ApplyDate = b.CreateOn ) " +
+		"b.SupplierId = IFNULL((SELECT a.`SupplierId` FROM OilSupplierCertAppend a WHERE a.`OldId` = b.OldId AND a.AppendType = b.SupplierTypeCode AND a.ApplyDate = b.CreateOn limit 1), 0), " +
+		"b.SupplierCertId = IFNULL((SELECT a.`SupplierCertId` FROM OilSupplierCertAppend a WHERE a.`OldId` = b.OldId AND a.AppendType = b.SupplierTypeCode AND a.ApplyDate = b.CreateOn limit 1), 0), " +
+		"b.SupplierCertAppendId = IFNULL((SELECT a.`Id` FROM OilSupplierCertAppend a WHERE a.`OldId` = b.OldId AND a.AppendType = b.SupplierTypeCode AND a.ApplyDate = b.CreateOn limit 1), 0) " +
 		where
 	_, err := s.DBE.Query(sql)
 	return err
@@ -365,9 +365,9 @@ func (s *TmpzcgtSession) UpdateCertSubIsType2(where string) error {
 
 // 导入资质名称
 func (s *TmpzcgtSession) InsertFileName() error {
-	sql := "INSERT INTO `OilSupplierFile` (Remark, NeedFileType, OtherRemark, SupplierTypeCode,CreateBy) " +
-		"SELECT z.企业名称 AS Remark ,f.类别 AS NeedFileType, f.说明 AS OtherRemark, " +
-		"( CASE 准入类别 WHEN '物资类' THEN '01' WHEN '基建类' THEN '02' WHEN '服务类' THEN '03' END ) SupplierTypeCode, " +
+	sql := "INSERT INTO `OilSupplierFile` (SupplierId, SupplierCertSubId, Remark, NeedFileType, OtherRemark, SupplierTypeCode,CreateBy) " +
+		"SELECT 0 AS SupplierId, 0 AS SupplierCertSubId, z.企业名称 AS Remark ,f.类别 AS NeedFileType, f.说明 AS OtherRemark, " +
+		"( CASE 准入类别 WHEN '物资类' THEN '01' WHEN '基建类' THEN '02' WHEN '服务类' THEN '03' else '000' END ) SupplierTypeCode, " +
 		"'导入' AS CreateBy " +
 		"FROM `tmp_file` f " +
 		"LEFT JOIN `tmp_zcgf` z ON (f.ID_GF = z.ID) " +
@@ -377,7 +377,7 @@ func (s *TmpzcgtSession) InsertFileName() error {
 }
 
 func (s *TmpzcgtSession) UpdateSupplierFileSId() error {
-	sql := "UPDATE `OilSupplierFile` b SET b.SupplierId = (SELECT a.Id FROM `OilSupplier` a WHERE a.SupplierName = b.Remark ) "
+	sql := "UPDATE `OilSupplierFile` b SET b.SupplierId = IFNULL((SELECT a.Id FROM `OilSupplier` a WHERE a.SupplierName = b.Remark AND a.Id IS NOT NULL limit 1 ), 0) "
 	_, err := s.DBE.Query(sql)
 	return err
 }

+ 2 - 2
src/dashoo.cn/backend/api/controllers/tmpzcgf/tmpzcgf.go

@@ -77,7 +77,7 @@ func (this *TmpzcgfController) UpdateCertTypeAndInflag() {
 	t := time.Now()
 	// session := utils.DBE.NewSession()
 	defer func() {
-		fmt.Println("=============开始更新Cert==========")
+		fmt.Println("=============更新Cert结束==========")
 		// session.Close()
 	}()
 	// err := session.Begin()
@@ -560,7 +560,7 @@ func (this *TmpzcgfController) UpdateCertSubIsType1() {
 	svc := tmpzcgf.GetTmpzcgtService(utils.DBE)
 	svc.GetEntities(&supplierlist, where)
 	for _, item := range supplierlist {
-		fmt.Println(item.SupplierName)
+		//fmt.Println(item.SupplierName)
 		where := "where b.Type = '3' and b.ModifiedBy = '" + item.SupplierName + "'"
 		err := svc.UpdateCertSubIsType2(where)
 		if err != nil {