wangwei 6 anni fa
parent
commit
e65cfa3022

+ 23 - 4
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/OrgController.java

@@ -131,6 +131,7 @@ public class OrgController extends ControllerSupport {
 			d.setRemark(next.getRemark());
 			d.setRootId(next.getRootId());
 			d.setTelephone(next.getTelephone());
+			d.setDomainName(next.getDomainName());
 		}
 
 		PageInfo<OrgDomain> ret = new PageInfo<OrgDomain>();
@@ -368,7 +369,7 @@ public class OrgController extends ControllerSupport {
 	@ApiOperation(value = "新增顶级机构", notes = "新增")
 	@PostMapping("addRootOrg")
 	public OrgEntity addRootOrg(@RequestBody OrgDomain domain) {
-		trim(domain);
+		trim(domain, true);
 
 		if (!isSuperAdmin()) {
 			throw new StatusException("B-140001", "非法访问");
@@ -405,7 +406,7 @@ public class OrgController extends ControllerSupport {
 	@ApiOperation(value = "更新顶级机构", notes = "更新")
 	@PutMapping("updateRootOrg")
 	public OrgEntity updateRootOrg(@RequestBody OrgDomain domain) {
-		trim(domain);
+		trim(domain, true);
 
 		if (!isSuperAdmin()) {
 			throw new StatusException("B-140001", "非法访问");
@@ -419,6 +420,12 @@ public class OrgController extends ControllerSupport {
 		info.setDomainName(domain.getDomainName());
 		info.setRemark(domain.getRemark());
 
+		Map<String, String> properties = domain.getProperties();
+		if (null == properties) {
+			properties = Maps.newHashMap();
+		}
+		info.setProperties(properties);
+
 		OrgEntity saved = orgService.saveRootOrg(info);
 		return saved;
 	}
@@ -433,7 +440,7 @@ public class OrgController extends ControllerSupport {
 	@ApiOperation(value = "新增子机构", notes = "新增")
 	@PostMapping("addSubOrg")
 	public OrgEntity addSubOrg(@RequestBody OrgDomain domain) {
-		trim(domain);
+		trim(domain, true);
 
 		User accessUser = getAccessUser();
 
@@ -451,6 +458,12 @@ public class OrgController extends ControllerSupport {
 		info.setRootId(accessUser.getRootOrgId());
 		info.setRemark(domain.getRemark());
 
+		Map<String, String> properties = domain.getProperties();
+		if (null == properties) {
+			properties = Maps.newHashMap();
+		}
+		info.setProperties(properties);
+
 		OrgEntity saved = orgService.saveSubOrg(info);
 		return saved;
 	}
@@ -465,7 +478,7 @@ public class OrgController extends ControllerSupport {
 	@ApiOperation(value = "更新子机构", notes = "更新")
 	@PutMapping("updateSubOrg")
 	public OrgEntity updateSubOrg(@RequestBody OrgDomain domain) {
-		trim(domain);
+		trim(domain, true);
 
 		User accessUser = getAccessUser();
 
@@ -483,6 +496,12 @@ public class OrgController extends ControllerSupport {
 		info.setRootId(accessUser.getRootOrgId());
 		info.setRemark(domain.getRemark());
 
+		Map<String, String> properties = domain.getProperties();
+		if (null == properties) {
+			properties = Maps.newHashMap();
+		}
+		info.setProperties(properties);
+
 		OrgEntity saved = orgService.saveSubOrg(info);
 		return saved;
 	}

+ 77 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/OrgServiceImpl.java

@@ -4,6 +4,8 @@ import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatc
 
 import java.io.InputStream;
 import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -13,23 +15,29 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
 
 import cn.com.qmth.examcloud.commons.base.exception.StatusException;
+import cn.com.qmth.examcloud.commons.base.helpers.DynamicEnum;
+import cn.com.qmth.examcloud.commons.base.helpers.DynamicEnumManager;
 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.base.constants.BasicConsts;
 import cn.com.qmth.examcloud.core.basic.dao.ExamSiteRepo;
+import cn.com.qmth.examcloud.core.basic.dao.OrgPropertyRepo;
 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.entity.ExamSite;
 import cn.com.qmth.examcloud.core.basic.dao.entity.OrgEntity;
+import cn.com.qmth.examcloud.core.basic.dao.entity.OrgPropertyEntity;
 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.OrgProperty;
 import cn.com.qmth.examcloud.core.basic.service.OrgService;
 import cn.com.qmth.examcloud.core.basic.service.bean.OrgDto;
 import cn.com.qmth.examcloud.core.basic.service.bean.OrgInfo;
@@ -52,6 +60,9 @@ public class OrgServiceImpl implements OrgService {
 	@Autowired
 	UserRoleRelationRepo userRoleRelationRepo;
 
+	@Autowired
+	OrgPropertyRepo orgPropertyRepo;
+
 	@Transactional
 	public List<ExcelError> importLearnCenter(Long orgId, InputStream inputStream) {
 		ExcelReader excelReader = new ExcelReader(OrgDto.class);
@@ -213,6 +224,7 @@ public class OrgServiceImpl implements OrgService {
 		String telephone = orgInfo.getTelephone();
 		String domainName = orgInfo.getDomainName();
 		String remark = orgInfo.getRemark();
+		Map<String, String> properties = orgInfo.getProperties();
 
 		if (StringUtils.isBlank(code)) {
 			throw new StatusException("B-150001", "code is null");
@@ -249,6 +261,22 @@ public class OrgServiceImpl implements OrgService {
 
 		OrgEntity saved = orgRepo.save(orgEntity);
 
+		Map<DynamicEnum, String> map = checkAndGetOrgProperties(properties);
+		for (Entry<DynamicEnum, String> entry : map.entrySet()) {
+			DynamicEnum de = entry.getKey();
+			String value = entry.getValue();
+			OrgPropertyEntity entity = orgPropertyRepo.findByOrgIdAndKeyId(saved.getId(),
+					de.getId());
+			if (null == entity) {
+				entity = new OrgPropertyEntity();
+				entity.setOrgId(saved.getId());
+				entity.setKeyId(de.getId());
+			}
+			entity.setValue(value);
+
+			orgPropertyRepo.save(entity);
+		}
+
 		return saved;
 	}
 
@@ -272,6 +300,7 @@ public class OrgServiceImpl implements OrgService {
 		Long rootId = orgInfo.getRootId();
 		Long parentId = orgInfo.getParentId();
 		String remark = orgInfo.getRemark();
+		Map<String, String> properties = orgInfo.getProperties();
 
 		if (null == enable) {
 			enable = true;
@@ -322,7 +351,55 @@ public class OrgServiceImpl implements OrgService {
 
 		OrgEntity saved = orgRepo.save(orgEntity);
 
+		Map<DynamicEnum, String> map = checkAndGetOrgProperties(properties);
+		for (Entry<DynamicEnum, String> entry : map.entrySet()) {
+			DynamicEnum de = entry.getKey();
+			String value = entry.getValue();
+			OrgPropertyEntity entity = orgPropertyRepo.findByOrgIdAndKeyId(saved.getId(),
+					de.getId());
+			if (null == entity) {
+				entity = new OrgPropertyEntity();
+				entity.setOrgId(saved.getId());
+				entity.setKeyId(de.getId());
+			}
+			entity.setValue(value);
+
+			orgPropertyRepo.save(entity);
+		}
+
 		return saved;
 	}
 
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param properties
+	 * @return
+	 */
+	private Map<DynamicEnum, String> checkAndGetOrgProperties(Map<String, String> properties) {
+		DynamicEnumManager manager = OrgProperty.getDynamicEnumManager();
+
+		Map<DynamicEnum, String> map = Maps.newHashMap();
+		if (null == properties) {
+			return map;
+		}
+		for (Entry<String, String> entry : properties.entrySet()) {
+			String key = entry.getKey();
+			String value = entry.getValue();
+			if (StringUtils.isBlank(value)) {
+				continue;
+			}
+			DynamicEnum de = null;
+			try {
+				de = manager.getByName(key);
+			} catch (Exception e) {
+				throw new StatusException("E-001004", "机构属性错误");
+			}
+			map.put(de, value.trim());
+		}
+
+		return map;
+	}
+
 }