master
huanghai 5 years ago
parent be4f4f870e
commit 948432f1e7

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

Loading…
Cancel
Save