From 948432f1e73ccf18d5fdd968ea48457c37d4354c Mon Sep 17 00:00:00 2001 From: huanghai <10402852@qq.com> Date: Wed, 19 Aug 2020 08:12:54 +0800 Subject: [PATCH] 'commit' --- .../BaseStudentDao/BaseStudentDao.go | 73 +++++++++++-------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/dsBaseRpc/RpcService/BaseStudent/BaseStudentDao/BaseStudentDao.go b/dsBaseRpc/RpcService/BaseStudent/BaseStudentDao/BaseStudentDao.go index 45cdaff5..1a969e2a 100644 --- a/dsBaseRpc/RpcService/BaseStudent/BaseStudentDao/BaseStudentDao.go +++ b/dsBaseRpc/RpcService/BaseStudent/BaseStudentDao/BaseStudentDao.go @@ -18,6 +18,7 @@ import ( "dsBaseRpc/Utils/RedisUtil" "dsBaseRpc/Utils/SqlKit" "dsBaseRpc/models" + "fmt" "github.com/360EntSecGroup-Skylar/excelize/v2" "github.com/xormplus/builder" "regexp" @@ -31,14 +32,14 @@ var db = DbUtil.Engine func ActionLog(ms []models.TBaseStudent, actionCode string, actionPersonId string, actionIp string) { msLog := make([]models.TBaseStudentLog, len(ms)) for i := range ms { - CommonUtil.CopyFields(ms[i], &msLog[i]) + _ = CommonUtil.CopyFields(ms[i], &msLog[i]) msLog[i].LogId = CommonUtil.GetUUID() msLog[i].ActionCode = actionCode msLog[i].ActionIpAddress = actionIp msLog[i].ActionPersonId = actionPersonId } //批量保存 - db.Insert(msLog) + _, _ = db.Insert(msLog) } //通过主键集合,查找对应的实体bean集合 @@ -63,7 +64,7 @@ func UpdateBaseStudent(model models.TBaseStudent, ForceUpdateFields []string) (i var selector = SqlKit.GetBean("t_base_student") SqlKit.DeleteCacheByIds(ids, selector) //更改登录表中的学生姓名 - SysLoginpersonDao.UpdatePersonName(model.PersonId, model.Xm) + _, _ = SysLoginpersonDao.UpdatePersonName(model.PersonId, model.Xm) //2、计算本次操作,有哪些字段需要更新 NeedUpdateFields := CommonUtil.GetNeedUpdateFields(model) //3、合并强制更新的字段 @@ -73,10 +74,10 @@ func UpdateBaseStudent(model models.TBaseStudent, ForceUpdateFields []string) (i //更改排序号 //(1)权限排序号的范围是parent_id var myBuilder = builder.Dialect(builder.MYSQL).Select("person_id").From("t_base_student") - myBuilder.ToBoundSQL() + _, _ = myBuilder.ToBoundSQL() //(2)查询获取到parent_id var m1 models.TBaseStudent - db.ID(model.PersonId).Get(&m1) + _, _ = db.ID(model.PersonId).Get(&m1) //5、更新操作,强制更新这些列 affected, err := db.ID(model.PersonId).Cols(ForceUpdateFields...).Update(model) return affected, err @@ -108,15 +109,20 @@ func PageBaseStudent(in *BaseStudentProto.QueryArg) ([]map[string]interface{}, i func ReviseTeacherOrg(Ids []string, ClassId 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 Ids { var person models.TBaseStudent person.ClassId = ClassId _, err := db.ID(Ids[i]).Cols("class_id").Update(person) if err != nil { - session.Rollback() + _ = session.Rollback() return err } } @@ -163,23 +169,23 @@ func ExportStudentInfoExcel(targetPath string, bureauId string, ExportExcelStatu f, _, _, SheetName := ExcelUtil.TemplateAddDict("student.xlsx", jsonTemplate) //2、添加批注 - f.AddComment(SheetName, "B201", `{"author":"示例: ","text":"填写年份全称,如:2019 或 2020。"}`) - f.AddComment(SheetName, "C201", `{"author":"示例: ","text":"填写本年级内班级的编号,如:1或2,代表本年级内的1班或2班。"}`) - f.AddComment(SheetName, "F201", `{"author":"示例: ","text":"1980-01-01"}`) + _ = f.AddComment(SheetName, "B201", `{"author":"示例: ","text":"填写年份全称,如:2019 或 2020。"}`) + _ = f.AddComment(SheetName, "C201", `{"author":"示例: ","text":"填写本年级内班级的编号,如:1或2,代表本年级内的1班或2班。"}`) + _ = f.AddComment(SheetName, "F201", `{"author":"示例: ","text":"1980-01-01"}`) //3、入学年份+班号的有效性 for k := 2 + ExcelUtil.HiddenRows; k <= 5000+ExcelUtil.HiddenRows; k++ { //入学年份 dvRange := excelize.NewDataValidation(true) dvRange.Sqref = "B" + CommonUtil.ConvertIntToString(k) + ":B" + CommonUtil.ConvertIntToString(k) - dvRange.SetRange(2014, 2030, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorBetween) + _ = dvRange.SetRange(2014, 2030, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorBetween) dvRange.SetError(excelize.DataValidationErrorStyleStop, "入学年份校验错误", "系统只支持2014-2030年度的班级!") - f.AddDataValidation(SheetName, dvRange) + _ = f.AddDataValidation(SheetName, dvRange) //班号 dvRange = excelize.NewDataValidation(true) dvRange.Sqref = "C" + CommonUtil.ConvertIntToString(k) + ":C" + CommonUtil.ConvertIntToString(k) - dvRange.SetRange(1, 99, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorBetween) + _ = dvRange.SetRange(1, 99, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorBetween) dvRange.SetError(excelize.DataValidationErrorStyleStop, "班号录入错误", "系统只支持1-99的班号!") - f.AddDataValidation(SheetName, dvRange) + _ = f.AddDataValidation(SheetName, dvRange) } //4、添加是否的下拉框K--->P for i := 11; i <= 16; i++ { @@ -187,8 +193,8 @@ func ExportStudentInfoExcel(targetPath string, bureauId string, ExportExcelStatu cName, _ := excelize.ColumnNumberToName(i) dvRange := excelize.NewDataValidation(true) dvRange.Sqref = cName + CommonUtil.ConvertIntToString(2+ExcelUtil.HiddenRows) + ":" + cName + CommonUtil.ConvertIntToString(ExcelUtil.RowsCount+ExcelUtil.HiddenRows) - dvRange.SetDropList([]string{"是", "否"}) - f.AddDataValidation(SheetName, dvRange) + _ = dvRange.SetDropList([]string{"是", "否"}) + _ = f.AddDataValidation(SheetName, dvRange) } //5、当前学校应该有哪些学段 stageList, _, _ := BaseClassDao.GetStage(bureauId) @@ -198,8 +204,8 @@ func ExportStudentInfoExcel(targetPath string, bureauId string, ExportExcelStatu for k := 2 + ExcelUtil.HiddenRows; k <= 5000+ExcelUtil.HiddenRows; k++ { dvRange := excelize.NewDataValidation(true) dvRange.Sqref = "A" + CommonUtil.ConvertIntToString(k) + ":A" + CommonUtil.ConvertIntToString(k) - dvRange.SetDropList(stageArray) - f.AddDataValidation(SheetName, dvRange) + _ = dvRange.SetDropList(stageArray) + _ = f.AddDataValidation(SheetName, dvRange) } } if ExportExcelStatus > 0 { @@ -257,7 +263,7 @@ func ExportStudentInfoExcel(targetPath string, bureauId string, ExportExcelStatu for j := range colNames { cName, _ := excelize.ColumnNumberToName(j + 1) cName = cName + strconv.Itoa(i+2+ExcelUtil.HiddenRows) - f.SetCellValue(SheetName, cName, list[i][colNames[j]]) + _ = f.SetCellValue(SheetName, cName, list[i][colNames[j]]) } } } @@ -320,7 +326,7 @@ func ImportStudentInfoExcel(excelPath string, bureauId string, actionPersonId st //4、获取所有单位的一些属性,用于一会维护人员信息时使用 var bureauModel models.TBaseOrganization - db.Where("org_id=?", bureauId).Get(&bureauModel) + _, _ = db.Where("org_id=?", bureauId).Get(&bureauModel) //6、新增 insertCount, _, _ = insertStudent(batchId, bureauModel, actionPersonId, actionIp) @@ -513,11 +519,11 @@ func checkExcel(excelPath string, s1 ExcelUtil.TemplateStruct, MapClass map[stri if !pass { //红色 style, _ := f.GetCellStyle(s1.Title, Const.RedCell) - f.SetCellStyle(s1.Title, cell, cell, style) + _ = f.SetCellStyle(s1.Title, cell, cell, style) firstSuccess = false } else { style, _ := f.GetCellStyle(s1.Title, Const.WhiteCell) - f.SetCellStyle(s1.Title, cell, cell, style) + _ = f.SetCellStyle(s1.Title, cell, cell, style) } } } @@ -529,7 +535,7 @@ func checkExcel(excelPath string, s1 ExcelUtil.TemplateStruct, MapClass map[stri 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 } @@ -641,7 +647,7 @@ func checkTempTable(excelPath string, s1 ExcelUtil.TemplateStruct, batchId strin rowNumber := listIdCardTeacher[i]["row_number"].(int64) cell := "F" + CommonUtil.ConvertInt64ToString(rowNumber) style, _ := f.GetCellStyle(s1.Title, Const.YellowCell) - f.SetCellStyle(s1.Title, cell, cell, style) + _ = f.SetCellStyle(s1.Title, cell, cell, style) //设计二级检查失败 success = false } @@ -659,7 +665,7 @@ func checkTempTable(excelPath string, s1 ExcelUtil.TemplateStruct, batchId strin rowNumber := listIdCardStudent[i]["row_number"].(int64) cell := "H" + CommonUtil.ConvertInt64ToString(rowNumber) style, _ := f.GetCellStyle(s1.Title, Const.YellowCell) - f.SetCellStyle(s1.Title, cell, cell, style) + _ = f.SetCellStyle(s1.Title, cell, cell, style) //设计二级检查失败 success = false } @@ -678,7 +684,7 @@ func insertStudent(batchId string, bureauModel models.TBaseOrganization, actionP //新增学生 studentImportExcelArray := make([]models.TBaseStudentImportExcel, 0) studentArray := make([]models.TBaseStudent, 0) - db.Where("batch_id=? and length(person_id)=0", batchId).Find(&studentImportExcelArray) + _ = db.Where("batch_id=? and length(person_id)=0", batchId).Find(&studentImportExcelArray) for i := range studentImportExcelArray { r1 := studentImportExcelArray[i] @@ -796,7 +802,7 @@ func updateStudentImport(batchId string, bureauModel models.TBaseOrganization, a //开始 studentImportExcelArray := make([]models.TBaseStudentImportExcel, 0) studentArray := make([]models.TBaseStudent, 0) - db.Where("batch_id=? and length(person_id)=36", batchId).Find(&studentImportExcelArray) + _ = db.Where("batch_id=? and length(person_id)=36", batchId).Find(&studentImportExcelArray) //准备更新的数据 for i := range studentImportExcelArray { @@ -866,12 +872,17 @@ func updateStudentImport(batchId string, bureauModel models.TBaseOrganization, a if len(studentArray) > 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 studentArray { _, err := session.Where("person_id=?", studentArray[k].PersonId).Update(studentArray[k]) if err != nil { - session.Rollback() + _ = session.Rollback() return 0, Const.DataBaseActionError, err } }