瀏覽代碼

开发 根据活动ID获取详情
分页查看运营活动列表
运营活动审核处理

LuTong 1 周之前
父節點
當前提交
b76b322f69

+ 1 - 1
alien-entity/src/main/java/shop/alien/entity/storePlatform/StoreOperationalActivity.java

@@ -67,7 +67,7 @@ public class StoreOperationalActivity {
     @TableField("coupon_quantity")
     private Integer couponQuantity;
 
-    @ApiModelProperty(value = "状态:0-禁用, 1-启用")
+    @ApiModelProperty(value = "状态:1-待审核, 2-未开始, 3-审核拒绝, 4-已售罄, 5-进行中, 6-已下架, 7-已结束")
     @TableField("status")
     private Integer status;
 

+ 99 - 0
alien-store/src/main/java/shop/alien/store/controller/OperationalActivityController.java

@@ -0,0 +1,99 @@
+package shop.alien.store.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import io.swagger.annotations.*;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+import shop.alien.entity.result.R;
+import shop.alien.entity.storePlatform.vo.StoreOperationalActivityVO;
+import shop.alien.store.service.OperationalActivityService;
+
+/**
+ * 运营活动管理控制器
+ *
+ * @author system
+ * @since 2025-11-26
+ */
+@Slf4j
+@Api(tags = {"商家端-运营活动管理"})
+@ApiSort(10)
+@CrossOrigin
+@RestController
+@RequestMapping("/operationalActivity")
+@RequiredArgsConstructor
+public class OperationalActivityController {
+
+    private final OperationalActivityService activityService;
+
+    @ApiOperation("根据活动ID获取详情")
+    @ApiOperationSupport(order = 4)
+    @ApiImplicitParam(name = "id", value = "活动ID", dataTypeClass = Integer.class, paramType = "path", required = true)
+    @GetMapping("/detail/{id}")
+    public R<StoreOperationalActivityVO> getActivityDetailById(@PathVariable("id") Integer id) {
+        log.info("OperationalActivityController.getActivityDetailById: id={}", id);
+        try {
+            StoreOperationalActivityVO result = activityService.getActivityDetailById(id);
+            return R.data(result);
+        } catch (IllegalArgumentException e) {
+            return R.fail(e.getMessage());
+        } catch (Exception e) {
+            log.error("OperationalActivityController.getActivityDetailById ERROR: {}", e.getMessage(), e);
+            return R.fail(e.getMessage());
+        }
+    }
+
+    @ApiOperation("分页查看运营活动列表")
+    @ApiOperationSupport(order = 5)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "storeId", value = "商户ID", dataTypeClass = Integer.class, paramType = "query"),
+            @ApiImplicitParam(name = "storeName", value = "商户名称(模糊)", dataTypeClass = String.class, paramType = "query"),
+            @ApiImplicitParam(name = "pageNum", value = "当前页", dataTypeClass = Integer.class, paramType = "query"),
+            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataTypeClass = Integer.class, paramType = "query")
+    })
+    @GetMapping("/detail")
+    public R<IPage<StoreOperationalActivityVO>> pageActivityDetail(
+            @RequestParam(value = "storeId", required = false) Integer storeId,
+            @RequestParam(value = "storeName", required = false) String storeName,
+            @RequestParam(value = "pageNum", required = false) Integer pageNum,
+            @RequestParam(value = "pageSize", required = false) Integer pageSize) {
+        log.info("OperationalActivityController.pageActivityDetail storeId={}, storeName={}, pageNum={}, pageSize={}", storeId, storeName, pageNum, pageSize);
+        try {
+            IPage<StoreOperationalActivityVO> result = activityService.pageActivityDetail(storeId, storeName, pageNum, pageSize);
+            return R.data(result);
+        } catch (IllegalArgumentException e) {
+            return R.fail(e.getMessage());
+        } catch (Exception e) {
+            log.error("OperationalActivityController.pageActivityDetail ERROR: {}", e.getMessage(), e);
+            return R.fail(e.getMessage());
+        }
+    }
+
+    @ApiOperation("运营活动审核处理")
+    @ApiOperationSupport(order = 6)
+    @PostMapping("/audit")
+    public R<String> auditActivity(
+            @RequestParam("id") Integer id,
+            @RequestParam("status") Integer status,
+            @RequestParam(value = "approvalComments", required = false) String approvalComments) {
+        log.info("OperationalActivityController.auditActivity: id={}, status={}, approvalComments={}", id, status, approvalComments);
+        if (id == null) {
+            return R.fail("活动ID不能为空");
+        }
+        if (status == null) {
+            return R.fail("审核状态不能为空");
+        }
+        try {
+            int result = activityService.auditActivity(id, status, approvalComments);
+            if (result > 0) {
+                return R.success("审核处理成功");
+            }
+            return R.fail("审核处理失败");
+        } catch (Exception e) {
+            log.error("OperationalActivityController.auditActivity ERROR: {}", e.getMessage(), e);
+            return R.fail(e.getMessage());
+        }
+    }
+
+}
+

+ 44 - 0
alien-store/src/main/java/shop/alien/store/service/OperationalActivityService.java

@@ -0,0 +1,44 @@
+package shop.alien.store.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import shop.alien.entity.storePlatform.vo.StoreOperationalActivityVO;
+
+/**
+ * 运营活动服务接口
+ *
+ * @author system
+ * @since 2025-11-26
+ */
+public interface OperationalActivityService {
+
+    /**
+     * 审核运营活动
+     *
+     * @param id               活动ID
+     * @param status           审核状态(1通过/0驳回等)
+     * @param approvalComments 驳回原因
+     * @return 更新结果
+     */
+    int auditActivity(Integer id, Integer status, String approvalComments);
+
+    /**
+     * 根据门店条件分页查询运营活动
+     *
+     * @param storeId   门店ID
+     * @param storeName 门店名称(模糊)
+     * @param pageNum   页码
+     * @param pageSize  每页数量
+     * @return 活动分页结果
+     */
+    IPage<StoreOperationalActivityVO> pageActivityDetail(Integer storeId, String storeName, Integer pageNum, Integer pageSize);
+
+    /**
+     * 根据活动ID获取活动详情
+     *
+     * @param id 活动ID
+     * @return 活动详情
+     */
+    StoreOperationalActivityVO getActivityDetailById(Integer id);
+
+}
+

+ 256 - 0
alien-store/src/main/java/shop/alien/store/service/impl/OperationalActivityServiceImpl.java

@@ -0,0 +1,256 @@
+package shop.alien.store.service.impl;
+
+import com.alibaba.excel.util.StringUtils;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+import shop.alien.entity.store.LifeDiscountCoupon;
+import shop.alien.entity.store.StoreImg;
+import shop.alien.entity.store.StoreInfo;
+import shop.alien.entity.storePlatform.StoreOperationalActivity;
+import shop.alien.entity.storePlatform.vo.StoreOperationalActivityVO;
+import shop.alien.mapper.LifeDiscountCouponMapper;
+import shop.alien.mapper.StoreImgMapper;
+import shop.alien.mapper.StoreInfoMapper;
+import shop.alien.mapper.storePlantform.StoreOperationalActivityMapper;
+import shop.alien.store.service.OperationalActivityService;
+
+import java.util.*;
+
+/**
+ * 运营活动服务实现类
+ * <p>
+ * 提供运营活动的增删改查功能,包括:
+ * 1. 活动的创建、更新、删除
+ * 2. 活动列表查询、分页查询
+ * 3. 活动状态管理
+ * </p>
+ *
+ * @author system
+ * @since 2025-11-26
+ */
+@Slf4j
+@Service
+@RequiredArgsConstructor
+public class OperationalActivityServiceImpl implements OperationalActivityService {
+
+    private final StoreOperationalActivityMapper activityMapper;
+
+    private final StoreImgMapper imgMapper;
+
+    private final LifeDiscountCouponMapper lifeDiscountCouponMapper;
+
+    private final StoreInfoMapper storeInfoMapper;
+
+    @Override
+    public int auditActivity(Integer id, Integer status, String approvalComments) {
+        log.info("OperationalActivityServiceImpl.auditActivity: id={}, status={}, approvalComments={}", id, status, approvalComments);
+
+        if (id == null) {
+            throw new IllegalArgumentException("活动ID不能为空");
+        }
+        if (status == null) {
+            throw new IllegalArgumentException("审核状态不能为空");
+        }
+
+        if (!Objects.equals(status, 1) && StringUtils.isBlank(approvalComments)) {
+            throw new IllegalArgumentException("驳回原因不能为空");
+        }
+
+        StoreOperationalActivity update = new StoreOperationalActivity();
+        update.setId(id);
+        if (Objects.equals(status, 1)) {
+            StoreOperationalActivity activity = activityMapper.selectById(id);
+            if (activity == null) {
+                throw new IllegalArgumentException("活动不存在");
+            }
+            update.setStatus(resolveApprovedStatus(activity));
+            update.setApprovalComments(null);
+        } else {
+            update.setStatus(3);
+            update.setApprovalComments(approvalComments);
+        }
+
+        return activityMapper.updateById(update);
+    }
+
+    @Override
+    public IPage<StoreOperationalActivityVO> pageActivityDetail(Integer storeId, String storeName, Integer pageNum, Integer pageSize) {
+        log.info("OperationalActivityServiceImpl.pageActivityDetail: storeId={}, storeName={}, pageNum={}, pageSize={}", storeId, storeName, pageNum, pageSize);
+
+        if (storeId == null && StringUtils.isBlank(storeName)) {
+            throw new IllegalArgumentException("请至少提供商户ID或商户名称");
+        }
+
+        int current = (pageNum == null || pageNum <= 0) ? 1 : pageNum;
+        int size = (pageSize == null || pageSize <= 0) ? 10 : pageSize;
+
+        // 收集门店ID
+        LinkedHashSet<Integer> storeIds = new LinkedHashSet<>();
+        if (storeId != null) {
+            storeIds.add(storeId);
+        }
+        if (StringUtils.isNotBlank(storeName)) {
+            LambdaQueryWrapper<StoreInfo> storeWrapper = new LambdaQueryWrapper<>();
+            storeWrapper.like(StoreInfo::getStoreName, storeName)
+                    .eq(StoreInfo::getDeleteFlag, 0)
+                    .select(StoreInfo::getId, StoreInfo::getStoreName);
+            List<StoreInfo> storeList = storeInfoMapper.selectList(storeWrapper);
+            for (StoreInfo info : storeList) {
+                if (info.getId() != null) {
+                    storeIds.add(info.getId());
+                }
+            }
+        }
+
+        if (storeIds.isEmpty()) {
+            return new Page<>(current, size, 0);
+        }
+
+        LambdaQueryWrapper<StoreOperationalActivity> wrapper = new LambdaQueryWrapper<>();
+        wrapper.in(StoreOperationalActivity::getStoreId, storeIds);
+        wrapper.eq(StoreOperationalActivity::getDeleteFlag, 0);
+        wrapper.orderByDesc(StoreOperationalActivity::getCreatedTime);
+
+        IPage<StoreOperationalActivity> entityPage = activityMapper.selectPage(new Page<>(current, size), wrapper);
+
+        List<StoreOperationalActivityVO> voRecords = new ArrayList<>(entityPage.getRecords().size());
+        Map<Integer, String> storeCache = new LinkedHashMap<>();
+
+        for (StoreOperationalActivity activity : entityPage.getRecords()) {
+            StoreOperationalActivityVO vo = new StoreOperationalActivityVO();
+            BeanUtils.copyProperties(activity, vo);
+            vo.setStatusName(resolveStatusName(activity.getStatus()));
+
+            if (activity.getCouponId() != null) {
+                LifeDiscountCoupon coupon = lifeDiscountCouponMapper.selectById(activity.getCouponId());
+                if (coupon != null) {
+                    vo.setCouponName(coupon.getName());
+                }
+            }
+
+            attachStoreInfo(vo, storeCache);
+            fillActivityImages(vo);
+            voRecords.add(vo);
+        }
+
+        Page<StoreOperationalActivityVO> voPage = new Page<>(entityPage.getCurrent(), entityPage.getSize(), entityPage.getTotal());
+        voPage.setRecords(voRecords);
+        return voPage;
+    }
+
+    @Override
+    public StoreOperationalActivityVO getActivityDetailById(Integer id) {
+        log.info("OperationalActivityServiceImpl.getActivityDetailById: id={}", id);
+
+        if (id == null) {
+            throw new IllegalArgumentException("活动ID不能为空");
+        }
+
+        StoreOperationalActivity activity = activityMapper.selectById(id);
+        if (activity == null) {
+            return null;
+        }
+
+        StoreOperationalActivityVO vo = new StoreOperationalActivityVO();
+        BeanUtils.copyProperties(activity, vo);
+        vo.setStatusName(resolveStatusName(activity.getStatus()));
+
+        if (activity.getCouponId() != null) {
+            LifeDiscountCoupon coupon = lifeDiscountCouponMapper.selectById(activity.getCouponId());
+            if (coupon != null) {
+                vo.setCouponName(coupon.getName());
+            }
+        }
+
+        attachStoreInfo(vo, new LinkedHashMap<>());
+        fillActivityImages(vo);
+        return vo;
+    }
+
+    private int resolveApprovedStatus(StoreOperationalActivity activity) {
+        Date now = new Date();
+        if (activity.getStartTime() == null || activity.getEndTime() == null) {
+            return 2;
+        }
+        if (now.before(activity.getStartTime())) {
+            return 2;
+        }
+        if (!now.after(activity.getEndTime())) {
+            return 5;
+        }
+        return 7;
+    }
+
+    private String resolveStatusName(Integer status) {
+        if (status == null) {
+            return null;
+        }
+        switch (status) {
+            case 1:
+                return "待审核";
+            case 2:
+                return "未开始";
+            case 3:
+                return "审核拒绝";
+            case 4:
+                return "已售罄";
+            case 5:
+                return "进行中";
+            case 6:
+                return "已下架";
+            case 7:
+                return "已结束";
+            default:
+                return null;
+        }
+    }
+
+    private void attachStoreInfo(StoreOperationalActivityVO vo, Map<Integer, String> cache) {
+        if (vo == null || vo.getStoreId() == null) {
+            return;
+        }
+        Integer sid = vo.getStoreId();
+        if (cache != null && cache.containsKey(sid)) {
+            vo.setStoreName(cache.get(sid));
+            return;
+        }
+        StoreInfo storeInfo = storeInfoMapper.selectById(sid);
+        if (storeInfo != null) {
+            vo.setStoreName(storeInfo.getStoreName());
+            if (cache != null) {
+                cache.put(sid, storeInfo.getStoreName());
+            }
+        }
+    }
+
+    private void fillActivityImages(StoreOperationalActivityVO vo) {
+        if (vo == null || vo.getStoreId() == null || vo.getId() == null) {
+            return;
+        }
+        StoreImg titleImg = imgMapper.selectOne(new LambdaQueryWrapper<StoreImg>()
+                .eq(StoreImg::getStoreId, vo.getStoreId())
+                .eq(StoreImg::getBusinessId, vo.getId())
+                .eq(StoreImg::getImgType, 26)
+                .eq(StoreImg::getDeleteFlag, 0));
+        if (titleImg != null) {
+            vo.setActivityTitleImg(titleImg);
+            vo.setActivityTitleImgUrl(titleImg.getImgUrl());
+        }
+
+        StoreImg detailImg = imgMapper.selectOne(new LambdaQueryWrapper<StoreImg>()
+                .eq(StoreImg::getStoreId, vo.getStoreId())
+                .eq(StoreImg::getBusinessId, vo.getId())
+                .eq(StoreImg::getImgType, 27)
+                .eq(StoreImg::getDeleteFlag, 0));
+        if (detailImg != null) {
+            vo.setActivityDetailImg(detailImg);
+            vo.setActivityDetailImgUrl(detailImg.getImgUrl());
+        }
+    }
+}
+