Browse Source

fix: 导入bug修复及提示优化

hsun 2 years ago
parent
commit
b309e9cee1
1 changed files with 34 additions and 25 deletions
  1. 34 25
      controller/contract/register.go

+ 34 - 25
controller/contract/register.go

@@ -1537,7 +1537,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 					// 续约/新增
 					if k == 1 {
 						if !utils.InArrayByStr(contractTypeArr, v) {
-							resp.Fail("合同类型有误, 请按模板导入", c)
+							resp.Fail(fmt.Sprintf("第%d行合同类型有误, 请按模板导入", i+1), c)
 							return
 						}
 						if v == "0" {
@@ -1565,7 +1565,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						if v == "是" {
 							tempItem := serviceTempNameMap[titleMap[k]]
 							if tempItem == nil {
-								resp.Fail("套餐名称不匹配, 请按模板导入", c)
+								resp.Fail(fmt.Sprintf("第%d行套餐名称不匹配, 请按模板导入", i+1), c)
 								return
 							}
 							cs := &fms.ContractService{
@@ -1594,7 +1594,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						if v == "是" {
 							tempItem := serviceTempNameMap[titleMap[k]]
 							if tempItem == nil {
-								resp.Fail("市场策略/财富管理套餐名称不匹配, 请按模板导入", c)
+								resp.Fail(fmt.Sprintf("第%d行市场策略/财富管理套餐名称不匹配, 请按模板导入", i+1), c)
 								return
 							}
 							cs := &fms.ContractService{
@@ -1624,7 +1624,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 							d := utils.ConvertToFormatDay(va, "2006/01/02") //录入日期
 							startDate, e = time.ParseInLocation("2006/01/02", d, time.Local)
 							if e != nil {
-								resp.Fail("开始时间格式有误, 请按模板导入", c)
+								resp.Fail(fmt.Sprintf("第%d行开始时间格式有误, 请按模板导入", i+1), c)
 								return
 							}
 						}
@@ -1638,7 +1638,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 							d := utils.ConvertToFormatDay(va, "2006/01/02") //录入日期
 							endDate, e = time.ParseInLocation("2006/01/02", d, time.Local)
 							if e != nil {
-								resp.Fail("到期时间格式有误, 请按模板导入", c)
+								resp.Fail(fmt.Sprintf("第%d行到期时间格式有误, 请按模板导入", i+1), c)
 								return
 							}
 						}
@@ -1650,7 +1650,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
-							resp.Fail("合同金额有误, 请按模板导入", c)
+							resp.Fail(fmt.Sprintf("第%d行合同金额有误, 请按模板导入", i+1), c)
 							return
 						}
 						rowRegister.ContractAmount = amount
@@ -1670,7 +1670,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 							d := utils.ConvertToFormatDay(va, "2006/01/02") //录入日期
 							signDate, e = time.ParseInLocation("2006/01/02", d, time.Local)
 							if e != nil {
-								resp.Fail("签订日格式有误, 请按模板导入", c)
+								resp.Fail(fmt.Sprintf("第%d行签订日格式有误, 请按模板导入", i+1), c)
 								return
 							}
 						}
@@ -1680,13 +1680,17 @@ func (rg *RegisterController) Import(c *gin.Context) {
 					// 合同状态
 					if k == 33 {
 						rowRegister.ContractStatus = fms.ContractStatusNameKeyMap[v]
+						if rowRegister.ContractStatus == 0 {
+							resp.Fail(fmt.Sprintf("第%d行合同状态不匹配, 请按模板导入", i+1), c)
+							return
+						}
 						continue
 					}
 					// 合同编号
 					if k == 34 {
 						rowContractCode := v
 						if rowContractCode == "" {
-							resp.Fail("合同编号不可为空, 请按模板导入", c)
+							resp.Fail(fmt.Sprintf("第%d行合同编号不可为空, 请按模板导入", i+1), c)
 							return
 						}
 						if utils.InArrayByStr(contractCodeArr, rowContractCode) {
@@ -1711,7 +1715,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 								d := utils.ConvertToFormatDay(va, "2006/01/02") //录入日期
 								invoiceDate, e = time.ParseInLocation("2006/01/02", d, time.Local)
 								if e != nil {
-									resp.Fail("开票时间1格式有误, 请按模板导入", c)
+									resp.Fail(fmt.Sprintf("第%d行开票时间1格式有误, 请按模板导入", i+1), c)
 									return
 								}
 							}
@@ -1725,7 +1729,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
-							resp.Fail("开票金额1有误, 请按模板导入", c)
+							resp.Fail(fmt.Sprintf("第%d行开票金额1有误, 请按模板导入", i+1), c)
 							return
 						}
 						rowInvoice1.Amount = amount
@@ -1740,7 +1744,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 								d := utils.ConvertToFormatDay(va, "2006/01/02") //录入日期
 								invoiceDate, e = time.ParseInLocation("2006/01/02", d, time.Local)
 								if e != nil {
-									resp.Fail("开票时间2格式有误, 请按模板导入", c)
+									resp.Fail(fmt.Sprintf("第%d行开票时间2格式有误, 请按模板导入", i+1), c)
 									return
 								}
 							}
@@ -1754,7 +1758,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
-							resp.Fail("开票金额2有误, 请按模板导入", c)
+							resp.Fail(fmt.Sprintf("第%d行开票金额2有误, 请按模板导入", i+1), c)
 							return
 						}
 						rowInvoice2.Amount = amount
@@ -1769,7 +1773,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 								d := utils.ConvertToFormatDay(va, "2006/01/02") //录入日期
 								invoiceDate, e = time.ParseInLocation("2006/01/02", d, time.Local)
 								if e != nil {
-									resp.Fail("开票时间3格式有误, 请按模板导入", c)
+									resp.Fail(fmt.Sprintf("第%d行开票时间3格式有误, 请按模板导入", i+1), c)
 									return
 								}
 							}
@@ -1783,7 +1787,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
-							resp.Fail("开票金额3有误, 请按模板导入", c)
+							resp.Fail(fmt.Sprintf("第%d行开票金额3有误, 请按模板导入", i+1), c)
 							return
 						}
 						rowInvoice3.Amount = amount
@@ -1799,7 +1803,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 								d := utils.ConvertToFormatDay(va, "2006/01/02") //录入日期
 								invoiceDate, e = time.ParseInLocation("2006/01/02", d, time.Local)
 								if e != nil {
-									resp.Fail("收款时间1格式有误, 请按模板导入", c)
+									resp.Fail(fmt.Sprintf("第%d行收款时间1格式有误, 请按模板导入", i+1), c)
 									return
 								}
 							}
@@ -1813,7 +1817,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
-							resp.Fail("收款金额1有误, 请按模板导入", c)
+							resp.Fail(fmt.Sprintf("第%d行收款金额1有误, 请按模板导入", i+1), c)
 							return
 						}
 						rowInvoice4.Amount = amount
@@ -1828,7 +1832,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 								d := utils.ConvertToFormatDay(va, "2006/01/02") //录入日期
 								invoiceDate, e = time.ParseInLocation("2006/01/02", d, time.Local)
 								if e != nil {
-									resp.Fail("收款时间2格式有误, 请按模板导入", c)
+									resp.Fail(fmt.Sprintf("第%d行收款时间2格式有误, 请按模板导入", i+1), c)
 									return
 								}
 							}
@@ -1842,7 +1846,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
-							resp.Fail("收款金额2有误, 请按模板导入", c)
+							resp.Fail(fmt.Sprintf("第%d行收款金额2有误, 请按模板导入", i+1), c)
 							return
 						}
 						rowInvoice5.Amount = amount
@@ -1857,7 +1861,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 								d := utils.ConvertToFormatDay(va, "2006/01/02") //录入日期
 								invoiceDate, e = time.ParseInLocation("2006/01/02", d, time.Local)
 								if e != nil {
-									resp.Fail("收款时间3格式有误, 请按模板导入", c)
+									resp.Fail(fmt.Sprintf("第%d行收款时间3格式有误, 请按模板导入", i+1), c)
 									return
 								}
 							}
@@ -1871,7 +1875,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
-							resp.Fail("收款金额3有误, 请按模板导入", c)
+							resp.Fail(fmt.Sprintf("第%d行收款金额3有误, 请按模板导入", i+1), c)
 							return
 						}
 						rowInvoice6.Amount = amount
@@ -1889,7 +1893,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 					// 说明有小套餐
 					tempItem := serviceTempNameMap["FICC小套餐"]
 					if tempItem == nil {
-						resp.Fail("小套餐名称不匹配, 请按模板导入", c)
+						resp.Fail(fmt.Sprintf("第%d行小套餐名称不匹配, 请按模板导入", i+1), c)
 						return
 					}
 					rowChartPermissionIds := strings.Join(rowChartPermissionIdArr, ",")
@@ -1906,15 +1910,20 @@ func (rg *RegisterController) Import(c *gin.Context) {
 					rowServices = append(rowServices, cs)
 				}
 
+				// 如果导入的最后一条合同编号为空并且合同编号之后的字段均为空
+				// excel这个包读行的时候不会再往后面没数据的地方读取, 所以此处需要重新判断一次
+				if rowRegister.ContractCode == "" {
+					resp.Fail(fmt.Sprintf("第%d行合同编号为空", i+1), c)
+					return
+				}
+				rowRegister.RegisterStatus = fms.ContractRegisterStatusIng
 				// 新增登记、套餐、开票到款信息
 				newId, e := fms.CreateImportContractRegister(rowRegister, rowServices, rowInvoices)
 				if e != nil {
-					resp.FailData("导入失败", "新增导入登记失败, Err: "+e.Error(), c)
+					resp.FailData(fmt.Sprintf("第%d行导入失败", i+1), "新增导入登记失败, Err: "+e.Error(), c)
 					return
 				}
-				if rowRegister.ContractType != fms.ContractTypePlus {
-					newIds = append(newIds, newId)
-				}
+				newIds = append(newIds, newId)
 			}
 		}
 	}