master
黄海 5 years ago
parent 00315db468
commit 31be7053ee

@ -0,0 +1,13 @@
package BaseMenuDao
import (
"dsBaseRpc/RpcService/BaseMenu/BaseMenuProto"
"dsBaseRpc/Utils/DbUtil"
)
var db = DbUtil.Engine
//批量增加
func AddBaseMenu(in *BaseMenuProto.ModelArg) (int64, error) {
return db.Insert(ms)
}

@ -1,16 +1,194 @@
package BaseMenuService
import (
"context"
"dsBaseRpc/Const"
"dsBaseRpc/Const/ErrorConst"
"dsBaseRpc/RpcService/BaseClass/BaseClassDao"
"dsBaseRpc/RpcService/BaseClass/BaseClassProto"
"dsBaseRpc/RpcService/BaseMenu/BaseMenuDao"
"dsBaseRpc/RpcService/BaseMenu/BaseMenuProto"
"dsBaseRpc/RpcService/BaseStudent/BaseStudentDao"
"dsBaseRpc/RpcService/BaseStudent/BaseStudentProto"
"dsBaseRpc/Utils/CommonUtil"
"dsBaseRpc/Utils/LogUtil"
"dsBaseRpc/Utils/SqlKit"
"dsBaseRpc/models"
"fmt"
)
type Rpc struct{} //服务对象
/*
//获取单条
rpc GetBaseMenu (ModelArg) returns (Reply) {}
//选择单条
func (s *Rpc) GetBaseMenu(ctx context.Context, in *BaseMenuProto.ModelArg) (*BaseMenuProto.Reply, error) {
//异常处理
defer func() {
if err := recover(); err != nil {
fmt.Printf("%s\n", err)
}
}()
//rpc响应
var reply BaseMenuProto.Reply
//通用获取单条
list := SqlKit.QueryByIds([]string{in.MenuId}, "t_base_menu")
//将结果序列化
reply.Success = true
reply.Count = 1
reply.Message = Const.SuccessDataBaseAction
reply.List = CommonUtil.SerializeToString(list)
return &reply, nil
}
//增加
rpc AddBaseMenu (ModelArg) returns (Reply) {}
//批量删除
rpc DeleteBaseMenu (DeleteIdsArg) returns (Reply) {}
func (s *Rpc) AddBaseMenu(ctx context.Context, in *BaseMenuProto.ModelArg) (*BaseMenuProto.Reply, error) {
//异常处理
defer func() {
if err := recover(); err != nil {
fmt.Printf("%s\n", err)
}
}()
//rpc响应
var reply BaseMenuProto.Reply
//调用dao
model := new(models.TBaseMenu)
//增加
_, err := BaseMenuDao.AddBaseMenu(in)
if err != nil {
reply.Success = false
reply.Message = Const.DataBaseActionError
LogUtil.Error(ErrorConst.SqlUpdateError, "执行AddBaseMenu时发生严重错误"+err.Error())
} else {
reply.Success = true
reply.Message = Const.SuccessDataBaseAction
}
return &reply, err
}
//删除
func (s *Rpc) DeleteBaseMenu(ctx context.Context, in *BaseMenuProto.DeleteIdsArg) (*BaseMenuProto.Reply, error) {
//异常处理
defer func() {
if err := recover(); err != nil {
fmt.Printf("%s\n", err)
}
}()
//rpc响应
var reply BaseMenuProto.Reply
//判断班级下是不是存在可用的学生?
for i := range in.Ids {
var inStudent BaseStudentProto.QueryArg
inStudent.Page = 1
inStudent.Limit = 1
inStudent.Xm = ""
inStudent.ClassId = in.Ids[i]
_, count, err := BaseStudentDao.PageBaseStudent(&inStudent)
if err != nil {
LogUtil.Error(ErrorConst.SqlUpdateError, "执行PageBaseStudent时发生严重错误"+err.Error())
reply.Success = false
reply.Message = Const.DataBaseActionError
return &reply, err
}
if count > 0 {
reply.Success = false
reply.Message = "班级下存在可用的学生,无法删除!"
return &reply, err
}
}
//调用通用删除命令进行删除
err := SqlKit.DeleteIds("t_base_class", in.Ids)
//错误处理
if err != nil {
LogUtil.Error(ErrorConst.SqlUpdateError, "执行DeleteBaseClass时发生严重错误"+err.Error())
reply.Success = false
reply.Message = Const.DataBaseActionError
return &reply, err
}
//记录日志
ms, err := BaseClassDao.GetByIds(in.Ids)
if err != nil {
LogUtil.Error(ErrorConst.SqlUpdateError, "执行FindModelsByIds时发生严重错误"+err.Error())
reply.Success = false
reply.Message = Const.DataBaseActionError
return &reply, err
}
err = BaseClassDao.ActionLog(ms, Const.ActionDelete, in.ActionPersonId, in.ActionIpAddress)
if err != nil {
reply.Success = false
reply.Message = Const.DataBaseActionError
LogUtil.Error(ErrorConst.SqlUpdateError, "执行ActionLog时发生严重错误"+err.Error())
}
reply.Success = true
reply.Message = Const.SuccessDataBaseAction
return &reply, err
}
//修改
rpc UpdateBaseMenu (ModelArg) returns (Reply) {}
//查询(不分页)
rpc PageBaseMenu (QueryArg) returns (Reply) {}
*/
func (s *Rpc) UpdateBaseMenu(ctx context.Context, in *BaseMenuProto.ModelArg) (*BaseMenuProto.Reply, error) {
//异常处理
defer func() {
if err := recover(); err != nil {
fmt.Printf("%s\n", err)
}
}()
//rpc响应
var reply BaseClassProto.Reply
//修改
model := new(models.TBaseClass)
model.ClassId = in.ClassId
model.ClassAlias = in.ClassAlias
model.TeacherId = in.TeacherId
_, err := BaseClassDao.UpdateBaseClass(*model, in.ForceUpdateFields)
//错误处理
if err != nil {
reply.Success = false
reply.Message = Const.DataBaseActionError
LogUtil.Error(ErrorConst.SqlUpdateError, "执行UpdateBaseClass时发生严重错误"+err.Error())
return &reply, err
}
//记录日志
ms, err := BaseClassDao.GetByIds([]string{in.ClassId})
if err != nil {
LogUtil.Error(ErrorConst.SqlUpdateError, "执行FindModelsByIds时发生严重错误"+err.Error())
reply.Success = false
reply.Message = Const.DataBaseActionError
return &reply, err
}
err = BaseClassDao.ActionLog(ms, Const.ActionUpdate, in.ActionPersonId, in.ActionIpAddress)
if err != nil {
reply.Success = false
reply.Message = Const.DataBaseActionError
LogUtil.Error(ErrorConst.SqlUpdateError, "执行ActionLog时发生严重错误"+err.Error())
}
reply.Success = true
reply.Message = Const.SuccessDataBaseAction
return &reply, nil
}
//分页查询
func (s *Rpc) PageBaseMenu(ctx context.Context, in *BaseMenuProto.QueryArg) (*BaseMenuProto.Reply, error) {
//异常处理
defer func() {
if err := recover(); err != nil {
fmt.Printf("%s\n", err)
}
}()
//rpc响应
var reply BaseClassProto.Reply
list, count, err := BaseClassDao.PageBaseClass(in)
//错误处理
if err != nil {
reply.Success = false
reply.Message = Const.DataBaseActionError
LogUtil.Error(ErrorConst.SqlQueryError, "执行PageBaseClass时发生严重错误"+err.Error())
return &reply, err
}
reply.Count = count
reply.Success = true
reply.Message = Const.SuccessDataBaseAction
reply.List = CommonUtil.SerializeToString(list)
return &reply, nil
}

@ -14,6 +14,9 @@ import (
)
func main() {
//记得检查是否xorm已安装
// go get github.com/go-xorm/cmd/xorm
//执行一次
var para = ConfigUtil.MysqlUser + ":" + ConfigUtil.MysqlPwd + "@(" + ConfigUtil.MysqlIp + ":" + ConfigUtil.MysqlPort + ")/" + ConfigUtil.MysqlDataBase + "?charset=utf8"
CommonUtil.Exec("xorm", "reverse", "mysql", para, "Templates")

@ -29,7 +29,6 @@ require (
github.com/go-redis/redis/v7 v7.4.0
github.com/go-sql-driver/mysql v1.5.0
github.com/go-xorm/cmd/xorm v0.0.0-20190426080617-f87981e709a1 // indirect
github.com/go-xorm/xorm v0.7.9 // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.4.2

@ -244,6 +244,7 @@ github.com/go-xorm/builder v0.0.0-20180322150003-a9b7ffcca3f0/go.mod h1:v8mE3MFB
github.com/go-xorm/builder v0.0.0-20180826070321-377feedb49e3 h1:X7269Yg+nTx6iLFxyPSbMj4ZIQHzEf0SozXjs3yy26c=
github.com/go-xorm/builder v0.0.0-20180826070321-377feedb49e3/go.mod h1:v8mE3MFBgtL+RGFNfUnAMUqqfk/Y4W5KuwCFQIEpQLk=
github.com/go-xorm/cmd v0.0.0-20190426080617-f87981e709a1 h1:2Nc5up6dv9Rbw5t3+icygrTAW9usUAeY1Ih1MbmNDR0=
github.com/go-xorm/cmd v0.0.0-20190426080617-f87981e709a1/go.mod h1:QsnOUqcd//dKCufiEqBxjFc8NsESHSTP3uyfppdZHMU=
github.com/go-xorm/cmd/xorm v0.0.0-20190426080617-f87981e709a1 h1:4w5pI2wRlOprh2nz5/jzSc79fi7K2RDTcdO70Jxh7gk=
github.com/go-xorm/cmd/xorm v0.0.0-20190426080617-f87981e709a1/go.mod h1:rqMt6kG8yO6aEP1XglHq9reDA1FfiSPEGL/LctclQAU=
github.com/go-xorm/core v0.0.0-20180322150003-0177c08cee88/go.mod h1:d8FJ9Br8OGyQl12MCclmYBuBqqxsyeedpXciV5Myih8=
@ -494,6 +495,7 @@ github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f h1:sgU
github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f/go.mod h1:UGmTpUd3rjbtfIpwAPrcfmGf/Z1HS95TATB+m57TPB8=
github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 h1:Bvq8AziQ5jFF4BHGAEDSqwPW1NJS3XshxbRCxtjFAZc=
github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042/go.mod h1:TPpsiPUEh0zFL1Snz4crhMlBe60PYxRHr5oFF3rRYg0=
github.com/lib/pq v0.0.0-20180523175426-90697d60dd84 h1:it29sI2IM490luSc3RAhp5WuCYnc6RtbfLVAB7nmC5M=
github.com/lib/pq v0.0.0-20180523175426-90697d60dd84/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=

@ -9,7 +9,7 @@ type TBaseClass struct {
Rxnf int32 `xorm:"not null default 1990 comment('入学年份') index(fk_t_base_class_t_dm_stage_1) INT(11)"`
Rxjj int32 `xorm:"not null default 0 comment('入学季节') INT(11)"`
SchoolingLength int32 `xorm:"not null default 3 comment('学制') INT(11)"`
StageId string `xorm:"not null default '''' comment('所属学段ID') index(fk_t_base_class_t_dm_stage_1) CHAR(1)"`
StageId int32 `xorm:"not null comment('所属学段ID') index(fk_t_base_class_t_dm_stage_1) INT(11)"`
TeacherId string `xorm:"not null default '''' comment('班主任ID') CHAR(36)"`
OrgId string `xorm:"not null default '''' comment('所在部门除职业和高等外都是0') CHAR(36)"`
BureauId string `xorm:"not null default '''' comment('所在学校ID') index(fk_t_base_class_t_dm_stage_1) CHAR(36)"`

@ -10,7 +10,7 @@ type TBaseClassLog struct {
Rxnf int32 `xorm:"not null default 1990 comment('入学年份') INT(11)"`
Rxjj int32 `xorm:"not null default 0 comment('入学季节') INT(11)"`
SchoolingLength int32 `xorm:"not null default 3 comment('学制') INT(11)"`
StageId string `xorm:"not null default '''' comment('所属学段ID') CHAR(1)"`
StageId int32 `xorm:"not null comment('所属学段ID') INT(11)"`
TeacherId string `xorm:"not null default '''' comment('班主任ID') CHAR(36)"`
OrgId string `xorm:"not null default '''' comment('所在部门除职业和高等外都是0') CHAR(36)"`
BureauId string `xorm:"not null default '''' comment('所在学校ID') CHAR(36)"`

@ -1,13 +1,11 @@
package models
type TBaseRole struct {
RoleId string `xorm:"not null pk comment('角色ID') CHAR(36)"`
RoleName string `xorm:"not null default '''' comment('角色名称') VARCHAR(100)"`
RoleCode string `xorm:"not null default '''' comment('角色编码') VARCHAR(100)"`
RoleLevel int32 `xorm:"not null default -1 comment('角色级别 1超级管理员 2省级教育局 3市级教育局 4区(县)级教育局 5省级教辅单位 6市级教辅单位 7区(县)级教辅单位 8校级 9大学区') INT(11)"`
BusinessCode string `xorm:"not null default '''' comment('业务系统编码对应表t_base_business') index CHAR(6)"`
IdentityId int32 `xorm:"not null default 1 comment('身份ID对应表t_sys_identity') INT(11)"`
BUse int32 `xorm:"not null default 1 comment('是否启用 0未启用 1启用') TINYINT(1)"`
ManageLevel int32 `xorm:"not null default 1 comment('管理级别 1只管理本级 2可以管理下一级') INT(11)"`
SortId int32 `xorm:"not null default 1 comment('排序号') INT(11)"`
RoleId string `xorm:"not null pk comment('角色ID') CHAR(36)"`
RoleName string `xorm:"not null default '''' comment('角色名称') VARCHAR(100)"`
RoleCode string `xorm:"not null default '''' comment('角色编码') VARCHAR(100)"`
RoleLevel int32 `xorm:"not null default -1 comment('角色级别 1超级管理员 2省级教育局 3市级教育局 4区(县)级教育局 5省级教辅单位 6市级教辅单位 7区(县)级教辅单位 8校级 9大学区') INT(11)"`
IdentityId int32 `xorm:"not null default 1 comment('身份ID对应表t_sys_identity') INT(11)"`
BUse int32 `xorm:"not null default 1 comment('是否启用 0未启用 1启用') TINYINT(1)"`
SortId int32 `xorm:"not null default 1 comment('排序号') INT(11)"`
}

@ -11,5 +11,5 @@ type TBaseTeacherOrg struct {
DistrictCode string `xorm:"not null default '''' comment('所在区行政区划码') CHAR(6)"`
MainSchoolId string `xorm:"not null default '''' comment('主校ID') CHAR(36)"`
SortId int32 `xorm:"not null comment('排序号在获取信息时如果排序号大于9999前台不显示') INT(11)"`
IsMain int32 `xorm:"not null default 1 comment('是不是主单位、主部门,待删除') INT(255)"`
IsMain int32 `xorm:"not null default 1 comment('是不是主单位、主部门') INT(255)"`
}

@ -30,6 +30,8 @@ type TDataexOrgtree struct {
ProvinceId string `xorm:"default 'NULL' comment('省编码') VARCHAR(6)"`
CityId string `xorm:"default 'NULL' comment('地市编码') VARCHAR(6)"`
AreaId string `xorm:"default 'NULL' comment('县区编码') VARCHAR(6)"`
AreaId2 string `xorm:"default 'NULL' VARCHAR(6)"`
AreaId3 string `xorm:"default 'NULL' VARCHAR(6)"`
LinksystemId string `xorm:"default 'NULL' comment('源业务系统') VARCHAR(36)"`
LinkId string `xorm:"default 'NULL' comment('业务系统机构原ID') VARCHAR(36)"`
ChangeTime time.Time `xorm:"default 'NULL' comment('最近修改时间') DATETIME"`

@ -3,4 +3,5 @@ package models
type TDwTable struct {
TableId int32 `xorm:"not null pk autoincr INT(255)"`
TableName string `xorm:"not null VARCHAR(255)"`
BUse int32 `xorm:"not null default 1 INT(255)"`
}

@ -9,5 +9,5 @@ type TDwTableField struct {
DecimalPointLength int32 `xorm:"not null default 0 comment('小数点后长度') INT(11)"`
Comment string `xorm:"default 'NULL' comment('描述') VARCHAR(255)"`
IsPk int32 `xorm:"not null default 0 comment('是否为主键') INT(255)"`
IsNull int32 `xorm:"not null comment('是否可为空') INT(255)"`
SortId int32 `xorm:"not null default 1 comment('排序号') INT(11)"`
}

@ -8,7 +8,7 @@ type TReportSqlquery struct {
Id string `xorm:"not null pk comment('查询ID') VARCHAR(36)"`
QueryName string `xorm:"not null comment('查询名称') VARCHAR(50)"`
QueryCode string `xorm:"not null comment('查询编码') VARCHAR(50)"`
QuerySql string `xorm:"not null comment('查询SQL') VARCHAR(4000)"`
QuerySql string `xorm:"not null comment('查询SQL') VARCHAR(6000)"`
JoinItem string `xorm:"default 'NULL' comment('关联查询字段名称') VARCHAR(255)"`
SystemId string `xorm:"not null comment('接入系统ID') index VARCHAR(36)"`
DatasourceId string `xorm:"not null comment('数据源ID') index VARCHAR(36)"`

Loading…
Cancel
Save