123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- package com.imed.costaccount.service.impl;
- import cn.hutool.core.util.StrUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- 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.mapper.CostShareLevelMapper;
- import com.imed.costaccount.model.CostShareLevel;
- import com.imed.costaccount.model.User;
- import com.imed.costaccount.model.dto.CostShareLevelEditDto;
- import com.imed.costaccount.model.dto.CostShareLevelSaveDto;
- import com.imed.costaccount.model.vo.CostShareLevelVO;
- import com.imed.costaccount.service.CostShareLevelService;
- import org.apache.shiro.SecurityUtils;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Propagation;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.StringUtils;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Objects;
- import java.util.stream.Collectors;
- @Service("costShareLevelService")
- public class CostShareLevelServiceImpl extends ServiceImpl<CostShareLevelMapper, CostShareLevel> implements CostShareLevelService {
- /**
- * 分页查询相关分摊层级信息
- *
- * @param current
- * @param pageSize
- * @param name
- * @param hospId
- * @return
- */
- @Override
- public PageUtils queryList(Integer current, Integer pageSize, String name, Long hospId) {
- Page<CostShareLevel> costShareLevelPage = new Page<>(current, pageSize);
- Page<CostShareLevel> pages = this.page(costShareLevelPage, new QueryWrapper<CostShareLevel>().lambda()
- .eq(!StringUtils.isEmpty(hospId), CostShareLevel::getHospId, hospId)
- .like(!StringUtils.isEmpty(name), CostShareLevel::getShareName, name)
- .orderByAsc(CostShareLevel::getLeverSort));
- List<CostShareLevel> costShareLevelList = pages.getRecords();
- List<CostShareLevelVO> costShareLevelVOList = BeanUtil.convertList(costShareLevelList, CostShareLevelVO.class);
- int max=costShareLevelVOList.size();
- costShareLevelVOList.forEach(i->{
- i.setMaxLevel(max);
- });
- PageUtils pageUtils = new PageUtils(pages);
- pageUtils.setList(costShareLevelVOList);
- return pageUtils;
- }
- /**
- * 保存
- *
- * @param costShareLevelSaveDto
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
- public void addCostShareLevel(CostShareLevelSaveDto costShareLevelSaveDto) {
- User user = (User) SecurityUtils.getSubject().getPrincipal();
- Long hospId = user.getHospId();
- // 检验目标层级必须大于等于当前层级
- String targetLevel = costShareLevelSaveDto.getTargetLevel();
- Integer leverSort = costShareLevelSaveDto.getLeverSort();
- checkTargetLevel(targetLevel, leverSort);
- CostShareLevel costShareLevel = BeanUtil.convertObj(costShareLevelSaveDto, CostShareLevel.class);
- costShareLevel.setCreateTime(System.currentTimeMillis());
- costShareLevel.setHospId(hospId);
- baseMapper.insert(costShareLevel);
- }
- /**
- * 查询层级级别大于等于当前
- */
- /**
- * 修改分摊层级数据
- *
- * @param costShareLevelEditDto
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
- public void updateByCostShareLevel(CostShareLevelEditDto costShareLevelEditDto) {
- User user = (User) SecurityUtils.getSubject().getPrincipal();
- Long hospId = user.getHospId();
- Long id = costShareLevelEditDto.getId();
- CostShareLevel costShareLevel = baseMapper.selectById(id);
- if (Objects.isNull(costShareLevel)){
- throw new CostException("分摊层级数据不存在");
- }
- String targetLevel = costShareLevelEditDto.getTargetLevel();
- Integer leverSort = costShareLevelEditDto.getLeverSort();
- checkTargetLevel(targetLevel, leverSort);
- baseMapper.deleteById(id);
- CostShareLevel costShareLevelRequest = BeanUtil.convertObj(costShareLevelEditDto, CostShareLevel.class);
- costShareLevelRequest.setId(null);
- costShareLevelRequest.setCreateTime(System.currentTimeMillis());
- costShareLevelRequest.setHospId(hospId);
- baseMapper.insert(costShareLevelRequest);
- }
- /**
- * 目标层级不能小于当前层级
- * @param targetLevel 目标层级
- * @param leverSort 当前层级
- */
- private void checkTargetLevel(String targetLevel, Integer leverSort) {
- List<Integer> targetLevelList = Arrays.stream(targetLevel.split(StrUtil.COMMA)).map(Integer::valueOf).collect(Collectors.toList());
- targetLevelList.forEach(i -> {
- if (i < leverSort) {
- throw new CostException(500, "目标层级不能小于当前层级");
- }
- });
- }
- /**
- * 获取所有的分摊层级数据
- *
- * @param hospId
- * @return
- */
- @Override
- public List<CostShareLevelVO> getAll(Long hospId) {
- QueryWrapper<CostShareLevel> wrapper = new QueryWrapper<>();
- wrapper.eq(!StringUtils.isEmpty(hospId), "hosp_id", hospId).orderByAsc("lever_sort");
- List<CostShareLevel> costShareLevels = baseMapper.selectList(wrapper);
- List<CostShareLevelVO> costShareLevelVOList = BeanUtil.convertList(costShareLevels, CostShareLevelVO.class);
- return costShareLevelVOList;
- }
- /**
- * 通过分摊层级序号得到分摊层级列表
- *
- * @param targetLevelList 分摊层级序号列表
- * @param hospId 医院id
- * @return CostShareLevel List
- */
- @Override
- public List<CostShareLevel> getListByLevelSort(ArrayList<String> targetLevelList, Long hospId) {
- return this.list(
- new LambdaQueryWrapper<CostShareLevel>()
- .in(CostShareLevel::getLeverSort, targetLevelList)
- .eq(CostShareLevel::getHospId, hospId)
- );
- }
- @Override
- public List<Long> getMaxId(Long hospId) {
- List<Long> ids = baseMapper.getMaxIds(hospId);
- return ids;
- }
- /**
- * 删除分摊等级的数据
- *
- * @param idList 分摊层级的id
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
- public void deleteByIds(List<Integer> idList) {
- this.removeByIds(idList);
- }
- }
|