| package com.mzl.flower.service.supplier; | 
|   | 
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
| import com.mzl.flower.config.security.SecurityUtils; | 
| import com.mzl.flower.dto.response.supplier.StationDTO; | 
| import com.mzl.flower.entity.supplier.Station; | 
| import com.mzl.flower.entity.system.Employee; | 
| import com.mzl.flower.entity.system.User; | 
| import com.mzl.flower.mapper.supplier.StationMapper; | 
| import com.mzl.flower.mapper.system.UserMapper; | 
| import org.apache.commons.lang3.StringUtils; | 
| import org.springframework.beans.BeanUtils; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.transaction.annotation.Transactional; | 
|   | 
| import java.math.BigDecimal; | 
| import java.util.List; | 
|   | 
| @Service | 
| @Transactional | 
| public class StationService { | 
|   | 
|   | 
|     private final StationMapper stationMapper; | 
|   | 
|     private final UserMapper userMapper; | 
|   | 
|     public StationService(StationMapper stationMapper, UserMapper userMapper) { | 
|         this.stationMapper = stationMapper; | 
|         this.userMapper = userMapper; | 
|     } | 
|   | 
|   | 
|     public void add(Station dto) { | 
|         if("0".equals(dto.getType())){ //总仓 | 
|             dto.setFreight(new BigDecimal(0)); | 
|         } | 
|         dto.create(SecurityUtils.getUserId()); | 
|         stationMapper.insert(dto); | 
|     } | 
|   | 
|     public void update(Station dto) { | 
|         if("0".equals(dto.getType())){ //总仓 | 
|             dto.setFreight(new BigDecimal(0)); | 
|         } | 
|         dto.update(SecurityUtils.getUserId()); | 
|         stationMapper.updateById(dto); | 
|     } | 
|   | 
|     public void delete(Long id) { | 
|         stationMapper.deleteById(id); | 
|     } | 
|   | 
|     public StationDTO detail(Long id) { | 
|         Station station = stationMapper.selectById(id); | 
|         if(station == null){ | 
|             return null; | 
|         } | 
|         StationDTO dto = new StationDTO(); | 
|         BeanUtils.copyProperties(station, dto); | 
|         if(StringUtils.isNotBlank(dto.getUserIds())){ | 
|             StringBuffer sb = new StringBuffer(); | 
|             for (String userId : dto.getUserIds().split(",")) { | 
|                 User user = userMapper.selectById(userId); | 
|                 if(user != null){ | 
|                     sb.append(user.getNickName()); | 
|                     sb.append(","); | 
|                 } | 
|             } | 
|             dto.setUserNames(sb.toString().substring(0, sb.toString().length() - 1)); | 
|         } | 
|         return dto; | 
|     } | 
|   | 
|     public Page<StationDTO> queryPage(String name, Page page) { | 
|         List<StationDTO> list = stationMapper.queryPage(page, name); | 
|         for (StationDTO dto : list) { | 
|             if(StringUtils.isNotBlank(dto.getUserIds())){ | 
|                 StringBuffer sb = new StringBuffer(); | 
|                 for (String userId : dto.getUserIds().split(",")) { | 
|                     User user = userMapper.selectById(userId); | 
|                     if(user != null){ | 
|                         sb.append(user.getNickName()); | 
|                         sb.append(","); | 
|                     } | 
|                 } | 
|                 dto.setUserNames(sb.toString().substring(0, sb.toString().length() - 1)); | 
|             } | 
|         } | 
|         page.setRecords(list); | 
|         return page; | 
|     } | 
|   | 
|     public List<StationDTO> queryList(String name) { | 
|         List<StationDTO> list = stationMapper.queryList( name); | 
|         return list; | 
|     } | 
|   | 
|     public Boolean getMainWarehouse(String userId) { | 
|         return stationMapper.selectCount(new LambdaQueryWrapper<Station>().eq(Station::getType,"0").like(Station::getUserIds, userId))>0; | 
|     } | 
| } |