删除优惠卷
新版优惠卷
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
package com.peanut.modules.common.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.common.entity.CouponEntity;
|
||||
import com.peanut.modules.common.entity.CouponHistory;
|
||||
import com.peanut.modules.common.entity.MyUserEntity;
|
||||
import com.peanut.modules.common.service.CouponHistoryService;
|
||||
import com.peanut.modules.common.service.CouponService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController("commonCoupon")
|
||||
@RequestMapping("common/coupon")
|
||||
public class CouponController {
|
||||
|
||||
@Autowired
|
||||
private CouponService couponService;
|
||||
@Autowired
|
||||
private CouponHistoryService couponHistoryService;
|
||||
|
||||
//优惠卷列表
|
||||
@RequestMapping("/getCouponList")
|
||||
public R getCouponList(@RequestBody Map params){
|
||||
Integer limit = Integer.valueOf(params.get("limit").toString());
|
||||
Integer page = Integer.valueOf(params.get("page").toString());
|
||||
LambdaQueryWrapper<CouponEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
if (StringUtils.isNotEmpty(params.get("couponType").toString())){
|
||||
wrapper.eq(CouponEntity::getCouponType,params.get("couponType"));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(params.get("couponRange").toString())){
|
||||
wrapper.eq(CouponEntity::getCouponRange,params.get("couponRange"));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(params.get("couponName").toString())){
|
||||
wrapper.like(CouponEntity::getCouponName,params.get("couponName"));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(params.get("currentState").toString())){
|
||||
wrapper.eq(CouponEntity::getCurrentState,params.get("currentState"));
|
||||
}
|
||||
wrapper.orderByDesc(CouponEntity::getCreateTime);
|
||||
Page<CouponEntity> couponPage = couponService.page(new Page<>(page, limit), wrapper);
|
||||
for (CouponEntity couponEntity : couponPage.getRecords()) {
|
||||
couponService.setRangeList(couponEntity);
|
||||
}
|
||||
return R.ok().put("couponPage",couponPage);
|
||||
}
|
||||
|
||||
//用户优惠卷列表
|
||||
@RequestMapping("/getCouponHistoryList")
|
||||
public R getCouponHistoryList(@RequestBody Map params){
|
||||
Integer limit = Integer.valueOf(params.get("limit").toString());
|
||||
Integer page = Integer.valueOf(params.get("page").toString());
|
||||
MPJLambdaWrapper<CouponHistory> wrapper = new MPJLambdaWrapper<>();
|
||||
wrapper.leftJoin(CouponEntity.class,CouponEntity::getId,CouponHistory::getCouponId);
|
||||
wrapper.leftJoin(MyUserEntity.class,MyUserEntity::getId,CouponHistory::getUserId);
|
||||
wrapper.selectAll(CouponHistory.class);
|
||||
if (StringUtils.isNotEmpty(params.get("getType").toString())){
|
||||
wrapper.eq(CouponHistory::getGetType,params.get("getType"));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(params.get("status").toString())){
|
||||
wrapper.eq(CouponHistory::getStatus,params.get("status"));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(params.get("userInfo").toString())) {
|
||||
wrapper.and(t->t.like(MyUserEntity::getName,params.get("userInfo")).or().like(MyUserEntity::getNickname,params.get("userInfo"))
|
||||
.or().like(MyUserEntity::getTel,params.get("userInfo")).or().like(MyUserEntity::getEmail,params.get("userInfo")));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(params.get("userId").toString())){
|
||||
wrapper.eq(MyUserEntity::getId,params.get("userId"));
|
||||
}
|
||||
wrapper.orderByAsc(CouponHistory::getStatus);
|
||||
wrapper.orderByDesc(CouponHistory::getCreateTime);
|
||||
Page<CouponHistory> couponList = couponHistoryService.page(new Page<>(page, limit), wrapper);
|
||||
return R.ok().put("couponList",couponList);
|
||||
}
|
||||
|
||||
//优惠劵详情
|
||||
@RequestMapping("/getCouponInfo")
|
||||
public R getCouponInfo(@RequestBody Map<String,Object> params){
|
||||
CouponEntity couponEntity = couponService.getById(Integer.parseInt(params.get("id").toString()));
|
||||
couponService.setRangeList(couponEntity);
|
||||
return R.ok().put("couponEntity",couponEntity);
|
||||
}
|
||||
|
||||
//修改优惠劵
|
||||
@RequestMapping("/updateCoupon")
|
||||
public R updateCoupon(@RequestBody CouponEntity couponEntity){
|
||||
int count = couponHistoryService.count(new LambdaQueryWrapper<CouponHistory>()
|
||||
.eq(CouponHistory::getCouponId,couponEntity.getId()));
|
||||
if (count>0){
|
||||
return R.error("已有用户拥有优惠卷");
|
||||
}
|
||||
CouponEntity c = couponService.getById(couponEntity.getId());
|
||||
if (c.getCurrentState()==0){
|
||||
return R.error("优惠卷发放中,请先结束再修改");
|
||||
}
|
||||
couponService.updateById(couponEntity);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//删除优惠劵
|
||||
@RequestMapping("/delCoupon")
|
||||
public R delCoupon(@RequestBody Map<String,Object> params){
|
||||
int couponId = Integer.parseInt(params.get("id").toString());
|
||||
int count = couponHistoryService.count(new LambdaQueryWrapper<CouponHistory>()
|
||||
.eq(CouponHistory::getCouponId,couponId));
|
||||
if (count>0){
|
||||
return R.error("已有用户拥有优惠卷");
|
||||
}
|
||||
CouponEntity c = couponService.getById(couponId);
|
||||
if (c.getCurrentState()==0){
|
||||
return R.error("优惠卷发放中,请先结束再删除");
|
||||
}
|
||||
couponService.removeById(couponId);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//新建优惠劵
|
||||
@RequestMapping("/addCoupon")
|
||||
public R addCoupon(@RequestBody CouponEntity couponEntity){
|
||||
couponService.save(couponEntity);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//发放优惠劵
|
||||
@RequestMapping("/insertCouponHistory")
|
||||
public R insertCouponHistory(@RequestBody Map<String,Object> params){
|
||||
int couponId = (int)params.get("couponId");
|
||||
int userId = (int)params.get("userId");
|
||||
int getType = (int)params.get("getType");
|
||||
return couponService.insertCouponHistory(couponId,userId,getType);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +1,9 @@
|
||||
package com.peanut.modules.common.dao;
|
||||
|
||||
import com.peanut.modules.common.entity.CouponEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.peanut.modules.common.entity.CouponEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Mapper
|
||||
public interface CouponDao extends BaseMapper<CouponEntity> {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
package com.peanut.modules.common.dao;
|
||||
|
||||
import com.peanut.modules.common.entity.CouponHistoryEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.peanut.modules.common.entity.CouponHistory;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Mapper
|
||||
public interface CouponHistoryDao extends BaseMapper<CouponHistoryEntity> {
|
||||
|
||||
public interface CouponHistoryDao extends BaseMapper<CouponHistory> {
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.peanut.modules.common.dao;
|
||||
|
||||
import com.peanut.modules.common.entity.CouponProductCategoryRelationEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Mapper
|
||||
public interface CouponProductCategoryRelationDao extends BaseMapper<CouponProductCategoryRelationEntity> {
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.peanut.modules.common.dao;
|
||||
|
||||
import com.peanut.modules.common.entity.CouponProductRelationEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Mapper
|
||||
public interface CouponProductRelationDao extends BaseMapper<CouponProductRelationEntity> {
|
||||
|
||||
}
|
||||
@@ -4,105 +4,69 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Data
|
||||
@TableName("sms_coupon")
|
||||
public class CouponEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@TableName("coupon")
|
||||
public class CouponEntity {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
@TableId
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 优惠券类型 0:现金,1:折扣
|
||||
*/
|
||||
private Integer couponType;
|
||||
//优惠券类型 0现金 1折扣
|
||||
private Integer couponType;
|
||||
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String couponName;
|
||||
//优惠卷范围 0无限制 1课程卷 2课程品类卷
|
||||
private Integer couponRange;
|
||||
|
||||
/**
|
||||
* 优惠券面额
|
||||
*/
|
||||
private BigDecimal couponAmount;
|
||||
//范围详情(课程卷是课程id,分割;课程品类卷是课程分类根id)
|
||||
private String rangeInfo;
|
||||
|
||||
/**
|
||||
* 优惠券封面图
|
||||
*/
|
||||
private String couponUrl;
|
||||
//优惠券名称
|
||||
private String couponName;
|
||||
|
||||
/**
|
||||
* 每人限领
|
||||
*/
|
||||
private Integer limitedCollar;
|
||||
//优惠券面额
|
||||
private BigDecimal couponAmount;
|
||||
|
||||
/**
|
||||
* 时效
|
||||
*/
|
||||
private String validity;
|
||||
//优惠券封面
|
||||
private String couponUrl;
|
||||
|
||||
/**
|
||||
* 生效方式 0:领取日生效 1: 设置生效日期
|
||||
*/
|
||||
private Integer takeEffectType;
|
||||
//每人限领
|
||||
private Integer limitedCollar;
|
||||
|
||||
/**
|
||||
* 生效日期
|
||||
*/
|
||||
private Date takeEffectDate;
|
||||
//生效方式 0长期有效 1领取生效 2自定义
|
||||
private Integer effectType;
|
||||
|
||||
/**
|
||||
* 截止日期
|
||||
*/
|
||||
private Date expirationDate;
|
||||
//时效(天)
|
||||
private Integer validity;
|
||||
|
||||
/**
|
||||
* 总发行数量
|
||||
*/
|
||||
public Integer totalCirculation;
|
||||
//生效日期
|
||||
private Date effectTime;
|
||||
|
||||
/**
|
||||
* 当前状态 0:全部,1:生效,2:已过期
|
||||
*/
|
||||
private String currentState;
|
||||
//截止日期
|
||||
private Date expireTime;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
//总发行数量
|
||||
private Integer totalCirculation;
|
||||
|
||||
/**
|
||||
* 删除标志
|
||||
*/
|
||||
@TableLogic
|
||||
private Integer delFlag;
|
||||
//当前状态 0 发放中 1结束
|
||||
private Integer currentState;
|
||||
|
||||
/**
|
||||
* 商品类型 0: 商品 ,1电子书
|
||||
*/
|
||||
private Integer couponProType;
|
||||
//备注
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 使用门槛
|
||||
*/
|
||||
private Integer useLevel;
|
||||
//使用门槛
|
||||
private Integer useLevel;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
@TableLogic
|
||||
private Integer delFlag;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<Object> rangeList;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.peanut.modules.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@TableName("coupon_history")
|
||||
public class CouponHistory {
|
||||
|
||||
@TableId
|
||||
private Integer id;
|
||||
|
||||
//优惠券id
|
||||
private Integer couponId;
|
||||
|
||||
//用户id
|
||||
private Integer userId;
|
||||
|
||||
//订单id
|
||||
private Integer orderId;
|
||||
|
||||
//获取类型 0 后台赠送 1 主动获取
|
||||
private Integer getType;
|
||||
|
||||
//使用状态 0 未使用 1 已使用 2 已过期
|
||||
private Integer status;
|
||||
|
||||
//生效方式 0长期有效 1领取生效 2自定义
|
||||
private Integer effectType;
|
||||
|
||||
//生效时间
|
||||
private Date startTime;
|
||||
|
||||
//失效时间
|
||||
private Date endTime;
|
||||
|
||||
//使用时间
|
||||
private Date useTime;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
@TableLogic
|
||||
private Integer delFlag;
|
||||
|
||||
@TableField(exist = false)
|
||||
private CouponEntity couponEntity;
|
||||
@TableField(exist = false)
|
||||
private MyUserEntity userEntity;
|
||||
@TableField(exist = false)
|
||||
private BuyOrder buyOrder;
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package com.peanut.modules.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Data
|
||||
@TableName("sms_coupon_history")
|
||||
public class CouponHistoryEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 优惠券id
|
||||
*/
|
||||
private Long couponId;
|
||||
/**
|
||||
* 会员id
|
||||
*/
|
||||
private Long memberId;
|
||||
/**
|
||||
* 订单id
|
||||
*/
|
||||
private Long orderId;
|
||||
/**
|
||||
* 优惠券码
|
||||
*/
|
||||
private String couponCode;
|
||||
/**
|
||||
* 领取人昵称
|
||||
*/
|
||||
private String memberNickname;
|
||||
/**
|
||||
* 获取类型:0->后台赠送;1->主动获取
|
||||
*/
|
||||
private Integer getType;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)//创建注解
|
||||
private Date createTime;
|
||||
/**
|
||||
* 使用状态:0->未使用;1->已使用;2->已过期
|
||||
*/
|
||||
private Integer useStatus;
|
||||
/**
|
||||
* 使用时间
|
||||
*/
|
||||
private Date useTime;
|
||||
/**
|
||||
* 订单号码
|
||||
*/
|
||||
private String orderSn;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String couponName;
|
||||
|
||||
|
||||
/**
|
||||
* 商品类型 0: 商品 ,1电子书
|
||||
*/
|
||||
private Integer couponProType;
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.peanut.modules.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Data
|
||||
@TableName("sms_coupon_product_category_relation")
|
||||
public class CouponProductCategoryRelationEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 优惠券id
|
||||
*/
|
||||
private Long couponId;
|
||||
/**
|
||||
* 商品分类id
|
||||
*/
|
||||
private Long productCategoryId;
|
||||
/**
|
||||
* 商品分类名称
|
||||
*/
|
||||
private String productCategoryName;
|
||||
/**
|
||||
* 父分类名称
|
||||
*/
|
||||
private String parentCategoryName;
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.peanut.modules.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Data
|
||||
@TableName("sms_coupon_product_relation")
|
||||
public class CouponProductRelationEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 优惠券id
|
||||
*/
|
||||
private Long couponId;
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Long productId;
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
private String productName;
|
||||
/**
|
||||
* 商品条码
|
||||
*/
|
||||
private String productSn;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.peanut.modules.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.common.entity.CouponHistory;
|
||||
|
||||
public interface CouponHistoryService extends IService<CouponHistory> {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.peanut.modules.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.common.entity.CouponEntity;
|
||||
|
||||
public interface CouponService extends IService<CouponEntity> {
|
||||
|
||||
CouponEntity setRangeList(CouponEntity couponEntity);
|
||||
|
||||
R insertCouponHistory(int couponId, int userId,int getType);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.peanut.modules.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.modules.common.dao.CouponHistoryDao;
|
||||
import com.peanut.modules.common.entity.CouponHistory;
|
||||
import com.peanut.modules.common.service.CouponHistoryService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service("commonCouponHistoryService")
|
||||
public class CouponHistoryServiceImpl extends ServiceImpl<CouponHistoryDao, CouponHistory> implements CouponHistoryService {
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.peanut.modules.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.utils.DateUtil;
|
||||
import com.peanut.common.utils.DateUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.config.DelayQueueConfig;
|
||||
import com.peanut.modules.common.dao.CouponDao;
|
||||
import com.peanut.modules.common.dao.CouponHistoryDao;
|
||||
import com.peanut.modules.common.dao.CourseDao;
|
||||
import com.peanut.modules.common.dao.CourseMedicineDao;
|
||||
import com.peanut.modules.common.entity.CouponEntity;
|
||||
import com.peanut.modules.common.entity.CouponHistory;
|
||||
import com.peanut.modules.common.service.CouponService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.amqp.core.MessagePostProcessor;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service("commonCouponService")
|
||||
public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> implements CouponService {
|
||||
|
||||
@Autowired
|
||||
private CouponDao couponDao;
|
||||
@Autowired
|
||||
private CouponHistoryDao couponHistoryDao;
|
||||
@Autowired
|
||||
private CourseDao courseDao;
|
||||
@Autowired
|
||||
private CourseMedicineDao courseMedicineDao;
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Override
|
||||
public CouponEntity setRangeList(CouponEntity couponEntity) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
if (StringUtils.isNotEmpty(couponEntity.getRangeInfo())){
|
||||
String[] arr = couponEntity.getRangeInfo().split(",");
|
||||
for (String str : arr) {
|
||||
if (couponEntity.getCouponRange()==1){
|
||||
list.add(courseDao.selectById(Integer.parseInt(str)));
|
||||
}else {
|
||||
list.add(courseMedicineDao.selectById(Integer.parseInt(str)));
|
||||
}
|
||||
}
|
||||
}
|
||||
couponEntity.setRangeList(list);
|
||||
return couponEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R insertCouponHistory(int couponId, int userId,int getType) {
|
||||
CouponEntity couponEntity = couponDao.selectById(couponId);
|
||||
int historyCount = couponHistoryDao.selectCount(new LambdaQueryWrapper<CouponHistory>()
|
||||
.eq(CouponHistory::getCouponId,couponId));
|
||||
if (historyCount<couponEntity.getTotalCirculation()){
|
||||
List<CouponHistory> historyList = couponHistoryDao.selectList(new LambdaQueryWrapper<CouponHistory>()
|
||||
.eq(CouponHistory::getUserId,userId)
|
||||
.eq(CouponHistory::getCouponId,couponId));
|
||||
if (historyList.size()<couponEntity.getLimitedCollar()){
|
||||
CouponHistory couponHistory = new CouponHistory();
|
||||
couponHistory.setCouponId(couponId);
|
||||
couponHistory.setUserId(userId);
|
||||
couponHistory.setGetType(getType);
|
||||
couponHistory.setEffectType(couponEntity.getEffectType());
|
||||
if (couponEntity.getEffectType()==1){
|
||||
couponHistory.setStartTime(new Date());
|
||||
couponHistory.setEndTime(DateUtils.addDateDays(new Date(),couponEntity.getValidity()));
|
||||
}else if (couponEntity.getEffectType()==2){
|
||||
couponHistory.setStartTime(couponEntity.getEffectTime());
|
||||
couponHistory.setEndTime(couponEntity.getExpireTime());
|
||||
}
|
||||
couponHistoryDao.insert(couponHistory);
|
||||
//发放完优惠卷设置过期
|
||||
rabbitTemplate.convertAndSend(
|
||||
DelayQueueConfig.COMMON_EXCHANGE,
|
||||
DelayQueueConfig.COMMON_ROUTING_KEY,
|
||||
"couponExpire"+","+couponHistory.getId(),
|
||||
messagePostProcessor(couponHistory.getEndTime().getTime()-new Date().getTime())
|
||||
);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error("每人限领"+couponEntity.getLimitedCollar()+"张");
|
||||
}
|
||||
}else {
|
||||
return R.error("优惠卷已放完");
|
||||
}
|
||||
}
|
||||
|
||||
private MessagePostProcessor messagePostProcessor(long date) {
|
||||
return message -> {
|
||||
message.getMessageProperties().setDelay((int)date);
|
||||
return message;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,9 +28,9 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
String endYear,String endMonth,String endDay) {
|
||||
String url = "";
|
||||
if ("A".equals(type)){
|
||||
url = generateACertificate(certificateNo, iconUrl, realName, des, endYear, endMonth, endDay);
|
||||
url = generateACertificate(certificateNo, iconUrl, realName, des, endYear+"年"+endMonth+"月"+endDay+"日");
|
||||
}else if ("B".equals(type)) {
|
||||
url = generateBCertificate(certificateNo, iconUrl, realName, des, endYear, endMonth, endDay);
|
||||
url = generateBCertificate(certificateNo, iconUrl, realName, des, endYear+"年"+endMonth+"月"+endDay+"日");
|
||||
}else if ("ZK".equals(type)){
|
||||
url = generateZKCertificate(certificateNo, iconUrl, realName, des, endYear, endMonth, endDay);
|
||||
}
|
||||
@@ -115,7 +115,7 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
}
|
||||
}
|
||||
|
||||
public String generateBCertificate(String no,String iconUrl,String name,String[] des,String endy,String endm,String endd) {
|
||||
public String generateBCertificate(String no,String iconUrl,String name,String[] des,String endYMD) {
|
||||
try {
|
||||
Image src = ImageIO.read(new URL("https://ehh-private-01.oss-cn-beijing.aliyuncs.com/certificate/B.png"));
|
||||
// 获取图片的高和宽
|
||||
@@ -137,14 +137,14 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
|
||||
if (StringUtils.isNotBlank(iconUrl)){
|
||||
Image images = ImageIO.read(new URL(iconUrl));
|
||||
g.drawImage(images,(wideth-images.getWidth(null))/2,400,245,280,null);
|
||||
g.drawImage(images,(wideth-images.getWidth(null))/2,400,245,275,null);
|
||||
}
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.setFont(new Font("宋体", Font.BOLD, 40));
|
||||
FontMetrics metricss = g.getFontMetrics();
|
||||
int namex = (wideth - metricss.stringWidth(name))/2;
|
||||
int namey = 730;
|
||||
int namey = 720;
|
||||
g.drawString(name, namex, namey);
|
||||
|
||||
String[] str = {"自","年","月","日至","年","月","日在太湖学堂","学习,修完","课程,共计","学时,确认合格。"};
|
||||
@@ -178,10 +178,8 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
}
|
||||
}
|
||||
|
||||
g.setFont(new Font("黑体", Font.BOLD, 28));
|
||||
g.drawString(endy,600,1158);
|
||||
g.drawString(endm,695,1158);
|
||||
g.drawString(endd,748,1158);
|
||||
g.setFont(new Font("黑体", Font.BOLD, 30));
|
||||
g.drawString(endYMD,630,1188);
|
||||
// 释放资源
|
||||
g.dispose();
|
||||
File tempFile = File.createTempFile("tempfile_"+UUID.randomUUID().toString(), ".jpg");
|
||||
@@ -194,7 +192,7 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
}
|
||||
}
|
||||
|
||||
public String generateACertificate(String no,String iconUrl,String name,String[] des,String endy,String endm,String endd) {
|
||||
public String generateACertificate(String no,String iconUrl,String name,String[] des,String endYMD) {
|
||||
try {
|
||||
Image src = ImageIO.read(new URL("https://ehh-private-01.oss-cn-beijing.aliyuncs.com/certificate/A.png"));
|
||||
// 获取图片的高和宽
|
||||
@@ -216,14 +214,14 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
|
||||
if (StringUtils.isNotBlank(iconUrl)){
|
||||
Image images = ImageIO.read(new URL(iconUrl));
|
||||
g.drawImage(images,(wideth-images.getWidth(null))/2,480,245,280,null);
|
||||
g.drawImage(images,(wideth-images.getWidth(null))/2,490,245,280,null);
|
||||
}
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.setFont(new Font("宋体", Font.BOLD, 50));
|
||||
FontMetrics metricss = g.getFontMetrics();
|
||||
int namex = (wideth - metricss.stringWidth(name))/2;
|
||||
int namey = 815;
|
||||
int namey = 840;
|
||||
g.drawString(name, namex, namey);
|
||||
|
||||
String[] str = {"自","年","月","日至","年","月","日在太湖学堂","学习,修完","课程,共计","学时,确认合格。"};
|
||||
@@ -241,7 +239,7 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
desTotalWidth = oneWordWidth;
|
||||
}
|
||||
g.setFont(new Font("宋体", Font.PLAIN, 32));
|
||||
g.drawString(str[j].charAt(k)+"",180+desTotalWidth-oneWordWidth,860+alreadyWriteLine*(dess.getHeight()+20));
|
||||
g.drawString(str[j].charAt(k)+"",180+desTotalWidth-oneWordWidth,890+alreadyWriteLine*(dess.getHeight()+20));
|
||||
}
|
||||
if (j<des.length){
|
||||
for (int k=0;k<des[j].length(); k++){
|
||||
@@ -252,15 +250,13 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
desTotalWidth = oneWordWidth;
|
||||
}
|
||||
g.setFont(new Font("黑体", Font.BOLD, 32));
|
||||
g.drawString(des[j].charAt(k)+"",180+desTotalWidth-oneWordWidth,860+alreadyWriteLine*(dess.getHeight()+20));
|
||||
g.drawString(des[j].charAt(k)+"",180+desTotalWidth-oneWordWidth,890+alreadyWriteLine*(dess.getHeight()+20));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.setFont(new Font("黑体", Font.BOLD, 28));
|
||||
g.drawString(endy,605,1185);
|
||||
g.drawString(endm,715,1185);
|
||||
g.drawString(endd,780,1185);
|
||||
g.setFont(new Font("黑体", Font.BOLD, 32));
|
||||
g.drawString(endYMD,605,1255);
|
||||
|
||||
// 释放资源
|
||||
g.dispose();
|
||||
@@ -290,19 +286,19 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
g.setFont(new Font("Arial", Font.BOLD, 48));
|
||||
FontMetrics metrics = g.getFontMetrics();
|
||||
int nox = (wideth - metrics.stringWidth(no))/2;
|
||||
int noy = 500;
|
||||
int noy = 460;
|
||||
g.drawString(no, nox, noy);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.setFont(new Font("Arial", Font.PLAIN, 58));
|
||||
g.setFont(new Font("Arial", Font.PLAIN, 60));
|
||||
FontMetrics metricss = g.getFontMetrics();
|
||||
//转换成拼音
|
||||
name = nameToPinyin(name);
|
||||
int namex = (wideth - metricss.stringWidth(name))/2;
|
||||
int namey = 660;
|
||||
int namey = 580;
|
||||
g.drawString(name, namex, namey);
|
||||
|
||||
g.setFont(new Font("Arial", Font.PLAIN, 30));
|
||||
g.setFont(new Font("Arial", Font.PLAIN, 32));
|
||||
FontMetrics dess = g.getFontMetrics();
|
||||
int alreadyWriteLine = 0; //已经写了多少行
|
||||
int nowWidth = 0; //目前一行的长度
|
||||
@@ -317,13 +313,13 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
int oneWordWidth = dess.charWidth(des.charAt(i)); //获取单个字符的长度
|
||||
if (nowWidth+oneWordWidth>700){//换行画
|
||||
alreadyWriteLine++;
|
||||
int writeY = 780 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距
|
||||
int writeY = 700 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距
|
||||
g.drawString(des.charAt(i) + "", 155, writeY);
|
||||
nowWidth = 0;
|
||||
space = false;
|
||||
nowWidth += oneWordWidth;
|
||||
}else {//一字一字画
|
||||
int writeY = 780 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距
|
||||
int writeY = 700 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距
|
||||
if (nowWidth==0&&space){//首行空一格
|
||||
g.drawString(des.charAt(i)+"", 155+oneWordWidth, writeY);
|
||||
nowWidth += oneWordWidth*2;
|
||||
|
||||
Reference in New Issue
Block a user