docs(deployment): 更新部署文档并添加自动化部署脚本
- 更新了 DEPLOYMENT.md 文档,增加了更多部署细节和说明 - 添加了 Linux 和 Windows 平台的自动化部署脚本 - 更新了 README.md,增加了部署相关说明 - 调整了 .env 文件配置,以适应新的部署流程 - 移除了部分不必要的代码和配置
This commit is contained in:
56
backend-java/promotion-service/pom.xml
Normal file
56
backend-java/promotion-service/pom.xml
Normal file
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.jiebanke</groupId>
|
||||
<artifactId>backend-java</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>promotion-service</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring Boot Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Eureka Client -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MyBatis Plus -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MySQL -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 结伴客公共模块 -->
|
||||
<dependency>
|
||||
<groupId>com.jiebanke</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.jiebanke.promotion;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
@MapperScan({"com.jiebanke.promotion.mapper"})
|
||||
@ComponentScan(basePackages = "com.jiebanke")
|
||||
public class PromotionApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(PromotionApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
package com.jiebanke.promotion.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.jiebanke.common.vo.ApiResponse;
|
||||
import com.jiebanke.promotion.entity.PromotionActivity;
|
||||
import com.jiebanke.promotion.entity.RewardRecord;
|
||||
import com.jiebanke.promotion.service.PromotionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/promotion")
|
||||
public class PromotionController {
|
||||
|
||||
@Autowired
|
||||
private PromotionService promotionService;
|
||||
|
||||
/**
|
||||
* 获取推广活动列表
|
||||
*/
|
||||
@GetMapping("/activities")
|
||||
public ApiResponse<Map<String, Object>> getPromotionActivities(
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(required = false) String name,
|
||||
@RequestParam(required = false) String status) {
|
||||
|
||||
IPage<PromotionActivity> activities = promotionService.getPromotionActivities(page, pageSize, name, status);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("activities", activities.getRecords());
|
||||
result.put("pagination", Map.of(
|
||||
"current", activities.getCurrent(),
|
||||
"pageSize", activities.getSize(),
|
||||
"total", activities.getTotal(),
|
||||
"totalPages", activities.getPages()
|
||||
));
|
||||
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取推广活动详情
|
||||
*/
|
||||
@GetMapping("/activities/{id}")
|
||||
public ApiResponse<PromotionActivity> getPromotionActivity(@PathVariable Long id) {
|
||||
PromotionActivity activity = promotionService.getPromotionActivityById(id);
|
||||
return ApiResponse.success(activity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建推广活动
|
||||
*/
|
||||
@PostMapping("/activities")
|
||||
public ApiResponse<Map<String, Object>> createPromotionActivity(@RequestBody PromotionActivity activity) {
|
||||
Long activityId = promotionService.createPromotionActivity(activity);
|
||||
PromotionActivity createdActivity = promotionService.getPromotionActivityById(activityId);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("activity", createdActivity);
|
||||
result.put("message", "推广活动创建成功");
|
||||
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新推广活动
|
||||
*/
|
||||
@PutMapping("/activities/{id}")
|
||||
public ApiResponse<Map<String, Object>> updatePromotionActivity(
|
||||
@PathVariable Long id,
|
||||
@RequestBody PromotionActivity activity) {
|
||||
|
||||
PromotionActivity updatedActivity = promotionService.updatePromotionActivity(id, activity);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("activity", updatedActivity);
|
||||
result.put("message", "推广活动更新成功");
|
||||
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除推广活动
|
||||
*/
|
||||
@DeleteMapping("/activities/{id}")
|
||||
public ApiResponse<Map<String, Object>> deletePromotionActivity(@PathVariable Long id) {
|
||||
boolean deleted = promotionService.deletePromotionActivity(id);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("message", "推广活动删除成功");
|
||||
result.put("id", id);
|
||||
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停推广活动
|
||||
*/
|
||||
@PostMapping("/activities/{id}/pause")
|
||||
public ApiResponse<Map<String, Object>> pausePromotionActivity(@PathVariable Long id) {
|
||||
boolean paused = promotionService.pausePromotionActivity(id);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("message", "推广活动已暂停");
|
||||
result.put("id", id);
|
||||
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复推广活动
|
||||
*/
|
||||
@PostMapping("/activities/{id}/resume")
|
||||
public ApiResponse<Map<String, Object>> resumePromotionActivity(@PathVariable Long id) {
|
||||
boolean resumed = promotionService.resumePromotionActivity(id);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("message", "推广活动已恢复");
|
||||
result.put("id", id);
|
||||
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取奖励记录列表
|
||||
*/
|
||||
@GetMapping("/rewards")
|
||||
public ApiResponse<Map<String, Object>> getRewardRecords(
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(required = false) String user,
|
||||
@RequestParam(required = false) String rewardType,
|
||||
@RequestParam(required = false) String status) {
|
||||
|
||||
IPage<RewardRecord> rewards = promotionService.getRewardRecords(page, pageSize, user, rewardType, status);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("rewards", rewards.getRecords());
|
||||
result.put("pagination", Map.of(
|
||||
"current", rewards.getCurrent(),
|
||||
"pageSize", rewards.getSize(),
|
||||
"total", rewards.getTotal(),
|
||||
"totalPages", rewards.getPages()
|
||||
));
|
||||
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发放奖励
|
||||
*/
|
||||
@PostMapping("/rewards/{id}/issue")
|
||||
public ApiResponse<Map<String, Object>> issueReward(@PathVariable Long id) {
|
||||
boolean issued = promotionService.issueReward(id);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("message", "奖励已发放");
|
||||
result.put("id", id);
|
||||
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取推广统计数据
|
||||
*/
|
||||
@GetMapping("/statistics")
|
||||
public ApiResponse<Map<String, Object>> getPromotionStatistics() {
|
||||
Map<String, Object> statistics = promotionService.getPromotionStatistics();
|
||||
return ApiResponse.success(statistics);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.jiebanke.promotion.entity;
|
||||
|
||||
import com.jiebanke.common.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class PromotionActivity extends BaseEntity {
|
||||
private String name;
|
||||
private String description;
|
||||
private String rewardType;
|
||||
private BigDecimal rewardAmount;
|
||||
private String status;
|
||||
private LocalDateTime startTime;
|
||||
private LocalDateTime endTime;
|
||||
private Integer maxParticipants;
|
||||
private Integer currentParticipants;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.jiebanke.promotion.entity;
|
||||
|
||||
import com.jiebanke.common.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class RewardRecord extends BaseEntity {
|
||||
private Long userId;
|
||||
private String userName;
|
||||
private String userPhone;
|
||||
private Long activityId;
|
||||
private String activityName;
|
||||
private String rewardType;
|
||||
private BigDecimal rewardAmount;
|
||||
private String status;
|
||||
private LocalDateTime issuedAt;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.jiebanke.promotion.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.jiebanke.promotion.entity.PromotionActivity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PromotionActivityMapper extends BaseMapper<PromotionActivity> {
|
||||
|
||||
/**
|
||||
* 根据状态获取推广活动列表
|
||||
* @param status 状态
|
||||
* @return 推广活动列表
|
||||
*/
|
||||
@Select("SELECT * FROM promotion_activities WHERE status = #{status} ORDER BY created_at DESC")
|
||||
List<PromotionActivity> selectByStatus(@Param("status") String status);
|
||||
|
||||
/**
|
||||
* 根据名称模糊查询推广活动
|
||||
* @param name 名称
|
||||
* @return 推广活动列表
|
||||
*/
|
||||
@Select("SELECT * FROM promotion_activities WHERE name LIKE CONCAT('%', #{name}, '%') ORDER BY created_at DESC")
|
||||
List<PromotionActivity> selectByName(@Param("name") String name);
|
||||
|
||||
/**
|
||||
* 暂停推广活动
|
||||
* @param id 活动ID
|
||||
* @return 更新记录数
|
||||
*/
|
||||
@Update("UPDATE promotion_activities SET status = 'paused', updated_at = NOW() WHERE id = #{id}")
|
||||
int pauseActivity(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 恢复推广活动
|
||||
* @param id 活动ID
|
||||
* @return 更新记录数
|
||||
*/
|
||||
@Update("UPDATE promotion_activities SET status = 'active', updated_at = NOW() WHERE id = #{id}")
|
||||
int resumeActivity(@Param("id") Long id);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.jiebanke.promotion.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.jiebanke.promotion.entity.RewardRecord;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface RewardRecordMapper extends BaseMapper<RewardRecord> {
|
||||
|
||||
/**
|
||||
* 根据用户ID获取奖励记录列表
|
||||
* @param userId 用户ID
|
||||
* @return 奖励记录列表
|
||||
*/
|
||||
@Select("SELECT * FROM reward_records WHERE user_id = #{userId} ORDER BY created_at DESC")
|
||||
List<RewardRecord> selectByUserId(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 根据状态获取奖励记录列表
|
||||
* @param status 状态
|
||||
* @return 奖励记录列表
|
||||
*/
|
||||
@Select("SELECT * FROM reward_records WHERE status = #{status} ORDER BY created_at DESC")
|
||||
List<RewardRecord> selectByStatus(@Param("status") String status);
|
||||
|
||||
/**
|
||||
* 发放奖励
|
||||
* @param id 奖励记录ID
|
||||
* @return 更新记录数
|
||||
*/
|
||||
@Update("UPDATE reward_records SET status = 'issued', issued_at = NOW() WHERE id = #{id}")
|
||||
int issueReward(@Param("id") Long id);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.jiebanke.promotion.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jiebanke.promotion.entity.PromotionActivity;
|
||||
import com.jiebanke.promotion.entity.RewardRecord;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface PromotionService extends IService<PromotionActivity> {
|
||||
|
||||
/**
|
||||
* 获取推广活动列表
|
||||
* @param page 页码
|
||||
* @param pageSize 每页数量
|
||||
* @param name 活动名称
|
||||
* @param status 状态
|
||||
* @return 推广活动分页列表
|
||||
*/
|
||||
IPage<PromotionActivity> getPromotionActivities(Integer page, Integer pageSize, String name, String status);
|
||||
|
||||
/**
|
||||
* 获取推广活动详情
|
||||
* @param id 活动ID
|
||||
* @return 推广活动
|
||||
*/
|
||||
PromotionActivity getPromotionActivityById(Long id);
|
||||
|
||||
/**
|
||||
* 创建推广活动
|
||||
* @param activity 活动信息
|
||||
* @return 创建的活动ID
|
||||
*/
|
||||
Long createPromotionActivity(PromotionActivity activity);
|
||||
|
||||
/**
|
||||
* 更新推广活动
|
||||
* @param id 活动ID
|
||||
* @param activity 更新的活动信息
|
||||
* @return 更新后的活动
|
||||
*/
|
||||
PromotionActivity updatePromotionActivity(Long id, PromotionActivity activity);
|
||||
|
||||
/**
|
||||
* 删除推广活动
|
||||
* @param id 活动ID
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
boolean deletePromotionActivity(Long id);
|
||||
|
||||
/**
|
||||
* 暂停推广活动
|
||||
* @param id 活动ID
|
||||
* @return 是否暂停成功
|
||||
*/
|
||||
boolean pausePromotionActivity(Long id);
|
||||
|
||||
/**
|
||||
* 恢复推广活动
|
||||
* @param id 活动ID
|
||||
* @return 是否恢复成功
|
||||
*/
|
||||
boolean resumePromotionActivity(Long id);
|
||||
|
||||
/**
|
||||
* 获取奖励记录列表
|
||||
* @param page 页码
|
||||
* @param pageSize 每页数量
|
||||
* @param user 用户
|
||||
* @param rewardType 奖励类型
|
||||
* @param status 状态
|
||||
* @return 奖励记录分页列表
|
||||
*/
|
||||
IPage<RewardRecord> getRewardRecords(Integer page, Integer pageSize, String user, String rewardType, String status);
|
||||
|
||||
/**
|
||||
* 发放奖励
|
||||
* @param id 奖励记录ID
|
||||
* @return 是否发放成功
|
||||
*/
|
||||
boolean issueReward(Long id);
|
||||
|
||||
/**
|
||||
* 获取推广统计数据
|
||||
* @return 统计数据
|
||||
*/
|
||||
Map<String, Object> getPromotionStatistics();
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package com.jiebanke.promotion.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jiebanke.common.exception.BusinessException;
|
||||
import com.jiebanke.promotion.entity.PromotionActivity;
|
||||
import com.jiebanke.promotion.entity.RewardRecord;
|
||||
import com.jiebanke.promotion.mapper.PromotionActivityMapper;
|
||||
import com.jiebanke.promotion.mapper.RewardRecordMapper;
|
||||
import com.jiebanke.promotion.service.PromotionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class PromotionServiceImpl extends ServiceImpl<PromotionActivityMapper, PromotionActivity> implements PromotionService {
|
||||
|
||||
@Autowired
|
||||
private PromotionActivityMapper promotionActivityMapper;
|
||||
|
||||
@Autowired
|
||||
private RewardRecordMapper rewardRecordMapper;
|
||||
|
||||
@Override
|
||||
public IPage<PromotionActivity> getPromotionActivities(Integer page, Integer pageSize, String name, String status) {
|
||||
QueryWrapper<PromotionActivity> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
if (name != null && !name.isEmpty()) {
|
||||
queryWrapper.like("name", name);
|
||||
}
|
||||
|
||||
if (status != null && !status.isEmpty()) {
|
||||
queryWrapper.eq("status", status);
|
||||
}
|
||||
|
||||
queryWrapper.orderByDesc("created_at");
|
||||
|
||||
Page<PromotionActivity> pageObj = new Page<>(page != null ? page : 1, pageSize != null ? pageSize : 10);
|
||||
return this.page(pageObj, queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PromotionActivity getPromotionActivityById(Long id) {
|
||||
PromotionActivity activity = this.getById(id);
|
||||
if (activity == null) {
|
||||
throw new BusinessException("推广活动不存在");
|
||||
}
|
||||
return activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createPromotionActivity(PromotionActivity activity) {
|
||||
this.save(activity);
|
||||
return activity.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PromotionActivity updatePromotionActivity(Long id, PromotionActivity activity) {
|
||||
PromotionActivity existingActivity = this.getById(id);
|
||||
if (existingActivity == null) {
|
||||
throw new BusinessException("推广活动不存在");
|
||||
}
|
||||
|
||||
// 更新字段
|
||||
if (activity.getName() != null) {
|
||||
existingActivity.setName(activity.getName());
|
||||
}
|
||||
if (activity.getDescription() != null) {
|
||||
existingActivity.setDescription(activity.getDescription());
|
||||
}
|
||||
if (activity.getRewardType() != null) {
|
||||
existingActivity.setRewardType(activity.getRewardType());
|
||||
}
|
||||
if (activity.getRewardAmount() != null) {
|
||||
existingActivity.setRewardAmount(activity.getRewardAmount());
|
||||
}
|
||||
if (activity.getStatus() != null) {
|
||||
existingActivity.setStatus(activity.getStatus());
|
||||
}
|
||||
if (activity.getStartTime() != null) {
|
||||
existingActivity.setStartTime(activity.getStartTime());
|
||||
}
|
||||
if (activity.getEndTime() != null) {
|
||||
existingActivity.setEndTime(activity.getEndTime());
|
||||
}
|
||||
if (activity.getMaxParticipants() != null) {
|
||||
existingActivity.setMaxParticipants(activity.getMaxParticipants());
|
||||
}
|
||||
if (activity.getCurrentParticipants() != null) {
|
||||
existingActivity.setCurrentParticipants(activity.getCurrentParticipants());
|
||||
}
|
||||
|
||||
this.updateById(existingActivity);
|
||||
return existingActivity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletePromotionActivity(Long id) {
|
||||
return this.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pausePromotionActivity(Long id) {
|
||||
int result = promotionActivityMapper.pauseActivity(id);
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resumePromotionActivity(Long id) {
|
||||
int result = promotionActivityMapper.resumeActivity(id);
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<RewardRecord> getRewardRecords(Integer page, Integer pageSize, String user, String rewardType, String status) {
|
||||
QueryWrapper<RewardRecord> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
if (user != null && !user.isEmpty()) {
|
||||
queryWrapper.like("user_name", user).or().like("user_phone", user);
|
||||
}
|
||||
|
||||
if (rewardType != null && !rewardType.isEmpty()) {
|
||||
queryWrapper.eq("reward_type", rewardType);
|
||||
}
|
||||
|
||||
if (status != null && !status.isEmpty()) {
|
||||
queryWrapper.eq("status", status);
|
||||
}
|
||||
|
||||
queryWrapper.orderByDesc("created_at");
|
||||
|
||||
Page<RewardRecord> pageObj = new Page<>(page != null ? page : 1, pageSize != null ? pageSize : 10);
|
||||
return rewardRecordMapper.selectPage(pageObj, queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean issueReward(Long id) {
|
||||
int result = rewardRecordMapper.issueReward(id);
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getPromotionStatistics() {
|
||||
// 获取活动总数
|
||||
int totalActivities = Math.toIntExact(this.count());
|
||||
|
||||
// 获取进行中的活动数
|
||||
QueryWrapper<PromotionActivity> activeWrapper = new QueryWrapper<>();
|
||||
activeWrapper.eq("status", "active");
|
||||
int activeActivities = Math.toIntExact(this.count(activeWrapper));
|
||||
|
||||
// 获取奖励记录总数
|
||||
int totalRewards = Math.toIntExact(rewardRecordMapper.selectCount(null));
|
||||
|
||||
// 获取已发放的奖励数
|
||||
QueryWrapper<RewardRecord> issuedWrapper = new QueryWrapper<>();
|
||||
issuedWrapper.eq("status", "issued");
|
||||
int issuedRewards = Math.toIntExact(rewardRecordMapper.selectCount(issuedWrapper));
|
||||
|
||||
// 计算总奖励金额
|
||||
QueryWrapper<RewardRecord> amountWrapper = new QueryWrapper<>();
|
||||
amountWrapper.eq("status", "issued").select("SUM(reward_amount) as totalAmount");
|
||||
Map<String, Object> amountMap = rewardRecordMapper.selectMap(amountWrapper);
|
||||
BigDecimal totalAmount = amountMap != null && amountMap.get("totalAmount") != null ?
|
||||
new BigDecimal(amountMap.get("totalAmount").toString()) : BigDecimal.ZERO;
|
||||
|
||||
Map<String, Object> statistics = new HashMap<>();
|
||||
statistics.put("totalActivities", totalActivities);
|
||||
statistics.put("activeActivities", activeActivities);
|
||||
statistics.put("totalRewards", totalRewards);
|
||||
statistics.put("issuedRewards", issuedRewards);
|
||||
statistics.put("totalAmount", totalAmount);
|
||||
|
||||
return statistics;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
server:
|
||||
port: 8086
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: promotion-service
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/jiebanke?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: root
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6379
|
||||
database: 0
|
||||
rabbitmq:
|
||||
host: localhost
|
||||
port: 5672
|
||||
username: guest
|
||||
password: guest
|
||||
|
||||
eureka:
|
||||
client:
|
||||
service-url:
|
||||
defaultZone: http://localhost:8761/eureka/
|
||||
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
global-config:
|
||||
db-config:
|
||||
id-type: auto
|
||||
Reference in New Issue
Block a user