From ca58aeaf8fac5c189739fe82732325eae09d6921 Mon Sep 17 00:00:00 2001 From: huanghai <10402852@qq.com> Date: Thu, 6 Aug 2020 11:02:44 +0800 Subject: [PATCH] 'commit' --- .../BaseOrganizationService.go | 13 +-- .../BaseTeacherDao/BaseTeacherDao.go | 108 +++++++++--------- .../BaseTeacherService/BaseTeacherService.go | 44 +++---- .../Tools/FillTeacherOrg/FillTeacherOrg.go | 39 +++++++ dsBaseRpc/models/t_base_teacher.go | 7 -- dsBaseRpc/models/t_base_teacher_log.go | 7 -- 6 files changed, 110 insertions(+), 108 deletions(-) create mode 100644 dsBaseRpc/Tools/FillTeacherOrg/FillTeacherOrg.go diff --git a/dsBaseRpc/RpcService/BaseOrganization/BaseOrganizationService/BaseOrganizationService.go b/dsBaseRpc/RpcService/BaseOrganization/BaseOrganizationService/BaseOrganizationService.go index eb1ad43e..bc4a79d8 100644 --- a/dsBaseRpc/RpcService/BaseOrganization/BaseOrganizationService/BaseOrganizationService.go +++ b/dsBaseRpc/RpcService/BaseOrganization/BaseOrganizationService/BaseOrganizationService.go @@ -729,19 +729,12 @@ func UpdateManager(bureauId string, bUse int32) error { model.Lxdh = "18888888888" model.Dzxx = "xx@dsideal.com" model.BUse = 1 - model.BureauId = bureauId - model.OrgId = bureauId - model.SortId = int32(BaseTeacherDao.GetMaxSortId(bureauId)) + 1 - var err error - _, model.ProvinceCode, model.CityCode, model.DistrictCode, _, err = BaseOrganizationDao.GetBureauAdministrativeDivision(model.BureauId) - if err != nil { - return err - } - - _, err = BaseTeacherDao.AddBaseTeacher(*model) + _, err := BaseTeacherDao.AddBaseTeacher(*model) if err != nil { return err } + //生成人员的组织机构数据 + BaseTeacherDao.AddTeacherOrgInfo([]string{personId}, bureauId, 1, 1) //(2)生成登录名和密码 accountArray := SysLoginpersonService.GenerateLoginAccount(1, 1) modelLoginPerson := new(models.TSysLoginperson) diff --git a/dsBaseRpc/RpcService/BaseTeacher/BaseTeacherDao/BaseTeacherDao.go b/dsBaseRpc/RpcService/BaseTeacher/BaseTeacherDao/BaseTeacherDao.go index 442bd9b7..e9d0e490 100644 --- a/dsBaseRpc/RpcService/BaseTeacher/BaseTeacherDao/BaseTeacherDao.go +++ b/dsBaseRpc/RpcService/BaseTeacher/BaseTeacherDao/BaseTeacherDao.go @@ -57,7 +57,7 @@ func GetByIds(ids []string) ([]models.TBaseTeacher, error) { */ func GetMaxSortId(OrgId string) int64 { //取最大值 - sql := "select ifnull(max(sort_id),0) as maxSortId from t_base_teacher where org_id=? and b_use=1" + sql := "select ifnull(max(sort_id),0) as maxSortId from t_base_teacher_org where org_id=? and b_use=1" listSort, _ := db.SQL(sql, OrgId).Query().List() SortId := listSort[0]["maxSortId"].(int64) return SortId @@ -97,8 +97,8 @@ func PageBaseTeacher(in *BaseTeacherProto.QueryArg) ([]map[string]interface{}, i // 注意使用limit时要使用方言 // 注意两个表关联时的on用法: var myBuilder = builder.Dialect(builder.MYSQL).Select("t1.*"). - From("t_base_teacher as t1"). - OrderBy("t1.sort_id") + From("t_base_teacher as t1").LeftJoin("t_base_teacher_org as t2", "t1.person_id=t2.person_id"). + OrderBy("t2.sort_id") //所在单位ID list := SqlKit.QueryByIds([]string{in.OrgId}, "t_base_organization") if list == nil { @@ -107,10 +107,10 @@ func PageBaseTeacher(in *BaseTeacherProto.QueryArg) ([]map[string]interface{}, i bureauId := list[0]["bureau_id"].(string) if in.OrgId == bureauId { //如果是单位ID - myBuilder.And(builder.Eq{"t1.bureau_id": in.OrgId}) + myBuilder.And(builder.Eq{"t2.bureau_id": in.OrgId}) } else { //如果是部门ID - myBuilder.And(builder.Eq{"t1.org_id": in.OrgId}) + myBuilder.And(builder.Eq{"t2.org_id": in.OrgId}) } //姓名模糊搜索 myBuilder.And(builder.Like{"t1.xm", in.Xm}) @@ -182,27 +182,16 @@ func FillLoginInfo(list *[]map[string]interface{}) error { //批量教师修改部门 func ReviseTeacherOrg(Ids []string, OrgId string) error { //1、目前这个部门,最大的SortId - sql := "select ifnull(max(sort_id),0) as maxSortId from t_base_teacher where b_use=1 and org_id=?" + sql := "select ifnull(max(sort_id),0) as maxSortId from t_base_teacher_org where b_use=1 and org_id=?" listSortId, _ := db.SQL(sql, OrgId).Query().List() maxSortId := int32(listSortId[0]["maxSortId"].(int64)) - //2、声明事务 - session := db.NewSession() - defer session.Close() - session.Begin() - for i := range Ids { - var person models.TBaseTeacher - person.OrgId = OrgId - person.SortId = maxSortId + int32(i+1) - _, err := db.ID(Ids[i]).Cols("org_id", "sort_id").Update(person) - if err != nil { - session.Rollback() - return err - } - } - //提交事务 - err := session.Commit() - return err + //2、删除旧的部门关系 + DeleteTeacherOrgInfo(Ids, OrgId) + + //3、插入人员部门关系 + AddTeacherOrgInfo(Ids, OrgId, 1, maxSortId) + return nil } //导出本单位教职工账号信息到EXCEL @@ -210,11 +199,13 @@ func ExportTeacherAccountInfoExcel(in *BaseTeacherProto.ModelArg) ([]map[string] var myBuilder = builder.Dialect(builder.MYSQL).Select("t1.*,t3.org_name"). From("t_sys_loginperson as t1"). InnerJoin("t_base_teacher as t2", "t1.person_id=t2.person_id"). - InnerJoin("t_base_organization as t3", "t2.org_id=t3.org_id") + InnerJoin("t_base_teacher_org as t4", "t2.person_id=t4.person_id"). + InnerJoin("t_base_organization as t3", "t4.org_id=t3.org_id") + myBuilder.Where(builder.Eq{"t1.b_use": 1}). And(builder.Eq{"t2.b_use": 1}). And(builder.Eq{"t3.b_use": 1}). - And(builder.Eq{"t2.bureau_id": in.BureauId}).And(builder.Eq{"t1.identity_id": 2}) + And(builder.Eq{"t3.bureau_id": in.BureauId}).And(builder.Eq{"t1.identity_id": 2}) myBuilder.OrderBy("t2.sort_id").OrderBy("t2.id_int") sql, err := myBuilder.ToBoundSQL() if err != nil { @@ -303,8 +294,9 @@ func ExportTeacherInfoExcel(targetPath string, bureauId string, ExportExcelStatu sql := `select t2.org_name,t1.xm, t1.mzm,t1.zzmmm,t1.sfzjlxm, (case t1.sfzjh when '-1' then '' else t1.sfzjh end ) as sfzjh, t1.xlm,t1.xwm,t1.zcm,t1.bzlbm,t1.stage_id,t1.subject_id,t1.gwzym,t1.lxdh,t1.dzxx - from t_base_teacher as t1 inner join t_base_organization as t2 on t1.org_id=t2.org_id - where t1.bureau_id=? and t1.identity_id=2 and t1.b_use=1 order by t1.sort_id,t1.id_int` + from t_base_teacher as t1 inner join t_base_teacher_org as t3 on t1.person_id=t3.person_id + inner join t_base_organization as t2 on t3.org_id=t2.org_id + where t3.bureau_id=? and t1.identity_id=2 and t1.b_use=1 order by t3.sort_id,t1.id_int` list, _ := db.SQL(sql, bureauId).Query().List() for i := range list { record := list[i] @@ -786,12 +778,8 @@ func insertTeacher(batchId string, bureauModel models.TBaseOrganization, actionP var model models.TBaseTeacher //身份 model.IdentityId = 2 - //所在部门 - model.OrgId = r1.OrgId //人员编号 model.PersonId = CommonUtil.GetUUID() - //单位 - model.BureauId = bureauModel.BureauId //导入即可用 model.BUse = 1 //身份证号 @@ -800,14 +788,7 @@ func insertTeacher(batchId string, bureauModel models.TBaseOrganization, actionP model.Sfzjlxm = r1.Sfzjlxm //编制 model.Bzlbm = r1.Bzlbm - //所属省份 - model.ProvinceCode = bureauModel.ProvinceCode - //所属城市 - model.CityCode = bureauModel.CityCode - //县区 - model.DistrictCode = bureauModel.DistrictCode - //主校 - model.MainSchoolId = bureauModel.MainSchoolId + //从教年月 model.Cjny = DateUtil.ConvertDate("1900-01-01") //出生日期与性别 @@ -821,8 +802,6 @@ func insertTeacher(batchId string, bureauModel models.TBaseOrganization, actionP model.Csrq = DateUtil.ConvertDate("1980-01-01") model.Xbm = "1" } - //排序号 - model.SortId = 1 //学段 model.StageId = r1.StageId //学科 @@ -853,6 +832,8 @@ func insertTeacher(batchId string, bureauModel models.TBaseOrganization, actionP model.StateId = 1 //添加到数组中 teacherArray = append(teacherArray, model) + //保存人员所在的部门信息 + AddTeacherOrgInfo([]string{model.PersonId}, r1.OrgId, 1, 1) } //批量插入 if len(teacherArray) > 0 { @@ -862,7 +843,6 @@ func insertTeacher(batchId string, bureauModel models.TBaseOrganization, actionP } //记录日志 ActionLog(teacherArray, Const.ActionInsert, actionPersonId, actionIp) - //产生登录名 accountArray := SysLoginpersonService.GenerateLoginAccount(2, int64(len(teacherImportExcelArray))) var loginpersonModels = make([]models.TSysLoginperson, 0) @@ -915,12 +895,8 @@ func updateTeacherImport(batchId string, bureauModel models.TBaseOrganization, a var model models.TBaseTeacher //身份 model.IdentityId = 2 - //所在部门 - model.OrgId = r1.OrgId //人员编号 model.PersonId = MapSfzjh[r1.Sfzjh] //通过身份证件号反向获取到人员的id - //单位 - model.BureauId = bureauModel.BureauId //导入即可用 model.BUse = 1 //身份证号 @@ -929,14 +905,6 @@ func updateTeacherImport(batchId string, bureauModel models.TBaseOrganization, a model.Sfzjlxm = r1.Sfzjlxm //编制 model.Bzlbm = r1.Bzlbm - //所属省份 - model.ProvinceCode = bureauModel.ProvinceCode - //所属城市 - model.CityCode = bureauModel.CityCode - //县区 - model.DistrictCode = bureauModel.DistrictCode - //主校 - model.MainSchoolId = bureauModel.MainSchoolId //从教年月 model.Cjny = DateUtil.ConvertDate("1999-09-01") //出生日期与性别 @@ -982,6 +950,8 @@ func updateTeacherImport(batchId string, bureauModel models.TBaseOrganization, a model.StateId = 1 //添加到数组中 teacherArray = append(teacherArray, model) + //保存人员所在的部门信息 + AddTeacherOrgInfo([]string{model.PersonId}, r1.OrgId, 1, 1) } //批量更新 if len(teacherArray) > 0 { @@ -1041,7 +1011,7 @@ func getOrgNameMap(bureauId string) (map[string]string, error) { 作者:黄海 时间:2020-08-05 */ -func AddTeacherOrgInfo(personIds []string, orgId string, isMain int32) (bool, string, error) { +func AddTeacherOrgInfo(personIds []string, orgId string, isMain int32, fromSortId int32) (bool, string, error) { //(1)获取单位ID list := SqlKit.QueryByIds([]string{orgId}, "t_base_organization") if len(list) == 0 { @@ -1067,12 +1037,13 @@ func AddTeacherOrgInfo(personIds []string, orgId string, isMain int32) (bool, st model.CityCode = CityCode model.DistrictCode = DistrictCode model.MainSchoolId = mainSchoolId - model.SortId = 1 + model.SortId = fromSortId model.IsMain = isMain _, err := db.Insert(model) if err != nil { return false, "插入人员部门关系表时失败!", err } + fromSortId++ } return true, "保存成功!", nil } @@ -1091,3 +1062,28 @@ func DeleteTeacherOrgInfo(personIds []string, orgId string) error { _, err := db.SQL(sql).Execute() return err } + +/** +功能:将人员从全部部门下删除,支持批量操作 +作者:黄海 +时间:2020-08-05 +*/ +func DeleteTeacherOrgInfoAll(personIds []string) error { + //主部门是不能删除的,主部门只能随着人员删除而删除 + //批量删除教师在此部门的信息 + var myBuilder = builder.Dialect(builder.MYSQL).Update(builder.Eq{"b_use": -2}). + From("t_base_teacher_org").Where(builder.Eq{"b_use": 1}.And(builder.In("person_id", personIds))) + sql, _ := myBuilder.ToBoundSQL() + _, err := db.SQL(sql).Execute() + return err +} + +/** +功能:修改指定人员在指定部门下的排序号 +作者:黄海 +时间:2020-08-05 +*/ +func UpdateSortId(personId string, orgId string, sortId int32) { + sql := `update t_base_teacher_org set sort_id=? where person_id=? and org_id=?` + db.SQL(sql, sortId, personId, orgId).Execute() +} diff --git a/dsBaseRpc/RpcService/BaseTeacher/BaseTeacherService/BaseTeacherService.go b/dsBaseRpc/RpcService/BaseTeacher/BaseTeacherService/BaseTeacherService.go index ba2e5481..f0911bf0 100644 --- a/dsBaseRpc/RpcService/BaseTeacher/BaseTeacherService/BaseTeacherService.go +++ b/dsBaseRpc/RpcService/BaseTeacher/BaseTeacherService/BaseTeacherService.go @@ -5,7 +5,6 @@ import ( "dsBaseRpc/Const" "dsBaseRpc/Const/ErrorConst" "dsBaseRpc/RpcService/BaseClass/BaseClassDao" - "dsBaseRpc/RpcService/BaseOrganization/BaseOrganizationDao" "dsBaseRpc/RpcService/BaseOrganizationManager/BaseOrganizationManagerDao" "dsBaseRpc/RpcService/BaseTeacher/BaseTeacherDao" "dsBaseRpc/RpcService/BaseTeacher/BaseTeacherProto" @@ -134,39 +133,24 @@ func (s *Rpc) AddBaseTeacher(ctx context.Context, in *BaseTeacherProto.ModelArg) //教师的身份ID model.IdentityId = 2 - //排序号 - if in.SortId == 0 { - model.SortId = int32(BaseTeacherDao.GetMaxSortId(in.OrgId)) + 1 - } else { - model.SortId = in.SortId - } - //主单位与主部门 - 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) + _, err := BaseTeacherDao.AddBaseTeacher(*model) if err != nil { reply.Success = false reply.Message = Const.DataBaseActionError LogUtil.Error(ErrorConst.SqlUpdateError, "执行AddBaseTeacher时发生严重错误:"+err.Error()) return &reply, err } + //记录教师所在单位和部门 + personIds := []string{model.PersonId} + var fromSortId int32 + //排序号 + if in.SortId == 0 { + fromSortId = int32(BaseTeacherDao.GetMaxSortId(in.OrgId)) + 1 + } else { + fromSortId = in.SortId + } + BaseTeacherDao.AddTeacherOrgInfo(personIds, in.OrgId, 1, fromSortId) // 生成教师账号 _, err = SysLoginpersonService.AddLoginperson(2, model.PersonId, model.Xm) if err != nil { @@ -212,6 +196,9 @@ func (s *Rpc) DeleteBaseTeacher(ctx context.Context, in *BaseTeacherProto.Delete reply.Message = Const.DataBaseActionError return &reply, err } + //删除人员所在的部门关系 + BaseTeacherDao.DeleteTeacherOrgInfoAll(in.Ids) + //记录日志 ms, err := BaseTeacherDao.GetByIds(in.Ids) if err != nil { @@ -291,7 +278,8 @@ func (s *Rpc) UpdateBaseTeacher(ctx context.Context, in *BaseTeacherProto.ModelA model.Zcm = in.Zcm model.Bzlbm = in.Bzlbm //排序号 - model.SortId = in.SortId + BaseTeacherDao.UpdateSortId(model.PersonId,in.OrgId,in.SortId) + //从教年月 if len(in.Cjny) == 0 { model.Cjny = DateUtil.ConvertDate("1900-01-01") } else { diff --git a/dsBaseRpc/Tools/FillTeacherOrg/FillTeacherOrg.go b/dsBaseRpc/Tools/FillTeacherOrg/FillTeacherOrg.go new file mode 100644 index 00000000..4b1fa0e8 --- /dev/null +++ b/dsBaseRpc/Tools/FillTeacherOrg/FillTeacherOrg.go @@ -0,0 +1,39 @@ +package main + +import ( + "dsBaseRpc/Utils/CommonUtil" + "dsBaseRpc/Utils/DbUtil" + "dsBaseRpc/models" + "fmt" +) + +var db = DbUtil.Engine + +func main() { + //1、清空人员部门关系表 + sql := `truncate table t_base_teacher_org` + db.SQL(sql).Execute() + + //2、插入人员部门关系表 + sql = `select * from t_base_teacher` + list, _ := db.SQL(sql).Query().List() + + for i := range list { + var model models.TBaseTeacherOrg + model.Id = CommonUtil.GetUUID() + model.BureauId = list[i]["bureau_id"].(string) + model.OrgId = list[i]["org_id"].(string) + model.PersonId = list[i]["person_id"].(string) + model.SortId = int32(list[i]["sort_id"].(int64)) + model.IsMain = 1 + model.ProvinceCode = list[i]["province_code"].(string) + model.CityCode = list[i]["city_code"].(string) + model.DistrictCode = list[i]["district_code"].(string) + if list[i]["mainschool_id"] != nil { + model.MainSchoolId = list[i]["mainschool_id"].(string) + } + model.BUse = int32(list[i]["b_use"].(int64)) + db.Insert(model) + } + fmt.Println("恭喜,数据迁移成功完成!") +} diff --git a/dsBaseRpc/models/t_base_teacher.go b/dsBaseRpc/models/t_base_teacher.go index b57b24ab..35cb469a 100644 --- a/dsBaseRpc/models/t_base_teacher.go +++ b/dsBaseRpc/models/t_base_teacher.go @@ -28,11 +28,4 @@ type TBaseTeacher struct { Dzxx string `xorm:"not null default '''' comment('电子信箱') index(dzxx) index(person_id_3) VARCHAR(100)"` BUse int32 `xorm:"not null default 1 comment('是否启用 0:未启用 1:启用') index(bureau_id) index(dzxx) index(lxdh) index(org_id) index(person_id) index(person_id_2) index(person_id_3) index(sfzjh) TINYINT(1)"` StateId int32 `xorm:"not null default 0 comment('教师状态码') INT(11)"` - BureauId string `xorm:"not null comment('所属单位(主)') index(bureau_id) CHAR(36)"` - OrgId string `xorm:"not null comment('所属部门(主)') index(org_id) CHAR(36)"` - MainSchoolId string `xorm:"not null comment('所属主校ID') CHAR(36)"` - ProvinceCode string `xorm:"not null comment('所属省CODE') VARCHAR(36)"` - CityCode string `xorm:"not null comment('所属市CODE') CHAR(6)"` - DistrictCode string `xorm:"not null comment('所属县区CODE') CHAR(6)"` - SortId int32 `xorm:"not null default 1 comment('在主部门的排序号') INT(11)"` } diff --git a/dsBaseRpc/models/t_base_teacher_log.go b/dsBaseRpc/models/t_base_teacher_log.go index 906e22ad..4b66f0d9 100644 --- a/dsBaseRpc/models/t_base_teacher_log.go +++ b/dsBaseRpc/models/t_base_teacher_log.go @@ -29,13 +29,6 @@ type TBaseTeacherLog struct { Dzxx string `xorm:"not null default '''' comment('电子信箱') VARCHAR(100)"` BUse int32 `xorm:"not null default 1 comment('是否启用 0:未启用 1:启用') TINYINT(1)"` StateId int32 `xorm:"not null default 0 comment('教师状态码') INT(11)"` - BureauId string `xorm:"not null comment('所属单位(主)') CHAR(36)"` - OrgId string `xorm:"not null comment('所属部门(主)') CHAR(36)"` - MainSchoolId string `xorm:"not null comment('所属主校ID') CHAR(36)"` - ProvinceCode string `xorm:"not null comment('所属省CODE') VARCHAR(36)"` - CityCode string `xorm:"not null comment('所属市CODE') CHAR(6)"` - DistrictCode string `xorm:"not null comment('所属县区CODE') CHAR(6)"` - SortId int32 `xorm:"not null default 1 comment('在主部门的排序号') INT(11)"` ActionPersonId string `xorm:"not null comment('操作人员ID') CHAR(36)"` ActionIpAddress string `xorm:"not null default '''' comment('操作IP') VARCHAR(100)"` ActionCode string `xorm:"not null comment('操作代码') VARCHAR(255)"`