Kaynağa Gözat

08 25 01 分摊后查询

hr 4 yıl önce
ebeveyn
işleme
96f58187f9

+ 1 - 0
src/main/java/com/imed/costaccount/common/shiro/ShiroConfig.java

@@ -42,6 +42,7 @@ public class ShiroConfig {
         filterMap.put("/v2/api-docs", "anon");
         filterMap.put("/swagger-ui.html", "anon");
         filterMap.put("/static/js/**", "anon");
+        filterMap.put("/demo", "anon");
         filterMap.put("/doc.html", "anon");
         filterMap.put("/swagger-resources/**", "anon");
         filterMap.put("/captcha.jpg", "anon");

+ 16 - 0
src/main/java/com/imed/costaccount/mapper/AllocationQueryMapper.java

@@ -0,0 +1,16 @@
+package com.imed.costaccount.mapper;
+
+import com.imed.costaccount.model.AllocationQuery;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 
+ * 
+ * @author huangrui
+ * @date 2021-08-26 08:51:45
+ */
+@Mapper
+public interface AllocationQueryMapper extends BaseMapper<AllocationQuery> {
+	
+}

+ 92 - 0
src/main/java/com/imed/costaccount/model/AllocationQuery.java

@@ -0,0 +1,92 @@
+package com.imed.costaccount.model;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+
+import java.math.BigDecimal;
+import java.io.Serializable;
+import java.util.Date;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+
+/**
+ * 
+ * 
+ * @author huangrui
+ * @email 
+ * @date 2021-08-26 08:51:45
+ */
+@Data
+@Accessors(chain = true)
+@AllArgsConstructor
+@NoArgsConstructor
+@TableName("cost_allocation_query")
+public class AllocationQuery implements Serializable {
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 主键
+	 */
+	@TableId
+	private Long id;
+	/**
+	 * 年
+	 */
+	private Integer dateYear;
+	/**
+	 * 月
+	 */
+	private Integer dateMonth;
+//	/**
+//	 * 分摊层级序号
+//	 */
+//	private Integer levelSort;
+//	/**
+//	 * 分摊层级数名称
+//	 */
+//	private String levelName;
+	/**
+	 * 医院id
+	 */
+	private Long hospId;
+	/**
+	 * 责任中心代码
+	 */
+	private String responsibilityCode;
+	/**
+	 * 责任中心名称
+	 */
+	private String responsibilityName;
+	/**
+	 * 来源id
+	 */
+	private Long originId;
+	/**
+	 * 来源类型
+	 */
+	private Long originType;
+	/**
+	 * 金额
+	 */
+	private BigDecimal amount;
+	/**
+	 * 会计科目
+	 */
+	private String accountingCode;
+	/**
+	 * 会计科目名称
+	 */
+	private String accountingName;
+	/**
+	 * 创建时间
+	 */
+	private Long createTime;
+	/**
+	 * 删除时间
+	 */
+	private Long deleteTime;
+
+}

+ 17 - 0
src/main/java/com/imed/costaccount/service/AllocationQueryService.java

@@ -0,0 +1,17 @@
+package com.imed.costaccount.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.imed.costaccount.model.AllocationQuery;
+
+
+/**
+ * 
+ *
+ * @author huangrui
+ * @email 
+ * @date 2021-08-26 08:51:45
+ */
+public interface AllocationQueryService extends IService<AllocationQuery> {
+
+}
+

+ 14 - 0
src/main/java/com/imed/costaccount/service/AllocationService.java

@@ -1,9 +1,14 @@
 package com.imed.costaccount.service;
 
+import cn.hutool.poi.excel.ExcelWriter;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.model.dto.StartDTO;
 import com.imed.costaccount.model.Allocation;
+import com.imed.costaccount.model.vo.CollectDataFormVO;
+import org.apache.poi.ss.usermodel.Sheet;
+
+import java.util.List;
 
 /**
  * 成本分摊后表
@@ -33,6 +38,15 @@ public interface AllocationService extends IService<Allocation> {
      */
     PageUtils queryAfterAllocation(String year, String responsibilityCode, Integer current, Integer pageSize, Long hospId);
 
+    /**
+     * 分摊后报表
+     * @param year 年月(yyyy-MM-dd)
+     * @param responsibilityCode 责任中心代码
+     * @return List
+     */
+    List<CollectDataFormVO> queryAfterAllocationForm(String year, String responsibilityCode);
+
+
 
     /**
      *  分摊报表导出

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

@@ -0,0 +1,16 @@
+package com.imed.costaccount.service.impl;
+
+import org.springframework.stereotype.Service;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+import com.imed.costaccount.mapper.AllocationQueryMapper;
+import com.imed.costaccount.model.AllocationQuery;
+import com.imed.costaccount.service.AllocationQueryService;
+
+
+@Service("allocationQueryService")
+public class AllocationQueryServiceImpl extends ServiceImpl<AllocationQueryMapper, AllocationQuery> implements AllocationQueryService {
+
+
+}

+ 72 - 8
src/main/java/com/imed/costaccount/service/impl/AllocationServiceImpl.java

@@ -17,13 +17,11 @@ import com.imed.costaccount.common.util.UserContext;
 import com.imed.costaccount.mapper.AllocationMapper;
 import com.imed.costaccount.model.*;
 import com.imed.costaccount.model.dto.StartDTO;
-import com.imed.costaccount.model.vo.AccountShareVO;
-import com.imed.costaccount.model.vo.AfterAllocationVO;
-import com.imed.costaccount.model.vo.AllocationReportVO;
-import com.imed.costaccount.model.vo.CostShareLevelVO;
+import com.imed.costaccount.model.vo.*;
 import com.imed.costaccount.service.*;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.ss.usermodel.Sheet;
-import org.jetbrains.annotations.NotNull;
+import org.apache.xmlbeans.impl.xb.xsdschema.All;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
@@ -33,7 +31,7 @@ import java.util.*;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 
-
+@Slf4j
 @Service("allocationService")
 public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocation> implements AllocationService {
 
@@ -43,15 +41,20 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
     private final CostAccountShareService accountShareService;
     private final ShareParamValueService shareParamValueService;
     private final CostShareParamService shareParamService;
+    private final AllocationQueryService allocationQueryService;
 
     public AllocationServiceImpl(CostCostingGroupService costCostingGroupService,
-                                 CostShareLevelService shareLevelService, ResponsibilityService responsibilityService, CostAccountShareService accountShareService, ShareParamValueService shareParamValueService, CostShareParamService shareParamService) {
+                                 CostShareLevelService shareLevelService,
+                                 ResponsibilityService responsibilityService,
+                                 CostAccountShareService accountShareService,
+                                 ShareParamValueService shareParamValueService, CostShareParamService shareParamService, AllocationQueryService allocationQueryService, AllocationQueryService allocationQueryService1) {
         this.costCostingGroupService = costCostingGroupService;
         this.shareLevelService = shareLevelService;
         this.responsibilityService = responsibilityService;
         this.accountShareService = accountShareService;
         this.shareParamValueService = shareParamValueService;
         this.shareParamService = shareParamService;
+        this.allocationQueryService = allocationQueryService1;
     }
 
     /**
@@ -178,6 +181,7 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
                                     .setShareParamCode(paramValue.getShareParamCode()).setShareParamName(shareParamName).setTotalAmount(totalAmount).setShareParamValueNum(paramValue.getValueNum())
                                     .setShareParamRate(numerator.divide(reduce, 4))
                             ;
+
                             // todo 目标分摊层级责任中心 就是当前列个表中的责任中心
                             allocations.add(targetAllocation);
                             costList.add(targetAllocation);
@@ -189,6 +193,56 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
             }
         }
         this.saveBatch(allocations);
+        List<Allocation> list = this.list(
+                new LambdaQueryWrapper<Allocation>()
+                        .eq(Allocation::getHospId, hospId).eq(Allocation::getDateYear, startDTO.getYear()).eq(Allocation::getDateMonth, startDTO.getMonth())
+        );
+        if (list.isEmpty()) {
+            log.error("未分摊到数据......");
+            return;
+        }
+
+        // 入cost_allocation_query 表 便于后续操作
+        this.saveAllocationQuery(list, costingGroups, hospId);
+    }
+
+    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Throwable.class)
+    public void saveAllocationQuery(List<Allocation> list, List<CostCostingGroup> costingGroups, Long hospId) {
+        List<AllocationQuery> saveList = new ArrayList<>();
+        list.forEach(i -> {
+            Long accountShareId = i.getAccountShareId();
+            CostAccountShare byId = accountShareService.getById(accountShareId);
+            if (Objects.isNull(byId)) {
+                return;
+            }
+            String accountingCodes = byId.getAccountingCodes();
+            if (StrUtil.isBlank(accountingCodes)) {
+                return;
+            }
+            String accountingNames = byId.getAccountingNames();
+            String alias = byId.getAlias();
+            if (StrUtil.isNotBlank(alias)) {
+                accountingNames = alias;
+            }
+            AllocationQuery allocationQuery = new AllocationQuery();
+            allocationQuery.setDateYear(i.getDateYear()).setDateMonth(i.getDateMonth())
+                    .setHospId(hospId).setResponsibilityCode(i.getResponsibilityCode()).setResponsibilityName(i.getResponsibilityName())
+                    .setOriginId(i.getId()).setOriginType(2L).setAmount(i.getAmount()).setAccountingCode(accountingCodes).setAccountingName(accountingNames)
+                    .setCreateTime(System.currentTimeMillis())
+            ;
+            saveList.add(allocationQuery);
+        });
+
+        costingGroups.forEach(i -> {
+            AllocationQuery allocationQuery = new AllocationQuery();
+            allocationQuery.setDateYear(i.getDateYear()).setDateMonth(i.getDateMonth())
+                    .setHospId(hospId).setResponsibilityCode(i.getResponsibilityCode()).setResponsibilityName(i.getResponsibilityName())
+                    .setOriginId(i.getId()).setOriginType(2L).setAmount(i.getAmount()).setAccountingCode(i.getAccountCode()).setAccountingName(i.getAccountName())
+                    .setCreateTime(System.currentTimeMillis())
+            ;
+            saveList.add(allocationQuery);
+        });
+        allocationQueryService.saveBatch(saveList);
     }
 
     /**
@@ -488,7 +542,6 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
      * @param month
      * @return
      */
-    @NotNull
     private List<AllocationReportVO> getAllocationReportVOS(Integer levelSort, Integer year, Integer month) {
         Long hospId = UserContext.getHospId();
         if (Objects.isNull(levelSort) || Objects.isNull(year) || Objects.isNull(month)) {
@@ -543,4 +596,15 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
         return allocationReportVOList;
     }
 
+    /**
+     * 分摊后报表
+     *
+     * @param year               年月(yyyy-MM-dd)
+     * @param responsibilityCode 责任中心代码
+     * @return List
+     */
+    @Override
+    public List<CollectDataFormVO> queryAfterAllocationForm(String year, String responsibilityCode) {
+        return null;
+    }
 }

+ 19 - 6
src/main/java/com/imed/costaccount/web/CostCostingGroupController.java

@@ -4,6 +4,7 @@ import com.imed.costaccount.common.exception.CostException;
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.common.util.Result;
 import com.imed.costaccount.model.dto.StartDTO;
+import com.imed.costaccount.model.vo.CollectDataFormVO;
 import com.imed.costaccount.service.AllocationService;
 import com.imed.costaccount.service.CostCostingGroupService;
 import io.swagger.annotations.Api;
@@ -13,6 +14,7 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
+import java.util.List;
 
 
 /**
@@ -74,24 +76,35 @@ public class CostCostingGroupController extends AbstractController {
     @PostMapping("/startAllocation")
     public Result startAllocation(@RequestBody @Valid StartDTO startDTO) {
 //        costCostingGroupService.startAllocation(startDTO, getHospId());
-        allocationService.startAllocation(startDTO,getHospId());
+        allocationService.startAllocation(startDTO, getHospId());
         return Result.ok();
     }
 
     @ApiOperation("分摊后列表")
     @GetMapping("/queryAfterAllocation")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "year",value = "年月日(yyyy-MM-dd)"),
-            @ApiImplicitParam(name = "responsibilityCode",value = "责任中心代码"),
-            @ApiImplicitParam(name = "current",value = "每页数据大小"),
-            @ApiImplicitParam(name = "pageSize",value = "每页数据大小")
+            @ApiImplicitParam(name = "year", value = "年月日(yyyy-MM-dd)"),
+            @ApiImplicitParam(name = "responsibilityCode", value = "责任中心代码"),
+            @ApiImplicitParam(name = "current", value = "每页数据大小"),
+            @ApiImplicitParam(name = "pageSize", value = "每页数据大小")
     })
     public Result queryAfterAllocation(@RequestParam(value = "year", required = false) String year,
                                        @RequestParam(value = "responsibilityCode", required = false) String responsibilityCode,
                                        @RequestParam(value = "current", defaultValue = "1", required = false) Integer current,
                                        @RequestParam(value = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
-        PageUtils pageUtils = allocationService.queryAfterAllocation(year, responsibilityCode, current, pageSize,getHospId());
+        PageUtils pageUtils = allocationService.queryAfterAllocation(year, responsibilityCode, current, pageSize, getHospId());
         return Result.ok(pageUtils);
     }
 
+    @ApiOperation("分摊后报表")
+    @GetMapping("/queryAfterAllocationForm")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "year", value = "年月日(yyyy-MM-dd)"),
+            @ApiImplicitParam(name = "responsibilityCode", value = "责任中心代码")
+    })
+    public Result queryAfterAllocationForm(@RequestParam(value = "year", required = false) String year,
+                                           @RequestParam(value = "responsibilityCode", required = false) String responsibilityCode) {
+        List<CollectDataFormVO> list = allocationService.queryAfterAllocationForm(year, responsibilityCode);
+        return Result.ok(list);
+    }
 }

+ 24 - 0
src/main/resources/mapper/AllocationQueryMapper.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.imed.costaccount.mapper.AllocationQueryMapper">
+
+	<!-- 可根据自己的需求,是否要使用 -->
+    <resultMap type="com.imed.costaccount.model.AllocationQuery" id="allocationQueryMap">
+        <result property="id" column="id"/>
+        <result property="dateYear" column="date_year"/>
+        <result property="dateMonth" column="date_month"/>
+        <result property="hospId" column="hosp_id"/>
+        <result property="responsibilityCode" column="responsibility_code"/>
+        <result property="responsibilityName" column="responsibility_name"/>
+        <result property="originId" column="origin_id"/>
+        <result property="originType" column="origin_type"/>
+        <result property="amount" column="amount"/>
+        <result property="accountingCode" column="accounting_code"/>
+        <result property="accountingName" column="accounting_name"/>
+        <result property="createTime" column="create_time"/>
+        <result property="deleteTime" column="delete_time"/>
+    </resultMap>
+
+
+</mapper>

+ 32 - 1
src/test/java/com/imed/costaccount/service/impl/AllocationServiceImplTest.java

@@ -1,6 +1,7 @@
 package com.imed.costaccount.service.impl;
 
 import com.imed.costaccount.common.util.PageUtils;
+import com.imed.costaccount.model.Allocation;
 import com.imed.costaccount.service.AccountingService;
 import com.imed.costaccount.service.AllocationService;
 import lombok.extern.slf4j.Slf4j;
@@ -10,6 +11,7 @@ import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.transaction.annotation.Transactional;
 
 @RunWith(SpringRunner.class)
 @SpringBootTest
@@ -28,7 +30,36 @@ public class AllocationServiceImplTest {
         long hospId = 11L;
         PageUtils pageUtils = allocationService.queryAfterAllocation(year, responsibilityCode, current, pageSize, hospId);
         Assert.assertNotNull(pageUtils);
-        log.info("pageUtils={}",pageUtils);
+        log.info("pageUtils={}", pageUtils);
+    }
+
+    @Test
+    @Transactional
+    public void testTransaction1() {
+        Allocation before = allocationService.getById(40);
+//        allocationService.removeById(40);
+        try {
+            Thread.sleep(1000);
+        } catch (InterruptedException e) {
+            throw new RuntimeException("111");
+        }
+
+        Allocation after = allocationService.getById(40);
+        Assert.assertEquals(before, after);
+    }
+
+
+
+    @Test
+    public void test() {
+        new Thread(this::testTransaction1).start();
+        new Thread(this::testDel).start();
+    }
+
+    @Test
+    @Transactional
+    public void testDel() {
+        allocationService.removeById(40);
     }
 
 }