增加导入附件的查看记录

This commit is contained in:
wuweihua
2026-10-15 15:02:23 +08:00
parent c704021f2f
commit 41ce05a08a
14 changed files with 585 additions and 13 deletions
@@ -42,4 +42,32 @@ public final class TabOrderSyncEsLog
String st = StringUtils.isEmpty(status) ? EsBizLogSupport.STATUS_SUCCESS : status;
store.save(EsLogType.ORDER_SOURCE_SYNC, bizId, reqJson, respJson, st, errorMessage);
}
/** Persist one failed sync order so it appears in order-source operation log. */
public static void saveOneFail(IBillSearchStore store, Object row, Object response, String errorMessage)
{
String orderId = null;
if (row instanceof com.bms.price.domain.vo.TabOrderMonitorVo)
{
orderId = ((com.bms.price.domain.vo.TabOrderMonitorVo) row).getOrderId();
}
else if (row instanceof Map)
{
Object v = ((Map<?, ?>) row).get("orderId");
if (v != null)
{
orderId = String.valueOf(v);
}
}
String bizId;
if (StringUtils.isEmpty(orderId))
{
bizId = "ONE_FAIL_" + System.currentTimeMillis();
}
else
{
bizId = "ONE_" + orderId.trim();
}
save(store, bizId, "ONE_FAIL", row, response, EsBizLogSupport.STATUS_FAIL, errorMessage);
}
}
@@ -84,6 +84,8 @@ public class TabOrderSyncAsyncRunner
AtomicInteger processed = new AtomicInteger(0);
AtomicInteger ok = new AtomicInteger(0);
AtomicInteger fail = new AtomicInteger(0);
List<Map<String, Object>> failDetails = java.util.Collections.synchronizedList(
new ArrayList<Map<String, Object>>());
int pageNum = 1;
while (true)
{
@@ -102,7 +104,7 @@ public class TabOrderSyncAsyncRunner
{
final TabOrderMonitorVo one = row;
jobs.add(() -> {
boolean success = syncOne(one);
boolean success = syncOne(one, failDetails);
if (success)
{
ok.incrementAndGet();
@@ -137,7 +139,10 @@ public class TabOrderSyncAsyncRunner
resp.put("ok", Integer.valueOf(ok.get()));
resp.put("fail", Integer.valueOf(fail.get()));
resp.put("threads", Integer.valueOf(threads));
TabOrderSyncEsLog.save(billSearchStore, asyncTaskId, "FILTER_DONE", query, resp, "SUCCESS", null);
resp.put("failDetails", truncateFailDetails(failDetails));
String doneStatus = fail.get() > 0 ? "FAIL" : "SUCCESS";
String doneErr = fail.get() > 0 ? ("fail=" + fail.get() + ", ok=" + ok.get()) : null;
TabOrderSyncEsLog.save(billSearchStore, asyncTaskId, "FILTER_DONE", query, resp, doneStatus, doneErr);
log.info("orderSource sync done asyncTaskId={} total={} ok={} fail={} threads={}",
asyncTaskId, total, ok.get(), fail.get(), threads);
}
@@ -253,12 +258,18 @@ public class TabOrderSyncAsyncRunner
return data;
}
private boolean syncOne(TabOrderMonitorVo row)
private boolean syncOne(TabOrderMonitorVo row, List<Map<String, Object>> failDetails)
{
try
{
PrcBillingTask task = billingTaskService.submitAndProcess(toSubmit(row));
return task != null && BillTaskSuccessStatus.SUCCESS.getCode().equals(task.getSuccessStatus());
boolean success = task != null
&& BillTaskSuccessStatus.SUCCESS.getCode().equals(task.getSuccessStatus());
if (!success)
{
collectFailDetail(failDetails, row, task, null);
}
return success;
}
catch (RuntimeException e)
{
@@ -266,10 +277,62 @@ public class TabOrderSyncAsyncRunner
row == null ? null : row.getOrderId(),
row == null ? null : row.getTransferOrderId(),
e.getMessage());
collectFailDetail(failDetails, row, null, e.getMessage());
return false;
}
}
private static final int FAIL_DETAIL_MAX = 200;
private static void collectFailDetail(List<Map<String, Object>> failDetails, TabOrderMonitorVo row,
PrcBillingTask task, String exceptionMessage)
{
if (failDetails == null)
{
return;
}
Map<String, Object> item = new LinkedHashMap<String, Object>();
item.put("orderId", row == null ? null : row.getOrderId());
item.put("transferOrderId", row == null ? null : row.getTransferOrderId());
String err = exceptionMessage;
if (task != null)
{
item.put("successStatus", task.getSuccessStatus());
item.put("billType", task.getBillType());
item.put("taskId", task.getTaskId());
if (StringUtils.isEmpty(err))
{
err = task.getErrorMessage();
}
}
if (StringUtils.isEmpty(err))
{
err = "sync failed";
}
item.put("errorMessage", err);
synchronized (failDetails)
{
if (failDetails.size() >= FAIL_DETAIL_MAX)
{
return;
}
failDetails.add(item);
}
}
private static List<Map<String, Object>> truncateFailDetails(List<Map<String, Object>> failDetails)
{
if (failDetails == null || failDetails.isEmpty())
{
return java.util.Collections.emptyList();
}
if (failDetails.size() <= FAIL_DETAIL_MAX)
{
return new ArrayList<Map<String, Object>>(failDetails);
}
return new ArrayList<Map<String, Object>>(failDetails.subList(0, FAIL_DETAIL_MAX));
}
private static void invokeAllQuiet(ExecutorService pool, List<Callable<Boolean>> jobs) throws InterruptedException
{
List<Future<Boolean>> futures = pool.invokeAll(jobs);
@@ -0,0 +1,30 @@
package com.bms.system.domain;
import com.bms.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 公共业务附件 bms_biz_attachment
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class BmsBizAttachment extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 批量修改计费重导入 */
public static final String BIZ_CHARGE_WEIGHT_IMPORT = "CHARGE_WEIGHT_IMPORT";
private Long attachmentId;
/** 业务类型 */
private String bizType;
/** 业务关联ID */
private String bizId;
private String fileName;
private String filePath;
private Long fileSize;
private String contentType;
private String fileExtension;
private String delFlag;
}
@@ -0,0 +1,18 @@
package com.bms.system.mapper;
import java.util.List;
import com.bms.system.domain.BmsBizAttachment;
/** Common biz attachment mapper */
public interface BmsBizAttachmentMapper
{
BmsBizAttachment selectBmsBizAttachmentById(Long attachmentId);
List<BmsBizAttachment> selectBmsBizAttachmentList(BmsBizAttachment query);
int insertBmsBizAttachment(BmsBizAttachment row);
int updateBmsBizAttachment(BmsBizAttachment row);
int deleteBmsBizAttachmentByIds(Long[] attachmentIds);
}
@@ -0,0 +1,18 @@
package com.bms.system.service;
import java.util.List;
import com.bms.system.domain.BmsBizAttachment;
/** 公共业务附件 */
public interface IBmsBizAttachmentService
{
BmsBizAttachment selectBmsBizAttachmentById(Long attachmentId);
List<BmsBizAttachment> selectBmsBizAttachmentList(BmsBizAttachment query);
/**
* 落盘保存上传文件并写附件记录
*/
BmsBizAttachment saveUpload(String bizType, String bizId, byte[] bytes, String filename,
String operName, String remark) throws Exception;
}
@@ -0,0 +1,104 @@
package com.bms.system.service.impl;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bms.common.config.BmsConfig;
import com.bms.common.exception.ServiceException;
import com.bms.common.utils.DateUtils;
import com.bms.common.utils.StringUtils;
import com.bms.common.utils.file.FileUploadUtils;
import com.bms.common.utils.uuid.IdUtils;
import com.bms.system.domain.BmsBizAttachment;
import com.bms.system.mapper.BmsBizAttachmentMapper;
import com.bms.system.service.IBmsBizAttachmentService;
@Service
public class BmsBizAttachmentServiceImpl implements IBmsBizAttachmentService
{
private static final String SUB_DIR = "biz/attachment";
@Autowired
private BmsBizAttachmentMapper attachmentMapper;
@Override
public BmsBizAttachment selectBmsBizAttachmentById(Long attachmentId)
{
return attachmentMapper.selectBmsBizAttachmentById(attachmentId);
}
@Override
public List<BmsBizAttachment> selectBmsBizAttachmentList(BmsBizAttachment query)
{
List<BmsBizAttachment> list = attachmentMapper.selectBmsBizAttachmentList(query);
return list == null ? Collections.emptyList() : list;
}
@Override
public BmsBizAttachment saveUpload(String bizType, String bizId, byte[] bytes, String filename,
String operName, String remark) throws Exception
{
if (StringUtils.isEmpty(bizType))
{
throw new ServiceException("bizType required");
}
if (bytes == null || bytes.length == 0)
{
throw new ServiceException("file empty");
}
String originalName = StringUtils.isNotEmpty(filename) ? filename : "upload.bin";
String ext = FilenameUtils.getExtension(originalName);
if (StringUtils.isEmpty(ext))
{
ext = "bin";
}
ext = ext.toLowerCase(Locale.ROOT);
String uploadDir = BmsConfig.getUploadPath() + File.separator + SUB_DIR;
String pathName = DateUtils.datePath() + "/" + IdUtils.fastSimpleUUID() + "." + ext;
File dest = FileUploadUtils.getAbsoluteFile(uploadDir, pathName);
FileOutputStream fos = null;
try
{
fos = new FileOutputStream(dest);
fos.write(bytes);
}
finally
{
IOUtils.close(fos);
}
String storedPath = FileUploadUtils.getPathFileName(uploadDir, pathName);
BmsBizAttachment row = new BmsBizAttachment();
row.setBizType(bizType.trim());
row.setBizId(bizId);
row.setFileName(originalName);
row.setFilePath(storedPath);
row.setFileSize(Long.valueOf(bytes.length));
row.setContentType(resolveContentType(ext));
row.setFileExtension(ext);
row.setRemark(remark);
row.setCreateBy(operName);
attachmentMapper.insertBmsBizAttachment(row);
return row;
}
private static String resolveContentType(String ext)
{
if ("xls".equals(ext))
{
return "application/vnd.ms-excel";
}
if ("xlsx".equals(ext))
{
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
}
return "";
}
}
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.system.mapper.BmsBizAttachmentMapper">
<resultMap type="BmsBizAttachment" id="BmsBizAttachmentResult">
<id property="attachmentId" column="attachment_id" />
<result property="bizType" column="biz_type" />
<result property="bizId" column="biz_id" />
<result property="fileName" column="file_name" />
<result property="filePath" column="file_path" />
<result property="fileSize" column="file_size" />
<result property="contentType" column="content_type" />
<result property="fileExtension" column="file_extension" />
<result property="remark" column="remark" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="delFlag" column="del_flag" />
</resultMap>
<sql id="selectBmsBizAttachmentVo">
select attachment_id, biz_type, biz_id, file_name, file_path, file_size, content_type,
file_extension, remark, create_by, create_time, update_by, update_time, del_flag
from bms_biz_attachment
</sql>
<select id="selectBmsBizAttachmentById" parameterType="Long" resultMap="BmsBizAttachmentResult">
<include refid="selectBmsBizAttachmentVo"/>
where attachment_id = #{attachmentId} and del_flag = '0'
</select>
<select id="selectBmsBizAttachmentList" parameterType="BmsBizAttachment" resultMap="BmsBizAttachmentResult">
<include refid="selectBmsBizAttachmentVo"/>
<where>
del_flag = '0'
<if test="bizType != null and bizType != ''">
AND biz_type = #{bizType}
</if>
<if test="bizId != null and bizId != ''">
AND biz_id = #{bizId}
</if>
<if test="fileName != null and fileName != ''">
AND file_name like concat('%', #{fileName}, '%')
</if>
<if test="createBy != null and createBy != ''">
AND create_by like concat('%', #{createBy}, '%')
</if>
<if test="params != null and params.beginTime != null and params.beginTime != ''">
AND create_time &gt;= #{params.beginTime}
</if>
<if test="params != null and params.endTime != null and params.endTime != ''">
AND create_time &lt;= #{params.endTime}
</if>
</where>
order by attachment_id desc
</select>
<insert id="insertBmsBizAttachment" parameterType="BmsBizAttachment" useGeneratedKeys="true" keyProperty="attachmentId">
insert into bms_biz_attachment (
<if test="bizType != null and bizType != ''">biz_type,</if>
<if test="bizId != null">biz_id,</if>
<if test="fileName != null and fileName != ''">file_name,</if>
<if test="filePath != null and filePath != ''">file_path,</if>
<if test="fileSize != null">file_size,</if>
<if test="contentType != null">content_type,</if>
<if test="fileExtension != null">file_extension,</if>
<if test="remark != null">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time,
del_flag
) values (
<if test="bizType != null and bizType != ''">#{bizType},</if>
<if test="bizId != null">#{bizId},</if>
<if test="fileName != null and fileName != ''">#{fileName},</if>
<if test="filePath != null and filePath != ''">#{filePath},</if>
<if test="fileSize != null">#{fileSize},</if>
<if test="contentType != null">#{contentType},</if>
<if test="fileExtension != null">#{fileExtension},</if>
<if test="remark != null">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate(),
'0'
)
</insert>
<update id="updateBmsBizAttachment" parameterType="BmsBizAttachment">
update bms_biz_attachment
<set>
<if test="bizId != null">biz_id = #{bizId},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
where attachment_id = #{attachmentId}
</update>
<update id="deleteBmsBizAttachmentByIds" parameterType="Long">
update bms_biz_attachment set del_flag = '2' where attachment_id in
<foreach collection="array" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>
</mapper>