|
@@ -0,0 +1,348 @@
|
|
|
+package controllers
|
|
|
+
|
|
|
+import (
|
|
|
+ "ERP_ams/Nats/NatsServer"
|
|
|
+ "ERP_ams/conf"
|
|
|
+ "ERP_ams/models/Account"
|
|
|
+ "ERP_ams/models/Attendance"
|
|
|
+ userlibs "git.baozhida.cn/ERP_libs/User"
|
|
|
+ "git.baozhida.cn/ERP_libs/lib"
|
|
|
+ beego "github.com/beego/beego/v2/server/web"
|
|
|
+ "math"
|
|
|
+ "strconv"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+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
|
|
|
+ }
|
|
|
+ // 年月 2023-01
|
|
|
+ T_month := c.GetString("T_month")
|
|
|
+
|
|
|
+ if len(T_month) > 0 {
|
|
|
+ _, err := time.Parse("2006-01", T_month)
|
|
|
+ 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)
|
|
|
+ r_jsons.Data, r_jsons.Num = Attendance.Read_Attendance_List("", c.User.T_uuid, T_month, 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
|
|
|
+ }
|
|
|
+ // 年月 2023-01
|
|
|
+ T_month := c.GetString("T_month")
|
|
|
+ if len(T_month) > 0 {
|
|
|
+ _, err := time.Parse("2006-01", T_month)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "日期格式错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ r_jsons.Data, r_jsons.Num = Attendance.Read_Attendance_List(T_uuid, "", T_month, 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_start_prove := c.GetString("T_start_prove")
|
|
|
+ T_end_time := c.GetString("T_end_time")
|
|
|
+ T_end_prove := c.GetString("T_end_prove")
|
|
|
+ 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_start_prove: T_start_prove,
|
|
|
+ T_end_time: endTime,
|
|
|
+ T_end_prove: T_end_prove,
|
|
|
+ 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_)
|
|
|
+
|
|
|
+ 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_start_prove := c.GetString("T_start_prove")
|
|
|
+ T_end_time := c.GetString("T_end_time")
|
|
|
+ T_end_prove := c.GetString("T_end_prove")
|
|
|
+ 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
|
|
|
+
|
|
|
+ }
|
|
|
+ if len(T_start_prove) > 0 {
|
|
|
+ leave.T_start_prove = T_start_prove
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 len(T_end_prove) > 0 {
|
|
|
+ leave.T_end_prove = T_end_prove
|
|
|
+ }
|
|
|
+
|
|
|
+ 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_start_prove", "T_end_time", "T_end_prove", "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)
|
|
|
+
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ // 年月 2023-01
|
|
|
+ T_month := c.GetString("T_month")
|
|
|
+ if len(T_month) > 0 {
|
|
|
+ _, err := time.Parse("2006-01", T_month)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "日期格式错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ attendance, cnt := Attendance.Read_Attendance_List_For_Stat(c.User.T_uuid, T_month, page, page_z)
|
|
|
+
|
|
|
+ var duration int
|
|
|
+ for i := 0; i < len(attendance); i++ {
|
|
|
+ if attendance[i].T_type == Attendance.AttendanceDaysOff || attendance[i].T_type == Attendance.AttendanceShiftPerf {
|
|
|
+ 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
|
|
|
+ r_jsons.Num = cnt
|
|
|
+ r_jsons.RemainingTime = duration
|
|
|
+ r_jsons.Data = attendance
|
|
|
+ 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
|
|
|
+}
|