|
|
package GovAreaService
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"dsBaseRpc/Const"
|
|
|
"dsBaseRpc/Const/ErrorConst"
|
|
|
"dsBaseRpc/RpcService/GovArea/GovAreaDao"
|
|
|
"dsBaseRpc/RpcService/GovArea/GovAreaProto"
|
|
|
"dsBaseRpc/Utils/CommonUtil"
|
|
|
"dsBaseRpc/Utils/LogUtil"
|
|
|
"dsBaseRpc/Utils/SqlKit"
|
|
|
"dsBaseRpc/models"
|
|
|
)
|
|
|
|
|
|
type Rpc struct{} //服务对象
|
|
|
|
|
|
//选择单条
|
|
|
func (s *Rpc) GetGovArea(ctx context.Context, in *GovAreaProto.ModelArg) (*GovAreaProto.Reply, error) {
|
|
|
//统一返回的结构体
|
|
|
var reply GovAreaProto.Reply
|
|
|
//参数检查
|
|
|
if len(in.AreaCode) != 6 {
|
|
|
reply.Success = false
|
|
|
reply.Message = "请传入6位的地区码进行查询!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
//通用获取单条
|
|
|
list := SqlKit.QueryByIds([]string{in.AreaCode}, "t_gov_area")
|
|
|
//将结果序列化
|
|
|
reply.Success = true
|
|
|
reply.Count = 1
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
reply.List = CommonUtil.SerializeToString(list)
|
|
|
return &reply, nil
|
|
|
}
|
|
|
|
|
|
//增加
|
|
|
func (s *Rpc) AddGovArea(ctx context.Context, in *GovAreaProto.ModelArg) (*GovAreaProto.Reply, error) {
|
|
|
var reply GovAreaProto.Reply
|
|
|
//1、判断区域码是不是已存在
|
|
|
exist, err := GovAreaDao.ExistAreaCode(in.AreaCode)
|
|
|
if err != nil {
|
|
|
//记录到错误日志
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行AddGovArea时发生严重错误:"+err.Error())
|
|
|
reply.Success = false
|
|
|
reply.Message = "增加失败,请检查原因!"
|
|
|
return &reply, err
|
|
|
}
|
|
|
if exist {
|
|
|
reply.Success = false
|
|
|
reply.Message = "输入的区域代码已存在,不能创建!"
|
|
|
return &reply, err
|
|
|
}
|
|
|
//2、检查非空
|
|
|
if len(in.AreaCode) == 0 {
|
|
|
reply.Success = false
|
|
|
reply.Message = "区域代码为空,不能创建!"
|
|
|
return &reply, err
|
|
|
}
|
|
|
if len(in.AreaName) == 0 {
|
|
|
reply.Success = false
|
|
|
reply.Message = "区域名称为空,不能创建!"
|
|
|
return &reply, err
|
|
|
}
|
|
|
var model models.TGovArea
|
|
|
model.AreaCode = in.AreaCode
|
|
|
model.AreaLevelId = in.AreaLevelId
|
|
|
model.AreaName = in.AreaName
|
|
|
model.AreaTypeId = in.AreaTypeId
|
|
|
//调用dao
|
|
|
_, err = GovAreaDao.AddGovArea(model)
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行AddGovArea时发生严重错误:"+err.Error())
|
|
|
} else {
|
|
|
reply.Success = true
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
}
|
|
|
return &reply, err
|
|
|
}
|
|
|
|
|
|
//删除
|
|
|
func (s *Rpc) DeleteGovArea(ctx context.Context, in *GovAreaProto.DeleteIdsArg) (*GovAreaProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply GovAreaProto.Reply
|
|
|
//调用通用删除命令进行删除
|
|
|
err := SqlKit.DeleteIds("t_gov_area", in.Ids)
|
|
|
//错误处理
|
|
|
if err != nil {
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行DeleteGovArea时发生严重错误:"+err.Error())
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
return &reply, err
|
|
|
}
|
|
|
reply.Success = true
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
return &reply, err
|
|
|
}
|
|
|
|
|
|
//修改
|
|
|
func (s *Rpc) UpdateGovArea(ctx context.Context, in *GovAreaProto.ModelArg) (*GovAreaProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply GovAreaProto.Reply
|
|
|
var err error
|
|
|
var model models.TGovArea
|
|
|
//1、修改
|
|
|
model.AreaCode = in.AreaCode
|
|
|
model.AreaLevelId = in.AreaLevelId
|
|
|
model.AreaName = in.AreaName
|
|
|
model.AreaTypeId = in.AreaTypeId
|
|
|
|
|
|
_, err = GovAreaDao.UpdateGovArea(model)
|
|
|
if err != nil {
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行UpdateGovArea时发生严重错误:"+err.Error())
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
return &reply, err
|
|
|
}
|
|
|
reply.Success = true
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
return &reply, err
|
|
|
}
|
|
|
|
|
|
//分页查询
|
|
|
func (s *Rpc) PageGovArea(ctx context.Context, in *GovAreaProto.QueryArg) (*GovAreaProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply GovAreaProto.Reply
|
|
|
//参数检查
|
|
|
if len(in.AreaCode) != 6 {
|
|
|
reply.Success = false
|
|
|
reply.Message = "请传入6位的地区码进行查询!"
|
|
|
reply.List = Const.BlankArrayString
|
|
|
return &reply, nil
|
|
|
}
|
|
|
_, _, count, list, err := GovAreaDao.PageGovArea(in)
|
|
|
//错误处理
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = "查询失败,请检查原因!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
//将结果序列化
|
|
|
reply.Success = true
|
|
|
reply.Message = "获取成功"
|
|
|
reply.Count = count
|
|
|
reply.List = CommonUtil.SerializeToString(list)
|
|
|
return &reply, nil
|
|
|
}
|