|
@@ -1,20 +1,32 @@
|
|
|
package com.jpsoft.bus.modules.bus.controller;
|
|
|
|
|
|
import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.bus.config.OSSConfig;
|
|
|
+import com.jpsoft.bus.modules.bus.entity.CompanyInfo;
|
|
|
+import com.jpsoft.bus.modules.bus.service.CompanyInfoService;
|
|
|
import com.jpsoft.bus.modules.common.dto.MessageResult;
|
|
|
import com.jpsoft.bus.modules.common.dto.Sort;
|
|
|
import com.jpsoft.bus.modules.bus.entity.VehicleInfo;
|
|
|
import com.jpsoft.bus.modules.bus.service.VehicleInfoService;
|
|
|
+import com.jpsoft.bus.modules.common.utils.OSSUtil;
|
|
|
+import com.jpsoft.bus.modules.common.utils.POIUtils;
|
|
|
import com.jpsoft.bus.modules.common.utils.PojoUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -27,9 +39,15 @@ import java.util.*;
|
|
|
public class VehicleInfoController {
|
|
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
+
|
|
|
@Autowired
|
|
|
private VehicleInfoService vehicleInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CompanyInfoService companyInfoService;
|
|
|
+
|
|
|
@ApiOperation(value="创建空记录")
|
|
|
@GetMapping("create")
|
|
|
public MessageResult<VehicleInfo> create(){
|
|
@@ -50,6 +68,7 @@ public class VehicleInfoController {
|
|
|
|
|
|
try {
|
|
|
vehicleInfo.setId(UUID.randomUUID().toString());
|
|
|
+ vehicleInfo.setStatus("1");
|
|
|
vehicleInfo.setDelFlag(false);
|
|
|
vehicleInfo.setCreateBy(subject);
|
|
|
vehicleInfo.setCreateTime(new Date());
|
|
@@ -199,7 +218,7 @@ public class VehicleInfoController {
|
|
|
@ApiOperation(value="列表")
|
|
|
@RequestMapping(value = "pageList",method = RequestMethod.POST)
|
|
|
public MessageResult<Map> pageList(
|
|
|
- String id,
|
|
|
+ String licensePlateNumber,String companyId,String gpsDeviceNo,String deviceNo,
|
|
|
@RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
@RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
@RequestAttribute String subject){
|
|
@@ -214,15 +233,133 @@ public class VehicleInfoController {
|
|
|
List<Sort> sortList = new ArrayList<>();
|
|
|
sortList.add(new Sort("id_","asc"));
|
|
|
|
|
|
- if (StringUtils.isNotEmpty(id)) {
|
|
|
- searchParams.put("id","%" + id + "%");
|
|
|
+ if (StringUtils.isNotEmpty(licensePlateNumber)) {
|
|
|
+ searchParams.put("licensePlateNumber","%" + licensePlateNumber + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(companyId)) {
|
|
|
+ searchParams.put("companyId",companyId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(gpsDeviceNo)) {
|
|
|
+ searchParams.put("gpsDeviceNo","%" + gpsDeviceNo + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(deviceNo)) {
|
|
|
+ searchParams.put("deviceNo","%" + deviceNo + "%");
|
|
|
}
|
|
|
|
|
|
Page<VehicleInfo> page = vehicleInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
|
|
|
+ for (VehicleInfo vehicleInfo:page) {
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(vehicleInfo.getCompanyId());
|
|
|
+ if(companyInfo!=null){
|
|
|
+ vehicleInfo.setCompanyName(companyInfo.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
msgResult.setResult(true);
|
|
|
msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
|
|
|
return msgResult;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value="导入车辆")
|
|
|
+ @PostMapping("importXls")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "uploadFile",value = "上传文件", required = true,paramType="form", dataType = "__file")
|
|
|
+ })
|
|
|
+ public MessageResult<String> importXls(MultipartFile uploadFile,
|
|
|
+ @RequestAttribute String subject){
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ POIUtils poiUtils = new POIUtils(uploadFile.getInputStream());
|
|
|
+ int sheetIndex = 0;
|
|
|
+ Sheet sheet1 = poiUtils.getSheetAt(sheetIndex);
|
|
|
+
|
|
|
+ int affectCount = 0;
|
|
|
+ int failCount = 0;
|
|
|
+ int validateColIndex = 10;
|
|
|
+
|
|
|
+ for(int rowIndex=1 ; rowIndex<=sheet1.getLastRowNum(); rowIndex++){
|
|
|
+ try {
|
|
|
+ String companyName = (String)poiUtils.getCellValue(sheetIndex,rowIndex,0).toString().replace(" ","");
|
|
|
+ String licensePlateNumber = (String)poiUtils.getCellValue(sheetIndex,rowIndex,1).toString().replace(" ","");
|
|
|
+ String gpsDeviceNo = (String)poiUtils.getCellValue(sheetIndex,rowIndex,2).toString().replace(" ","");
|
|
|
+ String deviceNo = (String)poiUtils.getCellValue(sheetIndex,rowIndex,3).toString().replace(" ","");
|
|
|
+ String loadNumber = (String)poiUtils.getCellValue(sheetIndex,rowIndex,4).toString().replace(" ","");
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(companyName)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ CompanyInfo companyInfo = companyInfoService.findByName(companyName);
|
|
|
+
|
|
|
+ if (companyInfo == null) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("所属单位不存在!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ VehicleInfo vehicleInfo = new VehicleInfo();
|
|
|
+ vehicleInfo.setId(UUID.randomUUID().toString());
|
|
|
+ vehicleInfo.setCompanyId(companyInfo.getId());
|
|
|
+ vehicleInfo.setLicensePlateNumber(licensePlateNumber);
|
|
|
+ vehicleInfo.setGpsDeviceNo(gpsDeviceNo);
|
|
|
+ vehicleInfo.setDeviceNo(deviceNo);
|
|
|
+ vehicleInfo.setStatus("1");
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(loadNumber)){
|
|
|
+ vehicleInfo.setLoadNumber(Integer.parseInt(loadNumber));
|
|
|
+ }
|
|
|
+
|
|
|
+ vehicleInfo.setDelFlag(false);
|
|
|
+ vehicleInfo.setCreateBy(subject);
|
|
|
+ vehicleInfo.setCreateTime(new Date());
|
|
|
+ vehicleInfoService.insert(vehicleInfo);
|
|
|
+
|
|
|
+ affectCount++;
|
|
|
+
|
|
|
+ }
|
|
|
+ catch(Exception innerEx){
|
|
|
+ logger.error(innerEx.getMessage(),innerEx);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (failCount>0){
|
|
|
+ //有导入失败的记录
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条,有" + failCount + "条数据未导入成功,错误原因请查看报表。");
|
|
|
+
|
|
|
+ //todo 只保留错误数据的sheet
|
|
|
+ Workbook wb = poiUtils.exportErrorXls(sheetIndex,validateColIndex,1 + affectCount + failCount);
|
|
|
+
|
|
|
+ //todo 将wb保存到oss
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+ wb.write(output);
|
|
|
+
|
|
|
+ byte[] buffer = output.toByteArray();
|
|
|
+ ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
+
|
|
|
+ String downloadUrl = OSSUtil.upload(ossConfig,"import","error.xls",input);
|
|
|
+
|
|
|
+ //todo 返回导入失败报表下载链接
|
|
|
+ msgResult.setData(downloadUrl);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
}
|