导入开票文件支持更多日期格式

product
chuang 2 years ago
parent bf1ec3ca41
commit 173416c6aa

@ -7,9 +7,10 @@ import cn.hutool.poi.excel.ExcelWriter;
import jnpf.base.ActionResult;
import jnpf.controller.UtilsController;
import jnpf.model.UploaderVO;
import jnpf.purchaseorder.model.purchaseorder.VehiclePictureFolder;
import jnpf.purchaseorder.utils.VehiclePictureFolderUtils;
import jnpf.util.FilePathUtil;
import jnpf.util.JsonUtil;
import jnpf.util.StringUtil;
import jnpf.util.context.SpringContext;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
@ -23,10 +24,8 @@ import sun.misc.BASE64Encoder;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @Author: WangChuang
@ -38,10 +37,11 @@ public class FileCopy {
public static ArrayList<Object> getInfoAndUpFile(File[] fileList) throws Exception {
String fileName = "";
// 单图片对应的信息
// 单图片对应的信息
HashMap<String, Object> fileMap = new HashMap<>();
// 车辆图片对应的信息
HashMap<String, Object> carFileMap = new HashMap<>();
HashMap<String, VehiclePictureFolder> folderHashMap = new HashMap<>();
ArrayList<Object> resultList = new ArrayList<>();
File excelFile = null;
for (int i = 0; i < fileList.length; i++) {
@ -61,14 +61,23 @@ public class FileCopy {
if (resultListt.get(2) != null) {
fileMap.putAll ((HashMap<String, Object>) resultListt.get(2));
}
if (resultListt.get(3)!=null){
folderHashMap.putAll((HashMap<String,VehiclePictureFolder>) resultListt.get(3));
}
}
if (file.isFile()) {
String indexString = name.substring(0, name.lastIndexOf("."));
String parent = file.getParent();
String parentName = parent.substring(parent.lastIndexOf("\\") + 1, parent.length());
VehiclePictureFolder vehiclePictureFolder = VehiclePictureFolderUtils.getVehiclePictureFolder(parentName);
parentName= StringUtil.getCharStr(parentName);
// 序号
parentName=vehiclePictureFolder.getSerialNumber();
if (!folderHashMap.containsKey(parentName)){
folderHashMap.put(parentName,vehiclePictureFolder);
}
// if (parentName.contains("-")){
// parentName=parentName.substring(0,parentName.lastIndexOf("-"));
// }
@ -96,7 +105,7 @@ public class FileCopy {
}
list.add(dataMap);
// 将榜单照片存在榜单列表中
// 将磅单照片存在磅单列表中
if (indexString.equals("1")||indexString.equals(parentName)) {
if (fileMap.containsKey(parentName)) {
List<Object> o = (List<Object>) fileMap.get(parentName);
@ -161,6 +170,9 @@ public class FileCopy {
Cell cell2 = row.createCell(21);
Cell cell3 = row.createCell(22);
Cell cell4 = row.createCell(23);
Cell cell6 = row.createCell(25);
Cell cell7 = row.createCell(26);
Cell cell8 = row.createCell(27);
Cell cell5 = row.getCell(9);
Cell strCell1 = row.getCell(8);
@ -169,12 +181,13 @@ public class FileCopy {
Cell strCell4 = row.getCell(5);
Cell strCell5 = row.getCell(11);
Cell strCell6 = row.getCell(12);
Cell strCell7 = row.getCell(1);
if (i1 == 0) {
Row row1 = sheet.getRow(2);
Cell cell11 = row1.createCell(19);
cell11.setCellValue("单图片地址");
cell11.setCellValue("单图片地址");
Cell cell22 = row1.createCell(20);
cell22.setCellValue("客户");
Cell cell33 = row1.createCell(21);
@ -185,12 +198,19 @@ public class FileCopy {
cell55.setCellValue("车辆图片地址");
Cell cell66 = row1.createCell(24);
cell66.setCellValue("错误原因");
Cell cell77 = row1.createCell(25);
cell77.setCellValue("司机姓名");
Cell cell88 = row1.createCell(26);
cell88.setCellValue("司机联系方式");
Cell cell99 = row1.createCell(27);
cell99.setCellValue("司机车牌号");
}
Object o1 = fileMap.get(String.valueOf(o));
Object o2 = carFileMap.get(String.valueOf(o));
VehiclePictureFolder vehiclePictureFolder1 = folderHashMap.get(String.valueOf(o));
cell.setCellValue(String.valueOf(o1).equals("null") ? "" : JsonUtil.getListToJsonArray((List<Map<String,Object>>)o1).toString());
cell.setCellValue(String.valueOf(o1).equals("null") ? "" : JsonUtil.getListToJsonArray((List<Map<String,Object>>)o1).toString());
cell4.setCellValue(String.valueOf(o2).equals("null") ? "" :JsonUtil.getListToJsonArray((List<Map<String,Object>>)o2).toString());
cell1.setCellValue(companyStr);
@ -198,6 +218,9 @@ public class FileCopy {
cell3.setCellValue(str3);
cell5.setCellType(CellType.STRING);
cell5.setCellValue(FileCopy.setSteColumn(cell5));
cell6.setCellValue(vehiclePictureFolder1.getDriverName()!=null?vehiclePictureFolder1.getDriverName():"");
cell7.setCellValue(vehiclePictureFolder1.getPhoneNumber()!=null?vehiclePictureFolder1.getPhoneNumber():"");
cell8.setCellValue(vehiclePictureFolder1.getCarNumber()!=null?vehiclePictureFolder1.getCarNumber():"");
strCell1.setCellType(CellType.STRING);
strCell1.setCellValue(FileCopy.setSteColumn(strCell1));
strCell2.setCellType(CellType.STRING);
@ -210,7 +233,34 @@ public class FileCopy {
strCell5.setCellValue(FileCopy.setSteColumn(strCell5));
strCell6.setCellType(CellType.STRING);
strCell6.setCellValue(FileCopy.setSteColumn(strCell6));
// strCell7.setCellType(CellType.STRING);
String stringCellValue = VehiclePictureFolderUtils.getValue(strCell7);
// strCell7.setCellValue(stringCellValue);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//定义新的日期格式
SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");//定义新的日期格式
SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy/MM/dd K:mm:ss a");//定义新的日期格式
SimpleDateFormat formatter3 = new SimpleDateFormat("yyyy.MM.dd");//定义新的日期格式
//format():将给定的 Date 格式化为日期/时间字符串。即date--->String
try {
if (stringCellValue.contains("/")){
Date date = formatter2.parse(stringCellValue);//parse():String--->date
strCell7.setCellValue(formatter.format(date));
}
else if (stringCellValue.contains("-")&&stringCellValue.contains(":")){
Date date = formatter.parse(stringCellValue);//parse():String--->date
strCell7.setCellValue(formatter.format(date));
} else if (stringCellValue.contains("-")) {
Date date = formatter1.parse(stringCellValue);//parse():String--->date
strCell7.setCellValue(formatter.format(date));
} else if (stringCellValue.contains(".")) {
Date date = formatter3.parse(stringCellValue);//parse():String--->date
strCell7.setCellValue(formatter.format(date));
}
} catch (Exception e) {
e.printStackTrace();
}
}
writer.flush(excelFile);
writer.close();
@ -228,7 +278,9 @@ public class FileCopy {
System.out.println(fileLoader.getName());
resultList.add(fileLoader.getName());
resultList.add(carFileMap);
resultList.add(fileMap);
resultList.add(folderHashMap);
return resultList;
}
input.close();
@ -244,6 +296,7 @@ public class FileCopy {
resultList.add(fileName);
resultList.add(carFileMap);
resultList.add(fileMap);
resultList.add(folderHashMap);
return resultList;
}

@ -80,11 +80,14 @@ public class PurchaseorderDTO {
private String purchaseId;
@Excel(name = "客户")
private String customerId;
@Excel(name = "司机")
@Excel(name = "司机名")
private String driverName;
@Excel(name = "联系方式")
@Excel(name = "司机联系方式")
private String contact;
@Excel(name = "司机车牌号")
private String driverVehicleId;
private String supplierId;
private String id;

@ -0,0 +1,23 @@
package jnpf.purchaseorder.model.purchaseorder;
import lombok.Data;
/**
* @Author: WangChuang
* @Date: 3/4/2023 1:50
* @Description //注释: 车辆图片的文件夹获取的信息
* @Version 1.0
*/
@Data
public class VehiclePictureFolder {
/**序号 **/
private String serialNumber;
/**车牌号**/
private String carNumber;
/**司机名字**/
private String driverName;
/**手机号**/
private String phoneNumber;
}

@ -73,7 +73,6 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.*;
import java.util.concurrent.CountDownLatch;
@ -1457,6 +1456,8 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl<PurchaseorderitemM
dataRowMap.put("driverName", model.getDriverName());
// 司机联系方式
dataRowMap.put("contact", model.getContact());
// 司机车牌号
dataRowMap.put("driverVehicleId", model.getDriverVehicleId());
dataRow.add(dataRowMap);
}
@ -1514,18 +1515,35 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl<PurchaseorderitemM
// 进行编码id的转换
for (int i = 0; i < num1; i++) {
PurchaseorderDTO model = dataList.get(i);
// 收获日期
if (model.getPoundDate() != null && !model.getPoundDate().isEmpty() && !model.getPoundDate().equals("null")) {
//// 收获日期
// if (model.getPoundDate() != null && !model.getPoundDate().isEmpty() && !model.getPoundDate().equals("null")) {
//
//// model.setCreatorTime(DateUtil.cstFormat(model.getCreatorTime()));
// Date date = null;
// if (model.getPoundDate().contains(".")){
// date = new SimpleDateFormat("yyyy.MM.dd").parse(model.getPoundDate());
// }else if (model.getPoundDate().contains("-")){
// date = new SimpleDateFormat("yyyy-MM-dd").parse(model.getPoundDate());
// }
// SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
// model.setPoundDate(formatter.format(date));
// 收获日期
if (model.getPoundDate() != null ) {
// model.setCreatorTime(DateUtil.cstFormat(model.getCreatorTime()));
Date date = null;
if (model.getPoundDate().contains(".")){
date = new SimpleDateFormat("yyyy.MM.dd").parse(model.getPoundDate());
}else if (model.getPoundDate().contains("-")){
date = new SimpleDateFormat("yyyy-MM-dd").parse(model.getPoundDate());
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
model.setPoundDate(formatter.format(date));
// Date date = null;
//// if (model.getPoundDate().contains(".")){
//// date = new SimpleDateFormat("yyyy.MM.dd").parse(model.getPoundDate());
//// }else if (model.getPoundDate().contains("-")){
//// date = new SimpleDateFormat("yyyy-MM-dd").parse(model.getPoundDate());
//// }
// SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// model.setPoundDate(formatter.format(model.getPoundDate()));
// 单位
if (model.getUnit() != null) {
if (model.getUnit().equals("吨") || model.getUnit().equals("T")) {
@ -1589,6 +1607,54 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl<PurchaseorderitemM
// ints.add(i);
// continue;
}
}else{
if (model.getDriverVehicleId()!=null){
model.setVehicleId(model.getDriverVehicleId());
LambdaQueryWrapper<VehicleEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(VehicleEntity::getTicketno, model.getVehicleId());
if (!String.valueOf(model.getDriverName()).equals("null")){
wrapper.eq(VehicleEntity::getDrivername,model.getDriverName());
}
List<VehicleEntity> vehicleEntityList = vehicleMapper.selectList(wrapper);
if (vehicleEntityList != null && vehicleEntityList.size() > 0) {
model.setVehicleId(vehicleEntityList.get(0).getId());
VehicleEntity vehicleEntity = vehicleEntityList.get(0);
// 车辆照片
vehicleEntity.setVehiclephotos(model.getCarPictures());
// 联系信息
if (!String.valueOf(model.getContact()).equals("null")&&!model.getContact().isEmpty()) {
vehicleEntity.setContact(model.getContact());
}
vehicleMapper.updateById(vehicleEntity);
} else {
// 添加车牌号
// id
Long aLong = new DefaultIdentifierGenerator().nextId(VehicleEntity.class);
VehicleEntity vehicleEntity = new VehicleEntity();
vehicleEntity.setId(aLong.toString());
// 车辆照片
vehicleEntity.setVehiclephotos(model.getCarPictures());
// 车牌号
vehicleEntity.setTicketno(model.getVehicleId());
// 联系方式
if (!String.valueOf(model.getContact()).equals("null")&&!model.getContact().isEmpty()){
vehicleEntity.setContact(model.getContact());
}
// 司机名称
if (!String.valueOf(model.getDriverName()).equals("null")&&!model.getDriverName().isEmpty()){
vehicleEntity.setDrivername(model.getDriverName());
}
vehicleMapper.insert(vehicleEntity);
model.setVehicleId(aLong.toString());
}
}else {
model.setCauseError("车牌号不存在!请添加车辆信息在尝试添加!");
errList.add(model);
ints.add(i);
continue;
}
}
// 货物
if (model.getMaterialId() != null) {

@ -0,0 +1,105 @@
package jnpf.purchaseorder.utils;
import jnpf.purchaseorder.model.purchaseorder.VehiclePictureFolder;
import jnpf.util.StringUtil;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.junit.jupiter.api.Test;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Pattern;
/**
* @Author: WangChuang
* @Date: 3/4/2023 2:01
* @Description //注释:
* @Version 1.0
*/
public class VehiclePictureFolderUtils {
/**
*
* @param str
* @return
*/
public static VehiclePictureFolder getVehiclePictureFolder(String str){
str=str.trim();
VehiclePictureFolder vehiclePictureFolder = new VehiclePictureFolder();
String charStr = StringUtil.getCharStr(str);
vehiclePictureFolder.setSerialNumber(charStr);
String substring = str.substring(str.indexOf(vehiclePictureFolder.getSerialNumber()) + vehiclePictureFolder.getSerialNumber().length(), str.length() );
String carRegex="^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[警京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼]{0,1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$";
String phoneRegex="0?(13|14|15|16|18|17|19)[0-9]{9}";
if (substring.length()>=7){
for (int i = 0; i <= substring.length()-7; i++) {
String carNumber = StringUtil.substring(substring, i, i + 7);
if ( Pattern.matches(carRegex, carNumber)){
vehiclePictureFolder.setCarNumber(carNumber);
break;
}
}
if (vehiclePictureFolder.getCarNumber()!=null){
String substring1 = substring.substring(0, substring.indexOf(vehiclePictureFolder.getCarNumber()));
String substring2 = substring.substring(substring.indexOf(vehiclePictureFolder.getCarNumber()) + vehiclePictureFolder.getCarNumber().length(), substring.length() );
substring=substring1+substring2;
if (substring1.length()>0){
substring=substring.replaceAll(substring1,"");
}
}
if (substring.length()>=11){
for (int i = 0; i <= substring.length()-11; i++) {
String phone = StringUtil.substring(substring, i, i + 11);
if ( Pattern.matches(phoneRegex, phone)){
vehiclePictureFolder.setPhoneNumber(phone);
break;
}
}
if (vehiclePictureFolder.getPhoneNumber()!=null){
String substring1 = substring.substring(0, substring.indexOf(vehiclePictureFolder.getPhoneNumber()));
String substring2 = substring.substring(substring.indexOf(vehiclePictureFolder.getPhoneNumber()) + vehiclePictureFolder.getPhoneNumber().length(), substring.length() );
substring=substring1+substring2;
}
if (substring.length()>=2){
vehiclePictureFolder.setDriverName(substring);
}
}
}
return vehiclePictureFolder;
}
@Test
public void test1(){ System.out.println(
VehiclePictureFolderUtils.getVehiclePictureFolder("1豫AS0K91李高洋15797755804"));
}
public static String getValue(Cell cell) {
if (cell.getCellType() == CellType.BOOLEAN) {
return String.valueOf(cell.getBooleanCellValue());
} else if (cell.getCellType() == CellType.NUMERIC) {
//20180622,支持日期格式
if(HSSFDateUtil.isCellDateFormatted(cell)){
Date d = (Date) cell.getDateCellValue();
DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//HH:mm:ss
return df2.format(d);
}
//数字
else{
//使用DecimalFormat对double进行了格式化随后使用format方法获得的String就是你想要的值了。
DecimalFormat df = new DecimalFormat("0");
return String.valueOf(df.format(cell.getNumericCellValue()));
}
} else {
return String.valueOf(cell.getStringCellValue());
}
}
}
Loading…
Cancel
Save