Browse Source

数据导入

ljx 4 years ago
parent
commit
3fdfb874bc

+ 3 - 1
src/main/java/com/imed/costaccount/model/CostIncomeFile.java

@@ -1,6 +1,7 @@
 package com.imed.costaccount.model;
 
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -36,7 +37,7 @@ public class CostIncomeFile implements Serializable {
 	/**
 	 * 文件名称
 	 */
-	private Integer fileName;
+	private String fileName;
 	/**
 	 * 文件上传路径
 	 */
@@ -72,6 +73,7 @@ public class CostIncomeFile implements Serializable {
 	/**
 	 * 删除时间,如果存在表示已删除13位时间戳
 	 */
+	@TableLogic(value = "0",delval = "UNIX_TIMESTAMP(NOW()) * 1000")
 	private Long deleteTime;
 
 }

+ 2 - 0
src/main/java/com/imed/costaccount/model/CostIncomeGroup.java

@@ -1,6 +1,7 @@
 package com.imed.costaccount.model;
 
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -154,6 +155,7 @@ public class CostIncomeGroup implements Serializable {
 	/**
 	 * 删除时间,如果存在表示已删除13位时间戳
 	 */
+	@TableLogic(value = "0",delval = "UNIX_TIMESTAMP(NOW()) * 1000")
 	private Long deleteTime;
 
 }

+ 3 - 2
src/main/java/com/imed/costaccount/service/CostIncomeGroupService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.common.util.Result;
 import com.imed.costaccount.model.CostIncomeGroup;
+import com.imed.costaccount.model.User;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
@@ -31,10 +32,10 @@ public interface CostIncomeGroupService extends IService<CostIncomeGroup> {
     /**
      * 批量导入收入数据
      * @param read
-     * @param hospId
+     * @param user
      * @param file
      * @return
      */
-    Result importIncomeGroup(List<List<Object>> read, Long hospId, MultipartFile file,Integer year,Integer month);
+    Result importIncomeGroup(List<List<Object>> read, User user, MultipartFile file, Integer year, Integer month);
 }
 

+ 29 - 7
src/main/java/com/imed/costaccount/service/impl/CostIncomeGroupServiceImpl.java

@@ -1,6 +1,7 @@
 package com.imed.costaccount.service.impl;
 
 import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -51,13 +52,16 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
 
     private final AccountingProductService accountingProductService;
 
-    public CostIncomeGroupServiceImpl(DepartmentService departmentService, ResponsibilityService responsibilityService, ProductService productService, AccountingService accountingService, ResponsibilityDepartmentService responsibilityDepartmentService, AccountingProductService accountingProductService) {
+    private final CostIncomeFileService costIncomeFileService;
+
+    public CostIncomeGroupServiceImpl(DepartmentService departmentService, ResponsibilityService responsibilityService, ProductService productService, AccountingService accountingService, ResponsibilityDepartmentService responsibilityDepartmentService, AccountingProductService accountingProductService, CostIncomeFileService costIncomeFileService) {
         this.departmentService = departmentService;
         this.responsibilityService = responsibilityService;
         this.productService = productService;
         this.accountingService = accountingService;
         this.responsibilityDepartmentService = responsibilityDepartmentService;
         this.accountingProductService = accountingProductService;
+        this.costIncomeFileService = costIncomeFileService;
     }
 
     /**
@@ -117,13 +121,14 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
      * 批量导入收入数据
      *
      * @param list   输入的文件
-     * @param hospId 医院Id
+     * @param user 用户
      * @param file
      * @return
      */
     @Override
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
-    public Result importIncomeGroup(List<List<Object>> list, Long hospId, MultipartFile file,Integer year,Integer month) {
+    public Result importIncomeGroup(List<List<Object>> list, User user, MultipartFile file,Integer year,Integer month) {
+        Long hospId = user.getHospId();
         // 移除前几行的抬头内容  list的大小对应的就是行数的大小
         for (int i = list.size() - 1; i >= 0; i--) {
             if (i == NumberConstant.ZERO || i == NumberConstant.ONE || i == NumberConstant.TWO || i == NumberConstant.THREE) {
@@ -158,11 +163,28 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
         if (StrUtil.isBlank(uploadFile)){
             throw new CostException(500,"文件上传异常");
         }
-
-        if (CollectionUtils.isEmpty(incomeErrorMessageList)) {
-            // 才将数据保存到收入归集里面
+        // 记录文件上传记录
+        CostIncomeFile costIncomeFile = new CostIncomeFile();
+        costIncomeFile.setFileType(file.getContentType());
+        costIncomeFile.setFileName(file.getOriginalFilename());
+        costIncomeFile.setFileUrl(uploadFile);
+        costIncomeFile.setTotalAmount(list.size());
+        if (!CollectionUtils.isEmpty(incomeErrorMessageList)) {
+            costIncomeFile.setSuccessAmount(NumberConstant.ZERO);
+            costIncomeFile.setErrorList(JSON.toJSONString(incomeErrorMessageList));
+        }else {
+            costIncomeFile.setSuccessAmount(list.size());
         }
-
+        costIncomeFile.setHospId(hospId);
+        costIncomeFile.setUserName(user.getName());
+        costIncomeFile.setUserId(user.getId());
+        costIncomeFile.setCreateTime(System.currentTimeMillis());
+        costIncomeFileService.save(costIncomeFile);
+        Long id = costIncomeFile.getId();
+        costIncomeGroupArrayList.forEach(i->{
+            // 设置文件Id
+            i.setFileId(id);
+        });
         return Result.ok();
     }
 

+ 2 - 2
src/main/java/com/imed/costaccount/web/ExcelController.java

@@ -433,8 +433,8 @@ public class ExcelController {
             List<List<Object>> read = reader.read();
             log.info("最开始:read={}",read);
             log.info("-------------------------------------------------------------------");
-            Long hospId = UserContext.getHospId();
-            return costIncomeGroupService.importIncomeGroup(read, hospId,file,year,month);
+            User user = UserContext.getCurrentUser();
+            return costIncomeGroupService.importIncomeGroup(read, user,file,year,month);
         }catch (IOException e){
             e.printStackTrace();;
             throw new CostException(500, "导入失败");