CostShareLevelServiceImpl.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package com.imed.costaccount.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.imed.costaccount.common.exception.CostException;
  6. import com.imed.costaccount.common.util.PageUtils;
  7. import com.imed.costaccount.mapper.CostShareLevelMapper;
  8. import com.imed.costaccount.model.CostShareLevel;
  9. import com.imed.costaccount.model.User;
  10. import com.imed.costaccount.model.dto.CostShareLevelEditDto;
  11. import com.imed.costaccount.model.dto.CostShareLevelSaveDto;
  12. import com.imed.costaccount.model.vo.CostShareLevelVO;
  13. import com.imed.costaccount.service.CostShareLevelService;
  14. import com.imed.costaccount.common.util.BeanUtil;
  15. import org.apache.shiro.SecurityUtils;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.transaction.annotation.Propagation;
  18. import org.springframework.transaction.annotation.Transactional;
  19. import org.springframework.util.StringUtils;
  20. import java.util.List;
  21. import java.util.Objects;
  22. @Service("costShareLevelService")
  23. public class CostShareLevelServiceImpl extends ServiceImpl<CostShareLevelMapper, CostShareLevel> implements CostShareLevelService {
  24. /**
  25. * 分页查询相关分摊层级信息
  26. *
  27. * @param current
  28. * @param pageSize
  29. * @param name
  30. * @param hospId
  31. * @return
  32. */
  33. @Override
  34. public PageUtils queryList(Integer current, Integer pageSize, String name, Long hospId) {
  35. Page<CostShareLevel> costShareLevelPage = new Page<>(current, pageSize);
  36. Page<CostShareLevel> pages = this.page(costShareLevelPage, new QueryWrapper<CostShareLevel>().lambda()
  37. .eq(!StringUtils.isEmpty(hospId), CostShareLevel::getHospId, hospId)
  38. .like(!StringUtils.isEmpty(name), CostShareLevel::getShareName, name)
  39. .orderByAsc(CostShareLevel::getLeverSort));
  40. List<CostShareLevel> costShareLevelList = pages.getRecords();
  41. List<CostShareLevelVO> costShareLevelVOList = BeanUtil.convertList(costShareLevelList, CostShareLevelVO.class);
  42. int max=costShareLevelVOList.size();
  43. costShareLevelVOList.forEach(i->{
  44. i.setMaxLevel(max);
  45. });
  46. PageUtils pageUtils = new PageUtils(pages);
  47. pageUtils.setList(costShareLevelVOList);
  48. return pageUtils;
  49. }
  50. /**
  51. * 保存
  52. *
  53. * @param costShareLevelSaveDto
  54. */
  55. @Override
  56. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  57. public void addCostShareLevel(CostShareLevelSaveDto costShareLevelSaveDto) {
  58. User user = (User) SecurityUtils.getSubject().getPrincipal();
  59. Long hospId = user.getHospId();
  60. CostShareLevel costShareLevel = BeanUtil.convertObj(costShareLevelSaveDto, CostShareLevel.class);
  61. costShareLevel.setCreateTime(System.currentTimeMillis());
  62. costShareLevel.setHospId(hospId);
  63. baseMapper.insert(costShareLevel);
  64. }
  65. /**
  66. * 修改分摊层级数据
  67. *
  68. * @param costShareLevelEditDto
  69. */
  70. @Override
  71. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  72. public void updateByCostShareLevel(CostShareLevelEditDto costShareLevelEditDto) {
  73. User user = (User) SecurityUtils.getSubject().getPrincipal();
  74. Long hospId = user.getHospId();
  75. Long id = costShareLevelEditDto.getId();
  76. CostShareLevel costShareLevel = baseMapper.selectById(id);
  77. if (Objects.isNull(costShareLevel)){
  78. throw new CostException("分摊层级数据不存在");
  79. }
  80. baseMapper.deleteById(id);
  81. CostShareLevel costShareLevelRequest = BeanUtil.convertObj(costShareLevelEditDto, CostShareLevel.class);
  82. costShareLevelRequest.setId(null);
  83. costShareLevelRequest.setCreateTime(System.currentTimeMillis());
  84. costShareLevelRequest.setHospId(hospId);
  85. baseMapper.insert(costShareLevelRequest);
  86. }
  87. /**
  88. * 获取所有的分摊层级数据
  89. *
  90. * @param hospId
  91. * @return
  92. */
  93. @Override
  94. public List<CostShareLevelVO> getAll(Long hospId) {
  95. QueryWrapper<CostShareLevel> wrapper = new QueryWrapper<>();
  96. wrapper.eq(!StringUtils.isEmpty(hospId),"hosp_id",hospId);
  97. List<CostShareLevel> costShareLevels = baseMapper.selectList(wrapper);
  98. List<CostShareLevelVO> costShareLevelVOList = BeanUtil.convertList(costShareLevels, CostShareLevelVO.class);
  99. return costShareLevelVOList;
  100. }
  101. }