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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
package com.stylefeng.guns.modular.system.controller;
 
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.util.DateUtil;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.model.TCarriers;
import com.stylefeng.guns.modular.system.service.TCarriersService;
import com.stylefeng.guns.modular.system.utils.WoUtil;
import com.stylefeng.guns.modular.system.utils.tips.ErrorTip;
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.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2023-01-09 09:51:51
 */
@Controller
@Api(tags = "承运商")
@RequestMapping("/api/tCarriers")
public class TCarriersController extends BaseController {
 
    @Autowired
    private TCarriersService carriersService;
 
 
    /**
     * 获取列表
     */
    @ApiOperation(value = "卡车公司-承运商列表",notes="卡车公司-承运商列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "time", value = "xxxx - xxxx", required = false, dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "name", value = "powerUnitNumber", required = false, dataType = "String",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 = "/list")
    @ResponseBody
        public Object list(String time,String name,int pageNumber,int pageSize) {
        Page<TCarriers> tCarriersPage = new Page<>(pageNumber, pageSize);
        String sTime=null;
        String eTime=null;
        EntityWrapper<TCarriers> wrapper = new EntityWrapper<>();
        wrapper.eq("remove",0);
        if(ToolUtil.isNotEmpty(name)){
            wrapper.like("company_name",name).or().like("account",name);
        }
        if(ToolUtil.isNotEmpty(time)){
            sTime=time.split(" - ")[0]+" 00:00:01";
            eTime=time.split(" - ")[1]+" 23:59:59";
            wrapper.between("create_time",sTime,eTime);
        }
        wrapper.orderBy("create_time",false);
        Page<TCarriers> tCarriersPage1 = carriersService.selectPage(tCarriersPage, wrapper);
        return new SuccessTip(tCarriersPage1);
        }
 
 
 
    @ApiOperation(value = "卡车公司-添加承运商",notes="卡车公司-添加承运商")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/addCarriers")
    @ResponseBody
    public Object addCarriers(@RequestBody TCarriers tCarriers) {
        tCarriers.setCreateTime(new Date());
        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 = "/updateCarriers")
    @ResponseBody
    public Object updateCarriers(@RequestBody TCarriers tCarriers) {
        carriersService.updateById(tCarriers);
        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 = "/deleteCarriers")
    @ResponseBody
    public Object deleteCarriers(int id) {
        TCarriers tCarriers = carriersService.selectById(id);
        tCarriers.setRemove(1);
        carriersService.updateById(tCarriers);
        return new SuccessTip();
    }
 
 
    /**
     * 导入操作
     *
     * @param request
     * @return
     */
    @ApiOperation(value = "卡车公司-承运商导入", notes = "卡车公司-承运商导入")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @RequestMapping(value = "/exportCarriers", method = RequestMethod.POST)
    @ResponseBody
    public Object exportCarriers(HttpServletRequest request, MultipartFile file,int id) {
        try {
            Workbook book = WoUtil.ImportFile(file);
            Sheet sh = book.getSheetAt(0);   //获取到第一个表
            ArrayList<TCarriers> list = new ArrayList<>();
 
            for (int i = 1; i <= sh.getLastRowNum(); i++) {
                Row row = sh.getRow(i);
 
                Cell cell0 = row.getCell(0);
                String zero = null;//COMPANY NAME
                if (ToolUtil.isNotEmpty(cell0)) {
                    cell0.setCellType(Cell.CELL_TYPE_STRING);
                    zero = String.valueOf(cell0.getStringCellValue()).trim();
                }
 
                Cell cell1 = row.getCell(1);
                String one = null;//SCAC CODE
                if (ToolUtil.isNotEmpty(cell1)) {
                    cell1.setCellType(Cell.CELL_TYPE_STRING);
                    one = String.valueOf(cell1.getStringCellValue()).trim();
                }
 
                Cell cell2 = row.getCell(2);
                String two = null;//LOGO
                if (ToolUtil.isNotEmpty(cell2)) {
                    cell2.setCellType(Cell.CELL_TYPE_STRING);
                    two = String.valueOf(cell2.getStringCellValue()).trim();
                }
 
                Cell cell3 = row.getCell(3);
                String three = null;//CONTACT PHONE
                if (ToolUtil.isNotEmpty(cell3)) {
                    cell3.setCellType(Cell.CELL_TYPE_STRING);
                    three = String.valueOf(cell3.getStringCellValue()).trim();
                }
 
                Cell cell4 = row.getCell(4);
                String four = null;//CONTACT EMAIL
                if (ToolUtil.isNotEmpty(cell4)) {
                    cell4.setCellType(Cell.CELL_TYPE_STRING);
                    four = String.valueOf(cell4.getStringCellValue()).trim();
                }
 
                Cell cell5 = row.getCell(5);
                String five = null;//ADDRESS
                if (ToolUtil.isNotEmpty(cell5)) {
                    cell5.setCellType(Cell.CELL_TYPE_STRING);
                    five = String.valueOf(cell5.getStringCellValue()).trim();
                }
 
                Cell cell6 = row.getCell(6);
                String six = null;//MC NUMBER
                if (ToolUtil.isNotEmpty(cell6)) {
                    cell6.setCellType(Cell.CELL_TYPE_STRING);
                    six = String.valueOf(cell6.getStringCellValue()).trim();
                }
 
                Cell cell7 = row.getCell(7);
                String seven = null;//USDOT
                if (ToolUtil.isNotEmpty(cell7)) {
                    cell7.setCellType(Cell.CELL_TYPE_STRING);
                    seven = String.valueOf(cell7.getStringCellValue()).trim();
                }
 
                Cell cell8 = row.getCell(8);
                if(cell8!=null){
                    cell8.setCellType(Cell.CELL_TYPE_STRING);
                }
                String eight = null;//SET UP THE TIME
                if (ToolUtil.isNotEmpty(cell8)) {
                    eight = String.valueOf(cell8.getStringCellValue()).trim();
                }
 
                Cell cell9 = row.getCell(9);
                if(cell9!=null){
                    cell9.setCellType(Cell.CELL_TYPE_STRING);
                }
                String nine = null;//LOGISTICS CONTACT NAME
                if (ToolUtil.isNotEmpty(cell9)) {
                    nine = String.valueOf(cell9.getStringCellValue()).trim();
                }
 
                Cell cell10 = row.getCell(10);
                if(cell10!=null){
                    cell10.setCellType(Cell.CELL_TYPE_STRING);
                }
 
                String ten = null;//LOGISTICS CONTACT EMAIL
                if (ToolUtil.isNotEmpty(cell10)) {
                    ten = String.valueOf(cell10.getStringCellValue()).trim();
                }
 
                Cell cell11 = row.getCell(11);
                if(cell11!=null){
                    cell11.setCellType(Cell.CELL_TYPE_STRING);
                }
                String eleven = null;//POWER UNITS
                if (ToolUtil.isNotEmpty(cell11)) {
                    eleven = String.valueOf(cell11.getStringCellValue()).trim();
                }
 
                Cell cell12 = row.getCell(12);
                if(cell12!=null){
                    cell12.setCellType(Cell.CELL_TYPE_STRING);
                }
                String twelve = null;//DRIVERS
                if (ToolUtil.isNotEmpty(cell12)) {
                    twelve = String.valueOf(cell12.getStringCellValue()).trim();
                }
 
                Cell cell13 = row.getCell(13);
                if(cell13!=null){
                    cell13.setCellType(Cell.CELL_TYPE_STRING);
                }
                String thirteen = null;//INSPECTIONS
                if (ToolUtil.isNotEmpty(cell13)) {
                    thirteen = String.valueOf(cell13.getStringCellValue()).trim();
                }
 
                Cell cell14 = row.getCell(14);
                if(cell14!=null){
                    cell14.setCellType(Cell.CELL_TYPE_STRING);
                }
                String fourteen = null;//Commission
                if (ToolUtil.isNotEmpty(cell14)) {
                    fourteen = String.valueOf(cell14.getStringCellValue()).trim();
                }
 
                Cell cell15 = row.getCell(15);
                if(cell15!=null){
                    cell15.setCellType(Cell.CELL_TYPE_STRING);
                }
                String fifteen = null;//BILL NUMBER
                if (ToolUtil.isNotEmpty(cell15)) {
                    fifteen = String.valueOf(cell15.getStringCellValue()).trim();
                }
 
                Cell cell16 = row.getCell(16);
                if(cell16!=null){
                    cell16.setCellType(Cell.CELL_TYPE_STRING);
                }
                String sixteen = null;//ACCOUNT
                if (ToolUtil.isNotEmpty(cell16)) {
                    sixteen = String.valueOf(cell16.getStringCellValue()).trim();
                }
 
                Cell cell17 = row.getCell(17);
                if(cell17!=null){
                    cell17.setCellType(Cell.CELL_TYPE_STRING);
                }
                String seventeen = null;//PASSWORD
                if (ToolUtil.isNotEmpty(cell17)) {
                    seventeen = String.valueOf(cell17.getStringCellValue()).trim();
                }
 
 
                if (ToolUtil.isEmpty(one) || ToolUtil.isEmpty(two) || ToolUtil.isEmpty(three)
                        || ToolUtil.isEmpty(four)|| ToolUtil.isEmpty(five) || ToolUtil.isEmpty(six) || ToolUtil.isEmpty(seven) || ToolUtil.isEmpty(eight) || ToolUtil.isEmpty(nine)
                        || ToolUtil.isEmpty(ten) || ToolUtil.isEmpty(eleven) || ToolUtil.isEmpty(twelve)
                        || ToolUtil.isEmpty(thirteen) || ToolUtil.isEmpty(fourteen) || ToolUtil.isEmpty(fifteen) || ToolUtil.isEmpty(sixteen) || ToolUtil.isEmpty(seventeen)) {
                    return new ErrorTip(500, "table can not be blank");
                }
                List<TCarriers> account = carriersService.selectList(new EntityWrapper<TCarriers>().eq("account", sixteen));
                if(account.size()>0){
                    continue;
                }
                TCarriers tCarriers = new TCarriers();
                tCarriers.setCompanyId(id);
                tCarriers.setRemove(0);
                tCarriers.setCompanyName(zero);
                tCarriers.setScacCode(one);
                tCarriers.setCompanyLogo(two);
                tCarriers.setContactPhone(three);
                tCarriers.setContactEmail(four);
                tCarriers.setAddress(five);
                tCarriers.setMcNumber(six);
                tCarriers.setUsdot(seven);
                Date date = DateUtil.parseDate(eight);
                tCarriers.setSetUpTheTime(date);
                tCarriers.setLogisticsContactName(nine);
                tCarriers.setLogisticsContactEmail(ten);
                tCarriers.setPowerUnits(eleven);
                tCarriers.setDrivers(twelve);
                tCarriers.setInspections(thirteen);
                tCarriers.setCommission(Double.valueOf(fourteen));
                tCarriers.setBillNumber(fifteen);
                tCarriers.setAccount(sixteen);
                tCarriers.setCreateTime(new Date());
                tCarriers.setPassword(SecureUtil.md5(seventeen));
                list.add(tCarriers);
            }
                if(list.size()>0){
 
                carriersService.insertBatch(list);
            }
            return new SuccessTip();
        } catch (Exception e) {
            e.printStackTrace();
            return new ErrorTip(500,"Error");
        }
    }
 
 
}