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());
|
carriersService.insert(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"),
|
})
|
@PostMapping(value = "/carriersInfo")
|
@ResponseBody
|
public Object carriersInfo( int id) {
|
TCarriers tCarriers = carriersService.selectById(id);
|
return new SuccessTip(tCarriers);
|
}
|
|
|
@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");
|
}
|
}
|
|
|
}
|