From 15f45579df5cae8bc98d2b9fc494da9d649c1320 Mon Sep 17 00:00:00 2001 From: zxc <954985706@qq.com> Date: Thu, 30 Jul 2020 14:25:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0-=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/AppLetAuthorizationServiceImpl.java | 10 ++--- .../ComponentVerifyTicketServiceImpl.java | 40 +++---------------- .../service/impl/WarrantServiceImpl.java | 7 ++-- 3 files changed, 11 insertions(+), 46 deletions(-) diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/AppLetAuthorizationServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/AppLetAuthorizationServiceImpl.java index 834866bfd2..dd50366b48 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/AppLetAuthorizationServiceImpl.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/AppLetAuthorizationServiceImpl.java @@ -5,12 +5,12 @@ import com.alibaba.fastjson.JSONObject; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.HttpClientManager; import com.epmet.constant.ModuleConstant; import com.epmet.dao.BindingAccountDao; import com.epmet.dao.CustomerMpDao; import com.epmet.dao.OpenPlatformAccountDao; -import com.epmet.dao.PaCustomerAgencyDao; import com.epmet.dto.form.GoToAuthFormDTO; import com.epmet.dto.form.OpenAppIdFormDTO; import com.epmet.dto.form.RemoveBindFormDTO; @@ -35,13 +35,9 @@ import java.util.Map; @Service public class AppLetAuthorizationServiceImpl implements AppLetAuthorizationService { - @Autowired - private PaCustomerAgencyDao paCustomerAgencyDao; @Autowired private ComponentVerifyTicketService componentVerifyTicketService; @Autowired - private ComponentVerifyTicketServiceImpl componentVerifyTicketServiceImpl; - @Autowired private OpenPlatformAccountDao openPlatformAccountDao; @Autowired private CustomerMpDao customerMpDao; @@ -85,7 +81,7 @@ public class AppLetAuthorizationServiceImpl implements AppLetAuthorizationServic //查询appId String authAppId = customerMpDao.getAppId(customerId, clientType); Map authInfo = redisThird.getAuthInfo(customerId, clientType); - AuthorizationInfoResultDTO authorizationInfo = componentVerifyTicketServiceImpl.mapToEntity(authInfo, AuthorizationInfoResultDTO.class); + AuthorizationInfoResultDTO authorizationInfo = ConvertUtils.mapToEntity(authInfo, AuthorizationInfoResultDTO.class); JSONObject jsonObject = new JSONObject(); jsonObject.put(ModuleConstant.LOW_APP_ID,authAppId); jsonObject.put(ModuleConstant.OPEN_APP_ID,openAppId); @@ -110,7 +106,7 @@ public class AppLetAuthorizationServiceImpl implements AppLetAuthorizationServic String clientType = formDTO.getClientType(); String authAppId = customerMpDao.getAppId(customerId, clientType); Map authInfo = redisThird.getAuthInfo(customerId, clientType); - AuthorizationInfoResultDTO authorizationInfo = componentVerifyTicketServiceImpl.mapToEntity(authInfo, AuthorizationInfoResultDTO.class); + AuthorizationInfoResultDTO authorizationInfo = ConvertUtils.mapToEntity(authInfo, AuthorizationInfoResultDTO.class); JSONObject jsonObject = new JSONObject(); jsonObject.put(ModuleConstant.LOW_APP_ID,authAppId); String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.UN_BIND + authorizationInfo.getAuthorizer_access_token(), JSON.toJSONString(jsonObject)).getData(); 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 0791597950..4414fac9bd 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 @@ -6,6 +6,7 @@ import com.alibaba.nacos.client.config.utils.IOUtils; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.HttpClientManager; import com.epmet.constant.ModuleConstant; import com.epmet.constant.ThirdRedisKeyConstant; @@ -31,7 +32,6 @@ import org.springframework.web.bind.annotation.RequestBody; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.InputStream; -import java.lang.reflect.Field; import java.util.*; import static com.epmet.constant.ModuleConstant.COMPONENT_ACCESS_TOKEN; @@ -175,7 +175,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe public void disposeAuthResult(Map result){ Map tempMap = result; Map data = tempMap; - AuthResultRecordFormDTO authResultRecord = mapToEntity(data, AuthResultRecordFormDTO.class); + AuthResultRecordFormDTO authResultRecord = ConvertUtils.mapToEntity(data, AuthResultRecordFormDTO.class); authResultRecord.setWechatCreateTime(this.sToDate(result.get(ModuleConstant.CREATE_TIME))); if (result.containsKey(ModuleConstant.AUTHORIZATION_CODE_EXPIRED_TIME)) { authResultRecord.setExpiredTime(this.sToDate(result.get(ModuleConstant.AUTHORIZATION_CODE_EXPIRED_TIME))); @@ -285,7 +285,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe String authInfo = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_QUERY_AUTH_URL + accessToken, JSON.toJSONString(jsonObject)).getData(); HashMap hashMap = JSON.parseObject(authInfo, HashMap.class); Map map = hashMap.get(ModuleConstant.AUTHORIZATION_INFO); - authorizationInfoResultDTO = mapToEntity(map, AuthorizationInfoResultDTO.class); + authorizationInfoResultDTO = ConvertUtils.mapToEntity(map, AuthorizationInfoResultDTO.class); String authAppId = authorizationInfoResultDTO.getAuthorizer_appid(); log.info("授权信息:"+map); String expiresIn = authorizationInfoResultDTO.getExpires_in().toString(); @@ -433,7 +433,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe boolean keyExist = authorizerInfo.containsKey(ModuleConstant.MINI_PROGRAM_INFO); if (keyExist == true){ log.info("授权方为小程序 并 开始插入信息"); - MiniInfoFormDTO miniInfoFormDTO = this.mapToEntity(authorizerInfo, MiniInfoFormDTO.class); + MiniInfoFormDTO miniInfoFormDTO = ConvertUtils.mapToEntity(authorizerInfo, MiniInfoFormDTO.class); miniInfoFormDTO.setCustomerId(customerId); miniInfoFormDTO.setClientType(clientType); //基础信息插入 @@ -485,7 +485,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe } }else { log.info("授权方为公众号 并 开始插入信息"); - PaInfoFormDTO paInfoFormDTO = this.mapToEntity(authorizerInfo, PaInfoFormDTO.class); + PaInfoFormDTO paInfoFormDTO = ConvertUtils.mapToEntity(authorizerInfo, PaInfoFormDTO.class); //公众号基本信息插入 paInfoDao.insertPaInfo(paInfoFormDTO); String primaryId = paInfoFormDTO.getId(); @@ -611,36 +611,6 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe } } - /** - * @Description map 转 Entity - * @param map - * @param entity - * @author zxc - */ - public T mapToEntity(Map map, Class entity) { - T t = null; - try { - t = entity.newInstance(); - for(Field field : entity.getDeclaredFields()) { - if (map.containsKey(field.getName())) { - boolean flag = field.isAccessible(); - field.setAccessible(true); - Object object = map.get(field.getName()); - if (object!= null && field.getType().isAssignableFrom(object.getClass())) { - field.set(t, object); - } - field.setAccessible(flag); - } - } - return t; - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - return t; - } - /** * @Description 转换过期时间 * @param expiresIn diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java index 20f75b74fb..956c5c31e6 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java @@ -1,6 +1,7 @@ package com.epmet.service.impl; import com.alibaba.nacos.client.config.utils.IOUtils; +import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.constant.ModuleConstant; import com.epmet.constant.ThirdRunTimeInfoConstant; import com.epmet.dao.*; @@ -44,8 +45,6 @@ public class WarrantServiceImpl implements WarrantService { @Value("${third.platform.token}") private String token; @Autowired - private ComponentVerifyTicketServiceImpl componentVerifyTicketService; - @Autowired private CodeAuditRecordDao codeAuditRecordDao; @Autowired private MiniInfoDao miniInfoDao; @@ -96,7 +95,7 @@ public class WarrantServiceImpl implements WarrantService { if (xml.get(ModuleConstant.MSG_TYPE).equals(ModuleConstant.EVENT_LOW)) { // TODO 目前来看,msgType = ‘event’ 的是代码审核结果 Long createTime = Long.valueOf(xml.get(ModuleConstant.CREATE_TIME).toString()); - CodeAuditRecordFormDTO codeAuditRecord = componentVerifyTicketService.mapToEntity(xml, CodeAuditRecordFormDTO.class); + CodeAuditRecordFormDTO codeAuditRecord = ConvertUtils.mapToEntity(xml, CodeAuditRecordFormDTO.class); codeAuditRecord.setWechatCreateTime(componentVerifyTicketServiceImpl.sToDate(createTime.toString())); String toUserName = codeAuditRecord.getToUserName();//小程序原始ID CustomerIdAndClientResultDTO customerIdAndClientResultDTO = miniInfoDao.selectCustomerIdAndClientByToUserName(toUserName); @@ -130,7 +129,7 @@ public class WarrantServiceImpl implements WarrantService { codeAuditResultDao.updateAuditResult(customerId, codeCustomerId, codeResult); }else if (xml.get(ModuleConstant.MSG_TYPE).equals(ModuleConstant.TEXT)){ // TODO 公众号回复消息 - MessagePushTextFormDTO messagePushTextFormDTO = componentVerifyTicketService.mapToEntity(xml, MessagePushTextFormDTO.class); + MessagePushTextFormDTO messagePushTextFormDTO = ConvertUtils.mapToEntity(xml, MessagePushTextFormDTO.class); Object createTime = xml.get(ModuleConstant.CREATE_TIME); Date date = componentVerifyTicketServiceImpl.sToDate(createTime.toString()); messagePushTextFormDTO.setWeChatCreateTime(date);