Commit 2a6dc0ca authored by wujipeng's avatar wujipeng
Browse files

模板去重逻辑修改

parent 14bc3c42
package com.platform.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD) // 表示该注解只能用于成员变量
@Retention(RetentionPolicy.RUNTIME) // 表示该注解在运行时可用
public @interface NumericValue {
double value(); // 唯一的数值参数
}
\ No newline at end of file
...@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.annotation.TableId; ...@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.platform.annotation.NumericValue;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -34,81 +33,64 @@ public class ExcelDataEntity { ...@@ -34,81 +33,64 @@ public class ExcelDataEntity {
@ApiModelProperty("目录id") @ApiModelProperty("目录id")
private String directoryId; private String directoryId;
@NumericValue(0)
@ApiModelProperty("交易类型") @ApiModelProperty("交易类型")
private String type; private String type;
@NumericValue(1)
@ApiModelProperty("交易主体的出入") @ApiModelProperty("交易主体的出入")
private String direction; private String direction;
@NumericValue(2)
@ApiModelProperty("交易时间") @ApiModelProperty("交易时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date time; private Date time;
@NumericValue(3)
@ApiModelProperty("交易金额") @ApiModelProperty("交易金额")
private double amount; private double amount;
@NumericValue(4)
@ApiModelProperty("交易流水号") @ApiModelProperty("交易流水号")
private String serial; private String serial;
@NumericValue(5)
@ApiModelProperty("收款方银行卡所属银行卡号") @ApiModelProperty("收款方银行卡所属银行卡号")
@TableField("payee_bank_card") @TableField("payee_bank_card")
private String payeeBankCard; private String payeeBankCard;
@NumericValue(6)
@ApiModelProperty("收款方支付账号") @ApiModelProperty("收款方支付账号")
@TableField("payee_account") @TableField("payee_account")
private String payeeAccount; private String payeeAccount;
@NumericValue(7)
@ApiModelProperty("收款方商户号") @ApiModelProperty("收款方商户号")
@TableField("payee_merchant") @TableField("payee_merchant")
private String payeeMerchant; private String payeeMerchant;
@NumericValue(8)
@ApiModelProperty("收款方商户名称") @ApiModelProperty("收款方商户名称")
@TableField("payee_name") @TableField("payee_name")
private String payeeName; private String payeeName;
@NumericValue(9)
@ApiModelProperty("付款方银行卡所属银行名称") @ApiModelProperty("付款方银行卡所属银行名称")
@TableField("payment_bank_name") @TableField("payment_bank_name")
private String paymentBankName; private String paymentBankName;
@NumericValue(10)
@ApiModelProperty("付款方银行卡所属银行卡号") @ApiModelProperty("付款方银行卡所属银行卡号")
@TableField("payment_bank_card") @TableField("payment_bank_card")
private String paymentBankCard; private String paymentBankCard;
@NumericValue(11)
@ApiModelProperty("付款方支付账号") @ApiModelProperty("付款方支付账号")
@TableField("payment_account") @TableField("payment_account")
private String paymentAccount; private String paymentAccount;
@NumericValue(12)
@ApiModelProperty("交易支付设备ip") @ApiModelProperty("交易支付设备ip")
private String ip; private String ip;
@NumericValue(13)
@ApiModelProperty("mac地址") @ApiModelProperty("mac地址")
private String mac; private String mac;
@NumericValue(14)
@ApiModelProperty("银行外部渠道交易流水号") @ApiModelProperty("银行外部渠道交易流水号")
@TableField("external_channel") @TableField("external_channel")
private String externalChannel; private String externalChannel;
@NumericValue(15)
@ApiModelProperty("支付账号") @ApiModelProperty("支付账号")
@TableField("pay_account") @TableField("pay_account")
private String payAccount; private String payAccount;
@NumericValue(16)
@ApiModelProperty("备注") @ApiModelProperty("备注")
private String remark; private String remark;
......
...@@ -12,7 +12,6 @@ import com.platform.model.vo.AnalysisVO; ...@@ -12,7 +12,6 @@ import com.platform.model.vo.AnalysisVO;
import com.platform.model.vo.FileUploadVO; import com.platform.model.vo.FileUploadVO;
import com.platform.model.vo.TableHeaderVO; import com.platform.model.vo.TableHeaderVO;
import com.platform.service.*; import com.platform.service.*;
import com.platform.utils.AnnotationUtils;
import com.platform.utils.DateUtils; import com.platform.utils.DateUtils;
import com.platform.utils.IdCardUtils; import com.platform.utils.IdCardUtils;
import com.platform.utils.StringUtils; import com.platform.utils.StringUtils;
...@@ -29,10 +28,8 @@ import javax.annotation.Resource; ...@@ -29,10 +28,8 @@ import javax.annotation.Resource;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
...@@ -134,31 +131,17 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -134,31 +131,17 @@ public class AnalysisServiceImpl implements AnalysisService {
filterIndex.add(tableHeaderVO.getIndex()); filterIndex.add(tableHeaderVO.getIndex());
} }
} }
for (int i = 0; i < tableHeaderList.size(); i++) {
if (!ObjectUtils.isEmpty(tableHeaderList.get(i)) && !ObjectUtils.isEmpty(tableHeaderList.get(i)) && tableHeaderList.get(i).getFilter()) {
filterIndex.add(i);
}
}
Map<String, ExcelDataEntity> excelDataMap = Maps.newHashMap(); Map<String, ExcelDataEntity> excelDataMap = Maps.newHashMap();
List<UserEntity> userList = Lists.newArrayList(); List<UserEntity> userList = Lists.newArrayList();
//保存excel数据,判断是否使用默认模板 //保存excel数据,判断是否使用默认模板
if (!ObjectUtils.isEmpty(ExcelTemplate)) { if (!ObjectUtils.isEmpty(ExcelTemplate) && !filterIndex.isEmpty()) {
List<ExcelDataEntity> afterDeduplication = Lists.newArrayList(); List<ExcelDataEntity> afterDeduplication = Lists.newArrayList();
for (ExcelDataEntity excelDatum : excelData) { deduplicationData(excelDataMap, excelData, filterIndex);
StringBuilder key = new StringBuilder();
for (Integer index : filterIndex) {
Field field = AnnotationUtils.findFieldByNumericValue(excelDatum, index);
if (field != null) {
Method getter = AnnotationUtils.findGetterMethod(field, excelDatum.getClass());
if (getter != null) {
try {
Object value = getter.invoke(excelDatum);
if (value != null) {
key.append(value);
}
} catch (IllegalAccessException | InvocationTargetException ignored) {
// 异常处理(建议至少记录日志)
}
}
}
}
excelDataMap.put(key.toString(), excelDatum);
}
//excelDataMap中的value传给afterDeduplication //excelDataMap中的value传给afterDeduplication
excelDataMap.forEach( excelDataMap.forEach(
(key, excelDatum) -> afterDeduplication.add(excelDatum) (key, excelDatum) -> afterDeduplication.add(excelDatum)
...@@ -214,6 +197,66 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -214,6 +197,66 @@ public class AnalysisServiceImpl implements AnalysisService {
} }
} }
private void deduplicationData(Map<String, ExcelDataEntity> excelDataMap, List<ExcelDataEntity> excelData, List<Integer> filterIndex) {
for (ExcelDataEntity excelDatum : excelData) {
StringBuilder key = new StringBuilder();
if (filterIndex.contains(0)) {
key.append(excelDatum.getType());
}
if (filterIndex.contains(1)) {
key.append(excelDatum.getDirection());
}
if (filterIndex.contains(2)) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = sdf.format(excelDatum.getTime());
key.append(formattedDate);
}
if (filterIndex.contains(3)) {
key.append(excelDatum.getAmount());
}
if (filterIndex.contains(4)) {
key.append(excelDatum.getSerial());
}
if (filterIndex.contains(5)) {
key.append(excelDatum.getPayeeBankCard());
}
if (filterIndex.contains(6)) {
key.append(excelDatum.getPayeeAccount());
}
if (filterIndex.contains(7)) {
key.append(excelDatum.getPayeeMerchant());
}
if (filterIndex.contains(8)) {
key.append(excelDatum.getPayeeName());
}
if (filterIndex.contains(9)) {
key.append(excelDatum.getPaymentBankName());
}
if (filterIndex.contains(10)) {
key.append(excelDatum.getPaymentBankCard());
}
if (filterIndex.contains(11)) {
key.append(excelDatum.getPaymentAccount());
}
if (filterIndex.contains(12)) {
key.append(excelDatum.getIp());
}
if (filterIndex.contains(13)) {
key.append(excelDatum.getMac());
}
if (filterIndex.contains(14)) {
key.append(excelDatum.getExternalChannel());
}
if (filterIndex.contains(15)) {
key.append(excelDatum.getPayAccount());
}
if (filterIndex.contains(16)) {
key.append(excelDatum.getRemark());
}
excelDataMap.put(key.toString(), excelDatum);
}
}
private ExcelDataEntity handleExcelData(List<TableHeaderVO> tableHeaderList, Row row, String folderName, String fileId, int caseId) { private ExcelDataEntity handleExcelData(List<TableHeaderVO> tableHeaderList, Row row, String folderName, String fileId, int caseId) {
ExcelDataEntity excelDataEntity = new ExcelDataEntity(); ExcelDataEntity excelDataEntity = new ExcelDataEntity();
......
package com.platform.utils;
import com.platform.annotation.NumericValue;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class AnnotationUtils {
/**
* 获取带有指定NumericValue值的字段
* @param target 目标对象
* @param value 要查找的注解值
* @return 匹配的字段,如果没有找到返回null
*/
public static Field findFieldByNumericValue(Object target, int value) {
for (Field field : target.getClass().getDeclaredFields()) {
NumericValue annotation = field.getAnnotation(NumericValue.class);
if (annotation != null && annotation.value() == value) {
return field;
}
}
return null;
}
/**
* 获取字段的getter方法
* @param field 目标字段
* @param clazz 目标类
* @return getter方法,如果没有找到返回null
*/
public static Method findGetterMethod(Field field, Class<?> clazz) {
String fieldName = field.getName();
String getterName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
try {
return clazz.getMethod(getterName);
} catch (NoSuchMethodException e) {
// 尝试boolean类型的is前缀
if (field.getType() == boolean.class || field.getType() == Boolean.class) {
getterName = "is" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
try {
return clazz.getMethod(getterName);
} catch (NoSuchMethodException ex) {
return null;
}
}
return null;
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment