123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- 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;
- import com.imed.costaccount.common.exception.CostException;
- import com.imed.costaccount.common.util.BeanUtil;
- import com.imed.costaccount.common.util.PageUtils;
- import com.imed.costaccount.constants.NumberConstant;
- import com.imed.costaccount.mapper.CostShareParamMapper;
- import com.imed.costaccount.model.CostShareParam;
- import com.imed.costaccount.model.dto.CostShareParamAccountDto;
- import com.imed.costaccount.model.dto.CostShareParamEditDto;
- import com.imed.costaccount.model.dto.CostShareParamSaveDto;
- import com.imed.costaccount.model.vo.CostShareParamVO;
- import com.imed.costaccount.service.CostShareParamService;
- import io.swagger.annotations.ApiOperation;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Propagation;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.CollectionUtils;
- import org.springframework.util.StringUtils;
- import java.util.*;
- import java.util.stream.Collectors;
- @Service("costShareParamService")
- public class CostShareParamServiceImpl extends ServiceImpl<CostShareParamMapper, CostShareParam> implements CostShareParamService {
- /**
- * 分页查询相关的分摊参数数据
- *
- * @param current
- * @param pageSize
- * @param name
- * @return
- */
- @Override
- public PageUtils queryList(Integer current, Integer pageSize, String name,Long hospId) {
- 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))
- ;
- List<CostShareParam> records = pages.getRecords();
- List<CostShareParamVO> costShareParamVOList = BeanUtil.convertList(records, CostShareParamVO.class);
- PageUtils pageUtils = new PageUtils(pages);
- pageUtils.setList(costShareParamVOList);
- return pageUtils;
- }
- /**
- * 保存分摊参数
- * 保存的时候需要校验分摊参数
- * @param costShareParamSaveDto
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
- public void addCostShareParam(CostShareParamSaveDto costShareParamSaveDto) {
- //检验分摊参数是存在
- getCostShareParamByCode(costShareParamSaveDto);
- CostShareParam costShareParam = BeanUtil.convertObj(costShareParamSaveDto, CostShareParam.class);
- costShareParam.setCreateTime(System.currentTimeMillis());
- baseMapper.insert(costShareParam);
- }
- /**
- * 检验分摊参数是存在
- */
- private void getCostShareParamByCode(CostShareParamSaveDto costShareParamSaveDto) {
- List<CostShareParam> costShareParamList = baseMapper.selectList(new QueryWrapper<CostShareParam>().lambda()
- .eq(CostShareParam::getHospId, costShareParamSaveDto.getHospId()));
- // 检验添加的分摊参数是否存在
- if (!CollectionUtils.isEmpty(costShareParamList)){
- Map<String, List<CostShareParam>> costShareMap = costShareParamList.stream().collect(Collectors.groupingBy(CostShareParam::getShareParamCode));
- if (!CollectionUtils.isEmpty(costShareMap.get(costShareParamSaveDto.getShareParamCode()))){
- throw new CostException(500,"分摊参数已存在");
- }
- }
- }
- /**
- * 修改分摊参数
- *
- * @param costShareParamEditDto
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
- public void updateCostShareParam(CostShareParamEditDto costShareParamEditDto) {
- Long id = costShareParamEditDto.getId();
- CostShareParam costShareParam = baseMapper.selectById(id);
- if (Objects.isNull(costShareParam)){
- throw new CostException(500,"对不起分摊参数不存在");
- }
- baseMapper.deleteById(id);
- // 判断当前输入的Code以最初的Code是否一样
- List<CostShareParam> costShareParamList = baseMapper.selectList(new QueryWrapper<CostShareParam>().lambda().select(CostShareParam::getShareParamCode).eq(CostShareParam::getHospId, costShareParamEditDto.getHospId()));
- Map<String, List<CostShareParam>> map = costShareParamList.stream().collect(Collectors.groupingBy(CostShareParam::getShareParamCode));
- if (!CollectionUtils.isEmpty(map.get(costShareParamEditDto.getShareParamCode()))){
- throw new CostException(500,"对不起分摊参数代码已存在");
- }
- CostShareParam costShareParamRequest = BeanUtil.convertObj(costShareParamEditDto, CostShareParam.class);
- costShareParamRequest.setId(null);
- costShareParamRequest.setCreateTime(System.currentTimeMillis());
- if (NumberConstant.ONE.equals( costShareParamEditDto.getShareParamCode()) && NumberConstant.ONE.equals(costShareParamEditDto.getShareParamCode())){
- costShareParamRequest.setAccountingId(costShareParam.getAccountingId());
- }
- baseMapper.insert(costShareParamRequest);
- }
- /**
- * 为按照科目的计算方式添加成本科目
- *
- * @param costShareParamAccountDto
- * @return
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
- public CostShareParam updateCostShareParamByAccountId(CostShareParamAccountDto costShareParamAccountDto) {
- Long costShareParamId = costShareParamAccountDto.getCostShareParamId();
- CostShareParam costShareParam = baseMapper.selectById(costShareParamId);
- // 判断当前操作的分层参数的计算方式是不是按科目计算
- if (NumberConstant.TWO.equals(costShareParam.getCalcType())){
- String[] accountIds = costShareParamAccountDto.getAccountIds();
- List<String> accountList = Arrays.asList(accountIds);
- if (!CollectionUtil.isEmpty(accountList)){
- String accounds = accountList.stream().map(String::valueOf).collect(Collectors.joining(","));
- costShareParam.setAccountingId(accounds);
- }else {
- costShareParam.setAccountingId(null);
- }
- baseMapper.updateById(costShareParam);
- }else {
- throw new CostException(500,"计算方式不是按会计科目计算");
- }
- return null;
- }
- /**
- * 获取所有分摊参数的集合信息
- *
- * @param hospId
- * @return
- */
- @Override
- @ApiOperation("获取所有的分摊参数的集合数据")
- public List<CostShareParamVO> getAll(Long hospId) {
- List<CostShareParam> costShareParamList = baseMapper.selectList(new QueryWrapper<CostShareParam>().lambda()
- .eq(CostShareParam::getHospId, hospId));
- List<CostShareParamVO> costShareParamVOList = BeanUtil.convertList(costShareParamList, CostShareParamVO.class);
- return costShareParamVOList;
- }
- /**
- * 根据医院的Id分摊参数的ID获取对应的分摊参数的数据
- *
- * @param id
- * @param hospId
- * @return
- */
- @Override
- public CostShareParamVO getByHospIdAndAPramId(Integer id, Long hospId) {
- CostShareParam costShareParam = baseMapper.selectOne(new QueryWrapper<CostShareParam>().lambda()
- .eq(CostShareParam::getHospId, hospId)
- .eq(CostShareParam::getId, id));
- 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)) {
- return Collections.emptyList();
- }
- String accountingId = byId.getAccountingId();
- if (!StringUtils.isEmpty(accountingId)){
- String[] split = accountingId.split(StrUtil.COMMA);
- List<Integer> collect = Arrays.stream(split).map(Integer::valueOf).collect(Collectors.toList());
- return collect;
- }else {
- return Collections.emptyList();
- }
- }
- }
|