liujie
2023-05-24 0c9e25aff0133d05bdaca55d1369eb90342b0b05
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
package com.stylefeng.guns.modular.system.controller;
 
 
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.modular.system.dao.TPortMapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.utils.tips.SuccessTip;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
 
@Controller
@Api(tags = "费用设置")
@RequestMapping("/api/rates")
public class RatesController {
 
    @Resource
    private ITRatesService ratesService;
 
    @Resource
    private ITCountryService countryService;
 
    @Resource
    private IWarehouseService warehouseService;
    @Resource
    private ITCompanyBasicService basicService;
 
 
    @ApiOperation(value = "卡车公司-获取港区设置列表",notes="卡车公司-获取港区设置列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "id", value = "当前公司id", required = true, dataType = "int",paramType = "query"),
    })
    @GetMapping(value = "/metroList")
    @ResponseBody
    public Object metroList(int pageNumber,int pageSize,int id) {
        Page<TRates> tRatesPage = new Page<>(pageNumber, pageSize);
        Page<TRates> tRates = ratesService.selectPage(tRatesPage,new EntityWrapper<TRates>().eq("company_id", id).eq("type", 1));
        Page<TRatesVo> tRatesVoPage = new Page<>();
        BeanUtil.copyProperties(tRates,tRatesVoPage);
        ArrayList<TRatesVo> tRatesVos = new ArrayList<>();
        for (TRates record : tRates.getRecords()) {
            TRatesVo tRatesVo = new TRatesVo();
            tRatesVo.setId(record.getId());
            tRatesVo.setRemarks(record.getRemarks());
            // city
            TCountry tCountry = countryService.selectById(record.getMetroId());
            tRatesVo.setMetro(tCountry.getName());
            tRatesVo.setZipCode(tCountry.getZipCode());
            // state
            TCountry tCountry1 = countryService.selectById(tCountry.getParentId());
            tRatesVo.setState(tCountry1.getName());
 
            tRatesVos.add(tRatesVo);
        }
        tRatesVoPage.setRecords(tRatesVos);
        return new SuccessTip(tRatesVoPage);
    }
 
    @Resource
    private TPortMapper tPortMapper;
 
    @ApiOperation(value = "卡车公司-获取特殊码头列表",notes="卡车公司-获取特殊码头列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "id", value = "当前公司id", required = true, dataType = "int",paramType = "query"),
    })
    @GetMapping(value = "/specialPortList")
    @ResponseBody
    public Object specialPortList(int pageNumber,int pageSize,int id) {
        Page<TRates> tRatesPage = new Page<>(pageNumber, pageSize);
        Page<TRates> tRates = ratesService.selectPage(tRatesPage,new EntityWrapper<TRates>().eq("company_id", id).eq("type", 2));
        Page<TRatesVoOne> tRatesVoPage = new Page<>();
        BeanUtil.copyProperties(tRates,tRatesVoPage);
        ArrayList<TRatesVoOne> tRatesVos = new ArrayList<>();
        for (TRates record : tRates.getRecords()) {
            TRatesVoOne tRatesVo = new TRatesVoOne();
            tRatesVo.setId(record.getId());
            tRatesVo.setRemarks(record.getRemarks());
            // city
            TPort tPort = tPortMapper.selectById(record.getMetroId());
            tRatesVo.setAddress(tPort.getAddress());
            tRatesVo.setZipCode(tPort.getZipCode());
            tRatesVo.setPortName(tPort.getName());
            TCountry tCountry = countryService.selectById(tPort.getCity());
            tRatesVo.setMetro(tCountry.getName());
            // state
            TCountry tCountry1 = countryService.selectById(tCountry.getParentId());
            tRatesVo.setState(tCountry1.getName());
 
            tRatesVos.add(tRatesVo);
        }
        tRatesVoPage.setRecords(tRatesVos);
        return new SuccessTip(tRatesVoPage);
    }
 
    @ApiOperation(value = "卡车公司-获取所有port",notes="卡车公司-获取所有port")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @GetMapping(value = "/portList")
    @ResponseBody
    public Object portList() {
        List<TPort> tCountries = tPortMapper.selectList(new EntityWrapper<TPort>().eq("remove", 0));
        return new SuccessTip(tCountries);
    }
 
 
    @ApiOperation(value = "卡车公司-获取所有state",notes="卡车公司-获取所有state")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @GetMapping(value = "/stateList")
    @ResponseBody
    public Object stateList() {
        List<TCountry> tCountries = countryService.selectList(new EntityWrapper<TCountry>().eq("type", 2).eq("remove", 0));
        return new SuccessTip(tCountries);
    }
 
 
    @ApiOperation(value = "卡车公司-根据stateId获取所有city",notes="卡车公司-根据stateId获取所有city")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int",paramType = "query"),
 
    })
    @GetMapping(value = "/cityList")
    @ResponseBody
    public Object cityList(int id) {
        List<TCountry> tCountries = countryService.selectList(new EntityWrapper<TCountry>().eq("type", 3).eq("remove", 0).eq("parent_id",id));
        return new SuccessTip(tCountries);
    }
 
 
 
    @ApiOperation(value = "卡车公司- 添加港区设置/特殊码头",notes="卡车公司-添加港区设置/特殊码头")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
 
    })
    @PostMapping(value = "/addMetro")
    @ResponseBody
    public Object addMetro(@RequestBody TRates tRates) {
        ratesService.insert(tRates);
        List<TWarehouse> tWarehouses = warehouseService.selectList(new EntityWrapper<TWarehouse>().eq("company_id", 0));
        tWarehouses.stream().forEach(e->{
                e.setPortId(tRates.getId());
        });
        ExecutorService executorService = Executors.newCachedThreadPool();
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                tWarehouses.forEach(e->e.setCompanyId(tRates.getCompanyId()));
                warehouseService.insertBatch(tWarehouses);
            }
        });
 
        return new SuccessTip();
    }
 
    @ApiOperation(value = "卡车公司- 港区详情",notes="卡车公司-港区详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int",paramType = "query"),
    })
    @GetMapping(value = "/metroInfo")
    @ResponseBody
    public Object metroInfo(int id) {
        TRatesInfo tRatesInfo = new TRatesInfo();
        TRates tRates = ratesService.selectById(id);
        tRatesInfo.setId(tRates.getId());
        tRatesInfo.setRemarks(tRates.getRemarks());
        tRatesInfo.setMetroId(tRates.getMetroId());
        TCountry tCountry = countryService.selectById(tRates.getMetroId());
        tRatesInfo.setStateId(tCountry.getParentId());
        return new SuccessTip(tRatesInfo);
    }
 
    @ApiOperation(value = "卡车公司- 特殊码头详情",notes="卡车公司-特殊码头详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int",paramType = "query"),
    })
    @GetMapping(value = "/specialPortInfo")
    @ResponseBody
    public Object specialPortInfo(int id) {
        TRatesInfoOne tRatesInfo = new TRatesInfoOne();
        TRates tRates = ratesService.selectById(id);
        tRatesInfo.setId(tRates.getId());
        tRatesInfo.setRemarks(tRates.getRemarks());
        tRatesInfo.setPortId(tRates.getMetroId());
        return new SuccessTip(tRatesInfo);
    }
 
    @ApiOperation(value = "卡车公司- 修改港区设置",notes="卡车公司-修改港区设置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/updateMetro")
    @ResponseBody
    public Object updateMetro(@RequestBody TRates tRates) {
        ratesService.updateById(tRates);
        return new SuccessTip();
    }
 
    @ApiOperation(value = "卡车公司- 删除港区设置",notes="卡车公司-删除港区设置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int",paramType = "query"),
    })
    @GetMapping(value = "/deleteMetro")
    @ResponseBody
    public Object deleteMetro( int id) {
        ratesService.deleteById(id);
        warehouseService.delete(new EntityWrapper<TWarehouse>().eq("port_id",id));
        return new SuccessTip();
    }
 
 
    @ApiOperation(value = "卡车公司- 获取亚马逊设置",notes="卡车公司-获取港区的亚马逊设置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "id", value = "港区id/特殊码头id", required = true, dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int",paramType = "query"),
    })
    @GetMapping(value = "/getWarehouseFromId")
    @ResponseBody
    public Object getWarehouseFromId(int id,int pageNumber,int pageSize) {
        Page<TWarehouse> tWarehousePage = new Page<>(pageNumber, pageSize);
        Page<TWarehouse> tWarehouses = warehouseService.selectPage(tWarehousePage,new EntityWrapper<TWarehouse>().eq("port_id", id));
        return new SuccessTip(tWarehouses);
    }
 
    @ApiOperation(value = "卡车公司- 根据id统一设置亚马逊价格",notes="卡车公司-根据id统一设置亚马逊价格")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "id", value = "港区id/特殊码头id", required = true, dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "money", value = "money", required = true, dataType = "double",paramType = "query"),
    })
    @GetMapping(value = "/setWarehousePrice")
    @ResponseBody
    public Object setWarehousePrice(int id,double money) {
        List<TWarehouse> tWarehouses = warehouseService.selectList(new EntityWrapper<TWarehouse>().eq("port_id", id));
        tWarehouses.stream().forEach(e->e.setWarePrice(new BigDecimal(money)));
        warehouseService.updateBatchById(tWarehouses);
        return new SuccessTip(tWarehouses);
    }
 
 
 
    @ApiOperation(value = "卡车公司- 根据id获取点对点/范围/距离",notes="卡车公司-根据id统一设置亚马逊价格")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "id", value = "港区id/特殊码头id", required = true, dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "type", value = "1/2/3 点对点/范围/距离", required = true, dataType = "int",paramType = "query"),
    })
    @GetMapping(value = "/getLane")
    @ResponseBody
    public Object getLane(int id,int pageNumber,int pageSize,int type) {
        Page<TCompanyBasic> tCompanyBasicPage = new Page<>(pageNumber, pageSize);
        Page<TCompanyBasic> basicPage = basicService.selectPage(tCompanyBasicPage,new EntityWrapper<TCompanyBasic>().eq("port_id", id).eq("type",type));
        return new SuccessTip(basicPage);
    }
 
 
    @ApiOperation(value = "卡车公司- 点对点/范围/距离详情",notes="卡车公司-点对点/范围/距离详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int",paramType = "query"),
    })
    @PostMapping(value = "/laneInfo")
    @ResponseBody
    public Object laneInfo( int id) {
        TCompanyBasic tCompanyBasic = basicService.selectById(id);
        HashMap<String, Object> map = new HashMap<>();
        map.put("data",tCompanyBasic);
 
        if(tCompanyBasic.getType()==2){
            String lonLat = tCompanyBasic.getLonLat();
            String[] split = lonLat.split("_");
            ArrayList<LonLat> lonLats = new ArrayList<>();
            for (String s : split) {
                String[] split1 = s.split(",");
                LonLat lonLat1 = new LonLat();
                lonLat1.setLat(split1[0]);
                lonLat1.setLng(split1[1]);
                lonLats.add(lonLat1);
            }
            map.put("lonlat",lonLats);
        }else {
            map.put("lonlat",new ArrayList<>());
        }
        return new SuccessTip(map);
    }
    @ApiOperation(value = "卡车公司- 添加点对点/范围/距离",notes="卡车公司-添加点对点/范围/距离")
 
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/addLane")
    @ResponseBody
    public Object addLane(@RequestBody TCompanyBasic basic) {
        basicService.insert(basic);
        return new SuccessTip();
    }
 
 
    @ApiOperation(value = "卡车公司- 编辑点对点/范围/距离",notes="卡车公司-编辑点对点/范围/距离")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/updateLane")
    @ResponseBody
    public Object updateLane(@RequestBody TCompanyBasic basic) {
        basicService.updateById(basic);
        return new SuccessTip();
    }
 
    @ApiOperation(value = "卡车公司- 删除点对点/范围/距离",notes="卡车公司-删除点对点/范围/距离")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int",paramType = "query"),
    })
    @GetMapping(value = "/delLane")
    @ResponseBody
    public Object delLane( int id) {
        basicService.deleteById(id);
        return new SuccessTip();
    }
 
    @Resource
    private ITCompanyFeeSettingService tCompanyFeeSettingMapper;
    @ApiOperation(value = "卡车公司- 根据港区/特殊码头id获取费用",notes="卡车公司-根据港区/特殊码头id获取费用\"")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "companyId", value = "当前公司id", required = true, dataType = "int",paramType = "query"),
    })
    @GetMapping(value = "/getFee")
    @ResponseBody
    public Object getFee( int id,int companyId) {
        List<TCompanyFeeSetting> feeSettings = tCompanyFeeSettingMapper.selectList(new EntityWrapper<TCompanyFeeSetting>().eq("rates_id", id).eq("company_id", companyId));
        return new SuccessTip(feeSettings);
    }
 
    @ApiOperation(value = "卡车公司- 添加费用",notes="卡车公司-添加费用\"")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/addFee")
    @ResponseBody
    public Object addFee(@RequestBody List<TCompanyFeeSetting> feeSettings) {
        tCompanyFeeSettingMapper.insertBatch(feeSettings);
        return new SuccessTip();
    }
 
 
    @ApiOperation(value = "卡车公司- 修改费用",notes="卡车公司-修改费用")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/updateFee")
    @ResponseBody
    public Object updateFee(@RequestBody List<TCompanyFeeSetting> feeSettings) {
        tCompanyFeeSettingMapper.updateBatchById(feeSettings);
        return new SuccessTip();
    }
 
 
 
}