Merge remote-tracking branch 'origin/feature/mall_product' into feature/mall_product

This commit is contained in:
jason 2023-10-16 22:43:54 +08:00
commit 34210d3534
92 changed files with 1244 additions and 878 deletions

2
sql/mysql/mall.sql Normal file
View File

@ -0,0 +1,2 @@
INSERT INTO system_menu (name, permission, type, sort, parent_id, path, icon, component, component_name)
VALUES ('商城首页', '', 2, 1, 2362, 'home', 'ep:home-filled', 'mall/home/index', 'MallHome');

1
sql/mysql/member.sql Normal file
View File

@ -0,0 +1 @@
ALTER TABLE member_user ADD COLUMN register_terminal tinyint NULL COMMENT '注册终端' AFTER register_ip;

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.framework.common.util.servlet;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil;
@ -27,7 +28,7 @@ public class ServletUtils {
* 返回 JSON 字符串
*
* @param response 响应
* @param object 对象会序列化成 JSON 字符串
* @param object 对象会序列化成 JSON 字符串
*/
@SuppressWarnings("deprecation") // 必须使用 APPLICATION_JSON_UTF8_VALUE否则会乱码
public static void writeJSON(HttpServletResponse response, Object object) {
@ -40,7 +41,7 @@ public class ServletUtils {
*
* @param response 响应
* @param filename 文件名
* @param content 附件内容
* @param content 附件内容
*/
public static void writeAttachment(HttpServletResponse response, String filename, byte[] content) throws IOException {
// 设置 header contentType
@ -88,6 +89,18 @@ public class ServletUtils {
return ServletUtil.getClientIP(request);
}
public static Integer getTerminal() {
return getHeaderInt("terminal");
}
public static String getHeader(String header) {
return getHeader(getRequest(), header);
}
public static Integer getHeaderInt(String header) {
return Convert.toInt(getHeader(header));
}
public static boolean isJsonRequest(ServletRequest request) {
return StrUtil.startWithIgnoreCase(request.getContentType(), MediaType.APPLICATION_JSON_VALUE);
}
@ -107,4 +120,12 @@ public class ServletUtils {
public static Map<String, String> getParamMap(HttpServletRequest request) {
return ServletUtil.getParamMap(request);
}
public static String getHeader(HttpServletRequest request, String header) {
if (request == null) {
return null;
}
return request.getHeader(header);
}
}

View File

@ -28,7 +28,7 @@ public interface CombinationRecordApi {
* 创建开团记录
*
* @param reqDTO 请求 DTO
* @return 团信息
* @return 团信息
*/
CombinationRecordCreateRespDTO createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO);

View File

@ -111,9 +111,10 @@ public interface ErrorCodeConstants {
ErrorCode BARGAIN_HELP_CREATE_FAIL_HELP_EXISTS = new ErrorCode(1_013_014_004, "助力失败,您已经助力过了");
// ========== 文章分类 1-013-015-000 ==========
ErrorCode ARTICLE_CATEGORY_NOT_EXISTS = new ErrorCode(1_013_015_000, "分类不存在");
ErrorCode ARTICLE_CATEGORY_NOT_EXISTS = new ErrorCode(1_013_015_000, "文章分类不存在");
ErrorCode ARTICLE_CATEGORY_DELETE_FAIL_HAVE_ARTICLES = new ErrorCode(1_013_015_001, "文章分类删除失败,存在关联文章");
// ========== 文章管理 1-013-016-000 ==========
ErrorCode ARTICLE_NOT_EXISTS = new ErrorCode(1_013_016_000, "文章管理不存在");
ErrorCode ARTICLE_NOT_EXISTS = new ErrorCode(1_013_016_000, "文章不存在");
}

View File

@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.promotion.controller.admin.article;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.*;
import cn.iocoder.yudao.module.promotion.convert.article.ArticleCategoryConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleCategoryDO;
@ -17,15 +15,11 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@Tag(name = "管理后台 - 文章分类")
@RestController
@ -65,23 +59,14 @@ public class ArticleCategoryController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('promotion:article-category:query')")
public CommonResult<ArticleCategoryRespVO> getArticleCategory(@RequestParam("id") Long id) {
ArticleCategoryDO articleCategory = articleCategoryService.getArticleCategory(id);
return success(ArticleCategoryConvert.INSTANCE.convert(articleCategory));
}
@GetMapping("/list")
@Operation(summary = "获得文章分类列表")
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
@PreAuthorize("@ss.hasPermission('promotion:article-category:query')")
public CommonResult<List<ArticleCategoryRespVO>> getArticleCategoryList(@RequestParam("ids") Collection<Long> ids) {
List<ArticleCategoryDO> list = articleCategoryService.getArticleCategoryList(ids);
return success(ArticleCategoryConvert.INSTANCE.convertList(list));
ArticleCategoryDO category = articleCategoryService.getArticleCategory(id);
return success(ArticleCategoryConvert.INSTANCE.convert(category));
}
@GetMapping("/list-all-simple")
@Operation(summary = "获取文章分类精简信息列表", description = "只包含被开启的文章分类,主要用于前端的下拉选项")
public CommonResult<List<ArticleCategorySimpleRespVO>> getSimpleDeptList() {
// 获得部门列表只要开启状态的
// 获得分类列表只要开启状态的
List<ArticleCategoryDO> list = articleCategoryService.getArticleCategoryListByStatus(CommonStatusEnum.ENABLE.getStatus());
// 降序排序后返回给前端
list.sort(Comparator.comparing(ArticleCategoryDO::getSort).reversed());
@ -96,16 +81,4 @@ public class ArticleCategoryController {
return success(ArticleCategoryConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/export-excel")
@Operation(summary = "导出文章分类 Excel")
@PreAuthorize("@ss.hasPermission('promotion:article-category:export')")
@OperateLog(type = EXPORT)
public void exportArticleCategoryExcel(@Valid ArticleCategoryExportReqVO exportReqVO,
HttpServletResponse response) throws IOException {
List<ArticleCategoryDO> list = articleCategoryService.getArticleCategoryList(exportReqVO);
// 导出 Excel
List<ArticleCategoryExcelVO> datas = ArticleCategoryConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "文章分类.xls", "数据", ArticleCategoryExcelVO.class, datas);
}
}

View File

@ -2,9 +2,10 @@ package cn.iocoder.yudao.module.promotion.controller.admin.article;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.*;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.convert.article.ArticleConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO;
import cn.iocoder.yudao.module.promotion.service.article.ArticleService;
@ -16,14 +17,9 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@Tag(name = "管理后台 - 文章管理")
@RestController
@ -67,15 +63,6 @@ public class ArticleController {
return success(ArticleConvert.INSTANCE.convert(article));
}
@GetMapping("/list")
@Operation(summary = "获得文章管理列表")
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
@PreAuthorize("@ss.hasPermission('promotion:article:query')")
public CommonResult<List<ArticleRespVO>> getArticleList(@RequestParam("ids") Collection<Long> ids) {
List<ArticleDO> list = articleService.getArticleList(ids);
return success(ArticleConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@Operation(summary = "获得文章管理分页")
@PreAuthorize("@ss.hasPermission('promotion:article:query')")
@ -84,16 +71,4 @@ public class ArticleController {
return success(ArticleConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/export-excel")
@Operation(summary = "导出文章管理 Excel")
@PreAuthorize("@ss.hasPermission('promotion:article:export')")
@OperateLog(type = EXPORT)
public void exportArticleExcel(@Valid ArticleExportReqVO exportReqVO,
HttpServletResponse response) throws IOException {
List<ArticleDO> list = articleService.getArticleList(exportReqVO);
// 导出 Excel
List<ArticleExcelVO> datas = ArticleConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "文章管理.xls", "数据", ArticleExcelVO.class, datas);
}
}

View File

@ -1,63 +0,0 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 文章管理 Excel VO
*
* @author HUIHUI
*/
@Data
public class ArticleExcelVO {
@ExcelProperty("文章编号")
private Long id;
@ExcelProperty("文章分类编号")
private Long categoryId;
@ExcelProperty("关联商品编号")
private Long spuId;
@ExcelProperty("文章标题")
private String title;
@ExcelProperty("文章作者")
private String author;
@ExcelProperty("文章封面图片地址")
private String picUrl;
@ExcelProperty("文章简介")
private String introduction;
@ExcelProperty("浏览次数")
private String browseCount;
@ExcelProperty("排序")
private Integer sort;
@ExcelProperty(value = "状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.COMMON_STATUS)
private Integer status;
@ExcelProperty("是否热门(小程序)")
private Boolean recommendHot;
@ExcelProperty("是否轮播图(小程序)")
private Boolean recommendBanner;
@ExcelProperty("文章内容")
private String content;
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -1,40 +0,0 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 文章管理 Excel 导出 Request VO参数和 ArticlePageReqVO 是一致的")
@Data
public class ArticleExportReqVO {
@Schema(description = "文章分类编号", example = "15458")
private Long categoryId;
@Schema(description = "关联商品编号", example = "22378")
private Long spuId;
@Schema(description = "文章标题")
private String title;
@Schema(description = "文章作者")
private String author;
@Schema(description = "状态", example = "2")
private Integer status;
@Schema(description = "是否热门(小程序)")
private Boolean recommendHot;
@Schema(description = "是否轮播图(小程序)")
private Boolean recommendBanner;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo;
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -34,6 +34,7 @@ public class ArticleBaseVO {
@Schema(description = "文章简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "这是一个简介")
private String introduction;
// TODO @puhui999浏览量的字段应该不是后端新增设置的哈
@Schema(description = "浏览次数", requiredMode = Schema.RequiredMode.REQUIRED, example = "111")
private String browseCount;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo;
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo;
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo;
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo;
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

View File

@ -1,39 +0,0 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 文章分类 Excel VO
*
* @author HUIHUI
*/
@Data
public class ArticleCategoryExcelVO {
@ExcelProperty("文章分类编号")
private Long id;
@ExcelProperty("文章分类名称")
private String name;
@ExcelProperty("图标地址")
private String picUrl;
@ExcelProperty(value = "状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.COMMON_STATUS)
private Integer status;
@ExcelProperty("排序")
private Integer sort;
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -1,25 +0,0 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 文章分类 Excel 导出 Request VO参数和 ArticleCategoryPageReqVO 是一致的")
@Data
public class ArticleCategoryExportReqVO {
@Schema(description = "文章分类名称", example = "秒杀")
private String name;
@Schema(description = "状态", example = "1")
private Integer status;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -40,8 +40,6 @@ public class CombinationRecordController {
@Lazy
private CombinationRecordService combinationRecordService;
// 然后如果 headId 非空并且第一页单独多查询一条 head 放到第 0 个位置相当于说第一页特殊一点
@GetMapping("/page")
@Operation(summary = "获得拼团记录分页")
@PreAuthorize("@ss.hasPermission('promotion:combination-record:query')")

View File

@ -1,16 +1,19 @@
package cn.iocoder.yudao.module.promotion.controller.app.article;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.promotion.controller.app.article.vo.category.AppArticleCategoryRespVO;
import cn.iocoder.yudao.module.promotion.convert.article.ArticleCategoryConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleCategoryDO;
import cn.iocoder.yudao.module.promotion.service.article.ArticleCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import javax.annotation.Resource;
import java.util.List;
import java.util.Random;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -20,20 +23,15 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Validated
public class AppArticleCategoryController {
@Resource
private ArticleCategoryService articleCategoryService;
@RequestMapping("/list")
@Operation(summary = "获得文章分类列表")
// TODO @芋艿swagger 注解
public CommonResult<List<AppArticleCategoryRespVO>> getArticleCategoryList() {
List<AppArticleCategoryRespVO> appArticleRespVOList = new ArrayList<>();
Random random = new Random();
for (int i = 0; i < 10; i++) {
AppArticleCategoryRespVO appArticleRespVO = new AppArticleCategoryRespVO();
appArticleRespVO.setId((long) (i + 1));
appArticleRespVO.setName("分类 - " + i);
appArticleRespVO.setPicUrl("https://www.iocoder.cn/" + (i + 1) + ".png");
appArticleRespVOList.add(appArticleRespVO);
}
return success(appArticleRespVOList);
List<ArticleCategoryDO> categoryList = articleCategoryService.getArticleCategoryListByStatus(
CommonStatusEnum.ENABLE.getStatus());
return success(ArticleCategoryConvert.INSTANCE.convertList04(categoryList));
}
}

View File

@ -4,16 +4,19 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.app.article.vo.article.AppArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.article.vo.article.AppArticleRespVO;
import cn.iocoder.yudao.module.promotion.convert.article.ArticleConvert;
import cn.iocoder.yudao.module.promotion.service.article.ArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import java.util.ArrayList;
import javax.annotation.Resource;
import java.util.List;
import java.util.Random;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -23,68 +26,33 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Validated
public class AppArticleController {
@Resource
private ArticleService articleService;
@RequestMapping("/list")
// TODO @芋艿swagger 注解
public CommonResult<List<AppArticleRespVO>> getArticleList(@RequestParam(value = "recommendHot", required = false) Boolean recommendHot,
@RequestParam(value = "recommendBanner", required = false) Boolean recommendBanner) {
List<AppArticleRespVO> appArticleRespVOList = new ArrayList<>();
Random random = new Random();
for (int i = 0; i < 10; i++) {
AppArticleRespVO appArticleRespVO = new AppArticleRespVO();
appArticleRespVO.setId((long) (i + 1));
appArticleRespVO.setTitle("芋道源码 - " + i + "模块");
appArticleRespVO.setAuthor("芋道源码");
appArticleRespVO.setCategoryId((long) random.nextInt(10000));
appArticleRespVO.setPicUrl("https://www.iocoder.cn/" + (i + 1) + ".png");
appArticleRespVO.setIntroduction("我是简介");
appArticleRespVO.setDescription("我是详细");
appArticleRespVO.setCreateTime(LocalDateTime.now());
appArticleRespVO.setBrowseCount(random.nextInt(10000));
appArticleRespVO.setSpuId((long) random.nextInt(10000));
appArticleRespVOList.add(appArticleRespVO);
}
return success(appArticleRespVOList);
@Operation(summary = "获得文章详情列表")
@Parameters({
@Parameter(name = "recommendHot", description = "是否热门", example = "false"), // 场景一查看指定的文章
@Parameter(name = "recommendBanner", description = "是否轮播图", example = "false") // 场景二查看指定的文章
})
public CommonResult<List<AppArticleRespVO>> getArticleList(
@RequestParam(value = "recommendHot", required = false) Boolean recommendHot,
@RequestParam(value = "recommendBanner", required = false) Boolean recommendBanner) {
return success(ArticleConvert.INSTANCE.convertList03(
articleService.getArticleCategoryListByRecommendHotAndRecommendBanner(recommendHot, recommendBanner)));
}
@RequestMapping("/page")
// TODO @芋艿swagger 注解
@Operation(summary = "获得文章详情分页")
public CommonResult<PageResult<AppArticleRespVO>> getArticlePage(AppArticlePageReqVO pageReqVO) {
List<AppArticleRespVO> appArticleRespVOList = new ArrayList<>();
Random random = new Random();
for (int i = 0; i < 10; i++) {
AppArticleRespVO appArticleRespVO = new AppArticleRespVO();
appArticleRespVO.setId((long) (i + 1));
appArticleRespVO.setTitle("芋道源码 - " + i + "模块");
appArticleRespVO.setAuthor("芋道源码");
appArticleRespVO.setCategoryId((long) random.nextInt(10000));
appArticleRespVO.setPicUrl("https://www.iocoder.cn/" + (i + 1) + ".png");
appArticleRespVO.setIntroduction("我是简介");
appArticleRespVO.setDescription("我是详细");
appArticleRespVO.setCreateTime(LocalDateTime.now());
appArticleRespVO.setBrowseCount(random.nextInt(10000));
appArticleRespVO.setSpuId((long) random.nextInt(10000));
appArticleRespVOList.add(appArticleRespVO);
}
return success(new PageResult<>(appArticleRespVOList, 10L));
return success(ArticleConvert.INSTANCE.convertPage02(articleService.getArticlePage(pageReqVO)));
}
@RequestMapping("/get")
// TODO @芋艿swagger 注解
@Operation(summary = "获得文章详情")
@Parameter(name = "id", description = "文章编号", example = "1024")
public CommonResult<AppArticleRespVO> getArticlePage(@RequestParam("id") Long id) {
Random random = new Random();
AppArticleRespVO appArticleRespVO = new AppArticleRespVO();
appArticleRespVO.setId((long) (1));
appArticleRespVO.setTitle("芋道源码 - " + 0 + "模块");
appArticleRespVO.setAuthor("芋道源码");
appArticleRespVO.setCategoryId((long) random.nextInt(10000));
appArticleRespVO.setPicUrl("https://www.iocoder.cn/" + (0 + 1) + ".png");
appArticleRespVO.setIntroduction("我是简介");
appArticleRespVO.setDescription("我是详细");
appArticleRespVO.setCreateTime(LocalDateTime.now());
appArticleRespVO.setBrowseCount(random.nextInt(10000));
appArticleRespVO.setSpuId((long) random.nextInt(10000));
appArticleRespVO.setSpuId(633L);
return success(appArticleRespVO);
return success(ArticleConvert.INSTANCE.convert01(articleService.getArticle(id)));
}
}

View File

@ -39,11 +39,4 @@ public class AppArticleRespVO {
@Schema(description = "关联的商品 SPU 编号", example = "1024")
private Long spuId;
// TODO 芋艿下面 2 个字段后端要存储前端不用返回
// @Schema(description = "是否热卖推荐", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
// private Boolean recommendHot;
//
// @Schema(description = "是否 Banner 推荐", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
// private Boolean recommendBanner;
}

View File

@ -16,11 +16,4 @@ public class AppArticleCategoryRespVO {
@Schema(description = "分类图标", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png")
private String picUrl;
// TODO 芋艿下面 2 个字段后端要存储前端不用返回
// @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
// private Integer status;
//
// @Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
// private Integer sort;
}

View File

@ -47,13 +47,13 @@ public class AppCombinationRecordController {
public CommonResult<AppCombinationRecordSummaryRespVO> getCombinationRecordSummary() {
AppCombinationRecordSummaryRespVO summary = new AppCombinationRecordSummaryRespVO();
// 1. 获得拼团参与用户数量
Long count = combinationRecordService.getCombinationUserCount();
if (count == 0) {
Long userCount = combinationRecordService.getCombinationUserCount();
if (userCount == 0) {
summary.setAvatars(Collections.emptyList());
summary.setUserCount(count);
summary.setUserCount(userCount);
return success(summary);
}
summary.setUserCount(count);
summary.setUserCount(userCount);
// 2. 获得拼团记录头像
List<CombinationRecordDO> records = combinationRecordService.getLatestCombinationRecordList(

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.convert.article;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.*;
import cn.iocoder.yudao.module.promotion.controller.app.article.vo.category.AppArticleCategoryRespVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleCategoryDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@ -28,8 +29,8 @@ public interface ArticleCategoryConvert {
PageResult<ArticleCategoryRespVO> convertPage(PageResult<ArticleCategoryDO> page);
List<ArticleCategoryExcelVO> convertList02(List<ArticleCategoryDO> list);
List<ArticleCategorySimpleRespVO> convertList03(List<ArticleCategoryDO> list);
List<AppArticleCategoryRespVO> convertList04(List<ArticleCategoryDO> categoryList);
}

View File

@ -1,10 +1,10 @@
package cn.iocoder.yudao.module.promotion.convert.article;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleExcelVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.article.vo.article.AppArticleRespVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@ -31,6 +31,10 @@ public interface ArticleConvert {
PageResult<ArticleRespVO> convertPage(PageResult<ArticleDO> page);
List<ArticleExcelVO> convertList02(List<ArticleDO> list);
AppArticleRespVO convert01(ArticleDO article);
PageResult<AppArticleRespVO> convertPage02(PageResult<ArticleDO> articlePage);
List<AppArticleRespVO> convertList03(List<ArticleDO> articleCategoryListByRecommendHotAndRecommendBanner);
}

View File

@ -192,7 +192,6 @@ public interface CombinationActivityConvert {
return result;
}
default AppCombinationRecordDetailRespVO convert(Long userId, CombinationRecordDO headRecord, List<CombinationRecordDO> memberRecords) {
AppCombinationRecordDetailRespVO respVO = new AppCombinationRecordDetailRespVO()
.setHeadRecord(convert(headRecord)).setMemberRecords(convertList3(memberRecords));
@ -208,31 +207,29 @@ public interface CombinationActivityConvert {
/**
* 转换生成虚拟成团虚拟记录
*
* @param virtualGroupHeadRecords 虚拟成团团长记录列表
* @param virtualGroupHeadRecord 虚拟成团团长记录
* @return 虚拟记录列表
*/
default List<CombinationRecordDO> convertVirtualGroupList(List<CombinationRecordDO> virtualGroupHeadRecords) {
default List<CombinationRecordDO> convertVirtualGroupList(CombinationRecordDO virtualGroupHeadRecord) {
List<CombinationRecordDO> createRecords = new ArrayList<>();
virtualGroupHeadRecords.forEach(headRecord -> {
// 计算需要创建的虚拟成团记录数量
int count = headRecord.getUserSize() - headRecord.getUserCount();
for (int i = 0; i < count; i++) {
// 基础信息和团长保持一致
CombinationRecordDO newRecord = new CombinationRecordDO().setActivityId(headRecord.getActivityId())
.setCombinationPrice(headRecord.getCombinationPrice()).setSpuId(headRecord.getSpuId()).setSpuName(headRecord.getSpuName())
.setPicUrl(headRecord.getPicUrl()).setSkuId(headRecord.getSkuId()).setHeadId(headRecord.getId())
.setStatus(headRecord.getStatus()) // 状态保持和创建时一致创建完成后会接着处理
.setVirtualGroup(headRecord.getVirtualGroup()).setExpireTime(headRecord.getExpireTime())
.setStartTime(headRecord.getStartTime()).setUserSize(headRecord.getUserSize()).setUserCount(headRecord.getUserCount());
// 虚拟信息
newRecord.setCount(0);
newRecord.setUserId(0L);
newRecord.setNickname("");
newRecord.setAvatar("");
newRecord.setOrderId(0L);
createRecords.add(newRecord);
}
});
// 计算需要创建的虚拟成团记录数量
int count = virtualGroupHeadRecord.getUserSize() - virtualGroupHeadRecord.getUserCount();
for (int i = 0; i < count; i++) {
// 基础信息和团长保持一致
CombinationRecordDO newRecord = new CombinationRecordDO().setActivityId(virtualGroupHeadRecord.getActivityId())
.setCombinationPrice(virtualGroupHeadRecord.getCombinationPrice()).setSpuId(virtualGroupHeadRecord.getSpuId()).setSpuName(virtualGroupHeadRecord.getSpuName())
.setPicUrl(virtualGroupHeadRecord.getPicUrl()).setSkuId(virtualGroupHeadRecord.getSkuId()).setHeadId(virtualGroupHeadRecord.getId())
.setStatus(virtualGroupHeadRecord.getStatus()) // 状态保持和创建时一致创建完成后会接着处理
.setVirtualGroup(virtualGroupHeadRecord.getVirtualGroup()).setExpireTime(virtualGroupHeadRecord.getExpireTime())
.setStartTime(virtualGroupHeadRecord.getStartTime()).setUserSize(virtualGroupHeadRecord.getUserSize()).setUserCount(virtualGroupHeadRecord.getUserCount());
// 虚拟信息
newRecord.setCount(0);
newRecord.setUserId(0L);
newRecord.setNickname("");
newRecord.setAvatar("");
newRecord.setOrderId(0L);
createRecords.add(newRecord);
}
return createRecords;
}

View File

@ -3,13 +3,10 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.article;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryPageReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleCategoryDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 文章分类 Mapper
*
@ -26,12 +23,4 @@ public interface ArticleCategoryMapper extends BaseMapperX<ArticleCategoryDO> {
.orderByDesc(ArticleCategoryDO::getSort));
}
default List<ArticleCategoryDO> selectList(ArticleCategoryExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<ArticleCategoryDO>()
.likeIfPresent(ArticleCategoryDO::getName, reqVO.getName())
.eqIfPresent(ArticleCategoryDO::getStatus, reqVO.getStatus())
.betweenIfPresent(ArticleCategoryDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(ArticleCategoryDO::getSort));
}
}

View File

@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.article;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.article.vo.article.AppArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO;
import org.apache.ibatis.annotations.Mapper;
@ -31,17 +31,16 @@ public interface ArticleMapper extends BaseMapperX<ArticleDO> {
.orderByDesc(ArticleDO::getId));
}
default List<ArticleDO> selectList(ArticleExportReqVO reqVO) {
default List<ArticleDO> selectList(Boolean recommendHot, Boolean recommendBanner) {
return selectList(new LambdaQueryWrapperX<ArticleDO>()
.eqIfPresent(ArticleDO::getCategoryId, reqVO.getCategoryId())
.eqIfPresent(ArticleDO::getTitle, reqVO.getTitle())
.eqIfPresent(ArticleDO::getAuthor, reqVO.getAuthor())
.eqIfPresent(ArticleDO::getStatus, reqVO.getStatus())
.eqIfPresent(ArticleDO::getSpuId, reqVO.getSpuId())
.eqIfPresent(ArticleDO::getRecommendHot, reqVO.getRecommendHot())
.eqIfPresent(ArticleDO::getRecommendBanner, reqVO.getRecommendBanner())
.betweenIfPresent(ArticleDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(ArticleDO::getId));
.eqIfPresent(ArticleDO::getRecommendHot, recommendHot)
.eqIfPresent(ArticleDO::getRecommendBanner, recommendBanner));
}
default PageResult<ArticleDO> selectPage(AppArticlePageReqVO pageReqVO) {
return selectPage(pageReqVO, new LambdaQueryWrapperX<ArticleDO>()
.eqIfPresent(ArticleDO::getCategoryId, pageReqVO.getCategoryId()));
}
}

View File

@ -99,10 +99,10 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
LambdaQueryWrapperX<CombinationRecordDO> queryWrapper = new LambdaQueryWrapperX<CombinationRecordDO>()
.eqIfPresent(CombinationRecordDO::getStatus, pageVO.getStatus())
.betweenIfPresent(CombinationRecordDO::getCreateTime, pageVO.getCreateTime());
// 如果 headId 非空说明查询指定团的团长 + 团员的拼团记录
if (pageVO.getHeadId() != null) {
queryWrapper.eq(CombinationRecordDO::getId, pageVO.getHeadId())
.or()
.eq(CombinationRecordDO::getHeadId, pageVO.getHeadId());
queryWrapper.eq(CombinationRecordDO::getId, pageVO.getHeadId()) // 团长
.or().eq(CombinationRecordDO::getHeadId, pageVO.getHeadId()); // 团员
}
return selectPage(pageVO, queryWrapper);
}
@ -127,10 +127,9 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
*
* @return 参加过拼团的用户数
*/
default Long selectUserDistinctCount() {
default Long selectUserCount() {
return selectCount(new QueryWrapper<CombinationRecordDO>()
.select("DISTINCT (user_id)")
.groupBy("user_id"));
.select("DISTINCT (user_id)"));
}
default List<CombinationRecordDO> selectListByHeadIdAndStatusAndExpireTimeLt(Long headId, Integer status, LocalDateTime dateTime) {
@ -140,8 +139,8 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
.lt(CombinationRecordDO::getExpireTime, dateTime));
}
default List<CombinationRecordDO> selectListByHeadIds(Collection<Long> headIds) {
return selectList(new LambdaQueryWrapperX<CombinationRecordDO>().in(CombinationRecordDO::getHeadId, headIds));
default List<CombinationRecordDO> selectListByHeadId(Long headId) {
return selectList(new LambdaQueryWrapperX<CombinationRecordDO>().eq(CombinationRecordDO::getHeadId, headId));
}
}

View File

@ -2,13 +2,11 @@ package cn.iocoder.yudao.module.promotion.service.article;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryUpdateReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleCategoryDO;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/**
@ -48,14 +46,6 @@ public interface ArticleCategoryService {
*/
ArticleCategoryDO getArticleCategory(Long id);
/**
* 获得文章分类列表
*
* @param ids 编号
* @return 文章分类列表
*/
List<ArticleCategoryDO> getArticleCategoryList(Collection<Long> ids);
/**
* 获得文章分类分页
*
@ -64,14 +54,6 @@ public interface ArticleCategoryService {
*/
PageResult<ArticleCategoryDO> getArticleCategoryPage(ArticleCategoryPageReqVO pageReqVO);
/**
* 获得文章分类列表, 用于 Excel 导出
*
* @param exportReqVO 查询条件
* @return 文章分类列表
*/
List<ArticleCategoryDO> getArticleCategoryList(ArticleCategoryExportReqVO exportReqVO);
/**
* 获得指定状态的文章分类列表
*

View File

@ -1,23 +1,22 @@
package cn.iocoder.yudao.module.promotion.service.article;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryUpdateReqVO;
import cn.iocoder.yudao.module.promotion.convert.article.ArticleCategoryConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleCategoryDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.article.ArticleCategoryMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.ARTICLE_CATEGORY_DELETE_FAIL_HAVE_ARTICLES;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.ARTICLE_CATEGORY_NOT_EXISTS;
/**
@ -31,14 +30,16 @@ public class ArticleCategoryServiceImpl implements ArticleCategoryService {
@Resource
private ArticleCategoryMapper articleCategoryMapper;
@Resource
private ArticleService articleService;
@Override
public Long createArticleCategory(ArticleCategoryCreateReqVO createReqVO) {
// 插入
ArticleCategoryDO articleCategory = ArticleCategoryConvert.INSTANCE.convert(createReqVO);
articleCategoryMapper.insert(articleCategory);
ArticleCategoryDO category = ArticleCategoryConvert.INSTANCE.convert(createReqVO);
articleCategoryMapper.insert(category);
// 返回
return articleCategory.getId();
return category.getId();
}
@Override
@ -54,6 +55,12 @@ public class ArticleCategoryServiceImpl implements ArticleCategoryService {
public void deleteArticleCategory(Long id) {
// 校验存在
validateArticleCategoryExists(id);
// 校验是不是存在关联文章
List<ArticleDO> articleList = articleService.getArticleByCategoryId(id);
if (CollUtil.isNotEmpty(articleList)) {
throw exception(ARTICLE_CATEGORY_DELETE_FAIL_HAVE_ARTICLES);
}
// 删除
articleCategoryMapper.deleteById(id);
}
@ -69,24 +76,11 @@ public class ArticleCategoryServiceImpl implements ArticleCategoryService {
return articleCategoryMapper.selectById(id);
}
@Override
public List<ArticleCategoryDO> getArticleCategoryList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return ListUtil.empty();
}
return articleCategoryMapper.selectBatchIds(ids);
}
@Override
public PageResult<ArticleCategoryDO> getArticleCategoryPage(ArticleCategoryPageReqVO pageReqVO) {
return articleCategoryMapper.selectPage(pageReqVO);
}
@Override
public List<ArticleCategoryDO> getArticleCategoryList(ArticleCategoryExportReqVO exportReqVO) {
return articleCategoryMapper.selectList(exportReqVO);
}
@Override
public List<ArticleCategoryDO> getArticleCategoryListByStatus(Integer status) {
return articleCategoryMapper.selectList(ArticleCategoryDO::getStatus, status);

View File

@ -1,25 +1,24 @@
package cn.iocoder.yudao.module.promotion.service.article;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.article.vo.article.AppArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/**
* 文章管理 Service 接口
* 文章详情 Service 接口
*
* @author HUIHUI
*/
public interface ArticleService {
/**
* 创建文章管理
* 创建文章详情
*
* @param createReqVO 创建信息
* @return 编号
@ -27,49 +26,58 @@ public interface ArticleService {
Long createArticle(@Valid ArticleCreateReqVO createReqVO);
/**
* 更新文章管理
* 更新文章详情
*
* @param updateReqVO 更新信息
*/
void updateArticle(@Valid ArticleUpdateReqVO updateReqVO);
/**
* 删除文章管理
* 删除文章详情
*
* @param id 编号
*/
void deleteArticle(Long id);
/**
* 获得文章管理
* 获得文章详情
*
* @param id 编号
* @return 文章管理
* @return 文章详情
*/
ArticleDO getArticle(Long id);
/**
* 获得文章管理列表
*
* @param ids 编号
* @return 文章管理列表
*/
List<ArticleDO> getArticleList(Collection<Long> ids);
/**
* 获得文章管理分页
* 获得文章详情分页
*
* @param pageReqVO 分页查询
* @return 文章管理分页
* @return 文章详情分页
*/
PageResult<ArticleDO> getArticlePage(ArticlePageReqVO pageReqVO);
/**
* 获得文章管理列表, 用于 Excel 导出
* 获得文章详情列表
*
* @param exportReqVO 查询条件
* @return 文章管理列表
* @param recommendHot 是否热门
* @param recommendBanner 是否轮播图
* @return 文章详情列表
*/
List<ArticleDO> getArticleList(ArticleExportReqVO exportReqVO);
List<ArticleDO> getArticleCategoryListByRecommendHotAndRecommendBanner(Boolean recommendHot, Boolean recommendBanner);
/**
* 获得文章详情分页
*
* @param pageReqVO 分页查询
* @return 文章详情分页
*/
PageResult<ArticleDO> getArticlePage(AppArticlePageReqVO pageReqVO);
/**
* 获得指定分类的文章列表
*
* @param categoryId 文章分类编号
* @return 文章列表
*/
List<ArticleDO> getArticleByCategoryId(Long categoryId);
}

View File

@ -1,23 +1,22 @@
package cn.iocoder.yudao.module.promotion.service.article;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.article.vo.article.AppArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.convert.article.ArticleConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleCategoryDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.article.ArticleMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.ARTICLE_CATEGORY_NOT_EXISTS;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.ARTICLE_NOT_EXISTS;
/**
@ -31,9 +30,14 @@ public class ArticleServiceImpl implements ArticleService {
@Resource
private ArticleMapper articleMapper;
@Resource
private ArticleCategoryService articleCategoryService;
@Override
public Long createArticle(ArticleCreateReqVO createReqVO) {
// 校验分类存在
validateArticleCategoryExists(createReqVO.getCategoryId());
// 插入
ArticleDO article = ArticleConvert.INSTANCE.convert(createReqVO);
articleMapper.insert(article);
@ -45,6 +49,9 @@ public class ArticleServiceImpl implements ArticleService {
public void updateArticle(ArticleUpdateReqVO updateReqVO) {
// 校验存在
validateArticleExists(updateReqVO.getId());
// 校验分类存在
validateArticleCategoryExists(updateReqVO.getCategoryId());
// 更新
ArticleDO updateObj = ArticleConvert.INSTANCE.convert(updateReqVO);
articleMapper.updateById(updateObj);
@ -64,17 +71,16 @@ public class ArticleServiceImpl implements ArticleService {
}
}
@Override
public ArticleDO getArticle(Long id) {
return articleMapper.selectById(id);
private void validateArticleCategoryExists(Long categoryId) {
ArticleCategoryDO articleCategory = articleCategoryService.getArticleCategory(categoryId);
if (articleCategory == null) {
throw exception(ARTICLE_CATEGORY_NOT_EXISTS);
}
}
@Override
public List<ArticleDO> getArticleList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return ListUtil.empty();
}
return articleMapper.selectBatchIds(ids);
public ArticleDO getArticle(Long id) {
return articleMapper.selectById(id);
}
@Override
@ -83,8 +89,18 @@ public class ArticleServiceImpl implements ArticleService {
}
@Override
public List<ArticleDO> getArticleList(ArticleExportReqVO exportReqVO) {
return articleMapper.selectList(exportReqVO);
public List<ArticleDO> getArticleCategoryListByRecommendHotAndRecommendBanner(Boolean recommendHot, Boolean recommendBanner) {
return articleMapper.selectList(recommendHot, recommendBanner);
}
@Override
public PageResult<ArticleDO> getArticlePage(AppArticlePageReqVO pageReqVO) {
return articleMapper.selectPage(pageReqVO);
}
@Override
public List<ArticleDO> getArticleByCategoryId(Long categoryId) {
return articleMapper.selectList(ArticleDO::getCategoryId, categoryId);
}
}

View File

@ -247,7 +247,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
@Override
public Long getCombinationUserCount() {
return combinationRecordMapper.selectUserDistinctCount();
return combinationRecordMapper.selectUserCount();
}
@Override
@ -339,59 +339,58 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
@Override
public KeyValue<Integer, Integer> expireCombinationRecord() {
// 1.获取所有正在进行中的过期的父拼团
// 1. 获取所有正在进行中的过期的父拼团
List<CombinationRecordDO> headExpireRecords = combinationRecordMapper.selectListByHeadIdAndStatusAndExpireTimeLt(
CombinationRecordDO.HEAD_ID_GROUP, CombinationRecordStatusEnum.IN_PROGRESS.getStatus(), LocalDateTime.now());
if (CollUtil.isEmpty(headExpireRecords)) {
return new KeyValue<>(0, 0);
}
// 2.获取拼团活动
// 2. 获取拼团活动
List<CombinationActivityDO> activities = combinationActivityService.getCombinationActivityListByIds(
convertSet(headExpireRecords, CombinationRecordDO::getActivityId));
Map<Long, CombinationActivityDO> activityMap = convertMap(activities, CombinationActivityDO::getId);
// 3.校验是否虚拟成团
List<CombinationRecordDO> virtualGroupHeadRecords = new ArrayList<>(); // 虚拟成团
for (Iterator<CombinationRecordDO> iterator = headExpireRecords.iterator(); iterator.hasNext(); ) {
CombinationRecordDO record = iterator.next();
// 3.1.不匹配则直接跳过
CombinationActivityDO activity = activityMap.get(record.getActivityId());
if (activity == null || !activity.getVirtualGroup()) { // 取不到活动的或者不是虚拟拼团的
continue;
// 3. 改成每个团处理一次哈这样 handleExpireRecordhandleVirtualGroupRecord 都改成按团处理每个是一个小事务
KeyValue<Integer, Integer> keyValue = new KeyValue<>(0, 0); // 统计过期拼团和虚拟成团
for (CombinationRecordDO recordDO : headExpireRecords) {
try {
CombinationActivityDO activity = activityMap.get(recordDO.getActivityId());
if (activity == null || !activity.getVirtualGroup()) { // 取不到活动的或者不是虚拟拼团的
// 3.1. 处理过期的拼团
getSelf().handleExpireRecord(recordDO);
keyValue.setKey(keyValue.getKey() + 1);
} else {
// 3.2. 处理虚拟成团
getSelf().handleVirtualGroupRecord(recordDO);
keyValue.setValue(keyValue.getValue() + 1);
}
} catch (Exception ignored) { // 处理异常继续循环
}
// 3.2.匹配则移除添加到虚拟成团中并结束寻找
virtualGroupHeadRecords.add(record);
iterator.remove();
break;
}
// 4.处理过期的拼团
getSelf().handleExpireRecord(headExpireRecords);
// 5.虚拟成团
getSelf().handleVirtualGroupRecord(virtualGroupHeadRecords);
return new KeyValue<>(headExpireRecords.size(), virtualGroupHeadRecords.size());
return keyValue;
}
/**
* 处理过期拼团
*
* @param headExpireRecords 过期拼团团长记录列表
* @param headExpireRecord 过期拼团团长记录列表
*/
@Transactional(rollbackFor = Exception.class)
public void handleExpireRecord(List<CombinationRecordDO> headExpireRecords) {
if (CollUtil.isEmpty(headExpireRecords)) {
public void handleExpireRecord(CombinationRecordDO headExpireRecord) {
if (headExpireRecord == null) {
return;
}
// 1.更新拼团记录
List<CombinationRecordDO> headsAndRecords = updateBatchCombinationRecords(headExpireRecords,
List<CombinationRecordDO> headsAndRecords = updateBatchCombinationRecords(headExpireRecord,
CombinationRecordStatusEnum.FAILED);
if (headsAndRecords == null) {
return;
}
// 2.订单取消 TODO 以现在的取消回滚逻辑好像只能循环了
// 2.订单取消
headsAndRecords.forEach(item -> {
tradeOrderApi.cancelPaidOrder(item.getUserId(), item.getOrderId());
});
@ -400,36 +399,32 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
/**
* 处理虚拟拼团
*
* @param virtualGroupHeadRecords 虚拟成团团长记录列表
* @param virtualGroupHeadRecord 虚拟成团团长记录列表
*/
@Transactional(rollbackFor = Exception.class)
public void handleVirtualGroupRecord(List<CombinationRecordDO> virtualGroupHeadRecords) {
if (CollUtil.isEmpty(virtualGroupHeadRecords)) {
public void handleVirtualGroupRecord(CombinationRecordDO virtualGroupHeadRecord) {
if (virtualGroupHeadRecord == null) {
return;
}
// 1. 团员补齐
combinationRecordMapper.insertBatch(CombinationActivityConvert.INSTANCE.convertVirtualGroupList(virtualGroupHeadRecords));
combinationRecordMapper.insertBatch(CombinationActivityConvert.INSTANCE.convertVirtualGroupList(virtualGroupHeadRecord));
// 2. 更新拼团记录
updateBatchCombinationRecords(virtualGroupHeadRecords, CombinationRecordStatusEnum.SUCCESS);
updateBatchCombinationRecords(virtualGroupHeadRecord, CombinationRecordStatusEnum.SUCCESS);
}
private List<CombinationRecordDO> updateBatchCombinationRecords(List<CombinationRecordDO> headRecords, CombinationRecordStatusEnum status) {
// 1. 查询团成员
List<CombinationRecordDO> records = combinationRecordMapper.selectListByHeadIds(
convertSet(headRecords, CombinationRecordDO::getId));
private List<CombinationRecordDO> updateBatchCombinationRecords(CombinationRecordDO headRecord, CombinationRecordStatusEnum status) {
// 1. 查询团成员包含团长
List<CombinationRecordDO> records = combinationRecordMapper.selectListByHeadId(headRecord.getId());
if (CollUtil.isEmpty(records)) {
return null;
}
Map<Long, List<CombinationRecordDO>> recordsMap = convertMultiMap(records, CombinationRecordDO::getHeadId);
headRecords.forEach(item -> {
recordsMap.get(item.getId()).add(item); // 把团长加进团里
});
records.add(headRecord);// 把团长加进去
// 2.批量更新拼团记录 status 失败/成团时间
List<CombinationRecordDO> headsAndRecords = mergeValuesFromMap(recordsMap);
List<CombinationRecordDO> updateRecords = new ArrayList<>(headsAndRecords.size());
List<CombinationRecordDO> updateRecords = new ArrayList<>(records.size());
LocalDateTime now = LocalDateTime.now();
headsAndRecords.forEach(item -> {
records.forEach(item -> {
CombinationRecordDO record = new CombinationRecordDO().setId(item.getId())
.setStatus(status.getStatus()).setEndTime(now);
if (CombinationRecordStatusEnum.isSuccess(status.getStatus())) { // 虚拟成团完事更改状态成功后还需要把参与人数修改为成团需要人数
@ -438,7 +433,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
updateRecords.add(record);
});
combinationRecordMapper.updateBatch(updateRecords);
return headsAndRecords;
return records;
}
/**

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.promotion.service.article;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryUpdateReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleCategoryDO;
@ -13,7 +12,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
@ -24,6 +22,7 @@ import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.ARTICLE_CATEGORY_NOT_EXISTS;
import static org.junit.jupiter.api.Assertions.*;
// TODO 芋艿review 单测
/**
* {@link ArticleCategoryServiceImpl} 的单元测试类
*
@ -137,39 +136,4 @@ public class ArticleCategoryServiceImplTest extends BaseDbUnitTest {
assertPojoEquals(dbArticleCategory, pageResult.getList().get(0));
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetArticleCategoryList() {
// mock 数据
ArticleCategoryDO dbArticleCategory = randomPojo(ArticleCategoryDO.class, o -> { // 等会查询到
o.setName(null);
o.setPicUrl(null);
o.setStatus(null);
o.setSort(null);
o.setCreateTime(null);
});
articleCategoryMapper.insert(dbArticleCategory);
// 测试 name 不匹配
articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setName(null)));
// 测试 picUrl 不匹配
articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setPicUrl(null)));
// 测试 status 不匹配
articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setStatus(null)));
// 测试 sort 不匹配
articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setSort(null)));
// 测试 createTime 不匹配
articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setCreateTime(null)));
// 准备参数
ArticleCategoryExportReqVO reqVO = new ArticleCategoryExportReqVO();
reqVO.setName(null);
reqVO.setStatus(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
List<ArticleCategoryDO> list = articleCategoryService.getArticleCategoryList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbArticleCategory, list.get(0));
}
}

View File

@ -2,10 +2,9 @@ package cn.iocoder.yudao.module.promotion.service.article;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.article.ArticleMapper;
import org.junit.jupiter.api.Disabled;
@ -13,7 +12,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
@ -166,68 +164,4 @@ public class ArticleServiceImplTest extends BaseDbUnitTest {
assertPojoEquals(dbArticle, pageResult.getList().get(0));
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetArticleList() {
// mock 数据
ArticleDO dbArticle = randomPojo(ArticleDO.class, o -> { // 等会查询到
o.setCategoryId(null);
o.setTitle(null);
o.setAuthor(null);
o.setPicUrl(null);
o.setIntroduction(null);
o.setBrowseCount(null);
o.setSort(null);
o.setStatus(null);
o.setSpuId(null);
o.setRecommendHot(null);
o.setRecommendBanner(null);
o.setContent(null);
o.setCreateTime(null);
});
articleMapper.insert(dbArticle);
// 测试 categoryId 不匹配
articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setCategoryId(null)));
// 测试 title 不匹配
articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setTitle(null)));
// 测试 author 不匹配
articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setAuthor(null)));
// 测试 picUrl 不匹配
articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setPicUrl(null)));
// 测试 introduction 不匹配
articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setIntroduction(null)));
// 测试 browseCount 不匹配
articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setBrowseCount(null)));
// 测试 sort 不匹配
articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setSort(null)));
// 测试 status 不匹配
articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setStatus(null)));
// 测试 spuId 不匹配
articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setSpuId(null)));
// 测试 recommendHot 不匹配
articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setRecommendHot(null)));
// 测试 recommendBanner 不匹配
articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setRecommendBanner(null)));
// 测试 content 不匹配
articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setContent(null)));
// 测试 createTime 不匹配
articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setCreateTime(null)));
// 准备参数
ArticleExportReqVO reqVO = new ArticleExportReqVO();
reqVO.setCategoryId(null);
reqVO.setTitle(null);
reqVO.setAuthor(null);
reqVO.setStatus(null);
reqVO.setSpuId(null);
reqVO.setRecommendHot(null);
reqVO.setRecommendBanner(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
List<ArticleDO> list = articleService.getArticleList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbArticle, list.get(0));
}
}

View File

@ -0,0 +1,48 @@
package cn.iocoder.yudao.module.statistics.enums;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
/**
* 时间范围类型的枚举
*
* @author owen
*/
@AllArgsConstructor
@Getter
public enum TimeRangeTypeEnum implements IntArrayValuable {
/**
*
*/
DAY(1),
/**
*
*/
WEEK(7),
/**
*
*/
MONTH(30),
/**
*
*/
YEAR(365),
;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(TimeRangeTypeEnum::getType).toArray();
/**
* 类型
*/
private final Integer type;
@Override
public int[] array() {
return ARRAYS;
}
}

View File

@ -1,16 +1,15 @@
package cn.iocoder.yudao.module.statistics.controller.admin.trade.vo;
package cn.iocoder.yudao.module.statistics.controller.admin.common.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
// TODO @疯狂是不是搞成公用的哈类似controller/admin/common下面直接放它
@Schema(description = "管理后台 - 交易统计对照 Response VO")
@Schema(description = "管理后台 - 数据对照 Response VO")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class TradeStatisticsComparisonRespVO<T> {
public class DataComparisonRespVO<T> {
@Schema(description = "当前数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private T value;

View File

@ -1,10 +1,15 @@
package cn.iocoder.yudao.module.statistics.controller.admin.member;
import cn.hutool.core.util.ArrayUtil;
import cn.iocoder.yudao.framework.common.enums.TerminalEnum;
import cn.hutool.core.util.NumberUtil;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.*;
import cn.iocoder.yudao.module.statistics.convert.member.MemberStatisticsConvert;
import cn.iocoder.yudao.module.statistics.service.infra.ApiAccessLogStatisticsService;
import cn.iocoder.yudao.module.statistics.service.member.MemberStatisticsService;
import cn.iocoder.yudao.module.statistics.service.trade.TradeOrderStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
@ -15,10 +20,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@Tag(name = "管理后台 - 会员统计")
@RestController
@ -29,6 +34,10 @@ public class MemberStatisticsController {
@Resource
private MemberStatisticsService memberStatisticsService;
@Resource
private TradeOrderStatisticsService tradeOrderStatisticsService;
@Resource
private ApiAccessLogStatisticsService apiAccessLogStatisticsService;
// TODO 芋艿已经 review
@GetMapping("/summary")
@ -43,11 +52,32 @@ public class MemberStatisticsController {
@Operation(summary = "获得会员分析数据")
@PreAuthorize("@ss.hasPermission('statistics:member:query')")
public CommonResult<MemberAnalyseRespVO> getMemberAnalyse(MemberAnalyseReqVO reqVO) {
return success(memberStatisticsService.getMemberAnalyse(
ArrayUtil.get(reqVO.getTimes(), 0), ArrayUtil.get(reqVO.getTimes(), 1)));
// 1. 查询数据
LocalDateTime beginTime = ArrayUtil.get(reqVO.getTimes(), 0);
LocalDateTime endTime = ArrayUtil.get(reqVO.getTimes(), 1);
// 1.1 查询分析对照数据
DataComparisonRespVO<MemberAnalyseDataRespVO> comparisonData = memberStatisticsService.getMemberAnalyseComparisonData(beginTime, endTime);
// TODO @疯狂这个可能有点特殊要按照 create_time 来查询不然它的漏斗就不统一因为是访问数量 > 今日下单人 > 今日支付人是一个统一的维度
// 1.2 查询成交用户数量
Integer payUserCount = tradeOrderStatisticsService.getPayUserCount(beginTime, endTime);
// 1.3 计算客单价
int atv = 0;
if (payUserCount != null && payUserCount > 0) {
// TODO @疯狂类似上面的 payUserCount
Integer payPrice = tradeOrderStatisticsService.getOrderPayPrice(beginTime, endTime);
atv = NumberUtil.div(payPrice, payUserCount).intValue();
}
// 1.4 查询访客数量
Integer visitUserCount = apiAccessLogStatisticsService.getIpCount(UserTypeEnum.MEMBER.getValue(), beginTime, endTime);
// 1.5 下单用户数量
Integer orderUserCount = tradeOrderStatisticsService.getOrderUserCount(beginTime, endTime);
// 2. 拼接返回
return success(MemberStatisticsConvert.INSTANCE.convert(visitUserCount, orderUserCount, payUserCount, atv, comparisonData));
}
// TODO 芋艿已经 review
// TODO @疯狂要不 get 前缀去掉和下面的 list 接口保持一致
@GetMapping("/get-area-statistics-list")
@Operation(summary = "按照省份,获得会员统计列表")
@PreAuthorize("@ss.hasPermission('statistics:member:query')")
@ -56,6 +86,7 @@ public class MemberStatisticsController {
}
// TODO 芋艿已经 review
// TODO @疯狂要不 get 前缀去掉和下面的 list 接口保持一致
@GetMapping("/get-sex-statistics-list")
@Operation(summary = "按照性别,获得会员统计列表")
@PreAuthorize("@ss.hasPermission('statistics:member:query')")
@ -63,16 +94,29 @@ public class MemberStatisticsController {
return success(memberStatisticsService.getMemberSexStatisticsList());
}
// TODO 芋艿已经 review
// TODO @疯狂要不 get 前缀去掉和下面的 list 接口保持一致
@GetMapping("/get-terminal-statistics-list")
@Operation(summary = "按照终端,获得会员统计列表")
@PreAuthorize("@ss.hasPermission('statistics:member:query')")
public CommonResult<List<MemberTerminalStatisticsRespVO>> getMemberTerminalStatisticsList() {
// TODO 疯狂这个可以晚点写因为 user = = 上还没记录 terminal
// TODO @疯狂 member_user 增加 registerTerminal 字段基于它来统计哈
List<MemberTerminalStatisticsRespVO> list = convertList(TerminalEnum.values(),
t -> new MemberTerminalStatisticsRespVO()
.setTerminal(t.getTerminal()).setUserCount(t.getTerminal() * 100));
return success(list);
return success(memberStatisticsService.getRegisterTerminalStatisticsList());
}
@GetMapping("/user-count-comparison")
@Operation(summary = "获得用户数量对照")
@PreAuthorize("@ss.hasPermission('statistics:member:query')")
public CommonResult<DataComparisonRespVO<MemberCountRespVO>> getUserCountComparison() {
return success(memberStatisticsService.getUserCountComparison());
}
// TODO 芋艿已经 review
@GetMapping("/register-count-list")
@Operation(summary = "获得会员注册数量列表")
@PreAuthorize("@ss.hasPermission('statistics:member:query')")
public CommonResult<List<MemberRegisterCountRespVO>> getMemberRegisterCountList(MemberAnalyseReqVO reqVO) {
return success(memberStatisticsService.getMemberRegisterCountList(
ArrayUtil.get(reqVO.getTimes(), 0), ArrayUtil.get(reqVO.getTimes(), 1)));
}
}

View File

@ -3,17 +3,15 @@ package cn.iocoder.yudao.module.statistics.controller.admin.member.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 会员分析对照数据 Response VO")
@Schema(description = "管理后台 - 会员分析数据 Response VO")
@Data
public class MemberAnalyseComparisonRespVO {
public class MemberAnalyseDataRespVO {
// TODO @疯狂这个字段要不改成注册用户量registerUserCount;
@Schema(description = "会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer userCount;
private Integer registerUserCount;
// TODO @疯狂这个字段名字改成 visitUserCount有访问就算活跃
@Schema(description = "活跃用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer activeUserCount;
private Integer visitUserCount;
@Schema(description = "充值会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "221")
private Integer rechargeUserCount;

View File

@ -1,6 +1,6 @@
package cn.iocoder.yudao.module.statistics.controller.admin.member.vo;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -8,9 +8,8 @@ import lombok.Data;
@Data
public class MemberAnalyseRespVO {
// TODO @疯狂这个字段改成 visitUserCount保持和 userCount 字段统一
@Schema(description = "访客数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer visitorCount;
private Integer visitUserCount;
@Schema(description = "下单用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer orderUserCount;
@ -22,6 +21,6 @@ public class MemberAnalyseRespVO {
private Integer atv;
@Schema(description = "对照数据", requiredMode = Schema.RequiredMode.REQUIRED)
private TradeStatisticsComparisonRespVO<MemberAnalyseComparisonRespVO> comparison;
private DataComparisonRespVO<MemberAnalyseDataRespVO> comparison;
}

View File

@ -15,11 +15,10 @@ public class MemberAreaStatisticsRespVO {
@Schema(description = "会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer userCount;
// TODO @疯狂要不 orderCreateUserCount orderPayUserCount 貌似更统一一些
@Schema(description = "订单创建数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer orderCreateCount;
@Schema(description = "订单支付数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "512")
private Integer orderPayCount;
@Schema(description = "下单的会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer orderCreateUserCount;
@Schema(description = "支付订单的会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "512")
private Integer orderPayUserCount;
@Schema(description = "订单支付金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "622")
private Integer orderPayPrice;

View File

@ -0,0 +1,17 @@
package cn.iocoder.yudao.module.statistics.controller.admin.member.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 会员数量统计 Response VO")
@Data
public class MemberCountRespVO {
@Schema(description = "用户访问量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer visitUserCount;
// TODO @疯狂要不改成 registerUserCount注册
@Schema(description = "新增用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer createUserCount;
}

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.statistics.controller.admin.member.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDate;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT;
@Schema(description = "管理后台 - 会员注册数量 Response VO")
@Data
public class MemberRegisterCountRespVO {
@JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY, timezone = TIME_ZONE_DEFAULT)
@Schema(description = "日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private LocalDate date;
@Schema(description = "数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer count;
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.statistics.controller.admin.pay;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.statistics.service.pay.PayWalletStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 支付统计")
@RestController
@RequestMapping("/statistics/pay")
@Validated
@Slf4j
public class PayStatisticsController {
@Resource
private PayWalletStatisticsService payWalletStatisticsService;
// TODO @疯狂要不搞成 PaySummary只是目前只有 rechargePrice 充值金额
@GetMapping("/wallet-recharge-price")
@Operation(summary = "获取充值金额")
public CommonResult<Integer> getWalletRechargePrice() {
return success(payWalletStatisticsService.getRechargePriceSummary());
}
}

View File

@ -3,9 +3,17 @@ package cn.iocoder.yudao.module.statistics.controller.admin.trade;
import cn.hutool.core.util.ArrayUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.*;
import cn.iocoder.yudao.module.statistics.convert.trade.TradeStatisticsConvert;
import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO;
import cn.iocoder.yudao.module.statistics.service.trade.AfterSaleStatisticsService;
import cn.iocoder.yudao.module.statistics.service.trade.BrokerageStatisticsService;
import cn.iocoder.yudao.module.statistics.service.trade.TradeOrderStatisticsService;
import cn.iocoder.yudao.module.statistics.service.trade.TradeStatisticsService;
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO;
import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleStatusEnum;
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
@ -17,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
@ -31,46 +40,91 @@ public class TradeStatisticsController {
@Resource
private TradeStatisticsService tradeStatisticsService;
@Resource
private TradeOrderStatisticsService tradeOrderStatisticsService;
@Resource
private AfterSaleStatisticsService afterSaleStatisticsService;
@Resource
private BrokerageStatisticsService brokerageStatisticsService;
// TODO 芋艿已经 review
@GetMapping("/summary")
@Operation(summary = "获得交易统计")
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
public CommonResult<TradeStatisticsComparisonRespVO<TradeSummaryRespVO>> getTradeSummaryComparison() {
// TODO @疯狂这个要不要 tradeStatisticsService 调用里面的多个方法组合出最终的 TradeSummaryRespVO
return success(tradeStatisticsService.getTradeSummaryComparison());
public CommonResult<DataComparisonRespVO<TradeSummaryRespVO>> getTradeSummaryComparison() {
// 1.1 昨天的数据
TradeSummaryRespBO yesterdayData = tradeStatisticsService.getTradeSummaryByDays(-1);
// 1.2 前天的数据用于对照昨天的数据
TradeSummaryRespBO beforeYesterdayData = tradeStatisticsService.getTradeSummaryByDays(-2);
// 2.1 本月数据
TradeSummaryRespBO monthData = tradeStatisticsService.getTradeSummaryByMonths(0);
// 2.2 上月数据用于对照本月的数据
TradeSummaryRespBO lastMonthData = tradeStatisticsService.getTradeSummaryByMonths(-1);
// 拼接数据
return success(TradeStatisticsConvert.INSTANCE.convert(yesterdayData, beforeYesterdayData, monthData, lastMonthData));
}
// TODO @疯狂晚点再改和讨论等首页的接口出来这个要不还是叫 analyse对比选中的时间段和上一个时间段类似 MemberStatisticsController getMemberAnalyse
@GetMapping("/trend/summary")
@Operation(summary = "获得交易状况统计")
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
public CommonResult<TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO>> getTradeTrendSummaryComparison(
public CommonResult<DataComparisonRespVO<TradeTrendSummaryRespVO>> getTradeTrendSummaryComparison(
TradeTrendReqVO reqVO) {
return success(tradeStatisticsService.getTradeTrendSummaryComparison(ArrayUtil.get(reqVO.getTimes(), 0),
ArrayUtil.get(reqVO.getTimes(), 1)));
}
// TODO 芋艿已经 review
// TODO @疯狂这个要不直接叫 list它即使就是把每条统计拿出来
@GetMapping("/trend/list")
@GetMapping("/list")
@Operation(summary = "获得交易状况明细")
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
public CommonResult<List<TradeTrendSummaryRespVO>> getTradeStatisticsList(
TradeTrendReqVO reqVO) {
return success(tradeStatisticsService.getTradeStatisticsList(ArrayUtil.get(reqVO.getTimes(), 0),
ArrayUtil.get(reqVO.getTimes(), 1)));
public CommonResult<List<TradeTrendSummaryRespVO>> getTradeStatisticsList(TradeTrendReqVO reqVO) {
List<TradeStatisticsDO> list = tradeStatisticsService.getTradeStatisticsList(ArrayUtil.get(reqVO.getTimes(), 0),
ArrayUtil.get(reqVO.getTimes(), 1));
return success(TradeStatisticsConvert.INSTANCE.convertList(list));
}
// TODO @疯狂这个要不直接叫 export它即使就是把每条统计导出
@GetMapping("/trend/export-excel")
// TODO 芋艿已经 review
@GetMapping("/export-excel")
@Operation(summary = "导出获得交易状况明细 Excel")
@PreAuthorize("@ss.hasPermission('statistics:trade:export')")
public void exportTradeStatisticsExcel(TradeTrendReqVO reqVO, HttpServletResponse response) throws IOException {
List<TradeTrendSummaryRespVO> list = tradeStatisticsService.getTradeStatisticsList(ArrayUtil.get(reqVO.getTimes(), 0),
List<TradeStatisticsDO> list = tradeStatisticsService.getTradeStatisticsList(ArrayUtil.get(reqVO.getTimes(), 0),
ArrayUtil.get(reqVO.getTimes(), 1));
// 导出 Excel
List<TradeTrendSummaryExcelVO> data = TradeStatisticsConvert.INSTANCE.convertList02(list);
List<TradeTrendSummaryRespVO> voList = TradeStatisticsConvert.INSTANCE.convertList(list);
List<TradeTrendSummaryExcelVO> data = TradeStatisticsConvert.INSTANCE.convertList02(voList);
ExcelUtils.write(response, "交易状况.xls", "数据", TradeTrendSummaryExcelVO.class, data);
}
// TODO 芋艿已经 review
@GetMapping("/order-count")
@Operation(summary = "获得交易订单数量")
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
public CommonResult<TradeOrderCountRespVO> getOrderCount() {
// 订单统计
TradeOrderCountRespVO vo = tradeOrderStatisticsService.getOrderCount();
// 售后统计
vo.setAfterSaleApply(afterSaleStatisticsService.getCountByStatus(AfterSaleStatusEnum.APPLY))
.setAuditingWithdraw(brokerageStatisticsService.getWithdrawCountByStatus(BrokerageWithdrawStatusEnum.AUDITING));
return success(vo);
}
// TODO 芋艿已经 review
@GetMapping("/order-comparison")
@Operation(summary = "获得交易订单数量")
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
public CommonResult<DataComparisonRespVO<TradeOrderSummaryRespVO>> getOrderComparison() {
return success(tradeOrderStatisticsService.getOrderComparison());
}
// TODO 芋艿已经 review
@GetMapping("/order-count-trend")
@Operation(summary = "获得订单量趋势统计")
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
public CommonResult<List<DataComparisonRespVO<TradeOrderTrendRespVO>>> getOrderCountTrendComparison(@Valid TradeOrderTrendReqVO reqVO) {
return success(tradeOrderStatisticsService.getOrderCountTrendComparison(reqVO));
}
}

View File

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.statistics.controller.admin.trade.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 交易订单数量 Response VO")
@Data
public class TradeOrderCountRespVO {
@Schema(description = "待发货", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long undelivered;
@Schema(description = "待核销", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long pickUp;
@Schema(description = "退款中", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long afterSaleApply;
@Schema(description = "提现待审核", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long auditingWithdraw;
}

View File

@ -0,0 +1,16 @@
package cn.iocoder.yudao.module.statistics.controller.admin.trade.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 交易订单统计 Response VO")
@Data
public class TradeOrderSummaryRespVO {
@Schema(description = "支付订单商品数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer orderPayCount;
@Schema(description = "总支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer orderPayPrice;
}

View File

@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.statistics.controller.admin.trade.vo;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.statistics.enums.TimeRangeTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 交易订单量趋势统计 Request VO")
@Data
public class TradeOrderTrendReqVO {
@Schema(description = "日期范围类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "日期范围类型不能为空")
@InEnum(value = TimeRangeTypeEnum.class, message = "日期范围类型,必须是 {value}")
private Integer type;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@Schema(description = "起始时间")
private LocalDateTime beginTime;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@Schema(description = "截止时间")
private LocalDateTime endTime;
}

View File

@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.statistics.controller.admin.trade.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 订单量趋势统计 Response VO")
@Data
public class TradeOrderTrendRespVO {
@Schema(description = "日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private String date;
@Schema(description = "订单数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer orderPayCount;
@Schema(description = "订单支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer orderPayPrice;
}

View File

@ -22,7 +22,7 @@ public class TradeTrendSummaryExcelVO {
private LocalDate date;
@ExcelProperty(value = "营业额", converter = MoneyConvert.class)
private Integer turnover;
private Integer turnoverPrice;
@ExcelProperty(value = "商品支付金额", converter = MoneyConvert.class)
private Integer orderPayPrice;
@ -34,7 +34,7 @@ public class TradeTrendSummaryExcelVO {
private Integer expensePrice;
@ExcelProperty(value = "余额支付金额", converter = MoneyConvert.class)
private Integer balancePrice;
private Integer orderWalletPayPrice;
@ExcelProperty(value = "支付佣金金额", converter = MoneyConvert.class)
private Integer brokerageSettlementPrice;

View File

@ -16,13 +16,15 @@ public class TradeTrendSummaryRespVO {
@JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY)
private LocalDate date;
// TODO @疯狂要不加个 turnoverPrice
@Schema(description = "营业额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer turnover; // 营业额 = 商品支付金额 + 充值金额
private Integer turnoverPrice; // 营业额 = 商品支付金额 + 充值金额
@Schema(description = "订单支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer orderPayPrice;
@Schema(description = "余额支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer orderWalletPayPrice;
@Schema(description = "订单退款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer orderRefundPrice;
@ -35,7 +37,4 @@ public class TradeTrendSummaryRespVO {
@Schema(description = "支出金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer expensePrice; // 余额支付金额 + 支付佣金金额 + 商品退款金额
@Schema(description = "余额支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer balancePrice; // TODO @疯狂这个字段要不改成walletPayPrice
}

View File

@ -4,6 +4,9 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjUtil;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.ip.core.Area;
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAnalyseDataRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAnalyseRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO;
import cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO;
@ -28,16 +31,20 @@ public interface MemberStatisticsConvert {
Map<Integer, Integer> userCountMap,
Map<Integer, MemberAreaStatisticsRespVO> orderMap) {
return CollectionUtils.convertList(areaList, area -> {
MemberAreaStatisticsRespVO orderVo = Optional.ofNullable(orderMap.get(area.getId())).orElseGet(MemberAreaStatisticsRespVO::new);
MemberAreaStatisticsRespVO orderVo = Optional.ofNullable(orderMap.get(area.getId()))
.orElseGet(MemberAreaStatisticsRespVO::new);
return new MemberAreaStatisticsRespVO()
.setAreaId(area.getId()).setAreaName(area.getName())
.setUserCount(MapUtil.getInt(userCountMap, area.getId(), 0))
.setOrderCreateCount(ObjUtil.defaultIfNull(orderVo.getOrderCreateCount(), 0))
.setOrderPayCount(ObjUtil.defaultIfNull(orderVo.getOrderPayCount(), 0))
.setOrderCreateUserCount(ObjUtil.defaultIfNull(orderVo.getOrderCreateUserCount(), 0))
.setOrderPayUserCount(ObjUtil.defaultIfNull(orderVo.getOrderPayUserCount(), 0))
.setOrderPayPrice(ObjUtil.defaultIfNull(orderVo.getOrderPayPrice(), 0));
});
}
MemberSummaryRespVO convert(RechargeSummaryRespBO rechargeSummary, Integer expensePrice, Integer userCount);
MemberAnalyseRespVO convert(Integer visitUserCount, Integer orderUserCount, Integer payUserCount, int atv,
DataComparisonRespVO<MemberAnalyseDataRespVO> comparison);
}

View File

@ -1,14 +1,14 @@
package cn.iocoder.yudao.module.statistics.convert.trade;
import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeSummaryRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryExcelVO;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO;
import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO;
import cn.iocoder.yudao.module.statistics.service.trade.bo.AfterSaleSummaryRespBO;
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeOrderSummaryRespBO;
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO;
import cn.iocoder.yudao.module.statistics.service.trade.bo.AfterSaleSummaryRespBO;
import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@ -25,10 +25,10 @@ public interface TradeStatisticsConvert {
TradeStatisticsConvert INSTANCE = Mappers.getMapper(TradeStatisticsConvert.class);
default TradeStatisticsComparisonRespVO<TradeSummaryRespVO> convert(TradeSummaryRespBO yesterdayData,
TradeSummaryRespBO beforeYesterdayData,
TradeSummaryRespBO monthData,
TradeSummaryRespBO lastMonthData) {
default DataComparisonRespVO<TradeSummaryRespVO> convert(TradeSummaryRespBO yesterdayData,
TradeSummaryRespBO beforeYesterdayData,
TradeSummaryRespBO monthData,
TradeSummaryRespBO lastMonthData) {
return convert(convert(yesterdayData, monthData), convert(beforeYesterdayData, lastMonthData));
}
@ -39,10 +39,10 @@ public interface TradeStatisticsConvert {
.setMonthOrderCount(monthData.getCount()).setMonthPayPrice(monthData.getSummary());
}
TradeStatisticsComparisonRespVO<TradeSummaryRespVO> convert(TradeSummaryRespVO value, TradeSummaryRespVO reference);
DataComparisonRespVO<TradeSummaryRespVO> convert(TradeSummaryRespVO value, TradeSummaryRespVO reference);
TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO> convert(TradeTrendSummaryRespVO value,
TradeTrendSummaryRespVO reference);
DataComparisonRespVO<TradeTrendSummaryRespVO> convert(TradeTrendSummaryRespVO value,
TradeTrendSummaryRespVO reference);
List<TradeTrendSummaryExcelVO> convertList02(List<TradeTrendSummaryRespVO> list);
@ -50,4 +50,21 @@ public interface TradeStatisticsConvert {
AfterSaleSummaryRespBO afterSaleSummary, Integer brokerageSettlementPrice,
WalletSummaryRespBO walletSummary);
List<TradeTrendSummaryRespVO> convertList(List<TradeStatisticsDO> list);
// TODO @疯狂要不要搞个默认的 convertA 方法然后这个 convert 去调用 convertA特殊字段再去 set
default TradeTrendSummaryRespVO convert(TradeStatisticsDO tradeStatistics) {
return new TradeTrendSummaryRespVO()
.setDate(tradeStatistics.getTime().toLocalDate())
// 营业额 = 商品支付金额 + 充值金额
.setTurnoverPrice(tradeStatistics.getOrderPayPrice() + tradeStatistics.getRechargePayPrice())
.setOrderPayPrice(tradeStatistics.getOrderPayPrice())
.setRechargePrice(tradeStatistics.getRechargePayPrice())
// 支出金额 = 余额支付金额 + 支付佣金金额 + 商品退款金额
.setExpensePrice(tradeStatistics.getOrderWalletPayPrice() + tradeStatistics.getBrokerageSettlementPrice() + tradeStatistics.getAfterSaleRefundPrice())
.setOrderWalletPayPrice(tradeStatistics.getOrderWalletPayPrice())
.setBrokerageSettlementPrice(tradeStatistics.getBrokerageSettlementPrice())
.setOrderRefundPrice(tradeStatistics.getAfterSaleRefundPrice());
}
}

View File

@ -48,11 +48,6 @@ public class TradeStatisticsDO extends TenantBaseDO {
* 总支付金额单位
*/
private Integer orderPayPrice;
// TODO @疯狂这个字段改成 walletPayPrice然后挪到 rechargePayCount 前面
/**
* 总支付金额余额单位
*/
private Integer orderWalletPayPrice;
/**
* 退款订单数
@ -68,6 +63,11 @@ public class TradeStatisticsDO extends TenantBaseDO {
*/
private Integer brokerageSettlementPrice;
// TODO @疯狂walletPayPrice钱包支付金额
/**
* 总支付金额余额单位
*/
private Integer orderWalletPayPrice;
/**
* 充值订单数
* <p>

View File

@ -13,14 +13,17 @@ import java.time.LocalDateTime;
* @author owen
*/
@Mapper
public interface ApiAccessLogStatisticsMapper extends BaseMapperX<Object> {
@SuppressWarnings("rawtypes")
public interface ApiAccessLogStatisticsMapper extends BaseMapperX {
// TODO @疯狂是不是 selectIpCount
Integer selectCountByIp(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO 芋艿已经 review
Integer selectIpCountByUserTypeAndCreateTimeBetween(@Param("userType") Integer userType,
@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO @疯狂是不是 selectUserCount
Integer selectCountByUserId(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO 芋艿已经 review
Integer selectUserCountByUserTypeAndCreateTimeBetween(@Param("userType") Integer userType,
@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
}

View File

@ -1,8 +1,10 @@
package cn.iocoder.yudao.module.statistics.dal.mysql.member;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberRegisterCountRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSexStatisticsRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberTerminalStatisticsRespVO;
import cn.iocoder.yudao.module.statistics.service.member.bo.MemberAreaStatisticsRespBO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -15,16 +17,31 @@ import java.util.List;
* @author owen
*/
@Mapper
public interface MemberStatisticsMapper extends BaseMapperX<Object> {
@SuppressWarnings("rawtypes")
public interface MemberStatisticsMapper extends BaseMapperX {
// TODO @芋艿已经 review
// TODO @疯狂要不还是搞下 bo虽然可能冗余了点~~
List<MemberAreaStatisticsRespVO> selectSummaryListByAreaId();
List<MemberAreaStatisticsRespBO> selectSummaryListByAreaId();
// TODO @芋艿已经 review
List<MemberSexStatisticsRespVO> selectSummaryListBySex();
// TODO @芋艿已经 review
List<MemberTerminalStatisticsRespVO> selectSummaryListByRegisterTerminal();
// TODO @芋艿已经 review
Integer selectUserCount(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO @芋艿已经 review
/**
* 获得用户的每天注册数量列表
*
* @param beginTime 开始时间
* @param endTime 结束时间
* @return 每天注册数量列表
*/
List<MemberRegisterCountRespVO> selectListByCreateTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
}

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.module.statistics.dal.mysql.pay;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO;
import cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO;
import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO;
import org.apache.ibatis.annotations.Mapper;
@ -15,7 +14,8 @@ import java.time.LocalDateTime;
* @author owen
*/
@Mapper
public interface PayWalletStatisticsMapper extends BaseMapperX<TradeStatisticsDO> {
@SuppressWarnings("rawtypes")
public interface PayWalletStatisticsMapper extends BaseMapperX {
// TODO 芋艿已经 review
WalletSummaryRespBO selectRechargeSummaryByPayTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@ -37,4 +37,7 @@ public interface PayWalletStatisticsMapper extends BaseMapperX<TradeStatisticsDO
@Param("endTime") LocalDateTime endTime,
@Param("payStatus") Boolean payStatus);
// TODO 芋艿已经 review
Integer selectRechargePriceSummary(@Param("payStatus") Integer payStatus);
}

View File

@ -20,4 +20,7 @@ public interface AfterSaleStatisticsMapper extends BaseMapperX<TradeStatisticsDO
AfterSaleSummaryRespBO selectSummaryByRefundTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO 芋艿已经 review
Long selectCountByStatus(@Param("status") Integer status);
}

View File

@ -15,9 +15,13 @@ import java.time.LocalDateTime;
@Mapper
public interface BrokerageStatisticsMapper extends BaseMapperX<TradeStatisticsDO> {
// TODO 芋艿已经 review
Integer selectSummaryPriceByStatusAndUnfreezeTimeBetween(@Param("bizType") Integer bizType,
@Param("status") Integer status,
@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO 芋艿已经 review
Long selectWithdrawCountByStatus(@Param("status") Integer status);
}

View File

@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.statistics.dal.mysql.trade;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeOrderSummaryRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeOrderTrendRespVO;
import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -40,4 +42,37 @@ public interface TradeOrderStatisticsMapper extends BaseMapperX<TradeStatisticsD
Integer selectUserCountByPayTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 按照支付时间统计订单按天分组
*
* @param beginTime 支付起始时间
* @param endTime 支付截止时间
* @return 订单统计列表
*/
List<TradeOrderTrendRespVO> selectListByPayTimeBetweenAndGroupByDay(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 按照支付时间统计订单按月分组
*
* @param beginTime 支付起始时间
* @param endTime 支付截止时间
* @return 订单统计列表
*/
List<TradeOrderTrendRespVO> selectListByPayTimeBetweenAndGroupByMonth(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO @芋艿已经 review
Long selectCountByStatus(@Param("status") Integer status);
// TODO 芋艿已经 review
Long selectCountByStatusAndPickUpStoreIdIsNotNull(@Param("status") Integer status);
// TODO 芋艿已经 review
TradeOrderSummaryRespVO selectPaySummaryByStatusAndPayTimeBetween(@Param("status") Integer status,
@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.statistics.dal.mysql.trade;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO;
import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO;
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO;
@ -21,14 +22,23 @@ public interface TradeStatisticsMapper extends BaseMapperX<TradeStatisticsDO> {
TradeSummaryRespBO selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
TradeTrendSummaryRespVO selectByTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
TradeTrendSummaryRespVO selectVoByTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO @芋艿已经 review
List<TradeTrendSummaryRespVO> selectListByTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
default List<TradeStatisticsDO> selectListByTimeBetween(LocalDateTime beginTime, LocalDateTime endTime) {
return selectList(new LambdaQueryWrapperX<TradeStatisticsDO>()
.between(TradeStatisticsDO::getTime, beginTime, endTime));
}
// TODO @芋艿已经 review
Integer selectExpensePriceByTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
// TODO @芋艿已经 review
default TradeStatisticsDO selectByTimeBetween(LocalDateTime beginTime, LocalDateTime endTime) {
return selectOne(new LambdaQueryWrapperX<TradeStatisticsDO>()
.between(TradeStatisticsDO::getTime, beginTime, endTime));
}
}

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.statistics.job.trade;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
@ -19,11 +21,25 @@ public class TradeStatisticsJob implements JobHandler {
@Resource
private TradeStatisticsService tradeStatisticsService;
/**
* 执行交易统计任务
*
* @param param 要统计的天数只能是正整数1 代表昨日数据
* @return 统计结果
*/
@Override
@TenantJob
public String execute(String param) {
String times = tradeStatisticsService.statisticsYesterdayTrade();
return StrUtil.format("交易统计耗时: {}", times);
// TODO @疯狂要搞个默认的 1
if (NumberUtil.isInteger(param)) {
throw new RuntimeException("交易统计任务的参数只能为是正整数");
}
Integer days = Convert.toInt(param, 0);
if (days < 1) {
throw new RuntimeException("交易统计任务的参数只能为是正整数");
}
String result = tradeStatisticsService.statisticsTrade(days);
return StrUtil.format("交易统计:\n{}", result);
}
}

View File

@ -9,26 +9,26 @@ import java.time.LocalDateTime;
*/
public interface ApiAccessLogStatisticsService {
// TODO @疯狂需要传递 userType因为访问日志可能涉及多种用户类型
// TODO @疯狂方法名要不改成 getUserCount原因让它更业务无关
// TODO 芋艿已经 review
/**
* 获取活跃用户数量
*
* @param userType 用户类型
* @param beginTime 起始时间
* @param endTime 截止时间
* @return 活跃用户数量
*/
Integer getActiveUserCount(LocalDateTime beginTime, LocalDateTime endTime);
Integer getUserCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime);
// TODO @疯狂需要传递 userType因为访问日志可能涉及多种用户类型
// TODO @疯狂方法名要不改成 getIpCount原因让它更业务无关
// TODO 芋艿已经 review
/**
* 获取访问用户数量
*
* @param userType 用户类型
* @param beginTime 起始时间
* @param endTime 截止时间
* @return 访问用户数量
*/
Integer getVisitorUserCount(LocalDateTime beginTime, LocalDateTime endTime);
Integer getIpCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime);
}

View File

@ -20,13 +20,13 @@ public class ApiAccessLogStatisticsServiceImpl implements ApiAccessLogStatistics
private ApiAccessLogStatisticsMapper apiAccessLogStatisticsMapper;
@Override
public Integer getActiveUserCount(LocalDateTime beginTime, LocalDateTime endTime) {
return apiAccessLogStatisticsMapper.selectCountByUserId(beginTime, endTime);
public Integer getUserCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime) {
return apiAccessLogStatisticsMapper.selectUserCountByUserTypeAndCreateTimeBetween(userType, beginTime, endTime);
}
@Override
public Integer getVisitorUserCount(LocalDateTime beginTime, LocalDateTime endTime) {
return apiAccessLogStatisticsMapper.selectCountByIp(beginTime, endTime);
public Integer getIpCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime) {
return apiAccessLogStatisticsMapper.selectIpCountByUserTypeAndCreateTimeBetween(userType, beginTime, endTime);
}
}

View File

@ -1,9 +1,7 @@
package cn.iocoder.yudao.module.statistics.service.member;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAnalyseRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSexStatisticsRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.*;
import java.time.LocalDateTime;
import java.util.List;
@ -25,14 +23,16 @@ public interface MemberStatisticsService {
// TODO 芋艿已经 review
/**
* 获取用户分析数据
* 获取会员分析对照数据
*
* @param beginTime 起始时间
* @param endTime 截止时间
* @return 用户分析数据
* @return 会员分析对照数据
*/
MemberAnalyseRespVO getMemberAnalyse(LocalDateTime beginTime, LocalDateTime endTime);
DataComparisonRespVO<MemberAnalyseDataRespVO> getMemberAnalyseComparisonData(LocalDateTime beginTime,
LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 按照省份获得会员统计列表
*
@ -40,6 +40,7 @@ public interface MemberStatisticsService {
*/
List<MemberAreaStatisticsRespVO> getMemberAreaStatisticsList();
// TODO 芋艿已经 review
/**
* 按照性别获得会员统计列表
*
@ -47,4 +48,30 @@ public interface MemberStatisticsService {
*/
List<MemberSexStatisticsRespVO> getMemberSexStatisticsList();
// TODO @疯狂这个要不要使用 getMemberTerminalStatisticsList保持统一
/**
* 按照终端获得会员统计列表
*
* @return 会员统计列表
*/
List<MemberTerminalStatisticsRespVO> getRegisterTerminalStatisticsList();
// TODO 芋艿已经 review
/**
* 获取用户注册数量列表
*
* @param beginTime 起始时间
* @param endTime 截止时间
* @return 注册数量列表
*/
List<MemberRegisterCountRespVO> getMemberRegisterCountList(LocalDateTime beginTime, LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 获得用户数量量统计对照
*
* @return 用户数量量统计对照
*/
DataComparisonRespVO<MemberCountRespVO> getUserCountComparison();
}

View File

@ -1,19 +1,22 @@
package cn.iocoder.yudao.module.statistics.service.member;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.ip.core.Area;
import cn.iocoder.yudao.framework.ip.core.enums.AreaTypeEnum;
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.*;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO;
import cn.iocoder.yudao.module.statistics.convert.member.MemberStatisticsConvert;
import cn.iocoder.yudao.module.statistics.dal.mysql.member.MemberStatisticsMapper;
import cn.iocoder.yudao.module.statistics.service.infra.ApiAccessLogStatisticsService;
import cn.iocoder.yudao.module.statistics.service.member.bo.MemberAreaStatisticsRespBO;
import cn.iocoder.yudao.module.statistics.service.pay.PayWalletStatisticsService;
import cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO;
import cn.iocoder.yudao.module.statistics.service.trade.TradeOrderStatisticsService;
import cn.iocoder.yudao.module.statistics.service.trade.TradeStatisticsService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.module.statistics.convert.member.MemberStatisticsConvert;
import javax.annotation.Resource;
import java.time.Duration;
@ -57,63 +60,77 @@ public class MemberStatisticsServiceImpl implements MemberStatisticsService {
@Override
public List<MemberAreaStatisticsRespVO> getMemberAreaStatisticsList() {
// 统计用户
// TODO @疯狂要处理下未知省份就是没填写省份的情况
// TODO @疯狂可能得把每个省的用户都查询出来然后去 order 那边 in因为要按照这些人为基础来计算用户规模量大可能不太好但是暂时就先这样搞吧 = =
Map<Integer, Integer> userCountMap = convertMap(memberStatisticsMapper.selectSummaryListByAreaId(),
vo -> AreaUtils.getParentIdByType(vo.getAreaId(), AreaTypeEnum.PROVINCE),
MemberAreaStatisticsRespVO::getUserCount, Integer::sum);
MemberAreaStatisticsRespBO::getUserCount, Integer::sum);
// 统计订单
Map<Integer, MemberAreaStatisticsRespVO> orderMap = convertMap(tradeOrderStatisticsService.getSummaryListByAreaId(),
vo -> AreaUtils.getParentIdByType(vo.getAreaId(), AreaTypeEnum.PROVINCE),
vo -> vo,
(a, b) -> new MemberAreaStatisticsRespVO()
.setOrderCreateCount(a.getOrderCreateCount() + b.getOrderCreateCount())
.setOrderPayCount(a.getOrderPayCount() + b.getOrderPayCount())
.setOrderCreateUserCount(a.getOrderCreateUserCount() + b.getOrderCreateUserCount())
.setOrderPayUserCount(a.getOrderPayUserCount() + b.getOrderPayUserCount())
.setOrderPayPrice(a.getOrderPayPrice() + b.getOrderPayPrice()));
// 拼接数据
return MemberStatisticsConvert.INSTANCE.convertList(AreaUtils.getByType(AreaTypeEnum.PROVINCE, area -> area), userCountMap, orderMap);
List<Area> areaList = AreaUtils.getByType(AreaTypeEnum.PROVINCE, area -> area);
areaList.add(new Area().setId(null).setName("未知"));
return MemberStatisticsConvert.INSTANCE.convertList(areaList, userCountMap, orderMap);
}
// TODO @疯狂这个方法要不拆成1controller 调用 getMemberAnalyseComparisonData2tradeOrderStatisticsService.getPayUserCount3tradeOrderStatisticsService.getOrderPayPrice4
// TODO 就是说分析交给 controller 去组合
@Override
public MemberAnalyseRespVO getMemberAnalyse(LocalDateTime beginTime, LocalDateTime endTime) {
public DataComparisonRespVO<MemberAnalyseDataRespVO> getMemberAnalyseComparisonData(LocalDateTime beginTime, LocalDateTime endTime) {
// 当前数据
MemberAnalyseDataRespVO vo = getMemberAnalyseData(beginTime, endTime);
// 对照数据
MemberAnalyseComparisonRespVO vo = getMemberAnalyseComparisonData(beginTime, endTime);
// TODO @疯狂如果时间段这么处理会不会 beginTime 重叠了因为是 <= 一个时间如果数据库插入的是 xxxx-yy-zz 00:00:00 的话它既满足 >= ? 也满足 <= 如果不好理解微信聊)
LocalDateTime referenceBeginTime = beginTime.minus(Duration.between(beginTime, endTime));
MemberAnalyseComparisonRespVO reference = getMemberAnalyseComparisonData(referenceBeginTime, beginTime);
// 计算客单价
// TODO @疯狂这个可能有点特殊要按照 create_time 来查询不然它的漏斗就不统一因为是访问数量 > 今日下单人 > 今日支付人是一个统一的维度
Integer payUserCount = tradeOrderStatisticsService.getPayUserCount(beginTime, endTime);
int atv = 0;
if (payUserCount != null && payUserCount > 0) {
// TODO @疯狂类似上面的 payUserCount
Integer payPrice = tradeOrderStatisticsService.getOrderPayPrice(beginTime, endTime);
atv = NumberUtil.div(payPrice, payUserCount).intValue();
}
return new MemberAnalyseRespVO()
.setVisitorCount(apiAccessLogStatisticsService.getVisitorUserCount(beginTime, endTime))
.setOrderUserCount(tradeOrderStatisticsService.getOrderUserCount(beginTime, endTime))
.setPayUserCount(payUserCount)
.setAtv(atv)
.setComparison(new TradeStatisticsComparisonRespVO<>(vo, reference));
LocalDateTime referenceEndDate = beginTime.minusDays(1); // 减少1天防止出现时间重叠
LocalDateTime referenceBeginDate = referenceEndDate.minus(Duration.between(beginTime, endTime));
MemberAnalyseDataRespVO reference = getMemberAnalyseData(
LocalDateTimeUtil.beginOfDay(referenceBeginDate), LocalDateTimeUtil.endOfDay(referenceEndDate));
return new DataComparisonRespVO<>(vo, reference);
}
private MemberAnalyseComparisonRespVO getMemberAnalyseComparisonData(LocalDateTime beginTime, LocalDateTime endTime) {
private MemberAnalyseDataRespVO getMemberAnalyseData(LocalDateTime beginTime, LocalDateTime endTime) {
Integer rechargeUserCount = Optional.ofNullable(payWalletStatisticsService.getUserRechargeSummary(beginTime, endTime))
.map(RechargeSummaryRespBO::getRechargeUserCount).orElse(0);
return new MemberAnalyseComparisonRespVO()
.setUserCount(memberStatisticsMapper.selectUserCount(beginTime, endTime))
.setActiveUserCount(apiAccessLogStatisticsService.getActiveUserCount(beginTime, endTime))
return new MemberAnalyseDataRespVO()
.setRegisterUserCount(memberStatisticsMapper.selectUserCount(beginTime, endTime))
.setVisitUserCount(apiAccessLogStatisticsService.getUserCount(UserTypeEnum.MEMBER.getValue(), beginTime, endTime))
.setRechargeUserCount(rechargeUserCount);
}
@Override
public List<MemberSexStatisticsRespVO> getMemberSexStatisticsList() {
// TODO @疯狂需要考虑用户性别为空则是未知
return memberStatisticsMapper.selectSummaryListBySex();
}
@Override
public List<MemberTerminalStatisticsRespVO> getRegisterTerminalStatisticsList() {
return memberStatisticsMapper.selectSummaryListByRegisterTerminal();
}
@Override
public List<MemberRegisterCountRespVO> getMemberRegisterCountList(LocalDateTime beginTime, LocalDateTime endTime) {
return memberStatisticsMapper.selectListByCreateTimeBetween(beginTime, endTime);
}
@Override
public DataComparisonRespVO<MemberCountRespVO> getUserCountComparison() {
// 今日时间范围
LocalDateTime beginOfToday = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
LocalDateTime endOfToday = LocalDateTimeUtil.endOfDay(beginOfToday);
// 昨日时间范围
LocalDateTime beginOfYesterday = LocalDateTimeUtil.beginOfDay(beginOfToday.minusDays(1));
LocalDateTime endOfYesterday = LocalDateTimeUtil.endOfDay(beginOfYesterday);
return new DataComparisonRespVO<MemberCountRespVO>()
.setValue(getUserCount(beginOfToday, endOfToday))
.setReference(getUserCount(beginOfYesterday, endOfYesterday));
}
private MemberCountRespVO getUserCount(LocalDateTime beginTime, LocalDateTime endTime) {
return new MemberCountRespVO()
.setCreateUserCount(memberStatisticsMapper.selectUserCount(beginTime, endTime))
.setVisitUserCount(apiAccessLogStatisticsService.getIpCount(UserTypeEnum.MEMBER.getValue(), beginTime, endTime));
}
}

View File

@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.statistics.service.member.bo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 会员地区统计 Response BO")
@Data
public class MemberAreaStatisticsRespBO {
/**
* 省份编号
*/
private Integer areaId;
/**
* 省份名称
*/
private String areaName;
/**
* 会员数量
*/
private Integer userCount;
/**
* 下单的会员数量
*/
private Integer orderCreateUserCount;
/**
* 支付订单的会员数量
*/
private Integer orderPayUserCount;
/**
* 订单支付金额单位
*/
private Integer orderPayPrice;
}

View File

@ -32,4 +32,12 @@ public interface PayWalletStatisticsService {
*/
RechargeSummaryRespBO getUserRechargeSummary(LocalDateTime beginTime, LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 获取充值金额合计
*
* @return 充值金额合计
*/
Integer getRechargePriceSummary();
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.statistics.service.pay;
import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum;
import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum;
import cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum;
import cn.iocoder.yudao.module.statistics.dal.mysql.pay.PayWalletStatisticsMapper;
import cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO;
@ -43,4 +44,9 @@ public class PayWalletStatisticsServiceImpl implements PayWalletStatisticsServic
return payWalletStatisticsMapper.selectRechargeSummaryGroupByWalletId(beginTime, endTime, true);
}
@Override
public Integer getRechargePriceSummary() {
return payWalletStatisticsMapper.selectRechargePriceSummary(PayOrderStatusEnum.SUCCESS.getStatus());
}
}

View File

@ -3,15 +3,20 @@ package cn.iocoder.yudao.module.statistics.service.pay.bo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
// TODO @疯狂BO 不用写 swagger 注解哈写注释就好啦
@Schema(description = "管理后台 - 充值统计 Response VO")
/**
* 充值统计 Response BO
*/
@Data
public class RechargeSummaryRespBO {
@Schema(description = "充值会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "221")
/**
* 充值会员数量
*/
private Integer rechargeUserCount;
@Schema(description = "充值金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
/**
* 充值金额
*/
private Integer rechargePrice;
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.statistics.service.trade;
import cn.iocoder.yudao.module.statistics.service.trade.bo.AfterSaleSummaryRespBO;
import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleStatusEnum;
import java.time.LocalDateTime;
@ -21,4 +22,13 @@ public interface AfterSaleStatisticsService {
*/
AfterSaleSummaryRespBO getAfterSaleSummary(LocalDateTime beginTime, LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 获取指定状态的售后订单数量
*
* @param status 售后状态
* @return 售后订单数量
*/
Long getCountByStatus(AfterSaleStatusEnum status);
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.statistics.service.trade;
import cn.iocoder.yudao.module.statistics.dal.mysql.trade.AfterSaleStatisticsMapper;
import cn.iocoder.yudao.module.statistics.service.trade.bo.AfterSaleSummaryRespBO;
import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleStatusEnum;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -25,4 +26,9 @@ public class AfterSaleStatisticsServiceImpl implements AfterSaleStatisticsServic
return afterSaleStatisticsMapper.selectSummaryByRefundTimeBetween(beginTime, endTime);
}
@Override
public Long getCountByStatus(AfterSaleStatusEnum status) {
return afterSaleStatisticsMapper.selectCountByStatus(status.getStatus());
}
}

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.statistics.service.trade;
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
import java.time.LocalDateTime;
/**
@ -19,4 +21,13 @@ public interface BrokerageStatisticsService {
*/
Integer getBrokerageSettlementPriceSummary(LocalDateTime beginTime, LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 获取指定状态的提现记录数量
*
* @param status 提现记录状态
* @return 提现记录数量
*/
Long getWithdrawCountByStatus(BrokerageWithdrawStatusEnum status);
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.statistics.service.trade;
import cn.iocoder.yudao.module.statistics.dal.mysql.trade.BrokerageStatisticsMapper;
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum;
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -28,4 +29,9 @@ public class BrokerageStatisticsServiceImpl implements BrokerageStatisticsServic
beginTime, endTime);
}
@Override
public Long getWithdrawCountByStatus(BrokerageWithdrawStatusEnum status) {
return brokerageStatisticsMapper.selectWithdrawCountByStatus(status.getStatus());
}
}

View File

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.statistics.service.trade;
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.*;
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeOrderSummaryRespBO;
import java.time.LocalDateTime;
@ -60,4 +62,29 @@ public interface TradeOrderStatisticsService {
*/
Integer getOrderPayPrice(LocalDateTime beginTime, LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 获得交易订单数量
*
* @return 订单数量
*/
TradeOrderCountRespVO getOrderCount();
// TODO 芋艿已经 review
/**
* 交易订单销售额对照
*
* @return 销售额对照
*/
DataComparisonRespVO<TradeOrderSummaryRespVO> getOrderComparison();
// TODO 芋艿已经 review
/**
* 获得订单量趋势统计
*
* @param reqVO 统计参数
* @return 订单量趋势统计
*/
List<DataComparisonRespVO<TradeOrderTrendRespVO>> getOrderCountTrendComparison(TradeOrderTrendReqVO reqVO);
}

View File

@ -1,14 +1,25 @@
package cn.iocoder.yudao.module.statistics.service.trade;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjUtil;
import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum;
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.*;
import cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeOrderStatisticsMapper;
import cn.iocoder.yudao.module.statistics.enums.TimeRangeTypeEnum;
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeOrderSummaryRespBO;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* 交易订单统计 Service 实现类
@ -50,4 +61,53 @@ public class TradeOrderStatisticsServiceImpl implements TradeOrderStatisticsServ
return tradeOrderStatisticsMapper.selectSummaryPriceByPayTimeBetween(beginTime, endTime);
}
@Override
public TradeOrderCountRespVO getOrderCount() {
// TODO 疯狂这个可以根据 status + delivertyType 来过滤呀ps是不是搞个 service 方法交给上层去聚合这样 TradeOrderCountRespVO 可以更明确返回不用搞 bo
Long undeliveredCount = tradeOrderStatisticsMapper.selectCountByStatus(TradeOrderStatusEnum.UNDELIVERED.getStatus());
Long pickUpCount = tradeOrderStatisticsMapper.selectCountByStatusAndPickUpStoreIdIsNotNull(TradeOrderStatusEnum.DELIVERED.getStatus());
return new TradeOrderCountRespVO()
.setPickUp(ObjUtil.defaultIfNull(pickUpCount, 0L))
.setUndelivered(ObjUtil.defaultIfNull(undeliveredCount, 0L));
}
@Override
public DataComparisonRespVO<TradeOrderSummaryRespVO> getOrderComparison() {
return new DataComparisonRespVO<TradeOrderSummaryRespVO>()
.setValue(getPayPriceSummary(LocalDateTime.now()))
.setReference(getPayPriceSummary(LocalDateTime.now().minusDays(1)));
}
private TradeOrderSummaryRespVO getPayPriceSummary(LocalDateTime date) {
LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(date);
LocalDateTime endTime = LocalDateTimeUtil.beginOfDay(date);
return tradeOrderStatisticsMapper.selectPaySummaryByStatusAndPayTimeBetween(
PayOrderStatusEnum.SUCCESS.getStatus(), beginTime, endTime);
}
@Override
public List<DataComparisonRespVO<TradeOrderTrendRespVO>> getOrderCountTrendComparison(TradeOrderTrendReqVO reqVO) {
// 查询当前数据
List<TradeOrderTrendRespVO> value = getOrderCountTrend(reqVO.getType(), reqVO.getBeginTime(), reqVO.getEndTime());
// 查询对照数据
LocalDateTime referenceEndTime = reqVO.getBeginTime().minusDays(1);
LocalDateTime referenceBeginTime = referenceEndTime.minus(Duration.between(reqVO.getBeginTime(), reqVO.getEndTime()));
List<TradeOrderTrendRespVO> reference = getOrderCountTrend(reqVO.getType(), referenceBeginTime, referenceEndTime);
// 顺序对比返回
return IntStream.range(0, value.size())
.mapToObj(index -> new DataComparisonRespVO<TradeOrderTrendRespVO>()
.setValue(CollUtil.get(value, index))
.setReference(CollUtil.get(reference, index)))
.collect(Collectors.toList());
}
private List<TradeOrderTrendRespVO> getOrderCountTrend(Integer timeRangeType, LocalDateTime beginTime, LocalDateTime endTime) {
// 情况一按年统计时以月份分组
if (TimeRangeTypeEnum.YEAR.getType().equals(timeRangeType)) {
return tradeOrderStatisticsMapper.selectListByPayTimeBetweenAndGroupByMonth(beginTime, endTime);
}
// 情况二其它以天分组
return tradeOrderStatisticsMapper.selectListByPayTimeBetweenAndGroupByDay(beginTime, endTime);
}
}

View File

@ -1,8 +1,9 @@
package cn.iocoder.yudao.module.statistics.service.trade;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeSummaryRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO;
import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO;
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO;
import java.time.LocalDateTime;
import java.util.List;
@ -14,26 +15,19 @@ import java.util.List;
*/
public interface TradeStatisticsService {
/**
* 获得交易统计
*
* @return 统计数据对照
*/
TradeStatisticsComparisonRespVO<TradeSummaryRespVO> getTradeSummaryComparison();
/**
* 获得交易状况统计对照
*
* @return 统计数据对照
*/
TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO> getTradeTrendSummaryComparison(
DataComparisonRespVO<TradeTrendSummaryRespVO> getTradeTrendSummaryComparison(
LocalDateTime beginTime, LocalDateTime endTime);
/**
* 获得交易状况统计
*
* @param beginTime 开始时间
* @param endTime 结束时间
* @param endTime 结束时间
* @return 统计数据对照
*/
Integer getExpensePrice(LocalDateTime beginTime, LocalDateTime endTime);
@ -41,16 +35,36 @@ public interface TradeStatisticsService {
/**
* 获得交易状况明细
*
* @param beginTime 开始时间
* @param endTime 结束时间
* @return 统计数据列表
*/
List<TradeTrendSummaryRespVO> getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime);
List<TradeStatisticsDO> getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime);
// TODO 芋艿已经 review
/**
* 统计昨日交易
* 统计指定天数的交易数据
*
* @return 耗时
* @return 统计结果
*/
String statisticsYesterdayTrade();
String statisticsTrade(Integer days);
// TODO 芋艿已经 review
/**
* 统计指定日期的交易数据
*
* @param days 增加的天数
* @return 交易数据
*/
TradeSummaryRespBO getTradeSummaryByDays(int days);
// TODO 芋艿已经 review
/**
* 统计指定月份的交易数据
*
* @param months 增加的月数
* @return 交易数据
*/
TradeSummaryRespBO getTradeSummaryByMonths(int months);
}

View File

@ -1,18 +1,18 @@
package cn.iocoder.yudao.module.statistics.service.trade;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import cn.iocoder.yudao.module.statistics.service.pay.PayWalletStatisticsService;
import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeSummaryRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO;
import cn.iocoder.yudao.module.statistics.convert.trade.TradeStatisticsConvert;
import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO;
import cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeStatisticsMapper;
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO;
import cn.iocoder.yudao.module.statistics.service.pay.PayWalletStatisticsService;
import cn.iocoder.yudao.module.statistics.service.trade.bo.AfterSaleSummaryRespBO;
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeOrderSummaryRespBO;
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO;
import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO;
import org.springframework.stereotype.Service;
import org.springframework.util.StopWatch;
import org.springframework.validation.annotation.Validated;
@ -21,6 +21,8 @@ import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* 交易统计 Service 实现类
@ -44,51 +46,27 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService {
private PayWalletStatisticsService payWalletStatisticsService;
@Override
public TradeStatisticsComparisonRespVO<TradeSummaryRespVO> getTradeSummaryComparison() {
// 1.1 昨天的数据
TradeSummaryRespBO yesterdayData = getTradeSummaryByDays(-1);
// 1.2 前天的数据用于对照昨天的数据
TradeSummaryRespBO beforeYesterdayData = getTradeSummaryByDays(-2);
// 2.1 本月数据
TradeSummaryRespBO monthData = getTradeSummaryByMonths(0);
// 2.2 上月数据用于对照本月的数据
TradeSummaryRespBO lastMonthData = getTradeSummaryByMonths(-1);
// 转换返回
return TradeStatisticsConvert.INSTANCE.convert(yesterdayData, beforeYesterdayData, monthData, lastMonthData);
}
/**
* 统计指定日期的交易数据
*
* @param days 增加的天数
* @return 交易数据
*/
private TradeSummaryRespBO getTradeSummaryByDays(int days) {
public TradeSummaryRespBO getTradeSummaryByDays(int days) {
LocalDateTime date = LocalDateTime.now().plusDays(days);
return tradeStatisticsMapper.selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(
LocalDateTimeUtil.beginOfDay(date), LocalDateTimeUtil.endOfDay(date));
}
/**
* 统计指定月份的交易数据
*
* @param months 增加的月数
* @return 交易数据
*/
private TradeSummaryRespBO getTradeSummaryByMonths(int months) {
@Override
public TradeSummaryRespBO getTradeSummaryByMonths(int months) {
LocalDateTime monthDate = LocalDateTime.now().plusMonths(months);
return tradeStatisticsMapper.selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(
LocalDateTimeUtils.beginOfMonth(monthDate), LocalDateTimeUtils.endOfMonth(monthDate));
}
@Override
public TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO> getTradeTrendSummaryComparison(LocalDateTime beginTime,
LocalDateTime endTime) {
public DataComparisonRespVO<TradeTrendSummaryRespVO> getTradeTrendSummaryComparison(LocalDateTime beginTime,
LocalDateTime endTime) {
// 统计数据
TradeTrendSummaryRespVO value = tradeStatisticsMapper.selectByTimeBetween(beginTime, endTime);
TradeTrendSummaryRespVO value = tradeStatisticsMapper.selectVoByTimeBetween(beginTime, endTime);
// 对照数据
LocalDateTime referenceBeginTime = beginTime.minus(Duration.between(beginTime, endTime));
TradeTrendSummaryRespVO reference = tradeStatisticsMapper.selectByTimeBetween(referenceBeginTime, beginTime);
TradeTrendSummaryRespVO reference = tradeStatisticsMapper.selectVoByTimeBetween(referenceBeginTime, beginTime);
return TradeStatisticsConvert.INSTANCE.convert(value, reference);
}
@ -97,42 +75,63 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService {
return tradeStatisticsMapper.selectExpensePriceByTimeBetween(beginTime, endTime);
}
// TODO @疯狂是不是直接返回 TradeStatisticsDO上层在去聚合
@Override
public List<TradeTrendSummaryRespVO> getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime) {
public List<TradeStatisticsDO> getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime) {
return tradeStatisticsMapper.selectListByTimeBetween(beginTime, endTime);
}
@Override
public String statisticsYesterdayTrade() {
// TODO @疯狂如果已经统计则跳过
// TODO @疯狂改成 statisticsTrade然后传入 days统计多少天days 通过 job 传参方便把历史给统计出来或者大家有的时候要修复数据 fix 业务数据然后清理统计表重新统计的时候
// 1. 从各个数据表统计对应数据
LocalDateTime yesterday = LocalDateTime.now().minusDays(1);
LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday);
LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday);
// 1.1 统计订单
StopWatch stopWatch = new StopWatch("交易统计");
public String statisticsTrade(Integer days) {
LocalDateTime today = LocalDateTime.now();
// TODO @疯狂不用并发哈因为租户可能会丢然后一般串行就好对性能没绝对的要求哈天数也不会多
return IntStream.rangeClosed(1, days)
.parallel()
.mapToObj(day -> statisticsTrade(today.minusDays(day)))
.sorted()
.collect(Collectors.joining("\n"));
}
/**
* 统计交易数据
*
* @param date 需要统计的日期
* @return 统计结果
*/
private String statisticsTrade(LocalDateTime date) {
// 1. 处理统计时间范围
LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(date);
LocalDateTime endTime = LocalDateTimeUtil.endOfDay(date);
String dateStr = DatePattern.NORM_DATE_FORMAT.format(date);
// 2. 检查该日是否已经统计过
TradeStatisticsDO entity = tradeStatisticsMapper.selectByTimeBetween(beginTime, endTime);
if (entity != null) {
return dateStr + " 数据已存在,如果需要重新统计,请先删除对应的数据";
}
// 3. 从各个数据表统计对应数据
StopWatch stopWatch = new StopWatch(dateStr);
// 3.1 统计订单
stopWatch.start("统计订单");
TradeOrderSummaryRespBO orderSummary = tradeOrderStatisticsService.getOrderSummary(beginTime, endTime);
stopWatch.stop();
// 1.2 统计售后
// 3.2 统计售后
stopWatch.start("统计售后");
AfterSaleSummaryRespBO afterSaleSummary = afterSaleStatisticsService.getAfterSaleSummary(beginTime, endTime);
stopWatch.stop();
// 1.3 统计佣金
// 3.3 统计佣金
stopWatch.start("统计佣金");
Integer brokerageSettlementPrice = brokerageStatisticsService.getBrokerageSettlementPriceSummary(beginTime, endTime);
stopWatch.stop();
// 1.4 统计充值
// 3.4 统计充值
stopWatch.start("统计充值");
WalletSummaryRespBO walletSummary = payWalletStatisticsService.getWalletSummary(beginTime, endTime);
stopWatch.stop();
// 2. 插入数据
TradeStatisticsDO entity = TradeStatisticsConvert.INSTANCE.convert(yesterday, orderSummary, afterSaleSummary,
brokerageSettlementPrice, walletSummary);
// 4. 插入数据
entity = TradeStatisticsConvert.INSTANCE.convert(date, orderSummary, afterSaleSummary, brokerageSettlementPrice,
walletSummary);
tradeStatisticsMapper.insert(entity);
// TODO @疯狂这里是不是也要把日期带上类似 108 那边
return stopWatch.prettyPrint();
}

View File

@ -2,23 +2,21 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.statistics.dal.mysql.infra.ApiAccessLogStatisticsMapper">
<select id="selectCountByIp" resultType="java.lang.Integer">
<!-- TODO @疯狂distinct 会不会更合适哈 -->
SELECT COUNT(1)
<select id="selectIpCountByUserTypeAndCreateTimeBetween" resultType="java.lang.Integer">
SELECT COUNT(DISTINCT user_ip)
FROM infra_api_access_log
WHERE create_time BETWEEN #{beginTime} AND #{endTime}
AND deleted = FALSE
GROUP BY user_ip
WHERE user_type = #{userType}
AND create_time BETWEEN #{beginTime} AND #{endTime}
AND deleted = FALSE
</select>
<select id="selectCountByUserId" resultType="java.lang.Integer">
<!-- TODO @疯狂distinct 会不会更合适哈 -->
SELECT COUNT(1)
<select id="selectUserCountByUserTypeAndCreateTimeBetween" resultType="java.lang.Integer">
SELECT COUNT(DISTINCT user_id)
FROM infra_api_access_log
WHERE user_id > 0
AND user_type = #{userType}
AND create_time BETWEEN #{beginTime} AND #{endTime}
AND deleted = FALSE
GROUP BY user_id
</select>
</mapper>

View File

@ -3,7 +3,7 @@
<mapper namespace="cn.iocoder.yudao.module.statistics.dal.mysql.member.MemberStatisticsMapper">
<select id="selectSummaryListByAreaId"
resultType="cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO">
resultType="cn.iocoder.yudao.module.statistics.service.member.bo.MemberAreaStatisticsRespBO">
SELECT area_id, COUNT(1) AS userCount
FROM member_user
WHERE deleted = FALSE
@ -18,6 +18,14 @@
GROUP BY sex
</select>
<select id="selectSummaryListByRegisterTerminal"
resultType="cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberTerminalStatisticsRespVO">
SELECT register_terminal as terminal, COUNT(1) AS userCount
FROM member_user
WHERE deleted = FALSE
GROUP BY register_terminal
</select>
<select id="selectUserCount" resultType="java.lang.Integer">
SELECT COUNT(1)
FROM member_user
@ -30,4 +38,14 @@
</if>
</select>
<select id="selectListByCreateTimeBetween"
resultType="cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberRegisterCountRespVO">
SELECT DATE_FORMAT(create_time, '%Y-%m-%d') AS date,
count(1) AS count
FROM member_user
WHERE create_time BETWEEN #{beginTime} AND #{endTime}
AND deleted = FALSE
GROUP BY date
</select>
</mapper>

View File

@ -32,9 +32,8 @@
<select id="selectRechargeSummaryGroupByWalletId"
resultType="cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO">
<!-- TODO @疯狂:是不是不用 group by而是通过 DISTINCT wallet_id 更合适哈? -->
SELECT COUNT(1) AS rechargeUserCount,
SUM(pay_price) AS rechargePrice
SELECT COUNT(DISTINCT wallet_id) AS rechargeUserCount,
SUM(pay_price) AS rechargePrice
FROM pay_wallet_recharge
WHERE pay_status = #{payStatus}
<if test="beginTime != null">
@ -44,7 +43,13 @@
AND pay_time &lt;= #{endTime}
</if>
AND deleted = FALSE
GROUP BY wallet_id
</select>
<select id="selectRechargePriceSummary" resultType="java.lang.Integer">
SELECT IFNULL(SUM(pay_price), 0)
FROM pay_wallet_recharge
WHERE pay_status = #{payStatus}
AND deleted = FALSE
</select>
</mapper>

View File

@ -11,4 +11,11 @@
AND deleted = FALSE
</select>
<select id="selectCountByStatus" resultType="java.lang.Long">
SELECT COUNT(1)
FROM trade_after_sale
WHERE status = #{status}
AND deleted = FALSE
</select>
</mapper>

View File

@ -11,4 +11,11 @@
AND deleted = FALSE
</select>
<select id="selectWithdrawCountByStatus" resultType="java.lang.Long">
SELECT COUNT(1)
FROM trade_brokerage_withdraw
WHERE status = #{status}
AND deleted = FALSE
</select>
</mapper>

View File

@ -2,17 +2,18 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeOrderStatisticsMapper">
<!-- TODO @疯狂:是返回不是的 MemberAreaStatisticsRespBO 哈 -->
<select id="selectSummaryListByAreaId"
resultType="cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO">
SELECT receiver_area_id AS areaId,
(SELECT COUNT(1)
(SELECT COUNT(DISTINCT s.user_id)
FROM trade_order AS s
WHERE s.receiver_area_id = m.receiver_area_id) AS orderCreateCount,
(SELECT COUNT(1)
WHERE s.receiver_area_id = m.receiver_area_id) AS orderCreateUserCount,
(SELECT COUNT(DISTINCT s.user_id)
FROM trade_order AS s
WHERE s.receiver_area_id = m.receiver_area_id
AND s.pay_status = TRUE
AND s.deleted = FALSE) AS orderPayCount,
AND s.deleted = FALSE) AS orderPayUserCount,
(SELECT SUM(s.pay_price)
FROM trade_order AS s
WHERE s.receiver_area_id = m.receiver_area_id
@ -24,14 +25,14 @@
</select>
<select id="selectUserCountByCreateTimeBetween" resultType="java.lang.Integer">
SELECT COUNT(DISTINCT(user_id))
SELECT COUNT(DISTINCT (user_id))
FROM trade_order
WHERE deleted = FALSE
AND create_time BETWEEN #{beginTime} AND #{endTime}
</select>
<select id="selectUserCountByPayTimeBetween" resultType="java.lang.Integer">
SELECT COUNT(DISTINCT(user_id))
SELECT COUNT(DISTINCT (user_id))
FROM trade_order
WHERE pay_time BETWEEN #{beginTime} AND #{endTime}
AND pay_status = TRUE
@ -61,4 +62,53 @@
AND create_time BETWEEN #{beginTime} AND #{endTime}
</select>
<select id="selectListByPayTimeBetweenAndGroupByDay"
resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeOrderTrendRespVO">
SELECT DATE_FORMAT(pay_time, '%Y-%m-%d') AS date,
COUNT(1) AS orderPayCount,
SUM(pay_price) AS orderPayPrice
FROM trade_order
WHERE pay_status = TRUE
AND create_time BETWEEN #{beginTime} AND #{endTime}
AND deleted = FALSE
GROUP BY date
</select>
<select id="selectListByPayTimeBetweenAndGroupByMonth"
resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeOrderTrendRespVO">
SELECT DATE_FORMAT(pay_time, '%Y-%m') AS date,
COUNT(1) AS orderPayCount,
SUM(pay_price) AS orderPayPrice
FROM trade_order
WHERE pay_status = TRUE
AND create_time BETWEEN #{beginTime} AND #{endTime}
AND deleted = FALSE
GROUP BY date
</select>
<select id="selectCountByStatus" resultType="java.lang.Long">
SELECT COUNT(1)
FROM trade_order
WHERE status = #{status}
AND deleted = FALSE
</select>
<select id="selectCountByStatusAndPickUpStoreIdIsNotNull" resultType="java.lang.Long">
SELECT COUNT(1)
FROM trade_order
WHERE status = #{status}
AND pick_up_store_id IS NOT NULL
AND deleted = FALSE
</select>
<select id="selectPaySummaryByStatusAndPayTimeBetween"
resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeOrderSummaryRespVO">
SELECT IFNULL(SUM(pay_price), 0) AS orderPayPrice,
COUNT(1) AS orderPayCount
FROM trade_order
WHERE status = #{status}
AND pay_time BETWEEN #{beginTime} AND #{endTime}
AND deleted = FALSE
</select>
</mapper>

View File

@ -11,16 +11,16 @@
AND deleted = FALSE
</select>
<select id="selectByTimeBetween"
<select id="selectVoByTimeBetween"
resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO">
SELECT
-- 营业额 = 商品支付金额 + 充值金额
SUM(order_pay_price + recharge_pay_price) AS turnover,
SUM(order_pay_price + recharge_pay_price) AS turnoverPrice,
SUM(order_pay_price) AS orderPayPrice,
SUM(recharge_pay_price) AS rechargePrice,
-- 支出金额 = 余额支付金额 + 支付佣金金额 + 商品退款金额
SUM(order_wallet_pay_price + brokerage_settlement_price + after_sale_refund_price) AS expensePrice,
SUM(order_wallet_pay_price) AS balancePrice,
SUM(order_wallet_pay_price) AS orderWalletPayPrice,
SUM(brokerage_settlement_price) AS brokerageSettlementPrice,
SUM(after_sale_refund_price) AS orderRefundPrice
FROM trade_statistics
@ -28,25 +28,6 @@
AND deleted = FALSE
</select>
<select id="selectListByTimeBetween"
resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO">
SELECT DATE_FORMAT(time, '%Y-%m-%d') AS date,
-- 营业额 = 商品支付金额 + 充值金额
SUM(order_pay_price + recharge_pay_price) AS turnover,
SUM(order_pay_price) AS orderPayPrice,
SUM(recharge_pay_price) AS rechargePrice,
-- 支出金额 = 余额支付金额 + 支付佣金金额 + 商品退款金额
SUM(order_wallet_pay_price + brokerage_settlement_price + after_sale_refund_price) AS expensePrice,
SUM(order_wallet_pay_price) AS balancePrice,
SUM(brokerage_settlement_price) AS brokerageSettlementPrice,
SUM(after_sale_refund_price) AS orderRefundPrice
FROM trade_statistics
WHERE time BETWEEN #{beginTime} AND #{endTime}
AND deleted = FALSE
<!-- TODO @疯狂:已经不用 group by它就是每天统计一条 -->
GROUP BY date
</select>
<select id="selectExpensePriceByTimeBetween" resultType="java.lang.Integer">
SELECT -- 支出金额 = 余额支付金额 + 支付佣金金额 + 商品退款金额
SUM(order_wallet_pay_price + brokerage_settlement_price + after_sale_refund_price) AS expensePrice

View File

@ -101,7 +101,7 @@ public interface TradeOrderMapper extends BaseMapperX<TradeOrderDO> {
* @param status 订单状态
* @return 交易订单
*/
default TradeOrderDO selectByUserIdAndActivityIdAndStatus(Long userId, Long activityId, Integer status) {
default TradeOrderDO selectByUserIdAndCombinationActivityIdAndStatus(Long userId, Long activityId, Integer status) {
return selectOne(new LambdaQueryWrapperX<TradeOrderDO>()
.eq(TradeOrderDO::getUserId, userId)
.eq(TradeOrderDO::getStatus, status)

View File

@ -46,7 +46,7 @@ public interface TradeOrderQueryService {
* @param status 订单状态
* @return 交易订单
*/
TradeOrderDO getActivityOrderByUserIdAndActivityIdAndStatus(Long userId, Long activityId, Integer status);
TradeOrderDO getCombinationActivityOrderByUserIdAndCombinationActivityIdAndStatus(Long userId, Long activityId, Integer status);
/**
* 获得订单列表

View File

@ -71,8 +71,8 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
}
@Override
public TradeOrderDO getActivityOrderByUserIdAndActivityIdAndStatus(Long userId, Long activityId, Integer status) {
return tradeOrderMapper.selectByUserIdAndActivityIdAndStatus(userId, activityId, status);
public TradeOrderDO getCombinationActivityOrderByUserIdAndCombinationActivityIdAndStatus(Long userId, Long activityId, Integer status) {
return tradeOrderMapper.selectByUserIdAndCombinationActivityIdAndStatus(userId, activityId, status);
}
@Override

View File

@ -8,10 +8,10 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.core.KeyValue;
import cn.iocoder.yudao.framework.common.enums.TerminalEnum;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
import cn.iocoder.yudao.module.member.api.address.AddressApi;
import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO;
import cn.iocoder.yudao.module.pay.api.order.PayOrderApi;
@ -187,7 +187,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
order.setStatus(TradeOrderStatusEnum.UNPAID.getStatus());
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus());
order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum));
order.setTerminal(TerminalEnum.H5.getTerminal()); // todo 数据来源?
// TODO @疯狂无状态terminal 不从 servletuTILS 而是通过 controller 传递给 service
order.setTerminal(ServletUtils.getTerminal());
// 支付 + 退款信息
order.setAdjustPrice(0).setPayStatus(false);
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()).setRefundPrice(0);

View File

@ -49,7 +49,7 @@ public class TradeCombinationOrderHandler implements TradeOrderHandler {
order.getCombinationHeadId(), item.getSkuId(), item.getCount());
// 2. 校验该用户是否存在未支付的拼团活动订单避免一个拼团可以下多个单子了
TradeOrderDO activityOrder = orderQueryService.getActivityOrderByUserIdAndActivityIdAndStatus(
TradeOrderDO activityOrder = orderQueryService.getCombinationActivityOrderByUserIdAndCombinationActivityIdAndStatus(
order.getUserId(), order.getCombinationActivityId(), TradeOrderStatusEnum.UNPAID.getStatus());
if (activityOrder != null) {
throw exception(ORDER_CREATE_FAIL_EXIST_UNPAID);
@ -70,8 +70,8 @@ public class TradeCombinationOrderHandler implements TradeOrderHandler {
TradeOrderConvert.INSTANCE.convert(order, item));
// 3. 更新拼团相关信息到订单
// TODO 芋艿只需要更新 record 如果创建订单时自己是团长的情况下 combinationHeadId 是为 null
// 设置团长编号这个操作时在订单是否后创建拼团记录时才设置的所以支付完创建拼团记录后需要设置一下记录编号和团长编号
// 为什么几个字段都要更新原因是
// 如果创建订单时自己是团长的情况下 combinationHeadId 是为 null 设置团长编号这个操作时在订单是否后创建拼团记录时才设置的
orderUpdateService.updateOrderCombinationInfo(order.getId(), order.getCombinationActivityId(),
combinationRecord.getCombinationRecordId(), combinationRecord.getCombinationHeadId());
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.member.dal.dataobject.user;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.enums.TerminalEnum;
import cn.iocoder.yudao.framework.ip.core.Area;
import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler;
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
@ -60,6 +61,11 @@ public class MemberUserDO extends TenantBaseDO {
* 注册 IP
*/
private String registerIp;
/**
* 注册终端
* 枚举 {@link TerminalEnum}
*/
private Integer registerTerminal;
/**
* 最后登录IP
*/
@ -111,7 +117,7 @@ public class MemberUserDO extends TenantBaseDO {
* 积分
*/
private Integer point;
// TODO 芋艿增加一个 totalPoint个人信息接口要返回
// TODO 疯狂增加一个 totalPoint个人信息接口要返回
/**
* 会员标签列表以逗号分隔

View File

@ -7,6 +7,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
import cn.iocoder.yudao.module.infra.api.file.FileApi;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateReqVO;
@ -99,6 +100,8 @@ public class MemberUserServiceImpl implements MemberUserService {
user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启
user.setPassword(encodePassword(password)); // 加密密码
user.setRegisterIp(registerIp);
// TODO @疯狂无状态terminal 不从 servletuTILS 而是通过 controller 传递给 service
user.setRegisterTerminal(ServletUtils.getTerminal());
memberUserMapper.insert(user);
// 发送 MQ 消息用户创建