123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544 |
- package controllers
- import (
- "ERP_salary/Nats"
- "ERP_salary/Nats/NatsServer"
- "ERP_salary/conf"
- "ERP_salary/logs"
- "ERP_salary/models/Account"
- "ERP_salary/models/Salary"
- "fmt"
- "github.com/beego/beego/v2/adapter/orm"
- beego "github.com/beego/beego/v2/server/web"
- natslibs "gogs.baozhida.cn/zoie/ERP_libs/Nats"
- userlibs "gogs.baozhida.cn/zoie/ERP_libs/User"
- "gogs.baozhida.cn/zoie/ERP_libs/lib"
- "math"
- "os"
- "strings"
- "time"
- )
- type SalaryController struct {
- beego.Controller
- User userlibs.User
- }
- func (c *SalaryController) Prepare() {
- c.User = *Account.User_r
- }
- // 管理员工资列表 默认显示上月工资
- func (c *SalaryController) Salary_List() {
- var r_jsons lib.R_JSONS
- T_date := c.GetString("T_date")
- var err error
- // 年月 2023-01
- if len(T_date) == 0 {
- T_date = time.Now().AddDate(0, -1, 0).Format("2006-01")
- }
- _, err = time.Parse("2006-01", T_date)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "日期格式错误!"}
- c.ServeJSON()
- return
- }
- userList, _ := NatsServer.Read_User_List_All()
- Account.Read_User_All_Map(userList)
- var salary_r Salary.Salary_R
- salary_List, num := Salary.Read_Salary_List("", T_date, 0, 0, 9999)
- for _, salary := range salary_List {
- salary_r.T_base += salary.T_base
- salary_r.T_post += salary.T_post
- salary_r.T_seniority += salary.T_seniority
- salary_r.T_actual_Perf += salary.T_actual_Perf
- salary_r.T_back_payment += salary.T_back_payment
- salary_r.T_attendance += salary.T_attendance
- salary_r.T_cut_payment += salary.T_cut_payment
- salary_r.T_laballot += salary.T_laballot
- salary_r.T_pension_insurance += salary.T_pension_insurance
- salary_r.T_unemployment_insurance += salary.T_unemployment_insurance
- salary_r.T_medical_insurance += salary.T_medical_insurance
- salary_r.T_large_medical_insurance += salary.T_large_medical_insurance
- salary_r.T_housing_fund += salary.T_housing_fund
- salary_r.T_tax += salary.T_tax
- salary_r.T_laborage += salary.T_laborage
- salary_r.T_total += salary.T_total
- }
- salary_r.T_user_name = "合计"
- salary_r.T_user_dept = "合计"
- salary_r.T_user_post = "合计"
- salary_List = append(salary_List, salary_r)
- r_jsons.Data = salary_List
- r_jsons.Num = num
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- func (c *SalaryController) Salary_Get() {
- T_uuid := c.GetString("T_uuid")
- T_date := c.GetString("T_date")
- salary, err := Salary.Read_Salary_ByT_uuid_T_date(T_uuid, T_date)
- if err != nil {
- if err.Error() == orm.ErrNoRows.Error() {
- salary_new, err := Salary.Read_Latest_Salary_ByT_uid(T_uuid)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
- c.ServeJSON()
- return
- }
- salary_new.T_State = 3
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: salary_new}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Salary.SalaryToSalary_R(salary)}
- c.ServeJSON()
- return
- }
- func (c *SalaryController) Salary_User_Get() {
- T_date := c.GetString("T_date")
- var err error
- // 年月 2023-01
- if len(T_date) == 0 {
- T_date = time.Now().AddDate(0, -1, 0).Format("2006-01")
- }
- salary, err := Salary.Read_Salary_ByT_date(c.User.T_uuid, T_date)
- if err != nil {
- if err.Error() == orm.ErrNoRows.Error() {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "暂无当月数据!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Salary.SalaryToSalary_R(salary)}
- c.ServeJSON()
- return
- }
- func (c *SalaryController) Salary_User_List() {
- var r_jsons lib.R_JSONS
- page, _ := c.GetInt("page")
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- r_jsons.Data, r_jsons.Num = Salary.Read_Salary_List(c.User.T_uuid, "", 2, page, page_z)
- r_jsons.Page = page
- r_jsons.Page_size = int(math.Ceil(float64(r_jsons.Num) / float64(page_z)))
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 添加或修改
- func (c *SalaryController) Salary_Post() {
- T_uuid := c.GetString("T_uuid")
- // 年月 2023-01
- T_date := c.GetString("T_date")
- if len(T_date) > 0 {
- _, err := time.Parse("2006-01", T_date)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "日期格式错误!"}
- c.ServeJSON()
- return
- }
- }
- T_base, _ := c.GetFloat("T_base")
- T_post, _ := c.GetFloat("T_post")
- T_seniority, _ := c.GetFloat("T_seniority")
- T_perf, _ := c.GetFloat("T_perf")
- T_perf_score, _ := c.GetInt("T_perf_score")
- T_back_payment, _ := c.GetFloat("T_back_payment")
- T_attendance, _ := c.GetFloat("T_attendance")
- T_cut_payment, _ := c.GetFloat("T_cut_payment")
- T_pension_insurance, _ := c.GetFloat("T_pension_insurance")
- T_unemployment_insurance, _ := c.GetFloat("T_unemployment_insurance")
- T_medical_insurance, _ := c.GetFloat("T_medical_insurance")
- T_Large_medical_insurance, _ := c.GetFloat("T_large_medical_insurance")
- T_housing_fund, _ := c.GetFloat("T_housing_fund")
- T_tax, _ := c.GetFloat("T_tax")
- T_remark := c.GetString("T_remark")
- salary, err := Salary.Read_Salary_ByT_uuid_T_date(T_uuid, T_date)
- if err != nil && err.Error() != orm.ErrNoRows.Error() {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- var_ := Salary.Salary{
- T_uid: T_uuid,
- T_date: T_date,
- T_base: float32(T_base),
- T_post: float32(T_post),
- T_seniority: float32(T_seniority),
- T_perf: float32(T_perf),
- T_perf_score: T_perf_score,
- T_back_payment: float32(T_back_payment),
- T_attendance: float32(T_attendance),
- T_cut_payment: float32(T_cut_payment),
- T_pension_insurance: float32(T_pension_insurance),
- T_unemployment_insurance: float32(T_unemployment_insurance),
- T_medical_insurance: float32(T_medical_insurance),
- T_large_medical_insurance: float32(T_Large_medical_insurance),
- T_housing_fund: float32(T_housing_fund),
- T_tax: float32(T_tax),
- T_remark: T_remark,
- T_State: 1,
- }
- if salary.Id == 0 {
- var_.Id, err = Salary.Add_Salary(var_)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败"}
- c.ServeJSON()
- return
- }
- } else {
- var_.Id = salary.Id
- cols := []string{"T_base", "T_post", "T_seniority", "T_perf", "T_perf_score", "T_back_payment", "T_attendance", "T_cut_payment",
- "T_pension_insurance", "T_unemployment_insurance", "T_medical_insurance", "T_large_medical_insurance", "T_housing_fund", "T_tax",
- "T_remark"}
- _, err = Salary.Update_Salary(var_, cols...)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败"}
- c.ServeJSON()
- return
- }
- }
- NatsServer.AddUserLogs(c.User.T_uuid, "薪资管理", "添加", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: var_.Id}
- c.ServeJSON()
- return
- }
- // 发送工资条
- func (c *SalaryController) Send_Salary() {
- T_id, _ := c.GetInt("T_id")
- salary, err := Salary.Read_Salary_ById(T_id)
- id, err := Salary.Send_Salary(salary)
- year, month := strings.Split(salary.T_date, "-")[0], strings.Split(salary.T_date, "-")[1]
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败"}
- c.ServeJSON()
- return
- }
- NatsServer.AddUserLogs(c.User.T_uuid, "薪资管理", "发送工资条", id)
- if salary.T_State == 1 {
- NatsServer.AddNews(salary.T_uid, fmt.Sprintf("【工资条】您的%s年%s月工资条已送达,请查收!", year, month), conf.MySalaryNewsUrl)
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id}
- c.ServeJSON()
- return
- }
- // 导出工资数据列表
- func (c *SalaryController) Salary_Excel() {
- // 年月 2023-01
- T_date := c.GetString("T_date")
- var da time.Time
- var err error
- if len(T_date) == 0 {
- T_date = time.Now().AddDate(0, -1, 0).Format("2006-01")
- }
- da, err = time.Parse("2006-01", T_date)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "日期格式错误!"}
- c.ServeJSON()
- return
- }
- year, month := strings.Split(T_date, "-")[0], strings.Split(T_date, "-")[1]
- f := excelize.NewFile() // 设置单元格的值
- Style1, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 20, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
- })
- Style2, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 11, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center"},
- })
- f.MergeCell("Sheet1", "A1", "W1")
- f.SetRowStyle("Sheet1", 1, 1, Style1)
- f.SetRowHeight("Sheet1", 1, 50)
- f.SetCellValue("Sheet1", "A1", fmt.Sprintf("贵州宝智达网络科技有限公司%s年%s月工资表", year, month))
- f.MergeCell("Sheet1", "A2", "W2")
- f.SetRowHeight("Sheet1", 2, 30)
- f.SetRowStyle("Sheet1", 2, 2, Style2)
- day := da.AddDate(0, 1, -1).Day()
- f.SetCellValue("Sheet1", "A2", fmt.Sprintf("工资期间:%s年%s月01日至%s年%s月%02d日", year, month, year, month, day))
- Style3, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 10, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- })
- f.SetCellStyle("Sheet1", "A3", "W3", Style3)
- f.SetRowHeight("Sheet1", 3, 60)
- // 这里设置表头
- f.SetCellValue("Sheet1", "A3", "序号")
- f.SetCellValue("Sheet1", "B3", "姓名")
- f.SetCellValue("Sheet1", "C3", "部门")
- f.SetCellValue("Sheet1", "D3", "岗位")
- f.SetCellValue("Sheet1", "E3", "基本工资")
- f.SetCellValue("Sheet1", "F3", "岗位工资")
- f.SetCellValue("Sheet1", "G3", "工龄工资")
- f.SetCellValue("Sheet1", "H3", "绩效金额")
- f.SetCellValue("Sheet1", "I3", "绩效得分")
- f.SetCellValue("Sheet1", "J3", "实发绩效")
- f.SetCellValue("Sheet1", "K3", "其他补款")
- f.SetCellValue("Sheet1", "L3", "考勤扣款")
- f.SetCellValue("Sheet1", "M3", "其他扣款")
- f.SetCellValue("Sheet1", "N3", "应发合计")
- f.SetCellValue("Sheet1", "O3", "养老保险")
- f.SetCellValue("Sheet1", "P3", "失业保险")
- f.SetCellValue("Sheet1", "Q3", "基本医疗保险")
- f.SetCellValue("Sheet1", "R3", "大额医疗保险")
- f.SetCellValue("Sheet1", "S3", "公积金")
- f.SetCellValue("Sheet1", "T3", "个税扣款")
- f.SetCellValue("Sheet1", "U3", "扣款合计")
- f.SetCellValue("Sheet1", "V3", "实发合计")
- f.SetCellValue("Sheet1", "W3", "备注")
- // 设置列宽
- f.SetColWidth("Sheet1", "A", "D", 10)
- f.SetColWidth("Sheet1", "E", "I", 5)
- f.SetColWidth("Sheet1", "J", "J", 10)
- f.SetColWidth("Sheet1", "K", "M", 5)
- f.SetColWidth("Sheet1", "O", "P", 5)
- f.SetColWidth("Sheet1", "Q", "R", 6)
- f.SetColWidth("Sheet1", "S", "T", 5)
- f.SetColWidth("Sheet1", "U", "V", 12)
- f.SetColWidth("Sheet1", "W", "W", 20)
- // 冻结1-3行
- f.SetPanes("Sheet1", &excelize.Panes{
- Freeze: true,
- Split: false,
- XSplit: 2,
- YSplit: 3,
- TopLeftCell: "A1",
- ActivePane: "topRight",
- })
- // 过滤器
- f.AutoFilter("Sheet1", "A3:V3", nil)
- userList, _ := NatsServer.Read_User_List_All()
- Account.Read_User_All_Map(userList)
- salary_List, _ := Salary.Read_Salary_List("", T_date, 0, 0, 9999)
- if len(salary_List) == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("暂无%s年%s月工资数据", year, month)}
- c.ServeJSON()
- return
- }
- // 循环写入数据
- line := 4
- var base, post, seniority, actual_Perf, back_payment, attendance, cut_payment, laballot float32
- var pension_insurance, unemployment_insurance, medical_insurance, Large_medical_insurance, housing_fund, tax, laborage, total float32
- for i, salary := range salary_List {
- if len(salary.T_user_post) < 7 {
- f.SetRowHeight("Sheet1", line, 22)
- }
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
- f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), salary.T_user_name)
- f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), salary.T_user_dept)
- f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), salary.T_user_post)
- f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), salary.T_base)
- f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), salary.T_post)
- f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), salary.T_seniority)
- f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), salary.T_perf)
- f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), salary.T_perf_score)
- f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), salary.T_actual_Perf)
- f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), salary.T_back_payment)
- f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), salary.T_attendance)
- f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), salary.T_cut_payment)
- f.SetCellValue("Sheet1", fmt.Sprintf("N%d", line), salary.T_laballot)
- f.SetCellValue("Sheet1", fmt.Sprintf("O%d", line), salary.T_pension_insurance)
- f.SetCellValue("Sheet1", fmt.Sprintf("P%d", line), salary.T_unemployment_insurance)
- f.SetCellValue("Sheet1", fmt.Sprintf("Q%d", line), salary.T_medical_insurance)
- f.SetCellValue("Sheet1", fmt.Sprintf("R%d", line), salary.T_large_medical_insurance)
- f.SetCellValue("Sheet1", fmt.Sprintf("S%d", line), salary.T_housing_fund)
- f.SetCellValue("Sheet1", fmt.Sprintf("T%d", line), salary.T_tax)
- f.SetCellValue("Sheet1", fmt.Sprintf("U%d", line), salary.T_laborage)
- f.SetCellValue("Sheet1", fmt.Sprintf("V%d", line), salary.T_total)
- f.SetCellValue("Sheet1", fmt.Sprintf("W%d", line), salary.T_remark)
- base += salary.T_base
- post += salary.T_post
- seniority += salary.T_seniority
- actual_Perf += salary.T_actual_Perf
- back_payment += salary.T_back_payment
- attendance += salary.T_attendance
- cut_payment += salary.T_cut_payment
- laballot += salary.T_laballot
- pension_insurance += salary.T_pension_insurance
- unemployment_insurance += salary.T_unemployment_insurance
- medical_insurance += salary.T_medical_insurance
- Large_medical_insurance += salary.T_large_medical_insurance
- housing_fund += salary.T_housing_fund
- tax += salary.T_tax
- laborage += salary.T_laborage
- total += salary.T_total
- line++
- }
- // ------------- 最后一行 合计 ------------------------
- f.SetRowHeight("Sheet1", line, 22)
- f.MergeCell("Sheet1", fmt.Sprintf("B%d", line), fmt.Sprintf("D%d", line))
- f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), "合计")
- // 代码统计
- //f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), base)
- //f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), post)
- //f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), seniority)
- //f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), actual_Perf)
- //f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), back_payment)
- //f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), attendance)
- //f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), cut_payment)
- //f.SetCellValue("Sheet1", fmt.Sprintf("N%d", line), laballot)
- //f.SetCellValue("Sheet1", fmt.Sprintf("O%d", line), pension_insurance)
- //f.SetCellValue("Sheet1", fmt.Sprintf("P%d", line), unemployment_insurance)
- //f.SetCellValue("Sheet1", fmt.Sprintf("Q%d", line), medical_insurance)
- //f.SetCellValue("Sheet1", fmt.Sprintf("R%d", line), Large_medical_insurance)
- //f.SetCellValue("Sheet1", fmt.Sprintf("S%d", line), housing_fund)
- //f.SetCellValue("Sheet1", fmt.Sprintf("T%d", line), tax)
- //f.SetCellValue("Sheet1", fmt.Sprintf("U%d", line), laborage)
- //f.SetCellValue("Sheet1", fmt.Sprintf("V%d", line), total)
- // 函数统计
- f.SetCellFormula("Sheet1", fmt.Sprintf("E%d", line), fmt.Sprintf("SUM(E4:E%d)", line-1))
- f.SetCellFormula("Sheet1", fmt.Sprintf("F%d", line), fmt.Sprintf("SUM(F4:F%d)", line-1))
- f.SetCellFormula("Sheet1", fmt.Sprintf("G%d", line), fmt.Sprintf("SUM(G4:G%d)", line-1))
- f.SetCellFormula("Sheet1", fmt.Sprintf("J%d", line), fmt.Sprintf("SUM(J4:J%d)", line-1))
- f.SetCellFormula("Sheet1", fmt.Sprintf("K%d", line), fmt.Sprintf("SUM(K4:K%d)", line-1))
- f.SetCellFormula("Sheet1", fmt.Sprintf("L%d", line), fmt.Sprintf("SUM(L4:L%d)", line-1))
- f.SetCellFormula("Sheet1", fmt.Sprintf("M%d", line), fmt.Sprintf("SUM(M4:M%d)", line-1))
- f.SetCellFormula("Sheet1", fmt.Sprintf("N%d", line), fmt.Sprintf("SUM(N4:N%d)", line-1))
- f.SetCellFormula("Sheet1", fmt.Sprintf("O%d", line), fmt.Sprintf("SUM(O4:O%d)", line-1))
- f.SetCellFormula("Sheet1", fmt.Sprintf("P%d", line), fmt.Sprintf("SUM(P4:P%d)", line-1))
- f.SetCellFormula("Sheet1", fmt.Sprintf("Q%d", line), fmt.Sprintf("SUM(Q4:Q%d)", line-1))
- f.SetCellFormula("Sheet1", fmt.Sprintf("R%d", line), fmt.Sprintf("SUM(R4:R%d)", line-1))
- f.SetCellFormula("Sheet1", fmt.Sprintf("S%d", line), fmt.Sprintf("SUM(S4:S%d)", line-1))
- f.SetCellFormula("Sheet1", fmt.Sprintf("T%d", line), fmt.Sprintf("SUM(T4:T%d)", line-1))
- f.SetCellFormula("Sheet1", fmt.Sprintf("U%d", line), fmt.Sprintf("SUM(U4:U%d)", line-1))
- f.SetCellFormula("Sheet1", fmt.Sprintf("V%d", line), fmt.Sprintf("SUM(V4:V%d)", line-1))
- Style4, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 10, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- })
- // 黄色填充
- StyleYullowFill, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 10, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- Fill: excelize.Fill{Type: "pattern", Color: []string{"#FFFF00"}, Pattern: 1},
- })
- // 绿色填充
- StyleGreenFill, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 10, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- Fill: excelize.Fill{Type: "pattern", Color: []string{"#92D050"}, Pattern: 1},
- })
- f.SetCellStyle("Sheet1", "A4", fmt.Sprintf("W%d", line), Style4)
- f.SetCellStyle("Sheet1", "N3", fmt.Sprintf("N%d", line-1), StyleYullowFill)
- f.SetCellStyle("Sheet1", "U3", fmt.Sprintf("U%d", line-1), StyleYullowFill)
- f.SetCellStyle("Sheet1", "V3", fmt.Sprintf("V%d", line-1), StyleGreenFill)
- filename := fmt.Sprintf("贵州宝智达网络科技有限公司%s年%s月工资表(%s)", year, month, lib.GetRandstring(6, "0123456789", 0))
- // 保存文件
- if err = f.SaveAs("ofile/" + filename + ".xlsx"); err != nil {
- fmt.Println(err)
- }
- // 上传 OSS
- nats := natslibs.NewNats(Nats.Nats, conf.NatsSubj_Prefix)
- url, is := nats.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+filename+".xlsx", "ofile/"+filename+".xlsx")
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "oss!"}
- c.ServeJSON()
- return
- }
- //删除目录
- err = os.Remove("ofile/" + filename + ".xlsx")
- if err != nil {
- logs.Error(lib.FuncName(), err)
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
- c.ServeJSON()
- return
- }
|