tao.mo

biz-customer、task-schedule | 修改 | 推送IMP001报文代码调整

mt
2024年12月18日17:39:06
Showing 39 changed files with 1001 additions and 832 deletions
......@@ -196,13 +196,13 @@ public class ConsignmentServiceImpl extends BaseService implements IConsignmentS
}
}
/**
* Todo 初始化插入预清关文件推送任务日志,szl添加
* Todo 初始化插入预清关文件推送邮件任务日志,szl添加
*/
/**
* 初始化插入预清关文件邮件推送日志,mt添加
* 初始化插入预清关文件推送日志,mt添加
*/
PushOb pushOb = pushObUtil.initPushOb(consignment,user);
PushOb pushOb = pushObUtil.initPushOb(consignment,uploadRecord,user);
/**
* 初始化插入提醒发件人邮件日志
*/
......
......@@ -52,10 +52,10 @@ public class AttachmentUtil {
private void initAttachment(Attachment attachment,String bizType,User user) throws Exception{
DictionaryEntries attachmentBizTypeEntries = cacheSystem.getDicAttachmentBizType(AttachmentBizTypeEnum.getCodeByExt1(bizType));
attachment.setBizTypeCode(attachmentBizTypeEntries.getCode());
attachment.setBizTypeName(attachmentBizTypeEntries.getEnglishName());
attachment.setBizTypeName(attachmentBizTypeEntries.getDescription());
DictionaryEntries attachmentFileTypeEntries = cacheSystem.getDicAttachmentFileType(AttachmentFileTypeEnum.FILE.getCode());
attachment.setFileTypeCode(attachmentFileTypeEntries.getCode());
attachment.setFileTypeName(attachmentFileTypeEntries.getEnglishName());
attachment.setFileTypeName(attachmentFileTypeEntries.getDescription());
attachment.setStatus(StatusEnum.YES.getCode());
attachment.setCreateUserId(user.getId());
attachment.setCreateUserName(user.getUserName());
......
......@@ -7,6 +7,7 @@ import com.fedex.connect.common.dependencies.util.AssignmentFieldUtils;
import com.fedex.connect.common.model.bi.DictionaryEntries;
import com.fedex.connect.common.model.biz.Consignment;
import com.fedex.connect.common.model.biz.PushOb;
import com.fedex.connect.common.model.biz.UploadRecord;
import com.fedex.connect.common.model.sys.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -29,14 +30,15 @@ public class PushObUtil {
* @param
* @return com.fedex.connect.common.model.biz.PushOb
*/
public PushOb initPushOb(Consignment consignment, User user) throws Exception{
public PushOb initPushOb(Consignment consignment, UploadRecord uploadRecord, User user) throws Exception{
DictionaryEntries pushObStatus = cacheSystem.getDicPushObStatus(PushObStatusEnum.TO_BE_SENT.getCode());
PushOb pushOb = new PushOb();
pushOb.setConsignmentId(consignment.getId());
pushOb.setConsignmentCode(consignment.getConsignmentCode());
pushOb.setPushNum(DigitConstants.DIGIT_ZERO_LONG);
pushOb.setStatusCode(pushObStatus.getCode());
pushOb.setStatusName(pushObStatus.getEnglishName());
pushOb.setStatusName(pushObStatus.getDescription());
pushOb.setUploadRecordId(uploadRecord.getId());
pushOb.setCreateUserId(user.getId());
pushOb.setCreateUserName(user.getUserName());
pushOb.setModifyUserId(user.getId());
......
......@@ -38,4 +38,4 @@ export:
upload:
path:
attachment: /app/Oracle/Middleware/user_projects/domains/base_domain/iclearConnect/upload/attachment
\ No newline at end of file
attachment: /var/share/iclearConnect/upload/attachment
\ No newline at end of file
......
......@@ -19,6 +19,7 @@
<result column="MODIFY_TIME" jdbcType="TIMESTAMP" property="modifyTime" />
<result column="MODIFY_USER_ID" jdbcType="NUMERIC" property="modifyUserId" />
<result column="MODIFY_USER_NAME" jdbcType="VARCHAR" property="modifyUserName" />
<result column="UPLOAD_RECORD_ID" jdbcType="NUMERIC" property="uploadRecordId" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
......@@ -81,7 +82,7 @@
<sql id="Base_Column_List">
ID, CONSIGNMENT_CODE, CONSIGNMENT_ID, PUSH_TIME, STATUS_CODE, STATUS_NAME, PUSH_NUM,
FILE_PATH, FILE_BACK_PATH, FILE_NAME, REMARK, CREATE_TIME, CREATE_USER_ID, CREATE_USER_NAME,
MODIFY_TIME, MODIFY_USER_ID, MODIFY_USER_NAME
MODIFY_TIME, MODIFY_USER_ID, MODIFY_USER_NAME, UPLOAD_RECORD_ID
</sql>
<select id="selectByExample" parameterType="com.fedex.connect.common.model.biz.PushObExample" resultMap="BaseResultMap">
<include refid="OracleDialectPrefix" />
......@@ -125,13 +126,15 @@
PUSH_NUM, FILE_PATH, FILE_BACK_PATH,
FILE_NAME, REMARK, CREATE_TIME,
CREATE_USER_ID, CREATE_USER_NAME, MODIFY_TIME,
MODIFY_USER_ID, MODIFY_USER_NAME)
MODIFY_USER_ID, MODIFY_USER_NAME, UPLOAD_RECORD_ID
)
values (#{id,jdbcType=NUMERIC}, #{consignmentCode,jdbcType=VARCHAR}, #{consignmentId,jdbcType=NUMERIC},
#{pushTime,jdbcType=TIMESTAMP}, #{statusCode,jdbcType=VARCHAR}, #{statusName,jdbcType=VARCHAR},
#{pushNum,jdbcType=NUMERIC}, #{filePath,jdbcType=VARCHAR}, #{fileBackPath,jdbcType=VARCHAR},
#{fileName,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
#{createUserId,jdbcType=NUMERIC}, #{createUserName,jdbcType=VARCHAR}, #{modifyTime,jdbcType=TIMESTAMP},
#{modifyUserId,jdbcType=NUMERIC}, #{modifyUserName,jdbcType=VARCHAR})
#{modifyUserId,jdbcType=NUMERIC}, #{modifyUserName,jdbcType=VARCHAR}, #{uploadRecordId,jdbcType=NUMERIC}
)
</insert>
<insert id="insertSelective" parameterType="com.fedex.connect.common.model.biz.PushOb">
<selectKey keyProperty="id" order="BEFORE" resultType="java.lang.Long">
......@@ -188,6 +191,9 @@
<if test="modifyUserName != null">
MODIFY_USER_NAME,
</if>
<if test="uploadRecordId != null">
UPLOAD_RECORD_ID,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{id,jdbcType=NUMERIC},
......@@ -239,6 +245,9 @@
<if test="modifyUserName != null">
#{modifyUserName,jdbcType=VARCHAR},
</if>
<if test="uploadRecordId != null">
#{uploadRecordId,jdbcType=NUMERIC},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.fedex.connect.common.model.biz.PushObExample" resultType="java.lang.Long">
......@@ -301,6 +310,9 @@
<if test="record.modifyUserName != null">
MODIFY_USER_NAME = #{record.modifyUserName,jdbcType=VARCHAR},
</if>
<if test="record.uploadRecordId != null">
UPLOAD_RECORD_ID = #{record.uploadRecordId,jdbcType=NUMERIC},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
......@@ -324,7 +336,8 @@
CREATE_USER_NAME = #{record.createUserName,jdbcType=VARCHAR},
MODIFY_TIME = #{record.modifyTime,jdbcType=TIMESTAMP},
MODIFY_USER_ID = #{record.modifyUserId,jdbcType=NUMERIC},
MODIFY_USER_NAME = #{record.modifyUserName,jdbcType=VARCHAR}
MODIFY_USER_NAME = #{record.modifyUserName,jdbcType=VARCHAR},
UPLOAD_RECORD_ID = #{record.uploadRecordId,jdbcType=NUMERIC}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
......@@ -380,6 +393,9 @@
<if test="modifyUserName != null">
MODIFY_USER_NAME = #{modifyUserName,jdbcType=VARCHAR},
</if>
<if test="uploadRecordId != null">
UPLOAD_RECORD_ID = #{uploadRecordId,jdbcType=NUMERIC},
</if>
</set>
where ID = #{id,jdbcType=NUMERIC}
</update>
......@@ -400,7 +416,8 @@
CREATE_USER_NAME = #{createUserName,jdbcType=VARCHAR},
MODIFY_TIME = #{modifyTime,jdbcType=TIMESTAMP},
MODIFY_USER_ID = #{modifyUserId,jdbcType=NUMERIC},
MODIFY_USER_NAME = #{modifyUserName,jdbcType=VARCHAR}
MODIFY_USER_NAME = #{modifyUserName,jdbcType=VARCHAR},
UPLOAD_RECORD_ID = #{uploadRecordId,jdbcType=NUMERIC}
where ID = #{id,jdbcType=NUMERIC}
</update>
<sql id="OracleDialectPrefix">
......
......@@ -94,6 +94,11 @@ public class PushOb implements Serializable {
*/
private String modifyUserName;
/**
* 用户上传记录表ID
*/
private Long uploadRecordId;
private static final long serialVersionUID = 1L;
public Long getId() {
......@@ -232,6 +237,14 @@ public class PushOb implements Serializable {
this.modifyUserName = modifyUserName == null ? null : modifyUserName.trim();
}
public Long getUploadRecordId() {
return uploadRecordId;
}
public void setUploadRecordId(Long uploadRecordId) {
this.uploadRecordId = uploadRecordId;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
......@@ -255,6 +268,7 @@ public class PushOb implements Serializable {
sb.append(", modifyTime=").append(modifyTime);
sb.append(", modifyUserId=").append(modifyUserId);
sb.append(", modifyUserName=").append(modifyUserName);
sb.append(", uploadRecordId=").append(uploadRecordId);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
......
......@@ -35,12 +35,12 @@ public class PushObDetail implements Serializable {
private String statusName;
/**
* 推送文件类型字典CODE,关联数据字典表。指定字典目录CODE:PUSH_OB_FILE_TYPE
* 推送文件类型字典CODE,关联数据字典表。指定字典目录CODE:ATTACHMENT_BIZ_TYPE,取值Ext1 字段值
*/
private String fileTypeCode;
/**
* 推送文件类型名称(XXX、XXX
* 推送文件类型名称(AWB、INV、PKL、OTH
*/
private String fileType;
......
......@@ -1234,6 +1234,66 @@ public class PushObExample {
addCriterion("MODIFY_USER_NAME not between", value1, value2, "modifyUserName");
return (Criteria) this;
}
public Criteria andUploadRecordIdIsNull() {
addCriterion("UPLOAD_RECORD_ID is null");
return (Criteria) this;
}
public Criteria andUploadRecordIdIsNotNull() {
addCriterion("UPLOAD_RECORD_ID is not null");
return (Criteria) this;
}
public Criteria andUploadRecordIdEqualTo(Long value) {
addCriterion("UPLOAD_RECORD_ID =", value, "uploadRecordId");
return (Criteria) this;
}
public Criteria andUploadRecordIdNotEqualTo(Long value) {
addCriterion("UPLOAD_RECORD_ID <>", value, "uploadRecordId");
return (Criteria) this;
}
public Criteria andUploadRecordIdGreaterThan(Long value) {
addCriterion("UPLOAD_RECORD_ID >", value, "uploadRecordId");
return (Criteria) this;
}
public Criteria andUploadRecordIdGreaterThanOrEqualTo(Long value) {
addCriterion("UPLOAD_RECORD_ID >=", value, "uploadRecordId");
return (Criteria) this;
}
public Criteria andUploadRecordIdLessThan(Long value) {
addCriterion("UPLOAD_RECORD_ID <", value, "uploadRecordId");
return (Criteria) this;
}
public Criteria andUploadRecordIdLessThanOrEqualTo(Long value) {
addCriterion("UPLOAD_RECORD_ID <=", value, "uploadRecordId");
return (Criteria) this;
}
public Criteria andUploadRecordIdIn(List<Long> values) {
addCriterion("UPLOAD_RECORD_ID in", values, "uploadRecordId");
return (Criteria) this;
}
public Criteria andUploadRecordIdNotIn(List<Long> values) {
addCriterion("UPLOAD_RECORD_ID not in", values, "uploadRecordId");
return (Criteria) this;
}
public Criteria andUploadRecordIdBetween(Long value1, Long value2) {
addCriterion("UPLOAD_RECORD_ID between", value1, value2, "uploadRecordId");
return (Criteria) this;
}
public Criteria andUploadRecordIdNotBetween(Long value1, Long value2) {
addCriterion("UPLOAD_RECORD_ID not between", value1, value2, "uploadRecordId");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {
......
......@@ -40,7 +40,7 @@
sys:系统 系统相关表,例如kafka表
log: 日志 日志记录表,例如邮件发送日志表
-->
<javaModelGenerator targetPackage="com.fedex.connect.common.model.sys" targetProject="src/main/java">
<javaModelGenerator targetPackage="com.fedex.connect.common.model.biz" targetProject="src/main/java">
<!---enableSubPackages:如果true,MBG会根据catalog和schema来生成子包。如果false就会直接用targetPackage属性-->
<property name="enableSubPackages" value="false"/>
<!--该属性只对MyBatis3有效,如果true就会使用构造方法入参,如果false就会使用setter方式。默认为false-->
......@@ -52,13 +52,13 @@
</javaModelGenerator>
<!-- 生成映射文件*.xml的位置-->
<sqlMapGenerator targetPackage="mapper.sys" targetProject="src/main/java/com/fedex/connect/common">
<sqlMapGenerator targetPackage="mapper.biz" targetProject="src/main/java/com/fedex/connect/common">
<!--如果true,MBG会根据catalog和schema来生成子包。如果false就会直接用targetPackage属性。默认为false-->
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.fedex.connect.common.dao.sys" targetProject="src/main/java">
<javaClientGenerator type="XMLMAPPER" targetPackage="com.fedex.connect.common.dao.biz" targetProject="src/main/java">
<!--如果true,MBG会根据catalog和schema来生成子包。如果false就会直接用targetPackage属性。默认为false-->
<property name="enableSubPackages" value="false"/>
</javaClientGenerator>
......@@ -135,14 +135,12 @@
<!-- selectByExampleQueryId="true">-->
<!-- <generatedKey column="ID" sqlStatement="SELECT SEQ_T_BIZ_PUSH_OB.NEXTVAL FROM DUAL" />-->
<!-- </table>-->
<!-- <table tableName="T_BIZ_PUSH_OB_DETAIL" domainObjectName="PushObDetail"-->
<!-- enableCountByExample="true" enableUpdateByExample="true"-->
<!-- enableDeleteByExample="true" enableSelectByExample="true"-->
<!-- selectByExampleQueryId="true">-->
<!-- <generatedKey column="ID" sqlStatement="SELECT SEQ_T_BIZ_PUSH_OB_DETAIL.NEXTVAL FROM DUAL" />-->
<!-- </table>-->
<table tableName="T_BIZ_PUSH_OB_DETAIL" domainObjectName="PushObDetail"
enableCountByExample="true" enableUpdateByExample="true"
enableDeleteByExample="true" enableSelectByExample="true"
selectByExampleQueryId="true">
<generatedKey column="ID" sqlStatement="SELECT SEQ_T_BIZ_PUSH_OB_DETAIL.NEXTVAL FROM DUAL" />
</table>
<!-- <table tableName="T_BI_PORTCLEAR_EMAIL_MAPPING" domainObjectName="PortclearEmailMapping"-->
<!-- enableCountByExample="true" enableUpdateByExample="true"-->
......@@ -169,12 +167,12 @@
<!-- selectByExampleQueryId="true">-->
<!-- <generatedKey column="ID" sqlStatement="SELECT SEQ_T_SYS_KAFKA_TEMPORARY_STORAGE.NEXTVAL FROM DUAL" />-->
<!-- </table>-->
<table schema="ICLEARIMP" tableName="T_SYS_PARAM_CONFIG" domainObjectName="ParamConfig"
enableCountByExample="true" enableUpdateByExample="true"
enableDeleteByExample="true" enableSelectByExample="true"
selectByExampleQueryId="true">
<generatedKey column="ID" sqlStatement="SELECT SEQ_T_SYS_PARAM_CONFIG.NEXTVAL FROM DUAL" />
</table>
<!-- <table schema="ICLEARIMP" tableName="T_SYS_PARAM_CONFIG" domainObjectName="ParamConfig"-->
<!-- enableCountByExample="true" enableUpdateByExample="true"-->
<!-- enableDeleteByExample="true" enableSelectByExample="true"-->
<!-- selectByExampleQueryId="true">-->
<!-- <generatedKey column="ID" sqlStatement="SELECT SEQ_T_SYS_PARAM_CONFIG.NEXTVAL FROM DUAL" />-->
<!-- </table>-->
<!-- <table tableName="T_SYS_PRIVILEGE" domainObjectName="Privilege"-->
<!-- enableCountByExample="true" enableUpdateByExample="true"-->
<!-- enableDeleteByExample="true" enableSelectByExample="true"-->
......@@ -193,12 +191,12 @@
<!-- selectByExampleQueryId="true">-->
<!-- <generatedKey column="ID" sqlStatement="SELECT SEQ_T_SYS_ROLE_PRIVILEGE.NEXTVAL FROM DUAL" />-->
<!-- </table>-->
<table schema="ICLEARIMP" tableName="T_SYS_USER" domainObjectName="User"
enableCountByExample="true" enableUpdateByExample="true"
enableDeleteByExample="true" enableSelectByExample="true"
selectByExampleQueryId="true">
<generatedKey column="ID" sqlStatement="SELECT SEQ_T_SYS_USER.NEXTVAL FROM DUAL" />
</table>
<!-- <table schema="ICLEARIMP" tableName="T_SYS_USER" domainObjectName="User"-->
<!-- enableCountByExample="true" enableUpdateByExample="true"-->
<!-- enableDeleteByExample="true" enableSelectByExample="true"-->
<!-- selectByExampleQueryId="true">-->
<!-- <generatedKey column="ID" sqlStatement="SELECT SEQ_T_SYS_USER.NEXTVAL FROM DUAL" />-->
<!-- </table>-->
<!-- <table schema="ICLEARIMP" tableName="T_SYS_USER_ROLE" domainObjectName="UserRole"-->
<!-- enableCountByExample="true" enableUpdateByExample="true"-->
<!-- enableDeleteByExample="true" enableSelectByExample="true"-->
......
......@@ -70,7 +70,7 @@ public interface BaseSeparatorConstants {
String SEPARATOR_ASTERISK = "*";
/**
* @Description 星号
* @Description 反斜杠
* @Author mt
* @Date 2024-11-11
*/
......
......@@ -24,6 +24,7 @@ public class DateUtil {
public static final String PATTERN_DATE_TIME_ORACLE = "yyyy-MM-dd hh:mi:ss";
public static final String PATTERN_DATE_TIME_MS = "yyyy-mm-dd hh24:mi:ss";
public static final String PATTERN_yyyyMMddHHmmss = "yyyyMMddHHmmss";
public static final String YYYYMMDDHH24MMSSSSS = "yyyyMMddHHmmssSSS";
private static SimpleDateFormat dateFormat = new SimpleDateFormat();
......@@ -47,6 +48,19 @@ public class DateUtil {
dateFormat.applyPattern(PATTERN_DATE_TIME);
return dateFormat.format(date);
}
/**
* 用默认格式格式化日期
*
* @param date
* @return
*/
public static String yyyyMMddHH24mmssSSS(Date date) {
SimpleDateFormat dateFormat = new SimpleDateFormat();
dateFormat.applyPattern(YYYYMMDDHH24MMSSSSS);
return dateFormat.format(date);
}
/**
* 用指定格式格式化日期
*
......
......@@ -262,4 +262,43 @@ public class NIOFileUtils {
}
return false;
}
/**
* @Author mt
* @Description 移动文件
* @Date 2024/5/30
* @param sourcePath
* @param targetPath
* @return void
*/
public void moveFile(String sourcePath,String targetPath) throws Exception{
//覆盖方式移动
Files.move(Paths.get(sourcePath),Paths.get(targetPath),StandardCopyOption.REPLACE_EXISTING);
}
/**
* @Author mt
* @Description 判断文件是否存在
* @Date 2024/9/10
* @param filePath
* @return boolean
*/
public boolean fileExists(String filePath){
return new File(filePath).exists();
}
/**
* @Author mt
* @Description 如果文件夹不存在则创建文件夹
* @Date 2024/5/29
* @param targetFolder
* @return void
*/
public void mkdirs(String targetFolder){
File folder = new File(targetFolder);
// 文件夹不存在,则创建文件夹
if (!folder.exists()) {
folder.mkdirs();
}
}
}
......
......@@ -497,7 +497,7 @@ public class StringExtUtil {
* @param val ID值
* @return
*/
public static String idLeftPadStr(Long val){
public static String idLeftPadStr(Long val, Integer len){
if (val == null){
return null;
}
......@@ -505,9 +505,8 @@ public class StringExtUtil {
return "0";
}
String valStr = val.toString();
int len = valStr.length();
if (valStr.length() <= 10){
return StringUtils.leftPad(valStr,10,"0");
if (valStr.length() <= len){
return StringUtils.leftPad(valStr,len,"0");
} else {
return valStr;
}
......@@ -554,4 +553,10 @@ public class StringExtUtil {
}
}
public static void main(String[] args){
String fileName = "202410271_20241027113156.pdf";
String f = fileName.substring(fileName.lastIndexOf("."));
System.out.println(f);
}
}
......
......@@ -75,4 +75,17 @@ public class PropertiesConfig {
@Value("${export.mail.sendEmail.password}")
String emailPassword;
//基础路径
@Value("${imp001.path.work}")
String imp001PathWork;
//zip输出目录
@Value("${imp001.path.final}")
String imp001PathFinal;
//文件备份目录
@Value("${imp001.path.bak}")
String imp001PathBak;
//文件异常文件存放目录
@Value("${imp001.path.error}")
String imp001PathError;
}
\ No newline at end of file
......
......@@ -6,7 +6,11 @@ package com.fedex.connect.task.constants;
* @Date 2024/4/18
*/
public interface Constant {
//TW001表头信息
/**
* @Author mt
* @Description IMP001表头信息
* @Date 2024/12/18
*/
interface IMP001_HEAD_KEYS{
/**
* 消息代码:IMP001报文标志
......@@ -15,14 +19,18 @@ public interface Constant {
/**
* 发送程序ID:TWEXP
*/
String SENDER_ID = "TWEXP";
String SENDER_ID = "PreCLR";
/**
* 接受程序ID:IMP
*/
String RECEIVER_ID = "IMP";
}
//文件后缀字符串keys
/**
* @Author mt
* @Description 文件后缀字符串keys
* @Date 2024/12/18
*/
interface FILE_SUFFIX_KEYS{
/**
* json字符串
......
package com.fedex.connect.task.data.bo;
import lombok.Data;
import java.util.Date;
/**
* @Author mt
* @Description 类说明 文件信息bo
* @Date 2024/5/30
*/
@Data
public class Imp001FileInfoBo {
//文件类型id
Long fileTypeId;
//文件类型名称
String fileTypeName;
//文件名称
String fileName;
//生成时间
Date pushTime;
}
package com.fedex.connect.task.data.bo;
import com.fedex.connect.common.model.bi.DictionaryEntries;
import com.fedex.connect.task.data.dto.imp001.Imp001Files;
import com.fedex.connect.task.data.dto.imp001.Imp001RootJsonDto;
import lombok.Data;
import java.util.Dictionary;
import java.util.List;
/**
* @Author mt
* @Description 类说明 tw001生成bo
* @Description 类说明 imp001生成bo
* @Date 2024/5/24
*/
@Data
public class Imp001GenerateBo {
//tw001报文对象
//运单号
String consignmentCode;
//运单ID
Long consignmentId;
//imp001报文对象
Imp001RootJsonDto imp001RootJsonDto;
//tw001临时文件夹目录
//imp001临时文件夹目录
String workFilePath;
//需要打包压缩包文件信息名称
List<Imp001FileInfoBo> fileInfoList;
//json Dir对象
DictionaryEntries jsonDictionary;
Imp001Files[] fileInfos;
//zip文件名称
String zipFileName;
//zip推送目标目录
......
......@@ -13,15 +13,14 @@ import java.io.Serializable;
public class Imp001Consignment implements Serializable {
/**
* @Author mt
* @Description 提单号码
* 12位数字,提单号码,可以重复
* @Date 2024/5/23
* @Description 每个报文只有一个12位运单号
* @Date 2024年12月18日
*/
private String deliveryNo;
/**
* @Author mt
* @Description 联络人
* @Date 2024/5/23
* @Description 运单附带文件数量
* @Date 2024年12月18日
*/
private Integer attachedFilesCount;
}
\ No newline at end of file
......
......@@ -24,7 +24,7 @@ public class Imp001Job {
@ProcessingInterval(paramCode = ParamConfigConstants.TASK_PARAM_KEYS.PUSH_IMP001_INTERVAL)
@Scheduled(cron = "${export.task.allocation.sendOb}")
public void sendObTask() {
//sendObService.sendOb();
sendObService.sendOb();
}
/**
......@@ -33,6 +33,6 @@ public class Imp001Job {
@ProcessingInterval
@Scheduled(cron = "${export.task.allocation.sendObRetry}")
public void sendObRetryTask() {
//sendObService.sendObRetry();
sendObService.sendObRetry();
}
}
......
package com.fedex.connect.task.repository.base;
import com.fedex.connect.common.dao.biz.AttachmentMapper;
import com.fedex.connect.common.dao.biz.ConsignmentMapper;
import com.fedex.connect.common.dao.biz.EmailMapper;
import com.fedex.connect.common.dao.biz.PushObMapper;
import com.fedex.connect.common.dao.biz.*;
import com.fedex.connect.common.dao.log.EmailHistoryMapper;
import com.fedex.connect.common.dao.sys.KafkaStorageHistoryMapper;
import com.fedex.connect.common.dao.sys.KafkaTemporaryStorageMapper;
......@@ -23,6 +20,8 @@ public class AbstractDaoRepository {
@Autowired
protected PushObMapper pushObMapper;
@Autowired
protected PushObDetailMapper pushObDetailMapper;
@Autowired
protected KafkaTemporaryStorageMapperExt kafkaTemporaryStorageMapperExt;
@Autowired
protected RedisSlabMapperExt redisSlabMapperExt;
......
......@@ -15,10 +15,8 @@ public interface AttachmentExtMapper {
"WHERE a.BIZ_ID = #{bizId}")
List<PushZipEmailDto> findAttachmentDetailsByBizId(@Param("bizId") Long bizId);
@Select("SELECT * FROM T_BIZ_ATTACHMENT WHERE UPLOAD_RECORD_ID = " +
"(SELECT MAX(ID) FROM T_BIZ_UPLOAD_RECORD WHERE " +
" CONSIGNMENT_ID = #{consignmentId}) AND STATUS = 1")
List<Attachment> queryAttachmentInfo(@Param("consignmentId") Long consignmentId);
@Select("SELECT * FROM T_BIZ_ATTACHMENT WHERE UPLOAD_RECORD_ID = #{uploadRecordId} AND BIZ_ID = #{consignmentId} AND STATUS = 1")
List<Attachment> queryAttachmentInfo(@Param("uploadRecordId") Long uploadRecordId,@Param("consignmentId") Long consignmentId);
/**
* 根据修改日期查询数据
......@@ -26,6 +24,6 @@ public interface AttachmentExtMapper {
* @return
*/
@Select("SELECT * FROM T_BIZ_ATTACHMENT " +
"WHERE MODIFY_TIME < TO_DATE(#{date}, 'YYYY-MM-DD') AND STATUS = 1")
"WHERE MODIFY_TIME &lt; TO_DATE(#{date}, 'YYYY-MM-DD') AND STATUS = 1")
List<Attachment> findAttachmentsOlderThan(@Param("date") String date);
}
......
......@@ -10,7 +10,7 @@ public interface IAttachmentRepository {
List<PushZipEmailDto> findAttachmentDetailsByBizId(@Param("bizId") Long bizId);
List<Attachment> queryAttachmentInfo(Long consignmentId);
List<Attachment> queryAttachmentInfo(Long uploadRecordId,Long consignmentId);
List<Attachment> findAttachmentsOlderThan(String date);
......
package com.fedex.connect.task.repository.repo.biz;
import com.fedex.connect.common.model.biz.PushObDetail;
import java.util.List;
public interface IPushObDetailRepository {
/**
* @Author mt
* @Description 功能说明 批量插入
* @Date 2024/5/30
* @param record
* @return void
*/
void batchInsert(List<PushObDetail> record);
}
......@@ -17,8 +17,8 @@ public class AttachmentRepositoryImpl extends AbstractDaoRepository implements I
}
@Override
public List<Attachment> queryAttachmentInfo(Long consignmentId){
return attachmentExtMapper.queryAttachmentInfo(consignmentId);
public List<Attachment> queryAttachmentInfo(Long uploadRecordId,Long consignmentId){
return attachmentExtMapper.queryAttachmentInfo(uploadRecordId,consignmentId);
}
@Override
......
package com.fedex.connect.task.repository.repo.biz.impl;
import com.fedex.connect.common.dependencies.util.Utils;
import com.fedex.connect.common.model.biz.PushObDetail;
import com.fedex.connect.task.repository.base.AbstractDaoRepository;
import com.fedex.connect.task.repository.repo.biz.IPushObDetailRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Objects;
/**
* @Author mt
* @Description 推送明细日志repository
* @Date 2024/5/30
*/
@Repository
public class PushObDetailRepository extends AbstractDaoRepository implements IPushObDetailRepository {
/**
* @Author mt
* @Description 功能说明 批量插入
* @Date 2024/5/30
* @param record
* @return void
*/
public void batchInsert(List<PushObDetail> record){
Utils.listOf(record).stream().filter(Objects::nonNull).forEach(r->{
pushObDetailMapper.insert(r);
});
}
}
......@@ -3,6 +3,7 @@ package com.fedex.connect.task.service.base;
import com.fedex.connect.common.dependencies.repository.repo.sys.IRedisSlabRepository;
import com.fedex.connect.task.repository.repo.biz.IAttachmentRepository;
import com.fedex.connect.task.repository.repo.biz.IEmailRepository;
import com.fedex.connect.task.repository.repo.biz.IPushObDetailRepository;
import com.fedex.connect.task.repository.repo.biz.IPushObRepository;
import com.fedex.connect.task.repository.repo.sys.IKafkaStorageHistoryRepository;
import com.fedex.connect.task.repository.repo.sys.IKafkaTemporaryStorageRepository;
......@@ -31,5 +32,7 @@ public class BaseService {
@Autowired
protected IPushObRepository pushObRepository;
@Autowired
protected IPushObDetailRepository pushObDetailRepository;
@Autowired
protected IParamConfigRepository paramConfigRepository;
}
\ No newline at end of file
......
package com.fedex.connect.task.service.biz;
import com.fedex.connect.common.model.biz.PushObDetail;
import java.util.List;
public interface IPushObDetailService {
/**
* @Author mt
* @Description 功能说明 批量插入
* @Date 2024/5/30
* @param record
* @return void
*/
void batchInsert(List<PushObDetail> record);
}
package com.fedex.connect.task.service.biz;
public interface IPushObService {
///**
// * @Author mt
// * @Description 推送Imp001报文数据zip包文件
// * @Date 2024/8/2
// * @param
// * @return void
// */
//void sendOb();
///**
// * @Author mt
// * @Description 推送Imp001文件错误重试
// * @Date 2024/8/2
// * @param
// * @return void
// */
//void sendObRetry();
/**
* @Author mt
* @Description 推送Imp001报文数据zip包文件
* @Date 2024/8/2
* @param
* @return void
*/
void sendOb();
/**
* @Author mt
* @Description 推送Imp001文件错误重试
* @Date 2024/8/2
* @param
* @return void
*/
void sendObRetry();
}
\ No newline at end of file
......
package com.fedex.connect.task.service.biz.impl;
import com.fedex.connect.common.model.biz.PushObDetail;
import com.fedex.connect.task.service.base.BaseService;
import com.fedex.connect.task.service.biz.IPushObDetailService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Author mt
* @Description 类说明 推送明细日志
* @Date 2024/5/30
*/
@Service
public class PushObDetailServiceImpl extends BaseService implements IPushObDetailService {
/**
* @Author mt
* @Description 功能说明 批量插入
* @Date 2024/5/30
* @param record
* @return void
*/
public void batchInsert(List<PushObDetail> record){
pushObDetailRepository.batchInsert(record);
}
}
package com.fedex.connect.task.service.biz.impl;
import com.fedex.connect.common.dependencies.cache.CacheSystem;
import com.fedex.connect.common.dependencies.contants.ParamConfigConstants;
import com.fedex.connect.common.dependencies.enums.biz.PushObStatusEnum;
import com.fedex.connect.common.dependencies.util.Utils;
import com.fedex.connect.common.model.bi.DictionaryEntries;
import com.fedex.connect.common.model.biz.PushOb;
import com.fedex.connect.common.model.sys.ParamConfig;
import com.fedex.connect.task.data.bo.Imp001GenerateBo;
import com.fedex.connect.task.service.base.BaseService;
import com.fedex.connect.task.service.biz.IPushObService;
import com.fedex.connect.task.utils.biz.imp001.Imp001GenerateUtil;
import com.fedex.connect.task.utils.biz.imp001.Imp001PushUtil;
import com.fedex.connect.task.utils.biz.imp001.Imp001RecordLogUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -20,92 +25,102 @@ import java.util.Objects;
/**
* @Author mt
* @Description 发送Imp001到进口组
* @Date 2024/5/24
* @Date 2024年12月18日
*/
@Slf4j
@Service
public class PushObServiceImpl extends BaseService implements IPushObService {
//@Autowired
//Imp001GenerateUtil imp001GenerateUtil;
//@Autowired
//Imp001PushUtil imp001PushUtil;
//@Autowired
//Imp001RecordLogUtil imp001RecordLogUtil;
//
///**
// * 推送OB报文数据zip包文件
// */
//@Override
//public void sendOb() {
// //获取每次处理数据量量参数
// ParamConfig paramConfig = paramConfigRepository.findValueByCode(ParamConfigConstants.TASK_PARAM_KEYS.PUSH_IMP001_NUMBER);
// Long rownum = Long.parseLong(paramConfig.getValue());
// //获取需要处理的记录
// List<PushOb> pushObList = pushObRepository.findPushOb(PushObStatusEnum.TO_BE_SENT.getCode(),rownum);
// //推送imp001数据
// this.pushOb(pushObList);
//}
//
///**
// * 推送OB文件错误重试
// */
//@Override
//public void sendObRetry() {
// //获取每次处理数据量量参数
// Map<String,ParamConfig> paramConfig = paramConfigRepository.findValueByCodes(ParamConfigConstants.TASK_PARAM_KEYS.PUSH_IMP001_NUMBER,
// ParamConfigConstants.TASK_PARAM_KEYS.PUSH_IMP001_RETRY_NUMBER);
// //推送IMP001重试处理数量
// ParamConfig retryNumConfig = paramConfig.get(ParamConfigConstants.TASK_PARAM_KEYS.PUSH_IMP001_RETRY_NUMBER);
// Long retryNum = Long.parseLong(retryNumConfig.getCode());
// //推送IMP001定时任务处理数量
// ParamConfig rownumConfig = paramConfig.get(ParamConfigConstants.TASK_PARAM_KEYS.PUSH_IMP001_NUMBER);
// Long rownum = Long.parseLong(rownumConfig.getCode());
// //获取需要重新处理的记录:处理4次以下,并且推送失败的
// List<PushOb> errPushObLog = pushObRepository.findErrPushOb(retryNum, PushObStatusEnum.PUSH_FAILED.getCode(),rownum);
// if (errPushObLog!=null && !errPushObLog.isEmpty()){
// log.info("sendObRetryTask : sendObRetry size: "+errPushObLog.size());
// //重新推送tw001数据
// this.pushOb(errPushObLog);
// }else{
// log.info("sendObRetryTask : No data found for sendObRetry!");
// }
//}
//
///**
// * @Author mt
// * @Description 推送tw001数据
// * @Date 2024/5/29
// * @param pushObList
// * @return void
// */
//private void pushOb(List<PushOb> pushObList){
// Utils.listOf(pushObList).stream().filter(Objects::nonNull).forEach(ob ->{
// boolean flag = false;
// String errorMsg = "";
// Imp001GenerateBo imp001GenerateBo = null;
// try {
// //生成tw001 json对象dto
// imp001GenerateBo = imp001GenerateUtil.generateImp001Json(ob);
// //根据tw001 json对象生成并且推送zip包
// imp001PushUtil.pushImp001(imp001GenerateBo);
// flag = true;
// }catch(Exception ex){
// log.error("pushOb error : ",ex);
// errorMsg = ex.getMessage();
// flag = false;
// }finally{
// /**
// * 如果生成失败,推送失败,则不会记录推送日志明细,更新推送日志表。
// * 记录日志,并且备份
// */
// if(flag){
// //推送成功
// imp001RecordLogUtil.pushSuccessRecordLog(imp001GenerateBo, ob);
// }else{
// //推送失败
// imp001RecordLogUtil.pushFailRecordLog(imp001GenerateBo, ob, errorMsg);
// }
// }
// });
//}
@Autowired
Imp001GenerateUtil imp001GenerateUtil;
@Autowired
Imp001PushUtil imp001PushUtil;
@Autowired
Imp001RecordLogUtil imp001RecordLogUtil;
@Autowired
CacheSystem cacheSystem;
/**
* 推送OB报文数据zip包文件
*/
@Override
public void sendOb() {
//获取每次处理数据量量参数
ParamConfig paramConfig = paramConfigRepository.findValueByCode(ParamConfigConstants.TASK_PARAM_KEYS.PUSH_IMP001_NUMBER);
Long rownum = Long.parseLong(paramConfig.getValue());
//获取需要处理的记录
List<PushOb> pushObList = pushObRepository.findPushOb(PushObStatusEnum.TO_BE_SENT.getCode(),rownum);
//推送imp001数据
this.pushOb(pushObList);
}
/**
* 推送OB文件错误重试
*/
@Override
public void sendObRetry() {
//获取每次处理数据量量参数
Map<String,ParamConfig> paramConfig = paramConfigRepository.findValueByCodes(ParamConfigConstants.TASK_PARAM_KEYS.PUSH_IMP001_NUMBER,
ParamConfigConstants.TASK_PARAM_KEYS.PUSH_IMP001_RETRY_NUMBER);
//推送IMP001重试处理数量
ParamConfig retryNumConfig = paramConfig.get(ParamConfigConstants.TASK_PARAM_KEYS.PUSH_IMP001_RETRY_NUMBER);
Long retryNum = Long.parseLong(retryNumConfig.getCode());
//推送IMP001定时任务处理数量
ParamConfig rownumConfig = paramConfig.get(ParamConfigConstants.TASK_PARAM_KEYS.PUSH_IMP001_NUMBER);
Long rownum = Long.parseLong(rownumConfig.getCode());
//获取需要重新处理的记录:处理4次以下,并且推送失败的
List<PushOb> errPushObLog = pushObRepository.findErrPushOb(retryNum, PushObStatusEnum.PUSH_FAILED.getCode(),rownum);
if (errPushObLog!=null && !errPushObLog.isEmpty()){
log.info("sendObRetryTask : sendObRetry size: "+errPushObLog.size());
//重新推送tw001数据
this.pushOb(errPushObLog);
}else{
log.info("sendObRetryTask : No data found for sendObRetry!");
}
}
/**
* @Author mt
* @Description 推送imp001数据
* @Date 2024/5/29
* @param pushObList
* @return void
*/
private void pushOb(List<PushOb> pushObList){
/**
* 推送成功状态字典
*/
DictionaryEntries pushSuccessEntries = cacheSystem.getDicPushObStatus(PushObStatusEnum.PUSH_SUCCESSFUL.getCode());
/**
* 推送失败状态字典
*/
DictionaryEntries pushFailedEntries = cacheSystem.getDicPushObStatus(PushObStatusEnum.PUSH_FAILED.getCode());
Utils.listOf(pushObList).stream().filter(Objects::nonNull).forEach(ob ->{
boolean flag = false;
String errorMsg = "";
Imp001GenerateBo imp001GenerateBo = null;
try {
//生成imp001 json对象dto
imp001GenerateBo = imp001GenerateUtil.generateImp001Json(ob);
//根据imp001 json对象生成并且推送zip包
imp001PushUtil.pushImp001(imp001GenerateBo);
flag = true;
}catch(Exception ex){
log.error("pushOb error : ",ex);
errorMsg = ex.getMessage();
flag = false;
}finally{
/**
* 如果生成失败,推送失败,则不会记录推送日志明细,更新推送日志表。
* 记录日志,并且备份
*/
if(flag){
//推送成功
imp001RecordLogUtil.pushSuccessRecordLog(imp001GenerateBo, ob, pushSuccessEntries);
}else{
//推送失败
imp001RecordLogUtil.pushFailRecordLog(imp001GenerateBo, ob, pushFailedEntries, errorMsg);
}
}
});
}
}
\ No newline at end of file
......
//package com.fedex.connect.task.utils.biz.imp001;
//
//import com.fedex.connect.common.dependencies.cache.CacheSystem;
//import com.fedex.connect.common.dependencies.util.NIOFileUtils;
//import com.fedex.connect.common.model.bi.DictionaryEntries;
//import com.fedex.connect.common.model.biz.Attachment;
//import com.fedex.connect.common.model.biz.Consignment;
//import com.fedex.connect.common.model.biz.PushOb;
//import com.fedex.connect.task.config.PropertiesConfig;
//import com.fedex.connect.task.data.bo.Imp001FileInfoBo;
//import com.fedex.connect.task.data.bo.Imp001GenerateBo;
//import com.fedex.connect.task.data.dto.imp001.*;
//import com.fedex.connect.task.repository.repo.biz.IAttachmentRepository;
//import com.fedex.connect.task.repository.repo.biz.IConsignmentRepository;
//import com.fedex.export.common.util.DateUtil;
//import com.fedex.export.common.util.NioFileUtils;
//import com.fedex.export.common.util.StringExtUtil;
//import com.fedex.export.common.util.Utils;
//import com.fedex.export.config.PropertiesConfig;
//import com.fedex.export.constants.Constant;
//import com.fedex.export.data.bo.Imp001FileInfoBo;
//import com.fedex.export.data.bo.Imp001GenerateBo;
//import com.fedex.export.data.dto.tw001.*;
//import com.fedex.export.repository.entity.*;
//import com.fedex.export.repository.entity.log.PushObLog;
//import com.fedex.export.service.business.IDeclareCheckInfoService;
//import com.fedex.export.service.business.IDeclareCustomsFileService;
//import com.fedex.export.service.business.IDeclareInfoService;
//import com.fedex.export.service.business.IUploadFileService;
//import com.fedex.export.service.system.ISysDictionaryService;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//import java.util.*;
//
///**
// * @Author mt
// * @Description imp001报文生成json,util
// * @Date 2024/5/24
// */
//@Slf4j
//@Component
//public class Imp001GenerateUtil {
// @Autowired
// CacheSystem cacheSystem;
// @Autowired
// private IAttachmentRepository attachmentRepository;
// @Autowired
// private NIOFileUtils nioFileUtils;
// @Autowired
// private PropertiesConfig propertiesConfig;
//
// /**
// * @Author mt
// * @Description 生成imp001报文json对象
// * @Date 2024/11/21
// * @param pushOb
// * @return Imp001GenerateBo
// */
// public Imp001GenerateBo generateImp001Json(PushOb pushOb) throws IOException{
// Imp001RootJsonDto tw001RootJsonDto = new Imp001RootJsonDto();
// List<Attachment> attachmentList = attachmentRepository.queryAttachmentInfo(pushOb.getConsignmentId());
// //生成IMP001报文数据
// Imp001Data imp001Data = new Imp001Data();
// Imp001Consignments[] consignments = new Imp001Consignments[1];
// Imp001Consignments imp001Consignments = new Imp001Consignments();
// //生成运单数据
// Imp001Consignment imp001Consignment = new Imp001Consignment();
// //运单号
// imp001Consignment.setDeliveryNo(pushOb.getConsignmentCode());
// //附件个数
// imp001Consignment.setAttachedFilesCount(attachmentList.size());
// //生成文件列表数据
// Imp001Files[] files = this.generateFiles(attachmentList);
// /***************设置对象赋值***************/
// imp001Consignments.setConsignment(imp001Consignment);
// imp001Consignments.setFiles(files);
// consignments[0] = imp001Consignments;
// imp001Data.setConsignments(consignments);
// //初始化TW001表头信息
// this.initImp001Head(tw001RootJsonDto);
// tw001RootJsonDto.setData(imp001Data);
// //返回对象
// Imp001GenerateBo tw001GenerateBo = new Imp001GenerateBo();
// tw001GenerateBo.setDeclareInfo(declareInfo);
// tw001GenerateBo.setImp001RootJsonDto(tw001RootJsonDto);
// //获取生成tw001临时文件夹目录
// String workFilePath = this.generateWorkPath(declareInfo.getDeliveryNo(),declareInfo.getDeclareId());
// tw001GenerateBo.setWorkFilePath(workFilePath);
// List<Imp001FileInfoBo> fileInfoLists = new ArrayList<Imp001FileInfoBo>();
// //存在图案商标则添加
// if(checkInfo != null && checkInfo.getBrandImage() != null){
// //初始化图案商标文件对象
// Imp001FileInfoBo fileInfoBo = this.initFileInfo(pushFileTypeMap,Constant.SEND_TW001_KEYS.PUSH_FILE_TYPE_KEYS.PUSH_STATUS_OB_5,checkInfo.getBrandImage());
// fileInfoLists.add(fileInfoBo);
// }
// if(files != null){
// for (Imp001Files file : files) {
// //获取文件类型 1:系统生成的的“聯絡方式與特殊交待事項”。2:系统生成的“出口報關檢核表”。3:用户上传的文件
// String fileTypeCode = this.getfileType(file.getSource());
// //初始化文件对象:1:系统生成的的“聯絡方式與特殊交待事項”。2:系统生成的“出口報關檢核表”。3:用户上传的文件
// Imp001FileInfoBo fileInfoBo = this.initFileInfo(pushFileTypeMap,fileTypeCode,file.getName());
// fileInfoLists.add(fileInfoBo);
// }
// }
// //设置文件信息
// tw001GenerateBo.setFileInfoList(fileInfoLists);
// //设置jsonDic
// tw001GenerateBo.setJsonDictionary(pushFileTypeMap.get(Constant.SEND_TW001_KEYS.PUSH_FILE_TYPE_KEYS.PUSH_STATUS_OB_4));
// return tw001GenerateBo;
// }
//
// /**
// * @Author mt
// * @Description 初始化TW001表头信息
// * @Date 2024/11/21
// * @param imp001RootJsonDto
// * @return void
// */
// private void initImp001Head(Imp001RootJsonDto imp001RootJsonDto){
// String UUIDStr=String.valueOf(UUID.randomUUID());
// //消息代码/类型
// imp001RootJsonDto.setMessageId(UUIDStr);
// //消息代码/类型
// imp001RootJsonDto.setMessageCode(Constant.SEND_TW001_KEYS.TW001_HEAD_KEYS.MESSAGE_CODE);
// //发送程序ID
// imp001RootJsonDto.setSenderId(Constant.SEND_TW001_KEYS.TW001_HEAD_KEYS.SENDER_ID);
// //接受程序ID
// imp001RootJsonDto.setReceiverId(Constant.SEND_TW001_KEYS.TW001_HEAD_KEYS.RECEIVER_ID);
// String sendTime = String.valueOf(System.currentTimeMillis());
// //发送时间,时间戳
// imp001RootJsonDto.setSendTime(sendTime);
// }
//
// /**
// * @Author mt
// * @Description 功能说明
// * @Date 2024/5/30
// * @param source 1:系统生成的的“聯絡方式與特殊交待事項”。2:系统生成的“出口報關檢核表”。3:用户上传的文件
// * @return java.lang.String
// */
// private String getfileType(Integer source){
// if(source.equals(Constant.SEND_TW001_KEYS.TW001_FILE_SOURCE_1)){
// return Constant.SEND_TW001_KEYS.PUSH_FILE_TYPE_KEYS.PUSH_STATUS_OB_1;
// }else if(source.equals(Constant.SEND_TW001_KEYS.TW001_FILE_SOURCE_2)){
// return Constant.SEND_TW001_KEYS.PUSH_FILE_TYPE_KEYS.PUSH_STATUS_OB_2;
// }else if(source.equals(Constant.SEND_TW001_KEYS.TW001_FILE_SOURCE_3)){
// return Constant.SEND_TW001_KEYS.PUSH_FILE_TYPE_KEYS.PUSH_STATUS_OB_3;
// }
// return null;
// }
//
// /**
// * @Author mt
// * @Description 功能说明 初始化fileInfo
// * @Date 2024/5/30
// * @param pushFileTypeMap
// * @param fileTypeCode
// * @param fileName
// * @return com.fedex.export.data.bo.Imp001FileInfoBo
// */
// private Imp001FileInfoBo initFileInfo(Map<String,SysDictionary> pushFileTypeMap, String fileTypeCode, String fileName){
// Imp001FileInfoBo fileInfoBo = new Imp001FileInfoBo();
// //类型编码不为空则初始化文件id,文件类型
// if(StringUtils.isNotEmpty(fileTypeCode)) {
// SysDictionary fileTypeDic = pushFileTypeMap.get(fileTypeCode);
// if (fileTypeDic != null) {
// fileInfoBo.setFileTypeId(fileTypeDic.getId());
// fileInfoBo.setFileTypeName(fileTypeDic.getChineseName());
// }
// }
// fileInfoBo.setPushTime(new Date());
// fileInfoBo.setFileName(fileName);
// return fileInfoBo;
// }
//
// /**
// * @Author mt
// * @Description 生成文件对象集合vo,并且将文件复制到指定目录
// * @Date 2024/11/21
// * @param attachmentList
// * @return com.fedex.connect.task.data.dto.imp001.Imp001Files[]
// */
// private Imp001Files[] generateFiles(List<Attachment> attachmentList) throws IOException{
// if(attachmentList == null || attachmentList.size() == 0){
// return null;
// }
// Imp001Files[] tw001Files = new Imp001Files[attachmentList.size()];
// for(int i = 0 ; i < attachmentList.size() ; i ++){
// Attachment attachment = attachmentList.get(i);
// Imp001Files file = new Imp001Files();
// //获取附件业务类型
// DictionaryEntries attBizType = cacheSystem.getDicAttachmentBizType(attachment.getBizTypeCode());
// //运单、发票、箱单、其他
// String bizTypeCode = attBizType.getExt1();
// if(StringUtils.isEmpty(bizTypeCode)){
// continue;
// }
// //重置文件名称,并且复制源文件到指定目录
// String fileName = this.generateFileName(uploadFile, deliveryNo, declareId);
// if(fileName == null){
// continue;
// }
// //文件名称
// file.setName(fileName);
// //文件来源
// file.setSource(source);
// //文件后缀转换为小写
// String suffix = uploadFile.getType();
// if(suffix != null){
// suffix = suffix.toLowerCase();
// }
// //文件名后缀
// file.setSuffix(suffix);
// //文件大小
// file.setFileSizeByte(uploadFile.getFileSizeByte() == null ? null : uploadFile.getFileSizeByte().intValue());
// tw001Files[i] = file;
// }
// return tw001Files;
// }
//
// /**
// * @Author mt
// * @Description 重置文件名称,并且复制源文件到指定目录
// * @Date 2024/5/29
// * @param uploadFile
// * @param deliveryNo
// * @param declareId
// * @return java.lang.String
// */
// private String generateFileName(UploadFile uploadFile,String deliveryNo,Long declareId) throws IOException{
// String generateFileName = null;
// if(!Utils.isEmpty(uploadFile.getName())){
// generateFileName = deliveryNo
// + Constant.COMMON_KEYS.UNDER_LINE + StringExtUtil.idLeftPadStr(uploadFile.getId())
// + Constant.COMMON_KEYS.UNDER_LINE + uploadFile.getName()
// + Constant.COMMON_KEYS.UNDER_LINE + DateUtil.yyyyMMddHH24mmssSSS(new Date()) + uploadFile.getType();
// }
// //获取源文件目录 实际文件路径:/var/share/icleartw/upload/declareFile/202401/476/出口報關申請表_20240116_132402_827.pdf
// String sourceFilePath = uploadFile.getServerPath() + Constant.COMMON_KEYS.BACK_SLASH + uploadFile.getServerName();
// //获取复制目标目录
// String targetFilePath = this.generateWorkPath(deliveryNo,declareId) + generateFileName;
// //原始文件存在则复制文件
// if(nioFileUtils.fileExists(sourceFilePath)){
// //复制文件到指定目录
// nioFileUtils.copyFile(sourceFilePath,targetFilePath);
// return generateFileName;
// }else{
// return null;
// }
// }
//
// /**
// * @Author mt
// * @Description 生成文件夹目录 /var/share/icleartw/TWIMPORT/work/yyyy-MM-dd/运单号_运单ID/
// * @Date 2024/5/29
// * @param deliveryNo
// * @param declareId
// * @return java.lang.String
// */
// private String generateWorkPath(String deliveryNo,Long declareId){
// String yyyyMMdd = DateUtil.format(new Date());
// String fileDir = propertiesConfig.getTw001PathWork() + Constant.COMMON_KEYS.BACK_SLASH +
// yyyyMMdd + Constant.COMMON_KEYS.BACK_SLASH +
// deliveryNo + Constant.COMMON_KEYS.UNDER_LINE + declareId + Constant.COMMON_KEYS.BACK_SLASH;
// //如果目录不存在则创建完整目录
// nioFileUtils.mkdirs(fileDir);
// return fileDir;
// }
//}
\ No newline at end of file
package com.fedex.connect.task.utils.biz.imp001;
import com.fedex.connect.common.dependencies.cache.CacheSystem;
import com.fedex.connect.common.dependencies.contants.BaseSeparatorConstants;
import com.fedex.connect.common.dependencies.contants.DigitConstants;
import com.fedex.connect.common.dependencies.util.DateUtil;
import com.fedex.connect.common.dependencies.util.NIOFileUtils;
import com.fedex.connect.common.dependencies.util.StringExtUtil;
import com.fedex.connect.common.dependencies.util.Utils;
import com.fedex.connect.common.model.bi.DictionaryEntries;
import com.fedex.connect.common.model.biz.Attachment;
import com.fedex.connect.common.model.biz.PushOb;
import com.fedex.connect.task.config.PropertiesConfig;
import com.fedex.connect.task.constants.Constant;
import com.fedex.connect.task.data.bo.Imp001GenerateBo;
import com.fedex.connect.task.data.dto.imp001.*;
import com.fedex.connect.task.repository.repo.biz.IAttachmentRepository;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
* @Author mt
* @Description imp001报文生成json,util
* @Date 2024/5/24
*/
@Slf4j
@Component
public class Imp001GenerateUtil {
@Autowired
CacheSystem cacheSystem;
@Autowired
private IAttachmentRepository attachmentRepository;
@Autowired
private NIOFileUtils nioFileUtils;
@Autowired
private PropertiesConfig propertiesConfig;
/**
* @Author mt
* @Description 生成imp001报文json对象
* @Date 2024/11/21
* @param pushOb
* @return Imp001GenerateBo
*/
public Imp001GenerateBo generateImp001Json(PushOb pushOb) throws IOException{
Imp001RootJsonDto imp001RootJsonDto = new Imp001RootJsonDto();
List<Attachment> attachmentList = attachmentRepository.queryAttachmentInfo(pushOb.getUploadRecordId(),pushOb.getConsignmentId());
//生成IMP001报文数据
Imp001Data imp001Data = new Imp001Data();
Imp001Consignments[] consignments = new Imp001Consignments[1];
Imp001Consignments imp001Consignments = new Imp001Consignments();
//生成运单数据
Imp001Consignment imp001Consignment = new Imp001Consignment();
//运单号
imp001Consignment.setDeliveryNo(pushOb.getConsignmentCode());
//附件个数
imp001Consignment.setAttachedFilesCount(attachmentList.size());
//生成文件列表数据
Imp001Files[] files = this.generateFiles(attachmentList,pushOb.getConsignmentCode(),pushOb.getConsignmentId());
/***************设置对象赋值***************/
imp001Consignments.setConsignment(imp001Consignment);
imp001Consignments.setFiles(files);
consignments[0] = imp001Consignments;
imp001Data.setConsignments(consignments);
//初始化IMP001表头信息
this.initImp001Head(imp001RootJsonDto);
imp001RootJsonDto.setData(imp001Data);
//返回对象
Imp001GenerateBo imp001GenerateBo = new Imp001GenerateBo();
imp001GenerateBo.setImp001RootJsonDto(imp001RootJsonDto);
//获取生成imp001临时文件夹目录
String workFilePath = this.generateWorkPath(pushOb.getConsignmentCode(),pushOb.getConsignmentId());
imp001GenerateBo.setWorkFilePath(workFilePath);
//设置文件信息
imp001GenerateBo.setFileInfos(files);
//设置运单号
imp001GenerateBo.setConsignmentCode(pushOb.getConsignmentCode());
//设置运单ID
imp001GenerateBo.setConsignmentId(pushOb.getConsignmentId());
return imp001GenerateBo;
}
/**
* @Author mt
* @Description 初始化imp001表头信息
* @Date 2024/11/21
* @param imp001RootJsonDto
* @return void
*/
private void initImp001Head(Imp001RootJsonDto imp001RootJsonDto){
String UUIDStr=String.valueOf(UUID.randomUUID());
//消息代码/类型
imp001RootJsonDto.setMessageId(UUIDStr);
//消息代码/类型
imp001RootJsonDto.setMessageCode(Constant.IMP001_HEAD_KEYS.MESSAGE_CODE);
//发送程序ID
imp001RootJsonDto.setSenderId(Constant.IMP001_HEAD_KEYS.SENDER_ID);
//接受程序ID
imp001RootJsonDto.setReceiverId(Constant.IMP001_HEAD_KEYS.RECEIVER_ID);
String sendTime = String.valueOf(System.currentTimeMillis());
//发送时间,时间戳
imp001RootJsonDto.setSendTime(sendTime);
}
/**
* @Author mt
* @Description 生成文件对象集合vo,并且将文件复制到指定目录
* @Date 2024/11/21
* @param attachmentList
* @return com.fedex.connect.task.data.dto.imp001.Imp001Files[]
*/
private Imp001Files[] generateFiles(List<Attachment> attachmentList,String consignmentCode,Long consignmentId) throws IOException{
if(attachmentList == null || attachmentList.size() == 0){
return null;
}
Imp001Files[] imp001Files = new Imp001Files[attachmentList.size()];
for(int i = 0 ; i < attachmentList.size() ; i ++){
Attachment attachment = attachmentList.get(i);
Imp001Files file = new Imp001Files();
//获取附件业务类型
DictionaryEntries attBizType = cacheSystem.getDicAttachmentBizType(attachment.getBizTypeCode());
//运单、发票、箱单、其他
String bizTypeCode = attBizType.getExt1();
if(StringUtils.isEmpty(bizTypeCode)){
continue;
}
//重置文件名称,并且复制源文件到指定目录
String fileName = this.generateFileName(attachment, (i+1),bizTypeCode, consignmentCode, consignmentId);
if(fileName == null){
continue;
}
//文件名称
file.setName(fileName);
//文件来源
file.setContentType(bizTypeCode);
//获取文件后缀,文件后缀转换为小写
String suffix = fileName.substring(fileName.lastIndexOf(BaseSeparatorConstants.SEPARATOR_POINT));
if(suffix != null){
suffix = suffix.toLowerCase();
}
//文件名后缀
file.setSuffix(suffix);
//文件大小
file.setFileSizeByte(attachment.getFileSize() == null ? null : attachment.getFileSize().intValue());
imp001Files[i] = file;
}
return imp001Files;
}
/**
* @Author mt
* @Description 重置文件名称,并且复制源文件到指定目录
* @Date 2024/12/18
* @param attachment
* @param consignmentCode
* @param consignmentId
* @return java.lang.String
*/
private String generateFileName(Attachment attachment,
Integer index,
String bizTypeCode,
String consignmentCode,
Long consignmentId) throws IOException{
String generateFileName = null;
String fileName = attachment.getFileName();
if(!Utils.isEmpty(fileName)){
//获取文件后缀
String fileSuffix = fileName.substring(fileName.lastIndexOf(BaseSeparatorConstants.SEPARATOR_POINT));
/**
* AWB_12位运单号_10位运单ID_三位文件顺序号_yyyyMMddHHmmssSSS
*/
generateFileName = bizTypeCode + BaseSeparatorConstants.SEPARATOR_UNDERLINE + consignmentCode
+ BaseSeparatorConstants.SEPARATOR_UNDERLINE + StringExtUtil.idLeftPadStr(attachment.getId(), DigitConstants.DIGIT_TEN)
+ BaseSeparatorConstants.SEPARATOR_UNDERLINE + StringExtUtil.idLeftPadStr(index.longValue(), DigitConstants.DIGIT_THREE)
+ BaseSeparatorConstants.SEPARATOR_UNDERLINE + DateUtil.yyyyMMddHH24mmssSSS(new Date()) + fileSuffix;
}
//获取源文件目录 实际文件路径:/var/share/iclearConnect/upload/attachment/2024-12-18/313913426666/AWB_202412161_20241218131852_001.pdf
String sourceFilePath = attachment.getFilePath() + BaseSeparatorConstants.SEPARATOR_SLASH + attachment.getFileName();
//获取复制目标目录
String targetFilePath = this.generateWorkPath(consignmentCode,consignmentId) + generateFileName;
//原始文件存在则复制文件
if(nioFileUtils.fileExists(sourceFilePath)){
//复制文件到指定目录
nioFileUtils.copyFile(sourceFilePath,targetFilePath);
return generateFileName;
}else{
return null;
}
}
/**
* @Author mt
* @Description 生成文件夹目录 /var/share/iClearPreCLR/ToIMPORT/work/yyyy-MM-dd/运单号_运单ID/
* @Date 2024/12/18
* @param consignmentCode
* @param consignmentId
* @return java.lang.String
*/
private String generateWorkPath(String consignmentCode,Long consignmentId){
String yyyyMMdd = DateUtil.format(new Date());
String fileDir = propertiesConfig.getImp001PathWork() + BaseSeparatorConstants.SEPARATOR_SLASH +
yyyyMMdd + BaseSeparatorConstants.SEPARATOR_SLASH +
consignmentCode + BaseSeparatorConstants.SEPARATOR_UNDERLINE + consignmentId + BaseSeparatorConstants.SEPARATOR_SLASH;
//如果目录不存在则创建完整目录
nioFileUtils.mkdirs(fileDir);
return fileDir;
}
}
\ No newline at end of file
......
//package com.fedex.connect.task.utils.biz.imp001;
//
//import com.fedex.connect.task.config.PropertiesConfig;
//import com.fedex.connect.task.data.bo.Imp001GenerateBo;
//import com.fedex.export.common.util.*;
//import com.fedex.export.config.PropertiesConfig;
//import com.fedex.export.constants.Constant;
//import com.fedex.export.data.bo.Imp001FileInfoBo;
//import com.fedex.export.data.bo.Imp001GenerateBo;
//import com.fedex.export.repository.entity.DeclareInfo;
//import com.fedex.export.repository.entity.SysDictionary;
//import lombok.extern.slf4j.Slf4j;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.io.File;
//import java.io.FileOutputStream;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//import java.util.Objects;
//
///**
// * @Author mt
// * @Description tw001报文推送,util
// * @Date 2024/5/29
// */
//@Slf4j
//@Component
//public class Imp001PushUtil {
// @Autowired
// PropertiesConfig propertiesConfig;
// @Autowired
// ZipUtils zipUtils;
// @Autowired
// NioFileUtils nioFileUtils;
//
// /**
// * @Author mt
// * @Description 推送imp001
// * @Date 2024/11/21
// * @param imp001GenerateBo
// * @return void
// */
// public void pushImp001(Imp001GenerateBo imp001GenerateBo) throws Exception{
// long start = System.currentTimeMillis();
// //生成zip临时文件到指定临时目录
// String zipFileName = this.toZips(imp001GenerateBo);
// //zip原始临时目录,zip为临时文件
// String zipSourceTempFilePath = imp001GenerateBo.getWorkFilePath() + zipFileName + Constant.FILE_SUFFIX_KEYS.TEMP;
// //推送zip文件最终目录
// String zipTargetFilePath = propertiesConfig.getTw001PathFinal() + zipFileName;
// //记录zip文件名称
// tw001GenerateBo.setZipFileName(zipFileName);
// //记录zip文件目标路径
// tw001GenerateBo.setZipFileTargetPath(zipTargetFilePath);
// //如果目录不存在则创建完整目录
// nioFileUtils.mkdirs(propertiesConfig.getTw001PathFinal());
// //推送zip临时文件到指定目标目录,复制文件到指定目录,采用
// String zipTargetTempFilePath = zipTargetFilePath + Constant.FILE_SUFFIX_KEYS.TEMP;
// //复制文件至目标目录,为临时文件
// nioFileUtils.copyFile(zipSourceTempFilePath,zipTargetTempFilePath);
// log.info("复制到目标目录完成 sourceTempFilePath : {} , targetTempFilePath : {} ",zipSourceTempFilePath,zipTargetTempFilePath);
// //重命名为正式文件
// nioFileUtils.moveFile(zipTargetTempFilePath,zipTargetFilePath);
// log.info("重命名为正式文件成功 zipTargetTempFilePath : {} , zipTargetFilePath : {} ",zipTargetTempFilePath,zipTargetFilePath);
// long end = System.currentTimeMillis();
// log.info("运单号TW001:{} 推送完成,总计耗时:{} ms",tw001GenerateBo.getDeclareInfo().getDeliveryNo() ,(end - start));
// }
//
// /**
// * @Author mt
// * @Description 功能说明 生成zip临时文件到指定临时目录
// * @Date 2024/5/30
// * @param tw001GenerateBo
// * @return java.lang.String
// */
// private String toZips(Imp001GenerateBo tw001GenerateBo) throws Exception{
// /******************初始化需要压缩文件列表****************/
// List<File> filesList = new ArrayList<File>();
// //生成json文件名称
// String jsonFileName = this.generateJsonFileName(tw001GenerateBo,"", Constant.FILE_SUFFIX_KEYS.JSON);
// //生成json文件
// JsonToJava.createJsonFile(JsonToJava.toJson(tw001GenerateBo.getTw001RootJsonDto()),
// tw001GenerateBo.getWorkFilePath(), jsonFileName);
// //获取json完整路径
// String jsonFilePath = tw001GenerateBo.getWorkFilePath() + jsonFileName;
// filesList.add(new File(jsonFilePath));
// //文件名称
// Utils.listOf(tw001GenerateBo.getFileInfoList()).stream().filter(Objects::nonNull).forEach(fileInfo ->{
// //文件如果存在则添加到文件集合中
// File file = new File(tw001GenerateBo.getWorkFilePath() + fileInfo.getFileName());
// if(file.exists()){
// filesList.add(file);
// }
// });
// //初始化json文件对象,并添加到文件集合中
// this.initJsonFileInfo(tw001GenerateBo,jsonFileName);
// //生成zip文件名称 .zip
// String zipFileName = this.generateJsonFileName(tw001GenerateBo, Constant.SEND_TW001_KEYS.TW001_HEAD_KEYS.MESSAGE_CODE, Constant.FILE_SUFFIX_KEYS.ZIP);
// //生成zip临时文件名称 .temp
// String zipTempFileName = zipFileName + Constant.FILE_SUFFIX_KEYS.TEMP;
// FileOutputStream fos = null;
// try{
// //完整zip临时文件名称
// File zipTemp = new File(tw001GenerateBo.getWorkFilePath() + zipTempFileName);
// fos = new FileOutputStream(zipTemp);
// zipUtils.toZip(filesList, fos);
// }catch(Exception ex){
// log.error("生成压缩包错误:{}",ex.getMessage(),ex);
// throw ex;
// }finally{
// try {
// if (fos != null) {
// fos.close();
// fos = null;
// }
// } catch (Exception e) {
// log.error(e.getMessage(),e);
// throw e;
// }
// }
// return zipFileName;
// }
//
// /**
// * @Author mt
// * @Description 功能说明 初始化json文件对象
// * @Date 2024/5/30
// * @param tw001GenerateBo
// * @param jsonFileName
// * @return void
// */
// private void initJsonFileInfo(Imp001GenerateBo tw001GenerateBo,String jsonFileName){
// SysDictionary jsonDic = tw001GenerateBo.getJsonDictionary();
// Imp001FileInfoBo fileInfoBo = new Imp001FileInfoBo();
// fileInfoBo.setFileName(jsonFileName);
// fileInfoBo.setFileTypeId(jsonDic.getId());
// fileInfoBo.setFileTypeName(jsonDic.getChineseName());
// fileInfoBo.setPushTime(new Date());
// tw001GenerateBo.getFileInfoList().add(fileInfoBo);
// }
//
// /**
// * @Author mt
// * @Description 功能说明 生成文件名称
// * @Date 2024/5/30
// * @param tw001GenerateBo
// * @param prefix 前缀
// * @param suffix 后缀
// * @return java.lang.String
// */
// private String generateJsonFileName(Imp001GenerateBo tw001GenerateBo,String prefix,String suffix){
// DeclareInfo declareInfo = tw001GenerateBo.getDeclareInfo();
// String fileName = prefix + declareInfo.getDeliveryNo() + Constant.COMMON_KEYS.UNDER_LINE
// + StringExtUtil.idLeftPadStr(declareInfo.getDeclareId()) + Constant.COMMON_KEYS.UNDER_LINE +
// DateUtil.yyyyMMddHH24mmssSSS(new Date()) + suffix;
// return fileName;
// }
//}
\ No newline at end of file
package com.fedex.connect.task.utils.biz.imp001;
import com.fedex.connect.common.dependencies.contants.BaseSeparatorConstants;
import com.fedex.connect.common.dependencies.contants.DigitConstants;
import com.fedex.connect.common.dependencies.util.*;
import com.fedex.connect.task.config.PropertiesConfig;
import com.fedex.connect.task.constants.Constant;
import com.fedex.connect.task.data.bo.Imp001GenerateBo;
import com.fedex.connect.task.data.dto.imp001.Imp001Files;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @Author mt
* @Description imp001报文推送,util
* @Date 2024/5/29
*/
@Slf4j
@Component
public class Imp001PushUtil {
@Autowired
PropertiesConfig propertiesConfig;
@Autowired
ZipUtils zipUtils;
@Autowired
NIOFileUtils nioFileUtils;
/**
* @Author mt
* @Description 推送imp001
* @Date 2024/11/21
* @param imp001GenerateBo
* @return void
*/
public void pushImp001(Imp001GenerateBo imp001GenerateBo) throws Exception{
long start = System.currentTimeMillis();
//生成zip临时文件到指定临时目录
String zipFileName = this.toZips(imp001GenerateBo);
//zip原始临时目录,zip为临时文件
String zipSourceTempFilePath = imp001GenerateBo.getWorkFilePath() + zipFileName + Constant.FILE_SUFFIX_KEYS.TEMP;
//推送zip文件最终目录
String zipTargetFilePath = propertiesConfig.getImp001PathFinal() + zipFileName;
//记录zip文件名称
imp001GenerateBo.setZipFileName(zipFileName);
//记录zip文件目标路径
imp001GenerateBo.setZipFileTargetPath(zipTargetFilePath);
//如果目录不存在则创建完整目录
nioFileUtils.mkdirs(propertiesConfig.getImp001PathFinal());
//推送zip临时文件到指定目标目录,复制文件到指定目录,采用
String zipTargetTempFilePath = zipTargetFilePath + Constant.FILE_SUFFIX_KEYS.TEMP;
//复制文件至目标目录,为临时文件
nioFileUtils.copyFile(zipSourceTempFilePath,zipTargetTempFilePath);
log.info("复制到目标目录完成 sourceTempFilePath : {} , targetTempFilePath : {} ",zipSourceTempFilePath,zipTargetTempFilePath);
//重命名为正式文件
nioFileUtils.moveFile(zipTargetTempFilePath,zipTargetFilePath);
log.info("重命名为正式文件成功 zipTargetTempFilePath : {} , zipTargetFilePath : {} ",zipTargetTempFilePath,zipTargetFilePath);
long end = System.currentTimeMillis();
log.info("运单号IMP001:{} 推送完成,总计耗时:{} ms",imp001GenerateBo.getConsignmentCode() ,(end - start));
}
/**
* @Author mt
* @Description 功能说明 生成zip临时文件到指定临时目录,将用户上传,以及生成的json文件打包进zip文件中
* @Date 2024/5/30
* @param imp001GenerateBo
* @return java.lang.String
*/
private String toZips(Imp001GenerateBo imp001GenerateBo) throws Exception{
/******************初始化需要压缩文件列表****************/
List<File> filesList = new ArrayList<File>();
//生成json文件名称
String jsonFileName = this.generateJsonFileName(imp001GenerateBo,"", Constant.FILE_SUFFIX_KEYS.JSON);
//生成json文件
JsonToJava.createJsonFile(JsonToJava.toJson(imp001GenerateBo.getImp001RootJsonDto()),
imp001GenerateBo.getWorkFilePath(), jsonFileName);
//获取json完整路径
String jsonFilePath = imp001GenerateBo.getWorkFilePath() + jsonFileName;
filesList.add(new File(jsonFilePath));
//文件名称
Imp001Files[] fileInfos = imp001GenerateBo.getFileInfos();
if(fileInfos != null && fileInfos.length > 0){
for (Imp001Files fileInfo : fileInfos) {
//文件如果存在则添加到文件集合中
File file = new File(imp001GenerateBo.getWorkFilePath() + fileInfo.getName());
if(file.exists()){
filesList.add(file);
}
}
}
//生成zip文件名称 .zip
String zipFileName = this.generateJsonFileName(imp001GenerateBo, Constant.IMP001_HEAD_KEYS.MESSAGE_CODE, Constant.FILE_SUFFIX_KEYS.ZIP);
//生成zip临时文件名称 .temp
String zipTempFileName = zipFileName + Constant.FILE_SUFFIX_KEYS.TEMP;
FileOutputStream fos = null;
try{
//完整zip临时文件名称
File zipTemp = new File(imp001GenerateBo.getWorkFilePath() + zipTempFileName);
fos = new FileOutputStream(zipTemp);
zipUtils.toZip(filesList, fos);
}catch(Exception ex){
log.error("生成压缩包错误:{}",ex.getMessage(),ex);
throw ex;
}finally{
try {
if (fos != null) {
fos.close();
fos = null;
}
} catch (Exception e) {
log.error(e.getMessage(),e);
throw e;
}
}
return zipFileName;
}
/**
* @Author mt
* @Description 功能说明 生成文件名称
* @Date 2024年12月18日
* @param imp001GenerateBo
* @param prefix 前缀
* @param suffix 后缀
* @return java.lang.String
*/
private String generateJsonFileName(Imp001GenerateBo imp001GenerateBo,String prefix,String suffix){
String fileName = prefix + imp001GenerateBo.getConsignmentCode() + BaseSeparatorConstants.SEPARATOR_UNDERLINE
+ StringExtUtil.idLeftPadStr(imp001GenerateBo.getConsignmentId(), DigitConstants.DIGIT_TEN) + BaseSeparatorConstants.SEPARATOR_UNDERLINE +
DateUtil.yyyyMMddHH24mmssSSS(new Date()) + suffix;
return fileName;
}
}
\ No newline at end of file
......
//package com.fedex.connect.task.utils.biz.imp001;
//
//import com.fedex.connect.common.model.biz.PushOb;
//import com.fedex.connect.task.config.PropertiesConfig;
//import com.fedex.connect.task.data.bo.Imp001GenerateBo;
//import com.fedex.export.common.enums.PushLogEnum;
//import com.fedex.export.common.util.DateUtil;
//import com.fedex.export.common.util.NioFileUtils;
//import com.fedex.export.common.util.Utils;
//import com.fedex.export.config.PropertiesConfig;
//import com.fedex.export.constants.Constant;
//import com.fedex.export.data.bo.Imp001GenerateBo;
//import com.fedex.export.repository.entity.DeclareInfo;
//import com.fedex.export.repository.entity.log.PushObDetail;
//import com.fedex.export.repository.entity.log.PushObLog;
//import com.fedex.export.repository.repo.business.IPushObLogRepository;
//import com.fedex.export.service.business.IPushObDetailService;
//import lombok.extern.slf4j.Slf4j;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//import java.util.Objects;
//
///**
// * @Author mt
// * @Description 类说明 推送tw001完成,记录日志,并且备份数据
// * @Date 2024/5/30
// */
//@Slf4j
//@Component
//public class Imp001RecordLogUtil {
// @Autowired
// PropertiesConfig propertiesConfig;
// @Autowired
// IPushObLogRepository pushObLogRepository;
// @Autowired
// IPushObDetailService pushObDetailService;
// @Autowired
// NioFileUtils nioFileUtils;
//
// /**
// * @Author mt
// * @Description 推送成功记录日志
// * @Date 2024/11/21
// * @param imp001GenerateBo
// * @param obLog
// * @return void
// */
// public void pushSuccessRecordLog(Imp001GenerateBo imp001GenerateBo, PushOb obLog){
// try {
// if(Objects.nonNull(imp001GenerateBo)){
// //备份文件,并且记录日志
// String targetPath = this.recordLog(imp001GenerateBo,obLog , propertiesConfig.getTw001PathBak(),PushLogEnum.PUSHED_SUCCESS,null);
// obLog.setFileName(imp001GenerateBo.getZipFileName());
// obLog.setFilePath(imp001GenerateBo.getZipFileTargetPath());
// obLog.setFileBackPath(targetPath);
// }
// obLog.setPushNum(obLog.getPushNum() + 1);
// obLog.setPushStatus(PushLogEnum.PUSHED_SUCCESS.getKey());
// obLog.setPushStatusDescribe(PushLogEnum.PUSHED_SUCCESS.getValue());
// obLog.setPushTime(new Date());
// obLog.setRemark("");
// //更新推送日志主表
// pushObLogRepository.updateById(obLog);
// }catch(Exception ex){
// log.error("pushSuccessRecordLog : {} " ,ex.getMessage(),ex);
// }
// }
//
// /**
// * @Author mt
// * @Description 功能说明 推送失败记录日志
// * @Date 2024/5/30
// * @param tw001GenerateBo
// * @param errorMsg
// * @return void
// */
// public void pushFailRecordLog(Imp001GenerateBo tw001GenerateBo, PushOb obLog, String errorMsg){
// try {
// if(Objects.nonNull(tw001GenerateBo)){
// //备份文件,并且记录失败日志
// String targetPath = this.recordLog(tw001GenerateBo,obLog,propertiesConfig.getTw001PathError(),PushLogEnum.PUSH_FAILED,errorMsg);
// obLog.setFileName(tw001GenerateBo.getZipFileName());
// obLog.setFilePath(tw001GenerateBo.getZipFileTargetPath());
// obLog.setFileBackPath(targetPath);
// }
// obLog.setPushNum(obLog.getPushNum() + 1);
// obLog.setPushStatus(PushLogEnum.PUSH_FAILED.getKey());
// obLog.setPushStatusDescribe(PushLogEnum.PUSH_FAILED.getValue());
// obLog.setPushTime(new Date());
// obLog.setRemark(errorMsg);
// //更新推送日志主表
// pushObLogRepository.updateById(obLog);
// }catch(Exception ex){
// log.error("pushFailRecordLog : {} " ,ex.getMessage(),ex);
// }
// }
//
// /**
// * @Author mt
// * @Description 功能说明 备份文件
// * @Date 2024/5/30
// * @param tw001GenerateBo
// * @param tarPath
// * @return 返回目标备份路径
// */
// private String recordLog(Imp001GenerateBo tw001GenerateBo,
// PushOb obLog,
// String tarPath,
// PushLogEnum pushLogEnum,
// String remark){
// String returnTargetPath = "";
// try{
// DeclareInfo declareInfo = tw001GenerateBo.getDeclareInfo();
// //文件原始路径
// String sourcePath = tw001GenerateBo.getWorkFilePath();
// //生成文件目标路径
// String targetPath = this.generateFilePath(declareInfo.getDeliveryNo(),declareInfo.getDeclareId(),tarPath);
// returnTargetPath = targetPath;
// //推送文件明细
// List<PushObDetail> pushObDetailList = new ArrayList<>();
// Utils.listOf(tw001GenerateBo.getFileInfoList()).stream().filter(Objects::nonNull).forEach(o->{
// try {
// //源文件完整路径
// String sPath = sourcePath + o.getFileName();
// //目标文件完整路径
// String tPath = targetPath + o.getFileName();
// //备份文件
// nioFileUtils.moveFile(sPath, tPath);
// //记录日志明细表
// PushObDetail pushObDetail = new PushObDetail();
// pushObDetail.setCreateTime(new Date());
// pushObDetail.setDeclareId(declareInfo.getDeclareId());
// pushObDetail.setDeliveryNo(declareInfo.getDeliveryNo());
// pushObDetail.setPushLogId(obLog.getId());
// pushObDetail.setPushStatus(pushLogEnum.getKey());
// pushObDetail.setPushStatusDescribe(pushLogEnum.getValue());
// pushObDetail.setFileTypeId(o.getFileTypeId());
// pushObDetail.setFileType(o.getFileTypeName());
// pushObDetail.setFileName(o.getFileName());
// pushObDetail.setPushTime(new Date());
// pushObDetail.setRemark(remark);
// pushObDetailList.add(pushObDetail);
// }catch(Exception ex){
// log.error("move file error : {} ",ex.getMessage(),ex);
// }
// });
// //批量插入推送日志明细
// pushObDetailService.batchInsert(pushObDetailList);
// log.info("batchInsert size : {} ",pushObDetailList.size());
// //zip包源文件完整路径
// String sPath = sourcePath + tw001GenerateBo.getZipFileName() + Constant.FILE_SUFFIX_KEYS.TEMP;
// //zip包目标文件完整路径
// String tPath = targetPath + tw001GenerateBo.getZipFileName();
// //备份zip包文件
// nioFileUtils.moveFile(sPath, tPath);
// //删除临时目录文件夹
// nioFileUtils.deleteDir(log,sourcePath,true);
// log.info("删除临时目录文件夹 sourcePath : {} ",sourcePath);
// }catch(Exception ex){
// log.error("recordLog error : {} ",ex.getMessage(),ex);
// }
// return returnTargetPath;
// }
//
// /**
// * @Author mt
// * @Description 功能说明 生成目标文件夹路径
// * @Date 2024/5/30
// * @param filePath
// * @return java.lang.String
// */
// private String generateFilePath(String deliveryNo,Long declareId,String filePath){
// String yyyyMMdd = DateUtil.format(new Date());
// String fileDir = filePath + yyyyMMdd + Constant.COMMON_KEYS.BACK_SLASH +
// deliveryNo + Constant.COMMON_KEYS.UNDER_LINE + declareId + Constant.COMMON_KEYS.BACK_SLASH;
// //如果目录不存在则创建完整目录
// nioFileUtils.mkdirs(fileDir);
// return fileDir;
// }
//}
package com.fedex.connect.task.utils.biz.imp001;
import com.fedex.connect.common.dependencies.contants.BaseSeparatorConstants;
import com.fedex.connect.common.dependencies.util.DateUtil;
import com.fedex.connect.common.dependencies.util.NIOFileUtils;
import com.fedex.connect.common.model.bi.DictionaryEntries;
import com.fedex.connect.common.model.biz.PushOb;
import com.fedex.connect.common.model.biz.PushObDetail;
import com.fedex.connect.task.config.PropertiesConfig;
import com.fedex.connect.task.constants.Constant;
import com.fedex.connect.task.data.bo.Imp001GenerateBo;
import com.fedex.connect.task.data.dto.imp001.Imp001Files;
import com.fedex.connect.task.repository.repo.biz.IPushObRepository;
import com.fedex.connect.task.service.biz.IPushObDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* @Author mt
* @Description 类说明 推送tw001完成,记录日志,并且备份数据
* @Date 2024/5/30
*/
@Slf4j
@Component
public class Imp001RecordLogUtil {
@Autowired
PropertiesConfig propertiesConfig;
@Autowired
IPushObRepository pushObLogRepository;
@Autowired
IPushObDetailService pushObDetailService;
@Autowired
NIOFileUtils nioFileUtils;
/**
* @Author mt
* @Description 推送成功记录日志
* @Date 2024/12/18
* @param imp001GenerateBo
* @param obLog
* @param pushSuccessEntries
* @return void
*/
public void pushSuccessRecordLog(Imp001GenerateBo imp001GenerateBo, PushOb obLog, DictionaryEntries pushSuccessEntries){
try {
if(Objects.nonNull(imp001GenerateBo)){
//备份文件,并且记录日志
String targetPath = this.recordLog(imp001GenerateBo,obLog , propertiesConfig.getImp001PathBak(),pushSuccessEntries,null);
obLog.setFileName(imp001GenerateBo.getZipFileName());
obLog.setFilePath(imp001GenerateBo.getZipFileTargetPath());
obLog.setFileBackPath(targetPath);
}
obLog.setPushNum(obLog.getPushNum() + 1);
obLog.setStatusCode(pushSuccessEntries.getCode());
obLog.setStatusName(pushSuccessEntries.getDescription());
obLog.setPushTime(new Date());
obLog.setRemark("");
//更新推送日志主表
pushObLogRepository.updateById(obLog);
}catch(Exception ex){
log.error("pushSuccessRecordLog : {} " ,ex.getMessage(),ex);
}
}
/**
* @Author mt
* @Description 推送失败记录日志
* @Date 2024/12/18
* @param tw001GenerateBo
* @param obLog
* @param pushFailedEntries
* @param errorMsg
* @return void
*/
public void pushFailRecordLog(Imp001GenerateBo tw001GenerateBo, PushOb obLog, DictionaryEntries pushFailedEntries, String errorMsg){
try {
if(Objects.nonNull(tw001GenerateBo)){
//备份文件,并且记录失败日志
String targetPath = this.recordLog(tw001GenerateBo,obLog,propertiesConfig.getImp001PathError(),pushFailedEntries,errorMsg);
obLog.setFileName(tw001GenerateBo.getZipFileName());
obLog.setFilePath(tw001GenerateBo.getZipFileTargetPath());
obLog.setFileBackPath(targetPath);
}
obLog.setPushNum(obLog.getPushNum() + 1);
obLog.setStatusCode(pushFailedEntries.getCode());
obLog.setStatusName(pushFailedEntries.getDescription());
obLog.setPushTime(new Date());
obLog.setRemark(errorMsg);
//更新推送日志主表
pushObLogRepository.updateById(obLog);
}catch(Exception ex){
log.error("pushFailRecordLog : {} " ,ex.getMessage(),ex);
}
}
/**
* @Author mt
* @Description 功能说明 备份文件
* @Date 2024/5/30
* @param tw001GenerateBo
* @param tarPath
* @return 返回目标备份路径
*/
private String recordLog(Imp001GenerateBo tw001GenerateBo,
PushOb obLog,
String tarPath,
DictionaryEntries pushStatusEntries,
String remark){
String returnTargetPath = "";
try{
//文件原始路径
String sourcePath = tw001GenerateBo.getWorkFilePath();
//生成文件目标路径
String targetPath = this.generateFilePath(tw001GenerateBo.getConsignmentCode(),tw001GenerateBo.getConsignmentId(),tarPath);
returnTargetPath = targetPath;
//推送文件明细
List<PushObDetail> pushObDetailList = new ArrayList<>();
Imp001Files[] fileInfos = tw001GenerateBo.getFileInfos();
for (Imp001Files fileInfo : fileInfos) {
try {
//源文件完整路径
String sPath = sourcePath + fileInfo.getName();
//目标文件完整路径
String tPath = targetPath + fileInfo.getName();
//备份文件
nioFileUtils.moveFile(sPath, tPath);
//记录日志明细表
PushObDetail pushObDetail = new PushObDetail();
pushObDetail.setCreateTime(new Date());
pushObDetail.setConsignmentId(tw001GenerateBo.getConsignmentId());
pushObDetail.setConsignmentCode(tw001GenerateBo.getConsignmentCode());
pushObDetail.setPushObId(obLog.getId());
pushObDetail.setStatusCode(pushStatusEntries.getCode());
pushObDetail.setStatusName(pushStatusEntries.getDescription());
pushObDetail.setFileType(fileInfo.getContentType());
pushObDetail.setFileName(fileInfo.getName());
pushObDetail.setPushTime(new Date());
pushObDetail.setRemark(remark);
pushObDetailList.add(pushObDetail);
}catch(Exception ex){
log.error("move file error : {} ",ex.getMessage(),ex);
}
}
//批量插入推送日志明细
pushObDetailService.batchInsert(pushObDetailList);
log.info("batchInsert size : {} ",pushObDetailList.size());
//zip包源文件完整路径
String sPath = sourcePath + tw001GenerateBo.getZipFileName() + Constant.FILE_SUFFIX_KEYS.TEMP;
//zip包目标文件完整路径
String tPath = targetPath + tw001GenerateBo.getZipFileName();
//备份zip包文件
nioFileUtils.moveFile(sPath, tPath);
//删除临时目录文件夹
nioFileUtils.deleteDir(log,sourcePath,true);
log.info("删除临时目录文件夹 sourcePath : {} ",sourcePath);
}catch(Exception ex){
log.error("recordLog error : {} ",ex.getMessage(),ex);
}
return returnTargetPath;
}
/**
* @Author mt
* @Description 功能说明 生成目标文件夹路径
* @Date 2024/5/30
* @param filePath
* @return java.lang.String
*/
private String generateFilePath(String consignmentCode,Long consignmentId,String filePath){
String yyyyMMdd = DateUtil.format(new Date());
String fileDir = filePath + yyyyMMdd + BaseSeparatorConstants.SEPARATOR_SLASH +
consignmentCode + BaseSeparatorConstants.SEPARATOR_UNDERLINE + consignmentId + BaseSeparatorConstants.SEPARATOR_SLASH;
//如果目录不存在则创建完整目录
nioFileUtils.mkdirs(fileDir);
return fileDir;
}
}
......
......@@ -268,15 +268,15 @@ public class ConFileEmailUtil {
//如果失败次数小于三则更新为待处理,继续处理
if (result){
conPushEmail.setTypeCode(success.getCode());
conPushEmail.setTypeName(success.getEnglishName());
conPushEmail.setTypeName(success.getDescription());
}else {
if (conPushEmail.getSendNum()<3){
conPushEmail.setTypeCode(pending.getCode());
conPushEmail.setTypeName(pending.getEnglishName());
conPushEmail.setTypeName(pending.getDescription());
conPushEmail.setSendNum(conPushEmail.getSendNum()+1);
}else {
conPushEmail.setTypeCode(failed.getCode());
conPushEmail.setTypeName(failed.getEnglishName());
conPushEmail.setTypeName(failed.getDescription());
}
}
}
......
......@@ -122,15 +122,15 @@ public class DuplicateEmailUtil {
email.setSendTime(new Date());
if (result){
email.setStatusCode(success.getCode());
email.setStatusName(success.getEnglishName());
email.setStatusName(success.getDescription());
}else {
if (email.getSendNum()<3){
email.setStatusCode(pending.getCode());
email.setStatusName(pending.getEnglishName());
email.setStatusName(pending.getDescription());
email.setSendNum(email.getSendNum()+1);
}else {
email.setStatusCode(failed.getCode());
email.setStatusName(failed.getEnglishName());
email.setStatusName(failed.getDescription());
}
}
}
......
......@@ -41,10 +41,10 @@ rpc:
rpcKafkaReceive1: http://localhost:8082/kafka-cndc-server/rpcKafka/rpcKafkaReceive
rpcKafkaReceive2: http://localhost:8082/kafka-cndc-server/rpcKafka/rpcKafkaReceive
tw001:
imp001:
path:
#基础路径
basePath: /var/share/icleartw/TWIMPORT/
basePath: /var/share/iClearPreCLR/ToIMPORT/
#json生成路径
work: ${tw001.path.basePath}work/
#zip输出目录
......
......@@ -21,10 +21,10 @@ rpc:
rpcKafkaReceive1: https://pjea0179.prod.apac.fedex.com:9002/icleartwkafka/rpcKafka/rpcKafkaReceive
rpcKafkaReceive2: https://pjea0180.prod.apac.fedex.com:9002/icleartwkafka/rpcKafka/rpcKafkaReceive
tw001:
imp001:
path:
#基础路径
basePath: /var/share/icleartw/TWIMPORT/
basePath: /var/share/iClearPreCLR/ToIMPORT/
#json生成路径
work: ${tw001.path.basePath}work/
#zip输出目录
......
......@@ -21,10 +21,10 @@ rpc:
rpcKafkaReceive1: http://47.103.140.98:7010/icleartwkafka/rpcKafka/rpcKafkaReceive
rpcKafkaReceive2: http://47.103.140.98:7010/icleartwkafka/rpcKafka/rpcKafkaReceive
tw001:
imp001:
path:
#基础路径
basePath: /app/Oracle/Middleware/user_projects/domains/base_domain/exportTw/TWIMPORT/
basePath: /app/Oracle/Middleware/user_projects/domains/base_domain/iClearPreCLR/ToIMPORT/
#json生成路径
work: ${tw001.path.basePath}work/
#zip输出目录
......
......@@ -21,10 +21,10 @@ rpc:
rpcKafkaReceive1: http://ujea0145.nonprod.apac.fedex.com:9001/icleartwkafka/rpcKafka/rpcKafkaReceive
rpcKafkaReceive2: http://ujea0146.nonprod.apac.fedex.com:9001/icleartwkafka/rpcKafka/rpcKafkaReceive
tw001:
imp001:
path:
#基础路径
basePath: /var/share/icleartw/TWIMPORT/
basePath: /var/share/iClearPreCLR/ToIMPORT/
#json生成路径
work: ${tw001.path.basePath}work/
#zip输出目录
......