|
@@ -22,7 +22,6 @@ import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
-import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
@@ -38,13 +37,18 @@ import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
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.security.bean.User;
|
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
|
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;
|
|
|
-import cn.com.qmth.examcloud.core.basic.dao.entity.Org;
|
|
|
+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.impl.ExportService;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.impl.OrgService;
|
|
@@ -65,7 +69,7 @@ public class OrgController extends ControllerSupport {
|
|
|
OrgService orgService;
|
|
|
|
|
|
@Autowired
|
|
|
- private JdbcTemplate jdbcTemplate;
|
|
|
+ OrgPropertyRepo orgPropertyRepo;
|
|
|
|
|
|
/**
|
|
|
* 方法注释
|
|
@@ -76,8 +80,8 @@ public class OrgController extends ControllerSupport {
|
|
|
*/
|
|
|
@ApiOperation(value = "按ID查询机构", notes = "ID查询")
|
|
|
@GetMapping("/{id}")
|
|
|
- public Org getOrg(@PathVariable Long id) {
|
|
|
- Org org = orgService.findOne(id);
|
|
|
+ public OrgEntity getOrg(@PathVariable Long id) {
|
|
|
+ OrgEntity org = orgService.findOne(id);
|
|
|
return org;
|
|
|
}
|
|
|
|
|
@@ -90,8 +94,8 @@ public class OrgController extends ControllerSupport {
|
|
|
*/
|
|
|
@ApiOperation(value = "查询下属机构不带分页", notes = "不分页")
|
|
|
@GetMapping("/sub/{parentId}")
|
|
|
- public List<Org> getSubOrgList(@PathVariable Long parentId) {
|
|
|
- List<Org> orgList = orgRepo.findByParentIdAndEnable(parentId, true);
|
|
|
+ public List<OrgEntity> getSubOrgList(@PathVariable Long parentId) {
|
|
|
+ List<OrgEntity> orgList = orgRepo.findByParentIdAndEnable(parentId, true);
|
|
|
return orgList;
|
|
|
}
|
|
|
|
|
@@ -108,7 +112,7 @@ public class OrgController extends ControllerSupport {
|
|
|
*/
|
|
|
@ApiOperation(value = "模糊查询顶级机构的子机构")
|
|
|
@GetMapping("/getSubOrgList/{curPage}/{pageSize}")
|
|
|
- public Page<Org> getSubOrgListOfRootOrg(@PathVariable Integer curPage,
|
|
|
+ public Page<OrgEntity> getSubOrgListOfRootOrg(@PathVariable Integer curPage,
|
|
|
@PathVariable Integer pageSize, @RequestParam Long rootOrgId, @RequestParam String code,
|
|
|
@RequestParam String name) {
|
|
|
|
|
@@ -122,12 +126,12 @@ public class OrgController extends ControllerSupport {
|
|
|
Pageable pageable = new PageRequest(curPage - 1, pageSize, Sort.Direction.DESC,
|
|
|
"updateTime");
|
|
|
|
|
|
- Org criteria = new Org();
|
|
|
+ OrgEntity criteria = new OrgEntity();
|
|
|
criteria.setParentId(rootOrgId);
|
|
|
criteria.setCode(code);
|
|
|
criteria.setName(name);
|
|
|
|
|
|
- Specification<Org> specification = (root, query, cb) -> {
|
|
|
+ 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())));
|
|
@@ -139,7 +143,7 @@ public class OrgController extends ControllerSupport {
|
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
};
|
|
|
|
|
|
- Page<Org> ret = orgRepo.findAll(specification, pageable);
|
|
|
+ Page<OrgEntity> ret = orgRepo.findAll(specification, pageable);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -151,16 +155,16 @@ public class OrgController extends ControllerSupport {
|
|
|
*/
|
|
|
@ApiOperation(value = "查询所有顶级机构")
|
|
|
@GetMapping("/getAllRootOrgList")
|
|
|
- public List<Org> getAllRootOrgList() {
|
|
|
+ public List<OrgEntity> getAllRootOrgList() {
|
|
|
|
|
|
- Specification<Org> specification = (root, query, cb) -> {
|
|
|
+ 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));
|
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
};
|
|
|
|
|
|
- List<Org> ret = orgRepo.findAll(specification);
|
|
|
+ List<OrgEntity> ret = orgRepo.findAll(specification);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -177,17 +181,17 @@ public class OrgController extends ControllerSupport {
|
|
|
*/
|
|
|
@ApiOperation(value = "模糊查询顶级机构")
|
|
|
@GetMapping("/getRootOrgList/{curPage}/{pageSize}")
|
|
|
- public Page<Org> getRootOrgList(@PathVariable Integer curPage, @PathVariable Integer pageSize,
|
|
|
- @RequestParam String code, @RequestParam String name) {
|
|
|
+ public Page<OrgEntity> getRootOrgList(@PathVariable Integer curPage,
|
|
|
+ @PathVariable Integer pageSize, @RequestParam String code, @RequestParam String name) {
|
|
|
|
|
|
Pageable pageable = new PageRequest(curPage - 1, pageSize, Sort.Direction.DESC,
|
|
|
"updateTime");
|
|
|
|
|
|
- Org criteria = new Org();
|
|
|
+ OrgEntity criteria = new OrgEntity();
|
|
|
criteria.setCode(code);
|
|
|
criteria.setName(name);
|
|
|
|
|
|
- Specification<Org> specification = (root, query, cb) -> {
|
|
|
+ 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())));
|
|
@@ -199,7 +203,7 @@ public class OrgController extends ControllerSupport {
|
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
};
|
|
|
|
|
|
- Page<Org> ret = orgRepo.findAll(specification, pageable);
|
|
|
+ Page<OrgEntity> ret = orgRepo.findAll(specification, pageable);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -213,14 +217,14 @@ public class OrgController extends ControllerSupport {
|
|
|
*/
|
|
|
@ApiOperation(value = "新增顶级机构", notes = "新增")
|
|
|
@PostMapping("addRootOrg")
|
|
|
- public Org addRootOrg(@RequestBody Org org) {
|
|
|
+ public OrgEntity addRootOrg(@RequestBody OrgEntity org) {
|
|
|
|
|
|
if (!isSuperAdmin()) {
|
|
|
throw new StatusException("B-140001", "非法访问");
|
|
|
}
|
|
|
|
|
|
org.setParentId(null);
|
|
|
- Org saved = orgService.save(org);
|
|
|
+ OrgEntity saved = orgService.save(org);
|
|
|
return saved;
|
|
|
}
|
|
|
|
|
@@ -233,7 +237,7 @@ public class OrgController extends ControllerSupport {
|
|
|
*/
|
|
|
@ApiOperation(value = "更新顶级机构", notes = "更新")
|
|
|
@PutMapping("updateRootOrg")
|
|
|
- public Org updateRootOrg(@RequestBody Org org) {
|
|
|
+ public OrgEntity updateRootOrg(@RequestBody OrgEntity org) {
|
|
|
trim(org);
|
|
|
if (!isSuperAdmin()) {
|
|
|
throw new StatusException("B-140001", "非法访问");
|
|
@@ -241,7 +245,7 @@ public class OrgController extends ControllerSupport {
|
|
|
|
|
|
org.setParentId(null);
|
|
|
org.setRootId(org.getId());
|
|
|
- Org saved = orgService.save(org);
|
|
|
+ OrgEntity saved = orgService.save(org);
|
|
|
return saved;
|
|
|
}
|
|
|
|
|
@@ -254,17 +258,17 @@ public class OrgController extends ControllerSupport {
|
|
|
*/
|
|
|
@ApiOperation(value = "新增子机构", notes = "新增")
|
|
|
@PostMapping("addSubOrg")
|
|
|
- public Org addSubOrg(@RequestBody Org org) {
|
|
|
+ public OrgEntity addSubOrg(@RequestBody OrgEntity org) {
|
|
|
trim(org);
|
|
|
User accessUser = getAccessUser();
|
|
|
|
|
|
- Org subOrg = orgRepo.findByRootIdAndCode(accessUser.getRootOrgId(), org.getCode());
|
|
|
+ OrgEntity subOrg = orgRepo.findByRootIdAndCode(accessUser.getRootOrgId(), org.getCode());
|
|
|
if (null != subOrg) {
|
|
|
throw new StatusException("B-140001", "机构代码已存在");
|
|
|
}
|
|
|
org.setParentId(accessUser.getRootOrgId());
|
|
|
org.setRootId(accessUser.getRootOrgId());
|
|
|
- Org saved = orgService.save(org);
|
|
|
+ OrgEntity saved = orgService.save(org);
|
|
|
|
|
|
// orgService.createLearnerCenterUser(saved);
|
|
|
return saved;
|
|
@@ -280,12 +284,12 @@ public class OrgController extends ControllerSupport {
|
|
|
*/
|
|
|
@ApiOperation(value = "更新子机构", notes = "更新")
|
|
|
@PutMapping("updateSubOrg")
|
|
|
- public Org updateSubOrg(@RequestBody Org org) {
|
|
|
+ public OrgEntity updateSubOrg(@RequestBody OrgEntity org) {
|
|
|
cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
|
|
|
|
org.setParentId(accessUser.getRootOrgId());
|
|
|
org.setRootId(accessUser.getRootOrgId());
|
|
|
- Org saved = orgService.save(org);
|
|
|
+ OrgEntity saved = orgService.save(org);
|
|
|
return saved;
|
|
|
}
|
|
|
|
|
@@ -333,20 +337,25 @@ public class OrgController extends ControllerSupport {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "查询logo")
|
|
|
+ @ApiOperation(value = "获取logo")
|
|
|
@GetMapping("/logo")
|
|
|
public void getLogo(@RequestParam("domain") String domain, HttpServletResponse response)
|
|
|
throws IOException {
|
|
|
- Org org = orgRepo.findRootOrg(domain);
|
|
|
- String logo = org.getLogo();
|
|
|
- IOUtils.copy(new FileInputStream(logo), response.getOutputStream());
|
|
|
- response.flushBuffer();
|
|
|
+ OrgEntity org = orgRepo.findRootOrg(domain);
|
|
|
+ DynamicEnumManager manager = OrgProperty.getDynamicEnumManager();
|
|
|
+ DynamicEnum de = manager.getByName("LOGO_PATH");
|
|
|
+
|
|
|
+ OrgPropertyEntity entity = orgPropertyRepo.findByOrgIdAndKeyId(org.getId(), de.getId());
|
|
|
+ if (null != entity) {
|
|
|
+ IOUtils.copy(new FileInputStream(entity.getValue()), response.getOutputStream());
|
|
|
+ response.flushBuffer();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "查询顶级机构")
|
|
|
@GetMapping("/getRootOrgByCode")
|
|
|
- public Org getRootOrgByCode(@RequestParam("code") String code) throws IOException {
|
|
|
- Org org = orgRepo.findRootOrg(code);
|
|
|
+ public OrgEntity getRootOrgByCode(@RequestParam("code") String code) throws IOException {
|
|
|
+ OrgEntity org = orgRepo.findRootOrg(code);
|
|
|
return org;
|
|
|
}
|
|
|
|
|
@@ -360,8 +369,8 @@ public class OrgController extends ControllerSupport {
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
@ApiOperation(value = "导入logo", notes = "导入logo")
|
|
|
- @PostMapping("/importLogo/{id}")
|
|
|
- public void importLogo(@PathVariable Long id, HttpServletRequest request,
|
|
|
+ @PostMapping("/importLogo/{orgId}")
|
|
|
+ public void importLogo(@PathVariable Long orgId, HttpServletRequest request,
|
|
|
@RequestParam CommonsMultipartFile file) throws IOException {
|
|
|
String schoolLogoPath = PropertiesUtil.getString(PropKeys.SCHOOL_LOGO_PATH);
|
|
|
if (StringUtils.isBlank(schoolLogoPath)) {
|
|
@@ -371,17 +380,28 @@ public class OrgController extends ControllerSupport {
|
|
|
String name = fileItem.getName();
|
|
|
String filePath = null;
|
|
|
if (name.endsWith(".jpg")) {
|
|
|
- filePath = schoolLogoPath + "/" + id + ".jpg";
|
|
|
+ filePath = schoolLogoPath + "/" + orgId + ".jpg";
|
|
|
} else if (name.endsWith(".gif")) {
|
|
|
- filePath = schoolLogoPath + "/" + id + ".gif";
|
|
|
+ filePath = schoolLogoPath + "/" + orgId + ".gif";
|
|
|
} else if (name.endsWith(".png")) {
|
|
|
- filePath = schoolLogoPath + "/" + id + ".png";
|
|
|
+ filePath = schoolLogoPath + "/" + orgId + ".png";
|
|
|
} else {
|
|
|
throw new StatusException("B-101001", "文件格式错误");
|
|
|
}
|
|
|
|
|
|
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(filePath));
|
|
|
- jdbcTemplate.update("update ecs_core_org t set t.logo=? where t.id=?", filePath, id);
|
|
|
+
|
|
|
+ DynamicEnumManager manager = OrgProperty.getDynamicEnumManager();
|
|
|
+ DynamicEnum de = manager.getByName("LOGO_PATH");
|
|
|
+
|
|
|
+ OrgPropertyEntity entity = orgPropertyRepo.findByOrgIdAndKeyId(orgId, de.getId());
|
|
|
+ if (null == entity) {
|
|
|
+ entity = new OrgPropertyEntity();
|
|
|
+ entity.setId(de.getId());
|
|
|
+ entity.setOrgId(orgId);
|
|
|
+ }
|
|
|
+ entity.setValue(filePath);
|
|
|
+ orgPropertyRepo.save(entity);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -394,9 +414,9 @@ public class OrgController extends ControllerSupport {
|
|
|
*/
|
|
|
@ApiOperation(value = "按机构名称模糊查询子机构列表")
|
|
|
@PostMapping("getSubOrgListByNameLike/{parentId}")
|
|
|
- public List<Org> getSubOrgListByNameLike(@PathVariable Long parentId,
|
|
|
+ public List<OrgEntity> getSubOrgListByNameLike(@PathVariable Long parentId,
|
|
|
@RequestParam String orgName) {
|
|
|
- List<Org> list = null;
|
|
|
+ List<OrgEntity> list = null;
|
|
|
if (StringUtils.isBlank(orgName)) {
|
|
|
list = Lists.newArrayList();
|
|
|
return list;
|