Commit fe32c604 authored by huangcb's avatar huangcb

增加银联获取对账单、更新公钥定时任务

parent eb656d8d
......@@ -2,6 +2,7 @@ package com.esv.freight.customer.common.unionpay;
import com.esv.freight.customer.common.constants.SDKConstants;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import java.io.*;
import java.nio.ByteBuffer;
......@@ -516,8 +517,7 @@ public class SDKUtil {
* @param encoding
* @return
*/
public static int getEncryptCert(Map<String, String> resData,
String encoding) {
public static int getEncryptCert(Map<String, String> resData, String encoding) {
String strCert = resData.get(SDKConstants.param_encryptPubKeyCert);
String certType = resData.get(SDKConstants.param_certType);
if (isEmpty(strCert) || isEmpty(certType)) {
......@@ -526,8 +526,7 @@ public class SDKUtil {
X509Certificate x509Cert = CertUtil.genCertificateByStr(strCert);
if (SDKConstants.CERTTYPE_01.equals(certType)) {
// 更新敏感信息加密公钥
if (!CertUtil.getEncryptCertId().equals(
x509Cert.getSerialNumber().toString())) {
if (!CertUtil.getEncryptCertId().equals(x509Cert.getSerialNumber().toString())) {
// ID不同时进行本地证书更新操作
String localCertPath = SDKConfig.getConfig().getEncryptCertPath();
String newLocalCertPath = genBackupName(localCertPath);
......@@ -695,10 +694,14 @@ public class SDKUtil {
int i = fileName.lastIndexOf(SDKConstants.POINT);
String leftFileName = fileName.substring(0, i);
String rightFileName = fileName.substring(i + 1);
String newFileName = leftFileName + "_backup" + SDKConstants.POINT + rightFileName;
String newFileName = leftFileName + "_backup_" + getTodayStr() + SDKConstants.POINT + rightFileName;
return newFileName;
}
public static String getTodayStr() {
DateTime dateTime = new DateTime(new Date());
return dateTime.toString("yyyyMMdd");
}
public static byte[] readFileByNIO(String filePath) {
FileInputStream in = null;
......
......@@ -121,7 +121,7 @@ public class UnionPayComponent {
throw new EException(ECode.THIRD_PARTY_ERROR.code(), "未定义异常");
}
} else {
log.error("验证签名失败");
log.error("[银联开放平台]验证签名失败");
throw new EException(ECode.THIRD_PARTY_ERROR.code(), "创建银联受理订单号失败");
}
} else {
......
package com.esv.freight.customer.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* @description: 定时任务配置
* @project: freight-customer-service
* @name: com.esv.freight.customer.config.ScheduleConfig
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/06/12 15:42
* @version:1.0
*/
@Configuration
@EnableScheduling
public class ScheduleConfig {
}
......@@ -30,7 +30,7 @@ public class DataPermHandler implements TenantHandler {
**/
private final List<String> filterTableNames = Arrays.asList(
"goods_owner_info", "goods_owner_audit_history", "goods_owner_delivery_address", "goods_owner_receive_address", "goods_owner_regularly_route",
"vehicle_audit_history", "vehicle_attachment", "driver_info", "driver_audit_history"
"vehicle_audit_history", "vehicle_attachment", "driver_info", "driver_audit_history", "unionpay_statement", "unionpay_public_cert_update"
);
@Override
......
......@@ -20,5 +20,5 @@ public interface PdfService {
* author HuangChaobin
* createTime 2020/05/28 20:17
**/
public void asyncSaveTargetFileInfo(String traceId, ContractOnlineRecordEntity entity, byte[] fileBytes);
void asyncSaveTargetFileInfo(String traceId, ContractOnlineRecordEntity entity, byte[] fileBytes);
}
......@@ -17,6 +17,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
......@@ -42,6 +43,7 @@ public class PdfServiceImpl implements PdfService {
private FeignFileService feignFileService;
@Autowired
@Lazy
private ContractOnlineRecordService contractOnlineRecordService;
@Value("${font.windows.dir}")
......
package com.esv.freight.customer.module.pay.dao;
import com.esv.freight.customer.module.pay.entity.UnionpayPublicCertUpdateEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 银联加密公钥更新记录表
*
* @author 黄朝斌
* @email huangchaobin@esvtek.com
* @date 2020-06-15 13:14:21
*/
@Mapper
public interface UnionpayPublicCertUpdateDao extends BaseMapper<UnionpayPublicCertUpdateEntity> {
}
package com.esv.freight.customer.module.pay.dao;
import com.esv.freight.customer.module.pay.entity.UnionpayStatementEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 银联对账单表
*
* @author 黄朝斌
* @email huangchaobin@esvtek.com
* @date 2020-06-12 15:34:12
*/
@Mapper
public interface UnionpayStatementDao extends BaseMapper<UnionpayStatementEntity> {
}
package com.esv.freight.customer.module.pay.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* 银联加密公钥更新记录表
*
* @author 黄朝斌
* @email huangchaobin@esvtek.com
* @date 2020-06-15 13:14:21
*/
@Data
@TableName("unionpay_public_cert_update")
public class UnionpayPublicCertUpdateEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
@TableId
private Long id;
/**
* 更新日期(yyyyMMdd)
*/
private String updateDate;
/**
* 更新结果:0-成功、1-无更新、2-更新失败、3-更新异常
*/
private Integer updateResult;
/**
* 创建时间
*/
private Date createTime;
/**
* 修改时间
*/
private Date updateTime;
}
package com.esv.freight.customer.module.pay.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* 银联对账单表
*
* @author 黄朝斌
* @email huangchaobin@esvtek.com
* @date 2020-06-12 15:34:12
*/
@Data
@TableName("unionpay_statement")
public class UnionpayStatementEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
@TableId
private Long id;
/**
* 账单类型:1-手机支付控件、2-在线网关支付
*/
private Integer statementCategory;
/**
* 对账单日期(yyyyMMdd)
*/
private String statementDate;
/**
* 对账单压缩包文件ID
*/
private Long zipId;
/**
* 对账单压缩包文件URL
*/
private String zipUrl;
/**
* 对账单明细文件ID
*/
private Long detailId;
/**
* 对账单明细文件URL
*/
private String detailUrl;
/**
* 对账单汇总文件ID
*/
private Long summaryId;
/**
* 对账单汇总文件URL
*/
private String summaryUrl;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private Date createTime;
}
package com.esv.freight.customer.module.pay.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.esv.freight.customer.module.pay.entity.UnionpayPublicCertUpdateEntity;
/**
* 银联加密公钥更新记录表
*
* @author 黄朝斌
* @email huangchaobin@esvtek.com
* @date 2020-06-15 13:14:21
*/
public interface UnionpayPublicCertUpdateService extends IService<UnionpayPublicCertUpdateEntity> {
/**
* description 保存记录
* param []
* return java.lang.Integer
* author HuangChaobin
* createTime 2020/06/15 13:19
**/
Integer saveRecord(UnionpayPublicCertUpdateEntity entity);
}
package com.esv.freight.customer.module.pay.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.esv.freight.customer.module.pay.entity.UnionpayStatementEntity;
/**
* 银联对账单表
*
* @author 黄朝斌
* @email huangchaobin@esvtek.com
* @date 2020-06-12 15:34:12
*/
public interface UnionpayStatementService extends IService<UnionpayStatementEntity> {
/**
* description 通过对账单日期查询记录
* param [date]
* return com.esv.freight.customer.module.pay.entity.UnionpayStatementEntity
* author HuangChaobin
* createTime 2020/06/12 16:09
**/
UnionpayStatementEntity getRecordByDate(String date);
}
package com.esv.freight.customer.module.pay.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.esv.freight.customer.module.pay.dao.UnionpayPublicCertUpdateDao;
import com.esv.freight.customer.module.pay.entity.UnionpayPublicCertUpdateEntity;
import com.esv.freight.customer.module.pay.service.UnionpayPublicCertUpdateService;
import org.springframework.stereotype.Service;
@Service("unionpayPublicCertUpdateService")
public class UnionpayPublicCertUpdateServiceImpl extends ServiceImpl<UnionpayPublicCertUpdateDao, UnionpayPublicCertUpdateEntity> implements UnionpayPublicCertUpdateService {
@Override
public Integer saveRecord(UnionpayPublicCertUpdateEntity entity) {
UnionpayPublicCertUpdateEntity dbEntity = this.baseMapper.selectOne(new LambdaQueryWrapper<UnionpayPublicCertUpdateEntity>()
.eq(UnionpayPublicCertUpdateEntity::getUpdateDate, entity.getUpdateDate()));
if (null == dbEntity) {
return this.baseMapper.insert(entity);
} else {
entity.setId(dbEntity.getId());
return this.baseMapper.updateById(entity);
}
}
}
\ No newline at end of file
package com.esv.freight.customer.module.pay.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.esv.freight.customer.module.pay.dao.UnionpayStatementDao;
import com.esv.freight.customer.module.pay.entity.UnionpayStatementEntity;
import com.esv.freight.customer.module.pay.service.UnionpayStatementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("unionpayStatementService")
public class UnionpayStatementServiceImpl extends ServiceImpl<UnionpayStatementDao, UnionpayStatementEntity> implements UnionpayStatementService {
@Override
public UnionpayStatementEntity getRecordByDate(String date) {
return this.baseMapper.selectOne(new LambdaQueryWrapper<UnionpayStatementEntity>().eq(UnionpayStatementEntity::getStatementDate, date));
}
}
\ No newline at end of file
<?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.esv.freight.customer.module.pay.dao.UnionpayPublicCertUpdateDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.esv.freight.customer.module.pay.entity.UnionpayPublicCertUpdateEntity" id="unionpayPublicCertUpdateMap">
<result property="id" column="id"/>
<result property="updateDate" column="update_date"/>
<result property="updateResult" column="update_result"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
</resultMap>
</mapper>
\ No newline at end of file
<?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.esv.freight.customer.module.pay.dao.UnionpayStatementDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.esv.freight.customer.module.pay.entity.UnionpayStatementEntity" id="unionpayStatementMap">
<result property="id" column="id"/>
<result property="statementCategory" column="statement_category"/>
<result property="statementDate" column="statement_date"/>
<result property="zipId" column="zip_id"/>
<result property="zipUrl" column="zip_url"/>
<result property="detailId" column="detail_id"/>
<result property="detailUrl" column="detail_url"/>
<result property="summaryId" column="summary_id"/>
<result property="summaryUrl" column="summary_url"/>
<result property="createTime" column="create_time"/>
</resultMap>
</mapper>
\ No newline at end of file
......@@ -3,14 +3,18 @@ package com.esv.freight.customer;
import com.esv.freight.customer.common.constants.CommonConstants;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.junit.After;
import org.junit.Before;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import java.util.UUID;
/**
* @description:
* @project: freight-file-service
......@@ -34,6 +38,7 @@ public class BaseTestController {
@Before
public void before() {
this.initLogTraceId();
log.info("=================================== Test Start ===================================");
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
TEST_START_TIME = System.currentTimeMillis();
......@@ -61,4 +66,12 @@ public class BaseTestController {
return httpHeaders;
}
private void initLogTraceId() {
String traceId = MDC.get("traceId");
if (StringUtils.isBlank(traceId)) {
traceId = UUID.randomUUID().toString().replace("-", "");
MDC.put("traceId", traceId);
}
}
}
package com.esv.freight.customer.schedule;
import lombok.extern.slf4j.Slf4j;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.schedule.UnionpayTaskTest
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/06/12 17:01
* @version:1.0
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Transactional
@Rollback(false)
public class UnionpayTaskTest {
@Autowired
private UnionpayTask unionpayTask;
/**
* 对账单定时任务触发器
**/
@Test
public void a1_getStatementTaskTrigger_test() throws Exception {
unionpayTask.getStatementTaskTrigger();
}
/**
* 银联加密公钥更新
**/
@Test
public void b1_updateCertTaskTrigger_test() throws Exception {
unionpayTask.updateCertTaskTrigger();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment