拆分模块
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
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.ds.other.service.EmployeeService;
|
||||
import com.ecep.contract.model.Employee;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/employee")
|
||||
public class EmployyeController {
|
||||
@Autowired
|
||||
private EmployeeService employeeService;
|
||||
|
||||
@RequestMapping("/findById")
|
||||
public Employee findById(Integer id) {
|
||||
return employeeService.findById(id);
|
||||
}
|
||||
|
||||
@RequestMapping("/list")
|
||||
public Page<Employee> list(
|
||||
Map<String, Object> params,
|
||||
@RequestParam(defaultValue = "0") int pageNumber,
|
||||
@RequestParam(defaultValue = "10") int pageSize) {
|
||||
Specification<Employee> spec = (root, query, cb) -> cb.conjunction();
|
||||
Sort sort = Sort.by(Sort.Order.desc("id"));
|
||||
Pageable pageable = PageRequest.of(pageNumber, pageSize, sort);
|
||||
return employeeService.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@RequestMapping("/save")
|
||||
public Employee save(Employee employee) {
|
||||
return employeeService.save(employee);
|
||||
}
|
||||
|
||||
@RequestMapping("/delete")
|
||||
public void delete(Integer id) {
|
||||
Employee employee = employeeService.findById(id);
|
||||
employeeService.delete(employee);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.ecep.contract.ds.other.controller;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
import com.ecep.contract.MessageHolder;
|
||||
import com.ecep.contract.cloud.u8.ctx.InventoryCtx;
|
||||
import com.ecep.contract.ds.other.service.InventoryService;
|
||||
import com.ecep.contract.model.Inventory;
|
||||
import com.ecep.contract.ui.Tasker;
|
||||
|
||||
public class InventorySyncTask extends Tasker<Object> {
|
||||
private InventoryCtx inventoryCtx;
|
||||
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) throws Exception {
|
||||
inventoryCtx = new InventoryCtx();
|
||||
inventoryCtx.initializeRepository(holder);
|
||||
|
||||
InventoryService service = inventoryCtx.getInventoryService();
|
||||
Pageable pageRequest = PageRequest.ofSize(200);
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
Specification<Inventory> spec = null;
|
||||
long total = service.count(spec);
|
||||
while (true) {
|
||||
if (isCancelled()) {
|
||||
break;
|
||||
}
|
||||
|
||||
Page<Inventory> page = service.findAll(spec, pageRequest);
|
||||
if (page.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (Inventory inventory : page) {
|
||||
if (isCancelled()) {
|
||||
break;
|
||||
}
|
||||
|
||||
String prefix = counter.get() + " / " + total + "> #" + inventory.getId() + "> ";
|
||||
MessageHolder subHolder = holder.sub(prefix);
|
||||
syncInventory(inventory, subHolder);
|
||||
|
||||
updateProgress(counter.incrementAndGet(), total);
|
||||
}
|
||||
if (!page.hasNext()) {
|
||||
break;
|
||||
}
|
||||
pageRequest = page.nextPageable();
|
||||
}
|
||||
updateProgress(1, 1);
|
||||
return super.call();
|
||||
}
|
||||
|
||||
private void syncInventory(Inventory inventory, MessageHolder holder) {
|
||||
if (inventoryCtx.syncInventoryDetailByCode(inventory, inventory.getCode(), holder)) {
|
||||
inventoryCtx.getInventoryService().save(inventory);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.ecep.contract.ds.other.repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import com.ecep.contract.model.Bank;
|
||||
|
||||
@Lazy
|
||||
@Repository
|
||||
public interface BankRepository extends MyRepository<Bank, Integer> {
|
||||
Optional<Bank> findFirstByName(String name);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.ecep.contract.ds.other.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
|
||||
import com.ecep.contract.model.BaseEnumEntity;
|
||||
|
||||
@NoRepositoryBean
|
||||
public interface BaseEnumEntityRepository<N extends Enum<?>, T extends BaseEnumEntity<N>, ID>
|
||||
extends JpaRepository<T, ID> {
|
||||
List<T> findAllByLang(String lang);
|
||||
|
||||
default Map<N, T> getCompleteMapByLocal(String lang) {
|
||||
HashMap<N, T> map = new HashMap<>();
|
||||
for (T t : findAllByLang(lang)) {
|
||||
map.put(t.getType(), t);
|
||||
}
|
||||
|
||||
ArrayList<T> needSaves = new ArrayList<>();
|
||||
for (N type : getEnumConstants()) {
|
||||
T v = map.get(type);
|
||||
if (v == null) {
|
||||
v = newEntity();
|
||||
v.setType(type);
|
||||
v.setLang(lang);
|
||||
v.setValue(type.name());
|
||||
needSaves.add(v);
|
||||
}
|
||||
}
|
||||
if (!needSaves.isEmpty()) {
|
||||
for (T v : saveAll(needSaves)) {
|
||||
map.put(v.getType(), v);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
T newEntity();
|
||||
|
||||
N[] getEnumConstants();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.ecep.contract.ds.other.repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import com.ecep.contract.model.Department;
|
||||
|
||||
/**
|
||||
* 部门 Repository
|
||||
*/
|
||||
@Lazy
|
||||
@Repository
|
||||
public interface DepartmentRepository extends MyRepository<Department, Integer> {
|
||||
Optional<Department> findByName(String name);
|
||||
|
||||
Optional<Department> findByCode(String code);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.ecep.contract.ds.other.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ecep.contract.model.Employee;
|
||||
import com.ecep.contract.model.EmployeeAuthBind;
|
||||
|
||||
@Lazy
|
||||
@Repository
|
||||
public interface EmployeeAuthBindRepository extends
|
||||
// JDBC interfaces
|
||||
CrudRepository<EmployeeAuthBind, Integer>, PagingAndSortingRepository<EmployeeAuthBind, Integer>,
|
||||
// JPA interfaces
|
||||
JpaRepository<EmployeeAuthBind, Integer>, JpaSpecificationExecutor<EmployeeAuthBind> {
|
||||
List<EmployeeAuthBind> findAllByEmployee(Employee employee, Sort sort);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.ecep.contract.ds.other.repository;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ecep.contract.model.EmployeeLoginHistory;
|
||||
|
||||
@Lazy
|
||||
@Repository
|
||||
public interface EmployeeLoginHistoryRepository extends
|
||||
// JDBC interfaces
|
||||
CrudRepository<EmployeeLoginHistory, Integer>,
|
||||
PagingAndSortingRepository<EmployeeLoginHistory, Integer>,
|
||||
// JPA interfaces
|
||||
JpaRepository<EmployeeLoginHistory, Integer>, JpaSpecificationExecutor<EmployeeLoginHistory> {
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.ecep.contract.ds.other.repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import com.ecep.contract.model.Employee;
|
||||
|
||||
@Lazy
|
||||
@Repository
|
||||
public interface EmployeeRepository extends MyRepository<Employee, Integer> {
|
||||
Optional<Employee> findByAccount(String username);
|
||||
|
||||
Optional<Employee> findByName(String name);
|
||||
|
||||
Optional<Employee> findByAlias(String alias);
|
||||
|
||||
Optional<Employee> findByCode(String personCode);
|
||||
|
||||
@Modifying
|
||||
@Query(value = "update EMPLOYEE_LOGIN_HISTORY e set e.LATEST_ACTIVE = now() where e.id = ?1", nativeQuery = true)
|
||||
void updateActive(int sessionId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.ecep.contract.ds.other.repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import com.ecep.contract.model.EmployeeRole;
|
||||
|
||||
@Lazy
|
||||
@Repository
|
||||
public interface EmployeeRoleRepository extends MyRepository<EmployeeRole, Integer> {
|
||||
|
||||
Optional<EmployeeRole> findByName(String name);
|
||||
|
||||
Optional<EmployeeRole> findByCode(String personCode);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.ecep.contract.ds.other.repository;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import com.ecep.contract.model.Function;
|
||||
|
||||
@Lazy
|
||||
@Repository
|
||||
public interface FunctionRepository extends MyRepository<Function, Integer> {
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.ecep.contract.ds.other.repository;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ecep.contract.model.HolidayTable;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Repository
|
||||
public interface HolidayTableRepository // curd
|
||||
extends CrudRepository<HolidayTable, LocalDate>, PagingAndSortingRepository<HolidayTable, LocalDate> {
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.ecep.contract.ds.other.repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ecep.contract.model.InventoryCatalog;
|
||||
|
||||
@Repository
|
||||
public interface InventoryCatalogRepository extends JpaRepository<InventoryCatalog, Integer>, JpaSpecificationExecutor<InventoryCatalog> {
|
||||
Optional<InventoryCatalog> findByCode(String code);
|
||||
|
||||
Optional<InventoryCatalog> findByName(String name);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.ecep.contract.ds.other.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import com.ecep.contract.model.Inventory;
|
||||
import com.ecep.contract.model.InventoryHistoryPrice;
|
||||
|
||||
@Lazy
|
||||
@Repository
|
||||
public interface InventoryHistoryPriceRepository extends MyRepository<InventoryHistoryPrice, Integer> {
|
||||
List<InventoryHistoryPrice> findAllByInventory(Inventory inventory);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.ecep.contract.ds.other.repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ecep.contract.model.Inventory;
|
||||
|
||||
@Repository
|
||||
public interface InventoryRepository extends JpaRepository<Inventory, Integer>, JpaSpecificationExecutor<Inventory> {
|
||||
Optional<Inventory> findByCode(String code);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.ecep.contract.ds.other.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ecep.contract.model.Permission;
|
||||
|
||||
@Lazy
|
||||
@Repository
|
||||
public interface PermissionRepository extends
|
||||
// JDBC interfaces
|
||||
CrudRepository<Permission, Integer>, PagingAndSortingRepository<Permission, Integer>,
|
||||
// JPA interfaces
|
||||
JpaRepository<Permission, Integer>, JpaSpecificationExecutor<Permission> {
|
||||
|
||||
|
||||
List<Permission> findAllByFunctionId(Integer functionId);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.ecep.contract.ds.other.repository;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import com.ecep.contract.model.SysConf;
|
||||
|
||||
@Repository
|
||||
public interface SysConfRepository extends MyRepository<SysConf, String> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.ecep.contract.ds.other.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.ds.other.repository.BankRepository;
|
||||
import com.ecep.contract.model.Bank;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "bank")
|
||||
public class BankService implements IEntityService<Bank> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private BankRepository bankRepository;
|
||||
|
||||
public Bank findById(Integer id) {
|
||||
return bankRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public Page<Bank> findAll(Specification<Bank> spec, Pageable pageable) {
|
||||
return bankRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<Bank> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return (root, query, builder) -> {
|
||||
return builder.or(
|
||||
builder.like(root.get("code"), "%" + searchText + "%"),
|
||||
builder.like(root.get("name"), "%" + searchText + "%"));
|
||||
};
|
||||
}
|
||||
|
||||
public List<Bank> search(String searchText) {
|
||||
Specification<Bank> spec = getSpecification(searchText);
|
||||
return bankRepository.findAll(spec, Pageable.ofSize(10)).getContent();
|
||||
}
|
||||
|
||||
public Bank findByName(String name) {
|
||||
return bankRepository.findFirstByName(name).orElse(null);
|
||||
}
|
||||
|
||||
public Bank save(Bank entity) {
|
||||
return bankRepository.save(entity);
|
||||
}
|
||||
|
||||
public void delete(Bank entity) {
|
||||
bankRepository.delete(entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.ecep.contract.ds.other.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.ds.other.repository.DepartmentRepository;
|
||||
import com.ecep.contract.model.Department;
|
||||
|
||||
/**
|
||||
* 部门
|
||||
*/
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "department")
|
||||
public class DepartmentService implements IEntityService<Department> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private DepartmentRepository repository;
|
||||
|
||||
@Cacheable(key = "#p0")
|
||||
@Override
|
||||
public Department findById(Integer id) {
|
||||
return repository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@Cacheable(key = "'code-'+#p0")
|
||||
public Department findByCode(String code) {
|
||||
return repository.findByCode(code).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Department> findAll(Specification<Department> spec, Pageable pageable) {
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<Department> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return (root, query, builder) -> {
|
||||
// 使用或条件组合查询,以实现对员工代码或名称的模糊搜索
|
||||
return builder.or(
|
||||
builder.like(root.get("code"), "%" + searchText + "%"),
|
||||
builder.like(root.get("name"), "%" + searchText + "%")
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
public List<Department> search(String searchText) {
|
||||
Specification<Department> spec = getSpecification(searchText);
|
||||
return repository.findAll(spec, Pageable.ofSize(10)).getContent();
|
||||
}
|
||||
|
||||
@Caching(
|
||||
evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'code-'+#p0.code")
|
||||
}
|
||||
)
|
||||
@Override
|
||||
public void delete(Department entity) {
|
||||
repository.delete(entity);
|
||||
}
|
||||
|
||||
@Caching(
|
||||
evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'code-'+#p0.code")
|
||||
}
|
||||
)
|
||||
@Override
|
||||
public Department save(Department entity) {
|
||||
return repository.save(entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.ecep.contract.ds.other.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.ds.other.repository.EmployeeAuthBindRepository;
|
||||
import com.ecep.contract.model.Employee;
|
||||
import com.ecep.contract.model.EmployeeAuthBind;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "employee-auth-bind")
|
||||
public class EmployeeAuthBindService implements IEntityService<EmployeeAuthBind> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private EmployeeAuthBindRepository repository;
|
||||
|
||||
@Override
|
||||
public EmployeeAuthBind findById(Integer id) {
|
||||
return repository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<EmployeeAuthBind> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return (root, query, builder) -> {
|
||||
return builder.or(
|
||||
builder.like(root.get("ip"), "%" + searchText + "%"),
|
||||
builder.like(root.get("mac"), "%" + searchText + "%"),
|
||||
builder.like(root.get("description"), "%" + searchText + "%")
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<EmployeeAuthBind> findAll(Specification<EmployeeAuthBind> spec, Pageable pageable) {
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(EmployeeAuthBind entity) {
|
||||
repository.delete(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmployeeAuthBind save(EmployeeAuthBind entity) {
|
||||
return repository.save(entity);
|
||||
}
|
||||
|
||||
public List<EmployeeAuthBind> findAllByEmployee(Employee employee, Sort sort) {
|
||||
return repository.findAllByEmployee(employee, sort);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.ecep.contract.ds.other.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.ds.other.repository.EmployeeLoginHistoryRepository;
|
||||
import com.ecep.contract.model.EmployeeLoginHistory;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "employee-login-history")
|
||||
public class EmployeeLoginHistoryService implements IEntityService<EmployeeLoginHistory> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private EmployeeLoginHistoryRepository repository;
|
||||
|
||||
@Override
|
||||
public EmployeeLoginHistory findById(Integer id) {
|
||||
return repository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<EmployeeLoginHistory> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return (root, query, builder) -> {
|
||||
return builder.or(
|
||||
builder.like(root.get("ip"), "%" + searchText + "%"),
|
||||
builder.like(root.get("mac"), "%" + searchText + "%")
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<EmployeeLoginHistory> findAll(Specification<EmployeeLoginHistory> spec, Pageable pageable) {
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(EmployeeLoginHistory entity) {
|
||||
repository.delete(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmployeeLoginHistory save(EmployeeLoginHistory entity) {
|
||||
return repository.save(entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.ecep.contract.ds.other.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.ds.other.repository.EmployeeRoleRepository;
|
||||
import com.ecep.contract.model.EmployeeRole;
|
||||
import com.ecep.contract.model.Function;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
/**
|
||||
* 员工角色服务
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "employee-role")
|
||||
public class EmployeeRoleService implements IEntityService<EmployeeRole> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private EmployeeRoleRepository roleRepository;
|
||||
|
||||
@Cacheable(key = "#p0")
|
||||
public EmployeeRole findById(Integer id) {
|
||||
return roleRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<EmployeeRole> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return (root, query, builder) -> {
|
||||
return builder.or(
|
||||
builder.like(root.get("code"), "%" + searchText + "%"),
|
||||
builder.like(root.get("name"), "%" + searchText + "%"));
|
||||
};
|
||||
}
|
||||
|
||||
@Cacheable(key = "'code-'+#p0")
|
||||
public EmployeeRole findByCode(String code) {
|
||||
return roleRepository.findByCode(code).orElse(null);
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'code-'+#p0.code")
|
||||
})
|
||||
public EmployeeRole save(EmployeeRole role) {
|
||||
return roleRepository.save(role);
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'code-'+#p0.code")
|
||||
})
|
||||
public void delete(EmployeeRole entity) {
|
||||
roleRepository.delete(entity);
|
||||
}
|
||||
|
||||
public Page<EmployeeRole> findAll(Specification<EmployeeRole> spec, Pageable pageable) {
|
||||
return roleRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Function> getFunctionsByRoleId(int roleId) {
|
||||
Optional<EmployeeRole> optional = roleRepository.findById(roleId);
|
||||
if (optional.isPresent()) {
|
||||
EmployeeRole role = optional.get();
|
||||
return role.getFunctions().stream().toList();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package com.ecep.contract.ds.other.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.ds.other.repository.EmployeeRepository;
|
||||
import com.ecep.contract.model.Employee;
|
||||
import com.ecep.contract.model.EmployeeRole;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
/**
|
||||
* 员工服务类
|
||||
*/
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "employee")
|
||||
public class EmployeeService implements IEntityService<Employee> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(EmployeeService.class);
|
||||
public static final int DEFAULT_SYSTEM_EMPLOYEE_ID = 26;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
/**
|
||||
* 根据员工ID查找员工信息,并使用缓存机制提高查询效率。
|
||||
* <p>
|
||||
* 该方法首先会检查缓存中是否存在对应的员工信息,如果存在则直接返回缓存中的数据,
|
||||
* 如果不存在则从数据库中查询,并将查询结果存入缓存中,以便下次查询时可以直接从缓存中获取。
|
||||
*
|
||||
* @param id 员工的唯一标识符,类型为Integer。
|
||||
* @return 返回与指定ID对应的Employee对象。如果数据库中不存在该ID对应的员工信息,则返回null。
|
||||
*/
|
||||
@Cacheable(key = "#p0")
|
||||
public Employee findById(Integer id) {
|
||||
// 从员工仓库中根据ID查找员工信息,如果不存在则返回null
|
||||
return employeeRepository.findById(id).orElse(null);
|
||||
}
|
||||
@Cacheable(key = "'ac-'+#p0")
|
||||
public Employee findByAccount(String username) {
|
||||
return employeeRepository.findByAccount(username).orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(key = "'name-'+#p0")
|
||||
public Employee findByName(String name) {
|
||||
return employeeRepository.findByName(name).orElseGet(() -> {
|
||||
return employeeRepository.findByAlias(name).orElse(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Cacheable(key = "'code-'+#p0")
|
||||
public Employee findByCode(String personCode) {
|
||||
return employeeRepository.findByCode(personCode).orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存员工信息,并在保存成功后根据指定的缓存键清除相关缓存。
|
||||
* <p>
|
||||
* 该函数使用了Spring的缓存注解 `@Caching`,结合 `@CacheEvict` 注解,在保存员工信息后,
|
||||
* 清除与该员工相关的缓存。具体清除的缓存键包括:
|
||||
* - 以员工ID为键的缓存
|
||||
* - 以员工姓名为键的缓存(键格式为 "name-员工姓名")
|
||||
* - 以员工代码为键的缓存(键格式为 "code-员工代码")
|
||||
*
|
||||
* @param employee 要保存的员工对象,包含员工的ID、姓名、代码等信息。
|
||||
* @return 返回保存后的员工对象,通常与传入的对象相同,但可能包含数据库生成的新ID或其他更新后的字段。
|
||||
*/
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'ac-'+#p0.account"),
|
||||
@CacheEvict(key = "'name-'+#p0.name"),
|
||||
@CacheEvict(key = "'code-'+#p0.code")
|
||||
})
|
||||
public Employee save(Employee employee) {
|
||||
// 调用员工仓库的保存方法,将员工信息持久化到数据库
|
||||
return employeeRepository.save(employee);
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"), @CacheEvict(key = "'ac-'+#p0.account"),
|
||||
@CacheEvict(key = "'name-'+#p0.name"),
|
||||
@CacheEvict(key = "'code-'+#p0.code")
|
||||
})
|
||||
public void delete(Employee employee) {
|
||||
employeeRepository.delete(employee);
|
||||
}
|
||||
|
||||
public Page<Employee> findAll(Specification<Employee> spec, Pageable pageable) {
|
||||
return employeeRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<Employee> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return (root, query, builder) -> {
|
||||
// 使用或条件组合查询,以实现对员工代码或名称的模糊搜索
|
||||
return builder.or(
|
||||
builder.like(root.get("account"), "%" + searchText + "%"),
|
||||
builder.like(root.get("name"), "%" + searchText + "%"),
|
||||
builder.like(root.get("alias"), "%" + searchText + "%"),
|
||||
builder.like(root.get("code"), "%" + searchText + "%"),
|
||||
builder.like(root.get("email"), "%" + searchText + "%"),
|
||||
builder.like(root.get("phone"), "%" + searchText + "%"));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据搜索文本查询员工列表
|
||||
* 此方法构建了一个特定的规格化查询,以实现对员工代码或名称的模糊搜索
|
||||
* 它通过将搜索文本与员工代码和名称进行模糊匹配来筛选结果
|
||||
* 此外,它只返回搜索结果的前10条记录
|
||||
*
|
||||
* @param searchText 要搜索的文本,用于在员工代码和名称中进行模糊匹配
|
||||
* @return 包含搜索结果的员工列表,最多10条记录
|
||||
*/
|
||||
public List<Employee> search(String searchText) {
|
||||
// 创建一个Specification对象,用于定义复杂的查询条件
|
||||
Specification<Employee> spec = getSpecification(searchText);
|
||||
return employeeRepository.findAll(spec, Pageable.ofSize(10)).getContent();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateActive(int sessionId) {
|
||||
employeeRepository.updateActive(sessionId);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<EmployeeRole> getRolesByEmployeeId(int employeeId) {
|
||||
Optional<Employee> optional = employeeRepository.findById(employeeId);
|
||||
if (optional.isPresent()) {
|
||||
Employee employee = optional.get();
|
||||
return employee.getRoles().stream().toList();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.ecep.contract.ds.other.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.ds.other.repository.FunctionRepository;
|
||||
import com.ecep.contract.model.Function;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "function")
|
||||
public class FunctionService implements IEntityService<Function> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private FunctionRepository repository;
|
||||
|
||||
/*
|
||||
|
||||
|
||||
*/
|
||||
@Cacheable(key = "#p0")
|
||||
public Function findById(Integer id) {
|
||||
return repository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id")
|
||||
})
|
||||
public Function save(Function role) {
|
||||
return repository.save(role);
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id")
|
||||
})
|
||||
public void delete(Function entity) {
|
||||
repository.delete(entity);
|
||||
}
|
||||
|
||||
public Page<Function> findAll(Specification<Function> spec, Pageable pageable) {
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<Function> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return (root, query, builder) -> {
|
||||
return builder.or(
|
||||
builder.like(root.get("key"), "%" + searchText + "%"),
|
||||
builder.like(root.get("name"), "%" + searchText + "%"),
|
||||
builder.like(root.get("controller"), "%" + searchText + "%"),
|
||||
builder.like(root.get("icon"), "%" + searchText + "%")
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.ecep.contract.ds.other.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.ecep.contract.ds.other.repository.InventoryCatalogRepository;
|
||||
import com.ecep.contract.model.InventoryCatalog;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "inventory-catalog")
|
||||
public class InventoryCatalogService {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private InventoryCatalogRepository repository;
|
||||
|
||||
@Cacheable(key = "#p0")
|
||||
public InventoryCatalog findById(Integer id) {
|
||||
return repository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
|
||||
@Cacheable(key = "'code-'+#p0")
|
||||
public InventoryCatalog findByCode(String code) {
|
||||
return repository.findByCode(code).orElse(null);
|
||||
}
|
||||
|
||||
@Cacheable(key = "'name-'+#p0")
|
||||
public InventoryCatalog findByName(String name) {
|
||||
return repository.findByName(name).orElse(null);
|
||||
}
|
||||
|
||||
public Page<InventoryCatalog> findAll(Specification<InventoryCatalog> spec, Pageable pageable) {
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Caching(
|
||||
evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'code-'+#p0.code"),
|
||||
@CacheEvict(key = "'name-'+#p0.code")
|
||||
}
|
||||
)
|
||||
public InventoryCatalog save(InventoryCatalog entity) {
|
||||
return repository.save(entity);
|
||||
}
|
||||
|
||||
public List<InventoryCatalog> search(String searchText) {
|
||||
Specification<InventoryCatalog> spec = (root, query, builder) -> {
|
||||
return builder.or(builder.like(root.get("code"), "%" + searchText + "%"),
|
||||
builder.like(root.get("name"), "%" + searchText + "%"));
|
||||
};
|
||||
return repository.findAll(spec, Pageable.ofSize(10)).getContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.ecep.contract.ds.other.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.ds.other.repository.InventoryHistoryPriceRepository;
|
||||
import com.ecep.contract.model.Inventory;
|
||||
import com.ecep.contract.model.InventoryHistoryPrice;
|
||||
|
||||
import jakarta.persistence.criteria.Path;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "inventory-history-price")
|
||||
public class InventoryHistoryPriceService implements IEntityService<InventoryHistoryPrice> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
InventoryHistoryPriceRepository repository;
|
||||
|
||||
@Override
|
||||
public InventoryHistoryPrice findById(Integer id) {
|
||||
return repository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<InventoryHistoryPrice> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return (root, query, builder) -> {
|
||||
Path<Inventory> inventory = root.get("inventory");
|
||||
return builder.or(
|
||||
builder.like(inventory.get("name"), "%" + searchText + "%"),
|
||||
builder.like(inventory.get("specification"), "%" + searchText + "%")
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<InventoryHistoryPrice> findAll(Specification<InventoryHistoryPrice> spec, Pageable pageable) {
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
|
||||
public List<InventoryHistoryPrice> findAllByInventory(Inventory inventory) {
|
||||
return repository.findAllByInventory(inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(InventoryHistoryPrice entity) {
|
||||
repository.delete(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHistoryPrice save(InventoryHistoryPrice entity) {
|
||||
return repository.save(entity);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.ecep.contract.ds.other.service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.ds.other.repository.InventoryRepository;
|
||||
import com.ecep.contract.model.Inventory;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
|
||||
import jakarta.persistence.criteria.Join;
|
||||
import jakarta.persistence.criteria.JoinType;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "inventory")
|
||||
public class InventoryService implements IEntityService<Inventory> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private InventoryRepository inventoryRepository;
|
||||
@Getter
|
||||
@Setter
|
||||
private int searchPageSize = 10;
|
||||
|
||||
@Cacheable(key = "#p0")
|
||||
public Inventory findById(Integer id) {
|
||||
return inventoryRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public Page<Inventory> findAll(Specification<Inventory> spec, Pageable pageable) {
|
||||
return inventoryRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<Inventory> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return SpecificationUtils.andWith(searchText, this::buildSearchSpecification);
|
||||
}
|
||||
|
||||
protected Specification<Inventory> buildSearchSpecification(String searchText) {
|
||||
return (root, query, builder) -> {
|
||||
Join<Object, Object> catalog = root.join("catalog", JoinType.LEFT);
|
||||
query.orderBy(
|
||||
builder.asc(builder.length(root.get("name"))),
|
||||
builder.asc(builder.length(root.get("specification"))));
|
||||
return builder.or(
|
||||
builder.and(
|
||||
builder.isNotNull(catalog),
|
||||
builder.equal(catalog.get("name"), searchText)),
|
||||
builder.like(root.get("code"), "%" + searchText + "%"),
|
||||
builder.like(root.get("specification"), "%" + searchText + "%"),
|
||||
builder.like(root.get("name"), "%" + searchText + "%"));
|
||||
};
|
||||
}
|
||||
|
||||
public List<Inventory> search(String searchText) {
|
||||
Pageable pageable = Pageable.ofSize(getSearchPageSize());
|
||||
pageable.getSort().and(Sort.by(Sort.Direction.DESC, "id"));
|
||||
Specification<Inventory> specification = getSpecification(searchText);
|
||||
return inventoryRepository.findAll(specification, pageable).getContent();
|
||||
}
|
||||
|
||||
@Cacheable(key = "'code-'+#p0")
|
||||
public Inventory findByCode(String code) {
|
||||
return inventoryRepository.findByCode(code).orElse(null);
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'code-'+#p0.code"),
|
||||
})
|
||||
public Inventory save(Inventory entity) {
|
||||
return inventoryRepository.save(entity);
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'code-'+#p0.code"),
|
||||
})
|
||||
public void delete(Inventory entity) {
|
||||
inventoryRepository.delete(entity);
|
||||
}
|
||||
|
||||
public long count(Specification<Inventory> spec) {
|
||||
return inventoryRepository.count(spec);
|
||||
}
|
||||
|
||||
public Inventory createNewInstance() {
|
||||
Inventory inventory = new Inventory();
|
||||
|
||||
inventory.setNameLock(false);
|
||||
inventory.setSpecificationLock(false);
|
||||
inventory.getSalePrice().setTaxRate(13);
|
||||
inventory.getPurchasePrice().setTaxRate(13);
|
||||
inventory.setWeightUnit("kg");
|
||||
inventory.setVolumeUnit("m³");
|
||||
inventory.setSizeUnit("mm");
|
||||
|
||||
inventory.setCreateTime(LocalDate.now());
|
||||
return inventory;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.ecep.contract.ds.other.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.ds.other.repository.PermissionRepository;
|
||||
import com.ecep.contract.model.Permission;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "permission")
|
||||
public class PermissionService implements IEntityService<Permission> {
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private PermissionRepository permissionRepository;
|
||||
|
||||
/*
|
||||
*/
|
||||
@Cacheable(key = "'permission-'+#p0")
|
||||
public Permission findById(Integer id) {
|
||||
return permissionRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<Permission> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return (root, query, builder) -> {
|
||||
return builder.or(
|
||||
builder.like(root.get("name"), "%" + searchText + "%"));
|
||||
};
|
||||
}
|
||||
|
||||
@Cacheable(key = "'permission-code-'+#p0")
|
||||
public Permission findByCode(String code) {
|
||||
// return permissionRepository.findByCode(code).orElse(null);
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "'permission-'+#p0.id"),
|
||||
// @CacheEvict(key = "'permission-code-'+#p0.code")
|
||||
})
|
||||
public Permission save(Permission role) {
|
||||
return permissionRepository.save(role);
|
||||
}
|
||||
|
||||
public Page<Permission> findAll(Specification<Permission> spec, Pageable pageable) {
|
||||
return permissionRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Permission entity) {
|
||||
permissionRepository.delete(entity);
|
||||
}
|
||||
|
||||
public List<Permission> findByFunctionId(int functionId) {
|
||||
return permissionRepository.findAllByFunctionId(functionId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.ecep.contract.ds.other.service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.ecep.contract.ds.other.repository.SysConfRepository;
|
||||
import com.ecep.contract.model.SysConf;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "sys_conf")
|
||||
public class SysConfService {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private SysConfRepository repository;
|
||||
|
||||
public SysConf findById(String key) {
|
||||
return repository.findById(key).orElse(null);
|
||||
}
|
||||
|
||||
@CacheEvict(key = "#p0.id")
|
||||
public SysConf save(SysConf conf) {
|
||||
return repository.save(conf);
|
||||
}
|
||||
|
||||
@CacheEvict(key = "#p0")
|
||||
public SysConf set(String key, String value) {
|
||||
SysConf conf = findById(key);
|
||||
if (conf == null) {
|
||||
conf = new SysConf();
|
||||
conf.setId(key);
|
||||
conf.setCreated(LocalDateTime.now());
|
||||
}
|
||||
conf.setValue(value);
|
||||
conf.setModified(LocalDateTime.now());
|
||||
repository.save(conf);
|
||||
return conf;
|
||||
}
|
||||
|
||||
@Cacheable(key = "#p0")
|
||||
public String getString(String key) {
|
||||
return get(key, null);
|
||||
}
|
||||
|
||||
public String get(String key, String defaultValue) {
|
||||
SysConf conf = findById(key);
|
||||
if (conf == null) {
|
||||
return defaultValue;
|
||||
} else {
|
||||
return conf.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@Cacheable(key = "#p0")
|
||||
public long getLong(String key) {
|
||||
return get(key, 0);
|
||||
}
|
||||
|
||||
public long get(String key, long defaultValue) {
|
||||
SysConf conf = findById(key);
|
||||
if (conf == null) {
|
||||
return defaultValue;
|
||||
} else {
|
||||
return Long.parseLong(conf.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Cacheable(key = "#p0")
|
||||
public int getInt(String key) {
|
||||
return get(key, 0);
|
||||
}
|
||||
|
||||
public int get(String key, int defaultValue) {
|
||||
SysConf conf = findById(key);
|
||||
if (conf == null) {
|
||||
return defaultValue;
|
||||
} else {
|
||||
return Integer.parseInt(conf.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Cacheable(key = "#p0")
|
||||
public boolean getBoolean(String key) {
|
||||
return get(key, false);
|
||||
}
|
||||
|
||||
public boolean get(String key, boolean defaultValue) {
|
||||
SysConf conf = findById(key);
|
||||
if (conf == null) {
|
||||
return defaultValue;
|
||||
} else {
|
||||
if (Boolean.parseBoolean(conf.getValue())) {
|
||||
return true;
|
||||
}
|
||||
return "1".equalsIgnoreCase(conf.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user