Browse Source

公司端新增优惠券队列

xdd 2 months ago
parent
commit
a910f53293

+ 1 - 17
fs-admin/src/main/java/com/fs/store/controller/FsCouponScheduleController.java

@@ -49,25 +49,9 @@ public class FsCouponScheduleController extends BaseController
     public TableDataInfo list(FsCouponSchedule fsCouponSchedule)
     {
 
-        if(StringUtils.isNotBlank(fsCouponSchedule.getOrderCode())){
-            FsStoreOrder fsStoreOrder = fsStoreOrderCacheService.selectFsStoreOrderByOrderCode(fsCouponSchedule.getOrderCode());
-            if(ObjectUtil.isNotNull(fsStoreOrder)){
-                fsCouponSchedule.setOrderId(fsStoreOrder.getId());
-            } else {
-                fsCouponSchedule.setOrderId(-1L);
-            }
-        }
-
         startPage();
         List<FsCouponSchedule> list = fsCouponScheduleService.selectFsCouponScheduleList(fsCouponSchedule);
-        for (FsCouponSchedule couponSchedule : list) {
-            if(ObjectUtil.isNotNull(couponSchedule.getOrderId())){
-                FsStoreOrder fsStoreOrder = fsStoreOrderCacheService.selectFsStoreOrderById(couponSchedule.getOrderId());
-                if(ObjectUtil.isNotNull(fsStoreOrder)){
-                    couponSchedule.setOrderCode(fsStoreOrder.getOrderCode());
-                }
-            }
-        }
+
         return getDataTable(list);
     }
 

+ 104 - 0
fs-company/src/main/java/com/fs/company/controller/FsCouponScheduleController.java

@@ -0,0 +1,104 @@
+package com.fs.company.controller;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.fs.common.annotation.Log;
+import com.fs.common.core.controller.BaseController;
+import com.fs.common.core.domain.AjaxResult;
+import com.fs.common.core.page.TableDataInfo;
+import com.fs.common.enums.BusinessType;
+import com.fs.common.utils.poi.ExcelUtil;
+import com.fs.store.cache.IFsStoreOrderCacheService;
+import com.fs.store.domain.FsCouponSchedule;
+import com.fs.store.domain.FsStoreOrder;
+import com.fs.store.service.IFsCouponScheduleService;
+import com.hc.openapi.tool.util.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * 定时发放优惠券队列Controller
+ *
+ * @author fs
+ * @date 2025-03-08
+ */
+@RestController
+@RequestMapping("/system/schedule")
+public class FsCouponScheduleController extends BaseController
+{
+    @Autowired
+    private IFsCouponScheduleService fsCouponScheduleService;
+
+    @Autowired
+    private IFsStoreOrderCacheService fsStoreOrderCacheService;
+
+    /**
+     * 查询定时发放优惠券队列列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:schedule:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(FsCouponSchedule fsCouponSchedule)
+    {
+        startPage();
+        List<FsCouponSchedule> list = fsCouponScheduleService.selectFsCouponScheduleList(fsCouponSchedule);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出定时发放优惠券队列列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:schedule:export')")
+    @Log(title = "定时发放优惠券队列", businessType = BusinessType.EXPORT)
+    @GetMapping("/export")
+    public AjaxResult export(FsCouponSchedule fsCouponSchedule)
+    {
+        List<FsCouponSchedule> list = fsCouponScheduleService.selectFsCouponScheduleList(fsCouponSchedule);
+        ExcelUtil<FsCouponSchedule> util = new ExcelUtil<FsCouponSchedule>(FsCouponSchedule.class);
+        return util.exportExcel(list, "schedule");
+    }
+
+    /**
+     * 获取定时发放优惠券队列详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('system:schedule:query')")
+    @GetMapping(value = "/{id}")
+    public AjaxResult getInfo(@PathVariable("id") Long id)
+    {
+        return AjaxResult.success(fsCouponScheduleService.selectFsCouponScheduleById(id));
+    }
+
+    /**
+     * 新增定时发放优惠券队列
+     */
+    @PreAuthorize("@ss.hasPermi('system:schedule:add')")
+    @Log(title = "定时发放优惠券队列", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody FsCouponSchedule fsCouponSchedule)
+    {
+        return toAjax(fsCouponScheduleService.insertFsCouponSchedule(fsCouponSchedule));
+    }
+
+    /**
+     * 修改定时发放优惠券队列
+     */
+    @PreAuthorize("@ss.hasPermi('system:schedule:edit')")
+    @Log(title = "定时发放优惠券队列", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody FsCouponSchedule fsCouponSchedule)
+    {
+        return toAjax(fsCouponScheduleService.updateFsCouponSchedule(fsCouponSchedule));
+    }
+
+    /**
+     * 删除定时发放优惠券队列
+     */
+    @PreAuthorize("@ss.hasPermi('system:schedule:remove')")
+    @Log(title = "定时发放优惠券队列", businessType = BusinessType.DELETE)
+	@DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable Long[] ids)
+    {
+        return toAjax(fsCouponScheduleService.deleteFsCouponScheduleByIds(ids));
+    }
+}

+ 16 - 0
fs-service-system/src/main/java/com/fs/store/cache/IFsUserCacheService.java

@@ -0,0 +1,16 @@
+package com.fs.store.cache;
+
+import com.fs.store.domain.FsUser;
+
+/**
+ * 用户查询缓存
+ */
+public interface IFsUserCacheService {
+    /**
+     * 查询用户
+     *
+     * @param userId 用户ID
+     * @return 用户
+     */
+    public FsUser selectFsUserById(Long userId);
+}

+ 28 - 0
fs-service-system/src/main/java/com/fs/store/cache/impl/IFsUserCacheServiceImpl.java

@@ -0,0 +1,28 @@
+package com.fs.store.cache.impl;
+
+import com.fs.store.cache.IFsUserCacheService;
+import com.fs.store.domain.FsUser;
+import com.fs.store.service.IFsUserService;
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.util.concurrent.TimeUnit;
+
+@RequiredArgsConstructor
+@Service
+@Slf4j
+public class IFsUserCacheServiceImpl implements IFsUserCacheService {
+    private final IFsUserService fsUserService;
+    private static final Cache<Long, FsUser> USER_CACHE = Caffeine.newBuilder()
+            .maximumSize(1000)
+            .expireAfterWrite(3, TimeUnit.MINUTES)
+            .build();
+
+    @Override
+    public FsUser selectFsUserById(Long userId) {
+        return USER_CACHE.get(userId,e->fsUserService.selectFsUserById(userId));
+    }
+}

+ 10 - 0
fs-service-system/src/main/java/com/fs/store/domain/FsCouponSchedule.java

@@ -136,4 +136,14 @@ public class FsCouponSchedule extends BaseEntity
     @Excel(name = "最大重试次数")
     private Integer maxRetries = 3;
 
+
+    /**
+     * 公司id
+     */
+    private Long companyId;
+
+    /**
+     * 公司用户id
+     */
+    private Long companyUserId;
 }

+ 33 - 1
fs-service-system/src/main/java/com/fs/store/service/impl/FsCouponScheduleServiceImpl.java

@@ -8,6 +8,9 @@ import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
 import com.fs.common.core.domain.R;
 import com.fs.common.utils.DateUtils;
+import com.fs.store.cache.IFsUserCacheService;
+import com.fs.store.cache.impl.IFsStoreOrderCacheServiceImpl;
+import com.fs.store.cache.impl.IFsUserCacheServiceImpl;
 import com.fs.store.domain.*;
 import com.fs.store.dto.TemplateMessageSendRequestDTO;
 import com.fs.store.enums.IcgProcessStatusEnum;
@@ -18,6 +21,7 @@ import com.fs.store.param.FsStoreCouponReceiveParam;
 import com.fs.store.service.IFsCouponScheduleService;
 import com.fs.store.service.IFsStoreCouponIssueService;
 import com.github.pagehelper.util.StringUtil;
+import com.hc.openapi.tool.util.StringUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
@@ -73,6 +77,8 @@ public class FsCouponScheduleServiceImpl implements IFsCouponScheduleService
      */
 //    private final String WX_MINI_APP_NOTIFY_TEMPLATE_ID = "5ZSzz2nPmJo9EuenZa78mQPScoOMc84LnEfEpV0-i04";
     private final String WX_MINI_APP_NOTIFY_TEMPLATE_ID = "K0RUbGggwYz7V4yjtJjFVXtthnx4hOJgHvr7RNOyRSE";
+    private final IFsStoreOrderCacheServiceImpl fsStoreOrderCacheService;
+    private final IFsUserCacheServiceImpl IFsUserCacheService;
 
     /**
      * 查询定时发放优惠券队列
@@ -110,7 +116,33 @@ public class FsCouponScheduleServiceImpl implements IFsCouponScheduleService
     @Override
     public List<FsCouponSchedule> selectFsCouponScheduleList(FsCouponSchedule fsCouponSchedule)
     {
-        return fsCouponScheduleMapper.selectFsCouponScheduleList(fsCouponSchedule);
+
+        if(StringUtils.isNotBlank(fsCouponSchedule.getOrderCode())){
+            FsStoreOrder fsStoreOrder = fsStoreOrderCacheService.selectFsStoreOrderByOrderCode(fsCouponSchedule.getOrderCode());
+            if(ObjectUtil.isNotNull(fsStoreOrder)){
+                fsCouponSchedule.setOrderId(fsStoreOrder.getId());
+            } else {
+                fsCouponSchedule.setOrderId(-1L);
+            }
+        }
+        List<FsCouponSchedule> list = fsCouponScheduleMapper.selectFsCouponScheduleList(fsCouponSchedule);
+
+        for (FsCouponSchedule couponSchedule : list) {
+            if(ObjectUtil.isNotNull(couponSchedule.getOrderId())){
+                FsStoreOrder fsStoreOrder = fsStoreOrderCacheService.selectFsStoreOrderById(couponSchedule.getOrderId());
+                if(ObjectUtil.isNotNull(fsStoreOrder)){
+                    couponSchedule.setOrderCode(fsStoreOrder.getOrderCode());
+                }
+            }
+
+            if(ObjectUtil.isNotNull(couponSchedule.getUserId())){
+                FsUser fsUser = IFsUserCacheService.selectFsUserById(couponSchedule.getUserId());
+                if(ObjectUtil.isNotNull(fsUser)){
+                    couponSchedule.setUserName(fsUser.getUsername());
+                }
+            }
+        }
+        return list;
     }
 
     /**

+ 3 - 0
fs-service-system/src/main/java/com/fs/store/service/impl/FsStoreOrderServiceImpl.java

@@ -1656,6 +1656,9 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
                     fsCouponSchedule.setSendTime(fsCouponSchedule.getOrderTime().plusMonths(1L).withDayOfMonth(10));
                     fsCouponSchedule.setRetryCount(0);
 
+                    fsCouponSchedule.setCompanyId(order.getCompanyId());
+                    fsCouponSchedule.setCompanyUserId(order.getCompanyUserId());
+
                     fsCouponScheduleService.insertFsCouponSchedule(fsCouponSchedule);
 
                     logger.info("插入优惠券定时发放任务成功,任务ID:{}",fsCouponSchedule.getId());

+ 2 - 0
fs-service-system/src/main/resources/mapper/store/FsCouponScheduleMapper.xml

@@ -49,6 +49,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="maxRetries != null "> and max_retries = #{maxRetries}</if>
             <if test="remark != null "> and remark = #{remark}</if>
             <if test="page != null "> and page = #{page}</if>
+            <if test="companyId != null "> and company_id = #{companyId}</if>
+            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
         </where>
     </select>