feat: 添加按ID查询的仓库方法并优化合同同步逻辑
添加了多个仓库的按ID查询方法,如findByCompanyId和findAllByContractId 优化了合同同步任务,使用ContractVo替代Contract减少数据库访问 重构了部分服务方法,支持通过ID直接操作,提升性能 修复了ProjectCostService中字段映射错误的问题
This commit is contained in:
@@ -38,17 +38,13 @@ public class ProjectCostTabSkinBase
|
||||
implements TabSkin {
|
||||
@Setter
|
||||
LocalDateTimeStringConverter localDateTimeStringConverter;
|
||||
ProjectService projectService;
|
||||
|
||||
public ProjectCostTabSkinBase(ProjectCostWindowController controller) {
|
||||
super(controller);
|
||||
}
|
||||
|
||||
ProjectService getProjectService() {
|
||||
if (projectService == null) {
|
||||
projectService = getBean(ProjectService.class);
|
||||
}
|
||||
return projectService;
|
||||
return getCachedBean(ProjectService.class);
|
||||
}
|
||||
|
||||
private LocalDateTimeStringConverter getLocalDateTimeStringConverter() {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.ecep.contract.converter;
|
||||
|
||||
import com.ecep.contract.service.InventoryService;
|
||||
import com.ecep.contract.vo.InventoryVo;
|
||||
import javafx.util.StringConverter;
|
||||
|
||||
/**
|
||||
* 存货字符串转换器
|
||||
* 用于在UI组件中显示存货信息并支持从字符串还原存货对象
|
||||
*/
|
||||
public class InventoryStringConverter extends StringConverter<InventoryVo> {
|
||||
|
||||
/** 存货服务,用于从字符串查找对应的存货对象 */
|
||||
private final InventoryService service;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @param service 存货服务实例
|
||||
*/
|
||||
public InventoryStringConverter(InventoryService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将存货对象转换为字符串表示
|
||||
*
|
||||
* @param object 存货对象
|
||||
* @return 存货的名称,如果对象为null则返回空字符串
|
||||
*/
|
||||
@Override
|
||||
public String toString(InventoryVo object) {
|
||||
return object == null ? "" : (object.getName()+"-"+ object.getSpecification());
|
||||
}
|
||||
|
||||
/**
|
||||
* 从字符串还原存货对象
|
||||
*
|
||||
* @param string 存货名称
|
||||
* @return 对应的存货对象,如果未找到则返回null
|
||||
*/
|
||||
@Override
|
||||
public InventoryVo fromString(String string) {
|
||||
return service.findByName(string);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,10 @@ package com.ecep.contract.service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import com.ecep.contract.converter.CustomerFileTypeStringConverter;
|
||||
import com.ecep.contract.converter.InventoryStringConverter;
|
||||
import com.ecep.contract.vo.CustomerFileTypeLocalVo;
|
||||
import javafx.util.StringConverter;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -13,7 +17,7 @@ import com.ecep.contract.vo.InventoryVo;
|
||||
|
||||
@Service
|
||||
public class InventoryService extends QueryService<InventoryVo, InventoryViewModel> {
|
||||
|
||||
private final StringConverter<InventoryVo> stringConverter = new InventoryStringConverter(this);
|
||||
@Override
|
||||
public InventoryVo createNewEntity() {
|
||||
InventoryVo inventory = new InventoryVo();
|
||||
@@ -44,4 +48,8 @@ public class InventoryService extends QueryService<InventoryVo, InventoryViewMod
|
||||
return page.getContent().getFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringConverter<InventoryVo> getStringConverter() {
|
||||
return stringConverter;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,14 @@ import com.ecep.contract.SpringApp;
|
||||
import com.ecep.contract.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.ds.other.service.EmployeeService;
|
||||
import com.ecep.contract.ds.other.service.SysConfService;
|
||||
import com.ecep.contract.util.ContextUtils;
|
||||
import com.ecep.contract.util.MyStringUtils;
|
||||
import com.ecep.contract.util.NumberUtils;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
public class AbstractCtx {
|
||||
public class AbstractCtx implements ContextUtils {
|
||||
@Setter
|
||||
@Getter
|
||||
Locale locale = Locale.getDefault();
|
||||
@@ -60,7 +61,7 @@ public class AbstractCtx {
|
||||
}
|
||||
|
||||
public boolean updateText(Supplier<String> getter, Consumer<String> setter, String text, MessageHolder holder,
|
||||
String topic) {
|
||||
String topic) {
|
||||
if (!Objects.equals(getter.get(), text)) {
|
||||
setter.accept(text);
|
||||
holder.info(topic + "修改为: " + text);
|
||||
@@ -70,7 +71,7 @@ public class AbstractCtx {
|
||||
}
|
||||
|
||||
public boolean updateAppendText(Supplier<String> getter, Consumer<String> setter, String text, MessageHolder holder,
|
||||
String topic) {
|
||||
String topic) {
|
||||
if (StringUtils.hasText(text)) {
|
||||
String str = MyStringUtils.appendIfAbsent(getter.get(), text);
|
||||
if (!Objects.equals(getter.get(), str)) {
|
||||
@@ -83,7 +84,7 @@ public class AbstractCtx {
|
||||
}
|
||||
|
||||
public boolean updateLocalDate(Supplier<LocalDate> getter, Consumer<LocalDate> setter, java.sql.Date date,
|
||||
MessageHolder holder, String topic) {
|
||||
MessageHolder holder, String topic) {
|
||||
if (date != null) {
|
||||
return updateLocalDate(getter, setter, date.toLocalDate(), holder, topic);
|
||||
}
|
||||
@@ -91,12 +92,12 @@ public class AbstractCtx {
|
||||
}
|
||||
|
||||
public boolean updateLocalDate(Supplier<LocalDate> getter, Consumer<LocalDate> setter, LocalDate date,
|
||||
MessageHolder holder, String topic) {
|
||||
MessageHolder holder, String topic) {
|
||||
return updateLocalDate(getter, setter, date, holder, topic, false);
|
||||
}
|
||||
|
||||
public boolean updateLocalDate(Supplier<LocalDate> getter, Consumer<LocalDate> setter, LocalDate date,
|
||||
MessageHolder holder, String topic, boolean allowNull) {
|
||||
MessageHolder holder, String topic, boolean allowNull) {
|
||||
if (date == null && !allowNull) {
|
||||
return false;
|
||||
}
|
||||
@@ -109,7 +110,7 @@ public class AbstractCtx {
|
||||
}
|
||||
|
||||
public boolean updateLocalDate(Supplier<LocalDate> getter, Consumer<LocalDate> setter, String strDate,
|
||||
MessageHolder holder, String topic) {
|
||||
MessageHolder holder, String topic) {
|
||||
LocalDate date = null;
|
||||
if (StringUtils.hasText(strDate)) {
|
||||
try {
|
||||
@@ -122,7 +123,7 @@ public class AbstractCtx {
|
||||
}
|
||||
|
||||
public boolean updateLocalDate(Supplier<LocalDate> getter, Consumer<LocalDate> setter, Timestamp timestamp,
|
||||
MessageHolder holder, String topic) {
|
||||
MessageHolder holder, String topic) {
|
||||
LocalDate date = null;
|
||||
|
||||
if (timestamp != null) {
|
||||
@@ -136,7 +137,7 @@ public class AbstractCtx {
|
||||
}
|
||||
|
||||
public boolean updateLocalDateTime(Supplier<LocalDateTime> getter, Consumer<LocalDateTime> setter,
|
||||
Timestamp timestamp, MessageHolder holder, String topic) {
|
||||
Timestamp timestamp, MessageHolder holder, String topic) {
|
||||
LocalDateTime dateTime = null;
|
||||
|
||||
if (timestamp != null) {
|
||||
@@ -152,7 +153,7 @@ public class AbstractCtx {
|
||||
}
|
||||
|
||||
public boolean updateLocalDateTime(Supplier<LocalDateTime> getter, Consumer<LocalDateTime> setter,
|
||||
LocalDateTime dateTime, MessageHolder holder, String topic) {
|
||||
LocalDateTime dateTime, MessageHolder holder, String topic) {
|
||||
if (!Objects.equals(getter.get(), dateTime)) {
|
||||
setter.accept(dateTime);
|
||||
holder.info(topic + "修改为: " + dateTime);
|
||||
@@ -162,7 +163,7 @@ public class AbstractCtx {
|
||||
}
|
||||
|
||||
public boolean updateInstant(Supplier<Instant> getter, Consumer<Instant> setter, Instant instant,
|
||||
MessageHolder holder, String topic) {
|
||||
MessageHolder holder, String topic) {
|
||||
if (!Objects.equals(getter.get(), instant)) {
|
||||
setter.accept(instant);
|
||||
holder.info(topic + "修改为: " + instant);
|
||||
@@ -172,13 +173,13 @@ public class AbstractCtx {
|
||||
}
|
||||
|
||||
public boolean updateNumber(Supplier<Double> getter, Consumer<Double> setter, BigDecimal value,
|
||||
MessageHolder holder, String topic) {
|
||||
MessageHolder holder, String topic) {
|
||||
double val = value.doubleValue();
|
||||
return updateNumber(getter, setter, val, holder, topic);
|
||||
}
|
||||
|
||||
public boolean updateNumber(Supplier<Double> getter, Consumer<Double> setter, double value, MessageHolder holder,
|
||||
String topic) {
|
||||
String topic) {
|
||||
if (getter.get() == null || !NumberUtils.equals(getter.get(), value)) {
|
||||
setter.accept(value);
|
||||
holder.info(topic + "修改为: " + value);
|
||||
@@ -188,7 +189,7 @@ public class AbstractCtx {
|
||||
}
|
||||
|
||||
public boolean updateNumber(Supplier<Float> getter, Consumer<Float> setter, float value, MessageHolder holder,
|
||||
String topic) {
|
||||
String topic) {
|
||||
if (getter.get() == null || !NumberUtils.equals(getter.get(), value)) {
|
||||
setter.accept(value);
|
||||
holder.info(topic + "修改为: " + value);
|
||||
@@ -198,7 +199,7 @@ public class AbstractCtx {
|
||||
}
|
||||
|
||||
public boolean updateNumber(Supplier<Integer> getter, Consumer<Integer> setter, Integer value, MessageHolder holder,
|
||||
String topic) {
|
||||
String topic) {
|
||||
if (getter.get() == null || !NumberUtils.equals(getter.get(), value)) {
|
||||
setter.accept(value);
|
||||
holder.info(topic + "修改为: " + value);
|
||||
|
||||
@@ -19,8 +19,6 @@ import com.ecep.contract.ds.vendor.service.VendorEntityService;
|
||||
import com.ecep.contract.ds.vendor.service.VendorService;
|
||||
import com.ecep.contract.ds.company.model.Company;
|
||||
import com.ecep.contract.model.Employee;
|
||||
import com.ecep.contract.ds.vendor.model.Vendor;
|
||||
import com.ecep.contract.ds.vendor.model.VendorEntity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -72,6 +70,36 @@ public class AbstractYongYouU8Ctx extends AbstractCtx {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean updateEmployeeId(Supplier<Integer> getter, Consumer<Integer> setter, EmployeeVo employee,
|
||||
MessageHolder holder, String topic) {
|
||||
if (employee == null) {
|
||||
return false;
|
||||
}
|
||||
var v1 = getter.get();
|
||||
if (v1 == null) {
|
||||
setter.accept(employee.getId());
|
||||
holder.info(topic + "更新为 " + employee.getName());
|
||||
return true;
|
||||
}
|
||||
if (!Objects.equals(v1, employee.getId())) {
|
||||
setter.accept(employee.getId());
|
||||
holder.info(topic + "更新为 " + employee.getName());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean updateEmployeeIdByCode(Supplier<Integer> getter, Consumer<Integer> setter, String code,
|
||||
MessageHolder holder, String topic) {
|
||||
if (StringUtils.hasText(code)) {
|
||||
var employee = getEmployeeService().findByCode(code);
|
||||
if (employee != null) {
|
||||
return updateEmployeeId(getter, setter, employee, holder, topic);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean updateEmployee(Supplier<Employee> getter, Consumer<Employee> setter, EmployeeVo employee,
|
||||
MessageHolder holder, String topic) {
|
||||
if (employee == null) {
|
||||
@@ -106,6 +134,17 @@ public class AbstractYongYouU8Ctx extends AbstractCtx {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean updateEmployeeIdByName(Supplier<Integer> getter, Consumer<Integer> setter, String name,
|
||||
MessageHolder holder, String topic) {
|
||||
if (StringUtils.hasText(name)) {
|
||||
EmployeeVo employee = getEmployeeService().findByName(name);
|
||||
if (employee != null) {
|
||||
return updateEmployeeId(getter, setter, employee, holder, topic);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean updateCompanyByCustomerCode(Supplier<Company> getter, Consumer<Company> setter, String customerCode,
|
||||
MessageHolder holder, String topic) {
|
||||
Company company = null;
|
||||
|
||||
@@ -14,6 +14,8 @@ import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -148,11 +150,11 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
List<Contract> list = getContractService().findAllByCompany(company);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Contract contract = list.get(i);
|
||||
syncContract(contract, holder);
|
||||
syncContract(contract.toVo(), holder);
|
||||
}
|
||||
}
|
||||
|
||||
public void syncContract(Contract contract, MessageHolder holder) {
|
||||
public void syncContract(ContractVo contract, MessageHolder holder) {
|
||||
boolean modified = updateContractDetailByGuid(contract, contract.getGuid(), holder);
|
||||
if (updateContractExec(contract, holder)) {
|
||||
modified = true;
|
||||
@@ -169,7 +171,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateContractDetailByGuid(Contract contract, String guid, MessageHolder holder) {
|
||||
public boolean updateContractDetailByGuid(ContractVo contract, String guid, MessageHolder holder) {
|
||||
if (repository == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -185,7 +187,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
/**
|
||||
* 应用合同数据
|
||||
*/
|
||||
public boolean applyContractDetail(Contract contract, Map<String, Object> rs, MessageHolder holder) {
|
||||
public boolean applyContractDetail(ContractVo contract, Map<String, Object> rs, MessageHolder holder) {
|
||||
if (rs == null || rs.isEmpty()) {
|
||||
holder.warn("CM_Contract_B 中未检索到合同数据");
|
||||
return false;
|
||||
@@ -259,15 +261,15 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
"变更日期")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(contract::getSetupPerson, contract::setSetupPerson, (String) rs.get("strSetupPerson"),
|
||||
if (updateEmployeeIdByName(contract::getSetupPersonId, contract::setSetupPersonId, (String) rs.get("strSetupPerson"),
|
||||
holder, "提交人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(contract::getInurePerson, contract::setInurePerson, (String) rs.get("strInurePerson"),
|
||||
if (updateEmployeeIdByName(contract::getInurePersonId, contract::setInurePersonId, (String) rs.get("strInurePerson"),
|
||||
holder, "生效人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(contract::getVaryPerson, contract::setVaryPerson, (String) rs.get("strVaryPerson"),
|
||||
if (updateEmployeeIdByName(contract::getVaryPersonId, contract::setVaryPersonId, (String) rs.get("strVaryPerson"),
|
||||
holder, "修改人")) {
|
||||
modified = true;
|
||||
}
|
||||
@@ -301,28 +303,19 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
}
|
||||
}
|
||||
|
||||
if (contract.getType() != null && contract.getPayWay() != null) {
|
||||
ContractType type = contract.getType();
|
||||
if (!Hibernate.isInitialized(type)) {
|
||||
type = getCachedBean(ContractTypeService.class).getById(type.getId());
|
||||
contract.setType(type);
|
||||
}
|
||||
if (contract.getTypeId() != null && contract.getPayWay() != null) {
|
||||
var typeId = contract.getTypeId();
|
||||
var type = getCachedBean(ContractTypeService.class).findById(typeId);
|
||||
if (!type.getDirection().equals(contract.getPayWay().getText())) {
|
||||
holder.warn("合同类型:" + type.getName() + "的付款方向与付款方式不一致:" + contract.getPayWay().getText());
|
||||
}
|
||||
}
|
||||
|
||||
if (contract.getKind() != null && contract.getType() != null) {
|
||||
ContractKind kind = contract.getKind();
|
||||
if (!Hibernate.isInitialized(kind)) {
|
||||
kind = getCachedBean(ContractKindService.class).getById(kind.getId());
|
||||
contract.setKind(kind);
|
||||
}
|
||||
ContractType type = contract.getType();
|
||||
if (!Hibernate.isInitialized(type)) {
|
||||
type = getCachedBean(ContractTypeService.class).getById(type.getId());
|
||||
contract.setType(type);
|
||||
}
|
||||
if (contract.getKindId() != null && contract.getTypeId() != null) {
|
||||
var kindId = contract.getKindId();
|
||||
var kind = getCachedBean(ContractKindService.class).findById(kindId);
|
||||
var typeId = contract.getTypeId();
|
||||
var type = getCachedBean(ContractTypeService.class).findById(typeId);
|
||||
if (!kind.getName().equals(type.getTitle())) {
|
||||
holder.warn("合同分类的名称:" + kind.getName() + "与合同类型的标题:" + type.getName() + "不一致");
|
||||
}
|
||||
@@ -337,8 +330,8 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
* @param unit 合同对应的单位代码
|
||||
* @param holder 消息处理对象
|
||||
*/
|
||||
private boolean updateCompanyByVendorUnitCode(Contract contract, String unit, MessageHolder holder) {
|
||||
Company company = contract.getCompany();
|
||||
private boolean updateCompanyByVendorUnitCode(ContractVo contract, String unit, MessageHolder holder) {
|
||||
var companyId = contract.getCompanyId();
|
||||
boolean modified = false;
|
||||
boolean vendorModified = false;
|
||||
VendorService vendorService = getCompanyVendorService();
|
||||
@@ -353,31 +346,33 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
|
||||
entity = save(entity);
|
||||
|
||||
Vendor vendor = getCompanyVendorService().getById(entity.getVendorId());
|
||||
var vendor = getCompanyVendorService().findById(entity.getVendorId());
|
||||
if (vendor == null) {
|
||||
if (company != null) {
|
||||
if (companyId != null) {
|
||||
var company = getCompanyService().findById(companyId);
|
||||
vendor = vendorService.findByCompany(company);
|
||||
}
|
||||
} else {
|
||||
if (!Hibernate.isInitialized(vendor)) {
|
||||
vendor = vendorService.getById(vendor.getId());
|
||||
}
|
||||
if (vendor.getCompany() == null) {
|
||||
vendor.setCompany(company);
|
||||
if (vendor.getCompanyId() == null) {
|
||||
vendor.setCompanyId(companyId);
|
||||
vendorModified = true;
|
||||
} else {
|
||||
if (company == null) {
|
||||
company = vendor.getCompany();
|
||||
} else if (!Objects.equals(company, vendor.getCompany())) {
|
||||
if (companyId == null) {
|
||||
companyId = vendor.getCompanyId();
|
||||
} else if (!Objects.equals(companyId, vendor.getCompanyId())) {
|
||||
var contractCompany = getCompanyService().findById(companyId);
|
||||
var vendorCompany = getCompanyService().findById(vendor.getCompanyId());
|
||||
holder.error(
|
||||
"供应商的企业和合同的企业不一致, 供应商的企业:" + vendor.getCompany().getId() + ",合同的企业:" + company.getId());
|
||||
"供应商的企业和合同的企业不一致, 供应商的企业:" + vendorCompany.getName() + ",合同的企业:" + contractCompany.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (vendor == null) {
|
||||
vendor = new Vendor();
|
||||
vendor.setCompany(company);
|
||||
vendorModified = true;
|
||||
var v0 = new Vendor();
|
||||
v0.setCompany(getCompanyService().getById(companyId));
|
||||
v0.setCreated(LocalDateTime.now());
|
||||
v0.setVersion(0);
|
||||
vendor = getCompanyVendorService().save(v0).toVo();
|
||||
}
|
||||
if (vendor.getDevelopDate() == null
|
||||
|| (entity.getDevelopDate() != null && vendor.getDevelopDate().isAfter(entity.getDevelopDate()))) {
|
||||
@@ -386,16 +381,17 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
holder.info("供应商的开发日期修改为:" + entity.getDevelopDate());
|
||||
}
|
||||
if (vendorModified) {
|
||||
vendor = vendorService.save(vendor);
|
||||
vendor = getVendorCtx().save(vendor);
|
||||
}
|
||||
|
||||
// 确定 company
|
||||
if (company == null) {
|
||||
company = getCompanyCtx().findOrCreateByNameOrAbbName(entity.getName(), entity.getAbbName(),
|
||||
if (companyId == null) {
|
||||
var company = getCompanyCtx().findOrCreateByNameOrAbbName(entity.getName(), entity.getAbbName(),
|
||||
entity.getDevelopDate(), holder);
|
||||
companyId = company.getId();
|
||||
}
|
||||
|
||||
if (updateCompany(contract, company, holder)) {
|
||||
if (updateCompanyId(contract, companyId, holder)) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
@@ -424,6 +420,19 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean updateCompanyId(ContractVo contract, Integer companyId, MessageHolder holder) {
|
||||
if (companyId == null) {
|
||||
return false;
|
||||
}
|
||||
if (Objects.equals(contract.getCompanyId(), companyId)) {
|
||||
return false;
|
||||
}
|
||||
contract.setCompanyId(companyId);
|
||||
var company = getCompanyService().getById(companyId);
|
||||
holder.info("关联至 " + company.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
private VendorEntityVo updateVendorEntityDetailByCode(VendorEntityVo entity, String unitCode,
|
||||
MessageHolder holder) {
|
||||
if (vendorEntityUpdateDelayDays > 0) {
|
||||
@@ -458,8 +467,8 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
return getCustomerCtx().updateCustomerEntityDetailByCode(entity, unitCode, holder);
|
||||
}
|
||||
|
||||
private boolean updateCompanyByCustomerUnitCode(Contract contract, String unit, MessageHolder holder) {
|
||||
Company company = contract.getCompany();
|
||||
private boolean updateCompanyByCustomerUnitCode(ContractVo contract, String unit, MessageHolder holder) {
|
||||
var companyId = contract.getCompanyId();
|
||||
boolean modified = false;
|
||||
boolean customerModified = false;
|
||||
CompanyCustomerEntityService customerEntityService = getCompanyCustomerEntityService();
|
||||
@@ -474,28 +483,27 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
|
||||
CustomerVo customer = customerService.findById(entity.getCustomerId());
|
||||
if (customer == null) {
|
||||
if (company != null) {
|
||||
customer = customerService.findByCompany(company).toVo();
|
||||
if (companyId != null) {
|
||||
customer = customerService.findByCompany(getCompanyService().findById(companyId));
|
||||
}
|
||||
} else {
|
||||
if (customer.getCompanyId() == null) {
|
||||
customer.setCompanyId(company.getId());
|
||||
customer.setCompanyId(companyId);
|
||||
customerModified = true;
|
||||
} else {
|
||||
if (company == null) {
|
||||
customer.setCompanyId(company.getId());
|
||||
} else if (!Objects.equals(company.getId(), customer.getCompanyId())) {
|
||||
if (companyId == null) {
|
||||
customer.setCompanyId(null);
|
||||
} else if (!Objects.equals(companyId, customer.getCompanyId())) {
|
||||
holder.error(
|
||||
"客户的企业和合同的企业不一致, 客户的企业:" + customer.getCompanyId() + ",合同的企业:" + company.getId());
|
||||
"客户的企业和合同的企业不一致, 客户的企业:#" + customer.getCompanyId() + ",合同的企业:#" + companyId);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (customer == null) {
|
||||
CompanyCustomer v1 = new CompanyCustomer();
|
||||
if (company != null && !Hibernate.isInitialized(company)) {
|
||||
company = getCompanyService().getById(company.getId());
|
||||
}
|
||||
v1.setId(getCachedBean(OldVersionService.class).newCompanyCustomer(company == null ? unit : company.getName()));
|
||||
var company = getCompanyService().getById(companyId);
|
||||
v1.setId(getCachedBean(OldVersionService.class)
|
||||
.newCompanyCustomer(companyId == null ? unit : company.getName()));
|
||||
v1.setCompany(company);
|
||||
|
||||
customer = customerService.save(v1).toVo();
|
||||
@@ -512,19 +520,20 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
customer = customerService.save(v0).toVo();
|
||||
}
|
||||
// 确定 company
|
||||
if (company == null) {
|
||||
company = getCompanyCtx().findOrCreateByNameOrAbbName(entity.getName(), entity.getAbbName(),
|
||||
if (companyId == null) {
|
||||
var company = getCompanyCtx().findOrCreateByNameOrAbbName(entity.getName(), entity.getAbbName(),
|
||||
entity.getDevelopDate(), holder);
|
||||
companyId = company.getId();
|
||||
}
|
||||
|
||||
if (updateCompany(contract, company, holder)) {
|
||||
if (updateCompanyId(contract, companyId, holder)) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
private boolean updatePayWay(Contract contract, String way, MessageHolder holder) {
|
||||
private boolean updatePayWay(ContractVo contract, String way, MessageHolder holder) {
|
||||
if (!StringUtils.hasText(way)) {
|
||||
holder.warn("无付款方向");
|
||||
return false;
|
||||
@@ -542,69 +551,85 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean updateTypeByCode(Contract contract, String typeCode, MessageHolder holder) {
|
||||
private boolean updateTypeByCode(ContractVo contract, String typeCode, MessageHolder holder) {
|
||||
var service = getCachedBean(ContractTypeService.class);
|
||||
var type = service.findByCode(typeCode);
|
||||
if (type == null) {
|
||||
contract.setType(null);
|
||||
contract.setTypeId(null);
|
||||
} else {
|
||||
if (contract.getType() == null || !Objects.equals(contract.getType().getId(), type.getId())) {
|
||||
contract.setType(service.getById(type.getId()));
|
||||
if (contract.getTypeId() == null) {
|
||||
contract.setTypeId(type.getId());
|
||||
holder.info("合同类型修改为: " + type.getName());
|
||||
return true;
|
||||
}
|
||||
if (!Objects.equals(contract.getTypeId(), type.getId())) {
|
||||
contract.setTypeId(type.getId());
|
||||
holder.info("合同类型修改为: " + type.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean updateGroupByCode(Contract contract, String groupCode, MessageHolder holder) {
|
||||
private boolean updateGroupByCode(ContractVo contract, String groupCode, MessageHolder holder) {
|
||||
var service = getCachedBean(ContractGroupService.class);
|
||||
var group = service.findByCode(groupCode);
|
||||
if (group == null) {
|
||||
contract.setGroup(null);
|
||||
contract.setGroupId(null);
|
||||
} else {
|
||||
if (contract.getGroup() == null || !Objects.equals(contract.getGroup().getId(), group.getId())) {
|
||||
contract.setGroup(service.getById(group.getId()));
|
||||
if (contract.getGroupId() == null) {
|
||||
contract.setGroupId(group.getId());
|
||||
holder.info("合同分组修改为: " + group.getName());
|
||||
return true;
|
||||
}
|
||||
if (!Objects.equals(contract.getGroupId(), group.getId())) {
|
||||
contract.setGroupId(group.getId());
|
||||
holder.info("合同分组修改为: " + group.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean updateKindByCode(Contract contract, String kindName, MessageHolder holder) {
|
||||
private boolean updateKindByCode(ContractVo contract, String kindName, MessageHolder holder) {
|
||||
var service = getCachedBean(ContractKindService.class);
|
||||
var kind = service.findByName(kindName);
|
||||
if (!Objects.equals(contract.getKind(), kind)) {
|
||||
contract.setKind(kind);
|
||||
holder.info("合同分类修改为: " + kind.getName());
|
||||
return true;
|
||||
if (kind == null) {
|
||||
contract.setKindId(null);
|
||||
} else {
|
||||
if (contract.getKindId() == null) {
|
||||
contract.setKindId(kind.getId());
|
||||
holder.info("合同分类修改为: " + kind.getName());
|
||||
return true;
|
||||
}
|
||||
if (!Objects.equals(contract.getKindId(), kind.getId())) {
|
||||
contract.setKindId(kind.getId());
|
||||
holder.info("合同分类修改为: " + kind.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean updateEmployeeByCode(Contract contract, String personId, MessageHolder holder) {
|
||||
boolean updated = updateEmployeeByCode(contract::getEmployee, contract::setEmployee, personId, holder, "业务员");
|
||||
Employee employee = contract.getEmployee();
|
||||
if (employee == null) {
|
||||
private boolean updateEmployeeByCode(ContractVo contract, String personId, MessageHolder holder) {
|
||||
boolean updated = updateEmployeeIdByCode(contract::getEmployeeId, contract::setEmployeeId, personId, holder,
|
||||
"业务员");
|
||||
Integer employeeId = contract.getEmployeeId();
|
||||
if (employeeId == null) {
|
||||
holder.warn("* 合同业务员:" + personId + " 未导入");
|
||||
} else {
|
||||
if (!Hibernate.isInitialized(employee)) {
|
||||
employee = getEmployeeService().getById(employee.getId());
|
||||
}
|
||||
if (!employee.isActive()) {
|
||||
holder.warn("业务员 " + employee.getName() + " 已经不可用,其离职日期:" + employee.getLeaveDate());
|
||||
var v1 = getEmployeeService().findById(employeeId);
|
||||
if (!v1.isActive()) {
|
||||
holder.warn("业务员 " + v1.getName() + " 已经不可用,其离职日期:" + v1.getLeaveDate());
|
||||
}
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
public Contract findContractByCode(String contractCode) {
|
||||
|
||||
public ContractVo findContractByCode(String contractCode) {
|
||||
var service = getContractService();
|
||||
var vo = service.findByCode(contractCode);
|
||||
if (vo == null) {
|
||||
// holder.warn("合同 " + contractCode + " 未导入");
|
||||
return null;
|
||||
}
|
||||
return service.getById(vo.getId());
|
||||
return service.findByCode(contractCode);
|
||||
}
|
||||
|
||||
public boolean syncByVendorEntity(Vendor vendor, VendorEntity entity, MessageHolder holder) {
|
||||
@@ -654,17 +679,17 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
}
|
||||
|
||||
public boolean updateContract(String contractID, String guid, MessageHolder holder) {
|
||||
Contract contract = findOrCreatByGuidOrContractId(guid, contractID, holder);
|
||||
ContractVo contract = findOrCreatByGuidOrContractId(guid, contractID, holder);
|
||||
boolean updated = false;
|
||||
boolean modified = applyContractDetail(contract, repository.queryContractDetail(guid), holder);
|
||||
if (modified) {
|
||||
contract = getContractService().save(contract);
|
||||
contract = save(contract);
|
||||
updated = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Contract findOrCreatByGuidOrContractId(String guid, String contractId, MessageHolder holder) {
|
||||
public ContractVo findOrCreatByGuidOrContractId(String guid, String contractId, MessageHolder holder) {
|
||||
ContractService service = getContractService();
|
||||
UUID.fromString(guid);
|
||||
ContractVo contract = service.findByGuid(guid);
|
||||
@@ -678,29 +703,26 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
v0.setCode(contractId);
|
||||
v0 = service.save(v0);
|
||||
holder.info("新建合同:" + contractId + ", GUID: " + guid);
|
||||
return v0;
|
||||
} else {
|
||||
return service.getById(contract.getId());
|
||||
return v0.toVo();
|
||||
}
|
||||
} else {
|
||||
return service.getById(contract.getId());
|
||||
}
|
||||
return contract;
|
||||
}
|
||||
|
||||
private boolean updateContract(Map<String, Object> rs, MessageHolder holder) {
|
||||
String contractID = (String) rs.get("strContractID");
|
||||
String guid = (String) rs.get("GUID");
|
||||
boolean updated = false;
|
||||
Contract contract = findOrCreatByGuidOrContractId(guid, contractID, holder);
|
||||
ContractVo contract = findOrCreatByGuidOrContractId(guid, contractID, holder);
|
||||
boolean modified = applyContractDetail(contract, rs, holder);
|
||||
if (modified) {
|
||||
contract = getContractService().save(contract);
|
||||
contract = save(contract);
|
||||
updated = true;
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
public boolean updateParentContract(Contract contract, MessageHolder holder) {
|
||||
public boolean updateParentContract(ContractVo contract, MessageHolder holder) {
|
||||
// 如果已经由父合同编号,跳过
|
||||
if (StringUtils.hasText(contract.getParentCode())) {
|
||||
return false;
|
||||
@@ -715,7 +737,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
return false;
|
||||
}
|
||||
|
||||
String parentCode = getContractService().getParentCode(contract);
|
||||
String parentCode = getContractService().getParentCode(contract.getCode());
|
||||
holder.info("尝试查找主合同:" + parentCode);
|
||||
List<Contract> list = getContractService().findByCodeStartsWith(ContractPayWay.RECEIVE, parentCode);
|
||||
if (list.isEmpty()) {
|
||||
@@ -732,7 +754,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
return updateText(contract::getCode, contract::setParentCode, parent.getCode(), holder, "主合同");
|
||||
}
|
||||
|
||||
public boolean updateContractExec(Contract contract, MessageHolder holder) {
|
||||
public boolean updateContractExec(ContractVo contract, MessageHolder holder) {
|
||||
if (repository == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -764,7 +786,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
* @param contract 合同
|
||||
* @param holder 消息
|
||||
*/
|
||||
public boolean syncContractItems(Contract contract, MessageHolder holder) {
|
||||
public boolean syncContractItems(ContractVo contract, MessageHolder holder) {
|
||||
if (repository == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -788,7 +810,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
boolean modified = false;
|
||||
if (contractItem == null) {
|
||||
contractItem = new ContractItem();
|
||||
contractItem.setContract(contract);
|
||||
contractItem.setContract(getContractService().getById(contract.getId()));
|
||||
contractItem.setRefId(refId);
|
||||
modified = true;
|
||||
|
||||
@@ -928,7 +950,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
return modified;
|
||||
}
|
||||
|
||||
private boolean sumItems(Contract contract, Collection<ContractItem> items, MessageHolder holder) {
|
||||
private boolean sumItems(ContractVo contract, Collection<ContractItem> items, MessageHolder holder) {
|
||||
if (items == null || items.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@@ -952,7 +974,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
return modified;
|
||||
}
|
||||
|
||||
public boolean updateContractPath(Contract contract, MessageHolder holder) {
|
||||
public boolean updateContractPath(ContractVo contract, MessageHolder holder) {
|
||||
// 如果合同路径存在
|
||||
if (CompanyFileUtils.exists(contract.getPath())) {
|
||||
File dir = new File(contract.getPath());
|
||||
@@ -998,17 +1020,15 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
} else if (contract.getPayWay() == ContractPayWay.RECEIVE) {
|
||||
// 销售合同
|
||||
File contractPath = null;
|
||||
Project project = contract.getProject();
|
||||
if (project != null) {
|
||||
project = getProjectCtx().initialize(project);
|
||||
ProjectSaleType saleType = project.getSaleType();
|
||||
if (saleType != null) {
|
||||
if (!Hibernate.isInitialized(saleType)) {
|
||||
saleType = getSaleTypeService().getById(saleType.getId());
|
||||
}
|
||||
Integer projectId = contract.getProject();
|
||||
if (projectId != null) {
|
||||
var projectVo = getProjectCtx().getProjectService().findById(projectId);
|
||||
var saleTypeId = projectVo.getSaleTypeId();
|
||||
if (saleTypeId != null) {
|
||||
ProjectSaleTypeVo saleType = getSaleTypeService().findById(saleTypeId);
|
||||
File dir = new File(saleType.getPath());
|
||||
if (saleType.isStoreByYear()) {
|
||||
dir = new File(dir, "20" + project.getCodeYear());
|
||||
dir = new File(dir, "20" + projectVo.getCodeYear());
|
||||
if (!dir.exists()) {
|
||||
if (dir.mkdir()) {
|
||||
holder.info("新建目录 " + dir.getAbsolutePath());
|
||||
@@ -1021,7 +1041,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
|
||||
// 从关联项目上未取得合同目录,尝试根据合同编码来确定合同目录
|
||||
if (contractPath == null) {
|
||||
ContractCatalog catalog = getContractService().findContractCatalogByContract(contract.getCode());
|
||||
ContractCatalogVo catalog = getContractService().findContractCatalogByContract(contract.getCode());
|
||||
if (catalog != null) {
|
||||
contractPath = getContractService().getContractCatalogPath(catalog, contract);
|
||||
}
|
||||
@@ -1048,7 +1068,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateContractAmount(Contract contract, MessageHolder holder) {
|
||||
public boolean updateContractAmount(ContractVo contract, MessageHolder holder) {
|
||||
if (contract.getAmount() == null || contract.getAmount() == 0.0d) {
|
||||
if (contract.getTotalAmount() > 0) {
|
||||
contract.setAmount(contract.getTotalAmount());
|
||||
@@ -1059,17 +1079,22 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateContractProject(Contract contract, Project project, MessageHolder holder) {
|
||||
public boolean updateContractProject(ContractVo contract, ProjectVo project, MessageHolder holder) {
|
||||
if (project == null) {
|
||||
holder.warn("合同所属项目更新失败,项目不存在");
|
||||
return false;
|
||||
}
|
||||
if (Objects.equals(contract.getProject(), project)) {
|
||||
return false;
|
||||
if (contract.getProject() == null) {
|
||||
contract.setProject(project.getId());
|
||||
holder.info("合同所属项目更新为:" + project.getName());
|
||||
return true;
|
||||
}
|
||||
project = getProjectCtx().initialize(project);
|
||||
holder.info("合同所属项目更新为:" + project.getName());
|
||||
contract.setProject(project);
|
||||
return true;
|
||||
if (!Objects.equals(contract.getProject(), project.getId())) {
|
||||
holder.info("合同所属项目更新为:" + project.getName());
|
||||
contract.setProject(project.getId());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1079,14 +1104,15 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
* @param holder
|
||||
* @return
|
||||
*/
|
||||
public boolean updateContractProject(Contract contract, Contract parent, MessageHolder holder) {
|
||||
Project project = contract.getProject();
|
||||
if (project == null && parent != null) {
|
||||
public boolean updateContractProject(ContractVo contract, ContractVo parent, MessageHolder holder) {
|
||||
Integer projectId = contract.getProject();
|
||||
if (projectId == null && parent != null) {
|
||||
// 尝试从父合同中获取项目对象
|
||||
project = parent.getProject();
|
||||
projectId = parent.getProject();
|
||||
}
|
||||
|
||||
if (project == null) {
|
||||
if (projectId == null) {
|
||||
holder.debug("合同没有关联项目");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1095,41 +1121,43 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
|
||||
ProjectCtx ctx = getProjectCtx();
|
||||
|
||||
project = ctx.initialize(project);
|
||||
if (project.getAmount() == null || project.getAmount() == 0) {
|
||||
if (ctx.updateNumber(project::getAmount, project::setAmount, contract.getAmount().intValue(), holder,
|
||||
var projectVo = getProjectCtx().getProjectService().findById(projectId);
|
||||
if (projectVo.getAmount() == null || projectVo.getAmount() == 0) {
|
||||
if (ctx.updateNumber(projectVo::getAmount, projectVo::setAmount, contract.getAmount().intValue(), holder,
|
||||
"项目金额")) {
|
||||
projectModified = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查项目的客户
|
||||
Company customer = project.getCustomer();
|
||||
if (customer == null) {
|
||||
Integer customerId = projectVo.getCustomerId();
|
||||
if (customerId == null) {
|
||||
// 查询合同关联的客户(主合同上的是客户)
|
||||
if (parent == null) { // 主合同时,parent 为 null
|
||||
if (contract.getPayWay() == ContractPayWay.RECEIVE) {
|
||||
customer = contract.getCompany();
|
||||
customerId = contract.getCompanyId();
|
||||
}
|
||||
} else {
|
||||
customer = parent.getCompany();
|
||||
if (customer == null) {
|
||||
customerId = parent.getCompanyId();
|
||||
if (customerId == null) {
|
||||
holder.warn("合同:" + parent.getCode() + " 没有关联的客户");
|
||||
}
|
||||
}
|
||||
if (customer != null) {
|
||||
if (ctx.updateCustomer(project, customer, holder)) {
|
||||
if (customerId != null) {
|
||||
if (ctx.updateCustomerId(projectVo, customerId, holder)) {
|
||||
projectModified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (projectModified) {
|
||||
project = ctx.save(project);
|
||||
contract.setProject(project);
|
||||
projectVo = ctx.save(projectVo);
|
||||
}
|
||||
|
||||
if (updateContractProject(contract, project, holder)) {
|
||||
if (!Objects.equals(contract.getProject(), projectId)) {
|
||||
contract.setProject(projectId);
|
||||
contractModified = true;
|
||||
}
|
||||
if (updateContractProject(contract, projectVo, holder)) {
|
||||
// 更新项目客户
|
||||
contractModified = true;
|
||||
}
|
||||
@@ -1137,7 +1165,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
return contractModified;
|
||||
}
|
||||
|
||||
public boolean syncContractFiles(Contract contract, MessageHolder holder) {
|
||||
public boolean syncContractFiles(ContractVo contract, MessageHolder holder) {
|
||||
String contractPath = contract.getPath();
|
||||
if (!StringUtils.hasText(contractPath)) {
|
||||
return false;
|
||||
@@ -1193,7 +1221,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
}
|
||||
// 未记录的文件,存储到 retrieveFiles
|
||||
ContractFile contractFile = new ContractFile();
|
||||
contractFile.setContract(contract);
|
||||
contractFile.setContract(getContractService().getById(contract.getId()));
|
||||
contractFile.setType(ContractFileType.General);
|
||||
contractFile.setFileName(file.getName());
|
||||
syncContractFile(contractFile, file, holder);
|
||||
@@ -1279,11 +1307,8 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
return Math.max(suggestFileName.length(), value.length());
|
||||
}
|
||||
|
||||
public Contract save(Contract contract) {
|
||||
return getContractService().save(contract);
|
||||
}
|
||||
|
||||
public boolean syncContractPayPlan(Contract contract, MessageHolder holder) {
|
||||
public boolean syncContractPayPlan(ContractVo contract, MessageHolder holder) {
|
||||
if (repository == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -1307,7 +1332,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
boolean modified = false;
|
||||
if (plan == null) {
|
||||
plan = new ContractPayPlan();
|
||||
plan.setContract(contract);
|
||||
plan.setContract(getContractService().getById(contract.getId()));
|
||||
plan.setRefId(refId);
|
||||
modified = true;
|
||||
|
||||
@@ -1367,4 +1392,15 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
}
|
||||
|
||||
public Contract save(Contract contract) {
|
||||
return getContractService().save(contract);
|
||||
}
|
||||
|
||||
public ContractVo save(ContractVo contract) {
|
||||
ContractService service = getContractService();
|
||||
Contract v0 = service.getById(contract.getId());
|
||||
service.updateByVo(v0, contract);
|
||||
return service.save(v0).toVo();
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.ecep.contract.vo.InventoryCatalogVo;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
@@ -158,8 +159,8 @@ public class InventoryCtx extends AbstractYongYouU8Ctx {
|
||||
* @return 是否更新
|
||||
*/
|
||||
private boolean updateInventoryCatalog(Supplier<InventoryCatalog> getter, Consumer<InventoryCatalog> setter,
|
||||
String catalogCode, MessageHolder holder, String topic) {
|
||||
InventoryCatalog catalog = null;
|
||||
String catalogCode, MessageHolder holder, String topic) {
|
||||
InventoryCatalogVo catalog = null;
|
||||
if (StringUtils.hasText(catalogCode)) {
|
||||
catalog = getInventoryCatalogService().findByCode(catalogCode);
|
||||
}
|
||||
@@ -168,11 +169,14 @@ public class InventoryCtx extends AbstractYongYouU8Ctx {
|
||||
holder.warn("无效" + topic + ":" + catalogCode);
|
||||
return true;
|
||||
} else {
|
||||
if (!Objects.equals(getter.get(), catalog)) {
|
||||
if (!Hibernate.isInitialized(catalog)) {
|
||||
catalog = getInventoryCatalogService().findByCode(catalogCode);
|
||||
}
|
||||
setter.accept(catalog);
|
||||
InventoryCatalog v1 = getter.get();
|
||||
if (v1 == null) {
|
||||
setter.accept(getInventoryCatalogService().getById(catalog.getId()));
|
||||
holder.info(topic + "修改为: " + catalog.getName());
|
||||
return true;
|
||||
}
|
||||
if (!Objects.equals(v1.getId(), catalog.getId())) {
|
||||
setter.accept(getInventoryCatalogService().getById(catalog.getId()));
|
||||
holder.info(topic + "修改为: " + catalog.getName());
|
||||
return true;
|
||||
}
|
||||
@@ -191,7 +195,7 @@ public class InventoryCtx extends AbstractYongYouU8Ctx {
|
||||
* @return 是否更新
|
||||
*/
|
||||
public boolean syncInventoryDetailByCode(Supplier<Inventory> getter, Consumer<Inventory> setter,
|
||||
String inventoryCode, MessageHolder holder, String topic) {
|
||||
String inventoryCode, MessageHolder holder, String topic) {
|
||||
if (!StringUtils.hasText(inventoryCode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.ecep.contract.vo.ContractVo;
|
||||
import com.ecep.contract.vo.PurchaseOrderItemVo;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
@@ -33,6 +34,7 @@ import com.ecep.contract.ds.vendor.model.PurchaseOrder;
|
||||
import com.ecep.contract.ds.vendor.model.PurchaseOrderItem;
|
||||
|
||||
import lombok.Setter;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class PurchaseBillVoucherCtx extends AbstractYongYouU8Ctx {
|
||||
@Setter
|
||||
@@ -197,12 +199,10 @@ public class PurchaseBillVoucherCtx extends AbstractYongYouU8Ctx {
|
||||
}
|
||||
}
|
||||
|
||||
public void syncByContract(Contract contract, MessageHolder holder) {
|
||||
public void syncByContract(ContractVo contract, MessageHolder holder) {
|
||||
PurchaseBillVoucherService voucherService = getPurchaseBillVoucherService();
|
||||
PurchaseBillVoucherItemService voucherItemService = getPurchaseBillVoucherItemService();
|
||||
List<PurchaseBillVoucherItem> items = voucherItemService.findAll((root, q, cb) -> {
|
||||
return cb.equal(root.get("contract"), contract);
|
||||
}, Sort.unsorted());
|
||||
List<PurchaseBillVoucherItem> items = voucherItemService.findAllByContract(contract);
|
||||
|
||||
Map<Integer, PurchaseBillVoucherItem> itemMap = items.stream()
|
||||
.collect(Collectors.toMap(PurchaseBillVoucherItem::getRefId, item -> item));
|
||||
@@ -376,7 +376,7 @@ public class PurchaseBillVoucherCtx extends AbstractYongYouU8Ctx {
|
||||
holder.info(topic + "修改为: " + item.getRefId());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (!Objects.equals(v1.getId(), item.getId())) {
|
||||
setter.accept(getPurchaseOrderItemService().getById(item.getId()));
|
||||
holder.info(topic + "修改为: " + item.getRefId());
|
||||
@@ -408,20 +408,27 @@ public class PurchaseBillVoucherCtx extends AbstractYongYouU8Ctx {
|
||||
|
||||
boolean updateContractByContractCode(Supplier<Contract> getter, Consumer<Contract> setter, String contractCode,
|
||||
MessageHolder holder, String topic) {
|
||||
Contract contract = null;
|
||||
if (contractCode != null) {
|
||||
ContractVo contract = null;
|
||||
if (StringUtils.hasText(contractCode)) {
|
||||
contract = getContractCtx().findContractByCode(contractCode);
|
||||
}
|
||||
if (contract == null) {
|
||||
setter.accept(null);
|
||||
holder.warn("无效" + topic + ":" + contractCode);
|
||||
return true;
|
||||
} else {
|
||||
if (!Objects.equals(getter.get(), contract)) {
|
||||
setter.accept(contract);
|
||||
holder.info(topic + "修改为: " + contract.getCode());
|
||||
return true;
|
||||
if (contract == null) {
|
||||
holder.warn("无相关记录, " + topic + ":" + contractCode);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
holder.warn("无效 " + topic + ":" + contractCode);
|
||||
return false;
|
||||
}
|
||||
Contract v1 = getter.get();
|
||||
if (v1 == null) {
|
||||
setter.accept(getContractCtx().getContractService().getById(contract.getId()));
|
||||
holder.info(topic + "修改为: " + contract.getCode());
|
||||
return true;
|
||||
}
|
||||
if (!Objects.equals(v1.getId(), contract.getId())) {
|
||||
setter.accept(getContractCtx().getContractService().getById(contract.getId()));
|
||||
holder.info(topic + "修改为: " + contract.getCode());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.ecep.contract.vo.ContractVo;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
@@ -77,25 +79,21 @@ public class PurchaseOrderCtx extends AbstractYongYouU8Ctx {
|
||||
return purchaseOrderItemService;
|
||||
}
|
||||
|
||||
public List<PurchaseOrder> syncByContract(Contract contract, MessageHolder holder) {
|
||||
public List<PurchaseOrder> syncByContract(ContractVo contract, MessageHolder holder) {
|
||||
PurchaseOrdersService ordersService = getPurchaseOrdersService();
|
||||
PurchaseOrderItemService itemService = getPurchaseOrderItemService();
|
||||
|
||||
List<PurchaseOrder> orders = ordersService.findAll((root, q, cb) -> {
|
||||
return cb.equal(root.get("contract"), contract);
|
||||
}, Sort.unsorted());
|
||||
List<PurchaseOrder> orders = ordersService.findAllByContract(contract);
|
||||
holder.debug("查找到 " + orders.size() + " 条采购订单记录在数据库中");
|
||||
Map<Integer, PurchaseOrder> ordersMap = orders.stream()
|
||||
.collect(Collectors.toMap(PurchaseOrder::getRefId, item -> item));
|
||||
|
||||
List<PurchaseOrderItem> items = itemService.findAll((root, q, cb) -> {
|
||||
return cb.equal(root.get("order").get("contract"), contract);
|
||||
}, Sort.unsorted());
|
||||
|
||||
// 按 order 分组
|
||||
Map<PurchaseOrder, Map<Integer, PurchaseOrderItem>> itemMap = items.stream()
|
||||
.collect(Collectors.groupingBy(PurchaseOrderItem::getOrder,
|
||||
Collectors.toMap(PurchaseOrderItem::getRefId, item -> item)));
|
||||
Map<PurchaseOrder, Map<Integer, PurchaseOrderItem>> itemMap = orders.stream()
|
||||
.collect(Collectors.toMap(Function.identity(), order -> itemService.findAllByOrder(order).stream().collect(
|
||||
Collectors.toMap(PurchaseOrderItem::getRefId, item -> item)
|
||||
))
|
||||
);
|
||||
|
||||
// 查询 U8 数据库
|
||||
List<Map<String, Object>> ds = repository.findAllPurchaseOrderItemByContractCode(contract.getCode());
|
||||
@@ -111,7 +109,7 @@ public class PurchaseOrderCtx extends AbstractYongYouU8Ctx {
|
||||
PurchaseOrder order = ordersMap.get(poId);
|
||||
if (order == null) {
|
||||
order = new PurchaseOrder();
|
||||
order.setContract(contract);
|
||||
order.setContract(getCachedBean(ContractService.class).getById(contract.getId()));
|
||||
order.setRefId(poId);
|
||||
|
||||
order = ordersService.save(order);
|
||||
@@ -263,7 +261,7 @@ public class PurchaseOrderCtx extends AbstractYongYouU8Ctx {
|
||||
}
|
||||
|
||||
private boolean applyPurchaseOrderItemDetail(PurchaseOrderItem item, Map<String, Object> map,
|
||||
MessageHolder holder) {
|
||||
MessageHolder holder) {
|
||||
Integer refId = (Integer) map.get("ID");
|
||||
String inventoryCode = (String) map.get("cInvCode");
|
||||
String contractCode = (String) map.get("ContractCode");
|
||||
@@ -326,7 +324,7 @@ public class PurchaseOrderCtx extends AbstractYongYouU8Ctx {
|
||||
}
|
||||
|
||||
boolean updateInventory(Supplier<Inventory> getter, Consumer<Inventory> setter, String inventoryCode,
|
||||
MessageHolder holder, String topic) {
|
||||
MessageHolder holder, String topic) {
|
||||
return getInventoryCtx().syncInventoryDetailByCode(getter, setter, inventoryCode, holder, topic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.ecep.contract.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.vo.ContractVo;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
import com.ecep.contract.MessageHolder;
|
||||
@@ -47,23 +50,21 @@ public class SalesOrderCtx extends AbstractYongYouU8Ctx {
|
||||
}
|
||||
|
||||
|
||||
public List<SalesOrder> syncByContract(Contract contract, MessageHolder holder) {
|
||||
public List<SalesOrder> syncByContract(ContractVo contract, MessageHolder holder) {
|
||||
SaleOrdersService saleOrdersService = getSaleOrdersService();
|
||||
SalesOrderItemService orderItemService = getOrderItemService();
|
||||
|
||||
List<SalesOrder> orders = saleOrdersService.findAll((root, q, cb) -> {
|
||||
return cb.equal(root.get("contract"), contract);
|
||||
}, Sort.unsorted());
|
||||
List<SalesOrder> orders = saleOrdersService.findAllByContract(contract);
|
||||
holder.debug("查找到 " + orders.size() + " 条销售订单记录在数据库中");
|
||||
Map<String, SalesOrder> ordersMap = orders.stream().collect(Collectors.toMap(SalesOrder::getCode, item -> item));
|
||||
|
||||
List<SalesOrderItem> items = orderItemService.findAll((root, q, cb) -> {
|
||||
return cb.equal(root.get("order").get("contract"), contract);
|
||||
}, Sort.unsorted());
|
||||
|
||||
// 按 order 分组
|
||||
Map<SalesOrder, Map<String, SalesOrderItem>> itemMap = items.stream().collect(Collectors.groupingBy(SalesOrderItem::getOrder,
|
||||
Collectors.toMap(SalesOrderItem::getCode, item -> item)));
|
||||
Map<SalesOrder, Map<String, SalesOrderItem>> itemMap = orders.stream()
|
||||
.collect(
|
||||
Collectors.toMap(Function.identity(), order -> orderItemService.findAllBySaleOrder(order).stream().collect(
|
||||
Collectors.toMap(SalesOrderItem::getCode, item -> item)
|
||||
))
|
||||
);
|
||||
|
||||
|
||||
// 查询 U8 数据库
|
||||
List<Map<String, Object>> ds = repository.findAllSalesOrderItemByContractCode(contract.getCode());
|
||||
@@ -79,7 +80,7 @@ public class SalesOrderCtx extends AbstractYongYouU8Ctx {
|
||||
SalesOrder order = ordersMap.get(orderCode);
|
||||
if (order == null) {
|
||||
order = new SalesOrder();
|
||||
order.setContract(contract);
|
||||
order.setContract(getCachedBean(ContractService.class).getById(contract.getId()));
|
||||
order.setCode(orderCode);
|
||||
|
||||
order = saleOrdersService.save(order);
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.function.Supplier;
|
||||
import com.ecep.contract.ds.vendor.service.VendorCatalogService;
|
||||
import com.ecep.contract.vo.VendorCatalogVo;
|
||||
import com.ecep.contract.vo.VendorEntityVo;
|
||||
import com.ecep.contract.vo.VendorVo;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -332,4 +333,10 @@ public class VendorCtx extends AbstractYongYouU8Ctx {
|
||||
}
|
||||
|
||||
|
||||
public VendorVo save(VendorVo vendor) {
|
||||
VendorService service = getCompanyVendorService();
|
||||
Vendor v0 = service.getById(vendor.getId());
|
||||
service.updateByVo(v0, vendor);
|
||||
return service.save(v0).toVo();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ public interface ContractFileRepository extends JpaRepository<ContractFile, Inte
|
||||
List<ContractFile> findByContract(Contract contract);
|
||||
|
||||
List<ContractFile> findAllByContract(Contract contract);
|
||||
|
||||
List<ContractFile> findAllByContractId(Integer contractId);
|
||||
|
||||
List<ContractFile> findAllByContractAndType(Contract contract, ContractFileType type);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ecep.contract.ds.contract.repository;
|
||||
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
@@ -8,12 +9,11 @@ import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.ecep.contract.ds.vendor.model.PurchaseBillVoucherItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface PurchaseBillVoucherItemRepository extends
|
||||
// JDBC interfaces
|
||||
CrudRepository<PurchaseBillVoucherItem, Integer>,
|
||||
PagingAndSortingRepository<PurchaseBillVoucherItem, Integer>,
|
||||
// JPA interfaces
|
||||
JpaRepository<PurchaseBillVoucherItem, Integer>, JpaSpecificationExecutor<PurchaseBillVoucherItem> {
|
||||
MyRepository<PurchaseBillVoucherItem, Integer> {
|
||||
|
||||
List<PurchaseBillVoucherItem> findAllByContractId(Integer contractId);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public interface PurchaseOrderRepository extends
|
||||
Optional<PurchaseOrder> findByRefId(Integer refId);
|
||||
|
||||
List<PurchaseOrder> findAllByContract(Contract contract);
|
||||
List<PurchaseOrder> findAllByContractId(Integer contractId);
|
||||
|
||||
List<PurchaseOrder> findByCodeStartsWith(String code);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public interface SalesOrderRepository extends MyRepository<SalesOrder, Integer>
|
||||
Optional<SalesOrder> findByCode(String code);
|
||||
|
||||
List<SalesOrder> findAllByContract(Contract contract);
|
||||
List<SalesOrder> findAllByContractId(Integer contractId);
|
||||
|
||||
List<SalesOrder> findByCodeStartsWith(String code);
|
||||
}
|
||||
|
||||
@@ -52,13 +52,13 @@ public class ContractCatalogService implements IEntityService<ContractCatalog>,
|
||||
}
|
||||
|
||||
@Cacheable(key = "'code-'+#p0")
|
||||
public ContractCatalog findByCode(String code) {
|
||||
return repository.findByCode(code).orElse(null);
|
||||
public ContractCatalogVo findByCode(String code) {
|
||||
return repository.findByCode(code).map(ContractCatalog::toVo).orElse(null);
|
||||
}
|
||||
|
||||
@Cacheable(key = "'catalogs'")
|
||||
public List<ContractCatalog> findAll() {
|
||||
return repository.findAll();
|
||||
public List<ContractCatalogVo> findAll() {
|
||||
return repository.findAll().stream().map(ContractCatalog::toVo).toList();
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.ecep.contract.ds.contract.service;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.ecep.contract.vo.ContractVo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -166,6 +167,11 @@ public class ContractFileService implements IEntityService<ContractFile>, QueryS
|
||||
return contractFileRepository.findAllByContract(contract).stream().map(ContractFile::toVo).toList();
|
||||
}
|
||||
|
||||
@Cacheable(key = "'allbycontract-'+#p0.id")
|
||||
public List<ContractFileVo> findAllByContract(ContractVo contract) {
|
||||
return contractFileRepository.findAllByContractId(contract.getId()).stream().map(ContractFile::toVo).toList();
|
||||
}
|
||||
|
||||
public List<ContractFile> searchByContract(Contract contract, String userText) {
|
||||
Specification<ContractFile> spec = (root, query, builder) -> {
|
||||
return builder.and(
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ecep.contract.ds.contract.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.vo.ContractVo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -98,6 +99,10 @@ public class ContractItemService implements IEntityService<ContractItem>, QueryS
|
||||
return itemRepository.findByContractId(contract.getId());
|
||||
}
|
||||
|
||||
public List<ContractItem> findAllByContract(ContractVo contract) {
|
||||
return itemRepository.findByContractId(contract.getId());
|
||||
}
|
||||
|
||||
public List<ContractItem> findAllByInventory(Inventory inventory) {
|
||||
return itemRepository.findByInventoryId(inventory.getId());
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ecep.contract.ds.contract.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.vo.ContractVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -74,8 +75,8 @@ public class ContractPayPlanService implements IEntityService<ContractPayPlan>,
|
||||
return findAll(spec, pageable).map(ContractPayPlan::toVo);
|
||||
}
|
||||
|
||||
public List<ContractPayPlan> findAllByContract(Contract contract) {
|
||||
return repository.findAllByContract(contract);
|
||||
public List<ContractPayPlan> findAllByContract(ContractVo contract) {
|
||||
return repository.findAllByContractId(contract.getId());
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.ecep.contract.vo.ContractCatalogVo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -149,7 +150,7 @@ public class ContractService extends EntityService<Contract, ContractVo, Integer
|
||||
/**
|
||||
* 返回合同的分类目录
|
||||
*/
|
||||
public File getContractCatalogPath(ContractCatalog catalog, Contract contract) {
|
||||
public File getContractCatalogPath(ContractCatalogVo catalog, ContractVo contract) {
|
||||
String parent = catalog.getParent();
|
||||
File dir = getBasePath();
|
||||
if (StringUtils.hasText(parent)) {
|
||||
@@ -186,7 +187,7 @@ public class ContractService extends EntityService<Contract, ContractVo, Integer
|
||||
return dir;
|
||||
}
|
||||
|
||||
public File getContractCatalogPath(ContractCatalog catalog, ContractVo contract) {
|
||||
public File getContractCatalogPath(ContractCatalogVo catalog, Contract contract) {
|
||||
String parent = catalog.getParent();
|
||||
File dir = getBasePath();
|
||||
if (StringUtils.hasText(parent)) {
|
||||
@@ -226,7 +227,7 @@ public class ContractService extends EntityService<Contract, ContractVo, Integer
|
||||
/**
|
||||
* 查找合同的分类
|
||||
*/
|
||||
public ContractCatalog findContractCatalogByContract(String contractCode) {
|
||||
public ContractCatalogVo findContractCatalogByContract(String contractCode) {
|
||||
if (!StringUtils.hasText(contractCode)) {
|
||||
return null;
|
||||
}
|
||||
@@ -341,16 +342,18 @@ public class ContractService extends EntityService<Contract, ContractVo, Integer
|
||||
return code.contains("-");
|
||||
}
|
||||
|
||||
public boolean isSubContract(ContractVo contract) {
|
||||
return isSubContractCode(contract.getCode());
|
||||
}
|
||||
|
||||
public boolean isSubContract(Contract contract) {
|
||||
return isSubContractCode(contract.getCode());
|
||||
}
|
||||
|
||||
public String getParentCode(Contract contract) {
|
||||
String code = contract.getCode();
|
||||
|
||||
int index = code.indexOf("-");
|
||||
public String getParentCode(String contractCode) {
|
||||
int index = contractCode.indexOf("-");
|
||||
if (index != -1) {
|
||||
return code.substring(0, index);
|
||||
return contractCode.substring(0, index);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -362,7 +365,7 @@ public class ContractService extends EntityService<Contract, ContractVo, Integer
|
||||
if (!isSubContract(contract)) {
|
||||
return false;
|
||||
}
|
||||
String parentCode = getParentCode(contract);
|
||||
String parentCode = getParentCode(contract.getCode());
|
||||
// fixed
|
||||
if (Objects.equals(contract.getParentCode(), parentCode)) {
|
||||
// 已经相同,跳过
|
||||
@@ -422,6 +425,10 @@ public class ContractService extends EntityService<Contract, ContractVo, Integer
|
||||
return contractRepository.findAllByParentCode(contract.getCode());
|
||||
}
|
||||
|
||||
public List<Contract> findAllByParent(ContractVo contract) {
|
||||
return contractRepository.findAllByParentCode(contract.getCode());
|
||||
}
|
||||
|
||||
public List<Contract> findByCodeStartsWith(ContractPayWay payWay, String parentCode) {
|
||||
return contractRepository.findByPayWayAndCodeStartsWith(payWay, parentCode);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ecep.contract.ds.contract.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.vo.ContractVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -100,4 +101,8 @@ public class PurchaseBillVoucherItemService
|
||||
model.setPrice(vo.getPrice());
|
||||
model.setDescription(vo.getDescription());
|
||||
}
|
||||
|
||||
public List<PurchaseBillVoucherItem> findAllByContract(ContractVo contract) {
|
||||
return repository.findAllByContractId(contract.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ecep.contract.ds.contract.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.ds.vendor.model.PurchaseOrder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -142,4 +143,8 @@ public class PurchaseOrderItemService implements IEntityService<PurchaseOrderIte
|
||||
model.setInventory(SpringApp.getBean(InventoryService.class).getById(vo.getInventoryId()));
|
||||
}
|
||||
}
|
||||
|
||||
public List<PurchaseOrderItem> findAllByOrder(PurchaseOrder order) {
|
||||
return repository.findAllByOrder(order);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ecep.contract.ds.contract.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.vo.ContractVo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -137,6 +138,10 @@ public class PurchaseOrdersService implements IEntityService<PurchaseOrder>, Que
|
||||
return repository.findAllByContract(contract);
|
||||
}
|
||||
|
||||
public List<PurchaseOrder> findAllByContract(ContractVo contract) {
|
||||
return repository.findAllByContractId(contract.getId());
|
||||
}
|
||||
|
||||
public List<PurchaseOrder> search(String searchText) {
|
||||
Specification<PurchaseOrder> spec = (root, query, builder) -> {
|
||||
return builder.or(
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ecep.contract.ds.contract.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.vo.ContractVo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -143,4 +144,8 @@ public class SaleOrdersService extends EntityService<SalesOrder, SalesOrderVo, I
|
||||
public List<SalesOrder> findAllByContract(Contract contract) {
|
||||
return repository.findAllByContract(contract);
|
||||
}
|
||||
|
||||
public List<SalesOrder> findAllByContract(ContractVo contract) {
|
||||
return repository.findAllByContractId(contract.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.ecep.contract.ds.contract.service;
|
||||
|
||||
import com.ecep.contract.ds.customer.model.SalesOrder;
|
||||
import com.ecep.contract.vo.ContractVo;
|
||||
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.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -21,6 +24,8 @@ import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.ecep.contract.vo.SalesOrderItemVo;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "contract-sale-order-item")
|
||||
@@ -108,4 +113,14 @@ public class SalesOrderItemService extends EntityService<SalesOrderItem, SalesOr
|
||||
model.setOrder(SpringApp.getBean(SaleOrdersService.class).getById(vo.getOrderId()));
|
||||
}
|
||||
}
|
||||
|
||||
public List<SalesOrderItem> findAllByContract(ContractVo contract) {
|
||||
return repository.findAll((root, q, cb) -> {
|
||||
return cb.equal(root.get("order").get("contract").get("id"), contract.getId());
|
||||
}, Sort.unsorted());
|
||||
}
|
||||
|
||||
public List<SalesOrderItem> findAllBySaleOrder(SalesOrder order) {
|
||||
return repository.findAllByOrder(order);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.ecep.contract.ds.project.service.ProjectService;
|
||||
import com.ecep.contract.ds.vendor.model.PurchaseOrder;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.jdbc.CannotGetJdbcConnectionException;
|
||||
@@ -106,7 +108,7 @@ public abstract class AbstContractRepairTasker extends Tasker<Object> {
|
||||
String state = (String) rs.get("strState");
|
||||
|
||||
holder.info("同步合同 " + contractID + " " + contractName);
|
||||
Contract contract = contractCtx.findOrCreatByGuidOrContractId(guid, contractID, holder);
|
||||
ContractVo contract = contractCtx.findOrCreatByGuidOrContractId(guid, contractID, holder);
|
||||
if (contract == null) {
|
||||
holder.warn("未知合同" + contractID + ", " + rs.get("strContractName"));
|
||||
return false;
|
||||
@@ -143,17 +145,17 @@ public abstract class AbstContractRepairTasker extends Tasker<Object> {
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
contract = contractCtx.save(contract);
|
||||
contract = save(contract);
|
||||
}
|
||||
|
||||
Contract parent = null;
|
||||
ContractVo parent = null;
|
||||
|
||||
if (contract.getPayWay() == ContractPayWay.PAY) {
|
||||
if (StringUtils.hasText(contract.getParentCode())) {
|
||||
parent = contractCtx.findContractByCode(contract.getParentCode());
|
||||
}
|
||||
}
|
||||
AtomicReference<Contract> refer = new AtomicReference<>(contract);
|
||||
AtomicReference<ContractVo> refer = new AtomicReference<>(contract);
|
||||
try {
|
||||
return repair(refer, parent, holder, progress -> {
|
||||
});
|
||||
@@ -163,6 +165,10 @@ public abstract class AbstContractRepairTasker extends Tasker<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
protected ContractVo save(ContractVo contract) {
|
||||
return contractCtx.save(contract);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contractProperty
|
||||
* @param holder
|
||||
@@ -170,11 +176,11 @@ public abstract class AbstContractRepairTasker extends Tasker<Object> {
|
||||
* @return
|
||||
*/
|
||||
public boolean repair(
|
||||
AtomicReference<Contract> contractProperty,
|
||||
Contract parent, MessageHolder holder, Consumer<Double> progress) {
|
||||
AtomicReference<ContractVo> contractProperty,
|
||||
ContractVo parent, MessageHolder holder, Consumer<Double> progress) {
|
||||
boolean repaired = false;
|
||||
boolean modified = false;
|
||||
Contract contract = contractProperty.get();
|
||||
ContractVo contract = contractProperty.get();
|
||||
|
||||
progress.accept(0.1);
|
||||
if (contractCtx.updateContractDetailByGuid(contract, contract.getGuid(), holder)) {
|
||||
@@ -197,7 +203,7 @@ public abstract class AbstContractRepairTasker extends Tasker<Object> {
|
||||
}
|
||||
progress.accept(0.5);
|
||||
if (modified) {
|
||||
contract = contractCtx.save(contract);
|
||||
contract = save(contract);
|
||||
contractProperty.set(contract);
|
||||
modified = false;
|
||||
repaired = true;
|
||||
@@ -216,7 +222,7 @@ public abstract class AbstContractRepairTasker extends Tasker<Object> {
|
||||
modified = true;
|
||||
}
|
||||
if (modified) {
|
||||
contract = contractCtx.save(contract);
|
||||
contract = save(contract);
|
||||
contractProperty.set(contract);
|
||||
modified = false;
|
||||
repaired = true;
|
||||
@@ -239,38 +245,38 @@ public abstract class AbstContractRepairTasker extends Tasker<Object> {
|
||||
return repaired;
|
||||
}
|
||||
|
||||
private void syncChildrenContract(Contract parent, MessageHolder holder, Consumer<Double> progress) {
|
||||
private void syncChildrenContract(ContractVo parent, MessageHolder holder, Consumer<Double> progress) {
|
||||
ContractService contractService = contractCtx.getContractService();
|
||||
ProjectService projectService = getCachedBean(ProjectService.class);
|
||||
List<Contract> list = contractService.findAllByParent(parent);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Contract v = list.get(i);
|
||||
holder.info("子合同 : " + v.getCode() + " " + v.getName());
|
||||
Contract v0 = list.get(i);
|
||||
ContractVo v1 = v0.toVo();
|
||||
holder.info("子合同 : " + v1.getCode() + " " + v1.getName());
|
||||
MessageHolder subHolder = holder.sub(" -- ");
|
||||
boolean modified = false;
|
||||
Project project = parent.getProject();
|
||||
if (project == null) {
|
||||
project = v.getProject();
|
||||
Integer projectId = parent.getProject();
|
||||
if (projectId == null) {
|
||||
projectId = v1.getProject();
|
||||
}
|
||||
AtomicReference<Contract> contractProperty = new AtomicReference<>(v);
|
||||
AtomicReference<ContractVo> contractProperty = new AtomicReference<>(v1);
|
||||
try {
|
||||
repair(contractProperty, parent, subHolder, p -> {
|
||||
});
|
||||
v1 = contractProperty.get();
|
||||
|
||||
v = contractProperty.get();
|
||||
if (contractCtx.updateContractProject(v, project, subHolder)) {
|
||||
var projectVo = projectService.findById(projectId);
|
||||
if (contractCtx.updateContractProject(v1, projectVo, subHolder)) {
|
||||
modified = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!Hibernate.isInitialized(v)) {
|
||||
v = contractService.getById(v.getId());
|
||||
}
|
||||
throw new RuntimeException("同步子合同失败, contract=" + v.toPrettyString(), e);
|
||||
throw new RuntimeException("同步子合同失败, 合同b编号:" + v1.getCode(), e);
|
||||
}
|
||||
if (modified) {
|
||||
try {
|
||||
v = contractCtx.save(v);
|
||||
v1 = save(v1);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("#" + v.getId() + ", v=" + v.getVersion(), e);
|
||||
throw new RuntimeException("#" + v1.getId() + ", ver=" + v1.getVersion(), e);
|
||||
}
|
||||
modified = false;
|
||||
}
|
||||
@@ -284,7 +290,7 @@ public abstract class AbstContractRepairTasker extends Tasker<Object> {
|
||||
* @param contract 合同
|
||||
* @param holder 消息
|
||||
*/
|
||||
private void syncSaleOrder(Contract contract, MessageHolder holder) {
|
||||
private void syncSaleOrder(ContractVo contract, MessageHolder holder) {
|
||||
SalesOrderCtx ctx = getSalesOrderCtx();
|
||||
if (ctx.getRepository() == null) {
|
||||
return;
|
||||
@@ -305,10 +311,13 @@ public abstract class AbstContractRepairTasker extends Tasker<Object> {
|
||||
* @param contract 合同
|
||||
* @param holder 消息
|
||||
*/
|
||||
private void syncPurchaseOrder(Contract contract, MessageHolder holder) {
|
||||
private void syncPurchaseOrder(ContractVo contract, MessageHolder holder) {
|
||||
PurchaseOrderCtx ctx1 = getPurchaseOrderCtx();
|
||||
if (ctx1.getRepository() != null) {
|
||||
ctx1.syncByContract(contract, holder);
|
||||
List<PurchaseOrder> orders = ctx1.syncByContract(contract, holder);
|
||||
if (orders == null) {
|
||||
holder.warn("没有采购订单异常");
|
||||
}
|
||||
}
|
||||
|
||||
PurchaseBillVoucherCtx ctx2 = getPurchaseBillVoucherCtx();
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ContractFilesRebuildAllTasker extends Tasker<Object> {
|
||||
}
|
||||
MessageHolder subHolder = holder.sub(
|
||||
counter.get() + " / " + total + "> " + contract.getCode() + " #" + contract.getId() + "> ");
|
||||
getContractCtx().syncContractFiles(contract, subHolder);
|
||||
getContractCtx().syncContractFiles(contract.toVo(), subHolder);
|
||||
updateProgress(counter.incrementAndGet(), total);
|
||||
}
|
||||
if (!page.hasNext()) {
|
||||
|
||||
@@ -31,7 +31,7 @@ public class ContractFilesRebuildTasker extends Tasker<Object> {
|
||||
updateTitle("遍历合同的文件进行“重置”操作");
|
||||
|
||||
ContractCtx contractCtx = new ContractCtx();
|
||||
if (contractCtx.syncContractFiles(contract, holder)) {
|
||||
if (contractCtx.syncContractFiles(contract.toVo(), holder)) {
|
||||
repaired = true;
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.ecep.contract.vo.ContractVo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -70,21 +71,22 @@ public class ContractRepairAllTasker extends AbstContractRepairTasker {
|
||||
break;
|
||||
}
|
||||
|
||||
for (Contract contract : page) {
|
||||
for (Contract c : page) {
|
||||
if (isCancelled()) {
|
||||
break;
|
||||
}
|
||||
var contract = c.toVo();
|
||||
MessageHolder subHolder = holder.sub(
|
||||
counter.get() + " / " + total + "> " + contract.getCode() + " #" + contract.getId() + "> ");
|
||||
MessageHolderImpl messageHolder = new MessageHolderImpl();
|
||||
try {
|
||||
Contract parent = null;
|
||||
ContractVo parent = null;
|
||||
if (contract.getPayWay() == ContractPayWay.PAY) {
|
||||
if (StringUtils.hasText(contract.getParentCode())) {
|
||||
parent = contractCtx.findContractByCode(contract.getParentCode());
|
||||
}
|
||||
}
|
||||
AtomicReference<Contract> contractProperty = new AtomicReference<>(contract);
|
||||
AtomicReference<ContractVo> contractProperty = new AtomicReference<>(contract);
|
||||
boolean repaired = repair(contractProperty, parent, messageHolder, progress -> {
|
||||
});
|
||||
String msg = messageHolder.messages.stream()
|
||||
|
||||
@@ -4,6 +4,7 @@ import static com.ecep.contract.SpringApp.getBean;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.ecep.contract.vo.ContractCatalogVo;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.MessageHolder;
|
||||
@@ -119,7 +120,7 @@ public class ContractRepairComm {
|
||||
parentDir = new File(parentPath);
|
||||
} else {
|
||||
// 主合同
|
||||
ContractCatalog catalog = getContractService().findContractCatalogByContract(contract.getCode());
|
||||
ContractCatalogVo catalog = getContractService().findContractCatalogByContract(contract.getCode());
|
||||
if (catalog == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
package com.ecep.contract.ds.customer.repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import com.ecep.contract.ds.company.model.Company;
|
||||
import com.ecep.contract.ds.customer.model.CompanyCustomer;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface CompanyCustomerRepository extends MyRepository<CompanyCustomer, Integer> {
|
||||
|
||||
Optional<CompanyCustomer> findByCompany(Company company);
|
||||
|
||||
Optional<CompanyCustomer> findByCompanyId(Integer companyId);
|
||||
|
||||
@Modifying
|
||||
@Transactional
|
||||
int deleteAllByCompany(Company company);
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.ecep.contract.vo.CompanyVo;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -80,6 +81,11 @@ public class CustomerService extends CompanyBasicService
|
||||
return repository.findByCompany(company).orElse(null);
|
||||
}
|
||||
|
||||
public CustomerVo findByCompany(CompanyVo company) {
|
||||
return repository.findByCompanyId(company.getId()).map(CompanyCustomer::toVo).orElse(null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CompanyCustomer getById(Integer id) {
|
||||
return repository.findById(id).orElse(null);
|
||||
@@ -193,7 +199,7 @@ public class CustomerService extends CompanyBasicService
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsDefaultType(F dbFile, File file,
|
||||
Consumer<String> status) {
|
||||
Consumer<String> status) {
|
||||
dbFile.setType((T) CustomerFileType.General);
|
||||
fillFile(dbFile, file, null, status);
|
||||
companyCustomerFileService.save((CompanyCustomerFile) dbFile);
|
||||
@@ -202,7 +208,7 @@ public class CustomerService extends CompanyBasicService
|
||||
|
||||
@Override
|
||||
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsEvaluationFile(F customerFile, File file,
|
||||
List<File> fileList, Consumer<String> status) {
|
||||
List<File> fileList, Consumer<String> status) {
|
||||
boolean modified = super.fillFileAsEvaluationFile(customerFile, file, fileList, status);
|
||||
|
||||
if (fileList != null) {
|
||||
@@ -236,7 +242,7 @@ public class CustomerService extends CompanyBasicService
|
||||
}
|
||||
|
||||
private <T, F extends CompanyBasicFile<T>> void updateEvaluationFileByJsonFile(F customerFile, File jsonFile,
|
||||
Consumer<String> status) throws IOException {
|
||||
Consumer<String> status) throws IOException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode root = objectMapper.readTree(jsonFile);
|
||||
if (!root.isObject()) {
|
||||
@@ -262,7 +268,7 @@ public class CustomerService extends CompanyBasicService
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected <T, F extends CompanyBasicFile<T>> F fillFileType(File file, List<File> fileList,
|
||||
Consumer<String> status) {
|
||||
Consumer<String> status) {
|
||||
CompanyCustomerFile customerFile = new CompanyCustomerFile();
|
||||
customerFile.setType(CustomerFileType.General);
|
||||
if (fillFile(customerFile, file, fileList, status)) {
|
||||
@@ -286,7 +292,7 @@ public class CustomerService extends CompanyBasicService
|
||||
return (fileName.contains(CompanyCustomerConstant.EVALUATION_FORM_NAME1)
|
||||
|| fileName.contains(CompanyCustomerConstant.EVALUATION_FORM_NAME2))
|
||||
&& (FileUtils.withExtensions(fileName, FileUtils.JPG, FileUtils.JPEG,
|
||||
FileUtils.PDF));
|
||||
FileUtils.PDF));
|
||||
}
|
||||
|
||||
public boolean makePathAbsent(CompanyCustomer companyCustomer) {
|
||||
|
||||
@@ -42,13 +42,13 @@ public class InventoryCatalogService implements IEntityService<InventoryCatalog>
|
||||
}
|
||||
|
||||
@Cacheable(key = "'code-'+#p0")
|
||||
public InventoryCatalog findByCode(String code) {
|
||||
return repository.findByCode(code).orElse(null);
|
||||
public InventoryCatalogVo findByCode(String code) {
|
||||
return repository.findByCode(code).map(InventoryCatalog::toVo).orElse(null);
|
||||
}
|
||||
|
||||
@Cacheable(key = "'name-'+#p0")
|
||||
public InventoryCatalog findByName(String name) {
|
||||
return repository.findByName(name).orElse(null);
|
||||
public InventoryCatalogVo findByName(String name) {
|
||||
return repository.findByName(name).map(InventoryCatalog::toVo).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ecep.contract.ds.project;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.ecep.contract.vo.ProjectVo;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
import com.ecep.contract.MessageHolder;
|
||||
@@ -13,15 +14,9 @@ import com.ecep.contract.ds.project.model.Project;
|
||||
import lombok.Setter;
|
||||
|
||||
public class ProjectCtx extends AbstractCtx {
|
||||
@Setter
|
||||
private ProjectService projectService;
|
||||
|
||||
|
||||
ProjectService getProjectService() {
|
||||
if (projectService == null) {
|
||||
projectService = getBean(ProjectService.class);
|
||||
}
|
||||
return projectService;
|
||||
public ProjectService getProjectService() {
|
||||
return getCachedBean(ProjectService.class);
|
||||
}
|
||||
|
||||
public boolean updateCustomer(Project project, Company customer, MessageHolder holder) {
|
||||
@@ -38,14 +33,27 @@ public class ProjectCtx extends AbstractCtx {
|
||||
return modified;
|
||||
}
|
||||
|
||||
public Project initialize(Project project) {
|
||||
if (Hibernate.isInitialized(project)) {
|
||||
return project;
|
||||
public boolean updateCustomerId(ProjectVo project, Integer customerId, MessageHolder holder) {
|
||||
boolean modified = false;
|
||||
if (!Objects.equals(project.getCustomerId(), customerId)) {
|
||||
project.setCustomerId(customerId);
|
||||
var customer = getCompanyService().findById(customerId);
|
||||
holder.info("同步合同所属项目客户为:" + customer.getName());
|
||||
modified = true;
|
||||
}
|
||||
return getProjectService().getById(project.getId());
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
|
||||
public Project save(Project project) {
|
||||
return getProjectService().save(project);
|
||||
}
|
||||
|
||||
public ProjectVo save(ProjectVo project) {
|
||||
ProjectService service = getProjectService();
|
||||
var v0 = service.getById(project.getId());
|
||||
service.updateByVo(v0, project);
|
||||
return service.save(v0).toVo();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,6 +143,15 @@ public class ProjectCostService implements IEntityService<ProjectCost>, QuerySer
|
||||
model.setDescription(vo.getDescription());
|
||||
model.setImportLock(vo.isImportLock());
|
||||
|
||||
model.setInTaxAmount(vo.getInTaxAmount());
|
||||
model.setInQuantities(vo.getInQuantities());
|
||||
model.setInExclusiveTaxAmount(vo.getInExclusiveTaxAmount());
|
||||
model.setOutTaxAmount(vo.getOutTaxAmount());
|
||||
model.setOutQuantities(vo.getOutQuantities());
|
||||
model.setOutExclusiveTaxAmount(vo.getOutExclusiveTaxAmount());
|
||||
model.setGrossProfitMargin(vo.getGrossProfitMargin());
|
||||
|
||||
|
||||
if (vo.getProject() == null) {
|
||||
model.setProject(null);
|
||||
} else {
|
||||
@@ -156,10 +165,10 @@ public class ProjectCostService implements IEntityService<ProjectCost>, QuerySer
|
||||
model.setContract(SpringApp.getBean(ContractService.class).getById(vo.getContractId()));
|
||||
}
|
||||
|
||||
if (vo.getApplicantId() == null) {
|
||||
if (vo.getAuthorizerId() == null) {
|
||||
model.setAuthorizer(null);
|
||||
} else {
|
||||
model.setApplicant(SpringApp.getBean(EmployeeService.class).getById(vo.getApplicantId()));
|
||||
model.setAuthorizer(SpringApp.getBean(EmployeeService.class).getById(vo.getAuthorizerId()));
|
||||
}
|
||||
|
||||
if (vo.getApplicantId() == null) {
|
||||
|
||||
@@ -24,6 +24,8 @@ public interface VendorRepository extends MyRepository<Vendor, Integer> {
|
||||
|
||||
Optional<Vendor> findByCompany(Company company);
|
||||
|
||||
Optional<Vendor> findByCompanyId(Integer companyId);
|
||||
|
||||
@Modifying
|
||||
@Transactional
|
||||
int deleteAllByCompany(Company company);
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.ecep.contract.vo.CompanyVo;
|
||||
import com.ecep.contract.vo.VendorCatalogVo;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.slf4j.Logger;
|
||||
@@ -121,6 +122,10 @@ public class VendorService extends CompanyBasicService
|
||||
return repository.findByCompany(company).orElse(null);
|
||||
}
|
||||
|
||||
public VendorVo findByCompany(CompanyVo company) {
|
||||
return repository.findByCompanyId(company.getId()).map(Vendor::toVo).orElse(null);
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id")
|
||||
})
|
||||
@@ -221,7 +226,7 @@ public class VendorService extends CompanyBasicService
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsDefaultType(F dbFile, File file,
|
||||
Consumer<String> status) {
|
||||
Consumer<String> status) {
|
||||
dbFile.setType((T) VendorFileType.General);
|
||||
fillFile(dbFile, file, null, status);
|
||||
vendorFileService.save((VendorFile) dbFile);
|
||||
@@ -231,7 +236,7 @@ public class VendorService extends CompanyBasicService
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected <T, F extends CompanyBasicFile<T>> F fillFileType(File file, List<File> fileList,
|
||||
Consumer<String> status) {
|
||||
Consumer<String> status) {
|
||||
VendorFile vendorFile = new VendorFile();
|
||||
vendorFile.setType(VendorFileType.General);
|
||||
vendorFile.setFilePath(file.getAbsolutePath());
|
||||
@@ -252,7 +257,7 @@ public class VendorService extends CompanyBasicService
|
||||
|
||||
@Override
|
||||
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsEvaluationFile(F customerFile, File file,
|
||||
List<File> fileList, Consumer<String> status) {
|
||||
List<File> fileList, Consumer<String> status) {
|
||||
boolean modified = super.fillFileAsEvaluationFile(customerFile, file, fileList, status);
|
||||
// 当评价表有日期,并且未设审核时
|
||||
boolean valid = FileUtils.isArchiveFile(customerFile.getFilePath()) && customerFile.getSignDate() != null;
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
import com.ecep.contract.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.ds.contract.tasker.AbstContractRepairTasker;
|
||||
import com.ecep.contract.ds.contract.tasker.ContractRepairComm;
|
||||
import com.ecep.contract.vo.ContractVo;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -19,7 +20,7 @@ import lombok.Getter;
|
||||
*/
|
||||
public class ContractRepairTasker extends AbstContractRepairTasker implements WebSocketServerTasker {
|
||||
@Getter
|
||||
private Contract contract;
|
||||
private ContractVo contract;
|
||||
@Getter
|
||||
boolean repaired = false;
|
||||
|
||||
@@ -31,13 +32,13 @@ public class ContractRepairTasker extends AbstContractRepairTasker implements We
|
||||
|
||||
public void init(JsonNode argsNode) {
|
||||
int contractId = argsNode.get(0).asInt();
|
||||
contract = getCachedBean(ContractService.class).getById(contractId);
|
||||
contract = getCachedBean(ContractService.class).findById(contractId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void repair(MessageHolder holder) {
|
||||
updateTitle("修复合同 " + contract.toPrettyString());
|
||||
Contract parent = null;
|
||||
updateTitle("修复合同 " + contract.getCode() + " - " + contract.getName());
|
||||
ContractVo parent = null;
|
||||
|
||||
if (contract.getPayWay() == ContractPayWay.PAY) {
|
||||
if (StringUtils.hasText(contract.getParentCode())) {
|
||||
@@ -45,7 +46,7 @@ public class ContractRepairTasker extends AbstContractRepairTasker implements We
|
||||
}
|
||||
}
|
||||
|
||||
AtomicReference<Contract> contractProperty = new AtomicReference<>(contract);
|
||||
AtomicReference<ContractVo> contractProperty = new AtomicReference<>(contract);
|
||||
if (repair(contractProperty, parent, holder, progress -> updateProgress(progress, 1))) {
|
||||
repaired = true;
|
||||
updateProperty("repaired", true);
|
||||
@@ -56,7 +57,7 @@ public class ContractRepairTasker extends AbstContractRepairTasker implements We
|
||||
updateProgress(1, 1);
|
||||
}
|
||||
|
||||
public void setContract(Contract contract) {
|
||||
public void setContract(ContractVo contract) {
|
||||
this.contract = contract;
|
||||
updateProperty("contract", contract);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user