|
@@ -13,16 +13,16 @@ import com.kcim.common.util.JacksonUtil;
|
|
import com.kcim.common.util.PageUtils;
|
|
import com.kcim.common.util.PageUtils;
|
|
import com.kcim.common.util.UserContext;
|
|
import com.kcim.common.util.UserContext;
|
|
import com.kcim.dao.mapper.CostAccountShareMapper;
|
|
import com.kcim.dao.mapper.CostAccountShareMapper;
|
|
-import com.kcim.dao.model.Accounting;
|
|
|
|
-import com.kcim.dao.model.CostAccountShare;
|
|
|
|
-import com.kcim.dao.model.CostShareLevel;
|
|
|
|
-import com.kcim.dao.model.Responsibility;
|
|
|
|
|
|
+import com.kcim.dao.model.*;
|
|
import com.kcim.dao.model.dto.AccountShareCopyDto;
|
|
import com.kcim.dao.model.dto.AccountShareCopyDto;
|
|
import com.kcim.dao.model.dto.CostAccountShareEditDto;
|
|
import com.kcim.dao.model.dto.CostAccountShareEditDto;
|
|
import com.kcim.dao.model.dto.CostAccountShareSaveDto;
|
|
import com.kcim.dao.model.dto.CostAccountShareSaveDto;
|
|
import com.kcim.dao.model.dto.ShareParamEditDto;
|
|
import com.kcim.dao.model.dto.ShareParamEditDto;
|
|
|
|
+import com.kcim.dao.repository.CostAccountShareDetailRepository;
|
|
|
|
+import com.kcim.dao.repository.CostAccountShareParamRepository;
|
|
import com.kcim.service.*;
|
|
import com.kcim.service.*;
|
|
import com.kcim.vo.*;
|
|
import com.kcim.vo.*;
|
|
|
|
+import lombok.AllArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
@@ -37,6 +37,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
|
+@AllArgsConstructor
|
|
@Service("costAccountShareService")
|
|
@Service("costAccountShareService")
|
|
public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMapper, CostAccountShare> implements CostAccountShareService {
|
|
public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMapper, CostAccountShare> implements CostAccountShareService {
|
|
|
|
|
|
@@ -48,13 +49,18 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
|
|
|
|
private final CostShareParamService costShareParamService;
|
|
private final CostShareParamService costShareParamService;
|
|
|
|
|
|
|
|
+ private final CostAccountShareDetailRepository costAccountShareDetailRepository;
|
|
|
|
+ private final CostAccountShareParamRepository costAccountShareParamRepository;
|
|
|
|
|
|
- public CostAccountShareServiceImpl(ResponsibilityService responsibilityService, AccountingService accountingService, CostShareLevelService costShareLevelService, CostShareParamService costShareParamService) {
|
|
|
|
- this.responsibilityService = responsibilityService;
|
|
|
|
- this.accountingService = accountingService;
|
|
|
|
- this.costShareLevelService = costShareLevelService;
|
|
|
|
- this.costShareParamService = costShareParamService;
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+// public CostAccountShareServiceImpl(CostAccountShareParamService costAccountShareParamService,CostAccountShareDetailService costAccountShareDetailService,ResponsibilityService responsibilityService, AccountingService accountingService, CostShareLevelService costShareLevelService, CostShareParamService costShareParamService) {
|
|
|
|
+// this.responsibilityService = responsibilityService;
|
|
|
|
+// this.accountingService = accountingService;
|
|
|
|
+// this.costShareLevelService = costShareLevelService;
|
|
|
|
+// this.costShareParamService = costShareParamService;
|
|
|
|
+// this.costAccountShareDetailService = costAccountShareDetailService;
|
|
|
|
+// this.costAccountShareParamService = costAccountShareParamService;
|
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 分页查询责任中心成本对照相关数据
|
|
* 分页查询责任中心成本对照相关数据
|
|
@@ -157,6 +163,8 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
costAccountShareRequest.setHospId(hospId);
|
|
costAccountShareRequest.setHospId(hospId);
|
|
costAccountShareRequest.setCreateTime(System.currentTimeMillis());
|
|
costAccountShareRequest.setCreateTime(System.currentTimeMillis());
|
|
baseMapper.insert(costAccountShareRequest);
|
|
baseMapper.insert(costAccountShareRequest);
|
|
|
|
+ //提交分摊设置对应的会计科目
|
|
|
|
+ applyShareParamProportion(costAccountShareRequest.getId(),costAccountShareRequest.getAccountingCodes());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -278,6 +286,38 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
BeanUtil.convertObj(accountShareEditDto, costAccountShare);
|
|
BeanUtil.convertObj(accountShareEditDto, costAccountShare);
|
|
costAccountShare.setId(costAccountShareEditDto.getId());
|
|
costAccountShare.setId(costAccountShareEditDto.getId());
|
|
baseMapper.updateById(costAccountShare);
|
|
baseMapper.updateById(costAccountShare);
|
|
|
|
+ //提交分摊设置对应的会计科目
|
|
|
|
+ applyShareParamProportion(costAccountShare.getId(),costAccountShare.getAccountingCodes());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 提交分摊设置对应的会计科目
|
|
|
|
+ * @param accountShareId
|
|
|
|
+ * @param accountingCodes
|
|
|
|
+ */
|
|
|
|
+ public void applyShareParamProportion(Long accountShareId , String accountingCodes ){
|
|
|
|
+ if(StringUtils.isEmpty(accountingCodes)){
|
|
|
|
+ //先作废上次的数据
|
|
|
|
+ costAccountShareDetailRepository.delCostAccountShareDetail(accountShareId);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ List<String> accountingCodeList = Arrays.stream(accountingCodes.split(StrUtil.COMMA)).collect(Collectors.toList());
|
|
|
|
+ applyAccountShareDetail(accountShareId,accountingCodeList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 提交分摊设置对应的会计科目
|
|
|
|
+ * @param accountShareId
|
|
|
|
+ * @param accountingCodeList
|
|
|
|
+ */
|
|
|
|
+ public void applyAccountShareDetail(Long accountShareId , List<String> accountingCodeList){
|
|
|
|
+ //先作废上次的数据
|
|
|
|
+ costAccountShareDetailRepository.delCostAccountShareDetail(accountShareId);
|
|
|
|
+ //保存新的分摊参数
|
|
|
|
+ List<CostAccountShareDetail> costAccountShareDetailList = accountingCodeList.stream().map(accountingCode ->
|
|
|
|
+ createCostAccountShareDetail(accountShareId,accountingCode)).collect(Collectors.toList());
|
|
|
|
+ costAccountShareDetailRepository.saveBatch(costAccountShareDetailList);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -331,6 +371,8 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
String paramList = JacksonUtil.obj2StrPretty(shareParamProportionVOList);
|
|
String paramList = JacksonUtil.obj2StrPretty(shareParamProportionVOList);
|
|
|
|
|
|
costAccountShare.setParamList(paramList);
|
|
costAccountShare.setParamList(paramList);
|
|
|
|
+ //提交分摊参数
|
|
|
|
+ applyShareParamProportion(shareParamEditDto);
|
|
} else {
|
|
} else {
|
|
costAccountShare.setParamList(null);
|
|
costAccountShare.setParamList(null);
|
|
}
|
|
}
|
|
@@ -338,6 +380,20 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
baseMapper.updateById(costAccountShare);
|
|
baseMapper.updateById(costAccountShare);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 提交分摊参数
|
|
|
|
+ * @param shareParamEditDto
|
|
|
|
+ */
|
|
|
|
+ public void applyShareParamProportion(ShareParamEditDto shareParamEditDto){
|
|
|
|
+ //先作废上次的数据
|
|
|
|
+ costAccountShareParamRepository.delCostAccountShareDetail(shareParamEditDto.getId());
|
|
|
|
+ //保存新的分摊参数
|
|
|
|
+ List<ShareParamProportionVO> newShareParamList = shareParamEditDto.getShareParamProportionVOList();
|
|
|
|
+ List<CostAccountShareParam> costAccountShareParamList = newShareParamList.stream().map(newShareParam ->
|
|
|
|
+ createCostAccountShareParam(shareParamEditDto.getId(),newShareParam.getShareParamCode(),newShareParam.getShareParamPopout())).collect(Collectors.toList());
|
|
|
|
+ costAccountShareParamRepository.saveBatch(costAccountShareParamList);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取责任中心成本表的分摊参数的集合
|
|
* 获取责任中心成本表的分摊参数的集合
|
|
*
|
|
*
|
|
@@ -422,7 +478,8 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
accountShareList.add(accountShareRequest);
|
|
accountShareList.add(accountShareRequest);
|
|
});
|
|
});
|
|
this.saveBatch(accountShareList);
|
|
this.saveBatch(accountShareList);
|
|
-
|
|
|
|
|
|
+ //主表向明细表同步
|
|
|
|
+ synMainCostAccountShare(accountShareList);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -500,6 +557,8 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
public void deleteByIds(List<Long> idList) {
|
|
public void deleteByIds(List<Long> idList) {
|
|
this.removeByIds(idList);
|
|
this.removeByIds(idList);
|
|
|
|
+ costAccountShareDetailRepository.delCostAccountShareDetailList(idList);
|
|
|
|
+ costAccountShareParamRepository.delCostAccountShareDetailList(idList);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -510,4 +569,123 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param direction 1主表向明细表同步 2明细表向主表同步
|
|
|
|
+ * @param accountShareId
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
|
|
|
|
+ public void synCostAccountShare(Integer direction, Long accountShareId) {
|
|
|
|
+ if(NumberConstant.ONE.equals(direction)){
|
|
|
|
+ synMainCostAccountShare(direction,accountShareId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 主表向明细表同步
|
|
|
|
+ * @param direction
|
|
|
|
+ * @param accountShareId
|
|
|
|
+ */
|
|
|
|
+ public void synMainCostAccountShare(Integer direction, Long accountShareId) {
|
|
|
|
+ List<CostAccountShare> costAccountShareList = getCostAccountShareList(accountShareId);
|
|
|
|
+ if (CollectionUtils.isEmpty(costAccountShareList)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ synMainCostAccountShare(costAccountShareList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 主表向明细表同步
|
|
|
|
+ * @param costAccountShareList
|
|
|
|
+ */
|
|
|
|
+ public void synMainCostAccountShare(List<CostAccountShare> costAccountShareList){
|
|
|
|
+ //生成分摊设置对应的会计科目对象
|
|
|
|
+ List<CostAccountShareDetail> fullCostAccountShareDetailList=new ArrayList<>();
|
|
|
|
+ //生成分摊设置对应的分摊参数对象
|
|
|
|
+ List<CostAccountShareParam> fullCostAccountShareParamList=new ArrayList<>();
|
|
|
|
+ //按主表的数据逐个转成会计科目对象和分摊参数对象
|
|
|
|
+ costAccountShareList.stream().forEach(costAccountShare->{
|
|
|
|
+ //处理会计科目
|
|
|
|
+ String accountingCodes = costAccountShare.getAccountingCodes();
|
|
|
|
+ if(!StringUtils.isEmpty(accountingCodes)){
|
|
|
|
+ List<String> accountingCodeList = Arrays.stream(accountingCodes.split(StrUtil.COMMA)).collect(Collectors.toList());
|
|
|
|
+ List<CostAccountShareDetail> costAccountShareDetailList = accountingCodeList.stream().map(accountingCode ->
|
|
|
|
+ createCostAccountShareDetail(costAccountShare.getId(),accountingCode)).collect(Collectors.toList());
|
|
|
|
+ fullCostAccountShareDetailList.addAll(costAccountShareDetailList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //处理分摊参数
|
|
|
|
+ String paramList = costAccountShare.getParamList();
|
|
|
|
+ if(!StringUtils.isEmpty(paramList)) {
|
|
|
|
+ List<ShareParamProportionVO> shareParamProportionVOS = JacksonUtil.str2ObjList(paramList, new TypeReference<List<ShareParamProportionVO>>() {
|
|
|
|
+ });
|
|
|
|
+ List<CostAccountShareParam> costAccountShareParamList = shareParamProportionVOS.stream().map(shareParamProportion ->
|
|
|
|
+ createCostAccountShareParam(costAccountShare.getId(), shareParamProportion.getShareParamCode(), shareParamProportion.getShareParamPopout())).
|
|
|
|
+ collect(Collectors.toList());
|
|
|
|
+ fullCostAccountShareParamList.addAll(costAccountShareParamList);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ //作废原来的数据
|
|
|
|
+ List<Long> accountShareIdList = costAccountShareList.stream().map(CostAccountShare::getId).collect(Collectors.toList());
|
|
|
|
+ costAccountShareDetailRepository.delCostAccountShareDetailList(accountShareIdList);
|
|
|
|
+ costAccountShareParamRepository.delCostAccountShareDetailList(accountShareIdList);
|
|
|
|
+ //保存会计科目对象
|
|
|
|
+ if (!CollectionUtils.isEmpty(fullCostAccountShareDetailList)) {
|
|
|
|
+ costAccountShareDetailRepository.saveBatch(fullCostAccountShareDetailList,NumberConstant.ONE_HUNDRED);
|
|
|
|
+ }
|
|
|
|
+ //保存分摊参数对象
|
|
|
|
+ if (!CollectionUtils.isEmpty(fullCostAccountShareParamList)) {
|
|
|
|
+ costAccountShareParamRepository.saveBatch(fullCostAccountShareParamList,NumberConstant.ONE_HUNDRED);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 创建分摊设置对应的会计科目对象
|
|
|
|
+ * @param accountShareId
|
|
|
|
+ * @param accountingCode
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public CostAccountShareDetail createCostAccountShareDetail(Long accountShareId,String accountingCode){
|
|
|
|
+ CostAccountShareDetail costAccountShareDetail = new CostAccountShareDetail();
|
|
|
|
+ costAccountShareDetail.setHospId(UserContext.getHospId());
|
|
|
|
+ costAccountShareDetail.setAccountShareId(accountShareId);
|
|
|
|
+ costAccountShareDetail.setAccountingCode(accountingCode);
|
|
|
|
+ costAccountShareDetail.setCreateUser(String.valueOf(UserContext.getCurrentUser().getId()));
|
|
|
|
+ costAccountShareDetail.setCreateTime(new Date());
|
|
|
|
+ return costAccountShareDetail;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 创建分摊设置对应的分摊参数对象
|
|
|
|
+ * @param accountShareId
|
|
|
|
+ * @param shareParamCode
|
|
|
|
+ * @param shareParamProportion
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public CostAccountShareParam createCostAccountShareParam(Long accountShareId,String shareParamCode,BigDecimal shareParamProportion) {
|
|
|
|
+ CostAccountShareParam costAccountShareParam = new CostAccountShareParam();
|
|
|
|
+ costAccountShareParam.setHospId(UserContext.getHospId());
|
|
|
|
+ costAccountShareParam.setAccountShareId(accountShareId);
|
|
|
|
+ costAccountShareParam.setShareParamCode(shareParamCode);
|
|
|
|
+ costAccountShareParam.setShareParamProportion(shareParamProportion);
|
|
|
|
+ costAccountShareParam.setCreateUser(String.valueOf(UserContext.getCurrentUser().getId()));
|
|
|
|
+ costAccountShareParam.setCreateTime(new Date());
|
|
|
|
+ return costAccountShareParam;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取所有的分摊参数配置
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public List<CostAccountShare> getCostAccountShareList(Long accountShareId){
|
|
|
|
+ LambdaQueryWrapper<CostAccountShare> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(CostAccountShare::getHospId, UserContext.getHospId());
|
|
|
|
+ queryWrapper.eq(CostAccountShare::getDeleteTime, NumberConstant.ZERO);
|
|
|
|
+ if(!ObjectUtils.isEmpty(accountShareId)){
|
|
|
|
+ queryWrapper.eq(CostAccountShare::getId, accountShareId);
|
|
|
|
+ }
|
|
|
|
+ return baseMapper.selectList(queryWrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|