Blame view

src/main/java/com/huaheng/pc/config/address/service/AddressServiceImpl.java 5.88 KB
pengcheng authored
1
2
package com.huaheng.pc.config.address.service;
mahuandong authored
3
import com.baomidou.mybatisplus.core.conditions.Wrapper;
pengcheng authored
4
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
周鸿 authored
5
import com.huaheng.common.utils.Wrappers;
pengcheng authored
6
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
import com.huaheng.common.constant.QuantityConstant;
pengcheng authored
8
9
10
11
12
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.pc.config.address.domain.Address;
import com.huaheng.pc.config.address.mapper.AddressMapper;
易文鹏 authored
13
import org.springframework.beans.factory.annotation.Autowired;
pengcheng authored
14
import org.springframework.stereotype.Service;
pengcheng authored
15
import org.springframework.transaction.annotation.Transactional;
pengcheng authored
16
mahuandong authored
17
18
import java.util.List;
pengcheng authored
19
20
21
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {
易文鹏 authored
22
23
    @Autowired
    private AddressMapper addressMapper;
tongzhonghao authored
24
25
26
27
28
29

    @Override
    public String selectAddress(String param, String warehouseCode) {
        return selectAddress(param,warehouseCode,null);
    }
pengcheng authored
30
    @Override
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    public Address selectAddressByParam(String param, String warehouseCode) {
        if(StringUtils.isEmpty(param)){
            throw new ServiceException("参数为空");
        }

        LambdaQueryWrapper<Address> addressLam = new LambdaQueryWrapper<>();
        addressLam.eq(Address::getParam,param)
                .eq(Address::getWarehouseCode, warehouseCode);
        Address address=this.getOne(addressLam);
        if(address == null){
            throw new ServiceException("参数错误,系统没有此参数对应的地址");
        }
        if(StringUtils.isEmpty(address.getUrl())){
            throw new ServiceException("地址为空");
        }
        return address;
    }

    @Override
50
    public String selectAddress(String param, String warehouseCode, String area) {
51
52
53
54
        if(StringUtils.isEmpty(param)){
            throw new ServiceException("参数为空");
        }
xumiao authored
55
        LambdaQueryWrapper<Address> addressLam = new LambdaQueryWrapper<>();
56
        addressLam.eq(Address::getParam,param)
周鸿 authored
57
58
                .eq(Address::getWarehouseCode, warehouseCode)
                .eq(StringUtils.isNotEmpty(area),Address::getNumber, area);
59
60
61
62
63
64
65
66
67
68
69
        Address address=this.getOne(addressLam);
        if(address == null){
            throw new ServiceException("参数错误,系统没有此参数对应的地址");
        }
        if(StringUtils.isEmpty(address.getUrl())){
            throw new ServiceException("地址为空");
        }
        return address.getUrl();
    }

    @Override
tongzhonghao authored
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
    public String selectAddress(String param, String warehouseCode, String area, Integer roadway) {
        if(StringUtils.isEmpty(param)){
            throw new ServiceException("参数为空");
        }

        LambdaQueryWrapper<Address> addressLam = Wrappers.lambdaQuery();
        addressLam.eq(Address::getParam,param)
                .eq(Address::getWarehouseCode, warehouseCode)
                .eq(Address::getArea, area)
                .eq(Address::getRoadway, roadway);
        Address address=this.getOne(addressLam);
        if(address == null){
            throw new ServiceException("参数错误,系统没有此参数对应的地址");
        }
        if(StringUtils.isEmpty(address.getUrl())){
            throw new ServiceException("地址为空");
        }
        return address.getUrl();
    }

    @Override
pengcheng authored
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    public String selectAddress(String param) {
        if(StringUtils.isEmpty(param)){
            throw new ServiceException("参数为空");
        }

        LambdaQueryWrapper<Address> addressLam = Wrappers.lambdaQuery();
        addressLam.eq(Address::getParam,param)
                .eq(Address::getWarehouseCode, ShiroUtils.getWarehouseCode());
        Address address=this.getOne(addressLam);
        if(address == null){
            throw new ServiceException("参数错误,系统没有此参数对应的地址");
        }
        if(StringUtils.isEmpty(address.getUrl())){
            throw new ServiceException("地址为空");
        }
        return address.getUrl();
    }
mahuandong authored
108
109
110
111
112
113
114
115

    /**
     * 复制地址表
     * @param warehouseCode 原仓库编码
     * @param newWarehouseCode 新仓库编码
     * @return 是否复制成功
     */
    @Override
pengcheng authored
116
    @Transactional
mahuandong authored
117
118
119
120
    public Boolean addressCopy(String warehouseCode, String newWarehouseCode) {
        log.trace("开始复制地址表");
        LambdaQueryWrapper<Address> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(Address::getWarehouseCode, newWarehouseCode);
游杰 authored
121
         if (!this.list(lambdaQueryWrapper).isEmpty()){
mahuandong authored
122
123
124
            log.error("该仓库已存在");
            return false;
        }
mahuandong authored
125
        lambdaQueryWrapper = Wrappers.lambdaQuery();
mahuandong authored
126
127
128
        lambdaQueryWrapper.eq(Address::getWarehouseCode, warehouseCode);
        List<Address> addressList = this.list(lambdaQueryWrapper);
129
        for (Address address : addressList) {
mahuandong authored
130
131
132
133
134
135
136
137
138
139
140
            address.setId(null);
            address.setWarehouseCode(newWarehouseCode);
        }

        if ( this.saveBatch(addressList) ){
            log.trace("复制地址表成功,新仓库编码是:"+newWarehouseCode);
            return true;
        } else {
            return false;
        }
    }
周峰 authored
141
142

    @Override
143
    public Address getAddressByUrl(String url, String warehouseCode) {
周峰 authored
144
        LambdaQueryWrapper<Address> addressLam = Wrappers.lambdaQuery();
145
        addressLam.eq(Address::getUrl,url);
周鸿 authored
146
        if(StringUtils.isEmpty(warehouseCode)) {
147
148
            addressLam.eq(Address::getWarehouseCode, QuantityConstant.ryTask_warehouse_code);
        } else {
149
            addressLam.eq(Address::getWarehouseCode, warehouseCode);
150
        }
周峰 authored
151
152
153
        Address address=this.getOne(addressLam);
        return address;
    }
154
易文鹏 authored
155
156
157
158
159
160

    @Override
    public Address selectEntity(Address address) {
        return addressMapper.selectEntity(address);
    }
pengcheng authored
161
}