|
@@ -19,23 +19,34 @@ import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+
|
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
|
|
|
import cn.com.qmth.examcloud.commons.base.util.excel.ExcelReader;
|
|
|
import cn.com.qmth.examcloud.commons.base.util.excel.ExcelReaderHandle;
|
|
|
+import cn.com.qmth.examcloud.commons.web.security.enums.RoleMeta;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.ExamSiteRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.OrgMemRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.RoleRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.UserRoleRelationRepo;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.constants.Consts;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.ExamSite;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.Org;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.RoleEntity;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.UserEntity;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.UserRoleRelationEntity;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.enums.OrgType;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.bean.OrgDto;
|
|
|
|
|
|
@Service
|
|
|
public class OrgService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ RoleRepo roleRepo;
|
|
|
+
|
|
|
@Autowired
|
|
|
OrgRepo orgRepo;
|
|
|
|
|
@@ -51,6 +62,9 @@ public class OrgService {
|
|
|
@Autowired
|
|
|
OrgMemRepo orgMemRepo;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ UserRoleRelationRepo userRoleRelationRepo;
|
|
|
+
|
|
|
@Transactional
|
|
|
public List<ExcelError> importLearnCenter(Long orgId, InputStream inputStream) {
|
|
|
ExcelReader excelReader = new ExcelReader(OrgDto.class);
|
|
@@ -78,10 +92,10 @@ public class OrgService {
|
|
|
private void saveOrgAndExamSite(OrgDto orgDto) {
|
|
|
Org org = orgRepo.findByParentIdAndCode(orgDto.getParentId(), orgDto.getCode());
|
|
|
if (org == null) {
|
|
|
-
|
|
|
Org tempOrg = orgRepo.save(orgAssembler(orgDto));
|
|
|
orgDto.setId(tempOrg.getId());
|
|
|
examSiteRepo.save(examSiteAssembler(orgDto));
|
|
|
+ createLeanCenterUser(tempOrg);
|
|
|
} else {
|
|
|
org.setName(orgDto.getName());
|
|
|
org.setContacts(orgDto.getContacts());
|
|
@@ -101,6 +115,29 @@ public class OrgService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 创建学习中心用户
|
|
|
+ *
|
|
|
+ * @param org
|
|
|
+ */
|
|
|
+ private void createLeanCenterUser(Org org) {
|
|
|
+ UserEntity user = userRepo.findByLoginName(org.getCode());
|
|
|
+ if (null != user) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ user = new UserEntity();
|
|
|
+ user.setLoginName(org.getCode());
|
|
|
+ user.setEnable(true);
|
|
|
+ user.setPassword(Consts.DEFAULT_PASSWORD);
|
|
|
+ UserEntity saved = userRepo.save(user);
|
|
|
+ List<UserRoleRelationEntity> userRoles = Lists.newArrayList();
|
|
|
+ RoleEntity role = roleRepo.findByCode(RoleMeta.LC_USER.name());
|
|
|
+ UserRoleRelationEntity relation = new UserRoleRelationEntity(saved.getId(), role.getId(),
|
|
|
+ role.getCode());
|
|
|
+ userRoles.add(relation);
|
|
|
+ userRoleRelationRepo.save(userRoles);
|
|
|
+ }
|
|
|
+
|
|
|
private Org orgAssembler(OrgDto orgDto) {
|
|
|
Org org = new Org();
|
|
|
org.setRootId(orgDto.getRootId());
|