You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
4.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package main
import (
"dsBaseRpc/RpcService/BaseClass/BaseClassProto"
"dsBaseRpc/RpcService/BaseClass/BaseClassService"
"dsBaseRpc/RpcService/BaseGlobal/BaseGlobalProto"
"dsBaseRpc/RpcService/BaseGlobal/BaseGlobalService"
"dsBaseRpc/RpcService/BaseMenu/BaseMenuProto"
"dsBaseRpc/RpcService/BaseMenu/BaseMenuService"
"dsBaseRpc/RpcService/BaseOrganization/BaseOrganizationProto"
"dsBaseRpc/RpcService/BaseOrganization/BaseOrganizationService"
"dsBaseRpc/RpcService/BasePosition/BasePositionProto"
"dsBaseRpc/RpcService/BasePosition/BasePositionService"
"dsBaseRpc/RpcService/BasePurview/BasePurviewProto"
"dsBaseRpc/RpcService/BasePurview/BasePurviewService"
"dsBaseRpc/RpcService/BaseRole/BaseRoleProto"
"dsBaseRpc/RpcService/BaseRole/BaseRoleService"
"dsBaseRpc/RpcService/BaseRoleMenu/BaseRoleMenuProto"
"dsBaseRpc/RpcService/BaseRoleMenu/BaseRoleMenuService"
"dsBaseRpc/RpcService/BaseRolePerson/BaseRolePersonProto"
"dsBaseRpc/RpcService/BaseRolePerson/BaseRolePersonService"
"dsBaseRpc/RpcService/BaseStudent/BaseStudentProto"
"dsBaseRpc/RpcService/BaseStudent/BaseStudentService"
"dsBaseRpc/RpcService/BaseTeacher/BaseTeacherProto"
"dsBaseRpc/RpcService/BaseTeacher/BaseTeacherService"
"dsBaseRpc/RpcService/GovArea/GovAreaProto"
"dsBaseRpc/RpcService/GovArea/GovAreaService"
"dsBaseRpc/RpcService/SysDict/SysDictProto"
"dsBaseRpc/RpcService/SysDict/SysDictService"
"dsBaseRpc/RpcService/SysLoginperson/SysLoginpersonProto"
"dsBaseRpc/RpcService/SysLoginperson/SysLoginpersonService"
"dsBaseRpc/Utils/CommonUtil"
"dsBaseRpc/Utils/ConfigUtil"
"dsBaseRpc/Utils/DbUtil"
"dsBaseRpc/Utils/FileUtil"
"dsBaseRpc/Utils/SysKit"
"fmt"
"github.com/robfig/cron/v3"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
"net"
"os"
)
// 配置步骤:
// https://studygolang.com/articles/16627?fr=sidebar
// 黄海下载的是这个protobuf-all-3.11.4.zip
func main() {
// 一、显示Logo
configIniFile := "./Config/logo.txt"
var logo = FileUtil.ReadFileContent(configIniFile)
fmt.Print(logo)
//创建日志文件目录
if !CommonUtil.Exists(ConfigUtil.DistributeRemotePath + "Logs") {
_ = os.MkdirAll(ConfigUtil.DistributeRemotePath+"Logs", os.ModePerm)
}
//添加定时清理垃圾的代码
c := cron.New(cron.WithSeconds())
_, _ = c.AddFunc("0 0 1 * * *", func() {
//清除导入数据的临时表
var db = DbUtil.Engine
sql := "truncate table t_base_teacher_import_excel"
_, _ = db.SQL(sql).Execute()
sql = "truncate table t_base_student_import_excel"
_, _ = db.SQL(sql).Execute()
//清空自动日志
var logPath = ConfigUtil.DistributeRemotePath + "Logs"
file := logPath + "/dsBaseRpc.log"
if CommonUtil.Exists(file) {
f, _ := os.OpenFile(file, os.O_WRONLY|os.O_TRUNC, 0600)
defer f.Close()
_, _ = f.WriteString("清空成功!")
}
})
c.Start()
defer c.Stop()
//二、清除redis所有Rpc层使用的缓存(不包含统一认证使用的缓存)
go func() {
SysKit.ClearRpcRedis()
}()
//三、初始化登录名的最大号
SysKit.InitLoginIdIntMax()
//四、发布Grpc服务
lis, err := net.Listen("tcp", ":"+ConfigUtil.RpcServerPort)
if err != nil {
fmt.Printf("failed to listen: %v\n", err)
}
//声明服务
s := grpc.NewServer()
//行政区划
GovAreaProto.RegisterGovAreaManageServer(s, &GovAreaService.Rpc{})
//权限
BasePurviewProto.RegisterBasePurviewManageServer(s, &BasePurviewService.Rpc{})
//字典
SysDictProto.RegisterSysDictManageServer(s, &SysDictService.Rpc{})
//组织机构
BaseOrganizationProto.RegisterBaseOrganizationManageServer(s, &BaseOrganizationService.Rpc{})
//班级
BaseClassProto.RegisterBaseClassManageServer(s, &BaseClassService.Rpc{})
//教师
BaseTeacherProto.RegisterBaseTeacherManageServer(s, &BaseTeacherService.Rpc{})
//学生
BaseStudentProto.RegisterBaseStudentManageServer(s, &BaseStudentService.Rpc{})
//登录账号
SysLoginpersonProto.RegisterSysLoginpersonManageServer(s, &SysLoginpersonService.Rpc{})
//全局变量
BaseGlobalProto.RegisterBaseGlobalManageServer(s, &BaseGlobalService.Rpc{})
//人员角色
BaseRolePersonProto.RegisterBaseRolePersonManageServer(s, &BaseRolePersonService.Rpc{})
//职务
BasePositionProto.RegisterBasePositionManageServer(s, &BasePositionService.Rpc{})
//菜单
BaseMenuProto.RegisterBaseMenuManageServer(s, &BaseMenuService.Rpc{})
//角色
BaseRoleProto.RegisterBaseRoleManageServer(s, &BaseRoleService.Rpc{})
//角色系统对应表
BaseRoleMenuProto.RegisterBaseRoleMenuManageServer(s, &BaseRoleMenuService.Rpc{})
//五、开启一个数据上报的协程
/*
go func() {
//异常处理
defer func() {
if err := recover(); err != nil {
fmt.Printf("%s\n", err)
}
}()
DataExchange.DataExchange()
}()
*/
//六、 注册反射服务 这个服务是CLI使用的 跟服务本身没有关系
reflection.Register(s)
//七、启动
fmt.Printf("服务发布成功,端口:%s\n", ConfigUtil.RpcServerPort)
if err := s.Serve(lis); err != nil {
fmt.Printf("failed to serve: %v\n", err)
}
}