券兑换码相关接口
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
package com.czg.controller.admin;
|
||||
|
||||
import com.czg.annotation.SaAdminCheckPermission;
|
||||
import com.czg.annotation.SaCheckMainShop;
|
||||
import com.czg.constant.TableValueConstant;
|
||||
import com.czg.market.dto.MkCouponRedemptionConfigDTO;
|
||||
import com.czg.market.dto.MkEnableConfigDTO;
|
||||
import com.czg.market.entity.MkCouponRedemptionConfig;
|
||||
import com.czg.market.service.MkCouponRedemptionConfigService;
|
||||
import com.czg.market.service.MkEnableConfigService;
|
||||
import com.czg.market.vo.MkCouponRedemptionCodeVO;
|
||||
import com.czg.market.vo.MkCouponRedemptionConfigVO;
|
||||
import com.czg.market.vo.MkEnableConfigVO;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.validator.group.UpdateGroup;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.groups.Default;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* 券兑换码相关
|
||||
* @author Administrator
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/couponRedemption")
|
||||
public class CouponRedemptionController {
|
||||
@Resource
|
||||
private MkCouponRedemptionConfigService configService;
|
||||
@Resource
|
||||
private MkEnableConfigService enableConfigService;
|
||||
|
||||
/**
|
||||
* 开关。可用门店修改
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "couponRedemption:enable", name = "券兑换码状态修改")
|
||||
@PutMapping("/enable")
|
||||
public CzgResult<Boolean> upEnable(@Validated @RequestBody MkEnableConfigDTO dto) {
|
||||
return CzgResult.success(enableConfigService.upEnable(StpKit.USER.getMainShopId(),StpKit.USER.getLoginIdAsLong(), dto, TableValueConstant.EnableConfig.Type.COUPON_REDEMPTION));
|
||||
}
|
||||
|
||||
/**
|
||||
* 开关状态,可用门店详情
|
||||
*/
|
||||
@GetMapping("/enable/status")
|
||||
public CzgResult<MkEnableConfigVO> upEnable() {
|
||||
return CzgResult.success(enableConfigService.detail(StpKit.USER.getMainShopId(), StpKit.USER.getLoginIdAsLong(), TableValueConstant.EnableConfig.Type.RECHARGE_REDEMPTION));
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置信息详情
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "couponRedemption:detail", name = "券兑换码列表")
|
||||
@GetMapping
|
||||
public CzgResult<MkCouponRedemptionConfigVO> detail(@RequestParam Integer id) {
|
||||
return CzgResult.success(configService.getOneAs(new QueryWrapper().eq(MkCouponRedemptionConfig::getId, id)
|
||||
.eq(MkCouponRedemptionConfig::getMainShopId, StpKit.USER.getMainShopId()), MkCouponRedemptionConfigVO.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置信息获取 列表
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "couponRedemption:list", name = "券兑换码列表")
|
||||
@GetMapping("/list")
|
||||
public CzgResult<Page<MkCouponRedemptionConfigVO>> list(@RequestParam(required = false, defaultValue = "-1") Integer status) {
|
||||
return CzgResult.success(configService.pageInfo(StpKit.USER.getMainShopId(), status));
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置信息添加
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "couponRedemption:add", name = "券兑换码配置添加")
|
||||
@PostMapping
|
||||
@SaCheckMainShop
|
||||
public CzgResult<Boolean> add(@Validated @RequestBody MkCouponRedemptionConfigDTO dto) {
|
||||
return CzgResult.success(configService.add(StpKit.USER.getMainShopId(), dto));
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置信息修改
|
||||
*
|
||||
* @return 是否成功
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "couponRedemption:edit", name = "券兑换码修改")
|
||||
@SaCheckMainShop
|
||||
@PutMapping
|
||||
public CzgResult<Boolean> edit(@Validated({UpdateGroup.class, Default.class}) @RequestBody MkCouponRedemptionConfigDTO dto) {
|
||||
return CzgResult.success(configService.edit(StpKit.USER.getShopId(), dto));
|
||||
}
|
||||
|
||||
/**
|
||||
* 券兑换码码列表
|
||||
*
|
||||
* @return 是否成功
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "couponRedemption:codeList", name = "券兑换码码列表")
|
||||
@GetMapping("/code/list")
|
||||
public CzgResult<Page<MkCouponRedemptionCodeVO>> codeList(@RequestParam Long redemptionId, @RequestParam(required = false) String code, @RequestParam(required = false) Integer status) {
|
||||
return CzgResult.success(configService.codeList(StpKit.USER.getMainShopId(), redemptionId, code, status));
|
||||
}
|
||||
|
||||
/**
|
||||
* 券兑换码码导出
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "couponRedemption:codeExport", name = "券兑换码码列表导出")
|
||||
@GetMapping("/code/export")
|
||||
public void exportCodeList(@RequestParam Long redemptionId, @RequestParam(required = false) String code, @RequestParam(required = false) Integer status,
|
||||
HttpServletResponse response, HttpServletRequest request) {
|
||||
configService.exportCodeList(StpKit.USER.getMainShopId(), redemptionId, code, status, response, request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.czg.market.dto;
|
||||
|
||||
import com.czg.validator.group.UpdateGroup;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Data
|
||||
public class MkCouponRedemptionConfigDTO implements Serializable {
|
||||
|
||||
|
||||
@NotNull(message = "id不能为空", groups = UpdateGroup.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@NotBlank(message = "名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 券信息
|
||||
*/
|
||||
@Valid
|
||||
private List<CouponInfoDTO> couponInfoList;
|
||||
|
||||
/**
|
||||
* 库存
|
||||
*/
|
||||
private Integer stock;
|
||||
|
||||
/**
|
||||
* 总数
|
||||
*/
|
||||
@Min(value = 0, message = "总数不能小于0")
|
||||
@NotNull(message = "总数不能为空")
|
||||
@Max(value = 1000, message = "总数不能大于1000")
|
||||
private Integer total;
|
||||
|
||||
/**
|
||||
* 可用开始时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 可用结束时间
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.czg.market.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 兑换码明细 实体类。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-10-22
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("mk_coupon_redemption_code")
|
||||
@Accessors(chain = true)
|
||||
public class MkCouponRedemptionCode implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 兑换配置id
|
||||
*/
|
||||
private Long redemptionId;
|
||||
|
||||
/**
|
||||
* 主店id
|
||||
*/
|
||||
private Long mainShopId;
|
||||
|
||||
/**
|
||||
* 兑换时间
|
||||
*/
|
||||
private LocalDateTime redemptionTime;
|
||||
|
||||
/**
|
||||
* 0未兑换 1已兑换
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 店铺用户id
|
||||
*/
|
||||
private Long shopUserId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
private String code;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.czg.market.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 充值优惠券修改 实体类。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-10-22
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("mk_coupon_redemption_config")
|
||||
public class MkCouponRedemptionConfig implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
|
||||
/**
|
||||
* 券信息
|
||||
*/
|
||||
private String couponInfoList;
|
||||
/**
|
||||
* 库存
|
||||
*/
|
||||
private Integer stock;
|
||||
|
||||
/**
|
||||
* 总数
|
||||
*/
|
||||
private Integer total;
|
||||
|
||||
/**
|
||||
* 可用开始时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 可用结束时间
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
* 门店id
|
||||
*/
|
||||
private Long mainShopId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Integer isEnable;
|
||||
@Column(ignore = true)
|
||||
private int status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.market.service;
|
||||
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.market.entity.MkCouponRedemptionCode;
|
||||
|
||||
/**
|
||||
* 兑换码明细 服务层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-10-22
|
||||
*/
|
||||
public interface MkCouponRedemptionCodeService extends IService<MkCouponRedemptionCode> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.czg.market.service;
|
||||
|
||||
import com.czg.market.dto.MkCouponRedemptionConfigDTO;
|
||||
import com.czg.market.vo.MkCouponRedemptionCodeVO;
|
||||
import com.czg.market.vo.MkCouponRedemptionConfigVO;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.market.entity.MkCouponRedemptionConfig;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 充值优惠券修改 服务层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-10-22
|
||||
*/
|
||||
public interface MkCouponRedemptionConfigService extends IService<MkCouponRedemptionConfig> {
|
||||
MkCouponRedemptionConfigVO detail(Long mainShopId);
|
||||
|
||||
Boolean edit(Long shopId, MkCouponRedemptionConfigDTO dto);
|
||||
|
||||
boolean add(Long mainShopId, MkCouponRedemptionConfigDTO dto);
|
||||
|
||||
Page<MkCouponRedemptionConfigVO> pageInfo(Long mainShopId, Integer status);
|
||||
|
||||
Page<MkCouponRedemptionCodeVO> codeList(Long mainShopId, Long id, String code, Integer status);
|
||||
|
||||
void exportCodeList(Long mainShopId, Long redemptionId, String code, Integer status, HttpServletResponse response, HttpServletRequest request);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.czg.market.vo;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 兑换码明细 实体类。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-10-21
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class MkCouponRedemptionCodeVO implements Serializable {
|
||||
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 兑换配置id
|
||||
*/
|
||||
private Long redemptionId;
|
||||
|
||||
/**
|
||||
* 主店id
|
||||
*/
|
||||
private Long mainShopId;
|
||||
|
||||
/**
|
||||
* 兑换时间
|
||||
*/
|
||||
private LocalDateTime redemptionTime;
|
||||
|
||||
/**
|
||||
* 0未兑换 1已兑换
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 店铺用户id
|
||||
*/
|
||||
private Long shopUserId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 兑换码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
private String nickName;
|
||||
/**
|
||||
* 用户手机号
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.czg.market.vo;
|
||||
|
||||
import com.czg.market.entity.MkRechargeRedemptionConfig;
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Data
|
||||
public class MkCouponRedemptionConfigVO implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 赠送金额
|
||||
*/
|
||||
private List<CouponInfoVO> couponInfoList;
|
||||
/**
|
||||
* 优惠券数量
|
||||
*/
|
||||
private int couponNum;
|
||||
|
||||
/**
|
||||
* 库存
|
||||
*/
|
||||
private Integer stock;
|
||||
|
||||
/**
|
||||
* 总数
|
||||
*/
|
||||
private Integer total;
|
||||
|
||||
/**
|
||||
* 可用开始时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 可用结束时间
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
* 门店id
|
||||
*/
|
||||
private Long mainShopId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@Column(ignore = true)
|
||||
private Integer status;
|
||||
}
|
||||
@@ -26,10 +26,8 @@ public interface TableValueConstant {
|
||||
interface EnableConfig {
|
||||
@Getter
|
||||
enum Type {
|
||||
RECHARGE_REDEMPTION("RECHARGE_REDEMPTION", "充值兑换"),
|
||||
PAY("PAY", "购买会员增积分"),
|
||||
MEMBER_TASK("MEMBER_TASK", "会员周奖励"),
|
||||
COST("COST", "消费增积分");
|
||||
RECHARGE_REDEMPTION("recharge_redemption", "充值兑换"),
|
||||
COUPON_REDEMPTION("coupon_redemption", "券兑换");
|
||||
private final String code;
|
||||
private final String msg;
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.market.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.market.entity.MkCouponRedemptionCode;
|
||||
|
||||
/**
|
||||
* 兑换码明细 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-10-22
|
||||
*/
|
||||
public interface MkCouponRedemptionCodeMapper extends BaseMapper<MkCouponRedemptionCode> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.market.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.market.entity.MkCouponRedemptionConfig;
|
||||
|
||||
/**
|
||||
* 充值优惠券修改 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-10-22
|
||||
*/
|
||||
public interface MkCouponRedemptionConfigMapper extends BaseMapper<MkCouponRedemptionConfig> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.czg.service.market.service.impl;
|
||||
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.market.entity.MkCouponRedemptionCode;
|
||||
import com.czg.market.service.MkCouponRedemptionCodeService;
|
||||
import com.czg.service.market.mapper.MkCouponRedemptionCodeMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 兑换码明细 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-10-22
|
||||
*/
|
||||
@Service
|
||||
public class MkCouponRedemptionCodeServiceImpl extends ServiceImpl<MkCouponRedemptionCodeMapper, MkCouponRedemptionCode> implements MkCouponRedemptionCodeService{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
package com.czg.service.market.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.hutool.poi.excel.ExcelWriter;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.market.dto.MkCouponRedemptionConfigDTO;
|
||||
import com.czg.market.entity.MkCouponRedemptionCode;
|
||||
import com.czg.market.entity.MkCouponRedemptionConfig;
|
||||
import com.czg.market.service.MkCouponRedemptionCodeService;
|
||||
import com.czg.market.vo.CouponInfoVO;
|
||||
import com.czg.market.vo.MkCouponRedemptionConfigVO;
|
||||
import com.czg.market.vo.MkCouponRedemptionCodeVO;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.MyQueryWrapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.market.service.MkCouponRedemptionConfigService;
|
||||
import com.czg.service.market.mapper.MkCouponRedemptionConfigMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 充值优惠券修改 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-10-22
|
||||
*/
|
||||
@Service
|
||||
public class MkCouponRedemptionConfigServiceImpl extends ServiceImpl<MkCouponRedemptionConfigMapper, MkCouponRedemptionConfig> implements MkCouponRedemptionConfigService{
|
||||
@Resource
|
||||
private MkCouponRedemptionCodeService codeService;
|
||||
|
||||
|
||||
@Override
|
||||
public MkCouponRedemptionConfigVO detail(Long mainShopId) {
|
||||
MkCouponRedemptionConfig redemptionConfig = getOne(new QueryWrapper().eq(MkCouponRedemptionConfig::getMainShopId, mainShopId));
|
||||
if (redemptionConfig == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MkCouponRedemptionConfigVO infoList = BeanUtil.copyProperties(redemptionConfig, MkCouponRedemptionConfigVO.class, "couponInfoList");
|
||||
if (StrUtil.isNotBlank(redemptionConfig.getCouponInfoList())) {
|
||||
infoList.setCouponInfoList(JSONArray.parseArray(redemptionConfig.getCouponInfoList(), CouponInfoVO.class));
|
||||
}
|
||||
|
||||
return infoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<MkCouponRedemptionConfigVO> pageInfo(Long mainShopId, Integer status) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper().eq(MkCouponRedemptionConfig::getMainShopId, mainShopId)
|
||||
.orderBy(MkCouponRedemptionConfig::getId, false);
|
||||
switch (status) {
|
||||
case 0:
|
||||
queryWrapper.le(MkCouponRedemptionConfig::getStartTime, DateUtil.date()).ge(MkCouponRedemptionConfig::getEndTime, DateUtil.date());
|
||||
break;
|
||||
case 1:
|
||||
queryWrapper.gt(MkCouponRedemptionConfig::getStartTime, DateUtil.date()).lt(MkCouponRedemptionConfig::getEndTime, DateUtil.date());
|
||||
break;
|
||||
}
|
||||
Page<MkCouponRedemptionConfig> page = page(PageUtil.buildPage(), queryWrapper);
|
||||
ArrayList<MkCouponRedemptionConfigVO> configList = new ArrayList<>();
|
||||
page.getRecords().forEach(item -> {
|
||||
if (item.getStartTime() != null && item.getEndTime() != null) {
|
||||
item.setStatus(!item.getStartTime().isAfter(DateUtil.date().toLocalDateTime()) && item.getEndTime().isBefore(DateUtil.date().toLocalDateTime()) ? 0 : 1);
|
||||
}else {
|
||||
item.setStatus(0);
|
||||
}
|
||||
|
||||
MkCouponRedemptionConfigVO config = BeanUtil.copyProperties(item, MkCouponRedemptionConfigVO.class);
|
||||
if (StrUtil.isNotBlank(item.getCouponInfoList())) {
|
||||
config.setCouponInfoList(JSONArray.parseArray(item.getCouponInfoList(), CouponInfoVO.class));
|
||||
config.setCouponNum(config.getCouponInfoList().stream().map(CouponInfoVO::getNum).reduce(0, Integer::sum));
|
||||
}
|
||||
configList.add(config);
|
||||
});
|
||||
|
||||
Page<MkCouponRedemptionConfigVO> page2 = new Page<>();
|
||||
BeanUtil.copyProperties(page, page2, "records");
|
||||
page2.setRecords(configList);
|
||||
return page2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(Long mainShopId, MkCouponRedemptionConfigDTO dto) {
|
||||
long count = count(new QueryWrapper().eq(MkCouponRedemptionConfig::getName, dto.getName()).eq(MkCouponRedemptionConfig::getMainShopId, mainShopId));
|
||||
AssertUtil.isTrue(count > 0, "名称已存在");
|
||||
MkCouponRedemptionConfig config = BeanUtil.copyProperties(dto, MkCouponRedemptionConfig.class, "couponInfoList");
|
||||
config.setMainShopId(mainShopId);
|
||||
config.setStock(config.getTotal());
|
||||
if (dto.getCouponInfoList() != null && !dto.getCouponInfoList().isEmpty()) {
|
||||
config.setCouponInfoList(JSONArray.toJSONString(dto.getCouponInfoList()));
|
||||
}
|
||||
save(config);
|
||||
|
||||
ArrayList<MkCouponRedemptionCode> codeArrayList = new ArrayList<>();
|
||||
|
||||
MkRechargeRedemptionConfigServiceImpl.generateCodes(config.getId(), config.getTotal()).forEach(code -> {
|
||||
codeArrayList.add(new MkCouponRedemptionCode().setRedemptionId(config.getId())
|
||||
.setMainShopId(mainShopId).setCode(code));
|
||||
});
|
||||
|
||||
return codeService.saveBatch(codeArrayList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean edit(Long shopId, MkCouponRedemptionConfigDTO dto) {
|
||||
MkCouponRedemptionConfig config = getOne(new QueryWrapper().eq(MkCouponRedemptionConfig::getMainShopId, shopId).eq(MkCouponRedemptionConfig::getId, dto.getId()));
|
||||
AssertUtil.isNull(config, "活动不存在");
|
||||
if (dto.getStock() != null) {
|
||||
if (config.getStock() < dto.getStock()) {
|
||||
throw new CzgException("库存仅允许删减");
|
||||
}
|
||||
int subStock = config.getStock() - dto.getStock();
|
||||
List<MkCouponRedemptionCode> subCodeList = codeService.list(new QueryWrapper().eq(MkCouponRedemptionCode::getRedemptionId, config.getId()).eq(MkCouponRedemptionCode::getStatus, 0).limit(subStock));
|
||||
subCodeList.forEach(item -> item.setStatus(1));
|
||||
codeService.updateBatch(subCodeList);
|
||||
}
|
||||
|
||||
BeanUtil.copyProperties(dto, config, "total", "amount", "startTime", "endTime", "couponInfoList");
|
||||
|
||||
if (dto.getCouponInfoList() != null && !dto.getCouponInfoList().isEmpty()) {
|
||||
config.setCouponInfoList(JSONArray.toJSONString(dto.getCouponInfoList()));
|
||||
}
|
||||
return updateById(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<MkCouponRedemptionCodeVO> codeList(Long mainShopId, Long id, String code, Integer status) {
|
||||
QueryWrapper queryWrapper = new MyQueryWrapper()
|
||||
.selectAll(MkCouponRedemptionCode.class)
|
||||
.select(ShopUser::getNickName, ShopUser::getPhone)
|
||||
.eq(MkCouponRedemptionCode::getMainShopId, mainShopId)
|
||||
.eq(MkCouponRedemptionCode::getRedemptionId, id)
|
||||
.orderBy(MkCouponRedemptionCode::getId, false);
|
||||
queryWrapper.eq(MkCouponRedemptionCode::getStatus, status);
|
||||
if (StrUtil.isNotBlank(code)) {
|
||||
queryWrapper.like(MkCouponRedemptionCode::getCode, code);
|
||||
}
|
||||
queryWrapper.leftJoin(ShopUser.class).on(ShopUser::getId, MkCouponRedemptionCode::getShopUserId);
|
||||
return codeService.pageAs(PageUtil.buildPage(), queryWrapper, MkCouponRedemptionCodeVO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportCodeList(Long mainShopId, Long redemptionId, String code, Integer status, HttpServletResponse response, HttpServletRequest request) {
|
||||
QueryWrapper queryWrapper = new MyQueryWrapper()
|
||||
.selectAll(MkCouponRedemptionCode.class)
|
||||
.select(ShopUser::getNickName, ShopUser::getPhone)
|
||||
.eq(MkCouponRedemptionCode::getMainShopId, mainShopId)
|
||||
.eq(MkCouponRedemptionCode::getRedemptionId, redemptionId);
|
||||
queryWrapper.eq(MkCouponRedemptionCode::getStatus, status);
|
||||
if (StrUtil.isNotBlank(code)) {
|
||||
queryWrapper.like(MkCouponRedemptionCode::getCode, code);
|
||||
}
|
||||
queryWrapper.leftJoin(ShopUser.class).on(ShopUser::getId, MkCouponRedemptionCode::getShopUserId);
|
||||
List<MkCouponRedemptionCodeVO> MkCouponRedemptionCodeVOS = codeService.listAs(queryWrapper, MkCouponRedemptionCodeVO.class);
|
||||
|
||||
List<Map<String, Object>> list = MkCouponRedemptionCodeVOS.stream()
|
||||
.map(item -> {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("code", item.getCode());
|
||||
map.put("redemptionTime", item.getRedemptionTime());
|
||||
map.put("userInfo", item.getShopUserId() == null ? "" : item.getNickName() + " " + item.getPhone());
|
||||
return map;
|
||||
})
|
||||
.toList();
|
||||
// 1. 创建 ExcelWriter
|
||||
ExcelWriter writer = ExcelUtil.getWriter(true);
|
||||
|
||||
// 2. 自定义标题别名(可选)
|
||||
|
||||
// 3. 写入数据
|
||||
|
||||
// 4. 设置响应头,告诉浏览器下载文件
|
||||
try (writer) {
|
||||
writer.addHeaderAlias("code", "兑换码");
|
||||
writer.addHeaderAlias("redemptionTime", "兑换时间");
|
||||
writer.addHeaderAlias("userInfo", "用户信息");
|
||||
writer.write(list, true);
|
||||
response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
||||
String fileName;
|
||||
fileName = URLEncoder.encode("兑换码", StandardCharsets.UTF_8);
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
|
||||
// 5. 输出到浏览器
|
||||
writer.flush(response.getOutputStream(), true);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.market.mapper.MkCouponRedemptionCodeMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.market.mapper.MkCouponRedemptionConfigMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user