|
@@ -1,20 +1,33 @@
|
|
|
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.entity.DriverInfo;
|
|
|
+import com.jpsoft.bus.modules.bus.service.CompanyInfoService;
|
|
|
import com.jpsoft.bus.modules.bus.service.DriverInfoService;
|
|
|
import com.jpsoft.bus.modules.common.dto.MessageResult;
|
|
|
+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 com.jpsoft.bus.modules.common.dto.Sort;
|
|
|
+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.*;
|
|
|
|
|
@@ -26,10 +39,15 @@ import java.util.*;
|
|
|
@Api(description = "driverInfo")
|
|
|
public class DriverInfoController {
|
|
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
|
|
|
@Autowired
|
|
|
private DriverInfoService driverInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CompanyInfoService companyInfoService;
|
|
|
+
|
|
|
@ApiOperation(value="创建空记录")
|
|
|
@GetMapping("create")
|
|
|
public MessageResult<DriverInfo> create(){
|
|
@@ -49,7 +67,6 @@ public class DriverInfoController {
|
|
|
MessageResult<DriverInfo> msgResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
|
- driverInfo.setId(UUID.randomUUID().toString());
|
|
|
driverInfo.setDelFlag(false);
|
|
|
driverInfo.setCreateBy(subject);
|
|
|
driverInfo.setCreateTime(new Date());
|
|
@@ -199,7 +216,7 @@ public class DriverInfoController {
|
|
|
@ApiOperation(value="列表")
|
|
|
@RequestMapping(value = "pageList",method = RequestMethod.POST)
|
|
|
public MessageResult<Map> pageList(
|
|
|
- String id,
|
|
|
+ String companyId,String name,String idCard,String phone,
|
|
|
@RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
@RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
@RequestAttribute String subject){
|
|
@@ -212,17 +229,129 @@ public class DriverInfoController {
|
|
|
Map<String,Object> searchParams = new HashMap<>();
|
|
|
|
|
|
List<Sort> sortList = new ArrayList<>();
|
|
|
- sortList.add(new Sort("id_","asc"));
|
|
|
+ sortList.add(new Sort("create_time","desc"));
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(companyId)) {
|
|
|
+ searchParams.put("companyId", companyId);
|
|
|
+ }
|
|
|
|
|
|
- if (StringUtils.isNotEmpty(id)) {
|
|
|
- searchParams.put("id","%" + id + "%");
|
|
|
+ if (StringUtils.isNotEmpty(name)) {
|
|
|
+ searchParams.put("name","%" + name + "%");
|
|
|
}
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(idCard)) {
|
|
|
+ searchParams.put("idCard","%" + idCard + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(phone)) {
|
|
|
+ searchParams.put("phone","%" + phone + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
Page<DriverInfo> page = driverInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
|
|
|
+ for (DriverInfo driverInfo:page) {
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(driverInfo.getCompanyId());
|
|
|
+ if(companyInfo!=null){
|
|
|
+ driverInfo.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 name = (String)poiUtils.getCellValue(sheetIndex,rowIndex,1).toString().replace(" ","");
|
|
|
+ String idCard = (String)poiUtils.getCellValue(sheetIndex,rowIndex,2).toString().replace(" ","");
|
|
|
+ String phone = (String)poiUtils.getCellValue(sheetIndex,rowIndex,3).toString().replace(" ","");
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(companyName)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ CompanyInfo companyInfo = companyInfoService.findByName(companyName);
|
|
|
+
|
|
|
+ if (companyInfo == null) {
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("所属单位不存在!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ DriverInfo driverInfo = new DriverInfo();
|
|
|
+ driverInfo.setCompanyId(companyInfo.getId());
|
|
|
+ driverInfo.setName(name);
|
|
|
+ driverInfo.setIdCard(idCard);
|
|
|
+ driverInfo.setPhone(phone);
|
|
|
+
|
|
|
+ driverInfo.setDelFlag(false);
|
|
|
+ driverInfo.setCreateBy(subject);
|
|
|
+ driverInfo.setCreateTime(new Date());
|
|
|
+ driverInfoService.insert(driverInfo);
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|