|
@@ -8,6 +8,10 @@ import java.util.List;
|
|
|
|
|
|
import cn.com.qmth.examcloud.service.core.dto.OrgDto;
|
|
|
import cn.com.qmth.examcloud.service.core.entity.ExamSite;
|
|
|
+import cn.com.qmth.examcloud.service.core.entity.UserRole;
|
|
|
+import cn.com.qmth.examcloud.service.core.enums.UserScope;
|
|
|
+import cn.com.qmth.examcloud.service.core.enums.UserType;
|
|
|
+import cn.com.qmth.examcloud.service.core.params.UserParam;
|
|
|
import cn.com.qmth.examcloud.service.core.repo.ExamSiteRepo;
|
|
|
import cn.com.qmth.examcloud.service.core.service.sync.DataSendService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -41,7 +45,7 @@ public class OrgService {
|
|
|
|
|
|
@Autowired
|
|
|
DataSendService dataSendService;
|
|
|
-
|
|
|
+
|
|
|
@Transactional
|
|
|
public List<ExcelError> importLearnCenter(Long orgId, InputStream inputStream) {
|
|
|
ExcelReader excelReader = new ExcelReader(OrgDto.class);
|
|
@@ -61,15 +65,20 @@ public class OrgService {
|
|
|
return excelErrors;
|
|
|
}
|
|
|
|
|
|
- private void saveOrgAndExamSite(OrgDto orgDto){
|
|
|
- Org org = orgRepo.findFirstByParentIdAndCode(orgDto.getParentId(),orgDto.getCode());
|
|
|
- if(org == null){
|
|
|
+ /**
|
|
|
+ * 保存学习中心和考点
|
|
|
+ * @param orgDto
|
|
|
+ */
|
|
|
+ private void saveOrgAndExamSite(OrgDto orgDto) {
|
|
|
+ Org org = orgRepo.findFirstByParentIdAndCode(orgDto.getParentId(), orgDto.getCode());
|
|
|
+ if (org == null) {
|
|
|
|
|
|
Org tempOrg = orgRepo.save(orgAssembler(orgDto));
|
|
|
orgDto.setId(tempOrg.getId());
|
|
|
examSiteRepo.save(examSiteAssembler(orgDto));
|
|
|
+ createOrgUser(tempOrg);
|
|
|
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
|
|
|
org.setName(orgDto.getName());
|
|
|
org.setContacts(orgDto.getContacts());
|
|
@@ -77,10 +86,10 @@ public class OrgService {
|
|
|
orgRepo.save(org);
|
|
|
|
|
|
orgDto.setId(org.getId());
|
|
|
- ExamSite examSite = examSiteRepo.findFirstByOrgIdAndCode(org.getId(),orgDto.getExamSiteCode());
|
|
|
- if(examSite == null){
|
|
|
+ ExamSite examSite = examSiteRepo.findFirstByOrgIdAndCode(org.getId(), orgDto.getExamSiteCode());
|
|
|
+ if (examSite == null) {
|
|
|
examSiteRepo.save(examSiteAssembler(orgDto));
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
examSite.setName(orgDto.getExamSiteName());
|
|
|
examSite.setContacts(orgDto.getContacts());
|
|
|
examSite.setTelphone(orgDto.getTelphone());
|
|
@@ -90,6 +99,22 @@ public class OrgService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 创建学习中心用户
|
|
|
+ * @param tempOrg
|
|
|
+ */
|
|
|
+ private void createOrgUser(Org tempOrg){
|
|
|
+ User user = new User(tempOrg.getName(), UserScope.ORG, tempOrg.getRootId(), tempOrg.getParentId(), UserType.NOT_STUDENT);
|
|
|
+ user.setLoginName(tempOrg.getCode());
|
|
|
+ user.setEnable(true);
|
|
|
+ user.setCreateTime(new Date());
|
|
|
+ user.setPassword(UserParam.DEFAULT_PASSWORD);
|
|
|
+ List<UserRole> userRoles = new ArrayList<UserRole>();
|
|
|
+ userRoles.add(new UserRole("ecs_exam_work", "LC_USER"));
|
|
|
+ user.setUserRoles(userRoles);
|
|
|
+ userRepo.save(user);
|
|
|
+ }
|
|
|
+
|
|
|
private Org orgAssembler(OrgDto orgDto){
|
|
|
Org org = new Org();
|
|
|
org.setRootId(orgDto.getRootId());
|
|
@@ -116,22 +141,22 @@ public class OrgService {
|
|
|
}
|
|
|
|
|
|
private ExcelError importCheck(OrgDto dto) {
|
|
|
- if(StringUtils.isEmpty(dto.getCode())){
|
|
|
+ if(StringUtils.isBlank(dto.getCode())){
|
|
|
return new ExcelError("中心代码不能为空");
|
|
|
}
|
|
|
- if(StringUtils.isEmpty(dto.getName())){
|
|
|
+ if(StringUtils.isBlank(dto.getName())){
|
|
|
return new ExcelError("中心名称不能为空");
|
|
|
}
|
|
|
- if(StringUtils.isEmpty(dto.getExamSiteCode())){
|
|
|
+ if(StringUtils.isBlank(dto.getExamSiteCode())){
|
|
|
return new ExcelError("考点代码不能为空");
|
|
|
}
|
|
|
- if(StringUtils.isEmpty(dto.getExamSiteName())){
|
|
|
+ if(StringUtils.isBlank(dto.getExamSiteName())){
|
|
|
return new ExcelError("考点名称不能为空");
|
|
|
}
|
|
|
- if(StringUtils.isEmpty(dto.getContacts())){
|
|
|
+ if(StringUtils.isBlank(dto.getContacts())){
|
|
|
return new ExcelError("联系人不能为空");
|
|
|
}
|
|
|
- if(StringUtils.isEmpty(dto.getTelphone())){
|
|
|
+ if(StringUtils.isBlank(dto.getTelphone())){
|
|
|
return new ExcelError("联系电话不能为空");
|
|
|
}
|
|
|
return null;
|