Browse Source

fix: 完善导入导出

hsun 2 years ago
parent
commit
08b92501bf
1 changed files with 23 additions and 4 deletions
  1. 23 4
      controller/contract/register.go

+ 23 - 4
controller/contract/register.go

@@ -1044,10 +1044,11 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		row2NameKeyMap[row2Title[i]] = i
 	}
 
-	// TODO:代付和补充协议
 	contractTMap := map[int]int{
-		fms.ContractTypeNew:   1,
-		fms.ContractTypeRenew: 0,
+		fms.ContractTypeNew:      1,
+		fms.ContractTypeRenew:    0,
+		fms.ContractTypeAgentPay: 2, // 代付合同
+		fms.ContractTypePlus:     3, // 补充协议
 	}
 	for _, v := range list {
 		k := -1
@@ -1446,6 +1447,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 
 	titleMap := make(map[int]string)
 	newIds := make([]int, 0)
+	contractTypeArr := []string{"0", "1", "2", "3"}
 	for _, sheet := range xlFile.Sheets {
 		// 遍历行读取
 		maxRow := sheet.MaxRow
@@ -1510,12 +1512,23 @@ func (rg *RegisterController) Import(c *gin.Context) {
 					}
 					// 续约/新增
 					if k == 1 {
+						if !utils.InArrayByStr(contractTypeArr, utils.TrimStr(cell.String())) {
+							resp.Fail("合同类型有误, 请按模板导入", c)
+							return
+						}
 						if utils.TrimStr(cell.String()) == "0" {
 							rowRegister.ContractType = fms.ContractTypeRenew
 						}
 						if utils.TrimStr(cell.String()) == "1" {
 							rowRegister.ContractType = fms.ContractTypeNew
 						}
+						if utils.TrimStr(cell.String()) == "2" {
+							rowRegister.ContractType = fms.ContractTypeAgentPay
+						}
+						if utils.TrimStr(cell.String()) == "3" {
+							rowRegister.ContractType = fms.ContractTypePlus
+							rowRegister.RegisterStatus = fms.ContractRegisterStatusComplete // 补充协议标记已完成
+						}
 					}
 					// 销售
 					if k == 2 {
@@ -1621,6 +1634,10 @@ func (rg *RegisterController) Import(c *gin.Context) {
 					// 合同编号
 					if k == 34 {
 						rowContractCode := utils.TrimStr(cell.String())
+						if rowContractCode == "" {
+							resp.Fail("合同编号不可为空, 请按模板导入", c)
+							return
+						}
 						if utils.InArrayByStr(contractCodeArr, rowContractCode) {
 							// 此合同已登记, 跳过本行的读取
 							break
@@ -1796,7 +1813,9 @@ func (rg *RegisterController) Import(c *gin.Context) {
 					resp.FailData("导入失败", "新增导入登记失败, Err: "+e.Error(), c)
 					return
 				}
-				newIds = append(newIds, newId)
+				if rowRegister.ContractType != fms.ContractTypePlus {
+					newIds = append(newIds, newId)
+				}
 			}
 		}
 	}