导出优化

This commit is contained in:
shuo.wang
2025-02-24 18:36:09 +08:00
parent 766bb5ccce
commit a064b1b08e
3 changed files with 65 additions and 11 deletions

View File

@@ -17,7 +17,9 @@
<select id="getPayTimeByShopIds" resultType="com.cool.store.dto.FranchiseFeeDTO">
select a.shop_id AS shopId ,
b.pay_time as payTime,
b.combined_field as combinedField,
a.year_franchise_fee as yearFranchiseFee,
a.first_year_manage_fee as firstYearManagementFee,
a.loan_margin as loanMargin,
a.first_year_start_time as firstYearStartTime,
a.first_year_end_time as firstYearEndTime,

View File

@@ -4,6 +4,7 @@ import lombok.Data;
import javax.persistence.Column;
import java.util.Date;
import java.util.List;
/**
* @Author: WangShuo
@@ -15,18 +16,24 @@ import java.util.Date;
@Data
public class FranchiseFeeDTO {
private Long shopId;
//缴费时间
private Date payTime;
//每年加盟费
private String yearFranchiseFee;
//保证金
private String loanMargin;
private Date firstYearStartTime;
private Date firstYearEndTime;
//第一年度管理费
private String firstYearManagementFee;
//第一年度品牌使用费
private String firstYearFee;
//履约保证金
private String performanceBond;
//组合字段
private String combinedField;
private List<Date> payTimeList;
}

View File

@@ -25,6 +25,8 @@ import com.cool.store.utils.easyExcel.EasyExcelUtil;
import com.cool.store.utils.poi.DateUtils;
import com.cool.store.utils.poi.StringUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
@@ -105,9 +107,16 @@ public class ExportRealizeServiceImpl implements ExportRealizeService {
List<Long> shopIds = list.stream().map(BranchShopResponse::getShopId).collect(Collectors.toList());
List<SignFranchiseDO> signFranchises = signFranchiseMapper.selectByShopIds(shopIds);
List<FranchiseFeeDTO> franchiseFees = franchiseFeeMapper.getPayTimeByShopIds(shopIds);
Map<Long, Date> payTimeMap = franchiseFees.stream().filter(o -> o.getPayTime() != null)
.filter(o -> o.getShopId() != null)
.collect(Collectors.toMap(FranchiseFeeDTO::getShopId, FranchiseFeeDTO::getPayTime));
Map<Long, List<Date>> payTimeMap = new HashMap<>();
for (FranchiseFeeDTO dto : franchiseFees) {
List<Date> payTimeList = JsonToDate(dto.getCombinedField());
if (dto.getPayTime() != null) {
payTimeList.add(dto.getPayTime());
}
Collections.sort(payTimeList);
payTimeMap.put(dto.getShopId(), payTimeList);
}
Map<Long, FranchiseFeeDTO> franchiseFeeDTOMap = franchiseFees.stream().filter(o -> o.getShopId() != null)
.collect(Collectors.toMap(FranchiseFeeDTO::getShopId, Function.identity()));
Map<Long, SignFranchiseDO> signFranchiseMap = new HashMap<>();
@@ -131,6 +140,8 @@ public class ExportRealizeServiceImpl implements ExportRealizeService {
dto.setFranchiseFeeBill(franchiseFeeDTO.getYearFranchiseFee());
dto.setLoanMargin(franchiseFeeDTO.getLoanMargin());
dto.setPerformanceBondBill(franchiseFeeDTO.getPerformanceBond());
dto.setFirstYearManagementFeeBill(franchiseFeeDTO.getFirstYearManagementFee());
dto.setFirstYearBrandingFeeBill(franchiseFeeDTO.getFirstYearFee());
}
dto.setUserName(response.getUsername());
dto.setMobile(response.getMobile());
@@ -146,9 +157,22 @@ public class ExportRealizeServiceImpl implements ExportRealizeService {
dto.setContractStartTime(DateUtils.parseDateToStr(SPECIAL_DATE_START_1, signFranchiseDO.getContractStartTime()));
dto.setContractEndTime(DateUtils.parseDateToStr(SPECIAL_DATE_START_1, signFranchiseDO.getContractEndTime()));
}
Date payTime = payTimeMap.get(response.getShopId());
if (Objects.nonNull(payTime)) {
dto.setFirstPayTime(DateUtils.parseDateToStr(SPECIAL_DATE_START_1, payTime));
List<Date> payTime = payTimeMap.getOrDefault(response.getShopId(), new ArrayList<>());
for (int i = 0; i < payTime.size() && i <= 3; i++) {
switch (i) {
case 0:
dto.setFirstPayTime(DateUtils.parseDateToStr(SPECIAL_DATE_START_1, payTime.get(i)));
break;
case 1:
dto.setSecondPayTime(DateUtils.parseDateToStr(SPECIAL_DATE_START_1, payTime.get(i)));
break;
case 2:
dto.setThirdPayTime(DateUtils.parseDateToStr(SPECIAL_DATE_START_1, payTime.get(i)));
break;
case 3:
dto.setFourthPayTime(DateUtils.parseDateToStr(SPECIAL_DATE_START_1, payTime.get(i)));
break;
}
}
InvoicingDO invoicingDO = InvoicingMap.get(response.getShopId());
if (invoicingDO != null) {
@@ -192,5 +216,26 @@ public class ExportRealizeServiceImpl implements ExportRealizeService {
}
return o.toString();
}
private List<Date> JsonToDate(String json) {
ObjectMapper mapper = new ObjectMapper();
// 解析JSON字符串为JsonNode对象
JsonNode jsonNode = null;
try {
jsonNode = mapper.readTree(json);
List<Date> payTimeList = new ArrayList<>();
// 遍历数组节点
for (JsonNode node : jsonNode) {
long payTime = node.get("payTime").asLong();
// 将时间戳转换为Date对象
Date date = new Date(payTime);
payTimeList.add(date);
}
return payTimeList;
} catch (Exception e) {
log.info("解析加盟费缴纳时间json失败");
throw new RuntimeException(e);
}
}
}