Commit 4496d0de authored by 刘子正's avatar 刘子正

班级导入分为企业版和行政班

parent 38a6912c
......@@ -72,7 +72,7 @@ public class BClassController extends PaginationController<BClass> {
MessageConstant.MESSAGE_ALERT_ERROR,
id);
}
/**
@ApiOperation(value="excel导入", notes="上传excel到服务器")
@ApiImplicitParam(name = "importFile", value = "excel文件", required = true, dataType = "MultipartFile")
@PreAuthorize("hasRole('ROLE_1001')")
......@@ -84,6 +84,31 @@ public class BClassController extends PaginationController<BClass> {
MessageConstant.MESSAGE_ALERT_ERROR,
null);
}
*/
@ApiOperation(value="行政班excel导入", notes="上传excel到服务器")
@ApiImplicitParam(name = "importFile", value = "excel文件", required = true, dataType = "MultipartFile")
@PreAuthorize("hasRole('ROLE_1001')")
@PostMapping(value = "administrativeExcelImport")
public Result administrativeExcelImport(MultipartFile importFile, String token) throws Exception {
PersistModel data = bClassService.administrativeImportExcel(MultipartFile2HSSFWorkbookConverter.convert(importFile),token);
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
null);
}
@ApiOperation(value="企业班excel导入", notes="上传excel到服务器")
@ApiImplicitParam(name = "importFile", value = "excel文件", required = true, dataType = "MultipartFile")
@PreAuthorize("hasRole('ROLE_1001')")
@PostMapping(value = "businessExcelImport")
public Result businessExcelImport(MultipartFile importFile, String token) throws Exception {
PersistModel data = bClassService.businessImportExcel(MultipartFile2HSSFWorkbookConverter.convert(importFile),token);
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
null);
}
@ApiOperation(value="唯一查找", notes="根据ID查找一条记录")
@ApiImplicitParam(name = "businessId", value = "businessId", required = true, dataType = "varchar")
......
......@@ -37,17 +37,27 @@ public interface BClassRepository extends BaseMapper<BClass> {
@Insert("<script>INSERT INTO b_class" +
"(create_date,update_date,del_flag,flag,business_id,code,class_name)VALUES" +
"(create_date,update_date,del_flag,flag,business_id,code,class_name,grade_code)VALUES" +
"<foreach collection=\"list\" item=\"item\" separator=\",\">" +
"( #{item.createDate},#{item.updateDate},#{item.delFlag},#{item.flag},#{item.businessId},#{item.code},#{item.className})" +
"( #{item.createDate},#{item.updateDate},#{item.delFlag},#{item.flag},#{item.businessId},#{item.code},#{item.className},#{item.gradeCode})" +
"</foreach></script>")
int insertList(List<BClass> bClasses);
@Insert("<script>INSERT INTO b_class" +
"(create_date,update_date,del_flag,flag,business_id,code,class_name,grade_code,type,agency_code)VALUES" +
"<foreach collection=\"list\" item=\"item\" separator=\",\">" +
"( #{item.createDate},#{item.updateDate},#{item.delFlag},#{item.flag},#{item.businessId},#{item.code},#{item.className},#{item.gradeCode},#{item.type},#{item.agencyCode})" +
"</foreach></script>")
int insertBusinessClassList(List<BClass> bClasses);
@Select("select * from b_class where del_flag != 1 and flag = 1")
@ResultMap(value = "BaseResultMap" )
List<BClass> queryBClassList();
@Select("select class_name from b_class where find_in_set(code,#{classesCode}) and del_flag != 1 and flag = 1")
List<String> queryClassNamesByIds(String classesCode);
@Select("select * from b_grade where code = #{gradeCode} and del_flag = 0 and flag = 1")
List<BClass> checkGrade(BClass bClass);
}
......@@ -51,11 +51,29 @@ public interface BClassService{
PersistModel removeBClass(String id);
/**
* 班级信息excel导入
* excel导入
* @param
* @return
*/
// PersistModel importExcel(HSSFWorkbook hwb, String token) throws IOException;
/**
* 行政班excel导入
* @param hwb
* @param token
* @return
* @throws IOException
*/
PersistModel administrativeImportExcel(HSSFWorkbook hwb, String token) throws IOException;
/**
* 企业版excel导入
* @param hwb
* @param token
* @return
* @throws IOException
*/
PersistModel importExcel(HSSFWorkbook hwb, String token) throws IOException;
PersistModel businessImportExcel(HSSFWorkbook hwb, String token) throws IOException;
List<SelectModel> queryBClassList();
}
......@@ -6,6 +6,7 @@ import org.rcisoft.business.bclass.dao.BClassRepository;
import org.rcisoft.business.bclass.entity.BClass;
import org.rcisoft.business.bclass.service.BClassService;
import org.rcisoft.business.brclassstudent.dao.BRClassStudentRepository;
import org.rcisoft.business.bstudent.entity.BStudent;
import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.exception.ServiceException;
......@@ -78,14 +79,70 @@ public class BClassServiceImpl implements BClassService {
return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS);
}
/**
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
@Override
public PersistModel importExcel(HSSFWorkbook hwb, String token) throws IOException {
ArrayList<BClass> bClasses = new ArrayList<BClass>();
ArrayList<String> repeatCode = new ArrayList<String>();
String[] headers = {"班级编号","班级名称"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers,false); //获取excel数据
if (values.size()<=0){
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST);
}
for(String[] value:values){ //将数据封装到entity
BClass bClass = null;
BClass b = new BClass(value[0]);
if(value[0]==null||value[0].equals("")||value[1]==null||value[1].equals("")){
continue;
}
if((bClass=bClassRepository.selectOne(b))!=null) {
repeatCode.add(value[0]);
continue;
}
bClass= new BClass(value[0],value[1]);
bClass.setCommonBusinessId();
UserUtil.setCurrentPersistOperation(bClass);
if(!bClasses.contains(bClass)){
bClasses.add(bClass);
}
}
if(bClasses.size()<1){
if(repeatCode.size()<1)
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST);
else
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST.getCode(),"Excel内所有数据之前都已经导入:"+ JSON.toJSONString(repeatCode));
}
String result = ExcelUtil.checkRepeat(repeatCode);
int line = bClassRepository.insertList(bClasses);
return new PersistModel(line,result);
}
*/
/**
* 行政班导入
* @param hwb
* @param token
* @return
* @throws IOException
*/
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
@Override
public PersistModel importExcel(HSSFWorkbook hwb, String token) throws IOException {
public PersistModel administrativeImportExcel(HSSFWorkbook hwb, String token) throws IOException {
ArrayList<BClass> bClasses = new ArrayList<BClass>();
ArrayList<String> repeatCode = new ArrayList<String>();
String[] headers = {"班级编号","班级名称"};
String[] headers = {"班级编号","班级名称","所属年级"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers,false); //获取excel数据
//判断年级是否存在
List<String> valuesGrade = new ArrayList<>();
if (values.size()<=0){
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST);
......@@ -101,7 +158,16 @@ public class BClassServiceImpl implements BClassService {
repeatCode.add(value[0]);
continue;
}
//判断:学年是否存在,存在才能录入
BClass b1 = new BClass();
b1.setGradeCode(value[2]);
if (bClassRepository.checkGrade(b1).size() == 0){
valuesGrade.add(value[2]);
continue;
}
bClass= new BClass(value[0],value[1]);
bClass.setGradeCode(value[2]);
bClass.setCommonBusinessId();
UserUtil.setCurrentPersistOperation(bClass);
......@@ -120,6 +186,71 @@ public class BClassServiceImpl implements BClassService {
String result = ExcelUtil.checkRepeat(repeatCode);
int line = bClassRepository.insertList(bClasses);
if(valuesGrade.size()>0){
result+="以下班级的所属年级信息不存在:"+ JSON.toJSONString(valuesGrade)+"。";
}
return new PersistModel(line,result);
}
@Override
public PersistModel businessImportExcel(HSSFWorkbook hwb, String token) {
ArrayList<BClass> bClasses = new ArrayList<BClass>();
ArrayList<String> repeatCode = new ArrayList<String>();
String[] headers = {"班级编号","班级名称","所属年级","教学单位"};
ArrayList<String[]> values = ExcelUtil.importExcel(hwb,headers,false); //获取excel数据
//判断年级是否存在
List<String> valuesGrade = new ArrayList<>();
if (values.size()<=0){
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST);
}
for(String[] value:values){ //将数据封装到entity
BClass bClass = null;
BClass b = new BClass(value[0]);
if(value[0]==null||value[0].equals("")||value[1]==null||value[1].equals("")){
continue;
}
if((bClass=bClassRepository.selectOne(b))!=null) {
repeatCode.add(value[0]);
continue;
}
//判断:学年是否存在,存在才能录入
BClass b1 = new BClass();
b1.setGradeCode(value[2]);
if (bClassRepository.checkGrade(b1).size() == 0){
valuesGrade.add(value[2]);
continue;
}
bClass= new BClass(value[0],value[1]);
bClass.setGradeCode(value[2]);
bClass.setAgencyCode(value[3]);
bClass.setType("1");
bClass.setCommonBusinessId();
UserUtil.setCurrentPersistOperation(bClass);
if(!bClasses.contains(bClass)){
bClasses.add(bClass);
}
}
if(bClasses.size()<1){
if(repeatCode.size()<1)
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST);
else
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DATA_NOT_EXIST.getCode(),"Excel内所有数据之前都已经导入:"+ JSON.toJSONString(repeatCode));
}
String result = ExcelUtil.checkRepeat(repeatCode);
int line = bClassRepository.insertBusinessClassList(bClasses);
if(valuesGrade.size()>0){
result+="以下班级的所属年级信息不存在:"+ JSON.toJSONString(valuesGrade)+"。";
}
return new PersistModel(line,result);
}
......
......@@ -4,6 +4,7 @@ import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.rcisoft.business.bclass.entity.BClass;
import org.rcisoft.business.bstudent.entity.BStudent;
import org.rcisoft.business.bstudent.entity.BStudentDto;
import org.rcisoft.core.base.BaseMapper;
......@@ -166,7 +167,7 @@ public interface BStudentRepository extends BaseMapper<BStudent> {
List<BStudent> queryStudentsByClassCode(String classCode);
@Select("select * from b_grade where code = #{gradeCode} and del_flag = 0 and flag = 1")
List<BStudent> checkStudentGrade(BStudent bStudent);
List<BClass> checkStudentGrade(BStudent bStudent);
}
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