package com.stylefeng.guns.modular.system.controller;
|
|
import cn.hutool.core.bean.BeanUtil;
|
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.TDriver;
|
import com.stylefeng.guns.modular.system.model.TDriverListVo;
|
import com.stylefeng.guns.modular.system.service.ITDriverService;
|
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.commons.lang.time.DateUtils;
|
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.text.DateFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
/**
|
* 控制器
|
*
|
* @author fengshuonan
|
* @Date 2022-12-30 17:04:55
|
*/
|
@Controller
|
@Api(tags = "司机")
|
@RequestMapping("/api/driver")
|
public class DriverController extends BaseController {
|
|
@Autowired
|
private ITDriverService driverService;
|
|
|
|
@ApiOperation(value = "卡车公司-司机列表", notes = "卡车公司-司机列表")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
@ApiImplicitParam(name = "time", value = "2000-01-01 - 2000-11-11", required = false, dataType = "String"),
|
@ApiImplicitParam(name = "name", value = "name", required = false, dataType = "String"),
|
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int"),
|
@ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int"),
|
@ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int"),
|
})
|
@GetMapping(value = "/driverList")
|
@ResponseBody
|
public Object driverList(String time, String name,int id, int pageNumber, int pageSize) {
|
String sTime = null;
|
String eTime = null;
|
EntityWrapper<TDriver> wrapper = new EntityWrapper<>();
|
Page<TDriver> tDriverPage = new Page<>(pageNumber, pageSize);
|
wrapper.eq("remove", 0);
|
wrapper.eq("is_carriers",1);
|
wrapper.eq("company_id",id);
|
if (ToolUtil.isNotEmpty(name)) {
|
wrapper.like("driver_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);
|
}
|
Page<TDriver> tDrivers = driverService.selectPage(tDriverPage, wrapper);
|
ArrayList<TDriverListVo> tDriverListVos = new ArrayList<>();
|
tDrivers.getRecords().stream().forEach(e -> {
|
TDriverListVo tDriverListVo = new TDriverListVo();
|
BeanUtil.copyProperties(e, tDriverListVo);
|
tDriverListVos.add(tDriverListVo);
|
});
|
|
Page<TDriverListVo> objectPage = new Page<>();
|
objectPage.setRecords(tDriverListVos);
|
BeanUtil.copyProperties(tDrivers, objectPage);
|
return new SuccessTip(objectPage);
|
}
|
|
|
@ApiOperation(value = "卡车公司-添加司机", notes = "卡车公司-添加司机")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
})
|
@PostMapping(value = "/driverAdd")
|
@ResponseBody
|
public Object driverAdd(@RequestBody TDriver driver) {
|
try {
|
driver.setCreateTime(new Date());
|
driverService.insert(driver);
|
return new SuccessTip();
|
} catch (Exception e) {
|
e.printStackTrace();
|
return new ErrorTip(500, "Error");
|
}
|
}
|
|
@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"),
|
})
|
@GetMapping(value = "/driverDelete")
|
@ResponseBody
|
public Object driverDelete(int id) {
|
try {
|
TDriver tDriver = driverService.selectById(id);
|
tDriver.setRemove(1);
|
driverService.updateById(tDriver);
|
return new SuccessTip();
|
} catch (Exception e) {
|
e.printStackTrace();
|
return new ErrorTip(500, "Error");
|
}
|
}
|
|
|
@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"),
|
})
|
@GetMapping(value = "/driverDetail")
|
@ResponseBody
|
public Object driverDetail(int id) {
|
try {
|
TDriver tDriver = driverService.selectById(id);
|
return new SuccessTip(tDriver);
|
} catch (Exception e) {
|
e.printStackTrace();
|
return new ErrorTip(500, "Error");
|
}
|
}
|
|
|
@ApiOperation(value = "卡车公司-编辑司机", notes = "卡车公司-编辑司机")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
})
|
@PostMapping(value = "/driverUpdate")
|
@ResponseBody
|
public Object driverUpdate(@RequestBody TDriver driver) {
|
try {
|
driverService.updateById(driver);
|
return new SuccessTip();
|
} catch (Exception e) {
|
e.printStackTrace();
|
return new ErrorTip(500, "Error");
|
}
|
}
|
|
/**
|
* 导入操作
|
*
|
* @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 = "/exportCar", method = RequestMethod.POST)
|
@ResponseBody
|
public Object exportCar(HttpServletRequest request, MultipartFile file) {
|
try {
|
Workbook book = WoUtil.ImportFile(file);
|
Sheet sh = book.getSheetAt(0); //获取到第一个表
|
for (int i = 1; i <= sh.getLastRowNum(); i++) {
|
Row row = sh.getRow(i);
|
|
Cell cell0 = row.getCell(0);
|
String zero = null;//司机名称
|
if (ToolUtil.isNotEmpty(cell0)) {
|
cell0.setCellType(Cell.CELL_TYPE_STRING);
|
zero = String.valueOf(cell0.getStringCellValue()).trim();
|
}
|
|
Cell cell1 = row.getCell(1);
|
String one = null;//Contact Number
|
|
if (ToolUtil.isNotEmpty(cell1)) {
|
cell1.setCellType(Cell.CELL_TYPE_STRING);
|
one = String.valueOf(cell1.getStringCellValue()).trim();
|
}
|
|
Cell cell2 = row.getCell(2);
|
String two = null;//Driver Number
|
if (ToolUtil.isNotEmpty(cell2)) {
|
cell2.setCellType(Cell.CELL_TYPE_STRING);
|
two = String.valueOf(cell2.getStringCellValue()).trim();
|
}
|
|
Cell cell3 = row.getCell(3);
|
String three = null;//Date of Birth
|
if (ToolUtil.isNotEmpty(cell3)) {
|
cell3.setCellType(Cell.CELL_TYPE_STRING);
|
three = String.valueOf(cell3.getStringCellValue()).trim();
|
}
|
|
Cell cell4 = row.getCell(4);
|
String four = null;//Address
|
if (ToolUtil.isNotEmpty(cell4)) {
|
cell4.setCellType(Cell.CELL_TYPE_STRING);
|
four = String.valueOf(cell4.getStringCellValue()).trim();
|
}
|
|
Cell cell5 = row.getCell(5);
|
String five = null;//Driver Type
|
if (ToolUtil.isNotEmpty(cell5)) {
|
cell5.setCellType(Cell.CELL_TYPE_STRING);
|
five = String.valueOf(cell5.getStringCellValue()).trim();
|
}
|
|
Cell cell6 = row.getCell(6);
|
String six = null;//Status
|
if (ToolUtil.isNotEmpty(cell6)) {
|
cell6.setCellType(Cell.CELL_TYPE_STRING);
|
six = String.valueOf(cell6.getStringCellValue()).trim();
|
}
|
|
Cell cell7 = row.getCell(7);
|
String seven = null;//StatusRemark
|
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;//Commercial Driiver Since Year
|
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;//License Type
|
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;//CDL Number
|
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;//Driving School
|
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;//Type of Experience
|
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;//License Endorsements
|
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;//Application Date
|
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;//Termination Date
|
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;//Bonus Eligibility Date
|
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;//Hire Date
|
if (ToolUtil.isNotEmpty(cell17)) {
|
seventeen = String.valueOf(cell17.getStringCellValue()).trim();
|
}
|
Cell cell18 = row.getCell(18);
|
if(cell18!=null){
|
cell18.setCellType(Cell.CELL_TYPE_STRING);
|
}
|
String eighteen = null;//Rehirable
|
if (ToolUtil.isNotEmpty(cell18)) {
|
eighteen = String.valueOf(cell18.getStringCellValue()).trim();
|
}
|
Cell cell19 = row.getCell(19);
|
if(cell19!=null){
|
cell19.setCellType(Cell.CELL_TYPE_STRING);
|
}
|
String nineteen = null;//License Endorsements One
|
if (ToolUtil.isNotEmpty(cell19)) {
|
nineteen = String.valueOf(cell19.getStringCellValue()).trim();
|
}
|
Cell cell20 = row.getCell(20);
|
if(cell20!=null){
|
cell20.setCellType(Cell.CELL_TYPE_STRING);
|
}
|
String twenty = null;//Insurance Co
|
if (ToolUtil.isNotEmpty(cell20)) {
|
twenty = String.valueOf(cell20.getStringCellValue()).trim();
|
}
|
Cell cell21 = row.getCell(21);
|
if(cell21!=null){
|
cell21.setCellType(Cell.CELL_TYPE_STRING);
|
}
|
String twentyOne = null;//Id Number
|
if (ToolUtil.isNotEmpty(cell21)) {
|
twentyOne = String.valueOf(cell21.getStringCellValue()).trim();
|
}
|
Cell cell22 = row.getCell(22);
|
if(cell22!=null){
|
cell22.setCellType(Cell.CELL_TYPE_STRING);
|
}
|
String twentyTwo = null;//Group Number
|
if (ToolUtil.isNotEmpty(cell22)) {
|
twentyTwo = String.valueOf(cell22.getStringCellValue()).trim();
|
}
|
Cell cell23 = row.getCell(23);
|
if(cell23!=null){
|
cell23.setCellType(Cell.CELL_TYPE_STRING);
|
}
|
String twentyThree = null;//License Expiration Date
|
if (ToolUtil.isNotEmpty(cell23)) {
|
twentyThree = String.valueOf(cell23.getStringCellValue()).trim();
|
}
|
Cell cell24 = row.getCell(24);
|
if(cell24!=null){
|
cell24.setCellType(Cell.CELL_TYPE_STRING);
|
}
|
String twentyFour = null;//Hazmat Endorsement Expiration Date
|
if (ToolUtil.isNotEmpty(cell24)) {
|
twentyFour = String.valueOf(cell24.getStringCellValue()).trim();
|
}
|
Cell cell25 = row.getCell(25);
|
if(cell25!=null){
|
cell25.setCellType(Cell.CELL_TYPE_STRING);
|
}
|
String twentyFive = null;//Insurance Expiration Date
|
if (ToolUtil.isNotEmpty(cell25)) {
|
twentyFive = String.valueOf(cell25.getStringCellValue()).trim();
|
}
|
Cell cell26 = row.getCell(26);
|
if(cell26!=null){
|
cell26.setCellType(Cell.CELL_TYPE_STRING);
|
}
|
String twentySix = null;//Last Drug Test Date
|
if (ToolUtil.isNotEmpty(cell26)) {
|
twentySix = String.valueOf(cell26.getStringCellValue()).trim();
|
}
|
Cell cell27 = row.getCell(27);
|
if(cell27!=null){
|
cell27.setCellType(Cell.CELL_TYPE_STRING);
|
}
|
String twentySeven = null;//TWIC Card Expiration Date
|
if (ToolUtil.isNotEmpty(cell27)) {
|
twentySeven = String.valueOf(cell27.getStringCellValue()).trim();
|
}
|
Cell cell28 = row.getCell(28);
|
if(cell28!=null){
|
cell28.setCellType(Cell.CELL_TYPE_STRING);
|
}
|
String twentyEight = null;//DOT Medical Card Expiration Date
|
if (ToolUtil.isNotEmpty(cell28)) {
|
twentyEight = String.valueOf(cell28.getStringCellValue()).trim();
|
}
|
Cell cell29 = row.getCell(29);
|
if(cell29!=null){
|
cell29.setCellType(Cell.CELL_TYPE_STRING);
|
}
|
String twentyNine = null;//Late Road Test Date
|
if (ToolUtil.isNotEmpty(cell29)) {
|
twentyNine = String.valueOf(cell29.getStringCellValue()).trim();
|
}
|
Cell cell30 = row.getCell(30);
|
if(cell30!=null){
|
cell30.setCellType(Cell.CELL_TYPE_STRING);
|
}
|
String thirty = null;//Last Alcogol Test Date
|
if (ToolUtil.isNotEmpty(cell30)) {
|
thirty = String.valueOf(cell30.getStringCellValue()).trim();
|
}
|
Cell cell31 = row.getCell(31);
|
if(cell31!=null){
|
cell31.setCellType(Cell.CELL_TYPE_STRING);
|
}
|
String thirtyOne = null;//Account
|
if (ToolUtil.isNotEmpty(cell31)) {
|
thirtyOne = String.valueOf(cell31.getStringCellValue()).trim();
|
}
|
Cell cell32 = row.getCell(32);
|
if(cell32!=null){
|
cell32.setCellType(Cell.CELL_TYPE_STRING);
|
}
|
String thirtyTwo = null;//Password
|
if (ToolUtil.isNotEmpty(cell32)) {
|
thirtyTwo = String.valueOf(cell32.getStringCellValue()).trim();
|
}
|
|
|
if (ToolUtil.isEmpty(thirtyOne) || ToolUtil.isEmpty(zero) || ToolUtil.isEmpty(one)
|
|| ToolUtil.isEmpty(thirtyTwo)) {
|
return new ErrorTip(500, "[Driver name、Contact number、Account、Password] can not be blank");
|
}
|
|
|
TDriver tDriver = new TDriver();
|
tDriver.setCreateTime(new Date());
|
tDriver.setRemove(0);
|
tDriver.setDriverName(zero);
|
tDriver.setContactNumber(one);
|
tDriver.setDriverNumber(two);
|
if (three != null) {
|
tDriver.setDateOfBrith(DateUtil.parseDate(three));
|
}
|
tDriver.setAddress(four);
|
if (five != null) {
|
tDriver.setDriverType(Integer.valueOf(five));
|
}
|
if (six != null) {
|
tDriver.setStatus(Integer.valueOf(six));
|
}
|
tDriver.setStatusRemark(seven);
|
tDriver.setSinceYear(eight);
|
tDriver.setLicenseType(nine);
|
tDriver.setCdlNumber(ten);
|
tDriver.setDrivingSchool(eleven);
|
tDriver.setTypeOfExperience(twelve);
|
tDriver.setLicenseEndorsements(thirteen);
|
|
if (fourteen != null) {
|
tDriver.setApplicationDate(DateUtil.parseDate(fourteen));
|
}
|
if (fifteen != null) {
|
tDriver.setTerminationDate(DateUtil.parseDate(fifteen));
|
}
|
if (sixteen != null) {
|
tDriver.setBonusEligibilityDate(DateUtil.parseDate(sixteen));
|
}
|
if (seventeen != null) {
|
tDriver.setHireDate(DateUtil.parseDate(seventeen));
|
}
|
tDriver.setRehirable(eighteen);
|
tDriver.setLicenseEndorsementsOne(nineteen);
|
tDriver.setInsuranceCo(twenty);
|
tDriver.setIdNumber(twentyOne);
|
tDriver.setGroupNumber(thirtyTwo);
|
if (twentyThree != null) {
|
tDriver.setLicenseExpirationDate(DateUtil.parseDate(twentyThree));
|
}
|
if (twentyFour != null) {
|
tDriver.setHazmatExpriationDate(DateUtil.parseDate(twentyFour));
|
}
|
if (twentyFive != null) {
|
tDriver.setInsuranceExpirationDate(DateUtil.parseDate(twentyFive));
|
}
|
if (twentySix != null) {
|
tDriver.setLastDrugTestDate(DateUtil.parseDate(twentySix));
|
}
|
if (twentySeven != null) {
|
tDriver.setTwicCardExpirationDate(DateUtil.parseDate(twentySeven));
|
}
|
if (twentyEight != null) {
|
tDriver.setDotCardExpirationDate(DateUtil.parseDate(twentyEight));
|
}
|
if (twentyNine != null) {
|
tDriver.setLastRoadTestDate(DateUtil.parseDate(twentyNine));
|
}
|
if (thirty != null) {
|
tDriver.setLastAlcoholTestDate(DateUtil.parseDate(thirty));
|
}
|
tDriver.setAccount(thirtyOne);
|
tDriver.setPassword(SecureUtil.md5(thirtyTwo));
|
List<TDriver> tDrivers = driverService.selectList(new EntityWrapper<TDriver>().eq("account", thirtyOne));
|
if(tDrivers.size()==0){
|
driverService.insert(tDriver);
|
}
|
}
|
return new SuccessTip();
|
} catch (Exception e) {
|
e.printStackTrace();
|
return new ErrorTip(500,"Error");
|
}
|
}
|
|
/**
|
* 转换日期
|
*
|
* @return
|
*/
|
public static String importByExcelForDate(String value) {//value就是它的天数
|
String currentCellValue = "";
|
if (value != null && !value.equals("")) {
|
Calendar calendar = new GregorianCalendar(1900, 0, -1);
|
Date d = calendar.getTime();
|
Date dd = DateUtils.addDays(d, Integer.valueOf(value));
|
DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
|
currentCellValue = formater.format(dd);
|
}
|
return currentCellValue;
|
}
|
|
}
|