|
@@ -1,12 +1,12 @@
|
|
|
package com.hz.employmentsite.services.impl;
|
|
|
|
|
|
import com.hz.employmentsite.AppConfig;
|
|
|
-import com.hz.employmentsite.mapper.WxMessagestatusMapper;
|
|
|
-import com.hz.employmentsite.mapper.WxMessagetempsettingFieldMapper;
|
|
|
-import com.hz.employmentsite.mapper.WxMessagetempsettingMapper;
|
|
|
+import com.hz.employmentsite.mapper.*;
|
|
|
import com.hz.employmentsite.model.*;
|
|
|
import com.hz.employmentsite.services.service.WechatService;
|
|
|
+import com.hz.employmentsite.util.DateUtils;
|
|
|
import com.hz.employmentsite.util.StringUtils;
|
|
|
+import com.hz.employmentsite.util.UrlUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import me.chanjar.weixin.mp.api.WxMpService;
|
|
@@ -38,9 +38,21 @@ public class WechatServiceImpl implements WechatService {
|
|
|
@Autowired
|
|
|
private WxMessagetempsettingFieldMapper wxMessagetempsettingFieldMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private WxQrcodeMapper wxQrcodeMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WxQrcodeScanRecordMapper wxQrcodeScanRecordMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private StringUtils stringUtils;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DateUtils dateUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UrlUtils urlUtils;
|
|
|
+
|
|
|
private final Logger logger;
|
|
|
|
|
|
public WechatServiceImpl() {
|
|
@@ -109,7 +121,7 @@ public class WechatServiceImpl implements WechatService {
|
|
|
throw new Exception("该消息已有成功推送记录,请勿重复推送!");
|
|
|
|
|
|
String sendUrl = "";
|
|
|
- if(!stringUtils.IsNullOrEmpty(url)){
|
|
|
+ if (!stringUtils.IsNullOrEmpty(url)) {
|
|
|
sendUrl = appConfig.wxMessageBaseUrl + url;
|
|
|
}
|
|
|
|
|
@@ -164,5 +176,67 @@ public class WechatServiceImpl implements WechatService {
|
|
|
return wxMessagetempsettingFieldMapper.selectByExample(exp);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String getQrcodeUrl(String url, String userId) {
|
|
|
+ Date nowDate = dateUtils.formatDateToYYYYMMDD(new Date());
|
|
|
+
|
|
|
+ WxQrcodeExample exp = new WxQrcodeExample();
|
|
|
+ WxQrcodeExample.Criteria cri = exp.or();
|
|
|
+ cri.andUserIdEqualTo(userId);
|
|
|
+ cri.andQrcodeDateEqualTo(nowDate);
|
|
|
+
|
|
|
+ WxQrcode dbData = wxQrcodeMapper.selectByExample(exp).stream().findFirst().orElse(null);
|
|
|
+ if (dbData == null) {
|
|
|
+
|
|
|
+ String qrCodeId = UUID.randomUUID().toString();
|
|
|
+
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
+ params.put("userId", userId);
|
|
|
+ params.put("qrCodeId", qrCodeId);
|
|
|
+ String fullUrl = appConfig.wxMessageBaseUrl + "?redirectUrl=" + urlUtils.getUrl(url, params);
|
|
|
+
|
|
|
+ dbData = new WxQrcode();
|
|
|
+ dbData.setQrcodeId(qrCodeId);
|
|
|
+ dbData.setUserId(userId);
|
|
|
+ dbData.setUrl(fullUrl);
|
|
|
+ dbData.setScanMax(100);
|
|
|
+ dbData.setRecordStatus(1);
|
|
|
+ dbData.setCreateUserID(userId);
|
|
|
+ dbData.setCreateTime(new Date());
|
|
|
+ dbData.setQrcodeDate(nowDate);
|
|
|
+
|
|
|
+ wxQrcodeMapper.insert(dbData);
|
|
|
+ } else {
|
|
|
+ dbData.setModifyTime(new Date());
|
|
|
+ dbData.setModifyUserID(userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ return dbData.getUrl();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean qrcodeVerify(String qrCodeId, String openId) {
|
|
|
+ Integer result = 0;
|
|
|
+
|
|
|
+ WxQrcode wxQrcode = wxQrcodeMapper.selectByPrimaryKey(qrCodeId);
|
|
|
+ WxQrcodeScanRecordExample exp = new WxQrcodeScanRecordExample();
|
|
|
+ WxQrcodeScanRecordExample.Criteria cri = exp.or();
|
|
|
+ cri.andQrcodeIdEqualTo(qrCodeId);
|
|
|
+ if (wxQrcode.getScanMax() <= wxQrcodeScanRecordMapper.selectByExample(exp).size())
|
|
|
+ return false;
|
|
|
+ else {
|
|
|
+ WxQrcodeScanRecord wxQrcodeScanRecord = new WxQrcodeScanRecord();
|
|
|
+ wxQrcodeScanRecord.setQrcodeScanRecordId(UUID.randomUUID().toString());
|
|
|
+ wxQrcodeScanRecord.setQrcodeId(qrCodeId);
|
|
|
+ wxQrcodeScanRecord.setOpenId(openId);
|
|
|
+ wxQrcodeScanRecord.setCreateTime(new Date());
|
|
|
+ wxQrcodeScanRecord.setRecordStatus(1);
|
|
|
+
|
|
|
+ result = wxQrcodeScanRecordMapper.insert(wxQrcodeScanRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result > 0;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|