|
@@ -1,9 +1,19 @@
|
|
|
package cn.com.qmth.examcloud.service.core.service;
|
|
|
|
|
|
-import cn.com.qmth.examcloud.service.core.repo.OrgRepo;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.common.util.excel.ExcelError;
|
|
|
+import cn.com.qmth.examcloud.common.util.excel.ExcelReader;
|
|
|
+import cn.com.qmth.examcloud.common.util.excel.ExcelReaderHandle;
|
|
|
+import cn.com.qmth.examcloud.service.core.entity.Org;
|
|
|
+import cn.com.qmth.examcloud.service.core.repo.OrgRepo;
|
|
|
+
|
|
|
/**
|
|
|
* 学校服务类
|
|
|
* Created by songyue on 17/1/14.
|
|
@@ -14,5 +24,36 @@ public class OrgService {
|
|
|
@Autowired
|
|
|
OrgRepo orgRepo;
|
|
|
|
|
|
+ public List<ExcelError> importLearnCenter(Long orgId, InputStream inputStream) {
|
|
|
+ List<Org> list = new ArrayList<Org>();
|
|
|
+ Org parentOrg = orgRepo.findById(orgId);
|
|
|
+ ExcelReader excelReader = new ExcelReader(Org.class);
|
|
|
+ List<ExcelError> excelErrors = excelReader.reader(inputStream, new ExcelReaderHandle() {
|
|
|
+ @Override
|
|
|
+ public ExcelError handle(Object obj) {
|
|
|
+ Org dto = (Org) obj;
|
|
|
+ dto.setRootId(orgId);
|
|
|
+ dto.setParentId(orgId);
|
|
|
+ dto.setApps(parentOrg.getApps());
|
|
|
+ dto.setCreateTime(new Date());
|
|
|
+ dto.setEnable(true);
|
|
|
+ ExcelError error = importCheck(dto);
|
|
|
+ if (error == null) {
|
|
|
+ list.add(dto);
|
|
|
+ }
|
|
|
+ return error;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ orgRepo.save(list);
|
|
|
+ return excelErrors;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ExcelError importCheck(Org dto) {
|
|
|
+ Org org = orgRepo.findByParentIdAndCode(dto.getParentId(),dto.getCode());
|
|
|
+ if(org!=null){
|
|
|
+ return new ExcelError("代码已存在");
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
}
|