package com.kcim.dao.repository; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.kcim.common.constants.NumberConstant; import com.kcim.common.util.UserContext; import com.kcim.dao.mapper.EquipmentMapper; import com.kcim.dao.model.Equipment; import com.kcim.vo.SessionUserVO; import org.springframework.stereotype.Repository; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; /** * @program: CostAccount * @description: 设备字典数据库交互 * @author: Wang.YS * @create: 2023-10-26 15:21 **/ @Repository public class EquipmentRepository extends ServiceImpl { /** * 获取列表 * @return 列表 */ public List getList(){ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Equipment::getHospId, UserContext.getHospId()); return this.list(queryWrapper); } public Map getEquipmentMinuteMap() { List list = getList(); if(!CollectionUtils.isEmpty(list)){ return list.stream().collect(Collectors.toMap(Equipment::getCode, Equipment::getCostPerMinute, (a, b) -> b)); } return new HashMap<>(); } public Page getPage(Integer current, Integer pageSize, String name, Integer stop) { Page page = new Page<>(current,pageSize); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Equipment::getHospId, UserContext.getHospId()); if(!stop.equals(NumberConstant.ONE)){ queryWrapper.eq(Equipment::getStatus,stop); } if(!StringUtils.isEmpty(name)){ queryWrapper.like(Equipment::getName,name); } return this.page(page,queryWrapper); } public void deleteEquipment(Integer id) { Equipment equipment = this.getById(id); if(Objects.nonNull(equipment)){ equipment.setDeleteTime(new Date()); equipment.setDeleteUser(String.valueOf(UserContext.getCurrentUser().getId())); this.updateById(equipment); this.removeById(id); } } public void removeList(List list) { for (Equipment equipment : list) { equipment.setDeleteTime(new Date()); equipment.setDeleteUser(String.valueOf(UserContext.getCurrentUser().getId())); } this.updateBatchById(list); List collect = list.stream().map(Equipment::getId).collect(Collectors.toList()); this.removeBatchByIds(collect); } public List getByCode(String code) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Equipment::getHospId, UserContext.getHospId()); queryWrapper.eq(Equipment::getCode, code); return this.list(queryWrapper); } public Equipment getOneByCode(String code) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Equipment::getHospId, UserContext.getHospId()); queryWrapper.eq(Equipment::getCode, code); return this.getOne(queryWrapper); } public Map getEquipmentMinuteMap(SessionUserVO currentUser) { List list = getList(currentUser); if(!CollectionUtils.isEmpty(list)){ return list.stream().collect(Collectors.toMap(Equipment::getCode, Equipment::getCostPerMinute, (a, b) -> b)); } return new HashMap<>(); } private List getList(SessionUserVO currentUser) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Equipment::getHospId, currentUser.getHospId()); return this.list(queryWrapper); } }