2
3
Yikoo 5 роки тому
батько
коміт
18bf8885af

+ 64 - 12
src/dashoo.cn/backend/api/controllers/oilcontract/contract.go

@@ -472,7 +472,7 @@ func (this *OilContractController) DocExport() {
 // @router /importexcel [get]
 func (this *OilContractController) ImportExcel() {
 	url := this.GetString("ExcelUrl")
-	var errorinfo ErrorInfo
+	var errorinfo ErrorDataInfo
 	if url == "" {
 		errorinfo.Code = -2
 		errorinfo.Message = "导入失败!"
@@ -481,8 +481,7 @@ func (this *OilContractController) ImportExcel() {
 	}
 	session := utils.DBE.NewSession()
 	err := session.Begin()
-	svc := contract.GetOilContractSession(session)
-
+	//svc := contract.GetOilContractSession(session)
 	if err != nil {
 		session.Rollback()
 		errorinfo.Code = -2
@@ -503,27 +502,56 @@ func (this *OilContractController) ImportExcel() {
 		fmt.Printf("open failed: %s\n", err)
 	}
 	var sheet = xlFile.Sheets[0]
-
 	// 插入字段
 	//Fstrs := "ContractNo,ContractName,Amount,ContractType,ContractSonClass,SmallClass,SignedDate,Number,ChooseWay,ContractMark,Currency,BudgetAmount,PerformAmount,IsInternal,IsForeign,IsDeal,MoneyFlows,MoneyChannel,MoneyChannelSon,MoneyChannelSmall,SingUnit,Place,StartDate,EndDate,DisputeResolution,Remark,ProjectOwner,SubmitDate,SealName,PoNumber"
 	//columnArr := strings.Split(Fstrs, ",")
-
 	defer func() {
 		session.Close()
 	}()
 
-	codemap := make(map[string](map[string]int))
+	//timeTemplate1 := "2006/01/02 15:04:05" //常规类型
+
+	codemap := make(map[int](map[string]string))
 	for i := 1; i < len(sheet.Rows); i++ {
 		lineNo := strconv.Itoa(i + 1)
 		fmt.Println(lineNo)
-
-
-
+		tmp := make(map[string]string)
+		tmp["ContractNo"]    = sheet.Rows[i].Cells[0].String()
+		tmp["ContractName"]  = sheet.Rows[i].Cells[1].String()
+		tmp["Amount"]        = sheet.Rows[i].Cells[2].String()
+		tmp["ContractClass"]    = sheet.Rows[i].Cells[3].String()
+		tmp["ContractSonClass"] = sheet.Rows[i].Cells[4].String()
+		tmp["SmallClass"]    = sheet.Rows[i].Cells[5].String()
+		tmp["SignedDate"]    = convertToFormatDay(sheet.Rows[i].Cells[6].Value)
+		tmp["SupplierName"]  = sheet.Rows[i].Cells[7].String()
+		tmp["People"]        = sheet.Rows[i].Cells[8].String()
+		tmp["Number"]        = sheet.Rows[i].Cells[9].String()
+		tmp["ChooseWay"]     = sheet.Rows[i].Cells[10].String()
+		tmp["ContractMark"]  = sheet.Rows[i].Cells[11].String()
+		tmp["Currency"]      = sheet.Rows[i].Cells[12].String()
+		tmp["BudgetAmount"]      = sheet.Rows[i].Cells[13].String()
+		tmp["PerformAmount"]     = sheet.Rows[i].Cells[14].String()
+		tmp["IsInternal"]        = sheet.Rows[i].Cells[15].String()
+		tmp["IsForeign"]         = sheet.Rows[i].Cells[16].String()
+		tmp["IsDeal"]            = sheet.Rows[i].Cells[17].String()
+		tmp["MoneyFlows"]        = sheet.Rows[i].Cells[18].String()
+		tmp["MoneyChannel"]      = sheet.Rows[i].Cells[19].String()
+		tmp["MoneyChannelSon"]   = sheet.Rows[i].Cells[20].String()
+		tmp["MoneyChannelSmall"] = sheet.Rows[i].Cells[21].String()
+		tmp["SingUnit"] = sheet.Rows[i].Cells[22].String()
+		tmp["Place"]    = sheet.Rows[i].Cells[23].String()
+
+		tmp["StartDate"]    = convertToFormatDay(sheet.Rows[i].Cells[24].Value)
+		tmp["EndDate"]      = convertToFormatDay(sheet.Rows[i].Cells[25].Value)
+		tmp["DisputeResolution"]      = sheet.Rows[i].Cells[26].String()
+		tmp["Remark"]                 = sheet.Rows[i].Cells[27].String()
+		tmp["ProjectOwner"]           = sheet.Rows[i].Cells[28].String()
+		tmp["SubmitDate"]             = convertToFormatDay(sheet.Rows[i].Cells[29].Value)
+		tmp["SealName"]      = sheet.Rows[i].Cells[30].String()
+		tmp["PoNumber"]      = sheet.Rows[i].Cells[31].String()
+		codemap[i-1] = tmp
 		//this.OperationCell(svc, lineNo, columnArr, sheet.Rows[i].Cells, &errLineNum)
-
-
 	}
-
 	os.Remove(filePath)
 	if errLineNum != "" {
 		session.Rollback()
@@ -537,10 +565,34 @@ func (this *OilContractController) ImportExcel() {
 		log.Println(elapsed)
 		errorinfo.Code = 0
 		errorinfo.Message = "导入成功!"
+		errorinfo.Item = codemap
 		this.Data["json"] = &errorinfo
 		this.ServeJSON()
 	}
 }
+// excel日期字段格式化 yyyy-mm-dd
+func convertToFormatDay(excelDaysString string)string{
+	// 2006-01-02 距离 1900-01-01的天数
+	baseDiffDay := int64(38719) //在网上工具计算的天数需要加2天,什么原因没弄清楚
+	curDiffDay := excelDaysString
+
+	comma := strings.Index(curDiffDay, ".")
+	if(comma != -1){
+		curDiffDay =  curDiffDay[0:comma]
+	}
+
+	b,_ :=  strconv.ParseInt(curDiffDay, 10, 64)  //strconv.Atoi(curDiffDay)
+	// 获取excel的日期距离2006-01-02的天数
+	realDiffDay := b - baseDiffDay
+	//fmt.Println("realDiffDay:",realDiffDay)
+	// 距离2006-01-02 秒数
+	realDiffSecond := realDiffDay * 24 * 3600
+	//fmt.Println("realDiffSecond:",realDiffSecond)
+	// 2006-01-02 15:04:05距离1970-01-01 08:00:00的秒数 网上工具可查出
+	baseOriginSecond := int64(1136185445)
+	resultTime := time.Unix((baseOriginSecond + realDiffSecond), 0).Format("2006-01-02")
+	return resultTime
+}
 
 func (this *OilContractController) OperationCell(svc *contract.OilContractSession, lineNo string, columnArr []string, cellsArr []*xlsx.Cell, errLineNum *string) {