Kaynağa Gözat

Merge branch 'master' of huangrui/CostAccount into dev

lijiaxi 4 yıl önce
ebeveyn
işleme
2a7cada294

+ 132 - 0
src/main/java/com/imed/costaccount/model/GetCheckData.java

@@ -0,0 +1,132 @@
+package com.imed.costaccount.model;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.imed.costaccount.common.exception.CostException;
+import com.imed.costaccount.service.*;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @author 李加喜
+ * @Package com.imed.costaccount.model
+ * @date 2021-08-10 17:15
+ */
+@Data
+@ApiModel("获取数据")
+public class GetCheckData {
+    @Autowired
+    private DepartmentService departmentService;
+
+    @Autowired
+    private ResponsibilityService responsibilityService;
+
+    @Autowired
+    private ProductService productService;
+
+    @Autowired
+    private  AccountingService accountingService;
+
+    @Autowired
+    private ResponsibilityDepartmentService responsibilityDepartmentService;
+
+    @Autowired
+    private CostIncomeGroupSetService costIncomeGroupSetService;
+
+    @Autowired
+    private AccountingProductService accountingProductService;
+    private Long hospId;
+    private Map<String, Department> departmentMap;
+    private Map<String, Product> productMap;
+    private Map<Long, Responsibility> responsibilityMap;
+    private Map<Long, Accounting> accountingMap;
+    private Map<Long, Long> responsibilityDepMap;
+    private Map<Long, Long> accountProMap;
+    private Map<Integer, CostIncomeGroupSet> incomeGroupSetMap;
+
+    public GetCheckData(Long hospId) {
+        this.hospId = hospId;
+    }
+
+    /**
+     * 根据科室Code+Name获取指定科室
+     * @return
+     */
+    public Map<String, Department> getDepartmentMap() {
+        return departmentMap;
+    }
+
+    /**
+     * 根据Product的Code+name 获取product
+     * @return
+     */
+    public Map<String, Product> getProductMap() {
+        return productMap;
+    }
+
+    /**
+     * 根据id获取责任中心
+     * @return
+     */
+    public Map<Long, Responsibility> getResponsibilityMap() {
+        return responsibilityMap;
+    }
+
+    /**
+     * 根据id后去会计科目
+     * @return
+     */
+    public Map<Long, Accounting> getAccountingMap() {
+        return accountingMap;
+    }
+
+    /**
+     * 根据科室的id获取责任中心的Id
+     * @return
+     */
+    public Map<Long, Long> getResponsibilityDepMap() {
+        return responsibilityDepMap;
+    }
+
+    /**
+     * 根据成本项目id获取会计科目Id
+     * @return
+     */
+    public Map<Long, Long> getAccountProMap() {
+        return accountProMap;
+    }
+    public Map<Integer, CostIncomeGroupSet> getIncomeGroupSetMap() {
+        return incomeGroupSetMap;
+    }
+
+    /**
+     * 根据开单科室状态科执行科室状态返回设置数据
+     * @return
+     */
+
+    public GetCheckData invoke() {
+        departmentMap = departmentService.list(new QueryWrapper<Department>().lambda().eq(Department::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getDepartmentCode() + k.getDepartmentName(), synOe -> synOe));
+        productMap = productService.list(new QueryWrapper<Product>().lambda().eq(Product::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getProductCode() + k.getProductName(), synOe -> synOe));
+        responsibilityMap = responsibilityService.list(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId, hospId)).stream().collect(Collectors.toMap(Responsibility::getId, synOe -> synOe));
+        accountingMap = accountingService.list(new QueryWrapper<Accounting>().lambda().eq(Accounting::getHospId, hospId)).stream().collect(Collectors.toMap(Accounting::getId, synOe -> synOe));
+        incomeGroupSetMap = costIncomeGroupSetService.list(new QueryWrapper<CostIncomeGroupSet>().lambda().eq(CostIncomeGroupSet::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getOpenDepartmentStatus() + k.getStartDepartmentStatus(), synOe -> synOe));
+        List<ResponsibilityDepartment> responsibilityDepartmentList = responsibilityDepartmentService.list(new QueryWrapper<ResponsibilityDepartment>().lambda()
+                .eq(ResponsibilityDepartment::getHospId, hospId));
+        if (CollectionUtils.isEmpty(responsibilityDepartmentList)) {
+            throw new CostException(500, "没有科室责任中心对照数据");
+        }
+        List<AccountingProduct> accountingProductList = accountingProductService.list(new QueryWrapper<AccountingProduct>().lambda().eq(AccountingProduct::getHospId, hospId));
+        if (CollectionUtils.isEmpty(accountingProductList)) {
+            throw new CostException(500, "没有成本会计对照数据");
+        }
+        responsibilityDepMap = responsibilityDepartmentList.stream().collect(Collectors.toMap(ResponsibilityDepartment::getDepartmentId, ResponsibilityDepartment::getResponsibilityId));
+        accountProMap = accountingProductList.stream().collect(Collectors.toMap(AccountingProduct::getProductId, AccountingProduct::getAccountingId));
+
+        return this;
+    }
+}

+ 52 - 0
src/main/java/com/imed/costaccount/model/vo/CostIncomeFileVO.java

@@ -0,0 +1,52 @@
+package com.imed.costaccount.model.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @author 李加喜
+ * @Package com.imed.costaccount.model.vo
+ * @date 2021-08-10 18:18
+ */
+@Data
+@ApiModel("分页查询文件列表数据")
+public class CostIncomeFileVO {
+    /**
+     * 主键 文件编号
+     */
+    @ApiModelProperty(name = "id",value = "文件编号")
+    private Long id;
+
+    @ApiModelProperty(name = "fileType",value = "文件类型")
+    private String fileType;
+    @ApiModelProperty(name = "fileName",value = "文件名称")
+    private String fileName;
+    /**
+     * 文件上传路径
+     */
+    @ApiModelProperty(name = "fileUrl",value = "文件地址")
+    private String fileUrl;
+    @ApiModelProperty(name = "successAmount",value = "导入成功记录数")
+    private Integer successAmount;
+    @ApiModelProperty(name = "totalAmount",value = "总记录数")
+    private Integer totalAmount;
+    @ApiModelProperty(name = "userName",value = "导入人员")
+    private String userName;
+    /**
+     * 创建时间
+     */
+    private Long createTime;
+    /**
+     * 导入时间
+     */
+    private String dateTime;
+    /**
+     * 错误详情
+     */
+    private String errorList;
+    /**
+     * 是否显示错误详情按钮
+     */
+    private Integer errStatus=0;
+}

+ 27 - 0
src/main/java/com/imed/costaccount/service/CostIncomeFileService.java

@@ -1,7 +1,13 @@
 package com.imed.costaccount.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.model.CostIncomeFile;
+import com.imed.costaccount.model.User;
+import com.imed.costaccount.model.vo.IncomeErrorMessage;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
 
 /**
  * 文件上传记录
@@ -12,5 +18,26 @@ import com.imed.costaccount.model.CostIncomeFile;
  */
 public interface CostIncomeFileService extends IService<CostIncomeFile> {
 
+    /**
+     * 保存文件上传记录
+     * @param list 文件数据
+     * @param user 当前用户
+     * @param file 上传文件
+     * @param hospId 医院Id
+     * @param incomeErrorMessageList 错误信息
+     * @param uploadFile 文件路径
+     * @return
+     */
+    CostIncomeFile saveCostIncomeFile(List<List<Object>> list, User user, MultipartFile file, Long hospId, List<IncomeErrorMessage> incomeErrorMessageList, String uploadFile);
+
+    /**
+     * 分页查询查询记录数据
+     * @param current
+     * @param pageSize
+     * @param name
+     * @param hospId
+     * @return
+     */
+    PageUtils queryList(Integer current, Integer pageSize, String name, Long hospId);
 }
 

+ 11 - 0
src/main/java/com/imed/costaccount/service/CostIncomeGroupService.java

@@ -37,5 +37,16 @@ public interface CostIncomeGroupService extends IService<CostIncomeGroup> {
      * @return
      */
     Result importIncomeGroup(List<List<Object>> read, User user, MultipartFile file, Integer year, Integer month);
+
+    /**
+     * 导入收入数据
+     * @param read 读取到的初始数据
+     * @param user 当前登录用户
+     * @param file 导入的文件
+     * @param year 年
+     * @param month 月
+     * @return {@link Result}
+     */
+    Result importDataByIncomeData(List<List<Object>> read, User user, MultipartFile file, Integer year, Integer month);
 }
 

+ 73 - 0
src/main/java/com/imed/costaccount/service/impl/CostIncomeFileServiceImpl.java

@@ -1,14 +1,87 @@
 package com.imed.costaccount.service.impl;
 
+import cn.hutool.core.date.DateUtil;
+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;
+import com.imed.costaccount.common.util.BeanUtil;
+import com.imed.costaccount.common.util.PageUtils;
+import com.imed.costaccount.constants.NumberConstant;
 import com.imed.costaccount.mapper.CostIncomeFileMapper;
 import com.imed.costaccount.model.CostIncomeFile;
+import com.imed.costaccount.model.User;
+import com.imed.costaccount.model.vo.CostIncomeFileVO;
+import com.imed.costaccount.model.vo.IncomeErrorMessage;
 import com.imed.costaccount.service.CostIncomeFileService;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
 
 
 @Service("costIncomeFileService")
 public class CostIncomeFileServiceImpl extends ServiceImpl<CostIncomeFileMapper, CostIncomeFile> implements CostIncomeFileService {
 
+    /**
+     * 保存文件上传记录
+     * @param list 文件数据
+     * @param user 当前用户
+     * @param file 上传文件
+     * @param hospId 医院Id
+     * @param incomeErrorMessageList 错误信息
+     * @param uploadFile 文件路径
+     * @return
+     */
+    @Override
+    public CostIncomeFile saveCostIncomeFile(List<List<Object>> list, User user, MultipartFile file, Long hospId, List<IncomeErrorMessage> incomeErrorMessageList, String uploadFile) {
+        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());
+        this.save(costIncomeFile);
+        return costIncomeFile;
+    }
 
+    /**
+     * 分页查询查询记录数据
+     *
+     * @param current
+     * @param pageSize
+     * @param name
+     * @param hospId
+     * @return
+     */
+    @Override
+    public PageUtils queryList(Integer current, Integer pageSize, String name, Long hospId) {
+        Page<CostIncomeFile> costIncomeFilePage = new Page<>(current, pageSize);
+        Page<CostIncomeFile> page = this.page(costIncomeFilePage, new QueryWrapper<CostIncomeFile>().lambda()
+                .eq(CostIncomeFile::getHospId, hospId).like(StrUtil.isNotBlank(name), CostIncomeFile::getFileName, name));
+        List<CostIncomeFile> records = page.getRecords();
+        List<CostIncomeFileVO> costIncomeFileVOList = BeanUtil.convertList(records, CostIncomeFileVO.class);
+        costIncomeFileVOList.forEach(i->{
+            String errorList = i.getErrorList();
+            if (StrUtil.isNotBlank(errorList)){
+                i.setErrStatus(NumberConstant.ONE);
+            }
+            i.setDateTime(DateUtil.format(DateUtil.date(i.getCreateTime()),"yyyy-MM-dd"));
+        });
+        PageUtils pageUtils = new PageUtils(page);
+        pageUtils.setList(costIncomeFileVOList);
+        return pageUtils;
+    }
 }

+ 84 - 31
src/main/java/com/imed/costaccount/service/impl/CostIncomeGroupServiceImpl.java

@@ -1,7 +1,6 @@
 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;
@@ -17,6 +16,7 @@ import com.imed.costaccount.model.vo.CostIncomeGroupBeforeVO;
 import com.imed.costaccount.model.vo.IncomeErrorMessage;
 import com.imed.costaccount.service.*;
 import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.NotNull;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
@@ -100,10 +100,10 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
         // 进行金额合并
         List<CostIncomeGroupAllAmountVO> costIncomeGroupAllAmountVoS = baseMapper.countMoney(costIncomeGroupBeforeVOList);
         //  对,的金额进行合并
-        AtomicReference<BigDecimal> totalAmount= null;
+        AtomicReference<BigDecimal> totalAmount = new AtomicReference<>(new BigDecimal("0.0000"));
         costIncomeGroupAllAmountVoS.forEach(i -> {
             String allMoney = i.getAllMoney();
-            if (allMoney.contains(StrUtil.COMMA)) {
+            if (StrUtil.isNotBlank(allMoney) && allMoney.contains(StrUtil.COMMA)) {
                 // 存在,在进行求和
                 long sum;
                 List<Long> list = Arrays.stream(allMoney.split(StrUtil.COMMA)).map(Long::valueOf).collect(Collectors.toList());
@@ -111,10 +111,11 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
                 i.setAmount(BigDecimal.valueOf(sum));
             }
             //TODO 统计总金额
-//            totalAmount.updateAndGet(v -> v + i.getAmount());
+            totalAmount.updateAndGet(v -> v.add(i.getAmount()));
         });
         PageUtils pageUtils = new PageUtils(pages);
         pageUtils.setList(costIncomeGroupAllAmountVoS);
+        pageUtils.setTotalAmount(totalAmount.get());
         return pageUtils;
     }
 
@@ -129,7 +130,13 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
     @Override
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public Result importIncomeGroup(List<List<Object>> list, User user, MultipartFile file,Integer year,Integer month) {
+        // 先检验当前年月是否存在数据
         Long hospId = user.getHospId();
+        List<CostIncomeGroup> groups = this.list(new QueryWrapper<CostIncomeGroup>().lambda().eq(CostIncomeGroup::getHospId, hospId)
+                .eq(CostIncomeGroup::getDateYear, year).eq(CostIncomeGroup::getDateMonth, month));
+        if (!CollectionUtils.isEmpty(groups)){
+            throw new CostException(500,year+"年"+month+"月数据已存在");
+        }
         // 移除前几行的抬头内容  list的大小对应的就是行数的大小
         for (int i = list.size() - 1; i >= 0; i--) {
             if (i == NumberConstant.ZERO || i == NumberConstant.ONE || i == NumberConstant.TWO || i == NumberConstant.THREE) {
@@ -139,12 +146,12 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
         log.info("读取的数据为:{}", list);
         List<IncomeErrorMessage> incomeErrorMessageList = new ArrayList<>();
         //获取所有的科室 成本项目 责任中心 会计科目
-        Map<String, Department> departmentMap = departmentService.list(new QueryWrapper<Department>().lambda().eq(Department::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getDepartmentCode() + k.getDepartmentName(), synOe -> synOe));
-        Map<String, Product> productMap = productService.list(new QueryWrapper<Product>().lambda().eq(Product::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getProductCode() + k.getProductName(), synOe -> synOe));
-        Map<Long, Responsibility> responsibilityMap = responsibilityService.list(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId, hospId)).stream().collect(Collectors.toMap(Responsibility::getId, synOe -> synOe));
-        Map<Long, Accounting> accountingMap = accountingService.list(new QueryWrapper<Accounting>().lambda().eq(Accounting::getHospId, hospId)).stream().collect(Collectors.toMap(Accounting::getId, synOe -> synOe));
-        List<ResponsibilityDepartment> responsibilityDepartmentList = responsibilityDepartmentService.list(new QueryWrapper<ResponsibilityDepartment>().lambda()
-                .eq(ResponsibilityDepartment::getHospId, hospId));
+        //
+        Map<String, Department> departmentMap = getDepartmentByCodeNameMap(hospId);
+        Map<String, Product> productMap = getProductByCodeNameMap(hospId);
+        Map<Long, Responsibility> responsibilityMap = getLongResponsibilityMap(hospId);
+        Map<Long, Accounting> accountingMap = getLongAccountingMap(hospId);
+        List<ResponsibilityDepartment> responsibilityDepartmentList = getResponsibilityDepartments(hospId);
         if (CollectionUtils.isEmpty(responsibilityDepartmentList)) {
             throw new CostException(500, "没有科室责任中心对照数据");
         }
@@ -152,10 +159,10 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
         if (CollectionUtils.isEmpty(accountingProductList)) {
             throw new CostException(500, "没有成本会计对照数据");
         }
-        Map<Long, Long> responsibilityDepMap = responsibilityDepartmentList.stream().collect(Collectors.toMap(ResponsibilityDepartment::getDepartmentId, ResponsibilityDepartment::getResponsibilityId));
-        Map<Long, Long> accountProMap = accountingProductList.stream().collect(Collectors.toMap(AccountingProduct::getProductId, AccountingProduct::getAccountingId));
+        Map<Long, Long> responsibilityDepMap = getDepartmentIdResponsibilityIdMap(responsibilityDepartmentList);
+        Map<Long, Long> accountProMap = getProductIdAccountIdMap(accountingProductList);
         List<CostIncomeGroup> costIncomeGroupArrayList = new ArrayList<>();
-        // 检验数据  TODO 缺少文件Id
+        // 检验数据
         checkImportData(list, incomeErrorMessageList, costIncomeGroupArrayList, departmentMap, productMap, responsibilityMap, accountingMap, responsibilityDepMap, accountProMap,hospId,year,month);
 
         // 文件上传
@@ -165,23 +172,7 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
             throw new CostException(500,"文件上传异常");
         }
         // 记录文件上传记录
-        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);
+        CostIncomeFile costIncomeFile =costIncomeFileService.saveCostIncomeFile(list, user, file, hospId, incomeErrorMessageList, uploadFile);
         Long id = costIncomeFile.getId();
         costIncomeGroupArrayList.forEach(i->{
             // 设置文件Id
@@ -193,6 +184,67 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
         return Result.ok();
     }
 
+    /**
+     * 返回成本会计对照数据  Key 成本项目Id   Value 会计科目Id
+     * @param accountingProductList
+     * @return
+     */
+    @NotNull
+    private Map<Long, Long> getProductIdAccountIdMap(List<AccountingProduct> accountingProductList) {
+        return accountingProductList.stream().collect(Collectors.toMap(AccountingProduct::getProductId, AccountingProduct::getAccountingId));
+    }
+
+    /**
+     *
+     * @param responsibilityDepartmentList
+     * @return
+     */
+    @NotNull
+    private Map<Long, Long> getDepartmentIdResponsibilityIdMap(List<ResponsibilityDepartment> responsibilityDepartmentList) {
+        return responsibilityDepartmentList.stream().collect(Collectors.toMap(ResponsibilityDepartment::getDepartmentId, ResponsibilityDepartment::getResponsibilityId));
+    }
+
+    private List<ResponsibilityDepartment> getResponsibilityDepartments(Long hospId) {
+        return responsibilityDepartmentService.list(new QueryWrapper<ResponsibilityDepartment>().lambda()
+                    .eq(ResponsibilityDepartment::getHospId, hospId));
+    }
+
+    @NotNull
+    private Map<Long, Accounting> getLongAccountingMap(Long hospId) {
+        return accountingService.list(new QueryWrapper<Accounting>().lambda().eq(Accounting::getHospId, hospId)).stream().collect(Collectors.toMap(Accounting::getId, synOe -> synOe));
+    }
+
+    @NotNull
+    private Map<Long, Responsibility> getLongResponsibilityMap(Long hospId) {
+        return responsibilityService.list(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId, hospId)).stream().collect(Collectors.toMap(Responsibility::getId, synOe -> synOe));
+    }
+
+    @NotNull
+    private Map<String, Product> getProductByCodeNameMap(Long hospId) {
+        return productService.list(new QueryWrapper<Product>().lambda().eq(Product::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getProductCode() + k.getProductName(), synOe -> synOe));
+    }
+
+    @NotNull
+    private Map<String, Department> getDepartmentByCodeNameMap(Long hospId) {
+        return departmentService.list(new QueryWrapper<Department>().lambda().eq(Department::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getDepartmentCode() + k.getDepartmentName(), synOe -> synOe));
+    }
+
+    /**
+     * 导入收入数据
+     *
+     * @param read  读取到的初始数据
+     * @param user  当前登录用户
+     * @param file  导入的文件
+     * @param year  年
+     * @param month 月
+     * @return {@link Result}
+     */
+    @Override
+    public Result importDataByIncomeData(List<List<Object>> read, User user, MultipartFile file, Integer year, Integer month) {
+        return null;
+    }
+
+
     /**
      * 检验数据
      *  @param list                     表单数据
@@ -213,7 +265,6 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
             IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
             List<Object> data = list.get(i);
             log.info("用户输入的数据是{}", data);
-            // TODO 暂时不走循环  直接获取数据的处理
             // 成本项目的代码和名称
             String productCode = data.get(0).toString();
             String productName = data.get(1).toString();
@@ -390,4 +441,6 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
         }
         return FILE_PATH + hospId + StrUtil.SLASH + fileName;
     }
+
+
 }

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

@@ -95,13 +95,14 @@ public class CostOtherPaymentsServiceImpl extends ServiceImpl<CostOtherPaymentsM
         if (Objects.isNull(otherPayments)){
             throw new CostException(500,"原始数据不存在");
         }
+
+        this.removeById(id);
         CostOtherPayments otherPaymentResponse = this.getOne(new QueryWrapper<CostOtherPayments>().lambda().eq(CostOtherPayments::getHospId, hospId)
                 .eq(CostOtherPayments::getPaymentsName,costOtherPaymentsEditDto.getPaymentsName())
                 .eq(CostOtherPayments::getPaymentsType,costOtherPaymentsEditDto.getPaymentsType()));
         if (Objects.nonNull(otherPaymentResponse)){
             throw new CostException(500,"修改后的数据已存在");
         }
-        this.removeById(id);
         CostOtherPayments costOtherPayments = BeanUtil.convertObj(costOtherPaymentsEditDto, CostOtherPayments.class);
         costOtherPayments.setCreateTime(System.currentTimeMillis());
         costOtherPayments.setId(null);

+ 13 - 7
src/main/java/com/imed/costaccount/web/CostIncomeFileController.java

@@ -1,10 +1,12 @@
 package com.imed.costaccount.web;
 
+import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.common.util.Result;
+import com.imed.costaccount.common.util.UserContext;
 import com.imed.costaccount.model.CostIncomeFile;
-import com.imed.costaccount.model.User;
 import com.imed.costaccount.service.CostIncomeFileService;
-import org.apache.shiro.SecurityUtils;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -18,7 +20,8 @@ import java.util.Arrays;
  * @date 2021-08-10 14:42:20
  */
 @RestController
-@RequestMapping("/costincomefile")
+@RequestMapping("/costAccount//costincomefile")
+@Api(tags = "文件记录")
 public class CostIncomeFileController {
     @Autowired
     private CostIncomeFileService costIncomeFileService;
@@ -27,11 +30,14 @@ public class CostIncomeFileController {
      * 分页查询列表
      * 查询的是
      */
-    @RequestMapping("/list")
+    @GetMapping("/list")
+    @ApiOperation("分页查询记录数据")
     public Result list(@RequestParam(value = "current", defaultValue = "1") Integer current,
-                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
-        User user = (User) SecurityUtils.getSubject().getPrincipal();
-        return Result.ok();
+                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
+                       @RequestParam(value = "name",required = false) String name){
+        Long hospId = UserContext.getHospId();
+        PageUtils pageUtils = costIncomeFileService.queryList(current,pageSize,name,hospId);
+        return Result.ok(pageUtils);
     }
 
 

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

@@ -1,6 +1,8 @@
 package com.imed.costaccount.web;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.io.IoUtil;
 import cn.hutool.poi.excel.ExcelReader;
@@ -88,7 +90,7 @@ public class ExcelController {
         writer.passCurrentRow();
         writer.merge(2, 2, 0, 4, "测试医院用户导入", false);
         writer.passCurrentRow();
-        writer.writeRow(Arrays.asList("院区","姓名", "工号", "密码","手机号码"));
+        writer.writeRow(Arrays.asList("院区", "姓名", "工号", "密码", "手机号码"));
 
         // 写入响应
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
@@ -109,7 +111,7 @@ public class ExcelController {
             in = file.getInputStream();
             ExcelReader reader = ExcelUtil.getReader(in);
             List<List<Object>> read = reader.read();
-            log.info("最开始:read={}",read);
+            log.info("最开始:read={}", read);
             log.info("-------------------------------假装我是个分割线------------------------------------");
             User user = (User) SecurityUtils.getSubject().getPrincipal();
             return userService.importUser(read, user);
@@ -118,6 +120,7 @@ public class ExcelController {
             throw new CostException(500, "导入失败");
         }
     }
+
     /**
      * 科室模板导出功能设置
      */
@@ -138,10 +141,10 @@ public class ExcelController {
         writer.passCurrentRow();
         writer.merge(2, 2, 0, 2, "医院科室批量导入", false);
         writer.passCurrentRow();
-        writer.setColumnWidth(0,20);
-        writer.setColumnWidth(1,15);
-        writer.setColumnWidth(2,15);
-        writer.writeRow(Arrays.asList("院区","科室名称", "科室代码"));
+        writer.setColumnWidth(0, 20);
+        writer.setColumnWidth(1, 15);
+        writer.setColumnWidth(2, 15);
+        writer.writeRow(Arrays.asList("院区", "科室名称", "科室代码"));
 
         // 写入响应
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
@@ -153,29 +156,32 @@ public class ExcelController {
         writer.close();
         IoUtil.close(out);
     }
+
     /**
      * 批量导入科室信息
      */
     @PostMapping("/importDepartment")
     @ApiOperation("导入科室信息")
-    public Result importDepartment(@RequestParam("file") MultipartFile file){
+    public Result importDepartment(@RequestParam("file") MultipartFile file) {
         InputStream in;
         try {
             in = file.getInputStream();
             ExcelReader reader = ExcelUtil.getReader(in);
             List<List<Object>> read = reader.read();
-            log.info("最开始:read={}",read);
+            log.info("最开始:read={}", read);
             log.info("-------------------------------------------------------------------");
             User user = (User) SecurityUtils.getSubject().getPrincipal();
             Long hospId = user.getHospId();
             return departmentService.importDepartment(read, hospId);
-        }catch (IOException e){
-            e.printStackTrace();;
+        } catch (IOException e) {
+            e.printStackTrace();
+            ;
             throw new CostException(500, "导入失败");
         }
     }
+
     /**
-     *  收入成本项目批量导入模板
+     * 收入成本项目批量导入模板
      */
     @ApiOperation("成本项目导出模板设置")
     @GetMapping("/getImportProductTemplate")
@@ -194,10 +200,10 @@ public class ExcelController {
         writer.passCurrentRow();
         writer.merge(2, 2, 0, 2, "医院成本收入批量导入", false);
         writer.passCurrentRow();
-        writer.setColumnWidth(0,20);
-        writer.setColumnWidth(1,15);
-        writer.setColumnWidth(2,15);
-        writer.writeRow(Arrays.asList("院区","成本项目名", "成本项目编号"));
+        writer.setColumnWidth(0, 20);
+        writer.setColumnWidth(1, 15);
+        writer.setColumnWidth(2, 15);
+        writer.writeRow(Arrays.asList("院区", "成本项目名", "成本项目编号"));
 
         // 写入响应
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
@@ -209,27 +215,30 @@ public class ExcelController {
         writer.close();
         IoUtil.close(out);
     }
+
     /**
-     *  收入成本项目批量导入
+     * 收入成本项目批量导入
      */
     @PostMapping("/importProduct")
     @ApiOperation("批量导入成本项目信息")
-    public Result importProduct(@RequestParam("file") MultipartFile file){
+    public Result importProduct(@RequestParam("file") MultipartFile file) {
         InputStream in;
         try {
             in = file.getInputStream();
             ExcelReader reader = ExcelUtil.getReader(in);
             List<List<Object>> read = reader.read();
-            log.info("最开始:read={}",read);
+            log.info("最开始:read={}", read);
             log.info("-------------------------------------------------------------------");
             User user = (User) SecurityUtils.getSubject().getPrincipal();
             Long hospId = user.getHospId();
             return productService.importProduct(read, hospId);
-        }catch (IOException e){
-            e.printStackTrace();;
+        } catch (IOException e) {
+            e.printStackTrace();
+            ;
             throw new CostException(500, "导入失败");
         }
     }
+
     /**
      * 收入成本数据导出模板
      */
@@ -252,17 +261,17 @@ public class ExcelController {
         writer.passCurrentRow();
         // 冻结前四行
         writer.setFreezePane(4);
-        writer.writeRow(Arrays.asList("成本项目代码","成本项目名称","开单科室","开单科室代码", "执行科室","执行科室代码","金额"));
-        int accountType=NumberConstant.ONE;
-        int column=NumberConstant.FOUR;
-        getProductByAccountType(hospId, writer,accountType,column);
-        writer.setColumnWidth(0,20);
-        writer.setColumnWidth(1,20);
-        writer.setColumnWidth(2,20);
-        writer.setColumnWidth(3,20);
-        writer.setColumnWidth(4,20);
-        writer.setColumnWidth(5,20);
-        writer.setColumnWidth(6,20);
+        writer.writeRow(Arrays.asList("成本项目代码", "成本项目名称", "开单科室", "开单科室代码", "执行科室", "执行科室代码", "金额"));
+        int accountType = NumberConstant.ONE;
+        int column = NumberConstant.FOUR;
+        getProductByAccountType(hospId, writer, accountType, column);
+        writer.setColumnWidth(0, 20);
+        writer.setColumnWidth(1, 20);
+        writer.setColumnWidth(2, 20);
+        writer.setColumnWidth(3, 20);
+        writer.setColumnWidth(4, 20);
+        writer.setColumnWidth(5, 20);
+        writer.setColumnWidth(6, 20);
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
         response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
         ServletOutputStream out = null;
@@ -271,6 +280,7 @@ public class ExcelController {
         writer.close();
         IoUtil.close(out);
     }
+
     /**
      * 成本数据导出模板
      */
@@ -295,19 +305,19 @@ public class ExcelController {
         // 设置科室的代码集合
         List<String> departmentCodeList = departmentLinkedList.stream().map(Department::getDepartmentCode).collect(Collectors.toList());
         List<String> departmentNameList = departmentLinkedList.stream().map(Department::getDepartmentName).collect(Collectors.toList());
-        departmentCodeList.add(0,null);
-        departmentCodeList.add(1,null);
+        departmentCodeList.add(0, null);
+        departmentCodeList.add(1, null);
         writer.writeRow(departmentCodeList);
-        departmentNameList.add(0,"成本项目代码");
-        departmentNameList.add(1,"成本项目名称");
+        departmentNameList.add(0, "成本项目代码");
+        departmentNameList.add(1, "成本项目名称");
         writer.writeRow(departmentNameList);
         // 设置科室名称的集合
         writer.setFreezePane(5);
-        int accountType=NumberConstant.TWO;
-        int column=NumberConstant.FIVE;
-        getProductByAccountType(hospId, writer,accountType,column);
-        writer.setColumnWidth(0,15);
-        writer.setColumnWidth(1,15);
+        int accountType = NumberConstant.TWO;
+        int column = NumberConstant.FIVE;
+        getProductByAccountType(hospId, writer, accountType, column);
+        writer.setColumnWidth(0, 15);
+        writer.setColumnWidth(1, 15);
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
         response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
         ServletOutputStream out = null;
@@ -316,14 +326,16 @@ public class ExcelController {
         writer.close();
         IoUtil.close(out);
     }
+
     /**
      * 获取执行类型的成本项目
-     * @param hospId 医院Id
-     * @param writer 操作流
+     *
+     * @param hospId      医院Id
+     * @param writer      操作流
      * @param accountType 会计科目类型 1 收入  2支出(成本)
-     * @param column 控制第几列
+     * @param column      控制第几列
      */
-    private void getProductByAccountType(Long hospId, ExcelWriter writer,Integer accountType,Integer column) {
+    private void getProductByAccountType(Long hospId, ExcelWriter writer, Integer accountType, Integer column) {
         // 所有的成本项目
         List<Product> productList = productService.list(new QueryWrapper<Product>().lambda().eq(Product::getHospId, hospId));
         // 所有成本会计对照数据
@@ -333,29 +345,30 @@ public class ExcelController {
         List<Product> products = new ArrayList<>();
         Map<Long, List<AccountingProduct>> accountProductMap = accountingProductList.stream().collect(Collectors.groupingBy(AccountingProduct::getProductId));
         Map<Long, List<Accounting>> accountMap = accountingList.stream().collect(Collectors.groupingBy(Accounting::getId));
-        productList.forEach(i->{
+        productList.forEach(i -> {
             Long productId = i.getId();
             List<AccountingProduct> accountingProducts = accountProductMap.get(productId);
-            if (CollUtil.isNotEmpty(accountingProducts)){
+            if (CollUtil.isNotEmpty(accountingProducts)) {
                 Long accountingId = accountingProducts.get(0).getAccountingId();
                 List<Accounting> accountings = accountMap.get(accountingId);
-                if (CollUtil.isNotEmpty(accountings) && accountType.equals(accountings.get(0).getAccountingType())){
+                if (CollUtil.isNotEmpty(accountings) && accountType.equals(accountings.get(0).getAccountingType())) {
                     products.add(i);
                 }
             }
         });
         // 写入响应第一列 第二列的数据
-        for (int j = 0; j<products.size(); j++){
-            writer.writeCellValue(0,j+column,productList.get(j).getProductCode());
-            writer.writeCellValue(1,j+column,productList.get(j).getProductName());
+        for (int j = 0; j < products.size(); j++) {
+            writer.writeCellValue(0, j + column, productList.get(j).getProductCode());
+            writer.writeCellValue(1, j + column, productList.get(j).getProductName());
         }
     }
+
     /**
      * 成本分摊参数导出模板
      */
     @GetMapping("/getShareParamTemplate")
     @ApiOperation("成本分摊参数导出模板")
-    public void getShareParamTemplate(HttpServletResponse response) throws IOException{
+    public void getShareParamTemplate(HttpServletResponse response) throws IOException {
         Long hospId = UserContext.getHospId();
         String uuid = UUID.randomUUID().toString();
         String url = System.getProperty("java.io.tmpdir") + File.separator + uuid + File.separator + uuid + ".xls";
@@ -374,22 +387,22 @@ public class ExcelController {
         // 设置科室的代码集合
         List<String> departmentCodeList = departmentLinkedList.stream().map(Department::getDepartmentCode).collect(Collectors.toList());
         List<String> departmentNameList = departmentLinkedList.stream().map(Department::getDepartmentName).collect(Collectors.toList());
-        departmentCodeList.add(0,null);
-        departmentCodeList.add(1,null);
+        departmentCodeList.add(0, null);
+        departmentCodeList.add(1, null);
         writer.writeRow(departmentCodeList);
-        departmentNameList.add(0,"成本分摊参数代码");
-        departmentNameList.add(1,"成本分摊参数名称");
+        departmentNameList.add(0, "成本分摊参数代码");
+        departmentNameList.add(1, "成本分摊参数名称");
         writer.writeRow(departmentNameList);
         // 设置科室名称的集合
         writer.setFreezePane(5);
         // 为第一列和第二列设置成本分摊参数的列表数据
         List<CostShareParam> costShareParamList = costShareParamService.list(new QueryWrapper<CostShareParam>().lambda().eq(CostShareParam::getHospId, hospId));
-        for (int j = 0; j<costShareParamList.size(); j++){
-            writer.writeCellValue(0,j+5,costShareParamList.get(j).getShareParamCode());
-            writer.writeCellValue(1,j+5,costShareParamList.get(j).getShareParamName());
+        for (int j = 0; j < costShareParamList.size(); j++) {
+            writer.writeCellValue(0, j + 5, costShareParamList.get(j).getShareParamCode());
+            writer.writeCellValue(1, j + 5, costShareParamList.get(j).getShareParamName());
         }
-        writer.setColumnWidth(0,15);
-        writer.setColumnWidth(1,15);
+        writer.setColumnWidth(0, 15);
+        writer.setColumnWidth(1, 15);
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
         response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
         ServletOutputStream out = null;
@@ -415,15 +428,17 @@ public class ExcelController {
         });
         return departmentLinkedList;
     }
+
     /**
-     *  导入 收入数据导入
+     * 导入 收入数据导入
+     *
      * @param file 导入的文件
      */
     @PostMapping("/importDataByFileType")
     @ApiOperation("批量导入指定类型数据信息")
-    public Result importProductAccount(@RequestParam("file") MultipartFile file,Integer year,Integer month){
-        if (Objects.isNull(file)){
-            throw new CostException(500,"请选择文件");
+    public Result importProductAccount(@RequestParam("file") MultipartFile file, Integer year, Integer month) {
+        if (Objects.isNull(file)) {
+            throw new CostException(500, "请选择文件");
         }
         InputStream in;
         // 导入的是收入数据
@@ -431,13 +446,44 @@ public class ExcelController {
             in = file.getInputStream();
             ExcelReader reader = ExcelUtil.getReader(in);
             List<List<Object>> read = reader.read();
-            log.info("最开始:read={}",read);
+            log.info("最开始:read={}", read);
             log.info("-------------------------------------------------------------------");
             User user = UserContext.getCurrentUser();
-            return costIncomeGroupService.importIncomeGroup(read, user,file,year,month);
-        }catch (IOException e){
-            e.printStackTrace();;
+            return costIncomeGroupService.importIncomeGroup(read, user, file, year, month);
+        } catch (IOException e) {
+            e.printStackTrace();
+            ;
             throw new CostException(500, "导入失败");
         }
     }
+
+    @ApiOperation("excel导入收入数据")
+    @PostMapping("/importDataByIncomeData")
+    public Result importDataByIncomeData(@RequestParam("file") MultipartFile file, Integer year, Integer month) {
+        if (Objects.isNull(year) || Objects.isNull(month)) {
+            DateTime dateTime = DateUtil.lastMonth();
+            year = DateUtil.year(dateTime);
+            month = DateUtil.month(dateTime);
+        }
+        if (Objects.isNull(file)) {
+            throw new CostException(500, "请选择文件");
+        }
+        InputStream in;
+        // 导入的是收入数据
+        try {
+            in = file.getInputStream();
+            ExcelReader reader = ExcelUtil.getReader(in);
+            List<List<Object>> read = reader.read();
+            log.info("最开始:read={}", read);
+            log.info("-------------------------------------------------------------------");
+            User user = UserContext.getCurrentUser();
+            return costIncomeGroupService.importDataByIncomeData(read, user, file, year, month);
+        } catch (IOException e) {
+            e.printStackTrace();
+            ;
+            throw new CostException(500, "导入失败");
+        }
+
+    }
+
 }

+ 12 - 0
src/main/resources/mapper/CostIncomeGroupMapper.xml

@@ -39,5 +39,17 @@
         <result property="deleteTime" column="delete_time"/>
     </resultMap>
 
+    <sql id="Base_Column_List" >
+    id, open_department_code, open_department_name, open_responsibility_code, open_responsibility_name, start_department_code, start_department_name, start_responsibility_code,
+    start_responsibility_name, product_code , product_name, account_code, account_name, open_department_amount, start_department_amount,amount,hosp_id,file_id,
+    doctor_number ,doctor_name,patient_id,outpatient_id,patient_name, patient_fee ,receipt_fee ,total_number ,unit ,fee_datetime,date_year,date_month,create_time,delete_time
+  </sql>
 
+    <select id="countMoney" resultType="com.imed.costaccount.model.vo.CostIncomeGroupAllAmountVO">
+        select
+        <include refid="Base_Column_List"/>
+        ,group_concat(amount) as addMoney
+        from cost_income_group
+        group by open_department_code , start_department_code , product_code;
+    </select>
 </mapper>