Commit 6e301e98 authored by Peter Cheng's avatar Peter Cheng

追加員工打卡記錄上鏈API

parent 87d08780
......@@ -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
// 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, 0x82, 0xa2, 0x56, 0x02, 0xa5, 0x4a, 0x2a, 0xf4, 0x7a, 0x8d, 0xe3, 0x1f,
0x4c, 0xb2, 0xb2, 0xbb, 0x5e, 0xf8, 0x2a, 0xbd, 0xea, 0x63, 0xf5, 0x71, 0xca, 0xee, 0x9a, 0x98,
0xab, 0xde, 0xcd, 0xf7, 0x9b, 0xcc, 0x64, 0xbe, 0x8f, 0x85, 0xeb, 0xed, 0xe9, 0x40, 0x32, 0xa5,
0xd5, 0x86, 0x64, 0x3c, 0x79, 0x5f, 0x0c, 0x0f, 0x52, 0x68, 0xc1, 0xfc, 0x25, 0xf1, 0x5c, 0xf5,
0xbf, 0x3c, 0x08, 0xa6, 0xa4, 0x27, 0xd9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 0x33,
0x84, 0x66, 0x46, 0x4a, 0xf1, 0x0d, 0x61, 0xcb, 0xe2, 0x42, 0xb2, 0x1b, 0x68, 0xb8, 0x59, 0x6c,
0xdb, 0xc6, 0x59, 0x99, 0x2d, 0x89, 0xd9, 0x0f, 0x6e, 0x8b, 0xa9, 0x4d, 0x9e, 0x4a, 0xf3, 0x64,
0x8f, 0x81, 0xcb, 0xd3, 0x8a, 0x65, 0xc3, 0x3e, 0x94, 0xa7, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff,
0xce, 0xc4, 0x57, 0xe3, 0x41, 0x02, 0x00, 0x00,
}
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
......@@ -13,6 +13,62 @@ var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
type TimeStruct struct {
Year string `protobuf:"bytes,1,opt,name=Year" json:"year"`
Month string `protobuf:"bytes,2,opt,name=Month" json:"month"`
Day string `protobuf:"bytes,3,opt,name=Day" json:"day"`
Hour string `protobuf:"bytes,4,opt,name=Hour" json:"hour"`
Minute string `protobuf:"bytes,5,opt,name=Minute" json:"minute"`
Second string `protobuf:"bytes,6,opt,name=Second" json:"second"`
}
func (m *TimeStruct) Reset() { *m = TimeStruct{} }
func (m *TimeStruct) String() string { return proto.CompactTextString(m) }
func (*TimeStruct) ProtoMessage() {}
func (*TimeStruct) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{0} }
func (m *TimeStruct) GetYear() string {
if m != nil {
return m.Year
}
return ""
}
func (m *TimeStruct) GetMonth() string {
if m != nil {
return m.Month
}
return ""
}
func (m *TimeStruct) GetDay() string {
if m != nil {
return m.Day
}
return ""
}
func (m *TimeStruct) GetHour() string {
if m != nil {
return m.Hour
}
return ""
}
func (m *TimeStruct) GetMinute() string {
if m != nil {
return m.Minute
}
return ""
}
func (m *TimeStruct) GetSecond() string {
if m != nil {
return m.Second
}
return ""
}
type Punchclock struct {
Begin *TimeStruct `protobuf:"bytes,7,opt,name=Begin" json:"begin"`
End *TimeStruct `protobuf:"bytes,8,opt,name=End" json:"end"`
......@@ -21,7 +77,7 @@ type Punchclock struct {
func (m *Punchclock) Reset() { *m = Punchclock{} }
func (m *Punchclock) String() string { return proto.CompactTextString(m) }
func (*Punchclock) ProtoMessage() {}
func (*Punchclock) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{0} }
func (*Punchclock) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{1} }
func (m *Punchclock) GetBegin() *TimeStruct {
if m != nil {
......@@ -37,82 +93,169 @@ func (m *Punchclock) GetEnd() *TimeStruct {
return nil
}
type TimeStruct struct {
Year string `protobuf:"bytes,1,opt,name=Year" json:"year"`
Month string `protobuf:"bytes,2,opt,name=Month" json:"month"`
Day string `protobuf:"bytes,3,opt,name=Day" json:"day"`
Hour string `protobuf:"bytes,4,opt,name=Hour" json:"hour"`
Minute string `protobuf:"bytes,5,opt,name=Minute" json:"minute"`
Second string `protobuf:"bytes,6,opt,name=Second" json:"second"`
type EmployeeOnChain struct {
Class string `protobuf:"bytes,9,opt,name=Class" json:"$class" form:"$class"`
Identify string `protobuf:"bytes,10,opt,name=Identify" json:"identify" form:"identify"`
FirstName string `protobuf:"bytes,11,opt,name=FirstName" json:"firstName" form:"firstName"`
LastName string `protobuf:"bytes,12,opt,name=LastName" json:"lastName" form:"lastName"`
}
func (m *TimeStruct) Reset() { *m = TimeStruct{} }
func (m *TimeStruct) String() string { return proto.CompactTextString(m) }
func (*TimeStruct) ProtoMessage() {}
func (*TimeStruct) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{1} }
func (m *EmployeeOnChain) Reset() { *m = EmployeeOnChain{} }
func (m *EmployeeOnChain) String() string { return proto.CompactTextString(m) }
func (*EmployeeOnChain) ProtoMessage() {}
func (*EmployeeOnChain) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{2} }
func (m *TimeStruct) GetYear() string {
func (m *EmployeeOnChain) GetClass() string {
if m != nil {
return m.Year
return m.Class
}
return ""
}
func (m *TimeStruct) GetMonth() string {
func (m *EmployeeOnChain) GetIdentify() string {
if m != nil {
return m.Month
return m.Identify
}
return ""
}
func (m *TimeStruct) GetDay() string {
func (m *EmployeeOnChain) GetFirstName() string {
if m != nil {
return m.Day
return m.FirstName
}
return ""
}
func (m *TimeStruct) GetHour() string {
func (m *EmployeeOnChain) GetLastName() string {
if m != nil {
return m.Hour
return m.LastName
}
return ""
}
func (m *TimeStruct) GetMinute() string {
type PunchclockOnChain struct {
Class string `protobuf:"bytes,13,opt,name=Class" json:"$class" form:"$class"`
ID string `protobuf:"bytes,14,opt,name=ID" json:"id" form:"id"`
OnWorkDate string `protobuf:"bytes,15,opt,name=OnWorkDate" json:"onWorkDate" form:"onWorkDate"`
OnWorkTime string `protobuf:"bytes,16,opt,name=OnWorkTime" json:"onWorkTime" form:"onWorkTime"`
OffWorkTime string `protobuf:"bytes,17,opt,name=OffWorkTime" json:"offWorkTime" form:"offWorkTime"`
WorkTimes string `protobuf:"bytes,18,opt,name=WorkTimes" json:"workTimes" form:"workTimes"`
Employee string `protobuf:"bytes,19,opt,name=Employee" json:"employee" form:"employee"`
}
func (m *PunchclockOnChain) Reset() { *m = PunchclockOnChain{} }
func (m *PunchclockOnChain) String() string { return proto.CompactTextString(m) }
func (*PunchclockOnChain) ProtoMessage() {}
func (*PunchclockOnChain) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{3} }
func (m *PunchclockOnChain) GetClass() string {
if m != nil {
return m.Minute
return m.Class
}
return ""
}
func (m *TimeStruct) GetSecond() string {
func (m *PunchclockOnChain) GetID() string {
if m != nil {
return m.Second
return m.ID
}
return ""
}
func (m *PunchclockOnChain) GetOnWorkDate() string {
if m != nil {
return m.OnWorkDate
}
return ""
}
func (m *PunchclockOnChain) GetOnWorkTime() string {
if m != nil {
return m.OnWorkTime
}
return ""
}
func (m *PunchclockOnChain) GetOffWorkTime() string {
if m != nil {
return m.OffWorkTime
}
return ""
}
func (m *PunchclockOnChain) GetWorkTimes() string {
if m != nil {
return m.WorkTimes
}
return ""
}
func (m *PunchclockOnChain) GetEmployee() string {
if m != nil {
return m.Employee
}
return ""
}
type DailyPunchclockData struct {
Employee *EmployeeOnChain `protobuf:"bytes,20,opt,name=Employee" json:"employee" form:"employee"`
Punchclock *Punchclock `protobuf:"bytes,21,opt,name=Punchclock" json:"punchclock" form:"punchclock"`
}
func (m *DailyPunchclockData) Reset() { *m = DailyPunchclockData{} }
func (m *DailyPunchclockData) String() string { return proto.CompactTextString(m) }
func (*DailyPunchclockData) ProtoMessage() {}
func (*DailyPunchclockData) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{4} }
func (m *DailyPunchclockData) GetEmployee() *EmployeeOnChain {
if m != nil {
return m.Employee
}
return nil
}
func (m *DailyPunchclockData) GetPunchclock() *Punchclock {
if m != nil {
return m.Punchclock
}
return nil
}
func init() {
proto.RegisterType((*Punchclock)(nil), "beans.Punchclock")
proto.RegisterType((*TimeStruct)(nil), "beans.TimeStruct")
proto.RegisterType((*Punchclock)(nil), "beans.Punchclock")
proto.RegisterType((*EmployeeOnChain)(nil), "beans.EmployeeOnChain")
proto.RegisterType((*PunchclockOnChain)(nil), "beans.PunchclockOnChain")
proto.RegisterType((*DailyPunchclockData)(nil), "beans.DailyPunchclockData")
}
func init() { proto.RegisterFile("punchclock.proto", fileDescriptor1) }
var fileDescriptor1 = []byte{
// 200 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x28, 0x28, 0xcd, 0x4b,
0xce, 0x48, 0xce, 0xc9, 0x4f, 0xce, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4d, 0x4a,
0x4d, 0xcc, 0x2b, 0x56, 0x8a, 0xe2, 0xe2, 0x0a, 0x80, 0x4b, 0x09, 0xa9, 0x73, 0xb1, 0x3a, 0xa5,
0xa6, 0x67, 0xe6, 0x49, 0xb0, 0x2b, 0x30, 0x6a, 0x70, 0x1b, 0x09, 0xea, 0x81, 0x15, 0xe9, 0x85,
0x64, 0xe6, 0xa6, 0x06, 0x97, 0x14, 0x95, 0x26, 0x97, 0x04, 0x41, 0xe4, 0x85, 0x94, 0xb9, 0x98,
0x5d, 0xf3, 0x52, 0x24, 0x38, 0x70, 0x29, 0x03, 0xc9, 0x2a, 0xf5, 0x30, 0x72, 0x71, 0x21, 0xc4,
0x84, 0x84, 0xb8, 0x58, 0x22, 0x53, 0x13, 0x8b, 0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0xc0,
0x6c, 0x21, 0x11, 0x2e, 0x56, 0xdf, 0xfc, 0xbc, 0x92, 0x0c, 0x09, 0x26, 0xb0, 0x20, 0x84, 0x23,
0x24, 0xc0, 0xc5, 0xec, 0x92, 0x58, 0x29, 0xc1, 0x0c, 0x16, 0x03, 0x31, 0x41, 0x7a, 0x3d, 0xf2,
0x4b, 0x8b, 0x24, 0x58, 0x20, 0x7a, 0x41, 0x6c, 0x21, 0x31, 0x2e, 0x36, 0xdf, 0xcc, 0xbc, 0xd2,
0x92, 0x54, 0x09, 0x56, 0xb0, 0x28, 0x94, 0x07, 0x12, 0x0f, 0x4e, 0x4d, 0xce, 0xcf, 0x4b, 0x91,
0x60, 0x83, 0x88, 0x43, 0x78, 0x49, 0x6c, 0x60, 0x8f, 0x1b, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff,
0x05, 0x73, 0xab, 0x0e, 0x0c, 0x01, 0x00, 0x00,
// 391 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xdf, 0x6a, 0xe2, 0x40,
0x14, 0xc6, 0x89, 0x1a, 0x57, 0x8f, 0xbb, 0xfe, 0x19, 0x5d, 0x39, 0x2c, 0xcb, 0x22, 0xd9, 0x8b,
0xf5, 0x4a, 0x58, 0xfb, 0x06, 0x35, 0x96, 0x0a, 0xb5, 0x16, 0x2d, 0x94, 0xf6, 0x6e, 0x8c, 0x63,
0x0d, 0xc6, 0x19, 0x49, 0x26, 0x17, 0x81, 0xf6, 0x0d, 0xfa, 0x7a, 0x7d, 0x9f, 0x32, 0x33, 0xe6,
0x4f, 0x5b, 0x7a, 0x77, 0xbe, 0xdf, 0x77, 0x4e, 0x38, 0x5f, 0xce, 0x40, 0xfb, 0x18, 0x73, 0x6f,
0xe7, 0x05, 0xc2, 0xdb, 0x8f, 0x8e, 0xa1, 0x90, 0x82, 0xd8, 0x6b, 0x46, 0x79, 0xe4, 0xbc, 0x58,
0x00, 0xb7, 0xfe, 0x81, 0xad, 0x64, 0x18, 0x7b, 0x92, 0x10, 0xa8, 0xdc, 0x33, 0x1a, 0xa2, 0x35,
0xb0, 0x86, 0xf5, 0xa5, 0xae, 0x49, 0x0f, 0xec, 0xb9, 0xe0, 0x72, 0x87, 0x25, 0x0d, 0x8d, 0x20,
0x6d, 0x28, 0xbb, 0x34, 0xc1, 0xb2, 0x66, 0xaa, 0x54, 0xb3, 0x97, 0x22, 0x0e,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x2a, 0x57, 0xfa, 0xeb, 0xb0, 0x6b, 0x72, 0xa5, 0xda, 0x79,
0x82, 0xae, 0x4b, 0xfd, 0x20, 0xc9, 0xb3, 0xb9, 0x54, 0x52, 0x32, 0x2e, 0x8c, 0xf4, 0xf4, 0x5d,
0xfa, 0xa7, 0xbb, 0x7c, 0x38, 0x42, 0xfe, 0x29, 0xf2, 0xbf, 0x78, 0x7d, 0xfc, 0xf9, 0xee, 0x9a,
0xb9, 0xb1, 0x2c, 0x34, 0xad, 0xab, 0xfa, 0x35, 0x9f, 0xbd, 0x05, 0x00, 0x00, 0xff, 0xff, 0xc8,
0xcd, 0x1e, 0xde, 0xe1, 0x02, 0x00, 0x00,
}
......@@ -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"`
......@@ -15,3 +10,30 @@ message TimeStruct {
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
......@@ -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
}
}
......@@ -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"})
}
......
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
}
......@@ -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
}
......@@ -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 取得環境參數
......
......@@ -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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment