浏览代码

feat: 净值规模导入功能开发(含新增编辑)

chenjianhua 7 月之前
父节点
当前提交
5d533e22a4
共有 18 个文件被更改,包括 500 次插入163 次删除
  1. 2 0
      service-base/src/main/java/com/simuwang/base/common/conts/ExcelConst.java
  2. 2 0
      service-base/src/main/java/com/simuwang/base/mapper/AssetMapper.java
  3. 2 0
      service-base/src/main/java/com/simuwang/base/mapper/NavMapper.java
  4. 41 0
      service-base/src/main/java/com/simuwang/base/pojo/dto/NavAssetExcelData.java
  5. 3 1
      service-base/src/main/java/com/simuwang/base/pojo/vo/ExcelFailDataVO.java
  6. 38 0
      service-base/src/main/java/com/simuwang/base/pojo/vo/ExcelNavAssetFailDataVO.java
  7. 38 0
      service-base/src/main/java/com/simuwang/base/pojo/vo/ExcelNavAssetSuccessDataVO.java
  8. 19 0
      service-base/src/main/java/com/simuwang/base/pojo/vo/FundNavAssetDelListVO.java
  9. 21 0
      service-base/src/main/java/com/simuwang/base/pojo/vo/FundNavAssetDelVO.java
  10. 3 0
      service-base/src/main/resources/mapper/AssetMapper.xml
  11. 3 0
      service-base/src/main/resources/mapper/NavMapper.xml
  12. 0 42
      service-manage/src/main/java/com/simuwang/manage/api/email/NavController.java
  13. 46 4
      service-manage/src/main/java/com/simuwang/manage/api/navAsset/FundNavAssetController.java
  14. 13 0
      service-manage/src/main/java/com/simuwang/manage/service/FundNavAssetService.java
  15. 0 4
      service-manage/src/main/java/com/simuwang/manage/service/ParseEmailDetailService.java
  16. 55 55
      service-manage/src/main/java/com/simuwang/manage/service/impl/DistributionServiceImpl.java
  17. 214 2
      service-manage/src/main/java/com/simuwang/manage/service/impl/FundNavAssetServiceImpl.java
  18. 0 55
      service-manage/src/main/java/com/simuwang/manage/service/impl/ParseEmailDetailServiceImpl.java

+ 2 - 0
service-base/src/main/java/com/simuwang/base/common/conts/ExcelConst.java

@@ -16,4 +16,6 @@ public class ExcelConst {
     public final static String DIVIDENDS_SPLIT_FAIL= "份额分红不能为0";
     public final static String NOT_MAPPING_FUND= "未匹配基金";
     public final static String SAVE_FAIL= "数据入库失败";
+    public static final String ERROR_NAV = "单位净值缺失或者有误";
+    public static final String ERROR_NAV_WITHDRAWAL = "累计净值缺失或者有误";
 }

+ 2 - 0
service-base/src/main/java/com/simuwang/base/mapper/AssetMapper.java

@@ -17,4 +17,6 @@ public interface AssetMapper {
     List<String> queryFundNavByDate(@Param("fundId") String fundId, @Param("priceDateList") List<String> priceDateList);
 
     AssetDO queryFundAsset(AssetDO fundAssetVO);
+
+    void deleteAsset(@Param("fundId") String fundId, @Param("priceDate") String priceDate);
 }

+ 2 - 0
service-base/src/main/java/com/simuwang/base/mapper/NavMapper.java

@@ -20,4 +20,6 @@ public interface NavMapper {
     void saveNav( NavDO navDO);
 
     void updateNav(NavDO navDO);
+
+    void deleteNav(@Param("fundId")String fundId, @Param("priceDate")String priceDate);
 }

+ 41 - 0
service-base/src/main/java/com/simuwang/base/pojo/dto/NavAssetExcelData.java

@@ -0,0 +1,41 @@
+package com.simuwang.base.pojo.dto;
+
+import lombok.Data;
+
+/**
+ * FileName: DistributionExcelData
+ * Author:   chenjianhua
+ * Date:     2024/9/16 10:57
+ * Description: ${DESCRIPTION}
+ */
+@Data
+public class NavAssetExcelData {
+    /**
+     * 基金ID
+     */
+    private String fundId;
+    /**
+     * 基金名称
+     */
+    private String fundName;
+    /**
+     * 净值日期
+     */
+    private String priceDate;
+    /**
+     * 单位净值
+     */
+    private String nav;
+    /**
+     * 累计净值
+     */
+    private String cumulativeNavWithdrawal;
+    /**
+     * 资产规模
+     */
+    private String assetNet;
+    /**
+     * 资产净值
+     */
+    private String assetShare;
+}

+ 3 - 1
service-base/src/main/java/com/simuwang/base/pojo/vo/ExcelFailDataVO.java

@@ -31,6 +31,8 @@ public class ExcelFailDataVO {
      * 单位分红/拆分比例
      */
     private String distribution;
-
+    /**
+     * 失败原因
+     */
     private String failReason;
 }

+ 38 - 0
service-base/src/main/java/com/simuwang/base/pojo/vo/ExcelNavAssetFailDataVO.java

@@ -0,0 +1,38 @@
+package com.simuwang.base.pojo.vo;
+
+import lombok.Data;
+
+/**
+ * FileName: ExcelSuccessDataVO
+ * Author:   chenjianhua
+ * Date:     2024/9/16 12:41
+ * Description: ${DESCRIPTION}
+ */
+@Data
+public class ExcelNavAssetFailDataVO {
+
+    /**
+     * 行号
+     */
+    private Integer rowNum;
+    /**
+     * 基金名称
+     */
+    private String fundName;
+    /**
+     * 净值日期
+     */
+    private String priceDate;
+    /**
+     * 分红类型
+     */
+    private String nav;
+    /**
+     * 单位分红/拆分比例
+     */
+    private String cumulativeNavWithdrawal;
+    /**
+     * 失败原因
+     */
+    private String failReason;
+}

+ 38 - 0
service-base/src/main/java/com/simuwang/base/pojo/vo/ExcelNavAssetSuccessDataVO.java

@@ -0,0 +1,38 @@
+package com.simuwang.base.pojo.vo;
+
+import lombok.Data;
+
+/**
+ * FileName: ExcelSuccessDataVO
+ * Author:   chenjianhua
+ * Date:     2024/9/16 12:41
+ * Description: ${DESCRIPTION}
+ */
+@Data
+public class ExcelNavAssetSuccessDataVO {
+
+    /**
+     * 基金名称
+     */
+    private String fundName;
+    /**
+     * 净值日期
+     */
+    private String priceDate;
+    /**
+     * 分红类型
+     */
+    private String nav;
+    /**
+     * 单位分红/拆分比例
+     */
+    private String cumulativeNavWithdrawal;
+    /**
+     * 资产规模
+     */
+    private String assetShare;
+    /**
+     * 资产净值
+     */
+    private String assetNet;
+}

+ 19 - 0
service-base/src/main/java/com/simuwang/base/pojo/vo/FundNavAssetDelListVO.java

@@ -0,0 +1,19 @@
+package com.simuwang.base.pojo.vo;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * FileName: FundNavAssetDelVO
+ * Author:   chenjianhua
+ * Date:     2024/9/16 14:24
+ * Description: ${DESCRIPTION}
+ */
+@Data
+public class FundNavAssetDelListVO {
+    /**
+     * 批量删除净值规模,按照基金ID和净值日期
+     */
+    private List<FundNavAssetDelVO> fundNavAssetDelVOList;
+}

+ 21 - 0
service-base/src/main/java/com/simuwang/base/pojo/vo/FundNavAssetDelVO.java

@@ -0,0 +1,21 @@
+package com.simuwang.base.pojo.vo;
+
+import lombok.Data;
+
+/**
+ * FileName: FundNavAssetDelVO
+ * Author:   chenjianhua
+ * Date:     2024/9/16 14:24
+ * Description: ${DESCRIPTION}
+ */
+@Data
+public class FundNavAssetDelVO {
+    /**
+     * 基金DI
+     */
+    private String fundId;
+    /**
+     * 净值日期
+     */
+    private String priceDate;
+}

+ 3 - 0
service-base/src/main/resources/mapper/AssetMapper.xml

@@ -37,6 +37,9 @@
             and price_date = #{itemDo.priceDate}
         </foreach>
     </insert>
+    <delete id="deleteAsset">
+        update PPW_EMAIL.asset set isvalid =0,updatetime=sysdate() where fund_id=#{fundId} and price_date=#{priceDate} and isvalid=1
+    </delete>
 
     <select id="queryFundNavByDate" resultType="java.lang.String">
         select price_date

+ 3 - 0
service-base/src/main/resources/mapper/NavMapper.xml

@@ -56,6 +56,9 @@
         where isvalid = 1
         and id=#{id}
     </update>
+    <delete id="deleteNav">
+        update PPW_EMAIL.nav set isvalid =0,updatetime=sysdate() where fund_id=#{fundId} and price_date=#{priceDate} and isvalid =1
+    </delete>
 
     <select id="queryFundNavByDate" resultType="java.lang.String">
         select price_date

+ 0 - 42
service-manage/src/main/java/com/simuwang/manage/api/email/NavController.java

@@ -1,42 +0,0 @@
-package com.simuwang.manage.api.email;
-
-import com.simuwang.base.pojo.vo.FundAssetVO;
-import com.simuwang.base.pojo.vo.FundNavVO;
-import com.smppw.common.pojo.ResultVo;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * FileName: NavController
- * Author:   chenjianhua
- * Date:     2024/9/14 13:59
- * Description: ${DESCRIPTION}
- */
-@RestController
-@RequestMapping("/v1/nav")
-public class NavController {
-
-    /**
-     * 新增基金规模
-     * @param fundAssetVO
-     * @return
-     */
-//    @PostMapping("/save-fund-asset")
-//    public ResultVo saveFundAsset(@RequestBody FundAssetVO fundAssetVO){
-//        parseEmailDetailService.saveFundAsset(fundAssetVO);
-//        return ResultVo.ok(true);
-//    }
-//
-//    /**
-//     * 新增基金规模
-//     * @param fundNavVO
-//     * @return
-//     */
-//    @PostMapping("/save-fund-nav")
-//    public ResultVo saveFundNav(@RequestBody FundNavVO fundNavVO){
-//        parseEmailDetailService.saveFundNav(fundNavVO);
-//        return ResultVo.ok(true);
-//    }
-}

+ 46 - 4
service-manage/src/main/java/com/simuwang/manage/api/navAsset/FundNavAssetController.java

@@ -3,12 +3,14 @@ package com.simuwang.manage.api.navAsset;
 import com.simuwang.base.common.support.MybatisPage;
 import com.simuwang.base.pojo.dto.query.DistributionPageQuery;
 import com.simuwang.base.pojo.dto.query.FundNavAssetPageQuery;
-import com.simuwang.base.pojo.vo.DistributionTablePageVO;
-import com.simuwang.base.pojo.vo.FundNavAssetVO;
+import com.simuwang.base.pojo.vo.*;
 import com.simuwang.manage.service.FundNavAssetService;
+import com.smppw.common.pojo.ResultVo;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * 净值规模管理
@@ -34,4 +36,44 @@ public class FundNavAssetController {
         return result;
     }
 
+    /**
+     * 新增基金规模
+     * @param fundAssetVO
+     * @return
+     */
+    @PostMapping("/save-fund-asset")
+    public ResultVo saveFundAsset(@RequestBody FundAssetVO fundAssetVO){
+        fundNavAssetService.saveFundAsset(fundAssetVO);
+        return ResultVo.ok(true);
+    }
+
+    /**
+     * 新增基金规模
+     * @param fundNavVO
+     * @return
+     */
+    @PostMapping("/save-fund-nav")
+    public ResultVo saveFundNav(@RequestBody FundNavVO fundNavVO){
+        fundNavAssetService.saveFundNav(fundNavVO);
+        return ResultVo.ok(true);
+    }
+
+    @RequestMapping("/delete-fund-nav-asset")
+    public ResultVo deleteFundNavAsset(@RequestBody FundNavAssetDelListVO fundNavAssetDelListVO){
+        fundNavAssetService.deleteFundNavAsset(fundNavAssetDelListVO);
+        return ResultVo.ok(true);
+    }
+
+    /**
+     * 上传分红信息
+     * @param file
+     * @param response
+     * @param request
+     * @return
+     */
+    @RequestMapping("upload-nav-asset")
+    public ResultVo uploadNavAsset(@RequestParam(value = "file",required = false) MultipartFile file, HttpServletResponse response, HttpServletRequest request){
+        ResultVo vo = fundNavAssetService.uploadNavAsset(file);
+        return vo;
+    }
 }

+ 13 - 0
service-manage/src/main/java/com/simuwang/manage/service/FundNavAssetService.java

@@ -2,7 +2,12 @@ package com.simuwang.manage.service;
 
 import com.simuwang.base.common.support.MybatisPage;
 import com.simuwang.base.pojo.dto.query.FundNavAssetPageQuery;
+import com.simuwang.base.pojo.vo.FundAssetVO;
+import com.simuwang.base.pojo.vo.FundNavAssetDelListVO;
 import com.simuwang.base.pojo.vo.FundNavAssetVO;
+import com.simuwang.base.pojo.vo.FundNavVO;
+import com.smppw.common.pojo.ResultVo;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * FileName: FundNavAssetService
@@ -12,4 +17,12 @@ import com.simuwang.base.pojo.vo.FundNavAssetVO;
  */
 public interface FundNavAssetService {
     MybatisPage<FundNavAssetVO> searchNavAssetList(FundNavAssetPageQuery fundNavAssetPageQuery);
+
+    void saveFundAsset(FundAssetVO fundAssetVO);
+
+    void saveFundNav(FundNavVO fundNavVO);
+
+    void deleteFundNavAsset(FundNavAssetDelListVO fundNavAssetDelListVO);
+
+    ResultVo uploadNavAsset(MultipartFile file);
 }

+ 0 - 4
service-manage/src/main/java/com/simuwang/manage/service/ParseEmailDetailService.java

@@ -17,8 +17,4 @@ public interface ParseEmailDetailService {
     MybatisPage<EmailFundNavVO> searchNavDetail(ParseDetailPageQuery parseDetailPageQuery);
 
     MybatisPage<EmailFundAssetVO> searchAssetDetail(ParseDetailPageQuery parseDetailPageQuery);
-
-    void saveFundAsset(FundAssetVO fundAssetVO);
-
-    void saveFundNav(FundNavVO fundNavVO);
 }

+ 55 - 55
service-manage/src/main/java/com/simuwang/manage/service/impl/DistributionServiceImpl.java

@@ -141,68 +141,68 @@ public class DistributionServiceImpl implements DistributionService {
         List<ExcelFailDataVO> excelFailDataVOList = new ArrayList<>();
         for(int dataIdx=1;dataIdx<list.size(); dataIdx++){
             DistributionExcelData excelData = list.get(dataIdx);
-            if((StringUtil.isEmpty(excelData.getFundName()) && StringUtil.isEmpty(excelData.getFundId()))
-            || StringUtil.isEmpty(excelData.getPriceDate()) || StringUtil.isEmpty(excelData.getNav())
-            || StringUtil.isEmpty(excelData.getDistributeType()) || StringUtil.isEmpty(excelData.getDistribution())
-            || StringUtil.isEmpty(excelData.getCumulativeNavWithdrawal())){
-                ExcelFailDataVO failDataVO = new ExcelFailDataVO();
-                failDataVO.setFailReason(ExcelConst.REQUIRE_FIELD);
-                failDataVO.setRowNum(dataIdx+startRow);
-                failDataVO.setDistribution(excelData.getDistribution());
-                failDataVO.setFundName(excelData.getFundName());
-                failDataVO.setPriceDate(excelData.getPriceDate());
-                failDataVO.setDistributeType(excelData.getDistributeType());
-                excelFailDataVOList.add(failDataVO);
-                continue;
-            }
-            if(excelData.getDistributeType().trim().equals(ExcelConst.CASH_DIVIDENDS)){
-                if(Double.valueOf(excelData.getDistribution()) < 0f){
-                    ExcelFailDataVO failDataVO = toExcelFailDataVO(excelData,ExcelConst.CASH_DIVIDENDS_FAIL,dataIdx+startRow);
+            try{
+                if((StringUtil.isEmpty(excelData.getFundName()) && StringUtil.isEmpty(excelData.getFundId()))
+                        || StringUtil.isEmpty(excelData.getPriceDate()) || StringUtil.isEmpty(excelData.getNav())
+                        || StringUtil.isEmpty(excelData.getDistributeType()) || StringUtil.isEmpty(excelData.getDistribution())
+                        || StringUtil.isEmpty(excelData.getCumulativeNavWithdrawal())){
+                    ExcelFailDataVO failDataVO = toExcelFailDataVO(excelData,ExcelConst.REQUIRE_FIELD,dataIdx+startRow);
                     excelFailDataVOList.add(failDataVO);
                     continue;
                 }
-            }else{
-                if(Double.valueOf(excelData.getDistribution()) == 0f){
-                    ExcelFailDataVO failDataVO = toExcelFailDataVO(excelData,ExcelConst.DIVIDENDS_SPLIT_FAIL,dataIdx+startRow);
-                    excelFailDataVOList.add(failDataVO);
-                    continue;
+                if(excelData.getDistributeType().trim().equals(ExcelConst.CASH_DIVIDENDS)){
+                    if(Double.valueOf(excelData.getDistribution()) < 0f){
+                        ExcelFailDataVO failDataVO = toExcelFailDataVO(excelData,ExcelConst.CASH_DIVIDENDS_FAIL,dataIdx+startRow);
+                        excelFailDataVOList.add(failDataVO);
+                        continue;
+                    }
+                }else{
+                    if(Double.valueOf(excelData.getDistribution()) == 0f){
+                        ExcelFailDataVO failDataVO = toExcelFailDataVO(excelData,ExcelConst.DIVIDENDS_SPLIT_FAIL,dataIdx+startRow);
+                        excelFailDataVOList.add(failDataVO);
+                        continue;
+                    }
                 }
-            }
-            if(StringUtil.isNotEmpty(excelData.getFundId())){
-                String fundName = fundInfoMapper.getFundNameByFundId(excelData.getFundId());
-                if(StringUtil.isEmpty(fundName)){
-                    ExcelFailDataVO failDataVO = toExcelFailDataVO(excelData,ExcelConst.NOT_MAPPING_FUND,dataIdx+startRow);
-                    excelFailDataVOList.add(failDataVO);
-                    continue;
+                if(StringUtil.isNotEmpty(excelData.getFundId())){
+                    String fundName = fundInfoMapper.getFundNameByFundId(excelData.getFundId());
+                    if(StringUtil.isEmpty(fundName)){
+                        ExcelFailDataVO failDataVO = toExcelFailDataVO(excelData,ExcelConst.NOT_MAPPING_FUND,dataIdx+startRow);
+                        excelFailDataVOList.add(failDataVO);
+                        continue;
+                    }
+                }else{
+                    String fundId = fundInfoMapper.queryFundIdByName(excelData.getFundName());
+                    if(StringUtil.isEmpty(fundId)){
+                        ExcelFailDataVO failDataVO = toExcelFailDataVO(excelData,ExcelConst.NOT_MAPPING_FUND,dataIdx+startRow);
+                        excelFailDataVOList.add(failDataVO);
+                        continue;
+                    }else{
+                        excelData.setFundId(fundId);
+                    }
                 }
-            }else{
-                String fundId = fundInfoMapper.queryFundIdByName(excelData.getFundName());
-                if(StringUtil.isEmpty(fundId)){
-                    ExcelFailDataVO failDataVO = toExcelFailDataVO(excelData,ExcelConst.NOT_MAPPING_FUND,dataIdx+startRow);
-                    excelFailDataVOList.add(failDataVO);
-                    continue;
+                //开始处理成功数据
+                DistributionVO distributionVO = new DistributionVO();
+                distributionVO.setFundId(excelData.getFundId());
+                distributionVO.setDistributeDate(excelData.getPriceDate());
+                distributionVO.setDistributeType(DistributeType.getDistributeTypeByInfo(excelData.getDistributeType()).getCode());
+                distributionVO.setDistribution(BigDecimal.valueOf(Double.valueOf(excelData.getDistribution())));
+                distributionVO.setNav(BigDecimal.valueOf(Double.valueOf(excelData.getNav())));
+                distributionVO.setCumulativeNavWithdrawal(BigDecimal.valueOf(Double.valueOf(excelData.getCumulativeNavWithdrawal())));
+                ResultVo vo = saveDistribution(distributionVO);
+                if((boolean)vo.getData() == true){
+                    ExcelSuccessDataVO successDataVO = new ExcelSuccessDataVO();
+                    successDataVO.setDistribution(excelData.getDistribution());
+                    successDataVO.setFundName(excelData.getFundName());
+                    successDataVO.setPriceDate(excelData.getPriceDate());
+                    successDataVO.setDistributeType(excelData.getDistributeType());
+                    successDataVOList.add(successDataVO);
                 }else{
-                    excelData.setFundId(fundId);
+                    ExcelFailDataVO failDataVO = toExcelFailDataVO(excelData,vo.getMsg(),dataIdx+startRow);
+                    excelFailDataVOList.add(failDataVO);
                 }
-            }
-            //开始处理成功数据
-            DistributionVO distributionVO = new DistributionVO();
-            distributionVO.setFundId(excelData.getFundId());
-            distributionVO.setDistributeDate(excelData.getPriceDate());
-            distributionVO.setDistributeType(DistributeType.getDistributeTypeByInfo(excelData.getDistributeType()).getCode());
-            distributionVO.setDistribution(BigDecimal.valueOf(Double.valueOf(excelData.getDistribution())));
-            distributionVO.setNav(BigDecimal.valueOf(Double.valueOf(excelData.getNav())));
-            distributionVO.setCumulativeNavWithdrawal(BigDecimal.valueOf(Double.valueOf(excelData.getCumulativeNavWithdrawal())));
-            ResultVo vo = saveDistribution(distributionVO);
-            if((boolean)vo.getData() == true){
-                ExcelSuccessDataVO successDataVO = new ExcelSuccessDataVO();
-                successDataVO.setDistribution(excelData.getDistribution());
-                successDataVO.setFundName(excelData.getFundName());
-                successDataVO.setPriceDate(excelData.getPriceDate());
-                successDataVO.setDistributeType(excelData.getDistributeType());
-                successDataVOList.add(successDataVO);
-            }else{
-                ExcelFailDataVO failDataVO = toExcelFailDataVO(excelData,vo.getMsg(),dataIdx+startRow);
+            }catch (Exception e){
+                logger.error(e.getMessage(),e);
+                ExcelFailDataVO failDataVO = toExcelFailDataVO(excelData,e.getMessage(),dataIdx+startRow);
                 excelFailDataVOList.add(failDataVO);
             }
         }

+ 214 - 2
service-manage/src/main/java/com/simuwang/manage/service/impl/FundNavAssetServiceImpl.java

@@ -1,16 +1,39 @@
 package com.simuwang.manage.service.impl;
 
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.read.listener.PageReadListener;
+import com.alibaba.excel.support.ExcelTypeEnum;
+import com.simuwang.base.common.conts.ExcelConst;
+import com.simuwang.base.common.enums.DistributeType;
 import com.simuwang.base.common.support.MybatisPage;
+import com.simuwang.base.common.util.DateUtils;
+import com.simuwang.base.common.util.StringUtil;
+import com.simuwang.base.mapper.AssetMapper;
+import com.simuwang.base.mapper.FundInfoMapper;
 import com.simuwang.base.mapper.FundNavAssetMapper;
-import com.simuwang.base.pojo.dos.CompanyEmailSendHistoryDO;
+import com.simuwang.base.mapper.NavMapper;
+import com.simuwang.base.pojo.dos.AssetDO;
 import com.simuwang.base.pojo.dos.FundNavAssetDO;
+import com.simuwang.base.pojo.dos.NavDO;
+import com.simuwang.base.pojo.dto.DistributionExcelData;
+import com.simuwang.base.pojo.dto.NavAssetExcelData;
 import com.simuwang.base.pojo.dto.query.FundNavAssetPageQuery;
-import com.simuwang.base.pojo.vo.FundNavAssetVO;
+import com.simuwang.base.pojo.vo.*;
 import com.simuwang.manage.service.FundNavAssetService;
+import com.smppw.common.pojo.ResultVo;
+import com.smppw.common.pojo.enums.status.ResultCode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.File;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -23,6 +46,16 @@ import java.util.stream.Collectors;
 public class FundNavAssetServiceImpl implements FundNavAssetService {
     @Autowired
     private FundNavAssetMapper fundNavAssetMapper;
+
+    @Autowired
+    private AssetMapper assetMapper;
+
+    @Autowired
+    private NavMapper navMapper;
+
+    @Autowired
+    private FundInfoMapper fundInfoMapper;
+    private static final Logger logger = LoggerFactory.getLogger(FundNavAssetServiceImpl.class);
     @Override
     public MybatisPage<FundNavAssetVO> searchNavAssetList(FundNavAssetPageQuery fundNavAssetPageQuery) {
         List<FundNavAssetDO> fundNavAssetDOList = fundNavAssetMapper.searchNavAssetList(fundNavAssetPageQuery);
@@ -30,4 +63,183 @@ public class FundNavAssetServiceImpl implements FundNavAssetService {
         long total = fundNavAssetMapper.countNavAssetList(fundNavAssetPageQuery);
         return MybatisPage.of(total,fundNavAssetVOList);
     }
+
+
+    @Override
+    public void saveFundAsset(FundAssetVO fundAssetVO) {
+        List<AssetDO> assetDOList = new ArrayList<>();
+        AssetDO assetDO = new AssetDO();
+        assetDO.setAssetNet(fundAssetVO.getAssetNet());
+        assetDO.setAssetShare(fundAssetVO.getAssetShare());
+        assetDO.setPriceDate(DateUtils.parse(fundAssetVO.getPriceDate(),DateUtils.YYYY_MM_DD));
+        assetDO.setFundId(fundAssetVO.getFundId());
+        assetDO.setUpdateTime(DateUtils.getNowDate());
+        assetDO.setIsvalid(1);
+        AssetDO oldAssetDO = assetMapper.queryFundAsset(assetDO);
+        if(StringUtil.isNull(oldAssetDO)){
+            assetDO.setCreateTime(DateUtils.getNowDate());
+            assetDOList.add(assetDO);
+            assetMapper.batchInsert(assetDOList);
+        }else{
+            oldAssetDO.setAssetShare(assetDO.getAssetShare());
+            oldAssetDO.setAssetNet(assetDO.getAssetNet());
+            assetDOList.add(oldAssetDO);
+            assetMapper.batchUpdate(assetDOList);
+        }
+    }
+
+    @Override
+    public void saveFundNav(FundNavVO fundNavVO) {
+        List<NavDO> navDOList = new ArrayList<>();
+        NavDO navDO = new NavDO();
+        navDO.setCumulativeNavWithdrawal(fundNavVO.getCumulativeNavWithdrawal());
+        navDO.setNav(fundNavVO.getNav());
+        navDO.setFundId(fundNavVO.getFundId());
+        navDO.setNav(fundNavVO.getNav());
+        navDO.setPriceDate(DateUtils.parse(fundNavVO.getPriceDate(),DateUtils.YYYY_MM_DD));
+        navDO.setIsvalid(1);
+        navDO.setUpdateTime(DateUtils.getNowDate());
+        NavDO oldNav = navMapper.queryFundNav(navDO);
+        if(StringUtil.isNull(oldNav)){
+            navDO.setCreateTime(DateUtils.getNowDate());
+            navDOList.add(navDO);
+            navMapper.batchInsert(navDOList);
+        }else{
+            oldNav.setUpdateTime(DateUtils.getNowDate());
+            oldNav.setCumulativeNav(navDO.getCumulativeNav());
+            oldNav.setCumulativeNavWithdrawal(navDO.getCumulativeNavWithdrawal());
+            oldNav.setNav(navDO.getNav());
+            navDOList.add(oldNav);
+            navMapper.batchUpdate(navDOList);
+        }
+    }
+
+    @Override
+    public void deleteFundNavAsset(FundNavAssetDelListVO fundNavAssetDelListVO) {
+        List<FundNavAssetDelVO> delVOList = fundNavAssetDelListVO.getFundNavAssetDelVOList();
+        for(FundNavAssetDelVO delVO : delVOList){
+            navMapper.deleteNav(delVO.getFundId(),delVO.getPriceDate());
+            assetMapper.deleteAsset(delVO.getFundId(),delVO.getPriceDate());
+        }
+    }
+
+    @Override
+    public ResultVo uploadNavAsset(MultipartFile excelFile) {
+        ResultVo vo = new ResultVo(ResultCode.SUCCESS);
+        File file = null;
+        try{
+            file = excelFile.getResource().getFile();
+            List<NavAssetExcelData> list = parseDistributionFile(file);
+            vo.setData(parseResult(list));
+        }catch (Exception e){
+            logger.error(e.getMessage(),e);
+            vo.setMsg("文件解析异常");
+            vo.setData(false);
+            return vo;
+        }
+        return vo;
+    }
+
+    private Map<String,Object> parseResult(List<NavAssetExcelData> list) {
+        Map<String,Object> result = new HashMap<>();
+        int startRow = 3;
+        List<ExcelNavAssetSuccessDataVO> successDataVOList = new ArrayList<>();
+        List<ExcelNavAssetFailDataVO> excelFailDataVOList = new ArrayList<>();
+        for(int dataIdx=1;dataIdx<list.size(); dataIdx++){
+            NavAssetExcelData excelData = list.get(dataIdx);
+            try{
+                if((StringUtil.isEmpty(excelData.getFundName()) && StringUtil.isEmpty(excelData.getFundId()))
+                        || StringUtil.isEmpty(excelData.getPriceDate())){
+                    ExcelNavAssetFailDataVO failDataVO = toExcelFailDataVO(excelData,ExcelConst.REQUIRE_FIELD,dataIdx+startRow);
+                    excelFailDataVOList.add(failDataVO);
+                    continue;
+                }
+                if(StringUtil.isNotEmpty(excelData.getFundId())){
+                    String fundName = fundInfoMapper.getFundNameByFundId(excelData.getFundId());
+                    if(StringUtil.isEmpty(fundName)){
+                        ExcelNavAssetFailDataVO failDataVO = toExcelFailDataVO(excelData,ExcelConst.NOT_MAPPING_FUND,dataIdx+startRow);
+                        excelFailDataVOList.add(failDataVO);
+                        continue;
+                    }
+                }else{
+                    String fundId = fundInfoMapper.queryFundIdByName(excelData.getFundName());
+                    if(StringUtil.isEmpty(fundId)){
+                        ExcelNavAssetFailDataVO failDataVO = toExcelFailDataVO(excelData,ExcelConst.NOT_MAPPING_FUND,dataIdx+startRow);
+                        excelFailDataVOList.add(failDataVO);
+                        continue;
+                    }else{
+                        excelData.setFundId(fundId);
+                    }
+                }
+                if(StringUtil.isEmpty(excelData.getNav()) || Double.valueOf(excelData.getNav()) < 0){
+                    ExcelNavAssetFailDataVO failDataVO = toExcelFailDataVO(excelData,ExcelConst.ERROR_NAV,dataIdx+startRow);
+                    excelFailDataVOList.add(failDataVO);
+                    continue;
+                }
+                if(StringUtil.isEmpty(excelData.getCumulativeNavWithdrawal()) || Double.valueOf(excelData.getCumulativeNavWithdrawal()) < 0){
+                    ExcelNavAssetFailDataVO failDataVO = toExcelFailDataVO(excelData,ExcelConst.ERROR_NAV_WITHDRAWAL,dataIdx+startRow);
+                    excelFailDataVOList.add(failDataVO);
+                    continue;
+                }
+                //开始处理成功数据
+                FundNavVO fundNavVO = new FundNavVO();
+                fundNavVO.setFundId(excelData.getFundId());
+                fundNavVO.setPriceDate(excelData.getPriceDate());
+                fundNavVO.setNav(BigDecimal.valueOf(Double.valueOf(excelData.getNav())));
+                fundNavVO.setCumulativeNavWithdrawal(BigDecimal.valueOf(Double.valueOf(excelData.getCumulativeNavWithdrawal())));
+                saveFundNav(fundNavVO);
+                if(StringUtil.isEmpty(excelData.getAssetNet()) && StringUtil.isEmpty(excelData.getAssetShare())){
+                    continue;
+                }
+                FundAssetVO fundAssetVO = new FundAssetVO();
+                fundAssetVO.setFundId(excelData.getFundId());
+                fundAssetVO.setPriceDate(excelData.getPriceDate());
+                fundAssetVO.setAssetNet(StringUtil.isEmpty(excelData.getAssetNet())?null:BigDecimal.valueOf(Double.valueOf(excelData.getAssetNet())));
+                fundAssetVO.setAssetShare(StringUtil.isEmpty(excelData.getAssetShare())?null:BigDecimal.valueOf(Double.valueOf(excelData.getAssetShare())));
+                saveFundAsset(fundAssetVO);
+                //处理成功结果
+                ExcelNavAssetSuccessDataVO excelNavAssetSuccessDataVO = new ExcelNavAssetSuccessDataVO();
+                excelNavAssetSuccessDataVO.setFundName(excelData.getFundName());
+                excelNavAssetSuccessDataVO.setPriceDate(excelData.getPriceDate());
+                excelNavAssetSuccessDataVO.setNav(excelData.getNav());
+                excelNavAssetSuccessDataVO.setCumulativeNavWithdrawal(excelData.getCumulativeNavWithdrawal());
+                excelNavAssetSuccessDataVO.setAssetNet(excelData.getAssetNet());
+                excelNavAssetSuccessDataVO.setAssetShare(excelData.getAssetShare());
+                successDataVOList.add(excelNavAssetSuccessDataVO);
+            }catch (Exception e){
+                logger.error(e.getMessage(),e);
+                ExcelNavAssetFailDataVO failDataVO = toExcelFailDataVO(excelData,e.getMessage(),dataIdx+startRow);
+                excelFailDataVOList.add(failDataVO);
+            }
+        }
+        result.put("success",successDataVOList);
+        result.put("fail",excelFailDataVOList);
+        return result;
+    }
+
+    private ExcelNavAssetFailDataVO toExcelFailDataVO(NavAssetExcelData excelData, String msg, int runNum) {
+        ExcelNavAssetFailDataVO failDataVO = new ExcelNavAssetFailDataVO();
+        failDataVO.setFailReason(msg);
+        failDataVO.setRowNum(runNum);
+        failDataVO.setFundName(excelData.getFundName());
+        failDataVO.setPriceDate(excelData.getPriceDate());
+        failDataVO.setNav(excelData.getNav());
+        failDataVO.setCumulativeNavWithdrawal(excelData.getCumulativeNavWithdrawal());
+        return failDataVO;
+    }
+
+    private List<NavAssetExcelData> parseDistributionFile(File file) {
+        // 创建一个 list 存储每行的数据,即 ExcelData 对象
+        List<NavAssetExcelData> list = new ArrayList<>();
+        // 直接使用 EasyExcel 的 read 方法,同时定义表头的类型,以便将列中数据映射为 ExcelData 对象
+        EasyExcel.read(file, NavAssetExcelData.class, new PageReadListener<NavAssetExcelData>(dataList -> {
+            // 并且每行数据,并将其 add 至 list 中
+            for (NavAssetExcelData excelData : dataList) {
+                if (excelData != null) {
+                    list.add(excelData);
+                }
+            }
+        })).excelType(ExcelTypeEnum.XLSX).sheet().doRead();
+        return list;
+    }
 }

+ 0 - 55
service-manage/src/main/java/com/simuwang/manage/service/impl/ParseEmailDetailServiceImpl.java

@@ -33,12 +33,6 @@ public class ParseEmailDetailServiceImpl implements ParseEmailDetailService {
 
     @Autowired
     private EmailFundAssetMapper emailFundAssetMapper;
-
-    @Autowired
-    private AssetMapper assetMapper;
-
-    @Autowired
-    private NavMapper navMapper;
     @Override
     public MybatisPage<EmailFundNavVO> searchNavDetail(ParseDetailPageQuery parseDetailPageQuery) {
         List<EmailFundNavDO> dataList = emailFundNavMapper.searchNavDetail(parseDetailPageQuery);
@@ -68,53 +62,4 @@ public class ParseEmailDetailServiceImpl implements ParseEmailDetailService {
         long total = emailFundAssetMapper.countAssetDetail(parseDetailPageQuery);
         return MybatisPage.of(total,voList);
     }
-
-    @Override
-    public void saveFundAsset(FundAssetVO fundAssetVO) {
-        List<AssetDO> assetDOList = new ArrayList<>();
-        AssetDO assetDO = new AssetDO();
-        assetDO.setAssetNet(fundAssetVO.getAssetNet());
-        assetDO.setAssetShare(fundAssetVO.getAssetShare());
-        assetDO.setPriceDate(DateUtils.parse(fundAssetVO.getPriceDate(),DateUtils.YYYY_MM_DD));
-        assetDO.setFundId(fundAssetVO.getFundId());
-        assetDO.setUpdateTime(DateUtils.getNowDate());
-        assetDO.setIsvalid(1);
-        AssetDO oldAssetDO = assetMapper.queryFundAsset(assetDO);
-        if(StringUtil.isNull(oldAssetDO)){
-            assetDO.setCreateTime(DateUtils.getNowDate());
-            assetDOList.add(assetDO);
-            assetMapper.batchInsert(assetDOList);
-        }else{
-            oldAssetDO.setAssetShare(assetDO.getAssetShare());
-            oldAssetDO.setAssetNet(assetDO.getAssetNet());
-            assetDOList.add(oldAssetDO);
-            assetMapper.batchUpdate(assetDOList);
-        }
-    }
-
-    @Override
-    public void saveFundNav(FundNavVO fundNavVO) {
-        List<NavDO> navDOList = new ArrayList<>();
-        NavDO navDO = new NavDO();
-        navDO.setCumulativeNavWithdrawal(fundNavVO.getCumulativeNavWithdrawal());
-        navDO.setNav(fundNavVO.getNav());
-        navDO.setFundId(fundNavVO.getFundId());
-        navDO.setNav(fundNavVO.getNav());
-        navDO.setPriceDate(DateUtils.parse(fundNavVO.getPriceDate(),DateUtils.YYYY_MM_DD));
-        navDO.setIsvalid(1);
-        navDO.setUpdateTime(DateUtils.getNowDate());
-        NavDO oldNav = navMapper.queryFundNav(navDO);
-        if(StringUtil.isNull(oldNav)){
-            navDO.setCreateTime(DateUtils.getNowDate());
-            navDOList.add(navDO);
-            navMapper.batchInsert(navDOList);
-        }else{
-            oldNav.setUpdateTime(DateUtils.getNowDate());
-            oldNav.setCumulativeNav(navDO.getCumulativeNav());
-            oldNav.setCumulativeNavWithdrawal(navDO.getCumulativeNavWithdrawal());
-            oldNav.setNav(navDO.getNav());
-            navDOList.add(oldNav);
-            navMapper.batchUpdate(navDOList);
-        }
-    }
 }