Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
homekeeper
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Peter Cheng
homekeeper
Commits
6df3bbad
Commit
6df3bbad
authored
Jun 19, 2019
by
Peter Cheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
追加重新設定所有員工休假區間功能
parent
a3bb5080
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
4 deletions
+90
-4
README.md
README.md
+15
-0
punchclock.go
controllers/punchclock.go
+34
-4
leave.go
models/leave.go
+40
-0
api.go
route/api.go
+1
-0
No files found.
README.md
View file @
6df3bbad
...
...
@@ -153,4 +153,19 @@ go get -u -v github.com/gin-gonic/gin
"key": "menu",
"value": "0:5"
}
```
計算休假區間,中間會扣除午休九十分鐘 http://
[
Your Host Name
]
:8806/PunchClock/CalcTime
```
//HTTP Header需設定成Content-Type: application/json
{
"begin":{"year":"2019","month":"6","day":"19","hour":"10","minute":"46"},
"end":{"year":"2019","month":"6","day":"25","hour":"18","minute":"0"}
}
```
重新設定所有員工休假區間 http://
[
Your Host Name
]
:8806/PunchClock/ResetAllUseMinute
```
//HTTP Header需設定成Content-Type: application/json
{}
```
\ No newline at end of file
controllers/punchclock.go
View file @
6df3bbad
...
...
@@ -14,9 +14,39 @@ import (
"github.com/teed7334-restore/homekeeper/models"
)
//ResetAllUseMinute 重新計算所有請假時間
func
ResetAllUseMinute
(
c
*
gin
.
Context
)
{
cfg
:=
env
.
GetEnv
()
models
.
SetUseMinuteToZero
()
result
:=
models
.
GetLeaveHistory
()
for
_
,
item
:=
range
result
{
beginDateStr
:=
item
.
Startdate
.
Format
(
cfg
.
TimeFormat
)
beginDateStr
=
strings
.
Split
(
beginDateStr
,
" "
)[
0
]
beginDateArr
:=
strings
.
Split
(
beginDateStr
,
"-"
)
beginTimeArr
:=
strings
.
Split
(
item
.
Starttime
,
":"
)
endDateStr
:=
item
.
Enddate
.
Format
(
cfg
.
TimeFormat
)
endDateStr
=
strings
.
Split
(
endDateStr
,
" "
)[
0
]
endDateArr
:=
strings
.
Split
(
endDateStr
,
"-"
)
endTimeArr
:=
strings
.
Split
(
item
.
Endtime
,
":"
)
begin
:=
&
beans
.
TimeStruct
{
Year
:
beginDateArr
[
0
],
Month
:
beginDateArr
[
1
],
Day
:
beginDateArr
[
2
],
Hour
:
beginTimeArr
[
0
],
Minute
:
beginTimeArr
[
1
],
Second
:
"00"
}
end
:=
&
beans
.
TimeStruct
{
Year
:
endDateArr
[
0
],
Month
:
endDateArr
[
1
],
Day
:
endDateArr
[
2
],
Hour
:
endTimeArr
[
0
],
Minute
:
endTimeArr
[
1
],
Second
:
"00"
}
params
:=
&
beans
.
Punchclock
{
Begin
:
begin
,
End
:
end
}
diffDay
,
diffHour
,
diffMinute
:=
calcLeaveScope
(
params
)
useMinute
:=
diffDay
*
8
*
60
+
diffHour
*
60
+
diffMinute
models
.
SetUseMinute
(
useMinute
,
item
.
ID
)
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"status"
:
"true"
})
}
//CalcTime 計算時數
func
CalcTime
(
c
*
gin
.
Context
)
{
params
:=
getPunchclockParams
(
c
)
diffDay
,
diffHour
,
diffMinute
:=
calcLeaveScope
(
params
)
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"diffDay"
:
diffDay
,
"diffHour"
:
diffHour
,
"diffMinute"
:
diffMinute
})
}
//calcLeaveScope 計算休假區間主程式
func
calcLeaveScope
(
params
*
beans
.
Punchclock
)
(
diffDay
int
,
diffHour
int
,
diffMinute
int
)
{
beginYear
:=
params
.
GetBegin
()
.
GetYear
()
beginMonth
:=
appendZero
(
params
.
GetBegin
()
.
GetMonth
())
beginDay
:=
appendZero
(
params
.
GetBegin
()
.
GetDay
())
...
...
@@ -31,9 +61,9 @@ func CalcTime(c *gin.Context) {
beginTime
,
_
:=
strconv
.
Atoi
(
beginHour
+
beginMinute
)
endTime
,
_
:=
strconv
.
Atoi
(
endHour
+
endMinute
)
diffDay
:
=
0
diffHour
:
=
0
diffMinute
:
=
0
diffDay
=
0
diffHour
=
0
diffMinute
=
0
beginHour
,
beginMinute
,
endHour
,
endMinute
=
changeToLunchTime
(
beginTime
,
endTime
,
beginHour
,
beginMinute
,
endHour
,
endMinute
)
...
...
@@ -68,7 +98,7 @@ func CalcTime(c *gin.Context) {
diffMinute
=
diffMinute
+
_diffMinute
}
diffDay
,
diffHour
,
diffMinute
=
setCarry
(
diffDay
,
diffHour
,
diffMinute
)
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"diffDay"
:
diffDay
,
"diffHour"
:
diffHour
,
"diffMinute"
:
diffMinute
})
return
diffDay
,
diffHour
,
diffMinute
}
//setCarry 設定進位
...
...
models/leave.go
0 → 100644
View file @
6df3bbad
package
models
import
(
"time"
db
"github.com/teed7334-restore/homekeeper/database"
)
//Leaves 休假申請物件
type
Leaves
struct
{
ID
int
Startdate
time
.
Time
Enddate
time
.
Time
Starttime
string
Endtime
string
}
//SetUseMinuteToZero 將使用時間設為零
func
SetUseMinuteToZero
()
{
sql
:=
"UPDATE leaves SET useMinute = ?"
db
.
Db
.
Exec
(
sql
,
0
)
sql
=
"UPDATE leaves_history SET useMinute = ?"
db
.
Db
.
Exec
(
sql
,
0
)
}
//SetUseMinute 設定休假花費時間
func
SetUseMinute
(
useMinute
int
,
ID
int
)
{
sql
:=
"UPDATE leaves SET useMinute = ? WHERE id = ?"
db
.
Db
.
Exec
(
sql
,
useMinute
,
ID
)
sql
=
"UPDATE leaves_history SET useMinute = ? WHERE id = ?"
db
.
Db
.
Exec
(
sql
,
useMinute
,
ID
)
}
//GetLeaveHistory 取得假期日誌
func
GetLeaveHistory
()
[]
*
Leaves
{
list
:=
[]
*
Leaves
{}
sql
:=
"SELECT id, startdate, enddate, starttime, endtime FROM leaves"
db
.
Db
.
Raw
(
sql
)
.
Scan
(
&
list
)
return
list
}
route/api.go
View file @
6df3bbad
...
...
@@ -27,5 +27,6 @@ func API() *gin.Engine {
route
.
POST
(
"/Redis/LSet"
,
controllers
.
LSetRedis
)
route
.
POST
(
"/Redis/LRange"
,
controllers
.
LRangeRedis
)
route
.
POST
(
"/PunchClock/CalcTime"
,
controllers
.
CalcTime
)
route
.
POST
(
"/PunchClock/ResetAllUseMinute"
,
controllers
.
ResetAllUseMinute
)
return
route
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment