This commit is contained in:
2026-01-08 10:49:30 +08:00
parent 21b9acf3c9
commit e5be277941
39 changed files with 1290 additions and 46 deletions

View File

@@ -324,6 +324,15 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
return false;
}
@Override
@CacheEvict(key = "#shopId")
public Boolean editEntry(Long shopId, String wechatMerchantId, String alipayMerchantId) {
ShopInfo shopInfo = new ShopInfo();
shopInfo.setWechatMerchantId(wechatMerchantId);
shopInfo.setAlipayMerchantId(alipayMerchantId);
return update(shopInfo, new QueryWrapper().eq(ShopInfo::getId, shopId));
}
@Override
public ShopDetailDTO detail(Long id) throws CzgException {
ShopInfo shopInfo = queryChain().eq(ShopInfo::getId, id == null ? StpKit.USER.getShopId() : id).one();

View File

@@ -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;
}

View File

@@ -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> {
}

View File

@@ -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);
}

View File

@@ -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;
}
}

View File

@@ -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>

View File

@@ -26,6 +26,11 @@
<artifactId>czg-pay</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.czg</groupId>
<artifactId>aggregation-pay</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,14 @@
package com.czg.service.system.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.system.entity.SysBankInfo;
/**
* 银行账户信息表 映射层。
*
* @author ww
* @since 2026-01-06
*/
public interface SysBankInfoMapper extends BaseMapper<SysBankInfo> {
}

View File

@@ -0,0 +1,14 @@
package com.czg.service.system.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.system.entity.SysCategoryInfo;
/**
* 类目信息表 映射层。
*
* @author ww
* @since 2026-01-06
*/
public interface SysCategoryInfoMapper extends BaseMapper<SysCategoryInfo> {
}

View File

@@ -0,0 +1,14 @@
package com.czg.service.system.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.system.entity.SysRegion;
/**
* 行政区表 映射层。
*
* @author ww
* @since 2026-01-06
*/
public interface SysRegionMapper extends BaseMapper<SysRegion> {
}

View File

@@ -0,0 +1,26 @@
package com.czg.service.system.service.impl;
import com.czg.BaseQueryParam;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.system.entity.SysBankInfo;
import com.czg.system.service.SysBankInfoService;
import com.czg.service.system.mapper.SysBankInfoMapper;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 银行账户信息表 服务层实现。
*
* @author ww
* @since 2026-01-06
*/
@Service
public class SysBankInfoServiceImpl extends ServiceImpl<SysBankInfoMapper, SysBankInfo> implements SysBankInfoService {
@Override
public Page<SysBankInfo> bankInfoList(BaseQueryParam param, String bankName) {
return page(Page.of(param.getPage(), param.getSize()), query().like(SysBankInfo::getBankAlias, bankName));
}
}

View File

@@ -0,0 +1,43 @@
package com.czg.service.system.service.impl;
import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.collection.CollUtil;
import com.czg.system.vo.SysCategoryInfoVO;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.system.entity.SysCategoryInfo;
import com.czg.system.service.SysCategoryInfoService;
import com.czg.service.system.mapper.SysCategoryInfoMapper;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 类目信息表 服务层实现。
*
* @author ww
* @since 2026-01-06
*/
@Service
public class SysCategoryInfoServiceImpl extends ServiceImpl<SysCategoryInfoMapper, SysCategoryInfo> implements SysCategoryInfoService {
@Cacheable(value = "common:category", key = "'all'")
@Override
public List<SysCategoryInfoVO> categoryList() {
List<SysCategoryInfo> list = list();
if (CollUtil.isEmpty(list)) {
return List.of();
}
List<SysCategoryInfoVO> result = new ArrayList<>();
Map<String, List<SysCategoryInfo>> stringListMap = CollStreamUtil.groupByKey(list, SysCategoryInfo::getFirstCategory);
stringListMap.forEach((k, v) -> {
SysCategoryInfoVO vo = new SysCategoryInfoVO();
vo.setFirstCategory(k);
vo.setChild(v);
result.add(vo);
});
return result;
}
}

View File

@@ -0,0 +1,56 @@
package com.czg.service.system.service.impl;
import com.czg.service.system.mapper.SysRegionMapper;
import com.czg.system.entity.SysRegion;
import com.czg.system.service.SysRegionService;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 行政区表 服务层实现。
*
* @author ww
* @since 2026-01-06
*/
@Service
public class SysRegionServiceImpl extends ServiceImpl<SysRegionMapper, SysRegion> implements SysRegionService {
@Cacheable(value = "common:region", key = "'all'")
@Override
public List<SysRegion> regionList() {
// 1. 单次查询获取所有数据
List<SysRegion> allRegions = list(query().ne(SysRegion::getRegionLevel, 1));
// 2. 一次性按层级分组,减少流遍历次数
Map<Integer, List<SysRegion>> regionByLevel = allRegions.stream()
.collect(Collectors.groupingBy(SysRegion::getRegionLevel));
// 3. 获取各层级数据,默认空列表避免空指针
List<SysRegion> parents = regionByLevel.getOrDefault(2, List.of());
List<SysRegion> level3Regions = regionByLevel.getOrDefault(3, List.of());
List<SysRegion> level4Regions = regionByLevel.getOrDefault(4, List.of());
// 4. 构建3级地区的子节点映射4级使用HashMap保证性能
Map<String, List<SysRegion>> level4ByParentId = level4Regions.stream()
.collect(Collectors.groupingBy(SysRegion::getParentRegionId, Collectors.toList()));
level3Regions.forEach(level3 -> {
List<SysRegion> children = level4ByParentId.getOrDefault(level3.getRegionId(), List.of());
level3.setChildren(children);
});
Map<String, List<SysRegion>> level3ByParentId = level3Regions.stream()
.collect(Collectors.groupingBy(SysRegion::getParentRegionId));
parents.forEach(parent -> {
List<SysRegion> children = level3ByParentId.getOrDefault(parent.getRegionId(), List.of());
parent.setChildren(children);
});
return parents;
}
}

View File

@@ -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.system.mapper.SysBankInfoMapper">
</mapper>

View File

@@ -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.system.mapper.SysCategoryInfoMapper">
</mapper>

View File

@@ -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.system.mapper.SysRegionMapper">
</mapper>