From 57755e68d324e32cae70af046db30b50cb41edfe Mon Sep 17 00:00:00 2001 From: sunyuchao Date: Fri, 7 Aug 2020 14:52:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AC=E4=BC=97=E5=8F=B7=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E6=8E=A5=E5=8F=A3=E6=B7=BB=E5=8A=A0=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=EF=BC=8C=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=B7=BB=E5=8A=A0=E5=8F=91=E9=80=81=E9=92=89?= =?UTF-8?q?=E9=92=89=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/result/CustomerAndUserResultDTO.java | 37 +++++++++++ .../PublicAccountCallBackController.java | 7 +++ .../java/com/epmet/dao/PaCustomerDao.java | 7 +++ .../ComponentVerifyTicketServiceImpl.java | 61 +++++++++++++++++++ .../main/resources/mapper/PaCustomerDao.xml | 24 ++++++++ 5 files changed, 136 insertions(+) create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/CustomerAndUserResultDTO.java diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/CustomerAndUserResultDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/CustomerAndUserResultDTO.java new file mode 100644 index 0000000000..08035efd03 --- /dev/null +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/CustomerAndUserResultDTO.java @@ -0,0 +1,37 @@ +package com.epmet.dto.result; + +import com.epmet.dto.PaCustomerDTO; +import com.epmet.dto.PaUserDTO; +import com.epmet.dto.PaUserWechatDTO; +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @Description 查询授权客户及管理员信息-接口返参 + * @Author sun + */ +@Data +public class CustomerAndUserResultDTO implements Serializable { + + private static final long serialVersionUID = 5214475907074876716L; + + /** + * 客户Id + */ + private String customerId; + /** + * 客户Id + */ + private String customerName; + /** + * 管理员称谓 + */ + private String appellation; + /** + * 管理员手机号 + */ + private String phone; +} diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/PublicAccountCallBackController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/PublicAccountCallBackController.java index b28809053d..6a8ee07de2 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/PublicAccountCallBackController.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/PublicAccountCallBackController.java @@ -55,6 +55,13 @@ public class PublicAccountCallBackController { } } + /** + * @return java.lang.String + * @author sun + * @description 此请求url是公众号后台设置的消息url,首次创建公众号时微信会发送get请求调用接口, + * 后边公众号所有的消息都是通过该url发送post请求,目前对于公众号的消息全部回复空字符串, + * 后续可以回复各种格式的消息,具体可参考: https://www.cnblogs.com/xdp-gacl/p/5161206.html + */ @PostMapping(value = "/callback") public String wxServerValdation() { return ""; diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaCustomerDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaCustomerDao.java index 7f59170729..126ef49db3 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaCustomerDao.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaCustomerDao.java @@ -22,6 +22,7 @@ import com.epmet.dto.PaCustomerDTO; import com.epmet.dto.form.ModifyCustomerFormDTO; import com.epmet.dto.form.RegisterByAuthFormDTO; import com.epmet.dto.result.CustomerAgencyResultDTO; +import com.epmet.dto.result.CustomerAndUserResultDTO; import com.epmet.dto.result.RegisterByAuthResultDTO; import com.epmet.entity.PaCustomerEntity; import org.apache.ibatis.annotations.Mapper; @@ -84,4 +85,10 @@ public interface PaCustomerDao extends BaseDao { * @date 2020/8/5 3:23 下午 */ String selectCustomerName(@Param("customerId") String customerId); + + /** + * @author sun + * @Description 查询客户及管理员信息 + */ + CustomerAndUserResultDTO selectCustomerAndUser(@Param("customerId") String customerId); } \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java index 9704f71e0a..aa327a2475 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java @@ -3,6 +3,10 @@ package com.epmet.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.client.config.utils.IOUtils; +import com.dingtalk.api.DefaultDingTalkClient; +import com.dingtalk.api.DingTalkClient; +import com.dingtalk.api.request.OapiRobotSendRequest; +import com.dingtalk.api.response.OapiRobotSendResponse; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.security.dto.TokenDto; @@ -12,6 +16,7 @@ import com.epmet.constant.ModuleConstant; import com.epmet.constant.ThirdRedisKeyConstant; import com.epmet.constant.ThirdRunTimeInfoConstant; import com.epmet.dao.*; +import com.epmet.dto.CustomerMpDTO; import com.epmet.dto.PaCustomerUserAgencyDTO; import com.epmet.dto.form.*; import com.epmet.dto.result.*; @@ -21,6 +26,7 @@ import com.epmet.mpaes.WXXmlToMapUtil; import com.epmet.redis.RedisThird; import com.epmet.service.ComponentVerifyTicketService; import com.epmet.wxapi.constant.WxMaCodeConstant; +import com.taobao.api.ApiException; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; @@ -34,6 +40,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.InputStream; import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; import static com.epmet.constant.ModuleConstant.COMPONENT_ACCESS_TOKEN; import static com.epmet.constant.ThirdRunTimeInfoConstant.*; @@ -88,6 +95,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe private PaUserDao paUserDao; @Autowired private PaCustomerServiceImpl paCustomerServiceImpl; + @Autowired + private PaCustomerDao paCustomerDao; @Value("${third.platform.appId}") private String componentAppId; @@ -448,6 +457,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe authCodeDao.updateAppId(customerId,clientType,authAppId); // 4. 保存授权方账户信息 this.saveAuthAccountInfo(customerId,authAppId,clientType); + // 5. 校验客户居民端、工作端小程序是否全部授权,全部授权完成的推送钉钉消息 sun + this.checkAuthorization(customerId); log.info("回调结束"); } @@ -689,4 +700,54 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe date.setTime(aLong); return date; } + + /** + * @author sun + * @Description 校验客户两哥小程序是否完成授权 + */ + private void checkAuthorization(String customerId){ + List list = customerMpDao.selectByCustomerId(customerId); + AtomicBoolean bl = new AtomicBoolean(false); + list.forEach(mp->{ + if(mp.getAuthorizationFlag()!=NumConstant.ONE){ + bl.set(true); + } + }); + if(!bl.get()){ + dDingNews(customerId); + } + } + + /** + * @author sun + * @Description 发送钉钉消息,通知运营人员有新客户完成授权 + */ + private String dDingNews(String customerId) { + //1.查询客户及管理员信息,用于发送消息使用 + CustomerAndUserResultDTO result = paCustomerDao.selectCustomerAndUser(customerId); + if (null == result || null == result.getCustomerId()) { + log.error("授权完成发送钉钉消息失败,原因:未查询到客户信息,客户Id->" + customerId); + return null; + } + //2.拼接钉钉消息内容并发送 + DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/robot/send?access_token=b4e47783ad72ba643278598ff8af90e745890c13538b2a4dc139635a71289dfd"); + OapiRobotSendRequest request = new OapiRobotSendRequest(); + request.setMsgtype("markdown"); + OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown(); + markdown.setTitle("授权客户信息"); + //"新客户通知"几个字是设置机器人时自定义的关键字,要保持代码与机器人设置的一致 + markdown.setText("新客户通知: \n" + + "> 客户名称: " + result.getCustomerName() + "\n\n" + + "> 管理员称谓: " + result.getAppellation() + "\n\n" + + "> 联系方式: " + result.getPhone() + "\n"); + request.setMarkdown(markdown); + try { + OapiRobotSendResponse response = client.execute(request); + } catch (ApiException e) { + log.error("机器人生病了......"); + e.printStackTrace(); + } + return null; + } + } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaCustomerDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaCustomerDao.xml index 2d09708ba1..ffceb02e07 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaCustomerDao.xml +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaCustomerDao.xml @@ -82,6 +82,30 @@ AND id = #{customerId} + + UPDATE pa_customer SET is_initialize = #{isInitialize}