CostShareLevelServiceImpl.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. PageUtils pageUtils = new PageUtils(pages);
  43. pageUtils.setList(costShareLevelVOList);
  44. return pageUtils;
  45. }
  46. /**
  47. * 保存
  48. *
  49. * @param costShareLevelSaveDto
  50. */
  51. @Override
  52. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  53. public void addCostShareLevel(CostShareLevelSaveDto costShareLevelSaveDto) {
  54. User user = (User) SecurityUtils.getSubject().getPrincipal();
  55. Long hospId = user.getHospId();
  56. CostShareLevel costShareLevel = BeanUtil.convertObj(costShareLevelSaveDto, CostShareLevel.class);
  57. costShareLevel.setCreateTime(System.currentTimeMillis());
  58. costShareLevel.setHospId(hospId);
  59. baseMapper.insert(costShareLevel);
  60. }
  61. /**
  62. * 修改分摊层级数据
  63. *
  64. * @param costShareLevelEditDto
  65. */
  66. @Override
  67. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  68. public void updateByCostShareLevel(CostShareLevelEditDto costShareLevelEditDto) {
  69. User user = (User) SecurityUtils.getSubject().getPrincipal();
  70. Long hospId = user.getHospId();
  71. Long id = costShareLevelEditDto.getId();
  72. CostShareLevel costShareLevel = baseMapper.selectById(id);
  73. if (Objects.isNull(costShareLevel)){
  74. throw new CostException("分摊层级数据不存在");
  75. }
  76. baseMapper.deleteById(id);
  77. CostShareLevel costShareLevelRequest = BeanUtil.convertObj(costShareLevelEditDto, CostShareLevel.class);
  78. costShareLevelRequest.setId(null);
  79. costShareLevelRequest.setCreateTime(System.currentTimeMillis());
  80. costShareLevelRequest.setHospId(hospId);
  81. baseMapper.insert(costShareLevelRequest);
  82. }
  83. /**
  84. * 获取所有的分摊层级数据
  85. *
  86. * @param hospId
  87. * @return
  88. */
  89. @Override
  90. public List<CostShareLevelVO> getAll(Long hospId) {
  91. QueryWrapper<CostShareLevel> wrapper = new QueryWrapper<>();
  92. wrapper.eq(!StringUtils.isEmpty(hospId),"hosp_id",hospId);
  93. List<CostShareLevel> costShareLevels = baseMapper.selectList(wrapper);
  94. List<CostShareLevelVO> costShareLevelVOList = BeanUtil.convertList(costShareLevels, CostShareLevelVO.class);
  95. return costShareLevelVOList;
  96. }
  97. }