|
@@ -4,7 +4,9 @@ import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
@@ -21,6 +23,7 @@ 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.DeleteMapping;
|
|
@@ -35,14 +38,17 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
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.PropertiesUtil;
|
|
|
import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
|
|
|
+import cn.com.qmth.examcloud.commons.web.helpers.page.PageInfo;
|
|
|
import cn.com.qmth.examcloud.commons.web.security.bean.User;
|
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.controller.bean.OrgDomain;
|
|
|
import cn.com.qmth.examcloud.core.basic.base.constants.PropKeys;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.OrgPropertyRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
|
|
@@ -50,8 +56,9 @@ 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.bean.OrgDto;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.bean.OrgInfo;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.impl.ExportService;
|
|
|
-import cn.com.qmth.examcloud.core.basic.service.impl.OrgService;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.impl.OrgServiceImpl;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
/**
|
|
@@ -66,7 +73,7 @@ public class OrgController extends ControllerSupport {
|
|
|
OrgRepo orgRepo;
|
|
|
|
|
|
@Autowired
|
|
|
- OrgService orgService;
|
|
|
+ OrgServiceImpl orgService;
|
|
|
|
|
|
@Autowired
|
|
|
OrgPropertyRepo orgPropertyRepo;
|
|
@@ -75,92 +82,173 @@ public class OrgController extends ControllerSupport {
|
|
|
* 方法注释
|
|
|
*
|
|
|
* @author WANGWEI
|
|
|
- * @param id
|
|
|
+ * @param curPage
|
|
|
+ * @param pageSize
|
|
|
+ * @param code
|
|
|
+ * @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 name) {
|
|
|
+
|
|
|
+ Pageable pageable = new PageRequest(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)));
|
|
|
+ }
|
|
|
+ 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();
|
|
|
+
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+
|
|
|
+ PageInfo<OrgDomain> ret = new PageInfo<OrgDomain>();
|
|
|
+ ret.setList(list);
|
|
|
+ ret.setTotal(page.getTotalElements());
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param orgId
|
|
|
* @return
|
|
|
*/
|
|
|
@ApiOperation(value = "按ID查询机构", notes = "ID查询")
|
|
|
- @GetMapping("/{id}")
|
|
|
- public OrgEntity getOrg(@PathVariable Long id) {
|
|
|
- OrgEntity org = orgService.findOne(id);
|
|
|
- return org;
|
|
|
+ @GetMapping("{orgId}")
|
|
|
+ public OrgEntity getOrg(@PathVariable Long orgId) {
|
|
|
+ OrgEntity orgEntity = orgRepo.findOne(orgId);
|
|
|
+ if (null == orgEntity) {
|
|
|
+ throw new StatusException("B-001250", "orgId is wrong");
|
|
|
+ }
|
|
|
+ validateRootOrgIsolation(orgEntity.getRootId());
|
|
|
+
|
|
|
+ return orgEntity;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 方法注释
|
|
|
*
|
|
|
* @author WANGWEI
|
|
|
- * @param parentId
|
|
|
+ * @param code
|
|
|
* @return
|
|
|
*/
|
|
|
- @ApiOperation(value = "查询下属机构不带分页", notes = "不分页")
|
|
|
- @GetMapping("/sub/{parentId}")
|
|
|
- public List<OrgEntity> getSubOrgList(@PathVariable Long parentId) {
|
|
|
- List<OrgEntity> orgList = orgRepo.findByParentIdAndEnable(parentId, true);
|
|
|
- return orgList;
|
|
|
+ @ApiOperation(value = "查询顶级机构")
|
|
|
+ @GetMapping("getRootOrgByCode")
|
|
|
+ public OrgEntity getRootOrgByCode(@RequestParam("code") String code) {
|
|
|
+ OrgEntity org = orgRepo.findByParentIdIsNullAndCode(code);
|
|
|
+ return org;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 修改请通知作者
|
|
|
+ * 方法注释
|
|
|
*
|
|
|
* @author WANGWEI
|
|
|
* @param curPage
|
|
|
* @param pageSize
|
|
|
- * @param rootOrgId
|
|
|
+ * @param parentId
|
|
|
* @param code
|
|
|
* @param name
|
|
|
* @return
|
|
|
*/
|
|
|
- @ApiOperation(value = "模糊查询顶级机构的子机构")
|
|
|
- @GetMapping("/getSubOrgList/{curPage}/{pageSize}")
|
|
|
- public Page<OrgEntity> getSubOrgListOfRootOrg(@PathVariable Integer curPage,
|
|
|
- @PathVariable Integer pageSize, @RequestParam Long rootOrgId, @RequestParam String code,
|
|
|
- @RequestParam String name) {
|
|
|
-
|
|
|
- User accessUser = getAccessUser();
|
|
|
- if (!isSuperAdmin()) {
|
|
|
- if (!accessUser.getRootOrgId().equals(rootOrgId)) {
|
|
|
- throw new StatusException("B-140001", "非法访问");
|
|
|
- }
|
|
|
+ @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) {
|
|
|
+
|
|
|
+ OrgEntity parentOrg = orgRepo.findOne(parentId);
|
|
|
+ if (null == parentOrg) {
|
|
|
+ throw new StatusException("B-001250", "parentId is wrong");
|
|
|
}
|
|
|
+ validateRootOrgIsolation(parentOrg.getRootId());
|
|
|
|
|
|
- Pageable pageable = new PageRequest(curPage - 1, pageSize, Sort.Direction.DESC,
|
|
|
- "updateTime");
|
|
|
-
|
|
|
- OrgEntity criteria = new OrgEntity();
|
|
|
- criteria.setParentId(rootOrgId);
|
|
|
- criteria.setCode(code);
|
|
|
- criteria.setName(name);
|
|
|
+ Pageable pageable = new PageRequest(curPage, pageSize, Sort.Direction.DESC, "updateTime");
|
|
|
|
|
|
Specification<OrgEntity> specification = (root, query, cb) -> {
|
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
|
- if (StringUtils.isNotEmpty(criteria.getName())) {
|
|
|
- predicates.add(cb.like(root.get("name"), toSqlSearchPattern(criteria.getName())));
|
|
|
+ predicates.add(cb.equal(root.get("parentId"), parentId));
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(name)) {
|
|
|
+ predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
}
|
|
|
- if (StringUtils.isNotEmpty(criteria.getCode())) {
|
|
|
- predicates.add(cb.like(root.get("code"), toSqlSearchPattern(criteria.getCode())));
|
|
|
+ if (StringUtils.isNotEmpty(code)) {
|
|
|
+ predicates.add(cb.like(root.get("code"), toSqlSearchPattern(code)));
|
|
|
}
|
|
|
- predicates.add(cb.equal(root.get("parentId"), criteria.getParentId()));
|
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
};
|
|
|
|
|
|
- Page<OrgEntity> ret = orgRepo.findAll(specification, pageable);
|
|
|
+ Page<OrgEntity> page = orgRepo.findAll(specification, pageable);
|
|
|
+ List<OrgDomain> list = Lists.newArrayList();
|
|
|
+ Iterator<OrgEntity> iterator = page.iterator();
|
|
|
+
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+
|
|
|
+ PageInfo<OrgDomain> ret = new PageInfo<OrgDomain>();
|
|
|
+ ret.setList(list);
|
|
|
+ ret.setTotal(page.getTotalElements());
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 修改请通知作者
|
|
|
+ * 方法注释
|
|
|
*
|
|
|
* @author WANGWEI
|
|
|
+ * @param enable
|
|
|
* @return
|
|
|
*/
|
|
|
- @ApiOperation(value = "查询所有顶级机构")
|
|
|
- @GetMapping("/getAllRootOrgList")
|
|
|
- public List<OrgEntity> getAllRootOrgList() {
|
|
|
+ @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")));
|
|
|
- predicates.add(cb.equal(root.get("enable"), true));
|
|
|
+ if (null != enable) {
|
|
|
+ predicates.add(cb.equal(root.get("enable"), enable));
|
|
|
+ }
|
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
};
|
|
|
|
|
@@ -169,62 +257,136 @@ public class OrgController extends ControllerSupport {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 修改请通知作者
|
|
|
+ * 方法注释
|
|
|
*
|
|
|
* @author WANGWEI
|
|
|
- * @param curPage
|
|
|
- * @param pageSize
|
|
|
- * @param rootOrgId
|
|
|
- * @param code
|
|
|
- * @param name
|
|
|
+ * @param parentId
|
|
|
+ * @param orgName
|
|
|
* @return
|
|
|
*/
|
|
|
- @ApiOperation(value = "模糊查询顶级机构")
|
|
|
- @GetMapping("/getRootOrgList/{curPage}/{pageSize}")
|
|
|
- public Page<OrgEntity> getRootOrgList(@PathVariable Integer curPage,
|
|
|
- @PathVariable Integer pageSize, @RequestParam String code, @RequestParam String name) {
|
|
|
+ @ApiOperation(value = "查询子机构列表")
|
|
|
+ @GetMapping("subOrgListByNameLike")
|
|
|
+ public List<OrgEntity> getSubOrgListByNameLike(@RequestParam(required = true) String name,
|
|
|
+ @RequestParam(required = false) Boolean enable) {
|
|
|
|
|
|
- Pageable pageable = new PageRequest(curPage - 1, pageSize, Sort.Direction.DESC,
|
|
|
- "updateTime");
|
|
|
+ if (StringUtils.isBlank(name)) {
|
|
|
+ List<OrgEntity> list = Lists.newArrayList();
|
|
|
+ return list;
|
|
|
+ }
|
|
|
|
|
|
- OrgEntity criteria = new OrgEntity();
|
|
|
- criteria.setCode(code);
|
|
|
- criteria.setName(name);
|
|
|
+ // 过载保护
|
|
|
+ int total = orgRepo.countByNameLike(name);
|
|
|
+ if (total > 1000) {
|
|
|
+ List<OrgEntity> list = Lists.newArrayList();
|
|
|
+ return list;
|
|
|
+ }
|
|
|
|
|
|
Specification<OrgEntity> specification = (root, query, cb) -> {
|
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
|
- if (StringUtils.isNotEmpty(criteria.getName())) {
|
|
|
- predicates.add(cb.like(root.get("name"), toSqlSearchPattern(criteria.getName())));
|
|
|
+ predicates.add(cb.equal(root.get("rootId"), getRootOrgId()));
|
|
|
+ if (StringUtils.isNotBlank(name)) {
|
|
|
+ predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
}
|
|
|
- if (StringUtils.isNotEmpty(criteria.getCode())) {
|
|
|
- predicates.add(cb.like(root.get("code"), toSqlSearchPattern(criteria.getCode())));
|
|
|
+ if (null != enable) {
|
|
|
+ predicates.add(cb.equal(root.get("enable"), enable));
|
|
|
}
|
|
|
- predicates.add(cb.isNull(root.get("parentId")));
|
|
|
+
|
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
};
|
|
|
+ Sort sort = new Sort(Direction.DESC, "updateTime");
|
|
|
+ List<OrgEntity> list = orgRepo.findAll(specification, sort);
|
|
|
|
|
|
- Page<OrgEntity> ret = orgRepo.findAll(specification, pageable);
|
|
|
- return ret;
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 方法注释
|
|
|
*
|
|
|
* @author WANGWEI
|
|
|
- * @param org
|
|
|
- * @param request
|
|
|
+ * @param orgId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "查询机构所有属性")
|
|
|
+ @GetMapping("allProperties/{orgId}")
|
|
|
+ public Map<String, String> getAllOrgProperties(@PathVariable Long orgId) {
|
|
|
+
|
|
|
+ OrgEntity orgEntity = orgRepo.findOne(orgId);
|
|
|
+ if (null == orgEntity) {
|
|
|
+ throw new StatusException("B-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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param orgId
|
|
|
+ * @param key
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "查询机构单个属性")
|
|
|
+ @GetMapping("property/{orgId}/{key}")
|
|
|
+ public String getOrgProperty(@PathVariable Long orgId, @PathVariable String key) {
|
|
|
+ OrgEntity orgEntity = orgRepo.findOne(orgId);
|
|
|
+ if (null == orgEntity) {
|
|
|
+ throw new StatusException("B-001250", "orgId is wrong");
|
|
|
+ }
|
|
|
+ validateRootOrgIsolation(orgEntity.getRootId());
|
|
|
+
|
|
|
+ DynamicEnumManager manager = OrgProperty.getDynamicEnumManager();
|
|
|
+ DynamicEnum de = manager.getByName(key);
|
|
|
+ OrgPropertyEntity one = orgPropertyRepo.findByOrgIdAndKeyId(orgId, de.getId());
|
|
|
+ if (null == one) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return one.getValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param domain
|
|
|
* @return
|
|
|
*/
|
|
|
@ApiOperation(value = "新增顶级机构", notes = "新增")
|
|
|
@PostMapping("addRootOrg")
|
|
|
- public OrgEntity addRootOrg(@RequestBody OrgEntity org) {
|
|
|
+ public OrgEntity addRootOrg(@RequestBody OrgDomain domain) {
|
|
|
+ trim(domain);
|
|
|
|
|
|
if (!isSuperAdmin()) {
|
|
|
throw new StatusException("B-140001", "非法访问");
|
|
|
}
|
|
|
|
|
|
- org.setParentId(null);
|
|
|
- OrgEntity saved = orgService.save(org);
|
|
|
+ if (StringUtils.isBlank(domain.getCode())) {
|
|
|
+ throw new StatusException("B-150001", "code is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ OrgEntity orgEntity = orgRepo.findByParentIdIsNullAndCode(domain.getCode());
|
|
|
+ if (null == orgEntity) {
|
|
|
+ throw new StatusException("B-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());
|
|
|
+
|
|
|
+ OrgEntity saved = orgService.saveRootOrg(info);
|
|
|
return saved;
|
|
|
}
|
|
|
|
|
@@ -232,20 +394,27 @@ public class OrgController extends ControllerSupport {
|
|
|
* 方法注释
|
|
|
*
|
|
|
* @author WANGWEI
|
|
|
- * @param org
|
|
|
+ * @param domain
|
|
|
* @return
|
|
|
*/
|
|
|
@ApiOperation(value = "更新顶级机构", notes = "更新")
|
|
|
@PutMapping("updateRootOrg")
|
|
|
- public OrgEntity updateRootOrg(@RequestBody OrgEntity org) {
|
|
|
- trim(org);
|
|
|
+ public OrgEntity updateRootOrg(@RequestBody OrgDomain domain) {
|
|
|
+ trim(domain);
|
|
|
+
|
|
|
if (!isSuperAdmin()) {
|
|
|
throw new StatusException("B-140001", "非法访问");
|
|
|
}
|
|
|
|
|
|
- org.setParentId(null);
|
|
|
- org.setRootId(org.getId());
|
|
|
- OrgEntity saved = orgService.save(org);
|
|
|
+ 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());
|
|
|
+
|
|
|
+ OrgEntity saved = orgService.saveRootOrg(info);
|
|
|
return saved;
|
|
|
}
|
|
|
|
|
@@ -253,24 +422,31 @@ public class OrgController extends ControllerSupport {
|
|
|
* 方法注释
|
|
|
*
|
|
|
* @author WANGWEI
|
|
|
- * @param org
|
|
|
+ * @param domain
|
|
|
* @return
|
|
|
*/
|
|
|
@ApiOperation(value = "新增子机构", notes = "新增")
|
|
|
@PostMapping("addSubOrg")
|
|
|
- public OrgEntity addSubOrg(@RequestBody OrgEntity org) {
|
|
|
- trim(org);
|
|
|
+ public OrgEntity addSubOrg(@RequestBody OrgDomain domain) {
|
|
|
+ trim(domain);
|
|
|
+
|
|
|
User accessUser = getAccessUser();
|
|
|
|
|
|
- OrgEntity subOrg = orgRepo.findByRootIdAndCode(accessUser.getRootOrgId(), org.getCode());
|
|
|
+ OrgEntity subOrg = orgRepo.findByRootIdAndCode(accessUser.getRootOrgId(), domain.getCode());
|
|
|
if (null != subOrg) {
|
|
|
throw new StatusException("B-140001", "机构代码已存在");
|
|
|
}
|
|
|
- org.setParentId(accessUser.getRootOrgId());
|
|
|
- org.setRootId(accessUser.getRootOrgId());
|
|
|
- OrgEntity saved = orgService.save(org);
|
|
|
|
|
|
- // orgService.createLearnerCenterUser(saved);
|
|
|
+ OrgInfo info = new OrgInfo();
|
|
|
+ info.setCode(domain.getCode());
|
|
|
+ info.setName(domain.getName());
|
|
|
+ info.setContacts(domain.getContacts());
|
|
|
+ info.setTelephone(domain.getTelephone());
|
|
|
+ info.setParentId(accessUser.getRootOrgId());
|
|
|
+ info.setRootId(accessUser.getRootOrgId());
|
|
|
+ info.setRemark(domain.getRemark());
|
|
|
+
|
|
|
+ OrgEntity saved = orgService.saveSubOrg(info);
|
|
|
return saved;
|
|
|
}
|
|
|
|
|
@@ -278,18 +454,31 @@ public class OrgController extends ControllerSupport {
|
|
|
* 方法注释
|
|
|
*
|
|
|
* @author WANGWEI
|
|
|
- * @param org
|
|
|
- * @param request
|
|
|
+ * @param domain
|
|
|
* @return
|
|
|
*/
|
|
|
@ApiOperation(value = "更新子机构", notes = "更新")
|
|
|
@PutMapping("updateSubOrg")
|
|
|
- public OrgEntity updateSubOrg(@RequestBody OrgEntity org) {
|
|
|
- cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
|
+ public OrgEntity updateSubOrg(@RequestBody OrgDomain domain) {
|
|
|
+ trim(domain);
|
|
|
+
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+
|
|
|
+ OrgEntity subOrg = orgRepo.findByRootIdAndCode(accessUser.getRootOrgId(), domain.getCode());
|
|
|
+ if (null != subOrg) {
|
|
|
+ throw new StatusException("B-140001", "机构代码已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ OrgInfo info = new OrgInfo();
|
|
|
+ info.setCode(domain.getCode());
|
|
|
+ info.setName(domain.getName());
|
|
|
+ info.setContacts(domain.getContacts());
|
|
|
+ info.setTelephone(domain.getTelephone());
|
|
|
+ info.setParentId(accessUser.getRootOrgId());
|
|
|
+ info.setRootId(accessUser.getRootOrgId());
|
|
|
+ info.setRemark(domain.getRemark());
|
|
|
|
|
|
- org.setParentId(accessUser.getRootOrgId());
|
|
|
- org.setRootId(accessUser.getRootOrgId());
|
|
|
- OrgEntity saved = orgService.save(org);
|
|
|
+ OrgEntity saved = orgService.saveSubOrg(info);
|
|
|
return saved;
|
|
|
}
|
|
|
|
|
@@ -299,6 +488,15 @@ public class OrgController extends ControllerSupport {
|
|
|
orgRepo.delete(id);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 待重构
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param request
|
|
|
+ * @param file
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
@ApiOperation(value = "按父ID导入子机构", notes = "导入子机构")
|
|
|
@PostMapping("/import")
|
|
|
public List<ExcelError> importLearnCenter(HttpServletRequest request,
|
|
@@ -310,6 +508,12 @@ public class OrgController extends ControllerSupport {
|
|
|
return excelErrors;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 待重构
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
@ApiOperation(value = "下载导入模板", notes = "下载导入模板")
|
|
|
@GetMapping("/download")
|
|
|
public void importFileTemplate(HttpServletResponse response) {
|
|
@@ -317,31 +521,54 @@ public class OrgController extends ControllerSupport {
|
|
|
ExportService.exportEXCEL("学习中心导入模板", OrgDto.class, list, response);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param ids
|
|
|
+ */
|
|
|
@ApiOperation(value = "启用机构", notes = "启用")
|
|
|
@PutMapping("/enable/{ids}")
|
|
|
- public void enableSchool(@PathVariable String ids) {
|
|
|
+ public void enableOrgs(@PathVariable String ids) {
|
|
|
List<Long> orgIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
.collect(Collectors.toList());
|
|
|
for (Long orgId : orgIds) {
|
|
|
- orgService.enableSchool(orgId, true);
|
|
|
+ OrgEntity org = orgRepo.findOne(orgId);
|
|
|
+ org.setEnable(true);
|
|
|
+ orgRepo.save(org);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param ids
|
|
|
+ */
|
|
|
@ApiOperation(value = "禁用机构", notes = "禁用")
|
|
|
@PutMapping("/disable/{ids}")
|
|
|
- public void disableSchool(@PathVariable String ids) {
|
|
|
+ public void disableOrgs(@PathVariable String ids) {
|
|
|
List<Long> orgIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
.collect(Collectors.toList());
|
|
|
for (Long orgId : orgIds) {
|
|
|
- orgService.enableSchool(orgId, false);
|
|
|
+ OrgEntity org = orgRepo.findOne(orgId);
|
|
|
+ org.setEnable(false);
|
|
|
+ orgRepo.save(org);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param domain
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
@ApiOperation(value = "获取logo")
|
|
|
@GetMapping("/logo")
|
|
|
public void getLogo(@RequestParam("domain") String domain, HttpServletResponse response)
|
|
|
throws IOException {
|
|
|
- OrgEntity org = orgRepo.findRootOrgByCode(domain);
|
|
|
+ OrgEntity org = orgRepo.findByParentIdIsNullAndDomainName(domain);
|
|
|
DynamicEnumManager manager = OrgProperty.getDynamicEnumManager();
|
|
|
DynamicEnum de = manager.getByName("LOGO_PATH");
|
|
|
|
|
@@ -352,13 +579,6 @@ public class OrgController extends ControllerSupport {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "查询顶级机构")
|
|
|
- @GetMapping("/getRootOrgByCode")
|
|
|
- public OrgEntity getRootOrgByCode(@RequestParam("code") String code) throws IOException {
|
|
|
- OrgEntity org = orgRepo.findRootOrgByCode(code);
|
|
|
- return org;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 方法注释
|
|
|
*
|
|
@@ -404,26 +624,4 @@ public class OrgController extends ControllerSupport {
|
|
|
orgPropertyRepo.save(entity);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 修改请通知作者
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @param parentId
|
|
|
- * @param orgName
|
|
|
- * @return
|
|
|
- */
|
|
|
- @ApiOperation(value = "按机构名称模糊查询子机构列表")
|
|
|
- @PostMapping("getSubOrgListByNameLike/{parentId}")
|
|
|
- public List<OrgEntity> getSubOrgListByNameLike(@PathVariable Long parentId,
|
|
|
- @RequestParam String orgName) {
|
|
|
- List<OrgEntity> list = null;
|
|
|
- if (StringUtils.isBlank(orgName)) {
|
|
|
- list = Lists.newArrayList();
|
|
|
- return list;
|
|
|
- }
|
|
|
- orgName = "%" + orgName + "%";
|
|
|
- list = orgRepo.findByParentIdAndNameLikeAndEnable(parentId, orgName, true);
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
}
|