|
@@ -2,18 +2,12 @@ package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import javax.validation.Valid;
|
|
|
|
|
|
-import cn.com.qmth.examcloud.api.commons.enums.BasicDataType;
|
|
|
-import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
-import cn.com.qmth.examcloud.core.basic.dao.entity.SpecialtyEntity;
|
|
|
-import cn.com.qmth.examcloud.core.basic.service.bean.SystemPropertyInfo;
|
|
|
-import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -23,11 +17,21 @@ 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.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.SystemPropertyRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.SystemPropertyEntity;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.SystemPropertyService;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.bean.SystemPropertyInfo;
|
|
|
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
@@ -43,75 +47,75 @@ import io.swagger.annotations.ApiOperation;
|
|
|
@RequestMapping("${$rmp.ctr.basic}/systemProperty")
|
|
|
public class SystemPropertyController extends ControllerSupport {
|
|
|
|
|
|
- @Autowired
|
|
|
- SystemPropertyService systemPropertyService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- SystemPropertyRepo systemPropertyRepo;
|
|
|
-
|
|
|
- @ApiOperation(value = "查询系统配置")
|
|
|
- @GetMapping("{key}")
|
|
|
- public Object get(@PathVariable String key) {
|
|
|
- Object object = systemPropertyService.get(key);
|
|
|
- return object;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "查询系统配置")
|
|
|
- @GetMapping("page/{curPage}/{pageSize}")
|
|
|
- public Page<SystemPropertyEntity> get(@PathVariable Integer curPage,
|
|
|
- @PathVariable Integer pageSize, @RequestParam(required = false) String propKey,
|
|
|
- @RequestParam(required = false) String description,
|
|
|
- @RequestParam(required = false) String propValue) {
|
|
|
-
|
|
|
- Specification<SystemPropertyEntity> specification = (root, query, cb) -> {
|
|
|
- List<Predicate> predicates = new ArrayList<>();
|
|
|
-
|
|
|
- if (StringUtils.isNotBlank(propKey)) {
|
|
|
- predicates.add(cb.like(root.get("propKey"), toSqlSearchPattern(propKey)));
|
|
|
- }
|
|
|
- if (StringUtils.isNotBlank(description)) {
|
|
|
- predicates.add(cb.like(root.get("description"), toSqlSearchPattern(description)));
|
|
|
- }
|
|
|
- if (StringUtils.isNotBlank(propValue)) {
|
|
|
- predicates.add(cb.like(root.get("propValue"), toSqlSearchPattern(propValue)));
|
|
|
- }
|
|
|
-
|
|
|
- return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
- };
|
|
|
-
|
|
|
- PageRequest pageRequest = PageRequest.of(curPage, pageSize,
|
|
|
- new Sort(Direction.DESC, "updateTime"));
|
|
|
-
|
|
|
- Page<SystemPropertyEntity> page = systemPropertyRepo.findAll(specification, pageRequest);
|
|
|
-
|
|
|
- return page;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "新增系统参数")
|
|
|
- @PostMapping
|
|
|
- public void addSysProp(@RequestBody @Valid SystemPropertyInfo info) {
|
|
|
- systemPropertyService.addSysProp(info);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "更新系统参数")
|
|
|
- @PutMapping
|
|
|
- public void updateSysProp(@RequestBody @Valid SystemPropertyInfo info) {
|
|
|
- systemPropertyService.updateSysProp(info);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "删除系统参数")
|
|
|
- @DeleteMapping("{ids}")
|
|
|
- public void deleteSysProp(@PathVariable @Required String ids) {
|
|
|
- List<String> propKeys = Stream.of(ids.split(",")).map(s -> s.trim())
|
|
|
- .collect(Collectors.toList());
|
|
|
- for (String key : propKeys) {
|
|
|
- SystemPropertyEntity prop = GlobalHelper.getEntity(systemPropertyRepo, key,
|
|
|
- SystemPropertyEntity.class);
|
|
|
- if (null == prop) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- systemPropertyRepo.delete(prop);
|
|
|
- }
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ SystemPropertyService systemPropertyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SystemPropertyRepo systemPropertyRepo;
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询系统配置")
|
|
|
+ @GetMapping("{key}")
|
|
|
+ public Object get(@PathVariable String key) {
|
|
|
+ Object object = systemPropertyService.get(key);
|
|
|
+ return object;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询系统配置")
|
|
|
+ @GetMapping("page/{curPage}/{pageSize}")
|
|
|
+ public Page<SystemPropertyEntity> get(@PathVariable Integer curPage,
|
|
|
+ @PathVariable Integer pageSize, @RequestParam(required = false) String propKey,
|
|
|
+ @RequestParam(required = false) String description,
|
|
|
+ @RequestParam(required = false) String propValue) {
|
|
|
+
|
|
|
+ Specification<SystemPropertyEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(propKey)) {
|
|
|
+ predicates.add(cb.like(root.get("propKey"), toSqlSearchPattern(propKey)));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(description)) {
|
|
|
+ predicates.add(cb.like(root.get("description"), toSqlSearchPattern(description)));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(propValue)) {
|
|
|
+ predicates.add(cb.like(root.get("propValue"), toSqlSearchPattern(propValue)));
|
|
|
+ }
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ PageRequest pageRequest = PageRequest.of(curPage, pageSize,
|
|
|
+ new Sort(Direction.DESC, "updateTime"));
|
|
|
+
|
|
|
+ Page<SystemPropertyEntity> page = systemPropertyRepo.findAll(specification, pageRequest);
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "新增系统参数")
|
|
|
+ @PostMapping
|
|
|
+ public void addSysProp(@RequestBody @Valid SystemPropertyInfo info) {
|
|
|
+ systemPropertyService.addSysProp(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "更新系统参数")
|
|
|
+ @PutMapping
|
|
|
+ public void updateSysProp(@RequestBody @Valid SystemPropertyInfo info) {
|
|
|
+ systemPropertyService.updateSysProp(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "删除系统参数")
|
|
|
+ @DeleteMapping("{ids}")
|
|
|
+ public void deleteSysProp(@PathVariable @Required String ids) {
|
|
|
+ List<String> propKeys = Stream.of(ids.split(",")).map(s -> s.trim())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (String key : propKeys) {
|
|
|
+ SystemPropertyEntity prop = GlobalHelper.getEntity(systemPropertyRepo, key,
|
|
|
+ SystemPropertyEntity.class);
|
|
|
+ if (null == prop) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ systemPropertyRepo.delete(prop);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|