|
@@ -0,0 +1,1406 @@
|
|
|
+package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.api.commons.exchange.PageInfo;
|
|
|
+import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
|
+import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.commons.helpers.DynamicEnum;
|
|
|
+import cn.com.qmth.examcloud.commons.helpers.DynamicEnumManager;
|
|
|
+import cn.com.qmth.examcloud.commons.util.JsonUtil;
|
|
|
+import cn.com.qmth.examcloud.commons.util.PathUtil;
|
|
|
+import cn.com.qmth.examcloud.commons.util.RegExpUtil;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.controller.bean.OrgDomain;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.controller.bean.SaveOrgPropertiesDomain;
|
|
|
+import cn.com.qmth.examcloud.core.basic.base.constants.SystemProps;
|
|
|
+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.entity.OrgEntity;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.OrgPropertyEntity;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.enums.OrgProperty;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.SystemPropertyService;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.bean.OrgInfo;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.cache.OrgCache;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.cache.RootOrgCache;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.cache.SystemPropertyCache;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.impl.OrgServiceImpl;
|
|
|
+import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.OrgCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.OrgPropertyCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.filestorage.FileStorageUtil;
|
|
|
+import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
|
|
|
+import cn.com.qmth.examcloud.task.api.request.SyncOrgReq;
|
|
|
+import cn.com.qmth.examcloud.web.config.SystemProperties;
|
|
|
+import cn.com.qmth.examcloud.web.filestorage.FileStoragePathEnvInfo;
|
|
|
+import cn.com.qmth.examcloud.web.filestorage.YunPathInfo;
|
|
|
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
+import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
|
+import cn.com.qmth.examcloud.web.support.ApiId;
|
|
|
+import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
+import cn.com.qmth.examcloud.web.support.Naked;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.codec.DecoderException;
|
|
|
+import org.apache.commons.codec.binary.Hex;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.fileupload.disk.DiskFileItem;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.domain.Sort.Direction;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
+
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+/**
|
|
|
+ * {@link StatusException} 状态码范围:001XXX<br>
|
|
|
+ * {@link ApiId}范围: 100-199<br>
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @date 2019年6月11日
|
|
|
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("${$rmp.ctr.basic}/org")
|
|
|
+public class OrgController extends ControllerSupport {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrgCache orgCache;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RootOrgCache rootOrgCache;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RedisClient redisClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrgRepo orgRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrgServiceImpl orgService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SystemProperties systemConfig;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrgPropertyRepo orgPropertyRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DataSyncCloudService dataSyncCloudService;
|
|
|
+
|
|
|
+// @Autowired
|
|
|
+// UpyunCloudService upyunCloudService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SystemPropertyCache systemPropertyCache;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SystemPropertyService systemPropertyService;
|
|
|
+
|
|
|
+ @ApiOperation(value = "分页查询所有机构")
|
|
|
+ @GetMapping("fullOrgPage/{curPage}/{pageSize}")
|
|
|
+ public PageInfo<OrgDomain> getFullOrgPage(@PathVariable Integer curPage,
|
|
|
+ @PathVariable Integer pageSize, @RequestParam(required = false) String code,
|
|
|
+ @RequestParam(required = false) String name,
|
|
|
+ @RequestParam(required = false) String propertyKeys) {
|
|
|
+
|
|
|
+ Pageable pageable = PageRequest.of(curPage, pageSize, Sort.Direction.DESC, "updateTime");
|
|
|
+
|
|
|
+ Specification<OrgEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(name)) {
|
|
|
+ predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(code)) {
|
|
|
+ predicates.add(cb.like(root.get("code"), toSqlSearchPattern(code)));
|
|
|
+ }
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ Page<OrgEntity> page = orgRepo.findAll(specification, pageable);
|
|
|
+ List<OrgDomain> list = Lists.newArrayList();
|
|
|
+ Iterator<OrgEntity> iterator = page.iterator();
|
|
|
+
|
|
|
+ List<String> propertyKeyList = null;
|
|
|
+ if (StringUtils.isNotBlank(propertyKeys)) {
|
|
|
+ propertyKeyList = RegExpUtil.findAll(propertyKeys, "\\w+");
|
|
|
+ }
|
|
|
+
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ OrgEntity next = iterator.next();
|
|
|
+ OrgDomain d = new OrgDomain();
|
|
|
+ list.add(d);
|
|
|
+
|
|
|
+ d.setCode(next.getCode());
|
|
|
+ d.setContacts(next.getContacts());
|
|
|
+ d.setEnable(next.getEnable());
|
|
|
+ d.setId(next.getId());
|
|
|
+ d.setName(next.getName());
|
|
|
+ d.setParentId(next.getParentId());
|
|
|
+ d.setRemark(next.getRemark());
|
|
|
+ d.setRootId(next.getRootId());
|
|
|
+ d.setTelephone(next.getTelephone());
|
|
|
+ d.setCreationTime(next.getCreationTime());
|
|
|
+ d.setUpdateTime(next.getUpdateTime());
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(propertyKeyList)) {
|
|
|
+ Map<String, String> properties = getProperties(d.getId(), propertyKeyList);
|
|
|
+ d.setProperties(properties);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ PageInfo<OrgDomain> ret = new PageInfo<OrgDomain>();
|
|
|
+ ret.setList(list);
|
|
|
+ ret.setTotal(page.getTotalElements());
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param curPage
|
|
|
+ * @param pageSize
|
|
|
+ * @param code
|
|
|
+ * @param domainName
|
|
|
+ * @param name
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "分页查询顶级机构")
|
|
|
+ @GetMapping("rootOrgPage/{curPage}/{pageSize}")
|
|
|
+ public PageInfo<OrgDomain> getRootOrgPage(@PathVariable Integer curPage,
|
|
|
+ @PathVariable Integer pageSize, @RequestParam(required = false) String code,
|
|
|
+ @RequestParam(required = false) String domainName,
|
|
|
+ @RequestParam(required = false) String name,
|
|
|
+ @RequestParam(required = false) String propertyKeys) {
|
|
|
+
|
|
|
+ Pageable pageable = PageRequest.of(curPage, pageSize, Sort.Direction.DESC, "updateTime");
|
|
|
+
|
|
|
+ Specification<OrgEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.isNull(root.get("parentId")));
|
|
|
+ if (StringUtils.isNotEmpty(name)) {
|
|
|
+ predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(code)) {
|
|
|
+ predicates.add(cb.like(root.get("code"), toSqlSearchPattern(code)));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(domainName)) {
|
|
|
+ predicates.add(cb.like(root.get("domainName"), toSqlSearchPattern(domainName)));
|
|
|
+ }
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ Page<OrgEntity> page = orgRepo.findAll(specification, pageable);
|
|
|
+ List<OrgDomain> list = Lists.newArrayList();
|
|
|
+ Iterator<OrgEntity> iterator = page.iterator();
|
|
|
+
|
|
|
+ List<String> propertyKeyList = null;
|
|
|
+ if (StringUtils.isNotBlank(propertyKeys)) {
|
|
|
+ propertyKeyList = RegExpUtil.findAll(propertyKeys, "\\w+");
|
|
|
+ }
|
|
|
+
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ OrgEntity next = iterator.next();
|
|
|
+ OrgDomain d = new OrgDomain();
|
|
|
+ list.add(d);
|
|
|
+
|
|
|
+ d.setCode(next.getCode());
|
|
|
+ d.setContacts(next.getContacts());
|
|
|
+ d.setEnable(next.getEnable());
|
|
|
+ d.setId(next.getId());
|
|
|
+ d.setName(next.getName());
|
|
|
+ d.setParentId(next.getParentId());
|
|
|
+ d.setRemark(next.getRemark());
|
|
|
+ d.setRootId(next.getRootId());
|
|
|
+ d.setTelephone(next.getTelephone());
|
|
|
+ d.setDomainName(next.getDomainName());
|
|
|
+ d.setCreationTime(next.getCreationTime());
|
|
|
+ d.setUpdateTime(next.getUpdateTime());
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(propertyKeyList)) {
|
|
|
+ Map<String, String> properties = getProperties(d.getId(), propertyKeyList);
|
|
|
+ d.setProperties(properties);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ PageInfo<OrgDomain> ret = new PageInfo<OrgDomain>();
|
|
|
+ ret.setList(list);
|
|
|
+ ret.setTotal(page.getTotalElements());
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param orgId
|
|
|
+ * @param propertyKeys
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, String> getProperties(Long orgId, List<String> propertyKeys) {
|
|
|
+ DynamicEnumManager manager = OrgProperty.getDynamicEnumManager();
|
|
|
+ Map<String, String> map = Maps.newHashMap();
|
|
|
+ for (String key : propertyKeys) {
|
|
|
+ DynamicEnum de = manager.getByName(key);
|
|
|
+ OrgPropertyEntity one = orgPropertyRepo.findByOrgIdAndKeyId(orgId, de.getId());
|
|
|
+ if (null != one) {
|
|
|
+ map.put(key, one.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param rootOrgId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "按ID查询顶级机构", notes = "ID查询")
|
|
|
+ @GetMapping("rootOrg/{rootOrgId}")
|
|
|
+ public OrgEntity getRootOrg(@PathVariable Long rootOrgId) {
|
|
|
+ OrgEntity orgEntity = GlobalHelper.getEntity(orgRepo, rootOrgId, OrgEntity.class);
|
|
|
+ if (null == orgEntity) {
|
|
|
+ throw new StatusException("001250", "rootOrgId is wrong");
|
|
|
+ }
|
|
|
+ if (null != orgEntity.getParentId()) {
|
|
|
+ throw new StatusException("001251", "rootOrgId is wrong");
|
|
|
+ }
|
|
|
+ validateRootOrgIsolation(orgEntity.getRootId());
|
|
|
+
|
|
|
+ return orgEntity;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param orgId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "按ID查询子机构", notes = "ID查询")
|
|
|
+ @GetMapping("subOrg/{orgId}")
|
|
|
+ public OrgEntity getSubOrg(@PathVariable Long orgId) {
|
|
|
+ OrgEntity orgEntity = GlobalHelper.getEntity(orgRepo, orgId, OrgEntity.class);
|
|
|
+ if (null == orgEntity) {
|
|
|
+ throw new StatusException("001250", "orgId is wrong");
|
|
|
+ }
|
|
|
+ if (null == orgEntity.getParentId()) {
|
|
|
+ throw new StatusException("001251", "orgId is wrong");
|
|
|
+ }
|
|
|
+ validateRootOrgIsolation(orgEntity.getRootId());
|
|
|
+
|
|
|
+ return orgEntity;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param code
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Naked
|
|
|
+ @ApiOperation(value = "查询顶级机构")
|
|
|
+ @GetMapping("getRootOrgByCode")
|
|
|
+ public OrgEntity getRootOrgByCode(@RequestParam("code") String code) {
|
|
|
+ OrgEntity org = orgRepo.findByParentIdIsNullAndCode(code);
|
|
|
+ return org;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Naked
|
|
|
+ @ApiOperation(value = "查询顶级机构")
|
|
|
+ @GetMapping("getRootOrgByDomain")
|
|
|
+ public Map<String, Object> getRootOrgByDomain(@RequestParam("domainName") String domainName) {
|
|
|
+ OrgEntity org = orgRepo.findByParentIdIsNullAndDomainName(domainName);
|
|
|
+ if (null == org) {
|
|
|
+ throw new StatusException("001259", "domainName is wrong");
|
|
|
+ }
|
|
|
+ Map<String, Object> map = Maps.newHashMap();
|
|
|
+ map.put("id", org.getId());
|
|
|
+ map.put("name", org.getName());
|
|
|
+ map.put("code", org.getCode());
|
|
|
+ map.put("enable", org.getEnable());
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param curPage
|
|
|
+ * @param pageSize
|
|
|
+ * @param parentId
|
|
|
+ * @param code
|
|
|
+ * @param name
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "分页查询子机构")
|
|
|
+ @GetMapping("subOrgPage/{curPage}/{pageSize}")
|
|
|
+ public PageInfo<OrgDomain> getSubOrgPage(@PathVariable Integer curPage,
|
|
|
+ @PathVariable Integer pageSize, @RequestParam(required = true) Long parentId,
|
|
|
+ @RequestParam(required = false) String code,
|
|
|
+ @RequestParam(required = false) String name,
|
|
|
+ @RequestParam(required = false) String propertyKeys) {
|
|
|
+
|
|
|
+ if (null == parentId) {
|
|
|
+ throw new StatusException("001249", "parentId is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ OrgEntity parentOrg = GlobalHelper.getEntity(orgRepo, parentId, OrgEntity.class);
|
|
|
+ if (null == parentOrg) {
|
|
|
+ throw new StatusException("001250", "parentId is wrong");
|
|
|
+ }
|
|
|
+ validateRootOrgIsolation(parentOrg.getRootId());
|
|
|
+
|
|
|
+ Pageable pageable = PageRequest.of(curPage, pageSize, Sort.Direction.DESC, "updateTime");
|
|
|
+
|
|
|
+ Specification<OrgEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.equal(root.get("parentId"), parentId));
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(name)) {
|
|
|
+ predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(code)) {
|
|
|
+ predicates.add(cb.like(root.get("code"), toSqlSearchPattern(code)));
|
|
|
+ }
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ Page<OrgEntity> page = orgRepo.findAll(specification, pageable);
|
|
|
+ List<OrgDomain> list = Lists.newArrayList();
|
|
|
+ Iterator<OrgEntity> iterator = page.iterator();
|
|
|
+
|
|
|
+ List<String> propertyKeyList = null;
|
|
|
+ if (StringUtils.isNotBlank(propertyKeys)) {
|
|
|
+ propertyKeyList = RegExpUtil.findAll(propertyKeys, "\\w+");
|
|
|
+ }
|
|
|
+
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ OrgEntity next = iterator.next();
|
|
|
+ OrgDomain d = new OrgDomain();
|
|
|
+ list.add(d);
|
|
|
+
|
|
|
+ d.setCode(next.getCode());
|
|
|
+ d.setContacts(next.getContacts());
|
|
|
+ d.setEnable(next.getEnable());
|
|
|
+ d.setId(next.getId());
|
|
|
+ d.setName(next.getName());
|
|
|
+ d.setParentId(next.getParentId());
|
|
|
+ d.setRemark(next.getRemark());
|
|
|
+ d.setRootId(next.getRootId());
|
|
|
+ d.setTelephone(next.getTelephone());
|
|
|
+ d.setCreationTime(next.getCreationTime());
|
|
|
+ d.setUpdateTime(next.getUpdateTime());
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(propertyKeyList)) {
|
|
|
+ Map<String, String> properties = getProperties(d.getId(), propertyKeyList);
|
|
|
+ d.setProperties(properties);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ PageInfo<OrgDomain> ret = new PageInfo<OrgDomain>();
|
|
|
+ ret.setList(list);
|
|
|
+ ret.setTotal(page.getTotalElements());
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param enable
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "查询顶级机构")
|
|
|
+ @GetMapping("getRootOrgList")
|
|
|
+ public List<OrgEntity> getRootOrgList(@RequestParam(required = false) Boolean enable) {
|
|
|
+
|
|
|
+ Specification<OrgEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.isNull(root.get("parentId")));
|
|
|
+ if (null != enable) {
|
|
|
+ predicates.add(cb.equal(root.get("enable"), enable));
|
|
|
+ }
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ List<OrgEntity> ret = orgRepo.findAll(specification);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param name
|
|
|
+ * @param rootOrgId
|
|
|
+ * @param enable
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "查询一级子机构列表")
|
|
|
+ @GetMapping("query")
|
|
|
+ public List<OrgEntity> querySubOrgList(@RequestParam(required = true) String name,
|
|
|
+ @RequestParam(required = false) Long rootOrgId,
|
|
|
+ @RequestParam(required = false) Boolean enable,
|
|
|
+ @RequestParam(required = false) Boolean returnEmptyWhenNameNull) {
|
|
|
+
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+ if (null == rootOrgId) {
|
|
|
+ rootOrgId = accessUser.getRootOrgId();
|
|
|
+ } else {
|
|
|
+ validateRootOrgIsolation(rootOrgId);
|
|
|
+ }
|
|
|
+
|
|
|
+ Long finalRootOrgId = rootOrgId;
|
|
|
+
|
|
|
+ if (null != returnEmptyWhenNameNull && returnEmptyWhenNameNull
|
|
|
+ && StringUtils.isBlank(name)) {
|
|
|
+ List<OrgEntity> list = Lists.newArrayList();
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ Specification<OrgEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.equal(root.get("rootId"), finalRootOrgId));
|
|
|
+ predicates.add(cb.isNotNull(root.get("parentId")));
|
|
|
+ if (StringUtils.isNotBlank(name)) {
|
|
|
+ Predicate pr1 = cb.like(root.get("name"), toSqlSearchPattern(name));
|
|
|
+ Predicate pr2 = cb.like(root.get("code"), toSqlSearchPattern(name));
|
|
|
+ predicates.add(cb.or(pr1, pr2));
|
|
|
+ }
|
|
|
+ if (null != enable) {
|
|
|
+ predicates.add(cb.equal(root.get("enable"), enable));
|
|
|
+ }
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ PageRequest pageRequest = PageRequest.of(0, 50, new Sort(Direction.DESC, "updateTime"));
|
|
|
+ Page<OrgEntity> page = orgRepo.findAll(specification, pageRequest);
|
|
|
+ Iterator<OrgEntity> iterator = page.iterator();
|
|
|
+ List<OrgEntity> list = Lists.newArrayList();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ OrgEntity next = iterator.next();
|
|
|
+
|
|
|
+ OrgEntity bean = new OrgEntity();
|
|
|
+ bean.setCode(next.getCode());
|
|
|
+ bean.setContacts(next.getContacts());
|
|
|
+ bean.setEnable(next.getEnable());
|
|
|
+ bean.setId(next.getId());
|
|
|
+ bean.setName(next.getName());
|
|
|
+ bean.setParentId(next.getParentId());
|
|
|
+ bean.setRemark(next.getRemark());
|
|
|
+ bean.setRootId(next.getRootId());
|
|
|
+ bean.setTelephone(next.getTelephone());
|
|
|
+
|
|
|
+ list.add(bean);
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询全量机构树")
|
|
|
+ @GetMapping("queryFullOrgTree")
|
|
|
+ public List<OrgDomain> queryFullOrgTree(@RequestParam(required = false) String propertyKeys) {
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+ Long rootOrgId = accessUser.getRootOrgId();
|
|
|
+
|
|
|
+ Specification<OrgEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.equal(root.get("rootId"), rootOrgId));
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ // 过载保护
|
|
|
+ long total = orgRepo.count(specification);
|
|
|
+ if (total > 1000) {
|
|
|
+ throw new StatusException("001251", "total is larger than 1000");
|
|
|
+ }
|
|
|
+
|
|
|
+ Sort sort = new Sort(Direction.ASC, "id");
|
|
|
+ List<OrgEntity> orgEntityList = orgRepo.findAll(specification, sort);
|
|
|
+
|
|
|
+ List<OrgDomain> ret = Lists.newArrayList();
|
|
|
+ Iterator<OrgEntity> iterator = orgEntityList.iterator();
|
|
|
+
|
|
|
+ List<String> propertyKeyList = null;
|
|
|
+ if (StringUtils.isNotBlank(propertyKeys)) {
|
|
|
+ propertyKeyList = RegExpUtil.findAll(propertyKeys, "\\w+");
|
|
|
+ }
|
|
|
+
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ OrgEntity next = iterator.next();
|
|
|
+ OrgDomain d = new OrgDomain();
|
|
|
+ ret.add(d);
|
|
|
+
|
|
|
+ d.setCode(next.getCode());
|
|
|
+ d.setContacts(next.getContacts());
|
|
|
+ d.setEnable(next.getEnable());
|
|
|
+ d.setId(next.getId());
|
|
|
+ d.setName(next.getName());
|
|
|
+ d.setParentId(next.getParentId());
|
|
|
+ d.setRemark(next.getRemark());
|
|
|
+ d.setRootId(next.getRootId());
|
|
|
+ d.setTelephone(next.getTelephone());
|
|
|
+ d.setCreationTime(next.getCreationTime());
|
|
|
+ d.setUpdateTime(next.getUpdateTime());
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(propertyKeyList)) {
|
|
|
+ Map<String, String> properties = getProperties(d.getId(), propertyKeyList);
|
|
|
+ d.setProperties(properties);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param orgId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "查询机构所有属性")
|
|
|
+ @GetMapping("allProperties/{orgId}")
|
|
|
+ public Map<String, String> getAllOrgProperties(@PathVariable Long orgId) {
|
|
|
+
|
|
|
+ OrgEntity orgEntity = GlobalHelper.getEntity(orgRepo, orgId, OrgEntity.class);
|
|
|
+ if (null == orgEntity) {
|
|
|
+ throw new StatusException("001250", "orgId is wrong");
|
|
|
+ }
|
|
|
+ validateRootOrgIsolation(orgEntity.getRootId());
|
|
|
+
|
|
|
+ Map<String, String> map = Maps.newHashMap();
|
|
|
+ List<OrgPropertyEntity> list = orgPropertyRepo.findByOrgId(orgId);
|
|
|
+ DynamicEnumManager manager = OrgProperty.getDynamicEnumManager();
|
|
|
+ for (OrgPropertyEntity cur : list) {
|
|
|
+ DynamicEnum de = manager.getById(cur.getKeyId());
|
|
|
+ map.put(de.getName(), cur.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Naked
|
|
|
+ @ApiOperation(value = "按属性组查询机构属性集合(无缓存)")
|
|
|
+ @GetMapping("getOrgPropertiesByGroupWithoutCache/{orgId}/{propertyGroupId}")
|
|
|
+ public Map<String, String> getOrgPropertiesByGroupWithoutCache(@PathVariable Long orgId,
|
|
|
+ @PathVariable String propertyGroupId) {
|
|
|
+
|
|
|
+ Map<String, String> properties = getOrgPropertiesByGroup(orgId, propertyGroupId);
|
|
|
+ return properties;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Naked
|
|
|
+ @ApiOperation(value = "按属性组查询机构属性集合(有缓存)")
|
|
|
+ @GetMapping("getOrgPropertiesByGroupWithCache/{orgId}/{propertyGroupId}")
|
|
|
+ public Map<String, String> getOrgPropertiesByGroupWithCache(@PathVariable Long orgId,
|
|
|
+ @PathVariable String propertyGroupId) {
|
|
|
+
|
|
|
+ String redisKey = "PROPERTIES_BY_GROUP:" + orgId + ":" + propertyGroupId;
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ Map<String, String> properties = redisClient.get(redisKey, Map.class);
|
|
|
+ if (null != properties) {
|
|
|
+ return properties;
|
|
|
+ }
|
|
|
+ properties = getOrgPropertiesByGroup(orgId, propertyGroupId);
|
|
|
+
|
|
|
+ redisClient.set(redisKey, properties, 60 * 10);
|
|
|
+ return properties;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> uploadOrgProperties2Upyun(Long orgId, String propertyGroupId) {
|
|
|
+ Map<String, String> properties = getOrgPropertiesByGroup(orgId, propertyGroupId);
|
|
|
+
|
|
|
+ OrgCacheBean org = CacheHelper.getOrg(orgId);
|
|
|
+ properties.put("ROOT_ORG_ID", String.valueOf(org.getRootId()));
|
|
|
+
|
|
|
+ OrgEntity orgEntity = GlobalHelper.getEntity(orgRepo, orgId, OrgEntity.class);
|
|
|
+ String fileSuffix = ".json";
|
|
|
+
|
|
|
+ String filePath = systemConfig.getTempDataDir() + File.separator + "orgProperties"
|
|
|
+ + File.separator + propertyGroupId + "_" + orgId + fileSuffix;
|
|
|
+ filePath = PathUtil.getCanonicalPath(filePath);
|
|
|
+ File file = new File(filePath);
|
|
|
+
|
|
|
+ Map<String, String> sortedProperties = new TreeMap<String, String>(
|
|
|
+ new java.util.Comparator<String>() {
|
|
|
+ @Override
|
|
|
+ public int compare(String str1, String str2) {
|
|
|
+ return str1.compareTo(str2);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ sortedProperties.putAll(properties);
|
|
|
+
|
|
|
+ String prettyJson = JsonUtil.toPrettyJson(sortedProperties);
|
|
|
+
|
|
|
+ List<String> urlList = Lists.newArrayList();
|
|
|
+ try {
|
|
|
+ FileUtils.write(file, prettyJson, "UTF-8");
|
|
|
+
|
|
|
+// PutFileReq req = new PutFileReq();
|
|
|
+// List<FormFilePart> formFilePartList = new ArrayList<FormFilePart>();
|
|
|
+// FormFilePart part = new FormFilePart("file", orgId + fileSuffix, file);
|
|
|
+// formFilePartList.add(part);
|
|
|
+//
|
|
|
+// req.setFormFilePartList(formFilePartList);
|
|
|
+//
|
|
|
+// req.setFileSuffix(fileSuffix);
|
|
|
+// req.setRootOrgId(orgEntity.getId());
|
|
|
+// req.setRootOrgDomain(orgEntity.getDomainName());
|
|
|
+// req.setExt1(propertyGroupId);
|
|
|
+//
|
|
|
+// PutFileResp putFileResp = null;
|
|
|
+//
|
|
|
+// req.setSiteId("orgPropertiesByOrgId");
|
|
|
+// putFileResp = upyunCloudService.putFile(req);
|
|
|
+// urlList.add(putFileResp.getUrl());
|
|
|
+//
|
|
|
+// req.setSiteId("orgPropertiesByOrgDomain");
|
|
|
+// putFileResp = upyunCloudService.putFile(req);
|
|
|
+// urlList.add(putFileResp.getUrl());
|
|
|
+
|
|
|
+ //通用存储
|
|
|
+ YunPathInfo pi=null;
|
|
|
+ FileStoragePathEnvInfo env=new FileStoragePathEnvInfo();
|
|
|
+ env.setFileSuffix(fileSuffix);
|
|
|
+ env.setRootOrgId(orgEntity.getId().toString());
|
|
|
+ env.setRootOrgDomain(orgEntity.getDomainName());
|
|
|
+ env.setExt1(propertyGroupId);
|
|
|
+ pi=FileStorageUtil.saveFile("orgPropertiesByOrgId", env, file,null);
|
|
|
+ urlList.add(pi.getUrl());
|
|
|
+ pi=FileStorageUtil.saveFile("orgPropertiesByOrgDomain", env, file,null);
|
|
|
+ urlList.add(pi.getUrl());
|
|
|
+
|
|
|
+ return urlList;
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new ExamCloudRuntimeException(e);
|
|
|
+ } finally {
|
|
|
+ FileUtils.deleteQuietly(file);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, String> getOrgPropertiesByGroup(Long orgId, String propertyGroupId) {
|
|
|
+
|
|
|
+ OrgEntity orgEntity = GlobalHelper.getEntity(orgRepo, orgId, OrgEntity.class);
|
|
|
+ if (null == orgEntity) {
|
|
|
+ throw new StatusException("001250", "orgId is wrong");
|
|
|
+ }
|
|
|
+
|
|
|
+ String key = SystemProps.ORG_PROPERTY_GROUP_PREFIX + propertyGroupId;
|
|
|
+
|
|
|
+ SysPropertyCacheBean groupCacheBean = systemPropertyCache.get(key);
|
|
|
+
|
|
|
+ if (null == groupCacheBean) {
|
|
|
+ throw new StatusException("001280", "unknown propertyGroupId");
|
|
|
+ }
|
|
|
+
|
|
|
+ Object value = groupCacheBean.getValue();
|
|
|
+ if (null == value || StringUtils.isBlank(String.valueOf(value))) {
|
|
|
+ throw new StatusException("001281", "value of [" + key + "] is blank");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> keys = RegExpUtil.findAll(String.valueOf(value), "[^\\,]+");
|
|
|
+ Map<String, String> properties = getProperties(orgEntity.getId(), keys);
|
|
|
+
|
|
|
+ return properties;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param orgId
|
|
|
+ * @param key
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "查询机构单个属性")
|
|
|
+ @GetMapping("property/{orgId}/{key}")
|
|
|
+ public String getOrgProperty(@PathVariable Long orgId, @PathVariable String key) {
|
|
|
+ OrgCacheBean org = CacheHelper.getOrg(orgId);
|
|
|
+ validateRootOrgIsolation(org.getRootId());
|
|
|
+
|
|
|
+ OrgPropertyCacheBean orgProperty = CacheHelper.getOrgProperty(orgId, key);
|
|
|
+ if (!orgProperty.getHasValue()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return orgProperty.getValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Naked
|
|
|
+ @ApiOperation(value = "查询机构单个属性(不鉴权)")
|
|
|
+ @GetMapping("propertyNoSession/{key}")
|
|
|
+ public String getOrgPropertyNoSession(@RequestParam(required = false) Long orgId,
|
|
|
+ @RequestParam(required = false) String domainName, @PathVariable String key) {
|
|
|
+ OrgEntity orgEntity = null;
|
|
|
+ if (null != orgId) {
|
|
|
+ orgEntity = GlobalHelper.getEntity(orgRepo, orgId, OrgEntity.class);
|
|
|
+ if (null == orgEntity) {
|
|
|
+ throw new StatusException("001250", "orgId is wrong");
|
|
|
+ }
|
|
|
+ } else if (StringUtils.isNotBlank(domainName)) {
|
|
|
+ orgEntity = orgRepo.findByParentIdIsNullAndDomainName(domainName);
|
|
|
+ if (null == orgEntity) {
|
|
|
+ throw new StatusException("001252", "domainName is wrong");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new StatusException("001253", "orgId and domainName are all null");
|
|
|
+ }
|
|
|
+
|
|
|
+ DynamicEnumManager manager = OrgProperty.getDynamicEnumManager();
|
|
|
+ DynamicEnum de = manager.getByName(key);
|
|
|
+ OrgPropertyEntity one = orgPropertyRepo.findByOrgIdAndKeyId(orgEntity.getId(), de.getId());
|
|
|
+ if (null == one) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return one.getValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param domain
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "新增顶级机构", notes = "新增")
|
|
|
+ @PostMapping("addRootOrg")
|
|
|
+ @Transactional
|
|
|
+ public OrgEntity addRootOrg(@RequestBody OrgDomain domain) {
|
|
|
+ trim(domain, true);
|
|
|
+
|
|
|
+ if (!isSuperAdmin()) {
|
|
|
+ throw new StatusException("140001", "非法访问");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(domain.getCode())) {
|
|
|
+ throw new StatusException("150001", "code is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ OrgEntity orgEntity = orgRepo.findByParentIdIsNullAndCode(domain.getCode());
|
|
|
+ if (null != orgEntity) {
|
|
|
+ throw new StatusException("150001", "机构代码已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ OrgInfo info = new OrgInfo();
|
|
|
+ info.setCode(domain.getCode());
|
|
|
+ info.setName(domain.getName());
|
|
|
+ info.setContacts(domain.getContacts());
|
|
|
+ info.setTelephone(domain.getTelephone());
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param domain
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "更新顶级机构", notes = "更新")
|
|
|
+ @PutMapping("updateRootOrg")
|
|
|
+ @Transactional
|
|
|
+ public OrgEntity updateRootOrg(@RequestBody OrgDomain domain) {
|
|
|
+ trim(domain, true);
|
|
|
+
|
|
|
+ if (!isSuperAdmin()) {
|
|
|
+ throw new StatusException("140001", "非法访问");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long id = domain.getId();
|
|
|
+ if (null == id) {
|
|
|
+ throw new StatusException("140001", "id is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ OrgEntity orgEntity = GlobalHelper.getEntity(orgRepo, id, OrgEntity.class);
|
|
|
+ if (null == orgEntity) {
|
|
|
+ throw new StatusException("140002", "orgEntity is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ validateRootOrgIsolation(orgEntity.getRootId());
|
|
|
+
|
|
|
+ OrgInfo info = new OrgInfo();
|
|
|
+
|
|
|
+ info.setEnable(domain.getEnable());
|
|
|
+ info.setCode(orgEntity.getCode());
|
|
|
+ info.setParentId(orgEntity.getParentId());
|
|
|
+ info.setRootId(orgEntity.getRootId());
|
|
|
+
|
|
|
+ info.setName(domain.getName());
|
|
|
+ info.setContacts(domain.getContacts());
|
|
|
+ info.setTelephone(domain.getTelephone());
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param domain
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "新增子机构", notes = "新增")
|
|
|
+ @PostMapping("addSubOrg")
|
|
|
+ @Transactional
|
|
|
+ public OrgEntity addSubOrg(@RequestBody OrgDomain domain) {
|
|
|
+ trim(domain, true);
|
|
|
+
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+ Long rootId = domain.getRootId();
|
|
|
+ if (null == rootId) {
|
|
|
+ rootId = accessUser.getRootOrgId();
|
|
|
+ }
|
|
|
+
|
|
|
+ validateRootOrgIsolation(rootId);
|
|
|
+
|
|
|
+ OrgEntity subOrg = orgRepo.findByRootIdAndCode(accessUser.getRootOrgId(), domain.getCode());
|
|
|
+ if (null != subOrg) {
|
|
|
+ throw new StatusException("140001", "机构代码已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long parentId = domain.getParentId();
|
|
|
+ if (null == parentId) {
|
|
|
+ parentId = rootId;
|
|
|
+ }
|
|
|
+
|
|
|
+ OrgInfo info = new OrgInfo();
|
|
|
+ info.setCode(domain.getCode());
|
|
|
+ info.setName(domain.getName());
|
|
|
+ info.setContacts(domain.getContacts());
|
|
|
+ info.setTelephone(domain.getTelephone());
|
|
|
+ info.setParentId(parentId);
|
|
|
+ info.setRootId(rootId);
|
|
|
+ info.setRemark(domain.getRemark());
|
|
|
+ info.setEnable(domain.getEnable());
|
|
|
+
|
|
|
+ Map<String, String> properties = domain.getProperties();
|
|
|
+ if (null == properties) {
|
|
|
+ properties = Maps.newHashMap();
|
|
|
+ }
|
|
|
+ info.setProperties(properties);
|
|
|
+
|
|
|
+ OrgEntity saved = orgService.saveSubOrg(info);
|
|
|
+ return saved;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param domain
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "更新子机构", notes = "更新")
|
|
|
+ @PutMapping("updateSubOrg")
|
|
|
+ @Transactional
|
|
|
+ public OrgEntity updateSubOrg(@RequestBody OrgDomain domain) {
|
|
|
+ trim(domain, true);
|
|
|
+
|
|
|
+ Long id = domain.getId();
|
|
|
+ if (null == id) {
|
|
|
+ throw new StatusException("140001", "id is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ OrgEntity orgEntity = GlobalHelper.getEntity(orgRepo, id, OrgEntity.class);
|
|
|
+ if (null == orgEntity) {
|
|
|
+ throw new StatusException("140002", "orgEntity is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ validateRootOrgIsolation(orgEntity.getRootId());
|
|
|
+
|
|
|
+ OrgInfo info = new OrgInfo();
|
|
|
+ info.setCode(orgEntity.getCode());
|
|
|
+ info.setParentId(orgEntity.getParentId());
|
|
|
+ info.setRootId(orgEntity.getRootId());
|
|
|
+
|
|
|
+ info.setName(domain.getName());
|
|
|
+ info.setContacts(domain.getContacts());
|
|
|
+ info.setTelephone(domain.getTelephone());
|
|
|
+ info.setRemark(domain.getRemark());
|
|
|
+ info.setEnable(domain.getEnable());
|
|
|
+
|
|
|
+ Map<String, String> properties = domain.getProperties();
|
|
|
+ if (null == properties) {
|
|
|
+ properties = Maps.newHashMap();
|
|
|
+ }
|
|
|
+ info.setProperties(properties);
|
|
|
+
|
|
|
+ OrgEntity saved = orgService.saveSubOrg(info);
|
|
|
+ return saved;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param ids
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "启用机构", notes = "启用")
|
|
|
+ @PutMapping("enable/{ids}")
|
|
|
+ public void enableOrgs(@PathVariable String ids) {
|
|
|
+ List<Long> orgIdList = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ setOrgsEnable(orgIdList, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param ids
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "禁用机构", notes = "禁用")
|
|
|
+ @PutMapping("disable/{ids}")
|
|
|
+ @Transactional
|
|
|
+ public void disableOrgs(@PathVariable String ids) {
|
|
|
+ List<Long> orgIdList = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ setOrgsEnable(orgIdList, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param orgIdList
|
|
|
+ * @param enable
|
|
|
+ */
|
|
|
+ private void setOrgsEnable(List<Long> orgIdList, Boolean enable) {
|
|
|
+ List<OrgEntity> savedList = Lists.newArrayList();
|
|
|
+ for (Long orgId : orgIdList) {
|
|
|
+ OrgEntity org = GlobalHelper.getEntity(orgRepo, orgId, OrgEntity.class);
|
|
|
+ if (null == org.getParentId()) {
|
|
|
+ if (!isSuperAdmin()) {
|
|
|
+ throw new StatusException("001550", "非法操作");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ validateRootOrgIsolation(org.getRootId());
|
|
|
+ org.setEnable(enable);
|
|
|
+ OrgEntity saved = orgRepo.saveAndFlush(org);
|
|
|
+ savedList.add(saved);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (OrgEntity saved : savedList) {
|
|
|
+ SyncOrgReq req = new SyncOrgReq();
|
|
|
+ req.setEnable(saved.getEnable());
|
|
|
+ req.setId(saved.getId());
|
|
|
+ req.setName(saved.getName());
|
|
|
+ req.setParentId(saved.getParentId());
|
|
|
+ req.setRootId(saved.getRootId());
|
|
|
+ req.setSyncType("update");
|
|
|
+ dataSyncCloudService.syncOrg(req);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (OrgEntity saved : savedList) {
|
|
|
+ orgCache.remove(saved.getId());
|
|
|
+ if (null != saved.getDomainName()) {
|
|
|
+ rootOrgCache.remove(saved.getDomainName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "保存机构属性", notes = "")
|
|
|
+ @PutMapping("saveOrgProperties")
|
|
|
+ @Transactional
|
|
|
+ public void saveOrgProperties(@RequestBody SaveOrgPropertiesDomain domain) {
|
|
|
+ Long orgId = domain.getOrgId();
|
|
|
+ OrgCacheBean org = CacheHelper.getOrg(orgId);
|
|
|
+
|
|
|
+ Map<String, String> properties = domain.getProperties();
|
|
|
+
|
|
|
+ if (!isSuperAdmin()) {
|
|
|
+ String editableProperties4SuperAdmin = (String) systemPropertyService
|
|
|
+ .get("editableProperties4SuperAdmin");
|
|
|
+ if (StringUtils.isNotBlank(editableProperties4SuperAdmin)) {
|
|
|
+ editableProperties4SuperAdmin = "," + editableProperties4SuperAdmin + ",";
|
|
|
+ for (String cur : properties.keySet()) {
|
|
|
+ cur = "," + cur + ",";
|
|
|
+ if (editableProperties4SuperAdmin.contains(cur)) {
|
|
|
+ throw new StatusException("140050", "非法操作");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ properties.put("ROOT_ORG_ID", String.valueOf(org.getRootId()));
|
|
|
+
|
|
|
+ List<String> relatedPropertyGroupIdList = domain.getRelatedPropertyGroupIdList();
|
|
|
+
|
|
|
+ OrgEntity orgEntity = GlobalHelper.getPresentEntity(orgRepo, orgId, OrgEntity.class);
|
|
|
+
|
|
|
+ validateRootOrgIsolation(orgEntity.getRootId());
|
|
|
+
|
|
|
+ orgService.saveOrgProperties(orgEntity.getId(), properties);
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(relatedPropertyGroupIdList)) {
|
|
|
+ for (String propertyGroupId : relatedPropertyGroupIdList) {
|
|
|
+ // 删除缓存
|
|
|
+ String redisKey = "PROPERTIES_BY_GROUP:" + orgId + ":" + propertyGroupId;
|
|
|
+ redisClient.delete(redisKey);
|
|
|
+
|
|
|
+ // 上传upyun
|
|
|
+ uploadOrgProperties2Upyun(orgId, propertyGroupId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param domain
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @Naked
|
|
|
+ @ApiOperation(value = "获取logo")
|
|
|
+ @GetMapping("logo")
|
|
|
+ public void getLogo(@RequestParam("domain") String domain, HttpServletResponse response)
|
|
|
+ throws IOException {
|
|
|
+ OrgEntity org = orgRepo.findByParentIdIsNullAndDomainName(domain);
|
|
|
+ if (null == org) {
|
|
|
+ throw new StatusException("140002", "orgEntity is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long orgId = org.getId();
|
|
|
+
|
|
|
+ DynamicEnumManager manager = OrgProperty.getDynamicEnumManager();
|
|
|
+
|
|
|
+ DynamicEnum logoFileSuffix = manager.getByName("LOGO_FILE_SUFFIX");
|
|
|
+
|
|
|
+ OrgPropertyEntity fileSuffixEntity = orgPropertyRepo.findByOrgIdAndKeyId(orgId,
|
|
|
+ logoFileSuffix.getId());
|
|
|
+
|
|
|
+ if (null == fileSuffixEntity) {
|
|
|
+ throw new StatusException("140003", "no logo");
|
|
|
+ }
|
|
|
+
|
|
|
+ String path = systemConfig.getTempDataDir() + "/logo/" + orgId
|
|
|
+ + fileSuffixEntity.getValue();
|
|
|
+
|
|
|
+ File file = new File(path);
|
|
|
+
|
|
|
+ if (file.exists()) {
|
|
|
+ FileInputStream in = null;
|
|
|
+ try {
|
|
|
+ in = new FileInputStream(file);
|
|
|
+ IOUtils.copy(in, response.getOutputStream());
|
|
|
+ response.flushBuffer();
|
|
|
+ } finally {
|
|
|
+ IOUtils.closeQuietly(in);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ DynamicEnum logoFile = manager.getByName("LOGO_FILE");
|
|
|
+ OrgPropertyEntity fileEntity = orgPropertyRepo.findByOrgIdAndKeyId(orgId, logoFile.getId());
|
|
|
+
|
|
|
+ byte[] decodeHex = null;;
|
|
|
+ try {
|
|
|
+ decodeHex = Hex.decodeHex(fileEntity.getValue());
|
|
|
+ } catch (DecoderException e) {
|
|
|
+ throw new ExamCloudRuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ FileUtils.writeByteArrayToFile(new File(path), decodeHex);
|
|
|
+
|
|
|
+ if (file.exists()) {
|
|
|
+ FileInputStream in = null;
|
|
|
+ try {
|
|
|
+ in = new FileInputStream(file);
|
|
|
+ IOUtils.copy(in, response.getOutputStream());
|
|
|
+ response.flushBuffer();
|
|
|
+ } finally {
|
|
|
+ IOUtils.closeQuietly(in);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param request
|
|
|
+ * @param file
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "导入logo", notes = "导入logo")
|
|
|
+ @PostMapping("importLogo/{orgId}")
|
|
|
+ @Transactional
|
|
|
+ public String importLogo(@PathVariable Long orgId, HttpServletRequest request,
|
|
|
+ @RequestParam CommonsMultipartFile file) throws IOException {
|
|
|
+
|
|
|
+ OrgEntity orgEntity = GlobalHelper.getEntity(orgRepo, orgId, OrgEntity.class);
|
|
|
+ if (null == orgEntity) {
|
|
|
+ throw new StatusException("140002", "orgEntity is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ validateRootOrgIsolation(orgEntity.getRootId());
|
|
|
+
|
|
|
+ DiskFileItem fileItem = (DiskFileItem) file.getFileItem();
|
|
|
+ File storeLocation = fileItem.getStoreLocation();
|
|
|
+ String name = file.getOriginalFilename();
|
|
|
+
|
|
|
+ System.out.println(storeLocation.length());
|
|
|
+ if (999999 < storeLocation.length()) {
|
|
|
+ throw new StatusException("140082", "文件过大");
|
|
|
+ }
|
|
|
+
|
|
|
+ String fileSuffix = null;
|
|
|
+ if (name.endsWith(".jpg")) {
|
|
|
+ fileSuffix = ".jpg";
|
|
|
+ } else if (name.endsWith(".gif")) {
|
|
|
+ fileSuffix = ".gif";
|
|
|
+ } else if (name.endsWith(".png")) {
|
|
|
+ fileSuffix = ".png";
|
|
|
+ } else {
|
|
|
+ throw new StatusException("101001", "文件格式错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ byte[] byteArray = null;
|
|
|
+ InputStream inputStream = null;
|
|
|
+ try {
|
|
|
+ inputStream = new FileInputStream(storeLocation);
|
|
|
+ byteArray = IOUtils.toByteArray(inputStream);
|
|
|
+ } finally {
|
|
|
+ IOUtils.closeQuietly(inputStream);
|
|
|
+ }
|
|
|
+
|
|
|
+ String hexString = Hex.encodeHexString(byteArray);
|
|
|
+
|
|
|
+ DynamicEnumManager manager = OrgProperty.getDynamicEnumManager();
|
|
|
+ DynamicEnum logoFile = manager.getByName("LOGO_FILE");
|
|
|
+ DynamicEnum logoFileSuffix = manager.getByName("LOGO_FILE_SUFFIX");
|
|
|
+ DynamicEnum logoFileUrl = manager.getByName("LOGO_FILE_URL");
|
|
|
+
|
|
|
+ OrgPropertyEntity fileEntity = orgPropertyRepo.findByOrgIdAndKeyId(orgId, logoFile.getId());
|
|
|
+ if (null == fileEntity) {
|
|
|
+ fileEntity = new OrgPropertyEntity();
|
|
|
+ fileEntity.setKeyId(logoFile.getId());
|
|
|
+ fileEntity.setOrgId(orgId);
|
|
|
+ }
|
|
|
+ fileEntity.setValue(hexString);
|
|
|
+ orgPropertyRepo.save(fileEntity);
|
|
|
+
|
|
|
+ OrgPropertyEntity fileSuffixEntity = orgPropertyRepo.findByOrgIdAndKeyId(orgId,
|
|
|
+ logoFileSuffix.getId());
|
|
|
+ if (null == fileSuffixEntity) {
|
|
|
+ fileSuffixEntity = new OrgPropertyEntity();
|
|
|
+ fileSuffixEntity.setKeyId(logoFileSuffix.getId());
|
|
|
+ fileSuffixEntity.setOrgId(orgId);
|
|
|
+ }
|
|
|
+ fileSuffixEntity.setValue(fileSuffix);
|
|
|
+ orgPropertyRepo.save(fileSuffixEntity);
|
|
|
+
|
|
|
+ String path = systemConfig.getTempDataDir() + "/logo/" + orgId
|
|
|
+ + fileSuffixEntity.getValue();
|
|
|
+
|
|
|
+ FileUtils.copyFile(storeLocation, new File(path));
|
|
|
+
|
|
|
+// PutFileReq req = new PutFileReq();
|
|
|
+// List<FormFilePart> formFilePartList = new ArrayList<FormFilePart>();
|
|
|
+// FormFilePart part = new FormFilePart("file", orgId + fileSuffix, storeLocation);
|
|
|
+// formFilePartList.add(part);
|
|
|
+//
|
|
|
+// req.setFormFilePartList(formFilePartList);
|
|
|
+// req.setSiteId("orgLogo");
|
|
|
+// req.setFileSuffix(fileSuffix);
|
|
|
+// req.setRootOrgId(orgEntity.getRootId());
|
|
|
+// PutFileResp putFileResp = upyunCloudService.putFile(req);
|
|
|
+// String url = putFileResp.getUrl();
|
|
|
+
|
|
|
+ //通用存储
|
|
|
+ FileStoragePathEnvInfo env=new FileStoragePathEnvInfo();
|
|
|
+ env.setFileSuffix(fileSuffix);
|
|
|
+ env.setRootOrgId(orgEntity.getRootId().toString());
|
|
|
+ YunPathInfo pi=FileStorageUtil.saveFile("orgLogo", env, storeLocation,null);
|
|
|
+ String url =pi.getUrl();
|
|
|
+
|
|
|
+ OrgPropertyEntity logoFileUrlEntity = orgPropertyRepo.findByOrgIdAndKeyId(orgId,
|
|
|
+ logoFileUrl.getId());
|
|
|
+ if (null == logoFileUrlEntity) {
|
|
|
+ logoFileUrlEntity = new OrgPropertyEntity();
|
|
|
+ logoFileUrlEntity.setKeyId(logoFileUrl.getId());
|
|
|
+ logoFileUrlEntity.setOrgId(orgId);
|
|
|
+ }
|
|
|
+ logoFileUrlEntity.setValue(url);
|
|
|
+ orgPropertyRepo.save(logoFileUrlEntity);
|
|
|
+
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "下载导入模板", notes = "下载导入模板")
|
|
|
+ @GetMapping("importTemplate")
|
|
|
+ public void getDownloadTemplate(HttpServletResponse response) {
|
|
|
+ String resoucePath = PathUtil.getResoucePath("templates/subOrgImportTemplate.xlsx");
|
|
|
+ exportFile("学习中心导入模板.xlsx", new File(resoucePath));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "导入子机构", notes = "")
|
|
|
+ @PostMapping("importSubOrg")
|
|
|
+ @Transactional
|
|
|
+ public Map<String, Object> importSubOrg(@RequestParam CommonsMultipartFile file) {
|
|
|
+ DiskFileItem item = (DiskFileItem) file.getFileItem();
|
|
|
+ File storeLocation = item.getStoreLocation();
|
|
|
+ List<Map<String, Object>> failRecords = orgService.importSubOrg(getRootOrgId(),
|
|
|
+ storeLocation);
|
|
|
+ Map<String, Object> map = Maps.newHashMap();
|
|
|
+ map.put("hasError", CollectionUtils.isNotEmpty(failRecords));
|
|
|
+ map.put("failRecords", failRecords);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入自定义菜单logo
|
|
|
+ *
|
|
|
+ * @author lideyin
|
|
|
+ * @param request
|
|
|
+ * @param file
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "导入自定义菜单logo", notes = "导入自定义菜单logo")
|
|
|
+ @PostMapping("importCusMenuLogo/{orgId}")
|
|
|
+ @Transactional
|
|
|
+ public String importCusMenuLogo(@PathVariable Long orgId, HttpServletRequest request,
|
|
|
+ @RequestParam CommonsMultipartFile file) throws IOException {
|
|
|
+
|
|
|
+ OrgEntity orgEntity = GlobalHelper.getEntity(orgRepo, orgId, OrgEntity.class);
|
|
|
+ if (null == orgEntity) {
|
|
|
+ throw new StatusException("140002", "orgEntity is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ validateRootOrgIsolation(orgEntity.getRootId());
|
|
|
+
|
|
|
+ DiskFileItem fileItem = (DiskFileItem) file.getFileItem();
|
|
|
+ File storeLocation = fileItem.getStoreLocation();
|
|
|
+ String name = file.getOriginalFilename();
|
|
|
+
|
|
|
+ System.out.println(storeLocation.length());
|
|
|
+ if (999999 < storeLocation.length()) {
|
|
|
+ throw new StatusException("140082", "文件过大");
|
|
|
+ }
|
|
|
+
|
|
|
+ String fileSuffix = null;
|
|
|
+ if (name.endsWith(".jpg")) {
|
|
|
+ fileSuffix = ".jpg";
|
|
|
+ } else if (name.endsWith(".gif")) {
|
|
|
+ fileSuffix = ".gif";
|
|
|
+ } else if (name.endsWith(".png")) {
|
|
|
+ fileSuffix = ".png";
|
|
|
+ } else {
|
|
|
+ throw new StatusException("101001", "文件格式错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ byte[] byteArray = null;
|
|
|
+ InputStream inputStream = null;
|
|
|
+ try {
|
|
|
+ inputStream = new FileInputStream(storeLocation);
|
|
|
+ byteArray = IOUtils.toByteArray(inputStream);
|
|
|
+ } finally {
|
|
|
+ IOUtils.closeQuietly(inputStream);
|
|
|
+ }
|
|
|
+
|
|
|
+ String hexString = Hex.encodeHexString(byteArray);
|
|
|
+
|
|
|
+ DynamicEnumManager manager = OrgProperty.getDynamicEnumManager();
|
|
|
+ DynamicEnum logoFile = manager.getByName("CUS_MENU_LOGO_FILE");
|
|
|
+ DynamicEnum logoFileSuffix = manager.getByName("CUS_MENU_LOGO_FILE_SUFFIX");
|
|
|
+ DynamicEnum logoFileUrl = manager.getByName("CUS_MENU_LOGO_FILE_URL");
|
|
|
+
|
|
|
+ OrgPropertyEntity fileEntity = orgPropertyRepo.findByOrgIdAndKeyId(orgId, logoFile.getId());
|
|
|
+ if (null == fileEntity) {
|
|
|
+ fileEntity = new OrgPropertyEntity();
|
|
|
+ fileEntity.setKeyId(logoFile.getId());
|
|
|
+ fileEntity.setOrgId(orgId);
|
|
|
+ }
|
|
|
+ fileEntity.setValue(hexString);
|
|
|
+ orgPropertyRepo.save(fileEntity);
|
|
|
+
|
|
|
+ OrgPropertyEntity fileSuffixEntity = orgPropertyRepo.findByOrgIdAndKeyId(orgId,
|
|
|
+ logoFileSuffix.getId());
|
|
|
+ if (null == fileSuffixEntity) {
|
|
|
+ fileSuffixEntity = new OrgPropertyEntity();
|
|
|
+ fileSuffixEntity.setKeyId(logoFileSuffix.getId());
|
|
|
+ fileSuffixEntity.setOrgId(orgId);
|
|
|
+ }
|
|
|
+ fileSuffixEntity.setValue(fileSuffix);
|
|
|
+ orgPropertyRepo.save(fileSuffixEntity);
|
|
|
+
|
|
|
+ String path = systemConfig.getTempDataDir() + "/cusMenuLogo/" + orgId
|
|
|
+ + fileSuffixEntity.getValue();
|
|
|
+
|
|
|
+ FileUtils.copyFile(storeLocation, new File(path));
|
|
|
+
|
|
|
+ //通用存储
|
|
|
+ FileStoragePathEnvInfo env=new FileStoragePathEnvInfo();
|
|
|
+ env.setFileSuffix(fileSuffix);
|
|
|
+ env.setRootOrgId(orgEntity.getRootId().toString());
|
|
|
+ YunPathInfo pi=FileStorageUtil.saveFile("orgLogo", env, storeLocation,null);
|
|
|
+ String url =pi.getUrl();
|
|
|
+
|
|
|
+ OrgPropertyEntity logoFileUrlEntity = orgPropertyRepo.findByOrgIdAndKeyId(orgId,
|
|
|
+ logoFileUrl.getId());
|
|
|
+ if (null == logoFileUrlEntity) {
|
|
|
+ logoFileUrlEntity = new OrgPropertyEntity();
|
|
|
+ logoFileUrlEntity.setKeyId(logoFileUrl.getId());
|
|
|
+ logoFileUrlEntity.setOrgId(orgId);
|
|
|
+ }
|
|
|
+ logoFileUrlEntity.setValue(url);
|
|
|
+ orgPropertyRepo.save(logoFileUrlEntity);
|
|
|
+
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+}
|