Browse Source

Merge remote-tracking branch 'origin/master'

ljx 4 years ago
parent
commit
5616588e78

+ 1 - 1
pom.xml

@@ -175,7 +175,7 @@
         <dependency>
             <groupId>org.apache.poi</groupId>
             <artifactId>poi-ooxml</artifactId>
-            <version>5.0.0</version>
+            <version>3.16</version>
         </dependency>
 
     </dependencies>

+ 1 - 1
src/main/java/com/imed/costaccount/model/dto/AccountProductSaveDTO.java

@@ -19,6 +19,6 @@ public class AccountProductSaveDTO {
     private Integer id;
 
     @ApiModelProperty(name="products",value = "成本项目id列表")
-    @NotEmpty(message = "成本项目id不能为空")
+//    @NotEmpty(message = "成本项目id不能为空")
     private List<Integer> products;
 }

+ 5 - 0
src/main/java/com/imed/costaccount/model/vo/AccountVO.java

@@ -23,5 +23,10 @@ public class AccountVO {
 
     private List<AccountVO> children;
 
+    /**
+     * true表示选中
+     */
+    private Boolean isSelect = false;
+
 
 }

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

@@ -23,9 +23,10 @@ public interface AccountingService extends IService<Accounting> {
      * 获取会计科目列表按收入支出类型
      * @param accountType  会计科目类型1.收入,2.支出
      * @param user
+     * @param shareParamId
      * @return
      */
-    List<AccountVO> getListByAccountType(Integer accountType, User user);
+    List<AccountVO> getListByAccountType(Integer accountType, User user, Integer shareParamId);
 
     /**
      * 保存会计科目

+ 3 - 0
src/main/java/com/imed/costaccount/service/CostShareParamService.java

@@ -60,5 +60,8 @@ public interface CostShareParamService extends IService<CostShareParam> {
      * @return
      */
     CostShareParamVO getByHospIdAndAPramId(Integer id, Integer hospId);
+
+    List<Integer> selectIsSelect(Integer shareParamId);
+
 }
 

+ 33 - 11
src/main/java/com/imed/costaccount/service/impl/AccountingServiceImpl.java

@@ -13,6 +13,7 @@ import com.imed.costaccount.model.dto.AccountingSaveDTO;
 import com.imed.costaccount.model.vo.AccountVO;
 import com.imed.costaccount.model.vo.SelectAccountingVO;
 import com.imed.costaccount.service.AccountingService;
+import com.imed.costaccount.service.CostShareParamService;
 import com.imed.costaccount.utils.BeanUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
@@ -26,27 +27,46 @@ import java.util.stream.Collectors;
 @Service("accountingService")
 public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Accounting> implements AccountingService {
 
+    private final CostShareParamService shareParamService;
+
+    public AccountingServiceImpl(CostShareParamService shareParamService) {
+        this.shareParamService = shareParamService;
+    }
 
     /**
      * 获取会计科目列表按收入支出类型
      *
-     * @param accountType 会计科目类型1.收入,2.支出
+     * @param accountType  会计科目类型1.收入,2.支出
      * @param user
+     * @param shareParamId
      * @return
      */
     @Override
-    public List<AccountVO> getListByAccountType(Integer accountType, User user) {
+    public List<AccountVO> getListByAccountType(Integer accountType, User user, Integer shareParamId) {
         // 1. 得到所有的会计科目
         List<Accounting> list = this.list(
                 new LambdaQueryWrapper<Accounting>()
                         .eq(Accounting::getHospId, user.getHospId())
-                .orderByDesc(Accounting::getCreateTime)
+                        .eq(Accounting::getAccountingType, accountType)
+                        .orderByDesc(Accounting::getCreateTime)
         );
         if (CollUtil.isEmpty(list)) {
             return Collections.emptyList();
         }
         // 所有的
         List<AccountVO> all = list.stream().map(i -> BeanUtil.convertObj(i, AccountVO.class)).collect(Collectors.toList());
+        // 查询所有的已绑定的
+        if (Objects.nonNull(shareParamId)) {
+            List<Integer> ids = shareParamService.selectIsSelect(shareParamId);
+            if (CollUtil.isNotEmpty(ids)) {
+                all.forEach(i -> {
+                    if (ids.contains(i.getId())) {
+                        i.setIsSelect(true);
+                    }
+                });
+            }
+        }
+
         // 顶层的
         List<AccountVO> parents = all.stream().filter(i -> i.getParentId() == 0).collect(Collectors.toList());
         List<AccountVO> accountVOS = new ArrayList<>();
@@ -59,6 +79,7 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
 
     /**
      * 递归处理
+     *
      * @param accountVO
      * @param list
      * @return
@@ -153,14 +174,14 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
     @Override
     public List<SelectAccountingVO> selectAccounting(User user) {
         List<Accounting> list = this.list(
-                new LambdaQueryWrapper<Accounting>().select(Accounting::getId,Accounting::getAccountingName,Accounting::getParentId,Accounting::getAllParentIds)
+                new LambdaQueryWrapper<Accounting>().select(Accounting::getId, Accounting::getAccountingName, Accounting::getParentId, Accounting::getAllParentIds)
                         .eq(Accounting::getHospId, user.getHospId())
         );
         if (CollUtil.isEmpty(list)) {
             return Collections.emptyList();
         }
         // 所有的
-        List<SelectAccountingVO> all = list.stream().map(i ->{
+        List<SelectAccountingVO> all = list.stream().map(i -> {
             SelectAccountingVO vo = new SelectAccountingVO();
             vo.setValue(i.getId());
             vo.setLabel(i.getAccountingName());
@@ -205,12 +226,12 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
      * @param user
      */
     @Override
-    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public void updateAccount(AccountingEditDTO accountingEditDTO, User user) {
         // TODO: 2021/7/28 追踪溯源需求不满足
         Integer id = accountingEditDTO.getId();
 //        this.checkAccountingCode(accountingEditDTO.getAccountingCode(), user.getHospId());
-        Accounting  one = this.baseMapper.selectOne(
+        Accounting one = this.baseMapper.selectOne(
                 new QueryWrapper<Accounting>().lambda()
                         .eq(Accounting::getAccountingCode, accountingEditDTO.getAccountingCode())
                         .eq(Accounting::getHospId, user.getHospId())
@@ -222,7 +243,7 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
             throw new CostException(500, "当前选中会计科目已被移除");
         }
         if (Objects.nonNull(one) && !byId.getAccountingCode().equals(one.getAccountingCode())) {
-                throw new CostException(500, "会计科目代码已存在,请重新生成");
+            throw new CostException(500, "会计科目代码已存在,请重新生成");
         }
         // 直接修改
         byId.setAccountingCode(accountingEditDTO.getAccountingCode());
@@ -269,7 +290,7 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
 //        return allParentIds;
 //    }
 
-    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public void saveAccount(AccountingEditDTO accountingEditDTO, User user, Accounting byId, Accounting accounting) {
         this.checkAccountingCode(accountingEditDTO.getAccountingCode(), user.getHospId());
         accounting.setAccountingCode(accounting.getAccountingCode());
@@ -295,6 +316,7 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
 
     /**
      * 得到自己还有所有的子节点
+     *
      * @param ids
      * @param accounts
      * @return
@@ -303,7 +325,7 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
 
         List<Accounting> list = this.list(
                 new LambdaQueryWrapper<Accounting>()
-                        .in(Accounting::getParentId, ids).eq(Accounting::getHospId,hospId)
+                        .in(Accounting::getParentId, ids).eq(Accounting::getHospId, hospId)
         );
         if (CollUtil.isEmpty(list)) {
             return accounts;
@@ -320,7 +342,7 @@ public class AccountingServiceImpl extends ServiceImpl<AccountingMapper, Account
      * @param user
      */
     @Override
-    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public void deleteAccount(Integer id, User user) {
         List<Accounting> list = new ArrayList<>();
         List<Accounting> andAllChild = this.getAndAllChild(Arrays.asList(id), user.getHospId(), list);

+ 17 - 2
src/main/java/com/imed/costaccount/service/impl/CostShareParamServiceImpl.java

@@ -1,6 +1,7 @@
 package com.imed.costaccount.service.impl;
 
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -46,7 +47,8 @@ public class CostShareParamServiceImpl extends ServiceImpl<CostShareParamMapper,
         Page<CostShareParam> costShareParamPage = new Page<>(current, pageSize);
         Page<CostShareParam> pages = this.page(costShareParamPage, new QueryWrapper<CostShareParam>().lambda()
                 .eq(!StringUtils.isEmpty(hospId), CostShareParam::getHospId, hospId)
-                .like(!StringUtils.isEmpty(name), CostShareParam::getShareParamName, name).orderByDesc(CostShareParam::getCreateTime))
+                .like(!StringUtils.isEmpty(name), CostShareParam::getShareParamName, name)
+                .orderByDesc(CostShareParam::getCreateTime))
                 ;
         List<CostShareParam> records = pages.getRecords();
         List<CostShareParamVO> costShareParamVOList = BeanUtil.convertList(records, CostShareParamVO.class);
@@ -125,7 +127,7 @@ public class CostShareParamServiceImpl extends ServiceImpl<CostShareParamMapper,
         Integer costShareParamId = costShareParamAccountDto.getCostShareParamId();
         CostShareParam costShareParam = baseMapper.selectById(costShareParamId);
         //  判断当前操作的分层参数的计算方式是不是按科目计算
-        if (NumberConstant.ONE.equals(costShareParam.getCalcType())){
+        if (NumberConstant.TWO.equals(costShareParam.getCalcType())){
             String[] accountIds = costShareParamAccountDto.getAccountIds();
             List<String> accountList = Arrays.asList(accountIds);
             if (!CollectionUtil.isEmpty(accountList)){
@@ -171,4 +173,17 @@ public class CostShareParamServiceImpl extends ServiceImpl<CostShareParamMapper,
         CostShareParamVO costShareParamVO = BeanUtil.convertObj(costShareParam, CostShareParamVO.class);
         return costShareParamVO;
     }
+
+    @Override
+    public List<Integer> selectIsSelect(Integer shareParamId) {
+        CostShareParam byId = this.getById(shareParamId);
+        if (Objects.isNull(byId)) {
+            throw new CostException(500, "当前分摊参数已被移除或不存在");
+        }
+        String accountingId = byId.getAccountingId();
+        String[] split = accountingId.split(StrUtil.COMMA);
+        List<Integer> collect = Arrays.stream(split).map(Integer::valueOf).collect(Collectors.toList());
+        return collect;
+
+    }
 }

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

@@ -45,7 +45,7 @@ public class ResponsibilityDepartmentServiceImpl
         List<CenterDepartmentVO> list = responsibilityService.getParentSon(user);
         for (CenterDepartmentVO centerDepartmentVO : list) {
             if (centerDepartmentVO.getIsGatherCenter() == 2) {
-                centerDepartmentVO.setDepartments(new ArrayList<>());
+                centerDepartmentVO.setDepartments(baseMapper.getDepartByCenterId(centerDepartmentVO.getResponsibilityId()));
             }
             List<CenterDepartmentVO> child = centerDepartmentVO.getChild();
             if (CollUtil.isEmpty(child)) {

+ 91 - 8
src/main/java/com/imed/costaccount/service/impl/ResponsibilityServiceImpl.java

@@ -108,6 +108,9 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
             throw new CostException(500, "非汇总中心不允许添加");
         }
 
+        if (responsibilitySaveDTO.getIsGatherCenter() == 1) {
+            throw new CostException(500, "子层级暂不允许为非汇总中心");
+        }
         this.save(center);
     }
 
@@ -139,14 +142,91 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
             throw new CostException(ErrorCodeEnum.DATA_NOT_EXIST);
         }
 
+        // 判断是否有子节点
+        List<Responsibility> list = this.list(
+                new LambdaQueryWrapper<Responsibility>()
+                        .eq(Responsibility::getHospId, user.getHospId())
+                        .eq(Responsibility::getParentId, id)
+        );
+        // 如果不存在子节点 ,修改它本身
+        if (list.isEmpty()) {
+            this.updateCurResp(center, responsibilityEditDTO, user);
+            return ;
+        }
 
-        // 如果修改父节点节点(只有两层的情况)
-        if (center.getResponsibilityLevel() == 1) {
-            this.updateParent(responsibilityEditDTO, center, user.getHospId());
-            return;
+        this.updateParent(responsibilityEditDTO, center, user.getHospId());
+//        // 不管是哪个绑定到父级目录下
+////        if (responsibilityEditDTO.getParentId() == 0) {
+////
+////        }
+////
+////
+////        // 如果修改父节点节点(只有两层的情况)
+//        if (center.getResponsibilityLevel() == 1) {
+//            this.updateParent(responsibilityEditDTO, center, user.getHospId());
+//            return;
+//        }
+
+//        this.updateCurrent(responsibilityEditDTO, center, user.getHospId());
+    }
+
+    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
+    public void updateAllResp(Responsibility center, ResponsibilityEditDTO dto, User user, List<Responsibility> list) {
+        // 删除原有的父节点数据
+        Integer id = dto.getId();
+        this.removeById(id);
+        this.checkCode(dto.getResponsibilityCode(), user.getHospId());
+        // 新增父节点数据
+        Responsibility newResponsibility = BeanUtil.convertObj(dto, Responsibility.class);
+        newResponsibility.setId(null).setHospId(user.getHospId()).setCreateTime(new Date().getTime()).setResponsibilityLevel(2);
+        // 相关校验
+        if (dto.getParentId() == 0) {
+            newResponsibility.setResponsibilityLevel(1);
+        }
+
+        // 如果是汇总中心,那么不存在分摊级别
+        Integer isGatherCenter = newResponsibility.getIsGatherCenter();
+        if (isGatherCenter == 1) {
+            newResponsibility.setShareId(null);
+            newResponsibility.setShareLevel(0);
+            newResponsibility.setShareName("");
+        }
+
+        if (Objects.nonNull(center) && (center.getIsGatherCenter() == 2)) {
+            throw new CostException(500, "非汇总中心不允许添加");
         }
 
-        this.updateCurrent(responsibilityEditDTO, center, user.getHospId());
+
+    }
+
+    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
+    public void updateCurResp(Responsibility center, ResponsibilityEditDTO dto, User user) {
+        // 删除
+        Integer id = dto.getId();
+        this.removeById(id);
+        // 校验code
+        this.checkCode(dto.getResponsibilityCode(), user.getHospId());
+
+        Responsibility newResponsibility = BeanUtil.convertObj(dto, Responsibility.class);
+        newResponsibility.setId(null)
+                .setHospId(user.getHospId())
+                .setCreateTime(System.currentTimeMillis())
+                .setParentId(dto.getParentId())
+                .setResponsibilityLevel(2);
+        // 如果变成了汇总中心,那么变成第一层
+        if (dto.getIsGatherCenter() == 1) {
+            newResponsibility.setShareId(null)
+                    .setShareLevel(0)
+                    .setShareName(null)
+                    .setParentId(0)
+                    .setResponsibilityLevel(1);
+        }
+        if (dto.getParentId() == 0) {
+            newResponsibility.setResponsibilityLevel(1);
+            // 永远为2的情况
+            newResponsibility.setIsGatherCenter(2);
+        }
+        this.save(newResponsibility);
     }
 
     /**
@@ -166,7 +246,7 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
         // 如果修改是否汇总中心 从是 -> 否那么子节点直接删除
         if (responsibility.getIsGatherCenter() == 1 && dto.getIsGatherCenter() == 2) {
             this.removeByIds(child.stream().map(Responsibility::getId).collect(Collectors.toList()));
-            return;
+//            return;
         }
 
         this.checkCode(dto.getResponsibilityCode(), hospId);
@@ -194,7 +274,10 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
         this.save(newResponsibility);
 
         // 将原来所有父节点下数据关联到新的父节点下
-        child.forEach(i -> i.setParentId(newResponsibility.getId()));
+        child.forEach(i -> {
+            i.setParentId(newResponsibility.getId());
+            i.setIsGatherCenter(2);
+        });
         this.updateBatchById(child);
 
     }
@@ -279,7 +362,7 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
                 .orderByDesc(Responsibility::getCreateTime)
         );
         if (CollUtil.isEmpty(parentList)) {
-            throw new CostException(ErrorCodeEnum.DATA_NOT_EXIST);
+            return Collections.emptyList();
         }
         List<Responsibility> sonList = this.list(
                 new LambdaQueryWrapper<Responsibility>()

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

@@ -39,9 +39,9 @@ public class AccountingController {
     @ApiOperation("获取会计科目列表按收入支出类型")
     @GetMapping("/list")
     @ApiImplicitParam(name = "accountType",value = "会计科目类型1.收入,2.支出")
-    public Result list(@RequestParam Integer accountType){
+    public Result list(@RequestParam Integer accountType,Integer shareParamId){
         User user = (User) SecurityUtils.getSubject().getPrincipal();
-        List<AccountVO> list = accountingService.getListByAccountType(accountType, user);
+        List<AccountVO> list = accountingService.getListByAccountType(accountType, user,shareParamId);
         PageUtils pageUtils = new PageUtils(list, 0, 0, 0);
         return Result.ok(pageUtils);
     }