|
|
package BaseStudentService
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"dsBaseRpc/Const"
|
|
|
"dsBaseRpc/Const/ErrorConst"
|
|
|
"dsBaseRpc/RpcService/BaseOrganization/BaseOrganizationDao"
|
|
|
"dsBaseRpc/RpcService/BaseParent/BaseParentDao"
|
|
|
"dsBaseRpc/RpcService/BaseStudent/BaseStudentDao"
|
|
|
"dsBaseRpc/RpcService/BaseStudent/BaseStudentProto"
|
|
|
"dsBaseRpc/RpcService/SysLoginperson/SysLoginpersonDao"
|
|
|
"dsBaseRpc/RpcService/SysLoginperson/SysLoginpersonService"
|
|
|
"dsBaseRpc/Utils/CommonUtil"
|
|
|
"dsBaseRpc/Utils/DateUtil"
|
|
|
"dsBaseRpc/Utils/ExcelUtil"
|
|
|
"dsBaseRpc/Utils/IdCardUtil"
|
|
|
"dsBaseRpc/Utils/LogUtil"
|
|
|
"dsBaseRpc/Utils/PinYinUtil"
|
|
|
"dsBaseRpc/Utils/SqlKit"
|
|
|
"dsBaseRpc/models"
|
|
|
"github.com/pkg/errors"
|
|
|
)
|
|
|
|
|
|
type Rpc struct{} //服务对象
|
|
|
//选择单条
|
|
|
func (s *Rpc) GetBaseStudent(ctx context.Context, in *BaseStudentProto.ModelArg) (*BaseStudentProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseStudentProto.Reply
|
|
|
//通用获取单条
|
|
|
list := SqlKit.QueryListMapByIds([]string{in.PersonId}, "t_base_student")
|
|
|
//将结果序列化
|
|
|
reply.Success = true
|
|
|
reply.Count = 1
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
reply.List = CommonUtil.SerializeToString(list)
|
|
|
return &reply, nil
|
|
|
}
|
|
|
|
|
|
//增加
|
|
|
func (s *Rpc) AddBaseStudent(ctx context.Context, in *BaseStudentProto.ModelArg) (*BaseStudentProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseStudentProto.Reply
|
|
|
//==========================================
|
|
|
//检查身份证的有效性
|
|
|
IdCardNo := []byte(in.Sfzjh)
|
|
|
if in.Sfzjlxm == "01" && !IdCardUtil.IsValidIdCardNo(&IdCardNo) {
|
|
|
reply.Success = false
|
|
|
reply.Message = "身份证号在不符合检查要求!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
//是不是重复
|
|
|
if !SysLoginpersonDao.IsValidIdCardNo(in.Sfzjh, "") {
|
|
|
reply.Success = false
|
|
|
reply.Message = "唯一身份标识在系统中已存在,无法创建!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
//==========================================
|
|
|
//调用dao
|
|
|
model := new(models.TBaseStudent)
|
|
|
//学生ID
|
|
|
model.PersonId = CommonUtil.GetUUID()
|
|
|
//学生姓名
|
|
|
model.Xm = in.Xm
|
|
|
//姓名拼音
|
|
|
model.Xmpy = PinYinUtil.PinYin(in.Xm)
|
|
|
//曾用名
|
|
|
model.Cym = in.Cym
|
|
|
|
|
|
//身份证件号
|
|
|
model.Sfzjh = in.Sfzjh
|
|
|
model.Sfzjlxm = in.Sfzjlxm
|
|
|
//如果是身份证
|
|
|
if model.Sfzjlxm == "1" {
|
|
|
//根据身份证号,提取男女,出生日期
|
|
|
_, birthday, xbm := IdCardUtil.GetIdCardNoInfo(in.Sfzjh)
|
|
|
model.Csrq = DateUtil.ConvertDateTime(birthday)
|
|
|
model.Xbm = xbm
|
|
|
} else {
|
|
|
//如果不是身份证号,那就用个默认值吧
|
|
|
model.Csrq = DateUtil.ConvertDateTime("1977-10-11 00:00:00")
|
|
|
model.Xbm = "1"
|
|
|
}
|
|
|
//民族 (有字典)
|
|
|
model.Mzm = in.Mzm
|
|
|
//政治面貌 (有字典)
|
|
|
model.Zzmmm = in.Zzmmm
|
|
|
//独生子女标志 0:不是 1:是
|
|
|
model.Dszybz = in.Dszybz
|
|
|
//随迁子女标志 0:不是 1:是
|
|
|
model.Sqznbz = in.Sqznbz
|
|
|
//进城务工人员随迁子女标志 0:不是 1:是
|
|
|
model.Jcwgrysqznbz = in.Jcwgrysqznbz
|
|
|
//孤儿标志 0:不是 1:是
|
|
|
model.Gebz = in.Gebz
|
|
|
//留守儿童标志 0:不是 1:是
|
|
|
model.Lsetbz = in.Lsetbz
|
|
|
//残疾标志 0:不是 1:是
|
|
|
model.Cjbz = in.Cjbz
|
|
|
//班级ID
|
|
|
model.ClassId = in.ClassId
|
|
|
//是否启用 0:未启用 1:启用
|
|
|
model.BUse = 1
|
|
|
//状态码
|
|
|
model.StateId = 1
|
|
|
list := SqlKit.QueryListMapByIds([]string{in.ClassId}, "t_base_class")
|
|
|
if list == nil || len(list) == 0 {
|
|
|
reply.Success = false
|
|
|
reply.Message = "没有找到对应的班级!"
|
|
|
return &reply, errors.New("传入的班级ID有误!")
|
|
|
}
|
|
|
//单位ID
|
|
|
BureauId := list[0]["bureau_id"].(string)
|
|
|
//省市县区
|
|
|
var err error
|
|
|
_, model.ProvinceCode, model.CityCode, model.DistrictCode, model.MainSchoolId, err = BaseOrganizationDao.GetBureauAdministrativeDivision(BureauId)
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = err.Error()
|
|
|
return &reply, err
|
|
|
}
|
|
|
//学校ID
|
|
|
model.BureauId = BureauId
|
|
|
//添加学生
|
|
|
_, err = BaseStudentDao.AddBaseStudent(*model)
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行AddBaseStudent时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
//为学生创建帐号
|
|
|
_, err = SysLoginpersonService.AddLoginperson(3, model.PersonId, model.Xm)
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行AddLoginperson时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
//为学生创建对应的家长
|
|
|
modelParent := new(models.TBaseParent)
|
|
|
modelParent.PersonId = CommonUtil.GetUUID()
|
|
|
modelParent.Xm = model.Xm + "家长"
|
|
|
modelParent.Lxdh = "-1"
|
|
|
modelParent.StudentId = model.PersonId
|
|
|
modelParent.ClassId = model.ClassId
|
|
|
modelParent.BureauId = model.BureauId
|
|
|
modelParent.ProvinceCode = model.ProvinceCode
|
|
|
modelParent.CityCode = model.CityCode
|
|
|
modelParent.DistrictCode = model.DistrictCode
|
|
|
modelParent.MainSchoolId = model.MainSchoolId
|
|
|
modelParent.BUse = 1
|
|
|
_, err = BaseParentDao.AddBaseParent(*modelParent)
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行AddBaseParent时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
//记录日志
|
|
|
BaseParentDao.ActionLog([]models.TBaseParent{*modelParent}, Const.ActionInsert, in.ActionPersonId, in.ActionIpAddress)
|
|
|
|
|
|
//为家长创建帐号
|
|
|
_, err = SysLoginpersonService.AddLoginperson(4, modelParent.PersonId, modelParent.Xm)
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行AddLoginperson时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
//记录日志
|
|
|
BaseStudentDao.ActionLog([]models.TBaseStudent{*model}, Const.ActionInsert, in.ActionPersonId, in.ActionIpAddress)
|
|
|
|
|
|
reply.Success = true
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
return &reply, err
|
|
|
}
|
|
|
|
|
|
//删除
|
|
|
func (s *Rpc) DeleteBaseStudent(ctx context.Context, in *BaseStudentProto.DeleteIdsArg) (*BaseStudentProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseStudentProto.Reply
|
|
|
//调用通用删除命令进行删除
|
|
|
err := SqlKit.DeleteIds("t_base_student", in.Ids)
|
|
|
//错误处理
|
|
|
if err != nil {
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行DeleteBaseStudent时发生严重错误:"+err.Error())
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
return &reply, err
|
|
|
}
|
|
|
//记录日志
|
|
|
ms, err := BaseStudentDao.GetByIds(in.Ids)
|
|
|
if err != nil {
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行FindModelsByIds时发生严重错误:"+err.Error())
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
return &reply, err
|
|
|
}
|
|
|
BaseStudentDao.ActionLog(ms, Const.ActionDelete, in.ActionPersonId, in.ActionIpAddress)
|
|
|
|
|
|
//根据学生IDS--->家长IDS
|
|
|
parentIds, err := BaseStudentDao.GetParentIds(in.Ids)
|
|
|
if err != nil {
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行GetParentIds时发生严重错误:"+err.Error())
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
return &reply, err
|
|
|
}
|
|
|
//删除对应的家长
|
|
|
SqlKit.DeleteIds("t_base_parent", parentIds)
|
|
|
//记录家长表的数据变更
|
|
|
ms2, err := BaseParentDao.GetByIds(parentIds)
|
|
|
if err != nil {
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行FindModelsByIds时发生严重错误:"+err.Error())
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
return &reply, err
|
|
|
}
|
|
|
BaseParentDao.ActionLog(ms2, Const.ActionDelete, in.ActionPersonId, in.ActionIpAddress)
|
|
|
|
|
|
reply.Success = true
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
return &reply, err
|
|
|
}
|
|
|
|
|
|
//修改
|
|
|
func (s *Rpc) UpdateBaseStudent(ctx context.Context, in *BaseStudentProto.ModelArg) (*BaseStudentProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseStudentProto.Reply
|
|
|
|
|
|
//==========================================
|
|
|
//检查身份证的有效性
|
|
|
IdCardNo := []byte(in.Sfzjh)
|
|
|
if in.Sfzjlxm == "01" && !IdCardUtil.IsValidIdCardNo(&IdCardNo) {
|
|
|
reply.Success = false
|
|
|
reply.Message = "身份证号在不符合检查要求!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
//是不是重复
|
|
|
if !SysLoginpersonDao.IsValidIdCardNo(in.Sfzjh, in.PersonId) {
|
|
|
reply.Success = false
|
|
|
reply.Message = "唯一身份标识在系统中已存在,无法创建!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
//==========================================
|
|
|
model := new(models.TBaseStudent)
|
|
|
//身份证件号
|
|
|
model.Sfzjh = in.Sfzjh
|
|
|
model.Sfzjlxm = in.Sfzjlxm
|
|
|
//如果是身份证
|
|
|
if model.Sfzjlxm == "1" {
|
|
|
//根据身份证号,提取男女,出生日期
|
|
|
_, birthday, xbm := IdCardUtil.GetIdCardNoInfo(in.Sfzjh)
|
|
|
model.Csrq = DateUtil.ConvertDateTime(birthday)
|
|
|
model.Xbm = xbm
|
|
|
} else {
|
|
|
//如果不是身份证号,那就用个默认值吧
|
|
|
model.Csrq = DateUtil.ConvertDateTime("1977-10-11 00:00:00")
|
|
|
model.Xbm = "1"
|
|
|
}
|
|
|
model.PersonId = in.PersonId
|
|
|
//学生姓名
|
|
|
model.Xm = in.Xm
|
|
|
//姓名拼音
|
|
|
model.Xmpy = PinYinUtil.PinYin(in.Xm)
|
|
|
//曾用名
|
|
|
model.Cym = in.Cym
|
|
|
//民族 (有字典)
|
|
|
model.Mzm = in.Mzm
|
|
|
//政治面貌 (有字典)
|
|
|
model.Zzmmm = in.Zzmmm
|
|
|
//独生子女标志 0:不是 1:是
|
|
|
model.Dszybz = in.Dszybz
|
|
|
//随迁子女标志 0:不是 1:是
|
|
|
model.Sqznbz = in.Sqznbz
|
|
|
//进城务工人员随迁子女标志 0:不是 1:是
|
|
|
model.Jcwgrysqznbz = in.Jcwgrysqznbz
|
|
|
//孤儿标志 0:不是 1:是
|
|
|
model.Gebz = in.Gebz
|
|
|
//留守儿童标志 0:不是 1:是
|
|
|
model.Lsetbz = in.Lsetbz
|
|
|
//残疾标志 0:不是 1:是
|
|
|
model.Cjbz = in.Cjbz
|
|
|
//查找此学生所在的班级
|
|
|
list := SqlKit.QueryListMapByIds([]string{in.PersonId}, "t_base_student")
|
|
|
if list == nil || len(list) == 0 {
|
|
|
reply.Success = false
|
|
|
reply.Message = "没有找到对应的学生!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
//班级ID
|
|
|
model.ClassId = list[0]["class_id"].(string)
|
|
|
//所在单位ID
|
|
|
BureauId := list[0]["bureau_id"].(string)
|
|
|
//是否启用 0:未启用 1:启用
|
|
|
model.BUse = 1
|
|
|
//状态码
|
|
|
model.StateId = 1
|
|
|
//省市县区+主校ID
|
|
|
var err error
|
|
|
_, model.ProvinceCode, model.CityCode, model.DistrictCode, model.MainSchoolId, err = BaseOrganizationDao.GetBureauAdministrativeDivision(BureauId)
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = err.Error()
|
|
|
return &reply, err
|
|
|
}
|
|
|
//学校ID
|
|
|
model.BureauId = list[0]["bureau_id"].(string)
|
|
|
_, err = BaseStudentDao.UpdateBaseStudent(*model, in.ForceUpdateFields)
|
|
|
//错误处理
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行UpdateBaseStudent时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
//记录日志
|
|
|
ms, err := BaseStudentDao.GetByIds([]string{in.PersonId})
|
|
|
if err != nil {
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行FindModelsByIds时发生严重错误:"+err.Error())
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
return &reply, err
|
|
|
}
|
|
|
BaseStudentDao.ActionLog(ms, Const.ActionUpdate, in.ActionPersonId, in.ActionIpAddress)
|
|
|
|
|
|
reply.Success = true
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
return &reply, nil
|
|
|
}
|
|
|
|
|
|
//分页查询
|
|
|
func (s *Rpc) PageBaseStudent(ctx context.Context, in *BaseStudentProto.QueryArg) (*BaseStudentProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseStudentProto.Reply
|
|
|
list, count, err := BaseStudentDao.PageBaseStudent(in)
|
|
|
//错误处理
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlQueryError, "执行PageBaseStudent时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
reply.Count = count
|
|
|
reply.Success = true
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
reply.List = CommonUtil.SerializeToString(list)
|
|
|
return &reply, nil
|
|
|
}
|
|
|
|
|
|
//学生调整班级
|
|
|
func (s *Rpc) ReviseStudentClass(ctx context.Context, in *BaseStudentProto.ReviseArg) (*BaseStudentProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseStudentProto.Reply
|
|
|
//调用dao
|
|
|
err := BaseStudentDao.ReviseTeacherOrg(in.Ids, in.ClassId)
|
|
|
//错误处理
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlQueryError, "执行ReviseTeacherOrg时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
reply.Count = int32(len(in.Ids))
|
|
|
reply.Success = true
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
return &reply, nil
|
|
|
}
|
|
|
|
|
|
//导出本校学生账号信息到EXCEL
|
|
|
func (s *Rpc) ExportStudentAccountInfoExcel(ctx context.Context, in *BaseStudentProto.ModelArg) (*BaseStudentProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseStudentProto.Reply
|
|
|
list, _, err := BaseStudentDao.ExportStudentAccountInfoExcel(in)
|
|
|
//错误处理
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlQueryError, "执行ExportStudentAccountInfoExcel时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
//1、配置文件
|
|
|
jsonTemplate := "student_account.json"
|
|
|
//2、导出
|
|
|
TargetPath := CommonUtil.GetExportExcelFilePath()
|
|
|
ExcelUtil.ExportExcel(jsonTemplate, list, TargetPath)
|
|
|
reply.ExcelPath = TargetPath
|
|
|
return &reply, nil
|
|
|
}
|
|
|
|
|
|
//导出本校学生信息到EXCEL
|
|
|
func (s *Rpc) ExportStudentInfoExcel(ctx context.Context, in *BaseStudentProto.ModelArg) (*BaseStudentProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseStudentProto.Reply
|
|
|
TargetPath := CommonUtil.GetExportExcelFilePath()
|
|
|
//哪个单位
|
|
|
bureauId := in.BureauId
|
|
|
//是不是需要导出空的excel
|
|
|
ExportExcelStatus := in.ExportExcelStatus
|
|
|
|
|
|
//目前只处理一个班级或全校的情况
|
|
|
var classIds = make([]string, 0)
|
|
|
if len(in.ClassId) > 0 {
|
|
|
classIds = append(classIds, in.ClassId)
|
|
|
}
|
|
|
BaseStudentDao.ExportStudentInfoExcel(TargetPath, bureauId, ExportExcelStatus, classIds)
|
|
|
reply.ExcelPath = TargetPath
|
|
|
return &reply, nil
|
|
|
}
|
|
|
|
|
|
//导入本校学生信息
|
|
|
func (s *Rpc) ImportStudentInfoExcel(ctx context.Context, in *BaseStudentProto.ImportArg) (*BaseStudentProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseStudentProto.Reply
|
|
|
//将业务逻辑封装到dao层
|
|
|
success, message, err := BaseStudentDao.ImportStudentInfoExcel(in.ExcelPath, in.BureauId, in.ActionPersonId, in.ActionIpAddress)
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
return &reply, nil
|
|
|
}
|
|
|
if !success {
|
|
|
reply.Success = false
|
|
|
return &reply, nil
|
|
|
} else {
|
|
|
reply.Success = true
|
|
|
reply.Message = message
|
|
|
return &reply, nil
|
|
|
}
|
|
|
}
|