|
@@ -1469,6 +1469,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
|
|
@@ -1530,36 +1537,40 @@ 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
|
|
|
}
|
|
|
// 续约/新增
|
|
|
if k == 1 {
|
|
|
if !utils.InArrayByStr(contractTypeArr, v) {
|
|
|
- resp.Fail("合同类型有误, 请按模板导入", c)
|
|
|
+ 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大套餐
|
|
@@ -1567,7 +1578,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{
|
|
@@ -1596,7 +1607,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{
|
|
@@ -1621,29 +1632,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("开始时间格式有误, 请按模板导入", 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("到期时间格式有误, 请按模板导入", 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
|
|
|
}
|
|
@@ -1652,7 +1680,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
|
|
@@ -1667,28 +1695,39 @@ 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("签订日格式有误, 请按模板导入", 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
|
|
|
}
|
|
|
// 合同状态
|
|
|
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) {
|
|
@@ -1710,13 +1749,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("开票时间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
|
|
@@ -1727,7 +1770,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
|
|
@@ -1742,10 +1785,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("开票时间2格式有误, 请按模板导入", 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
|
|
@@ -1756,7 +1803,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
|
|
@@ -1771,10 +1818,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("开票时间3格式有误, 请按模板导入", 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
|
|
@@ -1785,7 +1836,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
|
|
@@ -1801,10 +1852,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("收款时间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
|
|
@@ -1815,7 +1870,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
|
|
@@ -1830,10 +1885,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("收款时间2格式有误, 请按模板导入", 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
|
|
@@ -1844,7 +1903,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
|
|
@@ -1859,10 +1918,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("收款时间3格式有误, 请按模板导入", 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
|
|
@@ -1873,7 +1936,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
|
|
@@ -1891,7 +1954,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, ",")
|
|
@@ -1908,15 +1971,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)
|
|
|
}
|
|
|
}
|
|
|
}
|