|
@@ -9,13 +9,9 @@ import com.yeepay.yop.sdk.service.common.response.YopResponse;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.flowable.engine.TaskService;
|
|
import org.flowable.engine.TaskService;
|
|
|
-import org.flowable.engine.impl.persistence.entity.CommentEntityImpl;
|
|
|
|
|
-import org.flowable.engine.task.Comment;
|
|
|
|
|
import org.flowable.task.api.Task;
|
|
import org.flowable.task.api.Task;
|
|
|
import org.springblade.common.cache.FlowCache;
|
|
import org.springblade.common.cache.FlowCache;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
-import org.springblade.core.sms.model.SmsData;
|
|
|
|
|
-import org.springblade.core.tool.api.R;
|
|
|
|
|
import org.springblade.flow.business.constant.AuditCandidate;
|
|
import org.springblade.flow.business.constant.AuditCandidate;
|
|
|
import org.springblade.flow.business.service.FlowBusinessService;
|
|
import org.springblade.flow.business.service.FlowBusinessService;
|
|
|
import org.springblade.flow.core.entity.BladeFlow;
|
|
import org.springblade.flow.core.entity.BladeFlow;
|
|
@@ -26,26 +22,22 @@ import org.springblade.ldt.shop.entity.Audit;
|
|
|
import org.springblade.ldt.shop.entity.Shop;
|
|
import org.springblade.ldt.shop.entity.Shop;
|
|
|
import org.springblade.ldt.shop.service.IAuditService;
|
|
import org.springblade.ldt.shop.service.IAuditService;
|
|
|
import org.springblade.ldt.shop.service.IShopService;
|
|
import org.springblade.ldt.shop.service.IShopService;
|
|
|
-import org.springblade.modules.resource.enums.SmsCodeEnum;
|
|
|
|
|
-import org.springblade.modules.resource.utils.SmsUtil;
|
|
|
|
|
-import org.springblade.wx.config.ConfigForClient;
|
|
|
|
|
-import org.springblade.wx.config.ConfigForMall;
|
|
|
|
|
import org.springblade.wx.config.ConfigForShop;
|
|
import org.springblade.wx.config.ConfigForShop;
|
|
|
import org.springblade.wx.constant.MessageTemplate;
|
|
import org.springblade.wx.constant.MessageTemplate;
|
|
|
import org.springblade.wx.constant.MiniProgramType;
|
|
import org.springblade.wx.constant.MiniProgramType;
|
|
|
import org.springblade.wx.service.WeChatService;
|
|
import org.springblade.wx.service.WeChatService;
|
|
|
import org.springblade.wx.utils.UrlTransform;
|
|
import org.springblade.wx.utils.UrlTransform;
|
|
|
-import org.springblade.yeePay.common.YeePayConst;
|
|
|
|
|
import org.springblade.yeePay.common.YeepayApiConstant;
|
|
import org.springblade.yeePay.common.YeepayApiConstant;
|
|
|
-import org.springblade.yeePay.entity.ConfigAppDto;
|
|
|
|
|
-import org.springblade.yeePay.service.YeepayCommonService;
|
|
|
|
|
import org.springblade.yeePay.service.YeepaySaasService;
|
|
import org.springblade.yeePay.service.YeepaySaasService;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
|
|
-import java.util.*;
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
+import java.util.Set;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author: lianghanqiang
|
|
* @author: lianghanqiang
|
|
@@ -67,39 +59,44 @@ public class QueryAuthStatus {
|
|
|
private IAppShopService appShopService;
|
|
private IAppShopService appShopService;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 5分钟轮询微信认证列表
|
|
|
|
|
- * 用户申请状态待认证就通知用户进行账户确认
|
|
|
|
|
- * */
|
|
|
|
|
|
|
+ * 5分钟轮询微信认证列表
|
|
|
|
|
+ * 用户申请状态待认证就通知用户进行账户确认
|
|
|
|
|
+ */
|
|
|
@Scheduled(cron = "0 */1 * * * ?")
|
|
@Scheduled(cron = "0 */1 * * * ?")
|
|
|
- void queryStatus(){
|
|
|
|
|
|
|
+ void queryStatus() {
|
|
|
//查询当前微信认证队列各个状态
|
|
//查询当前微信认证队列各个状态
|
|
|
Set<AuthInfoData> authList = FlowCache.authList();
|
|
Set<AuthInfoData> authList = FlowCache.authList();
|
|
|
- if(Objects.isNull(authList)){
|
|
|
|
|
|
|
+ if (Objects.isNull(authList)) {
|
|
|
log.info("暂无认证队列");
|
|
log.info("暂无认证队列");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
authList.parallelStream().forEach(item -> {
|
|
authList.parallelStream().forEach(item -> {
|
|
|
- try{
|
|
|
|
|
|
|
+ try {
|
|
|
YopResponse yopResponse = yeepaySaasService.wechatAuthQuery(item);
|
|
YopResponse yopResponse = yeepaySaasService.wechatAuthQuery(item);
|
|
|
JSONObject resObj = JSON.parseObject(yopResponse.getStringResult());
|
|
JSONObject resObj = JSON.parseObject(yopResponse.getStringResult());
|
|
|
String applymentState = resObj.getString("applymentState");
|
|
String applymentState = resObj.getString("applymentState");
|
|
|
//状态为待用户验证
|
|
//状态为待用户验证
|
|
|
- if (Objects.equals(YeepayApiConstant.applymentState.APPLYMENT_STATE_WAITTING_FOR_CONFIRM_CONTACT.name(),applymentState)) {
|
|
|
|
|
- prepareForAuth(item,resObj);
|
|
|
|
|
|
|
+ boolean confirm = Objects.equals(YeepayApiConstant.applymentState.APPLYMENT_STATE_WAITTING_FOR_CONFIRM_CONTACT.name(), applymentState);
|
|
|
|
|
+ if (confirm) {
|
|
|
|
|
+ prepareForAuth(item, resObj);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //状态为驳回
|
|
|
|
|
- if (Objects.equals(YeepayApiConstant.applymentState.APPLYMENT_STATE_REJECTED.name(),applymentState)) {
|
|
|
|
|
- applyReject(item,resObj.getString("rejectReason"));
|
|
|
|
|
|
|
+ //状态为已完成认证
|
|
|
|
|
+ boolean passed = Objects.equals(YeepayApiConstant.applymentState.APPLYMENT_STATE_PASSED.name(), applymentState) ||
|
|
|
|
|
+ Objects.equals(YeepayApiConstant.applymentState.APPLYMENT_STATE_FREEZED.name(), applymentState);
|
|
|
|
|
+ if (passed) {
|
|
|
|
|
+ completeFlow(item, resObj.getString("rejectReason"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //状态为已完成认证
|
|
|
|
|
- if (Objects.equals(YeepayApiConstant.applymentState.APPLYMENT_STATE_PASSED.name(),applymentState)) {
|
|
|
|
|
- completeFlow(item);
|
|
|
|
|
|
|
+ //状态为驳回
|
|
|
|
|
+ boolean rejected = Objects.equals(YeepayApiConstant.applymentState.APPLYMENT_STATE_REJECTED.name(), applymentState);
|
|
|
|
|
+ if (rejected || (!passed && !confirm)) {
|
|
|
|
|
+ applyReject(item, resObj.getString("rejectReason"));
|
|
|
}
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
|
|
- log.error(String.format("查询微信认证状态异常:%s",e.getMessage()));
|
|
|
|
|
- applyReject(item,String.format("查询微信认证状态异常:%s",e.getMessage()));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error(String.format("查询微信认证状态异常:%s", e.getMessage()));
|
|
|
|
|
+ applyReject(item, String.format("查询微信认证状态异常:%s", e.getMessage()));
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -108,7 +105,7 @@ public class QueryAuthStatus {
|
|
|
* 用户申请驳回
|
|
* 用户申请驳回
|
|
|
* */
|
|
* */
|
|
|
public void applyReject(AuthInfoData item, String failReason) {
|
|
public void applyReject(AuthInfoData item, String failReason) {
|
|
|
- log.info(String.format("商户实名申请驳回,商户:%s;驳回原因:%s",item.getAudit().getShortName(),failReason));
|
|
|
|
|
|
|
+ log.info(String.format("商户实名申请驳回,商户:%s;驳回原因:%s", item.getAudit().getShortName(), failReason));
|
|
|
Audit audit = auditService.getById(Convert.toLong(item.getVariables().get("auditId")));
|
|
Audit audit = auditService.getById(Convert.toLong(item.getVariables().get("auditId")));
|
|
|
Shop shop = shopService.getById(Convert.toLong(item.getVariables().get("shopId")));
|
|
Shop shop = shopService.getById(Convert.toLong(item.getVariables().get("shopId")));
|
|
|
audit.setAuditStatus(ShopEnum.FAIL.name());
|
|
audit.setAuditStatus(ShopEnum.FAIL.name());
|
|
@@ -116,16 +113,20 @@ public class QueryAuthStatus {
|
|
|
List<Task> list = taskService.createTaskQuery().processInstanceId(audit.getProcessInstanceId()).taskAssignee(AuditCandidate.$INITIATOR.name()).active().list();
|
|
List<Task> list = taskService.createTaskQuery().processInstanceId(audit.getProcessInstanceId()).taskAssignee(AuditCandidate.$INITIATOR.name()).active().list();
|
|
|
Task task = list.get(0);
|
|
Task task = list.get(0);
|
|
|
taskService.addComment(task.getId(), task.getProcessInstanceId(), failReason);
|
|
taskService.addComment(task.getId(), task.getProcessInstanceId(), failReason);
|
|
|
- Assert.isTrue(auditService.saveOrUpdate(audit),()->{throw new ServiceException("商户:\"+shop.getId()+\" 完成商户认证--》 更新资料失败!");});
|
|
|
|
|
- Assert.isTrue(shopService.saveOrUpdate(shop),()->{throw new ServiceException("商户:\"+shop.getId()+\" 完成商户认证--》 更新审核状态失败!");});
|
|
|
|
|
|
|
+ Assert.isTrue(auditService.saveOrUpdate(audit), () -> {
|
|
|
|
|
+ throw new ServiceException("商户:\"+shop.getId()+\" 完成商户认证--》 更新资料失败!");
|
|
|
|
|
+ });
|
|
|
|
|
+ Assert.isTrue(shopService.saveOrUpdate(shop), () -> {
|
|
|
|
|
+ throw new ServiceException("商户:\"+shop.getId()+\" 完成商户认证--》 更新审核状态失败!");
|
|
|
|
|
+ });
|
|
|
FlowCache.removeAuthMember(item);
|
|
FlowCache.removeAuthMember(item);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 用户已完成授权,流程完成
|
|
|
|
|
- * */
|
|
|
|
|
|
|
+ * 用户已完成授权,流程完成
|
|
|
|
|
+ */
|
|
|
@Transactional
|
|
@Transactional
|
|
|
- public void completeFlow(AuthInfoData item) {
|
|
|
|
|
|
|
+ public void completeFlow(AuthInfoData item, String failReason) {
|
|
|
Audit audit = auditService.getById(Convert.toLong(item.getVariables().get("auditId")));
|
|
Audit audit = auditService.getById(Convert.toLong(item.getVariables().get("auditId")));
|
|
|
Shop shop = shopService.getById(Convert.toLong(item.getVariables().get("shopId")));
|
|
Shop shop = shopService.getById(Convert.toLong(item.getVariables().get("shopId")));
|
|
|
BladeFlow bladeFlow = new BladeFlow();
|
|
BladeFlow bladeFlow = new BladeFlow();
|
|
@@ -134,29 +135,37 @@ public class QueryAuthStatus {
|
|
|
|
|
|
|
|
IPage<BladeFlow> bladeFlowIPage = flowBusinessService.selectTodoPage(new Page<BladeFlow>(), bladeFlow);
|
|
IPage<BladeFlow> bladeFlowIPage = flowBusinessService.selectTodoPage(new Page<BladeFlow>(), bladeFlow);
|
|
|
BladeFlow task = bladeFlowIPage.getRecords().get(0);
|
|
BladeFlow task = bladeFlowIPage.getRecords().get(0);
|
|
|
- Assert.notNull(task,()->{ throw new ServiceException("商户:"+shop.getId()+" 完成商户认证--》 查询流程任务失败!"); });
|
|
|
|
|
|
|
+ Assert.notNull(task, () -> {
|
|
|
|
|
+ throw new ServiceException("商户:" + shop.getId() + " 完成商户认证--》 查询流程任务失败!");
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
task.setPass(Boolean.TRUE);
|
|
task.setPass(Boolean.TRUE);
|
|
|
task.setComment("商户入驻成功!");
|
|
task.setComment("商户入驻成功!");
|
|
|
- task.getVariables().put("applyPass",Boolean.TRUE);
|
|
|
|
|
|
|
+ task.getVariables().put("applyPass", Boolean.TRUE);
|
|
|
|
|
+ task.getVariables().put("failReason", failReason);
|
|
|
audit.setAuditStatus(ShopEnum.PASS.name());
|
|
audit.setAuditStatus(ShopEnum.PASS.name());
|
|
|
shop.setAuditStatus(ShopEnum.PASS.name());
|
|
shop.setAuditStatus(ShopEnum.PASS.name());
|
|
|
|
|
|
|
|
//配置小程序信息
|
|
//配置小程序信息
|
|
|
appShopService.configApp(shop);
|
|
appShopService.configApp(shop);
|
|
|
|
|
|
|
|
- Assert.isTrue(flowBusinessService.completeTask(task),()->{throw new ServiceException("商户:\"+shop.getId()+\" 完成商户认证--》 执行任务失败!");});
|
|
|
|
|
- Assert.isTrue(auditService.saveOrUpdate(audit),()->{throw new ServiceException("商户:\"+shop.getId()+\" 完成商户认证--》 更新资料失败!");});
|
|
|
|
|
- Assert.isTrue(shopService.saveOrUpdate(shop),()->{throw new ServiceException("商户:\"+shop.getId()+\" 完成商户认证--》 更新审核状态失败!");});
|
|
|
|
|
|
|
+ Assert.isTrue(flowBusinessService.completeTask(task), () -> {
|
|
|
|
|
+ throw new ServiceException("商户:\"+shop.getId()+\" 完成商户认证--》 执行任务失败!");
|
|
|
|
|
+ });
|
|
|
|
|
+ Assert.isTrue(auditService.saveOrUpdate(audit), () -> {
|
|
|
|
|
+ throw new ServiceException("商户:\"+shop.getId()+\" 完成商户认证--》 更新资料失败!");
|
|
|
|
|
+ });
|
|
|
|
|
+ Assert.isTrue(shopService.saveOrUpdate(shop), () -> {
|
|
|
|
|
+ throw new ServiceException("商户:\"+shop.getId()+\" 完成商户认证--》 更新审核状态失败!");
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
FlowCache.removeAuthMember(item);
|
|
FlowCache.removeAuthMember(item);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 通知用户
|
|
|
|
|
- * */
|
|
|
|
|
|
|
+ * 通知用户
|
|
|
|
|
+ */
|
|
|
private void sendMessageToUser(AuthInfoData item) {
|
|
private void sendMessageToUser(AuthInfoData item) {
|
|
|
try {
|
|
try {
|
|
|
|
|
|
|
@@ -167,19 +176,19 @@ public class QueryAuthStatus {
|
|
|
|
|
|
|
|
//微信模板消息
|
|
//微信模板消息
|
|
|
String openId = item.getShop().getOpenId();
|
|
String openId = item.getShop().getOpenId();
|
|
|
- String contentStr = String.format(MessageTemplate.INVITATION_SIGN.getContentString(),configForShop.getAppName(),"进入小程序完成认证");
|
|
|
|
|
|
|
+ String contentStr = String.format(MessageTemplate.INVITATION_SIGN.getContentString(), configForShop.getAppName(), "进入小程序完成认证");
|
|
|
JSONObject content = JSON.parseObject(contentStr);
|
|
JSONObject content = JSON.parseObject(contentStr);
|
|
|
- weChatService.sendTemplateMessage(openId, MessageTemplate.INVITATION_SIGN,content,configForShop.getAuthPage(), MiniProgramType.SHOP);
|
|
|
|
|
|
|
+ weChatService.sendTemplateMessage(openId, MessageTemplate.INVITATION_SIGN, content, configForShop.getAuthPage(), MiniProgramType.SHOP);
|
|
|
|
|
|
|
|
- }catch (Exception e){
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 认证二维码写进流程变量
|
|
|
|
|
- * */
|
|
|
|
|
|
|
+ * 认证二维码写进流程变量
|
|
|
|
|
+ */
|
|
|
private void notifyUserTask(AuthInfoData item, JSONObject resObj) {
|
|
private void notifyUserTask(AuthInfoData item, JSONObject resObj) {
|
|
|
Audit audit = auditService.getById(Convert.toLong(item.getVariables().get("auditId")));
|
|
Audit audit = auditService.getById(Convert.toLong(item.getVariables().get("auditId")));
|
|
|
Shop shop = shopService.getById(audit.getEntityId());
|
|
Shop shop = shopService.getById(audit.getEntityId());
|
|
@@ -193,7 +202,7 @@ public class QueryAuthStatus {
|
|
|
Map<String, Object> variables = task.getVariables();
|
|
Map<String, Object> variables = task.getVariables();
|
|
|
String authUrl = resObj.getString("qrcodeUrl");
|
|
String authUrl = resObj.getString("qrcodeUrl");
|
|
|
variables.put("qrcodeUrl", UrlTransform.cheakUrl(authUrl));
|
|
variables.put("qrcodeUrl", UrlTransform.cheakUrl(authUrl));
|
|
|
- taskService.setVariables(task.getTaskId(),variables);
|
|
|
|
|
|
|
+ taskService.setVariables(task.getTaskId(), variables);
|
|
|
shop.setAuditStatus(ShopEnum.WAITING_AUTH.name());
|
|
shop.setAuditStatus(ShopEnum.WAITING_AUTH.name());
|
|
|
audit.setAuditStatus(ShopEnum.WAITING_AUTH.name());
|
|
audit.setAuditStatus(ShopEnum.WAITING_AUTH.name());
|
|
|
shopService.saveOrUpdate(shop);
|
|
shopService.saveOrUpdate(shop);
|
|
@@ -201,18 +210,18 @@ public class QueryAuthStatus {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- private void prepareForAuth(AuthInfoData item, JSONObject resObj){
|
|
|
|
|
|
|
+ private void prepareForAuth(AuthInfoData item, JSONObject resObj) {
|
|
|
// if( Objects.isNull(item.getIsNotify()) || !item.getIsNotify()){
|
|
// if( Objects.isNull(item.getIsNotify()) || !item.getIsNotify()){
|
|
|
//
|
|
//
|
|
|
// }
|
|
// }
|
|
|
FlowCache.removeAuthMember(item);
|
|
FlowCache.removeAuthMember(item);
|
|
|
- try{
|
|
|
|
|
- notifyUserTask(item,resObj);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ notifyUserTask(item, resObj);
|
|
|
sendMessageToUser(item);
|
|
sendMessageToUser(item);
|
|
|
item.setIsNotify(Boolean.TRUE);
|
|
item.setIsNotify(Boolean.TRUE);
|
|
|
- }catch (Exception e){
|
|
|
|
|
- log.error("通知用户认证异常:"+ e.getMessage());
|
|
|
|
|
- }finally {
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("通知用户认证异常:" + e.getMessage());
|
|
|
|
|
+ } finally {
|
|
|
FlowCache.addAuthMember(item);
|
|
FlowCache.addAuthMember(item);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|