EquipmentRepository.java 4.0 KB

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