master
huanghai 5 years ago
parent 11e021f0f2
commit 6c8002374f

@ -474,14 +474,11 @@ func ImportTeacherInfoExcel(excelPath string, bureauId string, actionPersonId st
var bureauModel models.TBaseOrganization
db.Where("org_id=?", bureauId).Get(&bureauModel)
//5、更新标识修改,数据库里有的为修改,没有是新增
insertOrUpdateFlagSetting(batchId)
//5、新增
insertCount, _, _ = insertTeacher(batchId, actionPersonId, actionIp)
//6、新增
insertCount, _, _ = insertTeacher(batchId, bureauModel, actionPersonId, actionIp)
//7、修改
updateCount, _, _ = updateTeacherImport(batchId, bureauModel, actionPersonId, actionIp)
//6、修改
updateCount, _, _ = updateTeacherImport(batchId, actionPersonId, actionIp)
return true, "插入" + CommonUtil.ConvertIntToString(insertCount) + "条记录,更新" + CommonUtil.ConvertIntToString(updateCount) + "条记录!", nil
}
@ -839,24 +836,14 @@ func checkExcel(excelPath string, s1 ExcelUtil.TemplateStruct, MapOrgName map[st
return firstSuccess
}
/**
*/
func insertOrUpdateFlagSetting(batchId string) {
//1、更新标识修改,数据库里有的为修改,没有是新增
sql := `update t_base_teacher_import_excel as t1 join t_base_teacher as t2 on t1.sfzjh=t2.sfzjh
set t1.insert_or_update=2 where t2.b_use=1 and t1.batch_id=?`
db.SQL(sql, batchId).Execute()
}
/**
*/
func insertTeacher(batchId string, bureauModel models.TBaseOrganization, actionPersonId string, actionIp string) (int, string, error) {
func insertTeacher(batchId string, actionPersonId string, actionIp string) (int, string, error) {
//2、新增人员
teacherImportExcelArray := make([]models.TBaseTeacherImportExcel, 0)
teacherArray := make([]models.TBaseTeacher, 0)
db.Where("batch_id=? and insert_or_update=1", batchId).Find(&teacherImportExcelArray)
db.Where("batch_id=? and person_id is null", batchId).Find(&teacherImportExcelArray)
for i := range teacherImportExcelArray {
r1 := teacherImportExcelArray[i]
@ -884,8 +871,8 @@ func insertTeacher(batchId string, bureauModel models.TBaseOrganization, actionP
model.Xbm = xbm
} else {
//如果不是身份证号,那就用个默认值吧
model.Csrq = DateUtil.ConvertDate("1980-01-01")
model.Xbm = "1"
model.Csrq = r1.Csrq
model.Xbm = r1.Xbm
}
//学段
model.StageId = r1.StageId
@ -960,19 +947,11 @@ func insertTeacher(batchId string, bureauModel models.TBaseOrganization, actionP
/**
*/
func updateTeacherImport(batchId string, bureauModel models.TBaseOrganization, actionPersonId string, actionIp string) (int, string, error) {
//准备身份证号与人员id的映射map
sql := `select t1.person_id,t1.sfzjh from t_base_teacher as t1 inner join t_base_teacher_import_excel as t2
on t1.sfzjh=t2.sfzjh where t2.batch_id=?`
list, _ := db.SQL(sql, batchId).Query().List()
var MapSfzjh = make(map[string]string)
for i := range list {
MapSfzjh[list[i]["sfzjh"].(string)] = list[i]["person_id"].(string)
}
func updateTeacherImport(batchId string, actionPersonId string, actionIp string) (int, string, error) {
//开始
teacherImportExcelArray := make([]models.TBaseTeacherImportExcel, 0)
teacherArray := make([]models.TBaseTeacher, 0)
db.Where("batch_id=? and insert_or_update=2", batchId).Find(&teacherImportExcelArray)
db.Where("batch_id=? and person_id is not null", batchId).Find(&teacherImportExcelArray)
//准备更新的数据
for i := range teacherImportExcelArray {
@ -981,7 +960,7 @@ func updateTeacherImport(batchId string, bureauModel models.TBaseOrganization, a
//身份
model.IdentityId = 2
//人员编号
model.PersonId = MapSfzjh[r1.Sfzjh] //通过身份证件号反向获取到人员的id
model.PersonId = r1.PersonId
//导入即可用
model.BUse = 1
//身份证号
@ -1000,8 +979,8 @@ func updateTeacherImport(batchId string, bureauModel models.TBaseOrganization, a
model.Xbm = xbm
} else {
//如果不是身份证号,那就用个默认值吧
model.Csrq = DateUtil.ConvertDate("1977-10-11")
model.Xbm = "1"
model.Csrq = r1.Csrq
model.Xbm = r1.Xbm
}
//排序号
//model.SortId = 1 //排序号就不修改了,防止人为修改对了,这样导入再修改回去

Loading…
Cancel
Save