diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/GiftCouponController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/GiftCouponController.java new file mode 100644 index 0000000..9cf81f3 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/GiftCouponController.java @@ -0,0 +1,105 @@ +package com.ruoyi.web.controller.system; + +import java.io.IOException; +import java.util.List; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.ruoyi.jarvis.domain.GiftCoupon; +import com.ruoyi.jarvis.service.IGiftCouponService; +import org.springframework.web.bind.annotation.*; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.page.TableDataInfo; + +/** + * 礼金管理Controller + * + * @author ruoyi + */ +@RestController +@RequestMapping("/system/giftcoupon") +public class GiftCouponController extends BaseController { + + private final IGiftCouponService giftCouponService; + + public GiftCouponController(IGiftCouponService giftCouponService) { + this.giftCouponService = giftCouponService; + } + + /** + * 查询礼金列表 + */ + @GetMapping("/list") + public TableDataInfo list(GiftCoupon query, HttpServletRequest request) { + startPage(); + + // 处理时间筛选参数 + String beginTimeStr = request.getParameter("beginTime"); + String endTimeStr = request.getParameter("endTime"); + + if (beginTimeStr != null && !beginTimeStr.isEmpty()) { + query.getParams().put("beginTime", beginTimeStr); + } + if (endTimeStr != null && !endTimeStr.isEmpty()) { + query.getParams().put("endTime", endTimeStr); + } + + List list = giftCouponService.selectGiftCouponList(query); + return getDataTable(list); + } + + /** + * 导出礼金列表 + */ + @Log(title = "礼金管理", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, GiftCoupon giftCoupon) throws IOException { + String fileName = "礼金数据"; + + List list = giftCouponService.selectGiftCouponList(giftCoupon); + + // 设置响应头,指定文件名 + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + String encodedFileName = java.net.URLEncoder.encode(fileName + ".xlsx", "UTF-8"); + response.setHeader("Content-Disposition", "attachment; filename=" + encodedFileName); + // 添加download-filename响应头,以支持前端工具类 + response.setHeader("download-filename", encodedFileName); + + ExcelUtil util = new ExcelUtil(GiftCoupon.class); + util.exportExcel(response, list, fileName); + } + + /** + * 获取礼金详细信息 + */ + @GetMapping(value = "/{giftCouponKey}") + public AjaxResult getInfo(@PathVariable("giftCouponKey") String giftCouponKey) { + return success(giftCouponService.selectGiftCouponByKey(giftCouponKey)); + } + + /** + * 查询礼金统计信息 + */ + @GetMapping("/statistics") + public AjaxResult statistics(GiftCoupon giftCoupon, HttpServletRequest request) { + // 处理时间筛选参数 + String beginTimeStr = request.getParameter("beginTime"); + String endTimeStr = request.getParameter("endTime"); + + if (beginTimeStr != null && !beginTimeStr.isEmpty()) { + giftCoupon.getParams().put("beginTime", beginTimeStr); + } + if (endTimeStr != null && !endTimeStr.isEmpty()) { + giftCoupon.getParams().put("endTime", endTimeStr); + } + + GiftCoupon statistics = giftCouponService.selectGiftCouponStatistics(giftCoupon); + return success(statistics); + } +} + diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/domain/GiftCoupon.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/domain/GiftCoupon.java new file mode 100644 index 0000000..c53104f --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/domain/GiftCoupon.java @@ -0,0 +1,67 @@ +package com.ruoyi.jarvis.domain; + +import com.ruoyi.common.core.domain.BaseEntity; +import com.ruoyi.common.annotation.Excel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 礼金信息对象 gift_coupon + * + * @author ruoyi + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class GiftCoupon extends BaseEntity { + + /** 礼金Key(主键) */ + @Excel(name = "礼金Key") + private String giftCouponKey; + + /** 商品SKU ID */ + @Excel(name = "商品SKU") + private String skuId; + + /** 商品名称 */ + @Excel(name = "商品名称") + private String skuName; + + /** 礼金类型(g=自营,pop=POP) */ + @Excel(name = "类型", readConverterExp = "g=自营,pop=POP") + private String owner; + + /** 礼金金额(元) */ + @Excel(name = "礼金金额") + private Double amount; + + /** 礼金数量 */ + @Excel(name = "礼金数量") + private Integer quantity; + + /** 已使用数量 */ + @Excel(name = "已使用数量") + private Integer usedQuantity; + + /** 总分摊金额 */ + @Excel(name = "总分摊金额") + private Double totalOcsAmount; + + /** 使用次数(订单数量) */ + @Excel(name = "使用次数") + private Integer useCount; + + /** 创建时间(首次创建时间) */ + @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + private Date createTime; + + /** 过期时间 */ + @Excel(name = "过期时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + private Date expireTime; + + /** 是否过期(0否 1是) */ + @Excel(name = "是否过期", readConverterExp = "0=否,1=是") + private Integer isExpired; + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/mapper/GiftCouponMapper.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/mapper/GiftCouponMapper.java new file mode 100644 index 0000000..079cf41 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/mapper/GiftCouponMapper.java @@ -0,0 +1,26 @@ +package com.ruoyi.jarvis.mapper; + +import com.ruoyi.jarvis.domain.GiftCoupon; +import java.util.List; + +/** + * 礼金信息 Mapper 接口 + */ +public interface GiftCouponMapper { + + /** + * 查询礼金列表(从订单表中汇总) + */ + List selectGiftCouponList(GiftCoupon giftCoupon); + + /** + * 根据礼金Key查询详情 + */ + GiftCoupon selectGiftCouponByKey(String giftCouponKey); + + /** + * 查询礼金统计信息 + */ + GiftCoupon selectGiftCouponStatistics(GiftCoupon giftCoupon); + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/IGiftCouponService.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/IGiftCouponService.java new file mode 100644 index 0000000..a06362e --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/IGiftCouponService.java @@ -0,0 +1,26 @@ +package com.ruoyi.jarvis.service; + +import com.ruoyi.jarvis.domain.GiftCoupon; +import java.util.List; + +/** + * 礼金信息 Service 接口 + */ +public interface IGiftCouponService { + + /** + * 查询礼金列表 + */ + List selectGiftCouponList(GiftCoupon giftCoupon); + + /** + * 根据礼金Key查询详情 + */ + GiftCoupon selectGiftCouponByKey(String giftCouponKey); + + /** + * 查询礼金统计信息 + */ + GiftCoupon selectGiftCouponStatistics(GiftCoupon giftCoupon); + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/GiftCouponServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/GiftCouponServiceImpl.java new file mode 100644 index 0000000..ca2e822 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/GiftCouponServiceImpl.java @@ -0,0 +1,35 @@ +package com.ruoyi.jarvis.service.impl; + +import com.ruoyi.jarvis.domain.GiftCoupon; +import com.ruoyi.jarvis.mapper.GiftCouponMapper; +import com.ruoyi.jarvis.service.IGiftCouponService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 礼金信息 Service 实现类 + */ +@Service +public class GiftCouponServiceImpl implements IGiftCouponService { + + @Autowired + private GiftCouponMapper giftCouponMapper; + + @Override + public List selectGiftCouponList(GiftCoupon giftCoupon) { + return giftCouponMapper.selectGiftCouponList(giftCoupon); + } + + @Override + public GiftCoupon selectGiftCouponByKey(String giftCouponKey) { + return giftCouponMapper.selectGiftCouponByKey(giftCouponKey); + } + + @Override + public GiftCoupon selectGiftCouponStatistics(GiftCoupon giftCoupon) { + return giftCouponMapper.selectGiftCouponStatistics(giftCoupon); + } + +} diff --git a/ruoyi-system/src/main/resources/mapper/jarvis/GiftCouponMapper.xml b/ruoyi-system/src/main/resources/mapper/jarvis/GiftCouponMapper.xml new file mode 100644 index 0000000..619ebc2 --- /dev/null +++ b/ruoyi-system/src/main/resources/mapper/jarvis/GiftCouponMapper.xml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + SELECT + gift_coupon_key, + MAX(sku_id) as sku_id, + MAX(sku_name) as sku_name, + MAX(owner) as owner, + COUNT(DISTINCT order_id) as use_count, + SUM(gift_coupon_ocs_amount) as total_ocs_amount, + MIN(order_time) as create_time, + MAX(expire_time) as expire_time, + CASE + WHEN MAX(expire_time) IS NOT NULL AND MAX(expire_time) < NOW() THEN 1 + ELSE 0 + END as is_expired + FROM ( + SELECT + or_rows.gift_coupon_key, + or_rows.sku_id, + or_rows.sku_name, + CASE + WHEN or_rows.pop_id IS NULL OR or_rows.pop_id = '' THEN 'g' + ELSE 'pop' + END as owner, + or_rows.order_id, + or_rows.gift_coupon_ocs_amount, + or_rows.order_time, + NULL as expire_time + FROM order_rows or_rows + WHERE or_rows.gift_coupon_key IS NOT NULL AND or_rows.gift_coupon_key != '' + + AND or_rows.gift_coupon_key like concat('%', #{giftCouponKey}, '%') + + + AND or_rows.sku_id like concat('%', #{skuId}, '%') + + + AND or_rows.sku_name like concat('%', #{skuName}, '%') + + + AND CASE + WHEN or_rows.pop_id IS NULL OR or_rows.pop_id = '' THEN 'g' + ELSE 'pop' + END = #{owner} + + + AND or_rows.order_time >= #{params.beginTime} + + + AND or_rows.order_time <= #{params.endTime} + + ) gc + GROUP BY gift_coupon_key + + HAVING CASE + WHEN MAX(expire_time) IS NOT NULL AND MAX(expire_time) < NOW() THEN 1 + ELSE 0 + END = #{isExpired} + + + + + + + + + +