删除优惠卷
新版优惠卷
This commit is contained in:
@@ -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