feat: 新增多个服务类及工具类,重构部分代码结构
重构服务类结构,将分散的服务统一整合到service包下 新增ProjectConstant常量类及多个实体服务类 添加SecurityUtils安全工具类和BeanCacher工具类 优化部分UI控件和转换器的实现
This commit is contained in:
@@ -14,7 +14,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.MessageHolder;
|
||||
import com.ecep.contract.SpringApp;
|
||||
import com.ecep.contract.cloud.u8.ctx.ContractCtx;
|
||||
import com.ecep.contract.constant.CloudYuConstant;
|
||||
import com.ecep.contract.ds.contract.tasker.AbstContractRepairTasker;
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ public class ContractSyncTask extends AbstContractRepairTasker {
|
||||
holder.error("无法获取 YongYouU8Repository " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
if (getConfService().getBoolean(ContractCtx.KEY_SYNC_USE_LATEST_ID)) {
|
||||
if (getConfService().getBoolean(CloudYuConstant.KEY_SYNC_USE_LATEST_ID)) {
|
||||
syncByLatestId(holder);
|
||||
} else {
|
||||
syncByLatestDate(holder);
|
||||
@@ -45,7 +45,7 @@ public class ContractSyncTask extends AbstContractRepairTasker {
|
||||
}
|
||||
|
||||
private void syncByLatestId(MessageHolder holder) {
|
||||
int latestId = getConfService().getInt(ContractCtx.KEY_SYNC_BY_LATEST_ID);
|
||||
int latestId = getConfService().getInt(CloudYuConstant.KEY_SYNC_BY_LATEST_ID);
|
||||
updateTitle("用友U8系统-同步合同,从 " + latestId + " 开始");
|
||||
|
||||
Long total = repository.countAllContracts(latestId);
|
||||
@@ -81,11 +81,11 @@ public class ContractSyncTask extends AbstContractRepairTasker {
|
||||
updateProgress(counter.incrementAndGet(), total);
|
||||
});
|
||||
}
|
||||
getConfService().set(ContractCtx.KEY_SYNC_BY_LATEST_ID, String.valueOf(reference.get()));
|
||||
getConfService().set(CloudYuConstant.KEY_SYNC_BY_LATEST_ID, String.valueOf(reference.get()));
|
||||
}
|
||||
|
||||
private void syncByLatestDate(MessageHolder holder) {
|
||||
String strDateTime = getConfService().getString(ContractCtx.KEY_SYNC_BY_LATEST_DATE);
|
||||
String strDateTime = getConfService().getString(CloudYuConstant.KEY_SYNC_BY_LATEST_DATE);
|
||||
LocalDateTime latestDateTime = null;
|
||||
if (StringUtils.hasText(strDateTime)) {
|
||||
try {
|
||||
@@ -135,7 +135,7 @@ public class ContractSyncTask extends AbstContractRepairTasker {
|
||||
updateProgress(counter.incrementAndGet(), total);
|
||||
});
|
||||
}
|
||||
getConfService().set(ContractCtx.KEY_SYNC_BY_LATEST_DATE, String.valueOf(reference.get()));
|
||||
getConfService().set(CloudYuConstant.KEY_SYNC_BY_LATEST_DATE, String.valueOf(reference.get()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.MessageHolder;
|
||||
import com.ecep.contract.constant.CloudServiceConstant;
|
||||
import com.ecep.contract.constant.CloudYuConstant;
|
||||
import com.ecep.contract.ds.company.service.CompanyOldNameService;
|
||||
import com.ecep.contract.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.model.Company;
|
||||
@@ -18,11 +19,6 @@ import com.ecep.contract.model.CompanyOldName;
|
||||
import lombok.Setter;
|
||||
|
||||
public class CompanyCtx extends AbstractYongYouU8Ctx {
|
||||
/**
|
||||
* 自动创建公司的时间
|
||||
*/
|
||||
public static final String AUTO_CREATE_COMPANY_AFTER = "cloud.u8.auto-create-company-after";
|
||||
|
||||
@Setter
|
||||
private CompanyOldNameService companyOldNameService;
|
||||
|
||||
@@ -114,7 +110,7 @@ public class CompanyCtx extends AbstractYongYouU8Ctx {
|
||||
return null;
|
||||
}
|
||||
CompanyService companyService = getCompanyService();
|
||||
String autoCreateAfter = getConfService().getString(AUTO_CREATE_COMPANY_AFTER);
|
||||
String autoCreateAfter = getConfService().getString(CloudYuConstant.KEY_AUTO_CREATE_COMPANY_AFTER);
|
||||
// 当配置存在,且开发时间小于指定时间,不创建
|
||||
if (StringUtils.hasText(autoCreateAfter)) {
|
||||
LocalDate miniDate = LocalDate.parse(autoCreateAfter);
|
||||
|
||||
@@ -66,24 +66,6 @@ import lombok.Setter;
|
||||
* 合同上下文
|
||||
*/
|
||||
public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
public static final String KEY_PREFIX = "cloud.u8.contract.";
|
||||
/**
|
||||
* 合同同步后的最后一个日期
|
||||
*/
|
||||
public static final String KEY_SYNC_BY_LATEST_DATE = KEY_PREFIX + "latestDate";
|
||||
/**
|
||||
* 合同同步后的最后一个合同ID
|
||||
*/
|
||||
public static final String KEY_SYNC_BY_LATEST_ID = KEY_PREFIX + "latestId";
|
||||
/**
|
||||
* 合同同步时是否使用最后更新的Id来判断更新范围,否则使用最后更新的合同日期来判断更新范围
|
||||
*/
|
||||
public static final String KEY_SYNC_USE_LATEST_ID = KEY_PREFIX + "sync.use-latest-id";
|
||||
/**
|
||||
* 合同同步时的时间间隔,单位:秒
|
||||
*/
|
||||
public static final String KEY_SYNC_ELAPSE = KEY_PREFIX + "sync.elapse";
|
||||
|
||||
@Setter
|
||||
private ContractService contractService;
|
||||
@Setter
|
||||
|
||||
@@ -132,6 +132,10 @@ public class SecurityConfig {
|
||||
return User.builder()
|
||||
.username(employee.getName())
|
||||
.password(passwordEncoder().encode("default123")) // 使用默认密码进行加密
|
||||
.accountExpired(false) // 账户未过期
|
||||
.accountLocked(false) // 账户未锁定
|
||||
.credentialsExpired(false) // 凭证未过期
|
||||
.disabled(!employee.isActive()) // 根据员工状态设置是否禁用
|
||||
.authorities(authorities)
|
||||
.build();
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.ecep.contract.ds.company;
|
||||
|
||||
import com.ecep.contract.ds.company.service.CompanyContactService;
|
||||
import com.ecep.contract.ds.converter.EntityStringConverter;
|
||||
import com.ecep.contract.model.CompanyContact;
|
||||
import com.ecep.contract.util.EntityStringConverter;
|
||||
|
||||
public class CompanyContactStringConverter extends EntityStringConverter<CompanyContact> {
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.ecep.contract.ds.company.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.company.service.CompanyService;
|
||||
import com.ecep.contract.model.Company;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/company")
|
||||
public class CompanyController {
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
|
||||
@RequestMapping("/findById")
|
||||
public Company findById(Integer id) {
|
||||
return companyService.findById(id);
|
||||
}
|
||||
|
||||
@RequestMapping("/list")
|
||||
public Page<Company> list(
|
||||
Map<String, Object> params,
|
||||
@RequestParam(defaultValue = "0", name = "page") int pageNumber,
|
||||
@RequestParam(defaultValue = "10", name = "size") int pageSize) {
|
||||
Specification<Company> spec = null;
|
||||
Sort sort = Sort.by(Sort.Order.desc("id"));
|
||||
Pageable pageable = PageRequest.of(pageNumber, pageSize, sort);
|
||||
return companyService.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@RequestMapping("/save")
|
||||
public Company save(Company company) {
|
||||
return companyService.save(company);
|
||||
}
|
||||
|
||||
@RequestMapping("/delete")
|
||||
public void delete(Integer id) {
|
||||
Company company = companyService.findById(id);
|
||||
companyService.delete(company);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import com.ecep.contract.MyDateTimeUtils;
|
||||
import com.ecep.contract.cloud.rk.CloudRkService;
|
||||
import com.ecep.contract.cloud.tyc.CloudTycService;
|
||||
import com.ecep.contract.cloud.u8.YongYouU8Service;
|
||||
import com.ecep.contract.constant.CompanyCustomerConstant;
|
||||
import com.ecep.contract.constant.CompanyVendorConstant;
|
||||
import com.ecep.contract.ds.company.CompanyFileUtils;
|
||||
import com.ecep.contract.ds.company.repository.CompanyRepository;
|
||||
@@ -374,7 +375,7 @@ public class CompanyService implements IEntityService<Company> {
|
||||
}
|
||||
|
||||
public File getCustomerBasePath() {
|
||||
return new File(confService.getString(CompanyCustomerService.KEY_BASE_PATH));
|
||||
return new File(confService.getString(CompanyCustomerConstant.KEY_BASE_PATH));
|
||||
}
|
||||
|
||||
public File getBasePath() {
|
||||
|
||||
@@ -5,8 +5,8 @@ import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.ecep.contract.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.ds.converter.EntityStringConverter;
|
||||
import com.ecep.contract.model.Contract;
|
||||
import com.ecep.contract.util.EntityStringConverter;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
|
||||
@@ -32,27 +32,6 @@ import com.ecep.contract.model.ContractFileTypeLocal;
|
||||
@CacheConfig(cacheNames = "contract-file")
|
||||
public class ContractFileService implements IEntityService<ContractFile> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContractFileService.class);
|
||||
/**
|
||||
* 销售成本核算审批表模板
|
||||
*/
|
||||
public static final String KEY_CUSTOMER_COST_TEMPLATE = "customer.contract.cost.template";
|
||||
/**
|
||||
* 项目投标审批表模板
|
||||
*/
|
||||
public static final String KEY_CUSTOMER_BID_TEMPLATE = "customer.contract.bid.template";
|
||||
/**
|
||||
* 销售合同审批表模板
|
||||
*/
|
||||
public static final String KEY_CUSTOMER_APPLY_TEMPLATE = "customer.contract.apply.template";
|
||||
/**
|
||||
* 投标报价表模板
|
||||
*/
|
||||
public static final String KEY_QUOTATION_TEMPLATE = "customer.contract.quotation.template";
|
||||
/**
|
||||
* 采购合同审批表模板
|
||||
*/
|
||||
public static final String KEY_VENDOR_APPLY_TEMPLATE = "vendor.contract.apply.template";
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ContractFileRepository contractFileRepository;
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.ContractPayWay;
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.constant.ContractConstant;
|
||||
import com.ecep.contract.ds.contract.repository.ContractRepository;
|
||||
import com.ecep.contract.ds.other.service.SysConfService;
|
||||
import com.ecep.contract.model.Company;
|
||||
@@ -51,7 +52,6 @@ import jakarta.persistence.criteria.Predicate;
|
||||
@CacheConfig(cacheNames = "contract")
|
||||
public class ContractService implements IEntityService<Contract> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContractService.class);
|
||||
public static final String CONTRACT_BASE_PATH = "contract.base.path";
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ContractCatalogService contractCatalogService;
|
||||
@@ -144,7 +144,7 @@ public class ContractService implements IEntityService<Contract> {
|
||||
}
|
||||
|
||||
public File getBasePath() {
|
||||
return new File(confService.getString(CONTRACT_BASE_PATH));
|
||||
return new File(confService.getString(ContractConstant.KEY_BASE_PATH));
|
||||
}
|
||||
|
||||
public ContractGroup findGroupById(Integer id) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.ecep.contract.ds.contract.service.ContractBidVendorService;
|
||||
import com.ecep.contract.ds.contract.service.ContractFileService;
|
||||
import com.ecep.contract.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.ds.contract.service.ExtendVendorInfoService;
|
||||
import com.ecep.contract.ds.converter.NumberStringConverter;
|
||||
import com.ecep.contract.ds.customer.service.CompanyCustomerFileService;
|
||||
import com.ecep.contract.ds.customer.service.CompanyCustomerService;
|
||||
import com.ecep.contract.ds.other.service.EmployeeService;
|
||||
@@ -18,10 +19,12 @@ import com.ecep.contract.ds.vendor.service.CompanyVendorService;
|
||||
import com.ecep.contract.ds.vendor.service.VendorGroupRequireFileTypeService;
|
||||
import com.ecep.contract.ds.vendor.service.VendorGroupService;
|
||||
import com.ecep.contract.model.*;
|
||||
import com.ecep.contract.util.NumberStringConverter;
|
||||
import com.ecep.contract.util.SecurityUtils;
|
||||
|
||||
import lombok.Data;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -397,7 +400,7 @@ public class ContractVerifyComm {
|
||||
}
|
||||
|
||||
private void verifyVendorFile(VendorGroup group, boolean assignedProvider, Contract contract,
|
||||
MessageHolder holder) {
|
||||
MessageHolder holder) {
|
||||
if (group == null) {
|
||||
return;
|
||||
}
|
||||
@@ -492,7 +495,7 @@ public class ContractVerifyComm {
|
||||
}
|
||||
|
||||
private void verifyAsCustomer(Company company, CompanyExtendInfo companyExtendInfo, Contract contract,
|
||||
MessageHolder holder) {
|
||||
MessageHolder holder) {
|
||||
boolean valiad = true;
|
||||
Project project = contract.getProject();
|
||||
if (project == null) {
|
||||
@@ -590,7 +593,7 @@ public class ContractVerifyComm {
|
||||
}
|
||||
|
||||
private boolean verifyCustomerFileByContract(CompanyCustomer companyCustomer, Contract contract,
|
||||
MessageHolder holder) {
|
||||
MessageHolder holder) {
|
||||
List<LocalDate> verifyDates = new ArrayList<>();
|
||||
LocalDate minDate = LocalDate.of(2022, 1, 1);
|
||||
LocalDate developDate = companyCustomer.getDevelopDate();
|
||||
@@ -724,13 +727,8 @@ public class ContractVerifyComm {
|
||||
// 以下代码替换原有的获取当前用户逻辑,假设用户名即为员工 ID
|
||||
// 需根据实际业务调整 UserDetails 中的信息获取方式
|
||||
tasker.setCurrentUser(() -> {
|
||||
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
String username;
|
||||
if (principal instanceof UserDetails) {
|
||||
username = ((UserDetails) principal).getUsername();
|
||||
} else {
|
||||
username = principal.toString();
|
||||
}
|
||||
User currentUser = SecurityUtils.getCurrentUser();
|
||||
String username = currentUser.getUsername();
|
||||
try {
|
||||
return getEmployeeService().findByName(username);
|
||||
} catch (NumberFormatException e) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.ecep.contract.util;
|
||||
package com.ecep.contract.ds.converter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.ecep.contract.ds;
|
||||
package com.ecep.contract.ds.converter;
|
||||
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import jakarta.persistence.Converter;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.ecep.contract.util;
|
||||
package com.ecep.contract.ds.converter;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
@@ -4,8 +4,8 @@ import java.util.function.Function;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
import com.ecep.contract.ds.converter.EntityStringConverter;
|
||||
import com.ecep.contract.model.CustomerCatalog;
|
||||
import com.ecep.contract.util.EntityStringConverter;
|
||||
|
||||
public class CustomerClassStringConverter extends EntityStringConverter<CustomerCatalog> {
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.stereotype.Service;
|
||||
import com.ecep.contract.CompanyCustomerFileType;
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.SpringApp;
|
||||
import com.ecep.contract.constant.CompanyCustomerConstant;
|
||||
import com.ecep.contract.ds.company.service.CompanyBasicService;
|
||||
import com.ecep.contract.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.ds.customer.repository.CompanyCustomerEvaluationFormFileRepository;
|
||||
@@ -41,10 +42,6 @@ import jakarta.persistence.criteria.Path;
|
||||
@CacheConfig(cacheNames = "company-customer-file")
|
||||
public class CompanyCustomerFileService implements IEntityService<CompanyCustomerFile> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyCustomerFileService.class);
|
||||
/**
|
||||
* 客户资信评估表
|
||||
*/
|
||||
public static final String KEY_EVALUATION_FORM_TEMPLATE = "customer.evaluation.form.template";
|
||||
@Lazy
|
||||
@Autowired
|
||||
private SysConfService confService;
|
||||
@@ -219,7 +216,7 @@ public class CompanyCustomerFileService implements IEntityService<CompanyCustome
|
||||
|
||||
|
||||
public File getEvaluationFormTemplate() {
|
||||
String path = confService.getString(KEY_EVALUATION_FORM_TEMPLATE);
|
||||
String path = confService.getString(CompanyCustomerConstant.KEY_EVALUATION_FORM_TEMPLATE);
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -59,9 +59,6 @@ public class CompanyCustomerService extends CompanyBasicService
|
||||
implements IEntityService<CompanyCustomer> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyCustomerService.class);
|
||||
|
||||
public static final String KEY_BASE_PATH = "customer.base.path";
|
||||
public static final String KEY_SALEBOOK_PATH = "customer.salebook.path";
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private CompanyCustomerRepository companyCustomerRepository;
|
||||
@@ -153,7 +150,7 @@ public class CompanyCustomerService extends CompanyBasicService
|
||||
}
|
||||
|
||||
public File getBasePath() {
|
||||
return new File(confService.getString(KEY_BASE_PATH));
|
||||
return new File(confService.getString(CompanyCustomerConstant.KEY_BASE_PATH));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,6 @@ import com.ecep.contract.model.CustomerSatisfactionSurvey;
|
||||
@Service
|
||||
public class CustomerSatisfactionSurveyService
|
||||
implements IEntityService<CustomerSatisfactionSurvey> {
|
||||
public final static String KEY_TEMPLATE = "project.customer-satisfaction-survey.template";
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private CustomerSatisfactionSurveyRepository repository;
|
||||
|
||||
@@ -4,8 +4,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.ecep.contract.ds.converter.EntityStringConverter;
|
||||
import com.ecep.contract.model.Project;
|
||||
import com.ecep.contract.util.EntityStringConverter;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.ecep.contract.util;
|
||||
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
|
||||
public class SecurityUtils {
|
||||
public static User getCurrentUser() {
|
||||
return (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
}
|
||||
|
||||
public static boolean currentUserHasRole(String role) {
|
||||
return getCurrentUser().getAuthorities().stream()
|
||||
.anyMatch(grantedAuthority -> grantedAuthority.getAuthority().equals(role));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user