DepartmentServiceImpl.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package com.imed.costaccount.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  6. import com.imed.costaccount.common.exception.CostException;
  7. import com.imed.costaccount.common.util.BeanUtil;
  8. import com.imed.costaccount.common.util.PageUtils;
  9. import com.imed.costaccount.mapper.DepartmentMapper;
  10. import com.imed.costaccount.model.Department;
  11. import com.imed.costaccount.model.User;
  12. import com.imed.costaccount.model.dto.DepartmentRequest;
  13. import com.imed.costaccount.model.vo.DepartmentVO;
  14. import com.imed.costaccount.service.DepartmentService;
  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("departmentService")
  23. public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService {
  24. /**
  25. * 分页查询科室信息
  26. *
  27. * @param page
  28. * @param pageSize
  29. * @param hospId
  30. * @param name
  31. * @return
  32. */
  33. @Override
  34. public PageUtils queryList(Integer page, Integer pageSize,Integer hospId, String name) {
  35. Page<Department> departPage = new Page<>(page, pageSize);
  36. Page<Department> pages = this.page(departPage, new QueryWrapper<Department>().lambda()
  37. .eq(!StringUtils.isEmpty(hospId), Department::getHospId, hospId)
  38. .like(!StringUtils.isEmpty(name), Department::getDepartmentName, name));
  39. List<Department> records = pages.getRecords();
  40. List<DepartmentVO> departmentVOList = BeanUtil.convertList(records, DepartmentVO.class);
  41. PageUtils pageUtils = new PageUtils(pages);
  42. pageUtils.setList(departmentVOList);
  43. return pageUtils;
  44. }
  45. /**
  46. * 根据指定条件查询科室的相关信息
  47. * @param id
  48. * @param departmentName
  49. * @param departmentCode
  50. * @param hospId
  51. * @return
  52. */
  53. @Override
  54. public List<Department> getByDepartment(Integer id,String departmentName,String departmentCode,Integer hospId) {
  55. LambdaQueryWrapper<Department> wrapper = new QueryWrapper<Department>().lambda()
  56. .eq(!StringUtils.isEmpty(id), Department::getId, id)
  57. .like(!StringUtils.isEmpty(departmentName), Department::getDepartmentName, departmentName)
  58. .eq(!StringUtils.isEmpty(departmentCode), Department::getDepartmentCode, departmentCode)
  59. .eq(!StringUtils.isEmpty(hospId), Department::getHospId, hospId);
  60. List<Department> departmentList = baseMapper.selectList(wrapper);
  61. return departmentList;
  62. }
  63. /**
  64. * 保存科室信息
  65. * TODO 检验科室信息是否存在
  66. * @param departmentRequest
  67. */
  68. @Override
  69. public void addDepartment(DepartmentRequest departmentRequest) {
  70. User user = (User) SecurityUtils.getSubject().getPrincipal();
  71. Integer hospId = user.getHospId();
  72. departmentRequest.setHospId(hospId);
  73. Department department = BeanUtil.convertObj(departmentRequest, Department.class);
  74. department.setId(null);
  75. department.setCreateTime(System.currentTimeMillis());
  76. baseMapper.insert(department);
  77. }
  78. /**
  79. * 修改科室信息
  80. *
  81. * @param departmentRequest
  82. */
  83. @Override
  84. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  85. public void updateByDepartment(DepartmentRequest departmentRequest) {
  86. User user = (User) SecurityUtils.getSubject().getPrincipal();
  87. Integer hospId = user.getHospId();
  88. Integer id = departmentRequest.getId();
  89. Department department = baseMapper.selectById(id);
  90. if (Objects.isNull(department)){
  91. throw new CostException("未找到相关科室信息");
  92. }
  93. baseMapper.deleteById(id);
  94. // 新增操作
  95. Department departmentResponse = BeanUtil.convertObj(departmentRequest, Department.class);
  96. departmentResponse.setId(null);
  97. departmentResponse.setCreateTime(System.currentTimeMillis());
  98. departmentResponse.setHospId(hospId);
  99. baseMapper.insert(departmentResponse);
  100. }
  101. }