Răsfoiți Sursa

准入范围导入及修改优化

yuedefeng 5 ani în urmă
părinte
comite
515533010d

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

@@ -260,39 +260,62 @@ func (s *TmpzcgtSession) UpdateOilAnnualAudit() error {
 }
 
 func (s *TmpzcgtSession) InsertCertSub() error {
-	sql := "INSERT `OilSupplierCertSub` (" +
-		"OldId," +
-		"AppendStatus," +
-		"`Type`," +
-		"CreateBy," +
-		"Remark," +
-		"SupplierTypeCode," +
-		"`Code`," +
-		"`Name`" +
-
-		")SELECT " +
-		"t.`ID` AS OldId , '1' AS AppendStatus, '1' AS `Type`, '导入1' AS CreateBy, t.企业名称 As Remark, " +
-		"(CASE t.`准入类别` WHEN '物资类' THEN '01' WHEN '基建类' THEN '02' WHEN '服务类' THEN '03' WHEN '技术服务类' THEN '03' END) AS SupplierTypeCode," +
-		"REPLACE(SUBSTRING_INDEX (SUBSTRING_INDEX(SUBSTRING_INDEX(t.`准入范围`,';', b.help_topic_id + 1), ';', -1),' ' ,1),'BM','') AS `code`, " +
-		"SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(t.`准入范围`,';', b.help_topic_id + 1), ';', -1),' ' ,-1)AS `name` " +
-		"FROM tmp_zcgf t " +
+
+	countSql := "SELECT count(*) FROM tmp_zcgf t " +
 		"CROSS JOIN mysql.help_topic b " +
 		"ON b.help_topic_id <  (LENGTH(t.`准入范围`) - LENGTH(REPLACE(t.`准入范围`, ';', '')) + 1) " +
 		"WHERE " +
 		"1=1 and 准入标识 != '取消' " +
-		"AND LENGTH( SUBSTRING_INDEX(SUBSTRING_INDEX(t.`准入范围`,';', b.help_topic_id + 1), ';', -1) ) > 0 " +
-		"ORDER BY t.ID "
-	_, err := s.DBE.Query(sql)
+		"AND LENGTH( SUBSTRING_INDEX(SUBSTRING_INDEX(t.`准入范围`,';', b.help_topic_id + 1), ';', -1) ) > 0 "
+	countStr, err := s.DBE.Query(countSql)
+	var total int64
+	if len(countStr) > 0 {
+		results := countStr[0]
+		for _, value := range results {
+			total, err = strconv.ParseInt(string(value), 10, 64)
+			break
+		}
+		n := math.Ceil(float64(total) / 200)
+		for i:=0; i <= int(n); i++ {
+			start := strconv.Itoa(i * 200)
+			end := strconv.Itoa(200)
+			sql := "INSERT `OilSupplierCertSub` (" +
+				"OldId," +
+				"AppendStatus," +
+				"`Type`," +
+				"CreateBy," +
+				"Remark," +
+				"SupplierTypeCode," +
+				"`Code`," +
+				"`Name`" +
+
+				") SELECT " +
+				"t.`ID` AS OldId , '1' AS AppendStatus, '1' AS `Type`, '导入1' AS CreateBy, t.企业名称 As Remark, " +
+				"(CASE t.`准入类别` WHEN '物资类' THEN '01' WHEN '基建类' THEN '02' WHEN '服务类' THEN '03' WHEN '技术服务类' THEN '03' END) AS SupplierTypeCode," +
+				"REPLACE(SUBSTRING_INDEX (SUBSTRING_INDEX(SUBSTRING_INDEX(t.`准入范围`,';', b.help_topic_id + 1), ';', -1),' ' ,1),'BM','') AS `code`, " +
+				"SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(t.`准入范围`,';', b.help_topic_id + 1), ';', -1),' ' ,-1)AS `name` " +
+				"FROM tmp_zcgf t " +
+				"CROSS JOIN mysql.help_topic b " +
+				"ON b.help_topic_id <  (LENGTH(t.`准入范围`) - LENGTH(REPLACE(t.`准入范围`, ';', '')) + 1) " +
+				"WHERE " +
+				"1=1 and 准入标识 != '取消' " +
+				"AND LENGTH( SUBSTRING_INDEX(SUBSTRING_INDEX(t.`准入范围`,';', b.help_topic_id + 1), ';', -1) ) > 0 " +
+				"ORDER BY t.ID, SupplierTypeCode, `code` " +
+				"limit " + start + "," +  end
+			_, err = s.DBE.Query(sql)
+		}
+	}
 	return err
 }
 
-func (s *TmpzcgtSession) UpdateCertSub(where string) error {
-	/** 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 */
+func (s *TmpzcgtSession) UpdateCertSub() error {
+	/*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 = IFNULL((SELECT a.Id FROM OilSupplierCert a WHERE a.GfId =b.OldId AND a.SupplierTypeCode = b.SupplierTypeCode limit 1), 0) " +
+		" where b.Type = '1' and b.CreateBy='导入1'"*/
 
 	sql := "UPDATE OilSupplierCertSub b left join OilSupplierCert a on (a.GfId =b.OldId AND a.SupplierTypeCode = b.SupplierTypeCode)  SET b.SupplierId = IFNULL(a.SupplierId, 0)," +
-		"b.SupplierCertId = IFNULL(a.Id, 0) " + where +
-		" AND a.SupplierId IS NOT NULL"
+		"b.SupplierCertId = IFNULL(a.Id, 0) " +
+		" where b.Type = '1' and b.CreateBy='导入1' AND a.SupplierId IS NOT NULL"
 
 	_, err := s.DBE.Query(sql)
 	return err
@@ -421,7 +444,7 @@ func (s *TmpzcgtSession) UpOilSupplierCertAppend() error {
 	return err
 }
 
-func (s *TmpzcgtSession) UpdateCertSubIsType2(where string) error {
+func (s *TmpzcgtSession) UpdateCertSubIsType2() error {
 	/** sql := "UPDATE OilSupplierCertSub b SET " +
 		"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), " +
@@ -431,7 +454,7 @@ func (s *TmpzcgtSession) UpdateCertSubIsType2(where string) error {
 		"b.SupplierId = IFNULL(a.`SupplierId`, 0), " +
 		"b.SupplierCertId = IFNULL(a.`SupplierCertId`, 0), " +
 		"b.SupplierCertAppendId = IFNULL(a.`Id`, 0) " +
-		where
+		"where b.Type = '3'"
 	_, err := s.DBE.Query(sql)
 	return err
 }

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

@@ -377,6 +377,14 @@ func (this *TmpzcgfController) UpdateOilSupplierCertSub() {
 	}()
 	// err := session.Begin()
 	svc := tmpzcgf.GetTmpzcgtService(utils.DBE)
+	///////////////////
+	err := svc.UpdateCertSub()
+	if err != nil {
+		// session.Rollback()
+		fmt.Println(err)
+	}
+	///////////////////
+	/**
 	var supplierlist []supplier.OilSupplier
 	where := "CreateBy='导入'"
 	svc.GetEntities(&supplierlist, where)
@@ -387,7 +395,7 @@ func (this *TmpzcgfController) UpdateOilSupplierCertSub() {
 			// session.Rollback()
 			fmt.Println(err)
 		}
-	}
+	}*/
 	// err = session.Commit()
 	elapsed := time.Since(t)
 	fmt.Println(elapsed)
@@ -553,7 +561,13 @@ func (this *TmpzcgfController) UpdateCertSubIsType1() {
 	}()
 	// err := session.Begin()
 
-	var supplierlist []supplier.OilSupplier
+	svc := tmpzcgf.GetTmpzcgtService(utils.DBE)
+	err := svc.UpdateCertSubIsType2()
+	if err != nil {
+		// session.Rollback()
+		fmt.Println(err)
+	}
+	/*var supplierlist []supplier.OilSupplier
 	where := "CreateBy='导入'"
 	svc := tmpzcgf.GetTmpzcgtService(utils.DBE)
 	svc.GetEntities(&supplierlist, where)
@@ -566,7 +580,7 @@ func (this *TmpzcgfController) UpdateCertSubIsType1() {
 			fmt.Println(err)
 		}
 		// err = session.Commit()
-	}
+	}*/
 
 	elapsed := time.Since(t)
 	fmt.Println(elapsed)
@@ -871,7 +885,7 @@ func (this *TmpzcgfController) InsertAll() {
 
 	this.CapacityExpansion() // 编码扩充
 	// 历史数据导入-由于运行到此处中断,上面的代码临时注释
-	//this.UpdateCertSubIsType3() // 更新增项的准入范围 弃用 2020年11月26日
+	// this.UpdateCertSubIsType3() // 更新增项的准入范围 弃用 2020年11月26日
 	this.InsterAnnualAudit()
 	this.UpdateAnnualAudit()
 	this.InsterOilPaymentInfo()