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

Merge branch 'master' of huangrui/CostAccount into dev

lijiaxi 4 éve
szülő
commit
fee74b1f9a

+ 2 - 3
src/main/java/com/imed/costaccount/mapper/CostIncomeGroupMapper.java

@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.imed.costaccount.model.CostIncomeGroup;
 import com.imed.costaccount.model.vo.CollectionVO;
 import com.imed.costaccount.model.vo.CostIncomeGroupAllAmountVO;
-import com.imed.costaccount.model.vo.CostIncomeGroupBeforeVO;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -21,10 +20,10 @@ public interface CostIncomeGroupMapper extends BaseMapper<CostIncomeGroup> {
     /**
      * 按照开单科室  执行科室 成本项目进行筛选相同的金额汇总
      *
-     * @param costIncomeGroupBeforeVOList
+     * @param idList
      * @return
      */
-    List<CostIncomeGroupAllAmountVO> countMoney(List<CostIncomeGroupBeforeVO> costIncomeGroupBeforeVOList);
+    List<CostIncomeGroupAllAmountVO> countMoney(@Param("idList") List<Long> idList);
 
     /**
      * 获取收入归集分页列表

+ 5 - 2
src/main/java/com/imed/costaccount/model/AfterIncomegroup.java

@@ -3,6 +3,7 @@ package com.imed.costaccount.model;
 import io.swagger.annotations.ApiModel;
 import lombok.Data;
 
+import java.io.Serializable;
 import java.math.BigDecimal;
 
 /**
@@ -12,7 +13,9 @@ import java.math.BigDecimal;
  */
 @Data
 @ApiModel("归集数据标记")
-public class AfterIncomegroup {
+public class AfterIncomegroup implements Serializable {
+
+    private static final long serialVersionUID = 1L;
 
     /**
      * 开单科室状态 1 收益中心 2 执行中心
@@ -52,5 +55,5 @@ public class AfterIncomegroup {
     /**
      * 是直接还是间接 1直接 2 间接
      */
-    private Integer directStatus=1;
+    private Integer directStatus = 1;
 }

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

@@ -1,132 +0,0 @@
-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;
-    }
-}

+ 154 - 130
src/main/java/com/imed/costaccount/service/impl/CostIncomeGroupServiceImpl.java

@@ -83,27 +83,36 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
      */
     @Override
     public PageUtils queryList(Integer current, Integer pageSize, String dateTime, String responsibilityCode, String accountCode, Long hospId) {
+        // 先检验当前年月是否存在数据
         int year = 0;
         int month = 0;
+        Date date = DateUtils.StringToDate(dateTime, DateStyleEnum.YYYY_MM);
         if (StrUtil.isNotBlank(dateTime)) {
-            year = DateUtils.getYear(dateTime);
-            month = DateUtils.getMonth(dateTime);
+            year = DateUtil.year(date);
+            month = DateUtil.month(date) + 1;
         }
         Page<CostIncomeGroup> costIncomeGroupPage = new Page<>(current, pageSize);
         Page<CostIncomeGroup> pages = this.page(costIncomeGroupPage, new QueryWrapper<CostIncomeGroup>().lambda()
                 .eq(Objects.nonNull(hospId), CostIncomeGroup::getHospId, hospId)
                 .eq(!NumberConstant.ZERO.equals(year), CostIncomeGroup::getDateYear, year)
-                .eq(!NumberConstant.ONE.equals(month), CostIncomeGroup::getDateMonth, month)
+                .eq(!NumberConstant.ZERO.equals(month), CostIncomeGroup::getDateMonth, month)
                 .and(StrUtil.isNotBlank(responsibilityCode), i -> i.like(CostIncomeGroup::getOpenResponsibilityCode, responsibilityCode)
                         .or().like(CostIncomeGroup::getStartResponsibilityCode, responsibilityCode))
                 .like(StrUtil.isNotBlank(accountCode), CostIncomeGroup::getAccountCode, accountCode));
         List<CostIncomeGroup> records = pages.getRecords();
         List<CostIncomeGroupBeforeVO> costIncomeGroupBeforeVOList = BeanUtil.convertList(records, CostIncomeGroupBeforeVO.class);
-        // 查询所有的责任中心 科室 会计科目  成本项目的数据  处理名字
-        // TODO 修改直接获取名字
-        setCodeName(hospId, costIncomeGroupBeforeVOList);
+        if (CollectionUtils.isEmpty(costIncomeGroupBeforeVOList)){
+            PageUtils pageUtils = new PageUtils(pages);
+            pageUtils.setList(null);
+            pageUtils.setTotalAmount(new BigDecimal(0.0000));
+            return pageUtils;
+        }
+
         // 进行金额合并
-        List<CostIncomeGroupAllAmountVO> costIncomeGroupAllAmountVoS = baseMapper.countMoney(costIncomeGroupBeforeVOList);
+        List<Long> idList = costIncomeGroupBeforeVOList.stream().map(CostIncomeGroupBeforeVO::getId).collect(Collectors.toList());
+        List<CostIncomeGroupAllAmountVO> costIncomeGroupAllAmountVoS = baseMapper.countMoney(idList);
+        // 查询所有的责任中心 科室 会计科目  成本项目的数据  处理名字
+        setCodeName(costIncomeGroupAllAmountVoS);
         //  对,的金额进行合并
         AtomicReference<BigDecimal> totalAmount = new AtomicReference<>(new BigDecimal("0.0000"));
         costIncomeGroupAllAmountVoS.forEach(i -> {
@@ -150,11 +159,7 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
             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) {
-                list.remove(list.get(i));
-            }
-        }
+        removeTitle(list);
         log.info("读取的数据为:{}", list);
         List<IncomeErrorMessage> incomeErrorMessageList = new ArrayList<>();
         //获取所有的科室 成本项目 责任中心 会计科目
@@ -198,6 +203,14 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
         }
     }
 
+    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));
+            }
+        }
+    }
+
     /**
      * 返回成本会计对照数据  Key 成本项目Id   Value 会计科目Id
      *
@@ -282,6 +295,10 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
      */
     @Override
     public Result importDataByIncomeData(List<List<Object>> read, User user, MultipartFile file, Integer year, Integer month) {
+        // 去头
+        this.removeTitle(read);
+
+
         return null;
     }
 
@@ -302,10 +319,11 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
      */
     private void checkImportData(List<List<Object>> list, List<IncomeErrorMessage> incomeErrorMessageList, List<CostIncomeGroup> costIncomeGroupArrayList, Map<String, Department> departmentMap, Map<String, Product> productMap, Map<Long, Responsibility> responsibilityMap, Map<Long, Accounting> accountingMap, Map<Long, Long> responsibilityDepMap, Map<Long, Long> accountProMap, Long hospId, Integer year, Integer month) {
         for (int i = 0; i < list.size(); i++) {
+            int row = i + 5;
             CostIncomeGroup costIncomeGroup = new CostIncomeGroup();
             AfterIncomegroup afterIncomegroup = new AfterIncomegroup();
             // 用来检验数据合理性的循环
-            IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
+
             List<Object> data = list.get(i);
             log.info("用户输入的数据是{}", data);
             // 成本项目的代码和名称
@@ -316,15 +334,15 @@ 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.valueOf(Double.parseDouble(data.get(15).toString()));
+            BigDecimal beforeMoney = BigDecimal.valueOf(Double.parseDouble(("0".equals(data.get(15).toString()) || StrUtil.isBlank(data.get(15).toString())) ?"0.00":data.get(15).toString()));
             boolean checkNull = StrUtil.isBlank(data.get(15).toString());
-            boolean checkOne = NumberConstant.ZERO.equals(data.get(15).toString());
+            boolean checkOne = "0".equals(data.get(15).toString());
             if (checkNull || checkOne) {
                 // 要求这一行的数据必须全部填写
-                for (int j = 0; j < NumberConstant.FIVE; j++) {
+                for (int j = 0; j < data.size(); j++) {
                     if (Objects.isNull(data.get(j))) {
+                        IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
                         incomeErrorMessage.setTotal(i);
-                        int row = i + 1;
                         int column = j + 1;
                         incomeErrorMessage.setErrMessage("第{" + row + "}行第{" + column + "}列数据为空");
                         incomeErrorMessageList.add(incomeErrorMessage);
@@ -335,154 +353,160 @@ 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 (StrUtil.isNotBlank(productCode) && StrUtil.isNotBlank(productName)) {
-                    if (Objects.isNull(product)) {
-                        incomeErrorMessage.setTotal(i);
-                        incomeErrorMessage.setErrMessage("代码:" + productCode + " 名称:" + productName + "成本项目不存在");
+            if (StrUtil.isNotBlank(productCode) && StrUtil.isNotBlank(productName)) {
+                if (Objects.isNull(product)) {
+                    IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
+                    incomeErrorMessage.setTotal(row);
+                    incomeErrorMessage.setErrMessage("成本项目代码:" + productCode + " 名称:" + productName + "不存在");
+                    incomeErrorMessageList.add(incomeErrorMessage);
+                } else {
+                    // 检验对应的会计科目是否存在
+                    Long id = product.getId();
+                    Long accountId = accountProMap.get(id);
+                    if (Objects.isNull(accountingMap.get(accountId))) {
+                        IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
+                        incomeErrorMessage.setTotal(row);
+                        incomeErrorMessage.setErrMessage("成本项目代码:" + productCode + " 名称:" + productName + "对应的会计科目不存在");
                         incomeErrorMessageList.add(incomeErrorMessage);
                     } else {
-                        // 检验对应的会计科目是否存在
-                        Long id = product.getId();
-                        Long accountId = accountProMap.get(id);
-                        if (Objects.isNull(accountingMap.get(accountId))) {
-                            incomeErrorMessage.setTotal(i);
-                            incomeErrorMessage.setErrMessage("代码:" + productCode + " 名称:" + productName + "成本项目对应的会计科目不存在");
-                            incomeErrorMessageList.add(incomeErrorMessage);
-                        } else {
-                            costIncomeGroup.setProductCode(productCode);
-                            costIncomeGroup.setProductName(productName);
-                            costIncomeGroup.setAccountCode(accountingMap.get(accountId).getAccountingCode());
-                            costIncomeGroup.setAccountName(accountingMap.get(accountId).getAccountingName());
-                        }
+                        costIncomeGroup.setProductCode(productCode);
+                        costIncomeGroup.setProductName(productName);
+                        costIncomeGroup.setAccountCode(accountingMap.get(accountId).getAccountingCode());
+                        costIncomeGroup.setAccountName(accountingMap.get(accountId).getAccountingName());
                     }
-                } else {
-                    costIncomeGroup.setProductCode(null);
-                    costIncomeGroup.setProductName(null);
-                    costIncomeGroup.setAccountCode(null);
-                    costIncomeGroup.setAccountName(null);
                 }
+            } else {
+                costIncomeGroup.setProductCode(null);
+                costIncomeGroup.setProductName(null);
+                costIncomeGroup.setAccountCode(null);
+                costIncomeGroup.setAccountName(null);
             }
             // 检验开单科室
-            if (!checkNull && !checkOne) {
-                if (StrUtil.isNotBlank(openDepartmentCode) && StrUtil.isNotBlank(openDepartmentName)) {
-                    // 开单科室
-                    if (Objects.isNull(department)) {
-                        incomeErrorMessage.setTotal(i);
-                        incomeErrorMessage.setErrMessage("代码:" + productCode + " 名称:" + productName + "开单科室不存在");
+            if (StrUtil.isNotBlank(openDepartmentCode) && StrUtil.isNotBlank(openDepartmentName)) {
+                // 开单科室
+                if (Objects.isNull(department)) {
+                    IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
+                    incomeErrorMessage.setTotal(row);
+                    incomeErrorMessage.setErrMessage("开单科室代码:" + openDepartmentCode + " 科室名称:" + openDepartmentName + "不存在");
+                    incomeErrorMessageList.add(incomeErrorMessage);
+                } else {
+                    Long id = department.getId();
+                    Long responsibilityId = responsibilityDepMap.get(id);
+                    if (Objects.isNull(responsibilityMap.get(responsibilityId))) {
+                        IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
+                        incomeErrorMessage.setTotal(row);
+                        incomeErrorMessage.setErrMessage("开单科室代码代码:" + openDepartmentCode + " 科室名称:" + openDepartmentName + "对应的责任中心不存在");
                         incomeErrorMessageList.add(incomeErrorMessage);
                     } else {
-                        Long id = department.getId();
-                        Long responsibilityId = responsibilityDepMap.get(id);
-                        if (Objects.isNull(responsibilityMap.get(responsibilityId))) {
-                            incomeErrorMessage.setTotal(i);
-                            incomeErrorMessage.setErrMessage("代码:" + openDepartmentCode + " 名称:" + openDepartmentName + "科室对应的责任中心不存在");
-                            incomeErrorMessageList.add(incomeErrorMessage);
-                        } else {
-                            Responsibility responsibility = responsibilityMap.get(responsibilityId);
-                            costIncomeGroup.setOpenDepartmentCode(openDepartmentCode);
-                            costIncomeGroup.setOpenDepartmentName(openDepartmentName);
-                            costIncomeGroup.setOpenResponsibilityCode(responsibility.getResponsibilityCode());
-                            costIncomeGroup.setOpenResponsibilityName(responsibility.getResponsibilityName());
-                            afterIncomegroup.setOpenDepartmentCode(openDepartmentCode);
-                            afterIncomegroup.setOpenDepartmentName(openDepartmentName);
-                            afterIncomegroup.setOpenDepartmentStatus(responsibility.getResponsibilityType());
-                        }
+                        Responsibility responsibility = responsibilityMap.get(responsibilityId);
+                        costIncomeGroup.setOpenDepartmentCode(openDepartmentCode);
+                        costIncomeGroup.setOpenDepartmentName(openDepartmentName);
+                        costIncomeGroup.setOpenResponsibilityCode(responsibility.getResponsibilityCode());
+                        costIncomeGroup.setOpenResponsibilityName(responsibility.getResponsibilityName());
+                        afterIncomegroup.setOpenDepartmentCode(openDepartmentCode);
+                        afterIncomegroup.setOpenDepartmentName(openDepartmentName);
+                        afterIncomegroup.setOpenDepartmentStatus(responsibility.getResponsibilityType());
                     }
-                } else {
-                    costIncomeGroup.setOpenDepartmentCode(null);
-                    costIncomeGroup.setOpenDepartmentName(null);
-                    costIncomeGroup.setOpenResponsibilityCode(null);
-                    costIncomeGroup.setOpenResponsibilityName(null);
                 }
+            } else {
+                costIncomeGroup.setOpenDepartmentCode(null);
+                costIncomeGroup.setOpenDepartmentName(null);
+                costIncomeGroup.setOpenResponsibilityCode(null);
+                costIncomeGroup.setOpenResponsibilityName(null);
             }
             // 检验执行科室
-            if (!checkNull && !checkOne) {
-                if (StrUtil.isNotBlank(startDepartmentCode) && StrUtil.isNotBlank(startDepartmentName)) {
-                    //执行科室
-                    if (Objects.isNull(department1)) {
-                        incomeErrorMessage.setTotal(i);
-                        incomeErrorMessage.setErrMessage("代码:" + productCode + " 名称:" + productName + "执行科室不存在");
+            if (StrUtil.isNotBlank(startDepartmentCode) && StrUtil.isNotBlank(startDepartmentName)) {
+                //执行科室
+                if (Objects.isNull(department1)) {
+                    IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
+                    incomeErrorMessage.setTotal(row);
+                    incomeErrorMessage.setErrMessage("执行科室代码:" + startDepartmentCode + " 科室名称:" + startDepartmentName + "科室不存在");
+                    incomeErrorMessageList.add(incomeErrorMessage);
+                } else {
+                    Long id = department1.getId();
+                    Long responsibilityId = responsibilityDepMap.get(id);
+                    if (Objects.isNull(responsibilityMap.get(responsibilityId))) {
+                        IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
+                        incomeErrorMessage.setTotal(row);
+                        incomeErrorMessage.setErrMessage("执行科室代码:" + openDepartmentCode + " 名称:" + openDepartmentName + "对应的责任中心不存在");
                         incomeErrorMessageList.add(incomeErrorMessage);
                     } else {
-                        Long id = department1.getId();
-                        Long responsibilityId = responsibilityDepMap.get(id);
-                        if (Objects.isNull(responsibilityMap.get(responsibilityId))) {
-                            incomeErrorMessage.setTotal(i);
-                            incomeErrorMessage.setErrMessage("代码:" + openDepartmentCode + " 名称:" + openDepartmentName + "科室对应的责任中心不存在");
-                            incomeErrorMessageList.add(incomeErrorMessage);
-                        } else {
-                            Responsibility responsibility = responsibilityMap.get(responsibilityId);
-                            costIncomeGroup.setStartDepartmentCode(startDepartmentCode);
-                            costIncomeGroup.setStartDepartmentName(startDepartmentName);
-                            costIncomeGroup.setStartResponsibilityCode(responsibility.getResponsibilityCode());
-                            costIncomeGroup.setStartResponsibilityName(responsibility.getResponsibilityName());
-                            afterIncomegroup.setStartDepartmentCode(startDepartmentCode);
-                            afterIncomegroup.setStartDepartmentName(startDepartmentName);
-                            afterIncomegroup.setStartDepartmentStatus(responsibility.getResponsibilityType());
-                        }
+                        Responsibility responsibility = responsibilityMap.get(responsibilityId);
+                        costIncomeGroup.setStartDepartmentCode(startDepartmentCode);
+                        costIncomeGroup.setStartDepartmentName(startDepartmentName);
+                        costIncomeGroup.setStartResponsibilityCode(responsibility.getResponsibilityCode());
+                        costIncomeGroup.setStartResponsibilityName(responsibility.getResponsibilityName());
+                        afterIncomegroup.setStartDepartmentCode(startDepartmentCode);
+                        afterIncomegroup.setStartDepartmentName(startDepartmentName);
+                        afterIncomegroup.setStartDepartmentStatus(responsibility.getResponsibilityType());
                     }
-                } else {
-                    costIncomeGroup.setStartDepartmentCode(null);
-                    costIncomeGroup.setStartDepartmentName(null);
-                    costIncomeGroup.setStartResponsibilityCode(null);
-                    costIncomeGroup.setStartResponsibilityName(null);
                 }
+            } else {
+                costIncomeGroup.setStartDepartmentCode(null);
+                costIncomeGroup.setStartDepartmentName(null);
+                costIncomeGroup.setStartResponsibilityCode(null);
+                costIncomeGroup.setStartResponsibilityName(null);
             }
             costIncomeGroup.setDoctorNumber(Long.parseLong(data.get(6).toString())).setDoctorName(data.get(7).toString())
                     .setPatientId(Long.parseLong(data.get(8).toString())).setOutpatientId(Long.parseLong(data.get(9).toString()))
                     .setPatientName(data.get(10).toString()).setPatientFee(data.get(11).toString()).setReceiptFee(data.get(12).toString())
                     .setTotalNumber(Integer.parseInt(data.get(13).toString())).setUnit(data.get(14).toString())
-                    .setFeeDatetime(DateUtils.StringToDate(data.get(16).toString(), DateStyleEnum.YYYY_MM_DD_HH_MM_SS_EN));
-            if (StrUtil.isNotBlank(costIncomeGroup.getOpenResponsibilityCode())) {
-
-            }
+                    .setFeeDatetime(DateUtils.StringToDate(data.get(16).toString(), DateStyleEnum.YYYY_MM_DD_HH_MM_SS));
             costIncomeGroup.setHospId(hospId);
             costIncomeGroup.setCreateTime(System.currentTimeMillis());
             costIncomeGroup.setDateYear(year);
             costIncomeGroup.setDateMonth(month);
             costIncomeGroup.setAmount(beforeMoney);
             // 检验数据
-            Integer openDepartmentStatus = afterIncomegroup.getOpenDepartmentStatus();
-            Integer startDepartmentStatus = afterIncomegroup.getStartDepartmentStatus();
-            if (Objects.nonNull(openDepartmentStatus) && Objects.nonNull(startDepartmentStatus)) {
-                Map<String, CostIncomeGroupSet> incomeGroupSetMap = costIncomeGroupSetService.list(new QueryWrapper<CostIncomeGroupSet>().lambda().eq(CostIncomeGroupSet::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getOpenDepartmentStatus().toString() + k.getStartDepartmentStatus().toString(), synOe -> synOe));
-                CostIncomeGroupSet costIncomeGroupSet = incomeGroupSetMap.get(openDepartmentStatus.toString() + startDepartmentStatus.toString());
-                if (Objects.nonNull(costIncomeGroupSet)) {
-                    Map<String, Responsibility> map = responsibilityService.list(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId, hospId)).stream().collect(Collectors.toMap(Responsibility::getResponsibilityCode, synOe -> synOe));
-                    // 开单科室比例
-                    BigDecimal openDepartmentProportion = new BigDecimal(costIncomeGroupSet.getOpenDepartmentProportion().toString());
-                    // 执行科室比例
-                    BigDecimal startDepartmentProportion = new BigDecimal(costIncomeGroupSet.getStartDepartmentProportion().toString());
-                    // beforeMoney
-                    afterIncomegroup.setOpenDepartmentDecimal(beforeMoney.multiply(openDepartmentProportion).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP));
-                    afterIncomegroup.setStartDepartmentDecimal(beforeMoney.multiply(startDepartmentProportion).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP));
-                    String responsibilityCodes = costIncomeGroupSet.getResponsibilityCodes();
-                    if (NumberConstant.TWO.equals(costIncomeGroupSet.getOpenDepartmentStatus()) && NumberConstant.TWO.equals(costIncomeGroupSet.getStartDepartmentStatus()) && StrUtil.isNotBlank(responsibilityCodes)) {
-                        // /拼接的
-                        afterIncomegroup.setDirectStatus(NumberConstant.TWO);
-                        String responsibilityCode = responsibilityCodes.split(StrUtil.SLASH)[responsibilityCodes.split(StrUtil.SLASH).length - 1];
-                        Responsibility responsibility = map.get(responsibilityCode);
-                        if (Objects.nonNull(responsibility)) {
-                            afterIncomegroup.setResponsibilityCode(responsibility.getResponsibilityCode());
-                            afterIncomegroup.setResponsibilityName(responsibility.getResponsibilityName());
-                        }
-                        costIncomeGroup.setAfterIncomeGroup(JSON.toJSONString(afterIncomegroup));
+            getAfterData(hospId, costIncomeGroup, afterIncomegroup, beforeMoney);
+            costIncomeGroupArrayList.add(costIncomeGroup);
+        }
+    }
+
+    /**
+     * 封装需要的数据
+     * @param hospId
+     * @param costIncomeGroup
+     * @param afterIncomegroup
+     * @param beforeMoney
+     */
+    private void getAfterData(Long hospId, CostIncomeGroup costIncomeGroup, AfterIncomegroup afterIncomegroup, BigDecimal beforeMoney) {
+        Integer openDepartmentStatus = afterIncomegroup.getOpenDepartmentStatus();
+        Integer startDepartmentStatus = afterIncomegroup.getStartDepartmentStatus();
+        if (Objects.nonNull(openDepartmentStatus) && Objects.nonNull(startDepartmentStatus)) {
+            Map<String, CostIncomeGroupSet> incomeGroupSetMap = costIncomeGroupSetService.list(new QueryWrapper<CostIncomeGroupSet>().lambda().eq(CostIncomeGroupSet::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getOpenDepartmentStatus().toString() + k.getStartDepartmentStatus().toString(), synOe -> synOe));
+            CostIncomeGroupSet costIncomeGroupSet = incomeGroupSetMap.get(openDepartmentStatus.toString() + startDepartmentStatus.toString());
+            if (Objects.nonNull(costIncomeGroupSet)) {
+                Map<String, Responsibility> map = responsibilityService.list(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId, hospId)).stream().collect(Collectors.toMap(Responsibility::getResponsibilityCode, synOe -> synOe));
+                // 开单科室比例
+                BigDecimal openDepartmentProportion = new BigDecimal(costIncomeGroupSet.getOpenDepartmentProportion().toString());
+                // 执行科室比例
+                BigDecimal startDepartmentProportion = new BigDecimal(costIncomeGroupSet.getStartDepartmentProportion().toString());
+                // beforeMoney
+                afterIncomegroup.setOpenDepartmentDecimal(beforeMoney.multiply(openDepartmentProportion).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP));
+                afterIncomegroup.setStartDepartmentDecimal(beforeMoney.multiply(startDepartmentProportion).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP));
+                String responsibilityCodes = costIncomeGroupSet.getResponsibilityCodes();
+                if (NumberConstant.TWO.equals(costIncomeGroupSet.getOpenDepartmentStatus()) && NumberConstant.TWO.equals(costIncomeGroupSet.getStartDepartmentStatus()) && StrUtil.isNotBlank(responsibilityCodes)) {
+                    // /拼接的
+                    afterIncomegroup.setDirectStatus(NumberConstant.TWO);
+                    String responsibilityCode = responsibilityCodes.split(StrUtil.SLASH)[responsibilityCodes.split(StrUtil.SLASH).length - 1];
+                    Responsibility responsibility = map.get(responsibilityCode);
+                    if (Objects.nonNull(responsibility)) {
+                        afterIncomegroup.setResponsibilityCode(responsibility.getResponsibilityCode());
+                        afterIncomegroup.setResponsibilityName(responsibility.getResponsibilityName());
                     }
+                    costIncomeGroup.setAfterIncomeGroup(JSON.toJSONString(afterIncomegroup));
                 }
             }
-
-            costIncomeGroupArrayList.add(costIncomeGroup);
         }
     }
 
     /**
      * 设置相关名称
      *
-     * @param hospId
-     * @param costIncomeGroupBeforeVOList
+     * @param costIncomeGroupAllAmountVOList
      */
-    private void setCodeName(Long hospId, List<CostIncomeGroupBeforeVO> costIncomeGroupBeforeVOList) {
+    private void setCodeName(List<CostIncomeGroupAllAmountVO> costIncomeGroupAllAmountVOList) {
 //        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));
@@ -491,13 +515,13 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
 //        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 -> {
+        costIncomeGroupAllAmountVOList.forEach(i -> {
             // 以为这里的数据导入的  在导入的时候进行数据校验
             // 设置开单科室名称 执行科室名称  开单责任中心名称  执行责任中心名称 成本项目的名称 会计科目名称
             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.setStartResponsibilityCodeName("[" + i.getStartResponsibilityCode() + "]" + i.getStartResponsibilityName());
             i.setProductCodeName("[" + i.getProductCode() + "]" + i.getProductName());
             i.setAccountCodeName("[" + i.getAccountCode() + "]" + i.getAccountName());
         });

+ 28 - 17
src/main/java/com/imed/costaccount/service/impl/IncomeCollectionServiceImpl.java

@@ -1,29 +1,26 @@
 package com.imed.costaccount.service.impl;
 
 import cn.hutool.core.util.StrUtil;
-import cn.hutool.extra.template.TemplateUtil;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.imed.costaccount.common.constants.Constant;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.imed.costaccount.common.exception.CostException;
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.mapper.CostIncomeGroupMapper;
+import com.imed.costaccount.mapper.IncomeCollectionMapper;
+import com.imed.costaccount.model.AfterIncomegroup;
 import com.imed.costaccount.model.CostIncomeGroup;
+import com.imed.costaccount.model.IncomeCollection;
 import com.imed.costaccount.model.dto.CollectDTO;
 import com.imed.costaccount.model.vo.CollectedVO;
 import com.imed.costaccount.model.vo.CollectionVO;
+import com.imed.costaccount.service.IncomeCollectionService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-
-import com.imed.costaccount.mapper.IncomeCollectionMapper;
-import com.imed.costaccount.model.IncomeCollection;
-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;
 
@@ -112,24 +109,38 @@ public class IncomeCollectionServiceImpl
             incomeCollection.setAccountingName(costIncomeGroup.getAccountName());
             incomeCollection.setProductName(costIncomeGroup.getProductName());
             incomeCollection.setProductCode(costIncomeGroup.getProductCode());
+            incomeCollection.setAmount(costIncomeGroup.getAmount());
             incomeCollection.setHospId(hospId);
             // todo 来源id暂时不确定
             incomeCollection.setFileId(costIncomeGroup.getFileId());
             incomeCollection.setCreateTime(System.currentTimeMillis());
-            // TODO: 2021/8/10 待确认是否收入中心
+            String afterIncomeGroupStr = costIncomeGroup.getAfterIncomeGroup();
+            AfterIncomegroup afterIncomegroup = JSONUtil.toBean(afterIncomeGroupStr, AfterIncomegroup.class);
+            if (Objects.isNull(afterIncomegroup)) {
+                throw new CostException("未能正确归集对应的....");
+            }
+            // 转换一下其他的
+            if (afterIncomegroup.getDirectStatus() == 2) {
+                afterIncomegroup.setDirectStatus(0);
+            }
+            incomeCollection.setIsDirectIncome(afterIncomegroup.getDirectStatus());
             // 开单中心的数据
-            incomeCollection.setDepartmentCode(costIncomeGroup.getOpenDepartmentCode());
-            incomeCollection.setResponsibilityCode(costIncomeGroup.getOpenResponsibilityCode());
-            incomeCollection.setAmount(costIncomeGroup.getOpenDepartmentAmount());
+            incomeCollection.setDepartmentCode(afterIncomegroup.getOpenDepartmentCode());
+            incomeCollection.setDepartmentName(afterIncomegroup.getOpenDepartmentName());
+            incomeCollection.setResponsibilityCode(afterIncomegroup.getResponsibilityCode());
+            incomeCollection.setResponsibilityName(afterIncomegroup.getResponsibilityName());
+
             list.add(incomeCollection);
             // 执行科室数据
-            incomeCollection.setDepartmentCode(costIncomeGroup.getStartDepartmentCode());
-            incomeCollection.setResponsibilityCode(costIncomeGroup.getStartResponsibilityCode());
-            incomeCollection.setAmount(costIncomeGroup.getStartDepartmentAmount());
+            incomeCollection.setDepartmentCode(afterIncomegroup.getStartDepartmentCode());
+            incomeCollection.setDepartmentName(afterIncomegroup.getStartDepartmentName());
+            incomeCollection.setResponsibilityCode(afterIncomegroup.getResponsibilityCode());
+            incomeCollection.setResponsibilityName(afterIncomegroup.getResponsibilityName());
             list.add(incomeCollection);
         });
 
-        // TODO: 2021/8/10 几十万条数据如何处理
+
+        // TODO: 2021/8/10 几十万条数据如何处理 待测试处理
         this.saveBatch(list);
     }
 

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

@@ -481,33 +481,33 @@ public class ExcelController {
         }
     }
 
-    @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, "导入失败");
-        }
-
-    }
+//    @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, "导入失败");
+//        }
+//
+//    }
 
 }

+ 1 - 1
src/main/resources/application-dev.yml

@@ -27,7 +27,7 @@ spring:
   redis:
     port: 6379
     host: 112.124.59.133
-    password: zjxy!@#2021
+    password: xywl!@#2021
     jedis:
       pool:
         max-active: 30

+ 29 - 3
src/main/resources/mapper/CostIncomeGroupMapper.xml

@@ -5,7 +5,7 @@
 
 	<!-- 可根据自己的需求,是否要使用 -->
     <resultMap type="com.imed.costaccount.model.CostIncomeGroup" id="costIncomeGroupMap">
-        <result property="id" column="id"/>
+        <result property="id" jdbcType="BIGINT" column="id"/>
         <result property="openDepartmentCode" column="open_department_code"/>
         <result property="openDepartmentName" column="open_department_name"/>
         <result property="openResponsibilityCode" column="open_responsibility_code"/>
@@ -49,8 +49,34 @@
     <select id="countMoney" resultType="com.imed.costaccount.model.vo.CostIncomeGroupAllAmountVO">
         select
         <include refid="Base_Column_List"/>
-        ,group_concat(amount) as addMoney
+        ,group_concat(amount) as allMoney
         from cost_income_group
-        group by open_department_code , start_department_code , product_code;
+        where id IN
+        <foreach close=")" collection="idList" item="item" open="(" separator=",">
+            #{item}
+        </foreach>
+        group by open_department_code , start_department_code , product_code
     </select>
+
+    <select id="getCollections" resultType="com.imed.costaccount.model.vo.CollectionVO">
+        select file_id, date_year, date_month, sum(amount) as amount
+        from cost_income_group
+        where hosp_id = #{hospId}
+        <if test="date != null and date != ''">
+            date_year = YEAR(concat(#{date},'01')) and date_month = MONTH(concat(#{date},'01'))
+        </if>
+        group by date_month, date_year
+        limit #{startIndex},#{pageSize}
+    </select>
+
+    <select id="getCollectionCount" resultType="java.lang.Integer">
+        select count(*)
+        from cost_income_group
+        where hosp_id = #{hospId}
+        <if test="date != null and date != ''">
+            date_year = YEAR(concat(#{date},'01')) and date_month = MONTH(concat(#{date},'01'))
+        </if>
+    </select>
+
+
 </mapper>