ljx 4 лет назад
Родитель
Сommit
5d3d66ba56

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

@@ -0,0 +1,90 @@
+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 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;
+
+    public GetCheckData(Long hospId) {
+        this.hospId = hospId;
+    }
+
+    public Map<String, Department> getDepartmentMap() {
+        return departmentMap;
+    }
+
+    public Map<String, Product> getProductMap() {
+        return productMap;
+    }
+
+    public Map<Long, Responsibility> getResponsibilityMap() {
+        return responsibilityMap;
+    }
+
+    public Map<Long, Accounting> getAccountingMap() {
+        return accountingMap;
+    }
+
+    public Map<Long, Long> getResponsibilityDepMap() {
+        return responsibilityDepMap;
+    }
+
+    public Map<Long, Long> getAccountProMap() {
+        return accountProMap;
+    }
+
+    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));
+        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;
+    }
+}

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

@@ -2,6 +2,11 @@ package com.imed.costaccount.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 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 +17,16 @@ 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);
 }
 

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

@@ -1,14 +1,52 @@
 package com.imed.costaccount.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+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.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;
+    }
 }

+ 32 - 65
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;
@@ -100,11 +99,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());
@@ -112,10 +110,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;
     }
 
@@ -132,27 +131,23 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
     public Result importIncomeGroup(List<List<Object>> list, User user, MultipartFile file,Integer year,Integer month) {
         Long hospId = user.getHospId();
         // 移除前几行的抬头内容  list的大小对应的就是行数的大小
-        this.removeTitle(list);
+        for (int i = list.size() - 1; i >= 0; i--) {
+            if (i == NumberConstant.ZERO || i == NumberConstant.ONE || i == NumberConstant.TWO || i == NumberConstant.THREE) {
+                list.remove(list.get(i));
+            }
+        }
         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));
-        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, "没有成本会计对照数据");
-        }
-        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));
+        GetCheckData getCheckData = new GetCheckData(hospId).invoke();
+        Map<String, Department> departmentMap = getCheckData.getDepartmentMap();
+        Map<String, Product> productMap = getCheckData.getProductMap();
+        Map<Long, Responsibility> responsibilityMap = getCheckData.getResponsibilityMap();
+        Map<Long, Accounting> accountingMap = getCheckData.getAccountingMap();
+        Map<Long, Long> responsibilityDepMap = getCheckData.getResponsibilityDepMap();
+        Map<Long, Long> accountProMap = getCheckData.getAccountProMap();
         List<CostIncomeGroup> costIncomeGroupArrayList = new ArrayList<>();
-        // 检验数据  TODO 缺少文件Id
+        // 检验数据
         checkImportData(list, incomeErrorMessageList, costIncomeGroupArrayList, departmentMap, productMap, responsibilityMap, accountingMap, responsibilityDepMap, accountProMap,hospId,year,month);
 
         // 文件上传
@@ -162,23 +157,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
@@ -190,14 +169,22 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
         return Result.ok();
     }
 
-    private void removeTitle(List<List<Object>> list) {
-        for (int i = list.size() - 1; i >= 0; i--) {
-            if (i == NumberConstant.ZERO || i == NumberConstant.ONE || i == NumberConstant.TWO || i == NumberConstant.THREE) {
-                list.remove(list.get(i));
-            }
-        }
+    /**
+     * 导入收入数据
+     *
+     * @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                     表单数据
@@ -397,24 +384,4 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
     }
 
 
-    /**
-     * 导入收入数据
-     *
-     * @param read  读取到的初始数据
-     * @param user  当前登录用户
-     * @param file  导入的文件
-     * @param year  年
-     * @param month 月
-     * @return {@link Result}
-     */
-    @Override
-    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
-    public Result importDataByIncomeData(List<List<Object>> read, User user, MultipartFile file, Integer year, Integer month) {
-        // todo 文件上传
-
-        // 去掉头部的
-        this.removeTitle(read);
-
-        return null;
-    }
 }

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

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