Kaynağa Gözat

feat:数据缺失计算,周频日期不一致问题修复

chenjianhua 12 saat önce
ebeveyn
işleme
a95934803c

+ 7 - 7
service-base/src/main/java/com/simuwang/base/common/util/ExcelUtil.java

@@ -15,7 +15,7 @@ import org.apache.pdfbox.Loader;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.poi.hssf.usermodel.*;
 import org.apache.poi.ss.usermodel.*;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.apache.poi.xssf.usermodel.*;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
@@ -433,19 +433,19 @@ public class ExcelUtil {
         return data;
     }
 
-    public static HSSFWorkbook getHSSFWorkbook(String sheetName, List<String> title, Map<String, List<List<String>>> valueMap, HSSFWorkbook wb) {
+    public static XSSFWorkbook getHSSFWorkbook(String sheetName, List<String> title, Map<String, List<List<String>>> valueMap, XSSFWorkbook wb) {
 
         // 第一步,创建一个HSSFWorkbook,对应一个Excel文件
         if (wb == null) {
-            wb = new HSSFWorkbook();
+            wb = new XSSFWorkbook();
         }
         try {
             // 第二步,在workbook中添加一个sheet,对应Excel文件中的sheet
-            HSSFSheet sheet = wb.createSheet(sheetName);
+            XSSFSheet sheet = wb.createSheet(sheetName);
             // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制
-            HSSFRow row = sheet.createRow(0);
+            XSSFRow row = sheet.createRow(0);
             // 第四步,创建单元格,并设置值表头 设置表头居中
-            HSSFCellStyle style = wb.createCellStyle();
+            XSSFCellStyle style = wb.createCellStyle();
             style.setAlignment(HorizontalAlignment.LEFT);
             style.setWrapText(true);
             sheet.setColumnWidth(0, 10000);
@@ -455,7 +455,7 @@ public class ExcelUtil {
             sheet.setColumnWidth(4, 8000);
             sheet.setColumnWidth(5, 5000);
             //声明列对象
-            HSSFCell cell = null;
+            XSSFCell cell = null;
             //创建标题
             for (int i = 0; i < title.size(); i++) {
                 cell = row.createCell(i);

+ 1 - 1
service-base/src/main/resources/mapper/DeletionInfoMapper.xml

@@ -221,7 +221,7 @@
             from PPW_EMAIL.deletion_info d
             join PPW_EMAIL.pvn_fund_info info on d.fund_id=info.fund_id
             join PPW_EMAIL.pvn_company_info c on c.company_id=info.trust_id
-            where d.isvalid=1 and info.isvalid=1 and c.isvalid=1 and d.remark is null and d.is_send=0
+            where d.isvalid=1 and info.isvalid=1 and c.isvalid=1 and d.remark is null
             and d.fund_id in
             <foreach collection="fundIdList" index="index" item="fundId" separator="," open="(" close=")">
                 #{fundId}

+ 12 - 5
service-deploy/src/test/java/com/simuwang/ApplicationTest.java

@@ -11,7 +11,10 @@
 //import org.springframework.beans.factory.annotation.Autowired;
 //import org.springframework.boot.test.context.SpringBootTest;
 //
+//import java.time.LocalDate;
+//import java.time.temporal.WeekFields;
 //import java.util.ArrayList;
+//import java.util.Calendar;
 //import java.util.Date;
 //
 //@SpringBootTest(classes = Application.class)
@@ -35,11 +38,15 @@
 //
 //        Date startDate = DateUtil.parse("2024-10-10 15:00:00", DateConst.YYYY_MM_DD_HH_MM_SS);
 //        Date endDate = DateUtil.parse("2024-10-10 16:40:00", DateConst.YYYY_MM_DD_HH_MM_SS);
-//        try {
-//            emailParseService.parseEmail(emailInfoDTO, startDate, endDate);
-//        } catch (Exception e) {
-//            throw new RuntimeException(e);
-//        }
+//        // 获取当前时间的Calendar实例
+//        Calendar calendar = Calendar.getInstance();
+//        // 获取当前日期是一年中的第几周
+//        calendar.setTime(DateUtils.parse("2023-01-01", DateConst.YYYY_MM_DD));
+//        calendar.setMinimalDaysInFirstWeek(4);
+//        calendar.setFirstDayOfWeek(Calendar.MONDAY);
+//        int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR);
+//        int year = calendar.get(Calendar.YEAR);
+//        System.out.println(year+""+weekOfYear);
 //    }
 //
 //    @Test

+ 3 - 2
service-manage/src/main/java/com/simuwang/manage/api/deletion/DeletionController.java

@@ -17,6 +17,7 @@ import com.smppw.common.pojo.enums.status.ResultCode;
 import jakarta.servlet.ServletOutputStream;
 import jakarta.servlet.http.HttpServletResponse;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -131,11 +132,11 @@ public class DeletionController {
             dataList.add(data);
         }
         values.put(sheetName,dataList);
-        HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook(sheetName,head,values,null);
+        XSSFWorkbook wb = ExcelUtil.getHSSFWorkbook(sheetName,head,values,null);
         try {
             response.setContentType("application/x-xls");
             response.setCharacterEncoding("utf-8");
-            response.addHeader("Content-Disposition", "attachment;filename=" + EncodeUtil.encodeUTF8("缺失明细.xls"));
+            response.addHeader("Content-Disposition", "attachment;filename=" + EncodeUtil.encodeUTF8("缺失明细.xlsx"));
             ServletOutputStream outputStream = response.getOutputStream();
             wb.write(outputStream);
             outputStream.flush();

+ 5 - 3
service-manage/src/main/java/com/simuwang/manage/service/impl/CompanyEmailConfigServiceImpl.java

@@ -27,6 +27,7 @@ import jakarta.mail.Message;
 import jakarta.mail.Store;
 import jakarta.mail.internet.MimeMessage;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -35,6 +36,7 @@ import org.springframework.mail.javamail.JavaMailSender;
 import org.springframework.stereotype.Service;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -232,8 +234,8 @@ public class CompanyEmailConfigServiceImpl implements CompanyEmailConfigService
             dataList.add(data);
         }
         values.put(sheetName,dataList);
-        HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook(sheetName,head,values,null);
-        File file = new File(path+"/"+DateUtils.format(new Date(),DateUtils.YYYYMMDDHHMMSS)+"基金缺失明细.xls");
+        XSSFWorkbook wb = ExcelUtil.getHSSFWorkbook(sheetName,head,values,null);
+        File file = new File(path+"/"+DateUtils.format(new Date(),DateUtils.YYYYMMDDHHMMSS)+"基金缺失明细.xlsx");
         if(!file.exists()){
             try {
                 file.createNewFile();
@@ -242,7 +244,7 @@ public class CompanyEmailConfigServiceImpl implements CompanyEmailConfigService
             }
         }
         try {
-            wb.write(file);
+            wb.write(new FileOutputStream(file));
             wb.close();
         } catch (IOException e) {
             throw new RuntimeException(e);

+ 18 - 11
service-manage/src/main/java/com/simuwang/manage/service/impl/DeletionServiceImpl.java

@@ -213,14 +213,6 @@ public class DeletionServiceImpl implements DeletionService {
         return deletionInfoMapper.getFundDeletionTypeMapList();
     }
 
-    public static Integer getWeekOfYear(String priceDate) {
-        int year = Integer.parseInt(priceDate.substring(0, 4));
-        int week = DateUtil.weekOfYear(DateUtils.parse(priceDate, DateUtils.YYYY_MM_DD));
-        if (week < 10) {
-            return Integer.valueOf(year + "0" + week);
-        }
-        return Integer.valueOf(year + "" + week);
-    }
 
     private void distributionDeletion(String fundId, List<NavDO> navDOList) {
         if(navDOList.size() < 1){
@@ -310,8 +302,13 @@ public class DeletionServiceImpl implements DeletionService {
             Map<String,List<AssetDO>> navListMap = assetDOList.stream().collect(Collectors.groupingBy(e -> DateUtils.format(e.getPriceDate(),DateUtils.YYYY_MM_DD)));
             TreeMap<Integer,List<AssetDO>> weekNavListMap = new TreeMap<>();
             //按周数整合
+            Map<String,Integer> weekOfYearMap = new HashMap<>();
+            tradeDateDOList.forEach(tradeDateDO -> {weekOfYearMap.put(DateUtils.format(tradeDateDO.getTradeDate(), DateUtils.YYYY_MM_DD),tradeDateDO.getYearWeek());});
             for(String priceDate : navListMap.keySet()){
-                Integer weekOfYear = getWeekOfYear(priceDate);
+                Integer weekOfYear = weekOfYearMap.get(priceDate);
+                if(weekOfYear == null){
+                    continue;
+                }
                 if(weekNavListMap.containsKey(weekOfYear)){
                     List<AssetDO> assetDOS = weekNavListMap.get(weekOfYear);
                     assetDOS.addAll(navListMap.get(priceDate));
@@ -492,8 +489,13 @@ public class DeletionServiceImpl implements DeletionService {
             Map<String,List<NavDO>> navListMap = navDOList.stream().collect(Collectors.groupingBy(e -> DateUtils.format(e.getPriceDate(),DateUtils.YYYY_MM_DD)));
             TreeMap<Integer,List<NavDO>> weekNavListMap = new TreeMap<>();
             //按周数整合
+            Map<String,Integer> weekOfYearMap = new HashMap<>();
+            tradeDateDOList.forEach(tradeDateDO -> {weekOfYearMap.put(DateUtils.format(tradeDateDO.getTradeDate(), DateUtils.YYYY_MM_DD),tradeDateDO.getYearWeek());});
             for(String priceDate : navListMap.keySet()){
-                Integer weekOfYear = getWeekOfYear(priceDate);
+                Integer weekOfYear = weekOfYearMap.get(priceDate);
+                if(weekOfYear == null){
+                    continue;
+                }
                 if(weekNavListMap.containsKey(weekOfYear)){
                     List<NavDO> navDOS = weekNavListMap.get(weekOfYear);
                     navDOS.addAll(navListMap.get(priceDate));
@@ -673,8 +675,13 @@ public class DeletionServiceImpl implements DeletionService {
             Map<String,List<FundPositionDetailDO>> valuationListMap = fundPositionDetailDOList.stream().collect(Collectors.groupingBy(e -> DateUtils.format(e.getValuationDate(),DateUtils.YYYY_MM_DD)));
             TreeMap<Integer,List<FundPositionDetailDO>> weekNavListMap = new TreeMap<>();
             //按周数整合
+            Map<String,Integer> weekOfYearMap = new HashMap<>();
+            tradeDateDOList.forEach(tradeDateDO -> {weekOfYearMap.put(DateUtils.format(tradeDateDO.getTradeDate(), DateUtils.YYYY_MM_DD),tradeDateDO.getYearWeek());});
             for(String priceDate : valuationListMap.keySet()){
-                Integer weekOfYear = getWeekOfYear(priceDate);
+                Integer weekOfYear = weekOfYearMap.get(priceDate);
+                if(weekOfYear == null){
+                    continue;
+                }
                 if(weekNavListMap.containsKey(weekOfYear)){
                     List<FundPositionDetailDO> valuationDOS = weekNavListMap.get(weekOfYear);
                     valuationDOS.addAll(valuationListMap.get(priceDate));