2
0

CostShareLevelServiceImpl.java 4.3 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.mapper.CostShareLevelMapper;
  7. import com.imed.costaccount.model.CostShareLevel;
  8. import com.imed.costaccount.model.User;
  9. import com.imed.costaccount.model.dto.CostShareLevelEditDto;
  10. import com.imed.costaccount.model.dto.CostShareLevelSaveDto;
  11. import com.imed.costaccount.model.vo.CostShareLevelVO;
  12. import com.imed.costaccount.service.CostShareLevelService;
  13. import com.imed.costaccount.utils.BeanUtil;
  14. import com.imed.costaccount.utils.PageUtils;
  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, Integer 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. public void addCostShareLevel(CostShareLevelSaveDto costShareLevelSaveDto) {
  53. User user = (User) SecurityUtils.getSubject().getPrincipal();
  54. Integer hospId = user.getHospId();
  55. CostShareLevel costShareLevel = BeanUtil.convertObj(costShareLevelSaveDto, CostShareLevel.class);
  56. costShareLevel.setCreateTime(System.currentTimeMillis());
  57. costShareLevel.setHospId(hospId);
  58. baseMapper.insert(costShareLevel);
  59. }
  60. /**
  61. * 修改分摊层级数据
  62. *
  63. * @param costShareLevelEditDto
  64. */
  65. @Override
  66. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  67. public void updateByCostShareLevel(CostShareLevelEditDto costShareLevelEditDto) {
  68. User user = (User) SecurityUtils.getSubject().getPrincipal();
  69. Integer hospId = user.getHospId();
  70. Integer id = costShareLevelEditDto.getId();
  71. CostShareLevel costShareLevel = baseMapper.selectById(id);
  72. if (Objects.isNull(costShareLevel)){
  73. throw new CostException("分摊层级数据不存在");
  74. }
  75. baseMapper.deleteById(id);
  76. CostShareLevel costShareLevelRequest = BeanUtil.convertObj(costShareLevelEditDto, CostShareLevel.class);
  77. costShareLevelRequest.setId(null);
  78. costShareLevelRequest.setCreateTime(System.currentTimeMillis());
  79. costShareLevelRequest.setHospId(hospId);
  80. baseMapper.insert(costShareLevelRequest);
  81. }
  82. /**
  83. * 获取所有的分摊层级数据
  84. *
  85. * @param hospId
  86. * @return
  87. */
  88. @Override
  89. public List<CostShareLevelVO> getAll(Integer hospId) {
  90. QueryWrapper<CostShareLevel> wrapper = new QueryWrapper<>();
  91. wrapper.eq(!StringUtils.isEmpty(hospId),"hosp_id",hospId);
  92. List<CostShareLevel> costShareLevels = baseMapper.selectList(wrapper);
  93. List<CostShareLevelVO> costShareLevelVOList = BeanUtil.convertList(costShareLevels, CostShareLevelVO.class);
  94. return costShareLevelVOList;
  95. }
  96. }