18 changed files with 7515 additions and 60 deletions
@ -0,0 +1,55 @@ |
|||||
|
package personnelapi |
||||
|
|
||||
|
import ( |
||||
|
"encoding/csv" |
||||
|
"fmt" |
||||
|
"hr_server/middleware/snowflake" |
||||
|
"hr_server/overall/overallhandle" |
||||
|
"os" |
||||
|
) |
||||
|
|
||||
|
/** |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2022-11-26 10:01:34 |
||||
|
@ 功能: 创建csv文件 |
||||
|
@ 参数 |
||||
|
# |
||||
|
@ 返回值 |
||||
|
# |
||||
|
@ 方法原型 |
||||
|
# |
||||
|
*/ |
||||
|
|
||||
|
func WriteCsvFile(fileName string, titleAry []string, bodyAry []ExportPeopleCont) (string, error) { |
||||
|
if len(titleAry) < 1 && len(bodyAry) < 1 { |
||||
|
return "", nil |
||||
|
} |
||||
|
var manKeyNum int64 = 0 |
||||
|
node, nodeErr := snowflake.NewWorker(1) |
||||
|
if nodeErr == nil { |
||||
|
manKeyNum = node.GetId() |
||||
|
} else { |
||||
|
manKeyNum = overallhandle.TableNumber() |
||||
|
} |
||||
|
//创建csv文件
|
||||
|
filename := fmt.Sprintf("%v-%v.csv", fileName, manKeyNum) |
||||
|
xlsFile, fErr := os.OpenFile("uploads/"+filename, os.O_RDWR|os.O_CREATE, 0766) |
||||
|
if fErr != nil { |
||||
|
fmt.Println("Export:created excel file failed ==", fErr) |
||||
|
return "", fErr |
||||
|
} |
||||
|
defer xlsFile.Close() |
||||
|
//开始写入内容
|
||||
|
xlsFile.WriteString("\xEF\xBB\xBF") //写入UTF-8 BOM,此处如果不写入就会导致写入的汉字乱码
|
||||
|
wStr := csv.NewWriter(xlsFile) |
||||
|
wStr.Write(titleAry) //写入标题栏
|
||||
|
|
||||
|
//写入主体
|
||||
|
for _, v := range bodyAry { |
||||
|
wStr.Write([]string{fmt.Sprintf("%v\t", v.Number), v.Name, fmt.Sprintf("%v\t", v.Tel), fmt.Sprintf("%v\t", v.Idcardenddate), v.Org, v.Post, v.Team, v.EmpTypeNAme}) |
||||
|
} |
||||
|
// wStr.Write(bodyAry)
|
||||
|
wStr.Flush() |
||||
|
|
||||
|
return filename, nil |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
package personnelapi |
||||
|
|
||||
|
import "github.com/gin-gonic/gin" |
||||
|
|
||||
|
type ExportServer struct { |
||||
|
engine *gin.Engine |
||||
|
} |
||||
|
|
||||
|
//导出人员信息
|
||||
|
type ExportPeopleCont struct { |
||||
|
Number string `json:"number"` |
||||
|
Name string `json:"name"` |
||||
|
Tel string `json:"tel"` |
||||
|
Idcardenddate string `json:"idcardenddate"` |
||||
|
Org string `json:"org"` |
||||
|
Post string `json:"post"` |
||||
|
Team string `json:"team"` |
||||
|
EmpTypeNAme string `json:"emptype"` |
||||
|
} |
||||
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
Loading…
Reference in new issue