Browse Source

08 18 01 成本分摊前功能

hr 4 years ago
parent
commit
72f7bf80f4

+ 81 - 1
src/main/java/com/imed/costaccount/mapper/CostCostingGroupMapper.java

@@ -2,7 +2,13 @@ package com.imed.costaccount.mapper;
 
 import com.imed.costaccount.model.CostCostingGroup;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.imed.costaccount.model.vo.AllocationVO;
+import com.imed.costaccount.model.vo.CostingGroupStartVO;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.math.BigDecimal;
+import java.util.List;
 
 /**
  * 成本归集
@@ -12,5 +18,79 @@ import org.apache.ibatis.annotations.Mapper;
  */
 @Mapper
 public interface CostCostingGroupMapper extends BaseMapper<CostCostingGroup> {
-	
+
+
+    /**
+     * 成本分摊前查询列表
+     * @param startIndex 开始索引
+     * @param pageSize limit
+     * @param responsibilityCode 责任中心代码
+     * @param accountCode 会计中心代码
+     * @param year 年
+     * @param month 月
+     * @param hospId 医院
+     * @return {@link CostingGroupStartVO}
+     */
+    List<CostingGroupStartVO> queryStartAllocation(@Param("startIndex") Integer startIndex,
+                                                   @Param("pageSize") Integer pageSize,
+                                                   @Param("responsibilityCode") String responsibilityCode,
+                                                   @Param("accountCode") String accountCode,
+                                                   @Param("year") Integer year,
+                                                   @Param("month") Integer month,
+                                                   @Param("hospId") Long hospId);
+
+    /**
+     * 成本分摊前查询列表 总数
+     * @param responsibilityCode 责任中心代码
+     * @param accountCode 会计中心代码
+     * @param year 年
+     * @param month 月
+     * @param hospId 医院
+     * @return 总数
+     */
+    int queryStartAllocationCount(@Param("responsibilityCode") String responsibilityCode,
+                                  @Param("accountCode") String accountCode,
+                                  @Param("year") Integer year,
+                                  @Param("month") Integer month,
+                                  @Param("hospId") Long hospId);
+
+    /**
+     *成本分摊年月总金额
+     *
+     * @param responsibilityCode 责任中心代码
+     * @param accountCode 会计中心代码
+     * @param year 年
+     * @param month 月
+     * @param hospId 医院
+     * @return 总金额
+     */
+    BigDecimal queryStartAllocationTotalAmount(@Param("responsibilityCode") String responsibilityCode,
+                                               @Param("accountCode") String accountCode,
+                                               @Param("year") Integer year,
+                                               @Param("month") Integer month,
+                                               @Param("hospId") Long hospId);
+
+    /**
+     * 陈本分摊列表
+     * @param startIndex 开始索引
+     * @param pageSize 每页数据大小
+     * @param year 年
+     * @param month 月
+     * @param hospId 医院id
+     * @return 列表
+     */
+    List<AllocationVO> queryAllocation(@Param("startIndex") Integer startIndex,
+                                       @Param("pageSize") Integer pageSize,
+                                       @Param("year") Integer year,
+                                       @Param("month") Integer month,
+                                       @Param("hospId") Long hospId);
+
+    /**
+     * 同上
+     * @param year 年
+     * @param month 月
+     * @param hospId 医院id
+     * @return 总数
+     */
+    int queryAllocationCount(@Param("year") Integer year, @Param("month") Integer month, @Param("hospId") Long hospId);
 }

+ 2 - 0
src/main/java/com/imed/costaccount/model/CostCostingCollection.java

@@ -1,6 +1,7 @@
 package com.imed.costaccount.model;
 
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -89,6 +90,7 @@ public class CostCostingCollection implements Serializable {
 	/**
 	 * 删除时间
 	 */
+	@TableLogic(value = "0",delval = "UNIX_TIMESTAMP(NOW()) * 1000")
 	private Long deleteTime;
 	/**
 	 * 医院id

+ 2 - 0
src/main/java/com/imed/costaccount/model/CostCostingGroup.java

@@ -1,6 +1,7 @@
 package com.imed.costaccount.model;
 
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -101,6 +102,7 @@ public class CostCostingGroup implements Serializable {
 	/**
 	 * 删除时间,如果存在表示已删除13位时间戳
 	 */
+	@TableLogic(value = "0",delval = "UNIX_TIMESTAMP(NOW()) * 1000")
 	private Long deleteTime;
 
 }

+ 21 - 0
src/main/java/com/imed/costaccount/model/dto/StartDTO.java

@@ -0,0 +1,21 @@
+package com.imed.costaccount.model.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+@Data
+@ApiModel("通用开始归集的入参")
+public class StartDTO {
+
+    @ApiModelProperty(name = "year",value = "年")
+    @NotNull(message = "年不能为为空")
+    private Integer year;
+
+    @ApiModelProperty(name = "month",value = "月")
+    @NotNull(message = "月不能为空")
+    private Integer month;
+
+}

+ 24 - 0
src/main/java/com/imed/costaccount/model/vo/AllocationVO.java

@@ -0,0 +1,24 @@
+package com.imed.costaccount.model.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+@ApiModel("归集查询视图对象")
+public class AllocationVO {
+
+    @ApiModelProperty(name = "year",value = "年")
+    private Integer year;
+
+    @ApiModelProperty(name = "month",value = "月")
+    private Integer month;
+
+    @ApiModelProperty(name = "amount",value = "金额")
+    private BigDecimal amount;
+
+    @ApiModelProperty(name = "isAllocation",value = "是否分摊")
+    private Boolean isAllocation;
+}

+ 56 - 0
src/main/java/com/imed/costaccount/model/vo/CostingGroupStartVO.java

@@ -0,0 +1,56 @@
+package com.imed.costaccount.model.vo;
+
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+@Data
+@ApiModel("成本分摊前查询列表")
+public class CostingGroupStartVO implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+
+    @ApiModelProperty(name = "id",value = "id")
+    private Long id;
+
+    @ApiModelProperty(name = "year",value = "年")
+    private Integer year;
+
+    @ApiModelProperty(name = "month",value = "月")
+    private Integer month;
+
+    @ApiModelProperty(name = "amount",value = "金额")
+    private BigDecimal amount;
+
+    @ApiModelProperty(name = "departCode",value = "部门code")
+    private String departCode;
+
+    @ApiModelProperty(name = "departName",value = "部门名称")
+    private String departName;
+
+    @ApiModelProperty(name = "responsibilityCode",value = "责任中心代码")
+    private String responsibilityCode;
+
+    @ApiModelProperty(name = "responsibilityName",value = "责任中心名称")
+    private String responsibilityName;
+
+    @ApiModelProperty(name = "accountCode",value = "会计中心code")
+    private String accountCode;
+
+    @ApiModelProperty(name = "accountName",value = "会计中心名称")
+    private String accountName;
+
+    @ApiModelProperty(name = "productCode",value = "成本项目code")
+    private String productCode;
+
+    @ApiModelProperty(name = "productName",value = "成本项目名称")
+    private String productName;
+
+    @ApiModelProperty(name = "fileId",value = "文件id")
+    private Long fileId;
+
+}

+ 32 - 0
src/main/java/com/imed/costaccount/service/CostCostingGroupService.java

@@ -1,9 +1,11 @@
 package com.imed.costaccount.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.common.util.Result;
 import com.imed.costaccount.model.CostCostingGroup;
 import com.imed.costaccount.model.User;
+import com.imed.costaccount.model.dto.StartDTO;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
@@ -26,5 +28,35 @@ public interface CostCostingGroupService extends IService<CostCostingGroup> {
      * @return
      */
     Result importCostingGroup(List<List<Object>> read, User user, MultipartFile file, String dateTime, Integer fileType);
+
+    /**
+     * 分摊前查询
+     *
+     * @param current 当前页
+     * @param pageSize 每页数据大小
+     * @param responsibilityCode 责任中心代码
+     * @param accountCode 会计中心代码
+     * @param date 日期 yyyy-MM-dd
+     * @param hospId 医院id
+     * @return 分摊前查询列表
+     */
+    PageUtils queryStartAllocation(Integer current, Integer pageSize, String responsibilityCode, String accountCode, String date, Long hospId);
+
+    /**
+     * 成本分摊列表
+     * @param current 当前页
+     * @param pageSize 每页数据大小
+     * @param date 日期 这里是 yyyy-MM-dd
+     * @param hospId 医院id
+     * @return 分页对象
+     */
+    PageUtils queryAllocation(Integer current, Integer pageSize, String date, Long hospId);
+
+    /**
+     * 开始归集代码
+     * @param startDTO {@link StartDTO}
+     * @param hospId 医院id
+     */
+    void startAllocation(StartDTO startDTO, Long hospId);
 }
 

+ 109 - 13
src/main/java/com/imed/costaccount/service/impl/CostCostingGroupServiceImpl.java

@@ -1,8 +1,10 @@
 package com.imed.costaccount.service.impl;
 
+import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.druid.util.StringUtils;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.imed.costaccount.common.exception.CostException;
@@ -11,11 +13,11 @@ import com.imed.costaccount.constants.NumberConstant;
 import com.imed.costaccount.enums.DateStyleEnum;
 import com.imed.costaccount.mapper.CostCostingGroupMapper;
 import com.imed.costaccount.model.*;
+import com.imed.costaccount.model.dto.StartDTO;
+import com.imed.costaccount.model.vo.AllocationVO;
+import com.imed.costaccount.model.vo.CostingGroupStartVO;
 import com.imed.costaccount.model.vo.IncomeErrorMessage;
-import com.imed.costaccount.service.AccountingProductService;
-import com.imed.costaccount.service.CostCostingGroupService;
-import com.imed.costaccount.service.CostIncomeFileService;
-import com.imed.costaccount.service.ResponsibilityService;
+import com.imed.costaccount.service.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
@@ -39,14 +41,105 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
 
     private final ResponsibilityService responsibilityService;
 
-    public CostCostingGroupServiceImpl(CostIncomeGroupServiceImpl costIncomeGroupService, AccountingProductService accountingProductService, CostIncomeFileService costIncomeFileService, ResponsibilityService responsibilityService) {
+    private final CostCostingCollectionService costingCollectionService;
+
+    public CostCostingGroupServiceImpl(CostIncomeGroupServiceImpl costIncomeGroupService,
+                                       AccountingProductService accountingProductService,
+                                       CostIncomeFileService costIncomeFileService,
+                                       ResponsibilityService responsibilityService,
+                                       CostCostingCollectionService costingCollectionService) {
         this.costIncomeGroupService = costIncomeGroupService;
         this.accountingProductService = accountingProductService;
         this.costIncomeFileService = costIncomeFileService;
         this.responsibilityService = responsibilityService;
+        this.costingCollectionService = costingCollectionService;
+    }
+
+    /**
+     * 分摊前查询
+     *
+     * @param current            当前页
+     * @param pageSize           每页数据大小
+     * @param responsibilityCode 责任中心代码
+     * @param accountCode        会计中心代码
+     * @param date               日期 yyyy-MM-dd
+     * @param hospId             医院id
+     * @return 分摊前查询列表
+     */
+    @Override
+    public PageUtils queryStartAllocation(Integer current, Integer pageSize, String responsibilityCode, String accountCode, String date, Long hospId) {
+        Integer startIndex = (current - 1) * pageSize;
+        DateTime dateTime = DateUtil.parseDate(date);
+        Integer year = DateUtil.year(dateTime);
+        Integer month = DateUtil.month(dateTime) + 1;
+        List<CostingGroupStartVO> list = baseMapper.queryStartAllocation(startIndex, pageSize, responsibilityCode, accountCode, year, month, hospId);
+        int count = baseMapper.queryStartAllocationCount(responsibilityCode, accountCode, year, month, hospId);
+        BigDecimal totalAmount = baseMapper.queryStartAllocationTotalAmount(responsibilityCode, accountCode, year, month, hospId);
+
+        return new PageUtils(list, count, pageSize, current, totalAmount);
     }
 
 
+    /**
+     * 成本分摊列表
+     *
+     * @param current  当前页
+     * @param pageSize 每页数据大小
+     * @param date     日期 这里是 yyyy-MM-dd
+     * @param hospId
+     * @return 分页对象
+     */
+    @Override
+    public PageUtils queryAllocation(Integer current, Integer pageSize, String date, Long hospId) {
+        Integer year = null;
+        Integer month = null;
+        if (StrUtil.isNotBlank(date)) {
+            DateTime dateTime = DateUtil.parseDate(date);
+            year = DateUtil.year(dateTime);
+            month = DateUtil.month(dateTime) + 1;
+        }
+        Integer startIndex = (current - 1) * pageSize;
+
+        List<AllocationVO> list = baseMapper.queryAllocation(startIndex, pageSize, year, month, hospId);
+        list.forEach(i -> {
+            List<CostCostingCollection> collections = costingCollectionService.list(new LambdaQueryWrapper<CostCostingCollection>().eq(CostCostingCollection::getYear, i.getYear())
+                    .eq(CostCostingCollection::getMonth, i.getMonth())
+                    .eq(CostCostingCollection::getHospId, hospId)
+            );
+            if (!collections.isEmpty()) {
+                i.setIsAllocation(true);
+            }
+        });
+        int count = baseMapper.queryAllocationCount(year, month, hospId);
+        return new PageUtils(list, count, pageSize, current);
+    }
+
+    /**
+     * 开始归集代码
+     *
+     * @param startDTO {@link StartDTO}
+     * @param hospId   医院id
+     */
+    @Override
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
+    public void startAllocation(StartDTO startDTO, Long hospId) {
+//        // 先拿到这个月数据 如果数据量很大 优化处理
+//        List<CostCostingGroup> list = this.list(
+//                new LambdaQueryWrapper<CostCostingGroup>()
+//                        .eq(CostCostingGroup::getDateYear, startDTO.getYear())
+//                        .eq(CostCostingGroup::getDateMonth, startDTO.getMonth())
+//                        .eq(CostCostingGroup::getHospId, hospId)
+//        );
+//
+//        // 删除该年月已经归集过的数据
+//        costingCollectionService.remove(
+//                new LambdaQueryWrapper<CostCostingCollection>()
+//                        .eq(CostCostingCollection::getYear, startDTO.getYear())
+//                        .eq(CostCostingCollection::getMonth, startDTO.getMonth())
+//                        .eq(CostCostingCollection::getHospId, hospId)
+//        );
+    }
+
     /**
      * 批量导入成本数据
      *
@@ -140,6 +233,9 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
             return Result.build(200, "数据未成功导入", null);
         }
     }
+
+
+
     /**
      * 检验成本数据
      *
@@ -158,22 +254,22 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
         List<Object> departmentNames = list.get(1);
         //检验数据是否准确
         for (int i = 2; i < list.size(); i++) {
-            int row=i+5;
+            int row = i + 5;
             List<Object> data = list.get(i);
             for (int j = 2; j < departmentCodes.size(); j++) {
-                int column=j+1;
-                if (data.size() > j ) {
-                    if (Objects.isNull(data.get(j))){
+                int column = j + 1;
+                if (data.size() > j) {
+                    if (Objects.isNull(data.get(j))) {
                         data.set(j, NumberConstant.ZERO);
-                    }else if ( data.get(j).toString().contains("-") || !StringUtils.isNumber(data.get(j).toString())){
+                    } else if (data.get(j).toString().contains("-") || !StringUtils.isNumber(data.get(j).toString())) {
                         IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
                         incomeErrorMessage.setTotal(row);
-                        incomeErrorMessage.setErrMessage("第"+row+"行 第"+column+"列数据不符合规范");
+                        incomeErrorMessage.setErrMessage("第" + row + "行 第" + column + "列数据不符合规范");
                         incomeErrorMessageList.add(incomeErrorMessage);
-                    }else {
+                    } else {
                         data.set(j, Double.parseDouble(data.get(j).toString()));
                     }
-                }else {
+                } else {
                     data.add(NumberConstant.ZERO);
                 }
             }

+ 49 - 48
src/main/java/com/imed/costaccount/web/CostCostingGroupController.java

@@ -1,14 +1,17 @@
 package com.imed.costaccount.web;
 
+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.CostCostingGroup;
-import com.imed.costaccount.model.User;
+import com.imed.costaccount.model.dto.StartDTO;
 import com.imed.costaccount.service.CostCostingGroupService;
-import org.apache.shiro.SecurityUtils;
-import org.springframework.beans.factory.annotation.Autowired;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.Arrays;
+import javax.validation.Valid;
 
 
 /**
@@ -17,58 +20,56 @@ import java.util.Arrays;
  * @author KCYG
  * @date 2021-08-12 11:00:23
  */
+@Api(tags = "成本分摊")
 @RestController
 @RequestMapping("/costAccount/costcostinggroup")
-public class CostCostingGroupController {
-    @Autowired
-    private CostCostingGroupService costCostingGroupService;
+public class CostCostingGroupController extends AbstractController {
+    private final CostCostingGroupService costCostingGroupService;
 
-    /**
-     * 分页查询列表
-     * 查询的是
-     */
-    @RequestMapping("/list")
-    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();
+    public CostCostingGroupController(CostCostingGroupService costCostingGroupService) {
+        this.costCostingGroupService = costCostingGroupService;
     }
 
-
-    /**
-     * 信息
-     */
-    @RequestMapping("/info/{id}")
-    public Result info(@PathVariable("id") Long id){
-		CostCostingGroup costCostingGroup = costCostingGroupService.getById(id);
-        return Result.ok(costCostingGroup);
+    @ApiOperation("成本分摊前数据列表")
+    @GetMapping("/queryStartAllocation")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "current", value = "当前页", required = true),
+            @ApiImplicitParam(name = "pageSize", value = "当前页大小", required = true),
+            @ApiImplicitParam(name = "responsibilityCode", value = "责任中心代码", required = false),
+            @ApiImplicitParam(name = "accountCode", value = "会计中心代码"),
+            @ApiImplicitParam(name = "date", value = "年月yyyy-MM-dd")}
+    )
+    public Result queryStartAllocation(@RequestParam(value = "current", defaultValue = "1") Integer current,
+                                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
+                                       @RequestParam(value = "responsibilityCode", required = false) String responsibilityCode,
+                                       @RequestParam(value = "accountCode", required = false) String accountCode,
+                                       @RequestParam(value = "date") String date) {
+        // 简单校验时间格式 这里要求的是yyyy-MM-dd
+        if (date.length() != 10) {
+            throw new CostException("时间格式不正确,这里要求yyyy-MM-dd 格式");
+        }
+        PageUtils pageUtils = costCostingGroupService.queryStartAllocation(current, pageSize, responsibilityCode, accountCode, date, getHospId());
+        return Result.ok(pageUtils);
     }
 
-    /**
-     * 保存
-     */
-    @RequestMapping("/save")
-    public Result save(@RequestBody CostCostingGroup costCostingGroup){
-		costCostingGroupService.save(costCostingGroup);
-        return Result.ok();
+    @ApiOperation("成本分摊列表")
+    @GetMapping("/allocationList")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "current", value = "当前页", required = true),
+            @ApiImplicitParam(name = "pageSize", value = "当前页大小", required = true),
+            @ApiImplicitParam(name = "date", value = "年月yyyy-MM-dd", required = true)
+    })
+    public Result allocationList(@RequestParam(value = "current", defaultValue = "1", required = false) Integer current,
+                                 @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
+                                 @RequestParam(value = "date", required = false) String date) {
+        PageUtils pageUtils = costCostingGroupService.queryAllocation(current, pageSize, date, getHospId());
+        return Result.ok(pageUtils);
     }
 
-    /**
-     * 修改
-     */
-    @RequestMapping("/update")
-    public Result update(@RequestBody CostCostingGroup costCostingGroup){
-		costCostingGroupService.updateById(costCostingGroup);
+    @ApiOperation("开始归集")
+    @PostMapping("/startAllocation")
+    public Result startAllocation(@RequestBody @Valid StartDTO startDTO) {
+        costCostingGroupService.startAllocation(startDTO, getHospId());
         return Result.ok();
     }
-
-    /**
-     * 删除
-     */
-    @RequestMapping("/delete")
-    public Result delete(@RequestBody Long[] ids){
-		costCostingGroupService.removeByIds(Arrays.asList(ids));
-        return Result.ok();
-    }
-
 }

+ 5 - 2
src/main/java/com/imed/costaccount/web/CostIncomeGroupSetController.java

@@ -29,8 +29,11 @@ import java.util.List;
 @RequestMapping("/costAccount/costincomegroupset")
 @Api(tags = "收入归集设置操作")
 public class CostIncomeGroupSetController{
-    @Autowired
-    private CostIncomeGroupSetService costIncomeGroupSetService;
+    private final CostIncomeGroupSetService costIncomeGroupSetService;
+
+    public CostIncomeGroupSetController(CostIncomeGroupSetService costIncomeGroupSetService) {
+        this.costIncomeGroupSetService = costIncomeGroupSetService;
+    }
 
     /**
      * 分页查询列表

+ 110 - 1
src/main/resources/mapper/CostCostingGroupMapper.xml

@@ -3,7 +3,7 @@
 
 <mapper namespace="com.imed.costaccount.mapper.CostCostingGroupMapper">
 
-	<!-- 可根据自己的需求,是否要使用 -->
+    <!-- 可根据自己的需求,是否要使用 -->
     <resultMap type="com.imed.costaccount.model.CostCostingGroup" id="costCostingGroupMap">
         <result property="id" column="id"/>
         <result property="departmentCode" column="department_code"/>
@@ -25,6 +25,115 @@
         <result property="createTime" column="create_time"/>
         <result property="deleteTime" column="delete_time"/>
     </resultMap>
+    <select id="queryStartAllocation" resultType="com.imed.costaccount.model.vo.CostingGroupStartVO">
+        select
+        ccg.id as id,
+        ccg.date_year as year,
+        ccg.date_month as month,
+        ccg.amount as amount,
+        ccg.department_code as departCode,
+        sd.department_name as departName,
+        ccg.responsibility_code as responsibilityCode,
+        cr.responsibility_name as responsibilityName,
+        ccg.account_code as accountCode,
+        ccg.account_name as accountName,
+        ccg.product_code as productCode,
+        cp.product_name as productName,
+        ccg.file_id as fileId
+        from cost_costing_group ccg
+        left join sys_department sd
+        on ccg.hosp_id = sd.hosp_id and ccg.department_code = sd.department_code
+        left join cost_responsibility cr
+        on ccg.responsibility_code = cr.responsibility_code and ccg.hosp_id = cr.hosp_id
+        left join cost_accounting ca on ccg.account_code = ca.accounting_code and ccg.hosp_id = ca.hosp_id
+        left join cost_product cp
+        on cp.delete_time = 0 and ccg.product_code = cp.product_code and ccg.hosp_id = cp.hosp_id
+        where ccg.delete_time = 0
+        and ccg.date_year = #{year}
+        and ccg.date_month = #{month}
+        and ccg.hosp_id = #{hospId}
+        <if test="responsibilityCode != null and responsibilityCode != ''">
+            and responsibility_code = #{responsibilityCode}
+        </if>
+        <if test="accountCode != null and accountCode != ''">
+            and account_code #{accountCode}
+        </if>
+        and sd.delete_time = 0
+        and cr.delete_time = 0
+        and ca.delete_time = 0
+        limit #{startIndex},#{pageSize}
+    </select>
+    <select id="queryStartAllocationCount" resultType="java.lang.Integer">
+        select
+        count(*)
+        from cost_costing_group ccg
+        left join sys_department sd
+        on ccg.hosp_id = sd.hosp_id and ccg.department_code = sd.department_code
+        left join cost_responsibility cr
+        on ccg.responsibility_code = cr.responsibility_code and ccg.hosp_id = cr.hosp_id
+        left join cost_accounting ca on ccg.account_code = ca.accounting_code and ccg.hosp_id = ca.hosp_id
+        left join cost_product cp
+        on cp.delete_time = 0 and ccg.product_code = cp.product_code and ccg.hosp_id = cp.hosp_id
+        where ccg.delete_time = 0
+        and ccg.date_year = #{year}
+        and ccg.date_month = #{month}
+        and ccg.hosp_id = #{hospId}
+        <if test="responsibilityCode != null and responsibilityCode != ''">
+            and responsibility_code = #{responsibilityCode}
+        </if>
+        <if test="accountCode != null and accountCode != ''">
+            and account_code #{accountCode}
+        </if>
+        and sd.delete_time = 0
+        and cr.delete_time = 0
+        and ca.delete_time = 0
+    </select>
+    <select id="queryStartAllocationTotalAmount" resultType="java.math.BigDecimal">
+        select
+        sum(ccg.amount)
+        from cost_costing_group ccg
+        left join sys_department sd
+        on ccg.hosp_id = sd.hosp_id and ccg.department_code = sd.department_code
+        left join cost_responsibility cr
+        on ccg.responsibility_code = cr.responsibility_code and ccg.hosp_id = cr.hosp_id
+        left join cost_accounting ca on ccg.account_code = ca.accounting_code and ccg.hosp_id = ca.hosp_id
+        left join cost_product cp
+        on cp.delete_time = 0 and ccg.product_code = cp.product_code and ccg.hosp_id = cp.hosp_id
+        where ccg.delete_time = 0
+        and ccg.date_year = #{year}
+        and ccg.date_month = #{month}
+        and ccg.hosp_id = #{hospId}
+        <if test="responsibilityCode != null and responsibilityCode != ''">
+            and responsibility_code = #{responsibilityCode}
+        </if>
+        <if test="accountCode != null and accountCode != ''">
+            and account_code #{accountCode}
+        </if>
+        and sd.delete_time = 0
+        and cr.delete_time = 0
+        and ca.delete_time = 0
+    </select>
+    <select id="queryAllocation" resultType="com.imed.costaccount.model.vo.AllocationVO">
+        select date_year as year,date_month as month,IFNULL(sum(amount),0) as amount,false as isAllocation
+        from cost_costing_group
+        where delete_time = 0
+        <if test="year != null">
+            and date_year = #{year}
+            and date_month = #{month}
+        </if>
+        and hosp_id = #{hospId} group by date_year,date_month
+        limit #{startIndex},#{pageSize}
+    </select>
+    <select id="queryAllocationCount" resultType="java.lang.Integer">
+        select count(*) from (select count(*)
+        from cost_costing_group
+        where delete_time = 0
+        <if test="year != null">
+            and date_year = #{year}
+            and date_month = #{month}
+        </if>
+        and hosp_id = #{hospId} group by date_year,date_month) t
+    </select>
 
 
 </mapper>