Commit 574abf10 authored by fangxinjiang's avatar fangxinjiang

Merge branch 'MVP1.7.15' into MVP1.7.16

parents 9b7c86d2 46f55d43
package com.yifu.cloud.plus.v1.yifu.common.core.util;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* 月份计算工具类
* 提供根据当前时间向前推N个月的开始时间和结束时间计算功能
*
* @author fxj
*/
public class MonthCalculationUtils {
/**
* 私有构造函数,防止实例化
*/
private MonthCalculationUtils() {
throw new IllegalStateException("MonthCalculationUtils class");
}
/**
* 根据给定的月份数,计算从当前时间往前推n个月的开始时间和结束时间
*
* @param months 往前推的月份数
* @return 包含开始时间和结束时间的字符串数组,索引0为开始时间,索引1为结束时间
*/
public static String[] calculateMonthRange(int months) {
// 获取当前时间
LocalDateTime now = LocalDateTime.now();
// 计算目标月份的第一天 00:00:00
LocalDateTime start = now.minusMonths(months)
.withDayOfMonth(1)
.withHour(0)
.withMinute(0)
.withSecond(0)
.withNano(0);
// 计算目标月份的最后一天 23:59:59
LocalDateTime end = start.withDayOfMonth(start.toLocalDate().lengthOfMonth())
.withHour(23)
.withMinute(59)
.withSecond(59)
.withNano(0);
// 格式化时间
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return new String[]{
start.format(formatter),
end.format(formatter)
};
}
/**
* 根据给定的基准时间和月份数,计算从基准时间往前推n个月的开始时间和结束时间
*
* @param baseTime 基准时间
* @param months 往前推的月份数
* @return 包含开始时间和结束时间的字符串数组,索引0为开始时间,索引1为结束时间
*/
public static String[] calculateMonthRangeFromBase(LocalDateTime baseTime, int months) {
// 计算目标月份的第一天 00:00:00
LocalDateTime start = baseTime.minusMonths(months)
.withDayOfMonth(1)
.withHour(0)
.withMinute(0)
.withSecond(0)
.withNano(0);
// 计算目标月份的最后一天 23:59:59
LocalDateTime end = start.withDayOfMonth(start.toLocalDate().lengthOfMonth())
.withHour(23)
.withMinute(59)
.withSecond(59)
.withNano(0);
// 格式化时间
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return new String[]{
start.format(formatter),
end.format(formatter)
};
}
}
\ No newline at end of file
......@@ -32,9 +32,9 @@ public class QwExcelApiController {
* @Param
* @return
**/
@PostMapping("/tesxWxExcelApi")
@PostMapping("/wxExcelApi")
public void tesxWxExcelApi() {
qwExcelApiService.tesxWxExcelApi();
qwExcelApiService.wxExcelApi();
}
......
......@@ -63,4 +63,23 @@ public interface QwExcelApiMapper extends BaseMapper<EkpInvoiceInfo> {
"FROM view_contract_info")
List<Map<String, Object>> selectContractInfoAsMap();
/**
* 带参数的查询
* @param startDate 查询区间开始时间
* @param endDate 查询区间结束时间
* @return List<Map<String, Object>>
*/
List<Map<String, Object>> selectInvoiceList(@Param("startDate") String startDate,@Param("endDate") String endDate);
/**
* 查询合同信息列表
* @return List<Map<String, Object>>
*/
List<Map<String, Object>> selectContractList(@Param("limitStart") int limitStart,@Param("limitEnd") int limitEnd);
/**
* 查询合同信息列表
* @return List<Map<String, Object>>
*/
int selectContractListCount();
}
......@@ -14,23 +14,5 @@ import java.util.Map;
*/
public interface QwExcelApiService extends IService<EkpInvoiceInfo> {
void tesxWxExcelApi();
/**
* @Author fxj
* @Description 获取所有发票池信息
* @Date 16:09 2025/9/26
* @Param
* @return
**/
public List<Map<String, Object>> getInvoiceList();
/**
* @Author fxj
* @Description 获取所有合同数据
* @Date 16:09 2025/9/26
* @Param
* @return
**/
public List<Map<String, Object>> getContractList();
void wxExcelApi();
}
......@@ -8,10 +8,13 @@ import com.yifu.cloud.plus.v1.ekp.mapper.EkpBankAttaMapper;
import com.yifu.cloud.plus.v1.ekp.mapper.QwExcelApiMapper;
import com.yifu.cloud.plus.v1.ekp.service.QwExcelApiService;
import com.yifu.cloud.plus.v1.ekp.util.SmartSheetDebugService;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.MonthCalculationUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -29,18 +32,46 @@ public class QwExcelApiServiceImpl extends ServiceImpl<QwExcelApiMapper, EkpInvo
@Autowired
private WxConfig wxConfig;
@Override
public void tesxWxExcelApi() {
List<Map<String, Object>> records = baseMapper.selectInvoiceInfoAsMap();
debugService.debugInsertIssue(wxConfig,records);
}
@Override
public List<Map<String, Object>> getInvoiceList() {
return baseMapper.selectInvoiceInfoAsMap();
}
@Override
public List<Map<String, Object>> getContractList() {
return baseMapper.selectContractInfoAsMap();
public void wxExcelApi() {
int batchSize = 1000;
int batchCount = 0;
log.info("微信智能表格发票数据插入开始...");
//获取最近24个月的发票信息,按月去插入到智能表格中
String[] monthRange =null;
List<Map<String, Object>> records = new ArrayList<>();
List<Map<String, Object>> tempRecords = null;
for (int i = 0; i < 24; i++){
monthRange =MonthCalculationUtils.calculateMonthRange(i);
if (null != monthRange && monthRange.length == CommonConstants.dingleDigitIntArray[2]){
tempRecords = baseMapper.selectInvoiceList(monthRange[0],monthRange[1]);
}
if (tempRecords != null) {
records.addAll(tempRecords);
}
//分批插入
if (null != records && !records.isEmpty()){
batchCount = records.size() / batchSize;
for (int j = 0; j < batchCount; j++) {
tempRecords = records.subList(j * batchSize, (j + 1) * batchSize);
debugService.debugInsertIssue(wxConfig,tempRecords);
}
}
}
log.info("微信智能表格发票数据插入完成");
log.info("微信智能表格合同数据插入开始...");
//开始处理合同信息,先获取合同数,然后分批次插入数据,每批次1000条
int contractCount = baseMapper.selectContractListCount();
batchCount = contractCount / batchSize;
if (contractCount % batchSize != 0) {
batchCount++;
batchSize = contractCount / batchCount;
for (int i = 0; i < batchCount; i++) {
tempRecords = baseMapper.selectContractList(i * batchSize, (i + 1) * batchSize);
if (tempRecords != null) {
debugService.debugInsertIssue(wxConfig,tempRecords);
}
}
}
log.info("微信智能表格合同数据插入完成");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ Copyright (c) 2018-2025, lengleng All rights reserved.
~
~ Redistribution and use in source and binary forms, with or without
~ modification, are permitted provided that the following conditions are met:
~
~ Redistributions of source code must retain the above copyright notice,
~ this list of conditions and the following disclaimer.
~ Redistributions in binary form must reproduce the above copyright
~ notice, this list of conditions and the following disclaimer in the
~ documentation and/or other materials provided with the distribution.
~ Neither the name of the yifu4cloud.com developer nor the names of its
~ contributors may be used to endorse or promote products derived from
~ this software without specific prior written permission.
~ Author: lengleng (wangiegie@gmail.com)
~
-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yifu.cloud.plus.v1.ekp.mapper.QwExcelApiMapper">
<select id="selectInvoiceList" resultType="java.util.Map">
SELECT
a.fd_3afa7c19036b66 AS "发票号",
a.fd_3b05ae02ff41ae AS "合同号",
a.fd_3b05ade863b120 AS "开票金额",
date_format(a.fd_3afa7c1b153ff8, '%Y-%m-%d') AS "开票时间",
date_format(a.fd_3afa7c1b153ff8, '%Y-%m') AS "开票月份",
a.fd_3afac373e38ec4 AS "购买名称",
a.fd_3b0f037ecc0ed0 AS "发票状态",
a.fd_3b1bb0ccc14760 AS "红冲状态",
concat(
a.fd_3afa7c19036b66,
'&amp;',
ifnull(a.fd_3afac373e38ec4, ''),
'&amp;',
ifnull(date_format(a.fd_3afa7c1b153ff8, '%Y-%m'), '')
) AS "发票号&amp;购买方名称&amp;开票月份组合"
FROM ekp_bacdf3a32d242279ceb6 a
LEFT JOIN modeling_simple_main b ON a.fd_id = b.fd_id
<where>
<!-- 基础时间条件
b.doc_create_time > (curdate() - INTERVAL 15 MONTH)
AND b.doc_create_time < (curdate() - INTERVAL 12 MONTH)
-->
<!-- 动态条件 -->
1 = 1
<if test="startDate != null">
AND b.doc_create_time <![CDATA[ >= ]]> #{startDate}
</if>
<if test="endDate != null">
AND b.doc_create_time <![CDATA[ <= ]]> #{endDate}
</if>
</where>
ORDER BY a.fd_3afa7c1b153ff8 DESC
</select>
<!-- 基础查询:返回合同信息列表 -->
<select id="selectContractList" resultType="java.util.Map">
SELECT
a.fd_3ade33763baa0e AS "合同号",
a.fd_3ade334bac0016 AS "合同名称",
a.fd_3ade3353d31f6c AS "客户名称",
a.fd_3aeae8ad0c9e62_text AS "客户编码",
a.fd_division AS "事业部",
a.fd_new_line AS "事业部条线",
b.fd_name AS "业务收入归属部门",
a.fd_3b107c2e2546a6 AS "合同状态"
FROM
ekp_0103c453b2848c3bb31c a
LEFT JOIN sys_org_element b ON a.fd_3b1141597b4894 = b.fd_id
<where>
<if test="limitStart != null and limitEnd != null">
limit #{limitStart},#{limitEnd}
</if>
</where>
ORDER BY a.fd_3ade33763baa0e DESC
</select>
<select id="selectContractListCount" resultType="java.lang.Integer">
SELECT
count(1)
FROM
ekp_0103c453b2848c3bb31c a
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment