Przeglądaj źródła

后端: 资质级别配置变更同时变更企业资质

baichengfei 4 lat temu
rodzic
commit
1207feb42d

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

@@ -1090,39 +1090,39 @@ func (this *OilGoodsAptitudeController) UpdateCodeEntity() {
 		}
 	}
 
-	//var originModel goodsaptitude.OilGoodsAptitude
-	//svc.GetEntityByWhere(OilGoodsAptitudeName, "ClassId = "+id, &originModel)
+	var originModel goodsaptitude.OilGoodsAptitude
+	svc.GetEntityByWhere(OilGoodsAptitudeName, "ClassId = "+id, &originModel)
 
 	var model1 goodsaptitude.OilGoodsAptitude
 	colsGoods := []string{"GoodsLevel"}
 	model1.GoodsLevel = goodsLevel.GoodsLevel
 	svc.UpdateEntityBywheretbl(OilGoodsAptitudeName, &model1, colsGoods, "ClassId = "+id)
 
-	//if originModel.GoodsLevel != goodsLevel.GoodsLevel {
-	//	certSubSvc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
-	//	var certSubModel suppliercertsub.OilSupplierCertSub
-	//	certSubModel.GoodsLevel = goodsLevel.GoodsLevel
-	//	if model1.GoodsLevel == "2" {
-	//		// 变为二级
-	//		certSubSvc.UpdateEntityBywheretbl("OilSupplierCertSub", &certSubModel, colsGoods, " SupplierTypeCode = '01' and SubClassId = " + id)
-	//	} else {
-	//		// 变为一级
-	//		var supplierCertSubList []suppliercertsub.OilSupplierCertSub
-	//		certSubSvc.GetEntitysByWhere("OilSupplierCertSub", " SupplierTypeCode = '01' and SubClassId = " + id, &supplierCertSubList)
-	//		supSvc := supplier.GetOilSupplierService(utils.DBE)
-	//		for _, sub := range supplierCertSubList {
-	//			var supplierEntity supplier.OilSupplier
-	//			supSvc.GetEntityById(sub.SupplierId, &supplierEntity)
-	//			if supplierEntity.Grade == "1" {
-	//				// 公司是一级, 将二级物资变为一级, 直接更新
-	//				certSubSvc.UpdateEntityByIdCols(sub.Id, &certSubModel, colsGoods)
-	//			} else {
-	//				// 公司是二级, 将二级物资变为一级--- 不允许, 直接删除
-	//				certSubSvc.DeleteEntityById(sub.Id, &sub)
-	//			}
-	//		}
-	//	}
-	//}
+	if originModel.GoodsLevel != goodsLevel.GoodsLevel {
+		certSubSvc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
+		var certSubModel suppliercertsub.OilSupplierCertSub
+		certSubModel.GoodsLevel = goodsLevel.GoodsLevel
+		if model1.GoodsLevel == "2" {
+			// 变为二级
+			certSubSvc.UpdateEntityBywheretbl("OilSupplierCertSub", &certSubModel, colsGoods, " SupplierTypeCode = '01' and SubClassId = "+id)
+		} else {
+			// 变为一级
+			var supplierCertSubList []suppliercertsub.OilSupplierCertSub
+			certSubSvc.GetEntitysByWhere("OilSupplierCertSub", " SupplierTypeCode = '01' and SubClassId = "+id, &supplierCertSubList)
+			supSvc := supplier.GetOilSupplierService(utils.DBE)
+			for _, sub := range supplierCertSubList {
+				var supplierEntity supplier.OilSupplier
+				supSvc.GetEntityById(sub.SupplierId, &supplierEntity)
+				if supplierEntity.Grade == "1" {
+					// 公司是一级, 将二级物资变为一级, 直接更新
+					certSubSvc.UpdateEntityByIdCols(sub.Id, &certSubModel, colsGoods)
+				} else {
+					// 公司是二级, 将二级物资变为一级--- 不允许, 直接删除
+					certSubSvc.DeleteEntityById(sub.Id, &sub)
+				}
+			}
+		}
+	}
 
 	if err == nil {
 		errinfo.Message = "修改成功!"