package com.kcim.dao.repository; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.SpaceMapper; import com.kcim.dao.model.Space; 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:32 **/ @Repository public class SpaceRepository extends ServiceImpl { /** * 获取列表 * @return 列表 */ public List getList(){ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Space::getHospId, UserContext.getHospId()); return this.list(queryWrapper); } public Map getSpaceMinuteMap() { List list = getChildList(); if(!CollectionUtils.isEmpty(list)){ return list.stream().collect(Collectors.toMap(Space::getCode, Space::getCostPerMinute, (a, b) -> b)); } return new HashMap<>(); } public List getChildList(){ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Space::getHospId, UserContext.getHospId()); queryWrapper.eq(Space::getType, NumberConstant.ONE); return this.list(queryWrapper); } public List getList(String name, Integer type) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Space::getHospId, UserContext.getHospId()); if(!type.equals(NumberConstant.ONE)){ queryWrapper.eq(Space::getStatus,type); } if(!StringUtils.isEmpty(name)){ queryWrapper.like(Space::getName,name); } return this.list(queryWrapper); } public List getParentList() { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Space::getHospId, UserContext.getCurrentLoginHospId()); queryWrapper.eq(Space::getParentCode, NumberConstant.ZERO_S); return this.list(queryWrapper); } public void deleteSpaceCost(Integer id) { Space space = this.getById(id); if(Objects.nonNull(space)){ space.setDeleteTime(new Date()); space.setDeleteUser(String.valueOf(UserContext.getCurrentUser().getId())); this.updateById(space); this.removeById(id); } } public void removeList(List list) { for (Space space : list) { space.setDeleteTime(new Date()); space.setDeleteUser(String.valueOf(UserContext.getCurrentUser().getId())); } this.updateBatchById(list); List collect = list.stream().map(Space::getId).collect(Collectors.toList()); this.removeBatchByIds(collect); } public List getByCode(String code) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Space::getHospId, UserContext.getHospId()); queryWrapper.eq(Space::getCode, code); return this.list(queryWrapper); } public Space getOneByCode(String code) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Space::getHospId, UserContext.getHospId()); queryWrapper.eq(Space::getCode, code); return this.getOne(queryWrapper); } }