feat:新增年度报告模块
This commit is contained in:
parent
0557751b23
commit
8584b6a94e
33
.vscode/launch.json
vendored
Normal file
33
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
// 使用 IntelliSense 了解相关属性。
|
||||||
|
// 悬停以查看现有属性的描述。
|
||||||
|
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Launch Package",
|
||||||
|
"type": "go",
|
||||||
|
"request": "launch",
|
||||||
|
"mode": "auto",
|
||||||
|
"env": {
|
||||||
|
"GOPATH":"C:\\Users\\lenovo\\go",
|
||||||
|
"GOOS":"windows"
|
||||||
|
},
|
||||||
|
"program": "${workspaceFolder}\\cmd",
|
||||||
|
"args":[]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Run app.go",
|
||||||
|
"type": "go",
|
||||||
|
"request": "launch",
|
||||||
|
"mode": "debug",
|
||||||
|
"program": "${workspaceFolder}/cmd/app.go",
|
||||||
|
"cwd": "${workspaceFolder}/cmd",
|
||||||
|
"env": {
|
||||||
|
"DEBUG": "true",
|
||||||
|
"DUBBO_GO_CONFIG_PATH": "${workspaceFolder}/conf/dubbogo.yaml"
|
||||||
|
},
|
||||||
|
"dlvFlags": ["--check-go-version=false"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
22
.vscode/settings.json
vendored
Normal file
22
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"workbench.colorCustomizations": {
|
||||||
|
"activityBar.activeBackground": "#fa1b49",
|
||||||
|
"activityBar.background": "#fa1b49",
|
||||||
|
"activityBar.foreground": "#e7e7e7",
|
||||||
|
"activityBar.inactiveForeground": "#e7e7e799",
|
||||||
|
"activityBarBadge.background": "#155e02",
|
||||||
|
"activityBarBadge.foreground": "#e7e7e7",
|
||||||
|
"commandCenter.border": "#e7e7e799",
|
||||||
|
"sash.hoverBorder": "#fa1b49",
|
||||||
|
"statusBar.background": "#dd0531",
|
||||||
|
"statusBar.foreground": "#e7e7e7",
|
||||||
|
"statusBarItem.hoverBackground": "#fa1b49",
|
||||||
|
"statusBarItem.remoteBackground": "#dd0531",
|
||||||
|
"statusBarItem.remoteForeground": "#e7e7e7",
|
||||||
|
"titleBar.activeBackground": "#dd0531",
|
||||||
|
"titleBar.activeForeground": "#e7e7e7",
|
||||||
|
"titleBar.inactiveBackground": "#dd053199",
|
||||||
|
"titleBar.inactiveForeground": "#e7e7e799"
|
||||||
|
},
|
||||||
|
"peacock.color": "#dd0531"
|
||||||
|
}
|
1320
api/reports/reports.pb.go
Normal file
1320
api/reports/reports.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
109
api/reports/reports.proto
Normal file
109
api/reports/reports.proto
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
package reports;
|
||||||
|
//import "descriptor.proto";
|
||||||
|
//import "validator.proto";
|
||||||
|
|
||||||
|
option go_package = "./;reports";
|
||||||
|
|
||||||
|
service Reports{
|
||||||
|
//==================================年度报告======================================
|
||||||
|
rpc GetAnnualReportList(GetAnnualReportListReq) returns (GetAnnualReportListResp);
|
||||||
|
rpc AddAnnualReport(AddAnnualReportReq) returns (AddAnnualReportResp);
|
||||||
|
rpc EditAnnualReport(EditAnnualReportReq) returns (EditAnnualReportResp);
|
||||||
|
rpc DeleteAnnualReport(DeleteAnnualReportReq) returns (DeleteAnnualReportResp);
|
||||||
|
//==================================季度报告======================================
|
||||||
|
rpc GetQuarterlyReportList(GetQuarterlyReportListReq) returns (GetQuarterlyReportListResp);
|
||||||
|
}
|
||||||
|
|
||||||
|
message Filtrate{
|
||||||
|
string fileName = 3;//文件名称
|
||||||
|
int32 status = 4;//状态(1:上架,2:下架)
|
||||||
|
}
|
||||||
|
//==================================年度报告======================================
|
||||||
|
message GetAnnualReportListReq{
|
||||||
|
int32 page = 1;
|
||||||
|
int32 pageSize = 2;
|
||||||
|
Filtrate filtrate = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetAnnualReportListResp{
|
||||||
|
string msg = 1;
|
||||||
|
int32 page=2;
|
||||||
|
int32 pageSize =3;
|
||||||
|
int32 total = 4;
|
||||||
|
repeated AnnualReport data = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message AnnualReport{
|
||||||
|
int32 id = 1; //id
|
||||||
|
string fileName = 2; //文件名称
|
||||||
|
string date = 3; //日期
|
||||||
|
string fileUrl = 4; //访问地址
|
||||||
|
int32 status = 5; //状态(1:上架,2:下架)
|
||||||
|
int32 sort = 6; //排序
|
||||||
|
string updateTime = 7; //最近更新时间
|
||||||
|
string operator = 8; //操作人
|
||||||
|
int32 operatorId = 9; //操作人Id
|
||||||
|
}
|
||||||
|
|
||||||
|
message AddAnnualReportReq{
|
||||||
|
string fileName = 1; //文件名称
|
||||||
|
string date = 2; //日期
|
||||||
|
string fileUrl = 3; //访问地址
|
||||||
|
string operator = 4; //操作人
|
||||||
|
int32 operatorId = 5; //操作人Id
|
||||||
|
}
|
||||||
|
|
||||||
|
message AddAnnualReportResp{
|
||||||
|
string msg = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message EditAnnualReportReq{
|
||||||
|
int32 id = 1; //id
|
||||||
|
string fileName = 2; //文件名称
|
||||||
|
string date = 3; //日期
|
||||||
|
string fileUrl = 4; //访问地址
|
||||||
|
int32 sort = 5; //排序
|
||||||
|
int32 status = 6; //状态(1:上架,2:下架)
|
||||||
|
string operator = 7; //操作人
|
||||||
|
int32 operatorId = 8; //操作人Id
|
||||||
|
}
|
||||||
|
|
||||||
|
message EditAnnualReportResp{
|
||||||
|
string msg = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteAnnualReportReq{
|
||||||
|
int32 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteAnnualReportResp{
|
||||||
|
string msg = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//==================================季度报告======================================
|
||||||
|
message GetQuarterlyReportListReq{
|
||||||
|
int32 page = 1;
|
||||||
|
int32 pageSize = 2;
|
||||||
|
Filtrate filtrate = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetQuarterlyReportListResp{
|
||||||
|
string msg = 1;
|
||||||
|
int32 page=2;
|
||||||
|
int32 pageSize =3;
|
||||||
|
int32 total = 4;
|
||||||
|
repeated QuarterlyReport data = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message QuarterlyReport{
|
||||||
|
int32 id = 1; //id
|
||||||
|
string fileName = 2; //文件名称
|
||||||
|
string fileIntroduce = 3; //文件介绍
|
||||||
|
int32 sort = 4; //排序
|
||||||
|
int32 status = 5; //状态(1:上架,2:下架)
|
||||||
|
string updateTime = 6; //最近更新时间
|
||||||
|
string operator = 7; //操作人
|
||||||
|
int32 operatorId = 8; //操作人Id
|
||||||
|
}
|
||||||
|
|
80
api/reports/reports.validator.pb.go
Normal file
80
api/reports/reports.validator.pb.go
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||||
|
// source: api/reports/reports.proto
|
||||||
|
|
||||||
|
package reports
|
||||||
|
|
||||||
|
import (
|
||||||
|
fmt "fmt"
|
||||||
|
math "math"
|
||||||
|
proto "github.com/golang/protobuf/proto"
|
||||||
|
github_com_mwitkow_go_proto_validators "github.com/mwitkow/go-proto-validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
func (this *Filtrate) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *GetAnnualReportListReq) Validate() error {
|
||||||
|
if this.Filtrate != nil {
|
||||||
|
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Filtrate); err != nil {
|
||||||
|
return github_com_mwitkow_go_proto_validators.FieldError("Filtrate", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *GetAnnualReportListResp) Validate() error {
|
||||||
|
for _, item := range this.Data {
|
||||||
|
if item != nil {
|
||||||
|
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
||||||
|
return github_com_mwitkow_go_proto_validators.FieldError("Data", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *AnnualReport) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *AddAnnualReportReq) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *AddAnnualReportResp) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *EditAnnualReportReq) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *EditAnnualReportResp) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *DeleteAnnualReportReq) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *DeleteAnnualReportResp) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *GetQuarterlyReportListReq) Validate() error {
|
||||||
|
if this.Filtrate != nil {
|
||||||
|
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Filtrate); err != nil {
|
||||||
|
return github_com_mwitkow_go_proto_validators.FieldError("Filtrate", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *GetQuarterlyReportListResp) Validate() error {
|
||||||
|
for _, item := range this.Data {
|
||||||
|
if item != nil {
|
||||||
|
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
||||||
|
return github_com_mwitkow_go_proto_validators.FieldError("Data", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *QuarterlyReport) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
331
api/reports/reports_triple.pb.go
Normal file
331
api/reports/reports_triple.pb.go
Normal file
@ -0,0 +1,331 @@
|
|||||||
|
// Code generated by protoc-gen-go-triple. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// - protoc-gen-go-triple v1.0.5
|
||||||
|
// - protoc v5.26.0
|
||||||
|
// source: api/reports/reports.proto
|
||||||
|
|
||||||
|
package reports
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
protocol "dubbo.apache.org/dubbo-go/v3/protocol"
|
||||||
|
dubbo3 "dubbo.apache.org/dubbo-go/v3/protocol/dubbo3"
|
||||||
|
invocation "dubbo.apache.org/dubbo-go/v3/protocol/invocation"
|
||||||
|
grpc_go "github.com/dubbogo/grpc-go"
|
||||||
|
codes "github.com/dubbogo/grpc-go/codes"
|
||||||
|
metadata "github.com/dubbogo/grpc-go/metadata"
|
||||||
|
status "github.com/dubbogo/grpc-go/status"
|
||||||
|
common "github.com/dubbogo/triple/pkg/common"
|
||||||
|
constant "github.com/dubbogo/triple/pkg/common/constant"
|
||||||
|
triple "github.com/dubbogo/triple/pkg/triple"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
const _ = grpc_go.SupportPackageIsVersion7
|
||||||
|
|
||||||
|
// ReportsClient is the client API for Reports service.
|
||||||
|
//
|
||||||
|
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||||
|
type ReportsClient interface {
|
||||||
|
// ==================================年度报告======================================
|
||||||
|
GetAnnualReportList(ctx context.Context, in *GetAnnualReportListReq, opts ...grpc_go.CallOption) (*GetAnnualReportListResp, common.ErrorWithAttachment)
|
||||||
|
AddAnnualReport(ctx context.Context, in *AddAnnualReportReq, opts ...grpc_go.CallOption) (*AddAnnualReportResp, common.ErrorWithAttachment)
|
||||||
|
EditAnnualReport(ctx context.Context, in *EditAnnualReportReq, opts ...grpc_go.CallOption) (*EditAnnualReportResp, common.ErrorWithAttachment)
|
||||||
|
DeleteAnnualReport(ctx context.Context, in *DeleteAnnualReportReq, opts ...grpc_go.CallOption) (*DeleteAnnualReportResp, common.ErrorWithAttachment)
|
||||||
|
// ==================================季度报告======================================
|
||||||
|
GetQuarterlyReportList(ctx context.Context, in *GetQuarterlyReportListReq, opts ...grpc_go.CallOption) (*GetQuarterlyReportListResp, common.ErrorWithAttachment)
|
||||||
|
}
|
||||||
|
|
||||||
|
type reportsClient struct {
|
||||||
|
cc *triple.TripleConn
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReportsClientImpl struct {
|
||||||
|
GetAnnualReportList func(ctx context.Context, in *GetAnnualReportListReq) (*GetAnnualReportListResp, error)
|
||||||
|
AddAnnualReport func(ctx context.Context, in *AddAnnualReportReq) (*AddAnnualReportResp, error)
|
||||||
|
EditAnnualReport func(ctx context.Context, in *EditAnnualReportReq) (*EditAnnualReportResp, error)
|
||||||
|
DeleteAnnualReport func(ctx context.Context, in *DeleteAnnualReportReq) (*DeleteAnnualReportResp, error)
|
||||||
|
GetQuarterlyReportList func(ctx context.Context, in *GetQuarterlyReportListReq) (*GetQuarterlyReportListResp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ReportsClientImpl) GetDubboStub(cc *triple.TripleConn) ReportsClient {
|
||||||
|
return NewReportsClient(cc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ReportsClientImpl) XXX_InterfaceName() string {
|
||||||
|
return "reports.Reports"
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewReportsClient(cc *triple.TripleConn) ReportsClient {
|
||||||
|
return &reportsClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *reportsClient) GetAnnualReportList(ctx context.Context, in *GetAnnualReportListReq, opts ...grpc_go.CallOption) (*GetAnnualReportListResp, common.ErrorWithAttachment) {
|
||||||
|
out := new(GetAnnualReportListResp)
|
||||||
|
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||||
|
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/GetAnnualReportList", in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *reportsClient) AddAnnualReport(ctx context.Context, in *AddAnnualReportReq, opts ...grpc_go.CallOption) (*AddAnnualReportResp, common.ErrorWithAttachment) {
|
||||||
|
out := new(AddAnnualReportResp)
|
||||||
|
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||||
|
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/AddAnnualReport", in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *reportsClient) EditAnnualReport(ctx context.Context, in *EditAnnualReportReq, opts ...grpc_go.CallOption) (*EditAnnualReportResp, common.ErrorWithAttachment) {
|
||||||
|
out := new(EditAnnualReportResp)
|
||||||
|
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||||
|
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/EditAnnualReport", in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *reportsClient) DeleteAnnualReport(ctx context.Context, in *DeleteAnnualReportReq, opts ...grpc_go.CallOption) (*DeleteAnnualReportResp, common.ErrorWithAttachment) {
|
||||||
|
out := new(DeleteAnnualReportResp)
|
||||||
|
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||||
|
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/DeleteAnnualReport", in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *reportsClient) GetQuarterlyReportList(ctx context.Context, in *GetQuarterlyReportListReq, opts ...grpc_go.CallOption) (*GetQuarterlyReportListResp, common.ErrorWithAttachment) {
|
||||||
|
out := new(GetQuarterlyReportListResp)
|
||||||
|
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||||
|
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/GetQuarterlyReportList", in, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReportsServer is the server API for Reports service.
|
||||||
|
// All implementations must embed UnimplementedReportsServer
|
||||||
|
// for forward compatibility
|
||||||
|
type ReportsServer interface {
|
||||||
|
// ==================================年度报告======================================
|
||||||
|
GetAnnualReportList(context.Context, *GetAnnualReportListReq) (*GetAnnualReportListResp, error)
|
||||||
|
AddAnnualReport(context.Context, *AddAnnualReportReq) (*AddAnnualReportResp, error)
|
||||||
|
EditAnnualReport(context.Context, *EditAnnualReportReq) (*EditAnnualReportResp, error)
|
||||||
|
DeleteAnnualReport(context.Context, *DeleteAnnualReportReq) (*DeleteAnnualReportResp, error)
|
||||||
|
// ==================================季度报告======================================
|
||||||
|
GetQuarterlyReportList(context.Context, *GetQuarterlyReportListReq) (*GetQuarterlyReportListResp, error)
|
||||||
|
mustEmbedUnimplementedReportsServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnimplementedReportsServer must be embedded to have forward compatible implementations.
|
||||||
|
type UnimplementedReportsServer struct {
|
||||||
|
proxyImpl protocol.Invoker
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedReportsServer) GetAnnualReportList(context.Context, *GetAnnualReportListReq) (*GetAnnualReportListResp, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method GetAnnualReportList not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedReportsServer) AddAnnualReport(context.Context, *AddAnnualReportReq) (*AddAnnualReportResp, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method AddAnnualReport not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedReportsServer) EditAnnualReport(context.Context, *EditAnnualReportReq) (*EditAnnualReportResp, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method EditAnnualReport not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedReportsServer) DeleteAnnualReport(context.Context, *DeleteAnnualReportReq) (*DeleteAnnualReportResp, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method DeleteAnnualReport not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedReportsServer) GetQuarterlyReportList(context.Context, *GetQuarterlyReportListReq) (*GetQuarterlyReportListResp, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method GetQuarterlyReportList not implemented")
|
||||||
|
}
|
||||||
|
func (s *UnimplementedReportsServer) XXX_SetProxyImpl(impl protocol.Invoker) {
|
||||||
|
s.proxyImpl = impl
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *UnimplementedReportsServer) XXX_GetProxyImpl() protocol.Invoker {
|
||||||
|
return s.proxyImpl
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *UnimplementedReportsServer) XXX_ServiceDesc() *grpc_go.ServiceDesc {
|
||||||
|
return &Reports_ServiceDesc
|
||||||
|
}
|
||||||
|
func (s *UnimplementedReportsServer) XXX_InterfaceName() string {
|
||||||
|
return "reports.Reports"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedReportsServer) mustEmbedUnimplementedReportsServer() {}
|
||||||
|
|
||||||
|
// UnsafeReportsServer may be embedded to opt out of forward compatibility for this service.
|
||||||
|
// Use of this interface is not recommended, as added methods to ReportsServer will
|
||||||
|
// result in compilation errors.
|
||||||
|
type UnsafeReportsServer interface {
|
||||||
|
mustEmbedUnimplementedReportsServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterReportsServer(s grpc_go.ServiceRegistrar, srv ReportsServer) {
|
||||||
|
s.RegisterService(&Reports_ServiceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Reports_GetAnnualReportList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(GetAnnualReportListReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||||
|
args := []interface{}{}
|
||||||
|
args = append(args, in)
|
||||||
|
md, _ := metadata.FromIncomingContext(ctx)
|
||||||
|
invAttachment := make(map[string]interface{}, len(md))
|
||||||
|
for k, v := range md {
|
||||||
|
invAttachment[k] = v
|
||||||
|
}
|
||||||
|
invo := invocation.NewRPCInvocation("GetAnnualReportList", args, invAttachment)
|
||||||
|
if interceptor == nil {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
info := &grpc_go.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Reports_AddAnnualReport_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(AddAnnualReportReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||||
|
args := []interface{}{}
|
||||||
|
args = append(args, in)
|
||||||
|
md, _ := metadata.FromIncomingContext(ctx)
|
||||||
|
invAttachment := make(map[string]interface{}, len(md))
|
||||||
|
for k, v := range md {
|
||||||
|
invAttachment[k] = v
|
||||||
|
}
|
||||||
|
invo := invocation.NewRPCInvocation("AddAnnualReport", args, invAttachment)
|
||||||
|
if interceptor == nil {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
info := &grpc_go.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Reports_EditAnnualReport_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(EditAnnualReportReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||||
|
args := []interface{}{}
|
||||||
|
args = append(args, in)
|
||||||
|
md, _ := metadata.FromIncomingContext(ctx)
|
||||||
|
invAttachment := make(map[string]interface{}, len(md))
|
||||||
|
for k, v := range md {
|
||||||
|
invAttachment[k] = v
|
||||||
|
}
|
||||||
|
invo := invocation.NewRPCInvocation("EditAnnualReport", args, invAttachment)
|
||||||
|
if interceptor == nil {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
info := &grpc_go.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Reports_DeleteAnnualReport_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(DeleteAnnualReportReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||||
|
args := []interface{}{}
|
||||||
|
args = append(args, in)
|
||||||
|
md, _ := metadata.FromIncomingContext(ctx)
|
||||||
|
invAttachment := make(map[string]interface{}, len(md))
|
||||||
|
for k, v := range md {
|
||||||
|
invAttachment[k] = v
|
||||||
|
}
|
||||||
|
invo := invocation.NewRPCInvocation("DeleteAnnualReport", args, invAttachment)
|
||||||
|
if interceptor == nil {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
info := &grpc_go.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _Reports_GetQuarterlyReportList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(GetQuarterlyReportListReq)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||||
|
args := []interface{}{}
|
||||||
|
args = append(args, in)
|
||||||
|
md, _ := metadata.FromIncomingContext(ctx)
|
||||||
|
invAttachment := make(map[string]interface{}, len(md))
|
||||||
|
for k, v := range md {
|
||||||
|
invAttachment[k] = v
|
||||||
|
}
|
||||||
|
invo := invocation.NewRPCInvocation("GetQuarterlyReportList", args, invAttachment)
|
||||||
|
if interceptor == nil {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
info := &grpc_go.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||||
|
return result, result.Error()
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reports_ServiceDesc is the grpc_go.ServiceDesc for Reports service.
|
||||||
|
// It's only intended for direct use with grpc_go.RegisterService,
|
||||||
|
// and not to be introspected or modified (even as a copy)
|
||||||
|
var Reports_ServiceDesc = grpc_go.ServiceDesc{
|
||||||
|
ServiceName: "reports.Reports",
|
||||||
|
HandlerType: (*ReportsServer)(nil),
|
||||||
|
Methods: []grpc_go.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "GetAnnualReportList",
|
||||||
|
Handler: _Reports_GetAnnualReportList_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "AddAnnualReport",
|
||||||
|
Handler: _Reports_AddAnnualReport_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "EditAnnualReport",
|
||||||
|
Handler: _Reports_EditAnnualReport_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "DeleteAnnualReport",
|
||||||
|
Handler: _Reports_DeleteAnnualReport_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "GetQuarterlyReportList",
|
||||||
|
Handler: _Reports_GetQuarterlyReportList_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc_go.StreamDesc{},
|
||||||
|
Metadata: "api/reports/reports.proto",
|
||||||
|
}
|
2
clear.sh
Normal file
2
clear.sh
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
ls api/reports/*.pb.go | xargs -n1 -IX bash -c 'sed s/,omitempty// X > X.tmp && mv X{.tmp,}';
|
||||||
|
|
@ -21,6 +21,7 @@ func main() {
|
|||||||
config.SetProviderService(&controller.GovernanceProvider{})
|
config.SetProviderService(&controller.GovernanceProvider{})
|
||||||
config.SetProviderService(&controller.PressReleasesProvider{})
|
config.SetProviderService(&controller.PressReleasesProvider{})
|
||||||
config.SetProviderService(&controller.SecFilingsProvider{})
|
config.SetProviderService(&controller.SecFilingsProvider{})
|
||||||
|
config.SetProviderService(&controller.AnnualReportProvider{})
|
||||||
|
|
||||||
if err := config.Load(); err != nil {
|
if err := config.Load(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
31
internel/controller/annualReports.go
Normal file
31
internel/controller/annualReports.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"micro-document/api/reports"
|
||||||
|
"micro-document/internel/logic"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AnnualReportProvider struct {
|
||||||
|
reports.UnimplementedReportsServer
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取年度报告列表
|
||||||
|
func (AnnualReportProvider) List(_ context.Context, req *reports.GetAnnualReportListReq) (resp *reports.GetAnnualReportListResp, err error) {
|
||||||
|
return logic.AnnualReportsLogic.List(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增年度报告
|
||||||
|
func (AnnualReportProvider) Add(_ context.Context, req *reports.AddAnnualReportReq) (resp *reports.AddAnnualReportResp, err error) {
|
||||||
|
return logic.AnnualReportsLogic.Add(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 编辑年度报告
|
||||||
|
func (AnnualReportProvider) Edit(_ context.Context, req *reports.EditAnnualReportReq) (resp *reports.EditAnnualReportResp, err error) {
|
||||||
|
return logic.AnnualReportsLogic.Edit(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除年度报告
|
||||||
|
func (AnnualReportProvider) Delete(_ context.Context, req *reports.DeleteAnnualReportReq) (resp *reports.DeleteAnnualReportResp, err error) {
|
||||||
|
return logic.AnnualReportsLogic.Delete(req)
|
||||||
|
}
|
71
internel/dao/annualReports.go
Normal file
71
internel/dao/annualReports.go
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"micro-document/api/reports"
|
||||||
|
"micro-document/internel/model"
|
||||||
|
"micro-document/pkg/db"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type annualReportsDao struct{}
|
||||||
|
|
||||||
|
var AnnualReportsDao = new(annualReportsDao)
|
||||||
|
|
||||||
|
func (annualReportsDao) List(req *reports.GetAnnualReportListReq) (data []model.AnnualReport, total int64, err error) {
|
||||||
|
dbQuery := db.DocDB.Model(&model.AnnualReport{})
|
||||||
|
if req.Filtrate != nil {
|
||||||
|
if req.Filtrate.FileName != "" {
|
||||||
|
dbQuery = dbQuery.Where("file_name LIKE ?", "%"+req.Filtrate.FileName+"%")
|
||||||
|
}
|
||||||
|
if req.Filtrate.Status != 0 {
|
||||||
|
dbQuery = dbQuery.Where("status = ?", req.Filtrate.Status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//数据查询
|
||||||
|
dbQuery.Count(&total)
|
||||||
|
err = dbQuery.Scopes(db.Pagination(req.Page, req.PageSize)).Find(&data).Error
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (annualReportsDao) Add(req *reports.AddAnnualReportReq) (err error) {
|
||||||
|
err = db.DocDB.Model(&model.AnnualReport{}).Create(&model.AnnualReport{
|
||||||
|
FileName: req.FileName,
|
||||||
|
Date: req.Date,
|
||||||
|
FileUrl: req.FileUrl,
|
||||||
|
Operator: req.Operator,
|
||||||
|
OperatorID: req.OperatorId,
|
||||||
|
}).Error
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("新增年度报告失败")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (annualReportsDao) Edit(req *reports.EditAnnualReportReq) (err error) {
|
||||||
|
err = db.DocDB.Model(&model.AnnualReport{}).Where("id = ?", req.Id).UpdateColumns(&model.AnnualReport{
|
||||||
|
FileName: req.FileName,
|
||||||
|
Date: req.Date,
|
||||||
|
FileUrl: req.FileUrl,
|
||||||
|
Status: req.Status,
|
||||||
|
Sort: req.Sort,
|
||||||
|
Operator: req.Operator,
|
||||||
|
OperatorID: req.OperatorId,
|
||||||
|
UpdatedAt: time.Now(),
|
||||||
|
}).Error
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("编辑年度报告失败")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (annualReportsDao) Delete(req *reports.DeleteAnnualReportReq) (err error) {
|
||||||
|
err = db.DocDB.Model(&model.AnnualReport{}).Where("id = ?", req.Id).Delete(&model.AnnualReport{}).Error
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("删除年度报告失败")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
60
internel/logic/annualReports.go
Normal file
60
internel/logic/annualReports.go
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"micro-document/api/reports"
|
||||||
|
"micro-document/internel/dao"
|
||||||
|
util "micro-document/pkg/utils"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
)
|
||||||
|
|
||||||
|
type annualReportsLogic struct{}
|
||||||
|
|
||||||
|
var AnnualReportsLogic = new(annualReportsLogic)
|
||||||
|
|
||||||
|
func (annualReportsLogic) List(req *reports.GetAnnualReportListReq) (result *reports.GetAnnualReportListResp, err error) {
|
||||||
|
result = &reports.GetAnnualReportListResp{
|
||||||
|
Page: req.Page,
|
||||||
|
PageSize: req.PageSize,
|
||||||
|
}
|
||||||
|
data, total, err := dao.AnnualReportsDao.List(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("查询年度报告失败")
|
||||||
|
}
|
||||||
|
result.Total = int32(total)
|
||||||
|
if err = copier.CopyWithOption(&result.Data, &data, util.CopierProtoOptions); err != nil {
|
||||||
|
return nil, errors.New("复制年度报告失败")
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (annualReportsLogic) Add(req *reports.AddAnnualReportReq) (result *reports.AddAnnualReportResp, err error) {
|
||||||
|
result = &reports.AddAnnualReportResp{}
|
||||||
|
err = dao.AnnualReportsDao.Add(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("新增年度报告失败")
|
||||||
|
}
|
||||||
|
result.Msg = "新增年度报告成功"
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (annualReportsLogic) Edit(req *reports.EditAnnualReportReq) (result *reports.EditAnnualReportResp, err error) {
|
||||||
|
result = &reports.EditAnnualReportResp{}
|
||||||
|
err = dao.AnnualReportsDao.Edit(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("编辑年度报告失败")
|
||||||
|
}
|
||||||
|
result.Msg = "编辑年度报告成功"
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (annualReportsLogic) Delete(req *reports.DeleteAnnualReportReq) (result *reports.DeleteAnnualReportResp, err error) {
|
||||||
|
result = &reports.DeleteAnnualReportResp{}
|
||||||
|
err = dao.AnnualReportsDao.Delete(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("删除年度报告失败")
|
||||||
|
}
|
||||||
|
result.Msg = "删除年度报告成功"
|
||||||
|
return result, nil
|
||||||
|
}
|
25
internel/model/reports.go
Normal file
25
internel/model/reports.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/plugin/soft_delete"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AnnualReport struct {
|
||||||
|
ID uint `gorm:"primarykey"`
|
||||||
|
CreatedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
|
DeletedAt soft_delete.DeletedAt
|
||||||
|
FileName string `gorm:"column:file_name;type:varchar(100);not null;default:'';comment:文件名称"`
|
||||||
|
Date string `gorm:"column:date;type:varchar(100);not null;default:'';comment:日期"`
|
||||||
|
FileUrl string `gorm:"column:file_url;type:varchar(100);not null;default:'';comment:访问地址"`
|
||||||
|
Status int32 `gorm:"column:status;type:int;not null;default:2;comment:状态:1上架 2 下架"`
|
||||||
|
Sort int32 `gorm:"column:sort;type:int;not null;default:1;comment:排序"`
|
||||||
|
Operator string `gorm:"column:operator;type:varchar(100);not null;default:'';comment:操作人"`
|
||||||
|
OperatorID int32 `gorm:"column:operator_id;comment:操作人Id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*AnnualReport) TableName() string {
|
||||||
|
return "annual_report"
|
||||||
|
}
|
@ -35,6 +35,11 @@ func DbInit() {
|
|||||||
}
|
}
|
||||||
DocDB = dbq.Debug()
|
DocDB = dbq.Debug()
|
||||||
DocDB.Set("gorm:table_options", "ENGINE=InnoDB default charset=utf8")
|
DocDB.Set("gorm:table_options", "ENGINE=InnoDB default charset=utf8")
|
||||||
DocDB.AutoMigrate(&model.Governance{}, &model.PressReleases{}, &model.SecFilings{}, &model.FormType{})
|
DocDB.AutoMigrate(
|
||||||
|
&model.Governance{},
|
||||||
|
&model.PressReleases{},
|
||||||
|
&model.SecFilings{},
|
||||||
|
&model.FormType{},
|
||||||
|
&model.AnnualReport{})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
pkg/db/dto.go
Normal file
13
pkg/db/dto.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package db
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
|
func Pagination[T int | int32 | int64](page T, pageSize T) func(db *gorm.DB) *gorm.DB {
|
||||||
|
if page == 0 || pageSize == 0 {
|
||||||
|
page = 1
|
||||||
|
pageSize = 15
|
||||||
|
}
|
||||||
|
return func(db *gorm.DB) *gorm.DB {
|
||||||
|
return db.Limit(int(pageSize)).Offset(int((page - 1) * pageSize))
|
||||||
|
}
|
||||||
|
}
|
40
pkg/utils/copierOptions.go
Normal file
40
pkg/utils/copierOptions.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"micro-document/pkg/utils/stime"
|
||||||
|
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
)
|
||||||
|
|
||||||
|
var CopierProtoOptions = copier.Option{
|
||||||
|
IgnoreEmpty: true,
|
||||||
|
DeepCopy: true,
|
||||||
|
Converters: []copier.TypeConverter{
|
||||||
|
{
|
||||||
|
SrcType: time.Time{},
|
||||||
|
DstType: copier.String,
|
||||||
|
Fn: func(src interface{}) (interface{}, error) {
|
||||||
|
s, ok := src.(time.Time)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("src type :time.Time not matching")
|
||||||
|
}
|
||||||
|
return s.Format(stime.Format_Normal_YMDhms), nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
SrcType: copier.String,
|
||||||
|
DstType: time.Time{},
|
||||||
|
Fn: func(src interface{}) (interface{}, error) {
|
||||||
|
s, ok := src.(string)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("src type :time.Time not matching")
|
||||||
|
}
|
||||||
|
tt, err := stime.StringToTimeWithFormat(s, stime.Format_Normal_YMDhms)
|
||||||
|
return *tt, err
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
84
pkg/utils/stime/common.go
Normal file
84
pkg/utils/stime/common.go
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package stime
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Loc loc
|
||||||
|
|
||||||
|
type loc time.Location
|
||||||
|
|
||||||
|
func (l loc) Shanghai() *time.Location {
|
||||||
|
var shanghai, err = time.LoadLocation("Asia/Shanghai")
|
||||||
|
if err != nil {
|
||||||
|
shanghai = time.FixedZone("CST", 8*3600)
|
||||||
|
}
|
||||||
|
return shanghai
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
//常规时间格式(日期带横杠)
|
||||||
|
Format_Normal_YMDhms = "2006-01-02 15:04:05"
|
||||||
|
Format_Normal_YMD = "2006-01-02"
|
||||||
|
Format_Normal_hms = "15:04:05"
|
||||||
|
Format_Normal_hm = "15:04"
|
||||||
|
Format_Normal_YM = "2006-01"
|
||||||
|
//带斜杠的时间格式
|
||||||
|
Format_Slash_YMDhms = "2006/01/02 15:04:05"
|
||||||
|
Format_Slash_YMD = "2006/01/02"
|
||||||
|
//无间隔符
|
||||||
|
Format_NoSpacer_YMDhms = "20060102150405"
|
||||||
|
Format_NoSpacer_YMD = "20060102"
|
||||||
|
Format_ChinaChar_YMD = "2006年01月02日"
|
||||||
|
Format_ChinaChar_YMDhm = "2006年01月02日 15时04分"
|
||||||
|
Format_DB_YMDhms = "2006-01-02T15:04:05+08:00"
|
||||||
|
)
|
||||||
|
|
||||||
|
var MonthStrMap = map[string]string{
|
||||||
|
"January": "01",
|
||||||
|
"February": "02",
|
||||||
|
"March": "03",
|
||||||
|
"April": "04",
|
||||||
|
"May": "05",
|
||||||
|
"June": "06",
|
||||||
|
"July": "07",
|
||||||
|
"August": "08",
|
||||||
|
"September": "09",
|
||||||
|
"October": "10",
|
||||||
|
"November": "11",
|
||||||
|
"December": "12",
|
||||||
|
}
|
||||||
|
var MonthIntMap = map[string]int{
|
||||||
|
"January": 1,
|
||||||
|
"February": 2,
|
||||||
|
"March": 3,
|
||||||
|
"April": 4,
|
||||||
|
"May": 5,
|
||||||
|
"June": 6,
|
||||||
|
"July": 7,
|
||||||
|
"August": 8,
|
||||||
|
"September": 9,
|
||||||
|
"October": 10,
|
||||||
|
"November": 11,
|
||||||
|
"December": 12,
|
||||||
|
}
|
||||||
|
|
||||||
|
var WeekIntMap = map[string]int{
|
||||||
|
"Monday": 1,
|
||||||
|
"Tuesday": 2,
|
||||||
|
"Wednesday": 3,
|
||||||
|
"Thursday": 4,
|
||||||
|
"Friday": 5,
|
||||||
|
"Saturday": 6,
|
||||||
|
"Sunday": 7,
|
||||||
|
}
|
||||||
|
|
||||||
|
var WeekStrMap = map[string]string{
|
||||||
|
"Monday": "一",
|
||||||
|
"Tuesday": "二",
|
||||||
|
"Wednesday": "三",
|
||||||
|
"Thursday": "四",
|
||||||
|
"Friday": "五",
|
||||||
|
"Saturday": "六",
|
||||||
|
"Sunday": "日",
|
||||||
|
}
|
150
pkg/utils/stime/getTime.go
Normal file
150
pkg/utils/stime/getTime.go
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
package stime
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func StrNowDate() string {
|
||||||
|
return TimeToString(time.Now(), Format_Normal_YMD)
|
||||||
|
}
|
||||||
|
|
||||||
|
func StrNowYearMonth() string {
|
||||||
|
return TimeToString(time.Now(), Format_Normal_YM)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ThisMorming 今天凌晨
|
||||||
|
func ThisMorming(format string) (strTime string) {
|
||||||
|
thisTime := time.Now()
|
||||||
|
year := thisTime.Year()
|
||||||
|
month := MonthStrMap[thisTime.Month().String()]
|
||||||
|
day := fmt.Sprintf("%02d", thisTime.Day())
|
||||||
|
strTime = fmt.Sprintf("%v-%v-%v 00:00:00", year, month, day)
|
||||||
|
if format != Format_Normal_YMDhms {
|
||||||
|
t1, _ := time.ParseInLocation(Format_Normal_YMDhms, strTime, Loc.Shanghai())
|
||||||
|
strTime = t1.Format(format)
|
||||||
|
}
|
||||||
|
return strTime
|
||||||
|
}
|
||||||
|
|
||||||
|
// ThisMorningUnix 获取当日凌晨的时间戳
|
||||||
|
func ThisMorningToUnix() int64 {
|
||||||
|
thist := time.Now()
|
||||||
|
zero_tm := time.Date(thist.Year(), thist.Month(), thist.Day(), 0, 0, 0, 0, thist.Location()).Unix()
|
||||||
|
return zero_tm
|
||||||
|
}
|
||||||
|
|
||||||
|
// TomorrowMorning 第二天凌晨
|
||||||
|
func TomorrowMorning(baseTime time.Time) *time.Time {
|
||||||
|
year := baseTime.Year()
|
||||||
|
month := MonthStrMap[baseTime.Month().String()]
|
||||||
|
day := fmt.Sprintf("%02d", baseTime.Day()+1)
|
||||||
|
strTime := fmt.Sprintf("%v-%v-%v 00:00:00", year, month, day)
|
||||||
|
res, _ := StringToTime(strTime)
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
// ThisTimeUnix 获取当前时间的时间戳
|
||||||
|
func CurrentimeToUnix() int64 {
|
||||||
|
return time.Now().Unix()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Currentime 获取当前时间
|
||||||
|
func Currentime(format string) (strTime string) {
|
||||||
|
strTime = time.Now().Format(format)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// HoursAgo 若干小时之前的时间
|
||||||
|
func HoursAgo(hours time.Duration, format string) (lastTimeStr string) {
|
||||||
|
lastStamp := time.Now().Unix() - int64((time.Hour * hours).Seconds())
|
||||||
|
lastTime := time.Unix(lastStamp, 0).In(Loc.Shanghai())
|
||||||
|
lastTimeStr = lastTime.Format(format)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// TimeToString 时间转字符串
|
||||||
|
func TimeToString(t time.Time, format string) string {
|
||||||
|
return t.Format(format)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算指定月份的天数
|
||||||
|
func YearMonthToDayNumber(year int, month int) int {
|
||||||
|
// 有31天的月份
|
||||||
|
day31 := map[int]bool{
|
||||||
|
1: true,
|
||||||
|
3: true,
|
||||||
|
5: true,
|
||||||
|
7: true,
|
||||||
|
8: true,
|
||||||
|
10: true,
|
||||||
|
12: true,
|
||||||
|
}
|
||||||
|
if day31[month] == true {
|
||||||
|
return 31
|
||||||
|
}
|
||||||
|
// 有30天的月份
|
||||||
|
day30 := map[int]bool{
|
||||||
|
4: true,
|
||||||
|
6: true,
|
||||||
|
9: true,
|
||||||
|
11: true,
|
||||||
|
}
|
||||||
|
if day30[month] == true {
|
||||||
|
return 30
|
||||||
|
}
|
||||||
|
// 计算是平年还是闰年
|
||||||
|
if (year%4 == 0 && year%100 != 0) || year%400 == 0 {
|
||||||
|
// 得出2月的天数
|
||||||
|
return 29
|
||||||
|
}
|
||||||
|
// 得出2月的天数
|
||||||
|
return 28
|
||||||
|
}
|
||||||
|
|
||||||
|
// 求时间差(返回一个数字,该数字单位由传过来的unit决定。若unit为60,则单位是分钟。)
|
||||||
|
func GetDiffTime(start_time string, end_time string, unit int64) int64 {
|
||||||
|
// 转成时间戳
|
||||||
|
if len(start_time) == 10 {
|
||||||
|
start_time = fmt.Sprintf("%v 00:00:00", start_time)
|
||||||
|
}
|
||||||
|
if len(end_time) == 10 {
|
||||||
|
end_time = fmt.Sprintf("%v 00:00:00", end_time)
|
||||||
|
}
|
||||||
|
startUnix, _ := time.ParseInLocation("2006-01-02 15:04:05", start_time, Loc.Shanghai())
|
||||||
|
endUnix, _ := time.ParseInLocation("2006-01-02 15:04:05", end_time, Loc.Shanghai())
|
||||||
|
startTime := startUnix.Unix()
|
||||||
|
endTime := endUnix.Unix()
|
||||||
|
// 求相差天数
|
||||||
|
date := (endTime - startTime) / unit
|
||||||
|
return date
|
||||||
|
}
|
||||||
|
|
||||||
|
func TimeSince(pastTime string, format string) string {
|
||||||
|
|
||||||
|
t, err := time.Parse(format, pastTime)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
diff := time.Since(t)
|
||||||
|
if diff.Minutes() < 15 {
|
||||||
|
return "刚刚"
|
||||||
|
} else if diff.Minutes() >= 15 && diff.Minutes() < 30 {
|
||||||
|
return "15分钟前"
|
||||||
|
} else if diff.Minutes() >= 30 && diff.Minutes() < 60 {
|
||||||
|
return "半小时前"
|
||||||
|
} else if diff.Hours() >= 1 && diff.Hours() < 24 {
|
||||||
|
return fmt.Sprintf("%d小时前", int(diff.Hours()))
|
||||||
|
} else if diff.Hours() >= 24 && diff.Hours() < 24*15 {
|
||||||
|
return fmt.Sprintf("%d天前", int(diff.Hours()/24))
|
||||||
|
} else if diff.Hours() < 24*30 {
|
||||||
|
return "半月前"
|
||||||
|
} else if diff.Hours() < 24*30*6 { //小于半年
|
||||||
|
return fmt.Sprintf("%d月前", int(diff.Hours()/24/30))
|
||||||
|
} else if diff.Hours() < 24*365 { //小于1年
|
||||||
|
return "半年前"
|
||||||
|
} else {
|
||||||
|
return t.Format("2006-01-02 15:04:05")
|
||||||
|
}
|
||||||
|
}
|
101
pkg/utils/stime/getTimeExt.go
Normal file
101
pkg/utils/stime/getTimeExt.go
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
package stime
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 根据指定时间获取后面的若干天工作日列表
|
||||||
|
// param baseOn 指定基准时间
|
||||||
|
// param daysNum 获取工作日的数量
|
||||||
|
func GetWorkDayList(baseOn *time.Time, daysNum int) []time.Time {
|
||||||
|
var timeList []time.Time
|
||||||
|
var basCount = 1
|
||||||
|
var workDay time.Time
|
||||||
|
for {
|
||||||
|
if len(timeList) == daysNum {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
workDay = baseOn.AddDate(0, 0, basCount)
|
||||||
|
switch workDay.Weekday() {
|
||||||
|
case time.Saturday:
|
||||||
|
basCount += 2
|
||||||
|
continue
|
||||||
|
case time.Sunday:
|
||||||
|
basCount++
|
||||||
|
continue
|
||||||
|
default:
|
||||||
|
timeList = append(timeList, workDay)
|
||||||
|
basCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return timeList
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据指定时间获取后面的若干天工作日列表
|
||||||
|
// param baseOn 指定基准时间
|
||||||
|
// param daysNum 获取工作日的数量
|
||||||
|
func GetWorkDayStrList(baseOn *time.Time, daysNum int) []string {
|
||||||
|
var timeList []string
|
||||||
|
var basCount = 1
|
||||||
|
var workDay time.Time
|
||||||
|
for {
|
||||||
|
if len(timeList) == daysNum {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
workDay = baseOn.AddDate(0, 0, basCount)
|
||||||
|
switch workDay.Weekday() {
|
||||||
|
case time.Saturday:
|
||||||
|
basCount += 2
|
||||||
|
continue
|
||||||
|
case time.Sunday:
|
||||||
|
basCount++
|
||||||
|
continue
|
||||||
|
default:
|
||||||
|
timeList = append(timeList, TimeToString(workDay, Format_Normal_YMD))
|
||||||
|
basCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return timeList
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取时间差文字描述
|
||||||
|
func GetTimeDifferenceDesc(now *time.Time, before *time.Time) string {
|
||||||
|
if before == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if now.After(*before) {
|
||||||
|
subTimestamp := now.Unix() - before.Unix()
|
||||||
|
day := subTimestamp / (3600 * 24)
|
||||||
|
hour := (subTimestamp - day*3600*24) / 3600
|
||||||
|
minute := (subTimestamp - day*3600*24 - hour*3600) / 60
|
||||||
|
second := subTimestamp - day*3600*24 - hour*3600 - minute*60
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case day > 0:
|
||||||
|
if hour > 0 {
|
||||||
|
return fmt.Sprintf("%d天%d小时", day, hour)
|
||||||
|
} else {
|
||||||
|
return fmt.Sprintf("%d天", day)
|
||||||
|
}
|
||||||
|
case hour > 0:
|
||||||
|
if minute < 10 {
|
||||||
|
return fmt.Sprintf("%d小时", hour)
|
||||||
|
} else {
|
||||||
|
return fmt.Sprintf("%d小时%d", hour, minute)
|
||||||
|
}
|
||||||
|
case hour == 0 && minute > 0:
|
||||||
|
return fmt.Sprintf("%d分钟", minute)
|
||||||
|
case hour == 0 && minute == 0:
|
||||||
|
return fmt.Sprintf("%d秒", second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// TimeStampToBytes 时间戳转字节
|
||||||
|
func TimeStampToBytes(stamp int64) []byte {
|
||||||
|
timeStr := strconv.FormatInt(stamp, 2)
|
||||||
|
return []byte(timeStr)
|
||||||
|
}
|
12
pkg/utils/stime/getTimeExt_test.go
Normal file
12
pkg/utils/stime/getTimeExt_test.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package stime
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetWorkDayStrList(t *testing.T) {
|
||||||
|
now := time.Now()
|
||||||
|
result := GetWorkDayStrList(&now, 5)
|
||||||
|
t.Log(result)
|
||||||
|
}
|
64
pkg/utils/stime/timeTranslate.go
Normal file
64
pkg/utils/stime/timeTranslate.go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package stime
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetTimestampMillisecond() int64 {
|
||||||
|
now := time.Now()
|
||||||
|
return now.UnixNano() / 1e6
|
||||||
|
}
|
||||||
|
|
||||||
|
func StringToTime(strTime string) (*time.Time, error) {
|
||||||
|
const TIME_LAYOUT = "2006-01-02 15:04:05" //此时间不可更改
|
||||||
|
timeobj, err := time.ParseInLocation(TIME_LAYOUT, strTime, Loc.Shanghai())
|
||||||
|
return &timeobj, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func StringToTimeWithFormat(strTime string, timeFormat string) (*time.Time, error) {
|
||||||
|
timeobj, err := time.ParseInLocation(timeFormat, strTime, Loc.Shanghai())
|
||||||
|
return &timeobj, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 去除精确时间后面的小数点
|
||||||
|
func NowTimeToTime(layout string) *time.Time {
|
||||||
|
otime := time.Now().Format(layout) //"2006-01-02 15:04:05" and so on
|
||||||
|
tt, _ := StringToTime(otime)
|
||||||
|
return tt
|
||||||
|
}
|
||||||
|
|
||||||
|
// 时间之间的转换
|
||||||
|
func TimeStampToString(value interface{}, after_type string) {
|
||||||
|
switch value.(type) {
|
||||||
|
case string:
|
||||||
|
fmt.Println(value.(string))
|
||||||
|
case int64:
|
||||||
|
fmt.Println(value.(int64))
|
||||||
|
case int32:
|
||||||
|
fmt.Println(value.(int32))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAge(birthday time.Time) int {
|
||||||
|
if birthday.IsZero() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
now := time.Now()
|
||||||
|
year, month, day := now.Date()
|
||||||
|
if year == 0 || month == 0 || day == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
age := year - birthday.Year() - 1
|
||||||
|
//判断年龄
|
||||||
|
if birthday.Month() < month || birthday.Month() == month && birthday.Day() <= day {
|
||||||
|
age++
|
||||||
|
}
|
||||||
|
return age
|
||||||
|
}
|
||||||
|
func ParseTimeStamp(unix int64) (result time.Time) {
|
||||||
|
if unix == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return time.Unix(unix, 0)
|
||||||
|
}
|
19
pkg/utils/stime/timeTranslate_test.go
Normal file
19
pkg/utils/stime/timeTranslate_test.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package stime
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTime(t *testing.T) {
|
||||||
|
result := NowTimeToTime(Format_Normal_YMDhms)
|
||||||
|
fmt.Println(result)
|
||||||
|
}
|
||||||
|
func TestGetAge(t *testing.T) {
|
||||||
|
age := GetAge(time.Date(1991, 3, 6, 0, 0, 0, 0, Loc.Shanghai()))
|
||||||
|
fmt.Println(age)
|
||||||
|
if age != 31 {
|
||||||
|
t.Errorf("want 31 but get %v", age)
|
||||||
|
}
|
||||||
|
}
|
47
pkg/utils/stime/week.go
Normal file
47
pkg/utils/stime/week.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package stime
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
func NowWeekDay() string {
|
||||||
|
var weekday = [7]string{"七", "一", "二", "三", "四", "五", "六"}
|
||||||
|
week := int(time.Now().Weekday())
|
||||||
|
return weekday[week]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取按年算的周数
|
||||||
|
func GetYearWeek(t *time.Time) int {
|
||||||
|
yearDay := t.YearDay()
|
||||||
|
yearFirstDay := t.AddDate(0, 0, -yearDay+1)
|
||||||
|
firstDayInWeek := int(yearFirstDay.Weekday())
|
||||||
|
|
||||||
|
//今年第一周有几天
|
||||||
|
firstWeekDays := 1
|
||||||
|
if firstDayInWeek != 0 {
|
||||||
|
firstWeekDays = 7 - firstDayInWeek + 1
|
||||||
|
}
|
||||||
|
var week int
|
||||||
|
if yearDay <= firstWeekDays {
|
||||||
|
week = 1
|
||||||
|
} else {
|
||||||
|
week = (yearDay-firstWeekDays)/7 + 2
|
||||||
|
}
|
||||||
|
return week
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetWeekDate 获取基准时间范围最最近的某个星期时间
|
||||||
|
//
|
||||||
|
// param baseOn: 基准时间
|
||||||
|
// param weekNum: 中国星期数 1~7
|
||||||
|
// return *time.Time
|
||||||
|
func GetWeekDate(baseOn time.Time, weekNum int) *time.Time {
|
||||||
|
if baseOn.IsZero() || (weekNum <= 0 || weekNum > 7) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
baseDate := time.Date(baseOn.Year(), baseOn.Month(), baseOn.Day(), 0, 0, 0, 0, Loc.Shanghai())
|
||||||
|
var (
|
||||||
|
w = int(baseOn.Weekday())
|
||||||
|
weekDate time.Time
|
||||||
|
)
|
||||||
|
weekDate = baseDate.AddDate(0, 0, weekNum-w)
|
||||||
|
return &weekDate
|
||||||
|
}
|
14
pkg/utils/stime/week_test.go
Normal file
14
pkg/utils/stime/week_test.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package stime
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetYearWeek(t *testing.T) {
|
||||||
|
now := time.Now()
|
||||||
|
t.Log(GetYearWeek(&now))
|
||||||
|
var w = int(now.Weekday())
|
||||||
|
t.Log(now.AddDate(0, 0, -w+1).Weekday())
|
||||||
|
t.Log(now.AddDate(0, 0, 7-w).Weekday())
|
||||||
|
}
|
3
protocReports.bat
Normal file
3
protocReports.bat
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
@echo off
|
||||||
|
protoc -I . -I ./api/reports --proto_path=./api/reports --go_out=./api/reports --go-triple_out=./api/reports --govalidators_out=./api/reports ./api/reports/reports.proto
|
||||||
|
.\clear.sh
|
Loading…
Reference in New Issue
Block a user