feat: 新增多个服务类及工具类,重构部分代码结构

重构服务类结构,将分散的服务统一整合到service包下
新增ProjectConstant常量类及多个实体服务类
添加SecurityUtils安全工具类和BeanCacher工具类
优化部分UI控件和转换器的实现
This commit is contained in:
2025-09-06 13:43:52 +08:00
parent 0e444508ff
commit effd7b103c
253 changed files with 2920 additions and 1646 deletions

View File

@@ -0,0 +1,50 @@
package com.ecep.contract.ds.other.controller;
import java.util.Map;
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.jpa.domain.Specification;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ecep.contract.cloud.rk.CloudRkService;
import com.ecep.contract.model.CloudRk;
@RestController
@RequestMapping("/cloudRk")
public class CloudRkController {
@Autowired
private CloudRkService cloudRkService;
@RequestMapping("/findById")
public CloudRk findById(Integer id) {
return cloudRkService.findById(id);
}
@RequestMapping("/list")
public Page<CloudRk> list(
Map<String, Object> params,
@RequestParam(defaultValue = "0", name = "page") int pageNumber,
@RequestParam(defaultValue = "10", name = "size") int pageSize) {
Specification<CloudRk> spec = null;
Sort sort = Sort.by(Sort.Order.desc("id"));
Pageable pageable = PageRequest.of(pageNumber, pageSize, sort);
return cloudRkService.findAll(spec, pageable);
}
@RequestMapping("/save")
public CloudRk save(CloudRk cloudRk) {
return cloudRkService.save(cloudRk);
}
@RequestMapping("/delete")
public void delete(Integer id) {
CloudRk cloudRk = cloudRkService.findById(id);
cloudRkService.delete(cloudRk);
}
}

View File

@@ -0,0 +1,50 @@
package com.ecep.contract.ds.other.controller;
import java.util.Map;
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.jpa.domain.Specification;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ecep.contract.cloud.tyc.CloudTycService;
import com.ecep.contract.model.CloudTyc;
@RestController
@RequestMapping("/cloudTyc")
public class CloudTycController {
@Autowired
private CloudTycService cloudTycService;
@RequestMapping("/findById")
public CloudTyc findById(Integer id) {
return cloudTycService.findById(id);
}
@RequestMapping("/list")
public Page<CloudTyc> list(
Map<String, Object> params,
@RequestParam(defaultValue = "0", name = "page") int pageNumber,
@RequestParam(defaultValue = "10", name = "size") int pageSize) {
Specification<CloudTyc> spec = null;
Sort sort = Sort.by(Sort.Order.desc("id"));
Pageable pageable = PageRequest.of(pageNumber, pageSize, sort);
return cloudTycService.findAll(spec, pageable);
}
@RequestMapping("/save")
public CloudTyc save(CloudTyc cloudTyc) {
return cloudTycService.save(cloudTyc);
}
@RequestMapping("/delete")
public void delete(Integer id) {
CloudTyc cloudTyc = cloudTycService.findById(id);
cloudTycService.delete(cloudTyc);
}
}

View File

@@ -0,0 +1,50 @@
package com.ecep.contract.ds.other.controller;
import java.util.Map;
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.jpa.domain.Specification;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ecep.contract.cloud.u8.YongYouU8Service;
import com.ecep.contract.model.CloudYu;
@RestController
@RequestMapping("/cloudYu")
public class CloudYuController {
@Autowired
private YongYouU8Service yongYouU8Service;
@RequestMapping("/findById")
public CloudYu findById(Integer id) {
return yongYouU8Service.findById(id);
}
@RequestMapping("/list")
public Page<CloudYu> list(
Map<String, Object> params,
@RequestParam(defaultValue = "0", name = "page") int pageNumber,
@RequestParam(defaultValue = "10", name = "size") int pageSize) {
Specification<CloudYu> spec = null;
Sort sort = Sort.by(Sort.Order.desc("id"));
Pageable pageable = PageRequest.of(pageNumber, pageSize, sort);
return yongYouU8Service.findAll(spec, pageable);
}
@RequestMapping("/save")
public CloudYu save(CloudYu cloudYu) {
return yongYouU8Service.save(cloudYu);
}
@RequestMapping("/delete")
public void delete(Integer id) {
CloudYu cloudYu = yongYouU8Service.findById(id);
yongYouU8Service.delete(cloudYu);
}
}

View File

@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RestController;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.model.Employee;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.ecep.contract.util.SecurityUtils;
@RestController
@RequestMapping("/employee")
@@ -31,8 +31,9 @@ public class EmployeeController {
public Page<Employee> list(
Map<String, Object> params,
@RequestParam(defaultValue = "0", name = "page") int pageNumber,
@RequestParam(defaultValue = "10") int pageSize) {
@RequestParam(defaultValue = "10", name = "size") int pageSize) {
Specification<Employee> spec = null;
Sort sort = Sort.by(Sort.Order.desc("id"));
Pageable pageable = PageRequest.of(pageNumber, pageSize, sort);
return employeeService.findAll(spec, pageable);

View File

@@ -0,0 +1,80 @@
package com.ecep.contract.ds.other.controller;
import java.util.Map;
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.jpa.domain.Specification;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ecep.contract.ds.other.service.EmployeeRoleService;
import com.ecep.contract.model.EmployeeRole;
import com.ecep.contract.util.SecurityUtils;
import com.ecep.contract.util.SpecificationUtils;
@RestController
@RequestMapping("/employeeRole")
public class EmployeeRoleController {
@Autowired
private EmployeeRoleService employeeRoleService;
@RequestMapping("/findById")
public EmployeeRole findById(Integer id) {
return employeeRoleService.findById(id);
}
@RequestMapping("/list")
public Page<EmployeeRole> list(
Map<String, Object> params,
@RequestParam(defaultValue = "0", name = "page") int pageNumber,
@RequestParam(defaultValue = "10", name = "size") int pageSize) {
Specification<EmployeeRole> spec = null;
if (!SecurityUtils.currentUserHasRole("ROLE_ADMIN")) {
spec = SpecificationUtils.and(spec, (root, query, cb) -> cb.equal(root.get("systemAdministrator"), false));
}
String searchText = (String) params.get("searchText");
if (StringUtils.hasText(searchText)) {
spec = SpecificationUtils.andWith(searchText, (text) -> (root, query, cb) -> {
return cb.like(root.get("name"), "%" + text + "%");
});
}
Sort sort = Sort.by(Sort.Order.desc("id"));
Pageable pageable = PageRequest.of(pageNumber, pageSize, sort);
return employeeRoleService.findAll(spec, pageable);
}
@RequestMapping("/save")
public EmployeeRole save(EmployeeRole role) {
// 只有系统管理员才能保存角色
if (!SecurityUtils.currentUserHasRole("ROLE_ADMIN")) {
throw new SecurityException("无权限执行此操作");
}
return employeeRoleService.save(role);
}
@RequestMapping("/delete")
public void delete(Integer id) {
// 只有系统管理员才能删除角色
if (!SecurityUtils.currentUserHasRole("ROLE_ADMIN")) {
throw new SecurityException("无权限执行此操作");
}
EmployeeRole role = employeeRoleService.findById(id);
if (role != null && role.isSystemAdministrator()) {
throw new SecurityException("不能删除系统管理员角色");
}
employeeRoleService.delete(role);
}
@RequestMapping("/getFunctionsByRoleId")
public java.util.List<com.ecep.contract.model.Function> getFunctionsByRoleId(Integer roleId) {
return employeeRoleService.getFunctionsByRoleId(roleId);
}
}