|
|
package BaseTeacherService
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"dsBaseRpc/Const"
|
|
|
"dsBaseRpc/Const/ErrorConst"
|
|
|
"dsBaseRpc/RpcService/BaseOrganization/BaseOrganizationDao"
|
|
|
"dsBaseRpc/RpcService/BaseOrganizationManager/BaseOrganizationManagerDao"
|
|
|
"dsBaseRpc/RpcService/BaseTeacher/BaseTeacherDao"
|
|
|
"dsBaseRpc/RpcService/BaseTeacher/BaseTeacherProto"
|
|
|
"dsBaseRpc/RpcService/SysLoginperson/SysLoginpersonDao"
|
|
|
"dsBaseRpc/RpcService/SysLoginperson/SysLoginpersonService"
|
|
|
"dsBaseRpc/Utils/CommonUtil"
|
|
|
"dsBaseRpc/Utils/DateUtil"
|
|
|
"dsBaseRpc/Utils/EmailUtil"
|
|
|
"dsBaseRpc/Utils/ExcelUtil"
|
|
|
"dsBaseRpc/Utils/IdCardUtil"
|
|
|
"dsBaseRpc/Utils/LogUtil"
|
|
|
"dsBaseRpc/Utils/MobileUtil"
|
|
|
"dsBaseRpc/Utils/PinYinUtil"
|
|
|
"dsBaseRpc/Utils/SqlKit"
|
|
|
"dsBaseRpc/models"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
type Rpc struct{} //服务对象
|
|
|
|
|
|
//选择单条
|
|
|
func (s *Rpc) GetBaseTeacher(ctx context.Context, in *BaseTeacherProto.ModelArg) (*BaseTeacherProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseTeacherProto.Reply
|
|
|
//通用获取单条
|
|
|
list := SqlKit.QueryByIds([]string{in.PersonId}, "t_base_teacher")
|
|
|
|
|
|
//将结果序列化
|
|
|
reply.Success = true
|
|
|
reply.Count = 1
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
reply.List = CommonUtil.SerializeToString(list)
|
|
|
return &reply, nil
|
|
|
}
|
|
|
|
|
|
//增加
|
|
|
func (s *Rpc) AddBaseTeacher(ctx context.Context, in *BaseTeacherProto.ModelArg) (*BaseTeacherProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseTeacherProto.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
|
|
|
}
|
|
|
//==========================================
|
|
|
//如果是手机号,是不是合法
|
|
|
if len(in.Lxdh) > 0 && len(in.Lxdh) == 11 && !MobileUtil.VerifyMobileFormat(in.Lxdh) {
|
|
|
reply.Success = false
|
|
|
reply.Message = "联系电话在不是合法的手机号!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
//是不是重复
|
|
|
if len(in.Lxdh) > 0 && !SysLoginpersonDao.IsValidIdTel(in.Lxdh, "") {
|
|
|
reply.Success = false
|
|
|
reply.Message = "联系电话在系统中已存在,无法创建!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
//==========================================
|
|
|
//如果是电子信箱,是不是合法
|
|
|
if len(in.Dzxx) > 0 && !EmailUtil.VerifyEmailFormat(in.Dzxx) {
|
|
|
reply.Success = false
|
|
|
reply.Message = "电子信箱格式不合法!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
//是不是重复
|
|
|
if len(in.Dzxx) > 0 && !SysLoginpersonDao.IsValidIdEmail(in.Dzxx, "") {
|
|
|
reply.Success = false
|
|
|
reply.Message = "电子信箱已存在,无法创建!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
//==========================================
|
|
|
//调用dao
|
|
|
model := new(models.TBaseTeacher)
|
|
|
model.PersonId = CommonUtil.GetUUID()
|
|
|
model.Xm = in.Xm
|
|
|
model.Xmpy = PinYinUtil.PinYin(in.Xm)
|
|
|
model.Cym = in.Cym
|
|
|
model.Sfzjlxm = in.Sfzjlxm
|
|
|
model.Sfzjh = in.Sfzjh
|
|
|
if model.Sfzjlxm == "1" {
|
|
|
//如果是身份证
|
|
|
by := []byte(in.Sfzjh)
|
|
|
if !IdCardUtil.IsValidIdCardNo(&by) {
|
|
|
reply.Success = false
|
|
|
reply.Message = "身份证号不合法!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
//根据身份证号,提取男女,出生日期
|
|
|
_, birthday, xbm := IdCardUtil.GetIdCardNoInfo(in.Sfzjh)
|
|
|
model.Csrq = DateUtil.ConvertDateTime(birthday)
|
|
|
//如果身份证与传入的性别代码不符
|
|
|
if xbm != in.Xbm {
|
|
|
reply.Success = false
|
|
|
reply.Message = "性别代码与身份证中获取的不一致!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
model.Xbm = xbm
|
|
|
} else {
|
|
|
//如果不是身份证号,那就用个默认值吧
|
|
|
model.Csrq = DateUtil.ConvertDateTime("1977-10-11 00:00:00")
|
|
|
model.Xbm = in.Xbm
|
|
|
}
|
|
|
model.Mzm = in.Mzm
|
|
|
model.Zzmmm = in.Zzmmm
|
|
|
model.Xlm = in.Xlm
|
|
|
model.Xwm = in.Xwm
|
|
|
model.Zcm = in.Zcm
|
|
|
model.StateId = 1
|
|
|
model.Bzlbm = in.Bzlbm
|
|
|
if len(in.Cjny) == 0 {
|
|
|
model.Cjny = DateUtil.ConvertDateTime("1900-01-01 00:00:00")
|
|
|
} else {
|
|
|
//如果只传了年和月,手工补上日和时间
|
|
|
if len(in.Cjny) == 7 {
|
|
|
in.Cjny = in.Cjny + "-01 00:00:00"
|
|
|
model.Cjny = DateUtil.ConvertDateTime(in.Cjny)
|
|
|
} else {
|
|
|
st, err := time.Parse(DateUtil.TimeLayoutStr, in.Cjny) //string转time
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = "传入的从教年月格式不正确!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
model.Cjny = st
|
|
|
}
|
|
|
}
|
|
|
model.StageId = in.StageId
|
|
|
model.SubjectId = in.SubjectId
|
|
|
model.Gwzym = in.Gwzym
|
|
|
model.Lxdh = in.Lxdh
|
|
|
model.Dzxx = in.Dzxx
|
|
|
model.BUse = 1
|
|
|
//教师的身份ID
|
|
|
model.IdentityId = 2
|
|
|
//排序号
|
|
|
model.SortId = int32(BaseTeacherDao.GetMaxSortId(in.OrgId)) + 1
|
|
|
//主单位与主部门
|
|
|
list := SqlKit.QueryByIds([]string{in.OrgId}, "t_base_organization")
|
|
|
if list == nil || len(list) == 0 {
|
|
|
reply.Success = false
|
|
|
reply.Message = "没有找到指定的组织机构ID!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
BureauId := list[0]["bureau_id"].(string)
|
|
|
//主校ID
|
|
|
model.BureauId = BureauId
|
|
|
model.OrgId = in.OrgId
|
|
|
//所属省市县
|
|
|
var err error
|
|
|
_, model.ProvinceCode, model.CityCode, model.DistrictCode, model.MainSchoolId, err = BaseOrganizationDao.GetBureauAdministrativeDivision(model.BureauId)
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = err.Error()
|
|
|
return &reply, err
|
|
|
}
|
|
|
//调用DAO保存
|
|
|
_, err = BaseTeacherDao.AddBaseTeacher(*model)
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行AddBaseTeacher时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
// 生成教师帐号
|
|
|
_, err = SysLoginpersonService.AddLoginperson(2, model.PersonId, model.Xm)
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行AddLoginperson时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
//记录日志
|
|
|
BaseTeacherDao.ActionLog([]models.TBaseTeacher{*model}, Const.ActionInsert, in.ActionPersonId, in.ActionIpAddress)
|
|
|
|
|
|
reply.Success = true
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
return &reply, err
|
|
|
}
|
|
|
|
|
|
//删除
|
|
|
func (s *Rpc) DeleteBaseTeacher(ctx context.Context, in *BaseTeacherProto.DeleteIdsArg) (*BaseTeacherProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseTeacherProto.Reply
|
|
|
//调用通用删除命令进行删除
|
|
|
err := SqlKit.DeleteIds("t_base_teacher", in.Ids)
|
|
|
//删除人员对应的部门领导关系,不管有没有,都要删除一下。
|
|
|
BaseOrganizationManagerDao.DeleteOrgManagerByPersonIds(in.Ids)
|
|
|
//错误处理
|
|
|
if err != nil {
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行DeleteBaseTeacher时发生严重错误:"+err.Error())
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
return &reply, err
|
|
|
}
|
|
|
//记录日志
|
|
|
ms, err := BaseTeacherDao.GetByIds(in.Ids)
|
|
|
if err != nil {
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行FindModelsByIds时发生严重错误:"+err.Error())
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
return &reply, err
|
|
|
}
|
|
|
BaseTeacherDao.ActionLog(ms, Const.ActionDelete, in.ActionPersonId, in.ActionIpAddress)
|
|
|
|
|
|
reply.Success = true
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
return &reply, err
|
|
|
}
|
|
|
|
|
|
//修改
|
|
|
func (s *Rpc) UpdateBaseTeacher(ctx context.Context, in *BaseTeacherProto.ModelArg) (*BaseTeacherProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseTeacherProto.Reply
|
|
|
|
|
|
//检查身份证的有效性
|
|
|
IdCardNo := []byte(in.Sfzjh)
|
|
|
if in.Sfzjlxm == "1" && !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
|
|
|
}
|
|
|
|
|
|
//如果是手机号,是不是合法
|
|
|
if len(in.Lxdh) > 0 && len(in.Lxdh) == 11 && !MobileUtil.VerifyMobileFormat(in.Lxdh) {
|
|
|
reply.Success = false
|
|
|
reply.Message = "联系电话在不是合法的手机号!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
//是不是重复
|
|
|
if len(in.Lxdh) > 0 && !SysLoginpersonDao.IsValidIdTel(in.Lxdh, in.PersonId) {
|
|
|
reply.Success = false
|
|
|
reply.Message = "联系电话在系统中已存在,无法创建!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
|
|
|
if len(in.Dzxx) > 0 && !EmailUtil.VerifyEmailFormat(in.Dzxx) {
|
|
|
reply.Success = false
|
|
|
reply.Message = "电子信箱格式不合法!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
//是不是重复
|
|
|
if len(in.Dzxx) > 0 && !SysLoginpersonDao.IsValidIdEmail(in.Dzxx, in.PersonId) {
|
|
|
reply.Success = false
|
|
|
reply.Message = "电子信箱已存在,无法创建!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
|
|
|
//3、修改
|
|
|
model := new(models.TBaseTeacher)
|
|
|
model.PersonId = in.PersonId
|
|
|
model.Xm = in.Xm
|
|
|
model.Xmpy = PinYinUtil.PinYin(in.Xmpy)
|
|
|
model.Cym = in.Cym
|
|
|
//身份证件类型码
|
|
|
model.Sfzjlxm = in.Sfzjlxm
|
|
|
model.Sfzjh = in.Sfzjh
|
|
|
//如果是身份证
|
|
|
if model.Sfzjlxm == "1" {
|
|
|
//根据身份证号,提取男女,出生日期
|
|
|
_, birthday, xbm := IdCardUtil.GetIdCardNoInfo(in.Sfzjh)
|
|
|
model.Csrq = DateUtil.ConvertDateTime(birthday)
|
|
|
//如果身份证与传入的性别代码不符
|
|
|
if xbm != in.Xbm {
|
|
|
reply.Success = false
|
|
|
reply.Message = "性别代码与身份证中获取的不一致!"
|
|
|
return &reply, nil
|
|
|
}
|
|
|
model.Xbm = xbm
|
|
|
} else {
|
|
|
//如果不是身份证号,那就用个默认值吧
|
|
|
model.Csrq = DateUtil.ConvertDateTime("1977-10-11 00:00:00")
|
|
|
model.Xbm = in.Xbm
|
|
|
}
|
|
|
model.Mzm = in.Mzm
|
|
|
model.Zzmmm = in.Zzmmm
|
|
|
model.Xlm = in.Xlm
|
|
|
model.Xwm = in.Xwm
|
|
|
model.Zcm = in.Zcm
|
|
|
model.Bzlbm = in.Bzlbm
|
|
|
|
|
|
if len(in.Cjny) == 0 {
|
|
|
model.Cjny = DateUtil.ConvertDateTime("1900-01-01 00:00:00")
|
|
|
} else {
|
|
|
model.Cjny = DateUtil.ConvertDateTime(in.Cjny)
|
|
|
}
|
|
|
|
|
|
model.StageId = in.StageId
|
|
|
model.SubjectId = in.SubjectId
|
|
|
model.Gwzym = in.Gwzym
|
|
|
model.Lxdh = in.Lxdh
|
|
|
model.Dzxx = in.Dzxx
|
|
|
model.BUse = 1
|
|
|
_, err := BaseTeacherDao.UpdateBaseTeacher(*model, in.ForceUpdateFields)
|
|
|
//错误处理
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行UpdateBaseTeacher时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
//记录日志
|
|
|
ms, err := BaseTeacherDao.GetByIds([]string{in.PersonId})
|
|
|
if err != nil {
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行FindModelsByIds时发生严重错误:"+err.Error())
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
return &reply, err
|
|
|
}
|
|
|
BaseTeacherDao.ActionLog(ms, Const.ActionInsert, in.ActionPersonId, in.ActionIpAddress)
|
|
|
|
|
|
reply.Success = true
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
return &reply, nil
|
|
|
}
|
|
|
|
|
|
//分页查询
|
|
|
func (s *Rpc) PageBaseTeacher(ctx context.Context, in *BaseTeacherProto.QueryArg) (*BaseTeacherProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseTeacherProto.Reply
|
|
|
list, count, err := BaseTeacherDao.PageBaseTeacher(in)
|
|
|
//错误处理
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlQueryError, "执行PageBaseTeacher时发生严重错误:"+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) ReviseTeacherOrg(ctx context.Context, in *BaseTeacherProto.ReviseArg) (*BaseTeacherProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseTeacherProto.Reply
|
|
|
//调用dao
|
|
|
err := BaseTeacherDao.ReviseTeacherOrg(in.Ids, in.OrgId)
|
|
|
//错误处理
|
|
|
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) ExportTeacherAccountInfoExcel(ctx context.Context, in *BaseTeacherProto.ModelArg) (*BaseTeacherProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseTeacherProto.Reply
|
|
|
list, _, err := BaseTeacherDao.ExportTeacherAccountInfoExcel(in)
|
|
|
//错误处理
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlQueryError, "执行ExportTeacherAccountInfoExcel时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
//1、配置文件
|
|
|
jsonTemplate := "teacher_account.json"
|
|
|
//2、导出
|
|
|
TargetPath := CommonUtil.GetExportExcelFilePath()
|
|
|
ExcelUtil.ExportExcel(jsonTemplate, list, TargetPath)
|
|
|
reply.ExcelPath = TargetPath
|
|
|
return &reply, nil
|
|
|
}
|
|
|
|
|
|
//导出本单位教职工信息到EXCEL
|
|
|
func (s *Rpc) ExportTeacherInfoExcel(ctx context.Context, in *BaseTeacherProto.ModelArg) (*BaseTeacherProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseTeacherProto.Reply
|
|
|
//导出
|
|
|
TargetPath := CommonUtil.GetExportExcelFilePath()
|
|
|
//哪个单位
|
|
|
bureauId := in.BureauId
|
|
|
//是不是需要空的excel
|
|
|
ExportExcelStatus := in.ExportExcelStatus
|
|
|
BaseTeacherDao.ExportTeacherInfoExcel(TargetPath, bureauId, ExportExcelStatus)
|
|
|
reply.ExcelPath = TargetPath
|
|
|
return &reply, nil
|
|
|
}
|
|
|
|
|
|
//导入本校教师信息
|
|
|
func (s *Rpc) ImportTeacherInfoExcel(ctx context.Context, in *BaseTeacherProto.ImportArg) (*BaseTeacherProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseTeacherProto.Reply
|
|
|
//将业务逻辑封装到dao层
|
|
|
success, message, err := BaseTeacherDao.ImportTeacherInfoExcel(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
|
|
|
}
|
|
|
}
|