Ver código fonte

2023-12-28 修复时长计算

zoie 11 meses atrás
pai
commit
acd0126ebe
3 arquivos alterados com 46 adições e 14 exclusões
  1. 4 4
      conf/app.conf
  2. 37 10
      controllers/Leave.go
  3. 5 0
      controllers/Overtime.go

+ 4 - 4
conf/app.conf

@@ -7,12 +7,12 @@ copyrequestbody = true
 
 Sys_Name = "ERP_AMS"
 # Nats
-NatsServer_Url = "127.0.0.1:4222"
-NatsSubj_Prefix = ""
+NatsServer_Url = "127.0.0.1:4223"
+NatsSubj_Prefix = "Test_"
 
 
 # Mysql 线上
-MysqlServer_UrlPort = "192.168.192.251:3306"
+MysqlServer_UrlPort = "127.0.0.1:3316"
 MysqlServer_Database = "erp_ams_test"
 MysqlServer_Username = "erp_ams_test"
 MysqlServer_Password = "k24fRJB7pMrmeas3"
@@ -20,7 +20,7 @@ MysqlServer_MaxIdleConnections = 100
 MysqlServer_MaxOpenConnections = 200
 
 # Redis
-Redis_address = "192.168.192.251:6379"
+Redis_address = "127.0.0.1:6378"
 Redis_password = ""
 Redis_dbNum = "1"
 

+ 37 - 10
controllers/Leave.go

@@ -128,6 +128,11 @@ func (c *LeaveController) Leave_Add() {
 		return
 	}
 
+	if startTime.After(endTime) {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "开始时间不能大于结束时间"}
+		c.ServeJSON()
+		return
+	}
 	if T_type == Attendance.AttendanceDaysOff {
 		duration := Attendance.GetRemainingDaysOff(c.User.T_uuid)
 		if T_duration > duration {
@@ -383,6 +388,37 @@ func (c *LeaveController) Leave_Duration() {
 		c.ServeJSON()
 		return
 	}
+	endTime2 := time.Date(endTime.Year(), endTime.Month(), endTime.Day()-1, 17, 30, 0, 0, time.Local)
+	endTime3 := time.Date(endTime.Year(), endTime.Month(), endTime.Day(), 9, 0, 0, 0, time.Local)
+
+	endTime4 := time.Date(endTime.Year(), endTime.Month(), endTime.Day(), 17, 30, 0, 0, time.Local)
+	endTime5 := time.Date(endTime.Year(), endTime.Month(), endTime.Day()+1, 9, 0, 0, 0, time.Local)
+	if endTime.After(endTime2) && endTime.Before(endTime3) {
+		endTime = endTime2
+	}
+
+	if endTime.After(endTime4) && endTime.Before(endTime5) {
+		endTime = endTime4
+	}
+
+	startTime2 := time.Date(startTime.Year(), startTime.Month(), startTime.Day()-1, 17, 30, 0, 0, time.Local)
+	startTime3 := time.Date(startTime.Year(), startTime.Month(), startTime.Day(), 9, 0, 0, 0, time.Local)
+
+	startTime4 := time.Date(startTime.Year(), startTime.Month(), startTime.Day(), 17, 30, 0, 0, time.Local)
+	startTime5 := time.Date(startTime.Year(), startTime.Month(), startTime.Day()+1, 9, 0, 0, 0, time.Local)
+	if startTime.After(startTime2) && startTime.Before(startTime3) {
+		startTime = startTime3
+	}
+
+	if startTime.After(startTime4) && startTime.Before(startTime5) {
+		startTime = startTime5
+	}
+
+	if startTime.After(endTime) {
+		c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: 0}
+		c.ServeJSON()
+		return
+	}
 
 	//开始时间的小时和分钟
 	s_h := startTime.Hour()
@@ -392,16 +428,7 @@ func (c *LeaveController) Leave_Duration() {
 	diff_day := int(endTime.Sub(startTime).Hours() / 24) // 间隔天数
 	var diff_hours float32                               // 间隔小时
 	var diff_minutes float32                             // 间隔分钟
-	if s_h < 9 {
-		// 开始小时早于9点,从9点起算
-		s_h = 9
-		s_mm = 0
-	}
-	if e_h >= 17 && e_mm > 30 {
-		// 结束时间晚于17:30点,到17:30点止
-		e_h = 17
-		e_mm = 30
-	}
+
 	if e_mm < s_mm {
 		// 结束分钟数<开始分钟数,向小时借
 		e_mm += 60

+ 5 - 0
controllers/Overtime.go

@@ -93,6 +93,11 @@ func (c *OvertimeController) Overtime_Add() {
 		c.ServeJSON()
 		return
 	}
+	if startTime.After(endTime) {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "开始时间不能大于结束时间"}
+		c.ServeJSON()
+		return
+	}
 	var_ := Attendance.Attendance{
 		T_uid:        c.User.T_uuid,
 		T_type:       Attendance.AttendanceOvertime,