You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
5.0 KiB
134 lines
5.0 KiB
|
4 days ago
|
package publicapi
|
||
|
|
|
||
|
|
import (
|
||
|
|
"appPlatform/models/modelshr"
|
||
|
|
"appPlatform/overall"
|
||
|
|
"appPlatform/overall/publicmethod"
|
||
|
|
"encoding/csv"
|
||
|
|
"fmt"
|
||
|
|
"net/url"
|
||
|
|
"sort"
|
||
|
|
"strconv"
|
||
|
|
"strings"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2025-08-18 14:16:25
|
||
|
|
@ 功能: 下载排班模板
|
||
|
|
*/
|
||
|
|
func (a *ApiMethod) DownLoadDutyPage(c *gin.Context) {
|
||
|
|
orgId := c.Query("orgid") //哪个行政组织
|
||
|
|
types := c.Query("types") //什么类型
|
||
|
|
timeVal := c.Query("timeval") //时间
|
||
|
|
if orgId == "undefined" || orgId == "" || orgId == "" {
|
||
|
|
c.Writer.Write([]byte("未知行政组织"))
|
||
|
|
return
|
||
|
|
}
|
||
|
|
fmt.Printf("types:%T----->%v\n\n", types, types)
|
||
|
|
fmt.Printf("timeVal:%T----->%v\n\n", timeVal, timeVal)
|
||
|
|
var orgInfo modelshr.AdministrativeOrganization
|
||
|
|
err := orgInfo.GetCont(map[string]interface{}{"`id`": orgId})
|
||
|
|
if err != nil {
|
||
|
|
c.Writer.Write([]byte("未知行政组织"))
|
||
|
|
return
|
||
|
|
}
|
||
|
|
orgIdInt, _ := strconv.ParseInt(orgId, 10, 64)
|
||
|
|
var orgList []modelshr.AdministrativeOrganization
|
||
|
|
gormDb := overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Where("`state` = 1")
|
||
|
|
gormDb = gormDb.Where("`superior` = ?", orgIdInt)
|
||
|
|
gormDb.Order("`sort` ASC").Find(&orgList)
|
||
|
|
sort.Slice(orgList, func(i, j int) bool {
|
||
|
|
return orgList[i].Sort < orgList[j].Sort
|
||
|
|
})
|
||
|
|
dayAll := time.Now().Unix()
|
||
|
|
if timeVal != "" {
|
||
|
|
dayAll, _ = strconv.ParseInt(timeVal, 10, 64)
|
||
|
|
if publicmethod.GetIntLength(dayAll) >= 13 {
|
||
|
|
dayAll = dayAll / 1000
|
||
|
|
}
|
||
|
|
}
|
||
|
|
fmt.Printf("首行--timeVal----------->%v------------->%v\n\n\n", timeVal, dayAll)
|
||
|
|
|
||
|
|
dutyTitle := fmt.Sprintf("%v周末(节假日)在岗人员", orgInfo.Name)
|
||
|
|
fileName := fmt.Sprintf("%v_%v.csv", dutyTitle, publicmethod.GetUUid(1))
|
||
|
|
shuoMing := "人员录入格式为姓名(工号);括号为英文模式下括号;在岗时间代替方式为(B:白天;Y:夜间;S:上午;X:下午;Z:值班)不填默认为值班(Z),填写格式为:秦东(300450*Z)。代表姓名:秦东;工号:300450;今天值班。多个人员用英文','分开。如:杜婷婷(206527*B),秦东(300450*Z)。不要随意更改格式,也不要更改固定好的行政组织位置及其他模版中自带的信息。否则信息会录入失败!!!"
|
||
|
|
if types == "1" {
|
||
|
|
|
||
|
|
yearVal := publicmethod.UnixTimeToDay(dayAll, 16)
|
||
|
|
yearValInt, _ := strconv.Atoi(yearVal)
|
||
|
|
monthVal := publicmethod.UnixTimeToDay(dayAll, 17)
|
||
|
|
monthValInt, _ := strconv.Atoi(monthVal)
|
||
|
|
|
||
|
|
endTime := publicmethod.GetDaysInMonth(yearValInt, monthValInt)
|
||
|
|
monthEndDay, _ := strconv.Atoi(endTime.Days)
|
||
|
|
|
||
|
|
fmt.Printf("首行--timeVal-----monthValInt------>%v------------->%v------------->%v\n\n\n", yearValInt, monthValInt, endTime)
|
||
|
|
|
||
|
|
var builder strings.Builder
|
||
|
|
builder.WriteString("\xEF\xBB\xBF") //写入UTF-8 BOM 防止乱码
|
||
|
|
writer := csv.NewWriter(&builder)
|
||
|
|
writer.Write([]string{dutyTitle, shuoMing}) //标题
|
||
|
|
// dayAllStr := publicmethod.UnixTimeToDay(dayAll, 15)
|
||
|
|
var fristHane []string
|
||
|
|
dayAllStr := fmt.Sprintf("\t%v", publicmethod.UnixTimeToDay(dayAll, 15))
|
||
|
|
// fristHane = append(fristHane, fmt.Sprintf("%v年%v月", yearVal, monthVal))
|
||
|
|
fristHane = append(fristHane, dayAllStr)
|
||
|
|
|
||
|
|
for i := 1; i <= monthEndDay; i++ {
|
||
|
|
fristHane = append(fristHane, strconv.Itoa(i))
|
||
|
|
}
|
||
|
|
fmt.Printf("首行------------->%v------------->%v\n\n\n", monthEndDay, fristHane)
|
||
|
|
writer.Write(fristHane) //首行
|
||
|
|
if orgIdInt == 309 {
|
||
|
|
writer.Write([]string{"公司带班"})
|
||
|
|
}
|
||
|
|
writer.Write([]string{"公司值班"})
|
||
|
|
//循环输出体
|
||
|
|
for _, v := range orgList {
|
||
|
|
writer.Write([]string{v.Name}) //
|
||
|
|
}
|
||
|
|
writer.Flush()
|
||
|
|
|
||
|
|
c.Writer.Header().Add("Content-type", "application/octet-stream")
|
||
|
|
c.Header("Content-Type", "application/vnd.ms-excel;charset=utf8")
|
||
|
|
c.Header("Content-Disposition", "attachment; filename="+url.PathEscape(fileName))
|
||
|
|
// c.Header("Content-Disposition", "attachment; filename=团队角色盘点.csv")
|
||
|
|
c.Header("Content-Transfer-Encoding", "binary")
|
||
|
|
c.Writer.Write([]byte(builder.String()))
|
||
|
|
} else {
|
||
|
|
|
||
|
|
dayAllStr := fmt.Sprintf("\t%v", publicmethod.UnixTimeToDay(dayAll, 14))
|
||
|
|
dayHao := publicmethod.UnixTimeToDay(dayAll, 18)
|
||
|
|
|
||
|
|
// dayInt, _ := strconv.ParseInt(dayHao, 10, 64)
|
||
|
|
var builder strings.Builder
|
||
|
|
builder.WriteString("\xEF\xBB\xBF") //写入UTF-8 BOM 防止乱码
|
||
|
|
writer := csv.NewWriter(&builder)
|
||
|
|
writer.Write([]string{dutyTitle, shuoMing}) //标题
|
||
|
|
writer.Write([]string{dayAllStr, dayHao}) //首行
|
||
|
|
if orgIdInt == 309 {
|
||
|
|
writer.Write([]string{"公司带班"})
|
||
|
|
}
|
||
|
|
writer.Write([]string{"公司值班"})
|
||
|
|
//循环输出体
|
||
|
|
for _, v := range orgList {
|
||
|
|
writer.Write([]string{v.Name, ""}) //
|
||
|
|
}
|
||
|
|
writer.Flush()
|
||
|
|
|
||
|
|
c.Writer.Header().Add("Content-type", "application/octet-stream")
|
||
|
|
c.Header("Content-Type", "application/vnd.ms-excel;charset=utf8")
|
||
|
|
c.Header("Content-Disposition", "attachment; filename="+url.PathEscape(fileName))
|
||
|
|
// c.Header("Content-Disposition", "attachment; filename=团队角色盘点.csv")
|
||
|
|
c.Header("Content-Transfer-Encoding", "binary")
|
||
|
|
c.Writer.Write([]byte(builder.String()))
|
||
|
|
}
|
||
|
|
|
||
|
|
// c.Writer.Write([]byte("未知行政组织"))
|
||
|
|
}
|