liujie
2023-05-22 9f2315d92cc93f8f431805a10ea9ce3f79fa7eb2
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
package com.stylefeng.guns.modular.system.service.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.google.maps.model.LatLng;
import com.stylefeng.guns.modular.system.dao.*;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.modular.system.utils.GoogleMap.GeocodeVo;
import com.stylefeng.guns.modular.system.utils.GoogleMap.GoogleMapUtil;
import io.swagger.annotations.ApiModel;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 卡车公司 服务实现类
 * </p>
 *
 * @author stylefeng
 * @since 2023-01-30
 */
@Service
public class TCompanyServiceImpl extends ServiceImpl<TCompanyMapper, TCompany> implements ITCompanyService {
    @Autowired
    private ITQuoteService quoteService;
 
    @Autowired
    private ITOrderService orderService;
 
    @Autowired
    private ITGoodsService goodsService;
 
    @Autowired
    private TCompanyMapper companyMapper;
 
    @Autowired
    private TPriceMapper priceMapper;
    @Autowired
    private GoogleMapUtil googleMapUtil;
 
    @Autowired
    private TCountryMapper tCountryMapper;
 
    @Autowired
    private TPortMapper tPortMapper;
 
    @Autowired
    private WareHouseMapper wareHouseMapper;
 
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ITUserService itUserService;
 
    @Override
    public List<TCompanyVo> selectList1(Page<TCompanyVo> tCompanyVoPage, String name, String account) {
        return this.baseMapper.selectList1(tCompanyVoPage,name,account);
    }
 
    @Override
    public List<TCompanyVo> selectList2(Page<TCompanyVo> tCompanyVoPage, String name, String account, Integer state) {
        return this.baseMapper.selectList2(tCompanyVoPage,name,account,state);
    }
 
    @Override
    public TCompanyCalculationRespOne getQuotaFromId(Long id) {
        TQuote quote = quoteService.selectById(id);
        TCompanyCalculationRespOne tCompanyCalculationRespOne = new TCompanyCalculationRespOne();
        tCompanyCalculationRespOne.setQuoteId(quote.getId());
 
        List<TGoods> goods = goodsService.selectList(new EntityWrapper<TGoods>());
        // 找出所有的订单
        List<TOrder> orders = orderService.selectList(new EntityWrapper<TOrder>().eq("e_zip_z", quote.getOrderId()));
 
        TOrder tOrder = orders.get(0);
        TUser user = itUserService.selectById(quote.getUserId());
        tCompanyCalculationRespOne.setPickupStr(tOrder.getAccessorialStr());
        tCompanyCalculationRespOne.setDestinationStr(tOrder.getDeliveryStr());
        tCompanyCalculationRespOne.setCustomer(user.getCompanyName());
 
 
        if(quote.getCreateId()!=null){
            User user1 = userMapper.selectById(quote.getCreateId());
            tCompanyCalculationRespOne.setCreateUser(user1.getName());
        }else {
            tCompanyCalculationRespOne.setCreateUser(user.getCompanyName());
        }
 
        Integer port = tOrder.getPort();
        TPort tPort = tPortMapper.selectById(port);
        TCountry tCountry = tCountryMapper.selectById(tPort.getCity());
        tCompanyCalculationRespOne.setMetro(tCountry.getName());
        tCompanyCalculationRespOne.setZipCode(tPort.getZipCode());
        TCountry tCountry1 = tCountryMapper.selectById(tCountry.getParentId());
        tCompanyCalculationRespOne.setState(tCountry1.getName());
        tCompanyCalculationRespOne.setShipmentEta(tOrder.getShipmentDate());
        String warehouse = tOrder.getWarehouse();
        if(!"0".equals(warehouse)){
            List<TWarehouse> code = wareHouseMapper.selectList(new EntityWrapper<TWarehouse>().eq("code", warehouse));
            if(code.size()>0){
                tCompanyCalculationRespOne.setWarehouse(code.get(0).getAddress());
            }
        }
        tCompanyCalculationRespOne.setDeliveryDate(tOrder.getDeliveryDate());
 
 
        Integer companyId = tOrder.getCompanyId();
        List<TOrder> orders1 = orderService.selectList(new EntityWrapper<TOrder>().eq("e_zip_z", quote.getOrderId()).eq("company_id", companyId));
 
        ArrayList<LonLat> lonLats = new ArrayList<>();
        LonLat latLng = new LonLat();
        latLng.setLat("-113.6510249618184");
        latLng.setLng("37.8924429618184");
        lonLats.add(latLng);
        latLng=new LonLat();
        latLng.setLat("-113.066919618184");
        latLng.setLng("37.684389618184");
        lonLats.add(latLng);
        tCompanyCalculationRespOne.setLonLats(lonLats);
        ArrayList<TGoods> tGoods = new ArrayList<>();
        // 获取其中一个订单 去获取货物
        for (TOrder order : orders1) {
            List<TGoods> goodsList = goods.stream().filter(good -> good.getOrderId().equals(order.getId())).collect(Collectors.toList());
            tGoods.addAll(goodsList);
        }
        tCompanyCalculationRespOne.setTGoods(tGoods);
 
 
        ArrayList<CompanyInfo> companyInfos = new ArrayList<>();
        for (TOrder order : orders) {
            CompanyInfo tCompanyCalculationResp = new CompanyInfo();
            // 查询公司
            TCompany company = companyMapper.selectById(order.getCompanyId());
            tCompanyCalculationResp.setCompanyName(company.getName());
            tCompanyCalculationResp.setCompanyId(company.getId());
            tCompanyCalculationResp.setCarGoNumber(String.valueOf(company.getMcNumber()));
            tCompanyCalculationResp.setImg(company.getHeadImg());
            tCompanyCalculationResp.setExpirationDate(company.getExpirationTime());
 
            // 查询公司下的价格集合
            List<TPrice> prices = priceMapper.selectList(new EntityWrapper<TPrice>().eq("order_id", order.getId()));
            List<TCompanyResp> tCompanyRespList = new ArrayList<>();
            for (TPrice price : prices) {
                TCompanyResp tCompanyResp = new TCompanyResp();
                tCompanyResp.setOrderId(order.getId());
                tCompanyResp.setName(price.getType());
                tCompanyResp.setPrice(price.getPrice());
                tCompanyRespList.add(tCompanyResp);
            }
            BigDecimal bigDecimal = tCompanyRespList.stream().map(TCompanyResp::getPrice).reduce(BigDecimal::add).orElse(new BigDecimal(0.00));
            tCompanyCalculationResp.setAllTotal(bigDecimal);
            tCompanyCalculationResp.setList(tCompanyRespList);
            // 过滤订单
            List<TOrder> orderList = orders.stream().filter(o -> o.getCompanyId().equals(company.getId())).collect(Collectors.toList());
            tCompanyCalculationResp.setOrderList(orderList);
 
            companyInfos.add(tCompanyCalculationResp);
        }
        ArrayList<CompanyInfo> collect = companyInfos.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CompanyInfo::getCompanyId))), ArrayList::new));
        tCompanyCalculationRespOne.setCompanyInfos(collect);
        return tCompanyCalculationRespOne;
    }
 
    @Override
    public TCompanyCalculationRespOne getQuotaFromIdAndCompanyId(Long id, Integer companyIds) {
        TQuote quote = quoteService.selectById(id);
        TCompanyCalculationRespOne tCompanyCalculationRespOne = new TCompanyCalculationRespOne();
        tCompanyCalculationRespOne.setQuoteId(quote.getId());
 
        List<TGoods> goods = goodsService.selectList(new EntityWrapper<TGoods>());
        // 找出所有的订单
        List<TOrder> orders = orderService.selectList(new EntityWrapper<TOrder>().eq("e_zip_z", quote.getOrderId()));
 
        TOrder tOrder = orders.get(0);
        TUser user = itUserService.selectById(quote.getUserId());
        tCompanyCalculationRespOne.setPickupStr(tOrder.getAccessorialStr());
        tCompanyCalculationRespOne.setDestinationStr(tOrder.getDeliveryStr());
        tCompanyCalculationRespOne.setCustomer(user.getCompanyName());
 
        if(quote.getCreateId()!=null){
 
            User user1 = userMapper.selectById(quote.getCreateId());
            tCompanyCalculationRespOne.setCreateUser(user1.getName());
        }else {
            tCompanyCalculationRespOne.setCreateUser(user.getCompanyName());
        }
        Integer port = tOrder.getPort();
        TPort tPort = tPortMapper.selectById(port);
        TCountry tCountry = tCountryMapper.selectById(tPort.getCity());
        tCompanyCalculationRespOne.setMetro(tCountry.getName());
        tCompanyCalculationRespOne.setZipCode(tPort.getZipCode());
        TCountry tCountry1 = tCountryMapper.selectById(tCountry.getParentId());
        tCompanyCalculationRespOne.setState(tCountry1.getName());
        tCompanyCalculationRespOne.setShipmentEta(tOrder.getShipmentDate());
        String warehouse = tOrder.getWarehouse();
        if(!"0".equals(warehouse)){
            List<TWarehouse> code = wareHouseMapper.selectList(new EntityWrapper<TWarehouse>().eq("code", warehouse));
            if(code.size()>0){
                tCompanyCalculationRespOne.setWarehouse(code.get(0).getAddress());
            }
        }
        tCompanyCalculationRespOne.setDeliveryDate(tOrder.getDeliveryDate());
        List<TOrder> orders1 = orderService.selectList(new EntityWrapper<TOrder>().eq("e_zip_z", quote.getOrderId()).eq("company_id", companyIds));
        ArrayList<LonLat> lonLats = new ArrayList<>();
        LonLat latLng = new LonLat();
        latLng.setLat("-113.6510249618184");
        latLng.setLng("37.8924429618184");
        lonLats.add(latLng);
        latLng=new LonLat();
        latLng.setLat("-113.066919618184");
        latLng.setLng("37.684389618184");
        lonLats.add(latLng);
        tCompanyCalculationRespOne.setLonLats(lonLats);
        ArrayList<TGoods> tGoods = new ArrayList<>();
        // 获取其中一个订单 去获取货物
        for (TOrder order : orders1) {
            List<TGoods> goodsList = goods.stream().filter(good -> good.getOrderId().equals(order.getId())).collect(Collectors.toList());
            tGoods.addAll(goodsList);
        }
        tCompanyCalculationRespOne.setTGoods(tGoods);
 
 
        ArrayList<CompanyInfo> companyInfos = new ArrayList<>();
        for (TOrder order : orders1) {
            CompanyInfo tCompanyCalculationResp = new CompanyInfo();
            // 查询公司
            TCompany company = companyMapper.selectById(order.getCompanyId());
            tCompanyCalculationResp.setCompanyName(company.getName());
            tCompanyCalculationResp.setCompanyId(company.getId());
            tCompanyCalculationResp.setCarGoNumber(String.valueOf(company.getMcNumber()));
            tCompanyCalculationResp.setImg(company.getHeadImg());
            tCompanyCalculationResp.setExpirationDate(company.getExpirationTime());
 
            // 查询公司下的价格集合
            List<TPrice> prices = priceMapper.selectList(new EntityWrapper<TPrice>().eq("order_id", order.getId()));
            List<TCompanyResp> tCompanyRespList = new ArrayList<>();
            for (TPrice price : prices) {
                TCompanyResp tCompanyResp = new TCompanyResp();
                tCompanyResp.setOrderId(order.getId());
                tCompanyResp.setName(price.getType());
                tCompanyResp.setPrice(price.getPrice());
                tCompanyRespList.add(tCompanyResp);
            }
            BigDecimal bigDecimal = tCompanyRespList.stream().map(TCompanyResp::getPrice).reduce(BigDecimal::add).orElse(new BigDecimal(0.00));
            tCompanyCalculationResp.setAllTotal(bigDecimal);
            tCompanyCalculationResp.setList(tCompanyRespList);
            // 过滤订单
            List<TOrder> orderList = orders.stream().filter(o -> o.getCompanyId().equals(company.getId())).collect(Collectors.toList());
            tCompanyCalculationResp.setOrderList(orderList);
 
            companyInfos.add(tCompanyCalculationResp);
        }
        ArrayList<CompanyInfo> collect = companyInfos.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CompanyInfo::getCompanyId))), ArrayList::new));
        tCompanyCalculationRespOne.setCompanyInfos(collect);
        return tCompanyCalculationRespOne;
    }
 
    public List<TCompanyCalculationResp> getQuotaFromId1(Long id) {
        TQuote quote = quoteService.selectById(id);
        List<TCompanyCalculationResp> list = new ArrayList<>();
        List<TGoods> goods = goodsService.selectList(new EntityWrapper<TGoods>());
        // 找出所有的订单
        List<TOrder> orders = orderService.selectList(new EntityWrapper<TOrder>().eq("e_zip_z", quote.getOrderId()));
        for (TOrder order : orders) {
            TCompanyCalculationResp tCompanyCalculationResp = new TCompanyCalculationResp();
            // 过滤订单
            List<TGoods> goodsList = goods.stream().filter(good -> good.getOrderId().equals(order.getId())).collect(Collectors.
                    collectingAndThen(Collectors.toCollection(()->new TreeSet<>(Comparator.comparing(TGoods::getId))),ArrayList::new));
            tCompanyCalculationResp.setTGoods(goodsList);
 
            // 查询公司
            TCompany company = companyMapper.selectById(order.getCompanyId());
            tCompanyCalculationResp.setCompanyName(company.getName());
            tCompanyCalculationResp.setCompanyId(company.getId());
            tCompanyCalculationResp.setCarGoNumber(String.valueOf(company.getMcNumber()));
            tCompanyCalculationResp.setImg(company.getHeadImg());
 
            // 查询公司下的价格集合
            List<TPrice> prices = priceMapper.selectList(new EntityWrapper<TPrice>().eq("order_id", order.getId()));
            List<TCompanyResp> tCompanyRespList = new ArrayList<>();
            for (TPrice price : prices) {
                TCompanyResp tCompanyResp = new TCompanyResp();
                tCompanyResp.setOrderId(order.getId());
                tCompanyResp.setName(price.getType());
                tCompanyResp.setPrice(price.getPrice());
                tCompanyRespList.add(tCompanyResp);
            }
 
            // 过滤订单
            List<TOrder> orderList = orders.stream().filter(o -> o.getCompanyId().equals(company.getId())).collect(Collectors.toList());
            tCompanyCalculationResp.setOrderList(orderList);
 
            // 经纬度
            tCompanyCalculationResp.setStartLon(order.getStartLon());
            tCompanyCalculationResp.setStartLat(order.getStartLat());
//            GeocodeVo geocode = googleMapUtil.getGeocode(order.geteAddress());
//            if(Objects.nonNull(geocode)){
//                tCompanyCalculationResp.setEndLon(String.valueOf(geocode.getLng()));
//                tCompanyCalculationResp.setEndLat(String.valueOf(geocode.getLat()));
//            }
 
            list.add(tCompanyCalculationResp);
        }
        return list;
    }
}