package controllers import ( "ERP_ams/Nats/NatsServer" "ERP_ams/conf" "ERP_ams/models/Account" "ERP_ams/models/Attendance" "fmt" userlibs "git.baozhida.cn/ERP_libs/User" "git.baozhida.cn/ERP_libs/lib" beego "github.com/beego/beego/v2/server/web" "math" "strconv" ) type OvertimeController struct { beego.Controller User userlibs.User } func (c *OvertimeController) Prepare() { c.User = *Account.User_r } // 管理员加班审批列表 只显示待审核 func (c *OvertimeController) Overtime_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 } userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) r_jsons.Data, r_jsons.Num = Attendance.Read_Attendance_List("", c.User.T_uuid, 1, Attendance.AttendanceWaitAudit, 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 *OvertimeController) Overtime_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 } T_uuid := c.GetString("T_uuid") if len(T_uuid) == 0 { T_uuid = c.User.T_uuid } userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) r_jsons.Data, r_jsons.Num = Attendance.Read_Attendance_List(T_uuid, "", 1, 0, 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 *OvertimeController) Overtime_Add() { T_start_time := c.GetString("T_start_time") T_prove_img := c.GetString("T_prove_img") T_end_time := c.GetString("T_end_time") T_duration, _ := c.GetInt("T_duration") T_text := c.GetString("T_text") T_approver := c.GetString("T_approver") startTime, is := lib.TimeStrToTime(T_start_time) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式不正确"} c.ServeJSON() return } endTime, is := lib.TimeStrToTime(T_end_time) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式不正确"} c.ServeJSON() return } var_ := Attendance.Attendance{ T_uid: c.User.T_uuid, T_type: Attendance.AttendanceOvertime, T_start_time: startTime, T_prove_img: T_prove_img, T_end_time: endTime, T_duration: T_duration, T_text: T_text, T_approver: T_approver, T_State: Attendance.AttendanceWaitAudit, } _, err := Attendance.Add_Attendance(var_) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "我的加班", "添加", var_) NatsServer.AddNews(T_approver, fmt.Sprintf("【加班审批】您有一条%s的加班审批待处理", c.User.T_name), conf.OvertimeApprovalNewsUrl) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: var_.Id} c.ServeJSON() return } func (c *OvertimeController) Overtime_Update() { T_id, _ := c.GetInt("T_id") T_type, _ := c.GetInt("T_type") T_start_time := c.GetString("T_start_time") T_prove_img := c.GetString("T_prove_img") T_end_time := c.GetString("T_end_time") T_duration, _ := c.GetInt("T_duration") T_text := c.GetString("T_text") T_approver := c.GetString("T_approver") leave, err := Attendance.Read_Attendance_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"} c.ServeJSON() return } if leave.T_State == Attendance.AttendancePass { c.Data["json"] = lib.JSONS{Code: 202, Msg: "加班审批已通过,禁止修改!"} c.ServeJSON() return } if T_type > 0 { leave.T_type = T_type } if len(T_start_time) > 0 { startTime, is := lib.TimeStrToTime(T_start_time) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式不正确"} c.ServeJSON() return } leave.T_start_time = startTime } leave.T_prove_img = T_prove_img if len(T_end_time) > 0 { endTime, is := lib.TimeStrToTime(T_end_time) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "时间格式不正确"} c.ServeJSON() return } leave.T_end_time = endTime } if T_duration > 0 { leave.T_duration = T_duration } if len(T_text) > 0 { leave.T_text = T_text } if len(T_approver) > 0 { leave.T_approver = T_approver } leave.T_State = Attendance.AttendanceWaitAudit _, err = Attendance.Update_Attendance(leave, "T_type", "T_start_time", "T_prove_img", "T_end_time", "T_duration", "T_text", "T_approver", "T_State") if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "我的加班", "修改", leave) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id} c.ServeJSON() return } // 审批 func (c *OvertimeController) Overtime_Approval() { T_id, _ := c.GetInt("T_id") T_State, _ := c.GetInt("T_State") leave, err := Attendance.Read_Attendance_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"} c.ServeJSON() return } if leave.T_approver != c.User.T_uuid { c.Data["json"] = lib.JSONS{Code: 202, Msg: "无权操作!"} c.ServeJSON() return } if T_State == 1 { leave.T_State = Attendance.AttendancePass } if T_State == 0 { leave.T_State = Attendance.AttendanceNotPass } id, err := Attendance.Update_Attendance(leave, "T_State") if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "加班审批", "审批", leave) NatsServer.AddNews(leave.T_uid, "【加班申请】您的加班申请已通过", conf.MyOvertimeNewsUrl) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: id} c.ServeJSON() return } // 删除加班 func (c *OvertimeController) Overtime_Del() { T_id, _ := c.GetInt("T_id") leave, err := Attendance.Read_Attendance_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"} c.ServeJSON() return } if leave.T_State == Attendance.AttendancePass { c.Data["json"] = lib.JSONS{Code: 202, Msg: "加班审批已通过,禁止删除!"} c.ServeJSON() return } id, err := Attendance.Delete_Attendance(leave) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "我的加班", "删除", strconv.Itoa(T_id)) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: id} c.ServeJSON() return } // 加班统计 func (c *OvertimeController) Overtime_Stat() { page, _ := c.GetInt("page") if page < 1 { page = 1 } page_z, _ := c.GetInt("page_z") if page_z < 1 { page_z = conf.Page_size } T_uuid := c.GetString("T_uuid") if len(T_uuid) == 0 { T_uuid = c.User.T_uuid } attendance, cnt := Attendance.Read_Attendance_List_For_Stat(T_uuid, 0, 9999) userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) var duration int for i := len(attendance) - 1; i >= 0; i-- { if attendance[i].T_type == Attendance.AttendanceDaysOff || attendance[i].T_type == Attendance.AttendanceShiftPerf || attendance[i].T_type > 100 { duration -= attendance[i].T_duration attendance[i].T_duration = -attendance[i].T_duration } else { duration += attendance[i].T_duration } attendance[i].RemainingTime = duration } type R_JSONS struct { //必须的大写开头 Data interface{} RemainingTime int // 剩余时长 Num int64 Page int Page_size int } var r_jsons R_JSONS offset := (page - 1) * page_z limit := offset + page_z if limit > int(cnt) { limit = int(cnt) } r_jsons.Num = cnt r_jsons.RemainingTime = Attendance.GetRemainingDaysOff(T_uuid) r_jsons.Data = attendance[offset:limit] 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 }