Commit a209b953 authored by 刘子正's avatar 刘子正

教师excel导入 新增导入教学单位编号

parent 6d240af5
...@@ -82,8 +82,8 @@ public class BTeacherServiceImpl implements BTeacherService { ...@@ -82,8 +82,8 @@ public class BTeacherServiceImpl implements BTeacherService {
ArrayList<UserRole> userRoles = new ArrayList<UserRole>(); ArrayList<UserRole> userRoles = new ArrayList<UserRole>();
String[] headers = {"教师工号", "教师姓名", "性别","邮箱"}; String[] headers = {"教师工号", "教师姓名", "性别","邮箱","教学单位编号"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb, headers,false); //获取excel数据 ArrayList<String[]> values = ExcelUtil.importExcel(hwb, headers,true); //获取excel数据
if (values.size() == 0){ if (values.size() == 0){
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST); throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST);
} }
...@@ -92,6 +92,7 @@ public class BTeacherServiceImpl implements BTeacherService { ...@@ -92,6 +92,7 @@ public class BTeacherServiceImpl implements BTeacherService {
List<String> valuesRepeat = new ArrayList<>(); List<String> valuesRepeat = new ArrayList<>();
List<String> valuesShort = new ArrayList<>(); List<String> valuesShort = new ArrayList<>();
List<String> valuesEmailExist = new ArrayList<>(); List<String> valuesEmailExist = new ArrayList<>();
List<String> valuesAgencyExist = new ArrayList<>();
for (String[] value : values) { for (String[] value : values) {
...@@ -126,6 +127,14 @@ public class BTeacherServiceImpl implements BTeacherService { ...@@ -126,6 +127,14 @@ public class BTeacherServiceImpl implements BTeacherService {
continue; continue;
} }
//判断4:教师的所属教学单位是否存在,存在才能添加;
SysUser user3 = new SysUser();
user3.setAgencyCode(value[4]);
if (sysUserMapper.checkTeacherAgency(user3).size() == 0){
valuesAgencyExist.add(value[4]);
continue;
}
//合法:通过了三次判断,证明可建立该用户 //合法:通过了三次判断,证明可建立该用户
valuesOK.add(value); valuesOK.add(value);
...@@ -137,8 +146,9 @@ public class BTeacherServiceImpl implements BTeacherService { ...@@ -137,8 +146,9 @@ public class BTeacherServiceImpl implements BTeacherService {
value[2] = ""; value[2] = "";
//1. 添加user //1. 添加user
SysUser user = new SysUser(value[0], passwordEncoder.encode(global.getDEFAULT_PASSWORD()), value[1], value[2]); //号,密码,姓名,性别; SysUser user = new SysUser(value[0], passwordEncoder.encode(global.getDEFAULT_PASSWORD()), value[1], value[2]); //教师工号,密码,姓名,性别;
user.setEmail(value[3]); user.setEmail(value[3]);
user.setAgencyCode(value[4]);//教学单位编号
UserUtil.setCurrentPersistOperation(user); UserUtil.setCurrentPersistOperation(user);
//2 创建gitlab账户 //2 创建gitlab账户
/*GitUser gitUser = new GitUser(); /*GitUser gitUser = new GitUser();
...@@ -188,6 +198,9 @@ public class BTeacherServiceImpl implements BTeacherService { ...@@ -188,6 +198,9 @@ public class BTeacherServiceImpl implements BTeacherService {
if(valuesEmailExist.size()>0){ if(valuesEmailExist.size()>0){
result+="以下教师邮箱已注册或格式不正确:"+ JSON.toJSONString(valuesEmailExist)+"。"; result+="以下教师邮箱已注册或格式不正确:"+ JSON.toJSONString(valuesEmailExist)+"。";
} }
if (valuesAgencyExist.size()>0){
result+="以下教师的所属教学单位不存在:"+JSON.toJSONString(valuesAgencyExist)+"。";
}
if (valuesOK.size()<1){ if (valuesOK.size()<1){
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DB_INSERT_ERROR.getCode(),result); throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DB_INSERT_ERROR.getCode(),result);
...@@ -227,13 +240,13 @@ public class BTeacherServiceImpl implements BTeacherService { ...@@ -227,13 +240,13 @@ public class BTeacherServiceImpl implements BTeacherService {
BeanUtils.copyProperties((DataEntity) model, (DataEntity) user); BeanUtils.copyProperties((DataEntity) model, (DataEntity) user);
if (model.getBusinessId() == null) { if (model.getBusinessId() == null) {
if (sysUserMapper.selectOne(new SysUser(model.getCode(),"0","1")) != null) if (sysUserMapper.selectOne(new SysUser(model.getCode(),"0","1")) != null)
throw new ServiceException(ResultServiceEnums.TEACHER_EXISTS); {throw new ServiceException(ResultServiceEnums.TEACHER_EXISTS);}
SysUser user1 = new SysUser(); SysUser user1 = new SysUser();
user1.setEmail(model.getEmail()); user1.setEmail(model.getEmail());
user1.setDelFlag("0"); user1.setDelFlag("0");
user1.setFlag("1"); user1.setFlag("1");
if(sysUserMapper.selectOne(user1)!=null) if(sysUserMapper.selectOne(user1)!=null)
throw new ServiceException(ResultServiceEnums.EMAIL_EXISTS); {throw new ServiceException(ResultServiceEnums.EMAIL_EXISTS);}
//1添加用户 //1添加用户
user.setHeadPic(global.getDEFAULT_TEACHER_LOCATION()); user.setHeadPic(global.getDEFAULT_TEACHER_LOCATION());
UserUtil.setCurrentPersistOperation(user); UserUtil.setCurrentPersistOperation(user);
...@@ -249,13 +262,13 @@ public class BTeacherServiceImpl implements BTeacherService { ...@@ -249,13 +262,13 @@ public class BTeacherServiceImpl implements BTeacherService {
line = bTeacherRepository.insertSelective(model); line = bTeacherRepository.insertSelective(model);
if (line1 != line) if (line1 != line)
throw new ServiceException(ResultServiceEnums.INSERT_ERROR); {throw new ServiceException(ResultServiceEnums.INSERT_ERROR);}
} else { } else {
UserUtil.setCurrentMergeOperation(model); UserUtil.setCurrentMergeOperation(model);
line = bTeacherRepository.updateByPrimaryKeySelective(model); line = bTeacherRepository.updateByPrimaryKeySelective(model);
String uid = sysUserMapper.selectUserIdByStuOrTeaId(model.getBusinessId(), "b_teacher"); String uid = sysUserMapper.selectUserIdByStuOrTeaId(model.getBusinessId(), "b_teacher");
if (uid == null) if (uid == null)
throw new ServiceException(ResultServiceEnums.STUDENT_NOT_EXISTS); {throw new ServiceException(ResultServiceEnums.STUDENT_NOT_EXISTS);}
userService.updateUser(user,uid,line); userService.updateUser(user,uid,line);
} }
return new PersistModel(line); return new PersistModel(line);
...@@ -264,13 +277,13 @@ public class BTeacherServiceImpl implements BTeacherService { ...@@ -264,13 +277,13 @@ public class BTeacherServiceImpl implements BTeacherService {
private Map<String, Object> queryParamHandler(BTeacher model) { private Map<String, Object> queryParamHandler(BTeacher model) {
Map param = new HashMap<String, Object>(); Map param = new HashMap<String, Object>();
if (model.getName() != null) if (model.getName() != null)
param.put("name", "%" + model.getName() + "%"); {param.put("name", "%" + model.getName() + "%");}
else else
param.put("name", "%%"); {param.put("name", "%%");}
if (model.getCode() != null) if (model.getCode() != null)
param.put("code", "%" + model.getCode() + "%"); {param.put("code", "%" + model.getCode() + "%");}
else else
param.put("code", "%%"); {param.put("code", "%%");}
param.put("teacherCode", model.getTeacherCode()); param.put("teacherCode", model.getTeacherCode());
return param; return param;
} }
......
...@@ -2,6 +2,7 @@ package org.rcisoft.sys.user.dao; ...@@ -2,6 +2,7 @@ package org.rcisoft.sys.user.dao;
import org.apache.ibatis.annotations.*; import org.apache.ibatis.annotations.*;
import org.rcisoft.business.bagency.entity.BAgency;
import org.rcisoft.core.base.BaseMapper; import org.rcisoft.core.base.BaseMapper;
import org.rcisoft.sys.user.entity.SysUser; import org.rcisoft.sys.user.entity.SysUser;
import org.rcisoft.sys.user.entity.UserRole; import org.rcisoft.sys.user.entity.UserRole;
...@@ -25,9 +26,9 @@ public interface SysUserMapper extends BaseMapper<SysUser> { ...@@ -25,9 +26,9 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
List<SysUser> queryUserByName(String username); List<SysUser> queryUserByName(String username);
@Insert("<script>INSERT INTO s_user" + @Insert("<script>INSERT INTO s_user" +
"(create_date,update_date,create_by,update_by,remarks,del_flag,flag,business_id,login_name,password,name,sex,git_lab_id,git_lab_username,git_lab_impression_token,head_pic,email)VALUES" + "(create_date,update_date,create_by,update_by,remarks,del_flag,flag,business_id,login_name,password,name,sex,git_lab_id,git_lab_username,git_lab_impression_token,head_pic,email,agency_code)VALUES" +
"<foreach collection=\"list\" item=\"item\" separator=\",\">" + "<foreach collection=\"list\" item=\"item\" separator=\",\">" +
"( #{item.createDate},#{item.updateDate},#{item.createBy},#{item.updateBy},#{item.remarks},#{item.delFlag},#{item.flag},#{item.businessId},#{item.loginName},#{item.password},#{item.name},#{item.sex},#{item.gitLabId},#{item.gitLabUsername},#{item.gitLabImpressionToken},#{item.headPic},#{item.email})" + "( #{item.createDate},#{item.updateDate},#{item.createBy},#{item.updateBy},#{item.remarks},#{item.delFlag},#{item.flag},#{item.businessId},#{item.loginName},#{item.password},#{item.name},#{item.sex},#{item.gitLabId},#{item.gitLabUsername},#{item.gitLabImpressionToken},#{item.headPic},#{item.email},#{item.agencyCode})" +
"</foreach></script>") "</foreach></script>")
int insertList(List<SysUser> users); int insertList(List<SysUser> users);
...@@ -82,4 +83,8 @@ public interface SysUserMapper extends BaseMapper<SysUser> { ...@@ -82,4 +83,8 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
@Select("<script>select agency_code from s_user where business_id = #{businessId}</script>") @Select("<script>select agency_code from s_user where business_id = #{businessId}</script>")
String queryAgencyCodeByBusinessId(String businessId); String queryAgencyCodeByBusinessId(String businessId);
@Select("select * from b_agency where code = #{agencyCode} and del_flag = 0 and flag = 1")
List<BAgency> checkTeacherAgency(SysUser sysUser);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment