hsun 2 gadi atpakaļ
vecāks
revīzija
cd2a78382e
1 mainītis faili ar 84 papildinājumiem un 25 dzēšanām
  1. 84 25
      controller/contract/register.go

+ 84 - 25
controller/contract/register.go

@@ -1467,6 +1467,13 @@ func (rg *RegisterController) Import(c *gin.Context) {
 	titleMap := make(map[int]string)
 	newIds := make([]int, 0)
 	contractTypeArr := []string{"0", "1", "2", "3"}
+	contractTypeMap := map[string]int{
+		"0": fms.ContractTypeRenew,
+		"1": fms.ContractTypeNew,
+		"2": fms.ContractTypeAgentPay,
+		"3": fms.ContractTypePlus,
+	}
+	checkDate := time.Date(1900, 1, 1, 0, 0, 0, 0, time.Local)
 	for _, sheet := range xlFile.Sheets {
 		// 遍历行读取
 		maxRow := sheet.MaxRow
@@ -1528,9 +1535,12 @@ func (rg *RegisterController) Import(c *gin.Context) {
 				isSkip := false
 				for k, cell := range cells {
 					v := utils.TrimStr(cell.String())
-					//fmt.Printf("k: %d, v: %s\n", k, v)
 					// 客户名称
 					if k == 0 {
+						if v == "" {
+							resp.Fail(fmt.Sprintf("第%d行客户名称不可为空, 请按模板导入", i+1), c)
+							return
+						}
 						rowRegister.CompanyName = v
 						continue
 					}
@@ -1540,24 +1550,25 @@ func (rg *RegisterController) Import(c *gin.Context) {
 							resp.Fail(fmt.Sprintf("第%d行合同类型有误, 请按模板导入", i+1), c)
 							return
 						}
-						if v == "0" {
-							rowRegister.ContractType = fms.ContractTypeRenew
-						}
-						if v == "1" {
-							rowRegister.ContractType = fms.ContractTypeNew
-						}
-						if v == "2" {
-							rowRegister.ContractType = fms.ContractTypeAgentPay
-						}
-						if v == "3" {
-							rowRegister.ContractType = fms.ContractTypePlus
+						rowRegister.ContractType = contractTypeMap[v]
+						if rowRegister.ContractType == 0 {
+							resp.Fail(fmt.Sprintf("第%d行合同类型匹配有误, 请按模板导入", i+1), c)
+							return
 						}
 						continue
 					}
 					// 销售
 					if k == 2 {
+						if v == "" {
+							resp.Fail(fmt.Sprintf("第%d行销售名称不可为空, 请按模板导入", i+1), c)
+							return
+						}
 						rowRegister.SellerName = v
 						rowRegister.SellerId = sellerNameIdMap[rowRegister.SellerName]
+						if rowRegister.SellerId == 0 {
+							resp.Fail(fmt.Sprintf("第%d行销售名称与系统销售不匹配, 请核对名称后导入", i+1), c)
+							return
+						}
 						continue
 					}
 					// FICC大套餐
@@ -1619,29 +1630,46 @@ func (rg *RegisterController) Import(c *gin.Context) {
 					if k == 27 {
 						// 转换失败可能是因为格式为Excel日期格式, 读取出来会是一串数字, 将其转换成日期字符串再处理
 						va := cell.Value
+						if va == "" {
+							resp.Fail(fmt.Sprintf("第%d行开始时间不可为空, 请按模板导入", i+1), c)
+							return
+						}
 						startDate, e := time.ParseInLocation("2006/01/02", va, time.Local)
 						if e != nil {
-							d := utils.ConvertToFormatDay(va, "2006/01/02") //录入日期
+							d := utils.ConvertToFormatDay(va, "2006/01/02")
 							startDate, e = time.ParseInLocation("2006/01/02", d, time.Local)
 							if e != nil {
-								resp.Fail(fmt.Sprintf("第%d行开始时间格式有误, 请按模板导入", i+1), c)
+								resp.Fail(fmt.Sprintf("第%d行开始时间格式转换有误, 请按模板导入", i+1), c)
 								return
 							}
 						}
+						// 转换后的日期小于1900-01-01表示当前生成的日期是有问题的
+						if startDate.Before(checkDate) {
+							resp.Fail(fmt.Sprintf("第%d行开始时间格式有误, 请按模板导入", i+1), c)
+							return
+						}
 						rowRegister.StartDate = startDate
 						continue
 					}
 					if k == 28 {
 						va := cell.Value
+						if va == "" {
+							resp.Fail(fmt.Sprintf("第%d行到期时间不可为空, 请按模板导入", i+1), c)
+							return
+						}
 						endDate, e := time.ParseInLocation("2006/01/02", va, time.Local)
 						if e != nil {
-							d := utils.ConvertToFormatDay(va, "2006/01/02") //录入日期
+							d := utils.ConvertToFormatDay(va, "2006/01/02")
 							endDate, e = time.ParseInLocation("2006/01/02", d, time.Local)
 							if e != nil {
-								resp.Fail(fmt.Sprintf("第%d行到期时间格式有误, 请按模板导入", i+1), c)
+								resp.Fail(fmt.Sprintf("第%d行到期时间格式转换有误, 请按模板导入", i+1), c)
 								return
 							}
 						}
+						if endDate.Before(checkDate) {
+							resp.Fail(fmt.Sprintf("第%d行到期时间格式有误, 请按模板导入", i+1), c)
+							return
+						}
 						rowRegister.EndDate = endDate
 						continue
 					}
@@ -1665,15 +1693,22 @@ func (rg *RegisterController) Import(c *gin.Context) {
 					// k == 32为签订月,可忽略
 					if k == 31 {
 						va := cell.Value
+						if va == "" {
+							continue
+						}
 						signDate, e := time.ParseInLocation("2006/01/02", va, time.Local)
 						if e != nil {
-							d := utils.ConvertToFormatDay(va, "2006/01/02") //录入日期
+							d := utils.ConvertToFormatDay(va, "2006/01/02")
 							signDate, e = time.ParseInLocation("2006/01/02", d, time.Local)
 							if e != nil {
-								resp.Fail(fmt.Sprintf("第%d行签订日格式有误, 请按模板导入", i+1), c)
+								resp.Fail(fmt.Sprintf("第%d行签订日格式转换有误, 请按模板导入", i+1), c)
 								return
 							}
 						}
+						if signDate.Before(checkDate) {
+							resp.Fail(fmt.Sprintf("第%d行签订日格式有误, 请按模板导入", i+1), c)
+							return
+						}
 						rowRegister.SignDate = signDate
 						continue
 					}
@@ -1712,13 +1747,17 @@ func (rg *RegisterController) Import(c *gin.Context) {
 							va := cell.Value
 							invoiceDate, e := time.ParseInLocation("2006/01/02", va, time.Local)
 							if e != nil {
-								d := utils.ConvertToFormatDay(va, "2006/01/02") //录入日期
+								d := utils.ConvertToFormatDay(va, "2006/01/02")
 								invoiceDate, e = time.ParseInLocation("2006/01/02", d, time.Local)
 								if e != nil {
-									resp.Fail(fmt.Sprintf("第%d行开票时间1格式有误, 请按模板导入", i+1), c)
+									resp.Fail(fmt.Sprintf("第%d行开票时间1格式转换有误, 请按模板导入", i+1), c)
 									return
 								}
 							}
+							if invoiceDate.Before(checkDate) {
+								resp.Fail(fmt.Sprintf("第%d行开票时间1格式有误, 请按模板导入", i+1), c)
+								return
+							}
 							rowInvoice1.InvoiceDate = invoiceDate
 							rowInvoice1.ContractCode = rowRegister.ContractCode
 							rowInvoice1.InvoiceType = fms.ContractInvoiceTypeMake
@@ -1744,10 +1783,14 @@ 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(fmt.Sprintf("第%d行开票时间2格式有误, 请按模板导入", i+1), c)
+									resp.Fail(fmt.Sprintf("第%d行开票时间2格式转换有误, 请按模板导入", i+1), c)
 									return
 								}
 							}
+							if invoiceDate.Before(checkDate) {
+								resp.Fail(fmt.Sprintf("第%d行开票时间2格式有误, 请按模板导入", i+1), c)
+								return
+							}
 							rowInvoice2.InvoiceDate = invoiceDate
 							rowInvoice2.ContractCode = rowRegister.ContractCode
 							rowInvoice2.InvoiceType = fms.ContractInvoiceTypeMake
@@ -1773,10 +1816,14 @@ 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(fmt.Sprintf("第%d行开票时间3格式有误, 请按模板导入", i+1), c)
+									resp.Fail(fmt.Sprintf("第%d行开票时间3格式转换有误, 请按模板导入", i+1), c)
 									return
 								}
 							}
+							if invoiceDate.Before(checkDate) {
+								resp.Fail(fmt.Sprintf("第%d行开票时间3格式有误, 请按模板导入", i+1), c)
+								return
+							}
 							rowInvoice3.InvoiceDate = invoiceDate
 							rowInvoice3.ContractCode = rowRegister.ContractCode
 							rowInvoice3.InvoiceType = fms.ContractInvoiceTypeMake
@@ -1803,10 +1850,14 @@ 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(fmt.Sprintf("第%d行收款时间1格式有误, 请按模板导入", i+1), c)
+									resp.Fail(fmt.Sprintf("第%d行收款时间1格式转换有误, 请按模板导入", i+1), c)
 									return
 								}
 							}
+							if invoiceDate.Before(checkDate) {
+								resp.Fail(fmt.Sprintf("第%d行收款时间1格式有误, 请按模板导入", i+1), c)
+								return
+							}
 							rowInvoice4.InvoiceDate = invoiceDate
 							rowInvoice4.ContractCode = rowRegister.ContractCode
 							rowInvoice4.InvoiceType = fms.ContractInvoiceTypePay
@@ -1832,10 +1883,14 @@ 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(fmt.Sprintf("第%d行收款时间2格式有误, 请按模板导入", i+1), c)
+									resp.Fail(fmt.Sprintf("第%d行收款时间2格式转换有误, 请按模板导入", i+1), c)
 									return
 								}
 							}
+							if invoiceDate.Before(checkDate) {
+								resp.Fail(fmt.Sprintf("第%d行收款时间2格式有误, 请按模板导入", i+1), c)
+								return
+							}
 							rowInvoice5.InvoiceDate = invoiceDate
 							rowInvoice5.ContractCode = rowRegister.ContractCode
 							rowInvoice5.InvoiceType = fms.ContractInvoiceTypePay
@@ -1861,10 +1916,14 @@ 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(fmt.Sprintf("第%d行收款时间3格式有误, 请按模板导入", i+1), c)
+									resp.Fail(fmt.Sprintf("第%d行收款时间3格式转换有误, 请按模板导入", i+1), c)
 									return
 								}
 							}
+							if invoiceDate.Before(checkDate) {
+								resp.Fail(fmt.Sprintf("第%d行收款时间3格式有误, 请按模板导入", i+1), c)
+								return
+							}
 							rowInvoice6.InvoiceDate = invoiceDate
 							rowInvoice6.ContractCode = rowRegister.ContractCode
 							rowInvoice6.InvoiceType = fms.ContractInvoiceTypePay