ソースを参照

后:对比列表加协程

dubch 5 年 前
コミット
fdd63d7d76

+ 43 - 41
src/dashoo.cn/backend/api/controllers/oilsupplier/goodsaptitude.go

@@ -1496,7 +1496,7 @@ func (this *OilGoodsAptitudeController) ImportExcel() {
 		this.ServeJSON()
 	}
 	// 外网不用 go func()
-	//go func() {
+	go func() {
 		_dir := utils.Cfg.MustValue("file", "tmplateDir") + "xlsx"
 		filename := strconv.Itoa(int(time.Now().Unix())) + ".xlsx"
 		utils.DownloadFile(url, filename, _dir)
@@ -1529,7 +1529,7 @@ func (this *OilGoodsAptitudeController) ImportExcel() {
 			log.Println(elapsed)
 			this.CreateContrast()
 		}
-	//}()
+	}()
 	errorinfo.Code = 0
 	errorinfo.Message = "导入中,请等待!"
 	this.Data["json"] = &errorinfo
@@ -1692,46 +1692,48 @@ func (this *OilGoodsAptitudeController) TruncateImport() {
 // @Success 200 {object} sampletype.SampleType
 // @router /create-contrast [get]
 func (this *OilGoodsAptitudeController) CreateContrast() {
-	svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
-	svc.TruncateTable("OilSupplierContrast")
-	// 插入对比列表
-	var list1 []supplier.OilSupplier
-	svc.GetMyPagingEntitiesWithOrderBytbl(OilSupplierName, 0, 0, "Id", false, &list1, " 1=1")
-	svc.DBE.Query("SET unique_checks=0;")
-	svc.DBE.Query("SET autocommit=0;")
-	for _, item := range list1 {
-		var list []supplier.OilSupplierContrast
-		where := "  b.SupplierTypeCode='01' and a.Id = " + strconv.Itoa(item.Id)
-		svc.GetPagingTmpCheckedEntities(&list, where)
-		if list != nil {
-			var supplierCertSubList []suppliercertsub.OilSupplierCertSub
-			total := svc.GetTableTotal(" SupplierTypeCode = '01' AND SupplierId = " + strconv.Itoa(item.Id), &supplierCertSubList)
-			total1 := svc.GetNoSubCntTotal("a.SupplierTypeCode = '01' and b.`Name` is null and a.SupplierId = " + strconv.Itoa(item.Id))
-			list[0].SubCnt = int(total)
-			//list[0].MinClassId = "0"
-			list[0].NoSubCnt = int(total1)
-			//for _, sub := range supplierCertSubList {
-			//	var goodsList goodsaptitudeclass.OilGoodsAptitudeClass
-			//	where2 := "Code = '"+ sub.Code + "'"
-			//	svc.GetEntityByWhere(Tmp_OilGoodsAptitudeClassName, where2, &goodsList)
-			//	if goodsList.Id > 0{
-			//		list[0].MinClassId = strconv.Itoa(goodsList.Id)
-			//	} else {
-			//		list[0].MinClassId = "0"
-			//		break
-			//	}
-			//}
-			list[0].SetupTime = time.Now()
-			var oneTwo supplier.OilSupplierContrast
-			svc.GetEntityByCode("SupplierTypeCode = '01' and SupplierId = "+ strconv.Itoa(list[0].Id), &oneTwo)
-			list[0].OneTwoCount = oneTwo.OneTwoCount
-			list[0].TwoOneCount = oneTwo.TwoOneCount
-			svc.InsertEntityBytbl("OilSupplierContrast", list[0])
-			svc.DBE.Query("commit;")
+	go func() {
+		svc := goodsaptitude.GetOilGoodsAptitudeService(utils.DBE)
+		svc.TruncateTable("OilSupplierContrast")
+		// 插入对比列表
+		var list1 []supplier.OilSupplier
+		svc.GetMyPagingEntitiesWithOrderBytbl(OilSupplierName, 0, 0, "Id", false, &list1, " 1=1")
+		svc.DBE.Query("SET unique_checks=0;")
+		svc.DBE.Query("SET autocommit=0;")
+		for _, item := range list1 {
+			var list []supplier.OilSupplierContrast
+			where := "  b.SupplierTypeCode='01' and a.Id = " + strconv.Itoa(item.Id)
+			svc.GetPagingTmpCheckedEntities(&list, where)
+			if list != nil {
+				var supplierCertSubList []suppliercertsub.OilSupplierCertSub
+				total := svc.GetTableTotal(" SupplierTypeCode = '01' AND SupplierId = "+strconv.Itoa(item.Id), &supplierCertSubList)
+				total1 := svc.GetNoSubCntTotal("a.SupplierTypeCode = '01' and b.`Name` is null and a.SupplierId = " + strconv.Itoa(item.Id))
+				list[0].SubCnt = int(total)
+				//list[0].MinClassId = "0"
+				list[0].NoSubCnt = int(total1)
+				//for _, sub := range supplierCertSubList {
+				//	var goodsList goodsaptitudeclass.OilGoodsAptitudeClass
+				//	where2 := "Code = '"+ sub.Code + "'"
+				//	svc.GetEntityByWhere(Tmp_OilGoodsAptitudeClassName, where2, &goodsList)
+				//	if goodsList.Id > 0{
+				//		list[0].MinClassId = strconv.Itoa(goodsList.Id)
+				//	} else {
+				//		list[0].MinClassId = "0"
+				//		break
+				//	}
+				//}
+				list[0].SetupTime = time.Now()
+				var oneTwo supplier.OilSupplierContrast
+				svc.GetEntityByCode("SupplierTypeCode = '01' and SupplierId = "+strconv.Itoa(list[0].Id), &oneTwo)
+				list[0].OneTwoCount = oneTwo.OneTwoCount
+				list[0].TwoOneCount = oneTwo.TwoOneCount
+				svc.InsertEntityBytbl("OilSupplierContrast", list[0])
+				svc.DBE.Query("commit;")
+			}
 		}
-	}
-	svc.DBE.Query("SET unique_checks=1;")
-	svc.DBE.Query("SET autocommit=1;")
+		svc.DBE.Query("SET unique_checks=1;")
+		svc.DBE.Query("SET autocommit=1;")
+	}()
 	var errorinfo ErrorInfo
 	errorinfo.Code = 0
 	errorinfo.Message = "成功!"

+ 37 - 35
src/dashoo.cn/backend/api/controllers/oilsupplier/technologyservice.go

@@ -1925,42 +1925,44 @@ func (this *OilTechnologyServiceController) GetCompareList() {
 // @Success 200 {object} sampletype.SampleType
 // @router /create-contrast [get]
 func (this *OilTechnologyServiceController) CreateContrast() {
-	svc := technologyservice.GetOilTechnologyServiceService(utils.DBE)
-	svc.TruncateTable("OilSupplierTecContrast")
-	// 插入对比列表
-	var list1 []supplier.OilSupplier
-	svc.GetMyPagingEntitiesWithOrderBytbl(OilSupplierName, 0, 0, "Id", false, &list1, " 1=1")
-	svc.DBE.Query("SET unique_checks=0;")
-	svc.DBE.Query("SET autocommit=0;")
-	for _, item := range list1 {
-		var list []supplier.OilSupplierContrast
-		where := "  b.SupplierTypeCode='03' and a.Id = " + strconv.Itoa(item.Id)
-		svc.GetPagingTmpCheckedEntities(&list, where)
-		if list != nil {
-			var supplierCertSubList []suppliercertsub.OilSupplierCertSub
-			total := svc.GetTableTotal(" SupplierTypeCode='03' AND SupplierId = " + strconv.Itoa(item.Id), &supplierCertSubList)
-			total1 := svc.GetNoSubCntTotal("a.SupplierTypeCode = '03' and c.ClassId is null and a.SupplierId = " + strconv.Itoa(item.Id))
-			list[0].SubCnt = int(total)
-			//list[0].MinClassId = "0"
-			list[0].NoSubCnt = int(total1)
-			//for _, sub := range supplierCertSubList {
-			//	var technologyClassList technologyserviceclass.OilTechnologyServiceClass
-			//	where2 := "Name = '"+ sub.Name + "'"
-			//	svc.GetEntityByWhere(Tmp_TechnologyClassName, where2, &technologyClassList)
-			//	if technologyClassList.Id > 0{
-			//		list[0].MinClassId = strconv.Itoa(technologyClassList.Id)
-			//	} else {
-			//		list[0].MinClassId = "0"
-			//		break
-			//	}
-			//}
-			list[0].SetupTime = time.Now()
-			svc.InsertEntityBytbl("OilSupplierTecContrast", list[0])
-			svc.DBE.Query("commit;")
+	go func() {
+		svc := technologyservice.GetOilTechnologyServiceService(utils.DBE)
+		svc.TruncateTable("OilSupplierTecContrast")
+		// 插入对比列表
+		var list1 []supplier.OilSupplier
+		svc.GetMyPagingEntitiesWithOrderBytbl(OilSupplierName, 0, 0, "Id", false, &list1, " 1=1")
+		svc.DBE.Query("SET unique_checks=0;")
+		svc.DBE.Query("SET autocommit=0;")
+		for _, item := range list1 {
+			var list []supplier.OilSupplierContrast
+			where := "  b.SupplierTypeCode='03' and a.Id = " + strconv.Itoa(item.Id)
+			svc.GetPagingTmpCheckedEntities(&list, where)
+			if list != nil {
+				var supplierCertSubList []suppliercertsub.OilSupplierCertSub
+				total := svc.GetTableTotal(" SupplierTypeCode='03' AND SupplierId = "+strconv.Itoa(item.Id), &supplierCertSubList)
+				total1 := svc.GetNoSubCntTotal("a.SupplierTypeCode = '03' and c.ClassId is null and a.SupplierId = " + strconv.Itoa(item.Id))
+				list[0].SubCnt = int(total)
+				//list[0].MinClassId = "0"
+				list[0].NoSubCnt = int(total1)
+				//for _, sub := range supplierCertSubList {
+				//	var technologyClassList technologyserviceclass.OilTechnologyServiceClass
+				//	where2 := "Name = '"+ sub.Name + "'"
+				//	svc.GetEntityByWhere(Tmp_TechnologyClassName, where2, &technologyClassList)
+				//	if technologyClassList.Id > 0{
+				//		list[0].MinClassId = strconv.Itoa(technologyClassList.Id)
+				//	} else {
+				//		list[0].MinClassId = "0"
+				//		break
+				//	}
+				//}
+				list[0].SetupTime = time.Now()
+				svc.InsertEntityBytbl("OilSupplierTecContrast", list[0])
+				svc.DBE.Query("commit;")
+			}
 		}
-	}
-	svc.DBE.Query("SET unique_checks=1;")
-	svc.DBE.Query("SET autocommit=1;")
+		svc.DBE.Query("SET unique_checks=1;")
+		svc.DBE.Query("SET autocommit=1;")
+	}()
 	var errorinfo ErrorInfo
 	errorinfo.Code = 0
 	errorinfo.Message = "成功!"