SpaceRepository.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package com.kcim.dao.repository;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4. import com.kcim.common.constants.NumberConstant;
  5. import com.kcim.common.util.UserContext;
  6. import com.kcim.dao.mapper.SpaceMapper;
  7. import com.kcim.dao.model.Space;
  8. import org.springframework.stereotype.Repository;
  9. import org.springframework.util.CollectionUtils;
  10. import org.springframework.util.StringUtils;
  11. import java.math.BigDecimal;
  12. import java.util.*;
  13. import java.util.stream.Collectors;
  14. /**
  15. * @program: CostAccount
  16. * @description: 空间字典数据库交互
  17. * @author: Wang.YS
  18. * @create: 2023-10-26 15:32
  19. **/
  20. @Repository
  21. public class SpaceRepository extends ServiceImpl<SpaceMapper, Space> {
  22. /**
  23. * 获取列表
  24. * @return 列表
  25. */
  26. public List<Space> getList(){
  27. LambdaQueryWrapper<Space> queryWrapper = new LambdaQueryWrapper<>();
  28. queryWrapper.eq(Space::getHospId, UserContext.getHospId());
  29. return this.list(queryWrapper);
  30. }
  31. public Map<String, BigDecimal> getSpaceMinuteMap() {
  32. List<Space> list = getChildList();
  33. if(!CollectionUtils.isEmpty(list)){
  34. return list.stream().collect(Collectors.toMap(Space::getCode, Space::getCostPerMinute, (a, b) -> b));
  35. }
  36. return new HashMap<>();
  37. }
  38. public List<Space> getChildList(){
  39. LambdaQueryWrapper<Space> queryWrapper = new LambdaQueryWrapper<>();
  40. queryWrapper.eq(Space::getHospId, UserContext.getHospId());
  41. queryWrapper.eq(Space::getType, NumberConstant.ONE);
  42. return this.list(queryWrapper);
  43. }
  44. public List<Space> getList(String name, Integer type) {
  45. LambdaQueryWrapper<Space> queryWrapper = new LambdaQueryWrapper<>();
  46. queryWrapper.eq(Space::getHospId, UserContext.getHospId());
  47. if(!type.equals(NumberConstant.ONE)){
  48. queryWrapper.eq(Space::getStatus,type);
  49. }
  50. if(!StringUtils.isEmpty(name)){
  51. queryWrapper.like(Space::getName,name);
  52. }
  53. return this.list(queryWrapper);
  54. }
  55. public List<Space> getParentList() {
  56. LambdaQueryWrapper<Space> queryWrapper = new LambdaQueryWrapper<>();
  57. queryWrapper.eq(Space::getHospId, UserContext.getCurrentLoginHospId());
  58. queryWrapper.eq(Space::getParentCode, NumberConstant.ZERO_S);
  59. return this.list(queryWrapper);
  60. }
  61. public void deleteSpaceCost(Integer id) {
  62. Space space = this.getById(id);
  63. if(Objects.nonNull(space)){
  64. space.setDeleteTime(new Date());
  65. space.setDeleteUser(String.valueOf(UserContext.getCurrentUser().getId()));
  66. this.updateById(space);
  67. this.removeById(id);
  68. }
  69. }
  70. public void removeList(List<Space> list) {
  71. for (Space space : list) {
  72. space.setDeleteTime(new Date());
  73. space.setDeleteUser(String.valueOf(UserContext.getCurrentUser().getId()));
  74. }
  75. this.updateBatchById(list);
  76. List<Integer> collect = list.stream().map(Space::getId).collect(Collectors.toList());
  77. this.removeBatchByIds(collect);
  78. }
  79. public List<Space> getByCode(String code) {
  80. LambdaQueryWrapper<Space> queryWrapper = new LambdaQueryWrapper<>();
  81. queryWrapper.eq(Space::getHospId, UserContext.getHospId());
  82. queryWrapper.eq(Space::getCode, code);
  83. return this.list(queryWrapper);
  84. }
  85. public Space getOneByCode(String code) {
  86. LambdaQueryWrapper<Space> queryWrapper = new LambdaQueryWrapper<>();
  87. queryWrapper.eq(Space::getHospId, UserContext.getHospId());
  88. queryWrapper.eq(Space::getCode, code);
  89. return this.getOne(queryWrapper);
  90. }
  91. }