This commit is contained in:
2025-10-11 09:21:14 +08:00
parent bda92193d4
commit 553feac0a4
93 changed files with 1736 additions and 676 deletions

View File

@@ -1,6 +1,7 @@
package com.ecep.contract.service.tasker;
import static com.ecep.contract.util.ExcelUtils.setCellValue;
import static com.ecep.contract.util.ExcelUtils.getCellValue;
import java.io.File;
import java.io.FileInputStream;
@@ -12,6 +13,7 @@ import java.io.OutputStream;
import java.time.LocalDate;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
@@ -26,7 +28,7 @@ import com.ecep.contract.SpringApp;
import com.ecep.contract.cloud.tyc.CloudTycService;
import com.ecep.contract.ds.customer.service.CompanyCustomerEvaluationFormFileService;
import com.ecep.contract.ds.customer.service.CompanyCustomerFileService;
import com.ecep.contract.ds.customer.service.CompanyCustomerService;
import com.ecep.contract.ds.customer.service.CustomerService;
import com.ecep.contract.ds.other.model.CloudTyc;
import com.ecep.contract.ds.company.model.Company;
import com.ecep.contract.ds.customer.model.CompanyCustomer;
@@ -34,6 +36,7 @@ import com.ecep.contract.ds.customer.model.CompanyCustomerEvaluationFormFile;
import com.ecep.contract.ds.customer.model.CompanyCustomerFile;
import com.ecep.contract.ui.Tasker;
import com.ecep.contract.util.CompanyUtils;
import com.ecep.contract.util.ExcelUtils;
import com.fasterxml.jackson.databind.JsonNode;
public class CompanyCustomerEvaluationFormUpdateTask extends Tasker<Object> implements WebSocketServerTasker {
@@ -42,7 +45,7 @@ public class CompanyCustomerEvaluationFormUpdateTask extends Tasker<Object> impl
@Override
public void init(JsonNode argsNode) {
int customerId = argsNode.get(0).asInt();
customer = getCachedBean(CompanyCustomerService.class).getById(customerId);
customer = getCachedBean(CustomerService.class).getById(customerId);
}
CompanyCustomerFileService getCompanyCustomerFileService() {
@@ -131,36 +134,100 @@ public class CompanyCustomerEvaluationFormUpdateTask extends Tasker<Object> impl
}
private void updateSheet(Company company, Sheet sheet, MessageHolder holder) {
setCellValue(sheet, "B3", "客户编号:" + CompanyUtils.formatCompanyVendorId(customer.getId()));
setCellValue(sheet, "B4", "客户名称:" + company.getName());
String customerId = "客户编号:" + CompanyUtils.formatCompanyVendorId(customer.getId());
String currentCustomerId = ExcelUtils.getCellValue(sheet, "B3");
if (!Objects.equals(customerId, currentCustomerId)) {
setCellValue(sheet, "B3", customerId);
holder.info("更新客户编号为:" + CompanyUtils.formatCompanyVendorId(customer.getId()));
}
String customerName = "客户名称:" + company.getName();
String currentCustomerName = ExcelUtils.getCellValue(sheet, "B4");
if (!Objects.equals(customerName, currentCustomerName)) {
setCellValue(sheet, "B4", customerName);
holder.info("更新客户名称为:" + company.getName());
}
LocalDate suggestDate = getCompanyCustomerFileService().getNextSignDate(customer, holder);
if (suggestDate == null) {
suggestDate = LocalDate.now();
holder.debug("未获取到推荐评定日期,使用当前日期:" + suggestDate);
} else {
holder.debug("获取到推荐评定日期:" + suggestDate);
}
setCellValue(sheet, "H3", "评定时间:" + suggestDate);
String evalDate = "评定时间:" + suggestDate;
String currentEvalDate = ExcelUtils.getCellValue(sheet, "H3");
if (!Objects.equals(evalDate, currentEvalDate)) {
setCellValue(sheet, "H3", evalDate);
holder.info("更新评定时间为:" + suggestDate);
}
setCellValue(sheet, "H4", "统一社会信用代码:");
setCellValue(sheet, "H5", company.getUniscid());
if (!Objects.equals(company.getUniscid(), ExcelUtils.getCellValue(sheet, "H5"))) {
setCellValue(sheet, "H5", company.getUniscid());
holder.info("更新统一社会信用代码为:" + company.getUniscid());
}
// 注册所属地
setCellValue(sheet, "B5", "注册所属地:" + company.getDistrict());
String district = "注册所属地:" + company.getDistrict();
if (!Objects.equals(district, ExcelUtils.getCellValue(sheet, "B5"))) {
setCellValue(sheet, "B5", district);
holder.info("更新注册所属地为:" + company.getDistrict());
}
// 经营状态
setCellValue(sheet, "D6", "经营状态:" + company.getEntStatus());
String entStatus = "经营状态:" + company.getEntStatus();
if (!Objects.equals(entStatus, ExcelUtils.getCellValue(sheet, "D6"))) {
setCellValue(sheet, "D6", entStatus);
holder.info("更新经营状态为:" + company.getEntStatus());
}
// 成立日期
setCellValue(sheet, "H6", "成立日期:" + company.getSetupDate());
String setupDate = "成立日期:" + company.getSetupDate();
if (!Objects.equals(setupDate, ExcelUtils.getCellValue(sheet, "H6"))) {
setCellValue(sheet, "H6", setupDate);
holder.info("更新成立日期为:" + company.getSetupDate());
}
// 所属行业
setCellValue(sheet, "D7", "所属行业:" + company.getIndustry());
setCellValue(sheet, "D8",
"注册资金:" + company.getRegisteredCapital() + " " + company.getRegisteredCapitalCurrency());
String industry = "所属行业:" + company.getIndustry();
if (!Objects.equals(industry, ExcelUtils.getCellValue(sheet, "D7"))) {
setCellValue(sheet, "D7", industry);
holder.info("更新所属行业为:" + company.getIndustry());
}
String registeredCapital = "注册资金:" + company.getRegisteredCapital() + " " + company.getRegisteredCapitalCurrency();
if (!Objects.equals(registeredCapital, ExcelUtils.getCellValue(sheet, "D8"))) {
setCellValue(sheet, "D8", registeredCapital);
holder.info("更新注册资金为:" + registeredCapital);
}
// 企业类型
setCellValue(sheet, "H10", "企业类型:" + company.getEntType());
String entType = "企业类型:" + company.getEntType();
if (!Objects.equals(entType, ExcelUtils.getCellValue(sheet, "H10"))) {
setCellValue(sheet, "H10", entType);
holder.info("更新企业类型为:" + company.getEntType());
}
// 天眼评分
CloudTycService cloudTycService = SpringApp.getBean(CloudTycService.class);
CloudTyc cloudTyc = cloudTycService.getOrCreateCloudTyc(company);
setCellValue(sheet, "D10", "天眼评分:" + (cloudTyc.getScore() > 0 ? cloudTyc.getScore() : ""));
String tycScore = "天眼评分:" + (cloudTyc.getScore() > 0 ? cloudTyc.getScore() : "");
if (!Objects.equals(tycScore, ExcelUtils.getCellValue(sheet, "D10"))) {
setCellValue(sheet, "D10", tycScore);
if (cloudTyc.getScore() > 0) {
holder.info("更新天眼评分为:" + cloudTyc.getScore());
} else {
holder.debug("天眼评分未设置或为0");
}
}
// 检索评估表
holder.debug("开始检索客户评价表文件");
List<CompanyCustomerFile> customerFiles = getCompanyCustomerFileService().findAllByCustomerAndType(customer,
CustomerFileType.EvaluationForm);
holder.debug("共检索到 " + customerFiles.size() + " 个客户评价表文件");
List<CompanyCustomerEvaluationFormFile> filteredList = customerFiles.stream().filter(file -> {
return file.getSignDate() != null && file.isValid();
@@ -168,29 +235,45 @@ public class CompanyCustomerEvaluationFormUpdateTask extends Tasker<Object> impl
.sorted(Comparator.comparing(CompanyCustomerFile::getSignDate))
.map(getCompanyCustomerEvaluationFormFileService()::findByCustomerFile)
.toList();
holder.debug("有效评价表数量:" + filteredList.size());
if (filteredList.isEmpty()) {
setCellValue(sheet, "C40", "首次评价");
if (!Objects.equals("首次评价", ExcelUtils.getCellValue(sheet, "C40"))) {
setCellValue(sheet, "C40", "首次评价");
holder.info("设置客户为首次评价状态");
}
try {
sheet.addMergedRegion(CellRangeAddress.valueOf("C40:K40"));
} catch (Exception ignored) {
holder.debug("合并单元格C40:K40失败可能已合并");
}
} else {
holder.info("客户有 " + filteredList.size() + " 条评价表");
setCellValue(sheet, "C40", "评价日期");
try {
sheet.addMergedRegion(CellRangeAddress.valueOf("C40:D40"));
} catch (Exception ignored) {
holder.info("客户有 " + filteredList.size() + "有效评价表记录");
if (!Objects.equals("评价日期", ExcelUtils.getCellValue(sheet, "C40"))) {
setCellValue(sheet, "C40", "评价日期");
try {
sheet.addMergedRegion(CellRangeAddress.valueOf("C40:D40"));
} catch (Exception ignored) {
holder.debug("合并单元格C40:D40失败可能已合并");
}
}
if (!Objects.equals("经济指标", ExcelUtils.getCellValue(sheet, "E40"))) {
setCellValue(sheet, "E40", "经济指标");
}
if (!Objects.equals("综合指标", ExcelUtils.getCellValue(sheet, "F40"))) {
setCellValue(sheet, "F40", "综合指标");
}
if (!Objects.equals("资信等级", ExcelUtils.getCellValue(sheet, "G40"))) {
setCellValue(sheet, "G40", "资信等级");
}
setCellValue(sheet, "E40", "经济指标");
setCellValue(sheet, "F40", "综合指标");
setCellValue(sheet, "G40", "资信等级");
String[] CreditLevelTitles = new String[] { "-", "差★", " 一般★★", " 较好★★★", " 好★★★★", " " };
int baseRow = 40;
for (CompanyCustomerEvaluationFormFile form : filteredList) {
baseRow++;
CompanyCustomerFile customerFile = form.getCustomerFile();
if (!Hibernate.isInitialized(customerFile)) {
customerFile = getCompanyCustomerFileService().findById(customerFile.getId());
holder.debug("延迟加载评价表文件信息文件ID" + customerFile.getId());
}
setCellValue(sheet, baseRow, 2, String.valueOf(customerFile.getSignDate()));
setCellValue(sheet, baseRow, 4, form.getCatalog());
@@ -203,9 +286,10 @@ public class CompanyCustomerEvaluationFormUpdateTask extends Tasker<Object> impl
try {
sheet.addMergedRegion(new CellRangeAddress(baseRow, baseRow, 2, 3));
} catch (Exception ignored) {
holder.debug("合并单元格第" + baseRow + "行的2-3列失败可能已合并");
}
baseRow++;
}
holder.info("已成功更新所有评价表记录到Excel中");
}
}
}

View File

@@ -8,7 +8,7 @@ import com.ecep.contract.CustomerFileType;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.ds.contract.service.ContractService;
import com.ecep.contract.ds.customer.service.CompanyCustomerFileService;
import com.ecep.contract.ds.customer.service.CompanyCustomerService;
import com.ecep.contract.ds.customer.service.CustomerService;
import com.ecep.contract.ds.customer.model.CompanyCustomer;
import com.ecep.contract.ds.customer.model.CompanyCustomerFile;
import com.ecep.contract.ds.contract.model.Contract;
@@ -22,15 +22,15 @@ public class CompanyCustomerNextSignDateTask extends Tasker<Object> implements W
@Override
public void init(JsonNode argsNode) {
int customerId = argsNode.get(0).asInt();
customer = getCachedBean(CompanyCustomerService.class).getById(customerId);
customer = getCachedBean(CustomerService.class).getById(customerId);
}
CompanyCustomerFileService getCompanyCustomerFileService() {
return getCachedBean(CompanyCustomerFileService.class);
}
CompanyCustomerService getCompanyCustomerService() {
return getCachedBean(CompanyCustomerService.class);
CustomerService getCompanyCustomerService() {
return getCachedBean(CustomerService.class);
}
ContractService getContractService() {

View File

@@ -5,7 +5,7 @@ import org.springframework.util.StringUtils;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.ds.company.service.CompanyService;
import com.ecep.contract.ds.customer.service.CompanyCustomerService;
import com.ecep.contract.ds.customer.service.CustomerService;
import com.ecep.contract.ds.company.model.Company;
import com.ecep.contract.ds.customer.model.CompanyCustomer;
import com.ecep.contract.ui.Tasker;
@@ -19,8 +19,8 @@ public class CompanyCustomerRebuildFilesTasker extends Tasker<Object> implements
private CompanyCustomer customer;
CompanyCustomerService getCompanyCustomerService() {
return getCachedBean(CompanyCustomerService.class);
CustomerService getCompanyCustomerService() {
return getCachedBean(CustomerService.class);
}
@Override

View File

@@ -1,6 +1,7 @@
package com.ecep.contract.service.tasker;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.MyDateTimeUtils;
import com.ecep.contract.cloud.rk.CloudRkService;
import com.ecep.contract.cloud.rk.ctx.CloudRkCtx;
import com.ecep.contract.constant.CloudServiceConstant;
@@ -34,16 +35,18 @@ public class CompanyRkUpdateTasker extends Tasker<Object> implements WebSocketSe
@Override
protected Object execute(MessageHolder holder) throws Exception {
holder.debug("1. 从 " + CloudServiceConstant.RK_NAME + " 更新...");
try {
cloudRkService = getCachedBean(CloudRkService.class);
} catch (BeansException e) {
throw new RuntimeException("服务未启用");
throw new RuntimeException("服务未启用,请联系管理员");
}
CloudRk cloudRk = cloudRkService.getOrCreateCloudRk(company);
if (cloudRk == null) {
throw new RuntimeException("无法创建或获取 CloudRk 对象");
}
if (cloudRk.getLatestUpdate() != null) {
holder.info("上次更新:" + MyDateTimeUtils.format(cloudRk.getLatestUpdate()));
}
try {
CloudRkCtx cloudRkCtx = new CloudRkCtx();

View File

@@ -0,0 +1,282 @@
package com.ecep.contract.service.tasker;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.VendorFileType;
import com.ecep.contract.ds.company.service.CompanyContactService;
import com.ecep.contract.ds.company.service.CompanyService;
import com.ecep.contract.ds.vendor.model.Vendor;
import com.ecep.contract.ds.vendor.model.VendorFile;
import com.ecep.contract.ds.vendor.service.VendorFileService;
import com.ecep.contract.ds.vendor.service.VendorService;
import com.ecep.contract.ui.Tasker;
import com.ecep.contract.util.ExcelUtils;
import com.ecep.contract.vo.CompanyContactVo;
import com.ecep.contract.vo.CompanyVo;
import com.ecep.contract.vo.VendorVo;
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.poi.ss.usermodel.*;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.io.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Objects;
import static com.ecep.contract.util.ExcelUtils.getCellValue;
import static com.ecep.contract.util.ExcelUtils.setCellValue;
/**
* 更新供应商评价表
*/
@Component
public class CompanyVendorEvaluationFormUpdateTask extends Tasker<Object> implements WebSocketServerTasker {
private VendorVo vendor;
private CompanyVo company;
private File template;
@Override
public void init(JsonNode argsNode) {
int vendorId = argsNode.get(0).asInt();
vendor = getVendorService().findById(vendorId);
}
private VendorService getVendorService() {
return getCachedBean(VendorService.class);
}
VendorFileService getVendorFileService() {
return getCachedBean(VendorFileService.class);
}
@Override
protected Object execute(MessageHolder holder) throws Exception {
if (vendor == null) {
holder.error("未找到供应商信息");
return null;
}
if (!StringUtils.hasText(vendor.getPath())) {
holder.error("供应商目录未设置,请先设置供应商目录");
return null;
}
updateEvaluationForm(holder);
return null;
}
public void updateEvaluationForm(MessageHolder holder) {
company = getCachedBean(CompanyService.class).findById(vendor.getCompanyId());
template = getVendorFileService().getEvaluationFormTemplate();
if (template == null) {
holder.error("评价表模板文件未设置,请先设置评价表模板文件");
return;
}
if (!template.exists()) {
holder.error("评价表模板文件 " + template.getAbsolutePath() + " 不存在,请检查");
return;
}
updateProgress(1, 10);
File dir = new File(vendor.getPath());
String template_file_name = template.getName();
File destFile = new File(dir, template_file_name);
if (destFile.exists()) {
holder.info("表单文件已经存在," + destFile.getName());
try (
InputStream inp = new FileInputStream(destFile);
Workbook wb = WorkbookFactory.create(inp)) {
updateEvaluationForm(wb, destFile, holder);
holder.info("评价表已更新");
} catch (Exception e) {
holder.error(e.getMessage());
}
} else {
holder.info("根据模板 " + template_file_name + " 创建表单 " + destFile.getName());
try (
InputStream inp = new FileInputStream(template);
Workbook wb = WorkbookFactory.create(inp)) {
updateEvaluationForm(wb, destFile, holder);
holder.info("评价表已创建");
// 创建 VendorFile 对象
VendorFile vendorFile = new VendorFile();
Vendor vendorEntity = getCachedBean(VendorService.class).getById(vendor.getId());
vendorFile.setVendor(vendorEntity);
vendorFile.setFilePath(destFile.getAbsolutePath());
vendorFile.setType(VendorFileType.EvaluationForm);
vendorFile.setSignDate(LocalDate.now());
vendorFile.setValid(false);
getVendorFileService().save(vendorFile);
} catch (Exception e) {
holder.error(e.getMessage());
}
}
updateProgress(10, 10);
}
/**
* 更新供应商评估表,依据模板创建,如果已经存在生成的文件,则更新评估表
*
* @param wb work book
* @param destFile 目标文件
*/
public void updateEvaluationForm(Workbook wb, File destFile, MessageHolder holder) throws IOException {
updateProgress(2, 10);
Sheet sheet = wb.getSheetAt(0);
holder.info("更新 " + sheet.getSheetName() + " Sheet");
updateSheet(sheet, holder.sub(" - "));
updateProgress(8, 10);
// 输出到文件
try (OutputStream fileOut = new FileOutputStream(destFile)) {
wb.write(fileOut);
} catch (FileNotFoundException e) {
holder.error("写评估表时发生文件错误,请检查评估表是否被打开中:" + e.getMessage());
}
}
private void updateSheet(Sheet sheet, MessageHolder holder) {
String vendor_id = "" + vendor.getId();
if (!Objects.equals(vendor_id, getCellValue(sheet, "G1"))) {
setCellValue(sheet, "G1", vendor_id);
holder.info("供应商编号更新为:" + vendor_id);
}
String companyName = company.getName();
if (!Objects.equals(companyName, getCellValue(sheet, "B2"))) {
setCellValue(sheet, "B2", companyName);
holder.info("供应商名称更新为:" + companyName);
}
String address = null;
// 联系人
CompanyContactVo contact = null;
if (vendor.getContactId() != null) {
contact = getCompanyContactService().findById(vendor.getContactId());
if (contact != null) {
holder.debug("供应商指定联系人:" + contact.getName());
}
}
if (contact == null) {
contact = getCompanyContactService().findFirstByCompany(company);
if (contact != null) {
holder.debug("从公司联系人列表中获取联系人:" + contact.getName());
}
}
if (contact != null) {
String contactName = contact.getName();
if (!Objects.equals(contactName, getCellValue(sheet, "F2"))) {
setCellValue(sheet, "F2", contactName);
holder.info("联系人姓名更新为:" + contactName);
}
String contactPhone = contact.getPhone();
if (StringUtils.hasText(contactPhone)) {
if (!Objects.equals(contactPhone, getCellValue(sheet, "F3"))) {
setCellValue(sheet, "F3", contactPhone);
holder.info("联系人电话更新为:" + contactPhone);
}
}
if (StringUtils.hasText(contact.getAddress())) {
address = contact.getAddress();
}
}
if (!StringUtils.hasText(address)) {
address = company.getAddress();
if (StringUtils.hasText(address)) {
holder.debug("使用公司地址:" + address);
}
}
if (!StringUtils.hasText(address)) {
address = company.getRegAddr();
if (StringUtils.hasText(address)) {
holder.debug("使用公司注册地址:" + address);
}
}
if (StringUtils.hasText(address)) {
if (!Objects.equals(address, getCellValue(sheet, "B3"))) {
setCellValue(sheet, "B3", address);
holder.info("更新供应商地址为:" + address);
}
} else {
holder.warn("没有获取到供应商地址,请检查供应商信息");
}
String companyUniscid = company.getUniscid();
if (!Objects.equals(companyUniscid, getCellValue(sheet, "B8"))) {
setCellValue(sheet, "B8", companyUniscid);
holder.info("更新供应商统一社会信用代码为:" + companyUniscid);
}
String regCap = company.getRegisteredCapital() + " " + company.getRegisteredCapitalCurrency();
if (!Objects.equals(regCap, getCellValue(sheet, "E8"))) {
setCellValue(sheet, "E8", regCap);
holder.info("更新供应商注册资金为:" + regCap);
}
setCellValue(sheet, "H8", company.getOperationPeriodBegin());
if (company.getOperationPeriodEnd() == null) {
if (company.getOperationPeriodBegin() != null) {
setCellValue(sheet, "H9", "无固定期限");
}
} else {
setCellValue(sheet, "H9", company.getOperationPeriodEnd());
}
String vendorPurchase = vendor.getPurchase();
if (!Objects.equals(vendorPurchase, getCellValue(sheet, "C4"))) {
setCellValue(sheet, "C4", vendorPurchase);
holder.info("更新供应商采购内容为:" + vendorPurchase);
}
Cell a6 = ExcelUtils.getCell(sheet, "A6");
if (a6 != null) {
if (!Objects.equals(a6.getStringCellValue(), vendor.getDescription())) {
a6.setCellValue(vendor.getDescription());
holder.info("更新供应商描述为:" + StringUtils.truncate(a6.getStringCellValue(), 30));
}
if (a6.getCellStyle().getAlignment() != HorizontalAlignment.LEFT) {
a6.getCellStyle().setAlignment(HorizontalAlignment.LEFT);
holder.info("更新供应商描述对齐方式为左对齐");
}
}
// 第一个评价日期
Cell g16 = ExcelUtils.getCell(sheet, "G16");
if (g16 == null) {
holder.error("模板异常, 第一个评价日期单元格(G16)未找到!");
} else {
CellType cellType = g16.getCellType();
// 未设置, 尝试更新
if (cellType == CellType.BLANK || cellType == CellType.NUMERIC) {
holder.debug("推算下一个评价日期...");
LocalDate nextSignDate = getVendorFileService().getNextSignDate(vendor, holder.sub(" -| "));
// 当没有推荐日期时,说明不需要评价,更新为空
if (nextSignDate == null) {
g16.setBlank();
holder.info("!未推算出下一个评价日期,单元格设空!");
} else {
holder.debug("推算出下一个评价日期:" + nextSignDate);
LocalDateTime value = g16.getLocalDateTimeCellValue();
if (value == null) {
g16.setCellValue(nextSignDate);
holder.info("评价日期更新为:" + nextSignDate);
} else {
if (!Objects.equals(value.toLocalDate(), nextSignDate)) {
g16.setCellValue(nextSignDate);
holder.info("评价日期更新为:" + nextSignDate);
}
}
}
} else {
holder.warn("第一个评价日期所在单元格 " + g16.getAddress().formatAsR1C1String() + " 的单元格类型未知:" + cellType);
}
}
}
private CompanyContactService getCompanyContactService() {
return getCachedBean(CompanyContactService.class);
}
}

View File

@@ -2,7 +2,7 @@ package com.ecep.contract.service.tasker;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.ds.customer.service.CompanyCustomerFileService;
import com.ecep.contract.ds.customer.service.CompanyCustomerService;
import com.ecep.contract.ds.customer.service.CustomerService;
import com.ecep.contract.ds.company.model.Company;
import com.ecep.contract.ds.customer.model.CompanyCustomer;
import com.ecep.contract.ds.customer.model.CompanyCustomerFile;
@@ -104,7 +104,7 @@ public class CustomerFileMoveTasker extends Tasker<Object> implements WebSocketS
return getCachedBean(CompanyCustomerFileService.class);
}
private CompanyCustomerService getCompanyCustomerService() {
return getCachedBean(CompanyCustomerService.class);
private CustomerService getCompanyCustomerService() {
return getCachedBean(CustomerService.class);
}
}

View File

@@ -0,0 +1,121 @@
package com.ecep.contract.service.tasker;
import java.time.LocalDate;
import java.util.Comparator;
import java.util.List;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.VendorFileType;
import com.ecep.contract.ds.contract.model.Contract;
import com.ecep.contract.ds.contract.service.ContractService;
import com.ecep.contract.ds.vendor.model.Vendor;
import com.ecep.contract.ds.vendor.model.VendorFile;
import com.ecep.contract.ds.vendor.service.VendorFileService;
import com.ecep.contract.ds.vendor.service.VendorService;
import com.ecep.contract.ui.Tasker;
import com.fasterxml.jackson.databind.JsonNode;
public class VendorNextSignDateTask extends Tasker<Object> implements WebSocketServerTasker {
private Vendor vendor;
@Override
public void init(JsonNode argsNode) {
int vendorId = argsNode.get(0).asInt();
vendor = getCachedBean(VendorService.class).getById(vendorId);
}
VendorFileService getVendorFileService() {
return getCachedBean(VendorFileService.class);
}
VendorService getVendorService() {
return getCachedBean(VendorService.class);
}
ContractService getContractService() {
return getCachedBean(ContractService.class);
}
@Override
protected Object execute(MessageHolder holder) throws Exception {
if (vendor == null) {
holder.error("未找到供应商信息");
return null;
}
holder.info("开始计算供应商下一个评价日期");
LocalDate nextSignDate = calculateNextSignDate(holder);
if (nextSignDate != null) {
holder.info("下一个评价日期:" + nextSignDate);
} else {
holder.warn("无法计算下一个评价日期");
}
return nextSignDate;
}
private LocalDate calculateNextSignDate(MessageHolder holder) {
LocalDate miniContractDate = LocalDate.of(2022, 1, 1);
// 检索全部合同
ContractService contractService = getContractService();
List<Contract> contractList = contractService.findAllByCompanyVendor(vendor, null, null);
if (contractList.isEmpty()) {
holder.error("未发现已登记的合同");
return null;
}
holder.info("发现" + contractList.size() + "份合同");
// 检索评价表
List<VendorFile> files = getVendorFileService().findAllByVendorAndType(vendor,
VendorFileType.EvaluationForm);
VendorFile latestFile = files.stream()
.filter(v -> v.getSignDate() != null && v.isValid())
.max(Comparator.comparing(VendorFile::getSignDate))
.orElse(null);
// 没有有效的评价表的评价日期
if (latestFile == null) {
holder.warn("未发现有效的评价表");
// 返回最早的合同日期
Contract firstContract = contractList.stream()
.filter(v -> v.getSetupDate() != null && !v.getSetupDate().isBefore(miniContractDate))
.min(Comparator.comparing(Contract::getSetupDate))
.orElse(null);
if (firstContract == null) {
holder.error("最早的合同不存在");
return null;
}
LocalDate setupDate = firstContract.getSetupDate();
holder.info("选择最早的合同:" + firstContract.getCode() + ",日期:" + setupDate);
return setupDate.plusDays(-7);
}
// 有有效的评价表,计算下一个日期
LocalDate lastSignDate = latestFile.getSignDate();
holder.info("最近一次有效的评价表日期:" + lastSignDate);
// 查找最近一次评价日期之后的合同
Contract firstContractAfter = contractList.stream()
.filter(v -> v.getSetupDate() != null && v.getSetupDate().isAfter(lastSignDate))
.min(Comparator.comparing(Contract::getSetupDate))
.orElse(null);
if (firstContractAfter == null) {
holder.warn("没有找到在" + lastSignDate + "之后的合同");
// 返回当前日期作为建议
return LocalDate.now();
}
LocalDate setupDate = firstContractAfter.getSetupDate();
holder.info("找到最近一次评价日期后的第一个合同:" + firstContractAfter.getCode() + ",日期:" + setupDate);
return setupDate.plusDays(-7);
}
}