diff --git a/dsBaseRpc/RpcService/BaseOrganizationManager/BaseOrganizationManagerDao/BaseOrganizationManagerDao.go b/dsBaseRpc/RpcService/BaseOrganizationManager/BaseOrganizationManagerDao/BaseOrganizationManagerDao.go index dd2144e9..dec8504f 100644 --- a/dsBaseRpc/RpcService/BaseOrganizationManager/BaseOrganizationManagerDao/BaseOrganizationManagerDao.go +++ b/dsBaseRpc/RpcService/BaseOrganizationManager/BaseOrganizationManagerDao/BaseOrganizationManagerDao.go @@ -6,6 +6,7 @@ import ( "dsBaseRpc/Utils/SqlKit" "dsBaseRpc/models" "errors" + "fmt" ) //操作数据库的变量 @@ -31,8 +32,13 @@ func UpdateOrgManager(OrgId string, OrgManagerIds []string) error { //事务声明 session := db.NewSession() - defer session.Close() - session.Begin() + defer func() { + err := session.Close() + if err != nil { + fmt.Println(err.Error()) + } + }() + _ = session.Begin() //事务的内容 for i := range OrgManagerIds { @@ -44,7 +50,7 @@ func UpdateOrgManager(OrgId string, OrgManagerIds []string) error { u.OrgId = OrgId _, err := session.Insert(u) if err != nil { - session.Rollback() + _ = session.Rollback() return err } } diff --git a/dsBaseRpc/RpcService/BaseTeacher/BaseTeacherDao/BaseTeacherDao.go b/dsBaseRpc/RpcService/BaseTeacher/BaseTeacherDao/BaseTeacherDao.go index 5d2945f4..af5a0817 100644 --- a/dsBaseRpc/RpcService/BaseTeacher/BaseTeacherDao/BaseTeacherDao.go +++ b/dsBaseRpc/RpcService/BaseTeacher/BaseTeacherDao/BaseTeacherDao.go @@ -18,6 +18,7 @@ import ( "dsBaseRpc/Utils/RedisUtil" "dsBaseRpc/Utils/SqlKit" "dsBaseRpc/models" + "fmt" "github.com/360EntSecGroup-Skylar/excelize/v2" "github.com/pkg/errors" "github.com/xormplus/builder" @@ -137,7 +138,7 @@ func PageBaseTeacher(in *BaseTeacherProto.QueryArg) ([]map[string]interface{}, i //对于教师是不是修改过账号进行判断 SysLoginpersonService.FillPwdIsChange(&list) //扩展是不是在多个单位+部门下 - FillIsMutliOrg(&list) + FillIsMultiOrg(&list) //填充主单位,主部门信息 FillMainBureauOrgInfo(&list) //返回结果 @@ -149,7 +150,7 @@ func PageBaseTeacher(in *BaseTeacherProto.QueryArg) ([]map[string]interface{}, i 作者:黄海 时间:2020-08-05 */ -func FillIsMutliOrg(list2 *[]map[string]interface{}) { +func FillIsMultiOrg(list2 *[]map[string]interface{}) { list := *list2 var personIds = make([]string, 0) for i := range list { @@ -249,13 +250,21 @@ func FillLoginInfo(list *[]map[string]interface{}) error { return nil } -//批量教师修改部门 -func ReviseTeacherOrg(Ids []string, OrgId string) error { +/** +功能:获取指定部门的人员最大排序号 +*/ +func getOrgMaxSortId(OrgId string) int32 { //1、目前这个部门,最大的SortId 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)) + return maxSortId +} +//批量教师修改部门 +func ReviseTeacherOrg(Ids []string, OrgId string) error { + //获取指定部门的人员最大排序号 + maxSortId := getOrgMaxSortId(OrgId) //2、删除旧的部门关系 _ = DeleteTeacherOrgInfo(Ids, OrgId) @@ -315,7 +324,7 @@ func ExportTeacherInfoExcel(targetPath string, bureauId string, ExportExcelStatu } dictCols++ stageName := list[i]["dict_value"].(string) - f.SetCellValue(SheetName, dictCName+CommonUtil.ConvertIntToString(1), stageName) + _ = f.SetCellValue(SheetName, dictCName+CommonUtil.ConvertIntToString(1), stageName) //在学段下面第二行开始写入各个学段对应的学科 list2, _ := db.SQL(s1.Level2Sql[0][1], stageName).Query().List() @@ -324,14 +333,14 @@ func ExportTeacherInfoExcel(targetPath string, bureauId string, ExportExcelStatu _ = f.SetCellValue(SheetName, dictCName+CommonUtil.ConvertIntToString(k+2), subjectName) } //批量建立名称管理器 - f.SetDefinedName(&excelize.DefinedName{ + _ = f.SetDefinedName(&excelize.DefinedName{ Name: stageName, RefersTo: SheetName + "!$" + dictCName + "$2:$" + dictCName + "$" + CommonUtil.ConvertIntToString(len(list2)+1), Comment: stageName, Scope: SheetName, }) //隐藏字典列 - f.SetColVisible(SheetName, dictCName, false) + _ = f.SetColVisible(SheetName, dictCName, false) } //学段限定 dvRange := excelize.NewDataValidation(true) @@ -342,7 +351,7 @@ func ExportTeacherInfoExcel(targetPath string, bureauId string, ExportExcelStatu //学科级联绑定 dvRange = excelize.NewDataValidation(true) dvRange.Sqref = "N" + CommonUtil.ConvertIntToString(2+ExcelUtil.HiddenRows) + ":N" + CommonUtil.ConvertIntToString(ExcelUtil.RowsCount+ExcelUtil.HiddenRows) - dvRange.SetSqrefDropList("INDIRECT($M"+CommonUtil.ConvertIntToString(ExcelUtil.HiddenRows+2)+")", true) + _ = dvRange.SetSqrefDropList("INDIRECT($M"+CommonUtil.ConvertIntToString(ExcelUtil.HiddenRows+2)+")", true) _ = f.AddDataValidation(SheetName, dvRange) //部门 @@ -353,15 +362,15 @@ func ExportTeacherInfoExcel(targetPath string, bureauId string, ExportExcelStatu //字典列从cols+1开始 dictCName, _ := excelize.ColumnNumberToName(dictCols) for j := range list { - f.SetCellValue(SheetName, dictCName+CommonUtil.ConvertIntToString(j+1), list[j]["dict_value"]) + _ = f.SetCellValue(SheetName, dictCName+CommonUtil.ConvertIntToString(j+1), list[j]["dict_value"]) //隐藏字典列 - f.SetColVisible(SheetName, dictCName, false) + _ = f.SetColVisible(SheetName, dictCName, false) //要设置下拉框的列 dvRange := excelize.NewDataValidation(true) dvRange.Sqref = "A" + CommonUtil.ConvertIntToString(2+ExcelUtil.HiddenRows) + ":A" + CommonUtil.ConvertIntToString(ExcelUtil.RowsCount+ExcelUtil.HiddenRows) c := "$" + dictCName + "$1:" + dictCName + "$" + CommonUtil.ConvertIntToString(ExcelUtil.RowsCount) - dvRange.SetSqrefDropList(c, true) - f.AddDataValidation(SheetName, dvRange) + _ = dvRange.SetSqrefDropList(c, true) + _ = f.AddDataValidation(SheetName, dvRange) } } if ExportExcelStatus > 0 { @@ -807,7 +816,7 @@ func checkExcel(excelPath string, s1 ExcelUtil.TemplateStruct, MapOrgName map[st firstSuccess = false } else { style, _ := f.GetCellStyle(s1.Title, Const.WhiteCell) - f.SetCellStyle(s1.Title, cell, cell, style) + _=f.SetCellStyle(s1.Title, cell, cell, style) } } } @@ -819,7 +828,7 @@ func checkExcel(excelPath string, s1 ExcelUtil.TemplateStruct, MapOrgName map[st cell := "H" + CommonUtil.ConvertIntToString(rowArray[i]) //重复 style, _ := f.GetCellStyle(s1.Title, Const.BlueCell) - f.SetCellStyle(s1.Title, cell, cell, style) + _ = f.SetCellStyle(s1.Title, cell, cell, style) } firstSuccess = false } @@ -832,7 +841,7 @@ func checkExcel(excelPath string, s1 ExcelUtil.TemplateStruct, MapOrgName map[st cell := "O" + CommonUtil.ConvertIntToString(rowArray[i]) //重复 style, _ := f.GetCellStyle(s1.Title, Const.BlueCell) - f.SetCellStyle(s1.Title, cell, cell, style) + _ = f.SetCellStyle(s1.Title, cell, cell, style) } firstSuccess = false } @@ -851,7 +860,7 @@ func insertTeacher(batchId string, actionPersonId string, actionIp string) (int, //2、新增人员 teacherImportExcelArray := make([]models.TBaseTeacherImportExcel, 0) teacherArray := make([]models.TBaseTeacher, 0) - db.Where("batch_id=? and length(person_id)=0", batchId).Find(&teacherImportExcelArray) + _ = db.Where("batch_id=? and length(person_id)=0", batchId).Find(&teacherImportExcelArray) for i := range teacherImportExcelArray { r1 := teacherImportExcelArray[i] @@ -1025,14 +1034,19 @@ func updateTeacherImport(batchId string, actionPersonId string, actionIp string) //添加到数组中 teacherArray = append(teacherArray, model) //保存人员所在的部门信息 - AddTeacherOrgInfo([]string{model.PersonId}, r1.OrgId, 1, 1) + _, _, _, _ = AddTeacherOrgInfo([]string{model.PersonId}, r1.OrgId, 1, 1) } //批量更新 if len(teacherArray) > 0 { //声明事务 session := db.NewSession() - defer session.Close() - session.Begin() + defer func() { + err := session.Close() + if err != nil { + fmt.Println(err.Error()) + } + }() + _ = session.Begin() for k := range teacherArray { _, err := session.Where("person_id=?", teacherArray[k].PersonId). Cols("b_use", "sfzjh", "sfzjlxm", "bzlbm", "cjny", @@ -1040,7 +1054,7 @@ func updateTeacherImport(batchId string, actionPersonId string, actionIp string) "xmpy", "xwm", "zcm", "mzm", "zzmmm", "gwzym", "lxdh", "dzxx", "state_id").Update(teacherArray[k]) if err != nil { - session.Rollback() + _ = session.Rollback() return 0, Const.DataBaseActionError, err } } @@ -1102,7 +1116,7 @@ func AddTeacherOrgInfo(personIds []string, orgId string, isMain int32, fromSortI return false, "", "在查找单位的行政区划关系时出错!", nil } //(3)删除旧的 - DeleteTeacherOrgInfo(personIds, orgId) + _ = DeleteTeacherOrgInfo(personIds, orgId) //(4)如果isMain==1,还需要清除原来这些人员的主部门,准备插入新的 if isMain == 1 { disableMainOrg(personIds) @@ -1168,7 +1182,7 @@ func DeleteTeacherOrgInfoAll(personIds []string) error { */ func UpdateSortId(personId string, sortId int32) { sql := `update t_base_teacher_org set sort_id=? where person_id=?` - db.SQL(sql, sortId, personId).Execute() + _, _ = db.SQL(sql, sortId, personId).Execute() } /** @@ -1179,7 +1193,7 @@ func UpdateSortId(personId string, sortId int32) { func disableMainOrg(personIds []string) { for i := range personIds { sql := `update t_base_teacher_org set b_use=-2 where person_id=? and is_main=1` - db.SQL(sql, personIds[i]).Execute() + _, _ = db.SQL(sql, personIds[i]).Execute() } } @@ -1313,11 +1327,23 @@ func PageTeacherMultipleBureau(in *BaseTeacherProto.PageMultipleBureauArg) ([]ma func SettingMainOrg(in *BaseTeacherProto.SettingMainOrgArg) (bool, string, error) { //将旧的设置为删除状态 sql := `update t_base_teacher_org set b_use=-2 where person_id=? and b_use=1 and is_main=1` - db.SQL(sql, in.PersonId).Execute() + _, _ = db.SQL(sql, in.PersonId).Execute() //将新的ID设置为主单位状态 sql = `update t_base_teacher_org set is_main=1,b_use=1 where id=?` - db.SQL(sql, in.Id).Execute() + _, _ = db.SQL(sql, in.Id).Execute() return true, "设置成功!", nil } + +//教师的调转 +func TeacherTransfer(personId string, orgId string) error { + //1、因为只有唯一个单位+部门的人员才能进行调转,所以直接找到此关系,禁用即可 + sql := `update t_base_teacher_org set b_use=-2 where person_id=? and b_use=1` + _, _ = db.SQL(sql, personId).Execute() + //2、插入新的关系 + fromSortId := getOrgMaxSortId(orgId) + _, _, _, _ = AddTeacherOrgInfo([]string{personId}, orgId, 1, fromSortId) + + return nil +}