Merge branch 'test' into prod

# Conflicts:
#	cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java
#	cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkShareBaseServiceImpl.java
This commit is contained in:
2026-01-31 16:22:16 +08:00
37 changed files with 550 additions and 441 deletions

View File

@@ -1,11 +1,11 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.service.GeoService;
import com.czg.exception.CzgException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;
@@ -49,7 +49,7 @@ public class GeoServiceImpl implements GeoService {
param.put("key", "7a7f2e4790ea222660a027352ee3af39");
param.put("keywords", keywords);
param.put("subdistrict", "1");
if (StringUtils.isNotBlank(subdistrict)) {
if (StrUtil.isNotBlank(subdistrict)) {
param.put("subdistrict", "2");
}
param.put("extensions", "base");

View File

@@ -459,7 +459,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
@Override
public BigDecimal updateAmount(Long id, BigDecimal amount) {
ShopInfo shopInfo = getShopInfo(id);
if (shopInfo.getAmount() == null || shopInfo.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
if (shopInfo.getAmount().add(amount).compareTo(BigDecimal.ZERO) < 0) {
throw new CzgException("更新失败");
}
boolean flag = mapper.updateAmount(id, amount);

View File

@@ -7,13 +7,13 @@ import com.czg.config.RedisCst;
import com.czg.exception.CzgException;
import com.czg.sa.StpKit;
import com.czg.service.RedisService;
import com.czg.utils.CzgRandomUtils;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.ShopSong;
import com.czg.account.service.ShopSongService;
import com.czg.service.account.mapper.ShopSongMapper;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.stereotype.Service;
/**
@@ -23,7 +23,7 @@ import org.springframework.stereotype.Service;
* @since 2025-03-01
*/
@Service
public class ShopSongServiceImpl extends ServiceImpl<ShopSongMapper, ShopSong> implements ShopSongService{
public class ShopSongServiceImpl extends ServiceImpl<ShopSongMapper, ShopSong> implements ShopSongService {
@Resource
private RedisService redisService;
@@ -49,18 +49,12 @@ public class ShopSongServiceImpl extends ServiceImpl<ShopSongMapper, ShopSong> i
public String getSongUrl(Long shopId) {
String code;
String key = RedisCst.getSongUrlKey(shopId);
if(redisService.hasKey(key)){
if (redisService.hasKey(key)) {
code = (String) redisService.get(key);
}else {
code = RandomStringUtils.randomAlphanumeric(12);
} else {
code = CzgRandomUtils.randomString(12);
redisService.set(key, code);
}
return code;
}
public static void main(String[] args) {
String string = RandomStringUtils.randomAlphanumeric(12);
System.out.println(string);
}
}

View File

@@ -18,7 +18,7 @@
and amount - #{money} >= 0
</update>
<update id="updateOneOrTwoAmount">
update tb_shop_user
update mk_distribution_invite
<set>
<if test="isOne != null and isOne == 1">
one_income = one_income + #{amount}
@@ -27,7 +27,7 @@
two_income = two_income + #{amount}
</if>
</set>
where id = #{shopUserId}
where shop_user_id = #{shopUserId} and shop_id = #{shopId}
</update>
@@ -256,10 +256,10 @@
</select>
<select id="getInviteUser" resultType="com.czg.market.vo.InviteUserVO">
SELECT
invite.id AS shopUserId,
invite.head_img AS headImg,
invite.nick_name AS shopUserName,
invite.phone AS shopUserPhone,
u.id AS shopUserId,
u.head_img AS headImg,
u.nick_name AS shopUserName,
u.phone AS shopUserPhone,
invite.one_income AS oneIncome,
invite.invite_time AS inviteTime,
dist.total_income AS totalIncome,
@@ -269,12 +269,14 @@
dist.status AS status,
dist.distribution_level_id AS levelId,
dist.distribution_level_name AS levelName,
invite.distribution_shops AS distributionShops
FROM tb_shop_user invite
left join mk_distribution_user dist on invite.id = dist.id and dist.shop_id = #{shopId}
WHERE invite.`parent_user_id` = #{distributionUserId}
u.distribution_shops AS distributionShops
FROM mk_distribution_invite invite
left join tb_shop_user u on invite.shop_user_id = u.id
left join mk_distribution_user dist on invite.shop_user_id = dist.id
WHERE invite.`parent_user_id` = #{distributionUserId} and invite.shop_id = #{shopId}
<if test="distributionLevelId != null">and dist.distribution_level_id = #{distributionLevelId}</if>
<if test="shopUserId != null">and invite.id = #{shopUserId}</if>
GROUP BY invite.id
ORDER BY invite.`invite_time` DESC
</select>
</mapper>

View File

@@ -0,0 +1,14 @@
package com.czg.service.market.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.market.entity.MkDistributionInvite;
/**
* 全民股东邀请关系 映射层。
*
* @author ww
* @since 2026-01-31
*/
public interface MkDistributionInviteMapper extends BaseMapper<MkDistributionInvite> {
}

View File

@@ -0,0 +1,22 @@
package com.czg.service.market.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.market.entity.MkDistributionInvite;
import com.czg.market.service.MkDistributionInviteService;
import com.czg.service.market.mapper.MkDistributionInviteMapper;
import org.springframework.stereotype.Service;
/**
* 全民股东邀请关系 服务层实现。
*
* @author ww
* @since 2026-01-31
*/
@Service
public class MkDistributionInviteServiceImpl extends ServiceImpl<MkDistributionInviteMapper, MkDistributionInvite> implements MkDistributionInviteService{
@Override
public MkDistributionInvite getByShopIdAndShopUserId(Long shopId, Long shopUserId) {
return getOne(query().eq(MkDistributionInvite::getShopId, shopId).eq(MkDistributionInvite::getShopUserId, shopUserId));
}
}

View File

@@ -76,6 +76,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
@Resource
private MkDistributionDeliverService distributionDeliverService;
@Resource
private MkDistributionInviteService distributionInviteService;
@Resource
private AppWxServiceImpl appWxService;
@DubboReference
private ShopUserService shopUserService;
@@ -148,9 +150,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
AssertUtil.isNull(shopUser, "店铺用户不存在");
UserInfo userInfo = userInfoService.getById(shopUser.getUserId());
result.put("cashOutAmount", userInfo.getDistributionAmount() == null ? 0.0 : userInfo.getDistributionAmount());
if (shopUser.getParentUserId() != null) {
MkDistributionUser mkDistributionUser = getMkDistributionUserByIdAndShopId(shopUser.getParentUserId(), shopId);
MkDistributionInvite invite = distributionInviteService.getByShopIdAndShopUserId(shopId, shopUser.getId());
if (invite != null && invite.getParentUserId() != null) {
MkDistributionUser mkDistributionUser = getMkDistributionUserByIdAndShopId(invite.getParentUserId(), shopId);
AssertUtil.isNull(mkDistributionUser, "上级分销员不存在");
ShopUser shopUserParent = shopUserService.getById(mkDistributionUser.getId());
result.put("parentName", shopUserParent.getNickName());
@@ -234,8 +236,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
public void bindInviteUser(MkDistributionUserDTO param) throws CzgException, ValidateException {
ShopUser shopUser = shopUserService.getById(param.getId());
AssertUtil.isNull(shopUser, "店铺用户不存在");
if (shopUser.getParentUserId() != null) {
throw new CzgException("店铺用户已绑定分销员");
MkDistributionInvite shopUserInvite = distributionInviteService.getByShopIdAndShopUserId(param.getShopId(), shopUser.getId());
if (shopUserInvite != null && shopUserInvite.getParentUserId() != null) {
throw new CzgException("店铺用户已存在上级");
}
MkDistributionUser parent = getOne(QueryWrapper.create().eq(MkDistributionUser::getInviteCode, param.getInviteCode()));
AssertUtil.isNull(parent, "邀请人不存在");
@@ -250,28 +253,28 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
}
ShopUser parentShopUser = shopUserService.getById(parent.getId());
AssertUtil.isNull(parentShopUser, "邀请人不存在");
MkDistributionInvite parentShopUserInvite = distributionInviteService.getByShopIdAndShopUserId(param.getShopId(), parentShopUser.getId());
if (parentShopUserInvite != null && parentShopUserInvite.getParentUserId() != null && parentShopUserInvite.getParentUserId().equals(shopUser.getId())) {
throw new CzgException("存在绑定关系,不可绑定");
}
if (parentShopUserInvite != null && parentShopUserInvite.getGradeUserId() != null && parentShopUserInvite.getGradeUserId().equals(shopUser.getId())) {
throw new CzgException("存在绑定关系,不可绑定");
}
if (parentShopUser.getParentUserId() != null && parentShopUser.getParentUserId().equals(shopUser.getId())) {
throw new CzgException("存在绑定关系,不可绑定");
}
if (parentShopUser.getGradeUserId() != null && parentShopUser.getGradeUserId().equals(shopUser.getId())) {
throw new CzgException("存在绑定关系,不可绑定");
}
//更新自己的上级
shopUser.setParentUserId(parentShopUser.getId());
shopUser.setGradeUserId(parentShopUser.getParentUserId());
ShopUser upShopUser1 = new ShopUser();
upShopUser1.setParentUserId(parentShopUser.getId());
upShopUser1.setGradeUserId(parentShopUser.getParentUserId());
upShopUser1.setInviteTime(LocalDateTime.now());
shopUserService.update(upShopUser1, QueryWrapper.create().eq(ShopUser::getId, shopUser.getId()));
if (shopUser.getParentUserId() != null) {
MkDistributionInvite newShopUserInvite = new MkDistributionInvite();
newShopUserInvite.setShopId(param.getShopId());
newShopUserInvite.setUserId(shopUser.getUserId());
newShopUserInvite.setShopUserId(shopUser.getId());
newShopUserInvite.setParentUserId(parentShopUser.getId());
newShopUserInvite.setGradeUserId(parentShopUserInvite == null ? null : parentShopUserInvite.getParentUserId());
newShopUserInvite.setInviteTime(LocalDateTime.now());
distributionInviteService.save(newShopUserInvite);
if (parentShopUserInvite != null && parentShopUserInvite.getParentUserId() != null) {
//更新自己的下级 的上级的上级 为自己的上级
ShopUser upShopUser = new ShopUser();
upShopUser.setGradeUserId(shopUser.getParentUserId());
shopUserService.update(upShopUser, QueryWrapper.create().eq(ShopUser::getParentUserId, shopUser.getId()));
MkDistributionInvite childShopUserInvite = new MkDistributionInvite();
childShopUserInvite.setGradeUserId(parentShopUser.getId());
distributionInviteService.update(childShopUserInvite, QueryWrapper.create().eq(MkDistributionInvite::getParentUserId, shopUser.getId()));
}
MkDistributionUser newDistributionUser = new MkDistributionUser();
@@ -320,14 +323,12 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
public void bindInviteUser(Long fromUserId, Long toUserId, Long shopId) throws CzgException, ValidateException {
ShopUser shopUser = shopUserService.getById(toUserId);
AssertUtil.isNull(shopUser, "店铺用户不存在");
if (shopUser.getParentUserId() != null) {
throw new CzgException("店铺用户已绑定上级");
MkDistributionInvite shopUserInvite = distributionInviteService.getByShopIdAndShopUserId(shopId, shopUser.getId());
if (shopUserInvite != null && shopUserInvite.getParentUserId() != null) {
throw new CzgException("店铺用户已存在上级");
}
MkDistributionUser parent = getOne(QueryWrapper.create().eq(MkDistributionUser::getId, fromUserId));
MkDistributionUser parent = getOne(QueryWrapper.create().eq(MkDistributionUser::getId, fromUserId).eq(MkDistributionUser::getShopId, shopId));
AssertUtil.isNull(parent, "邀请人不存在");
if (!parent.getShopId().equals(shopId)) {
throw new CzgException("邀请人不是本店铺的分销员");
}
if (parent.getId().equals(shopUser.getId())) {
throw new CzgException("不能绑定自己为上级");
}
@@ -337,28 +338,28 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
ShopUser parentShopUser = shopUserService.getById(parent.getId());
AssertUtil.isNull(parentShopUser, "邀请人不存在");
if (parentShopUser.getParentUserId() != null && parentShopUser.getParentUserId().equals(shopUser.getId())) {
MkDistributionInvite parentShopUserInvite = distributionInviteService.getByShopIdAndShopUserId(shopId, parentShopUser.getId());
if (parentShopUserInvite != null && parentShopUserInvite.getParentUserId() != null && parentShopUserInvite.getParentUserId().equals(shopUser.getId())) {
throw new CzgException("存在绑定关系,不可绑定");
}
if (parentShopUser.getGradeUserId() != null && parentShopUser.getGradeUserId().equals(shopUser.getId())) {
if (parentShopUserInvite != null && parentShopUserInvite.getGradeUserId() != null && parentShopUserInvite.getGradeUserId().equals(shopUser.getId())) {
throw new CzgException("存在绑定关系,不可绑定");
}
//更新自己的上级
shopUser.setParentUserId(parentShopUser.getId());
shopUser.setGradeUserId(parentShopUser.getParentUserId());
//更新自己的下级 的上级的上级 为自己的上级
ShopUser upShopUser1 = new ShopUser();
upShopUser1.setParentUserId(parentShopUser.getId());
upShopUser1.setGradeUserId(parentShopUser.getParentUserId());
upShopUser1.setInviteTime(LocalDateTime.now());
shopUserService.update(upShopUser1, QueryWrapper.create().eq(ShopUser::getId, shopUser.getId()));
if (shopUser.getParentUserId() != null) {
MkDistributionInvite newShopUserInvite = new MkDistributionInvite();
newShopUserInvite.setShopId(shopId);
newShopUserInvite.setUserId(shopUser.getUserId());
newShopUserInvite.setShopUserId(shopUser.getId());
newShopUserInvite.setParentUserId(parentShopUser.getId());
newShopUserInvite.setGradeUserId(parentShopUserInvite == null ? null : parentShopUserInvite.getParentUserId());
newShopUserInvite.setInviteTime(LocalDateTime.now());
distributionInviteService.save(newShopUserInvite);
if (parentShopUserInvite != null && parentShopUserInvite.getParentUserId() != null) {
//更新自己的下级 的上级的上级 为自己的上级
ShopUser upShopUser = new ShopUser();
upShopUser.setGradeUserId(shopUser.getParentUserId());
shopUserService.update(upShopUser, QueryWrapper.create().eq(ShopUser::getParentUserId, shopUser.getId()));
MkDistributionInvite childShopUserInvite = new MkDistributionInvite();
childShopUserInvite.setGradeUserId(parentShopUser.getId());
distributionInviteService.update(childShopUserInvite, QueryWrapper.create().eq(MkDistributionInvite::getParentUserId, shopUser.getId()));
}
MkDistributionUser newDistributionUser = new MkDistributionUser();
@@ -406,8 +407,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
public void costUpgradeLevelBefore(Long userId, Long shopId) {
ShopUser shopUser = shopUserService.getShopUserInfo(shopId, userId);
costUpgradeLevel(shopUser.getId(), shopId);
if (shopUser.getParentUserId() != null) {
costUpgradeLevel(shopUser.getParentUserId(), shopId);
MkDistributionInvite shopUserInvite = distributionInviteService.getByShopIdAndShopUserId(shopId, shopUser.getId());
if (shopUserInvite != null && shopUserInvite.getParentUserId() != null) {
costUpgradeLevel(shopUserInvite.getParentUserId(), shopId);
}
}
@@ -774,18 +776,19 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
AssertUtil.isTrue(config.getIsEnable() != 1, "分销未开启");
// 产生消费的用户
ShopUser curUser = shopUserService.getShopUserInfo(shopId, sourceUserId);
if (curUser == null || curUser.getParentUserId() == null) {
MkDistributionInvite sourceInviteUser = distributionInviteService.getByShopIdAndShopUserId(shopId, curUser.getId());
if (sourceInviteUser.getParentUserId() == null) {
return;
}
log.info("开始分销, 当前来源用户: {}, shopId: {}, 邀请人id: {}", sourceUserId, shopId, curUser.getParentUserId());
log.info("开始分销, 当前来源用户: {}, shopId: {}, 邀请人id: {}", sourceUserId, shopId, sourceInviteUser.getParentUserId());
MkDistributionUser distributionUser = getMkDistributionUserByIdAndShopId(curUser.getParentUserId(), shopId);
MkDistributionUser distributionUser = getMkDistributionUserByIdAndShopId(sourceInviteUser.getParentUserId(), shopId);
MkDistributionLevelConfig level = levelConfigService.getById(distributionUser.getDistributionLevelId());
deepReward(curUser, level.getCommission(), config, distributionUser,
amount, sourceId, type, orderNo, 1);
if (curUser.getGradeUserId() != null) {
MkDistributionUser parentDis = getMkDistributionUserByIdAndShopId(curUser.getGradeUserId(), shopId);
if (sourceInviteUser.getGradeUserId() != null) {
MkDistributionUser parentDis = getMkDistributionUserByIdAndShopId(sourceInviteUser.getGradeUserId(), shopId);
MkDistributionLevelConfig parentDisLevel = levelConfigService.getById(parentDis.getDistributionLevelId());
deepReward(curUser, parentDisLevel.getCommission().subtract(level.getCommission()), config, parentDis,
amount, sourceId, type, orderNo, 2);

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.market.mapper.MkDistributionInviteMapper">
</mapper>

View File

@@ -65,8 +65,10 @@
<select id="getOrderConsumeAmountByList" resultType="java.math.BigDecimal">
SELECT IFNULL(SUM(ord.pay_amount), 0) AS totalAmount
FROM tb_shop_user invite
INNER JOIN tb_order_info ord ON invite.user_id = ord.user_id
FROM mk_distribution_invite invite
INNER JOIN tb_shop_user su on invite.shop_user_id = su.id
INNER JOIN tb_order_info ord ON su.user_id = ord.user_id
and invite.shop_id = #{shopId}
AND ord.shop_id = #{shopId}
AND ord.STATUS = 'done'
AND ord.pay_type NOT IN ('vip_pay', 'credit_pay')

View File

@@ -1,18 +1,21 @@
package com.czg.service.order.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.czg.excel.ExcelExportUtil;
import com.czg.excel.SheetData;
import com.czg.order.param.TableSummaryParam;
import com.czg.order.service.TableSummaryService;
import com.czg.order.vo.TableSummaryExportVo;
import com.czg.service.order.mapper.ShopTableOrderStatisticMapper;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -27,9 +30,8 @@ public class TableSummaryServiceImpl implements TableSummaryService {
@Resource
private ShopTableOrderStatisticMapper shopTableOrderStatisticMapper;
@Override
public List<TableSummaryExportVo> summaryExportList(TableSummaryParam param) {
public void summaryExportList(TableSummaryParam param, HttpServletResponse response) {
if (param.getBeginDate() == null && param.getEndDate() == null) {
// 获取当前日期
LocalDate currentDate = LocalDate.now();
@@ -46,49 +48,103 @@ public class TableSummaryServiceImpl implements TableSummaryService {
param.setBeginDate(formattedStartDate + " 00:00:00");
param.setEndDate(formattedEndDate + " 23:59:59");
}
List<TableSummaryExportVo> list = shopTableOrderStatisticMapper.findSummaryExportList(param);
if (CollUtil.isEmpty(list)) {
return List.of();
ExcelExportUtil.exportToResponse(new ArrayList<>(), TableSummaryExportVo.class, "台桌统计", response);
return;
}
record TableSummary(String tableKey, BigDecimal totalSales, Map<Long, BigDecimal> productSales) {}
Map<String, TableSummary> summaryMap = list.stream()
// === Step 1: 按日期计算 当日总销售额 ===
Map<String, BigDecimal> dailyTotalMap = list.stream()
.collect(Collectors.groupingBy(
vo -> vo.getTableCode() + "_" + vo.getCreateDate(),
Collectors.collectingAndThen(
Collectors.toList(),
vos -> {
String tableKey = vos.getFirst().getTableCode() + "_" + vos.getFirst().getCreateDate();
BigDecimal totalSales = vos.stream()
.map(TableSummaryExportVo::getAmount)
.reduce(BigDecimal.ZERO, BigDecimal::add);
Map<Long, BigDecimal> productSales = vos.stream()
.collect(Collectors.groupingBy(
TableSummaryExportVo::getProductId,
Collectors.reducing(
BigDecimal.ZERO,
TableSummaryExportVo::getAmount,
BigDecimal::add
)
));
return new TableSummary(tableKey, totalSales, productSales);
}
)
TableSummaryExportVo::getCreateDate,
Collectors.reducing(BigDecimal.ZERO, TableSummaryExportVo::getAmount, BigDecimal::add)
));
list.forEach(vo -> {
TableSummary summary = summaryMap.get(vo.getTableConcatDate());
if (summary != null) {
vo.setTotalSalesAmount(summary.totalSales());
vo.setSalesAmount(summary.productSales().getOrDefault(vo.getProductId(), BigDecimal.ZERO));
}
});
// 追加个空行用于处理表格样式
TableSummaryExportVo nullVo = new TableSummaryExportVo();
list.add(nullVo);
return list;
// === Step 2: 按 台桌+日期 计算 每台桌当日销售额 ===
Map<String, BigDecimal> tableDailyTotalMap = list.stream()
.collect(Collectors.groupingBy(
vo -> vo.getTableCode() + "_" + vo.getCreateDate(),
Collectors.reducing(BigDecimal.ZERO, TableSummaryExportVo::getAmount, BigDecimal::add)
));
// === Step 3: 回填字段 ===
for (TableSummaryExportVo vo : list) {
String dateKey = vo.getCreateDate();
String tableDateKey = vo.getTableCode() + "_" + dateKey;
// 设置“总销售额” = 该台桌当天总销售额
vo.setSalesAmount(tableDailyTotalMap.getOrDefault(tableDateKey, BigDecimal.ZERO));
// 设置“当日总销售额” = 当天所有台桌总和
vo.setTotalSalesAmount(dailyTotalMap.getOrDefault(dateKey, BigDecimal.ZERO));
}
// === Step 4: 导出 ===
List<SheetWriteHandler> strategies = calculateMergeCells(list);
ExcelExportUtil.exportMultipleSheetsToResponse(
List.of(new SheetData()
.setData(list)
.setSheetName("台桌统计")
.setHandlers(strategies)
.setClazz(TableSummaryExportVo.class)),
"台桌统计",
response);
}
}
/**
* 计算需要合并的单元格信息
*/
private List<SheetWriteHandler> calculateMergeCells(List<TableSummaryExportVo> list) {
List<SheetWriteHandler> mergeInfos = new ArrayList<>();
if (CollUtil.isEmpty(list)) {
return mergeInfos;
}
// 按日期分组(用于合并“日期”和“当日总销售额”列)
Map<String, List<TableSummaryExportVo>> byDate = list.stream()
.collect(Collectors.groupingBy(TableSummaryExportVo::getCreateDate));
int currentRow = 1; // Excel 数据从第1行开始第0行为标题
// 按日期排序
List<String> sortedDates = byDate.keySet().stream().sorted().toList();
for (String date : sortedDates) {
List<TableSummaryExportVo> dateGroup = byDate.get(date);
int dateSize = dateGroup.size();
// 合并“日期”列第0列和“当日总销售额”列第9列
if (dateSize > 1) {
mergeInfos.add(ExcelExportUtil.createMergeStrategy(currentRow, currentRow + dateSize - 1, 0, 0));
mergeInfos.add(ExcelExportUtil.createMergeStrategy(currentRow, currentRow + dateSize - 1, 9, 9));
}
// 在日期组内,按台桌分组(用于合并“台桌”和“总销售额”列)
Map<String, List<TableSummaryExportVo>> byTable = dateGroup.stream()
.collect(Collectors.groupingBy(TableSummaryExportVo::getTableName));
int tableStartRow = currentRow;
List<String> sortedTables = byTable.keySet().stream().sorted().toList();
for (String table : sortedTables) {
List<TableSummaryExportVo> tableGroup = byTable.get(table);
int tableSize = tableGroup.size();
// 合并“台桌”列第1列和“总销售额”列第8列
if (tableSize > 1) {
mergeInfos.add(ExcelExportUtil.createMergeStrategy(tableStartRow, tableStartRow + tableSize - 1, 1, 1));
mergeInfos.add(ExcelExportUtil.createMergeStrategy(tableStartRow, tableStartRow + tableSize - 1, 8, 8));
}
tableStartRow += tableSize;
}
currentRow += dateSize;
}
return mergeInfos;
}
}

View File

@@ -277,7 +277,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
.setIsSale(getMainSkuIsSale(exportDTO))
.setGroupTitleName(proGroupDTO.getTitle())
.setGroupProductNumber(Optional.ofNullable(proGroupDTO.getNumber()).map(String::valueOf).orElse(""))
.setGroupProductName(good.getProName() + " " + good.getSkuName());
.setGroupProductName(good.getProName() + "-" + good.getSkuName());
dataList.add(pkgDto);
}
@@ -327,8 +327,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
}
private void addMergeHandler(List<SheetWriteHandler> handlers, int firstRow, int lastRow, int firstCol, int lastCol) {
OnceAbsoluteMergeStrategy strategy = new OnceAbsoluteMergeStrategy(firstRow, lastRow, firstCol, lastCol);
handlers.add(strategy);
handlers.add(ExcelExportUtil.createMergeStrategy(firstRow, lastRow, firstCol, lastCol));
}
@Override

View File

@@ -3,7 +3,9 @@ package com.czg.service.product.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.constants.SystemConstants;
import com.czg.excel.ExcelExportUtil;
import com.czg.exception.CzgException;
import com.czg.product.dto.ProductCategoryExportDTO;
import com.czg.product.dto.ShopProdCategoryDTO;
import com.czg.product.entity.ShopProdCategory;
import com.czg.product.service.ProductService;
@@ -16,6 +18,7 @@ import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@@ -62,6 +65,14 @@ public class ShopProdCategoryServiceImpl extends ServiceImpl<ShopProdCategoryMap
return super.listAs(queryWrapper, ShopProdCategoryDTO.class);
}
@Override
public void exportShopProdCategory(ShopProdCategoryDTO param, HttpServletResponse response) {
QueryWrapper queryWrapper = buildQueryWrapper(param);
queryWrapper.eq(ShopProdCategory::getStatus, SystemConstants.OneZero.ONE);
List<ProductCategoryExportDTO> exportList = listAs(queryWrapper, ProductCategoryExportDTO.class);
ExcelExportUtil.exportToResponse(exportList, ProductCategoryExportDTO.class, "商品分类列表", response);
}
@Override
public ShopProdCategoryDTO getShopProdCategoryById(Long id) {
Long shopId = StpKit.USER.getShopId(0L);

View File

@@ -3,7 +3,9 @@ package com.czg.service.product.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.constants.SystemConstants;
import com.czg.excel.ExcelExportUtil;
import com.czg.exception.CzgException;
import com.czg.product.dto.ProductUnitExportDTO;
import com.czg.product.dto.ShopProdUnitDTO;
import com.czg.product.entity.ShopProdUnit;
import com.czg.product.enums.UnitTypeEnum;
@@ -15,6 +17,7 @@ import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Service;
import java.util.List;
@@ -59,6 +62,14 @@ public class ShopProdUnitServiceImpl extends ServiceImpl<ShopProdUnitMapper, Sho
return super.listAs(queryWrapper, ShopProdUnitDTO.class);
}
@Override
public void exportShopProdUnit(ShopProdUnitDTO param, HttpServletResponse response) {
QueryWrapper queryWrapper = buildQueryWrapper(param);
queryWrapper.eq(ShopProdUnit::getStatus,SystemConstants.OneZero.ONE);
List<ProductUnitExportDTO> unitExportDTOList = listAs(queryWrapper, ProductUnitExportDTO.class);
ExcelExportUtil.exportToResponse(unitExportDTOList, ProductUnitExportDTO.class, "单位列表", response);
}
@Override
public ShopProdUnitDTO getShopProdUnitById(Long id) {
Long shopId = StpKit.USER.getShopId(0L);