修改float精度问题
parent
a691c6def9
commit
01c6cf1cdc
|
@ -17,6 +17,7 @@ import aiyh.utils.sqlUtil.builderSql.impl.BuilderSqlImpl;
|
|||
import aiyh.utils.sqlUtil.whereUtil.Where;
|
||||
import aiyh.utils.sqlUtil.whereUtil.impl.PrepWhereImpl;
|
||||
import aiyh.utils.sqlUtil.whereUtil.impl.WhereImpl;
|
||||
import aiyh.utils.tool.cn.hutool.core.util.StrUtil;
|
||||
import aiyh.utils.zwl.common.ToolUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
@ -28,6 +29,7 @@ import com.weaver.general.TimeUtil;
|
|||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
import org.apache.log4j.*;
|
||||
import org.h2.util.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import weaver.common.util.string.StringUtil;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.docs.docs.DocImageManager;
|
||||
|
@ -61,6 +63,9 @@ import java.lang.reflect.*;
|
|||
import java.math.BigDecimal;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -3952,4 +3957,41 @@ public class Util extends weaver.general.Util {
|
|||
supportLanuage.append("`~`~");
|
||||
return supportLanuage.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>获取临时路径</h2>
|
||||
*
|
||||
* @param dir 临时路径名
|
||||
* @param prefix 文件后缀
|
||||
* @return 文件路径名
|
||||
*/
|
||||
@NotNull
|
||||
public static String getTempFilePath(String dir, String prefix) {
|
||||
if (StrUtil.isBlank(dir)) {
|
||||
dir = "temp";
|
||||
}
|
||||
if (StrUtil.isBlank(prefix)) {
|
||||
throw new CustomerException("this prefix can not be null!");
|
||||
}
|
||||
String sysFilePath = GCONST.getSysFilePath();
|
||||
String filePath = "";
|
||||
if (sysFilePath.endsWith(File.separator)) {
|
||||
filePath = sysFilePath + "cus_temp" + File.separator + dir + File.separator +
|
||||
System.currentTimeMillis() + "-" + dir + "-" + UUID.randomUUID() + prefix;
|
||||
} else {
|
||||
filePath = sysFilePath + File.separator + "cus_temp" + File.separator + dir + File.separator +
|
||||
System.currentTimeMillis() + "-" + dir + "-" + UUID.randomUUID() + prefix;
|
||||
}
|
||||
Path path = Paths.get(filePath);
|
||||
if (!Files.exists(path)) {
|
||||
Path parent = path.getParent();
|
||||
try {
|
||||
Files.createDirectories(parent);
|
||||
} catch (IOException e) {
|
||||
throw new CustomerException(Util.logStr("can not create file [{}]", filePath));
|
||||
}
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,11 @@ public class FloatTypeHandler implements TypeHandler {
|
|||
}
|
||||
return 0.0F;
|
||||
}
|
||||
return Float.parseFloat(string);
|
||||
float v = Float.parseFloat(string);
|
||||
if (!string.equals(String.valueOf(v))) {
|
||||
return Double.parseDouble(string);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,7 +45,11 @@ public class FloatTypeHandler implements TypeHandler {
|
|||
}
|
||||
return 0.0F;
|
||||
}
|
||||
return Float.parseFloat(string);
|
||||
float v = Float.parseFloat(string);
|
||||
if (!string.equals(String.valueOf(v))) {
|
||||
return Double.parseDouble(string);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -55,7 +63,11 @@ public class FloatTypeHandler implements TypeHandler {
|
|||
}
|
||||
return 0.0F;
|
||||
}
|
||||
return Float.parseFloat(string);
|
||||
float v = Float.parseFloat(string);
|
||||
if (!string.equals(String.valueOf(v))) {
|
||||
return Double.parseDouble(string);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,7 +81,11 @@ public class FloatTypeHandler implements TypeHandler {
|
|||
}
|
||||
return 0.0F;
|
||||
}
|
||||
return Float.parseFloat(string);
|
||||
float v = Float.parseFloat(string);
|
||||
if (!string.equals(String.valueOf(v))) {
|
||||
return Double.parseDouble(string);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -473,15 +473,15 @@ public class ResultMapper {
|
|||
}
|
||||
if ("FLOAT".equalsIgnoreCase(columnType) || "DOUBLE".equalsIgnoreCase(columnType) || "DECIMAL".equalsIgnoreCase(columnType)) {
|
||||
if (enable) {
|
||||
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getFloat(i + 1));
|
||||
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1));
|
||||
continue;
|
||||
}
|
||||
if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) {
|
||||
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getFloat(i + 1));
|
||||
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1));
|
||||
}
|
||||
((Map<? super Object, ? super Object>) o).put(columnName[i].toLowerCase(), rs.getFloat(i + 1));
|
||||
((Map<? super Object, ? super Object>) o).put(columnName[i].toUpperCase(), rs.getFloat(i + 1));
|
||||
((Map<? super Object, ? super Object>) o).put(columnName[i], rs.getFloat(i + 1));
|
||||
((Map<? super Object, ? super Object>) o).put(columnName[i].toLowerCase(), rs.getString(i + 1));
|
||||
((Map<? super Object, ? super Object>) o).put(columnName[i].toUpperCase(), rs.getString(i + 1));
|
||||
((Map<? super Object, ? super Object>) o).put(columnName[i], rs.getString(i + 1));
|
||||
continue;
|
||||
}
|
||||
if (method.isAnnotationPresent(Associations.class)) {
|
||||
|
|
|
@ -414,7 +414,6 @@ public class DealWithMapping extends ToolUtil {
|
|||
}
|
||||
// 6为List类型
|
||||
else if (ParamTypeEnum.LIST == anEnum) {
|
||||
String childType = mappingDetail.getChildType();
|
||||
List<MappingDetail> childList = mappingDetail.getChildList();
|
||||
List<Object> list = new ArrayList<>();
|
||||
requestParam.put(paramName, list);
|
||||
|
@ -744,12 +743,15 @@ public class DealWithMapping extends ToolUtil {
|
|||
if ("".equals(value)) {
|
||||
value = Util.null2String(detailMap.get(fieldNameLower));
|
||||
}
|
||||
} else if ("".equals(childSource)) {
|
||||
value = valueContext;
|
||||
} else {
|
||||
value = Util.null2String(mainMap.get(fieldName));
|
||||
if ("".equals(value)) {
|
||||
value = Util.null2String(detailMap.get(fieldNameLower));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
value = o.execute(mainMap, detailMap, String.valueOf(value == null ? "" : value), pathParamMap);
|
||||
}
|
||||
|
@ -1237,6 +1239,7 @@ public class DealWithMapping extends ToolUtil {
|
|||
*/
|
||||
private void listValueDeal(Map<String, Object> mainMap, List<MappingDetail> childList, List<Object> list, MappingDetail detail) throws ValueDealException {
|
||||
String childSource = detail.getDataSource();
|
||||
|
||||
String childType = detail.getChildType();
|
||||
if ("1".equals(childSource)) {
|
||||
int mainId = Util.getIntValue(Util.null2String(mainMap.get("id")));
|
||||
|
|
|
@ -21,10 +21,7 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -56,47 +53,60 @@ public class VoucherPayableNewAction extends SafeCusBaseAction {
|
|||
|
||||
@PrintParamMark
|
||||
@RequiredMark("凭证类型,1- 应付凭证; 2- 付款凭证")
|
||||
@ActionDefaultTestValue("1")
|
||||
private String voucherType;
|
||||
|
||||
|
||||
@PrintParamMark
|
||||
@RequiredMark("应付凭证远程路径")
|
||||
@ActionDefaultTestValue("/test")
|
||||
private String pavRemotePath;
|
||||
|
||||
|
||||
@PrintParamMark
|
||||
@RequiredMark("付款凭证远程路径")
|
||||
@ActionDefaultTestValue("/test")
|
||||
private String pmvRemotePath;
|
||||
|
||||
@PrintParamMark
|
||||
@RequiredMark("用户名")
|
||||
@ActionDefaultTestValue("userName")
|
||||
private String userName;
|
||||
|
||||
@PrintParamMark
|
||||
@RequiredMark("密码")
|
||||
@ActionDefaultTestValue("password")
|
||||
private String password;
|
||||
|
||||
|
||||
@PrintParamMark
|
||||
@RequiredMark("ip")
|
||||
@ActionDefaultTestValue("127.0.0.1")
|
||||
private String ip;
|
||||
|
||||
|
||||
@PrintParamMark
|
||||
@RequiredMark("应付凭证远程文件名称前缀")
|
||||
@ActionDefaultTestValue("test")
|
||||
private String pavFileName;
|
||||
|
||||
|
||||
@PrintParamMark
|
||||
@RequiredMark("付款凭证远程文件名称前缀")
|
||||
@ActionDefaultTestValue("test")
|
||||
private String pmvFileName;
|
||||
|
||||
@PrintParamMark
|
||||
@ActionOptionalParam(desc = "是否删除生成的临时本地文件,true - 删除 false - 不删除", value = "false")
|
||||
private String deleteTemp = "false";
|
||||
|
||||
@PrintParamMark
|
||||
@RequiredMark("过滤字段字段名称,接口参数配置中的接口参数名,也就是序号")
|
||||
@ActionDefaultTestValue("100")
|
||||
private String filterField;
|
||||
|
||||
@Override
|
||||
|
||||
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) {
|
||||
|
||||
try {
|
||||
|
@ -136,7 +146,8 @@ public class VoucherPayableNewAction extends SafeCusBaseAction {
|
|||
private String getFile(String billTable, RequestInfo requestInfo) {
|
||||
dealWithMapping.setMainTable(billTable);
|
||||
RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(onlyMark);
|
||||
Map<String, Object> requestParam = dealWithMapping.getRequestParam(getObjMainTableValue(requestInfo), requestMappingConfig);
|
||||
Map<String, Object> objMainTableValue = getObjMainTableValue(requestInfo);
|
||||
Map<String, Object> requestParam = dealWithMapping.getRequestParam(objMainTableValue, requestMappingConfig);
|
||||
Assert.notEmpty(requestParam, "query config error, can not query result by onlyMark:[{}],Please check the configuration table", onlyMark);
|
||||
// 借方
|
||||
List<Object> debit = (List<Object>) requestParam.get("debit");
|
||||
|
@ -164,10 +175,13 @@ public class VoucherPayableNewAction extends SafeCusBaseAction {
|
|||
}
|
||||
sb.deleteCharAt(sb.lastIndexOf("\t"));
|
||||
sb.append("\r\n");
|
||||
log.info("头写入的数据:" + sb);
|
||||
// 写入借方信息
|
||||
writeList(debit, sb);
|
||||
log.info("debit写入的数据:" + sb);
|
||||
// 写入贷方信息
|
||||
writeList(creditSide, sb);
|
||||
log.info("creditSide写入的数据:" + sb);
|
||||
String filePath = getFilePath();
|
||||
try {
|
||||
OutputStreamWriter out = new OutputStreamWriter(
|
||||
|
@ -200,6 +214,15 @@ public class VoucherPayableNewAction extends SafeCusBaseAction {
|
|||
keys = sortKey(keys);
|
||||
for (Object o : list) {
|
||||
Map<String, Object> map = (Map<String, Object>) o;
|
||||
if (map.containsKey(filterField)) {
|
||||
try {
|
||||
String value = Util.null2String(map.get(filterField));
|
||||
if (Double.parseDouble(value) == 0.0) {
|
||||
continue;
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
for (String key : keys) {
|
||||
if (map.containsKey(key)) {
|
||||
sb.append(map.get(key))
|
||||
|
@ -212,11 +235,43 @@ public class VoucherPayableNewAction extends SafeCusBaseAction {
|
|||
}
|
||||
|
||||
private List<String> sortKey(List<String> list) {
|
||||
return list.stream()
|
||||
.map(Integer::parseInt)
|
||||
.sorted()
|
||||
.map(Util::null2String)
|
||||
.collect(Collectors.toList());
|
||||
List<Entry> entryList = new ArrayList<>();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Entry entry = new Entry();
|
||||
entry.setIndex(i);
|
||||
entry.setValue(list.get(i));
|
||||
entryList.add(entry);
|
||||
}
|
||||
List<Entry> collect = entryList.stream()
|
||||
.sorted(
|
||||
Comparator.comparing(Entry::getValue)
|
||||
).collect(Collectors.toList());
|
||||
List<String> result = new ArrayList<>();
|
||||
for (Entry entry : collect) {
|
||||
result.add(list.get(entry.getIndex()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
class Entry {
|
||||
private Integer index;
|
||||
private String value;
|
||||
|
||||
public Integer getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(Integer index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public Double getValue() {
|
||||
return Double.parseDouble(value);
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
|
|
@ -96,7 +96,7 @@ public interface SapConfigMapper {
|
|||
* @author youHong.ai ******************************************
|
||||
*/
|
||||
@Select("select * from $t{billTable} where requestid = #{requestId}")
|
||||
Map<String, Object> selectWorkflowDataByRequestId(@ParamMapper("requestId") String requestId,
|
||||
Map<String, String> selectWorkflowDataByRequestId(@ParamMapper("requestId") String requestId,
|
||||
@ParamMapper("billTable") String billTable);
|
||||
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ public class SapConfigService {
|
|||
}
|
||||
|
||||
private SapVoucher parseByPaymentDetailTable(String requestId, String billTable, SapConfigMain sapConfigMain) {
|
||||
Map<String, Object> workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable);
|
||||
Map<String, String> workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable);
|
||||
Assert.notNull(workflowMainData, "payment: query workflow data fail, query request id is {}", requestId);
|
||||
List<Map<String, Object>> workflowDetailData = mapper.selectWorkflowDataByMainId(Util.null2String(workflowMainData.get("id")),
|
||||
sapConfigMain.getDocumentDetailTableName());
|
||||
|
@ -120,7 +120,7 @@ public class SapConfigService {
|
|||
|
||||
|
||||
private SapVoucher parsePaymentByMainTable(String requestId, String billTable, SapConfigMain sapConfigMain) {
|
||||
Map<String, Object> workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable);
|
||||
Map<String, String> workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable);
|
||||
Assert.notNull(workflowMainData, "payment: query workflow data fail, query request id is {}", requestId);
|
||||
Map<String, Object> workflowData = new HashMap<>();
|
||||
workflowData.put("main", workflowMainData);
|
||||
|
@ -144,7 +144,7 @@ public class SapConfigService {
|
|||
*/
|
||||
private SapVoucher parseByMainTable(String requestId,
|
||||
String billTable, SapConfigMain sapConfigMain) {
|
||||
Map<String, Object> workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable);
|
||||
Map<String, String> workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable);
|
||||
Assert.notNull(workflowMainData, "query workflow data fail, query request id is {}", requestId);
|
||||
Map<String, Object> workflowData = new HashMap<>();
|
||||
workflowData.put("main", workflowMainData);
|
||||
|
@ -248,7 +248,7 @@ public class SapConfigService {
|
|||
*/
|
||||
private SapVoucher parseByDetailTable(String requestId,
|
||||
String billTable, SapConfigMain sapConfigMain) {
|
||||
Map<String, Object> workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable);
|
||||
Map<String, String> workflowMainData = mapper.selectWorkflowDataByRequestId(requestId, billTable);
|
||||
Assert.notNull(workflowMainData, "query workflow data fail, query request id is {}", requestId);
|
||||
List<Map<String, Object>> workflowDetailData = mapper.selectWorkflowDataByMainId(Util.null2String(workflowMainData.get("id")),
|
||||
sapConfigMain.getDocumentDetailTableName());
|
||||
|
|
|
@ -2,7 +2,6 @@ package weaver.youhong.ai.haripijiu.action.sapdocking.service;
|
|||
|
||||
import aiyh.utils.Util;
|
||||
import aiyh.utils.excention.CustomerException;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import weaver.general.GCONST;
|
||||
|
@ -74,16 +73,14 @@ public class VoucherPayableService {
|
|||
public String sendSapVoucher(String onlyMark, String requestId, String billTable) {
|
||||
|
||||
SapVoucher voucherData = configService.getVoucherData(onlyMark, requestId, billTable);
|
||||
logger.info("查询的凭证配置数据: " + JSON.toJSONString(voucherData));
|
||||
/* ******************* 整理数据 ******************* */
|
||||
StringBuilder voucherHeadBuilder = new StringBuilder();
|
||||
List<VoucherItem> voucherHead = voucherData.getVoucherHead();
|
||||
for (VoucherItem voucherItem : voucherHead) {
|
||||
voucherHeadBuilder.append(voucherItem.getValue())
|
||||
voucherHeadBuilder.append(Util.null2String(voucherItem.getValue()).replace(" ", " "))
|
||||
.append("\t");
|
||||
}
|
||||
String voucherHeadStr = voucherHeadBuilder.substring(0, voucherHeadBuilder.lastIndexOf("\t")) + "\r\n";
|
||||
logger.info("凭证头:" + voucherHeadStr);
|
||||
StringBuilder voucherDetailBuilder = new StringBuilder();
|
||||
List<List<VoucherItem>> voucherDetail = voucherData.getVoucherDetail();
|
||||
for (List<VoucherItem> voucherItems : voucherDetail) {
|
||||
|
@ -91,7 +88,6 @@ public class VoucherPayableService {
|
|||
.append("\r\n");
|
||||
}
|
||||
String voucherDetailStr = voucherDetailBuilder.substring(0, voucherDetailBuilder.lastIndexOf("\r\n"));
|
||||
logger.info("凭证数据:" + voucherHeadStr);
|
||||
String filePath = getFilePath();
|
||||
try {
|
||||
// BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
|
||||
|
@ -115,7 +111,6 @@ public class VoucherPayableService {
|
|||
|
||||
public String sendReceiptVoucher(String onlyMark, String requestId, String billTable) {
|
||||
SapVoucher voucherData = configService.getReceiptPaymentData(onlyMark, requestId, billTable);
|
||||
logger.info("查询的凭证配置数据: " + JSON.toJSONString(voucherData));
|
||||
/* ******************* 整理数据 ******************* */
|
||||
StringBuilder voucherHeadBuilder = new StringBuilder();
|
||||
List<List<VoucherItem>> voucherDetail = voucherData.getVoucherDetail();
|
||||
|
@ -143,7 +138,6 @@ public class VoucherPayableService {
|
|||
}
|
||||
}
|
||||
String voucherHaredStr = voucherHeadBuilder.toString();
|
||||
logger.info("凭证数据:" + voucherHaredStr);
|
||||
String filePath = getFilePath();
|
||||
try {
|
||||
OutputStreamWriter out = new OutputStreamWriter(
|
||||
|
@ -166,27 +160,25 @@ public class VoucherPayableService {
|
|||
|
||||
public List<String> sendPaymentVoucher(String onlyMark, String requestId, String billTable) {
|
||||
SapVoucher voucherData = configService.getReceiptPaymentData(onlyMark, requestId, billTable);
|
||||
logger.info("配置数据:" + JSON.toJSONString(voucherData));
|
||||
List<String> filePathList = new ArrayList<>();
|
||||
/* ******************* 整理数据 ******************* */
|
||||
StringBuilder voucherHeadBuilder = new StringBuilder();
|
||||
List<List<VoucherItem>> voucherDetail = voucherData.getVoucherDetail();
|
||||
for (List<VoucherItem> voucherItems : voucherDetail) {
|
||||
for (VoucherItem voucherItem : voucherItems) {
|
||||
voucherHeadBuilder.append(voucherItem.getName())
|
||||
voucherHeadBuilder.append(Util.null2String(voucherItem.getName()).replace(" ", " "))
|
||||
.append("\t");
|
||||
}
|
||||
voucherHeadBuilder = new StringBuilder(voucherHeadBuilder
|
||||
.substring(0, voucherHeadBuilder.lastIndexOf("\t")) + "\r\n");
|
||||
|
||||
for (VoucherItem voucherItem : voucherItems) {
|
||||
voucherHeadBuilder.append(voucherItem.getValue())
|
||||
voucherHeadBuilder.append(Util.null2String(voucherItem.getValue()).replace(" ", " "))
|
||||
.append("\t");
|
||||
}
|
||||
voucherHeadBuilder = new StringBuilder(voucherHeadBuilder
|
||||
.substring(0, voucherHeadBuilder.lastIndexOf("\t")) + "");
|
||||
String voucherHeadStr = voucherHeadBuilder.toString();
|
||||
logger.info("凭证数据:" + voucherHeadStr);
|
||||
String filePath = getFilePath();
|
||||
try {
|
||||
// BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
|
||||
|
@ -220,9 +212,9 @@ public class VoucherPayableService {
|
|||
private String appendVoucherItems(List<VoucherItem> voucherItems) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (VoucherItem voucherItem : voucherItems) {
|
||||
result.append(voucherItem.getValue())
|
||||
result.append(Util.null2String(voucherItem.getValue()).replace(" ", " "))
|
||||
.append("\t");
|
||||
}
|
||||
return result.toString();
|
||||
return result.substring(0, result.lastIndexOf("\t"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package weaver.youhong.ai.intellectualproperty.cusgetvalue;
|
||||
|
||||
import aiyh.utils.excention.CustomerException;
|
||||
import weaver.xiao.commons.config.interfacies.CusInterfaceGetValue;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1>关键字urlecode编码</h1>
|
||||
*
|
||||
* <p>create: 2023/4/19 15:33</p>
|
||||
*
|
||||
* @author youHong.ai
|
||||
*/
|
||||
public class ContentUrlEncodeGetValue implements CusInterfaceGetValue {
|
||||
@Override
|
||||
public Object execute(Map<String, Object> mainMap,
|
||||
Map<String, Object> detailMap,
|
||||
String currentValue,
|
||||
Map<String, String> pathParam) {
|
||||
try {
|
||||
String content = pathParam.get("content");
|
||||
return URLEncoder.encode(content, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new CustomerException("关键字内容url编码错误!", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package weaver.youhong.ai.intellectualproperty.cusgetvalue;
|
|||
import aiyh.utils.Util;
|
||||
import aiyh.utils.entity.DocImageInfo;
|
||||
import aiyh.utils.excention.CustomerException;
|
||||
import aiyh.utils.tool.cn.hutool.core.util.StrUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.file.ImageFileManager;
|
||||
import weaver.xiao.commons.config.interfacies.CusInterfaceGetValue;
|
||||
|
@ -26,6 +27,12 @@ public class FileToBase64CusGetValue implements CusInterfaceGetValue {
|
|||
public Object execute(Map<String, Object> mainMap, Map<String, Object> detailMap,
|
||||
String currentValue, Map<String, String> pathParam) {
|
||||
try {
|
||||
if (StrUtil.isBlank(currentValue)) {
|
||||
throw new CustomerException("签章文件必填,不能为空!");
|
||||
}
|
||||
if (currentValue.split(",").length > 1) {
|
||||
throw new CustomerException("签章文件有且只能有一个文件!");
|
||||
}
|
||||
DocImageInfo docImageInfo = Util.selectImageInfoByDocId(currentValue);
|
||||
InputStream inputStream = ImageFileManager.getInputStreamById(docImageInfo.getImageFileId());
|
||||
byte[] src = new byte[inputStream.available()];
|
||||
|
|
|
@ -4,9 +4,17 @@ import aiyh.utils.GenerateFileUtil;
|
|||
import aiyh.utils.Util;
|
||||
import basetest.BaseTest;
|
||||
import org.junit.Test;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.youhong.ai.haripijiu.action.sapdocking.ReceiptAndPaymentAction;
|
||||
import weaver.youhong.ai.haripijiu.action.sapdocking.VoucherPayableAction;
|
||||
import weaver.youhong.ai.haripijiu.action.sapdocking.VoucherPayableNewAction;
|
||||
import weaver.youhong.ai.haripijiu.action.sapdocking.config.mapper.SapConfigMapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <h1>测试</h1>
|
||||
|
@ -29,4 +37,119 @@ public class TestHaRiPiJiu extends BaseTest {
|
|||
|
||||
Util.actionTest(VoucherPayableNewAction.class, 405407);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String st = "506845\t德欧仕咖啡商贸(上海)有限公司\t2023-04-18\t2023-04-30\tRMB\tSH\tDG-FK-20230414-026\tOA对公付款德欧仕咖啡商贸(上海)有限公司4月咖啡机租赁费 德欧仕DG-FK-20230414-026\r\n" +
|
||||
"咖啡机4月租赁费\t7512001516\tJ0\t1000.0\tHumRes\tASHSDY\tCN-SH\tKEG\tJapanese Restaurant\t\t\r\n";
|
||||
String tes = "506916\t上海外服(集团)有限公司\t2023-04-18\t2023-04-18\tRMB\tSH\tDG-FK-20230418-050\tOA对公付款上海外服(集团)有限公司2023年4月社保 上海外服(集团)有限公司 DG-FK-20230418-050\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t2569.38\tHumRes\tASHSDY\tCN-SH\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t18177.8\tFin\tASHSDY\tCN-SH\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t4490.16\tSupp\tASHSDY\tCN-SH\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t3103.55\tSale\tASHSDY\tCN-SO\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t4866.33\tMark\tASHSDY\tCN-SH\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t13462.87\tSale\tASHSDY\tCN-NW\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t27892.48\tSale\tASHSDY\tCN-EC\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t1196.55\tSale\tASHSDY\tCN-CAL\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t3493.5\tSale\tASHSDY\tCN-ECOMM\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t3045000900\tJ0\t1471312.8\tHumRes\tASHSDY\tCN-SH\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t900306\tJ0\t160273.88\tSale\tASHSDY\tCN-DL\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t900304\tJ0\t25539.43\tSale\tASHSDY\tCN-SZ\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t900303\tJ0\t161387.66\tSale\tASHSDY\tCN-GZ\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t900305\tJ0\t54713.68\tSale\tASHSDY\tCN-CD\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t900302\tJ0\t26830.94\tSale\tASHSDY\tCN-BJ\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t2060001270\tJ0\t1540.54\tHumRes\tASHSDY\tCN-SH\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t2060001160\tJ0\t802.32\tHumRes\tASHSDY\tCN-SH\tKEG\tJapanese Restaurant\t\t\n";
|
||||
String niuma = "506916\t上海外服(集团)有限公司\t2023-04-18\t2023-04-18\tRMB\tSH\tDG-FK-20230418-050\tOA对公付款上海外服(集团)有限公司2023年4月社保 上海外服(集团)有限公司 DG-FK-20230418-050\r\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t2569.38\tHumRes\tASHSDY\tCN-SH\tKEG\tJapanese Restaurant\t\r\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t18177.8\tFin\tASHSDY\tCN-SH\tKEG\tJapanese Restaurant\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t4490.16\tSupp\tASHSDY\tCN-SH\tKEG\tJapanese Restaurant\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t3103.55\tSale\tASHSDY\tCN-SO\tKEG\tJapanese Restaurant\t\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t4866.33\tMark\tASHSDY\tCN-SH\tKEG\tJapanese Restaurant\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t13462.87\tSale\tASHSDY\tCN-NW\tKEG\tJapanese Restaurant\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t27892.48\tSale\tASHSDY\tCN-EC\tKEG\tJapanese Restaurant\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t1196.55\tSale\tASHSDY\tCN-CAL\tKEG\tJapanese Restaurant\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t7512001100\tJ0\t3493.5\tSale\tASHSDY\tCN-ECOMM\tKEG\tJapanese Restaurant\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t3045000900\tJ0\t1471312.8\tHumRes\tASHSDY\tCN-SH\tKEG\tJapanese Restaurant\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t900306\tJ0\t160273.88\tSale\tASHSDY\tCN-DL\tKEG\tJapanese Restaurant\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t900304\tJ0\t25539.43\tSale\tASHSDY\tCN-SZ\tKEG\tJapanese Restaurant\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t900303\tJ0\t161387.66\tSale\tASHSDY\tCN-GZ\tKEG\tJapanese Restaurant\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t900305\tJ0\t54713.68\tSale\tASHSDY\tCN-CD\tKEG\tJapanese Restaurant\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t900302\tJ0\t26830.94\tSale\tASHSDY\tCN-BJ\tKEG\tJapanese Restaurant\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t2060001270\tJ0\t1540.54\tHumRes\tASHSDY\tCN-SH\tKEG\tJapanese Restaurant\t\n" +
|
||||
"4.20网银 支付4月管理费 上海外服\t2060001160\tJ0\t802.32\tHumRes\tASHSDY\tCN-SH\tKEG\tJapanese Restaurant\t";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tes").append("\t").append("ateat").append("\t").append("asdfasdg").append("\r\n");
|
||||
sb.append("asldjf").append("\t").append("adsfasdf").append("\t").append("数据拉升").append("\r\n");
|
||||
String substring = sb.substring(0, sb.lastIndexOf("\r\n"));
|
||||
System.out.println(substring);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testsd() {
|
||||
|
||||
List<String> list = Arrays.asList("10", "32", "6", "2.5", "2", "0", "3");
|
||||
List<String> result = sortKey(list);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tesetmje() {
|
||||
SapConfigMapper mapper = Util.getMapper(SapConfigMapper.class);
|
||||
System.out.println(mapper.selectWorkflowDataByRequestId("419422", "formtable_main_20"));
|
||||
RecordSet rs = new RecordSet();
|
||||
rs.executeQuery("SELECT *\n" +
|
||||
"FROM formtable_main_20\n" +
|
||||
"WHERE requestid = ?", "419422");
|
||||
if (rs.next()) {
|
||||
String jecs = rs.getString("jecs");
|
||||
System.out.println(jecs);
|
||||
System.out.println(Double.parseDouble(jecs));
|
||||
System.out.println(Float.parseFloat(jecs));
|
||||
System.out.println(new Double(Double.parseDouble(jecs)).floatValue());
|
||||
}
|
||||
}
|
||||
|
||||
class Entry {
|
||||
private Integer index;
|
||||
private String value;
|
||||
|
||||
public Integer getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(Integer index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public Double getValue() {
|
||||
return Double.parseDouble(value);
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> sortKey(List<String> list) {
|
||||
List<Entry> entryList = new ArrayList<>();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Entry entry = new Entry();
|
||||
entry.setIndex(i);
|
||||
entry.setValue(list.get(i));
|
||||
entryList.add(entry);
|
||||
}
|
||||
List<Entry> collect = entryList.stream()
|
||||
.sorted(
|
||||
Comparator.comparing(Entry::getValue)
|
||||
).collect(Collectors.toList());
|
||||
List<String> result = new ArrayList<>();
|
||||
for (Entry entry : collect) {
|
||||
result.add(list.get(entry.getIndex()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package youhong.ai.utiltest;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* <h1>表内容</h1>
|
||||
*
|
||||
* <p>create: 2023/4/19 10:48</p>
|
||||
*
|
||||
* @author youHong.ai
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class ExcelBody extends ExcelCell{
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package youhong.ai.utiltest;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* <h1>单元格内容</h1>
|
||||
*
|
||||
* <p>create: 2023/4/19 10:49</p>
|
||||
*
|
||||
* @author youHong.ai
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class ExcelCell {
|
||||
/** 表头名称 */
|
||||
private Object value;
|
||||
|
||||
/** 单元格格式 */
|
||||
private IExcelCellStyleCreator cellStyle;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package youhong.ai.utiltest;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* <h1>excel表头</h1>
|
||||
*
|
||||
* <p>create: 2023/4/19 10:46</p>
|
||||
*
|
||||
* @author youHong.ai
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class ExcelHead extends ExcelCell {
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
package youhong.ai.utiltest;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import aiyh.utils.tool.cn.hutool.core.collection.CollectionUtil;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.xssf.streaming.SXSSFCell;
|
||||
import org.apache.poi.xssf.streaming.SXSSFRow;
|
||||
import org.apache.poi.xssf.streaming.SXSSFSheet;
|
||||
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <h1>excel导出</h1>
|
||||
*
|
||||
* <p>create: 2023/4/19 10:39</p>
|
||||
*
|
||||
* @author youHong.ai
|
||||
*/
|
||||
public class ExcelPort {
|
||||
|
||||
public static String export(String sheetName, List<ExcelRow> dataList,
|
||||
IExcelCellStyleCreator headStyle,
|
||||
IExcelCellStyleCreator bodyStyle) {
|
||||
SXSSFWorkbook workbook = new SXSSFWorkbook();
|
||||
createSheet(sheetName, workbook, dataList, headStyle, bodyStyle);
|
||||
String excel = Util.getTempFilePath("excel", ".xlsx");
|
||||
try {
|
||||
workbook.write(Files.newOutputStream(Paths.get(excel)));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return excel;
|
||||
}
|
||||
|
||||
|
||||
public static String export(List<ExcelSheet> sheetList,
|
||||
IExcelCellStyleCreator headStyle,
|
||||
IExcelCellStyleCreator bodyStyle) {
|
||||
SXSSFWorkbook workbook = new SXSSFWorkbook();
|
||||
for (ExcelSheet excelSheet : sheetList) {
|
||||
createSheet(excelSheet.getSheetName(), workbook, excelSheet.getDataList(), headStyle, bodyStyle);
|
||||
}
|
||||
String excel = Util.getTempFilePath("excel", ".xlsx");
|
||||
try {
|
||||
workbook.write(Files.newOutputStream(Paths.get(excel)));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return excel;
|
||||
}
|
||||
|
||||
|
||||
private static void createSheet(String sheetName, SXSSFWorkbook wb, List<ExcelRow> dataList,
|
||||
IExcelCellStyleCreator headStyle,
|
||||
IExcelCellStyleCreator bodyStyle) {
|
||||
SXSSFSheet sheet = wb.createSheet(sheetName);
|
||||
createDate(sheet, wb, dataList, headStyle, bodyStyle);
|
||||
}
|
||||
|
||||
private static void createDate(SXSSFSheet sheet, SXSSFWorkbook wb, List<ExcelRow> dataList,
|
||||
IExcelCellStyleCreator headStyle,
|
||||
IExcelCellStyleCreator bodyStyle) {
|
||||
if (CollectionUtil.isEmpty(dataList) || dataList.size() < 1) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < dataList.size(); i++) {
|
||||
ExcelRow excelRow = dataList.get(i);
|
||||
SXSSFRow row = sheet.createRow(i);
|
||||
if (!Objects.isNull(excelRow.getRowHeight()) && excelRow.getRowHeight() > 0) {
|
||||
row.setHeightInPoints(excelRow.getRowHeight());
|
||||
}
|
||||
List<ExcelCell> rowData = excelRow.getDataList();
|
||||
for (int j = 0; j < rowData.size(); j++) {
|
||||
ExcelCell cellValue = rowData.get(j);
|
||||
SXSSFCell cell = row.createCell(j);
|
||||
CellStyle style = null;
|
||||
XSSFRichTextString text = new XSSFRichTextString(Util.null2String(cellValue.getValue()));
|
||||
cell.setCellValue(text);
|
||||
// sheet.trackAllColumnsForAutoSizing();
|
||||
// sheet.autoSizeColumn(i);
|
||||
if (i == 0) {
|
||||
if (Objects.nonNull(headStyle)) {
|
||||
style = headStyle.createStyle(wb, i, j, row, cell, sheet);
|
||||
}
|
||||
} else {
|
||||
if (Objects.nonNull(bodyStyle)) {
|
||||
style = bodyStyle.createStyle(wb, i, j, row, cell, sheet);
|
||||
}
|
||||
}
|
||||
if (Objects.nonNull(style)) {
|
||||
cell.setCellStyle(style);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package youhong.ai.utiltest;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <h1>表行</h1>
|
||||
*
|
||||
* <p>create: 2023/4/19 10:56</p>
|
||||
*
|
||||
* @author youHong.ai
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class ExcelRow {
|
||||
|
||||
private Float rowHeight;
|
||||
private List<ExcelCell> dataList;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package youhong.ai.utiltest;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <h1>excel表</h1>
|
||||
*
|
||||
* <p>create: 2023/4/19 11:14</p>
|
||||
*
|
||||
* @author youHong.ai
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class ExcelSheet {
|
||||
private String sheetName;
|
||||
private List<ExcelRow> dataList;
|
||||
}
|
|
@ -4,6 +4,12 @@ import aiyh.utils.GenerateFileUtil;
|
|||
import aiyh.utils.Util;
|
||||
import aiyh.utils.tool.cn.hutool.core.collection.CollectionUtil;
|
||||
import basetest.BaseTest;
|
||||
import org.apache.poi.hssf.util.HSSFColor;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.streaming.SXSSFCell;
|
||||
import org.apache.poi.xssf.streaming.SXSSFRow;
|
||||
import org.apache.poi.xssf.streaming.SXSSFSheet;
|
||||
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
||||
import org.junit.Test;
|
||||
import weaver.youhong.ai.haripijiu.action.sapdocking.VoucherPayableNewAction;
|
||||
|
||||
|
@ -13,6 +19,8 @@ import java.lang.reflect.Type;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public class GenericTest extends BaseTest {
|
||||
|
@ -90,4 +98,147 @@ public class GenericTest extends BaseTest {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGa() {
|
||||
List<ExcelRow> list = new ArrayList<>();
|
||||
for (int i = 0; i < 11; i++) {
|
||||
ExcelRow excelRow = new ExcelRow();
|
||||
if (i == 0) {
|
||||
excelRow.setRowHeight(21F);
|
||||
}
|
||||
List<ExcelCell> rowList = new ArrayList<>();
|
||||
for (int j = 0; j < 5; j++) {
|
||||
ExcelCell excelCell = new ExcelCell();
|
||||
if (j == 4) {
|
||||
if (i == 0) {
|
||||
excelCell.setValue("单元格" + i + "-" + j);
|
||||
} else if (i == 1) {
|
||||
excelCell.setValue("单元格式文件的开源库。用它来进行excel文件的导出是很趁手的格" + i + "-" + j);
|
||||
} else if (i == 2) {
|
||||
excelCell.setValue("单格式文件的开源库。格式文件的开源库。用它来进行excel文件的导出是很趁手的用它来进行excel文件的导出是很趁手的元格" + i + "-" + j);
|
||||
} else if (i == 3) {
|
||||
excelCell.setValue("单元是apache旗下用于读写Microsoft Office 二格" + i + "-" + j);
|
||||
} else if (i == 10) {
|
||||
excelCell.setValue("是apache旗下用于读写Microsoft Office 二单asdfalsdfj不知道https://ecology.yeyaguitu.cn/spa/custom/static/index.html#/main/cs/app/0313c91108504ce0843ad3648fb1fd33_click-img?_key=q9f1jj元格" + i + "-" + j);
|
||||
} else {
|
||||
excelCell.setValue("单元格" + i + "-" + j);
|
||||
}
|
||||
} else {
|
||||
excelCell.setValue("单元格" + i + "-" + j);
|
||||
}
|
||||
rowList.add(excelCell);
|
||||
}
|
||||
excelRow.setDataList(rowList);
|
||||
list.add(excelRow);
|
||||
}
|
||||
System.out.println(ExcelPort.export("test", list,
|
||||
GenericTest::setHeaderStyle
|
||||
, GenericTest::setBodyStyle));
|
||||
}
|
||||
|
||||
private static CellStyle setHeaderStyle(SXSSFWorkbook workbook,
|
||||
Integer rowIndex,
|
||||
Integer colIndex,
|
||||
SXSSFRow row,
|
||||
SXSSFCell cell,
|
||||
SXSSFSheet sheet) {
|
||||
// 设置表格单元格格式
|
||||
CellStyle style = workbook.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
style.setBorderRight(BorderStyle.THIN);
|
||||
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
|
||||
style.setBorderLeft(BorderStyle.THIN);
|
||||
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
|
||||
style.setBorderTop(BorderStyle.THIN);
|
||||
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
||||
style.setBorderBottom(BorderStyle.THIN);
|
||||
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
||||
style.setWrapText(true);
|
||||
// 设置字体格式
|
||||
Font font = workbook.createFont();
|
||||
font.setFontName("微软雅黑");
|
||||
font.setFontHeightInPoints((short) 14);
|
||||
font.setBold(true);
|
||||
font.setColor(HSSFColor.HSSFColorPredefined.WHITE.getIndex());
|
||||
style.setFont(font);
|
||||
int columnWidth = sheet.getColumnWidth(colIndex);
|
||||
String value = cell.getStringCellValue();
|
||||
/** 计算字符串中中文字符的数量 */
|
||||
int count = chineseCharCountOf(value);
|
||||
/**在该列字符长度的基础上加上汉字个数计算列宽 */
|
||||
int length = (value.length() - count) * 256 + (count + 1) * 512;
|
||||
length = length * (14 / font.getFontHeightInPoints());
|
||||
if (length >= columnWidth && length < 256 * 256) {
|
||||
sheet.setColumnWidth(colIndex, length);
|
||||
}
|
||||
if (colIndex == 1 || colIndex == 2 || colIndex == 3) {
|
||||
style.setFillForegroundColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
|
||||
} else {
|
||||
style.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
|
||||
}
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
return style;
|
||||
}
|
||||
|
||||
private static CellStyle setBodyStyle(SXSSFWorkbook workbook,
|
||||
Integer rowIndex,
|
||||
Integer colIndex,
|
||||
SXSSFRow row,
|
||||
SXSSFCell cell,
|
||||
SXSSFSheet sheet) {
|
||||
// 设置表格单元格格式
|
||||
CellStyle style = workbook.createCellStyle();
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setBorderRight(BorderStyle.THIN);
|
||||
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
|
||||
style.setBorderLeft(BorderStyle.THIN);
|
||||
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
|
||||
style.setBorderTop(BorderStyle.THIN);
|
||||
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
||||
style.setBorderBottom(BorderStyle.THIN);
|
||||
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
||||
style.setWrapText(true);
|
||||
// 设置字体格式
|
||||
Font font = workbook.createFont();
|
||||
font.setFontName("微软雅黑");
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
style.setFont(font);
|
||||
int columnWidth = sheet.getColumnWidth(colIndex);
|
||||
String value = cell.getStringCellValue();
|
||||
/** 计算字符串中中文字符的数量 */
|
||||
int count = chineseCharCountOf(value);
|
||||
/**在该列字符长度的基础上加上汉字个数计算列宽 */
|
||||
int length = (value.length() - count) * 256 + (count + 1) * 512;
|
||||
length = length * 11 / font.getFontHeightInPoints();
|
||||
if (length >= columnWidth && length < 256 * 256) {
|
||||
sheet.setColumnWidth(colIndex, length);
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算字符串中中文字符的数量
|
||||
* 参见 <a hrft="https://www.cnblogs.com/straybirds/p/6392306.html">《汉字unicode编码范围》</a>
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
private static int chineseCharCountOf(String input) {
|
||||
int count = 0;// 汉字数量
|
||||
if (null != input) {
|
||||
String regEx = "[\\u4e00-\\u9fa5]";
|
||||
Pattern p = Pattern.compile(regEx);
|
||||
Matcher m = p.matcher(input);
|
||||
int len = m.groupCount();
|
||||
// 获取汉字个数
|
||||
while (m.find()) {
|
||||
for (int i = 0; i <= len; i++) {
|
||||
count = count + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package youhong.ai.utiltest;
|
||||
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.xssf.streaming.SXSSFCell;
|
||||
import org.apache.poi.xssf.streaming.SXSSFRow;
|
||||
import org.apache.poi.xssf.streaming.SXSSFSheet;
|
||||
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
||||
|
||||
/**
|
||||
* <h1>创建样式</h1>
|
||||
*
|
||||
* <p>create: 2023/4/19 13:53</p>
|
||||
*
|
||||
* @author youHong.ai
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface IExcelCellStyleCreator {
|
||||
|
||||
CellStyle createStyle(SXSSFWorkbook workbook,
|
||||
Integer rowIndex,
|
||||
Integer colIndex,
|
||||
SXSSFRow row,
|
||||
SXSSFCell cell,
|
||||
SXSSFSheet sheet);
|
||||
}
|
Loading…
Reference in New Issue