Browse Source

物资类 重复不添加

shihang 6 years ago
parent
commit
4df999f5fd
1 changed files with 43 additions and 37 deletions
  1. 43 37
      src/dashoo.cn/backend/api/controllers/oilsupplier/suppliercertsub.go

+ 43 - 37
src/dashoo.cn/backend/api/controllers/oilsupplier/suppliercertsub.go

@@ -319,45 +319,38 @@ func (this *OilSupplierCertSubController) AddGoodsBus() {
 			this.Data["json"] = &errinfo
 			this.ServeJSON()
 		}
-		datamain.SubClassId, _ = utils.StrTo(dataother.CheckList[n].Id).Int()
-		datamain.Code = dataother.CheckList[n].Code
-		datamain.Name = dataother.CheckList[n].Name
-		datamain.Remark = dataother.Remark
-		datamain.IsDelete = 0
-		datamain.CreateBy = this.User.Realname
-		datamain.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
+		where_sub := "SupplierTypeCode = 01 and SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'"
+		where_sub += " and SupplierCertId = '" + strconv.Itoa(dataother.SupplierCertId) + "'"
+		where_sub += " and SubClassId = '" + dataother.CheckList[n].Id + "'"
+		var model suppliercertsub.OilSupplierCertSub
 		svc := suppliercertsub.GetOilSupplierCertSubService(utils.DBE)
-		svc.InsertEntityBytbl(OilSupplierCertSubName, &datamain)
-
-		filesvc := supplierfile.GetSupplierfileService(utils.DBE)
-		needList := filesvc.GetGoodsNeedFileList(dataother.CheckList[n].Id)
-
-		var list []supplierfile.OilSupplierFile
-		where := "SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'"
-		svc.GetEntitysByWhere(OilSupplierFileName, where, &list)
-
-		if len(list) == 0 { //第一次添加准入项,将共有必备资质写入文件表
-			for i := 0; i < len(needList); i++ {
-				var entity supplierfile.OilSupplierFile
-				entity.SupplierId = dataother.SupplierId
-				if i < 4 {
-					entity.SupplierTypeCode = "000"
-				} else {
-					entity.SupplierTypeCode = dataother.SupplierTypeCode
-				}
-				entity.NeedFileType = needList[i].FileName
-				entity.FileType = 1
-				entity.EffectDate = time.Now()
-				entity.CreateBy = this.User.Realname
-				entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
-				svc.InsertEntityBytbl(OilSupplierFileName, &entity)
-			}
-		} else {
-			if len(needList) > 4 {
-				for i := 4; i < len(needList); i++ {
+		has := svc.GetEntityByWhere(OilSupplierCertSubName, where_sub, &model)
+
+		if !has {
+			datamain.SubClassId, _ = utils.StrTo(dataother.CheckList[n].Id).Int()
+			datamain.Code = dataother.CheckList[n].Code
+			datamain.Name = dataother.CheckList[n].Name
+			datamain.Remark = dataother.Remark
+			datamain.IsDelete = 0
+			datamain.CreateBy = this.User.Realname
+			datamain.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
+			svc.InsertEntityBytbl(OilSupplierCertSubName, &datamain)
+
+			filesvc := supplierfile.GetSupplierfileService(utils.DBE)
+			needList := filesvc.GetGoodsNeedFileList(dataother.CheckList[n].Id)
+
+			var list []supplierfile.OilSupplierFile
+			where := "SupplierId = '" + strconv.Itoa(dataother.SupplierId) + "'"
+			svc.GetEntitysByWhere(OilSupplierFileName, where, &list)
+			if len(list) == 0 { //第一次添加准入项,将共有必备资质写入文件表
+				for i := 0; i < len(needList); i++ {
 					var entity supplierfile.OilSupplierFile
 					entity.SupplierId = dataother.SupplierId
-					entity.SupplierTypeCode = dataother.SupplierTypeCode
+					if i < 4 {
+						entity.SupplierTypeCode = "000"
+					} else {
+						entity.SupplierTypeCode = dataother.SupplierTypeCode
+					}
 					entity.NeedFileType = needList[i].FileName
 					entity.FileType = 1
 					entity.EffectDate = time.Now()
@@ -365,10 +358,23 @@ func (this *OilSupplierCertSubController) AddGoodsBus() {
 					entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
 					svc.InsertEntityBytbl(OilSupplierFileName, &entity)
 				}
+			} else {
+				if len(needList) > 4 {
+					for i := 4; i < len(needList); i++ {
+						var entity supplierfile.OilSupplierFile
+						entity.SupplierId = dataother.SupplierId
+						entity.SupplierTypeCode = dataother.SupplierTypeCode
+						entity.NeedFileType = needList[i].FileName
+						entity.FileType = 1
+						entity.EffectDate = time.Now()
+						entity.CreateBy = this.User.Realname
+						entity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
+						svc.InsertEntityBytbl(OilSupplierFileName, &entity)
+					}
+				}
 			}
 		}
 	}
-
 }
 
 // @Title 新增准入范围