Forráskód Böngészése

Merge branch 'master' of huangrui/CostAccount into dev

lijiaxi 4 éve
szülő
commit
c769e01f8c

+ 9 - 0
src/main/java/com/imed/costaccount/common/exception/CostExceptionHandler.java

@@ -4,6 +4,7 @@ import com.imed.costaccount.common.util.ErrorResult;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shiro.authz.UnauthorizedException;
 import org.springframework.dao.DataAccessException;
+import org.springframework.validation.BindException;
 import org.springframework.validation.ObjectError;
 import org.springframework.web.bind.MethodArgumentNotValidException;
 import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -35,6 +36,14 @@ public class CostExceptionHandler {
         return ErrorResult.errorMsg(500, this.formatAllErrorMessages(e.getBindingResult().getAllErrors()));
     }
 
+    @ExceptionHandler(value = BindException.class)
+    public ErrorResult handlerBindException(BindException e) {
+        e.printStackTrace();
+        log.info("GlobalExceptionHandler...");
+        log.info("错误代码:" + e.getMessage());
+        return ErrorResult.errorMsg(500, this.formatAllErrorMessages(e.getBindingResult().getAllErrors()));
+    }
+
 //    @ResponseStatus(value = HttpStatus.UNAUTHORIZED)
     @ExceptionHandler(value = UnauthorizedException.class)
     public ErrorResult handlerUnauthorizedException(UnauthorizedException e) {

+ 37 - 1
src/main/java/com/imed/costaccount/common/util/PageUtils.java

@@ -3,6 +3,7 @@ package com.imed.costaccount.common.util;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -32,6 +33,11 @@ public class PageUtils implements Serializable {
 	 * 列表数据
 	 */
 	private List<?> list;
+
+	/**
+	 * 归集后的数据总额
+	 */
+	private BigDecimal totalAmount;
 	
 	/**
 	 * 分页
@@ -48,6 +54,23 @@ public class PageUtils implements Serializable {
 		this.totalPage = (int)Math.ceil((double)totalCount/pageSize);
 	}
 
+	/**
+	 * 分页
+	 * @param list        列表数据
+	 * @param totalCount  总记录数
+	 * @param pageSize    每页记录数
+	 * @param current    当前页数
+	 * @param totalAmount  总金额
+	 */
+	public PageUtils(List<?> list, int totalCount, int pageSize, int current,BigDecimal totalAmount) {
+		this.list = list;
+		this.totalCount = totalCount;
+		this.pageSize = pageSize;
+		this.current = current ;
+		this.totalPage = (int)Math.ceil((double)totalCount/pageSize);
+		this.totalAmount = totalAmount;
+	}
+
 	/**
 	 * 分页
 	 */
@@ -98,5 +121,18 @@ public class PageUtils implements Serializable {
 	public void setList(List<?> list) {
 		this.list = list;
 	}
-	
+
+	public static long getSerialVersionUID() {
+		return serialVersionUID;
+	}
+
+	public BigDecimal getTotalAmount() {
+		return totalAmount;
+	}
+
+	public void setTotalAmount(BigDecimal totalAmount) {
+		this.totalAmount = totalAmount;
+	}
+
+
 }

+ 29 - 1
src/main/java/com/imed/costaccount/mapper/IncomeCollectionMapper.java

@@ -2,7 +2,13 @@ package com.imed.costaccount.mapper;
 
 import com.imed.costaccount.model.IncomeCollection;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.imed.costaccount.model.dto.CollectDTO;
+import com.imed.costaccount.model.vo.CollectedVO;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.math.BigDecimal;
+import java.util.List;
 
 /**
  * 归集后列表
@@ -12,5 +18,27 @@ import org.apache.ibatis.annotations.Mapper;
  */
 @Mapper
 public interface IncomeCollectionMapper extends BaseMapper<IncomeCollection> {
-	
+
+    /**
+     * 分页List
+     *
+     * @param collectDTO {@link CollectDTO}
+     * @return {@link CollectedVO}
+     */
+    List<CollectedVO> getCollectList(@Param("collectDTO") CollectDTO collectDTO);
+
+    /**
+     * 总数
+     * @param collectDTO {@link CollectDTO}
+     * @return
+     */
+    int getCollectListCount(@Param("collectDTO") CollectDTO collectDTO);
+
+    /**
+     * 计算总金额
+     * @param collectDTO {@link CollectDTO}
+     * @return
+     */
+    BigDecimal getTotalAmount(@Param("collectDTO") CollectDTO collectDTO);
+
 }

+ 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;
 
 }

+ 24 - 0
src/main/java/com/imed/costaccount/model/dto/CollectDTO.java

@@ -0,0 +1,24 @@
+package com.imed.costaccount.model.dto;
+
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+@Data
+@ApiModel("归集后数据查询入参")
+public class CollectDTO {
+
+    private Integer current ;
+
+    private Integer pageSize ;
+
+    @NotBlank(message = "时间不能为空")
+    private String date;
+
+    private String  responsibilityCode;
+
+    private String accountingCode;
+
+    private Long hospId;
+}

+ 35 - 0
src/main/java/com/imed/costaccount/model/vo/CollectedVO.java

@@ -0,0 +1,35 @@
+package com.imed.costaccount.model.vo;
+
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+@ApiModel("归集后数据列表")
+public class CollectedVO {
+
+    private Integer year;
+
+    private Integer month;
+
+    private String departmentCode;
+
+    private String departmentName;
+
+    private String responsibilityCode;
+
+    private String responsibilityName;
+
+    private String accountingCode;
+
+    private String accountingName;
+
+    private String projectCode;
+
+    private String projectName;
+
+    private Integer isDirectIncome;
+
+    private BigDecimal amount;
+}

+ 13 - 0
src/main/java/com/imed/costaccount/model/vo/CostIncomeGroupBeforeVO.java

@@ -21,36 +21,49 @@ public class CostIncomeGroupBeforeVO {
     @ApiModelProperty(name = "openDepartmentCode",value = "开单科室的代码")
     private String openDepartmentCode;
 
+    @ApiModelProperty(name = "openDepartmentName",value = "开单科室的名称")
+    private String openDepartmentName;
+
     @ApiModelProperty(name = "openDepartmentCodeName",value = "开单科室的代码+名称")
     private String openDepartmentCodeName;
 
     @ApiModelProperty(name = "openResponsibilityCode",value = "开单责任中心的代码")
     private String openResponsibilityCode;
 
+    private String openResponsibilityName;
+
     @ApiModelProperty(name = "openResponsibilityCodeName",value = "开单责任中心的代码+名称")
     private String openResponsibilityCodeName;
 
     @ApiModelProperty(name = "startDepartmentCode",value = "执行科室的代码")
     private String startDepartmentCode;
 
+    private String startDepartmentName;
+
     @ApiModelProperty(name = "startDepartmentCodeName",value = "执行科室代码+名称")
     private String startDepartmentCodeName;
 
     @ApiModelProperty(name = "startResponsibilityCode",value = "执行责任中心代码")
     private String startResponsibilityCode;
 
+    private String startResponsibilityName;
+
     @ApiModelProperty(name = "startResponsibilityCodeName",value = "执行责任中心代码+名称")
     private String startResponsibilityCodeName;
 
     @ApiModelProperty(name = "productCode",value = "成本项目的代码")
     private String productCode;
 
+    private String productName;
+
     @ApiModelProperty(name = "productCodeName",value = "成本项目的代码+名称")
     private String productCodeName;
 
     @ApiModelProperty(name = "accountCode",value = "会计科目的代码")
     private String accountCode;
 
+    private String accountName;
+
     @ApiModelProperty(name = "accountCodeName",value = "会计科目的代码+名称")
     private String accountCodeName;
 

+ 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);
 }
 

+ 10 - 0
src/main/java/com/imed/costaccount/service/IncomeCollectionService.java

@@ -3,6 +3,7 @@ package com.imed.costaccount.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.model.IncomeCollection;
+import com.imed.costaccount.model.dto.CollectDTO;
 
 /**
  * 归集后列表
@@ -41,5 +42,14 @@ public interface IncomeCollectionService extends IService<IncomeCollection> {
      * @param hospId 医院id
      */
     void cancelCollect(Integer year, Integer month, Long hospId);
+
+    /**
+     * 归集后数据分页列表
+     *
+     * @param collectDTO {@link CollectDTO} 查询相关参数
+     * @return {@link PageUtils}
+     */
+    PageUtils collectList(CollectDTO collectDTO);
+
 }
 

+ 62 - 34
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;
@@ -27,6 +28,7 @@ import java.io.File;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 
 @Slf4j
@@ -51,13 +53,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;
     }
 
     /**
@@ -95,10 +100,9 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
         // 进行金额合并
         List<CostIncomeGroupAllAmountVO> costIncomeGroupAllAmountVoS = baseMapper.countMoney(costIncomeGroupBeforeVOList);
         //  对,的金额进行合并
-        BigDecimal totalAmount= null;
+        AtomicReference<BigDecimal> totalAmount= null;
         costIncomeGroupAllAmountVoS.forEach(i -> {
             String allMoney = i.getAllMoney();
-
             if (allMoney.contains(StrUtil.COMMA)) {
                 // 存在,在进行求和
                 long sum;
@@ -107,6 +111,7 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
                 i.setAmount(BigDecimal.valueOf(sum));
             }
             //TODO 统计总金额
+//            totalAmount.updateAndGet(v -> v + i.getAmount());
         });
         PageUtils pageUtils = new PageUtils(pages);
         pageUtils.setList(costIncomeGroupAllAmountVoS);
@@ -117,13 +122,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 +164,32 @@ 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());
+        String substring = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf("."))+System.currentTimeMillis()+".xsl";
+        costIncomeFile.setFileName(substring);
+        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);
+        });
+        if (CollectionUtils.isEmpty(incomeErrorMessageList)){
+            this.saveBatch(costIncomeGroupArrayList);
         }
-
         return Result.ok();
     }
 
@@ -195,10 +222,10 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
             String openDepartmentCode = data.get(3).toString();
             String startDepartmentName = data.get(4).toString();
             String startDepartmentCode = data.get(5).toString();
-            BigDecimal beforeMoney = (BigDecimal) data.get(15);
-            boolean checkNull = Objects.isNull(beforeMoney);
-            boolean checkOne = NumberConstant.ZERO.equals(Integer.parseInt(beforeMoney.toString()));
-            if (!checkNull && !checkOne) {
+            BigDecimal beforeMoney = BigDecimal.valueOf(Double.parseDouble(data.get(15).toString()));
+            boolean checkNull = StrUtil.isBlank(data.get(15).toString());
+            boolean checkOne = NumberConstant.ZERO.equals(data.get(15).toString());
+            if (checkNull || checkOne) {
                 // 要求这一行的数据必须全部填写
                 for (int j = 0; j < NumberConstant.FIVE; j++) {
                     if (Objects.isNull(data.get(j))) {
@@ -214,7 +241,7 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
             Product product = productMap.get(productCode + productName);
             Department department = departmentMap.get(openDepartmentCode + openDepartmentName);
             Department department1 = departmentMap.get(startDepartmentCode + startDepartmentName);
-            if (checkNull || checkOne ){
+            if (!checkNull && !checkOne ){
                 if (StrUtil.isNotBlank(productCode) && StrUtil.isNotBlank(productName)){
                     if (Objects.isNull(product)) {
                         incomeErrorMessage.setTotal(i);
@@ -243,7 +270,7 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
                 }
             }
             // 检验开单科室
-            if (checkNull || checkOne ){
+            if (!checkNull && !checkOne ){
                 if (StrUtil.isNotBlank(openDepartmentCode) && StrUtil.isNotBlank(openDepartmentName)){
                     // 开单科室
                     if (Objects.isNull(department)) {
@@ -261,7 +288,7 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
                             costIncomeGroup.setOpenDepartmentCode(openDepartmentCode);
                             costIncomeGroup.setOpenDepartmentName(openDepartmentName);
                             costIncomeGroup.setOpenResponsibilityCode(responsibilityMap.get(responsibilityId).getResponsibilityCode());
-                            costIncomeGroup.setOpenResponsibilityCode(responsibilityMap.get(responsibilityId).getResponsibilityName());
+                            costIncomeGroup.setOpenResponsibilityName(responsibilityMap.get(responsibilityId).getResponsibilityName());
                         }
                     }
                 }else {
@@ -272,7 +299,7 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
                 }
             }
             // 检验执行科室
-            if (checkNull || checkOne ){
+            if ( !checkNull && !checkOne ){
                 if (StrUtil.isNotBlank(startDepartmentCode) && StrUtil.isNotBlank(startDepartmentName)){
                     //执行科室
                     if (Objects.isNull(department1)) {
@@ -288,9 +315,9 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
                             incomeErrorMessageList.add(incomeErrorMessage);
                         } else {
                             costIncomeGroup.setStartDepartmentCode(startDepartmentCode);
-                            costIncomeGroup.setOpenDepartmentName(startDepartmentName);
+                            costIncomeGroup.setStartDepartmentName(startDepartmentName);
                             costIncomeGroup.setStartResponsibilityCode(responsibilityMap.get(responsibilityId).getResponsibilityCode());
-                            costIncomeGroup.setStartResponsibilityCode(responsibilityMap.get(responsibilityId).getResponsibilityName());
+                            costIncomeGroup.setStartResponsibilityName(responsibilityMap.get(responsibilityId).getResponsibilityName());
                         }
                     }
                 }else {
@@ -311,6 +338,7 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
             costIncomeGroup.setDateYear(year);
             costIncomeGroup.setDateMonth(month);
             costIncomeGroup.setAmount(beforeMoney);
+            costIncomeGroupArrayList.add(costIncomeGroup);
         }
     }
 
@@ -321,23 +349,23 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
      * @param costIncomeGroupBeforeVOList
      */
     private void setCodeName(Long hospId, List<CostIncomeGroupBeforeVO> costIncomeGroupBeforeVOList) {
-        List<Responsibility> responsibilityList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId, hospId));
-        Map<String, String> responsibilityMap = responsibilityList.stream().collect(Collectors.toMap(Responsibility::getResponsibilityCode, Responsibility::getResponsibilityName));
-        List<Department> departmentList = departmentService.list(new QueryWrapper<Department>().lambda().eq(Department::getHospId, hospId));
-        Map<String, String> departmentMap = departmentList.stream().collect(Collectors.toMap(Department::getDepartmentCode, Department::getDepartmentName));
-        List<Product> productList = productService.list(new QueryWrapper<Product>().lambda().eq(Product::getHospId, hospId));
-        Map<String, String> productMap = productList.stream().collect(Collectors.toMap(Product::getProductCode, Product::getProductName));
-        List<Accounting> accountingList = accountingService.list(new QueryWrapper<Accounting>().lambda().eq(Accounting::getHospId, hospId));
-        Map<String, String> accountMap = accountingList.stream().collect(Collectors.toMap(Accounting::getAccountingCode, Accounting::getAccountingName));
+//        List<Responsibility> responsibilityList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId, hospId));
+//        Map<String, String> responsibilityMap = responsibilityList.stream().collect(Collectors.toMap(Responsibility::getResponsibilityCode, Responsibility::getResponsibilityName));
+//        List<Department> departmentList = departmentService.list(new QueryWrapper<Department>().lambda().eq(Department::getHospId, hospId));
+//        Map<String, String> departmentMap = departmentList.stream().collect(Collectors.toMap(Department::getDepartmentCode, Department::getDepartmentName));
+//        List<Product> productList = productService.list(new QueryWrapper<Product>().lambda().eq(Product::getHospId, hospId));
+//        Map<String, String> productMap = productList.stream().collect(Collectors.toMap(Product::getProductCode, Product::getProductName));
+//        List<Accounting> accountingList = accountingService.list(new QueryWrapper<Accounting>().lambda().eq(Accounting::getHospId, hospId));
+//        Map<String, String> accountMap = accountingList.stream().collect(Collectors.toMap(Accounting::getAccountingCode, Accounting::getAccountingName));
         costIncomeGroupBeforeVOList.forEach(i -> {
             // 以为这里的数据导入的  在导入的时候进行数据校验
             // 设置开单科室名称 执行科室名称  开单责任中心名称  执行责任中心名称 成本项目的名称 会计科目名称
-            i.setOpenDepartmentCodeName("[" + i.getOpenDepartmentCode() + "]" + departmentMap.get(i.getOpenDepartmentCode()));
-            i.setOpenResponsibilityCodeName("[" + i.getOpenResponsibilityCode() + "]" + responsibilityMap.get(i.getOpenResponsibilityCode()));
-            i.setStartDepartmentCodeName("[" + i.getStartDepartmentCode() + "]" + departmentMap.get(i.getStartDepartmentCode()));
-            i.setStartResponsibilityCodeName("[" + i.getStartResponsibilityCode() + "]" + responsibilityMap.get(i.getStartResponsibilityCode()));
-            i.setProductCodeName("[" + i.getProductCode() + "]" + productMap.get(i.getProductCode()));
-            i.setAccountCodeName("[" + i.getAccountCode() + "]" + accountMap.get(i.getAccountCode()));
+            i.setOpenDepartmentCodeName("[" + i.getOpenDepartmentCode() + "]" + i.getOpenDepartmentName());
+            i.setOpenResponsibilityCodeName("[" + i.getOpenResponsibilityCode() + "]" + i.getOpenResponsibilityName());
+            i.setStartDepartmentCodeName("[" + i.getStartDepartmentCode() + "]" + i.getStartDepartmentName());
+            i.setStartResponsibilityCodeName("[" + i.getStartResponsibilityCode() + "]" + i.getStartResponsibilityCode());
+            i.setProductCodeName("[" + i.getProductCode() + "]" + i.getProductName());
+            i.setAccountCodeName("[" + i.getAccountCode() + "]" + i.getAccountName());
         });
     }
 
@@ -346,7 +374,7 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
      */
     public String uploadFile(MultipartFile file, User user) {
         Long hospId = user.getHospId();
-        String fileName = file.getOriginalFilename();
+        String fileName = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf("."))+System.currentTimeMillis()+".xsl";
         String localFilePath = fileTempPath + StrUtil.SLASH + hospId + StrUtil.SLASH;
         File tempFile = new File(localFilePath);
         if (!tempFile.exists()) {

+ 1 - 1
src/main/java/com/imed/costaccount/service/impl/CostNumberBedSetServiceImpl.java

@@ -173,13 +173,13 @@ public class CostNumberBedSetServiceImpl extends ServiceImpl<CostNumberBedSetMap
         }
         String shareParamCodes = costNumberBedSetEditDto.getShareParamCode();
         Integer incomeFieldNums = costNumberBedSetEditDto.getIncomeFieldNum();
+        this.removeById(id);
         CostNumberBedSet costNumberBedSetResponse = this.getOne(new QueryWrapper<CostNumberBedSet>().lambda().eq(CostNumberBedSet::getHospId, hospId)
                 .eq(CostNumberBedSet::getShareParamCode, shareParamCodes)
                 .eq(CostNumberBedSet::getIncomeFieldNum, incomeFieldNums));
         if (Objects.nonNull(costNumberBedSetResponse)){
             throw new CostException(500,"数据已经存在");
         }
-        this.removeById(id);
         CostNumberBedSet costNumberBedSetRequest = BeanUtil.convertObj(costNumberBedSetEditDto, CostNumberBedSet.class);
         costNumberBedSetRequest.setHospId(hospId);
         costNumberBedSetRequest.setCreateTime(System.currentTimeMillis());

+ 33 - 4
src/main/java/com/imed/costaccount/service/impl/IncomeCollectionServiceImpl.java

@@ -9,6 +9,8 @@ import com.imed.costaccount.common.exception.CostException;
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.mapper.CostIncomeGroupMapper;
 import com.imed.costaccount.model.CostIncomeGroup;
+import com.imed.costaccount.model.dto.CollectDTO;
+import com.imed.costaccount.model.vo.CollectedVO;
 import com.imed.costaccount.model.vo.CollectionVO;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
@@ -20,6 +22,8 @@ import com.imed.costaccount.service.IncomeCollectionService;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -60,7 +64,7 @@ public class IncomeCollectionServiceImpl
             IncomeCollection one = this.getOne(
                     new LambdaQueryWrapper<IncomeCollection>().select(IncomeCollection::getId)
                             .eq(IncomeCollection::getYear, i.getYear())
-                            .eq(IncomeCollection::getMonth,i.getMonth())
+                            .eq(IncomeCollection::getMonth, i.getMonth())
                             .last(LIMIT)
             );
             if (Objects.isNull(one)) {
@@ -80,7 +84,7 @@ public class IncomeCollectionServiceImpl
      * @param hospId 医院id
      */
     @Override
-    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public void collect(Integer year, Integer month, Long hospId) {
         //  可能几十万次数据 需要分段异步多线程处理,分布式锁处理,
         List<CostIncomeGroup> costIncomeGroups = incomeGroupMapper.selectList(
@@ -90,7 +94,7 @@ public class IncomeCollectionServiceImpl
                         .eq(CostIncomeGroup::getHospId, hospId)
         );
         if (costIncomeGroups.isEmpty()) {
-            String format = StrUtil.format("{}年{}月数据不存在,请先导入数据",year,month);
+            String format = StrUtil.format("{}年{}月数据不存在,请先导入数据", year, month);
             throw new CostException(format);
         }
         // 根据会计科目和成本项目归纳所有数据
@@ -112,6 +116,7 @@ public class IncomeCollectionServiceImpl
             // todo 来源id暂时不确定
             incomeCollection.setFileId(costIncomeGroup.getFileId());
             incomeCollection.setCreateTime(System.currentTimeMillis());
+            // TODO: 2021/8/10 待确认是否收入中心
             // 开单中心的数据
             incomeCollection.setDepartmentCode(costIncomeGroup.getOpenDepartmentCode());
             incomeCollection.setResponsibilityCode(costIncomeGroup.getOpenResponsibilityCode());
@@ -136,7 +141,7 @@ public class IncomeCollectionServiceImpl
      * @param hospId 医院id
      */
     @Override
-    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public void cancelCollect(Integer year, Integer month, Long hospId) {
         LambdaQueryWrapper<IncomeCollection> wrapper = new LambdaQueryWrapper<IncomeCollection>()
                 .eq(IncomeCollection::getYear, year)
@@ -144,4 +149,28 @@ public class IncomeCollectionServiceImpl
                 .eq(IncomeCollection::getHospId, hospId);
         this.remove(wrapper);
     }
+
+    /**
+     * 归集后数据分页列表
+     *
+     * @param collectDTO {@link CollectDTO} 查询相关参数
+     * @return {@link PageUtils}
+     */
+    @Override
+    public PageUtils collectList(CollectDTO collectDTO) {
+        // 分页数据初始化
+        Integer current = collectDTO.getCurrent();
+        current = (Objects.isNull(current) || current == 0) ? 0 : current - 1;
+        Integer pageSize = collectDTO.getPageSize();
+        pageSize = Objects.isNull(pageSize) ? 10 : pageSize;
+        collectDTO.setCurrent(current * pageSize);
+        collectDTO.setPageSize(pageSize);
+
+        // 查询需要的数据 DB
+        List<CollectedVO> list = baseMapper.getCollectList(collectDTO);
+        int count = baseMapper.getCollectListCount(collectDTO);
+        BigDecimal totalAmount = baseMapper.getTotalAmount(collectDTO);
+
+        return new PageUtils(list, count, pageSize, current, totalAmount);
+    }
 }

+ 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, "导入失败");

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

@@ -2,12 +2,15 @@ package com.imed.costaccount.web;
 
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.common.util.Result;
+import com.imed.costaccount.model.dto.CollectDTO;
 import com.imed.costaccount.service.CostIncomeGroupService;
 import com.imed.costaccount.service.IncomeCollectionService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.web.bind.annotation.*;
 
+import javax.validation.Valid;
+
 
 /**
  * 归集后列表
@@ -41,15 +44,23 @@ public class IncomeCollectionController extends AbstractController {
 
     @ApiOperation("归集操作(开始归集)")
     @PostMapping("/collect")
-    public Result collect(@RequestParam Integer year,@RequestParam Integer month) {
+    public Result collect(@RequestParam Integer year, @RequestParam Integer month) {
         incomeCollectionService.collect(year, month, getHospId());
         return Result.ok();
     }
 
     @ApiOperation("撤销归集")
     @PostMapping("/cancelCollect")
-    public Result cancelCollect(@RequestParam Integer year,@RequestParam Integer month) {
+    public Result cancelCollect(@RequestParam Integer year, @RequestParam Integer month) {
         incomeCollectionService.cancelCollect(year, month, getHospId());
         return Result.ok();
     }
+
+    @ApiOperation("归集后数据列表")
+    @GetMapping("/collectList")
+    public Result collectList(@ModelAttribute @Valid CollectDTO collectDTO) {
+        collectDTO.setHospId(getHospId());
+        PageUtils pageUtils = incomeCollectionService.collectList(collectDTO);
+        return Result.ok(pageUtils);
+    }
 }

+ 46 - 3
src/main/resources/mapper/IncomeCollectionMapper.xml

@@ -3,7 +3,7 @@
 
 <mapper namespace="com.imed.costaccount.mapper.IncomeCollectionMapper">
 
-	<!-- 可根据自己的需求,是否要使用 -->
+    <!-- 可根据自己的需求,是否要使用 -->
     <resultMap type="com.imed.costaccount.model.IncomeCollection" id="incomeCollectionMap">
         <result property="id" column="id"/>
         <result property="year" column="year"/>
@@ -18,11 +18,54 @@
         <result property="productName" column="product_name"/>
         <result property="isDirectIncome" column="is_direct_income"/>
         <result property="amount" column="amount"/>
-        <result property="fileId" column="file_id" />
-        <result property="hospId" column="hosp_id" />
+        <result property="fileId" column="file_id"/>
+        <result property="hospId" column="hosp_id"/>
         <result property="createTime" column="create_time"/>
         <result property="deleteTime" column="delete_time"/>
     </resultMap>
 
+    <select id="getCollectList" resultType="com.imed.costaccount.model.vo.CollectedVO">
+        select * from cost_income_collection
+        where delete_time = 0 and hosp_id = #{collectDTO.hospId}
+        <if test="collectDTO.date != null and collectDTO.date != ''">
+            and `year` = YEAR(concat(#{collectDTO.date},'01')) and `month` = MONTH(concat(#{collectDTO.date},'01'))
+        </if>
+        <if test="collectDTO.responsibilityCode != null and collectDTO.responsibilityCode != ''">
+            and responsibility_code = #{collectDTO.responsibilityCode}
+        </if>
+        <if test="collectDTO.accountingCode != null and collectDTO.accountingCode != ''">
+            and accounting_code = #{collectDTO.accountingCode}
+        </if>
+        limit #{collectDTO.current},#{collectDTO.pageSize};
+    </select>
+
+    <select id="getCollectListCount" resultType="java.lang.Integer">
+        select count(*) from cost_income_collection
+        where delete_time = 0 and hosp_id = #{collectDTO.hospId}
+        <if test="collectDTO.date != null and collectDTO.date != ''">
+            and `year` = YEAR(concat(#{collectDTO.date},'01')) and `month` = MONTH(concat(#{collectDTO.date},'01'))
+        </if>
+        <if test="collectDTO.responsibilityCode != null and collectDTO.responsibilityCode != ''">
+            and responsibility_code = #{collectDTO.responsibilityCode}
+        </if>
+        <if test="collectDTO.accountingCode != null and collectDTO.accountingCode != ''">
+            and accounting_code = #{collectDTO.accountingCode}
+        </if>
+    </select>
+
+    <select id="getTotalAmount" resultType="java.math.BigDecimal">
+        select IFNULL(sum(amount),0) as totalAmount from cost_income_collection
+        where delete_time = 0 and hosp_id = #{collectDTO.hospId}
+        <if test="collectDTO.date != null and collectDTO.date != ''">
+            and `year` = YEAR(concat(#{collectDTO.date},'01')) and `month` = MONTH(concat(#{collectDTO.date},'01'))
+        </if>
+        <if test="collectDTO.responsibilityCode != null and collectDTO.responsibilityCode != ''">
+            and responsibility_code = #{collectDTO.responsibilityCode}
+        </if>
+        <if test="collectDTO.accountingCode != null and collectDTO.accountingCode != ''">
+            and accounting_code = #{collectDTO.accountingCode}
+        </if>
+    </select>
+
 
 </mapper>