进件
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package com.czg.service.order.dto;
|
||||
|
||||
import com.czg.dto.req.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
*/
|
||||
@Data
|
||||
public class AggregateMerchantVO extends AggregateMerchantDto{
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
private String errorMsg;
|
||||
|
||||
/**
|
||||
* {@link com.czg.PayCst.EntryStatus}
|
||||
* 微信状态
|
||||
* WAIT 待提交 INIT 待处理 AUDIT 审核中 SIGN 待签约 REJECTED 失败 FINISH 已完成
|
||||
*/
|
||||
private String wechatStatus;
|
||||
|
||||
/**
|
||||
* 微信进件错误信息
|
||||
*/
|
||||
private String wechatErrorMsg;
|
||||
/**
|
||||
* 微信进件签名地址
|
||||
*/
|
||||
private String wechatSignUrl;
|
||||
|
||||
/**
|
||||
* {@link com.czg.PayCst.EntryStatus}
|
||||
* 支付宝状态
|
||||
* WAIT 待提交 INIT 待处理 AUDIT 审核中 SIGN 待签约 REJECTED 失败 FINISH 已完成
|
||||
*/
|
||||
private String alipayStatus;
|
||||
|
||||
/**
|
||||
* 支付宝进件错误信息
|
||||
*/
|
||||
private String alipayErrorMsg;
|
||||
/**
|
||||
* 支付宝进件签名地址
|
||||
*/
|
||||
private String alipaySignUrl;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.order.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.order.entity.ShopDirectMerchant;
|
||||
|
||||
/**
|
||||
* 商户进件 映射层。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2026-01-07
|
||||
*/
|
||||
public interface ShopDirectMerchantMapper extends BaseMapper<ShopDirectMerchant> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.czg.service.order.service;
|
||||
import com.czg.dto.req.AggregateMerchantDto;
|
||||
import com.czg.service.order.dto.AggregateMerchantVO;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.order.entity.ShopDirectMerchant;
|
||||
|
||||
/**
|
||||
* 商户进件 服务层。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2026-01-07
|
||||
*/
|
||||
public interface ShopDirectMerchantService extends IService<ShopDirectMerchant> {
|
||||
|
||||
|
||||
AggregateMerchantVO getEntry(Long shopId);
|
||||
|
||||
boolean entryManager(AggregateMerchantDto reqDto);
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.io.unit.DataSizeUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.EntryManager;
|
||||
import com.czg.PayCst;
|
||||
import com.czg.config.RabbitPublisher;
|
||||
import com.czg.dto.req.*;
|
||||
import com.czg.service.order.dto.AggregateMerchantVO;
|
||||
import com.czg.utils.FunUtils;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.order.entity.ShopDirectMerchant;
|
||||
import com.czg.service.order.service.ShopDirectMerchantService;
|
||||
import com.czg.service.order.mapper.ShopDirectMerchantMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* 商户进件 服务层实现。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2026-01-07
|
||||
*/
|
||||
@Service
|
||||
public class ShopDirectMerchantServiceImpl extends ServiceImpl<ShopDirectMerchantMapper, ShopDirectMerchant> implements ShopDirectMerchantService {
|
||||
|
||||
@Resource
|
||||
private RabbitPublisher rabbitPublisher;
|
||||
// 全局原子计数器,按天重置(避免数值过大)
|
||||
private static final AtomicLong COUNTER = new AtomicLong(0);
|
||||
// 记录上一次的日期,用于重置计数器
|
||||
private static String LAST_DATE = DateUtil.format(new Date(), "yyyyMMdd");
|
||||
|
||||
@Override
|
||||
public AggregateMerchantVO getEntry(Long shopId) {
|
||||
ShopDirectMerchant merchant = getById(shopId);
|
||||
if (merchant == null) {
|
||||
return null;
|
||||
}
|
||||
return convertVO(merchant);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean entryManager(AggregateMerchantDto reqDto) {
|
||||
boolean isSave = false;
|
||||
boolean result;
|
||||
if (StrUtil.isBlank(reqDto.getMerchantCode())) {
|
||||
reqDto.setMerchantCode(getMerchantCode());
|
||||
isSave = true;
|
||||
}
|
||||
EntryManager.verifyEntryParam(reqDto);
|
||||
|
||||
|
||||
ShopDirectMerchant merchant = new ShopDirectMerchant();
|
||||
merchant.setShopId(reqDto.getShopId());
|
||||
merchant.setMerchantCode(reqDto.getMerchantCode());
|
||||
merchant.setLicenceNo(reqDto.getBusinessLicenceInfo().getLicenceNo());
|
||||
|
||||
merchant.setMerchantBaseInfo(JSONObject.toJSONString(reqDto.getMerchantBaseInfo()));
|
||||
merchant.setLegalPersonInfo(JSONObject.toJSONString(reqDto.getLegalPersonInfo()));
|
||||
merchant.setBusinessLicenceInfo(JSONObject.toJSONString(reqDto.getBusinessLicenceInfo()));
|
||||
merchant.setStoreInfo(JSONObject.toJSONString(reqDto.getStoreInfo()));
|
||||
merchant.setSettlementInfo(JSONObject.toJSONString(reqDto.getSettlementInfo()));
|
||||
merchant.setWechatStatus(PayCst.EntryStatus.WAIT);
|
||||
merchant.setAlipayStatus(PayCst.EntryStatus.WAIT);
|
||||
if (isSave) {
|
||||
result = save(merchant);
|
||||
} else {
|
||||
result = updateById(merchant);
|
||||
}
|
||||
//发送进件队列消息
|
||||
FunUtils.transactionSafeRun(() -> rabbitPublisher.sendEntryManagerMsg(reqDto.getShopId().toString()));
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String getMerchantCode() {
|
||||
Date now = new Date();
|
||||
// 1. 获取当前日期(yyyyMMdd)
|
||||
String currentDate = DateUtil.format(now, "yyyyMMdd");
|
||||
// 2. 每天重置计数器,避免数值溢出
|
||||
synchronized (COUNTER) {
|
||||
if (!currentDate.equals(LAST_DATE)) {
|
||||
COUNTER.set(0);
|
||||
LAST_DATE = currentDate;
|
||||
}
|
||||
}
|
||||
// 3. 原子递增,获取唯一序号(同一毫秒内不会重复)
|
||||
long seq = COUNTER.incrementAndGet();
|
||||
// 4. 时间戳(毫秒级)+ 6位序号(补零)
|
||||
String timeStr = DateUtil.format(now, "yyyyMMddHHmmss");
|
||||
String seqStr = String.format("%03d", seq);
|
||||
return "CZG" + timeStr + seqStr;
|
||||
}
|
||||
|
||||
|
||||
public AggregateMerchantVO convertVO(ShopDirectMerchant entity) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AggregateMerchantVO vo = new AggregateMerchantVO();
|
||||
vo.setShopId(entity.getShopId());
|
||||
vo.setMerchantCode(entity.getMerchantCode());
|
||||
|
||||
// 解析JSON字段
|
||||
vo.setMerchantBaseInfo(JSONObject.parseObject(entity.getMerchantBaseInfo(), MerchantBaseInfoDto.class));
|
||||
vo.setLegalPersonInfo(JSONObject.parseObject(entity.getLegalPersonInfo(), LegalPersonInfoDto.class));
|
||||
vo.setBusinessLicenceInfo(JSONObject.parseObject(entity.getBusinessLicenceInfo(), BusinessLicenceInfoDto.class));
|
||||
vo.setStoreInfo(JSONObject.parseObject(entity.getStoreInfo(), StoreInfoDto.class));
|
||||
vo.setSettlementInfo(JSONObject.parseObject(entity.getSettlementInfo(), SettlementInfoDto.class));
|
||||
|
||||
// 设置其他字段
|
||||
vo.setCreateTime(entity.getCreateTime());
|
||||
vo.setUpdateTime(entity.getUpdateTime());
|
||||
vo.setWechatStatus(entity.getWechatStatus());
|
||||
vo.setWechatErrorMsg(entity.getWechatErrorMsg());
|
||||
vo.setWechatSignUrl(entity.getWechatSignUrl());
|
||||
vo.setAlipayStatus(entity.getAlipayStatus());
|
||||
vo.setAlipayErrorMsg(entity.getAlipayErrorMsg());
|
||||
vo.setAlipaySignUrl(entity.getAlipaySignUrl());
|
||||
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?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.czg.service.order.mapper.ShopDirectMerchantMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user