|
@@ -3,12 +3,16 @@ package com.abi.qms.platform.service.impl;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
+import com.abi.base.foundation.util.RedisClient;
|
|
|
+import com.abi.qms.platform.constant.RedisKeysConstant;
|
|
|
+import com.abi.qms.platform.dao.entity.BaseFactory;
|
|
|
import com.abi.qms.platform.dao.entity.QrPackage;
|
|
|
import com.abi.qms.platform.dao.entity.QrPackageBatch;
|
|
|
import com.abi.qms.platform.dao.entity.QrPackageDownloadRecord;
|
|
|
import com.abi.qms.platform.dao.enums.QrPackageApplyStatusEnum;
|
|
|
import com.abi.qms.platform.dao.enums.QrPackageGenerateStatusEnum;
|
|
|
import com.abi.qms.platform.dao.enums.QrRepertoryTypeEnum;
|
|
|
+import com.abi.qms.platform.dao.mapper.BaseFactoryMapper;
|
|
|
import com.abi.qms.platform.dao.mapper.QrPackageBatchMapper;
|
|
|
import com.abi.qms.platform.dao.mapper.QrPackageDownloadRecordMapper;
|
|
|
import com.abi.qms.platform.dao.mapper.QrPackageMapper;
|
|
@@ -18,24 +22,19 @@ import com.abi.qms.platform.dto.res.GetQrPackageDetailRes;
|
|
|
import com.abi.qms.platform.dto.res.ListQrPackageRes;
|
|
|
import com.abi.qms.platform.dto.res.ValidSAPOrderNoAndMaterialRes;
|
|
|
import com.abi.qms.platform.infrastructure.mq.GenerateCodeConsumer;
|
|
|
-import com.abi.qms.platform.infrastructure.util.AssertUtil;
|
|
|
-import com.abi.qms.platform.infrastructure.util.PageUtil;
|
|
|
-import com.abi.qms.platform.infrastructure.util.UserUtil;
|
|
|
import com.abi.qms.platform.infrastructure.util.*;
|
|
|
-import com.abi.qms.platform.service.QrDataService;
|
|
|
import com.abi.qms.platform.service.QrPackageService;
|
|
|
import com.abi.task.common.api.exception.BusinessException;
|
|
|
import com.abi.task.common.api.exception.ErrorCodeEnum;
|
|
|
-import com.abi.task.common.utils.ICollectionUtil;
|
|
|
import com.abi.task.common.utils.PojoConverterUtils;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.sun.xml.internal.bind.v2.TODO;
|
|
|
import freemarker.template.Template;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.redisson.misc.Hash;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.amqp.core.AmqpTemplate;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -45,12 +44,10 @@ import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
import java.net.URLEncoder;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.text.MessageFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 码包 Service业务层处理
|
|
@@ -66,10 +63,7 @@ public class QrPackageServiceImpl implements QrPackageService {
|
|
|
private QrPackageMapper qrPackageMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- private AmqpTemplate amqpTemplate;
|
|
|
-
|
|
|
-// @Autowired
|
|
|
-// private QrDataService qrDataService;
|
|
|
+ private BaseFactoryMapper baseFactoryMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private QrPackageDownloadRecordMapper qrPackageDownloadRecordMapper;
|
|
@@ -77,9 +71,18 @@ public class QrPackageServiceImpl implements QrPackageService {
|
|
|
@Autowired
|
|
|
private QrPackageBatchMapper qrPackageBatchMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AmqpTemplate amqpTemplate;
|
|
|
+
|
|
|
@Autowired
|
|
|
private SendmailUtil sendmailUtil;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SmsUtil smsUtil;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisClient redisClient;
|
|
|
+
|
|
|
/**
|
|
|
* 保存码包
|
|
|
*/
|
|
@@ -321,8 +324,15 @@ public class QrPackageServiceImpl implements QrPackageService {
|
|
|
|
|
|
@Override
|
|
|
public void downloadQrPackage(DownloadQrPackageReq req, HttpServletResponse response) {
|
|
|
+ //查询码包
|
|
|
QrPackage qrPackage = qrPackageMapper.selectById(req.getId());
|
|
|
AssertUtil.isNull(qrPackage, "码包不存在");
|
|
|
+ //查询包材厂
|
|
|
+ BaseFactory factory = baseFactoryMapper.selectById(qrPackage.getFactoryCoverId());
|
|
|
+ AssertUtil.isNull(factory, "包材厂不存在");
|
|
|
+ if(StringUtils.isBlank(factory.getKeymanMobile())){
|
|
|
+ throw new BusinessException("包材厂手机号不存在");
|
|
|
+ }
|
|
|
|
|
|
// 只有已生成状态下才可下载
|
|
|
Integer generateStatus = qrPackage.getGenerateStatus();
|
|
@@ -330,6 +340,13 @@ public class QrPackageServiceImpl implements QrPackageService {
|
|
|
throw new BusinessException("码包不可下载");
|
|
|
}
|
|
|
|
|
|
+ //特殊:校验验证码是否正确,正确才可以下载
|
|
|
+ boolean verifyCaptchaResult = verifyCaptcha(factory.getKeymanMobile(), req.getCaptcha(), qrPackage.getId());
|
|
|
+ if(!verifyCaptchaResult){
|
|
|
+ throw new BusinessException("验证码错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ //开始下载
|
|
|
BufferedInputStream in = null;
|
|
|
BufferedOutputStream out = null;
|
|
|
try {
|
|
@@ -433,4 +450,61 @@ public class QrPackageServiceImpl implements QrPackageService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 发送短信验证码
|
|
|
+ *
|
|
|
+ * @param req
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void sendMobileMsg(SendMobileMsgReq req) {
|
|
|
+ //查询码包
|
|
|
+ QrPackage qrPackage = qrPackageMapper.selectById(req.getId());
|
|
|
+ AssertUtil.isNull(qrPackage, "码包不存在");
|
|
|
+ //查询包材厂
|
|
|
+ BaseFactory factory = baseFactoryMapper.selectById(qrPackage.getFactoryCoverId());
|
|
|
+ AssertUtil.isNull(factory, "包材厂不存在");
|
|
|
+ if(StringUtils.isBlank(factory.getKeymanMobile())){
|
|
|
+ throw new BusinessException("包材厂手机号不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ //key:packId:mobile
|
|
|
+ Long packId = qrPackage.getId();
|
|
|
+ String mobile = factory.getKeymanMobile();
|
|
|
+ String key = MessageFormat.format("{0}{1}:{2}",RedisKeysConstant.DOWNLOAD_MOBILE_MSG, packId, mobile);
|
|
|
+
|
|
|
+ //获取随机验证码
|
|
|
+ String captcha = RandomCodeUtils.getCaptcha(6);
|
|
|
+
|
|
|
+ //发送短信
|
|
|
+ smsUtil.sendCode(mobile, captcha);
|
|
|
+
|
|
|
+ //将验证码存入redis
|
|
|
+ redisClient.getRedisTemplate().opsForValue().set(key, captcha, 30 * 60, TimeUnit.SECONDS);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验校验码
|
|
|
+ * @param mobile
|
|
|
+ * @param inputCaptcha
|
|
|
+ * @param packId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean verifyCaptcha(String mobile, String inputCaptcha, Long packId) {
|
|
|
+ String key = MessageFormat.format("{0}{1}:{2}",RedisKeysConstant.DOWNLOAD_MOBILE_MSG, packId, mobile);
|
|
|
+ log.info("验证下载key:{}", key);
|
|
|
+ String captcha = redisClient.get(key);
|
|
|
+ log.info(inputCaptcha + "--------------------" + captcha);
|
|
|
+
|
|
|
+ //不一致返回false
|
|
|
+ if (!inputCaptcha.equals(captcha)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除校验码
|
|
|
+ redisClient.delete(key);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|