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
6e301e98
Commit
6e301e98
authored
Aug 29, 2019
by
Peter Cheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
追加員工打卡記錄上鏈API
parent
87d08780
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
749 additions
and
99 deletions
+749
-99
README.md
README.md
+66
-19
hyperledgerREST.pb.go
beans/hyperledgerREST.pb.go
+243
-0
hyperledgerREST.proto
beans/hyperledgerREST.proto
+30
-0
punchclock.pb.go
beans/punchclock.pb.go
+182
-39
punchclock.proto
beans/punchclock.proto
+27
-5
sendMail.pb.go
beans/sendMail.pb.go
+4
-4
base.go
controllers/base.go
+36
-0
mail.go
controllers/mail.go
+1
-4
punchclock.go
controllers/punchclock.go
+126
-6
redis.go
controllers/redis.go
+24
-21
env.swp
env/env.swp
+5
-1
api.go
route/api.go
+5
-0
No files found.
README.md
View file @
6e301e98
...
...
@@ -170,24 +170,71 @@ go get -u -v github.com/gin-gonic/gin
{}
```
重新設定所有員工休假區間 http://
[
Your Host Name
]
:8806/GoMyPay/PayCreditCard
```
//HTTP Header需設定成Content-Type: application/json
{
"Send_Type":"1",
"Pay_Mode_No":"2",
"Order_No":"2019062500001",
"Amount":"100",
"TransCode":"00",
"Buyer_Name":"Peter Cheng",
"Buyer_Mail":"teed7334@gmail.com",
"Buyer_Memo":"Omega 手錶",
"CardNo":"5509158011124600",
"ExpireDate":"2307",
"CVV":"811",
"TransMode":"1",
"Installment":"0",
"e_return":"1",
"Str_Check":""
取鏈上取得打卡資料 http://
[
Your Host Name
]
:8806/PunchClock/GetEmployeeOnChain
```
//HTTP Header需設定成Content-Type: application/json
{
"identify":"00190"
}
```
寫入員工卡鐘資料 http://
[
Your Host Name
]
:8806/PunchClock/AddEmployeeOnChain
```
//HTTP Header需設定成Content-Type: application/json
{
"identify":"00192",
"firstName":"Tony",
"lastName":"Chen"
}
```
取鏈上取得打卡資料 http://
[
Your Host Name
]
:8806/PunchClock/GetPunchclockOnChain
```
//HTTP Header需設定成Content-Type: application/json
{
"id":"3acde18a-a36b-49de-be4f-b552398b140f"
}
```
寫入員工卡鐘資料 http://
[
Your Host Name
]
:8806/PunchClock/AddPunchclockOnChain
```
//HTTP Header需設定成Content-Type: application/json
{
"id":"20190822.00190",
"onWorkDate":"2019-08-22",
"onWorkTime":"09:50",
"offWorkTime":"20:00",
"workTimes":"9 hour 1 minute",
"employee": "00190"
}
```
將每天員工打卡資料上鏈 http://
[
Your Host Name
]
:8806/PunchClock/UploadDailyPunchclockData
```
//HTTP Header需設定成Content-Type: application/json
{
"employee": {
"identify": "00190",
"firstName": "Peter",
"lastName": "Cheng"
},
"punchclock": {
"begin": {
"year": "2019",
"month": "08",
"day": "28",
"hour": "09",
"minute": "24",
"second": "00"
},
"end": {
"year": "2019",
"month": "08",
"day": "28",
"hour": "20",
"minute": "05",
"second": "00"
}
}
}
```
\ No newline at end of file
beans/hyperledgerREST.pb.go
0 → 100644
View file @
6e301e98
// Code generated by protoc-gen-go.
// source: hyperledgerREST.proto
// DO NOT EDIT!
/*
Package beans is a generated protocol buffer package.
It is generated from these files:
hyperledgerREST.proto
punchclock.proto
redis.proto
sendMail.proto
It has these top-level messages:
GetEmployee
GetPunchclock
APIError
TimeStruct
Punchclock
EmployeeOnChain
PunchclockOnChain
DailyPunchclockData
Redis
SendMail
*/
package
beans
import
proto
"github.com/golang/protobuf/proto"
import
fmt
"fmt"
import
math
"math"
// Reference imports to suppress errors if they are not otherwise used.
var
_
=
proto
.
Marshal
var
_
=
fmt
.
Errorf
var
_
=
math
.
Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const
_
=
proto
.
ProtoPackageIsVersion2
// please upgrade the proto package
type
GetEmployee
struct
{
Class
string
`protobuf:"bytes,1,opt,name=Class" json:"$class" form:"$class"`
Identify
string
`protobuf:"bytes,2,opt,name=Identify" json:"identify" form:"identify"`
FirstName
string
`protobuf:"bytes,3,opt,name=FirstName" json:"firstName" form:"firstName"`
LastName
string
`protobuf:"bytes,4,opt,name=LastName" json:"lastName" form:"lastName"`
Error
*
APIError
`protobuf:"bytes,5,opt,name=Error" json:"error" form:"error"`
}
func
(
m
*
GetEmployee
)
Reset
()
{
*
m
=
GetEmployee
{}
}
func
(
m
*
GetEmployee
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
GetEmployee
)
ProtoMessage
()
{}
func
(
*
GetEmployee
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor0
,
[]
int
{
0
}
}
func
(
m
*
GetEmployee
)
GetClass
()
string
{
if
m
!=
nil
{
return
m
.
Class
}
return
""
}
func
(
m
*
GetEmployee
)
GetIdentify
()
string
{
if
m
!=
nil
{
return
m
.
Identify
}
return
""
}
func
(
m
*
GetEmployee
)
GetFirstName
()
string
{
if
m
!=
nil
{
return
m
.
FirstName
}
return
""
}
func
(
m
*
GetEmployee
)
GetLastName
()
string
{
if
m
!=
nil
{
return
m
.
LastName
}
return
""
}
func
(
m
*
GetEmployee
)
GetError
()
*
APIError
{
if
m
!=
nil
{
return
m
.
Error
}
return
nil
}
type
GetPunchclock
struct
{
Class
string
`protobuf:"bytes,12,opt,name=Class" json:"$class" form:"$class"`
ID
string
`protobuf:"bytes,13,opt,name=ID" json:"id" form:"id"`
OnWorkDate
string
`protobuf:"bytes,14,opt,name=OnWorkDate" json:"onWorkDate" form:"onWorkDate"`
OffWorkTime
string
`protobuf:"bytes,15,opt,name=OffWorkTime" json:"offWorkTime" form:"offWorkTime"`
WorkTimes
string
`protobuf:"bytes,16,opt,name=WorkTimes" json:"workTimes" form:"workTimes"`
Employee
string
`protobuf:"bytes,17,opt,name=Employee" json:"employee" form:"employee"`
Error
*
APIError
`protobuf:"bytes,18,opt,name=Error" json:"error" form:"error"`
}
func
(
m
*
GetPunchclock
)
Reset
()
{
*
m
=
GetPunchclock
{}
}
func
(
m
*
GetPunchclock
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
GetPunchclock
)
ProtoMessage
()
{}
func
(
*
GetPunchclock
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor0
,
[]
int
{
1
}
}
func
(
m
*
GetPunchclock
)
GetClass
()
string
{
if
m
!=
nil
{
return
m
.
Class
}
return
""
}
func
(
m
*
GetPunchclock
)
GetID
()
string
{
if
m
!=
nil
{
return
m
.
ID
}
return
""
}
func
(
m
*
GetPunchclock
)
GetOnWorkDate
()
string
{
if
m
!=
nil
{
return
m
.
OnWorkDate
}
return
""
}
func
(
m
*
GetPunchclock
)
GetOffWorkTime
()
string
{
if
m
!=
nil
{
return
m
.
OffWorkTime
}
return
""
}
func
(
m
*
GetPunchclock
)
GetWorkTimes
()
string
{
if
m
!=
nil
{
return
m
.
WorkTimes
}
return
""
}
func
(
m
*
GetPunchclock
)
GetEmployee
()
string
{
if
m
!=
nil
{
return
m
.
Employee
}
return
""
}
func
(
m
*
GetPunchclock
)
GetError
()
*
APIError
{
if
m
!=
nil
{
return
m
.
Error
}
return
nil
}
type
APIError
struct
{
StatusCode
int32
` protobuf:"varint,6,opt,name=statusCode" json:"statusCode,omitempty"`
Name
string
` protobuf:"bytes,7,opt,name=name" json:"name,omitempty"`
Message
string
` protobuf:"bytes,8,opt,name=message" json:"message,omitempty"`
Status
string
` protobuf:"bytes,9,opt,name=status" json:"status,omitempty"`
Code
string
` protobuf:"bytes,10,opt,name=code" json:"code,omitempty"`
Stack
string
` protobuf:"bytes,11,opt,name=stack" json:"stack,omitempty"`
}
func
(
m
*
APIError
)
Reset
()
{
*
m
=
APIError
{}
}
func
(
m
*
APIError
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
APIError
)
ProtoMessage
()
{}
func
(
*
APIError
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor0
,
[]
int
{
2
}
}
func
(
m
*
APIError
)
GetStatusCode
()
int32
{
if
m
!=
nil
{
return
m
.
StatusCode
}
return
0
}
func
(
m
*
APIError
)
GetName
()
string
{
if
m
!=
nil
{
return
m
.
Name
}
return
""
}
func
(
m
*
APIError
)
GetMessage
()
string
{
if
m
!=
nil
{
return
m
.
Message
}
return
""
}
func
(
m
*
APIError
)
GetStatus
()
string
{
if
m
!=
nil
{
return
m
.
Status
}
return
""
}
func
(
m
*
APIError
)
GetCode
()
string
{
if
m
!=
nil
{
return
m
.
Code
}
return
""
}
func
(
m
*
APIError
)
GetStack
()
string
{
if
m
!=
nil
{
return
m
.
Stack
}
return
""
}
func
init
()
{
proto
.
RegisterType
((
*
GetEmployee
)(
nil
),
"beans.GetEmployee"
)
proto
.
RegisterType
((
*
GetPunchclock
)(
nil
),
"beans.GetPunchclock"
)
proto
.
RegisterType
((
*
APIError
)(
nil
),
"beans.APIError"
)
}
func
init
()
{
proto
.
RegisterFile
(
"hyperledgerREST.proto"
,
fileDescriptor0
)
}
var
fileDescriptor0
=
[]
byte
{
// 344 bytes of a gzipped FileDescriptorProto
0x1f
,
0x8b
,
0x08
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x02
,
0xff
,
0x7c
,
0x92
,
0xdf
,
0x6a
,
0xea
,
0x40
,
0x10
,
0xc6
,
0x89
,
0xc7
,
0xf8
,
0x67
,
0x72
,
0xd4
,
0x73
,
0x96
,
0xb6
,
0x0c
,
0xa5
,
0x94
,
0x20
,
0x14
,
0xbc
,
0xf2
,
0xa2
,
0x7d
,
0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View file @
6e301e98
syntax
=
"proto3"
;
package
beans
;
message
GetEmployee
{
string
Class
=
1
;
//`json:"$class" form:"$class"`
string
Identify
=
2
;
//`json:"identify" form:"identify"`
string
FirstName
=
3
;
//`json:"firstName" form:"firstName"`
string
LastName
=
4
;
//`json:"lastName" form:"lastName"`
APIError
Error
=
5
;
//`json:"error" form:"error"`
}
message
GetPunchclock
{
string
Class
=
12
;
//`json:"$class" form:"$class"`
string
ID
=
13
;
//`json:"id" form:"id"`
string
OnWorkDate
=
14
;
//`json:"onWorkDate" form:"onWorkDate"`
string
OffWorkTime
=
15
;
//`json:"offWorkTime" form:"offWorkTime"`
string
WorkTimes
=
16
;
//`json:"workTimes" form:"workTimes"`
string
Employee
=
17
;
//`json:"employee" form:"employee"`
APIError
Error
=
18
;
//`json:"error" form:"error"`
}
message
APIError
{
int32
statusCode
=
6
;
//`json:"status_code" form:"status_code"`
string
name
=
7
;
//`json:"name" form:"name"`
string
message
=
8
;
//`json:"message" form:"message"`
string
status
=
9
;
//`json:"status" form:"status"`
string
code
=
10
;
//`json:"code" form:"code"`
string
stack
=
11
;
//`json:"stack" form:"stack"`
}
\ No newline at end of file
beans/punchclock.pb.go
View file @
6e301e98
This diff is collapsed.
Click to expand it.
beans/punchclock.proto
View file @
6e301e98
...
...
@@ -2,11 +2,6 @@ syntax = "proto3";
package
beans
;
message
Punchclock
{
TimeStruct
Begin
=
7
;
//`json:"begin"`
TimeStruct
End
=
8
;
//`json:"end"`
}
message
TimeStruct
{
string
Year
=
1
;
//`json:"year"`
string
Month
=
2
;
//`json:"month"`
...
...
@@ -14,4 +9,31 @@ message TimeStruct {
string
Hour
=
4
;
//`json:"hour"`
string
Minute
=
5
;
//`json:"minute"`
string
Second
=
6
;
//`json:"second"`
}
message
Punchclock
{
TimeStruct
Begin
=
7
;
//`json:"begin"`
TimeStruct
End
=
8
;
//`json:"end"`
}
message
EmployeeOnChain
{
string
Class
=
9
;
//`json:"$class" form:"$class"`
string
Identify
=
10
;
//`json:"identify" form:"identify"`
string
FirstName
=
11
;
//`json:"firstName" form:"firstName"`
string
LastName
=
12
;
//`json:"lastName" form:"lastName"`
}
message
PunchclockOnChain
{
string
Class
=
13
;
//`json:"$class" form:"$class"`
string
ID
=
14
;
//`json:"id" form:"id"`
string
OnWorkDate
=
15
;
//`json:"onWorkDate" form:"onWorkDate"`
string
OnWorkTime
=
16
;
//`json:"onWorkTime" form:"onWorkTime"`
string
OffWorkTime
=
17
;
//`json:"offWorkTime" form:"offWorkTime"`
string
WorkTimes
=
18
;
//`json:"workTimes" form:"workTimes"`
string
Employee
=
19
;
//`json:"employee" form:"employee"`
}
message
DailyPunchclockData
{
EmployeeOnChain
Employee
=
20
;
//`json:"employee" form:"employee"`
Punchclock
Punchclock
=
21
;
//`json:"punchclock" form:"punchclock"`
}
\ No newline at end of file
beans/sendMail.pb.go
View file @
6e301e98
...
...
@@ -14,10 +14,10 @@ var _ = fmt.Errorf
var
_
=
math
.
Inf
type
SendMail
struct
{
To
string
` protobuf:"bytes,1,opt,name=To" json:"To,omitempty"
form:"to"`
Cc
string
` protobuf:"bytes,2,opt,name=Cc" json:"Cc,omitempty"
form:"cc"`
Subject
string
` protobuf:"bytes,3,opt,name=Subject" json:"Subject,omitempty"
form:"subject"`
Content
string
` protobuf:"bytes,4,opt,name=Content" json:"Content,omitempty"
form:"content"`
To
string
` protobuf:"bytes,1,opt,name=To" json:"To,omitempty" form:"to"`
Cc
string
` protobuf:"bytes,2,opt,name=Cc" json:"Cc,omitempty" form:"cc"`
Subject
string
` protobuf:"bytes,3,opt,name=Subject" json:"Subject,omitempty" form:"subject"`
Content
string
` protobuf:"bytes,4,opt,name=Content" json:"Content,omitempty" form:"content"`
}
func
(
m
*
SendMail
)
Reset
()
{
*
m
=
SendMail
{}
}
...
...
controllers/base.go
View file @
6e301e98
...
...
@@ -2,13 +2,21 @@ package controllers
import
(
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"github.com/gin-gonic/gin"
"github.com/teed7334-restore/homekeeper/beans"
"github.com/teed7334-restore/homekeeper/env"
)
//ChainResultObject Hyperledger REST回傳物件
type
ChainResultObject
interface
{
GetError
()
*
beans
.
APIError
}
var
cfg
=
env
.
GetEnv
()
//GetURL 透過HTTP GET取得網頁資料
...
...
@@ -41,3 +49,31 @@ func PostURL(url string, params []byte) []byte {
defer
result
.
Body
.
Close
()
return
body
}
//getParams 取得HTTP POST帶過來之參數
func
getParams
(
c
*
gin
.
Context
,
params
interface
{})
{
err
:=
c
.
BindJSON
(
params
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
}
//getChainParams 取得Hyperledger鏈上傳來的資料
func
getChainParams
(
url
string
,
params
[]
byte
,
action
string
,
resultObject
ChainResultObject
)
{
result
:=
[]
byte
{}
switch
action
{
case
"GET"
:
result
=
GetURL
(
url
)
case
"POST"
:
result
=
PostURL
(
url
,
params
)
}
err
:=
json
.
Unmarshal
(
result
,
resultObject
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
}
if
resultObject
.
GetError
()
!=
nil
{
log
.
Println
(
resultObject
.
GetError
()
.
GetMessage
())
return
}
}
controllers/mail.go
View file @
6e301e98
...
...
@@ -13,10 +13,7 @@ import (
//SendMail 寄信用API
func
SendMail
(
c
*
gin
.
Context
)
{
params
:=
&
beans
.
SendMail
{}
err
:=
c
.
BindJSON
(
params
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
getParams
(
c
,
params
)
doSendMail
(
params
)
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"status"
:
"true"
})
}
...
...
controllers/punchclock.go
View file @
6e301e98
package
controllers
import
(
"encoding/json"
"log"
"net/http"
"strconv"
...
...
@@ -9,6 +10,7 @@ import (
"unicode/utf8"
"github.com/gin-gonic/gin"
uuid
"github.com/satori/go.uuid"
"github.com/teed7334-restore/homekeeper/beans"
"github.com/teed7334-restore/homekeeper/models"
)
...
...
@@ -43,7 +45,8 @@ func CallCalcTime(onWorkTime time.Time, offWorkTime time.Time) (diffDay int, dif
//CalcTime 計算時數
func
CalcTime
(
c
*
gin
.
Context
)
{
params
:=
getPunchclockParams
(
c
)
params
:=
&
beans
.
Punchclock
{}
getParams
(
c
,
params
)
diffDay
,
diffHour
,
diffMinute
:=
calcLeaveScope
(
params
)
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"diffDay"
:
diffDay
,
"diffHour"
:
diffHour
,
"diffMinute"
:
diffMinute
})
}
...
...
@@ -233,12 +236,129 @@ func isSameDay(pc *beans.Punchclock) bool {
return
begin
==
end
}
//getPunchclockParams 取得HTTP POST帶過來之參數
func
getPunchclockParams
(
c
*
gin
.
Context
)
*
beans
.
Punchclock
{
params
:=
&
beans
.
Punchclock
{}
err
:=
c
.
BindJSON
(
params
)
//GetEmployeeOnChain 取鏈上取得員工資料
func
GetEmployeeOnChain
(
c
*
gin
.
Context
)
{
params
:=
&
beans
.
EmployeeOnChain
{}
getParams
(
c
,
params
)
id
:=
params
.
GetIdentify
()
empolyee
:=
doGetEmployeeOnChain
(
id
)
c
.
JSON
(
http
.
StatusOK
,
empolyee
)
}
//doGetEmployeeOnChain 執行從鏈上取得員工資料
func
doGetEmployeeOnChain
(
id
string
)
*
beans
.
GetEmployee
{
url
:=
cfg
.
Hyperledger
.
Host
+
"/api/Employee/"
+
id
empolyee
:=
&
beans
.
GetEmployee
{}
getChainParams
(
url
,
[]
byte
{},
"GET"
,
empolyee
)
return
empolyee
}
//AddEmployeeOnChain 追加鏈上員工資料
func
AddEmployeeOnChain
(
c
*
gin
.
Context
)
{
params
:=
&
beans
.
EmployeeOnChain
{}
getParams
(
c
,
params
)
empolyee
:=
doAddEmployeeOnChain
(
params
)
c
.
JSON
(
http
.
StatusOK
,
&
empolyee
)
}
//doAddEmployeeOnChain 執行新增員工到鏈上
func
doAddEmployeeOnChain
(
params
*
beans
.
EmployeeOnChain
)
*
beans
.
GetEmployee
{
params
.
Class
=
"com.taipay.network.Employee"
url
:=
cfg
.
Hyperledger
.
Host
+
"/api/Employee/"
jsonParams
,
err
:=
json
.
Marshal
(
params
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
return
params
empolyee
:=
&
beans
.
GetEmployee
{}
getChainParams
(
url
,
jsonParams
,
"POST"
,
empolyee
)
return
empolyee
}
//AddPunchclockOnChain 寫入員工卡鐘資料
func
AddPunchclockOnChain
(
c
*
gin
.
Context
)
{
params
:=
&
beans
.
PunchclockOnChain
{}
getParams
(
c
,
params
)
punchclock
:=
doAddPunchclockOnChain
(
params
)
c
.
JSON
(
200
,
&
punchclock
)
}
//GetPunchclockOnChain 取鏈上取得打卡資料
func
GetPunchclockOnChain
(
c
*
gin
.
Context
)
{
params
:=
&
beans
.
PunchclockOnChain
{}
getParams
(
c
,
params
)
id
:=
params
.
GetID
()
punchclock
:=
doGetPunchclockOnChain
(
id
)
c
.
JSON
(
http
.
StatusOK
,
punchclock
)
}
//doGetPunchclockOnChain 執行從鏈上取得打卡資料
func
doGetPunchclockOnChain
(
id
string
)
*
beans
.
GetPunchclock
{
url
:=
cfg
.
Hyperledger
.
Host
+
"/api/Punchclock/"
+
id
punchclock
:=
&
beans
.
GetPunchclock
{}
getChainParams
(
url
,
[]
byte
{},
"GET"
,
punchclock
)
return
punchclock
}
//doAddPunchclockOnChain
func
doAddPunchclockOnChain
(
params
*
beans
.
PunchclockOnChain
)
*
beans
.
GetPunchclock
{
params
.
Class
=
"com.taipay.network.Punchclock"
url
:=
cfg
.
Hyperledger
.
Host
+
"/api/Punchclock/"
jsonParams
,
err
:=
json
.
Marshal
(
params
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
punchclock
:=
&
beans
.
GetPunchclock
{}
getChainParams
(
url
,
jsonParams
,
"POST"
,
punchclock
)
return
punchclock
}
//UploadDailyPunchclockData 將每天員工打卡資料上鏈
func
UploadDailyPunchclockData
(
c
*
gin
.
Context
)
{
params
:=
&
beans
.
DailyPunchclockData
{}
getParams
(
c
,
params
)
id
:=
params
.
GetEmployee
()
.
GetIdentify
()
employee
:=
doGetEmployeeOnChain
(
id
)
if
employee
.
GetError
()
!=
nil
{
employee
=
doAddEmployeeOnChain
(
params
.
GetEmployee
())
if
employee
.
GetError
()
!=
nil
{
log
.
Println
(
employee
.
GetError
()
.
GetMessage
())
return
}
}
dailyPunchclockData
:=
combinDailyPunchData
(
params
)
result
:=
doAddPunchclockOnChain
(
dailyPunchclockData
)
c
.
JSON
(
200
,
&
result
)
}
//combinDailyPunchData 合併需上傳之打卡記錄
func
combinDailyPunchData
(
params
*
beans
.
DailyPunchclockData
)
*
beans
.
PunchclockOnChain
{
year
:=
params
.
GetPunchclock
()
.
GetBegin
()
.
GetYear
()
month
:=
params
.
GetPunchclock
()
.
GetBegin
()
.
GetMonth
()
day
:=
params
.
GetPunchclock
()
.
GetBegin
()
.
GetDay
()
identify
:=
params
.
GetEmployee
()
.
GetIdentify
()
dailyPunchclockData
:=
&
beans
.
PunchclockOnChain
{}
dailyPunchclockData
.
ID
=
getDailyPunchclockID
()
dailyPunchclockData
.
OnWorkDate
=
year
+
"-"
+
month
+
"-"
+
day
dailyPunchclockData
.
OnWorkTime
=
params
.
GetPunchclock
()
.
GetBegin
()
.
GetHour
()
+
":"
+
params
.
GetPunchclock
()
.
GetBegin
()
.
GetMinute
()
dailyPunchclockData
.
OffWorkTime
=
params
.
GetPunchclock
()
.
GetEnd
()
.
GetHour
()
+
":"
+
params
.
GetPunchclock
()
.
GetEnd
()
.
GetMinute
()
diffDay
,
diffHour
,
diffMinute
:=
calcLeaveScope
(
params
.
GetPunchclock
())
if
diffDay
>
0
{
diffHour
=
diffHour
+
diffDay
*
8
}
dailyPunchclockData
.
WorkTimes
=
strconv
.
Itoa
(
diffHour
)
+
" Hours "
+
strconv
.
Itoa
(
diffMinute
)
+
" Minutes"
dailyPunchclockData
.
Employee
=
identify
return
dailyPunchclockData
}
//getDailyPunchclockID 取得打卡記錄上鏈用ID
func
getDailyPunchclockID
()
string
{
id
:=
uuid
.
Must
(
uuid
.
NewV4
())
.
String
()
for
{
punchclock
:=
doGetPunchclockOnChain
(
id
)
if
punchclock
.
GetError
()
!=
nil
{
break
}
id
=
uuid
.
Must
(
uuid
.
NewV4
())
.
String
()
}
return
id
}
controllers/redis.go
View file @
6e301e98
...
...
@@ -13,7 +13,8 @@ import (
//GetRedis 取得Redis資料
func
GetRedis
(
c
*
gin
.
Context
)
{
params
:=
getRedisParams
(
c
)
params
:=
&
beans
.
Redis
{}
getParams
(
c
,
params
)
client
:=
initRedis
()
value
,
err
:=
redis
.
String
(
client
.
Do
(
"get"
,
params
.
GetKey
()))
if
err
!=
nil
{
...
...
@@ -25,7 +26,8 @@ func GetRedis(c *gin.Context) {
//SetRedis 設定Redis資料
func
SetRedis
(
c
*
gin
.
Context
)
{
params
:=
getRedisParams
(
c
)
params
:=
&
beans
.
Redis
{}
getParams
(
c
,
params
)
client
:=
initRedis
()
value
,
err
:=
client
.
Do
(
"set"
,
params
.
GetKey
(),
params
.
GetValue
())
if
err
!=
nil
{
...
...
@@ -37,7 +39,8 @@ func SetRedis(c *gin.Context) {
//IncrRedis 對Redis資料進行遞增
func
IncrRedis
(
c
*
gin
.
Context
)
{
params
:=
getRedisParams
(
c
)
params
:=
&
beans
.
Redis
{}
getParams
(
c
,
params
)
client
:=
initRedis
()
value
,
err
:=
client
.
Do
(
"incr"
,
params
.
GetKey
())
if
err
!=
nil
{
...
...
@@ -49,7 +52,8 @@ func IncrRedis(c *gin.Context) {
//DecrRedis 對Redis資料進行遞減
func
DecrRedis
(
c
*
gin
.
Context
)
{
params
:=
getRedisParams
(
c
)
params
:=
&
beans
.
Redis
{}
getParams
(
c
,
params
)
client
:=
initRedis
()
value
,
err
:=
client
.
Do
(
"decr"
,
params
.
GetKey
())
if
err
!=
nil
{
...
...
@@ -61,7 +65,8 @@ func DecrRedis(c *gin.Context) {
//HSetRedis 對Redis資料建立Hashmap
func
HSetRedis
(
c
*
gin
.
Context
)
{
params
:=
getRedisParams
(
c
)
params
:=
&
beans
.
Redis
{}
getParams
(
c
,
params
)
client
:=
initRedis
()
value
,
err
:=
client
.
Do
(
"hset"
,
params
.
GetKey
(),
params
.
GetHkey
(),
params
.
GetValue
())
if
err
!=
nil
{
...
...
@@ -73,7 +78,8 @@ func HSetRedis(c *gin.Context) {
//HGetRedis 取得建立Hashmap的Redis資料
func
HGetRedis
(
c
*
gin
.
Context
)
{
params
:=
getRedisParams
(
c
)
params
:=
&
beans
.
Redis
{}
getParams
(
c
,
params
)
client
:=
initRedis
()
value
,
err
:=
redis
.
String
(
client
.
Do
(
"hget"
,
params
.
GetKey
(),
params
.
GetHkey
()))
if
err
!=
nil
{
...
...
@@ -85,7 +91,8 @@ func HGetRedis(c *gin.Context) {
//SAddRedis 對Redis進行資料添加,並排除重複項目
func
SAddRedis
(
c
*
gin
.
Context
)
{
params
:=
getRedisParams
(
c
)
params
:=
&
beans
.
Redis
{}
getParams
(
c
,
params
)
client
:=
initRedis
()
value
,
err
:=
client
.
Do
(
"sadd"
,
params
.
GetKey
(),
params
.
GetValue
())
if
err
!=
nil
{
...
...
@@ -97,7 +104,8 @@ func SAddRedis(c *gin.Context) {
//SCardRedis 取得Key中的資料集合總數
func
SCardRedis
(
c
*
gin
.
Context
)
{
params
:=
getRedisParams
(
c
)
params
:=
&
beans
.
Redis
{}
getParams
(
c
,
params
)
client
:=
initRedis
()
value
,
err
:=
client
.
Do
(
"scard"
,
params
.
GetKey
())
if
err
!=
nil
{
...
...
@@ -109,7 +117,8 @@ func SCardRedis(c *gin.Context) {
//LPushRedis 對Redis中List資料的前面做資料添加
func
LPushRedis
(
c
*
gin
.
Context
)
{
params
:=
getRedisParams
(
c
)
params
:=
&
beans
.
Redis
{}
getParams
(
c
,
params
)
client
:=
initRedis
()
value
,
err
:=
client
.
Do
(
"lpush"
,
params
.
GetKey
(),
params
.
GetValue
())
if
err
!=
nil
{
...
...
@@ -121,7 +130,8 @@ func LPushRedis(c *gin.Context) {
//RPushRedis 對Redis中List資料的後面做資料添加
func
RPushRedis
(
c
*
gin
.
Context
)
{
params
:=
getRedisParams
(
c
)
params
:=
&
beans
.
Redis
{}
getParams
(
c
,
params
)
client
:=
initRedis
()
value
,
err
:=
client
.
Do
(
"rpush"
,
params
.
GetKey
(),
params
.
GetValue
())
if
err
!=
nil
{
...
...
@@ -133,7 +143,8 @@ func RPushRedis(c *gin.Context) {
//LSetRedis 從Redis中List資料的第...列做資料修改
func
LSetRedis
(
c
*
gin
.
Context
)
{
params
:=
getRedisParams
(
c
)
params
:=
&
beans
.
Redis
{}
getParams
(
c
,
params
)
client
:=
initRedis
()
value
,
err
:=
client
.
Do
(
"lset"
,
params
.
GetKey
(),
params
.
GetHkey
(),
params
.
GetValue
())
if
err
!=
nil
{
...
...
@@ -145,7 +156,8 @@ func LSetRedis(c *gin.Context) {
//LRangeRedis 取得Redis中List特定範圍裡面的資料
func
LRangeRedis
(
c
*
gin
.
Context
)
{
params
:=
getRedisParams
(
c
)
params
:=
&
beans
.
Redis
{}
getParams
(
c
,
params
)
getRange
:=
strings
.
Split
(
params
.
GetValue
(),
":"
)
begin
:=
getRange
[
0
]
end
:=
getRange
[
1
]
...
...
@@ -165,12 +177,3 @@ func initRedis() redis.Conn {
}
return
client
}
func
getRedisParams
(
c
*
gin
.
Context
)
*
beans
.
Redis
{
params
:=
&
beans
.
Redis
{}
err
:=
c
.
BindJSON
(
params
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
return
params
}
env/env.swp
View file @
6e301e98
...
...
@@ -24,6 +24,9 @@ type Config struct {
Host
string
Protocol
string
}
Hyperledger
struct
{
Host
string
}
}
var
cfg
=
&
Config
{}
...
...
@@ -33,7 +36,7 @@ func init() {
cfg
.
TimeFormat
=
"2006-01-02 15:04:05"
cfg
.
Database
.
User
=
""
cfg
.
Database
.
Password
=
""
cfg
.
Database
.
Host
=
""
cfg
.
Database
.
Host
=
"
127.0.0.1
"
cfg
.
Database
.
Database
=
""
cfg
.
Database
.
Charset
=
"utf8mb4"
cfg
.
Database
.
ParseTime
=
"true"
...
...
@@ -45,6 +48,7 @@ func init() {
cfg
.
Mail
.
Password
=
""
cfg
.
Redis
.
Host
=
"127.0.0.1:6379"
cfg
.
Redis
.
Protocol
=
"tcp"
cfg
.
Hyperledger
.
Host
=
"http://127.0.0.1:3000"
}
//
GetEnv
取得環境參數
...
...
route/api.go
View file @
6e301e98
...
...
@@ -28,5 +28,10 @@ func API() *gin.Engine {
route
.
POST
(
"/Redis/LRange"
,
controllers
.
LRangeRedis
)
route
.
POST
(
"/PunchClock/CalcTime"
,
controllers
.
CalcTime
)
route
.
POST
(
"/PunchClock/ResetAllUseMinute"
,
controllers
.
ResetAllUseMinute
)
route
.
POST
(
"/PunchClock/GetEmployeeOnChain"
,
controllers
.
GetEmployeeOnChain
)
route
.
POST
(
"/PunchClock/AddEmployeeOnChain"
,
controllers
.
AddEmployeeOnChain
)
route
.
POST
(
"/PunchClock/GetPunchclockOnChain"
,
controllers
.
GetPunchclockOnChain
)
route
.
POST
(
"/PunchClock/AddPunchclockOnChain"
,
controllers
.
AddPunchclockOnChain
)
route
.
POST
(
"/PunchClock/UploadDailyPunchclockData"
,
controllers
.
UploadDailyPunchclockData
)
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