gongzuming
2024-09-12 478693f3f19392b057bf886a6a34e16321d9e6da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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;
    }
}